@openclaw/diffs 2026.9.6 → 2026.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icon.png +0 -0
- package/dist/.setup/{browser.runtime-VjaO3wrj.mjs → browser.runtime-v15gbeC0.mjs} +1 -1
- package/dist/.setup/{viewer-assets-D3qrnaxI.mjs → viewer-assets-Bg9efLih.mjs} +24 -49
- package/dist/assets/viewer-runtime.js +2 -2
- package/dist/index.js +241 -201
- package/node_modules/@pierre/diffs/dist/components/File.d.ts +1 -0
- package/node_modules/@pierre/diffs/dist/components/File.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/File.js +4 -0
- package/node_modules/@pierre/diffs/dist/components/File.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/FileDiff.d.ts +1 -0
- package/node_modules/@pierre/diffs/dist/components/FileDiff.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/FileDiff.js +4 -0
- package/node_modules/@pierre/diffs/dist/components/FileDiff.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.js +8 -9
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.js +8 -6
- package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/editor/editor.js +3 -5
- package/node_modules/@pierre/diffs/dist/editor/editor.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/editor/textMeasure.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/editor/textMeasure.js +27 -3
- package/node_modules/@pierre/diffs/dist/editor/textMeasure.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js +8 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/registerCustomLanguage.d.ts +3 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/registerCustomLanguage.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/registerCustomLanguage.js +3 -1
- package/node_modules/@pierre/diffs/dist/highlighter/languages/registerCustomLanguage.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/node_modules/@pierre/diffs/dist/worker/WorkerPoolManager.js +40 -38
- package/node_modules/@pierre/diffs/dist/worker/WorkerPoolManager.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/worker/worker-portable.js +8 -1
- package/node_modules/@pierre/diffs/dist/worker/worker-portable.js.map +1 -1
- package/node_modules/@pierre/diffs/dist/worker/worker.js +8 -1
- package/node_modules/@pierre/diffs/dist/worker/worker.js.map +1 -1
- package/node_modules/@pierre/diffs/package.json +1 -1
- package/node_modules/typebox/build/compile/code.mjs +1 -2
- package/node_modules/typebox/build/compile/validator.mjs +5 -1
- package/node_modules/typebox/build/format/iri.mjs +16 -9
- package/node_modules/typebox/build/guard/emit.mjs +2 -2
- package/node_modules/typebox/build/guard/guard.d.mts +7 -5
- package/node_modules/typebox/build/guard/guard.mjs +14 -9
- package/node_modules/typebox/build/guard/index.mjs +6 -0
- package/node_modules/typebox/build/guard/unicode/unicode.d.mts +6 -0
- package/node_modules/typebox/build/guard/unicode/unicode.mjs +35 -0
- package/node_modules/typebox/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
- package/node_modules/typebox/build/schema/build.mjs +2 -3
- package/node_modules/typebox/build/schema/engine/_pathing.d.mts +1 -0
- package/node_modules/typebox/build/schema/engine/_pathing.mjs +11 -0
- package/node_modules/typebox/build/schema/engine/_refine.mjs +13 -5
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +2 -1
- package/node_modules/typebox/build/schema/engine/dependencies.mjs +2 -1
- package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +2 -1
- package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +1 -1
- package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/format.mjs +9 -2
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +3 -2
- package/node_modules/typebox/build/schema/engine/properties.mjs +3 -2
- package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -1
- package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +1 -1
- package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/ref.d.mts +1 -1
- package/node_modules/typebox/build/schema/engine/ref.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/schema.mjs +24 -24
- package/node_modules/typebox/build/schema/parse.mjs +3 -0
- package/node_modules/typebox/build/schema/pointer/pointer.d.mts +1 -6
- package/node_modules/typebox/build/schema/pointer/pointer.mjs +47 -64
- package/node_modules/typebox/build/system/settings/internal.d.mts +2 -0
- package/node_modules/typebox/build/system/settings/internal.mjs +20 -0
- package/node_modules/typebox/build/system/settings/settings.d.mts +11 -0
- package/node_modules/typebox/build/system/settings/settings.mjs +14 -0
- package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
- package/node_modules/typebox/build/type/extends/inference.mjs +15 -2
- package/node_modules/typebox/build/type/extends/tuple.d.mts +2 -1
- package/node_modules/typebox/build/type/extends/tuple.mjs +21 -1
- package/node_modules/typebox/build/value/parse/parse.mjs +10 -4
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +3 -1
- package/package.json +6 -6
- package/dist/api.js +0 -3
- package/dist/runtime-api.js +0 -2
- /package/node_modules/typebox/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n DIFFS_TAG_NAME,\n EMPTY_RENDER_RANGE,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n THEME_CSS_ATTRIBUTE,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport type { Editor } from '../editor/editor';\nimport type { TextDocument } from '../editor/textDocument';\nimport type {\n CapturedDiffSessionState,\n EditCompletionDecision,\n EditorActiveLineOptions,\n EditorChangeEvent,\n FileDiffEditCompleteEvent,\n RetainedDiffSessionSnapshot,\n} from '../editor/types';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport {\n type GetHoveredLineResult,\n type GetLineIndexUtility,\n InteractionManager,\n type InteractionManagerBaseOptions,\n pluckInteractionOptions,\n type SelectionWriteOptions,\n} from '../managers/InteractionManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { ScrollSyncManager } from '../managers/ScrollSyncManager';\nimport {\n dequeueRender,\n queueRender,\n} from '../managers/UniversalRenderingManager';\nimport {\n DiffHunksRenderer,\n type DiffHunksRendererOptions,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nexport type { FileDiffEditCompleteEvent } from '../editor/types';\nimport type {\n AppliedThemeStyleCache,\n BaseCodeOptions,\n BaseDiffOptions,\n CustomPreProperties,\n DiffLineAnnotation,\n ExpansionDirections,\n DiffsHighlighter,\n FileContents,\n FileDiffMetadata,\n HighlightedToken,\n HunkData,\n HunkSeparators,\n LineAnnotation,\n MaybeDiffFileInput,\n PostRenderPhase,\n PrePropertiesConfig,\n RenderHeaderFilenameSuffixCallback,\n RenderHeaderMetadataCallback,\n RenderHeaderPrefixCallback,\n RenderRange,\n SelectedLineRange,\n SelectionSide,\n ThemeTypes,\n} from '../types';\nimport { areDiffLineAnnotationsEqual } from '../utils/areDiffLineAnnotationsEqual';\nimport { areDiffTargetsEqual } from '../utils/areDiffTargetsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areHunkDataEqual } from '../utils/areHunkDataEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { awaitWithTimeout } from '../utils/awaitWithTimeout';\nimport {\n cloneFileDiffMetadata,\n cloneHunks,\n} from '../utils/cloneFileDiffMetadata';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createGutterUtilityContentNode } from '../utils/createGutterUtilityContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport {\n patchScrollbarGutterSize,\n wrapThemeCSS,\n wrapUnsafeCSS,\n} from '../utils/cssWrappers';\nimport {\n adoptEditSessionAnnotations,\n type EditSessionAnnotations,\n resolveEditSessionSlotName,\n writeEditSessionAnnotations,\n} from '../utils/editSessionAnnotations';\nimport {\n captureExpansionAnchors,\n finishEditSessionForDiff,\n rebuildExpansionFromAnchors,\n} from '../utils/editSessionHunks';\nimport { getDiffFileInput } from '../utils/getDiffFileInput';\nimport { getDiffHunksRendererOptions } from '../utils/getDiffHunksRendererOptions';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHunkSideStartBoundary } from '../utils/getHunkSideBoundaries';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { getThemes } from '../utils/getThemes';\nimport { guardWebKitScrollDuringRebuild } from '../utils/guardWebKitScrollDuringRebuild';\nimport { upsertHostThemeStyle } from '../utils/hostTheme';\nimport { hydratePartialDiff } from '../utils/hydratePartialDiff';\nimport { isDefaultRenderRange } from '../utils/isDefaultRenderRange';\nimport { isDiffPlainText } from '../utils/isDiffPlainText';\nimport { isStyleNode } from '../utils/isStyleNode';\nimport { iterateOverDiff } from '../utils/iterateOverDiff';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { isSafari } from '../utils/platform';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { getMeasuredScrollbarGutter } from '../utils/scrollbarGutter';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport { splitFileContents } from '../utils/splitFileContents';\nimport { recomputeDiffRenderLineCounts } from '../utils/updateDiffHunks';\nimport {\n getExpandedRegion,\n getHunkAdditionLineRange,\n getNearestRenderableAdditionLine,\n getTrailingExpandedRegion,\n isAdditionLineRenderable,\n} from '../utils/virtualDiffLayout';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\ntype LoadedPartialDiffContents = Awaited<\n ReturnType<NonNullable<BaseDiffOptions['loadDiffFiles']>>\n>;\n\ntype DeferredSelectedLinesWrite = [\n range: SelectedLineRange | null,\n options: SelectionWriteOptions | undefined,\n];\n\ntype DeferredEditorActiveLineWrite = [\n lineNumber: number | null,\n options: EditorActiveLineOptions | undefined,\n];\n\nfunction canHydrateDiff(fileDiff: FileDiffMetadata): boolean {\n return (\n fileDiff.isPartial &&\n (fileDiff.type === 'change' ||\n fileDiff.type === 'rename-changed' ||\n fileDiff.type === 'rename-pure')\n );\n}\n\n// Edit sessions incrementally clone the diff as needed while editing,\n// initially we start with a top level fast clone\nfunction createEditSessionDiff(fileDiff: FileDiffMetadata): FileDiffMetadata {\n const editSessionDiff = { ...fileDiff };\n delete editSessionDiff.cacheKey;\n return editSessionDiff;\n}\n\nfunction shouldResetUndoState(\n prevDiff: FileDiffMetadata,\n nextDiff: FileDiffMetadata\n): boolean {\n if (prevDiff.isPartial || nextDiff.isPartial) {\n throw new Error(\n 'FileDiff.shouldResetEditorForExternalDiff: diffs must be fully hydrated'\n );\n }\n const prevLanguage = prevDiff.lang ?? getFiletypeFromFileName(prevDiff.name);\n const nextLanguage = nextDiff.lang ?? getFiletypeFromFileName(nextDiff.name);\n const prevHasOldFile = prevDiff.type !== 'new';\n const nextHasOldFile = nextDiff.type !== 'new';\n if (\n prevDiff.name !== nextDiff.name ||\n prevLanguage !== nextLanguage ||\n prevHasOldFile !== nextHasOldFile ||\n prevDiff.deletionLines.length !== nextDiff.deletionLines.length\n ) {\n return true;\n }\n return prevDiff.deletionLines.some(\n (line, index) => line !== nextDiff.deletionLines[index]\n );\n}\n\nfunction areLinesEqual(first: string[], second: string[]): boolean {\n return (\n first.length === second.length &&\n first.every((line, index) => line === second[index])\n );\n}\n\n// There are certain scenarios where if a diff changes in a certain way, we\n// cannot consider the session resumable. Basically if the old file has\n// changed in any way (name or contents), then our restored diff would be\n// completely invalid\nfunction canRestoreDiffSession(\n snapshot: RetainedDiffSessionSnapshot,\n externalDiff: FileDiffMetadata\n): boolean {\n const { oldFile } = snapshot;\n if (oldFile == null) {\n return externalDiff.type === 'new';\n }\n return (\n externalDiff.type !== 'new' &&\n oldFile.name === (externalDiff.prevName ?? externalDiff.name) &&\n areLinesEqual(oldFile.lines, externalDiff.deletionLines)\n );\n}\n\nexport interface FileDiffRenderBaseProps<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n deferManagers?: boolean;\n forceRender?: boolean;\n preventEmit?: boolean;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n renderRange?: RenderRange;\n}\n\nexport type FileDiffRenderProps<LAnnotation> =\n FileDiffRenderBaseProps<LAnnotation> & MaybeDiffFileInput;\n\nexport type FileDiffHydrationProps<LAnnotation> = Omit<\n FileDiffRenderBaseProps<LAnnotation>,\n 'fileContainer'\n> &\n MaybeDiffFileInput & {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n };\n\nexport type FileDiffType = 'file-diff' | 'unresolved-file';\n\nexport type FileDiffEditChangeHandler<LAnnotation, Caret> = (\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n) => void;\n\n/**\n * Decides a completed edit synchronously: return `'accept'` to install the\n * event's `fileDiff` and annotations, or `'reject'` to restore the original\n * values. The event is frozen, so re-key the accepted diff in place\n * (`event.fileDiff.cacheKey = '…'`) before accepting. The event's editor is\n * detached and returns its final state from `getViewState()`. A missing handler\n * rejects.\n */\nexport type FileDiffEditCompleteHandler<LAnnotation, Caret> = (\n event: FileDiffEditCompleteEvent<LAnnotation, Caret>\n) => EditCompletionDecision;\n\nexport interface FileDiffOptions<LAnnotation, Caret>\n extends\n Omit<BaseDiffOptions, 'hunkSeparators'>,\n InteractionManagerBaseOptions<'diff'> {\n hunkSeparators?:\n | Exclude<HunkSeparators, 'custom'> /**\n * @deprecated Custom hunk separator functions are deprecated and will be\n * removed in a future version.\n */\n | ((\n hunk: HunkData,\n instance: FileDiff<LAnnotation, Caret>\n ) => HTMLElement | DocumentFragment | null | undefined);\n disableFileHeader?: boolean;\n renderHeaderPrefix?: RenderHeaderPrefixCallback;\n renderHeaderFilenameSuffix?: RenderHeaderFilenameSuffixCallback;\n renderHeaderMetadata?: RenderHeaderMetadataCallback;\n renderCustomHeader?: RenderHeaderMetadataCallback;\n /**\n * When true, errors during rendering are rethrown instead of being caught\n * and displayed in the DOM. Useful for testing or when you want to handle\n * errors yourself.\n */\n disableErrorHandling?: boolean;\n renderAnnotation?(\n annotation: DiffLineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderGutterUtility?(\n getHoveredRow: () => GetHoveredLineResult<'diff'> | undefined\n ): HTMLElement | null | undefined;\n\n onPostRender?(\n node: HTMLElement,\n instance: FileDiff<LAnnotation, Caret>,\n phase: PostRenderPhase\n ): unknown;\n\n /**\n * Fired for every document change of an active edit session on this\n * component, with the same `EditorChangeEvent` the editor reports through\n * its own `onChange`. Do not feed the event's file back into the component\n * while the session is active.\n */\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n\n /**\n * Fired when `edit` toggles false or a component unmounts, including when the\n * final contents are unchanged. If no callback is provided, the component\n * reverts to the last `fileDiff` or `oldFile`/`newFiles` and annotations\n * passed into it. The callback receives the detached editor with its final\n * pre-detach state.\n */\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: DiffLineAnnotation<LAnnotation>;\n}\n\ninterface CustomHunkElementCache {\n element: HTMLElement;\n hunkData: HunkData;\n}\n\ninterface ColumnElements {\n gutter: HTMLElement;\n content: HTMLElement;\n}\n\ninterface TrimColumnsToOverlapProps {\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements;\n diffStyle: 'split' | 'unified';\n overlapEnd: number;\n overlapStart: number;\n previousStart: number;\n trimEnd: number;\n trimStart: number;\n}\n\ninterface ApplyPartialRenderProps {\n fileDiff: FileDiffMetadata;\n previousRenderRange: RenderRange | undefined;\n renderRange: RenderRange | undefined;\n}\n\ninterface PendingFileLoad {\n fileDiff: FileDiffMetadata;\n promise: Promise<void>;\n}\n\ntype HydrationSetup<LAnnotation> = {\n fileDiff: FileDiffMetadata | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} & MaybeDiffFileInput;\n\ninterface HeaderCache {\n lastRenderedHTML: string | undefined;\n html: string | undefined;\n fileDiff: FileDiffMetadata | undefined;\n}\n\ninterface EditSession<LAnnotation> {\n diff: FileDiffMetadata;\n annotations:\n | EditSessionAnnotations<DiffLineAnnotation<LAnnotation>>\n | undefined;\n /*\n * `outgoingDiff` keeps the diff the document still holds (the render already\n * shows the new `diff`): its presence signals the pending replacement, and it\n * supplies the old-file side both for the undo-reset decision and for\n * capturing session state.\n */\n outgoingDiff: FileDiffMetadata | undefined;\n}\n\nlet instanceId = -1;\n\nexport class FileDiff<LAnnotation = undefined, Caret = undefined> {\n // NOTE(amadeus): We sorta need this to ensure the web-component file is\n // properly loaded\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file-diff:${++instanceId}`;\n readonly type: FileDiffType = 'file-diff';\n\n protected fileContainer: HTMLElement | undefined;\n protected spriteSVG: SVGElement | undefined;\n protected pre: HTMLPreElement | undefined;\n protected codeUnified: HTMLElement | undefined;\n protected codeDeletions: HTMLElement | undefined;\n protected codeAdditions: HTMLElement | undefined;\n protected bufferBefore: HTMLElement | undefined;\n protected bufferAfter: HTMLElement | undefined;\n protected themeCSSStyle: HTMLStyleElement | undefined;\n protected appliedThemeCSS: AppliedThemeStyleCache | undefined;\n protected hasAdoptedThemeCSS = false;\n protected unsafeCSSStyle: HTMLStyleElement | undefined;\n protected appliedUnsafeCSS: string | undefined;\n protected gutterUtilityContent: HTMLElement | undefined;\n\n protected headerElement: HTMLElement | undefined;\n protected headerPrefix: HTMLElement | undefined;\n protected headerFilenameSuffix: HTMLElement | undefined;\n protected headerMetadata: HTMLElement | undefined;\n protected headerCustom: HTMLElement | undefined;\n protected separatorCache: Map<string, CustomHunkElementCache> = new Map();\n protected errorWrapper: HTMLElement | undefined;\n protected placeHolder: HTMLElement | undefined;\n\n protected hunksRenderer: DiffHunksRenderer<LAnnotation>;\n protected resizeManager: ResizeManager;\n protected scrollSyncManager: ScrollSyncManager;\n protected interactionManager: InteractionManager<'diff'>;\n\n protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n protected lineAnnotations: DiffLineAnnotation<LAnnotation>[] = [];\n protected managersDirty = false;\n\n protected deletionFile?: FileContents | null;\n protected additionFile?: FileContents | null;\n public fileDiff: FileDiffMetadata | undefined;\n private editSession: EditSession<LAnnotation> | undefined;\n protected renderedDiff: FileDiffMetadata | undefined;\n protected renderRange: RenderRange | undefined;\n protected pendingFiles: PendingFileLoad | undefined;\n protected appliedPreAttributes: PrePropertiesConfig | undefined;\n protected headerCache: HeaderCache = {\n lastRenderedHTML: undefined,\n html: undefined,\n fileDiff: undefined,\n };\n protected lastRowCount: number | undefined;\n private mounted = false;\n\n protected enabled = true;\n\n protected editor: Editor<'file-diff', LAnnotation, Caret> | undefined;\n protected refreshViewTimeout: ReturnType<typeof setTimeout> | undefined;\n // Defer selected-line and editor active-line writes while a refresh rebuilds\n // the diff rows. This is separate from the timeout because the refresh can\n // escalate to a full rerender without one.\n protected lineStateRefreshPending = false;\n protected deferredSelectedLines: DeferredSelectedLinesWrite | undefined;\n protected deferredEditorActiveLine: DeferredEditorActiveLineWrite | undefined;\n\n constructor(\n public options: FileDiffOptions<LAnnotation, Caret> = {\n theme: DEFAULT_THEMES,\n },\n protected workerManager?: WorkerPoolManager | undefined,\n protected isContainerManaged = false\n ) {\n this.hunksRenderer = this.createHunksRenderer(options);\n this.resizeManager = new ResizeManager();\n this.scrollSyncManager = new ScrollSyncManager();\n this.interactionManager = new InteractionManager(\n 'diff',\n pluckInteractionOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info' ||\n options.hunkSeparators === 'line-info-basic'\n ? this.handleExpandHunk\n : undefined,\n this.getLineIndex\n )\n );\n this.workerManager?.subscribeToThemeChanges(this);\n this.enabled = true;\n }\n\n protected handleHighlightRender = (): void => {\n this.rerender();\n };\n\n private getTheme() {\n return (\n this.workerManager?.getDiffRenderOptions().theme ??\n this.options.theme ??\n DEFAULT_THEMES\n );\n }\n\n protected getHunksRendererOptions(\n options: FileDiffOptions<LAnnotation, Caret>\n ): DiffHunksRendererOptions {\n return getDiffHunksRendererOptions(options);\n }\n\n protected createHunksRenderer(\n options: FileDiffOptions<LAnnotation, Caret>\n ): DiffHunksRenderer<LAnnotation> {\n return new DiffHunksRenderer<LAnnotation>(\n this.getHunksRendererOptions(options),\n this.getAnnotationSlotName,\n this.handleHighlightRender,\n this.workerManager\n );\n }\n\n public getLineIndex: GetLineIndexUtility = (\n lineNumber: number,\n side: SelectionSide = 'additions'\n ) => {\n return this.getLineIndexForDiff(\n this.getDiffForLineIndex(),\n lineNumber,\n side\n );\n };\n\n protected getDiffForLineIndex(): FileDiffMetadata | undefined {\n return this.getRenderedDiff();\n }\n\n // Resolve source lines against the same diff that produced the rendered\n // rows. During an asynchronous replacement, that can be the previous diff.\n protected getLineIndexForDiff(\n fileDiff: FileDiffMetadata | undefined,\n lineNumber: number,\n side: SelectionSide\n ): [number, number] | undefined {\n if (fileDiff == null) {\n return undefined;\n }\n const lastHunk = fileDiff.hunks.at(-1);\n let targetUnifiedIndex: number | undefined;\n let targetSplitIndex: number | undefined;\n hunkIterator: for (const hunk of fileDiff.hunks) {\n const hunkStart =\n side === 'deletions' ? hunk.deletionStart : hunk.additionStart;\n const hunkCount =\n side === 'deletions' ? hunk.deletionCount : hunk.additionCount;\n let currentLineNumber =\n getHunkSideStartBoundary(hunkStart, hunkCount) + 1;\n let splitIndex = hunk.splitLineStart;\n let unifiedIndex = hunk.unifiedLineStart;\n\n // If we've selected a line between or before a hunk,\n // we should grab its index here\n if (lineNumber < currentLineNumber) {\n const difference = currentLineNumber - lineNumber;\n targetUnifiedIndex = Math.max(unifiedIndex - difference, 0);\n targetSplitIndex = Math.max(splitIndex - difference, 0);\n break hunkIterator;\n }\n\n if (lineNumber >= currentLineNumber + hunkCount) {\n if (hunk === lastHunk) {\n const difference = lineNumber - (currentLineNumber + hunkCount);\n targetUnifiedIndex =\n unifiedIndex + hunk.unifiedLineCount + difference;\n targetSplitIndex = splitIndex + hunk.splitLineCount + difference;\n break hunkIterator;\n }\n continue;\n }\n\n for (const content of hunk.hunkContent) {\n if (content.type === 'context') {\n if (lineNumber < currentLineNumber + content.lines) {\n const difference = lineNumber - currentLineNumber;\n targetSplitIndex = splitIndex + difference;\n targetUnifiedIndex = unifiedIndex + difference;\n break hunkIterator;\n } else {\n currentLineNumber += content.lines;\n splitIndex += content.lines;\n unifiedIndex += content.lines;\n }\n } else {\n const sideCount =\n side === 'deletions' ? content.deletions : content.additions;\n if (lineNumber < currentLineNumber + sideCount) {\n const indexDifference = lineNumber - currentLineNumber;\n targetUnifiedIndex =\n unifiedIndex +\n (side === 'additions' ? content.deletions : 0) +\n indexDifference;\n targetSplitIndex = splitIndex + indexDifference;\n\n break hunkIterator;\n } else {\n currentLineNumber += sideCount;\n splitIndex += Math.max(content.deletions, content.additions);\n unifiedIndex += content.deletions + content.additions;\n }\n }\n }\n\n break hunkIterator;\n }\n\n if (targetUnifiedIndex == null || targetSplitIndex == null) {\n return undefined;\n }\n return [targetUnifiedIndex, targetSplitIndex];\n }\n\n // FIXME(amadeus): This is a bit of a looming issue that I'll need to resolve:\n // * Do we publicly allow merging of options or do we have individualized setters?\n // * When setting new options, we need to figure out what settings require a\n // re-render and which can just be applied more elegantly\n // * There's also an issue of options that live here on the File class and\n // those that live on the Hunk class, and it's a bit of an issue with passing\n // settings down and mirroring them (not great...)\n public setOptions(\n options: FileDiffOptions<LAnnotation, Caret> | undefined\n ): void {\n if (options == null) return;\n this.options = options;\n this.clearReusableHeader();\n this.hunksRenderer.setOptions(this.getHunksRendererOptions(options));\n this.syncInteractionOptions();\n }\n\n protected syncInteractionOptions(): void {\n this.interactionManager.setOptions(\n pluckInteractionOptions(\n this.options,\n typeof this.options.hunkSeparators === 'function' ||\n (this.options.hunkSeparators ?? 'line-info') === 'line-info' ||\n this.options.hunkSeparators === 'line-info-basic'\n ? this.handleExpandHunk\n : undefined,\n this.getLineIndex\n )\n );\n }\n\n private mergeOptions(\n options: Partial<FileDiffOptions<LAnnotation, Caret>>\n ): void {\n this.options = { ...this.options, ...options };\n }\n\n public setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.applyCachedThemeState(themeType);\n }\n\n private applyCachedThemeState(themeType: ThemeTypes): boolean {\n if (\n typeof this.options.theme === 'string' ||\n this.fileContainer == null ||\n this.appliedThemeCSS == null\n ) {\n return false;\n }\n const effectiveThemeType = this.appliedThemeCSS.baseThemeType ?? themeType;\n if (this.appliedThemeCSS.themeType === effectiveThemeType) {\n return false;\n }\n this.applyThemeState(\n this.fileContainer,\n this.appliedThemeCSS.themeStyles,\n themeType,\n this.appliedThemeCSS.baseThemeType\n );\n return true;\n }\n\n private hasThemeChanged(): boolean {\n return (\n this.appliedThemeCSS != null &&\n !areThemesEqual(this.appliedThemeCSS.theme, this.getTheme())\n );\n }\n\n public getHoveredLine = (): GetHoveredLineResult<'diff'> | undefined => {\n return this.interactionManager.getHoveredLine();\n };\n\n public getAnnotationSlotName = (\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>\n ): string => {\n return resolveEditSessionSlotName(\n this.editSession?.annotations,\n annotation,\n getLineAnnotationName\n );\n };\n\n // Return the annotations this component currently renders. Once editing\n // starts, the private session state owns them.\n protected getLatestAnnotations(): DiffLineAnnotation<LAnnotation>[] {\n return this.editSession?.annotations?.current ?? this.lineAnnotations;\n }\n\n // Returns true when the caller passed annotations this component has not\n // handled yet. Re-renders often re-pass an annotations array the component\n // already holds — the external one, or one the active session tracks — and\n // treating those repeats as new writes would move annotations, so they are\n // recognized by identity and ignored.\n protected isNewAnnotations(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n const session = this.editSession?.annotations;\n const externalAnnotations = this.lineAnnotations;\n if (lineAnnotations === externalAnnotations) {\n return false;\n }\n return (\n session == null ||\n (lineAnnotations !== session.provided &&\n lineAnnotations !== session.current)\n );\n }\n\n public setLineAnnotations(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): void {\n const sessionAnnotations = this.editSession?.annotations;\n if (sessionAnnotations == null) {\n this.lineAnnotations = lineAnnotations;\n return;\n }\n if (!this.isNewAnnotations(lineAnnotations)) {\n return;\n }\n // Externally provided annotations are the source of truth: they become the\n // new external collection and the session renders them at the line numbers\n // given. The caller owns whether those positions still make sense after an\n // edit; a revert renders this collection unchanged rather than moving them.\n this.lineAnnotations = lineAnnotations;\n writeEditSessionAnnotations(\n sessionAnnotations,\n lineAnnotations,\n getLineAnnotationName\n );\n }\n\n // Takes annotations the editor remapped and makes them what the session\n // renders: updates the session, feeds the renderer, and re-renders\n // annotation rows. Returns true when new annotations were adopted —\n // virtualized subclasses override this and refresh their layout on true.\n //\n // The editor delivers annotations through two calls. An edit that changes\n // the line count sends them with the structural rebuild\n // (applyDocumentChange) and again with the change event (__acceptEditorChange);\n // the identity check makes the second call a no-op. An edit that keeps the\n // line count skips the rebuild, so the event is its only path here.\n //\n // The annotations the caller passed in are never touched — stale\n // re-renders keep deduping against them.\n protected syncEditSessionAnnotationsFromEditor(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n const session = this.editSession?.annotations;\n if (session == null || lineAnnotations === session.current) {\n return false;\n }\n session.current = lineAnnotations;\n this.hunksRenderer.setLineAnnotations(lineAnnotations);\n this.renderAnnotations();\n return true;\n }\n\n private canPartiallyRender(\n forceRender: boolean,\n annotationsChanged: boolean,\n didContentChange: boolean\n ): boolean {\n if (\n forceRender ||\n annotationsChanged ||\n didContentChange ||\n typeof this.options.hunkSeparators === 'function'\n ) {\n return false;\n }\n return true;\n }\n\n public setSelectedLines(\n range: SelectedLineRange | null,\n options?: SelectionWriteOptions\n ): void {\n if (this.lineStateRefreshPending) {\n this.deferredSelectedLines = [range, options];\n } else {\n this.interactionManager.setSelection(range, options);\n }\n }\n\n public setEditorActiveLine(\n lineNumber: number | null,\n options?: EditorActiveLineOptions\n ): void {\n if (this.lineStateRefreshPending) {\n this.deferredEditorActiveLine = [lineNumber, options];\n } else {\n this.interactionManager.setEditorActiveLine(lineNumber, {\n lineNumberOnly: options?.lineNumberOnly,\n side: options?.side ?? 'additions',\n });\n }\n }\n\n // A refresh can receive selected-lines and editor active-line writes in either\n // order. Apply the latest value from each after the rows are stable.\n protected flushDeferredLineState(): void {\n const {\n deferredEditorActiveLine: editorActiveLine,\n deferredSelectedLines: selectedLines,\n } = this;\n this.lineStateRefreshPending = false;\n this.deferredEditorActiveLine = undefined;\n this.deferredSelectedLines = undefined;\n\n if (editorActiveLine != null) {\n this.setEditorActiveLine(...editorActiveLine);\n }\n if (selectedLines != null) {\n this.interactionManager.setSelection(...selectedLines);\n }\n }\n\n public flushManagers(): void {\n if (!this.managersDirty || this.pre == null) {\n this.managersDirty = false;\n return;\n }\n\n const { diffStyle = 'split', overflow = 'scroll' } = this.options;\n this.interactionManager.setup(this.pre);\n this.resizeManager.setup(this.pre, {\n disableAnnotations: overflow === 'wrap',\n columnVariables: this.shouldApplyColumnVariables(overflow)\n ? 'apply'\n : 'measure',\n });\n if (overflow === 'scroll' && diffStyle === 'split') {\n this.scrollSyncManager.setup(\n this.pre,\n this.codeDeletions,\n this.codeAdditions\n );\n } else {\n this.scrollSyncManager.cleanUp();\n }\n this.managersDirty = false;\n }\n\n protected shouldApplyColumnVariables(overflow: 'scroll' | 'wrap'): boolean {\n if (typeof this.options.hunkSeparators === 'function') {\n return true;\n }\n return (\n overflow === 'scroll' &&\n (this.getLatestAnnotations().length > 0 ||\n this.pre?.hasAttribute('data-has-merge-conflict') === true)\n );\n }\n\n public getCodeScrollLeft(): number {\n return Math.max(\n this.codeUnified?.scrollLeft ?? 0,\n this.codeDeletions?.scrollLeft ?? 0,\n this.codeAdditions?.scrollLeft ?? 0\n );\n }\n\n public setCodeScrollLeft(position: number): void {\n if (this.codeUnified != null) {\n this.codeUnified.scrollLeft = position;\n }\n if (this.codeAdditions != null) {\n this.codeAdditions.scrollLeft = position;\n }\n if (this.codeDeletions != null) {\n this.codeDeletions.scrollLeft = position;\n }\n }\n\n public __getEffectiveCodeOptions(): BaseCodeOptions {\n return { ...this.options, ...this.hunksRenderer.getEffectiveCodeOptions() };\n }\n\n public cleanUp(recycle: boolean = false): void {\n const { editor } = this;\n dequeueRender(this.handleEditSessionRender);\n this.emitPostRender(true);\n // Tear the editor down while the code scrollers still exist. A recycle\n // keeps its document and undo history; a full teardown drops them as the\n // session ends.\n editor?.cleanUp(recycle ? 'recycle' : 'discard');\n if (!recycle) {\n this.editor = undefined;\n }\n this.resizeManager.cleanUp();\n this.interactionManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.managersDirty = false;\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.renderRange = undefined;\n if (!recycle) {\n this.pendingFiles = undefined;\n }\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.remove();\n }\n this.fileContainer = undefined;\n this.mounted = false;\n if (!recycle) {\n this.lineAnnotations = [];\n }\n this.clearAuxiliaryNodes();\n this.annotationCache.clear();\n this.pre = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n this.bufferBefore?.remove();\n this.bufferBefore = undefined;\n this.bufferAfter?.remove();\n this.bufferAfter = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n this.headerCache.lastRenderedHTML = undefined;\n if (!recycle) {\n this.clearReusableHeader();\n }\n this.errorWrapper?.remove();\n this.errorWrapper = undefined;\n this.spriteSVG = undefined;\n this.lastRowCount = undefined;\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n this.hasAdoptedThemeCSS = false;\n this.unsafeCSSStyle = undefined;\n this.appliedUnsafeCSS = undefined;\n\n if (recycle) {\n this.hunksRenderer.recycle();\n } else {\n this.hunksRenderer.cleanUp();\n this.workerManager = undefined;\n // Clean up the data\n this.fileDiff = undefined;\n this.editSession = undefined;\n this.renderedDiff = undefined;\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n this.refreshViewTimeout = undefined;\n }\n this.lineStateRefreshPending = false;\n this.deferredEditorActiveLine = undefined;\n this.deferredSelectedLines = undefined;\n this.enabled = false;\n }\n\n public virtualizedSetup(): void {\n this.enabled = true;\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n public hydrate({\n fileContainer,\n prerenderedHTML,\n preventEmit = false,\n lineAnnotations,\n fileDiff,\n ...fileInputProps\n }: FileDiffHydrationProps<LAnnotation>): void {\n if (!this.enabled) {\n throw new Error(\n 'FileDiff.hydrate: attempting to call hydrate after cleaned up'\n );\n }\n if (this.fileContainer != null) {\n throw new Error(\n 'FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated'\n );\n }\n const fileInput = getDiffFileInput(fileInputProps, 'FileDiff.hydrate');\n const oldFile = fileInput?.oldFile;\n const newFile = fileInput?.newFile;\n this.hydrateElements(fileContainer, prerenderedHTML);\n // An editor attached before hydration may carry a retained keyed document\n // and its session-shaped hunks. Render through that private session instead\n // of adopting external markup, so hydration cannot recompute or flash it.\n const forceEditorRender = this.editor != null;\n if (\n forceEditorRender ||\n shouldRenderCode(\n this.pre,\n hasDiffContent({ fileDiff, oldFile, newFile }),\n this.options.collapsed\n ) ||\n shouldRenderHeader(\n this.headerElement,\n hasDiffHeaderContent({ fileDiff, oldFile, newFile }),\n this.options.disableFileHeader\n )\n ) {\n this.render({\n ...fileInputProps,\n fileContainer,\n lineAnnotations,\n fileDiff,\n forceRender: forceEditorRender || fileInputProps.forceRender,\n preventEmit: true,\n });\n }\n // Otherwise orchestrate our setup\n else {\n this.hydrationSetup({\n fileDiff,\n lineAnnotations,\n ...fileInput,\n });\n }\n if (!preventEmit) {\n this.emitPostRender();\n }\n }\n\n protected hydrateElements(\n fileContainer: HTMLElement,\n prerenderedHTML: string | undefined\n ): void {\n if (this.fileContainer !== fileContainer) {\n this.emitPostRender(true);\n }\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of fileContainer.shadowRoot?.children ?? []) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n for (const code of element.children) {\n if (\n !(code instanceof HTMLElement) ||\n code.tagName.toLowerCase() !== 'code'\n ) {\n continue;\n }\n if ('deletions' in code.dataset) {\n this.codeDeletions = code;\n }\n if ('additions' in code.dataset) {\n this.codeAdditions = code;\n }\n if ('unified' in code.dataset) {\n this.codeUnified = code;\n }\n }\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(THEME_CSS_ATTRIBUTE)\n ) {\n this.themeCSSStyle = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n this.appliedUnsafeCSS = element.textContent;\n continue;\n }\n }\n if (this.pre != null) {\n this.syncCodeNodesFromPre(this.pre);\n this.pre.removeAttribute('data-dehydrated');\n }\n this.fileContainer = fileContainer;\n this.hydrateMeasuredScrollbar();\n }\n\n protected hydrationSetup({\n fileDiff,\n oldFile,\n newFile,\n lineAnnotations,\n }: HydrationSetup<LAnnotation>): void {\n // It's possible we are hydrating a pure-rename and therefore there will be\n // no pre element\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.additionFile = newFile;\n this.deletionFile = oldFile;\n this.fileDiff =\n fileDiff ??\n (oldFile !== undefined && newFile !== undefined\n ? parseDiffFromFile(oldFile, newFile, this.options.parseDiffOptions)\n : undefined);\n\n if (this.pre == null) {\n return;\n }\n\n this.syncInteractionOptions();\n this.hunksRenderer.hydrate(this.fileDiff);\n this.renderedDiff = this.fileDiff;\n // FIXME(amadeus): not sure how to handle this yet...\n // this.renderSeparators();\n this.renderAnnotations();\n this.renderGutterUtility();\n this.injectUnsafeCSS();\n this.managersDirty = true;\n this.flushManagers();\n }\n\n public rerender(): void {\n if (\n !this.enabled ||\n (this.fileDiff == null &&\n this.additionFile == null &&\n this.deletionFile == null)\n ) {\n return;\n }\n this.render({ forceRender: true, renderRange: this.renderRange });\n }\n\n public onThemeChange(): void {\n this.hunksRenderer.clearRenderCache();\n this.rerender();\n }\n\n // This wrapper must stay separate from `expandHunk` because subclasses like\n // `VirtualizedFileDiff` replace `expandHunk` with their own instance field\n // after `super()` returns. `InteractionManager` is created in this base\n // constructor, so it needs a stable callback that resolves `this.expandHunk`\n // at click time instead of capturing the base implementation too early.\n public handleExpandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections,\n expansionLineCountOverride?: number\n ): void => {\n this.expandHunk(hunkIndex, direction, expansionLineCountOverride);\n };\n\n public expandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections,\n expansionLineCountOverride?: number\n ): void => {\n this.hunksRenderer.expandHunk(\n hunkIndex,\n direction,\n expansionLineCountOverride\n );\n this.loadFilesIfNecessary();\n this.rerender();\n };\n\n protected loadFilesIfNecessary(): void {\n const {\n fileDiff,\n options: { loadDiffFiles },\n } = this;\n if (\n fileDiff == null ||\n loadDiffFiles == null ||\n !canHydrateDiff(fileDiff) ||\n this.pendingFiles?.fileDiff === fileDiff\n ) {\n return;\n }\n\n const promise = this.loadFilesForDiff(fileDiff, loadDiffFiles);\n const pendingFiles: PendingFileLoad = (this.pendingFiles = {\n fileDiff,\n promise,\n });\n // Track the exact request object so an older completion for the same diff\n // cannot clear a newer request.\n const clearPendingFiles = (): void => {\n if (this.pendingFiles === pendingFiles) {\n this.pendingFiles = undefined;\n }\n };\n pendingFiles.promise = promise.finally(clearPendingFiles);\n }\n\n private async loadFilesForDiff(\n fileDiff: FileDiffMetadata,\n loadDiffFiles: NonNullable<BaseDiffOptions['loadDiffFiles']>\n ): Promise<void> {\n try {\n const files = await loadDiffFiles(fileDiff);\n if (!this.enabled || this.fileDiff !== fileDiff) {\n return;\n }\n\n await this.handleFilesLoaded(fileDiff, files);\n } catch (error: unknown) {\n if (this.options.disableErrorHandling === true) {\n throw error;\n }\n console.error(error);\n }\n }\n\n protected async handleFilesLoaded(\n expectedDiff: FileDiffMetadata,\n files: LoadedPartialDiffContents\n ): Promise<void> {\n if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) {\n return;\n }\n hydratePartialDiff('merge', expectedDiff, files);\n this.setHydratedState(files);\n if (this.startHydratedEditSession(expectedDiff)) {\n this.rerender();\n return;\n }\n await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));\n if (!this.enabled || this.fileDiff !== expectedDiff) {\n return;\n }\n this.rerender();\n }\n\n // Start editing from an already hydrated `this.fileDiff`. The keyless\n // shallow copy shares nested data until an edit needs to change it.\n protected startHydratedEditSession(expectedDiff: FileDiffMetadata): boolean {\n if (expectedDiff.isPartial) {\n throw new Error(\n 'FileDiff.startHydratedEditSession: diffs cannot be partial for editing'\n );\n }\n if (this.fileDiff !== expectedDiff) {\n return false;\n }\n const { editor } = this;\n if (this.editSession?.outgoingDiff != null) {\n this.installEditSession(expectedDiff);\n return true;\n }\n if (editor == null || this.editSession != null) {\n return false;\n }\n this.installEditSession(\n expectedDiff,\n editor.__getDocumentContents(getAdditionFile(expectedDiff)),\n editor.__getDocumentSessionState()\n );\n return true;\n }\n\n // Install a replacement diff from the caller; returns false when it is the\n // diff already installed. During an edit session the diff the editor's\n // document still holds is kept as `outgoingDiff` until the editor syncs, so\n // it can decide whether the swap keeps or resets undo history.\n protected updateExternalDiff(\n incomingExternalDiff: FileDiffMetadata,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n if (areDiffTargetsEqual(this.fileDiff, incomingExternalDiff)) {\n return false;\n }\n\n const outgoingDiff =\n this.editSession?.outgoingDiff ?? this.editSession?.diff;\n\n this.fileDiff = incomingExternalDiff;\n if (outgoingDiff != null) {\n if (incomingExternalDiff.isPartial) {\n this.loadFilesIfNecessary();\n } else {\n this.installEditSession(incomingExternalDiff);\n }\n if (this.editSession != null) {\n this.editSession.outgoingDiff = outgoingDiff;\n }\n } else if (this.editor != null) {\n if (incomingExternalDiff.isPartial) {\n this.loadFilesIfNecessary();\n } else {\n this.installEditSession(\n incomingExternalDiff,\n this.editor.__getDocumentContents(\n getAdditionFile(incomingExternalDiff)\n ),\n this.editor.__getDocumentSessionState()\n );\n }\n }\n if (this.editSession?.annotations != null && lineAnnotations != null) {\n // These annotations arrived with the new diff, so their line numbers\n // describe it. The positions the session tracked for the old document\n // mean nothing now: the session restarts from these annotations, and\n // they also become what renders once the session ends.\n this.lineAnnotations = lineAnnotations;\n this.editSession.annotations = adoptEditSessionAnnotations(\n lineAnnotations,\n getLineAnnotationName,\n this.editSession.annotations\n );\n }\n return true;\n }\n\n // When an editor opens a document saved under a document key,\n // `retainedDocument` restores its text and undo history. It is omitted when\n // replacing the diff in an open editor so the replacement is handled as a\n // new external update instead of overwriting the document being edited.\n private installEditSession(\n externalDiff: FileDiffMetadata,\n retainedDocument?: FileContents,\n retainedSession?: RetainedDiffSessionSnapshot\n ): void {\n const externalContents = externalDiff.additionLines.join('');\n const retainedLines =\n retainedDocument != null\n ? splitFileContents(retainedDocument.contents)\n : undefined;\n const restoreRetainedSession =\n retainedSession != null &&\n canRestoreDiffSession(retainedSession, externalDiff);\n if (retainedSession != null && !restoreRetainedSession) {\n throw new Error(\n 'FileDiff: retained session cannot resume against a different old file'\n );\n }\n if (\n retainedDocument != null &&\n retainedDocument.contents !== externalContents &&\n !restoreRetainedSession\n ) {\n throw new Error(\n 'FileDiff: retained edits are missing their diff session state'\n );\n }\n const usesExternalDocument =\n retainedDocument == null ||\n (retainedDocument.name === externalDiff.name &&\n retainedDocument.lang === externalDiff.lang &&\n retainedDocument.contents === externalContents);\n const sessionDiff = createEditSessionDiff(externalDiff);\n if (\n retainedDocument != null &&\n retainedLines != null &&\n !usesExternalDocument\n ) {\n sessionDiff.name = retainedDocument.name;\n sessionDiff.lang = retainedDocument.lang;\n }\n if (\n restoreRetainedSession &&\n retainedSession != null &&\n retainedLines != null\n ) {\n sessionDiff.additionLines = retainedLines;\n sessionDiff.type = retainedSession.type;\n sessionDiff.hunks = retainedSession.hunks;\n sessionDiff.editSessionDirty = true;\n recomputeDiffRenderLineCounts(sessionDiff);\n }\n this.editSession = {\n diff: sessionDiff,\n // Seed annotations when the session is created so the adopt-block in\n // updateExternalDiff fires on the next external update — this is what an\n // attach-before-hydrate (React) mount relies on, since the session does\n // not exist yet at attach. A live session keeps the ones it tracks.\n annotations:\n this.editSession?.annotations ??\n adoptEditSessionAnnotations(\n this.lineAnnotations,\n getLineAnnotationName\n ),\n outgoingDiff: this.editSession?.outgoingDiff,\n };\n this.hunksRenderer.beginEditSession(\n sessionDiff,\n usesExternalDocument && !restoreRetainedSession ? externalDiff : undefined\n );\n }\n\n protected setHydratedState(files: LoadedPartialDiffContents): void {\n this.deletionFile = files.oldFile;\n this.additionFile = files.newFile;\n this.workerManager?.cleanUpTasks(this.hunksRenderer);\n this.hunksRenderer.clearRenderCache();\n }\n\n public render({\n fileDiff,\n deferManagers = false,\n forceRender = false,\n preventEmit = false,\n lineAnnotations,\n fileContainer,\n containerWrapper,\n renderRange,\n ...fileInputProps\n }: FileDiffRenderProps<LAnnotation>): boolean {\n if (!this.enabled) {\n // NOTE(amadeus): May need to be a silent failure? Making it loud for now\n // to better understand it\n throw new Error(\n 'FileDiff.render: attempting to call render after cleaned up'\n );\n }\n\n const fileInput = getDiffFileInput(fileInputProps, 'FileDiff.render');\n const oldFile = fileInput?.oldFile;\n const newFile = fileInput?.newFile;\n\n // postpone background tokenizing to next frame for avoiding UI freeze\n // during render\n this.editor?.__postponeBgTokenizeToNextFrame();\n\n const {\n collapsed = false,\n themeType = 'system',\n expandUnchanged = false,\n } = this.options;\n const nextRenderRange = collapsed ? undefined : renderRange;\n const themeChanged = this.hasThemeChanged();\n const hasFileInput = fileInput != null;\n const filesDidChange =\n hasFileInput &&\n (!areOptionalFilesEqual(oldFile, this.deletionFile) ||\n !areOptionalFilesEqual(newFile, this.additionFile));\n let diffDidChange =\n fileDiff != null && !areDiffTargetsEqual(fileDiff, this.fileDiff);\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.getLatestAnnotations().length > 0)\n ? this.isNewAnnotations(lineAnnotations)\n : false;\n\n if (\n !collapsed &&\n areRenderRangesEqual(nextRenderRange, this.renderRange) &&\n !forceRender &&\n !annotationsChanged &&\n !themeChanged &&\n // If using the fileDiff API, lets check to see if they are equal to\n // avoid doing work\n ((fileDiff != null && !diffDidChange) ||\n // If using the oldFile/newFile API then lets check to see if they are\n // equal\n (fileDiff == null && !filesDidChange))\n ) {\n const rendered = this.applyCachedThemeState(themeType);\n if (rendered) {\n this.finalizeRender();\n }\n return rendered;\n }\n\n let nextParsedFileDiff: FileDiffMetadata | undefined;\n if (\n fileDiff == null &&\n hasFileInput &&\n (filesDidChange || this.fileDiff == null)\n ) {\n nextParsedFileDiff = parseDiffFromFile(\n fileInput.oldFile,\n fileInput.newFile,\n this.options.parseDiffOptions\n );\n }\n\n const { renderRange: previousRenderRange } = this;\n this.renderRange = nextRenderRange;\n // Store files only when this render actually carried a file input:\n // internal rerenders pass none, and wiping the pair here would defeat the\n // oldFile/newFile early-return on every later host render. An explicit\n // fileDiff input supersedes a previously parsed pair, so clear it then.\n if (hasFileInput) {\n this.deletionFile = oldFile;\n this.additionFile = newFile;\n } else if (fileDiff != null) {\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n\n if (fileDiff != null && diffDidChange) {\n this.updateExternalDiff(fileDiff, lineAnnotations);\n } else if (nextParsedFileDiff != null) {\n diffDidChange = true;\n this.updateExternalDiff(nextParsedFileDiff, lineAnnotations);\n }\n if (diffDidChange) {\n this.clearReusableHeader();\n }\n\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n\n const latestDiff = this.getLatestDiff();\n if (latestDiff == null) {\n return false;\n }\n // Backstop for sessions that ended without their exit hook running (e.g.\n // session-shaped metadata reused after a host teardown): restore\n // recompute-shaped hunks before rendering.\n if (\n latestDiff.editSessionDirty === true &&\n this.shouldSelfHealEditSession()\n ) {\n finishEditSessionForDiff(latestDiff, this.options.parseDiffOptions);\n void this.hunksRenderer.refreshHighlightedResult();\n }\n if (expandUnchanged) {\n this.loadFilesIfNecessary();\n }\n this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));\n this.syncInteractionOptions();\n\n this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());\n\n const { disableErrorHandling = false, disableFileHeader = false } =\n this.options;\n\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.remove();\n this.headerElement = undefined;\n this.headerCache.lastRenderedHTML = undefined;\n }\n this.clearHeaderSlots();\n }\n fileContainer = this.getOrCreateFileContainer(\n fileContainer,\n containerWrapper\n );\n this.applyCachedThemeState(themeType);\n\n if (collapsed) {\n this.removeRenderedCode();\n this.clearAuxiliaryNodes();\n\n try {\n const hunksResult = this.hunksRenderer.renderDiff(\n latestDiff,\n EMPTY_RENDER_RANGE\n );\n if (hunksResult != null) {\n this.applyThemeState(\n fileContainer,\n hunksResult.themeStyles,\n themeType,\n hunksResult.baseThemeType\n );\n }\n if (hunksResult?.headerElement != null) {\n this.applyHeaderToDOM(\n hunksResult.headerElement,\n fileContainer,\n hunksResult.fileDiff\n );\n }\n this.renderSeparators([]);\n this.renderedDiff = hunksResult?.fileDiff ?? latestDiff;\n this.injectUnsafeCSS();\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n this.finalizeRender();\n if (!preventEmit) {\n this.emitPostRender();\n }\n return true;\n }\n\n try {\n const pre = this.getOrCreatePreNode(fileContainer);\n\n // Attempt to partially render\n const didPartiallyRender =\n this.canPartiallyRender(\n forceRender,\n annotationsChanged,\n filesDidChange ||\n diffDidChange ||\n themeChanged ||\n !areDiffTargetsEqual(this.renderedDiff, latestDiff)\n ) &&\n this.applyPartialRender({\n fileDiff: latestDiff,\n previousRenderRange,\n renderRange: nextRenderRange,\n });\n\n // If we were unable to partially render, perform a full render\n if (!didPartiallyRender) {\n const hunksResult = this.hunksRenderer.renderDiff(\n latestDiff,\n nextRenderRange\n );\n if (hunksResult == null) {\n if (\n this.workerManager?.isInitialized() === false &&\n this.workerManager.isWorkingPool()\n ) {\n void this.workerManager\n .initialize()\n .catch(() => {})\n .then(() => this.rerender());\n }\n return false;\n }\n\n this.applyThemeState(\n fileContainer,\n hunksResult.themeStyles,\n themeType,\n hunksResult.baseThemeType\n );\n\n if (hunksResult.headerElement != null) {\n this.applyHeaderToDOM(\n hunksResult.headerElement,\n fileContainer,\n hunksResult.fileDiff\n );\n }\n if (\n hunksResult.additionsContentAST != null ||\n hunksResult.deletionsContentAST != null ||\n hunksResult.unifiedContentAST != null\n ) {\n this.applyHunksToDOM(pre, hunksResult);\n } else if (this.pre != null) {\n this.pre.remove();\n this.pre = undefined;\n }\n this.renderSeparators(hunksResult.hunkData);\n this.renderedDiff = hunksResult.fileDiff;\n }\n this.applyBuffers(pre, nextRenderRange);\n this.injectUnsafeCSS();\n this.renderAnnotations();\n this.renderGutterUtility();\n\n this.managersDirty = true;\n if (!deferManagers) {\n this.flushManagers();\n }\n\n this.finalizeRender();\n if (this.editor != null) {\n this.syncRenderViewToEditor();\n }\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n if (!preventEmit) {\n this.emitPostRender();\n }\n return true;\n }\n\n protected finalizeRender(): void {}\n\n protected emitPostRender(unmount = false): void {\n const {\n fileContainer,\n options: { onPostRender },\n } = this;\n\n if (unmount) {\n if (!this.mounted) {\n return;\n }\n this.mounted = false;\n if (fileContainer == null) {\n return;\n }\n this.options.onPostRender?.(fileContainer, this, 'unmount');\n return;\n }\n\n if (fileContainer == null) {\n return;\n }\n\n const phase: PostRenderPhase = this.mounted ? 'update' : 'mount';\n this.mounted = true;\n onPostRender?.(fileContainer, this, phase);\n }\n\n // Return the newest diff this component intends to display. An active edit\n // session owns that state instead of the caller-provided diff.\n protected getLatestDiff(\n fileDiff: FileDiffMetadata | undefined = this.fileDiff\n ): FileDiffMetadata | undefined {\n return this.editSession?.diff ?? fileDiff;\n }\n\n // Return the diff that produced the DOM currently owned by this instance.\n // It can trail getLatestDiff while replacement highlighting is pending.\n protected getRenderedDiff(): FileDiffMetadata | undefined {\n return this.renderedDiff;\n }\n\n private syncRenderViewToEditor(): void {\n const { editor, fileContainer } = this;\n const lineAnnotations = this.getLatestAnnotations();\n const renderRange = this.computeEditorRenderRange(this.renderRange);\n const fileDiff = this.getLatestDiff();\n if (\n editor == null ||\n fileContainer == null ||\n fileDiff == null ||\n fileDiff.isPartial\n ) {\n return;\n }\n const sync = (highlighter: DiffsHighlighter): void => {\n if (\n !this.enabled ||\n this.editor !== editor ||\n this.fileContainer !== fileContainer ||\n this.getLatestDiff() !== fileDiff\n ) {\n return;\n }\n const replacement = this.editSession?.outgoingDiff;\n const externalDiff = this.fileDiff;\n const externalDocument =\n replacement != null && externalDiff != null && replacement !== fileDiff;\n const resetHistory = externalDocument\n ? shouldResetUndoState(replacement, externalDiff)\n : false;\n editor.__syncRenderView({\n highlighter,\n fileContainer,\n fileDiff,\n lineAnnotations,\n renderRange,\n externalDocument,\n resetHistory,\n });\n };\n const theme = this.getTheme();\n const lang = fileDiff.lang ?? getFiletypeFromFileName(fileDiff.name);\n // Sync synchronously whenever the shared highlighter is ready; otherwise\n // load it and sync once it resolves.\n const highlighter = getHighlighterIfLoaded({ theme, lang });\n if (highlighter != null) {\n sync(highlighter);\n } else {\n void getSharedHighlighter({\n themes: getThemes(theme),\n langs: ['text', lang],\n preferredHighlighter:\n this.workerManager?.getPreferredHighlighter() ??\n this.options.preferredHighlighter,\n }).then(sync);\n }\n }\n\n // The stored render range is in rendered-row units for the windowed AST\n // pipeline, but the editor consumes render ranges in document-line units.\n // Derive the addition-side document window covered by the rendered rows:\n // startingLine = first addition line with a row in the window, totalLines =\n // last such line - first + 1, and 0 when the window holds no addition rows\n // (e.g. a pure-deletion run taller than the viewport).\n private computeEditorRenderRange(\n renderRange: RenderRange | undefined\n ): RenderRange | undefined {\n const fileDiff = this.getLatestDiff();\n if (\n renderRange == null ||\n fileDiff == null ||\n isDefaultRenderRange(renderRange)\n ) {\n return renderRange;\n }\n const {\n diffStyle = 'split',\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n let firstLineNumber: number | undefined;\n let lastLineNumber: number | undefined;\n iterateOverDiff({\n diff: fileDiff,\n diffStyle,\n startingLine: renderRange.startingLine,\n totalLines: renderRange.totalLines,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n callback: ({ additionLine }) => {\n if (additionLine != null) {\n firstLineNumber ??= additionLine.lineNumber;\n lastLineNumber = additionLine.lineNumber;\n }\n },\n });\n if (firstLineNumber == null || lastLineNumber == null) {\n return { ...renderRange, startingLine: 0, totalLines: 0 };\n }\n return {\n ...renderRange,\n startingLine: firstLineNumber - 1,\n totalLines: lastLineNumber - firstLineNumber + 1,\n };\n }\n\n /** @internal The editor applied or edited past the pending external replacement. */\n public __acknowledgeDocumentUpdate(): void {\n if (this.editSession != null) {\n this.editSession.outgoingDiff = undefined;\n }\n }\n\n /** @internal Settle annotations locally. */\n public __acceptEditorChange(\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n ): void {\n const { lineAnnotations } = event;\n if (lineAnnotations != null) {\n this.syncEditSessionAnnotationsFromEditor(lineAnnotations);\n }\n }\n\n public emitEditChange(\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n ): void {\n const { onEditChange } = this.options;\n onEditChange?.(event);\n }\n\n /**\n * @internal Capture the current diff session, or return `undefined` when no\n * complete compatible session exists.\n *\n * When `clone` is true, the returned lines and hunks are copied.\n */\n public __captureDocumentSessionState(\n clone = true\n ): CapturedDiffSessionState | undefined {\n let { fileDiff, editSession: { diff: sessionDiff, outgoingDiff } = {} } =\n this;\n if (outgoingDiff != null && fileDiff != null) {\n if (!fileDiff.isPartial && shouldResetUndoState(outgoingDiff, fileDiff)) {\n return undefined;\n }\n sessionDiff = outgoingDiff;\n }\n if (sessionDiff == null || sessionDiff.isPartial) {\n return undefined;\n }\n return {\n diffSession: {\n oldFile:\n sessionDiff.type !== 'new'\n ? {\n name: sessionDiff.prevName ?? sessionDiff.name,\n lines: clone\n ? [...sessionDiff.deletionLines]\n : sessionDiff.deletionLines,\n }\n : null,\n type: sessionDiff.type,\n hunks: clone ? cloneHunks(sessionDiff.hunks) : sessionDiff.hunks,\n },\n hasChanges: sessionDiff.editSessionDirty === true,\n };\n }\n\n /** @internal Associate this component with its editor for a render lifecycle. */\n public __attachEditor(\n editor: Editor<'file-diff', LAnnotation, Caret>\n ): () => void {\n // Editing is a plain file-diff concern only. Subclasses with their own\n // hunk semantics (UnresolvedFile) are not editable, so an editor must\n // never attach to them.\n if (this.type !== 'file-diff') {\n throw new Error(\n `FileDiff.__attachEditor: cannot attach an editor to a \"${this.type}\" diff`\n );\n }\n if (this.editor != null) {\n throw new Error('FileDiff.__attachEditor: an editor is already attached');\n }\n const detach = () => {\n this.editor = undefined;\n this.finishEditSession();\n };\n try {\n this.resumeEditorRendering(editor);\n return detach;\n } catch (error) {\n detach();\n throw error;\n }\n }\n\n /** @internal Resume rendering for the editor already associated with this component. */\n public __resumeEditor(editor: Editor<'file-diff', LAnnotation, Caret>): void {\n if (this.editor !== editor) {\n throw new Error('FileDiff.__resumeEditor: editor association changed');\n }\n this.resumeEditorRendering(editor);\n }\n\n private resumeEditorRendering(\n editor: Editor<'file-diff', LAnnotation, Caret>\n ): void {\n const { fileDiff: externalDiff } = this;\n const pendingReplacement = this.editSession?.outgoingDiff;\n // A pending replacement whose diff was partial when it arrived installs now\n // that we are (re)attaching with a hydrated diff.\n if (\n pendingReplacement != null &&\n externalDiff != null &&\n !externalDiff.isPartial &&\n this.editSession?.diff === pendingReplacement\n ) {\n this.installEditSession(externalDiff);\n }\n const initialExternalDiff =\n this.editSession == null &&\n externalDiff != null &&\n !externalDiff.isPartial\n ? externalDiff\n : undefined;\n if (initialExternalDiff != null) {\n this.installEditSession(\n initialExternalDiff,\n editor.__getDocumentContents(getAdditionFile(initialExternalDiff)),\n editor.__getDocumentSessionState()\n );\n } else if (this.editSession != null) {\n this.hunksRenderer.beginEditSession(this.editSession.diff);\n }\n this.editor = editor;\n // The editor sync below refuses partial diffs (it needs the full file\n // contents); kick off hydration so the loaded re-render re-runs it.\n if (this.fileDiff?.isPartial === true) {\n this.loadFilesIfNecessary();\n }\n const editSessionDiff = this.editSession?.diff;\n if (this.hunksRenderer.editorRenderReady()) {\n // Compatible markup can be reused without repainting. Once the renderer\n // transfers that cache to the private session, the existing DOM belongs\n // to the session as well.\n if (\n editSessionDiff != null &&\n this.hunksRenderer.diffCache === editSessionDiff\n ) {\n this.renderedDiff = editSessionDiff;\n }\n this.syncRenderViewToEditor();\n } else {\n // The current markup is missing the editor's token metadata, or its\n // highlight is still pending: render through the session, which also\n // syncs the render view once it paints.\n this.rerender();\n }\n }\n\n // Session exit for the live detach path.\n private finishEditSession(): void {\n this.hunksRenderer.endEditSession();\n this.finalizeEditSessionHunks();\n }\n\n /**\n * @internal\n *\n * Ends the edit session and settles which diff this component renders.\n * Requires the editor to be detached first. Does nothing when no session\n * exists, so callers can invoke it again safely after it has settled.\n *\n * `onEditComplete` receives the completed diff, current external diff,\n * complete file pair, and both annotation collections even when the final\n * text is unchanged. In `install` mode, accepting installs the completed diff\n * and its annotations; rejecting or having no handler restores the external\n * values. `discard` mode always restores the external values. An accepted\n * diff cannot reuse the replaced diff's `cacheKey`.\n */\n public __completeEditSession(\n editor: Editor<'file-diff', LAnnotation, Caret>,\n mode: 'install' | 'discard'\n ): void {\n this.settleEditSession(mode === 'install', editor);\n }\n\n private settleEditSession(\n installResult: boolean,\n editor: Editor<'file-diff', LAnnotation, Caret> | undefined\n ): void {\n const {\n editSession,\n fileDiff: externalDiff,\n lineAnnotations: externalAnnotations,\n } = this;\n if (editSession == null || externalDiff == null) {\n return;\n }\n const { diff: editSessionDiff, annotations: editSessionAnnotations } =\n editSession;\n if (this.editor != null) {\n throw new Error(\n 'FileDiff.__completeEditSession: detach the editor before completing the session'\n );\n }\n this.hunksRenderer.endEditSession();\n this.finalizeEditSessionHunks();\n\n const sessionAnnotationsCurrent = editSessionAnnotations?.current;\n let acceptedDiff: FileDiffMetadata | undefined;\n let acceptedOldFile: FileContents | null = null;\n let acceptedNewFile: FileContents | null = null;\n let failed = false;\n let failure: unknown;\n if (editor == null) {\n throw new Error(\n 'FileDiff.__completeEditSession: editor is required for completion'\n );\n }\n const completedDiff = cloneFileDiffMetadata(editSessionDiff);\n const newFile: FileContents = {\n name: completedDiff.name,\n contents: completedDiff.additionLines.join(''),\n };\n if (completedDiff.lang != null) {\n newFile.lang = completedDiff.lang;\n }\n const event: FileDiffEditCompleteEvent<LAnnotation, Caret> = {\n fileDiff: completedDiff,\n editor,\n originalFileDiff: externalDiff,\n oldFile:\n completedDiff.type === 'new'\n ? null\n : {\n name: completedDiff.prevName ?? completedDiff.name,\n contents: completedDiff.deletionLines.join(''),\n },\n newFile,\n lineAnnotations: sessionAnnotationsCurrent,\n originalLineAnnotations: externalAnnotations,\n };\n // Frozen so a handler cannot swap the event's fileDiff/originalFileDiff\n // references; nested mutation (i.e. a fresh cacheKey on event.fileDiff)\n // still works.\n Object.freeze(event);\n try {\n editor.__emitEditComplete(event);\n const decision = this.options.onEditComplete?.(event);\n if (decision === 'accept') {\n if (\n completedDiff.cacheKey != null &&\n completedDiff.cacheKey === externalDiff.cacheKey\n ) {\n throw new Error(\n 'FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey'\n );\n }\n acceptedDiff = completedDiff;\n acceptedOldFile = event.oldFile;\n acceptedNewFile = event.newFile;\n }\n } catch (error) {\n failed = true;\n failure = error;\n }\n\n if (installResult && acceptedDiff != null) {\n this.fileDiff = acceptedDiff;\n // Callers using the oldFile/newFile API get the stored pair\n // refreshed so their next render with the event's files does not\n // reparse over the accepted diff. Every editable pair has a new\n // side (deleted files cannot be edited), so that is the check.\n if (this.additionFile != null) {\n this.deletionFile = acceptedOldFile;\n this.additionFile = acceptedNewFile;\n }\n if (sessionAnnotationsCurrent != null) {\n this.lineAnnotations = sessionAnnotationsCurrent;\n }\n }\n this.editSession = undefined;\n if (installResult && this.fileContainer != null) {\n this.rerender();\n }\n if (failed) {\n throw failure;\n }\n }\n\n /**\n * Run the session-end recompute: restore recompute-shaped hunks (a\n * context-only region collapses away, boundaries re-derive), preserve\n * expansion state best-effort via old-side anchors, and repaint through\n * the session render path — which also invalidates virtualized layout,\n * since nothing else does at exit now that editing does not flip\n * expandUnchanged. Marker-guarded and idempotent; CodeView also calls this\n * when ending a session whose detach closure was consumed by a recycle.\n * Safe on a cleaned-up instance: the recompute is pure metadata work and\n * the deferred rerender is enabled-guarded. Returns true when a recompute\n * ran.\n */\n public finalizeEditSessionHunks(): boolean {\n const fileDiff = this.getLatestDiff();\n if (fileDiff == null || fileDiff.editSessionDirty !== true) {\n return false;\n }\n const { collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD } =\n this.options;\n const anchors = captureExpansionAnchors(\n fileDiff,\n this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold\n );\n finishEditSessionForDiff(fileDiff, this.options.parseDiffOptions);\n this.hunksRenderer.setExpandedHunksMap(\n rebuildExpansionFromAnchors(fileDiff, anchors)\n );\n void this.hunksRenderer.refreshHighlightedResult();\n this.escalateEditSessionRender();\n return true;\n }\n\n // normally triggered by the host when the document line count changes\n public applyDocumentChange(\n textDocument: TextDocument<'file-diff', LAnnotation>,\n newLineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void {\n const editSessionDiff = this.editSession?.diff;\n if (editSessionDiff == null) {\n throw new Error(\n 'FileDiff.applyDocumentChange: requires an active edit session'\n );\n }\n this.detachAdditionLines();\n this.hunksRenderer.beginEditSession(editSessionDiff);\n this.hunksRenderer.applyDocumentChange(textDocument);\n if (newLineAnnotations != null) {\n this.syncEditSessionAnnotationsFromEditor(newLineAnnotations);\n }\n this.rerender();\n this.interactionManager.setSelectionDirty();\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light',\n options: {\n shouldRefreshDiffsView?: boolean;\n lineCountChangeInFlight?: boolean;\n } = {}\n ): void {\n const editSessionDiff = this.editSession?.diff;\n if (editSessionDiff == null) {\n throw new Error(\n 'FileDiff.updateRenderCache: requires an active edit session'\n );\n }\n this.detachAdditionLines();\n this.hunksRenderer.beginEditSession(editSessionDiff);\n const { shouldRefreshDiffsView, lineCountChangeInFlight } = options;\n const regionsChanged = this.hunksRenderer.updateRenderCache(\n dirtyLines,\n themeType,\n lineCountChangeInFlight\n );\n // A same-line-count edit that reshaped the session regions (an edit into\n // a collapsed gap) changes the rendered row set, which the debounced\n // line-type refresh below cannot express. Escalate to a deferred full\n // re-render — never a synchronous one, since this runs mid-editor-pass\n // and rebuilding rows the editor is about to touch detaches its geometry\n // caches.\n if (regionsChanged) {\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n this.refreshViewTimeout = undefined;\n }\n this.lineStateRefreshPending = true;\n this.escalateEditSessionRender();\n return;\n }\n if (shouldRefreshDiffsView === true) {\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n }\n this.lineStateRefreshPending = true;\n this.refreshViewTimeout = setTimeout(() => {\n this.refreshViewTimeout = undefined;\n if (this.options.diffStyle === 'split') {\n this.refreshSplitDiffView();\n } else {\n this.refreshUnifiedDiffView();\n }\n this.flushDeferredLineState();\n }, 150);\n }\n }\n\n private detachAdditionLines(): void {\n const editSessionDiff = this.editSession?.diff;\n const { fileDiff } = this;\n if (\n editSessionDiff != null &&\n (editSessionDiff.additionLines === fileDiff?.additionLines ||\n editSessionDiff.additionLines === editSessionDiff.deletionLines)\n ) {\n editSessionDiff.additionLines = [...editSessionDiff.additionLines];\n }\n }\n\n // Editor-facing visibility oracle: whether a one-based new-file line has\n // (or will have on scroll) a rendered row under the current expansion\n // state. See isAdditionLineRenderable.\n public isLineRenderable(lineNumber: number): boolean {\n const fileDiff = this.getRenderedDiff();\n if (fileDiff == null) {\n return true;\n }\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n return isAdditionLineRenderable({\n fileDiff,\n lineNumber,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n });\n }\n\n // Fold-skip companion to isLineRenderable: the nearest renderable one-based\n // new-file line at or beyond lineNumber in the given direction.\n public getNearestRenderableLine(\n lineNumber: number,\n direction: 'up' | 'down'\n ): number | undefined {\n const fileDiff = this.getRenderedDiff();\n if (fileDiff == null) {\n return lineNumber;\n }\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n return getNearestRenderableAdditionLine({\n fileDiff,\n lineNumber,\n direction,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n });\n }\n\n // Expand collapsed context so a one-based new-file line can render: one\n // deterministic expansion from the nearest gap edge, sized to reach the\n // target plus the normal expansion step (clamped to the gap at render).\n // Routed through expandHunk so subclass expansion flows (CodeView's\n // deferred pendingExpansions) apply.\n public revealLine(lineNumber: number): boolean {\n const fileDiff = this.getRenderedDiff();\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n expansionLineCount = 100,\n } = this.options;\n if (fileDiff == null || fileDiff.isPartial || expandUnchanged) {\n return false;\n }\n const expandedHunks = this.hunksRenderer.getExpandedHunksMap();\n\n for (const [hunkIndex, hunk] of fileDiff.hunks.entries()) {\n const [hunkStart, hunkEnd] = getHunkAdditionLineRange(hunk);\n if (lineNumber < hunkStart) {\n const region = getExpandedRegion({\n isPartial: fileDiff.isPartial,\n rangeSize: hunk.collapsedBefore,\n expandedHunks,\n hunkIndex,\n collapsedContextThreshold,\n });\n const gapStart = hunkStart - region.rangeSize;\n if (\n region.renderAll ||\n lineNumber < gapStart + region.fromStart ||\n lineNumber >= hunkStart - region.fromEnd\n ) {\n return false;\n }\n const fromStartDistance =\n lineNumber - (gapStart + region.fromStart) + 1;\n const fromEndDistance = hunkStart - region.fromEnd - lineNumber;\n if (fromStartDistance <= fromEndDistance) {\n this.expandHunk(\n hunkIndex,\n 'up',\n fromStartDistance + expansionLineCount\n );\n } else {\n this.expandHunk(\n hunkIndex,\n 'down',\n fromEndDistance + expansionLineCount\n );\n }\n return true;\n }\n if (lineNumber < hunkEnd) {\n return false;\n }\n }\n\n const trailingRegion = getTrailingExpandedRegion({\n fileDiff,\n hunkIndex: fileDiff.hunks.length - 1,\n expandedHunks,\n collapsedContextThreshold,\n errorPrefix: 'FileDiff.revealLine',\n });\n if (trailingRegion == null || trailingRegion.renderAll) {\n return false;\n }\n const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];\n const [, trailingStart] = getHunkAdditionLineRange(lastHunk);\n if (\n lineNumber < trailingStart + trailingRegion.fromStart ||\n lineNumber >= trailingStart + trailingRegion.rangeSize\n ) {\n return false;\n }\n this.expandHunk(\n fileDiff.hunks.length,\n 'up',\n lineNumber -\n (trailingStart + trailingRegion.fromStart) +\n 1 +\n expansionLineCount\n );\n return true;\n }\n\n // Whether render() may run the session-exit recompute on dirty metadata.\n // False while an editor is attached (the session is live). CodeView-managed\n // instances override this: their sessions survive recycling with no editor\n // attached, and CodeView runs the exit recompute itself when it reaps a\n // session.\n protected shouldSelfHealEditSession(): boolean {\n return this.editor == null;\n }\n\n // Deferred full re-render for session region changes. The subsequent\n // render() ends in syncRenderViewToEditor, which resets the editor's\n // geometry caches against the rebuilt rows. VirtualizedFileDiff overrides\n // this to also invalidate its layout caches.\n protected escalateEditSessionRender(): void {\n queueRender(this.handleEditSessionRender);\n }\n\n private handleEditSessionRender = (): void => {\n this.rerender();\n this.flushDeferredLineState();\n };\n\n private removeRenderedCode(): void {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.interactionManager.cleanUp();\n\n this.bufferBefore?.remove();\n this.bufferBefore = undefined;\n this.bufferAfter?.remove();\n this.bufferAfter = undefined;\n\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n\n this.pre?.remove();\n this.pre = undefined;\n\n this.appliedPreAttributes = undefined;\n this.lastRowCount = undefined;\n }\n\n private clearAuxiliaryNodes(): void {\n for (const { element } of this.separatorCache.values()) {\n element.remove();\n }\n this.separatorCache.clear();\n\n for (const { element } of this.annotationCache.values()) {\n element.remove();\n }\n this.annotationCache.clear();\n\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n }\n\n public renderPlaceholder(height: number): boolean {\n if (this.fileContainer == null) {\n return false;\n }\n this.emitPostRender(true);\n this.cleanChildNodes();\n\n if (this.placeHolder == null) {\n const shadowRoot =\n this.fileContainer.shadowRoot ??\n this.fileContainer.attachShadow({ mode: 'open' });\n this.placeHolder = document.createElement('div');\n this.placeHolder.dataset.placeholder = '';\n shadowRoot.appendChild(this.placeHolder);\n }\n this.placeHolder.style.setProperty('height', `${height}px`);\n return true;\n }\n\n public async primeHighlightCache(\n fileDiff: FileDiffMetadata | undefined = this.fileDiff\n ): Promise<void> {\n const { workerManager } = this;\n if (\n fileDiff == null ||\n workerManager == null ||\n !workerManager.isWorkingPool() ||\n fileDiff.cacheKey == null ||\n isDiffPlainText(fileDiff)\n ) {\n return;\n }\n const tokenizeMaxLength =\n this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n if (\n Math.max(fileDiff.additionLines.length, fileDiff.deletionLines.length) >\n tokenizeMaxLength\n ) {\n return;\n }\n\n await workerManager\n .primeDiffHighlightCache(fileDiff)\n .catch((error: unknown) => {\n console.error(error);\n });\n }\n\n private cleanChildNodes() {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.interactionManager.cleanUp();\n this.clearAuxiliaryNodes();\n\n this.bufferAfter?.remove();\n this.bufferBefore?.remove();\n this.codeAdditions?.remove();\n this.codeDeletions?.remove();\n this.codeUnified?.remove();\n this.errorWrapper?.remove();\n this.headerElement?.remove();\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerCustom?.remove();\n this.pre?.remove();\n this.spriteSVG?.remove();\n this.themeCSSStyle?.remove();\n this.unsafeCSSStyle?.remove();\n\n this.bufferAfter = undefined;\n this.bufferBefore = undefined;\n this.codeAdditions = undefined;\n this.codeDeletions = undefined;\n this.codeUnified = undefined;\n this.errorWrapper = undefined;\n this.headerElement = undefined;\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n this.pre = undefined;\n this.spriteSVG = undefined;\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n this.hasAdoptedThemeCSS = false;\n this.unsafeCSSStyle = undefined;\n this.appliedUnsafeCSS = undefined;\n\n this.headerCache.lastRenderedHTML = undefined;\n this.lastRowCount = undefined;\n this.mounted = false;\n }\n\n private renderSeparators(hunkData: HunkData[]): void {\n const { hunkSeparators } = this.options;\n if (\n this.isContainerManaged ||\n this.fileContainer == null ||\n typeof hunkSeparators !== 'function'\n ) {\n for (const { element } of this.separatorCache.values()) {\n element.remove();\n }\n this.separatorCache.clear();\n return;\n }\n const staleSeparators = new Map(this.separatorCache);\n for (const hunk of hunkData) {\n const id = hunk.slotName;\n let cache = this.separatorCache.get(id);\n if (cache == null || !areHunkDataEqual(hunk, cache.hunkData)) {\n cache?.element.remove();\n const element = document.createElement('div');\n element.style.display = 'contents';\n element.slot = hunk.slotName;\n const child = hunkSeparators(hunk, this);\n if (child != null) {\n element.appendChild(child);\n }\n this.fileContainer.appendChild(element);\n cache = { element, hunkData: hunk };\n this.separatorCache.set(id, cache);\n }\n staleSeparators.delete(id);\n }\n for (const [id, { element }] of staleSeparators.entries()) {\n this.separatorCache.delete(id);\n element.remove();\n }\n }\n\n protected renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.remove();\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n const lineAnnotations = this.getLatestAnnotations();\n if (renderAnnotation != null && lineAnnotations.length > 0) {\n for (const [index, annotation] of lineAnnotations.entries()) {\n const name = this.getAnnotationSlotName(annotation);\n const id = `${index}-${name}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areDiffLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.remove();\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(name),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.remove();\n }\n }\n\n protected renderGutterUtility(): void {\n const { renderGutterUtility } = this.options;\n if (this.fileContainer == null || renderGutterUtility == null) {\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n return;\n }\n const element = renderGutterUtility(this.interactionManager.getHoveredLine);\n if (element != null && this.gutterUtilityContent != null) {\n return;\n } else if (element == null) {\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n return;\n }\n const gutterUtilityContent = createGutterUtilityContentNode();\n gutterUtilityContent.appendChild(element);\n this.fileContainer.appendChild(gutterUtilityContent);\n this.gutterUtilityContent = gutterUtilityContent;\n }\n\n protected getOrCreateFileContainer(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const { fileContainer: previousContainer } = this;\n const nextContainer =\n fileContainer ??\n previousContainer ??\n document.createElement(DIFFS_TAG_NAME);\n const containerChanged = previousContainer !== nextContainer;\n if (previousContainer != null && containerChanged) {\n this.editor?.__captureFocusForDOMReplacement();\n }\n if (containerChanged) {\n this.emitPostRender(true);\n }\n this.fileContainer = nextContainer;\n if (previousContainer != null && containerChanged) {\n this.headerCache.lastRenderedHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (containerChanged) {\n this.adoptReusableShellElements(this.fileContainer);\n }\n this.ensureSpriteSVG(this.fileContainer);\n return this.fileContainer;\n }\n\n // NOTE(amadeus): Technically this method is not safe for use outside of\n // the CodeView component, however I don't think in practice it really\n // should matter, but maybe there's some system we need in place to prevent\n // this from running outside of that environment?\n //\n // It's making very specific assumptions that all the elements will have the\n // correct content based on CodeView global options\n private adoptReusableShellElements(fileContainer: HTMLElement): void {\n const { shadowRoot } = fileContainer;\n if (shadowRoot == null) {\n return;\n }\n\n for (const element of shadowRoot.children) {\n if (element instanceof SVGElement) {\n this.spriteSVG ??= element;\n } else if (\n isStyleNode(element) &&\n element.hasAttribute(THEME_CSS_ATTRIBUTE)\n ) {\n this.themeCSSStyle ??= element;\n this.hasAdoptedThemeCSS = true;\n } else if (\n isStyleNode(element) &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle ??= element;\n this.appliedUnsafeCSS ??= this.options.unsafeCSS ?? undefined;\n }\n }\n }\n\n private ensureSpriteSVG(fileContainer: HTMLElement): void {\n const shadowRoot =\n fileContainer.shadowRoot ?? fileContainer.attachShadow({ mode: 'open' });\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n }\n }\n if (this.spriteSVG != null && this.spriteSVG.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.spriteSVG);\n }\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n this.appliedPreAttributes = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n shadowRoot.appendChild(this.pre);\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== shadowRoot) {\n this.editor?.__captureFocusForDOMReplacement();\n shadowRoot.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n\n return this.pre;\n }\n\n protected syncCodeNodesFromPre(pre: HTMLPreElement): void {\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n for (const child of Array.from(pre.children)) {\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n if (child.hasAttribute('data-unified')) {\n this.codeUnified = child;\n } else if (child.hasAttribute('data-deletions')) {\n this.codeDeletions = child;\n } else if (child.hasAttribute('data-additions')) {\n this.codeAdditions = child;\n }\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement,\n fileDiff: FileDiffMetadata\n ): void {\n this.cleanupErrorWrapper();\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n // Session metadata changes in place, so an HTML cache created from the\n // external diff cannot describe the current edit-session header.\n const {\n headerCache: {\n fileDiff: cachedHeaderDiff,\n html: cachedHeaderHTML,\n lastRenderedHTML,\n },\n } = this;\n const editSessionDiff = this.editSession?.diff;\n const reusableHeaderHTML =\n fileDiff !== editSessionDiff &&\n areDiffTargetsEqual(cachedHeaderDiff, fileDiff)\n ? cachedHeaderHTML\n : undefined;\n const headerHTML = reusableHeaderHTML ?? toHtml(headerAST);\n this.headerCache.html = headerHTML;\n this.headerCache.fileDiff = fileDiff;\n if (headerHTML !== lastRenderedHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.headerCache.lastRenderedHTML = headerHTML;\n }\n\n if (this.isContainerManaged) {\n return;\n }\n\n const {\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n } = this.options;\n\n if (renderCustomHeader != null) {\n const content = renderCustomHeader(fileDiff) ?? undefined;\n this.headerCustom = this.upsertHeaderSlotElement(\n container,\n this.headerCustom,\n CUSTOM_HEADER_SLOT_ID,\n content\n );\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n return;\n }\n\n const prefix = renderHeaderPrefix?.(fileDiff) ?? undefined;\n const suffix = renderHeaderFilenameSuffix?.(fileDiff) ?? undefined;\n const content = renderHeaderMetadata?.(fileDiff) ?? undefined;\n this.headerPrefix = this.upsertHeaderSlotElement(\n container,\n this.headerPrefix,\n HEADER_PREFIX_SLOT_ID,\n prefix\n );\n this.headerFilenameSuffix = this.upsertHeaderSlotElement(\n container,\n this.headerFilenameSuffix,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n suffix\n );\n this.headerMetadata = this.upsertHeaderSlotElement(\n container,\n this.headerMetadata,\n HEADER_METADATA_SLOT_ID,\n content\n );\n this.headerCustom?.remove();\n this.headerCustom = undefined;\n }\n\n protected clearReusableHeader(): void {\n this.headerCache.html = undefined;\n this.headerCache.fileDiff = undefined;\n }\n\n private clearHeaderSlots(): void {\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerCustom?.remove();\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n }\n\n // Header slot callbacks are presence-based render hooks, not reactive views.\n private upsertHeaderSlotElement(\n container: HTMLElement,\n current: HTMLElement | undefined,\n slot: string,\n content: Element | string | number | undefined\n ): HTMLElement | undefined {\n if (content == null) {\n current?.remove();\n return undefined;\n }\n const element = current ?? this.createHeaderSlotElement(slot);\n if (current == null) {\n container.appendChild(element);\n }\n this.replaceHeaderSlotContent(element, content);\n return element;\n }\n\n private replaceHeaderSlotContent(\n element: HTMLElement,\n content: Element | string | number\n ): void {\n element.replaceChildren();\n if (content instanceof Element) {\n element.appendChild(content);\n } else {\n element.innerText = `${content}`;\n }\n }\n\n private createHeaderSlotElement(slot: string): HTMLElement {\n const element = document.createElement('div');\n element.slot = slot;\n return element;\n }\n\n protected injectUnsafeCSS(): void {\n const { unsafeCSS } = this.options;\n const shadowRoot = this.fileContainer?.shadowRoot;\n if (shadowRoot == null) {\n return;\n }\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.remove();\n this.unsafeCSSStyle = undefined;\n }\n this.appliedUnsafeCSS = undefined;\n return;\n }\n\n if (\n this.unsafeCSSStyle?.parentNode === shadowRoot &&\n this.appliedUnsafeCSS === unsafeCSS\n ) {\n return;\n }\n\n // Create or update the style element\n this.unsafeCSSStyle ??= createUnsafeCSSStyleNode();\n if (this.unsafeCSSStyle.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.textContent = wrapUnsafeCSS(unsafeCSS);\n this.appliedUnsafeCSS = unsafeCSS;\n }\n\n private applyThemeState(\n container: HTMLElement,\n themeStyles: string,\n themeType: ThemeTypes,\n baseThemeType?: 'light' | 'dark'\n ): void {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const effectiveThemeType = baseThemeType ?? themeType;\n const currentTheme = this.getTheme();\n const theme =\n typeof currentTheme === 'string' ? currentTheme : { ...currentTheme };\n const scrollbarGutter = getMeasuredScrollbarGutter(shadowRoot);\n if (\n this.themeCSSStyle?.parentNode === shadowRoot &&\n this.appliedThemeCSS?.themeStyles === themeStyles &&\n this.appliedThemeCSS.themeType === effectiveThemeType &&\n this.appliedThemeCSS.scrollbarGutter === scrollbarGutter\n ) {\n this.appliedThemeCSS.theme = theme;\n return;\n }\n if (\n this.hasAdoptedThemeCSS &&\n this.themeCSSStyle?.parentNode === shadowRoot\n ) {\n this.hasAdoptedThemeCSS = false;\n this.appliedThemeCSS = {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n };\n return;\n }\n this.themeCSSStyle = upsertHostThemeStyle({\n shadowRoot,\n currentNode: this.themeCSSStyle,\n themeCSS: wrapThemeCSS(themeStyles, effectiveThemeType, scrollbarGutter),\n });\n this.appliedThemeCSS =\n this.themeCSSStyle != null\n ? {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n }\n : undefined;\n }\n\n private hydrateMeasuredScrollbar(): void {\n const shadowRoot = this.fileContainer?.shadowRoot;\n if (shadowRoot == null || this.themeCSSStyle == null) {\n return;\n }\n this.themeCSSStyle.textContent = patchScrollbarGutterSize(\n this.themeCSSStyle.textContent ?? '',\n getMeasuredScrollbarGutter(shadowRoot)\n );\n }\n\n // A boolean check to ensure that edit mode in WebKit doesn't cause potential\n // scroll jumps to due bugs with WebKit. The workarounds have performance\n // implications so we avoid running the workarounds on browsers or scenarios\n // where they are not applicable\n protected shouldGuardRebuildScroll(): boolean {\n return this.editor != null && isSafari();\n }\n\n private applyHunksToDOM(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n if (this.shouldGuardRebuildScroll()) {\n guardWebKitScrollDuringRebuild(pre, () =>\n this.replaceCodeColumns(pre, result)\n );\n } else {\n this.replaceCodeColumns(pre, result);\n }\n }\n\n // Renders a code column's AST into an existing elements without replacing\n // the gutter and content parents. Identity matters in edit mode: the content\n // element is the focused contenteditable, and replacing it ends the\n // browser's editing session — focus tears down and restores, and iOS\n // answers every session restart with an animated caret reveal.\n //\n // Returns false when the element has no column pair yet (initial render,\n // or a diff-style switch built a fresh element); the caller then assigns\n // the full innerHTML.\n private applyCodeColumnsInPlace(\n code: HTMLElement,\n ast: ElementContent[],\n rowCount: number\n ): boolean {\n const columns = this.getColumnPair(code);\n if (columns == null) {\n return false;\n }\n const gutterChildren = getElementChildren(ast[0]);\n const contentChildren = getElementChildren(ast[1]);\n if (gutterChildren == null || contentChildren == null) {\n return false;\n }\n columns.gutter.innerHTML = toHtml(gutterChildren);\n columns.content.innerHTML = toHtml(contentChildren);\n if (rowCount !== this.lastRowCount) {\n columns.gutter.style.setProperty('grid-row', `span ${rowCount}`);\n columns.content.style.setProperty('grid-row', `span ${rowCount}`);\n }\n return true;\n }\n\n private replaceCodeColumns(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n const { overflow = 'scroll' } = this.options;\n const containerSize =\n (this.options.hunkSeparators ?? 'line-info') === 'line-info';\n const rowSpan = overflow === 'wrap' ? result.rowCount : undefined;\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n\n let shouldReplace = false;\n // Create code elements and insert HTML content\n const codeElements: HTMLElement[] = [];\n const unifiedAST = this.hunksRenderer.renderCodeAST('unified', result);\n const deletionsAST = this.hunksRenderer.renderCodeAST('deletions', result);\n const additionsAST = this.hunksRenderer.renderCodeAST('additions', result);\n this.editor?.__captureFocusForDOMReplacement();\n if (unifiedAST != null) {\n shouldReplace =\n this.codeUnified == null ||\n this.codeAdditions != null ||\n this.codeDeletions != null;\n\n // Clean up addition/deletion elements if necessary\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n\n this.codeUnified = getOrCreateCodeNode({\n code: this.codeUnified,\n columnType: 'unified',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeUnified,\n unifiedAST,\n result.rowCount\n )\n ) {\n this.codeUnified.innerHTML =\n this.hunksRenderer.renderPartialHTML(unifiedAST);\n }\n codeElements.push(this.codeUnified);\n } else if (deletionsAST != null || additionsAST != null) {\n if (deletionsAST != null) {\n shouldReplace = this.codeDeletions == null || this.codeUnified != null;\n\n // Clean up unified column if necessary\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n\n this.codeDeletions = getOrCreateCodeNode({\n code: this.codeDeletions,\n columnType: 'deletions',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeDeletions,\n deletionsAST,\n result.rowCount\n )\n ) {\n this.codeDeletions.innerHTML =\n this.hunksRenderer.renderPartialHTML(deletionsAST);\n }\n codeElements.push(this.codeDeletions);\n } else {\n // If we have no deletion column, lets clean it up if it exists\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n }\n\n if (additionsAST != null) {\n shouldReplace =\n shouldReplace ||\n this.codeAdditions == null ||\n this.codeUnified != null;\n\n // Clean up unified column if necessary\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n\n this.codeAdditions = getOrCreateCodeNode({\n code: this.codeAdditions,\n columnType: 'additions',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeAdditions,\n additionsAST,\n result.rowCount\n )\n ) {\n this.codeAdditions.innerHTML =\n this.hunksRenderer.renderPartialHTML(additionsAST);\n }\n codeElements.push(this.codeAdditions);\n } else {\n // If we have no addition column, lets clean it up if it exists\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n }\n } else {\n // if we get in here, there's no content to render, so lets just clean\n // everything up\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n }\n\n if (codeElements.length === 0) {\n pre.textContent = '';\n } else if (shouldReplace) {\n pre.replaceChildren(...codeElements);\n }\n\n this.lastRowCount = result.rowCount;\n }\n\n private applyPartialRender({\n fileDiff,\n previousRenderRange,\n renderRange,\n }: ApplyPartialRenderProps): boolean {\n const {\n pre,\n codeUnified,\n codeAdditions,\n codeDeletions,\n options: { diffStyle = 'split' },\n } = this;\n if (\n pre == null ||\n // We must have a current and previous render range to do a partial render\n previousRenderRange == null ||\n renderRange == null ||\n // Neither render range may be infinite\n !Number.isFinite(previousRenderRange.totalLines) ||\n !Number.isFinite(renderRange.totalLines) ||\n this.lastRowCount == null\n ) {\n return false;\n }\n const codeElements = this.getCodeColumns(\n diffStyle,\n codeUnified,\n codeDeletions,\n codeAdditions\n );\n if (codeElements == null) {\n return false;\n }\n\n const previousStart = previousRenderRange.startingLine;\n const nextStart = renderRange.startingLine;\n const previousEnd = previousStart + previousRenderRange.totalLines;\n const nextEnd = nextStart + renderRange.totalLines;\n\n const overlapStart = Math.max(previousStart, nextStart);\n const overlapEnd = Math.min(previousEnd, nextEnd);\n if (overlapEnd <= overlapStart) {\n return false;\n }\n\n const trimStart = Math.max(0, overlapStart - previousStart);\n const trimEnd = Math.max(0, previousEnd - overlapEnd);\n\n const trimResult = this.trimColumns({\n columns: codeElements,\n trimStart,\n trimEnd,\n previousStart,\n overlapStart,\n overlapEnd,\n diffStyle,\n });\n if (trimResult < 0) {\n throw new Error('FileDiff.applyPartialRender: failed to trim to overlap');\n }\n\n if (this.lastRowCount < trimResult) {\n throw new Error(\n 'FileDiff.applyPartialRender: trimmed beyond DOM row count'\n );\n }\n\n let rowCount = this.lastRowCount - trimResult;\n const renderChunk = (\n startingLine: number,\n totalLines: number\n ): HunksRenderResult | undefined => {\n if (totalLines <= 0) {\n return undefined;\n }\n return this.hunksRenderer.renderDiff(fileDiff, {\n startingLine,\n totalLines,\n bufferBefore: 0,\n bufferAfter: 0,\n });\n };\n\n const prependResult = renderChunk(\n nextStart,\n Math.max(overlapStart - nextStart, 0)\n );\n if (prependResult == null && nextStart < overlapStart) {\n return false;\n }\n\n const appendResult = renderChunk(\n overlapEnd,\n Math.max(nextEnd - overlapEnd, 0)\n );\n if (appendResult == null && nextEnd > overlapEnd) {\n return false;\n }\n\n const applyChunk = (\n result: HunksRenderResult | undefined,\n insertPosition: 'afterbegin' | 'beforeend'\n ) => {\n if (result == null) {\n return;\n }\n if (diffStyle === 'unified' && !Array.isArray(codeElements)) {\n this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);\n } else if (diffStyle === 'split' && Array.isArray(codeElements)) {\n this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);\n } else {\n throw new Error(\n 'FileDiff.applyPartialRender.applyChunk: invalid chunk application'\n );\n }\n rowCount += result.rowCount;\n this.renderedDiff = result.fileDiff;\n };\n\n this.cleanupErrorWrapper();\n applyChunk(prependResult, 'afterbegin');\n applyChunk(appendResult, 'beforeend');\n\n if (this.lastRowCount !== rowCount) {\n this.applyRowSpan(diffStyle, codeElements, rowCount);\n this.lastRowCount = rowCount;\n }\n\n return true;\n }\n\n private insertPartialHTML(\n diffStyle: 'unified',\n columns: ColumnElements,\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void;\n private insertPartialHTML(\n diffStyle: 'split',\n columns: [ColumnElements | undefined, ColumnElements | undefined],\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void;\n private insertPartialHTML(\n diffStyle: 'split' | 'unified',\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements,\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void {\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n const unifiedAST = this.hunksRenderer.renderCodeAST('unified', result);\n this.renderPartialColumn(columns, unifiedAST, insertPosition);\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n const deletionsAST = this.hunksRenderer.renderCodeAST(\n 'deletions',\n result\n );\n const additionsAST = this.hunksRenderer.renderCodeAST(\n 'additions',\n result\n );\n this.renderPartialColumn(columns[0], deletionsAST, insertPosition);\n this.renderPartialColumn(columns[1], additionsAST, insertPosition);\n } else {\n throw new Error(\n 'FileDiff.insertPartialHTML: Invalid argument composition'\n );\n }\n }\n\n // fast refresh diff view via updating the `data-line-type` after an edit.\n // only for split view.\n private refreshSplitDiffView(): void {\n const fileDiff = this.getLatestDiff();\n if (this.options.diffStyle !== 'split' || fileDiff == null) {\n return;\n }\n\n const hunksResult = this.hunksRenderer.renderDiff(\n fileDiff,\n this.renderRange\n );\n if (hunksResult == null) {\n return;\n }\n\n const columns = this.getCodeColumns(\n 'split',\n this.codeUnified,\n this.codeDeletions,\n this.codeAdditions\n );\n if (!Array.isArray(columns)) {\n return;\n }\n\n const applyLineType = (\n type: 'deletions' | 'additions',\n column: ColumnElements | undefined\n ) => {\n if (column == null) {\n return;\n }\n const ast = this.hunksRenderer.renderCodeAST(type, hunksResult);\n const gutterChildren = getElementChildren(ast?.[0]);\n const contentChildren = getElementChildren(ast?.[1]);\n for (const [el, astChildren] of [\n [column.gutter, gutterChildren],\n [column.content, contentChildren],\n ] as const) {\n if (\n astChildren != null &&\n el.childElementCount === astChildren.length\n ) {\n for (let i = 0; i < astChildren.length; i++) {\n const gutterElement = el.children[i] as HTMLElement;\n const gutterChild = astChildren[i] as HASTElement;\n const lineType = gutterChild.properties['data-line-type'] as\n | string\n | undefined;\n if (\n lineType != null &&\n gutterElement.dataset.lineType !== lineType\n ) {\n gutterElement.dataset.lineType = lineType;\n }\n }\n }\n }\n };\n\n applyLineType('deletions', columns[0]);\n applyLineType('additions', columns[1]);\n this.renderedDiff = hunksResult.fileDiff;\n }\n\n // full diff view re-rendering\n // only for unified view.\n private refreshUnifiedDiffView(): void {\n const fileDiff = this.getLatestDiff();\n if (this.options.diffStyle !== 'unified' || fileDiff == null) {\n return;\n }\n\n const hunksResult = this.hunksRenderer.renderDiff(\n fileDiff,\n this.renderRange\n );\n if (hunksResult == null) {\n return;\n }\n\n const columns = this.getCodeColumns(\n 'unified',\n this.codeUnified,\n this.codeDeletions,\n this.codeAdditions\n );\n if (columns == null || Array.isArray(columns)) {\n return;\n }\n\n const ast = this.hunksRenderer.renderCodeAST('unified', hunksResult);\n const gutterChildren = getElementChildren(ast?.[0]);\n const contentChildren = getElementChildren(ast?.[1]);\n const applyColumns = () => {\n for (const [el, astChildren] of [\n [columns.gutter, gutterChildren],\n [columns.content, contentChildren],\n ] as const) {\n if (astChildren != null) {\n el.innerHTML = toHtml(astChildren);\n }\n }\n\n if (hunksResult.rowCount !== this.lastRowCount) {\n this.applyRowSpan('unified', columns, hunksResult.rowCount);\n this.lastRowCount = hunksResult.rowCount;\n }\n this.renderedDiff = hunksResult.fileDiff;\n };\n if (this.shouldGuardRebuildScroll()) {\n guardWebKitScrollDuringRebuild(this.pre, applyColumns);\n } else {\n applyColumns();\n }\n this.renderSeparators(hunksResult.hunkData);\n\n this.managersDirty = true;\n this.flushManagers();\n\n // sync the render view to the editor\n this.syncRenderViewToEditor();\n }\n\n private renderPartialColumn(\n column: ColumnElements | undefined,\n ast: ElementContent[] | undefined,\n insertPosition: 'afterbegin' | 'beforeend'\n ) {\n if (column == null || ast == null) {\n return;\n }\n const gutterChildren = getElementChildren(ast[0]);\n const contentChildren = getElementChildren(ast[1]);\n if (gutterChildren == null || contentChildren == null) {\n throw new Error('FileDiff.insertPartialHTML: Unexpected AST structure');\n }\n const firstHASTElement = contentChildren.at(0);\n if (\n insertPosition === 'beforeend' &&\n firstHASTElement?.type === 'element' &&\n typeof firstHASTElement.properties['data-buffer-size'] === 'number'\n ) {\n this.mergeBuffersIfNecessary(\n firstHASTElement.properties['data-buffer-size'],\n column.content.children[column.content.children.length - 1],\n column.gutter.children[column.gutter.children.length - 1],\n gutterChildren,\n contentChildren,\n true\n );\n }\n const lastHASTElement = contentChildren.at(-1);\n if (\n insertPosition === 'afterbegin' &&\n lastHASTElement?.type === 'element' &&\n typeof lastHASTElement.properties['data-buffer-size'] === 'number'\n ) {\n this.mergeBuffersIfNecessary(\n lastHASTElement.properties['data-buffer-size'],\n column.content.children[0],\n column.gutter.children[0],\n gutterChildren,\n contentChildren,\n false\n );\n }\n\n column.gutter.insertAdjacentHTML(\n insertPosition,\n this.hunksRenderer.renderPartialHTML(gutterChildren)\n );\n column.content.insertAdjacentHTML(\n insertPosition,\n this.hunksRenderer.renderPartialHTML(contentChildren)\n );\n }\n\n private mergeBuffersIfNecessary(\n adjustmentSize: number,\n contentElement: Element,\n gutterElement: Element,\n gutterChildren: ElementContent[],\n contentChildren: ElementContent[],\n fromStart: boolean\n ) {\n if (\n !(contentElement instanceof HTMLElement) ||\n !(gutterElement instanceof HTMLElement)\n ) {\n return;\n }\n const currentSize = this.getBufferSize(contentElement.dataset);\n if (currentSize == null) {\n return;\n }\n if (fromStart) {\n gutterChildren.shift();\n contentChildren.shift();\n } else {\n gutterChildren.pop();\n contentChildren.pop();\n }\n this.updateBufferSize(contentElement, currentSize + adjustmentSize);\n this.updateBufferSize(gutterElement, currentSize + adjustmentSize);\n }\n\n private applyRowSpan(\n diffStyle: 'split' | 'unified',\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements,\n rowCount: number\n ): void {\n const applySpan = (column: ColumnElements | undefined) => {\n if (column == null) {\n return;\n }\n column.gutter.style.setProperty('grid-row', `span ${rowCount}`);\n column.content.style.setProperty('grid-row', `span ${rowCount}`);\n };\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n applySpan(columns);\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n applySpan(columns[0]);\n applySpan(columns[1]);\n } else {\n throw new Error('dun fuuuuked up');\n }\n }\n\n private trimColumnRows(\n columns: ColumnElements | undefined,\n preTrimCount: number,\n postTrimStart: number\n ): number {\n let visibleLineIndex = 0;\n let rowCount = 0;\n let rowIndex = 0;\n let pendingMetadataTrim = false;\n const hasPostTrim = postTrimStart >= 0;\n\n if (columns == null) {\n return 0;\n }\n const contentChildren = Array.from(columns.content.children);\n const gutterChildren = Array.from(columns.gutter.children);\n if (contentChildren.length !== gutterChildren.length) {\n throw new Error('FileDiff.trimColumnRows: columns do not match');\n }\n\n while (rowIndex < contentChildren.length) {\n if (preTrimCount <= 0 && !hasPostTrim && !pendingMetadataTrim) {\n break;\n }\n const gutterElement = gutterChildren[rowIndex];\n const contentElement = contentChildren[rowIndex];\n rowIndex++;\n\n if (\n !(gutterElement instanceof HTMLElement) ||\n !(contentElement instanceof HTMLElement)\n ) {\n console.error({ gutterElement, contentElement });\n throw new Error('FileDiff.trimColumnRows: invalid row elements');\n }\n\n if (pendingMetadataTrim) {\n pendingMetadataTrim = false;\n if (\n (gutterElement.dataset.gutterBuffer === 'annotation' &&\n 'lineAnnotation' in contentElement.dataset) ||\n (gutterElement.dataset.gutterBuffer === 'metadata' &&\n 'noNewline' in contentElement.dataset)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n continue;\n }\n }\n\n // If we found a line element, lets trim it if necessary\n if (\n 'lineIndex' in gutterElement.dataset &&\n 'lineIndex' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n if (preTrimCount > 0) {\n preTrimCount--;\n if (preTrimCount === 0) {\n pendingMetadataTrim = true;\n }\n }\n rowCount++;\n }\n visibleLineIndex++;\n continue;\n }\n\n // Separators should be removed, but don't count towards line indices\n if (\n 'separator' in gutterElement.dataset &&\n 'separator' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n // Annotations should be removed, but don't count towards line indices\n if (\n gutterElement.dataset.gutterBuffer === 'annotation' &&\n 'lineAnnotation' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n if (\n gutterElement.dataset.gutterBuffer === 'metadata' &&\n 'noNewline' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n if (\n gutterElement.dataset.gutterBuffer === 'buffer' &&\n 'contentBuffer' in contentElement.dataset\n ) {\n const totalRows = this.getBufferSize(contentElement.dataset);\n if (totalRows == null) {\n throw new Error('FileDiff.trimColumnRows: invalid element');\n }\n if (preTrimCount > 0) {\n const rowsToRemove = Math.min(preTrimCount, totalRows);\n const newSize = totalRows - rowsToRemove;\n if (newSize > 0) {\n this.updateBufferSize(gutterElement, newSize);\n this.updateBufferSize(contentElement, newSize);\n rowCount += rowsToRemove;\n } else {\n gutterElement.remove();\n contentElement.remove();\n rowCount += totalRows;\n }\n preTrimCount -= rowsToRemove;\n if (preTrimCount === 0 && newSize === 0) {\n pendingMetadataTrim = true;\n }\n }\n // If we are in a post clip era...\n else if (hasPostTrim) {\n const bufferStart = visibleLineIndex;\n const bufferEnd = visibleLineIndex + totalRows - 1;\n if (postTrimStart <= bufferStart) {\n gutterElement.remove();\n contentElement.remove();\n rowCount += totalRows;\n } else if (postTrimStart <= bufferEnd) {\n const rowsToRemove = bufferEnd - postTrimStart + 1;\n const newSize = totalRows - rowsToRemove;\n this.updateBufferSize(gutterElement, newSize);\n this.updateBufferSize(contentElement, newSize);\n rowCount += rowsToRemove;\n }\n }\n visibleLineIndex += totalRows;\n continue;\n }\n\n console.error({ gutterElement, contentElement });\n throw new Error('FileDiff.trimColumnRows: unknown row elements');\n }\n\n return rowCount;\n }\n\n private trimColumns({\n columns,\n diffStyle,\n overlapEnd,\n overlapStart,\n previousStart,\n trimEnd,\n trimStart,\n // NOTE(amadeus): If we return -1 it means something went wrong\n // with the trim...\n // oxlint-disable-next-line no-redundant-type-constituents\n }: TrimColumnsToOverlapProps): number | -1 {\n const preTrimCount = Math.max(0, overlapStart - previousStart);\n const postTrimStart = overlapEnd - previousStart;\n if (postTrimStart < 0) {\n throw new Error('FileDiff.trimColumns: overlap ends before previous');\n }\n const shouldTrimStart = trimStart > 0;\n const shouldTrimEnd = trimEnd > 0;\n if (!shouldTrimStart && !shouldTrimEnd) {\n return 0;\n }\n const effectivePreTrimCount = shouldTrimStart ? preTrimCount : 0;\n const effectivePostTrimStart = shouldTrimEnd ? postTrimStart : -1;\n\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n const removedRows = this.trimColumnRows(\n columns,\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n return removedRows;\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n const deletionsTrim = this.trimColumnRows(\n columns[0],\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n const additionsTrim = this.trimColumnRows(\n columns[1],\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n // We should avoid the trim validation if we are split but\n // there's only one side\n if (\n columns[0] != null &&\n columns[1] != null &&\n deletionsTrim !== additionsTrim\n ) {\n throw new Error('FileDiff.trimColumns: split columns out of sync');\n }\n return columns[0] != null ? deletionsTrim : additionsTrim;\n } else {\n console.error({ diffStyle, columns });\n throw new Error('FileDiff.trimColumns: Invalid columns for diffType');\n }\n }\n\n private getBufferSize(properties: DOMStringMap): number | undefined {\n const parsed = Number.parseInt(properties?.bufferSize ?? '', 10);\n return Number.isNaN(parsed) ? undefined : parsed;\n }\n\n private updateBufferSize(element: HTMLElement, size: number): void {\n element.dataset.bufferSize = `${size}`;\n element.style.setProperty('grid-row', `span ${size}`);\n element.style.setProperty('min-height', `calc(${size} * 1lh)`);\n }\n\n private getColumnPair(\n code: HTMLElement | undefined\n ): ColumnElements | undefined {\n if (code == null) {\n return undefined;\n }\n const gutter = code.children[0];\n const content = code.children[1];\n if (\n !(gutter instanceof HTMLElement) ||\n !(content instanceof HTMLElement) ||\n gutter.dataset.gutter == null ||\n content.dataset.content == null\n ) {\n return undefined;\n }\n return { gutter, content };\n }\n\n private getCodeColumns(\n diffStyle: 'split' | 'unified',\n codeUnified: HTMLElement | undefined,\n codeDeletions: HTMLElement | undefined,\n codeAdditions: HTMLElement | undefined\n ):\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements\n | undefined {\n if (diffStyle === 'unified') {\n return this.getColumnPair(codeUnified);\n } else {\n const deletions = this.getColumnPair(codeDeletions);\n const additions = this.getColumnPair(codeAdditions);\n return deletions != null || additions != null\n ? [deletions, additions]\n : undefined;\n }\n }\n\n protected updateBuffers(renderRange: RenderRange): void {\n if (this.pre != null) {\n this.applyBuffers(this.pre, renderRange);\n }\n }\n\n private applyBuffers(\n pre: HTMLPreElement,\n renderRange: RenderRange | undefined\n ) {\n if (renderRange == null || this.shouldDisableVirtualizationBuffers()) {\n if (this.bufferBefore != null) {\n this.bufferBefore.remove();\n this.bufferBefore = undefined;\n }\n if (this.bufferAfter != null) {\n this.bufferAfter.remove();\n this.bufferAfter = undefined;\n }\n return;\n }\n // NOTE(amadeus): A very hacky pass at buffers outside the pre elements...\n // i may need to improve this...\n if (renderRange.bufferBefore > 0) {\n if (this.bufferBefore == null) {\n this.bufferBefore = document.createElement('div');\n this.bufferBefore.dataset.virtualizerBuffer = 'before';\n pre.before(this.bufferBefore);\n }\n this.bufferBefore.style.setProperty(\n 'height',\n `${renderRange.bufferBefore}px`\n );\n this.bufferBefore.style.setProperty('contain', 'strict');\n } else if (this.bufferBefore != null) {\n this.bufferBefore.remove();\n this.bufferBefore = undefined;\n }\n\n if (renderRange.bufferAfter > 0) {\n if (this.bufferAfter == null) {\n this.bufferAfter = document.createElement('div');\n this.bufferAfter.dataset.virtualizerBuffer = 'after';\n pre.after(this.bufferAfter);\n }\n this.bufferAfter.style.setProperty(\n 'height',\n `${renderRange.bufferAfter}px`\n );\n this.bufferAfter.style.setProperty('contain', 'strict');\n } else if (this.bufferAfter != null) {\n this.bufferAfter.remove();\n this.bufferAfter = undefined;\n }\n }\n\n protected shouldDisableVirtualizationBuffers(): boolean {\n return this.options.disableVirtualizationBuffers ?? false;\n }\n\n protected applyPreNodeAttributes(\n pre: HTMLPreElement,\n { additionsContentAST, deletionsContentAST, totalLines }: HunksRenderResult,\n customProperties?: CustomPreProperties\n ): void {\n const {\n diffIndicators = 'bars',\n disableBackground = false,\n disableLineNumbers = false,\n overflow = 'scroll',\n diffStyle = 'split',\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n type: 'diff',\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split:\n diffStyle === 'unified'\n ? false\n : additionsContentAST != null && deletionsContentAST != null,\n totalLines,\n customProperties,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n this.pre?.remove();\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.textContent = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.remove();\n this.errorWrapper = undefined;\n }\n}\n\ninterface HasContentProps {\n fileDiff: FileDiffMetadata | undefined;\n oldFile: FileContents | null | undefined;\n newFile: FileContents | null | undefined;\n}\n\nfunction getAdditionFile(fileDiff: FileDiffMetadata): FileContents {\n return {\n name: fileDiff.name,\n lang: fileDiff.lang,\n contents: fileDiff.additionLines.join(''),\n };\n}\n\nfunction areOptionalFilesEqual(\n fileA: FileContents | null | undefined,\n fileB: FileContents | null | undefined\n): boolean {\n if (fileA == null || fileB == null) {\n return fileA == null && fileB == null;\n }\n return areFilesEqual(fileA, fileB);\n}\n\nfunction hasDiffContent({\n fileDiff,\n oldFile,\n newFile,\n}: HasContentProps): boolean {\n return (\n (fileDiff != null && fileDiff.hunks.length > 0) ||\n oldFile != null ||\n newFile != null\n );\n}\n\nfunction hasDiffHeaderContent({\n fileDiff,\n oldFile,\n newFile,\n}: HasContentProps): boolean {\n return fileDiff != null || oldFile != null || newFile != null;\n}\n\nfunction shouldRenderCode(\n pre: HTMLPreElement | undefined,\n hasContent: boolean,\n collapsed = false\n): boolean {\n return !collapsed && pre == null && hasContent;\n}\n\nfunction shouldRenderHeader(\n headerElement: HTMLElement | undefined,\n hasContent: boolean,\n disableFileHeader = false\n): boolean {\n return headerElement == null && hasContent && !disableFileHeader;\n}\n\nfunction getElementChildren(\n node: ElementContent | undefined\n): ElementContent[] | undefined {\n if (node == null || node.type !== 'element') {\n return undefined;\n }\n return node.children ?? [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwJA,SAAS,eAAe,UAAqC;CAC3D,OACE,SAAS,cACR,SAAS,SAAS,YACjB,SAAS,SAAS,oBAClB,SAAS,SAAS;AAExB;AAIA,SAAS,sBAAsB,UAA8C;CAC3E,MAAM,kBAAkB,EAAE,GAAG,SAAS;CACtC,OAAO,gBAAgB;CACvB,OAAO;AACT;AAEA,SAAS,qBACP,UACA,UACS;CACT,IAAI,SAAS,aAAa,SAAS,WACjC,MAAM,IAAI,MACR,yEACF;CAEF,MAAM,eAAe,SAAS,QAAQ,wBAAwB,SAAS,IAAI;CAC3E,MAAM,eAAe,SAAS,QAAQ,wBAAwB,SAAS,IAAI;CAC3E,MAAM,iBAAiB,SAAS,SAAS;CACzC,MAAM,iBAAiB,SAA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ACA,SACA,WAC2B;CAC3B,OAAO,YAAY,QAAQ,WAAW,QAAQ,WAAW;AAC3D;AAEA,SAAS,iBACP,KACA,YACA,YAAY,OACH;CACT,OAAO,CAAC,aAAa,OAAO,QAAQ;AACtC;AAEA,SAAS,mBACP,eACA,YACA,oBAAoB,OACX;CACT,OAAO,iBAAiB,QAAQ,cAAc,CAAC;AACjD;AAEA,SAAS,mBACP,MAC8B;CAC9B,IAAI,QAAQ,QAAQ,KAAK,SAAS,WAChC;CAEF,OAAO,KAAK,YAAY,CAAC;AAC3B"}
|
|
1
|
+
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n DIFFS_TAG_NAME,\n EMPTY_RENDER_RANGE,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n THEME_CSS_ATTRIBUTE,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport type { Editor } from '../editor/editor';\nimport type { TextDocument } from '../editor/textDocument';\nimport type {\n CapturedDiffSessionState,\n EditCompletionDecision,\n EditorActiveLineOptions,\n EditorChangeEvent,\n FileDiffEditCompleteEvent,\n RetainedDiffSessionSnapshot,\n} from '../editor/types';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport {\n type GetHoveredLineResult,\n type GetLineIndexUtility,\n InteractionManager,\n type InteractionManagerBaseOptions,\n pluckInteractionOptions,\n type SelectionWriteOptions,\n} from '../managers/InteractionManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { ScrollSyncManager } from '../managers/ScrollSyncManager';\nimport {\n dequeueRender,\n queueRender,\n} from '../managers/UniversalRenderingManager';\nimport {\n DiffHunksRenderer,\n type DiffHunksRendererOptions,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nexport type { FileDiffEditCompleteEvent } from '../editor/types';\nimport type {\n AppliedThemeStyleCache,\n BaseCodeOptions,\n BaseDiffOptions,\n CustomPreProperties,\n DiffLineAnnotation,\n ExpansionDirections,\n DiffsHighlighter,\n FileContents,\n FileDiffMetadata,\n HighlightedToken,\n HunkData,\n HunkSeparators,\n LineAnnotation,\n MaybeDiffFileInput,\n PostRenderPhase,\n PrePropertiesConfig,\n RenderHeaderFilenameSuffixCallback,\n RenderHeaderMetadataCallback,\n RenderHeaderPrefixCallback,\n RenderRange,\n SelectedLineRange,\n SelectionSide,\n ThemeTypes,\n} from '../types';\nimport { areDiffLineAnnotationsEqual } from '../utils/areDiffLineAnnotationsEqual';\nimport { areDiffTargetsEqual } from '../utils/areDiffTargetsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areHunkDataEqual } from '../utils/areHunkDataEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { awaitWithTimeout } from '../utils/awaitWithTimeout';\nimport {\n cloneFileDiffMetadata,\n cloneHunks,\n} from '../utils/cloneFileDiffMetadata';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createGutterUtilityContentNode } from '../utils/createGutterUtilityContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport {\n patchScrollbarGutterSize,\n wrapThemeCSS,\n wrapUnsafeCSS,\n} from '../utils/cssWrappers';\nimport {\n adoptEditSessionAnnotations,\n type EditSessionAnnotations,\n resolveEditSessionSlotName,\n writeEditSessionAnnotations,\n} from '../utils/editSessionAnnotations';\nimport {\n captureExpansionAnchors,\n finishEditSessionForDiff,\n rebuildExpansionFromAnchors,\n} from '../utils/editSessionHunks';\nimport { getDiffFileInput } from '../utils/getDiffFileInput';\nimport { getDiffHunksRendererOptions } from '../utils/getDiffHunksRendererOptions';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHunkSideStartBoundary } from '../utils/getHunkSideBoundaries';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { getThemes } from '../utils/getThemes';\nimport { guardWebKitScrollDuringRebuild } from '../utils/guardWebKitScrollDuringRebuild';\nimport { upsertHostThemeStyle } from '../utils/hostTheme';\nimport { hydratePartialDiff } from '../utils/hydratePartialDiff';\nimport { isDefaultRenderRange } from '../utils/isDefaultRenderRange';\nimport { isDiffPlainText } from '../utils/isDiffPlainText';\nimport { isStyleNode } from '../utils/isStyleNode';\nimport { iterateOverDiff } from '../utils/iterateOverDiff';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { isSafari } from '../utils/platform';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { getMeasuredScrollbarGutter } from '../utils/scrollbarGutter';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport { splitFileContents } from '../utils/splitFileContents';\nimport { recomputeDiffRenderLineCounts } from '../utils/updateDiffHunks';\nimport {\n getExpandedRegion,\n getHunkAdditionLineRange,\n getNearestRenderableAdditionLine,\n getTrailingExpandedRegion,\n isAdditionLineRenderable,\n} from '../utils/virtualDiffLayout';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\ntype LoadedPartialDiffContents = Awaited<\n ReturnType<NonNullable<BaseDiffOptions['loadDiffFiles']>>\n>;\n\ntype DeferredSelectedLinesWrite = [\n range: SelectedLineRange | null,\n options: SelectionWriteOptions | undefined,\n];\n\ntype DeferredEditorActiveLineWrite = [\n lineNumber: number | null,\n options: EditorActiveLineOptions | undefined,\n];\n\nfunction canHydrateDiff(fileDiff: FileDiffMetadata): boolean {\n return (\n fileDiff.isPartial &&\n (fileDiff.type === 'change' ||\n fileDiff.type === 'rename-changed' ||\n fileDiff.type === 'rename-pure')\n );\n}\n\n// Edit sessions incrementally clone the diff as needed while editing,\n// initially we start with a top level fast clone\nfunction createEditSessionDiff(fileDiff: FileDiffMetadata): FileDiffMetadata {\n const editSessionDiff = { ...fileDiff };\n delete editSessionDiff.cacheKey;\n return editSessionDiff;\n}\n\nfunction shouldResetUndoState(\n prevDiff: FileDiffMetadata,\n nextDiff: FileDiffMetadata\n): boolean {\n if (prevDiff.isPartial || nextDiff.isPartial) {\n throw new Error(\n 'FileDiff.shouldResetEditorForExternalDiff: diffs must be fully hydrated'\n );\n }\n const prevLanguage = prevDiff.lang ?? getFiletypeFromFileName(prevDiff.name);\n const nextLanguage = nextDiff.lang ?? getFiletypeFromFileName(nextDiff.name);\n const prevHasOldFile = prevDiff.type !== 'new';\n const nextHasOldFile = nextDiff.type !== 'new';\n if (\n prevDiff.name !== nextDiff.name ||\n prevLanguage !== nextLanguage ||\n prevHasOldFile !== nextHasOldFile ||\n prevDiff.deletionLines.length !== nextDiff.deletionLines.length\n ) {\n return true;\n }\n return prevDiff.deletionLines.some(\n (line, index) => line !== nextDiff.deletionLines[index]\n );\n}\n\nfunction areLinesEqual(first: string[], second: string[]): boolean {\n return (\n first.length === second.length &&\n first.every((line, index) => line === second[index])\n );\n}\n\n// There are certain scenarios where if a diff changes in a certain way, we\n// cannot consider the session resumable. Basically if the old file has\n// changed in any way (name or contents), then our restored diff would be\n// completely invalid\nfunction canRestoreDiffSession(\n snapshot: RetainedDiffSessionSnapshot,\n externalDiff: FileDiffMetadata\n): boolean {\n const { oldFile } = snapshot;\n if (oldFile == null) {\n return externalDiff.type === 'new';\n }\n return (\n externalDiff.type !== 'new' &&\n oldFile.name === (externalDiff.prevName ?? externalDiff.name) &&\n areLinesEqual(oldFile.lines, externalDiff.deletionLines)\n );\n}\n\nexport interface FileDiffRenderBaseProps<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n deferManagers?: boolean;\n forceRender?: boolean;\n preventEmit?: boolean;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n renderRange?: RenderRange;\n}\n\nexport type FileDiffRenderProps<LAnnotation> =\n FileDiffRenderBaseProps<LAnnotation> & MaybeDiffFileInput;\n\nexport type FileDiffHydrationProps<LAnnotation> = Omit<\n FileDiffRenderBaseProps<LAnnotation>,\n 'fileContainer'\n> &\n MaybeDiffFileInput & {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n };\n\nexport type FileDiffType = 'file-diff' | 'unresolved-file';\n\nexport type FileDiffEditChangeHandler<LAnnotation, Caret> = (\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n) => void;\n\n/**\n * Decides a completed edit synchronously: return `'accept'` to install the\n * event's `fileDiff` and annotations, or `'reject'` to restore the original\n * values. The event is frozen, so re-key the accepted diff in place\n * (`event.fileDiff.cacheKey = '…'`) before accepting. The event's editor is\n * detached and returns its final state from `getViewState()`. A missing handler\n * rejects.\n */\nexport type FileDiffEditCompleteHandler<LAnnotation, Caret> = (\n event: FileDiffEditCompleteEvent<LAnnotation, Caret>\n) => EditCompletionDecision;\n\nexport interface FileDiffOptions<LAnnotation, Caret>\n extends\n Omit<BaseDiffOptions, 'hunkSeparators'>,\n InteractionManagerBaseOptions<'diff'> {\n hunkSeparators?:\n | Exclude<HunkSeparators, 'custom'> /**\n * @deprecated Custom hunk separator functions are deprecated and will be\n * removed in a future version.\n */\n | ((\n hunk: HunkData,\n instance: FileDiff<LAnnotation, Caret>\n ) => HTMLElement | DocumentFragment | null | undefined);\n disableFileHeader?: boolean;\n renderHeaderPrefix?: RenderHeaderPrefixCallback;\n renderHeaderFilenameSuffix?: RenderHeaderFilenameSuffixCallback;\n renderHeaderMetadata?: RenderHeaderMetadataCallback;\n renderCustomHeader?: RenderHeaderMetadataCallback;\n /**\n * When true, errors during rendering are rethrown instead of being caught\n * and displayed in the DOM. Useful for testing or when you want to handle\n * errors yourself.\n */\n disableErrorHandling?: boolean;\n renderAnnotation?(\n annotation: DiffLineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderGutterUtility?(\n getHoveredRow: () => GetHoveredLineResult<'diff'> | undefined\n ): HTMLElement | null | undefined;\n\n onPostRender?(\n node: HTMLElement,\n instance: FileDiff<LAnnotation, Caret>,\n phase: PostRenderPhase\n ): unknown;\n\n /**\n * Fired for every document change of an active edit session on this\n * component, with the same `EditorChangeEvent` the editor reports through\n * its own `onChange`. Do not feed the event's file back into the component\n * while the session is active.\n */\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n\n /**\n * Fired when `edit` toggles false or a component unmounts, including when the\n * final contents are unchanged. If no callback is provided, the component\n * reverts to the last `fileDiff` or `oldFile`/`newFiles` and annotations\n * passed into it. The callback receives the detached editor with its final\n * pre-detach state.\n */\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: DiffLineAnnotation<LAnnotation>;\n}\n\ninterface CustomHunkElementCache {\n element: HTMLElement;\n hunkData: HunkData;\n}\n\ninterface ColumnElements {\n gutter: HTMLElement;\n content: HTMLElement;\n}\n\ninterface TrimColumnsToOverlapProps {\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements;\n diffStyle: 'split' | 'unified';\n overlapEnd: number;\n overlapStart: number;\n previousStart: number;\n trimEnd: number;\n trimStart: number;\n}\n\ninterface ApplyPartialRenderProps {\n fileDiff: FileDiffMetadata;\n previousRenderRange: RenderRange | undefined;\n renderRange: RenderRange | undefined;\n}\n\ninterface PendingFileLoad {\n fileDiff: FileDiffMetadata;\n promise: Promise<void>;\n}\n\ntype HydrationSetup<LAnnotation> = {\n fileDiff: FileDiffMetadata | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} & MaybeDiffFileInput;\n\ninterface HeaderCache {\n lastRenderedHTML: string | undefined;\n html: string | undefined;\n fileDiff: FileDiffMetadata | undefined;\n}\n\ninterface EditSession<LAnnotation> {\n diff: FileDiffMetadata;\n annotations:\n | EditSessionAnnotations<DiffLineAnnotation<LAnnotation>>\n | undefined;\n /*\n * `outgoingDiff` keeps the diff the document still holds (the render already\n * shows the new `diff`): its presence signals the pending replacement, and it\n * supplies the old-file side both for the undo-reset decision and for\n * capturing session state.\n */\n outgoingDiff: FileDiffMetadata | undefined;\n}\n\nlet instanceId = -1;\n\nexport class FileDiff<LAnnotation = undefined, Caret = undefined> {\n // NOTE(amadeus): We sorta need this to ensure the web-component file is\n // properly loaded\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file-diff:${++instanceId}`;\n readonly type: FileDiffType = 'file-diff';\n\n protected fileContainer: HTMLElement | undefined;\n protected spriteSVG: SVGElement | undefined;\n protected pre: HTMLPreElement | undefined;\n protected codeUnified: HTMLElement | undefined;\n protected codeDeletions: HTMLElement | undefined;\n protected codeAdditions: HTMLElement | undefined;\n protected bufferBefore: HTMLElement | undefined;\n protected bufferAfter: HTMLElement | undefined;\n protected themeCSSStyle: HTMLStyleElement | undefined;\n protected appliedThemeCSS: AppliedThemeStyleCache | undefined;\n protected hasAdoptedThemeCSS = false;\n protected unsafeCSSStyle: HTMLStyleElement | undefined;\n protected appliedUnsafeCSS: string | undefined;\n protected gutterUtilityContent: HTMLElement | undefined;\n\n protected headerElement: HTMLElement | undefined;\n protected headerPrefix: HTMLElement | undefined;\n protected headerFilenameSuffix: HTMLElement | undefined;\n protected headerMetadata: HTMLElement | undefined;\n protected headerCustom: HTMLElement | undefined;\n protected separatorCache: Map<string, CustomHunkElementCache> = new Map();\n protected errorWrapper: HTMLElement | undefined;\n protected placeHolder: HTMLElement | undefined;\n\n protected hunksRenderer: DiffHunksRenderer<LAnnotation>;\n protected resizeManager: ResizeManager;\n protected scrollSyncManager: ScrollSyncManager;\n protected interactionManager: InteractionManager<'diff'>;\n\n protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n protected lineAnnotations: DiffLineAnnotation<LAnnotation>[] = [];\n protected managersDirty = false;\n\n protected deletionFile?: FileContents | null;\n protected additionFile?: FileContents | null;\n public fileDiff: FileDiffMetadata | undefined;\n private editSession: EditSession<LAnnotation> | undefined;\n protected renderedDiff: FileDiffMetadata | undefined;\n protected renderRange: RenderRange | undefined;\n protected pendingFiles: PendingFileLoad | undefined;\n protected appliedPreAttributes: PrePropertiesConfig | undefined;\n protected headerCache: HeaderCache = {\n lastRenderedHTML: undefined,\n html: undefined,\n fileDiff: undefined,\n };\n protected lastRowCount: number | undefined;\n private mounted = false;\n\n protected enabled = true;\n\n protected editor: Editor<'file-diff', LAnnotation, Caret> | undefined;\n protected refreshViewTimeout: ReturnType<typeof setTimeout> | undefined;\n // Defer selected-line and editor active-line writes while a refresh rebuilds\n // the diff rows. This is separate from the timeout because the refresh can\n // escalate to a full rerender without one.\n protected lineStateRefreshPending = false;\n protected deferredSelectedLines: DeferredSelectedLinesWrite | undefined;\n protected deferredEditorActiveLine: DeferredEditorActiveLineWrite | undefined;\n\n constructor(\n public options: FileDiffOptions<LAnnotation, Caret> = {\n theme: DEFAULT_THEMES,\n },\n protected workerManager?: WorkerPoolManager | undefined,\n protected isContainerManaged = false\n ) {\n this.hunksRenderer = this.createHunksRenderer(options);\n this.resizeManager = new ResizeManager();\n this.scrollSyncManager = new ScrollSyncManager();\n this.interactionManager = new InteractionManager(\n 'diff',\n pluckInteractionOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info' ||\n options.hunkSeparators === 'line-info-basic'\n ? this.handleExpandHunk\n : undefined,\n this.getLineIndex\n )\n );\n this.workerManager?.subscribeToThemeChanges(this);\n this.enabled = true;\n }\n\n protected handleHighlightRender = (): void => {\n this.rerender();\n };\n\n private getTheme() {\n return (\n this.workerManager?.getDiffRenderOptions().theme ??\n this.options.theme ??\n DEFAULT_THEMES\n );\n }\n\n protected getHunksRendererOptions(\n options: FileDiffOptions<LAnnotation, Caret>\n ): DiffHunksRendererOptions {\n return getDiffHunksRendererOptions(options);\n }\n\n protected createHunksRenderer(\n options: FileDiffOptions<LAnnotation, Caret>\n ): DiffHunksRenderer<LAnnotation> {\n return new DiffHunksRenderer<LAnnotation>(\n this.getHunksRendererOptions(options),\n this.getAnnotationSlotName,\n this.handleHighlightRender,\n this.workerManager\n );\n }\n\n public getLineIndex: GetLineIndexUtility = (\n lineNumber: number,\n side: SelectionSide = 'additions'\n ) => {\n return this.getLineIndexForDiff(\n this.getDiffForLineIndex(),\n lineNumber,\n side\n );\n };\n\n protected getDiffForLineIndex(): FileDiffMetadata | undefined {\n return this.getRenderedDiff();\n }\n\n // Resolve source lines against the same diff that produced the rendered\n // rows. During an asynchronous replacement, that can be the previous diff.\n protected getLineIndexForDiff(\n fileDiff: FileDiffMetadata | undefined,\n lineNumber: number,\n side: SelectionSide\n ): [number, number] | undefined {\n if (fileDiff == null) {\n return undefined;\n }\n const lastHunk = fileDiff.hunks.at(-1);\n let targetUnifiedIndex: number | undefined;\n let targetSplitIndex: number | undefined;\n hunkIterator: for (const hunk of fileDiff.hunks) {\n const hunkStart =\n side === 'deletions' ? hunk.deletionStart : hunk.additionStart;\n const hunkCount =\n side === 'deletions' ? hunk.deletionCount : hunk.additionCount;\n let currentLineNumber =\n getHunkSideStartBoundary(hunkStart, hunkCount) + 1;\n let splitIndex = hunk.splitLineStart;\n let unifiedIndex = hunk.unifiedLineStart;\n\n // If we've selected a line between or before a hunk,\n // we should grab its index here\n if (lineNumber < currentLineNumber) {\n const difference = currentLineNumber - lineNumber;\n targetUnifiedIndex = Math.max(unifiedIndex - difference, 0);\n targetSplitIndex = Math.max(splitIndex - difference, 0);\n break hunkIterator;\n }\n\n if (lineNumber >= currentLineNumber + hunkCount) {\n if (hunk === lastHunk) {\n const difference = lineNumber - (currentLineNumber + hunkCount);\n targetUnifiedIndex =\n unifiedIndex + hunk.unifiedLineCount + difference;\n targetSplitIndex = splitIndex + hunk.splitLineCount + difference;\n break hunkIterator;\n }\n continue;\n }\n\n for (const content of hunk.hunkContent) {\n if (content.type === 'context') {\n if (lineNumber < currentLineNumber + content.lines) {\n const difference = lineNumber - currentLineNumber;\n targetSplitIndex = splitIndex + difference;\n targetUnifiedIndex = unifiedIndex + difference;\n break hunkIterator;\n } else {\n currentLineNumber += content.lines;\n splitIndex += content.lines;\n unifiedIndex += content.lines;\n }\n } else {\n const sideCount =\n side === 'deletions' ? content.deletions : content.additions;\n if (lineNumber < currentLineNumber + sideCount) {\n const indexDifference = lineNumber - currentLineNumber;\n targetUnifiedIndex =\n unifiedIndex +\n (side === 'additions' ? content.deletions : 0) +\n indexDifference;\n targetSplitIndex = splitIndex + indexDifference;\n\n break hunkIterator;\n } else {\n currentLineNumber += sideCount;\n splitIndex += Math.max(content.deletions, content.additions);\n unifiedIndex += content.deletions + content.additions;\n }\n }\n }\n\n break hunkIterator;\n }\n\n if (targetUnifiedIndex == null || targetSplitIndex == null) {\n return undefined;\n }\n return [targetUnifiedIndex, targetSplitIndex];\n }\n\n // FIXME(amadeus): This is a bit of a looming issue that I'll need to resolve:\n // * Do we publicly allow merging of options or do we have individualized setters?\n // * When setting new options, we need to figure out what settings require a\n // re-render and which can just be applied more elegantly\n // * There's also an issue of options that live here on the File class and\n // those that live on the Hunk class, and it's a bit of an issue with passing\n // settings down and mirroring them (not great...)\n public setOptions(\n options: FileDiffOptions<LAnnotation, Caret> | undefined\n ): void {\n if (options == null) return;\n this.options = options;\n this.clearReusableHeader();\n this.hunksRenderer.setOptions(this.getHunksRendererOptions(options));\n this.syncInteractionOptions();\n }\n\n protected syncInteractionOptions(): void {\n this.interactionManager.setOptions(\n pluckInteractionOptions(\n this.options,\n typeof this.options.hunkSeparators === 'function' ||\n (this.options.hunkSeparators ?? 'line-info') === 'line-info' ||\n this.options.hunkSeparators === 'line-info-basic'\n ? this.handleExpandHunk\n : undefined,\n this.getLineIndex\n )\n );\n }\n\n private mergeOptions(\n options: Partial<FileDiffOptions<LAnnotation, Caret>>\n ): void {\n this.options = { ...this.options, ...options };\n }\n\n public setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.applyCachedThemeState(themeType);\n }\n\n private applyCachedThemeState(themeType: ThemeTypes): boolean {\n if (\n typeof this.options.theme === 'string' ||\n this.fileContainer == null ||\n this.appliedThemeCSS == null\n ) {\n return false;\n }\n const effectiveThemeType = this.appliedThemeCSS.baseThemeType ?? themeType;\n if (this.appliedThemeCSS.themeType === effectiveThemeType) {\n return false;\n }\n this.applyThemeState(\n this.fileContainer,\n this.appliedThemeCSS.themeStyles,\n themeType,\n this.appliedThemeCSS.baseThemeType\n );\n return true;\n }\n\n private hasThemeChanged(): boolean {\n return (\n this.appliedThemeCSS != null &&\n !areThemesEqual(this.appliedThemeCSS.theme, this.getTheme())\n );\n }\n\n public getHoveredLine = (): GetHoveredLineResult<'diff'> | undefined => {\n return this.interactionManager.getHoveredLine();\n };\n\n public getAnnotationSlotName = (\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>\n ): string => {\n return resolveEditSessionSlotName(\n this.editSession?.annotations,\n annotation,\n getLineAnnotationName\n );\n };\n\n // Return the annotations this component currently renders. Once editing\n // starts, the private session state owns them.\n protected getLatestAnnotations(): DiffLineAnnotation<LAnnotation>[] {\n return this.editSession?.annotations?.current ?? this.lineAnnotations;\n }\n\n // Returns true when the caller passed annotations this component has not\n // handled yet. Re-renders often re-pass an annotations array the component\n // already holds — the external one, or one the active session tracks — and\n // treating those repeats as new writes would move annotations, so they are\n // recognized by identity and ignored.\n protected isNewAnnotations(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n const session = this.editSession?.annotations;\n const externalAnnotations = this.lineAnnotations;\n if (lineAnnotations === externalAnnotations) {\n return false;\n }\n return (\n session == null ||\n (lineAnnotations !== session.provided &&\n lineAnnotations !== session.current)\n );\n }\n\n public setLineAnnotations(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): void {\n const sessionAnnotations = this.editSession?.annotations;\n if (sessionAnnotations == null) {\n this.lineAnnotations = lineAnnotations;\n return;\n }\n if (!this.isNewAnnotations(lineAnnotations)) {\n return;\n }\n // Externally provided annotations are the source of truth: they become the\n // new external collection and the session renders them at the line numbers\n // given. The caller owns whether those positions still make sense after an\n // edit; a revert renders this collection unchanged rather than moving them.\n this.lineAnnotations = lineAnnotations;\n writeEditSessionAnnotations(\n sessionAnnotations,\n lineAnnotations,\n getLineAnnotationName\n );\n }\n\n // Takes annotations the editor remapped and makes them what the session\n // renders: updates the session, feeds the renderer, and re-renders\n // annotation rows. Returns true when new annotations were adopted —\n // virtualized subclasses override this and refresh their layout on true.\n //\n // The editor delivers annotations through two calls. An edit that changes\n // the line count sends them with the structural rebuild\n // (applyDocumentChange) and again with the change event (__acceptEditorChange);\n // the identity check makes the second call a no-op. An edit that keeps the\n // line count skips the rebuild, so the event is its only path here.\n //\n // The annotations the caller passed in are never touched — stale\n // re-renders keep deduping against them.\n protected syncEditSessionAnnotationsFromEditor(\n lineAnnotations: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n const session = this.editSession?.annotations;\n if (session == null || lineAnnotations === session.current) {\n return false;\n }\n session.current = lineAnnotations;\n this.hunksRenderer.setLineAnnotations(lineAnnotations);\n this.renderAnnotations();\n return true;\n }\n\n private canPartiallyRender(\n forceRender: boolean,\n annotationsChanged: boolean,\n didContentChange: boolean\n ): boolean {\n if (\n forceRender ||\n annotationsChanged ||\n didContentChange ||\n typeof this.options.hunkSeparators === 'function'\n ) {\n return false;\n }\n return true;\n }\n\n public setSelectedLines(\n range: SelectedLineRange | null,\n options?: SelectionWriteOptions\n ): void {\n if (this.lineStateRefreshPending) {\n this.deferredSelectedLines = [range, options];\n } else {\n this.interactionManager.setSelection(range, options);\n }\n }\n\n public setEditorActiveLine(\n lineNumber: number | null,\n options?: EditorActiveLineOptions\n ): void {\n if (this.lineStateRefreshPending) {\n this.deferredEditorActiveLine = [lineNumber, options];\n } else {\n this.interactionManager.setEditorActiveLine(lineNumber, {\n lineNumberOnly: options?.lineNumberOnly,\n side: options?.side ?? 'additions',\n });\n }\n }\n\n // A refresh can receive selected-lines and editor active-line writes in either\n // order. Apply the latest value from each after the rows are stable.\n protected flushDeferredLineState(): void {\n const {\n deferredEditorActiveLine: editorActiveLine,\n deferredSelectedLines: selectedLines,\n } = this;\n this.lineStateRefreshPending = false;\n this.deferredEditorActiveLine = undefined;\n this.deferredSelectedLines = undefined;\n\n if (editorActiveLine != null) {\n this.setEditorActiveLine(...editorActiveLine);\n }\n if (selectedLines != null) {\n this.interactionManager.setSelection(...selectedLines);\n }\n }\n\n public flushManagers(): void {\n if (!this.managersDirty || this.pre == null) {\n this.managersDirty = false;\n return;\n }\n\n const { diffStyle = 'split', overflow = 'scroll' } = this.options;\n this.interactionManager.setup(this.pre);\n this.resizeManager.setup(this.pre, {\n disableAnnotations: overflow === 'wrap',\n columnVariables: this.shouldApplyColumnVariables(overflow)\n ? 'apply'\n : 'measure',\n });\n if (overflow === 'scroll' && diffStyle === 'split') {\n this.scrollSyncManager.setup(\n this.pre,\n this.codeDeletions,\n this.codeAdditions\n );\n } else {\n this.scrollSyncManager.cleanUp();\n }\n this.managersDirty = false;\n }\n\n protected shouldApplyColumnVariables(overflow: 'scroll' | 'wrap'): boolean {\n if (typeof this.options.hunkSeparators === 'function') {\n return true;\n }\n return (\n overflow === 'scroll' &&\n (this.getLatestAnnotations().length > 0 ||\n this.pre?.hasAttribute('data-has-merge-conflict') === true)\n );\n }\n\n public getCodeScrollLeft(): number {\n return Math.max(\n this.codeUnified?.scrollLeft ?? 0,\n this.codeDeletions?.scrollLeft ?? 0,\n this.codeAdditions?.scrollLeft ?? 0\n );\n }\n\n public setCodeScrollLeft(position: number): void {\n if (this.codeUnified != null) {\n this.codeUnified.scrollLeft = position;\n }\n if (this.codeAdditions != null) {\n this.codeAdditions.scrollLeft = position;\n }\n if (this.codeDeletions != null) {\n this.codeDeletions.scrollLeft = position;\n }\n }\n\n public __getEffectiveCodeOptions(): BaseCodeOptions {\n return { ...this.options, ...this.hunksRenderer.getEffectiveCodeOptions() };\n }\n\n public cleanUp(recycle: boolean = false): void {\n const { editor } = this;\n dequeueRender(this.handleEditSessionRender);\n this.emitPostRender(true);\n // Tear the editor down while the code scrollers still exist. A recycle\n // keeps its document and undo history; a full teardown drops them as the\n // session ends.\n editor?.cleanUp(recycle ? 'recycle' : 'discard');\n if (!recycle) {\n this.editor = undefined;\n }\n this.resizeManager.cleanUp();\n this.interactionManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.managersDirty = false;\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.renderRange = undefined;\n if (!recycle) {\n this.pendingFiles = undefined;\n }\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.remove();\n }\n this.fileContainer = undefined;\n this.mounted = false;\n if (!recycle) {\n this.lineAnnotations = [];\n }\n this.clearAuxiliaryNodes();\n this.annotationCache.clear();\n this.pre = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n this.bufferBefore?.remove();\n this.bufferBefore = undefined;\n this.bufferAfter?.remove();\n this.bufferAfter = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n this.headerCache.lastRenderedHTML = undefined;\n if (!recycle) {\n this.clearReusableHeader();\n }\n this.errorWrapper?.remove();\n this.errorWrapper = undefined;\n this.spriteSVG = undefined;\n this.lastRowCount = undefined;\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n this.hasAdoptedThemeCSS = false;\n this.unsafeCSSStyle = undefined;\n this.appliedUnsafeCSS = undefined;\n\n if (recycle) {\n this.hunksRenderer.recycle();\n } else {\n this.hunksRenderer.cleanUp();\n this.workerManager = undefined;\n // Clean up the data\n this.fileDiff = undefined;\n this.editSession = undefined;\n this.renderedDiff = undefined;\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n this.refreshViewTimeout = undefined;\n }\n this.lineStateRefreshPending = false;\n this.deferredEditorActiveLine = undefined;\n this.deferredSelectedLines = undefined;\n this.enabled = false;\n }\n\n public virtualizedSetup(): void {\n this.enabled = true;\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n public hydrate({\n fileContainer,\n prerenderedHTML,\n preventEmit = false,\n lineAnnotations,\n fileDiff,\n ...fileInputProps\n }: FileDiffHydrationProps<LAnnotation>): void {\n if (!this.enabled) {\n throw new Error(\n 'FileDiff.hydrate: attempting to call hydrate after cleaned up'\n );\n }\n if (this.fileContainer != null) {\n throw new Error(\n 'FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated'\n );\n }\n const fileInput = getDiffFileInput(fileInputProps, 'FileDiff.hydrate');\n const oldFile = fileInput?.oldFile;\n const newFile = fileInput?.newFile;\n this.hydrateElements(fileContainer, prerenderedHTML);\n // An editor attached before hydration may carry a retained keyed document\n // and its session-shaped hunks. Render through that private session instead\n // of adopting external markup, so hydration cannot recompute or flash it.\n const forceEditorRender = this.editor != null;\n if (\n forceEditorRender ||\n shouldRenderCode(\n this.pre,\n hasDiffContent({ fileDiff, oldFile, newFile }),\n this.options.collapsed\n ) ||\n shouldRenderHeader(\n this.headerElement,\n hasDiffHeaderContent({ fileDiff, oldFile, newFile }),\n this.options.disableFileHeader\n )\n ) {\n this.render({\n ...fileInputProps,\n fileContainer,\n lineAnnotations,\n fileDiff,\n forceRender: forceEditorRender || fileInputProps.forceRender,\n preventEmit: true,\n });\n }\n // Otherwise orchestrate our setup\n else {\n this.hydrationSetup({\n fileDiff,\n lineAnnotations,\n ...fileInput,\n });\n }\n if (!preventEmit) {\n this.emitPostRender();\n }\n }\n\n protected hydrateElements(\n fileContainer: HTMLElement,\n prerenderedHTML: string | undefined\n ): void {\n if (this.fileContainer !== fileContainer) {\n this.emitPostRender(true);\n }\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of fileContainer.shadowRoot?.children ?? []) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n for (const code of element.children) {\n if (\n !(code instanceof HTMLElement) ||\n code.tagName.toLowerCase() !== 'code'\n ) {\n continue;\n }\n if ('deletions' in code.dataset) {\n this.codeDeletions = code;\n }\n if ('additions' in code.dataset) {\n this.codeAdditions = code;\n }\n if ('unified' in code.dataset) {\n this.codeUnified = code;\n }\n }\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(THEME_CSS_ATTRIBUTE)\n ) {\n this.themeCSSStyle = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n this.appliedUnsafeCSS = element.textContent;\n continue;\n }\n }\n if (this.pre != null) {\n this.syncCodeNodesFromPre(this.pre);\n this.pre.removeAttribute('data-dehydrated');\n }\n this.fileContainer = fileContainer;\n this.hydrateMeasuredScrollbar();\n }\n\n protected hydrationSetup({\n fileDiff,\n oldFile,\n newFile,\n lineAnnotations,\n }: HydrationSetup<LAnnotation>): void {\n // It's possible we are hydrating a pure-rename and therefore there will be\n // no pre element\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.additionFile = newFile;\n this.deletionFile = oldFile;\n this.fileDiff =\n fileDiff ??\n (oldFile !== undefined && newFile !== undefined\n ? parseDiffFromFile(oldFile, newFile, this.options.parseDiffOptions)\n : undefined);\n\n if (this.pre == null) {\n return;\n }\n\n this.syncInteractionOptions();\n this.hunksRenderer.hydrate(this.fileDiff);\n this.renderedDiff = this.fileDiff;\n // FIXME(amadeus): not sure how to handle this yet...\n // this.renderSeparators();\n this.renderAnnotations();\n this.renderGutterUtility();\n this.injectUnsafeCSS();\n this.managersDirty = true;\n this.flushManagers();\n }\n\n public rerender(): void {\n if (\n !this.enabled ||\n (this.fileDiff == null &&\n this.additionFile == null &&\n this.deletionFile == null)\n ) {\n return;\n }\n this.render({ forceRender: true, renderRange: this.renderRange });\n }\n\n public onThemeChange(): void {\n this.hunksRenderer.clearRenderCache();\n this.rerender();\n }\n\n // This wrapper must stay separate from `expandHunk` because subclasses like\n // `VirtualizedFileDiff` replace `expandHunk` with their own instance field\n // after `super()` returns. `InteractionManager` is created in this base\n // constructor, so it needs a stable callback that resolves `this.expandHunk`\n // at click time instead of capturing the base implementation too early.\n public handleExpandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections,\n expansionLineCountOverride?: number\n ): void => {\n this.expandHunk(hunkIndex, direction, expansionLineCountOverride);\n };\n\n public expandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections,\n expansionLineCountOverride?: number\n ): void => {\n this.hunksRenderer.expandHunk(\n hunkIndex,\n direction,\n expansionLineCountOverride\n );\n this.loadFilesIfNecessary();\n this.rerender();\n };\n\n protected loadFilesIfNecessary(): void {\n const {\n fileDiff,\n options: { loadDiffFiles },\n } = this;\n if (\n fileDiff == null ||\n loadDiffFiles == null ||\n !canHydrateDiff(fileDiff) ||\n this.pendingFiles?.fileDiff === fileDiff\n ) {\n return;\n }\n\n const promise = this.loadFilesForDiff(fileDiff, loadDiffFiles);\n const pendingFiles: PendingFileLoad = (this.pendingFiles = {\n fileDiff,\n promise,\n });\n // Track the exact request object so an older completion for the same diff\n // cannot clear a newer request.\n const clearPendingFiles = (): void => {\n if (this.pendingFiles === pendingFiles) {\n this.pendingFiles = undefined;\n }\n };\n pendingFiles.promise = promise.finally(clearPendingFiles);\n }\n\n private async loadFilesForDiff(\n fileDiff: FileDiffMetadata,\n loadDiffFiles: NonNullable<BaseDiffOptions['loadDiffFiles']>\n ): Promise<void> {\n try {\n const files = await loadDiffFiles(fileDiff);\n if (!this.enabled || this.fileDiff !== fileDiff) {\n return;\n }\n\n await this.handleFilesLoaded(fileDiff, files);\n } catch (error: unknown) {\n if (this.options.disableErrorHandling === true) {\n throw error;\n }\n console.error(error);\n }\n }\n\n protected async handleFilesLoaded(\n expectedDiff: FileDiffMetadata,\n files: LoadedPartialDiffContents\n ): Promise<void> {\n if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) {\n return;\n }\n hydratePartialDiff('merge', expectedDiff, files);\n this.setHydratedState(files);\n if (this.startHydratedEditSession(expectedDiff)) {\n this.rerender();\n return;\n }\n await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));\n if (!this.enabled || this.fileDiff !== expectedDiff) {\n return;\n }\n this.rerender();\n }\n\n // Start editing from an already hydrated `this.fileDiff`. The keyless\n // shallow copy shares nested data until an edit needs to change it.\n protected startHydratedEditSession(expectedDiff: FileDiffMetadata): boolean {\n if (expectedDiff.isPartial) {\n throw new Error(\n 'FileDiff.startHydratedEditSession: diffs cannot be partial for editing'\n );\n }\n if (this.fileDiff !== expectedDiff) {\n return false;\n }\n const { editor } = this;\n if (this.editSession?.outgoingDiff != null) {\n this.installEditSession(expectedDiff);\n return true;\n }\n if (editor == null || this.editSession != null) {\n return false;\n }\n this.installEditSession(\n expectedDiff,\n editor.__getDocumentContents(getAdditionFile(expectedDiff)),\n editor.__getDocumentSessionState()\n );\n return true;\n }\n\n // Install a replacement diff from the caller; returns false when it is the\n // diff already installed. During an edit session the diff the editor's\n // document still holds is kept as `outgoingDiff` until the editor syncs, so\n // it can decide whether the swap keeps or resets undo history.\n protected updateExternalDiff(\n incomingExternalDiff: FileDiffMetadata,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): boolean {\n if (areDiffTargetsEqual(this.fileDiff, incomingExternalDiff)) {\n return false;\n }\n\n const outgoingDiff =\n this.editSession?.outgoingDiff ?? this.editSession?.diff;\n\n this.fileDiff = incomingExternalDiff;\n if (outgoingDiff != null) {\n if (incomingExternalDiff.isPartial) {\n this.loadFilesIfNecessary();\n } else {\n this.installEditSession(incomingExternalDiff);\n }\n if (this.editSession != null) {\n this.editSession.outgoingDiff = outgoingDiff;\n }\n } else if (this.editor != null) {\n if (incomingExternalDiff.isPartial) {\n this.loadFilesIfNecessary();\n } else {\n this.installEditSession(\n incomingExternalDiff,\n this.editor.__getDocumentContents(\n getAdditionFile(incomingExternalDiff)\n ),\n this.editor.__getDocumentSessionState()\n );\n }\n }\n if (this.editSession?.annotations != null && lineAnnotations != null) {\n // These annotations arrived with the new diff, so their line numbers\n // describe it. The positions the session tracked for the old document\n // mean nothing now: the session restarts from these annotations, and\n // they also become what renders once the session ends.\n this.lineAnnotations = lineAnnotations;\n this.editSession.annotations = adoptEditSessionAnnotations(\n lineAnnotations,\n getLineAnnotationName,\n this.editSession.annotations\n );\n }\n return true;\n }\n\n // When an editor opens a document saved under a document key,\n // `retainedDocument` restores its text and undo history. It is omitted when\n // replacing the diff in an open editor so the replacement is handled as a\n // new external update instead of overwriting the document being edited.\n private installEditSession(\n externalDiff: FileDiffMetadata,\n retainedDocument?: FileContents,\n retainedSession?: RetainedDiffSessionSnapshot\n ): void {\n const externalContents = externalDiff.additionLines.join('');\n const retainedLines =\n retainedDocument != null\n ? splitFileContents(retainedDocument.contents)\n : undefined;\n const restoreRetainedSession =\n retainedSession != null &&\n canRestoreDiffSession(retainedSession, externalDiff);\n if (retainedSession != null && !restoreRetainedSession) {\n throw new Error(\n 'FileDiff: retained session cannot resume against a different old file'\n );\n }\n if (\n retainedDocument != null &&\n retainedDocument.contents !== externalContents &&\n !restoreRetainedSession\n ) {\n throw new Error(\n 'FileDiff: retained edits are missing their diff session state'\n );\n }\n const usesExternalDocument =\n retainedDocument == null ||\n (retainedDocument.name === externalDiff.name &&\n retainedDocument.lang === externalDiff.lang &&\n retainedDocument.contents === externalContents);\n const sessionDiff = createEditSessionDiff(externalDiff);\n if (\n retainedDocument != null &&\n retainedLines != null &&\n !usesExternalDocument\n ) {\n sessionDiff.name = retainedDocument.name;\n sessionDiff.lang = retainedDocument.lang;\n }\n if (\n restoreRetainedSession &&\n retainedSession != null &&\n retainedLines != null\n ) {\n sessionDiff.additionLines = retainedLines;\n sessionDiff.type = retainedSession.type;\n sessionDiff.hunks = retainedSession.hunks;\n sessionDiff.editSessionDirty = true;\n recomputeDiffRenderLineCounts(sessionDiff);\n }\n this.editSession = {\n diff: sessionDiff,\n // Seed annotations when the session is created so the adopt-block in\n // updateExternalDiff fires on the next external update — this is what an\n // attach-before-hydrate (React) mount relies on, since the session does\n // not exist yet at attach. A live session keeps the ones it tracks.\n annotations:\n this.editSession?.annotations ??\n adoptEditSessionAnnotations(\n this.lineAnnotations,\n getLineAnnotationName\n ),\n outgoingDiff: this.editSession?.outgoingDiff,\n };\n this.hunksRenderer.beginEditSession(\n sessionDiff,\n usesExternalDocument && !restoreRetainedSession ? externalDiff : undefined\n );\n }\n\n protected setHydratedState(files: LoadedPartialDiffContents): void {\n this.deletionFile = files.oldFile;\n this.additionFile = files.newFile;\n this.workerManager?.cleanUpTasks(this.hunksRenderer);\n this.hunksRenderer.clearRenderCache();\n }\n\n public render({\n fileDiff,\n deferManagers = false,\n forceRender = false,\n preventEmit = false,\n lineAnnotations,\n fileContainer,\n containerWrapper,\n renderRange,\n ...fileInputProps\n }: FileDiffRenderProps<LAnnotation>): boolean {\n if (!this.enabled) {\n // NOTE(amadeus): May need to be a silent failure? Making it loud for now\n // to better understand it\n throw new Error(\n 'FileDiff.render: attempting to call render after cleaned up'\n );\n }\n\n const fileInput = getDiffFileInput(fileInputProps, 'FileDiff.render');\n const oldFile = fileInput?.oldFile;\n const newFile = fileInput?.newFile;\n\n // postpone background tokenizing to next frame for avoiding UI freeze\n // during render\n this.editor?.__postponeBgTokenizeToNextFrame();\n\n const {\n collapsed = false,\n themeType = 'system',\n expandUnchanged = false,\n } = this.options;\n const nextRenderRange = collapsed ? undefined : renderRange;\n const themeChanged = this.hasThemeChanged();\n const hasFileInput = fileInput != null;\n const filesDidChange =\n hasFileInput &&\n (!areOptionalFilesEqual(oldFile, this.deletionFile) ||\n !areOptionalFilesEqual(newFile, this.additionFile));\n let diffDidChange =\n fileDiff != null && !areDiffTargetsEqual(fileDiff, this.fileDiff);\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.getLatestAnnotations().length > 0)\n ? this.isNewAnnotations(lineAnnotations)\n : false;\n\n if (\n !collapsed &&\n areRenderRangesEqual(nextRenderRange, this.renderRange) &&\n !forceRender &&\n !annotationsChanged &&\n !themeChanged &&\n // If using the fileDiff API, lets check to see if they are equal to\n // avoid doing work\n ((fileDiff != null && !diffDidChange) ||\n // If using the oldFile/newFile API then lets check to see if they are\n // equal\n (fileDiff == null && !filesDidChange))\n ) {\n const rendered = this.applyCachedThemeState(themeType);\n if (rendered) {\n this.finalizeRender();\n }\n return rendered;\n }\n\n let nextParsedFileDiff: FileDiffMetadata | undefined;\n if (\n fileDiff == null &&\n hasFileInput &&\n (filesDidChange || this.fileDiff == null)\n ) {\n nextParsedFileDiff = parseDiffFromFile(\n fileInput.oldFile,\n fileInput.newFile,\n this.options.parseDiffOptions\n );\n }\n\n const { renderRange: previousRenderRange } = this;\n this.renderRange = nextRenderRange;\n // Store files only when this render actually carried a file input:\n // internal rerenders pass none, and wiping the pair here would defeat the\n // oldFile/newFile early-return on every later host render. An explicit\n // fileDiff input supersedes a previously parsed pair, so clear it then.\n if (hasFileInput) {\n this.deletionFile = oldFile;\n this.additionFile = newFile;\n } else if (fileDiff != null) {\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n\n if (fileDiff != null && diffDidChange) {\n this.updateExternalDiff(fileDiff, lineAnnotations);\n } else if (nextParsedFileDiff != null) {\n diffDidChange = true;\n this.updateExternalDiff(nextParsedFileDiff, lineAnnotations);\n }\n if (diffDidChange) {\n this.clearReusableHeader();\n }\n\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n\n const latestDiff = this.getLatestDiff();\n if (latestDiff == null) {\n return false;\n }\n // Backstop for sessions that ended without their exit hook running (e.g.\n // session-shaped metadata reused after a host teardown): restore\n // recompute-shaped hunks before rendering.\n if (\n latestDiff.editSessionDirty === true &&\n this.shouldSelfHealEditSession()\n ) {\n finishEditSessionForDiff(latestDiff, this.options.parseDiffOptions);\n void this.hunksRenderer.refreshHighlightedResult();\n }\n if (expandUnchanged) {\n this.loadFilesIfNecessary();\n }\n this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));\n this.syncInteractionOptions();\n\n this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());\n\n const { disableErrorHandling = false, disableFileHeader = false } =\n this.options;\n\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.remove();\n this.headerElement = undefined;\n this.headerCache.lastRenderedHTML = undefined;\n }\n this.clearHeaderSlots();\n }\n fileContainer = this.getOrCreateFileContainer(\n fileContainer,\n containerWrapper\n );\n this.applyCachedThemeState(themeType);\n\n if (collapsed) {\n this.removeRenderedCode();\n this.clearAuxiliaryNodes();\n\n try {\n const hunksResult = this.hunksRenderer.renderDiff(\n latestDiff,\n EMPTY_RENDER_RANGE\n );\n if (hunksResult != null) {\n this.applyThemeState(\n fileContainer,\n hunksResult.themeStyles,\n themeType,\n hunksResult.baseThemeType\n );\n }\n if (hunksResult?.headerElement != null) {\n this.applyHeaderToDOM(\n hunksResult.headerElement,\n fileContainer,\n hunksResult.fileDiff\n );\n }\n this.renderSeparators([]);\n this.renderedDiff = hunksResult?.fileDiff ?? latestDiff;\n this.injectUnsafeCSS();\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n this.finalizeRender();\n if (!preventEmit) {\n this.emitPostRender();\n }\n return true;\n }\n\n try {\n const pre = this.getOrCreatePreNode(fileContainer);\n\n // Attempt to partially render\n const didPartiallyRender =\n this.canPartiallyRender(\n forceRender,\n annotationsChanged,\n filesDidChange ||\n diffDidChange ||\n themeChanged ||\n !areDiffTargetsEqual(this.renderedDiff, latestDiff)\n ) &&\n this.applyPartialRender({\n fileDiff: latestDiff,\n previousRenderRange,\n renderRange: nextRenderRange,\n });\n\n // If we were unable to partially render, perform a full render\n if (!didPartiallyRender) {\n const hunksResult = this.hunksRenderer.renderDiff(\n latestDiff,\n nextRenderRange\n );\n if (hunksResult == null) {\n if (\n this.workerManager?.isInitialized() === false &&\n this.workerManager.isWorkingPool()\n ) {\n void this.workerManager\n .initialize()\n .catch(() => {})\n .then(() => this.rerender());\n }\n return false;\n }\n\n this.applyThemeState(\n fileContainer,\n hunksResult.themeStyles,\n themeType,\n hunksResult.baseThemeType\n );\n\n if (hunksResult.headerElement != null) {\n this.applyHeaderToDOM(\n hunksResult.headerElement,\n fileContainer,\n hunksResult.fileDiff\n );\n }\n if (\n hunksResult.additionsContentAST != null ||\n hunksResult.deletionsContentAST != null ||\n hunksResult.unifiedContentAST != null\n ) {\n this.applyHunksToDOM(pre, hunksResult);\n } else if (this.pre != null) {\n this.pre.remove();\n this.pre = undefined;\n }\n this.renderSeparators(hunksResult.hunkData);\n this.renderedDiff = hunksResult.fileDiff;\n }\n this.applyBuffers(pre, nextRenderRange);\n this.injectUnsafeCSS();\n this.renderAnnotations();\n this.renderGutterUtility();\n\n this.managersDirty = true;\n if (!deferManagers) {\n this.flushManagers();\n }\n\n this.finalizeRender();\n if (this.editor != null) {\n this.syncRenderViewToEditor();\n }\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n if (!preventEmit) {\n this.emitPostRender();\n }\n return true;\n }\n\n protected finalizeRender(): void {}\n\n protected emitPostRender(unmount = false): void {\n const {\n fileContainer,\n options: { onPostRender },\n } = this;\n\n if (unmount) {\n if (!this.mounted) {\n return;\n }\n this.mounted = false;\n if (fileContainer == null) {\n return;\n }\n this.options.onPostRender?.(fileContainer, this, 'unmount');\n return;\n }\n\n if (fileContainer == null) {\n return;\n }\n\n const phase: PostRenderPhase = this.mounted ? 'update' : 'mount';\n this.mounted = true;\n onPostRender?.(fileContainer, this, phase);\n }\n\n // Return the newest diff this component intends to display. An active edit\n // session owns that state instead of the caller-provided diff.\n protected getLatestDiff(\n fileDiff: FileDiffMetadata | undefined = this.fileDiff\n ): FileDiffMetadata | undefined {\n return this.editSession?.diff ?? fileDiff;\n }\n\n // Return the diff that produced the DOM currently owned by this instance.\n // It can trail getLatestDiff while replacement highlighting is pending.\n protected getRenderedDiff(): FileDiffMetadata | undefined {\n return this.renderedDiff;\n }\n\n private syncRenderViewToEditor(): void {\n const { editor, fileContainer } = this;\n const lineAnnotations = this.getLatestAnnotations();\n const renderRange = this.computeEditorRenderRange(this.renderRange);\n const fileDiff = this.getLatestDiff();\n if (\n editor == null ||\n fileContainer == null ||\n fileDiff == null ||\n fileDiff.isPartial\n ) {\n return;\n }\n const sync = (highlighter: DiffsHighlighter): void => {\n if (\n !this.enabled ||\n this.editor !== editor ||\n this.fileContainer !== fileContainer ||\n this.getLatestDiff() !== fileDiff\n ) {\n return;\n }\n const replacement = this.editSession?.outgoingDiff;\n const externalDiff = this.fileDiff;\n const externalDocument =\n replacement != null && externalDiff != null && replacement !== fileDiff;\n const resetHistory = externalDocument\n ? shouldResetUndoState(replacement, externalDiff)\n : false;\n editor.__syncRenderView({\n highlighter,\n fileContainer,\n fileDiff,\n lineAnnotations,\n renderRange,\n externalDocument,\n resetHistory,\n });\n };\n const theme = this.getTheme();\n const lang = fileDiff.lang ?? getFiletypeFromFileName(fileDiff.name);\n // Sync synchronously whenever the shared highlighter is ready; otherwise\n // load it and sync once it resolves.\n const highlighter = getHighlighterIfLoaded({ theme, lang });\n if (highlighter != null) {\n sync(highlighter);\n } else {\n void getSharedHighlighter({\n themes: getThemes(theme),\n langs: ['text', lang],\n preferredHighlighter:\n this.workerManager?.getPreferredHighlighter() ??\n this.options.preferredHighlighter,\n }).then(sync);\n }\n }\n\n // The stored render range is in rendered-row units for the windowed AST\n // pipeline, but the editor consumes render ranges in document-line units.\n // Derive the addition-side document window covered by the rendered rows:\n // startingLine = first addition line with a row in the window, totalLines =\n // last such line - first + 1, and 0 when the window holds no addition rows\n // (e.g. a pure-deletion run taller than the viewport).\n private computeEditorRenderRange(\n renderRange: RenderRange | undefined\n ): RenderRange | undefined {\n const fileDiff = this.getLatestDiff();\n if (\n renderRange == null ||\n fileDiff == null ||\n isDefaultRenderRange(renderRange)\n ) {\n return renderRange;\n }\n const {\n diffStyle = 'split',\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n let firstLineNumber: number | undefined;\n let lastLineNumber: number | undefined;\n iterateOverDiff({\n diff: fileDiff,\n diffStyle,\n startingLine: renderRange.startingLine,\n totalLines: renderRange.totalLines,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n callback: ({ additionLine }) => {\n if (additionLine != null) {\n firstLineNumber ??= additionLine.lineNumber;\n lastLineNumber = additionLine.lineNumber;\n }\n },\n });\n if (firstLineNumber == null || lastLineNumber == null) {\n return { ...renderRange, startingLine: 0, totalLines: 0 };\n }\n return {\n ...renderRange,\n startingLine: firstLineNumber - 1,\n totalLines: lastLineNumber - firstLineNumber + 1,\n };\n }\n\n /** @internal The editor applied or edited past the pending external replacement. */\n public __acknowledgeDocumentUpdate(): void {\n if (this.editSession != null) {\n this.editSession.outgoingDiff = undefined;\n }\n }\n\n /** @internal Settle annotations locally. */\n public __acceptEditorChange(\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n ): void {\n const { lineAnnotations } = event;\n if (lineAnnotations != null) {\n this.syncEditSessionAnnotationsFromEditor(lineAnnotations);\n }\n }\n\n public emitEditChange(\n event: EditorChangeEvent<'file-diff', LAnnotation, Caret>\n ): void {\n const { onEditChange } = this.options;\n onEditChange?.(event);\n }\n\n /**\n * @internal Capture the current diff session, or return `undefined` when no\n * complete compatible session exists.\n *\n * When `clone` is true, the returned lines and hunks are copied.\n */\n public __captureDocumentSessionState(\n clone = true\n ): CapturedDiffSessionState | undefined {\n let { fileDiff, editSession: { diff: sessionDiff, outgoingDiff } = {} } =\n this;\n if (outgoingDiff != null && fileDiff != null) {\n if (!fileDiff.isPartial && shouldResetUndoState(outgoingDiff, fileDiff)) {\n return undefined;\n }\n sessionDiff = outgoingDiff;\n }\n if (sessionDiff == null || sessionDiff.isPartial) {\n return undefined;\n }\n return {\n diffSession: {\n oldFile:\n sessionDiff.type !== 'new'\n ? {\n name: sessionDiff.prevName ?? sessionDiff.name,\n lines: clone\n ? [...sessionDiff.deletionLines]\n : sessionDiff.deletionLines,\n }\n : null,\n type: sessionDiff.type,\n hunks: clone ? cloneHunks(sessionDiff.hunks) : sessionDiff.hunks,\n },\n hasChanges: sessionDiff.editSessionDirty === true,\n };\n }\n\n /** @internal Associate this component with its editor for a render lifecycle. */\n public __attachEditor(\n editor: Editor<'file-diff', LAnnotation, Caret>\n ): () => void {\n // Editing is a plain file-diff concern only. Subclasses with their own\n // hunk semantics (UnresolvedFile) are not editable, so an editor must\n // never attach to them.\n if (this.type !== 'file-diff') {\n throw new Error(\n `FileDiff.__attachEditor: cannot attach an editor to a \"${this.type}\" diff`\n );\n }\n if (this.editor != null) {\n throw new Error('FileDiff.__attachEditor: an editor is already attached');\n }\n const detach = () => {\n this.editor = undefined;\n this.finishEditSession();\n };\n try {\n this.resumeEditorRendering(editor);\n return detach;\n } catch (error) {\n detach();\n throw error;\n }\n }\n\n /** @internal Resume rendering for the editor already associated with this component. */\n public __resumeEditor(editor: Editor<'file-diff', LAnnotation, Caret>): void {\n if (this.editor !== editor) {\n throw new Error('FileDiff.__resumeEditor: editor association changed');\n }\n this.resumeEditorRendering(editor);\n }\n\n private resumeEditorRendering(\n editor: Editor<'file-diff', LAnnotation, Caret>\n ): void {\n const { fileDiff: externalDiff } = this;\n const pendingReplacement = this.editSession?.outgoingDiff;\n // A pending replacement whose diff was partial when it arrived installs now\n // that we are (re)attaching with a hydrated diff.\n if (\n pendingReplacement != null &&\n externalDiff != null &&\n !externalDiff.isPartial &&\n this.editSession?.diff === pendingReplacement\n ) {\n this.installEditSession(externalDiff);\n }\n const initialExternalDiff =\n this.editSession == null &&\n externalDiff != null &&\n !externalDiff.isPartial\n ? externalDiff\n : undefined;\n if (initialExternalDiff != null) {\n this.installEditSession(\n initialExternalDiff,\n editor.__getDocumentContents(getAdditionFile(initialExternalDiff)),\n editor.__getDocumentSessionState()\n );\n } else if (this.editSession != null) {\n this.hunksRenderer.beginEditSession(this.editSession.diff);\n }\n this.editor = editor;\n // The editor sync below refuses partial diffs (it needs the full file\n // contents); kick off hydration so the loaded re-render re-runs it.\n if (this.fileDiff?.isPartial === true) {\n this.loadFilesIfNecessary();\n }\n const editSessionDiff = this.editSession?.diff;\n if (this.hunksRenderer.editorRenderReady()) {\n // Compatible markup can be reused without repainting. Once the renderer\n // transfers that cache to the private session, the existing DOM belongs\n // to the session as well.\n if (\n editSessionDiff != null &&\n this.hunksRenderer.diffCache === editSessionDiff\n ) {\n this.renderedDiff = editSessionDiff;\n }\n this.syncRenderViewToEditor();\n } else {\n // The current markup is missing the editor's token metadata, or its\n // highlight is still pending: render through the session, which also\n // syncs the render view once it paints.\n this.rerender();\n }\n }\n\n // Session exit for the live detach path.\n private finishEditSession(): void {\n this.hunksRenderer.endEditSession();\n this.finalizeEditSessionHunks();\n }\n\n /**\n * @internal\n *\n * Ends the edit session and settles which diff this component renders.\n * Requires the editor to be detached first. Does nothing when no session\n * exists, so callers can invoke it again safely after it has settled.\n *\n * `onEditComplete` receives the completed diff, current external diff,\n * complete file pair, and both annotation collections even when the final\n * text is unchanged. In `install` mode, accepting installs the completed diff\n * and its annotations; rejecting or having no handler restores the external\n * values. `discard` mode always restores the external values. An accepted\n * diff cannot reuse the replaced diff's `cacheKey`.\n */\n public __completeEditSession(\n editor: Editor<'file-diff', LAnnotation, Caret>,\n mode: 'install' | 'discard'\n ): void {\n this.settleEditSession(mode === 'install', editor);\n }\n\n private settleEditSession(\n installResult: boolean,\n editor: Editor<'file-diff', LAnnotation, Caret> | undefined\n ): void {\n const {\n editSession,\n fileDiff: externalDiff,\n lineAnnotations: externalAnnotations,\n } = this;\n if (editSession == null || externalDiff == null) {\n return;\n }\n const { diff: editSessionDiff, annotations: editSessionAnnotations } =\n editSession;\n if (this.editor != null) {\n throw new Error(\n 'FileDiff.__completeEditSession: detach the editor before completing the session'\n );\n }\n this.hunksRenderer.endEditSession();\n this.finalizeEditSessionHunks();\n\n const sessionAnnotationsCurrent = editSessionAnnotations?.current;\n let acceptedDiff: FileDiffMetadata | undefined;\n let acceptedOldFile: FileContents | null = null;\n let acceptedNewFile: FileContents | null = null;\n let failed = false;\n let failure: unknown;\n if (editor == null) {\n throw new Error(\n 'FileDiff.__completeEditSession: editor is required for completion'\n );\n }\n const completedDiff = cloneFileDiffMetadata(editSessionDiff);\n const newFile: FileContents = {\n name: completedDiff.name,\n contents: completedDiff.additionLines.join(''),\n };\n if (completedDiff.lang != null) {\n newFile.lang = completedDiff.lang;\n }\n const event: FileDiffEditCompleteEvent<LAnnotation, Caret> = {\n fileDiff: completedDiff,\n editor,\n originalFileDiff: externalDiff,\n oldFile:\n completedDiff.type === 'new'\n ? null\n : {\n name: completedDiff.prevName ?? completedDiff.name,\n contents: completedDiff.deletionLines.join(''),\n },\n newFile,\n lineAnnotations: sessionAnnotationsCurrent,\n originalLineAnnotations: externalAnnotations,\n };\n // Frozen so a handler cannot swap the event's fileDiff/originalFileDiff\n // references; nested mutation (i.e. a fresh cacheKey on event.fileDiff)\n // still works.\n Object.freeze(event);\n try {\n editor.__emitEditComplete(event);\n const decision = this.options.onEditComplete?.(event);\n if (decision === 'accept') {\n if (\n completedDiff.cacheKey != null &&\n completedDiff.cacheKey === externalDiff.cacheKey\n ) {\n throw new Error(\n 'FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey'\n );\n }\n acceptedDiff = completedDiff;\n acceptedOldFile = event.oldFile;\n acceptedNewFile = event.newFile;\n }\n } catch (error) {\n failed = true;\n failure = error;\n }\n\n if (installResult && acceptedDiff != null) {\n this.fileDiff = acceptedDiff;\n // Callers using the oldFile/newFile API get the stored pair\n // refreshed so their next render with the event's files does not\n // reparse over the accepted diff. Every editable pair has a new\n // side (deleted files cannot be edited), so that is the check.\n if (this.additionFile != null) {\n this.deletionFile = acceptedOldFile;\n this.additionFile = acceptedNewFile;\n }\n if (sessionAnnotationsCurrent != null) {\n this.lineAnnotations = sessionAnnotationsCurrent;\n }\n }\n this.editSession = undefined;\n if (installResult && this.fileContainer != null) {\n this.rerender();\n }\n if (failed) {\n throw failure;\n }\n }\n\n /**\n * Run the session-end recompute: restore recompute-shaped hunks (a\n * context-only region collapses away, boundaries re-derive), preserve\n * expansion state best-effort via old-side anchors, and repaint through\n * the session render path — which also invalidates virtualized layout,\n * since nothing else does at exit now that editing does not flip\n * expandUnchanged. Marker-guarded and idempotent; CodeView also calls this\n * when ending a session whose detach closure was consumed by a recycle.\n * Safe on a cleaned-up instance: the recompute is pure metadata work and\n * the deferred rerender is enabled-guarded. Returns true when a recompute\n * ran.\n */\n public finalizeEditSessionHunks(): boolean {\n const fileDiff = this.getLatestDiff();\n if (fileDiff == null || fileDiff.editSessionDirty !== true) {\n return false;\n }\n const { collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD } =\n this.options;\n const anchors = captureExpansionAnchors(\n fileDiff,\n this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold\n );\n finishEditSessionForDiff(fileDiff, this.options.parseDiffOptions);\n this.hunksRenderer.setExpandedHunksMap(\n rebuildExpansionFromAnchors(fileDiff, anchors)\n );\n void this.hunksRenderer.refreshHighlightedResult();\n this.escalateEditSessionRender();\n return true;\n }\n\n // normally triggered by the host when the document line count changes\n public applyDocumentChange(\n textDocument: TextDocument<'file-diff', LAnnotation>,\n newLineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void {\n const editSessionDiff = this.editSession?.diff;\n if (editSessionDiff == null) {\n throw new Error(\n 'FileDiff.applyDocumentChange: requires an active edit session'\n );\n }\n this.detachAdditionLines();\n this.hunksRenderer.beginEditSession(editSessionDiff);\n this.hunksRenderer.applyDocumentChange(textDocument);\n if (newLineAnnotations != null) {\n this.syncEditSessionAnnotationsFromEditor(newLineAnnotations);\n }\n this.rerender();\n this.interactionManager.setSelectionDirty();\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light',\n options: {\n shouldRefreshDiffsView?: boolean;\n lineCountChangeInFlight?: boolean;\n } = {}\n ): void {\n const editSessionDiff = this.editSession?.diff;\n if (editSessionDiff == null) {\n throw new Error(\n 'FileDiff.updateRenderCache: requires an active edit session'\n );\n }\n this.detachAdditionLines();\n this.hunksRenderer.beginEditSession(editSessionDiff);\n const { shouldRefreshDiffsView, lineCountChangeInFlight } = options;\n const regionsChanged = this.hunksRenderer.updateRenderCache(\n dirtyLines,\n themeType,\n lineCountChangeInFlight\n );\n // A same-line-count edit that reshaped the session regions (an edit into\n // a collapsed gap) changes the rendered row set, which the debounced\n // line-type refresh below cannot express. Escalate to a deferred full\n // re-render — never a synchronous one, since this runs mid-editor-pass\n // and rebuilding rows the editor is about to touch detaches its geometry\n // caches.\n if (regionsChanged) {\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n this.refreshViewTimeout = undefined;\n }\n this.lineStateRefreshPending = true;\n this.escalateEditSessionRender();\n return;\n }\n if (shouldRefreshDiffsView === true) {\n if (this.refreshViewTimeout != null) {\n clearTimeout(this.refreshViewTimeout);\n }\n this.lineStateRefreshPending = true;\n this.refreshViewTimeout = setTimeout(() => {\n this.refreshViewTimeout = undefined;\n if (this.options.diffStyle === 'split') {\n this.refreshSplitDiffView();\n } else {\n this.refreshUnifiedDiffView();\n }\n this.flushDeferredLineState();\n }, 150);\n }\n }\n\n private detachAdditionLines(): void {\n const editSessionDiff = this.editSession?.diff;\n const { fileDiff } = this;\n if (\n editSessionDiff != null &&\n (editSessionDiff.additionLines === fileDiff?.additionLines ||\n editSessionDiff.additionLines === editSessionDiff.deletionLines)\n ) {\n editSessionDiff.additionLines = [...editSessionDiff.additionLines];\n }\n }\n\n // Editor-facing visibility oracle: whether a one-based new-file line has\n // (or will have on scroll) a rendered row under the current expansion\n // state. See isAdditionLineRenderable.\n public isLineRenderable(lineNumber: number): boolean {\n const fileDiff = this.getRenderedDiff();\n if (fileDiff == null) {\n return true;\n }\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n return isAdditionLineRenderable({\n fileDiff,\n lineNumber,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n });\n }\n\n // Fold-skip companion to isLineRenderable: the nearest renderable one-based\n // new-file line at or beyond lineNumber in the given direction.\n public getNearestRenderableLine(\n lineNumber: number,\n direction: 'up' | 'down'\n ): number | undefined {\n const fileDiff = this.getRenderedDiff();\n if (fileDiff == null) {\n return lineNumber;\n }\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n } = this.options;\n return getNearestRenderableAdditionLine({\n fileDiff,\n lineNumber,\n direction,\n expandedHunks: expandUnchanged\n ? true\n : this.hunksRenderer.getExpandedHunksMap(),\n collapsedContextThreshold,\n });\n }\n\n // Expand collapsed context so a one-based new-file line can render: one\n // deterministic expansion from the nearest gap edge, sized to reach the\n // target plus the normal expansion step (clamped to the gap at render).\n // Routed through expandHunk so subclass expansion flows (CodeView's\n // deferred pendingExpansions) apply.\n public revealLine(lineNumber: number): boolean {\n const fileDiff = this.getRenderedDiff();\n const {\n expandUnchanged = false,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n expansionLineCount = 100,\n } = this.options;\n if (fileDiff == null || fileDiff.isPartial || expandUnchanged) {\n return false;\n }\n const expandedHunks = this.hunksRenderer.getExpandedHunksMap();\n\n for (const [hunkIndex, hunk] of fileDiff.hunks.entries()) {\n const [hunkStart, hunkEnd] = getHunkAdditionLineRange(hunk);\n if (lineNumber < hunkStart) {\n const region = getExpandedRegion({\n isPartial: fileDiff.isPartial,\n rangeSize: hunk.collapsedBefore,\n expandedHunks,\n hunkIndex,\n collapsedContextThreshold,\n });\n const gapStart = hunkStart - region.rangeSize;\n if (\n region.renderAll ||\n lineNumber < gapStart + region.fromStart ||\n lineNumber >= hunkStart - region.fromEnd\n ) {\n return false;\n }\n const fromStartDistance =\n lineNumber - (gapStart + region.fromStart) + 1;\n const fromEndDistance = hunkStart - region.fromEnd - lineNumber;\n if (fromStartDistance <= fromEndDistance) {\n this.expandHunk(\n hunkIndex,\n 'up',\n fromStartDistance + expansionLineCount\n );\n } else {\n this.expandHunk(\n hunkIndex,\n 'down',\n fromEndDistance + expansionLineCount\n );\n }\n return true;\n }\n if (lineNumber < hunkEnd) {\n return false;\n }\n }\n\n const trailingRegion = getTrailingExpandedRegion({\n fileDiff,\n hunkIndex: fileDiff.hunks.length - 1,\n expandedHunks,\n collapsedContextThreshold,\n errorPrefix: 'FileDiff.revealLine',\n });\n if (trailingRegion == null || trailingRegion.renderAll) {\n return false;\n }\n const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];\n const [, trailingStart] = getHunkAdditionLineRange(lastHunk);\n if (\n lineNumber < trailingStart + trailingRegion.fromStart ||\n lineNumber >= trailingStart + trailingRegion.rangeSize\n ) {\n return false;\n }\n this.expandHunk(\n fileDiff.hunks.length,\n 'up',\n lineNumber -\n (trailingStart + trailingRegion.fromStart) +\n 1 +\n expansionLineCount\n );\n return true;\n }\n\n // Whether render() may run the session-exit recompute on dirty metadata.\n // False while an editor is attached (the session is live). CodeView-managed\n // instances override this: their sessions survive recycling with no editor\n // attached, and CodeView runs the exit recompute itself when it reaps a\n // session.\n protected shouldSelfHealEditSession(): boolean {\n return this.editor == null;\n }\n\n // Deferred full re-render for session region changes. The subsequent\n // render() ends in syncRenderViewToEditor, which resets the editor's\n // geometry caches against the rebuilt rows. VirtualizedFileDiff overrides\n // this to also invalidate its layout caches.\n protected escalateEditSessionRender(): void {\n queueRender(this.handleEditSessionRender);\n }\n\n private handleEditSessionRender = (): void => {\n this.rerender();\n this.flushDeferredLineState();\n };\n\n private removeRenderedCode(): void {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.interactionManager.cleanUp();\n\n this.bufferBefore?.remove();\n this.bufferBefore = undefined;\n this.bufferAfter?.remove();\n this.bufferAfter = undefined;\n\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n\n this.pre?.remove();\n this.pre = undefined;\n\n this.appliedPreAttributes = undefined;\n this.lastRowCount = undefined;\n }\n\n private clearAuxiliaryNodes(): void {\n for (const { element } of this.separatorCache.values()) {\n element.remove();\n }\n this.separatorCache.clear();\n\n for (const { element } of this.annotationCache.values()) {\n element.remove();\n }\n this.annotationCache.clear();\n\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n }\n\n public renderPlaceholder(height: number): boolean {\n if (this.fileContainer == null) {\n return false;\n }\n this.emitPostRender(true);\n this.cleanChildNodes();\n\n if (this.placeHolder == null) {\n const shadowRoot =\n this.fileContainer.shadowRoot ??\n this.fileContainer.attachShadow({ mode: 'open' });\n this.placeHolder = document.createElement('div');\n this.placeHolder.dataset.placeholder = '';\n shadowRoot.appendChild(this.placeHolder);\n }\n return this.setPlaceholderHeight(height);\n }\n\n protected setPlaceholderHeight(height: number): boolean {\n if (this.placeHolder == null) {\n return false;\n }\n this.placeHolder.style.setProperty('height', `${height}px`);\n return true;\n }\n\n public async primeHighlightCache(\n fileDiff: FileDiffMetadata | undefined = this.fileDiff\n ): Promise<void> {\n const { workerManager } = this;\n if (\n fileDiff == null ||\n workerManager == null ||\n !workerManager.isWorkingPool() ||\n fileDiff.cacheKey == null ||\n isDiffPlainText(fileDiff)\n ) {\n return;\n }\n const tokenizeMaxLength =\n this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n if (\n Math.max(fileDiff.additionLines.length, fileDiff.deletionLines.length) >\n tokenizeMaxLength\n ) {\n return;\n }\n\n await workerManager\n .primeDiffHighlightCache(fileDiff)\n .catch((error: unknown) => {\n console.error(error);\n });\n }\n\n private cleanChildNodes() {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.interactionManager.cleanUp();\n this.clearAuxiliaryNodes();\n\n this.bufferAfter?.remove();\n this.bufferBefore?.remove();\n this.codeAdditions?.remove();\n this.codeDeletions?.remove();\n this.codeUnified?.remove();\n this.errorWrapper?.remove();\n this.headerElement?.remove();\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerCustom?.remove();\n this.pre?.remove();\n this.spriteSVG?.remove();\n this.themeCSSStyle?.remove();\n this.unsafeCSSStyle?.remove();\n\n this.bufferAfter = undefined;\n this.bufferBefore = undefined;\n this.codeAdditions = undefined;\n this.codeDeletions = undefined;\n this.codeUnified = undefined;\n this.errorWrapper = undefined;\n this.headerElement = undefined;\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n this.pre = undefined;\n this.spriteSVG = undefined;\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n this.hasAdoptedThemeCSS = false;\n this.unsafeCSSStyle = undefined;\n this.appliedUnsafeCSS = undefined;\n\n this.headerCache.lastRenderedHTML = undefined;\n this.lastRowCount = undefined;\n this.mounted = false;\n }\n\n private renderSeparators(hunkData: HunkData[]): void {\n const { hunkSeparators } = this.options;\n if (\n this.isContainerManaged ||\n this.fileContainer == null ||\n typeof hunkSeparators !== 'function'\n ) {\n for (const { element } of this.separatorCache.values()) {\n element.remove();\n }\n this.separatorCache.clear();\n return;\n }\n const staleSeparators = new Map(this.separatorCache);\n for (const hunk of hunkData) {\n const id = hunk.slotName;\n let cache = this.separatorCache.get(id);\n if (cache == null || !areHunkDataEqual(hunk, cache.hunkData)) {\n cache?.element.remove();\n const element = document.createElement('div');\n element.style.display = 'contents';\n element.slot = hunk.slotName;\n const child = hunkSeparators(hunk, this);\n if (child != null) {\n element.appendChild(child);\n }\n this.fileContainer.appendChild(element);\n cache = { element, hunkData: hunk };\n this.separatorCache.set(id, cache);\n }\n staleSeparators.delete(id);\n }\n for (const [id, { element }] of staleSeparators.entries()) {\n this.separatorCache.delete(id);\n element.remove();\n }\n }\n\n protected renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.remove();\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n const lineAnnotations = this.getLatestAnnotations();\n if (renderAnnotation != null && lineAnnotations.length > 0) {\n for (const [index, annotation] of lineAnnotations.entries()) {\n const name = this.getAnnotationSlotName(annotation);\n const id = `${index}-${name}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areDiffLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.remove();\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(name),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.remove();\n }\n }\n\n protected renderGutterUtility(): void {\n const { renderGutterUtility } = this.options;\n if (this.fileContainer == null || renderGutterUtility == null) {\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n return;\n }\n const element = renderGutterUtility(this.interactionManager.getHoveredLine);\n if (element != null && this.gutterUtilityContent != null) {\n return;\n } else if (element == null) {\n this.gutterUtilityContent?.remove();\n this.gutterUtilityContent = undefined;\n return;\n }\n const gutterUtilityContent = createGutterUtilityContentNode();\n gutterUtilityContent.appendChild(element);\n this.fileContainer.appendChild(gutterUtilityContent);\n this.gutterUtilityContent = gutterUtilityContent;\n }\n\n protected getOrCreateFileContainer(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const { fileContainer: previousContainer } = this;\n const nextContainer =\n fileContainer ??\n previousContainer ??\n document.createElement(DIFFS_TAG_NAME);\n const containerChanged = previousContainer !== nextContainer;\n if (previousContainer != null && containerChanged) {\n this.editor?.__captureFocusForDOMReplacement();\n }\n if (containerChanged) {\n this.emitPostRender(true);\n }\n this.fileContainer = nextContainer;\n if (previousContainer != null && containerChanged) {\n this.headerCache.lastRenderedHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (containerChanged) {\n this.adoptReusableShellElements(this.fileContainer);\n }\n this.ensureSpriteSVG(this.fileContainer);\n return this.fileContainer;\n }\n\n // NOTE(amadeus): Technically this method is not safe for use outside of\n // the CodeView component, however I don't think in practice it really\n // should matter, but maybe there's some system we need in place to prevent\n // this from running outside of that environment?\n //\n // It's making very specific assumptions that all the elements will have the\n // correct content based on CodeView global options\n private adoptReusableShellElements(fileContainer: HTMLElement): void {\n const { shadowRoot } = fileContainer;\n if (shadowRoot == null) {\n return;\n }\n\n for (const element of shadowRoot.children) {\n if (element instanceof SVGElement) {\n this.spriteSVG ??= element;\n } else if (\n isStyleNode(element) &&\n element.hasAttribute(THEME_CSS_ATTRIBUTE)\n ) {\n this.themeCSSStyle ??= element;\n this.hasAdoptedThemeCSS = true;\n } else if (\n isStyleNode(element) &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle ??= element;\n this.appliedUnsafeCSS ??= this.options.unsafeCSS ?? undefined;\n }\n }\n }\n\n private ensureSpriteSVG(fileContainer: HTMLElement): void {\n const shadowRoot =\n fileContainer.shadowRoot ?? fileContainer.attachShadow({ mode: 'open' });\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n }\n }\n if (this.spriteSVG != null && this.spriteSVG.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.spriteSVG);\n }\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n this.appliedPreAttributes = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n shadowRoot.appendChild(this.pre);\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== shadowRoot) {\n this.editor?.__captureFocusForDOMReplacement();\n shadowRoot.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n\n return this.pre;\n }\n\n protected syncCodeNodesFromPre(pre: HTMLPreElement): void {\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n for (const child of Array.from(pre.children)) {\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n if (child.hasAttribute('data-unified')) {\n this.codeUnified = child;\n } else if (child.hasAttribute('data-deletions')) {\n this.codeDeletions = child;\n } else if (child.hasAttribute('data-additions')) {\n this.codeAdditions = child;\n }\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement,\n fileDiff: FileDiffMetadata\n ): void {\n this.cleanupErrorWrapper();\n this.placeHolder?.remove();\n this.placeHolder = undefined;\n // Session metadata changes in place, so an HTML cache created from the\n // external diff cannot describe the current edit-session header.\n const {\n headerCache: {\n fileDiff: cachedHeaderDiff,\n html: cachedHeaderHTML,\n lastRenderedHTML,\n },\n } = this;\n const editSessionDiff = this.editSession?.diff;\n const reusableHeaderHTML =\n fileDiff !== editSessionDiff &&\n areDiffTargetsEqual(cachedHeaderDiff, fileDiff)\n ? cachedHeaderHTML\n : undefined;\n const headerHTML = reusableHeaderHTML ?? toHtml(headerAST);\n this.headerCache.html = headerHTML;\n this.headerCache.fileDiff = fileDiff;\n if (headerHTML !== lastRenderedHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.headerCache.lastRenderedHTML = headerHTML;\n }\n\n if (this.isContainerManaged) {\n return;\n }\n\n const {\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n } = this.options;\n\n if (renderCustomHeader != null) {\n const content = renderCustomHeader(fileDiff) ?? undefined;\n this.headerCustom = this.upsertHeaderSlotElement(\n container,\n this.headerCustom,\n CUSTOM_HEADER_SLOT_ID,\n content\n );\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n return;\n }\n\n const prefix = renderHeaderPrefix?.(fileDiff) ?? undefined;\n const suffix = renderHeaderFilenameSuffix?.(fileDiff) ?? undefined;\n const content = renderHeaderMetadata?.(fileDiff) ?? undefined;\n this.headerPrefix = this.upsertHeaderSlotElement(\n container,\n this.headerPrefix,\n HEADER_PREFIX_SLOT_ID,\n prefix\n );\n this.headerFilenameSuffix = this.upsertHeaderSlotElement(\n container,\n this.headerFilenameSuffix,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n suffix\n );\n this.headerMetadata = this.upsertHeaderSlotElement(\n container,\n this.headerMetadata,\n HEADER_METADATA_SLOT_ID,\n content\n );\n this.headerCustom?.remove();\n this.headerCustom = undefined;\n }\n\n protected clearReusableHeader(): void {\n this.headerCache.html = undefined;\n this.headerCache.fileDiff = undefined;\n }\n\n private clearHeaderSlots(): void {\n this.headerPrefix?.remove();\n this.headerFilenameSuffix?.remove();\n this.headerMetadata?.remove();\n this.headerCustom?.remove();\n this.headerPrefix = undefined;\n this.headerFilenameSuffix = undefined;\n this.headerMetadata = undefined;\n this.headerCustom = undefined;\n }\n\n // Header slot callbacks are presence-based render hooks, not reactive views.\n private upsertHeaderSlotElement(\n container: HTMLElement,\n current: HTMLElement | undefined,\n slot: string,\n content: Element | string | number | undefined\n ): HTMLElement | undefined {\n if (content == null) {\n current?.remove();\n return undefined;\n }\n const element = current ?? this.createHeaderSlotElement(slot);\n if (current == null) {\n container.appendChild(element);\n }\n this.replaceHeaderSlotContent(element, content);\n return element;\n }\n\n private replaceHeaderSlotContent(\n element: HTMLElement,\n content: Element | string | number\n ): void {\n element.replaceChildren();\n if (content instanceof Element) {\n element.appendChild(content);\n } else {\n element.innerText = `${content}`;\n }\n }\n\n private createHeaderSlotElement(slot: string): HTMLElement {\n const element = document.createElement('div');\n element.slot = slot;\n return element;\n }\n\n protected injectUnsafeCSS(): void {\n const { unsafeCSS } = this.options;\n const shadowRoot = this.fileContainer?.shadowRoot;\n if (shadowRoot == null) {\n return;\n }\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.remove();\n this.unsafeCSSStyle = undefined;\n }\n this.appliedUnsafeCSS = undefined;\n return;\n }\n\n if (\n this.unsafeCSSStyle?.parentNode === shadowRoot &&\n this.appliedUnsafeCSS === unsafeCSS\n ) {\n return;\n }\n\n // Create or update the style element\n this.unsafeCSSStyle ??= createUnsafeCSSStyleNode();\n if (this.unsafeCSSStyle.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.textContent = wrapUnsafeCSS(unsafeCSS);\n this.appliedUnsafeCSS = unsafeCSS;\n }\n\n private applyThemeState(\n container: HTMLElement,\n themeStyles: string,\n themeType: ThemeTypes,\n baseThemeType?: 'light' | 'dark'\n ): void {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const effectiveThemeType = baseThemeType ?? themeType;\n const currentTheme = this.getTheme();\n const theme =\n typeof currentTheme === 'string' ? currentTheme : { ...currentTheme };\n const scrollbarGutter = getMeasuredScrollbarGutter(shadowRoot);\n if (\n this.themeCSSStyle?.parentNode === shadowRoot &&\n this.appliedThemeCSS?.themeStyles === themeStyles &&\n this.appliedThemeCSS.themeType === effectiveThemeType &&\n this.appliedThemeCSS.scrollbarGutter === scrollbarGutter\n ) {\n this.appliedThemeCSS.theme = theme;\n return;\n }\n if (\n this.hasAdoptedThemeCSS &&\n this.themeCSSStyle?.parentNode === shadowRoot\n ) {\n this.hasAdoptedThemeCSS = false;\n this.appliedThemeCSS = {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n };\n return;\n }\n this.themeCSSStyle = upsertHostThemeStyle({\n shadowRoot,\n currentNode: this.themeCSSStyle,\n themeCSS: wrapThemeCSS(themeStyles, effectiveThemeType, scrollbarGutter),\n });\n this.appliedThemeCSS =\n this.themeCSSStyle != null\n ? {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n }\n : undefined;\n }\n\n private hydrateMeasuredScrollbar(): void {\n const shadowRoot = this.fileContainer?.shadowRoot;\n if (shadowRoot == null || this.themeCSSStyle == null) {\n return;\n }\n this.themeCSSStyle.textContent = patchScrollbarGutterSize(\n this.themeCSSStyle.textContent ?? '',\n getMeasuredScrollbarGutter(shadowRoot)\n );\n }\n\n // A boolean check to ensure that edit mode in WebKit doesn't cause potential\n // scroll jumps to due bugs with WebKit. The workarounds have performance\n // implications so we avoid running the workarounds on browsers or scenarios\n // where they are not applicable\n protected shouldGuardRebuildScroll(): boolean {\n return this.editor != null && isSafari();\n }\n\n private applyHunksToDOM(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n if (this.shouldGuardRebuildScroll()) {\n guardWebKitScrollDuringRebuild(pre, () =>\n this.replaceCodeColumns(pre, result)\n );\n } else {\n this.replaceCodeColumns(pre, result);\n }\n }\n\n // Renders a code column's AST into an existing elements without replacing\n // the gutter and content parents. Identity matters in edit mode: the content\n // element is the focused contenteditable, and replacing it ends the\n // browser's editing session — focus tears down and restores, and iOS\n // answers every session restart with an animated caret reveal.\n //\n // Returns false when the element has no column pair yet (initial render,\n // or a diff-style switch built a fresh element); the caller then assigns\n // the full innerHTML.\n private applyCodeColumnsInPlace(\n code: HTMLElement,\n ast: ElementContent[],\n rowCount: number\n ): boolean {\n const columns = this.getColumnPair(code);\n if (columns == null) {\n return false;\n }\n const gutterChildren = getElementChildren(ast[0]);\n const contentChildren = getElementChildren(ast[1]);\n if (gutterChildren == null || contentChildren == null) {\n return false;\n }\n columns.gutter.innerHTML = toHtml(gutterChildren);\n columns.content.innerHTML = toHtml(contentChildren);\n if (rowCount !== this.lastRowCount) {\n columns.gutter.style.setProperty('grid-row', `span ${rowCount}`);\n columns.content.style.setProperty('grid-row', `span ${rowCount}`);\n }\n return true;\n }\n\n private replaceCodeColumns(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n const { overflow = 'scroll' } = this.options;\n const containerSize =\n (this.options.hunkSeparators ?? 'line-info') === 'line-info';\n const rowSpan = overflow === 'wrap' ? result.rowCount : undefined;\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n\n let shouldReplace = false;\n // Create code elements and insert HTML content\n const codeElements: HTMLElement[] = [];\n const unifiedAST = this.hunksRenderer.renderCodeAST('unified', result);\n const deletionsAST = this.hunksRenderer.renderCodeAST('deletions', result);\n const additionsAST = this.hunksRenderer.renderCodeAST('additions', result);\n this.editor?.__captureFocusForDOMReplacement();\n if (unifiedAST != null) {\n shouldReplace =\n this.codeUnified == null ||\n this.codeAdditions != null ||\n this.codeDeletions != null;\n\n // Clean up addition/deletion elements if necessary\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n\n this.codeUnified = getOrCreateCodeNode({\n code: this.codeUnified,\n columnType: 'unified',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeUnified,\n unifiedAST,\n result.rowCount\n )\n ) {\n this.codeUnified.innerHTML =\n this.hunksRenderer.renderPartialHTML(unifiedAST);\n }\n codeElements.push(this.codeUnified);\n } else if (deletionsAST != null || additionsAST != null) {\n if (deletionsAST != null) {\n shouldReplace = this.codeDeletions == null || this.codeUnified != null;\n\n // Clean up unified column if necessary\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n\n this.codeDeletions = getOrCreateCodeNode({\n code: this.codeDeletions,\n columnType: 'deletions',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeDeletions,\n deletionsAST,\n result.rowCount\n )\n ) {\n this.codeDeletions.innerHTML =\n this.hunksRenderer.renderPartialHTML(deletionsAST);\n }\n codeElements.push(this.codeDeletions);\n } else {\n // If we have no deletion column, lets clean it up if it exists\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n }\n\n if (additionsAST != null) {\n shouldReplace =\n shouldReplace ||\n this.codeAdditions == null ||\n this.codeUnified != null;\n\n // Clean up unified column if necessary\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n\n this.codeAdditions = getOrCreateCodeNode({\n code: this.codeAdditions,\n columnType: 'additions',\n rowSpan,\n containerSize,\n });\n if (\n !this.applyCodeColumnsInPlace(\n this.codeAdditions,\n additionsAST,\n result.rowCount\n )\n ) {\n this.codeAdditions.innerHTML =\n this.hunksRenderer.renderPartialHTML(additionsAST);\n }\n codeElements.push(this.codeAdditions);\n } else {\n // If we have no addition column, lets clean it up if it exists\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n }\n } else {\n // if we get in here, there's no content to render, so lets just clean\n // everything up\n this.codeUnified?.remove();\n this.codeUnified = undefined;\n this.codeDeletions?.remove();\n this.codeDeletions = undefined;\n this.codeAdditions?.remove();\n this.codeAdditions = undefined;\n }\n\n if (codeElements.length === 0) {\n pre.textContent = '';\n } else if (shouldReplace) {\n pre.replaceChildren(...codeElements);\n }\n\n this.lastRowCount = result.rowCount;\n }\n\n private applyPartialRender({\n fileDiff,\n previousRenderRange,\n renderRange,\n }: ApplyPartialRenderProps): boolean {\n const {\n pre,\n codeUnified,\n codeAdditions,\n codeDeletions,\n options: { diffStyle = 'split' },\n } = this;\n if (\n pre == null ||\n // We must have a current and previous render range to do a partial render\n previousRenderRange == null ||\n renderRange == null ||\n // Neither render range may be infinite\n !Number.isFinite(previousRenderRange.totalLines) ||\n !Number.isFinite(renderRange.totalLines) ||\n this.lastRowCount == null\n ) {\n return false;\n }\n const codeElements = this.getCodeColumns(\n diffStyle,\n codeUnified,\n codeDeletions,\n codeAdditions\n );\n if (codeElements == null) {\n return false;\n }\n\n const previousStart = previousRenderRange.startingLine;\n const nextStart = renderRange.startingLine;\n const previousEnd = previousStart + previousRenderRange.totalLines;\n const nextEnd = nextStart + renderRange.totalLines;\n\n const overlapStart = Math.max(previousStart, nextStart);\n const overlapEnd = Math.min(previousEnd, nextEnd);\n if (overlapEnd <= overlapStart) {\n return false;\n }\n\n const trimStart = Math.max(0, overlapStart - previousStart);\n const trimEnd = Math.max(0, previousEnd - overlapEnd);\n\n const trimResult = this.trimColumns({\n columns: codeElements,\n trimStart,\n trimEnd,\n previousStart,\n overlapStart,\n overlapEnd,\n diffStyle,\n });\n if (trimResult < 0) {\n throw new Error('FileDiff.applyPartialRender: failed to trim to overlap');\n }\n\n if (this.lastRowCount < trimResult) {\n throw new Error(\n 'FileDiff.applyPartialRender: trimmed beyond DOM row count'\n );\n }\n\n let rowCount = this.lastRowCount - trimResult;\n const renderChunk = (\n startingLine: number,\n totalLines: number\n ): HunksRenderResult | undefined => {\n if (totalLines <= 0) {\n return undefined;\n }\n return this.hunksRenderer.renderDiff(fileDiff, {\n startingLine,\n totalLines,\n bufferBefore: 0,\n bufferAfter: 0,\n });\n };\n\n const prependResult = renderChunk(\n nextStart,\n Math.max(overlapStart - nextStart, 0)\n );\n if (prependResult == null && nextStart < overlapStart) {\n return false;\n }\n\n const appendResult = renderChunk(\n overlapEnd,\n Math.max(nextEnd - overlapEnd, 0)\n );\n if (appendResult == null && nextEnd > overlapEnd) {\n return false;\n }\n\n const applyChunk = (\n result: HunksRenderResult | undefined,\n insertPosition: 'afterbegin' | 'beforeend'\n ) => {\n if (result == null) {\n return;\n }\n if (diffStyle === 'unified' && !Array.isArray(codeElements)) {\n this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);\n } else if (diffStyle === 'split' && Array.isArray(codeElements)) {\n this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);\n } else {\n throw new Error(\n 'FileDiff.applyPartialRender.applyChunk: invalid chunk application'\n );\n }\n rowCount += result.rowCount;\n this.renderedDiff = result.fileDiff;\n };\n\n this.cleanupErrorWrapper();\n applyChunk(prependResult, 'afterbegin');\n applyChunk(appendResult, 'beforeend');\n\n if (this.lastRowCount !== rowCount) {\n this.applyRowSpan(diffStyle, codeElements, rowCount);\n this.lastRowCount = rowCount;\n }\n\n return true;\n }\n\n private insertPartialHTML(\n diffStyle: 'unified',\n columns: ColumnElements,\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void;\n private insertPartialHTML(\n diffStyle: 'split',\n columns: [ColumnElements | undefined, ColumnElements | undefined],\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void;\n private insertPartialHTML(\n diffStyle: 'split' | 'unified',\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements,\n result: HunksRenderResult,\n insertPosition: 'afterbegin' | 'beforeend'\n ): void {\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n const unifiedAST = this.hunksRenderer.renderCodeAST('unified', result);\n this.renderPartialColumn(columns, unifiedAST, insertPosition);\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n const deletionsAST = this.hunksRenderer.renderCodeAST(\n 'deletions',\n result\n );\n const additionsAST = this.hunksRenderer.renderCodeAST(\n 'additions',\n result\n );\n this.renderPartialColumn(columns[0], deletionsAST, insertPosition);\n this.renderPartialColumn(columns[1], additionsAST, insertPosition);\n } else {\n throw new Error(\n 'FileDiff.insertPartialHTML: Invalid argument composition'\n );\n }\n }\n\n // fast refresh diff view via updating the `data-line-type` after an edit.\n // only for split view.\n private refreshSplitDiffView(): void {\n const fileDiff = this.getLatestDiff();\n if (this.options.diffStyle !== 'split' || fileDiff == null) {\n return;\n }\n\n const hunksResult = this.hunksRenderer.renderDiff(\n fileDiff,\n this.renderRange\n );\n if (hunksResult == null) {\n return;\n }\n\n const columns = this.getCodeColumns(\n 'split',\n this.codeUnified,\n this.codeDeletions,\n this.codeAdditions\n );\n if (!Array.isArray(columns)) {\n return;\n }\n\n const applyLineType = (\n type: 'deletions' | 'additions',\n column: ColumnElements | undefined\n ) => {\n if (column == null) {\n return;\n }\n const ast = this.hunksRenderer.renderCodeAST(type, hunksResult);\n const gutterChildren = getElementChildren(ast?.[0]);\n const contentChildren = getElementChildren(ast?.[1]);\n for (const [el, astChildren] of [\n [column.gutter, gutterChildren],\n [column.content, contentChildren],\n ] as const) {\n if (\n astChildren != null &&\n el.childElementCount === astChildren.length\n ) {\n for (let i = 0; i < astChildren.length; i++) {\n const gutterElement = el.children[i] as HTMLElement;\n const gutterChild = astChildren[i] as HASTElement;\n const lineType = gutterChild.properties['data-line-type'] as\n | string\n | undefined;\n if (\n lineType != null &&\n gutterElement.dataset.lineType !== lineType\n ) {\n gutterElement.dataset.lineType = lineType;\n }\n }\n }\n }\n };\n\n applyLineType('deletions', columns[0]);\n applyLineType('additions', columns[1]);\n this.renderedDiff = hunksResult.fileDiff;\n }\n\n // full diff view re-rendering\n // only for unified view.\n private refreshUnifiedDiffView(): void {\n const fileDiff = this.getLatestDiff();\n if (this.options.diffStyle !== 'unified' || fileDiff == null) {\n return;\n }\n\n const hunksResult = this.hunksRenderer.renderDiff(\n fileDiff,\n this.renderRange\n );\n if (hunksResult == null) {\n return;\n }\n\n const columns = this.getCodeColumns(\n 'unified',\n this.codeUnified,\n this.codeDeletions,\n this.codeAdditions\n );\n if (columns == null || Array.isArray(columns)) {\n return;\n }\n\n const ast = this.hunksRenderer.renderCodeAST('unified', hunksResult);\n const gutterChildren = getElementChildren(ast?.[0]);\n const contentChildren = getElementChildren(ast?.[1]);\n const applyColumns = () => {\n for (const [el, astChildren] of [\n [columns.gutter, gutterChildren],\n [columns.content, contentChildren],\n ] as const) {\n if (astChildren != null) {\n el.innerHTML = toHtml(astChildren);\n }\n }\n\n if (hunksResult.rowCount !== this.lastRowCount) {\n this.applyRowSpan('unified', columns, hunksResult.rowCount);\n this.lastRowCount = hunksResult.rowCount;\n }\n this.renderedDiff = hunksResult.fileDiff;\n };\n if (this.shouldGuardRebuildScroll()) {\n guardWebKitScrollDuringRebuild(this.pre, applyColumns);\n } else {\n applyColumns();\n }\n this.renderSeparators(hunksResult.hunkData);\n\n this.managersDirty = true;\n this.flushManagers();\n\n // sync the render view to the editor\n this.syncRenderViewToEditor();\n }\n\n private renderPartialColumn(\n column: ColumnElements | undefined,\n ast: ElementContent[] | undefined,\n insertPosition: 'afterbegin' | 'beforeend'\n ) {\n if (column == null || ast == null) {\n return;\n }\n const gutterChildren = getElementChildren(ast[0]);\n const contentChildren = getElementChildren(ast[1]);\n if (gutterChildren == null || contentChildren == null) {\n throw new Error('FileDiff.insertPartialHTML: Unexpected AST structure');\n }\n const firstHASTElement = contentChildren.at(0);\n if (\n insertPosition === 'beforeend' &&\n firstHASTElement?.type === 'element' &&\n typeof firstHASTElement.properties['data-buffer-size'] === 'number'\n ) {\n this.mergeBuffersIfNecessary(\n firstHASTElement.properties['data-buffer-size'],\n column.content.children[column.content.children.length - 1],\n column.gutter.children[column.gutter.children.length - 1],\n gutterChildren,\n contentChildren,\n true\n );\n }\n const lastHASTElement = contentChildren.at(-1);\n if (\n insertPosition === 'afterbegin' &&\n lastHASTElement?.type === 'element' &&\n typeof lastHASTElement.properties['data-buffer-size'] === 'number'\n ) {\n this.mergeBuffersIfNecessary(\n lastHASTElement.properties['data-buffer-size'],\n column.content.children[0],\n column.gutter.children[0],\n gutterChildren,\n contentChildren,\n false\n );\n }\n\n column.gutter.insertAdjacentHTML(\n insertPosition,\n this.hunksRenderer.renderPartialHTML(gutterChildren)\n );\n column.content.insertAdjacentHTML(\n insertPosition,\n this.hunksRenderer.renderPartialHTML(contentChildren)\n );\n }\n\n private mergeBuffersIfNecessary(\n adjustmentSize: number,\n contentElement: Element,\n gutterElement: Element,\n gutterChildren: ElementContent[],\n contentChildren: ElementContent[],\n fromStart: boolean\n ) {\n if (\n !(contentElement instanceof HTMLElement) ||\n !(gutterElement instanceof HTMLElement)\n ) {\n return;\n }\n const currentSize = this.getBufferSize(contentElement.dataset);\n if (currentSize == null) {\n return;\n }\n if (fromStart) {\n gutterChildren.shift();\n contentChildren.shift();\n } else {\n gutterChildren.pop();\n contentChildren.pop();\n }\n this.updateBufferSize(contentElement, currentSize + adjustmentSize);\n this.updateBufferSize(gutterElement, currentSize + adjustmentSize);\n }\n\n private applyRowSpan(\n diffStyle: 'split' | 'unified',\n columns:\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements,\n rowCount: number\n ): void {\n const applySpan = (column: ColumnElements | undefined) => {\n if (column == null) {\n return;\n }\n column.gutter.style.setProperty('grid-row', `span ${rowCount}`);\n column.content.style.setProperty('grid-row', `span ${rowCount}`);\n };\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n applySpan(columns);\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n applySpan(columns[0]);\n applySpan(columns[1]);\n } else {\n throw new Error('dun fuuuuked up');\n }\n }\n\n private trimColumnRows(\n columns: ColumnElements | undefined,\n preTrimCount: number,\n postTrimStart: number\n ): number {\n let visibleLineIndex = 0;\n let rowCount = 0;\n let rowIndex = 0;\n let pendingMetadataTrim = false;\n const hasPostTrim = postTrimStart >= 0;\n\n if (columns == null) {\n return 0;\n }\n const contentChildren = Array.from(columns.content.children);\n const gutterChildren = Array.from(columns.gutter.children);\n if (contentChildren.length !== gutterChildren.length) {\n throw new Error('FileDiff.trimColumnRows: columns do not match');\n }\n\n while (rowIndex < contentChildren.length) {\n if (preTrimCount <= 0 && !hasPostTrim && !pendingMetadataTrim) {\n break;\n }\n const gutterElement = gutterChildren[rowIndex];\n const contentElement = contentChildren[rowIndex];\n rowIndex++;\n\n if (\n !(gutterElement instanceof HTMLElement) ||\n !(contentElement instanceof HTMLElement)\n ) {\n console.error({ gutterElement, contentElement });\n throw new Error('FileDiff.trimColumnRows: invalid row elements');\n }\n\n if (pendingMetadataTrim) {\n pendingMetadataTrim = false;\n if (\n (gutterElement.dataset.gutterBuffer === 'annotation' &&\n 'lineAnnotation' in contentElement.dataset) ||\n (gutterElement.dataset.gutterBuffer === 'metadata' &&\n 'noNewline' in contentElement.dataset)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n continue;\n }\n }\n\n // If we found a line element, lets trim it if necessary\n if (\n 'lineIndex' in gutterElement.dataset &&\n 'lineIndex' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n if (preTrimCount > 0) {\n preTrimCount--;\n if (preTrimCount === 0) {\n pendingMetadataTrim = true;\n }\n }\n rowCount++;\n }\n visibleLineIndex++;\n continue;\n }\n\n // Separators should be removed, but don't count towards line indices\n if (\n 'separator' in gutterElement.dataset &&\n 'separator' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n // Annotations should be removed, but don't count towards line indices\n if (\n gutterElement.dataset.gutterBuffer === 'annotation' &&\n 'lineAnnotation' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n if (\n gutterElement.dataset.gutterBuffer === 'metadata' &&\n 'noNewline' in contentElement.dataset\n ) {\n if (\n preTrimCount > 0 ||\n (hasPostTrim && visibleLineIndex >= postTrimStart)\n ) {\n gutterElement.remove();\n contentElement.remove();\n rowCount++;\n }\n continue;\n }\n\n if (\n gutterElement.dataset.gutterBuffer === 'buffer' &&\n 'contentBuffer' in contentElement.dataset\n ) {\n const totalRows = this.getBufferSize(contentElement.dataset);\n if (totalRows == null) {\n throw new Error('FileDiff.trimColumnRows: invalid element');\n }\n if (preTrimCount > 0) {\n const rowsToRemove = Math.min(preTrimCount, totalRows);\n const newSize = totalRows - rowsToRemove;\n if (newSize > 0) {\n this.updateBufferSize(gutterElement, newSize);\n this.updateBufferSize(contentElement, newSize);\n rowCount += rowsToRemove;\n } else {\n gutterElement.remove();\n contentElement.remove();\n rowCount += totalRows;\n }\n preTrimCount -= rowsToRemove;\n if (preTrimCount === 0 && newSize === 0) {\n pendingMetadataTrim = true;\n }\n }\n // If we are in a post clip era...\n else if (hasPostTrim) {\n const bufferStart = visibleLineIndex;\n const bufferEnd = visibleLineIndex + totalRows - 1;\n if (postTrimStart <= bufferStart) {\n gutterElement.remove();\n contentElement.remove();\n rowCount += totalRows;\n } else if (postTrimStart <= bufferEnd) {\n const rowsToRemove = bufferEnd - postTrimStart + 1;\n const newSize = totalRows - rowsToRemove;\n this.updateBufferSize(gutterElement, newSize);\n this.updateBufferSize(contentElement, newSize);\n rowCount += rowsToRemove;\n }\n }\n visibleLineIndex += totalRows;\n continue;\n }\n\n console.error({ gutterElement, contentElement });\n throw new Error('FileDiff.trimColumnRows: unknown row elements');\n }\n\n return rowCount;\n }\n\n private trimColumns({\n columns,\n diffStyle,\n overlapEnd,\n overlapStart,\n previousStart,\n trimEnd,\n trimStart,\n // NOTE(amadeus): If we return -1 it means something went wrong\n // with the trim...\n // oxlint-disable-next-line no-redundant-type-constituents\n }: TrimColumnsToOverlapProps): number | -1 {\n const preTrimCount = Math.max(0, overlapStart - previousStart);\n const postTrimStart = overlapEnd - previousStart;\n if (postTrimStart < 0) {\n throw new Error('FileDiff.trimColumns: overlap ends before previous');\n }\n const shouldTrimStart = trimStart > 0;\n const shouldTrimEnd = trimEnd > 0;\n if (!shouldTrimStart && !shouldTrimEnd) {\n return 0;\n }\n const effectivePreTrimCount = shouldTrimStart ? preTrimCount : 0;\n const effectivePostTrimStart = shouldTrimEnd ? postTrimStart : -1;\n\n if (diffStyle === 'unified' && !Array.isArray(columns)) {\n const removedRows = this.trimColumnRows(\n columns,\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n return removedRows;\n } else if (diffStyle === 'split' && Array.isArray(columns)) {\n const deletionsTrim = this.trimColumnRows(\n columns[0],\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n const additionsTrim = this.trimColumnRows(\n columns[1],\n effectivePreTrimCount,\n effectivePostTrimStart\n );\n // We should avoid the trim validation if we are split but\n // there's only one side\n if (\n columns[0] != null &&\n columns[1] != null &&\n deletionsTrim !== additionsTrim\n ) {\n throw new Error('FileDiff.trimColumns: split columns out of sync');\n }\n return columns[0] != null ? deletionsTrim : additionsTrim;\n } else {\n console.error({ diffStyle, columns });\n throw new Error('FileDiff.trimColumns: Invalid columns for diffType');\n }\n }\n\n private getBufferSize(properties: DOMStringMap): number | undefined {\n const parsed = Number.parseInt(properties?.bufferSize ?? '', 10);\n return Number.isNaN(parsed) ? undefined : parsed;\n }\n\n private updateBufferSize(element: HTMLElement, size: number): void {\n element.dataset.bufferSize = `${size}`;\n element.style.setProperty('grid-row', `span ${size}`);\n element.style.setProperty('min-height', `calc(${size} * 1lh)`);\n }\n\n private getColumnPair(\n code: HTMLElement | undefined\n ): ColumnElements | undefined {\n if (code == null) {\n return undefined;\n }\n const gutter = code.children[0];\n const content = code.children[1];\n if (\n !(gutter instanceof HTMLElement) ||\n !(content instanceof HTMLElement) ||\n gutter.dataset.gutter == null ||\n content.dataset.content == null\n ) {\n return undefined;\n }\n return { gutter, content };\n }\n\n private getCodeColumns(\n diffStyle: 'split' | 'unified',\n codeUnified: HTMLElement | undefined,\n codeDeletions: HTMLElement | undefined,\n codeAdditions: HTMLElement | undefined\n ):\n | [ColumnElements | undefined, ColumnElements | undefined]\n | ColumnElements\n | undefined {\n if (diffStyle === 'unified') {\n return this.getColumnPair(codeUnified);\n } else {\n const deletions = this.getColumnPair(codeDeletions);\n const additions = this.getColumnPair(codeAdditions);\n return deletions != null || additions != null\n ? [deletions, additions]\n : undefined;\n }\n }\n\n protected updateBuffers(renderRange: RenderRange): void {\n if (this.pre != null) {\n this.applyBuffers(this.pre, renderRange);\n }\n }\n\n private applyBuffers(\n pre: HTMLPreElement,\n renderRange: RenderRange | undefined\n ) {\n if (renderRange == null || this.shouldDisableVirtualizationBuffers()) {\n if (this.bufferBefore != null) {\n this.bufferBefore.remove();\n this.bufferBefore = undefined;\n }\n if (this.bufferAfter != null) {\n this.bufferAfter.remove();\n this.bufferAfter = undefined;\n }\n return;\n }\n // NOTE(amadeus): A very hacky pass at buffers outside the pre elements...\n // i may need to improve this...\n if (renderRange.bufferBefore > 0) {\n if (this.bufferBefore == null) {\n this.bufferBefore = document.createElement('div');\n this.bufferBefore.dataset.virtualizerBuffer = 'before';\n pre.before(this.bufferBefore);\n }\n this.bufferBefore.style.setProperty(\n 'height',\n `${renderRange.bufferBefore}px`\n );\n this.bufferBefore.style.setProperty('contain', 'strict');\n } else if (this.bufferBefore != null) {\n this.bufferBefore.remove();\n this.bufferBefore = undefined;\n }\n\n if (renderRange.bufferAfter > 0) {\n if (this.bufferAfter == null) {\n this.bufferAfter = document.createElement('div');\n this.bufferAfter.dataset.virtualizerBuffer = 'after';\n pre.after(this.bufferAfter);\n }\n this.bufferAfter.style.setProperty(\n 'height',\n `${renderRange.bufferAfter}px`\n );\n this.bufferAfter.style.setProperty('contain', 'strict');\n } else if (this.bufferAfter != null) {\n this.bufferAfter.remove();\n this.bufferAfter = undefined;\n }\n }\n\n protected shouldDisableVirtualizationBuffers(): boolean {\n return this.options.disableVirtualizationBuffers ?? false;\n }\n\n protected applyPreNodeAttributes(\n pre: HTMLPreElement,\n { additionsContentAST, deletionsContentAST, totalLines }: HunksRenderResult,\n customProperties?: CustomPreProperties\n ): void {\n const {\n diffIndicators = 'bars',\n disableBackground = false,\n disableLineNumbers = false,\n overflow = 'scroll',\n diffStyle = 'split',\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n type: 'diff',\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split:\n diffStyle === 'unified'\n ? false\n : additionsContentAST != null && deletionsContentAST != null,\n totalLines,\n customProperties,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n this.pre?.remove();\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.textContent = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.remove();\n this.errorWrapper = undefined;\n }\n}\n\ninterface HasContentProps {\n fileDiff: FileDiffMetadata | undefined;\n oldFile: FileContents | null | undefined;\n newFile: FileContents | null | undefined;\n}\n\nfunction getAdditionFile(fileDiff: FileDiffMetadata): FileContents {\n return {\n name: fileDiff.name,\n lang: fileDiff.lang,\n contents: fileDiff.additionLines.join(''),\n };\n}\n\nfunction areOptionalFilesEqual(\n fileA: FileContents | null | undefined,\n fileB: FileContents | null | undefined\n): boolean {\n if (fileA == null || fileB == null) {\n return fileA == null && fileB == null;\n }\n return areFilesEqual(fileA, fileB);\n}\n\nfunction hasDiffContent({\n fileDiff,\n oldFile,\n newFile,\n}: HasContentProps): boolean {\n return (\n (fileDiff != null && fileDiff.hunks.length > 0) ||\n oldFile != null ||\n newFile != null\n );\n}\n\nfunction hasDiffHeaderContent({\n fileDiff,\n oldFile,\n newFile,\n}: HasContentProps): boolean {\n return fileDiff != null || oldFile != null || newFile != null;\n}\n\nfunction shouldRenderCode(\n pre: HTMLPreElement | undefined,\n hasContent: boolean,\n collapsed = false\n): boolean {\n return !collapsed && pre == null && hasContent;\n}\n\nfunction shouldRenderHeader(\n headerElement: HTMLElement | undefined,\n hasContent: boolean,\n disableFileHeader = false\n): boolean {\n return headerElement == null && hasContent && !disableFileHeader;\n}\n\nfunction getElementChildren(\n node: ElementContent | undefined\n): ElementContent[] | undefined {\n if (node == null || node.type !== 'element') {\n return undefined;\n }\n return node.children ?? [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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