Replace diff-builder rendering by plain Lit rendering

This is a vast simplification of how GrDiff is being rendered. There is
no need to explicitly request rendering of the diff. It will just happen
as part of Lit's usual rendering process.

This also means that lots of `init()` and `cleanup()` methods are
obsolete.

With this change the notion of a "diff builder" is gone. Apart from
merging the GrDiffBuilder into GrDiff we are also mergin the image diff
builder and the binary diff builder into GrDiff, see the new
`renderImageDiff()` and `renderBinaryDiff()` methods.

We are adding a `getUpdateComplete` pattern to gr-diff and
gr-diff-section that is already used elsewhere: It allows parents to
`await el.updateComplete` making sure that all children are also
already rendered. This allows us to remove `waitUntilRendered()` from
gr-diff-group.

Release-Notes: skip
Google-Bug-Id: b/280018960
Change-Id: I8dd98ab9ea35dbed6eb05a43071f9cf67594d013
diff --git a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-utils.ts b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-utils.ts
index 0b688a6..cfb64b9 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-utils.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff-utils.ts
@@ -4,8 +4,9 @@
  * SPDX-License-Identifier: Apache-2.0
  */
 import {BlameInfo, CommentRange} from '../../../types/common';
-import {Side} from '../../../constants/constants';
+import {Side, SpecialFilePath} from '../../../constants/constants';
 import {
+  DiffContextExpandedExternalDetail,
   DiffPreferencesInfo,
   DiffResponsiveMode,
   DisplayLine,
@@ -15,6 +16,7 @@
   RenderPreferences,
 } from '../../../api/diff';
 import {getBaseUrl} from '../../../utils/url-util';
+import {GrDiffGroup} from './gr-diff-group';
 
 /**
  * In JS, unicode code points above 0xFFFF occupy two elements of a string.
@@ -227,6 +229,20 @@
   return defaultContext;
 }
 
+export function computeLineLength(
+  prefs: DiffPreferencesInfo,
+  path: string | undefined
+): number {
+  if (path === SpecialFilePath.COMMIT_MESSAGE) {
+    return 72;
+  }
+  const lineLength = prefs.line_length;
+  if (Number.isInteger(lineLength) && lineLength > 0) {
+    return lineLength;
+  }
+  return 100;
+}
+
 export function computeKeyLocations(
   lineOfInterest: DisplayLine | undefined,
   comments: GrDiffCommentThread[]
@@ -474,3 +490,11 @@
 
   return blameNode;
 }
+
+export interface DiffContextExpandedEventDetail
+  extends DiffContextExpandedExternalDetail {
+  /** The context control group that should be replaced by `groups`. */
+  contextGroup: GrDiffGroup;
+  groups: GrDiffGroup[];
+  numLines: number;
+}