@openclaw/diffs 2026.9.6 → 2026.9.7
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":"textMeasure.d.ts","names":[],"sources":["../../src/editor/textMeasure.ts"],"mappings":";cAUa;;;
|
|
1
|
+
{"version":3,"file":"textMeasure.d.ts","names":[],"sources":["../../src/editor/textMeasure.ts"],"mappings":";cAUa;;;EAUX;;EAEA;;EAEA;;EAEA;;EAGA,KAAK,MAAM;;;;;;;;;;;;;;;;EA+DX;;EAwCA,iBAAiB;;;;;EA0CjB,iBACE,kBACA,sBACA;;EAoBF,uBAAuB;;;;;;EAYvB,oBAAoB;;;;;;EAiDpB;;;iBAYc,wBAAwB;;iBAiBxB,gCACd,cACA;;iBA6Cc,6BACd;;;;;;iBA2Bc,4BACd,cACA"}
|
|
@@ -4,6 +4,7 @@ const TEXT_WIDTH_CACHE_LIMIT = 4096;
|
|
|
4
4
|
const COMBINING_MARK_PATTERN = /\p{Mark}/u;
|
|
5
5
|
var Metrics = class {
|
|
6
6
|
#root;
|
|
7
|
+
#canvas;
|
|
7
8
|
#canvasCtx;
|
|
8
9
|
#font;
|
|
9
10
|
#textWidthCache = /* @__PURE__ */ new Map();
|
|
@@ -19,7 +20,8 @@ var Metrics = class {
|
|
|
19
20
|
init(root) {
|
|
20
21
|
if (this.#root === root && this.#canvasCtx !== void 0 && this.ch !== -1) return;
|
|
21
22
|
this.#root = root;
|
|
22
|
-
this.#
|
|
23
|
+
this.#canvas ??= h("canvas", { style: { display: "none" } });
|
|
24
|
+
this.#canvasCtx ??= this.#canvas.getContext("2d") ?? void 0;
|
|
23
25
|
if (this.#canvasCtx === void 0) throw new Error("Could not get canvas context");
|
|
24
26
|
const parent = root.parentElement;
|
|
25
27
|
if (parent !== null) {
|
|
@@ -32,7 +34,7 @@ var Metrics = class {
|
|
|
32
34
|
const font = fontSize + " " + fontFamily;
|
|
33
35
|
if (this.#font !== font || this.ch === -1) {
|
|
34
36
|
this.#font = font;
|
|
35
|
-
this.#
|
|
37
|
+
this.#setCanvasFont(font);
|
|
36
38
|
this.ch = this.canvasMeasureTextWidth("0");
|
|
37
39
|
this.clearTextWidthCache();
|
|
38
40
|
}
|
|
@@ -56,13 +58,35 @@ var Metrics = class {
|
|
|
56
58
|
*/
|
|
57
59
|
remeasureCharacterWidth() {
|
|
58
60
|
if (this.#canvasCtx === void 0 || this.#font === void 0) return false;
|
|
59
|
-
this.#
|
|
61
|
+
this.#setCanvasFont(this.#font);
|
|
60
62
|
const ch = this.canvasMeasureTextWidth("0");
|
|
61
63
|
const characterWidthChanged = ch !== this.ch;
|
|
62
64
|
if (characterWidthChanged) this.ch = ch;
|
|
63
65
|
const textWidthCacheCleared = this.#clearTextWidthCache();
|
|
64
66
|
return characterWidthChanged || textWidthCacheCleared;
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Set the canvas font while the canvas is connected to the document.
|
|
70
|
+
*
|
|
71
|
+
* WebKit resolves a canvas font from the canvas element's computed style at
|
|
72
|
+
* assignment. A detached canvas has none, so WebKit ignores user-installed
|
|
73
|
+
* fonts and measures the fallback family while the DOM renders the real font,
|
|
74
|
+
* shifting every caret and selection in hosts that allow user-installed fonts
|
|
75
|
+
* (WKWebView, Playwright WebKit). Connecting the canvas for the assignment
|
|
76
|
+
* makes it measure the same font the DOM renders.
|
|
77
|
+
*/
|
|
78
|
+
#setCanvasFont(font) {
|
|
79
|
+
const root = this.#root;
|
|
80
|
+
const canvas = this.#canvas;
|
|
81
|
+
const canvasCtx = this.#canvasCtx;
|
|
82
|
+
if (root == null || canvas == null || canvasCtx == null) throw new Error("Metrics not initialized");
|
|
83
|
+
root.append(canvas);
|
|
84
|
+
try {
|
|
85
|
+
canvasCtx.font = font;
|
|
86
|
+
} finally {
|
|
87
|
+
canvas.remove();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
66
90
|
/** measure the width of the text */
|
|
67
91
|
measureTextWidth(text) {
|
|
68
92
|
if (!text.includes(" ")) return this.#measureTextWidthWithoutTabs(text);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textMeasure.js","names":[],"sources":["../../src/editor/textMeasure.ts"],"sourcesContent":["import { getGraphemeSegmenter, h, round } from './utils';\n\n// Upper bound on cached DOM text-width measurements. The cache only holds\n// non-ASCII runs (emoji, ZWJ sequences, variation selectors, combining marks),\n// so it stays small for ordinary code, but capping it prevents unbounded growth\n// on emoji-heavy documents. Past the cap the oldest entry is evicted.\nconst TEXT_WIDTH_CACHE_LIMIT = 4096;\n\nconst COMBINING_MARK_PATTERN = /\\p{Mark}/u;\n\nexport class Metrics {\n #root?: HTMLElement;\n #canvasCtx?: CanvasRenderingContext2D;\n #font?: string;\n\n // Memoizes domMeasureTextWidth() results\n #textWidthCache = new Map<string, number>();\n\n /** Width of the '0' character. */\n ch: number = -1;\n /** Size of a tab(\\t) character. */\n tabSize: number = 2;\n /** Height of the code line. */\n lineHeight: number = 20;\n /** Padding top of the root element. */\n paddingTop: number = 0;\n\n /** initialize the metrics */\n init(root: HTMLElement): void {\n if (\n this.#root === root &&\n this.#canvasCtx !== undefined &&\n this.ch !== -1\n ) {\n // already initialized\n return;\n }\n\n this.#root = root;\n this.#canvasCtx ??=\n document.createElement('canvas').getContext('2d') ?? undefined;\n if (this.#canvasCtx === undefined) {\n throw new Error('Could not get canvas context');\n }\n\n const parent = root.parentElement;\n if (parent !== null) {\n const { paddingTop } = getComputedStyle(parent);\n if (paddingTop.endsWith('px')) {\n this.paddingTop = parseFloat(paddingTop.slice(0, -2));\n }\n }\n\n const { fontSize, fontFamily, tabSize, lineHeight } =\n getComputedStyle(root);\n if (lineHeight.endsWith('px')) {\n this.lineHeight = parseFloat(lineHeight.slice(0, -2));\n } else if (fontSize.endsWith('px')) {\n this.lineHeight = round(\n parseFloat(fontSize.slice(0, -2)) * parseFloat(lineHeight)\n );\n }\n const font = fontSize + ' ' + fontFamily;\n if (this.#font !== font || this.ch === -1) {\n this.#font = font;\n this.#canvasCtx.font = font;\n this.ch = this.canvasMeasureTextWidth('0');\n // Cached DOM widths were measured against the previous font.\n this.clearTextWidthCache();\n }\n const nextTabSize = parseInt(tabSize, 10);\n if (!Number.isNaN(nextTabSize)) {\n this.tabSize = nextTabSize;\n }\n }\n\n /**\n * Re-measure the '0' character width against the font that is loaded right\n * now, returning true when measurement-dependent UI should refresh.\n *\n * A custom web font can finish loading after the editor first renders.\n * Until then canvas measureText reports the fallback font's width, and\n * getComputedStyle returns the same font-family string before and after the\n * file arrives, so init()'s font guard never re-measures on its own. Call\n * this once fonts have settled (e.g. on document.fonts.ready) to replace a\n * width measured against the fallback font with the real glyph width. Font\n * completion can also change DOM-measured emoji/ZWJ widths while leaving the\n * ASCII width unchanged, and the computed font string stays the same in both\n * cases. The boolean return lets the caller skip re-rendering when there is no\n * measured state to refresh.\n */\n remeasureCharacterWidth(): boolean {\n if (this.#canvasCtx === undefined || this.#font === undefined) {\n return false;\n }\n this.#canvasCtx.font = this.#font;\n const ch = this.canvasMeasureTextWidth('0');\n const characterWidthChanged = ch !== this.ch;\n if (characterWidthChanged) {\n this.ch = ch;\n }\n const textWidthCacheCleared = this.#clearTextWidthCache();\n return characterWidthChanged || textWidthCacheCleared;\n }\n\n /** measure the width of the text */\n measureTextWidth(text: string): number {\n if (!text.includes('\\t')) {\n return this.#measureTextWidthWithoutTabs(text);\n }\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n const asciiColumns = getExpandedAsciiTextColumns(text, this.tabSize);\n if (asciiColumns !== -1) {\n return asciiColumns * this.ch;\n }\n\n let width = 0;\n let runStart = 0;\n const tabStopWidth = this.tabSize * this.ch;\n for (let i = 0; i < text.length; i++) {\n if (text.charCodeAt(i) !== /* '\\t' */ 9) {\n continue;\n }\n\n if (i > runStart) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart, i));\n }\n // CSS tab stops are pixel positions, so wide glyphs before a tab must\n // contribute their measured width rather than one logical column.\n if (tabStopWidth > 0) {\n const remainder = width % tabStopWidth;\n width += remainder === 0 ? tabStopWidth : tabStopWidth - remainder;\n }\n runStart = i + 1;\n }\n\n if (runStart < text.length) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart));\n }\n return round(width);\n }\n\n /**\n * Pixel width from a wrapped segment's start up to a character. Tabs advance\n * from the segment start so their stops line up with the rendered text.\n */\n segmentTextWidth(\n lineText: string,\n segmentStart: number,\n character: number\n ): number {\n if (character <= segmentStart) {\n return 0;\n }\n const segmentText = lineText.slice(segmentStart, character);\n const asciiColumns = getExpandedAsciiTextColumns(segmentText, this.tabSize);\n return asciiColumns !== -1\n ? asciiColumns * this.ch\n : this.measureTextWidth(segmentText);\n }\n\n #measureTextWidthWithoutTabs(text: string): number {\n if (needsDomTextMeasurement(text)) {\n return this.domMeasureTextWidth(text);\n }\n return this.canvasMeasureTextWidth(text);\n }\n\n /** measure the width of the text using the canvas measureText API */\n canvasMeasureTextWidth(text: string): number {\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n return round(this.#canvasCtx.measureText(text).width);\n }\n\n /**\n * measure the width of the text using the DOM\n * this is slow because it cause a reflow, use it for non-ascii text;\n * results are memoized per text so repeated measurements skip the reflow\n */\n domMeasureTextWidth(text: string): number {\n if (this.#root === undefined) {\n throw new Error('Metrics not initialized');\n }\n const cacheKey = text + '|' + this.#font;\n const cached = this.#textWidthCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n const measureEl = h(\n 'span',\n {\n style: {\n position: 'absolute',\n top: '0',\n left: '0',\n visibility: 'hidden',\n pointerEvents: 'none',\n whiteSpace: 'pre',\n font: 'inherit',\n },\n textContent: text,\n },\n this.#root\n );\n let width: number;\n try {\n // round() to match canvasMeasureTextWidth and ch; otherwise the DOM path\n // returns raw sub-pixel widths and caret/selection offsets drift between\n // ASCII and non-ASCII runs on the same line.\n width = round(measureEl.getBoundingClientRect().width);\n } finally {\n measureEl.remove();\n }\n if (this.#textWidthCache.size >= TEXT_WIDTH_CACHE_LIMIT) {\n const oldestKey = this.#textWidthCache.keys().next().value;\n if (oldestKey !== undefined) {\n this.#textWidthCache.delete(oldestKey);\n }\n }\n this.#textWidthCache.set(cacheKey, width);\n return width;\n }\n\n /**\n * discard memoized DOM text widths\n * call this when the inherited font may have changed without re-running\n * init(), e.g. on a layout reflow, so stale widths are not reused\n */\n clearTextWidthCache(): void {\n this.#clearTextWidthCache();\n }\n\n #clearTextWidthCache(): boolean {\n const hadCachedTextWidths = this.#textWidthCache.size > 0;\n this.#textWidthCache.clear();\n return hadCachedTextWidths;\n }\n}\n\n/** Check if the text needs DOM text measurement. */\nexport function needsDomTextMeasurement(text: string): boolean {\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (\n (code >= 0xd800 && code <= 0xdfff) ||\n code === 0x200d ||\n code === 0xfe0e ||\n code === 0xfe0f ||\n (code > 0x7f && COMBINING_MARK_PATTERN.test(text.charAt(i)))\n ) {\n return true;\n }\n }\n return false;\n}\n\n/** snap the text offset to the Unicode boundary */\nexport function snapTextOffsetToUnicodeBoundary(\n text: string,\n offset: number\n): number {\n const boundedOffset = Math.max(0, Math.min(offset, text.length));\n if (\n boundedOffset === 0 ||\n boundedOffset === text.length ||\n !needsDomTextMeasurement(text)\n ) {\n return boundedOffset;\n }\n // Avoid measuring a caret position inside one visual emoji/grapheme.\n // Browser caret movement can report offsets around UTF-16 surrogate\n // pairs and emoji joiners; measuring a partial sequence gives a\n // replacement-glyph width.\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n const segmentStart = segment.index;\n const segmentEnd = segmentStart + segment.segment.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n }\n return boundedOffset;\n }\n // Degraded path for engines lacking Intl.Segmenter: snap out of a\n // surrogate pair by stepping over code points.\n let segmentStart = 0;\n for (const codePoint of text) {\n const segmentEnd = segmentStart + codePoint.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n segmentStart = segmentEnd;\n }\n return boundedOffset;\n}\n\n/** get the offsets of the Unicode grapheme clusters in the text */\nexport function getUnicodeMeasurementOffsets(\n text: string\n): number[] | undefined {\n if (!needsDomTextMeasurement(text)) {\n return undefined;\n }\n const offsets = [0];\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n offsets.push(segment.index + segment.segment.length);\n }\n return offsets;\n }\n // Degraded path for engines lacking Intl.Segmenter: step by code point.\n let offset = 0;\n for (const codePoint of text) {\n offset += codePoint.length;\n offsets.push(offset);\n }\n return offsets;\n}\n\n/**\n * Count the rendered columns of ASCII text, advancing each tab to the next\n * fixed tab stop (a multiple of tabSize) to match CSS `tab-size`. Returns -1\n * for non-ASCII text, which must be measured glyph-by-glyph instead.\n */\nexport function getExpandedAsciiTextColumns(\n text: string,\n tabSize: number\n): number {\n let columns = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code > 127) {\n return -1;\n }\n columns += code === /* '\\t' */ 9 ? tabSize - (columns % tabSize) : 1;\n }\n return columns;\n}\n"],"mappings":";;AAMA,MAAM,yBAAyB;AAE/B,MAAM,yBAAyB;AAE/B,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CAGA,kCAAkB,IAAI,IAAoB;;CAG1C,KAAa;;CAEb,UAAkB;;CAElB,aAAqB;;CAErB,aAAqB;;CAGrB,KAAK,MAAyB;EAC5B,IACE,KAAK,UAAU,QACf,KAAK,eAAe,KAAA,KACpB,KAAK,OAAO,IAGZ;EAGF,KAAK,QAAQ;EACb,KAAK,eACH,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,IAAI,KAAK,KAAA;EACvD,IAAI,KAAK,eAAe,KAAA,GACtB,MAAM,IAAI,MAAM,8BAA8B;EAGhD,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;GACnB,MAAM,EAAE,eAAe,iBAAiB,MAAM;GAC9C,IAAI,WAAW,SAAS,IAAI,GAC1B,KAAK,aAAa,WAAW,WAAW,MAAM,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AK,MAAM,aAAa,MAAM;EAC5B,MAAM,aAAa,eAAe,UAAU;EAC5C,IAAI,gBAAgB,gBAAgB,gBAAgB,YAClD,OAAO;EAET,IAAI,iBAAiB,cACnB;EAEF,eAAe;CACjB;CACA,OAAO;AACT;;AAGA,SAAgB,6BACd,MACsB;CACtB,IAAI,CAAC,wBAAwB,IAAI,GAC/B;CAEF,MAAM,UAAU,CAAC,CAAC;CAClB,MAAM,YAAY,qBAAqB;CACvC,IAAI,cAAc,KAAA,GAAW;EAC3B,KAAK,MAAM,WAAW,UAAU,QAAQ,IAAI,GAC1C,QAAQ,KAAK,QAAQ,QAAQ,QAAQ,QAAQ,MAAM;EAErD,OAAO;CACT;CAEA,IAAI,SAAS;CACb,KAAK,MAAM,aAAa,MAAM;EAC5B,UAAU,UAAU;EACpB,QAAQ,KAAK,MAAM;CACrB;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,4BACd,MACA,SACQ;CACR,IAAI,UAAU;CACd,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,KACT,OAAO;EAET,WAAW,SAAoB,IAAI,UAAW,UAAU,UAAW;CACrE;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"textMeasure.js","names":[],"sources":["../../src/editor/textMeasure.ts"],"sourcesContent":["import { getGraphemeSegmenter, h, round } from './utils';\n\n// Upper bound on cached DOM text-width measurements. The cache only holds\n// non-ASCII runs (emoji, ZWJ sequences, variation selectors, combining marks),\n// so it stays small for ordinary code, but capping it prevents unbounded growth\n// on emoji-heavy documents. Past the cap the oldest entry is evicted.\nconst TEXT_WIDTH_CACHE_LIMIT = 4096;\n\nconst COMBINING_MARK_PATTERN = /\\p{Mark}/u;\n\nexport class Metrics {\n #root?: HTMLElement;\n #canvas?: HTMLCanvasElement;\n #canvasCtx?: CanvasRenderingContext2D;\n #font?: string;\n\n // Memoizes domMeasureTextWidth() results\n #textWidthCache = new Map<string, number>();\n\n /** Width of the '0' character. */\n ch: number = -1;\n /** Size of a tab(\\t) character. */\n tabSize: number = 2;\n /** Height of the code line. */\n lineHeight: number = 20;\n /** Padding top of the root element. */\n paddingTop: number = 0;\n\n /** initialize the metrics */\n init(root: HTMLElement): void {\n if (\n this.#root === root &&\n this.#canvasCtx !== undefined &&\n this.ch !== -1\n ) {\n // already initialized\n return;\n }\n\n this.#root = root;\n this.#canvas ??= h('canvas', { style: { display: 'none' } });\n this.#canvasCtx ??= this.#canvas.getContext('2d') ?? undefined;\n if (this.#canvasCtx === undefined) {\n throw new Error('Could not get canvas context');\n }\n\n const parent = root.parentElement;\n if (parent !== null) {\n const { paddingTop } = getComputedStyle(parent);\n if (paddingTop.endsWith('px')) {\n this.paddingTop = parseFloat(paddingTop.slice(0, -2));\n }\n }\n\n const { fontSize, fontFamily, tabSize, lineHeight } =\n getComputedStyle(root);\n if (lineHeight.endsWith('px')) {\n this.lineHeight = parseFloat(lineHeight.slice(0, -2));\n } else if (fontSize.endsWith('px')) {\n this.lineHeight = round(\n parseFloat(fontSize.slice(0, -2)) * parseFloat(lineHeight)\n );\n }\n const font = fontSize + ' ' + fontFamily;\n if (this.#font !== font || this.ch === -1) {\n this.#font = font;\n this.#setCanvasFont(font);\n this.ch = this.canvasMeasureTextWidth('0');\n // Cached DOM widths were measured against the previous font.\n this.clearTextWidthCache();\n }\n const nextTabSize = parseInt(tabSize, 10);\n if (!Number.isNaN(nextTabSize)) {\n this.tabSize = nextTabSize;\n }\n }\n\n /**\n * Re-measure the '0' character width against the font that is loaded right\n * now, returning true when measurement-dependent UI should refresh.\n *\n * A custom web font can finish loading after the editor first renders.\n * Until then canvas measureText reports the fallback font's width, and\n * getComputedStyle returns the same font-family string before and after the\n * file arrives, so init()'s font guard never re-measures on its own. Call\n * this once fonts have settled (e.g. on document.fonts.ready) to replace a\n * width measured against the fallback font with the real glyph width. Font\n * completion can also change DOM-measured emoji/ZWJ widths while leaving the\n * ASCII width unchanged, and the computed font string stays the same in both\n * cases. The boolean return lets the caller skip re-rendering when there is no\n * measured state to refresh.\n */\n remeasureCharacterWidth(): boolean {\n if (this.#canvasCtx === undefined || this.#font === undefined) {\n return false;\n }\n this.#setCanvasFont(this.#font);\n const ch = this.canvasMeasureTextWidth('0');\n const characterWidthChanged = ch !== this.ch;\n if (characterWidthChanged) {\n this.ch = ch;\n }\n const textWidthCacheCleared = this.#clearTextWidthCache();\n return characterWidthChanged || textWidthCacheCleared;\n }\n\n /**\n * Set the canvas font while the canvas is connected to the document.\n *\n * WebKit resolves a canvas font from the canvas element's computed style at\n * assignment. A detached canvas has none, so WebKit ignores user-installed\n * fonts and measures the fallback family while the DOM renders the real font,\n * shifting every caret and selection in hosts that allow user-installed fonts\n * (WKWebView, Playwright WebKit). Connecting the canvas for the assignment\n * makes it measure the same font the DOM renders.\n */\n #setCanvasFont(font: string): void {\n const root = this.#root;\n const canvas = this.#canvas;\n const canvasCtx = this.#canvasCtx;\n if (root == null || canvas == null || canvasCtx == null) {\n throw new Error('Metrics not initialized');\n }\n root.append(canvas);\n try {\n canvasCtx.font = font;\n } finally {\n canvas.remove();\n }\n }\n\n /** measure the width of the text */\n measureTextWidth(text: string): number {\n if (!text.includes('\\t')) {\n return this.#measureTextWidthWithoutTabs(text);\n }\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n const asciiColumns = getExpandedAsciiTextColumns(text, this.tabSize);\n if (asciiColumns !== -1) {\n return asciiColumns * this.ch;\n }\n\n let width = 0;\n let runStart = 0;\n const tabStopWidth = this.tabSize * this.ch;\n for (let i = 0; i < text.length; i++) {\n if (text.charCodeAt(i) !== /* '\\t' */ 9) {\n continue;\n }\n\n if (i > runStart) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart, i));\n }\n // CSS tab stops are pixel positions, so wide glyphs before a tab must\n // contribute their measured width rather than one logical column.\n if (tabStopWidth > 0) {\n const remainder = width % tabStopWidth;\n width += remainder === 0 ? tabStopWidth : tabStopWidth - remainder;\n }\n runStart = i + 1;\n }\n\n if (runStart < text.length) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart));\n }\n return round(width);\n }\n\n /**\n * Pixel width from a wrapped segment's start up to a character. Tabs advance\n * from the segment start so their stops line up with the rendered text.\n */\n segmentTextWidth(\n lineText: string,\n segmentStart: number,\n character: number\n ): number {\n if (character <= segmentStart) {\n return 0;\n }\n const segmentText = lineText.slice(segmentStart, character);\n const asciiColumns = getExpandedAsciiTextColumns(segmentText, this.tabSize);\n return asciiColumns !== -1\n ? asciiColumns * this.ch\n : this.measureTextWidth(segmentText);\n }\n\n #measureTextWidthWithoutTabs(text: string): number {\n if (needsDomTextMeasurement(text)) {\n return this.domMeasureTextWidth(text);\n }\n return this.canvasMeasureTextWidth(text);\n }\n\n /** measure the width of the text using the canvas measureText API */\n canvasMeasureTextWidth(text: string): number {\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n return round(this.#canvasCtx.measureText(text).width);\n }\n\n /**\n * measure the width of the text using the DOM\n * this is slow because it cause a reflow, use it for non-ascii text;\n * results are memoized per text so repeated measurements skip the reflow\n */\n domMeasureTextWidth(text: string): number {\n if (this.#root === undefined) {\n throw new Error('Metrics not initialized');\n }\n const cacheKey = text + '|' + this.#font;\n const cached = this.#textWidthCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n const measureEl = h(\n 'span',\n {\n style: {\n position: 'absolute',\n top: '0',\n left: '0',\n visibility: 'hidden',\n pointerEvents: 'none',\n whiteSpace: 'pre',\n font: 'inherit',\n },\n textContent: text,\n },\n this.#root\n );\n let width: number;\n try {\n // round() to match canvasMeasureTextWidth and ch; otherwise the DOM path\n // returns raw sub-pixel widths and caret/selection offsets drift between\n // ASCII and non-ASCII runs on the same line.\n width = round(measureEl.getBoundingClientRect().width);\n } finally {\n measureEl.remove();\n }\n if (this.#textWidthCache.size >= TEXT_WIDTH_CACHE_LIMIT) {\n const oldestKey = this.#textWidthCache.keys().next().value;\n if (oldestKey !== undefined) {\n this.#textWidthCache.delete(oldestKey);\n }\n }\n this.#textWidthCache.set(cacheKey, width);\n return width;\n }\n\n /**\n * discard memoized DOM text widths\n * call this when the inherited font may have changed without re-running\n * init(), e.g. on a layout reflow, so stale widths are not reused\n */\n clearTextWidthCache(): void {\n this.#clearTextWidthCache();\n }\n\n #clearTextWidthCache(): boolean {\n const hadCachedTextWidths = this.#textWidthCache.size > 0;\n this.#textWidthCache.clear();\n return hadCachedTextWidths;\n }\n}\n\n/** Check if the text needs DOM text measurement. */\nexport function needsDomTextMeasurement(text: string): boolean {\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (\n (code >= 0xd800 && code <= 0xdfff) ||\n code === 0x200d ||\n code === 0xfe0e ||\n code === 0xfe0f ||\n (code > 0x7f && COMBINING_MARK_PATTERN.test(text.charAt(i)))\n ) {\n return true;\n }\n }\n return false;\n}\n\n/** snap the text offset to the Unicode boundary */\nexport function snapTextOffsetToUnicodeBoundary(\n text: string,\n offset: number\n): number {\n const boundedOffset = Math.max(0, Math.min(offset, text.length));\n if (\n boundedOffset === 0 ||\n boundedOffset === text.length ||\n !needsDomTextMeasurement(text)\n ) {\n return boundedOffset;\n }\n // Avoid measuring a caret position inside one visual emoji/grapheme.\n // Browser caret movement can report offsets around UTF-16 surrogate\n // pairs and emoji joiners; measuring a partial sequence gives a\n // replacement-glyph width.\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n const segmentStart = segment.index;\n const segmentEnd = segmentStart + segment.segment.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n }\n return boundedOffset;\n }\n // Degraded path for engines lacking Intl.Segmenter: snap out of a\n // surrogate pair by stepping over code points.\n let segmentStart = 0;\n for (const codePoint of text) {\n const segmentEnd = segmentStart + codePoint.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n segmentStart = segmentEnd;\n }\n return boundedOffset;\n}\n\n/** get the offsets of the Unicode grapheme clusters in the text */\nexport function getUnicodeMeasurementOffsets(\n text: string\n): number[] | undefined {\n if (!needsDomTextMeasurement(text)) {\n return undefined;\n }\n const offsets = [0];\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n offsets.push(segment.index + segment.segment.length);\n }\n return offsets;\n }\n // Degraded path for engines lacking Intl.Segmenter: step by code point.\n let offset = 0;\n for (const codePoint of text) {\n offset += codePoint.length;\n offsets.push(offset);\n }\n return offsets;\n}\n\n/**\n * Count the rendered columns of ASCII text, advancing each tab to the next\n * fixed tab stop (a multiple of tabSize) to match CSS `tab-size`. Returns -1\n * for non-ASCII text, which must be measured glyph-by-glyph instead.\n */\nexport function getExpandedAsciiTextColumns(\n text: string,\n tabSize: number\n): number {\n let columns = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code > 127) {\n return -1;\n }\n columns += code === /* '\\t' */ 9 ? tabSize - (columns % tabSize) : 1;\n }\n return columns;\n}\n"],"mappings":";;AAMA,MAAM,yBAAyB;AAE/B,MAAM,yBAAyB;AAE/B,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CACA;CAGA,kCAAkB,IAAI,IAAoB;;CAG1C,KAAa;;CAEb,UAAkB;;CAElB,aAAqB;;CAErB,aAAqB;;CAGrB,KAAK,MAAyB;EAC5B,IACE,KAAK,UAAU,QACf,KAAK,eAAe,KAAA,KACpB,KAAK,OAAO,IAGZ;EAGF,KAAK,QAAQ;EACb,KAAK,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;EAC3D,KAAK,eAAe,KAAK,QAAQ,WAAW,IAAI,KAAK,KAAA;EACrD,IAAI,KAAK,eAAe,KAAA,GACtB,MAAM,IAAI,MAAM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@ -9,8 +9,15 @@ function attachResolvedLanguages(resolvedLanguages, highlighter) {
|
|
|
9
9
|
lang = resolvedLang;
|
|
10
10
|
ResolvedLanguages.set(resolvedLang.name, lang);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
const grammar = lang.data.find((grammar) => grammar.name === lang.name || grammar.aliases?.includes(lang.name) === true);
|
|
13
|
+
if (grammar == null) throw new Error(`attachResolvedLanguages: No returned grammar declares "${lang.name}" as its name or an alias.`);
|
|
13
14
|
highlighter.loadLanguageSync(lang.data);
|
|
15
|
+
try {
|
|
16
|
+
highlighter.getLanguage(lang.name);
|
|
17
|
+
} catch {
|
|
18
|
+
throw new Error(`attachResolvedLanguages: "${grammar.name}" is already loaded without alias "${lang.name}". Load the alias first or give the grammar a unique name.`);
|
|
19
|
+
}
|
|
20
|
+
AttachedLanguages.add(lang.name);
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
23
|
//#endregion
|
package/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachResolvedLanguages.js","names":[],"sources":["../../../src/highlighter/languages/attachResolvedLanguages.ts"],"sourcesContent":["import type { DiffsHighlighter } from '../../types';\nimport type { ResolvedLanguage } from '../../worker';\nimport { AttachedLanguages, ResolvedLanguages } from './constants';\n\nexport function attachResolvedLanguages(\n resolvedLanguages: ResolvedLanguage | ResolvedLanguage[],\n highlighter: DiffsHighlighter\n): void {\n resolvedLanguages = Array.isArray(resolvedLanguages)\n ? resolvedLanguages\n : [resolvedLanguages];\n\n for (const resolvedLang of resolvedLanguages) {\n if (AttachedLanguages.has(resolvedLang.name)) continue;\n let lang = ResolvedLanguages.get(resolvedLang.name);\n if (lang == null) {\n lang = resolvedLang;\n ResolvedLanguages.set(resolvedLang.name, lang);\n }\n
|
|
1
|
+
{"version":3,"file":"attachResolvedLanguages.js","names":[],"sources":["../../../src/highlighter/languages/attachResolvedLanguages.ts"],"sourcesContent":["import type { DiffsHighlighter } from '../../types';\nimport type { ResolvedLanguage } from '../../worker';\nimport { AttachedLanguages, ResolvedLanguages } from './constants';\n\nexport function attachResolvedLanguages(\n resolvedLanguages: ResolvedLanguage | ResolvedLanguage[],\n highlighter: DiffsHighlighter\n): void {\n resolvedLanguages = Array.isArray(resolvedLanguages)\n ? resolvedLanguages\n : [resolvedLanguages];\n\n for (const resolvedLang of resolvedLanguages) {\n if (AttachedLanguages.has(resolvedLang.name)) continue;\n let lang = ResolvedLanguages.get(resolvedLang.name);\n if (lang == null) {\n lang = resolvedLang;\n ResolvedLanguages.set(resolvedLang.name, lang);\n }\n const grammar = lang.data.find(\n (grammar) =>\n grammar.name === lang.name ||\n grammar.aliases?.includes(lang.name) === true\n );\n if (grammar == null) {\n throw new Error(\n `attachResolvedLanguages: No returned grammar declares \"${lang.name}\" as its name or an alias.`\n );\n }\n highlighter.loadLanguageSync(lang.data);\n // Shiki can skip an already-loaded grammar, including any newly added aliases.\n try {\n highlighter.getLanguage(lang.name);\n } catch {\n throw new Error(\n `attachResolvedLanguages: \"${grammar.name}\" is already loaded without alias \"${lang.name}\". Load the alias first or give the grammar a unique name.`\n );\n }\n AttachedLanguages.add(lang.name);\n }\n}\n"],"mappings":";;AAIA,SAAgB,wBACd,mBACA,aACM;CACN,oBAAoB,MAAM,QAAQ,iBAAiB,IAC/C,oBACA,CAAC,iBAAiB;CAEtB,KAAK,MAAM,gBAAgB,mBAAmB;EAC5C,IAAI,kBAAkB,IAAI,aAAa,IAAI,GAAG;EAC9C,IAAI,OAAO,kBAAkB,IAAI,aAAa,IAAI;EAClD,IAAI,QAAQ,MAAM;GAChB,OAAO;GACP,kBAAkB,IAAI,aAAa,MAAM,IAAI;EAC/C;EACA,MAAM,UAAU,KAAK,KAAK,MACvB,YACC,QAAQ,SAAS,KAAK,QACtB,QAAQ,SAAS,SAAS,KAAK,IAAI,MAAM,IAC7C;EACA,IAAI,WAAW,MACb,MAAM,IAAI,MACR,0DAA0D,KAAK,KAAK,2BACtE;EAEF,YAAY,iBAAiB,KAAK,IAAI;EAEtC,IAAI;GACF,YAAY,YAAY,KAAK,IAAI;EACnC,QAAQ;GACN,MAAM,IAAI,MACR,6BAA6B,QAAQ,KAAK,qCAAqC,KAAK,KAAK,2DAC3F;EACF;EACA,kBAAkB,IAAI,KAAK,IAAI;CACjC;AACF"}
|
|
@@ -2,7 +2,9 @@ import { DynamicImportLanguageRegistration } from "shiki";
|
|
|
2
2
|
//#region src/highlighter/languages/registerCustomLanguage.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Register a custom language loader and optionally map it to
|
|
5
|
-
* file names or extensions.
|
|
5
|
+
* file names or extensions. The registered name must match a returned
|
|
6
|
+
* grammar's name or aliases; registering a loader does not automatically add a
|
|
7
|
+
* grammar alias.
|
|
6
8
|
*/
|
|
7
9
|
declare function registerCustomLanguage(lang: string, loader: DynamicImportLanguageRegistration,
|
|
8
10
|
/**
|
package/node_modules/@pierre/diffs/dist/highlighter/languages/registerCustomLanguage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerCustomLanguage.d.ts","names":[],"sources":["../../../src/highlighter/languages/registerCustomLanguage.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerCustomLanguage.d.ts","names":[],"sources":["../../../src/highlighter/languages/registerCustomLanguage.ts"],"mappings":";;;;;;;;iBAWgB,uBACd,cACA,QAAQ,mCAOR;;;;;;;AAAA"}
|
|
@@ -3,7 +3,9 @@ import { setCustomExtension } from "../../utils/getFiletypeFromFileName.js";
|
|
|
3
3
|
//#region src/highlighter/languages/registerCustomLanguage.ts
|
|
4
4
|
/**
|
|
5
5
|
* Register a custom language loader and optionally map it to
|
|
6
|
-
* file names or extensions.
|
|
6
|
+
* file names or extensions. The registered name must match a returned
|
|
7
|
+
* grammar's name or aliases; registering a loader does not automatically add a
|
|
8
|
+
* grammar alias.
|
|
7
9
|
*/
|
|
8
10
|
function registerCustomLanguage(lang, loader, extensionsOrFilenames = []) {
|
|
9
11
|
if (lang === "text" || lang === "ansi") throw new Error("registerCustomLanguage: 'text' and 'ansi' are reserved language names");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerCustomLanguage.js","names":[],"sources":["../../../src/highlighter/languages/registerCustomLanguage.ts"],"sourcesContent":["import type { DynamicImportLanguageRegistration } from 'shiki';\n\nimport { setCustomExtension } from '../../utils/getFiletypeFromFileName';\nimport { RegisteredCustomLanguages } from './constants';\n\n/**\n * Register a custom language loader and optionally map it to\n * file names or extensions.\n */\nexport function registerCustomLanguage(\n lang: string,\n loader: DynamicImportLanguageRegistration,\n /**\n * File names or extensions to map to this language. Use exact filenames\n * (e.g., \"Dockerfile\", \"CMakeLists.txt\") or extension tokens without a dot\n * (e.g., \"proto\", \"foo\"). Compound extensions are supported\n * (e.g., \"blade.php\").\n */\n extensionsOrFilenames: string[] = []\n): void {\n if (lang === 'text' || lang === 'ansi') {\n throw new Error(\n \"registerCustomLanguage: 'text' and 'ansi' are reserved language names\"\n );\n }\n if (RegisteredCustomLanguages.has(lang)) {\n console.error(\n `registerCustomLanguage: lang: ${lang} is already registered`\n );\n return;\n }\n RegisteredCustomLanguages.set(lang, loader);\n for (const extension of extensionsOrFilenames) {\n setCustomExtension(extension, lang);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerCustomLanguage.js","names":[],"sources":["../../../src/highlighter/languages/registerCustomLanguage.ts"],"sourcesContent":["import type { DynamicImportLanguageRegistration } from 'shiki';\n\nimport { setCustomExtension } from '../../utils/getFiletypeFromFileName';\nimport { RegisteredCustomLanguages } from './constants';\n\n/**\n * Register a custom language loader and optionally map it to\n * file names or extensions. The registered name must match a returned\n * grammar's name or aliases; registering a loader does not automatically add a\n * grammar alias.\n */\nexport function registerCustomLanguage(\n lang: string,\n loader: DynamicImportLanguageRegistration,\n /**\n * File names or extensions to map to this language. Use exact filenames\n * (e.g., \"Dockerfile\", \"CMakeLists.txt\") or extension tokens without a dot\n * (e.g., \"proto\", \"foo\"). Compound extensions are supported\n * (e.g., \"blade.php\").\n */\n extensionsOrFilenames: string[] = []\n): void {\n if (lang === 'text' || lang === 'ansi') {\n throw new Error(\n \"registerCustomLanguage: 'text' and 'ansi' are reserved language names\"\n );\n }\n if (RegisteredCustomLanguages.has(lang)) {\n console.error(\n `registerCustomLanguage: lang: ${lang} is already registered`\n );\n return;\n }\n RegisteredCustomLanguages.set(lang, loader);\n for (const extension of extensionsOrFilenames) {\n setCustomExtension(extension, lang);\n }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,uBACd,MACA,QAOA,wBAAkC,CAAC,GAC7B;CACN,IAAI,SAAS,UAAU,SAAS,QAC9B,MAAM,IAAI,MACR,uEACF;CAEF,IAAI,0BAA0B,IAAI,IAAI,GAAG;EACvC,QAAQ,MACN,iCAAiC,KAAK,uBACxC;EACA;CACF;CACA,0BAA0B,IAAI,MAAM,MAAM;CAC1C,KAAK,MAAM,aAAa,uBACtB,mBAAmB,WAAW,IAAI;AAEtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerPoolManager.d.ts","names":[],"sources":["../../src/worker/WorkerPoolManager.ts"],"mappings":";;;;UA+EU;EACR,WAAW,eAAe;EAC1B,WAAW,eAAe;;UAYlB;EACR;;KAKG,qBAAqB,uBAAuB;cAEpC;UAkCD;UAjCF;mBACS;UACT;UACA;UACA;UACA;UACA;UAEA;UACA;UAIA;UAGA;UACA;UAKA;UACA;UACA;UACA;UACA;UACA;UACA;UAEA;EAER,YACU,SAAS,qBAEf,OACA,OACA,qBACA,cACA,mBACA,uBACA,wBACC;EAeE;EAIA,mBAAmB,MAAM,eAAe;EAMxC,mBACL,MAAM,mBACL;EAMI,iBAAiB;EAKjB,mBAAmB;EAQnB,mBAAmB;EAQpB,mBACJ,OACA,qBACA,cACA,mBACA,yBACC,QAAQ,0BAA0B;EA4E9B,2BAA2B;EAI3B,wBAAwB;EAMxB,wBAAwB;UAIjB;EA6CP,wBAAwB,UAAU;EASlC,0BAA0B,UAAU;EAKpC,uBACL,WAAW,OAAO;UASZ;UAKA;EAWD,aAAa,UAAU;EAkBvB;EAIM,WAAW,YAAW,uBAA4B;UAiFjD;UAsFN;UAiBA;EA2BD,iBACL,UAAU,sBACV,MAAM;EAqBD,wBAAwB,MAAM,eAAe;UAe5C;EAgCD,gBACL,MAAM,cACN,sBACA,oBACA,mBACC;EAaI,iBACL,UAAU,sBACV,MAAM;EAqBD,wBAAwB,MAAM,mBAAmB;UAehD;EAgCD,gBACL,MAAM,kBACN,sBACA,oBACA,gBAAgB,YAAY,6BAC5B,qCACC;EAYI;UAqBC;UAIA;UAMA;UAWA;EAOD,YAAY;UAwBX;UA+DA;UA0CA;UAcM;UAyDN;
|
|
1
|
+
{"version":3,"file":"WorkerPoolManager.d.ts","names":[],"sources":["../../src/worker/WorkerPoolManager.ts"],"mappings":";;;;UA+EU;EACR,WAAW,eAAe;EAC1B,WAAW,eAAe;;UAYlB;EACR;;KAKG,qBAAqB,uBAAuB;cAEpC;UAkCD;UAjCF;mBACS;UACT;UACA;UACA;UACA;UACA;UAEA;UACA;UAIA;UAGA;UACA;UAKA;UACA;UACA;UACA;UACA;UACA;UACA;UAEA;EAER,YACU,SAAS,qBAEf,OACA,OACA,qBACA,cACA,mBACA,uBACA,wBACC;EAeE;EAIA,mBAAmB,MAAM,eAAe;EAMxC,mBACL,MAAM,mBACL;EAMI,iBAAiB;EAKjB,mBAAmB;EAQnB,mBAAmB;EAQpB,mBACJ,OACA,qBACA,cACA,mBACA,yBACC,QAAQ,0BAA0B;EA4E9B,2BAA2B;EAI3B,wBAAwB;EAMxB,wBAAwB;UAIjB;EA6CP,wBAAwB,UAAU;EASlC,0BAA0B,UAAU;EAKpC,uBACL,WAAW,OAAO;UASZ;UAKA;EAWD,aAAa,UAAU;EAkBvB;EAIM,WAAW,YAAW,uBAA4B;UAiFjD;UAsFN;UAiBA;EA2BD,iBACL,UAAU,sBACV,MAAM;EAqBD,wBAAwB,MAAM,eAAe;UAe5C;EAgCD,gBACL,MAAM,cACN,sBACA,oBACA,mBACC;EAaI,iBACL,UAAU,sBACV,MAAM;EAqBD,wBAAwB,MAAM,mBAAmB;UAehD;EAgCD,gBACL,MAAM,kBACN,sBACA,oBACA,gBAAgB,YAAY,6BAC5B,qCACC;EAYI;UAqBC;UAIA;UAMA;UAWA;EAOD,YAAY;UAwBX;UA+DA;UA0CA;UAcM;UAyDN;UAuGA;UACA;UAMA;UAYA;UAqBA;UAmCA;UAeA;UAUA;UA8BA;UAOA;UAOA;UAWA;UASA;UAgBA;UAeA;UAWA;UAUA;UAOA;UAMA;UAOA;UAOA;UAkBA;UAQA;UASA;UAMA;UAQA;UAYA;UAYA;UAQA;UAiBA;UAiBA;UAKA;UAIC;UAWD"}
|
|
@@ -657,43 +657,46 @@ var WorkerPoolManager = class {
|
|
|
657
657
|
this.rejectRenderTaskCallbacks(task, error);
|
|
658
658
|
} else throw new Error("handleWorkerMessage: unknown task type");
|
|
659
659
|
throw error;
|
|
660
|
-
} else
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
660
|
+
} else {
|
|
661
|
+
if (isRenderTask(task)) for (const { name } of task.request.resolvedLanguages ?? []) managedWorker.langs.add(name);
|
|
662
|
+
switch (response.requestType) {
|
|
663
|
+
case "initialize":
|
|
664
|
+
if (task.type !== "initialize") throw new Error("handleWorkerMessage: task/response dont match");
|
|
665
|
+
this.syncCustomExtensionVersion(managedWorker, task.request);
|
|
666
|
+
task.resolve();
|
|
667
|
+
break;
|
|
668
|
+
case "set-render-options":
|
|
669
|
+
if (task.type !== "set-render-options") throw new Error("handleWorkerMessage: task/response dont match");
|
|
670
|
+
task.resolve();
|
|
671
|
+
break;
|
|
672
|
+
case "file": {
|
|
673
|
+
if (task.type !== "file") throw new Error("handleWorkerMessage: task/response dont match");
|
|
674
|
+
const { result, options } = response;
|
|
675
|
+
if (!this.isCurrentRenderTask(task) || !areFileRenderOptionsEqual(options, this.getFileRenderOptions())) throw IGNORE_RESPONSE;
|
|
676
|
+
const { request } = task;
|
|
677
|
+
this.syncCustomExtensionVersion(managedWorker, request);
|
|
678
|
+
if (task.cacheKeyAtDispatch != null) this.fileCache.set(task.cacheKeyAtDispatch, {
|
|
679
|
+
result,
|
|
680
|
+
options
|
|
681
|
+
});
|
|
682
|
+
this.resolveRenderTaskCallbacks(task);
|
|
683
|
+
this.notifyFileInstances(task, result, options);
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
case "diff": {
|
|
687
|
+
if (task.type !== "diff") throw new Error("handleWorkerMessage: task/response dont match");
|
|
688
|
+
const { result, options } = response;
|
|
689
|
+
if (!this.isCurrentRenderTask(task) || !areDiffRenderOptionsEqual(options, this.getDiffRenderOptions())) throw IGNORE_RESPONSE;
|
|
690
|
+
const { request } = task;
|
|
691
|
+
this.syncCustomExtensionVersion(managedWorker, request);
|
|
692
|
+
if (task.cacheKeyAtDispatch != null) this.diffCache.set(task.cacheKeyAtDispatch, {
|
|
693
|
+
result,
|
|
694
|
+
options
|
|
695
|
+
});
|
|
696
|
+
this.resolveRenderTaskCallbacks(task);
|
|
697
|
+
this.notifyDiffInstances(task, result, options);
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
697
700
|
}
|
|
698
701
|
}
|
|
699
702
|
} catch (error) {
|
|
@@ -732,7 +735,6 @@ var WorkerPoolManager = class {
|
|
|
732
735
|
executeTask(managedWorker, task) {
|
|
733
736
|
if (shouldSyncCustomExtensions(task.request)) this.maybeAttachCustomExtensions(managedWorker, task.request);
|
|
734
737
|
if (!this.activeTaskById.has(task.id)) this.assignWorkerToTask(task, managedWorker);
|
|
735
|
-
for (const lang of getLangsFromTask(task)) managedWorker.langs.add(lang);
|
|
736
738
|
try {
|
|
737
739
|
if (task.type === "file") task.cacheKeyAtDispatch = task.request.file.cacheKey;
|
|
738
740
|
else if (task.type === "diff") task.cacheKeyAtDispatch = task.request.diff.cacheKey;
|