@dou-ui/code 0.1.0-alpha.3 → 0.1.0-alpha.30
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/assets/default-BWWFJmzn.js.map +1 -0
- package/dist/code-diff.js.map +1 -1
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +756 -63
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/code-editor.js.map +1 -1
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +784 -474
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extension.js +6 -1
- package/dist/extension.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/language/highlighter.js +1 -1
- package/dist/language/highlighter.js.map +1 -1
- package/dist/language/language.js +24 -2
- package/dist/language/language.js.map +1 -1
- package/dist/language/remote-tokens.js +131 -0
- package/dist/language/remote-tokens.js.map +1 -0
- package/dist/language/worker-client.js +308 -33
- package/dist/language/worker-client.js.map +1 -1
- package/dist/language/worker-protocol.js.map +1 -1
- package/dist/shiki/index.js +54 -3
- package/dist/shiki/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/code-diff.vue.d.ts +18 -21
- package/dist/types/code-editor.vue.d.ts +3 -1
- package/dist/types/extension.d.ts +57 -5
- package/dist/types/index.d.ts +97 -21
- package/dist/types/language/language.d.ts +27 -0
- package/dist/types/language/remote-tokens.d.ts +38 -0
- package/dist/types/language/worker-client.d.ts +85 -15
- package/dist/types/language/worker-protocol.d.ts +53 -2
- package/dist/types/shiki/index.d.ts +36 -1
- package/dist/types/types.d.ts +166 -10
- package/dist/types/view/measure.d.ts +6 -0
- package/dist/types/worker/index.d.ts +27 -12
- package/dist/view/measure.js +23 -5
- package/dist/view/measure.js.map +1 -1
- package/dist/worker/default.js +1 -1
- package/dist/worker/index.js +280 -53
- package/dist/worker/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/assets/default-BZBMZKf_.js.map +0 -1
package/dist/view/measure.js
CHANGED
|
@@ -20,11 +20,33 @@ var Measure = class {
|
|
|
20
20
|
padY = 8;
|
|
21
21
|
/** Space before and after each line (`--dou-code-editor-padding-x`). */
|
|
22
22
|
padX = 12;
|
|
23
|
+
/** Space left of line numbers in the gutter (`--dou-code-editor-gutter-padding-left`). */
|
|
24
|
+
gutterPadLeft = 16;
|
|
25
|
+
/** Space right of line numbers in the gutter (`--dou-code-editor-gutter-padding-right`). */
|
|
26
|
+
gutterPadRight = 12;
|
|
23
27
|
tabSize = 2;
|
|
24
28
|
widths = /* @__PURE__ */ new Map();
|
|
25
29
|
constructor(probe) {
|
|
26
30
|
this.probe = probe;
|
|
27
31
|
}
|
|
32
|
+
/** Reads the CSS padding variables; returns `true` when any changed. */
|
|
33
|
+
refreshPadding() {
|
|
34
|
+
const el = this.probe();
|
|
35
|
+
if (!el) return false;
|
|
36
|
+
el.style.padding = "var(--dou-code-editor-padding-y, 8px) var(--dou-code-editor-padding-x, 12px) var(--dou-code-editor-gutter-padding-left, 16px) var(--dou-code-editor-gutter-padding-right, 12px)";
|
|
37
|
+
const style = getComputedStyle(el);
|
|
38
|
+
const padY = px(style.paddingTop, 8);
|
|
39
|
+
const padX = px(style.paddingRight, 12);
|
|
40
|
+
const gutterPadLeft = px(style.paddingBottom, 16);
|
|
41
|
+
const gutterPadRight = px(style.paddingLeft, 12);
|
|
42
|
+
el.style.padding = "";
|
|
43
|
+
const changed = padY !== this.padY || padX !== this.padX || gutterPadLeft !== this.gutterPadLeft || gutterPadRight !== this.gutterPadRight;
|
|
44
|
+
this.padY = padY;
|
|
45
|
+
this.padX = padX;
|
|
46
|
+
this.gutterPadLeft = gutterPadLeft;
|
|
47
|
+
this.gutterPadRight = gutterPadRight;
|
|
48
|
+
return changed;
|
|
49
|
+
}
|
|
28
50
|
/** Reads the cell width and line height again, e.g. after the font changed. */
|
|
29
51
|
refresh(tabSize) {
|
|
30
52
|
this.tabSize = tabSize;
|
|
@@ -36,11 +58,7 @@ var Measure = class {
|
|
|
36
58
|
if (rect.width > 0) this.cell = rect.width / 64;
|
|
37
59
|
if (rect.height > 0) this.lineHeight = Math.round(rect.height);
|
|
38
60
|
el.textContent = "";
|
|
39
|
-
|
|
40
|
-
const style = getComputedStyle(el);
|
|
41
|
-
this.padY = px(style.paddingTop, 8);
|
|
42
|
-
this.padX = px(style.paddingLeft, 12);
|
|
43
|
-
el.style.padding = "";
|
|
61
|
+
this.refreshPadding();
|
|
44
62
|
}
|
|
45
63
|
/** Width of one character as drawn. */
|
|
46
64
|
width(cluster) {
|
package/dist/view/measure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure.js","names":[],"sources":["../../src/view/measure.ts"],"sourcesContent":["import { clusterStarts, isAscii } from '../core/chars'\n\n/**\n * Text metrics without reading layout per line: every plain ASCII\n * character is one monospace cell, and anything else (CJK, emoji, accents)\n * is measured once in the page's own font and remembered. Tabs reach to\n * the next tab stop.\n */\n/** A length read from computed styles, in px. */\nfunction px(value: string, fallback: number) {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? Math.max(0, n) : fallback\n}\n\nexport class Measure {\n /** Width of one monospace cell. */\n cell = 8\n lineHeight = 20\n /** Space above the first line and below the last (`--dou-code-editor-padding-y`). */\n padY = 8\n /** Space before and after each line (`--dou-code-editor-padding-x`). */\n padX = 12\n tabSize = 2\n private widths = new Map<string, number>()\n\n constructor(private readonly probe: () => HTMLElement | null | undefined) {}\n\n /** Reads the cell width and line height again, e.g. after the font changed. */\n refresh(tabSize: number) {\n this.tabSize = tabSize\n this.widths.clear()\n const el = this.probe()\n if (!el) return\n el.textContent = 'x'.repeat(64)\n const rect = el.getBoundingClientRect()\n if (rect.width > 0) this.cell = rect.width / 64\n if (rect.height > 0) this.lineHeight = Math.round(rect.height)\n el.textContent = ''\n
|
|
1
|
+
{"version":3,"file":"measure.js","names":[],"sources":["../../src/view/measure.ts"],"sourcesContent":["import { clusterStarts, isAscii } from '../core/chars'\n\n/**\n * Text metrics without reading layout per line: every plain ASCII\n * character is one monospace cell, and anything else (CJK, emoji, accents)\n * is measured once in the page's own font and remembered. Tabs reach to\n * the next tab stop.\n */\n/** A length read from computed styles, in px. */\nfunction px(value: string, fallback: number) {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? Math.max(0, n) : fallback\n}\n\nexport class Measure {\n /** Width of one monospace cell. */\n cell = 8\n lineHeight = 20\n /** Space above the first line and below the last (`--dou-code-editor-padding-y`). */\n padY = 8\n /** Space before and after each line (`--dou-code-editor-padding-x`). */\n padX = 12\n /** Space left of line numbers in the gutter (`--dou-code-editor-gutter-padding-left`). */\n gutterPadLeft = 16\n /** Space right of line numbers in the gutter (`--dou-code-editor-gutter-padding-right`). */\n gutterPadRight = 12\n tabSize = 2\n private widths = new Map<string, number>()\n\n constructor(private readonly probe: () => HTMLElement | null | undefined) {}\n\n /** Reads the CSS padding variables; returns `true` when any changed. */\n refreshPadding(): boolean {\n const el = this.probe()\n if (!el) return false\n // Through a padding, so a calc() in the variable comes out in pixels.\n el.style.padding =\n 'var(--dou-code-editor-padding-y, 8px) var(--dou-code-editor-padding-x, 12px) var(--dou-code-editor-gutter-padding-left, 16px) var(--dou-code-editor-gutter-padding-right, 12px)'\n const style = getComputedStyle(el)\n const padY = px(style.paddingTop, 8)\n const padX = px(style.paddingRight, 12)\n const gutterPadLeft = px(style.paddingBottom, 16)\n const gutterPadRight = px(style.paddingLeft, 12)\n el.style.padding = ''\n const changed =\n padY !== this.padY ||\n padX !== this.padX ||\n gutterPadLeft !== this.gutterPadLeft ||\n gutterPadRight !== this.gutterPadRight\n this.padY = padY\n this.padX = padX\n this.gutterPadLeft = gutterPadLeft\n this.gutterPadRight = gutterPadRight\n return changed\n }\n\n /** Reads the cell width and line height again, e.g. after the font changed. */\n refresh(tabSize: number) {\n this.tabSize = tabSize\n this.widths.clear()\n const el = this.probe()\n if (!el) return\n el.textContent = 'x'.repeat(64)\n const rect = el.getBoundingClientRect()\n if (rect.width > 0) this.cell = rect.width / 64\n if (rect.height > 0) this.lineHeight = Math.round(rect.height)\n el.textContent = ''\n this.refreshPadding()\n }\n\n /** Width of one character as drawn. */\n width(cluster: string): number {\n const code = cluster.charCodeAt(0)\n if (cluster.length === 1 && code >= 0x20 && code < 0x7f) return this.cell\n let width = this.widths.get(cluster)\n if (width !== undefined) return width\n const el = this.probe()\n if (el) {\n el.textContent = cluster\n width = el.getBoundingClientRect().width\n el.textContent = ''\n }\n // No layout (tests, a hidden editor): wide scripts take two cells.\n if (!width)\n width = /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]|[\\ud83c-\\ud83e]/.test(cluster)\n ? this.cell * 2\n : this.cell\n // Only keep it once the page has fonts, so a fallback guess isn't kept forever.\n if (el?.isConnected) this.widths.set(cluster, width)\n return width\n }\n\n private tab(x: number) {\n const stop = this.cell * this.tabSize\n return (Math.floor(x / stop + 1e-6) + 1) * stop\n }\n\n /** The x of column `col` in `text`, from the line's start. */\n x(text: string, col: number): number {\n col = Math.min(col, text.length)\n if (isAscii(text)) {\n if (!text.includes('\\t')) return col * this.cell\n let x = 0\n for (let i = 0; i < col; i++) x = text.charCodeAt(i) === 9 ? this.tab(x) : x + this.cell\n return x\n }\n let x = 0\n const starts = clusterStarts(text)\n for (let i = 0; i < starts.length - 1 && starts[i]! < col; i++) {\n const cluster = text.slice(starts[i], starts[i + 1])\n x = cluster === '\\t' ? this.tab(x) : x + this.width(cluster)\n }\n return x\n }\n\n /** The column nearest to `x` in `text`, on a character boundary. */\n col(text: string, x: number): number {\n if (x <= 0) return 0\n if (isAscii(text) && !text.includes('\\t'))\n return Math.min(text.length, Math.round(x / this.cell))\n let left = 0\n const ascii = isAscii(text)\n const starts = ascii ? null : clusterStarts(text)\n const count = ascii ? text.length : starts!.length - 1\n for (let i = 0; i < count; i++) {\n const from = ascii ? i : starts![i]!\n const to = ascii ? i + 1 : starts![i + 1]!\n const cluster = text.slice(from, to)\n const right = cluster === '\\t' ? this.tab(left) : left + this.width(cluster)\n if (x < (left + right) / 2) return from\n if (x < right) return to\n left = right\n }\n return text.length\n }\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,GAAG,OAAe,UAAkB;CAC3C,MAAM,IAAI,OAAO,WAAW,KAAK;CACjC,OAAO,OAAO,SAAS,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC,IAAI;AAC/C;AAEA,IAAa,UAAb,MAAqB;CAeU;;CAb7B,OAAO;CACP,aAAa;;CAEb,OAAO;;CAEP,OAAO;;CAEP,gBAAgB;;CAEhB,iBAAiB;CACjB,UAAU;CACV,yBAAiB,IAAI,IAAoB;CAEzC,YAAY,OAA8D;EAA7C,KAAA,QAAA;CAA8C;;CAG3E,iBAA0B;EACxB,MAAM,KAAK,KAAK,MAAM;EACtB,IAAI,CAAC,IAAI,OAAO;EAEhB,GAAG,MAAM,UACP;EACF,MAAM,QAAQ,iBAAiB,EAAE;EACjC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC;EACnC,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE;EACtC,MAAM,gBAAgB,GAAG,MAAM,eAAe,EAAE;EAChD,MAAM,iBAAiB,GAAG,MAAM,aAAa,EAAE;EAC/C,GAAG,MAAM,UAAU;EACnB,MAAM,UACJ,SAAS,KAAK,QACd,SAAS,KAAK,QACd,kBAAkB,KAAK,iBACvB,mBAAmB,KAAK;EAC1B,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,OAAO;CACT;;CAGA,QAAQ,SAAiB;EACvB,KAAK,UAAU;EACf,KAAK,OAAO,MAAM;EAClB,MAAM,KAAK,KAAK,MAAM;EACtB,IAAI,CAAC,IAAI;EACT,GAAG,cAAc,IAAI,OAAO,EAAE;EAC9B,MAAM,OAAO,GAAG,sBAAsB;EACtC,IAAI,KAAK,QAAQ,GAAG,KAAK,OAAO,KAAK,QAAQ;E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