@pierre/diffs 1.3.0-rc.3 → 1.3.0
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/dist/components/CodeView.d.ts +1 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +1 -1
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +2 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +21 -11
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +2 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +15 -4
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +2 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +33 -20
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +1 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +12 -3
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/editor/editor.js +2 -2
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +8 -2
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/react/CodeView.js +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +7 -0
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +1 -0
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +7 -0
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.d.ts","names":[],"sources":["../../src/editor/tokenizer.ts"],"mappings":";;;;UAqBiB,oBAAA;EACf,WAAA,EAAa,gBAAA;EACb,YAAA,EAAc,YAAA;EACd,WAAA,EAAa,eAAA;EACb,aAAA;EACA,QAAA,GAAW,KAAA;EACX,eAAA,GACE,KAAA,EAAO,GAAA,SAAY,KAAA,CAAM,gBAAA,IACzB,SAAA;EAKF,aAAA;EACA,OAAA;AAAA;;cAIW,eAAA;EAAA;MAyFP,SAAA;EAIJ,kCAAA,CACE,SAAA;EAsBF,WAAA;IACE,WAAA;IACA,WAAA;IACA,YAAA;IACA,aAAA;IACA,QAAA;IACA,eAAA;IACA,aAAA;IACA;EAAA,GACC,oBAAA;EAsHH,SAAA,CAAU,WAAA,EAAa,eAAA;
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","names":[],"sources":["../../src/editor/tokenizer.ts"],"mappings":";;;;UAqBiB,oBAAA;EACf,WAAA,EAAa,gBAAA;EACb,YAAA,EAAc,YAAA;EACd,WAAA,EAAa,eAAA;EACb,aAAA;EACA,QAAA,GAAW,KAAA;EACX,eAAA,GACE,KAAA,EAAO,GAAA,SAAY,KAAA,CAAM,gBAAA,IACzB,SAAA;EAKF,aAAA;EACA,OAAA;AAAA;;cAIW,eAAA;EAAA;MAyFP,SAAA;EAIJ,kCAAA,CACE,SAAA;EAsBF,WAAA;IACE,WAAA;IACA,WAAA;IACA,YAAA;IACA,aAAA;IACA,QAAA;IACA,eAAA;IACA,aAAA;IACA;EAAA,GACC,oBAAA;EAsHH,SAAA,CAAU,WAAA,EAAa,eAAA;EAyFvB,OAAA;EAUA,QAAA,CACE,MAAA,EAAQ,kBAAA,EACR,WAAA,GAAc,WAAA,GACb,GAAA,SAAY,KAAA,CAAM,gBAAA;EAmMrB,kBAAA,CAAmB,WAAA,GAAc,WAAA;EAKjC,sBAAA;EAiBA,uBAAA;EAYA,wBAAA;AAAA;AAAA,iBAocc,gBAAA,CACd,MAAA,EAAQ,KAAA,CAAM,gBAAA,KACZ,WAAA"}
|
package/dist/editor/tokenizer.js
CHANGED
|
@@ -101,7 +101,7 @@ var EditorTokenizer = class {
|
|
|
101
101
|
this.#debug = __debug ?? false;
|
|
102
102
|
this.#ensureGrammar();
|
|
103
103
|
this.#colorMap = [];
|
|
104
|
-
this.#setTheme(typeof theme === "string" ? theme : theme[themeType], themeType);
|
|
104
|
+
this.#setTheme(typeof theme === "string" ? theme : theme[themeType], typeof theme === "string" ? void 0 : themeType);
|
|
105
105
|
}
|
|
106
106
|
#emitThemeChange(themeName, themeType) {
|
|
107
107
|
if (themeName === this.#themeName && themeType === this.#themeType) return;
|
|
@@ -126,8 +126,14 @@ var EditorTokenizer = class {
|
|
|
126
126
|
}
|
|
127
127
|
syncTheme(codeOptions) {
|
|
128
128
|
const { themeType = "system", theme = DEFAULT_THEMES } = codeOptions;
|
|
129
|
+
if (typeof theme === "string") {
|
|
130
|
+
const pinnedThemeType = this.#highlighter.getTheme(theme).type;
|
|
131
|
+
if (theme === this.#themeName && pinnedThemeType === this.#themeType) return;
|
|
132
|
+
this.#emitThemeChange(theme, pinnedThemeType);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
129
135
|
const nextThemeType = themeType === "system" ? this.#resolveSystemThemeType() : themeType;
|
|
130
|
-
const nextThemeName =
|
|
136
|
+
const nextThemeName = theme[nextThemeType];
|
|
131
137
|
if (nextThemeType === this.#themeType && nextThemeName === this.#themeName) return;
|
|
132
138
|
this.#emitThemeChange(nextThemeName, nextThemeType);
|
|
133
139
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.js","names":["#isCleanedUp","#textDocument","#grammar","#highlighter","#ensureActiveTheme","#scheduleStatePrebuild","#tokenizerId","#backgroundJobId","#backgroundPrebuildEndLine","#backgroundPrebuild","#backgroundTokenize","#themeType","#matchBrackets","#ensureGrammar","#bracketIgnoredRanges","#buildStateStack","#stateStack","#tokenizeLineAt","#mediaQueryList","#resolveSystemThemeType","#emitThemeChange","#disposes","#tokenizeMaxLineLength","#setStyle","#onDeferTokenize","#onThemeChange","#debug","#colorMap","#setTheme","#themeName","#comparisonStateStack","#comparisonStateStackStart","#comparisonLineChanges","#scheduleBackgroundTokenize","#detachMessageListener","#shiftComparisonStateStack","#prebuildStateStack","#pendingPrebuildEndLine","#isStopped","#isPaused","#lastLine","#backgroundChangedLineRanges","#backgroundChangedRangeIndex","#postTokenizeMessage","#isMessageListenerAttached","#onMessage","#attachMessageListener","#cacheBracketIgnoredRanges","#getPreviousEndState"],"sources":["../../src/editor/tokenizer.ts"],"sourcesContent":["import { colorUtils } from '@pierre/theming/color';\nimport {\n EncodedTokenMetadata,\n type IGrammar,\n INITIAL,\n type StateStack,\n} from 'shiki/textmate';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n HighlightedToken,\n RenderRange,\n} from '../types';\nimport type { TextDocument, TextDocumentChange } from './textDocument';\nimport { addEventListener, debounce, h } from './utils';\n\nconst TOKENIZE_TIME_LIMIT = 500;\nlet nextTokenizerId = 0;\n\nexport interface EditorTokenizerProps {\n highlighter: DiffsHighlighter;\n textDocument: TextDocument<unknown>;\n codeOptions: BaseCodeOptions;\n matchBrackets?: boolean;\n setStyle: (style: string) => void;\n onDeferTokenize: (\n lines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light'\n ) => void;\n // Fired after the active theme (light/dark mode or theme name) changes and the\n // new theme CSS has been applied. Lets the editor recompute overlay pieces\n // that captured a resolved theme color, e.g. rounded selection corner masks.\n onThemeChange?: () => void;\n __debug?: boolean;\n}\n\n/** Stoppable code tokenizer for the editor */\nexport class EditorTokenizer {\n #highlighter: DiffsHighlighter;\n #grammar: IGrammar | undefined;\n #mediaQueryList: MediaQueryList;\n #themeType: 'light' | 'dark' = 'dark';\n // The resolved name of the theme currently applied to the editor (e.g.\n // `github-light`). Tracked so `syncTheme` can detect a host-driven theme swap\n // even when the light/dark mode itself is unchanged.\n #themeName = '';\n #colorMap: string[];\n #textDocument: TextDocument<unknown>;\n #tokenizeMaxLineLength: number;\n #setStyle: EditorTokenizerProps['setStyle'];\n #onDeferTokenize: EditorTokenizerProps['onDeferTokenize'];\n #onThemeChange: EditorTokenizerProps['onThemeChange'];\n #matchBrackets: boolean;\n #debug: boolean;\n #disposes?: (() => void)[];\n #isCleanedUp = false;\n\n // state\n #stateStack: StateStack[] = [INITIAL]; // cached state stack by line index\n #comparisonStateStack: StateStack[] = [];\n #comparisonStateStackStart = 0;\n #comparisonLineChanges: NonNullable<\n TextDocumentChange['changedLineChanges']\n > = [];\n #lastLine: number = -1;\n #isStopped: boolean = true;\n #isPaused: boolean = false;\n #backgroundJobId: number = 0;\n #tokenizerId = ++nextTokenizerId;\n #backgroundPrebuildEndLine = -1;\n #pendingPrebuildEndLine = -1;\n #backgroundChangedLineRanges: readonly [number, number][] | undefined;\n #backgroundChangedRangeIndex: number = 0;\n #bracketIgnoredRanges: ([number, number][] | null | undefined)[] = [];\n #isMessageListenerAttached: boolean = false;\n\n #prebuildStateStack = debounce(async (renderRange?: RenderRange) => {\n // Drop work scheduled before cleanUp; a late timer must not call setTheme\n // on a highlighter that tests (or hosts) have already disposed.\n if (this.#isCleanedUp) {\n return;\n }\n const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};\n const endLine = Math.min(\n totalLines === Infinity ? Infinity : startingLine + totalLines,\n this.#textDocument.lineCount\n );\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId)\n ) {\n await this.#highlighter.loadLanguage(this.#textDocument.languageId);\n if (this.#isCleanedUp) {\n return;\n }\n this.#grammar = this.#highlighter.getLanguage(\n this.#textDocument.languageId\n );\n }\n this.#ensureActiveTheme();\n this.#scheduleStatePrebuild(endLine);\n }, 500);\n\n #onMessage = ({ data }: MessageEvent<unknown>) => {\n if (typeof data !== 'object' || data === null) {\n return;\n }\n const { type, tokenizerId, jobId } = data as {\n type?: unknown;\n tokenizerId?: unknown;\n jobId?: unknown;\n };\n if (\n type === 'tokenize' &&\n tokenizerId === this.#tokenizerId &&\n typeof jobId === 'number' &&\n jobId === this.#backgroundJobId\n ) {\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#backgroundPrebuild(jobId);\n } else {\n this.#backgroundTokenize(jobId);\n }\n }\n };\n\n get themeType(): 'light' | 'dark' {\n return this.#themeType;\n }\n\n getStringCommentRegexpRangesInLine(\n lineIndex: number\n ): [number, number][] | null {\n if (\n !this.#matchBrackets ||\n lineIndex < 0 ||\n lineIndex >= this.#textDocument.lineCount\n ) {\n return null;\n }\n this.#ensureGrammar();\n if (this.#grammar === undefined) {\n return null;\n }\n if (this.#bracketIgnoredRanges[lineIndex] === undefined) {\n this.#buildStateStack(lineIndex);\n const state = this.#stateStack[lineIndex] ?? INITIAL;\n const result = this.#tokenizeLineAt(lineIndex, state);\n this.#stateStack[lineIndex + 1] = result.state;\n }\n return this.#bracketIgnoredRanges[lineIndex] ?? null;\n }\n\n constructor({\n codeOptions,\n highlighter,\n textDocument,\n matchBrackets,\n setStyle,\n onDeferTokenize,\n onThemeChange,\n __debug,\n }: EditorTokenizerProps) {\n const {\n themeType: themeTypeOption = 'system',\n theme = DEFAULT_THEMES,\n tokenizeMaxLineLength = 1000,\n } = codeOptions;\n this.#mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');\n let themeType: 'light' | 'dark' | undefined;\n if (themeTypeOption === 'system') {\n // Prefer the host document's computed color-scheme (page CSS/classes can\n // force light/dark while the OS media query differs) over matchMedia.\n themeType = this.#resolveSystemThemeType();\n } else {\n themeType = themeTypeOption;\n }\n // Only track the document/system color scheme when the surface follows it\n // (`themeType: 'system'`). A surface pinned to an explicit 'dark'/'light'\n // theme keeps that theme regardless of the page, so re-tokenizing after an\n // edit must emit the same `--diffs-token-{theme}` variable the SSR markup\n // used; otherwise the edited tokens fall back to the default foreground.\n if (typeof theme !== 'string' && themeTypeOption === 'system') {\n const observer = new MutationObserver((mutations) => {\n for (const { type, attributeName } of mutations) {\n if (\n type === 'attributes' &&\n attributeName !== null &&\n (attributeName === 'class' || attributeName.startsWith('data-'))\n ) {\n const themeType = this.#resolveSystemThemeType();\n this.#emitThemeChange(theme[themeType], themeType);\n break;\n }\n }\n });\n observer.observe(document.documentElement, { attributes: true });\n observer.observe(document.body, { attributes: true });\n this.#disposes = [\n addEventListener(this.#mediaQueryList, 'change', () => {\n // Re-read computed color-scheme so a host-forced scheme still wins\n // when the OS preference changes underneath it.\n const themeType = this.#resolveSystemThemeType();\n this.#emitThemeChange(theme[themeType], themeType);\n }),\n () => observer.disconnect(),\n ];\n }\n this.#highlighter = highlighter;\n this.#textDocument = textDocument;\n this.#tokenizeMaxLineLength = tokenizeMaxLineLength;\n this.#setStyle = setStyle;\n this.#onDeferTokenize = onDeferTokenize;\n this.#onThemeChange = onThemeChange;\n this.#matchBrackets = matchBrackets !== false;\n this.#debug = __debug ?? false;\n this.#ensureGrammar();\n this.#colorMap = [];\n this.#setTheme(\n typeof theme === 'string' ? theme : theme[themeType],\n themeType\n );\n }\n\n // By default, diffs components support dual themes, but the tokenizer only renders\n // the preferred theme. When the theme type is changed, the tokenizer will re-tokenize the document.\n #emitThemeChange(themeName: string, themeType: 'light' | 'dark') {\n if (themeName === this.#themeName && themeType === this.#themeType) {\n return;\n }\n this.#setTheme(themeName, themeType);\n this.stopBackgroundTokenize();\n this.#stateStack = [INITIAL];\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n if (this.#grammar !== undefined && this.#textDocument.lineCount > 0) {\n this.#scheduleBackgroundTokenize(0);\n }\n // The theme CSS is now applied, so overlay pieces that captured a resolved\n // theme color (e.g. rounded selection corner masks) can recompute against\n // the new colors instead of keeping the old light/dark value.\n this.#onThemeChange?.();\n }\n\n // Respect an explicit host color-scheme override. When the computed value\n // advertises support for both schemes, let the OS preference choose one.\n #resolveSystemThemeType(): 'light' | 'dark' {\n try {\n if (\n typeof document !== 'undefined' &&\n typeof getComputedStyle === 'function' &&\n document.body != null\n ) {\n const colorSchemes = getComputedStyle(document.body).colorScheme.split(\n /\\s+/\n );\n const supportsDark = colorSchemes.includes('dark');\n const supportsLight = colorSchemes.includes('light');\n // A single host-forced scheme wins. `light dark` only declares support\n // for both schemes, so the media query still selects the active one.\n if (supportsDark !== supportsLight) {\n return supportsDark ? 'dark' : 'light';\n }\n }\n } catch {\n // jsdom and similar harnesses may lack getComputedStyle or throw; fall\n // through to the OS media query.\n }\n return this.#mediaQueryList.matches ? 'dark' : 'light';\n }\n\n // Re-apply the editor's theme from the surface's current code options. Edit\n // mode reuses a single tokenizer across re-renders, so when the host swaps the\n // theme — a theme picker, a light/dark toggle, etc. — we must recompute the\n // active theme and re-tokenize. Without this the editor keeps rendering the\n // theme it captured when it first attached (stale line-highlight background\n // and token colors). System-driven changes are still handled by the\n // observers wired up in the constructor; this covers explicit `themeType`/\n // `theme` option changes that those observers don't see.\n syncTheme(codeOptions: BaseCodeOptions): void {\n const { themeType = 'system', theme = DEFAULT_THEMES } = codeOptions;\n const nextThemeType =\n themeType === 'system' ? this.#resolveSystemThemeType() : themeType;\n const nextThemeName =\n typeof theme === 'string' ? theme : theme[nextThemeType];\n if (\n nextThemeType === this.#themeType &&\n nextThemeName === this.#themeName\n ) {\n return;\n }\n this.#emitThemeChange(nextThemeName, nextThemeType);\n }\n\n #setTheme(themeName: string, themeType?: 'light' | 'dark') {\n const { theme, colorMap } = this.#highlighter.setTheme(themeName);\n const { colors = {} } = this.#highlighter.getTheme(themeName);\n const selectionBackground = colors['editor.selectionBackground'];\n const themeLineHighlightBackground =\n colors['editor.lineHighlightBackground'];\n const lineHighlightBackground =\n themeLineHighlightBackground != null &&\n themeLineHighlightBackground.trim() !== '' &&\n !colorUtils.isFullyTransparent(themeLineHighlightBackground)\n ? themeLineHighlightBackground\n : undefined;\n // A usable theme background opts into the semantic active-line mix.\n // Missing backgrounds retain the resolved row color and rely on a border.\n const lineHighlightBorder =\n colors['editor.lineHighlightBorder'] ??\n (lineHighlightBackground == null\n ? 'color-mix(in lab, var(--diffs-bg) 70%, var(--diffs-fg))'\n : 'transparent');\n const activeLineSourceMix =\n lineHighlightBackground == null ? '100%' : '85%';\n const cursorForeground = colors['editorCursor.foreground'];\n const findMatchBackground = colors['editor.findMatchBackground'];\n const findMatchHighlightBackground =\n colors['editor.findMatchHighlightBackground'];\n const bracketMatchBackground = colors['editorBracketMatch.background'];\n const bracketMatchBorder = colors['editorBracketMatch.border'];\n const hintForeground = colors['editorHint.foreground'];\n const infoForeground = colors['editorInfo.foreground'];\n const warningForeground = colors['editorWarning.foreground'];\n const errorForeground = colors['editorError.foreground'];\n this.#setStyle(`:host {\n --diffs-editor-selection-bg: ${selectionBackground ?? 'var(--diffs-line-bg)'};\n --diffs-editor-line-highlight-border: ${lineHighlightBorder};\n --diffs-editor-active-line-source-mix: ${activeLineSourceMix};\n --diffs-editor-match-bg: ${findMatchBackground ?? 'initial'};\n --diffs-editor-match-highlight-bg: ${findMatchHighlightBackground ?? 'initial'};\n --diffs-editor-bracket-match-bg: ${bracketMatchBackground ?? 'initial'};\n --diffs-editor-bracket-match-border: ${bracketMatchBorder ?? 'initial'};\n --diffs-editor-cursor-fg: ${cursorForeground ?? 'initial'};\n --diffs-editor-hint-fg: ${hintForeground ?? 'initial'};\n --diffs-editor-info-fg: ${infoForeground ?? 'initial'};\n --diffs-editor-warning-fg: ${warningForeground ?? 'initial'};\n --diffs-editor-error-fg: ${errorForeground ?? 'initial'};\n }`);\n this.#themeName = themeName;\n this.#themeType = themeType ?? theme.type;\n this.#colorMap = colorMap;\n }\n\n // The shared highlighter is also used for dual-theme SSR (`themes: {dark,light}`),\n // which leaves its active theme on whichever pass finished last (usually light).\n // The tokenizer caches a single-theme colorMap from construction; if we tokenize\n // without re-activating that theme, grammar color indices are looked up in the\n // wrong map — property names resolve to a near-foreground gray while types and\n // comments (stable across maps) still look correct. Re-apply before every\n // tokenize path so a first edit after load matches a later file-switch re-attach.\n #ensureActiveTheme(): void {\n if (this.#themeName === '') {\n return;\n }\n const { colorMap } = this.#highlighter.setTheme(this.#themeName);\n this.#colorMap = colorMap;\n }\n\n cleanUp(): void {\n this.#isCleanedUp = true;\n this.stopBackgroundTokenize();\n this.#detachMessageListener();\n this.#disposes?.forEach((dispose) => dispose());\n this.#disposes = undefined;\n }\n\n // to use `tokenize`, call `prebuildStateStackMap` first to prebuild\n // the state stack map for the given render range.\n tokenize(\n change: TextDocumentChange,\n renderRange?: RenderRange\n ): Map<number, Array<HighlightedToken>> {\n this.#ensureGrammar();\n this.#ensureActiveTheme();\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId)\n ) {\n throw new Error(\n `Grammar for language \"${this.#textDocument.languageId}\" not loaded`\n );\n }\n\n if (this.#matchBrackets) {\n // Clear ignored token ranges for lines invalidated by the edit.\n this.#bracketIgnoredRanges.length = Math.min(\n this.#bracketIgnoredRanges.length,\n change.startLine\n );\n }\n\n const { lineCount } = this.#textDocument;\n const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};\n const renderRangeEndLine =\n totalLines === Infinity\n ? lineCount\n : Math.min(startingLine + totalLines, lineCount);\n\n const dirtyStart = change.startLine;\n const viewStart = Math.max(startingLine, dirtyStart);\n const crossesRenderRangeEnd =\n renderRange !== undefined &&\n totalLines !== Infinity &&\n change.lineDelta > 0 &&\n dirtyStart < renderRangeEndLine &&\n change.endLine >= renderRangeEndLine;\n const canReuseCachedStates =\n change.lineDelta === 0 &&\n (change.changedLineChanges?.every(([, , lineDelta]) => lineDelta === 0) ??\n true);\n const canCacheTokenizedStates =\n canReuseCachedStates ||\n renderRange === undefined ||\n dirtyStart >= viewStart;\n const changedLineRanges: readonly [number, number][] =\n change.changedLineRanges ?? [[dirtyStart, change.endLine]];\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n let offscreenSyncEnd = -1;\n if (dirtyStart < viewStart) {\n for (const [rangeStart, rangeEnd] of changedLineRanges) {\n if (rangeStart < viewStart) {\n offscreenSyncEnd = Math.max(\n offscreenSyncEnd,\n Math.min(rangeEnd, viewStart - 1)\n );\n }\n }\n }\n const shouldFlushOffscreenLines =\n offscreenSyncEnd >= dirtyStart &&\n (canReuseCachedStates || change.lineDelta < 0);\n if (canReuseCachedStates) {\n this.#buildStateStack(dirtyStart);\n } else {\n this.#shiftComparisonStateStack(change);\n if (renderRange === undefined || dirtyStart >= viewStart) {\n this.#buildStateStack(viewStart);\n }\n }\n\n let changedRangeIndex = 0;\n let currentChangedRangeEnd = changedLineRanges[changedRangeIndex][1];\n let backgroundStartLine: number | undefined;\n let backgroundChangedRangeIndex = 0;\n let line = canReuseCachedStates\n ? changedLineRanges[changedRangeIndex][0]\n : viewStart;\n let settled = false;\n const dirtyLines: Map<number, Array<HighlightedToken>> = new Map();\n const offscreenDirtyLines:\n | Map<number, Array<HighlightedToken>>\n | undefined = shouldFlushOffscreenLines ? new Map() : undefined;\n if (offscreenDirtyLines !== undefined && !canReuseCachedStates) {\n const offscreenEnd = Math.min(\n offscreenSyncEnd + 1,\n viewStart,\n renderRangeEndLine\n );\n if (offscreenEnd > dirtyStart) {\n this.#buildStateStack(offscreenEnd);\n let offscreenLine = dirtyStart;\n let offscreenState = this.#stateStack[offscreenLine] ?? INITIAL;\n for (; offscreenLine < offscreenEnd; offscreenLine++) {\n const resolved = this.#tokenizeLineAt(offscreenLine, offscreenState);\n offscreenState = resolved.state;\n offscreenDirtyLines.set(offscreenLine, resolved.resolvedTokens);\n }\n this.#stateStack[offscreenEnd] = offscreenState;\n }\n }\n // Seed the loop's grammar state after the offscreen flush, not before it.\n // When a delete's removed lines reach the viewport's first line, the flush\n // rebuilds the cached state up to `line`; reading it earlier would capture\n // the truncated INITIAL state and color the viewport as if outside an open\n // construct (block comment, template literal) it is actually inside.\n let state = this.#stateStack[line] ?? INITIAL;\n for (; line < renderRangeEndLine; ) {\n const previousNextState = canReuseCachedStates\n ? this.#stateStack[line + 1]\n : undefined;\n if (canCacheTokenizedStates) {\n this.#stateStack[line] = state;\n }\n\n const { resolvedTokens, state: nextState } = this.#tokenizeLineAt(\n line,\n state\n );\n state = nextState;\n\n if (line >= viewStart) {\n dirtyLines.set(line, resolvedTokens);\n } else {\n offscreenDirtyLines?.set(line, resolvedTokens);\n }\n\n if (canCacheTokenizedStates) {\n this.#stateStack[line + 1] = state;\n }\n settled =\n line >= currentChangedRangeEnd &&\n canReuseCachedStates &&\n previousNextState !== undefined &&\n state.equals(previousNextState);\n if (settled) {\n changedRangeIndex++;\n const nextRange = changedLineRanges[changedRangeIndex];\n if (nextRange === undefined) {\n break;\n }\n if (nextRange[0] >= renderRangeEndLine) {\n backgroundStartLine = nextRange[0];\n backgroundChangedRangeIndex = changedRangeIndex;\n break;\n }\n if (this.#stateStack[nextRange[0]] === undefined) {\n currentChangedRangeEnd = nextRange[1];\n line++;\n } else {\n line = nextRange[0];\n state = this.#stateStack[line] ?? state;\n currentChangedRangeEnd = nextRange[1];\n }\n settled = false;\n continue;\n }\n line++;\n }\n\n if (canCacheTokenizedStates) {\n if (line < renderRangeEndLine) {\n this.#stateStack[line + 1] = state;\n } else {\n this.#stateStack[line] = state;\n }\n }\n\n if (offscreenDirtyLines !== undefined && offscreenDirtyLines.size > 0) {\n this.#onDeferTokenize(offscreenDirtyLines, this.#themeType);\n }\n\n if (backgroundStartLine !== undefined) {\n this.#scheduleBackgroundTokenize(\n backgroundStartLine,\n changedLineRanges,\n backgroundChangedRangeIndex\n );\n } else if (!settled && line < lineCount) {\n const backgroundLine =\n crossesRenderRangeEnd && dirtyStart >= viewStart\n ? renderRangeEndLine\n : dirtyStart < viewStart && !canReuseCachedStates\n ? dirtyStart\n : line;\n this.#scheduleBackgroundTokenize(\n backgroundLine,\n changedLineRanges,\n changedRangeIndex\n );\n }\n\n return dirtyLines;\n }\n\n prebuildStateStack(renderRange?: RenderRange): void {\n this.#ensureGrammar();\n this.#prebuildStateStack(renderRange);\n }\n\n stopBackgroundTokenize(): void {\n this.#pendingPrebuildEndLine = -1;\n if (this.#isStopped) {\n return;\n }\n this.#isStopped = true;\n this.#isPaused = false;\n this.#lastLine = -1;\n this.#backgroundPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = undefined;\n this.#backgroundChangedRangeIndex = 0;\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n this.#detachMessageListener();\n }\n\n pauseBackgroundTokenize(): void {\n if (this.#isStopped || this.#isPaused) {\n return;\n }\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization paused', {\n jobId: this.#backgroundJobId,\n });\n }\n this.#isPaused = true;\n }\n\n resumeBackgroundTokenize(): void {\n if (\n this.#isStopped ||\n !this.#isPaused ||\n this.#grammar === undefined ||\n this.#lastLine < 0\n ) {\n return;\n }\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization resumed', {\n jobId: this.#backgroundJobId,\n });\n }\n this.#isPaused = false;\n this.#postTokenizeMessage(this.#backgroundJobId);\n }\n\n #ensureGrammar(): void {\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId) &&\n this.#highlighter\n .getLoadedLanguages()\n .includes(this.#textDocument.languageId)\n ) {\n this.#grammar = this.#highlighter.getLanguage(\n this.#textDocument.languageId\n );\n }\n }\n\n #attachMessageListener(): void {\n if (this.#isMessageListenerAttached) {\n return;\n }\n globalThis.addEventListener('message', this.#onMessage);\n this.#isMessageListenerAttached = true;\n }\n\n #detachMessageListener(): void {\n if (!this.#isMessageListenerAttached) {\n return;\n }\n globalThis.removeEventListener('message', this.#onMessage);\n this.#isMessageListenerAttached = false;\n }\n\n #postTokenizeMessage(jobId: number): void {\n // use `postMessage` instead of `setTimeout(fn, 0)` to avoid 4ms delay\n globalThis.postMessage({\n type: 'tokenize',\n tokenizerId: this.#tokenizerId,\n jobId,\n });\n }\n\n #scheduleBackgroundTokenize(\n startLine: number,\n changedLineRanges?: readonly [number, number][],\n changedRangeIndex = 0\n ): void {\n if (isGrammarlessLanguage(this.#textDocument.languageId)) {\n return;\n }\n\n const jobId = ++this.#backgroundJobId;\n\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization scheduled', {\n jobId,\n startLine,\n changedLineRanges,\n changedRangeIndex,\n });\n }\n\n this.#isStopped = false;\n this.#isPaused = false;\n this.#lastLine = startLine;\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#pendingPrebuildEndLine = Math.max(\n this.#pendingPrebuildEndLine,\n this.#backgroundPrebuildEndLine\n );\n }\n this.#backgroundPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = changedLineRanges;\n this.#backgroundChangedRangeIndex = changedRangeIndex;\n this.#attachMessageListener();\n this.#postTokenizeMessage(jobId);\n }\n\n #scheduleStatePrebuild(endLine: number): void {\n if (this.#grammar === undefined || this.#stateStack.length > endLine) {\n return;\n }\n // Extend an active prebuild, or retain the target until the foreground\n // edit job reconverges and releases the state cache.\n if (!this.#isStopped) {\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#backgroundPrebuildEndLine = Math.max(\n this.#backgroundPrebuildEndLine,\n endLine\n );\n } else {\n this.#pendingPrebuildEndLine = Math.max(\n this.#pendingPrebuildEndLine,\n endLine\n );\n }\n return;\n }\n\n const jobId = ++this.#backgroundJobId;\n this.#isStopped = false;\n this.#isPaused = false;\n this.#lastLine = this.#stateStack.length - 1;\n this.#backgroundPrebuildEndLine = endLine;\n this.#pendingPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = undefined;\n this.#backgroundChangedRangeIndex = 0;\n this.#attachMessageListener();\n this.#postTokenizeMessage(jobId);\n }\n\n #tokenizeLineAt(\n line: number,\n state: StateStack\n ): { resolvedTokens: Array<HighlightedToken>; state: StateStack } {\n const lineText = this.#textDocument.getLineText(line);\n if (lineText.length > this.#tokenizeMaxLineLength) {\n console.warn(\n `[diffs] Line(${line}) too long to tokenize: ${lineText.length}`\n );\n this.#cacheBracketIgnoredRanges(line, null);\n return { resolvedTokens: [[0, '', lineText]], state };\n }\n if (\n this.#grammar === undefined ||\n lineText === '' ||\n lineText.trim() === ''\n ) {\n this.#cacheBracketIgnoredRanges(line, null);\n return { resolvedTokens: [[0, '', lineText]], state };\n }\n const result = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets\n );\n this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);\n return {\n resolvedTokens: result.resolvedTokens,\n state: result.ruleStack,\n };\n }\n\n #cacheBracketIgnoredRanges(\n line: number,\n ranges: [number, number][] | null\n ): void {\n if (this.#matchBrackets) {\n this.#bracketIgnoredRanges[line] = ranges;\n }\n }\n\n // Preserve old end states as comparison-only sentinels, copying whichever\n // side of the edit is smaller. Index shifts are resolved lazily on lookup.\n #shiftComparisonStateStack(change: TextDocumentChange): void {\n const lineChanges =\n change.changedLineChanges ??\n ([[change.startLine, change.endLine, change.lineDelta]] as const);\n const comparisonStart = change.startLine + 1;\n const comparisonLength = this.#stateStack.length - comparisonStart;\n if (comparisonStart <= comparisonLength) {\n this.#comparisonStateStack = this.#stateStack;\n this.#comparisonStateStackStart = 0;\n this.#stateStack = this.#stateStack.slice(0, comparisonStart);\n } else {\n this.#comparisonStateStackStart = comparisonStart;\n this.#comparisonStateStack = this.#stateStack.slice(comparisonStart);\n this.#stateStack.length = Math.min(\n this.#stateStack.length,\n comparisonStart\n );\n }\n this.#comparisonLineChanges = lineChanges;\n }\n\n #getPreviousEndState(line: number): StateStack | undefined {\n let previousLine = line;\n for (\n let index = this.#comparisonLineChanges.length - 1;\n index >= 0;\n index--\n ) {\n const [startLine, endLine, lineDelta] =\n this.#comparisonLineChanges[index];\n if (lineDelta === 0) {\n continue;\n }\n if (previousLine > endLine) {\n previousLine -= lineDelta;\n } else if (previousLine > startLine) {\n return this.#stateStack[line];\n }\n }\n return (\n this.#comparisonStateStack[\n previousLine - this.#comparisonStateStackStart\n ] ?? this.#stateStack[line]\n );\n }\n\n #buildStateStack(endAt: number, timeBudget?: number): boolean {\n const boundedEndAt = Math.min(\n Math.max(0, endAt),\n this.#textDocument.lineCount\n );\n if (this.#stateStack.length > boundedEndAt || this.#grammar === undefined) {\n return true;\n }\n const startedAt = timeBudget === undefined ? 0 : performance.now();\n let line = this.#stateStack.length - 1;\n let state = this.#stateStack[line] ?? INITIAL;\n while (line < boundedEndAt) {\n this.#stateStack[line] = state;\n const lineText = this.#textDocument.getLineText(line);\n if (\n lineText.length <= this.#tokenizeMaxLineLength &&\n lineText !== '' &&\n lineText.trim() !== ''\n ) {\n const result = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets,\n false\n );\n this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);\n state = result.ruleStack;\n } else {\n this.#cacheBracketIgnoredRanges(line, null);\n }\n line++;\n this.#stateStack[line] = state;\n if (\n timeBudget !== undefined &&\n performance.now() - startedAt > timeBudget\n ) {\n break;\n }\n }\n return line >= boundedEndAt;\n }\n\n #backgroundPrebuild(jobId: number): void {\n if (\n this.#isStopped ||\n this.#isPaused ||\n this.#grammar === undefined ||\n jobId !== this.#backgroundJobId\n ) {\n return;\n }\n\n this.#ensureActiveTheme();\n // State prebuilds intentionally omit rendered tokens and yield between\n // short chunks so a deep viewport does not monopolize the main thread.\n const complete = this.#buildStateStack(this.#backgroundPrebuildEndLine, 1);\n if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) {\n return;\n }\n if (complete) {\n this.stopBackgroundTokenize();\n return;\n }\n this.#lastLine = this.#stateStack.length - 1;\n this.#postTokenizeMessage(jobId);\n }\n\n #backgroundTokenize(jobId: number) {\n if (\n this.#isStopped ||\n this.#isPaused ||\n this.#grammar === undefined ||\n jobId !== this.#backgroundJobId\n ) {\n return;\n }\n\n this.#ensureActiveTheme();\n\n const t = performance.now();\n const lines = new Map<number, Array<HighlightedToken>>();\n const totalLines = this.#textDocument.lineCount;\n const changedLineRanges = this.#backgroundChangedLineRanges;\n\n let line = this.#lastLine;\n let state = this.#stateStack[line] ?? INITIAL;\n let settled = false;\n let changedRangeIndex = this.#backgroundChangedRangeIndex;\n let currentChangedRangeEnd = changedLineRanges?.[changedRangeIndex]?.[1];\n for (; line < totalLines; ) {\n this.#stateStack[line] = state;\n\n const previousNextState =\n currentChangedRangeEnd !== undefined\n ? this.#getPreviousEndState(line + 1)\n : undefined;\n const lineText = this.#textDocument.getLineText(line);\n if (lineText.length > this.#tokenizeMaxLineLength) {\n console.warn(\n `[diffs] Line(${line}) too long to tokenize: ${lineText.length}`\n );\n lines.set(line, [[0, '', lineText]]);\n this.#cacheBracketIgnoredRanges(line, null);\n } else if (lineText === '' || lineText.trim() === '') {\n lines.set(line, [[0, '', lineText]]);\n this.#cacheBracketIgnoredRanges(line, null);\n } else {\n const ret = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets\n );\n lines.set(line, ret.resolvedTokens);\n this.#cacheBracketIgnoredRanges(line, ret.bracketIgnoredRanges);\n state = ret.ruleStack;\n }\n\n this.#stateStack[line + 1] = state;\n settled =\n currentChangedRangeEnd !== undefined &&\n line >= currentChangedRangeEnd &&\n previousNextState !== undefined &&\n state.equals(previousNextState);\n line++;\n if (settled) {\n changedRangeIndex++;\n const nextRange = changedLineRanges?.[changedRangeIndex];\n if (nextRange === undefined) {\n break;\n }\n currentChangedRangeEnd = nextRange[1];\n if (this.#stateStack[nextRange[0]] === undefined) {\n settled = false;\n } else {\n line = nextRange[0];\n state = this.#stateStack[line] ?? state;\n settled = false;\n continue;\n }\n }\n\n // limit the time of partial tokenize to 1ms\n if (performance.now() - t > 1) {\n break;\n }\n }\n\n this.#onDeferTokenize(lines, this.#themeType);\n if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) {\n return;\n }\n\n if (settled || line >= totalLines) {\n const pendingPrebuildEndLine = this.#pendingPrebuildEndLine;\n this.stopBackgroundTokenize();\n if (pendingPrebuildEndLine >= 0) {\n this.#scheduleStatePrebuild(pendingPrebuildEndLine);\n }\n return;\n }\n\n this.#lastLine = line;\n this.#backgroundChangedRangeIndex = changedRangeIndex;\n this.#postTokenizeMessage(jobId);\n }\n}\n\nfunction tokenizeLine(\n grammar: IGrammar,\n colorMap: string[],\n lineText: string,\n stateStack: StateStack,\n timeLimit?: number,\n collectBracketIgnoredRanges = true,\n resolveTokens = true\n): {\n ruleStack: StateStack;\n resolvedTokens: Array<HighlightedToken>;\n bracketIgnoredRanges: [number, number][];\n} {\n const result = grammar.tokenizeLine2(lineText, stateStack, timeLimit);\n if (result.stoppedEarly) {\n console.warn(\n `[diffs] Time limit reached when tokenizing line: ${lineText.substring(0, 100)}`\n );\n }\n const rawTokens = result.tokens;\n const tokensLength = rawTokens.length / 2;\n const resolvedTokens: Array<HighlightedToken> = [];\n const bracketIgnoredRanges: [number, number][] = [];\n if (!resolveTokens && !collectBracketIgnoredRanges) {\n return {\n ruleStack: result.ruleStack,\n resolvedTokens,\n bracketIgnoredRanges,\n };\n }\n for (let j = 0; j < tokensLength; j++) {\n const offset = rawTokens[2 * j];\n const nextOffset =\n j + 1 < tokensLength ? rawTokens[2 * j + 2] : lineText.length;\n if (offset === nextOffset) {\n // should never reach here, skip if happens anyway\n continue;\n }\n const metadata = rawTokens[2 * j + 1];\n if (resolveTokens) {\n const fg = EncodedTokenMetadata.getForeground(metadata);\n resolvedTokens.push([\n offset,\n colorMap[fg],\n lineText.slice(offset, nextOffset),\n ]);\n }\n if (\n collectBracketIgnoredRanges &&\n EncodedTokenMetadata.getTokenType(metadata) > 0\n ) {\n bracketIgnoredRanges.push([offset, nextOffset]);\n }\n }\n return {\n ruleStack: result.ruleStack,\n resolvedTokens,\n bracketIgnoredRanges,\n };\n}\n\nexport function renderLineTokens(\n tokens: Array<HighlightedToken>\n): (HTMLElement | string)[] {\n return tokens.map(([char, fg, textContent]) => {\n if (char === 0 && fg === '') {\n if (textContent === '') {\n return h('br');\n }\n return textContent;\n }\n return h('span', {\n dataset: {\n char: char.toString(),\n },\n style: `color:${fg};`,\n textContent: textContent,\n });\n });\n}\n\n// Shiki special-cases `text` and `ansi` in codeToHast but does not expose grammars.\nfunction isGrammarlessLanguage(languageId: string): boolean {\n return languageId === 'text' || languageId === 'ansi';\n}\n"],"mappings":";;;;;AAkBA,MAAM,sBAAsB;AAC5B,IAAI,kBAAkB;;AAoBtB,IAAa,kBAAb,MAA6B;CAC3B;CACA;CACA;CACA,aAA+B;CAI/B,aAAa;CACb;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,eAAe;CAGf,cAA4B,CAAC,OAAO;CACpC,wBAAsC,CAAC;CACvC,6BAA6B;CAC7B,yBAEI,CAAC;CACL,YAAoB;CACpB,aAAsB;CACtB,YAAqB;CACrB,mBAA2B;CAC3B,eAAe,EAAE;CACjB,6BAA6B;CAC7B,0BAA0B;CAC1B;CACA,+BAAuC;CACvC,wBAAmE,CAAC;CACpE,6BAAsC;CAEtC,sBAAsB,SAAS,OAAO,gBAA8B;EAGlE,IAAI,KAAKA,cACP;EAEF,MAAM,EAAE,eAAe,GAAG,aAAa,aAAa,eAAe,CAAC;EACpE,MAAM,UAAU,KAAK,IACnB,eAAe,WAAW,WAAW,eAAe,YACpD,KAAKC,cAAc,SACrB;EACA,IACE,KAAKC,aAAa,KAAA,KAClB,CAAC,sBAAsB,KAAKD,cAAc,UAAU,GACpD;GACA,MAAM,KAAKE,aAAa,aAAa,KAAKF,cAAc,UAAU;GAClE,IAAI,KAAKD,cACP;GAEF,KAAKE,WAAW,KAAKC,aAAa,YAChC,KAAKF,cAAc,UACrB;EACF;EACA,KAAKG,mBAAmB;EACxB,KAAKC,uBAAuB,OAAO;CACrC,GAAG,GAAG;CAEN,cAAc,EAAE,WAAkC;EAChD,IAAI,OAAO,SAAS,YAAY,SAAS,MACvC;EAE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;CAElD;CACA,OAAO;EACL,WAAW,OAAO;EAClB;EACA;CACF;AACF;AAEA,SAAgB,iBACd,QAC0B;CAC1B,OAAO,OAAO,KAAK,CAAC,MAAM,IAAI,iBAAiB;EAC7C,IAAI,SAAS,KAAK,OAAO,IAAI;GAC3B,IAAI,gBAAgB,IAClB,OAAO,EAAE,IAAI;GAEf,OAAO;EACT;EACA,OAAO,EAAE,QAAQ;GACf,SAAS,EACP,MAAM,KAAK,SAAS,EACtB;GACA,OAAO,SAAS,GAAG;GACN;EACf,CAAC;CACH,CAAC;AACH;AAGA,SAAS,sBAAsB,YAA6B;CAC1D,OAAO,eAAe,UAAU,eAAe;AACjD"}
|
|
1
|
+
{"version":3,"file":"tokenizer.js","names":["#isCleanedUp","#textDocument","#grammar","#highlighter","#ensureActiveTheme","#scheduleStatePrebuild","#tokenizerId","#backgroundJobId","#backgroundPrebuildEndLine","#backgroundPrebuild","#backgroundTokenize","#themeType","#matchBrackets","#ensureGrammar","#bracketIgnoredRanges","#buildStateStack","#stateStack","#tokenizeLineAt","#mediaQueryList","#resolveSystemThemeType","#emitThemeChange","#disposes","#tokenizeMaxLineLength","#setStyle","#onDeferTokenize","#onThemeChange","#debug","#colorMap","#setTheme","#themeName","#comparisonStateStack","#comparisonStateStackStart","#comparisonLineChanges","#scheduleBackgroundTokenize","#detachMessageListener","#shiftComparisonStateStack","#prebuildStateStack","#pendingPrebuildEndLine","#isStopped","#isPaused","#lastLine","#backgroundChangedLineRanges","#backgroundChangedRangeIndex","#postTokenizeMessage","#isMessageListenerAttached","#onMessage","#attachMessageListener","#cacheBracketIgnoredRanges","#getPreviousEndState"],"sources":["../../src/editor/tokenizer.ts"],"sourcesContent":["import { colorUtils } from '@pierre/theming/color';\nimport {\n EncodedTokenMetadata,\n type IGrammar,\n INITIAL,\n type StateStack,\n} from 'shiki/textmate';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n HighlightedToken,\n RenderRange,\n} from '../types';\nimport type { TextDocument, TextDocumentChange } from './textDocument';\nimport { addEventListener, debounce, h } from './utils';\n\nconst TOKENIZE_TIME_LIMIT = 500;\nlet nextTokenizerId = 0;\n\nexport interface EditorTokenizerProps {\n highlighter: DiffsHighlighter;\n textDocument: TextDocument<unknown>;\n codeOptions: BaseCodeOptions;\n matchBrackets?: boolean;\n setStyle: (style: string) => void;\n onDeferTokenize: (\n lines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light'\n ) => void;\n // Fired after the active theme (light/dark mode or theme name) changes and the\n // new theme CSS has been applied. Lets the editor recompute overlay pieces\n // that captured a resolved theme color, e.g. rounded selection corner masks.\n onThemeChange?: () => void;\n __debug?: boolean;\n}\n\n/** Stoppable code tokenizer for the editor */\nexport class EditorTokenizer {\n #highlighter: DiffsHighlighter;\n #grammar: IGrammar | undefined;\n #mediaQueryList: MediaQueryList;\n #themeType: 'light' | 'dark' = 'dark';\n // The resolved name of the theme currently applied to the editor (e.g.\n // `github-light`). Tracked so `syncTheme` can detect a host-driven theme swap\n // even when the light/dark mode itself is unchanged.\n #themeName = '';\n #colorMap: string[];\n #textDocument: TextDocument<unknown>;\n #tokenizeMaxLineLength: number;\n #setStyle: EditorTokenizerProps['setStyle'];\n #onDeferTokenize: EditorTokenizerProps['onDeferTokenize'];\n #onThemeChange: EditorTokenizerProps['onThemeChange'];\n #matchBrackets: boolean;\n #debug: boolean;\n #disposes?: (() => void)[];\n #isCleanedUp = false;\n\n // state\n #stateStack: StateStack[] = [INITIAL]; // cached state stack by line index\n #comparisonStateStack: StateStack[] = [];\n #comparisonStateStackStart = 0;\n #comparisonLineChanges: NonNullable<\n TextDocumentChange['changedLineChanges']\n > = [];\n #lastLine: number = -1;\n #isStopped: boolean = true;\n #isPaused: boolean = false;\n #backgroundJobId: number = 0;\n #tokenizerId = ++nextTokenizerId;\n #backgroundPrebuildEndLine = -1;\n #pendingPrebuildEndLine = -1;\n #backgroundChangedLineRanges: readonly [number, number][] | undefined;\n #backgroundChangedRangeIndex: number = 0;\n #bracketIgnoredRanges: ([number, number][] | null | undefined)[] = [];\n #isMessageListenerAttached: boolean = false;\n\n #prebuildStateStack = debounce(async (renderRange?: RenderRange) => {\n // Drop work scheduled before cleanUp; a late timer must not call setTheme\n // on a highlighter that tests (or hosts) have already disposed.\n if (this.#isCleanedUp) {\n return;\n }\n const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};\n const endLine = Math.min(\n totalLines === Infinity ? Infinity : startingLine + totalLines,\n this.#textDocument.lineCount\n );\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId)\n ) {\n await this.#highlighter.loadLanguage(this.#textDocument.languageId);\n if (this.#isCleanedUp) {\n return;\n }\n this.#grammar = this.#highlighter.getLanguage(\n this.#textDocument.languageId\n );\n }\n this.#ensureActiveTheme();\n this.#scheduleStatePrebuild(endLine);\n }, 500);\n\n #onMessage = ({ data }: MessageEvent<unknown>) => {\n if (typeof data !== 'object' || data === null) {\n return;\n }\n const { type, tokenizerId, jobId } = data as {\n type?: unknown;\n tokenizerId?: unknown;\n jobId?: unknown;\n };\n if (\n type === 'tokenize' &&\n tokenizerId === this.#tokenizerId &&\n typeof jobId === 'number' &&\n jobId === this.#backgroundJobId\n ) {\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#backgroundPrebuild(jobId);\n } else {\n this.#backgroundTokenize(jobId);\n }\n }\n };\n\n get themeType(): 'light' | 'dark' {\n return this.#themeType;\n }\n\n getStringCommentRegexpRangesInLine(\n lineIndex: number\n ): [number, number][] | null {\n if (\n !this.#matchBrackets ||\n lineIndex < 0 ||\n lineIndex >= this.#textDocument.lineCount\n ) {\n return null;\n }\n this.#ensureGrammar();\n if (this.#grammar === undefined) {\n return null;\n }\n if (this.#bracketIgnoredRanges[lineIndex] === undefined) {\n this.#buildStateStack(lineIndex);\n const state = this.#stateStack[lineIndex] ?? INITIAL;\n const result = this.#tokenizeLineAt(lineIndex, state);\n this.#stateStack[lineIndex + 1] = result.state;\n }\n return this.#bracketIgnoredRanges[lineIndex] ?? null;\n }\n\n constructor({\n codeOptions,\n highlighter,\n textDocument,\n matchBrackets,\n setStyle,\n onDeferTokenize,\n onThemeChange,\n __debug,\n }: EditorTokenizerProps) {\n const {\n themeType: themeTypeOption = 'system',\n theme = DEFAULT_THEMES,\n tokenizeMaxLineLength = 1000,\n } = codeOptions;\n this.#mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');\n let themeType: 'light' | 'dark' | undefined;\n if (themeTypeOption === 'system') {\n // Prefer the host document's computed color-scheme (page CSS/classes can\n // force light/dark while the OS media query differs) over matchMedia.\n themeType = this.#resolveSystemThemeType();\n } else {\n themeType = themeTypeOption;\n }\n // Only track the document/system color scheme when the surface follows it\n // (`themeType: 'system'`). A surface pinned to an explicit 'dark'/'light'\n // theme keeps that theme regardless of the page, so re-tokenizing after an\n // edit must emit the same `--diffs-token-{theme}` variable the SSR markup\n // used; otherwise the edited tokens fall back to the default foreground.\n if (typeof theme !== 'string' && themeTypeOption === 'system') {\n const observer = new MutationObserver((mutations) => {\n for (const { type, attributeName } of mutations) {\n if (\n type === 'attributes' &&\n attributeName !== null &&\n (attributeName === 'class' || attributeName.startsWith('data-'))\n ) {\n const themeType = this.#resolveSystemThemeType();\n this.#emitThemeChange(theme[themeType], themeType);\n break;\n }\n }\n });\n observer.observe(document.documentElement, { attributes: true });\n observer.observe(document.body, { attributes: true });\n this.#disposes = [\n addEventListener(this.#mediaQueryList, 'change', () => {\n // Re-read computed color-scheme so a host-forced scheme still wins\n // when the OS preference changes underneath it.\n const themeType = this.#resolveSystemThemeType();\n this.#emitThemeChange(theme[themeType], themeType);\n }),\n () => observer.disconnect(),\n ];\n }\n this.#highlighter = highlighter;\n this.#textDocument = textDocument;\n this.#tokenizeMaxLineLength = tokenizeMaxLineLength;\n this.#setStyle = setStyle;\n this.#onDeferTokenize = onDeferTokenize;\n this.#onThemeChange = onThemeChange;\n this.#matchBrackets = matchBrackets !== false;\n this.#debug = __debug ?? false;\n this.#ensureGrammar();\n this.#colorMap = [];\n this.#setTheme(\n typeof theme === 'string' ? theme : theme[themeType],\n typeof theme === 'string' ? undefined : themeType\n );\n }\n\n // By default, diffs components support dual themes, but the tokenizer only renders\n // the preferred theme. When the theme type is changed, the tokenizer will re-tokenize the document.\n #emitThemeChange(themeName: string, themeType: 'light' | 'dark') {\n if (themeName === this.#themeName && themeType === this.#themeType) {\n return;\n }\n this.#setTheme(themeName, themeType);\n this.stopBackgroundTokenize();\n this.#stateStack = [INITIAL];\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n if (this.#grammar !== undefined && this.#textDocument.lineCount > 0) {\n this.#scheduleBackgroundTokenize(0);\n }\n // The theme CSS is now applied, so overlay pieces that captured a resolved\n // theme color (e.g. rounded selection corner masks) can recompute against\n // the new colors instead of keeping the old light/dark value.\n this.#onThemeChange?.();\n }\n\n // Respect an explicit host color-scheme override. When the computed value\n // advertises support for both schemes, let the OS preference choose one.\n #resolveSystemThemeType(): 'light' | 'dark' {\n try {\n if (\n typeof document !== 'undefined' &&\n typeof getComputedStyle === 'function' &&\n document.body != null\n ) {\n const colorSchemes = getComputedStyle(document.body).colorScheme.split(\n /\\s+/\n );\n const supportsDark = colorSchemes.includes('dark');\n const supportsLight = colorSchemes.includes('light');\n // A single host-forced scheme wins. `light dark` only declares support\n // for both schemes, so the media query still selects the active one.\n if (supportsDark !== supportsLight) {\n return supportsDark ? 'dark' : 'light';\n }\n }\n } catch {\n // jsdom and similar harnesses may lack getComputedStyle or throw; fall\n // through to the OS media query.\n }\n return this.#mediaQueryList.matches ? 'dark' : 'light';\n }\n\n // Re-apply the editor's theme from the surface's current code options. Edit\n // mode reuses a single tokenizer across re-renders, so when the host swaps the\n // theme — a theme picker, a light/dark toggle, etc. — we must recompute the\n // active theme and re-tokenize. Without this the editor keeps rendering the\n // theme it captured when it first attached (stale line-highlight background\n // and token colors). System-driven changes are still handled by the\n // observers wired up in the constructor; this covers explicit `themeType`/\n // `theme` option changes that those observers don't see.\n syncTheme(codeOptions: BaseCodeOptions): void {\n const { themeType = 'system', theme = DEFAULT_THEMES } = codeOptions;\n // A single pinned theme does not follow the themeType option or system\n // scheme flips; its own classification stays authoritative.\n if (typeof theme === 'string') {\n const pinnedThemeType = this.#highlighter.getTheme(theme).type;\n if (theme === this.#themeName && pinnedThemeType === this.#themeType) {\n return;\n }\n this.#emitThemeChange(theme, pinnedThemeType);\n return;\n }\n const nextThemeType =\n themeType === 'system' ? this.#resolveSystemThemeType() : themeType;\n const nextThemeName = theme[nextThemeType];\n if (\n nextThemeType === this.#themeType &&\n nextThemeName === this.#themeName\n ) {\n return;\n }\n this.#emitThemeChange(nextThemeName, nextThemeType);\n }\n\n #setTheme(themeName: string, themeType?: 'light' | 'dark') {\n const { theme, colorMap } = this.#highlighter.setTheme(themeName);\n const { colors = {} } = this.#highlighter.getTheme(themeName);\n const selectionBackground = colors['editor.selectionBackground'];\n const themeLineHighlightBackground =\n colors['editor.lineHighlightBackground'];\n const lineHighlightBackground =\n themeLineHighlightBackground != null &&\n themeLineHighlightBackground.trim() !== '' &&\n !colorUtils.isFullyTransparent(themeLineHighlightBackground)\n ? themeLineHighlightBackground\n : undefined;\n // A usable theme background opts into the semantic active-line mix.\n // Missing backgrounds retain the resolved row color and rely on a border.\n const lineHighlightBorder =\n colors['editor.lineHighlightBorder'] ??\n (lineHighlightBackground == null\n ? 'color-mix(in lab, var(--diffs-bg) 70%, var(--diffs-fg))'\n : 'transparent');\n const activeLineSourceMix =\n lineHighlightBackground == null ? '100%' : '85%';\n const cursorForeground = colors['editorCursor.foreground'];\n const findMatchBackground = colors['editor.findMatchBackground'];\n const findMatchHighlightBackground =\n colors['editor.findMatchHighlightBackground'];\n const bracketMatchBackground = colors['editorBracketMatch.background'];\n const bracketMatchBorder = colors['editorBracketMatch.border'];\n const hintForeground = colors['editorHint.foreground'];\n const infoForeground = colors['editorInfo.foreground'];\n const warningForeground = colors['editorWarning.foreground'];\n const errorForeground = colors['editorError.foreground'];\n this.#setStyle(`:host {\n --diffs-editor-selection-bg: ${selectionBackground ?? 'var(--diffs-line-bg)'};\n --diffs-editor-line-highlight-border: ${lineHighlightBorder};\n --diffs-editor-active-line-source-mix: ${activeLineSourceMix};\n --diffs-editor-match-bg: ${findMatchBackground ?? 'initial'};\n --diffs-editor-match-highlight-bg: ${findMatchHighlightBackground ?? 'initial'};\n --diffs-editor-bracket-match-bg: ${bracketMatchBackground ?? 'initial'};\n --diffs-editor-bracket-match-border: ${bracketMatchBorder ?? 'initial'};\n --diffs-editor-cursor-fg: ${cursorForeground ?? 'initial'};\n --diffs-editor-hint-fg: ${hintForeground ?? 'initial'};\n --diffs-editor-info-fg: ${infoForeground ?? 'initial'};\n --diffs-editor-warning-fg: ${warningForeground ?? 'initial'};\n --diffs-editor-error-fg: ${errorForeground ?? 'initial'};\n }`);\n this.#themeName = themeName;\n this.#themeType = themeType ?? theme.type;\n this.#colorMap = colorMap;\n }\n\n // The shared highlighter is also used for dual-theme SSR (`themes: {dark,light}`),\n // which leaves its active theme on whichever pass finished last (usually light).\n // The tokenizer caches a single-theme colorMap from construction; if we tokenize\n // without re-activating that theme, grammar color indices are looked up in the\n // wrong map — property names resolve to a near-foreground gray while types and\n // comments (stable across maps) still look correct. Re-apply before every\n // tokenize path so a first edit after load matches a later file-switch re-attach.\n #ensureActiveTheme(): void {\n if (this.#themeName === '') {\n return;\n }\n const { colorMap } = this.#highlighter.setTheme(this.#themeName);\n this.#colorMap = colorMap;\n }\n\n cleanUp(): void {\n this.#isCleanedUp = true;\n this.stopBackgroundTokenize();\n this.#detachMessageListener();\n this.#disposes?.forEach((dispose) => dispose());\n this.#disposes = undefined;\n }\n\n // to use `tokenize`, call `prebuildStateStackMap` first to prebuild\n // the state stack map for the given render range.\n tokenize(\n change: TextDocumentChange,\n renderRange?: RenderRange\n ): Map<number, Array<HighlightedToken>> {\n this.#ensureGrammar();\n this.#ensureActiveTheme();\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId)\n ) {\n throw new Error(\n `Grammar for language \"${this.#textDocument.languageId}\" not loaded`\n );\n }\n\n if (this.#matchBrackets) {\n // Clear ignored token ranges for lines invalidated by the edit.\n this.#bracketIgnoredRanges.length = Math.min(\n this.#bracketIgnoredRanges.length,\n change.startLine\n );\n }\n\n const { lineCount } = this.#textDocument;\n const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};\n const renderRangeEndLine =\n totalLines === Infinity\n ? lineCount\n : Math.min(startingLine + totalLines, lineCount);\n\n const dirtyStart = change.startLine;\n const viewStart = Math.max(startingLine, dirtyStart);\n const crossesRenderRangeEnd =\n renderRange !== undefined &&\n totalLines !== Infinity &&\n change.lineDelta > 0 &&\n dirtyStart < renderRangeEndLine &&\n change.endLine >= renderRangeEndLine;\n const canReuseCachedStates =\n change.lineDelta === 0 &&\n (change.changedLineChanges?.every(([, , lineDelta]) => lineDelta === 0) ??\n true);\n const canCacheTokenizedStates =\n canReuseCachedStates ||\n renderRange === undefined ||\n dirtyStart >= viewStart;\n const changedLineRanges: readonly [number, number][] =\n change.changedLineRanges ?? [[dirtyStart, change.endLine]];\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n let offscreenSyncEnd = -1;\n if (dirtyStart < viewStart) {\n for (const [rangeStart, rangeEnd] of changedLineRanges) {\n if (rangeStart < viewStart) {\n offscreenSyncEnd = Math.max(\n offscreenSyncEnd,\n Math.min(rangeEnd, viewStart - 1)\n );\n }\n }\n }\n const shouldFlushOffscreenLines =\n offscreenSyncEnd >= dirtyStart &&\n (canReuseCachedStates || change.lineDelta < 0);\n if (canReuseCachedStates) {\n this.#buildStateStack(dirtyStart);\n } else {\n this.#shiftComparisonStateStack(change);\n if (renderRange === undefined || dirtyStart >= viewStart) {\n this.#buildStateStack(viewStart);\n }\n }\n\n let changedRangeIndex = 0;\n let currentChangedRangeEnd = changedLineRanges[changedRangeIndex][1];\n let backgroundStartLine: number | undefined;\n let backgroundChangedRangeIndex = 0;\n let line = canReuseCachedStates\n ? changedLineRanges[changedRangeIndex][0]\n : viewStart;\n let settled = false;\n const dirtyLines: Map<number, Array<HighlightedToken>> = new Map();\n const offscreenDirtyLines:\n | Map<number, Array<HighlightedToken>>\n | undefined = shouldFlushOffscreenLines ? new Map() : undefined;\n if (offscreenDirtyLines !== undefined && !canReuseCachedStates) {\n const offscreenEnd = Math.min(\n offscreenSyncEnd + 1,\n viewStart,\n renderRangeEndLine\n );\n if (offscreenEnd > dirtyStart) {\n this.#buildStateStack(offscreenEnd);\n let offscreenLine = dirtyStart;\n let offscreenState = this.#stateStack[offscreenLine] ?? INITIAL;\n for (; offscreenLine < offscreenEnd; offscreenLine++) {\n const resolved = this.#tokenizeLineAt(offscreenLine, offscreenState);\n offscreenState = resolved.state;\n offscreenDirtyLines.set(offscreenLine, resolved.resolvedTokens);\n }\n this.#stateStack[offscreenEnd] = offscreenState;\n }\n }\n // Seed the loop's grammar state after the offscreen flush, not before it.\n // When a delete's removed lines reach the viewport's first line, the flush\n // rebuilds the cached state up to `line`; reading it earlier would capture\n // the truncated INITIAL state and color the viewport as if outside an open\n // construct (block comment, template literal) it is actually inside.\n let state = this.#stateStack[line] ?? INITIAL;\n for (; line < renderRangeEndLine; ) {\n const previousNextState = canReuseCachedStates\n ? this.#stateStack[line + 1]\n : undefined;\n if (canCacheTokenizedStates) {\n this.#stateStack[line] = state;\n }\n\n const { resolvedTokens, state: nextState } = this.#tokenizeLineAt(\n line,\n state\n );\n state = nextState;\n\n if (line >= viewStart) {\n dirtyLines.set(line, resolvedTokens);\n } else {\n offscreenDirtyLines?.set(line, resolvedTokens);\n }\n\n if (canCacheTokenizedStates) {\n this.#stateStack[line + 1] = state;\n }\n settled =\n line >= currentChangedRangeEnd &&\n canReuseCachedStates &&\n previousNextState !== undefined &&\n state.equals(previousNextState);\n if (settled) {\n changedRangeIndex++;\n const nextRange = changedLineRanges[changedRangeIndex];\n if (nextRange === undefined) {\n break;\n }\n if (nextRange[0] >= renderRangeEndLine) {\n backgroundStartLine = nextRange[0];\n backgroundChangedRangeIndex = changedRangeIndex;\n break;\n }\n if (this.#stateStack[nextRange[0]] === undefined) {\n currentChangedRangeEnd = nextRange[1];\n line++;\n } else {\n line = nextRange[0];\n state = this.#stateStack[line] ?? state;\n currentChangedRangeEnd = nextRange[1];\n }\n settled = false;\n continue;\n }\n line++;\n }\n\n if (canCacheTokenizedStates) {\n if (line < renderRangeEndLine) {\n this.#stateStack[line + 1] = state;\n } else {\n this.#stateStack[line] = state;\n }\n }\n\n if (offscreenDirtyLines !== undefined && offscreenDirtyLines.size > 0) {\n this.#onDeferTokenize(offscreenDirtyLines, this.#themeType);\n }\n\n if (backgroundStartLine !== undefined) {\n this.#scheduleBackgroundTokenize(\n backgroundStartLine,\n changedLineRanges,\n backgroundChangedRangeIndex\n );\n } else if (!settled && line < lineCount) {\n const backgroundLine =\n crossesRenderRangeEnd && dirtyStart >= viewStart\n ? renderRangeEndLine\n : dirtyStart < viewStart && !canReuseCachedStates\n ? dirtyStart\n : line;\n this.#scheduleBackgroundTokenize(\n backgroundLine,\n changedLineRanges,\n changedRangeIndex\n );\n }\n\n return dirtyLines;\n }\n\n prebuildStateStack(renderRange?: RenderRange): void {\n this.#ensureGrammar();\n this.#prebuildStateStack(renderRange);\n }\n\n stopBackgroundTokenize(): void {\n this.#pendingPrebuildEndLine = -1;\n if (this.#isStopped) {\n return;\n }\n this.#isStopped = true;\n this.#isPaused = false;\n this.#lastLine = -1;\n this.#backgroundPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = undefined;\n this.#backgroundChangedRangeIndex = 0;\n this.#comparisonStateStack = [];\n this.#comparisonStateStackStart = 0;\n this.#comparisonLineChanges = [];\n this.#detachMessageListener();\n }\n\n pauseBackgroundTokenize(): void {\n if (this.#isStopped || this.#isPaused) {\n return;\n }\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization paused', {\n jobId: this.#backgroundJobId,\n });\n }\n this.#isPaused = true;\n }\n\n resumeBackgroundTokenize(): void {\n if (\n this.#isStopped ||\n !this.#isPaused ||\n this.#grammar === undefined ||\n this.#lastLine < 0\n ) {\n return;\n }\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization resumed', {\n jobId: this.#backgroundJobId,\n });\n }\n this.#isPaused = false;\n this.#postTokenizeMessage(this.#backgroundJobId);\n }\n\n #ensureGrammar(): void {\n if (\n this.#grammar === undefined &&\n !isGrammarlessLanguage(this.#textDocument.languageId) &&\n this.#highlighter\n .getLoadedLanguages()\n .includes(this.#textDocument.languageId)\n ) {\n this.#grammar = this.#highlighter.getLanguage(\n this.#textDocument.languageId\n );\n }\n }\n\n #attachMessageListener(): void {\n if (this.#isMessageListenerAttached) {\n return;\n }\n globalThis.addEventListener('message', this.#onMessage);\n this.#isMessageListenerAttached = true;\n }\n\n #detachMessageListener(): void {\n if (!this.#isMessageListenerAttached) {\n return;\n }\n globalThis.removeEventListener('message', this.#onMessage);\n this.#isMessageListenerAttached = false;\n }\n\n #postTokenizeMessage(jobId: number): void {\n // use `postMessage` instead of `setTimeout(fn, 0)` to avoid 4ms delay\n globalThis.postMessage({\n type: 'tokenize',\n tokenizerId: this.#tokenizerId,\n jobId,\n });\n }\n\n #scheduleBackgroundTokenize(\n startLine: number,\n changedLineRanges?: readonly [number, number][],\n changedRangeIndex = 0\n ): void {\n if (isGrammarlessLanguage(this.#textDocument.languageId)) {\n return;\n }\n\n const jobId = ++this.#backgroundJobId;\n\n if (this.#debug) {\n console.log('[diffs/editor] background tokenization scheduled', {\n jobId,\n startLine,\n changedLineRanges,\n changedRangeIndex,\n });\n }\n\n this.#isStopped = false;\n this.#isPaused = false;\n this.#lastLine = startLine;\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#pendingPrebuildEndLine = Math.max(\n this.#pendingPrebuildEndLine,\n this.#backgroundPrebuildEndLine\n );\n }\n this.#backgroundPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = changedLineRanges;\n this.#backgroundChangedRangeIndex = changedRangeIndex;\n this.#attachMessageListener();\n this.#postTokenizeMessage(jobId);\n }\n\n #scheduleStatePrebuild(endLine: number): void {\n if (this.#grammar === undefined || this.#stateStack.length > endLine) {\n return;\n }\n // Extend an active prebuild, or retain the target until the foreground\n // edit job reconverges and releases the state cache.\n if (!this.#isStopped) {\n if (this.#backgroundPrebuildEndLine >= 0) {\n this.#backgroundPrebuildEndLine = Math.max(\n this.#backgroundPrebuildEndLine,\n endLine\n );\n } else {\n this.#pendingPrebuildEndLine = Math.max(\n this.#pendingPrebuildEndLine,\n endLine\n );\n }\n return;\n }\n\n const jobId = ++this.#backgroundJobId;\n this.#isStopped = false;\n this.#isPaused = false;\n this.#lastLine = this.#stateStack.length - 1;\n this.#backgroundPrebuildEndLine = endLine;\n this.#pendingPrebuildEndLine = -1;\n this.#backgroundChangedLineRanges = undefined;\n this.#backgroundChangedRangeIndex = 0;\n this.#attachMessageListener();\n this.#postTokenizeMessage(jobId);\n }\n\n #tokenizeLineAt(\n line: number,\n state: StateStack\n ): { resolvedTokens: Array<HighlightedToken>; state: StateStack } {\n const lineText = this.#textDocument.getLineText(line);\n if (lineText.length > this.#tokenizeMaxLineLength) {\n console.warn(\n `[diffs] Line(${line}) too long to tokenize: ${lineText.length}`\n );\n this.#cacheBracketIgnoredRanges(line, null);\n return { resolvedTokens: [[0, '', lineText]], state };\n }\n if (\n this.#grammar === undefined ||\n lineText === '' ||\n lineText.trim() === ''\n ) {\n this.#cacheBracketIgnoredRanges(line, null);\n return { resolvedTokens: [[0, '', lineText]], state };\n }\n const result = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets\n );\n this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);\n return {\n resolvedTokens: result.resolvedTokens,\n state: result.ruleStack,\n };\n }\n\n #cacheBracketIgnoredRanges(\n line: number,\n ranges: [number, number][] | null\n ): void {\n if (this.#matchBrackets) {\n this.#bracketIgnoredRanges[line] = ranges;\n }\n }\n\n // Preserve old end states as comparison-only sentinels, copying whichever\n // side of the edit is smaller. Index shifts are resolved lazily on lookup.\n #shiftComparisonStateStack(change: TextDocumentChange): void {\n const lineChanges =\n change.changedLineChanges ??\n ([[change.startLine, change.endLine, change.lineDelta]] as const);\n const comparisonStart = change.startLine + 1;\n const comparisonLength = this.#stateStack.length - comparisonStart;\n if (comparisonStart <= comparisonLength) {\n this.#comparisonStateStack = this.#stateStack;\n this.#comparisonStateStackStart = 0;\n this.#stateStack = this.#stateStack.slice(0, comparisonStart);\n } else {\n this.#comparisonStateStackStart = comparisonStart;\n this.#comparisonStateStack = this.#stateStack.slice(comparisonStart);\n this.#stateStack.length = Math.min(\n this.#stateStack.length,\n comparisonStart\n );\n }\n this.#comparisonLineChanges = lineChanges;\n }\n\n #getPreviousEndState(line: number): StateStack | undefined {\n let previousLine = line;\n for (\n let index = this.#comparisonLineChanges.length - 1;\n index >= 0;\n index--\n ) {\n const [startLine, endLine, lineDelta] =\n this.#comparisonLineChanges[index];\n if (lineDelta === 0) {\n continue;\n }\n if (previousLine > endLine) {\n previousLine -= lineDelta;\n } else if (previousLine > startLine) {\n return this.#stateStack[line];\n }\n }\n return (\n this.#comparisonStateStack[\n previousLine - this.#comparisonStateStackStart\n ] ?? this.#stateStack[line]\n );\n }\n\n #buildStateStack(endAt: number, timeBudget?: number): boolean {\n const boundedEndAt = Math.min(\n Math.max(0, endAt),\n this.#textDocument.lineCount\n );\n if (this.#stateStack.length > boundedEndAt || this.#grammar === undefined) {\n return true;\n }\n const startedAt = timeBudget === undefined ? 0 : performance.now();\n let line = this.#stateStack.length - 1;\n let state = this.#stateStack[line] ?? INITIAL;\n while (line < boundedEndAt) {\n this.#stateStack[line] = state;\n const lineText = this.#textDocument.getLineText(line);\n if (\n lineText.length <= this.#tokenizeMaxLineLength &&\n lineText !== '' &&\n lineText.trim() !== ''\n ) {\n const result = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets,\n false\n );\n this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);\n state = result.ruleStack;\n } else {\n this.#cacheBracketIgnoredRanges(line, null);\n }\n line++;\n this.#stateStack[line] = state;\n if (\n timeBudget !== undefined &&\n performance.now() - startedAt > timeBudget\n ) {\n break;\n }\n }\n return line >= boundedEndAt;\n }\n\n #backgroundPrebuild(jobId: number): void {\n if (\n this.#isStopped ||\n this.#isPaused ||\n this.#grammar === undefined ||\n jobId !== this.#backgroundJobId\n ) {\n return;\n }\n\n this.#ensureActiveTheme();\n // State prebuilds intentionally omit rendered tokens and yield between\n // short chunks so a deep viewport does not monopolize the main thread.\n const complete = this.#buildStateStack(this.#backgroundPrebuildEndLine, 1);\n if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) {\n return;\n }\n if (complete) {\n this.stopBackgroundTokenize();\n return;\n }\n this.#lastLine = this.#stateStack.length - 1;\n this.#postTokenizeMessage(jobId);\n }\n\n #backgroundTokenize(jobId: number) {\n if (\n this.#isStopped ||\n this.#isPaused ||\n this.#grammar === undefined ||\n jobId !== this.#backgroundJobId\n ) {\n return;\n }\n\n this.#ensureActiveTheme();\n\n const t = performance.now();\n const lines = new Map<number, Array<HighlightedToken>>();\n const totalLines = this.#textDocument.lineCount;\n const changedLineRanges = this.#backgroundChangedLineRanges;\n\n let line = this.#lastLine;\n let state = this.#stateStack[line] ?? INITIAL;\n let settled = false;\n let changedRangeIndex = this.#backgroundChangedRangeIndex;\n let currentChangedRangeEnd = changedLineRanges?.[changedRangeIndex]?.[1];\n for (; line < totalLines; ) {\n this.#stateStack[line] = state;\n\n const previousNextState =\n currentChangedRangeEnd !== undefined\n ? this.#getPreviousEndState(line + 1)\n : undefined;\n const lineText = this.#textDocument.getLineText(line);\n if (lineText.length > this.#tokenizeMaxLineLength) {\n console.warn(\n `[diffs] Line(${line}) too long to tokenize: ${lineText.length}`\n );\n lines.set(line, [[0, '', lineText]]);\n this.#cacheBracketIgnoredRanges(line, null);\n } else if (lineText === '' || lineText.trim() === '') {\n lines.set(line, [[0, '', lineText]]);\n this.#cacheBracketIgnoredRanges(line, null);\n } else {\n const ret = tokenizeLine(\n this.#grammar,\n this.#colorMap,\n lineText,\n state,\n TOKENIZE_TIME_LIMIT,\n this.#matchBrackets\n );\n lines.set(line, ret.resolvedTokens);\n this.#cacheBracketIgnoredRanges(line, ret.bracketIgnoredRanges);\n state = ret.ruleStack;\n }\n\n this.#stateStack[line + 1] = state;\n settled =\n currentChangedRangeEnd !== undefined &&\n line >= currentChangedRangeEnd &&\n previousNextState !== undefined &&\n state.equals(previousNextState);\n line++;\n if (settled) {\n changedRangeIndex++;\n const nextRange = changedLineRanges?.[changedRangeIndex];\n if (nextRange === undefined) {\n break;\n }\n currentChangedRangeEnd = nextRange[1];\n if (this.#stateStack[nextRange[0]] === undefined) {\n settled = false;\n } else {\n line = nextRange[0];\n state = this.#stateStack[line] ?? state;\n settled = false;\n continue;\n }\n }\n\n // limit the time of partial tokenize to 1ms\n if (performance.now() - t > 1) {\n break;\n }\n }\n\n this.#onDeferTokenize(lines, this.#themeType);\n if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) {\n return;\n }\n\n if (settled || line >= totalLines) {\n const pendingPrebuildEndLine = this.#pendingPrebuildEndLine;\n this.stopBackgroundTokenize();\n if (pendingPrebuildEndLine >= 0) {\n this.#scheduleStatePrebuild(pendingPrebuildEndLine);\n }\n return;\n }\n\n this.#lastLine = line;\n this.#backgroundChangedRangeIndex = changedRangeIndex;\n this.#postTokenizeMessage(jobId);\n }\n}\n\nfunction tokenizeLine(\n grammar: IGrammar,\n colorMap: string[],\n lineText: string,\n stateStack: StateStack,\n timeLimit?: number,\n collectBracketIgnoredRanges = true,\n resolveTokens = true\n): {\n ruleStack: StateStack;\n resolvedTokens: Array<HighlightedToken>;\n bracketIgnoredRanges: [number, number][];\n} {\n const result = grammar.tokenizeLine2(lineText, stateStack, timeLimit);\n if (result.stoppedEarly) {\n console.warn(\n `[diffs] Time limit reached when tokenizing line: ${lineText.substring(0, 100)}`\n );\n }\n const rawTokens = result.tokens;\n const tokensLength = rawTokens.length / 2;\n const resolvedTokens: Array<HighlightedToken> = [];\n const bracketIgnoredRanges: [number, number][] = [];\n if (!resolveTokens && !collectBracketIgnoredRanges) {\n return {\n ruleStack: result.ruleStack,\n resolvedTokens,\n bracketIgnoredRanges,\n };\n }\n for (let j = 0; j < tokensLength; j++) {\n const offset = rawTokens[2 * j];\n const nextOffset =\n j + 1 < tokensLength ? rawTokens[2 * j + 2] : lineText.length;\n if (offset === nextOffset) {\n // should never reach here, skip if happens anyway\n continue;\n }\n const metadata = rawTokens[2 * j + 1];\n if (resolveTokens) {\n const fg = EncodedTokenMetadata.getForeground(metadata);\n resolvedTokens.push([\n offset,\n colorMap[fg],\n lineText.slice(offset, nextOffset),\n ]);\n }\n if (\n collectBracketIgnoredRanges &&\n EncodedTokenMetadata.getTokenType(metadata) > 0\n ) {\n bracketIgnoredRanges.push([offset, nextOffset]);\n }\n }\n return {\n ruleStack: result.ruleStack,\n resolvedTokens,\n bracketIgnoredRanges,\n };\n}\n\nexport function renderLineTokens(\n tokens: Array<HighlightedToken>\n): (HTMLElement | string)[] {\n return tokens.map(([char, fg, textContent]) => {\n if (char === 0 && fg === '') {\n if (textContent === '') {\n return h('br');\n }\n return textContent;\n }\n return h('span', {\n dataset: {\n char: char.toString(),\n },\n style: `color:${fg};`,\n textContent: textContent,\n });\n });\n}\n\n// Shiki special-cases `text` and `ansi` in codeToHast but does not expose grammars.\nfunction isGrammarlessLanguage(languageId: string): boolean {\n return languageId === 'text' || languageId === 'ansi';\n}\n"],"mappings":";;;;;AAkBA,MAAM,sBAAsB;AAC5B,IAAI,kBAAkB;;AAoBtB,IAAa,kBAAb,MAA6B;CAC3B;CACA;CACA;CACA,aAA+B;CAI/B,aAAa;CACb;CACA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AAE,IAAI;GAEf,OAAO;EACT;EACA,OAAO,EAAE,QAAQ;GACf,SAAS,EACP,MAAM,KAAK,SAAS,EACtB;GACA,OAAO,SAAS,GAAG;GACN;EACf,CAAC;CACH,CAAC;AACH;AAGA,SAAS,sBAAsB,YAA6B;CAC1D,OAAO,eAAe,UAAU,eAAe;AACjD"}
|
package/dist/react/CodeView.js
CHANGED
|
@@ -8,8 +8,8 @@ import { renderDiffChildren } from "./utils/renderDiffChildren.js";
|
|
|
8
8
|
import { renderFileChildren } from "./utils/renderFileChildren.js";
|
|
9
9
|
import { WorkerPoolContext } from "./WorkerPoolContext.js";
|
|
10
10
|
import { forwardRef, memo, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
11
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
11
|
import { createPortal, flushSync } from "react-dom";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
//#region src/react/CodeView.tsx
|
|
14
14
|
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
15
15
|
function createDefaultCache(controlled) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Element, ElementContent, Properties } from "../node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.js";
|
|
2
|
-
import { BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, DiffsTextDocument, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HighlightedToken, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
|
|
2
|
+
import { BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, DiffsTextDocument, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HighlightedToken, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
|
|
3
3
|
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
|
|
4
4
|
import { DiffLineMetadata } from "../utils/iterateOverDiff.js";
|
|
5
5
|
|
|
@@ -146,6 +146,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
146
146
|
initializeHighlighter(): Promise<DiffsHighlighter>;
|
|
147
147
|
hydrate(diff: FileDiffMetadata | undefined): void;
|
|
148
148
|
private getLocalHighlightTheme;
|
|
149
|
+
getEffectiveCodeOptions(): Pick<BaseCodeOptions, 'theme' | 'tokenizeMaxLineLength'>;
|
|
149
150
|
private getRenderOptions;
|
|
150
151
|
renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;
|
|
151
152
|
asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;UAyIiB,wBAAA,SAAiC,eAAe;EAC/D,gBAAA,GAAmB,oBAAA;AAAA;AAAA,UAGJ,oCAAA,SAA6C,IAAA,CAC5D,2BAAA;EAGA,gBAAA,EAAkB,oBAAA;AAAA;AAAA,UAGH,0BAAA;EACf,IAAA;EACA,QAAA,EAAU,SAAS;EACnB,iBAAA;EACA,iBAAA;AAAA;AAAA,UAGe,wBAAA;EACf,IAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,cAAA;EACf,cAAA,EAAgB,SAAA;EAChB,gBAAA,GAAmB,UAAA;EACnB,iBAAA,GAAoB,UAAA;AAAA;AAAA,UAUL,mBAAA;EACf,IAAA;EACA,SAAA;EACA,SAAA;EACA,gBAAA;EACA,c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,QAeW,cAAA;EAAA,QAyBN,yBAAA;EAeD,kBAAA,CACL,IAAA,EAAM,gBAAA,EACN,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,EACT,WAAA;EAAA,QAQM,oBAAA;EAAA,QA+BA,4BAAA;EAAA,QAcA,yBAAA;EAaD,gBAAA,CAAiB,KAAA;EAAA,QAIhB,oBAAA;EAAA,QAIA,iBAAA;EAgjBD,aAAA,CACL,IAAA,yCACA,MAAA,EAAQ,iBAAA,GACP,cAAA;EAyBI,aAAA,CACL,MAAA,EAAQ,iBAAA,EACR,QAAA,GAAU,cAAA,KACT,OAAA;EAkDI,cAAA,CACL,MAAA,EAAQ,iBAAA,EACR,YAAA,GAAc,cAAA;EAKT,iBAAA,CACL,QAAA,EAAU,cAAA,IACV,UAAA;EAAA,QAqBM,wBAAA;EAAA,QAiEA,cAAA;EAAA,QA+DA,YAAA;AAAA"}
|
|
@@ -362,6 +362,13 @@ var DiffHunksRenderer = class {
|
|
|
362
362
|
getLocalHighlightTheme() {
|
|
363
363
|
return this.workerManager?.getDiffRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
|
|
364
364
|
}
|
|
365
|
+
getEffectiveCodeOptions() {
|
|
366
|
+
const poolOptions = this.workerManager?.isWorkingPool() === true ? this.workerManager.getDiffRenderOptions() : void 0;
|
|
367
|
+
return {
|
|
368
|
+
theme: this.getLocalHighlightTheme(),
|
|
369
|
+
tokenizeMaxLineLength: poolOptions?.tokenizeMaxLineLength ?? this.options.tokenizeMaxLineLength
|
|
370
|
+
};
|
|
371
|
+
}
|
|
365
372
|
getRenderOptions(diff) {
|
|
366
373
|
const options = (() => {
|
|
367
374
|
if (this.workerManager?.isWorkingPool() === true) {
|