ultra-text 1.0.1 → 1.0.3
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/README.md +339 -1039
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +97 -31
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +4 -3
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +14 -7
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +235 -68
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +11 -3
- package/dist/atlas/cpuWorker.js +179 -22
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +188 -287
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +257 -0
- package/dist/atlas/gpuCommon.js +845 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +226 -249
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +329 -158
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1065 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +72 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +167 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
- package/dist/atlas/vanillaGpuHelpers.js +354 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +243 -297
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +94 -165
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +53 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +31 -13
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +175 -57
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +78 -28
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +891 -484
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +105 -28
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +91 -44
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +17 -3
- package/dist/slug/SlugMaterial.js +98 -26
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +19 -15
- package/dist/slug/coverage.js +380 -225
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -2
- package/dist/slug/preprocessCore.js +199 -148
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +113 -74
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +112 -67
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +356 -255
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +410 -0
- package/dist/slug/vanillaCore.js +1630 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +7 -1454
- package/dist/slug.d.ts +2 -2
- package/dist/slug.js +7 -7
- package/dist/text/GlyphTextMaterial.d.ts +6 -1
- package/dist/text/GlyphTextMaterial.js +16 -12
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +125 -38
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -79
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +16 -1
- package/dist/text/geometryUtils.js +83 -8
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +434 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +101 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +23 -1
- package/dist/text/reflow.js +223 -94
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +7 -1474
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +17 -2
- package/dist/windfoil/geometry.js +220 -57
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +57 -29
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +2 -0
- package/dist/windfoil/preprocessCore.js +69 -37
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +4 -1
- package/dist/windfoil/runtime.js +69 -63
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +78 -6
- package/dist/windfoil/storage.js +166 -11
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +256 -62
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +915 -265
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +393 -103
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +27 -25
- package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
package/dist/dom/Text.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DomSdf } from "./DomSdf.js";
|
|
2
2
|
import { classNames, copyTextOptions, createTextSource, cssDeclarations, waitForHostFonts } from "./textHost.js";
|
|
3
3
|
// src/dom/Text.ts
|
|
4
|
-
var Text = class extends DomSdf {
|
|
4
|
+
var Text = class Text extends DomSdf {
|
|
5
5
|
ready;
|
|
6
6
|
pageBackdrop = false;
|
|
7
7
|
#h;
|
|
@@ -23,6 +23,10 @@ var Text = class extends DomSdf {
|
|
|
23
23
|
}
|
|
24
24
|
this.ready = this.#p();
|
|
25
25
|
}
|
|
26
|
+
static async create(messageOrRenderer, optionsOrSource, maybeOptions) {
|
|
27
|
+
if (typeof messageOrRenderer === "string") return new Text(messageOrRenderer, optionsOrSource).ready;
|
|
28
|
+
return super.create(messageOrRenderer, optionsOrSource, maybeOptions);
|
|
29
|
+
}
|
|
26
30
|
async #p() {
|
|
27
31
|
try {
|
|
28
32
|
let revision = await this.#wf();
|
package/dist/dom/Text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.js","names":[],"sources":["../../src/dom/Text.ts"],"sourcesContent":["import type { TextClass, TextCss, TextOptions } from '../types.js'\nimport { DomSdf, type DomSdfRebuildOptions } from './DomSdf.js'\nimport {\n classNames,\n copyTextOptions,\n createTextSource,\n cssDeclarations,\n waitForHostFonts,\n} from './textHost.js'\n\nexport class Text extends DomSdf {\n declare readonly options: Readonly<TextOptions>\n readonly ready: Promise<this>\n protected override readonly pageBackdrop = false\n #h: HTMLElement\n #a = new AbortController()\n #d = false\n #r = 0\n #i = false\n\n constructor(message: string, options: TextOptions) {\n const input = copyTextOptions(options)\n const [parent, host, source] = createTextSource(message, input)\n super(input.renderer, source, input)\n this.name = 'ultra-text string text'\n this.#h = host\n try {\n parent.append(host)\n } catch (error) {\n this.dispose()\n throw error\n }\n this.ready = this.#p()\n }\n\n async #p(): Promise<this> {\n try {\n let revision = await this.#wf()\n this.#i = true\n const initial = this.initialize()\n this.#i = false\n await initial\n while (revision !== this.#r) {\n revision = await this.#wf()\n await super.rebuild()\n }\n this.#a.signal.throwIfAborted()\n this.options.signal?.throwIfAborted()\n return this\n } catch (error) {\n this.dispose()\n throw error\n }\n }\n\n async #wf(): Promise<number> {\n let revision: number\n do {\n revision = this.#r\n this.source.getBoundingClientRect()\n await waitForHostFonts(this.source.ownerDocument, [\n this.#a.signal,\n ...(this.options.signal ? [this.options.signal] : []),\n ])\n } while (revision !== this.#r)\n return revision\n }\n\n get text(): string {\n return this.source.textContent\n }\n\n set text(message: string) {\n this.#l()\n this.source.textContent = message\n }\n\n setCss(css: TextCss): this {\n this.#l()\n this.source.style.cssText = cssDeclarations(this.source.ownerDocument, css)\n return this\n }\n\n setClass(cssClass: TextClass): this {\n this.#l()\n this.source.className = classNames(cssClass)\n if (this.options.selectable) this.source.classList.add('sdf-selectable')\n return this\n }\n\n override async rebuild(options: DomSdfRebuildOptions = {}): Promise<void> {\n if (!this.#i) await this.ready\n await super.rebuild(options)\n }\n\n #l(): void {\n if (this.#d) throw new Error('Text: this instance is disposed')\n this.#r++\n }\n\n override dispose(): void {\n if (this.#d) return\n this.#d = true\n this.#a.abort(new DOMException('The Text instance was disposed', 'AbortError'))\n super.dispose()\n this.#h.remove()\n }\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Text.js","names":[],"sources":["../../src/dom/Text.ts"],"sourcesContent":["import type { WebGPURenderer } from 'three/webgpu'\n\nimport type { DomSdfOptions, TextClass, TextCss, TextOptions } from '../types.js'\nimport { DomSdf, type DomSdfRebuildOptions } from './DomSdf.js'\nimport {\n classNames,\n copyTextOptions,\n createTextSource,\n cssDeclarations,\n waitForHostFonts,\n} from './textHost.js'\n\nexport class Text extends DomSdf {\n declare readonly options: Readonly<TextOptions>\n readonly ready: Promise<this>\n protected override readonly pageBackdrop = false\n #h: HTMLElement\n #a = new AbortController()\n #d = false\n #r = 0\n #i = false\n\n constructor(message: string, options: TextOptions) {\n const input = copyTextOptions(options)\n const [parent, host, source] = createTextSource(message, input)\n super(input.renderer, source, input)\n this.name = 'ultra-text string text'\n this.#h = host\n try {\n parent.append(host)\n } catch (error) {\n this.dispose()\n throw error\n }\n this.ready = this.#p()\n }\n\n static override create(message: string, options: TextOptions): Promise<Text>\n static override create(\n renderer: WebGPURenderer,\n source: HTMLElement,\n options?: DomSdfOptions,\n ): Promise<DomSdf>\n static override async create(\n messageOrRenderer: string | WebGPURenderer,\n optionsOrSource: TextOptions | HTMLElement,\n maybeOptions?: DomSdfOptions,\n ): Promise<DomSdf> {\n if (typeof messageOrRenderer === 'string') {\n return new Text(messageOrRenderer, optionsOrSource as TextOptions).ready\n }\n return super.create(messageOrRenderer, optionsOrSource as HTMLElement, maybeOptions)\n }\n\n async #p(): Promise<this> {\n try {\n let revision = await this.#wf()\n this.#i = true\n const initial = this.initialize()\n this.#i = false\n await initial\n while (revision !== this.#r) {\n revision = await this.#wf()\n await super.rebuild()\n }\n this.#a.signal.throwIfAborted()\n this.options.signal?.throwIfAborted()\n return this\n } catch (error) {\n this.dispose()\n throw error\n }\n }\n\n async #wf(): Promise<number> {\n let revision: number\n do {\n revision = this.#r\n this.source.getBoundingClientRect()\n await waitForHostFonts(this.source.ownerDocument, [\n this.#a.signal,\n ...(this.options.signal ? [this.options.signal] : []),\n ])\n } while (revision !== this.#r)\n return revision\n }\n\n get text(): string {\n return this.source.textContent\n }\n\n set text(message: string) {\n this.#l()\n this.source.textContent = message\n }\n\n setCss(css: TextCss): this {\n this.#l()\n this.source.style.cssText = cssDeclarations(this.source.ownerDocument, css)\n return this\n }\n\n setClass(cssClass: TextClass): this {\n this.#l()\n this.source.className = classNames(cssClass)\n if (this.options.selectable) this.source.classList.add('sdf-selectable')\n return this\n }\n\n override async rebuild(options: DomSdfRebuildOptions = {}): Promise<void> {\n if (!this.#i) await this.ready\n await super.rebuild(options)\n }\n\n #l(): void {\n if (this.#d) throw new Error('Text: this instance is disposed')\n this.#r++\n }\n\n override dispose(): void {\n if (this.#d) return\n this.#d = true\n this.#a.abort(new DOMException('The Text instance was disposed', 'AbortError'))\n super.dispose()\n this.#h.remove()\n }\n}\n"],"mappings":";;;AAYA,IAAa,OAAb,MAAa,aAAa,OAAO;CAE/B;CACA,eAA2C;CAC3C;CACA,KAAK,IAAI,gBAAgB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K,GAAG;EACR,KAAK,OAAO,cAAc;CAC5B;CAEA,OAAO,KAAoB;EACzB,KAAK,GAAG;EACR,KAAK,OAAO,MAAM,UAAU,gBAAgB,KAAK,OAAO,eAAe,GAAG;EAC1E,OAAO;CACT;CAEA,SAAS,UAA2B;EAClC,KAAK,GAAG;EACR,KAAK,OAAO,YAAY,WAAW,QAAQ;EAC3C,IAAI,KAAK,QAAQ,YAAY,KAAK,OAAO,UAAU,IAAI,gBAAgB;EACvE,OAAO;CACT;CAEA,MAAe,QAAQ,UAAgC,CAAC,GAAkB;EACxE,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK;EACzB,MAAM,MAAM,QAAQ,OAAO;CAC7B;CAEA,KAAW;EACT,IAAI,KAAK,IAAI,MAAM,IAAI,MAAM,iCAAiC;EAC9D,KAAK;CACP;CAEA,UAAyB;EACvB,IAAI,KAAK,IAAI;EACb,KAAK,KAAK;EACV,KAAK,GAAG,MAAM,IAAI,aAAa,kCAAkC,YAAY,CAAC;EAC9E,MAAM,QAAQ;EACd,KAAK,GAAG,OAAO;CACjB;AACF"}
|
|
@@ -5,7 +5,8 @@ function setShapingContext(context, request) {
|
|
|
5
5
|
const slice = request.shaping?.slice;
|
|
6
6
|
if (slice && !(slice[0] >= 0 && slice[0] < slice[1] && slice[1] <= 1)) throw new RangeError("Browser shaping slices must satisfy 0 <= start < end <= 1");
|
|
7
7
|
context.direction = request.shaping?.direction ?? "inherit";
|
|
8
|
-
|
|
8
|
+
const language = request.shaping?.language ?? "";
|
|
9
|
+
if (context.canvas.lang !== language) context.canvas.lang = language;
|
|
9
10
|
if ("lang" in context) context.lang = request.shaping?.language ?? "inherit";
|
|
10
11
|
const size = request.shaping ? Number.parseFloat(/[\d.]+px/.exec(request.font.canvasFont)?.[0] ?? "0") : 0;
|
|
11
12
|
context.letterSpacing = `${(request.shaping?.letterSpacing ?? 0) * size}px`;
|
|
@@ -103,11 +104,15 @@ function captureBrowserRuns(block, context, range, segmenter) {
|
|
|
103
104
|
let shaping = null;
|
|
104
105
|
let styleKey = "";
|
|
105
106
|
let preserveNewlines = false;
|
|
107
|
+
let shapingKey = "";
|
|
106
108
|
const flush = () => {
|
|
107
109
|
if (!inline || !shaping || nodes.length === 0) return;
|
|
108
110
|
const activeInline = inline;
|
|
109
111
|
const activeShaping = shaping;
|
|
110
|
-
const
|
|
112
|
+
const activeShapingKey = shapingKey;
|
|
113
|
+
let source = "";
|
|
114
|
+
if (nodes.length === 1) source = nodes[0].data;
|
|
115
|
+
else for (const node of nodes) source += node.data;
|
|
111
116
|
let nodeIndex = 0;
|
|
112
117
|
let nodeOffset = 0;
|
|
113
118
|
let text = "";
|
|
@@ -159,7 +164,7 @@ function captureBrowserRuns(block, context, range, segmenter) {
|
|
|
159
164
|
width: bounds.width / tiles
|
|
160
165
|
},
|
|
161
166
|
request: {
|
|
162
|
-
key: `${activeInline.font.key}\u0000browser:${JSON.stringify(state)}:${character}`,
|
|
167
|
+
key: `${activeInline.font.key}\u0000browser:${tiles === 1 ? activeShapingKey : JSON.stringify(state)}:${character}`,
|
|
163
168
|
character,
|
|
164
169
|
font: activeInline.font,
|
|
165
170
|
shaping: state
|
|
@@ -185,10 +190,24 @@ function captureBrowserRuns(block, context, range, segmenter) {
|
|
|
185
190
|
for (const part of segmenter.segment(source)) {
|
|
186
191
|
context.signal?.throwIfAborted();
|
|
187
192
|
const seg = part.segment;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
const c0 = seg.charCodeAt(0);
|
|
194
|
+
if (c0 <= 32) {
|
|
195
|
+
if (seg.length === 1) {
|
|
196
|
+
if (c0 === 32) {
|
|
197
|
+
if (bounds) text += " ";
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (c0 === 9 || c0 === 10 || c0 === 13) {
|
|
201
|
+
if (preserveNewlines) emit();
|
|
202
|
+
else if (bounds) text += " ";
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (/^[\t\n\r ]+$/u.test(seg)) {
|
|
207
|
+
if (preserveNewlines && /[\n\r\t]/u.test(seg)) emit();
|
|
208
|
+
else if (bounds) text += " ";
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
192
211
|
}
|
|
193
212
|
locate(part.index);
|
|
194
213
|
const firstNode = nodeIndex;
|
|
@@ -272,18 +291,16 @@ function captureBrowserRuns(block, context, range, segmenter) {
|
|
|
272
291
|
letterSpacing: nextInline.letterSpacing / size,
|
|
273
292
|
wordSpacing: nextInline.wordSpacing / size
|
|
274
293
|
};
|
|
275
|
-
const
|
|
294
|
+
const nextShapingKey = JSON.stringify(nextShaping);
|
|
295
|
+
const c = nextInline.color;
|
|
296
|
+
const nextKey = `${nextInline.font.key}|${size}|${c[0]},${c[1]},${c[2]},${c[3]}|${nextInline.decorations.length ? JSON.stringify(nextInline.decorations) : ""}|${nextInline.z}|${nextShapingKey}|${whiteSpace}|${nextInline.transform ? JSON.stringify(nextInline.transform) : ""}`;
|
|
276
297
|
if (nextKey !== styleKey) flush();
|
|
277
298
|
inline = nextInline;
|
|
278
299
|
prevStyle = style;
|
|
279
300
|
shaping = nextShaping;
|
|
301
|
+
shapingKey = nextShapingKey;
|
|
280
302
|
styleKey = nextKey;
|
|
281
|
-
preserveNewlines =
|
|
282
|
-
"pre",
|
|
283
|
-
"pre-wrap",
|
|
284
|
-
"pre-line",
|
|
285
|
-
"break-spaces"
|
|
286
|
-
].includes(whiteSpace);
|
|
303
|
+
preserveNewlines = whiteSpace === "pre" || whiteSpace === "pre-wrap" || whiteSpace === "pre-line" || whiteSpace === "break-spaces";
|
|
287
304
|
nodes.push(textNode);
|
|
288
305
|
}
|
|
289
306
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserShaping.js","names":[],"sources":["../../src/dom/browserShaping.ts"],"sourcesContent":["import type {\n DomSdfOptions,\n GlyphLayout,\n FontStyleSnapshot,\n GlyphRequest,\n TextDecorationLayout,\n} from '../types.js'\nimport { precedingCharacter, transformText, type TextTransform } from './textTransform.js'\n\ninterface InlineStyle {\n readonly font: FontStyleSnapshot\n readonly fontSize: number\n readonly letterSpacing: number\n readonly wordSpacing: number\n readonly color: readonly [number, number, number, number]\n readonly decorations: readonly TextDecorationLayout[]\n readonly z: number\n readonly transform: TextTransform | null\n}\n\ninterface CaptureContext {\n readonly style: (element: Element) => CSSStyleDeclaration\n readonly inline: (parent: HTMLElement) => InlineStyle | null\n readonly signal: AbortSignal | undefined\n readonly options: DomSdfOptions\n readonly svg?: (element: Element, sequence: number) => void\n /** Told each measured grapheme box, so the capture can find the browser's baseline. */\n readonly box?: (\n font: FontStyleSnapshot,\n box: {\n readonly left: number\n readonly top: number\n readonly right: number\n readonly bottom: number\n readonly width: number\n readonly height: number\n },\n ) => void\n}\n\n/** Applied only by the opt-in atlas path; ordinary glyphs also reset shared Canvas state. */\nexport function setShapingContext(context: CanvasRenderingContext2D, request: GlyphRequest): void {\n const slice = request.shaping?.slice\n if (slice && !(slice[0] >= 0 && slice[0] < slice[1] && slice[1] <= 1)) {\n throw new RangeError('Browser shaping slices must satisfy 0 <= start < end <= 1')\n }\n context.direction = request.shaping?.direction ?? 'inherit'\n context.canvas.lang = request.shaping?.language ?? ''\n if ('lang' in context) context.lang = request.shaping?.language ?? 'inherit'\n const size = request.shaping\n ? Number.parseFloat(/[\\d.]+px/.exec(request.font.canvasFont)?.[0] ?? '0')\n : 0\n context.letterSpacing = `${(request.shaping?.letterSpacing ?? 0) * size}px`\n context.wordSpacing = `${(request.shaping?.wordSpacing ?? 0) * size}px`\n}\n\n/** Native helpers and measured descents are shared only within one capture. */\nexport function createBrowserCapture(document: Document) {\n let helpers:\n | {\n range: Range\n segmenter: Intl.Segmenter\n canvas: HTMLCanvasElement\n metricsContext: CanvasRenderingContext2D | null\n }\n | undefined\n const descents = new Map<FontStyleSnapshot, Map<string, number>>()\n return (\n block: HTMLElement,\n context: CaptureContext & {\n readonly blockIndex: number\n readonly rootRect: DOMRect\n readonly invScale: number\n readonly clip: [number, number, number, number]\n readonly glyphs: GlyphLayout[]\n readonly requests: Map<string, GlyphRequest>\n readonly lineKeys: Set<string>\n readonly lineSequences: Map<string, number>\n },\n ): void => {\n if (!helpers) {\n const canvas = document.createElement('canvas')\n helpers = {\n range: document.createRange(),\n segmenter: new Intl.Segmenter(undefined, { granularity: 'grapheme' }),\n canvas,\n metricsContext: canvas.getContext('2d'),\n }\n }\n const { range, segmenter, canvas, metricsContext } = helpers\n const { blockIndex, rootRect, invScale, clip, glyphs, requests, lineKeys, lineSequences } =\n context\n let previousRun = -1\n let sequence = 0\n let baselineOffset: number | undefined\n let motionOrigin!: readonly [number, number, number]\n let motionIndex = (glyphs.at(-1)?.motionOrigin?.[2] ?? -1) + 1\n for (const entry of captureBrowserRuns(block, context, range, segmenter)) {\n if ('svg' in entry) {\n context.svg?.(entry.svg, sequence)\n motionIndex = (glyphs.at(-1)?.motionOrigin?.[2] ?? motionIndex) + 1\n continue\n }\n const { inline, bounds, request, run } = entry\n requests.set(request.key, request)\n const lineKey = `${blockIndex}:${Math.round(bounds.top * 4)}`\n if (run !== previousRun) {\n sequence = lineSequences.get(lineKey) ?? 0\n lineSequences.set(lineKey, sequence + 1)\n previousRun = run\n const slice = request.shaping?.slice ?? [0, 1]\n const width = bounds.width / (slice[1] - slice[0])\n motionOrigin = [\n (bounds.left - width * slice[0] + width / 2 - rootRect.left) * invScale,\n (rootRect.bottom - (bounds.top + bounds.bottom) / 2) * invScale,\n motionIndex++,\n ]\n if (metricsContext) {\n // Font metrics are pixel-rounded at each size; scaling baked metrics can\n // otherwise move a shaped line by half a CSS pixel.\n let byText = descents.get(request.font)\n if (!byText) descents.set(request.font, (byText = new Map<string, number>()))\n const lang = request.shaping?.language ?? ''\n const metricKey = lang ? `${lang}\\u0000${request.character}` : request.character\n let descent = byText.get(metricKey)\n if (descent === undefined) {\n canvas.lang = lang\n if ('lang' in metricsContext) metricsContext.lang = lang || 'inherit'\n metricsContext.font = request.font.canvasFont.replace(\n /[\\d.]+px/,\n `${inline.font.size}px`,\n )\n descent = metricsContext.measureText(request.character).fontBoundingBoxDescent\n byText.set(metricKey, descent)\n }\n baselineOffset = descent * invScale\n }\n }\n lineKeys.add(lineKey)\n glyphs.push({\n glyphKey: request.key,\n fontSize: inline.fontSize,\n originX: (bounds.left - rootRect.left) * invScale,\n lineBottom: (rootRect.bottom - bounds.bottom) * invScale,\n ...(baselineOffset !== undefined && Number.isFinite(baselineOffset)\n ? { baselineOffset }\n : {}),\n motionOrigin,\n advance: bounds.width * invScale,\n decorations: inline.decorations,\n decorationWidth: bounds.width * invScale,\n block: blockIndex,\n breakBefore: 'hard',\n clip,\n color: inline.color,\n sequence,\n z: inline.z,\n })\n }\n }\n}\n\ninterface BrowserTextRun {\n readonly run: number\n readonly inline: InlineStyle\n readonly request: GlyphRequest\n readonly bounds: { left: number; top: number; right: number; bottom: number; width: number }\n}\n\nexport function validateBrowserShaping(options: DomSdfOptions): void {\n if (options.layoutEngine === 'pretext' || options.reshape) {\n throw new Error('textShaping \"browser\" requires Range without a reshape callback')\n }\n if (\n options.textBackend === 'windfoil' &&\n !['sdf', 'sdf-glyphs'].includes(options.windfoil?.fallback ?? '')\n ) {\n throw new Error('textShaping \"browser\" requires SDF or windfoil.fallback: \"sdf\"')\n }\n if (typeof Intl.Segmenter !== 'function') {\n throw new Error('textShaping \"browser\" requires Intl.Segmenter')\n }\n}\n\n/** Keep native shaping context intact, including across equivalent inline markup. */\nfunction captureBrowserRuns(\n block: HTMLElement,\n context: CaptureContext,\n range: Range,\n segmenter: Intl.Segmenter,\n): (BrowserTextRun | { svg: Element })[] {\n const document = block.ownerDocument\n const result: (BrowserTextRun | { svg: Element })[] = []\n let nodes: Text[] = []\n let inline: InlineStyle | null = null\n let shaping: NonNullable<GlyphRequest['shaping']> | null = null\n let styleKey = ''\n let preserveNewlines = false\n\n const flush = (): void => {\n if (!inline || !shaping || nodes.length === 0) return\n const activeInline = inline\n const activeShaping = shaping\n const source = nodes.length === 1 ? nodes[0]!.data : nodes.map((node) => node.data).join('')\n let nodeIndex = 0\n let nodeOffset = 0\n let text = ''\n // Blink maps each text node on its own, so a transformed run notes where its text enters\n // one: case context stops there, and `capitalize` reads the character before each piece.\n let pieces: { readonly at: number; readonly node: number; readonly offset: number }[] = []\n let bounds: BrowserTextRun['bounds'] | null = null\n const transform = activeInline.transform\n const append = (segment: string, index: number, node: number, nodeStart: number): void => {\n for (let from = index; transform;) {\n if (pieces.at(-1)?.node !== node)\n pieces.push({ at: text.length + from - index, node, offset: from - nodeStart })\n // A cluster can continue into the next text node across inline markup.\n from = nodeStart + nodes[node]!.length\n if (index + segment.length <= from || node === nodes.length - 1) break\n nodeStart = from\n node++\n }\n text += segment\n }\n const emit = (): void => {\n const run = text.replace(/ +$/u, '')\n let character = run\n if (transform) {\n character = ''\n for (const [index, piece] of pieces.entries()) {\n const end = Math.min(pieces[index + 1]?.at ?? run.length, run.length)\n if (end <= piece.at) continue\n const data = nodes[piece.node]!.data\n character += transformText(\n run.slice(piece.at, end),\n transform,\n transform.caseMap !== 'capitalize'\n ? undefined\n : piece.offset > 0\n ? Array.from(data.slice(Math.max(0, piece.offset - 2), piece.offset)).pop()\n : precedingCharacter(nodes[piece.node]!, context.style),\n )\n }\n }\n if (bounds && /[^\\s\\p{Cf}]/u.test(character)) {\n // Leave room for SDF padding and small bake-size-dependent metric differences.\n const tileWidth = Math.max(\n 1,\n ((context.options.maxAtlasSize ?? 2048) - 2 * (context.options.padding ?? 12) - 4) * 0.9,\n )\n const tiles = Math.max(\n 1,\n Math.ceil(\n ((bounds.width / activeInline.font.size) * (context.options.bakeSize ?? 96)) /\n tileWidth,\n ),\n )\n for (let tile = 0; tile < tiles; tile++) {\n const slice = [tile / tiles, (tile + 1) / tiles] as const\n const state = tiles > 1 ? { ...activeShaping, slice } : activeShaping\n result.push({\n run: result.length - tile,\n inline: activeInline,\n bounds:\n tiles === 1\n ? bounds\n : {\n ...bounds,\n left: bounds.left + bounds.width * slice[0],\n right: bounds.left + bounds.width * slice[1],\n width: bounds.width / tiles,\n },\n request: {\n key: `${activeInline.font.key}\\u0000browser:${JSON.stringify(state)}:${character}`,\n character,\n font: activeInline.font,\n shaping: state,\n },\n })\n }\n }\n bounds = null\n text = ''\n pieces = []\n }\n const locate = (offset: number): void => {\n while (nodeIndex < nodes.length - 1 && offset >= nodeOffset + nodes[nodeIndex]!.length) {\n nodeOffset += nodes[nodeIndex++]!.length\n }\n }\n const scratchBox = { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 }\n for (const part of segmenter.segment(source)) {\n context.signal?.throwIfAborted()\n const seg = part.segment\n const c0 = seg.charCodeAt(0)\n if (c0 <= 32 && (seg === ' ' || /^[\\t\\n\\r ]+$/u.test(seg))) {\n if (preserveNewlines && seg !== ' ' && /[\\n\\r\\t]/u.test(seg)) emit()\n else if (bounds) text += ' '\n continue\n }\n locate(part.index)\n const firstNode = nodeIndex\n const firstStart = nodeOffset\n range.setStart(nodes[nodeIndex]!, part.index - nodeOffset)\n const end = part.index + seg.length\n locate(end)\n range.setEnd(nodes[nodeIndex]!, end - nodeOffset)\n const box = range.getBoundingClientRect()\n const width = box.width\n const height = box.height\n if (height <= 0 || width <= 0) {\n // Joiners, isolates, combining marks, and other bidi controls still participate in shaping.\n if (bounds ? /^[\\p{Cf}\\p{M}]+$/u.test(seg) : /^\\p{Cf}+$/u.test(seg))\n append(seg, part.index, firstNode, firstStart)\n continue\n }\n const left = box.left\n const right = box.right\n const top = box.top\n const bottom = box.bottom\n scratchBox.left = left\n scratchBox.top = top\n scratchBox.right = right\n scratchBox.bottom = bottom\n scratchBox.width = width\n scratchBox.height = height\n context.box?.(activeInline.font, scratchBox)\n if (bounds && (Math.abs(top - bounds.top) > 0.5 || Math.abs(bottom - bounds.bottom) > 0.5))\n emit()\n append(seg, part.index, firstNode, firstStart)\n if (bounds) {\n if (left < bounds.left) bounds.left = left\n if (right > bounds.right) bounds.right = right\n if (top < bounds.top) bounds.top = top\n if (bottom > bounds.bottom) bounds.bottom = bottom\n bounds.width = bounds.right - bounds.left\n } else {\n bounds = { left, right, top, bottom, width }\n }\n }\n emit()\n nodes = []\n }\n\n let blockLang: string | undefined\n const langOf = (element: Element): string =>\n element.getAttribute('lang') ??\n (element === block\n ? (blockLang ??= block.closest('[lang]')?.getAttribute('lang') ?? '')\n : element.parentElement\n ? langOf(element.parentElement)\n : '')\n\n let prevStyle: CSSStyleDeclaration | null = null\n const walker = document.createTreeWalker(block, 5 /* SHOW_ELEMENT | SHOW_TEXT */)\n let node = walker.nextNode()\n while (node) {\n context.signal?.throwIfAborted()\n if (node.nodeType === 1) {\n const element = node as Element\n if (\n context.svg &&\n (element.localName === 'svg' || element.localName === 'img') &&\n !element.parentElement?.closest('svg')\n ) {\n flush()\n result.push({ svg: element })\n }\n if (element.tagName === 'BR') flush()\n else if (nodes.length > 0 && context.style(element) !== prevStyle) {\n const display = context.style(element).display\n if (display && !display.startsWith('inline') && display !== 'contents') flush()\n }\n } else {\n const textNode = node as Text\n const parent = textNode.parentElement!\n const nextInline =\n context.svg && parent.closest('svg') && !parent.closest('foreignObject')\n ? null\n : context.inline(parent)\n if (!nextInline) flush()\n else {\n const style = context.style(parent)\n if (nextInline === inline && style === prevStyle && !parent.hasAttribute('lang')) {\n nodes.push(textNode)\n node = walker.nextNode()\n continue\n }\n const size = nextInline.font.size\n const whiteSpace = style.whiteSpace\n const nextShaping: NonNullable<GlyphRequest['shaping']> = {\n direction: style.direction === 'rtl' ? 'rtl' : 'ltr',\n language: langOf(parent),\n letterSpacing: nextInline.letterSpacing / size,\n wordSpacing: nextInline.wordSpacing / size,\n }\n const nextKey = `${nextInline.font.key}|${size}|${nextInline.color.join(',')}|${nextInline.decorations.length ? JSON.stringify(nextInline.decorations) : ''}|${nextInline.z}|${nextShaping.direction}|${nextShaping.language}|${nextShaping.letterSpacing}|${nextShaping.wordSpacing}|${whiteSpace}|${nextInline.transform ? JSON.stringify(nextInline.transform) : ''}`\n if (nextKey !== styleKey) flush()\n inline = nextInline\n prevStyle = style\n shaping = nextShaping\n styleKey = nextKey\n preserveNewlines = ['pre', 'pre-wrap', 'pre-line', 'break-spaces'].includes(whiteSpace)\n nodes.push(textNode)\n }\n }\n node = walker.nextNode()\n }\n flush()\n return result\n}\n"],"mappings":";;;AAyCA,SAAgB,kBAAkB,SAAmC,SAA6B;CAChG,MAAM,QAAQ,QAAQ,SAAS;CAC/B,IAAI,SAAS,EAAE,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,MAAM,MAAM,MAAM,IACjE,MAAM,IAAI,WAAW,2DAA2D;CAElF,QAAQ,YAAY,QAAQ,SAAS,aAAa;CAClD,QAAQ,OAAO,OAAO,QAAQ,SAAS,YAAY;CACnD,IAAI,UAAU,SAAS,QAAQ,OAAO,QAAQ,SAAS,YAAY;CACnE,MAAM,OAAO,QAAQ,UACjB,OAAO,WAAW,WAAW,KAAK,QAAQ,KAAK,UAAU,CAAC,GAAG,MAAM,GAAG,IACtE;CACJ,QAAQ,gBAAgB,IAAI,QAAQ,SAAS,iBAAiB,KAAK,KAAK;CACxE,QAAQ,cAAc,IAAI,QAAQ,SAAS,eAAe,KAAK,KAAK;AACtE;;AAGA,SAAgB,qBAAqB,UAAoB;CACvD,IAAI;CAQJ,MAAM,2BAAW,IAAI,IAA4C;CACjE,QACE,OACA,YAUS;EACT,IAAI,CAAC,SAAS;GACZ,MAAM,SAAS,SAAS,cAAc,QAAQ;GAC9C,UAAU;IACR,OAAO,SAAS,YAAY;IAC5B,WAAW,IAAI,KAAK,UAAU,KAAA,GAAW,EAAE,aAAa,WAAW,CAAC;IACpE;IACA,gBAAgB,OAAO,WAAW,IAAI;GACxC;EACF;EACA,MAAM,EAAE,OAAO,WAAW,QAAQ,mBAAmB;EACrD,MAAM,EAAE,YAAY,UAAU,UAAU,MAAM,QAAQ,UAAU,UAAU,kBACxE;EACF,IAAI,cAAc;EAClB,IAAI,WAAW;EACf,IAAI;EACJ,IA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IAAI,GAAG,KAAK,GAAG,WAAW,MAAM,KAAK,GAAG,EAAE,GAAG,WAAW,YAAY,SAAS,KAAK,UAAU,WAAW,WAAW,IAAI,GAAG,GAAG,WAAW,EAAE,GAAG,YAAY,UAAU,GAAG,YAAY,SAAS,GAAG,YAAY,cAAc,GAAG,YAAY,YAAY,GAAG,WAAW,GAAG,WAAW,YAAY,KAAK,UAAU,WAAW,SAAS,IAAI;IACpW,IAAI,YAAY,UAAU,MAAM;IAChC,SAAS;IACT,YAAY;IACZ,UAAU;IACV,WAAW;IACX,mBAAmB;KAAC;KAAO;KAAY;KAAY;IAAc,CAAC,CAAC,SAAS,UAAU;IACtF,MAAM,KAAK,QAAQ;GACrB;EACF;EACA,OAAO,OAAO,SAAS;CACzB;CACA,MAAM;CACN,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"browserShaping.js","names":[],"sources":["../../src/dom/browserShaping.ts"],"sourcesContent":["import type {\n DomSdfOptions,\n GlyphLayout,\n FontStyleSnapshot,\n GlyphRequest,\n TextDecorationLayout,\n} from '../types.js'\nimport { precedingCharacter, transformText, type TextTransform } from './textTransform.js'\n\ninterface InlineStyle {\n readonly font: FontStyleSnapshot\n readonly fontSize: number\n readonly letterSpacing: number\n readonly wordSpacing: number\n readonly color: readonly [number, number, number, number]\n readonly decorations: readonly TextDecorationLayout[]\n readonly z: number\n readonly transform: TextTransform | null\n}\n\ninterface CaptureContext {\n readonly style: (element: Element) => CSSStyleDeclaration\n readonly inline: (parent: HTMLElement) => InlineStyle | null\n readonly signal: AbortSignal | undefined\n readonly options: DomSdfOptions\n readonly svg?: (element: Element, sequence: number) => void\n /** Told each measured grapheme box, so the capture can find the browser's baseline. */\n readonly box?: (\n font: FontStyleSnapshot,\n box: {\n readonly left: number\n readonly top: number\n readonly right: number\n readonly bottom: number\n readonly width: number\n readonly height: number\n },\n ) => void\n}\n\n/** Applied only by the opt-in atlas path; ordinary glyphs also reset shared Canvas state. */\nexport function setShapingContext(context: CanvasRenderingContext2D, request: GlyphRequest): void {\n const slice = request.shaping?.slice\n if (slice && !(slice[0] >= 0 && slice[0] < slice[1] && slice[1] <= 1)) {\n throw new RangeError('Browser shaping slices must satisfy 0 <= start < end <= 1')\n }\n context.direction = request.shaping?.direction ?? 'inherit'\n const language = request.shaping?.language ?? ''\n if (context.canvas.lang !== language) context.canvas.lang = language\n if ('lang' in context) context.lang = request.shaping?.language ?? 'inherit'\n const size = request.shaping\n ? Number.parseFloat(/[\\d.]+px/.exec(request.font.canvasFont)?.[0] ?? '0')\n : 0\n context.letterSpacing = `${(request.shaping?.letterSpacing ?? 0) * size}px`\n context.wordSpacing = `${(request.shaping?.wordSpacing ?? 0) * size}px`\n}\n\n/** Native helpers and measured descents are shared only within one capture. */\nexport function createBrowserCapture(document: Document) {\n let helpers:\n | {\n range: Range\n segmenter: Intl.Segmenter\n canvas: HTMLCanvasElement\n metricsContext: CanvasRenderingContext2D | null\n }\n | undefined\n const descents = new Map<FontStyleSnapshot, Map<string, number>>()\n return (\n block: HTMLElement,\n context: CaptureContext & {\n readonly blockIndex: number\n readonly rootRect: DOMRect\n readonly invScale: number\n readonly clip: [number, number, number, number]\n readonly glyphs: GlyphLayout[]\n readonly requests: Map<string, GlyphRequest>\n readonly lineKeys: Set<string>\n readonly lineSequences: Map<string, number>\n },\n ): void => {\n if (!helpers) {\n const canvas = document.createElement('canvas')\n helpers = {\n range: document.createRange(),\n segmenter: new Intl.Segmenter(undefined, { granularity: 'grapheme' }),\n canvas,\n metricsContext: canvas.getContext('2d'),\n }\n }\n const { range, segmenter, canvas, metricsContext } = helpers\n const { blockIndex, rootRect, invScale, clip, glyphs, requests, lineKeys, lineSequences } =\n context\n let previousRun = -1\n let sequence = 0\n let baselineOffset: number | undefined\n let motionOrigin!: readonly [number, number, number]\n let motionIndex = (glyphs.at(-1)?.motionOrigin?.[2] ?? -1) + 1\n for (const entry of captureBrowserRuns(block, context, range, segmenter)) {\n if ('svg' in entry) {\n context.svg?.(entry.svg, sequence)\n motionIndex = (glyphs.at(-1)?.motionOrigin?.[2] ?? motionIndex) + 1\n continue\n }\n const { inline, bounds, request, run } = entry\n requests.set(request.key, request)\n const lineKey = `${blockIndex}:${Math.round(bounds.top * 4)}`\n if (run !== previousRun) {\n sequence = lineSequences.get(lineKey) ?? 0\n lineSequences.set(lineKey, sequence + 1)\n previousRun = run\n const slice = request.shaping?.slice ?? [0, 1]\n const width = bounds.width / (slice[1] - slice[0])\n motionOrigin = [\n (bounds.left - width * slice[0] + width / 2 - rootRect.left) * invScale,\n (rootRect.bottom - (bounds.top + bounds.bottom) / 2) * invScale,\n motionIndex++,\n ]\n if (metricsContext) {\n // Font metrics are pixel-rounded at each size; scaling baked metrics can\n // otherwise move a shaped line by half a CSS pixel.\n let byText = descents.get(request.font)\n if (!byText) descents.set(request.font, (byText = new Map<string, number>()))\n const lang = request.shaping?.language ?? ''\n const metricKey = lang ? `${lang}\\u0000${request.character}` : request.character\n let descent = byText.get(metricKey)\n if (descent === undefined) {\n canvas.lang = lang\n if ('lang' in metricsContext) metricsContext.lang = lang || 'inherit'\n metricsContext.font = request.font.canvasFont.replace(\n /[\\d.]+px/,\n `${inline.font.size}px`,\n )\n descent = metricsContext.measureText(request.character).fontBoundingBoxDescent\n byText.set(metricKey, descent)\n }\n baselineOffset = descent * invScale\n }\n }\n lineKeys.add(lineKey)\n glyphs.push({\n glyphKey: request.key,\n fontSize: inline.fontSize,\n originX: (bounds.left - rootRect.left) * invScale,\n lineBottom: (rootRect.bottom - bounds.bottom) * invScale,\n ...(baselineOffset !== undefined && Number.isFinite(baselineOffset)\n ? { baselineOffset }\n : {}),\n motionOrigin,\n advance: bounds.width * invScale,\n decorations: inline.decorations,\n decorationWidth: bounds.width * invScale,\n block: blockIndex,\n breakBefore: 'hard',\n clip,\n color: inline.color,\n sequence,\n z: inline.z,\n })\n }\n }\n}\n\ninterface BrowserTextRun {\n readonly run: number\n readonly inline: InlineStyle\n readonly request: GlyphRequest\n readonly bounds: { left: number; top: number; right: number; bottom: number; width: number }\n}\n\nexport function validateBrowserShaping(options: DomSdfOptions): void {\n if (options.layoutEngine === 'pretext' || options.reshape) {\n throw new Error('textShaping \"browser\" requires Range without a reshape callback')\n }\n if (\n options.textBackend === 'windfoil' &&\n !['sdf', 'sdf-glyphs'].includes(options.windfoil?.fallback ?? '')\n ) {\n throw new Error('textShaping \"browser\" requires SDF or windfoil.fallback: \"sdf\"')\n }\n if (typeof Intl.Segmenter !== 'function') {\n throw new Error('textShaping \"browser\" requires Intl.Segmenter')\n }\n}\n\n/** Keep native shaping context intact, including across equivalent inline markup. */\nfunction captureBrowserRuns(\n block: HTMLElement,\n context: CaptureContext,\n range: Range,\n segmenter: Intl.Segmenter,\n): (BrowserTextRun | { svg: Element })[] {\n const document = block.ownerDocument\n const result: (BrowserTextRun | { svg: Element })[] = []\n let nodes: Text[] = []\n let inline: InlineStyle | null = null\n let shaping: NonNullable<GlyphRequest['shaping']> | null = null\n let styleKey = ''\n let preserveNewlines = false\n\n let shapingKey = ''\n\n const flush = (): void => {\n if (!inline || !shaping || nodes.length === 0) return\n const activeInline = inline\n const activeShaping = shaping\n const activeShapingKey = shapingKey\n let source = ''\n if (nodes.length === 1) {\n source = nodes[0]!.data\n } else {\n for (const node of nodes) source += node.data\n }\n let nodeIndex = 0\n let nodeOffset = 0\n let text = ''\n // Blink maps each text node on its own, so a transformed run notes where its text enters\n // one: case context stops there, and `capitalize` reads the character before each piece.\n let pieces: { readonly at: number; readonly node: number; readonly offset: number }[] = []\n let bounds: BrowserTextRun['bounds'] | null = null\n const transform = activeInline.transform\n const append = (segment: string, index: number, node: number, nodeStart: number): void => {\n for (let from = index; transform;) {\n if (pieces.at(-1)?.node !== node)\n pieces.push({ at: text.length + from - index, node, offset: from - nodeStart })\n // A cluster can continue into the next text node across inline markup.\n from = nodeStart + nodes[node]!.length\n if (index + segment.length <= from || node === nodes.length - 1) break\n nodeStart = from\n node++\n }\n text += segment\n }\n const emit = (): void => {\n const run = text.replace(/ +$/u, '')\n let character = run\n if (transform) {\n character = ''\n for (const [index, piece] of pieces.entries()) {\n const end = Math.min(pieces[index + 1]?.at ?? run.length, run.length)\n if (end <= piece.at) continue\n const data = nodes[piece.node]!.data\n character += transformText(\n run.slice(piece.at, end),\n transform,\n transform.caseMap !== 'capitalize'\n ? undefined\n : piece.offset > 0\n ? Array.from(data.slice(Math.max(0, piece.offset - 2), piece.offset)).pop()\n : precedingCharacter(nodes[piece.node]!, context.style),\n )\n }\n }\n if (bounds && /[^\\s\\p{Cf}]/u.test(character)) {\n // Leave room for SDF padding and small bake-size-dependent metric differences.\n const tileWidth = Math.max(\n 1,\n ((context.options.maxAtlasSize ?? 2048) - 2 * (context.options.padding ?? 12) - 4) * 0.9,\n )\n const tiles = Math.max(\n 1,\n Math.ceil(\n ((bounds.width / activeInline.font.size) * (context.options.bakeSize ?? 96)) /\n tileWidth,\n ),\n )\n for (let tile = 0; tile < tiles; tile++) {\n const slice = [tile / tiles, (tile + 1) / tiles] as const\n const state = tiles > 1 ? { ...activeShaping, slice } : activeShaping\n result.push({\n run: result.length - tile,\n inline: activeInline,\n bounds:\n tiles === 1\n ? bounds\n : {\n ...bounds,\n left: bounds.left + bounds.width * slice[0],\n right: bounds.left + bounds.width * slice[1],\n width: bounds.width / tiles,\n },\n request: {\n key: `${activeInline.font.key}\\u0000browser:${tiles === 1 ? activeShapingKey : JSON.stringify(state)}:${character}`,\n character,\n font: activeInline.font,\n shaping: state,\n },\n })\n }\n }\n bounds = null\n text = ''\n pieces = []\n }\n const locate = (offset: number): void => {\n while (nodeIndex < nodes.length - 1 && offset >= nodeOffset + nodes[nodeIndex]!.length) {\n nodeOffset += nodes[nodeIndex++]!.length\n }\n }\n const scratchBox = { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 }\n for (const part of segmenter.segment(source)) {\n context.signal?.throwIfAborted()\n const seg = part.segment\n const c0 = seg.charCodeAt(0)\n if (c0 <= 32) {\n if (seg.length === 1) {\n if (c0 === 32) {\n if (bounds) text += ' '\n continue\n }\n if (c0 === 9 || c0 === 10 || c0 === 13) {\n if (preserveNewlines) emit()\n else if (bounds) text += ' '\n continue\n }\n }\n if (/^[\\t\\n\\r ]+$/u.test(seg)) {\n if (preserveNewlines && /[\\n\\r\\t]/u.test(seg)) emit()\n else if (bounds) text += ' '\n continue\n }\n }\n locate(part.index)\n const firstNode = nodeIndex\n const firstStart = nodeOffset\n range.setStart(nodes[nodeIndex]!, part.index - nodeOffset)\n const end = part.index + seg.length\n locate(end)\n range.setEnd(nodes[nodeIndex]!, end - nodeOffset)\n const box = range.getBoundingClientRect()\n const width = box.width\n const height = box.height\n if (height <= 0 || width <= 0) {\n // Joiners, isolates, combining marks, and other bidi controls still participate in shaping.\n if (bounds ? /^[\\p{Cf}\\p{M}]+$/u.test(seg) : /^\\p{Cf}+$/u.test(seg))\n append(seg, part.index, firstNode, firstStart)\n continue\n }\n const left = box.left\n const right = box.right\n const top = box.top\n const bottom = box.bottom\n scratchBox.left = left\n scratchBox.top = top\n scratchBox.right = right\n scratchBox.bottom = bottom\n scratchBox.width = width\n scratchBox.height = height\n context.box?.(activeInline.font, scratchBox)\n if (bounds && (Math.abs(top - bounds.top) > 0.5 || Math.abs(bottom - bounds.bottom) > 0.5))\n emit()\n append(seg, part.index, firstNode, firstStart)\n if (bounds) {\n if (left < bounds.left) bounds.left = left\n if (right > bounds.right) bounds.right = right\n if (top < bounds.top) bounds.top = top\n if (bottom > bounds.bottom) bounds.bottom = bottom\n bounds.width = bounds.right - bounds.left\n } else {\n bounds = { left, right, top, bottom, width }\n }\n }\n emit()\n nodes = []\n }\n\n let blockLang: string | undefined\n const langOf = (element: Element): string =>\n element.getAttribute('lang') ??\n (element === block\n ? (blockLang ??= block.closest('[lang]')?.getAttribute('lang') ?? '')\n : element.parentElement\n ? langOf(element.parentElement)\n : '')\n\n let prevStyle: CSSStyleDeclaration | null = null\n const walker = document.createTreeWalker(block, 5 /* SHOW_ELEMENT | SHOW_TEXT */)\n let node = walker.nextNode()\n while (node) {\n context.signal?.throwIfAborted()\n if (node.nodeType === 1) {\n const element = node as Element\n if (\n context.svg &&\n (element.localName === 'svg' || element.localName === 'img') &&\n !element.parentElement?.closest('svg')\n ) {\n flush()\n result.push({ svg: element })\n }\n if (element.tagName === 'BR') flush()\n else if (nodes.length > 0 && context.style(element) !== prevStyle) {\n const display = context.style(element).display\n if (display && !display.startsWith('inline') && display !== 'contents') flush()\n }\n } else {\n const textNode = node as Text\n const parent = textNode.parentElement!\n const nextInline =\n context.svg && parent.closest('svg') && !parent.closest('foreignObject')\n ? null\n : context.inline(parent)\n if (!nextInline) flush()\n else {\n const style = context.style(parent)\n if (nextInline === inline && style === prevStyle && !parent.hasAttribute('lang')) {\n nodes.push(textNode)\n node = walker.nextNode()\n continue\n }\n const size = nextInline.font.size\n const whiteSpace = style.whiteSpace\n const nextShaping: NonNullable<GlyphRequest['shaping']> = {\n direction: style.direction === 'rtl' ? 'rtl' : 'ltr',\n language: langOf(parent),\n letterSpacing: nextInline.letterSpacing / size,\n wordSpacing: nextInline.wordSpacing / size,\n }\n const nextShapingKey = JSON.stringify(nextShaping)\n const c = nextInline.color\n const nextKey = `${nextInline.font.key}|${size}|${c[0]},${c[1]},${c[2]},${c[3]}|${nextInline.decorations.length ? JSON.stringify(nextInline.decorations) : ''}|${nextInline.z}|${nextShapingKey}|${whiteSpace}|${nextInline.transform ? JSON.stringify(nextInline.transform) : ''}`\n if (nextKey !== styleKey) flush()\n inline = nextInline\n prevStyle = style\n shaping = nextShaping\n shapingKey = nextShapingKey\n styleKey = nextKey\n preserveNewlines =\n whiteSpace === 'pre' ||\n whiteSpace === 'pre-wrap' ||\n whiteSpace === 'pre-line' ||\n whiteSpace === 'break-spaces'\n nodes.push(textNode)\n }\n }\n node = walker.nextNode()\n }\n flush()\n return result\n}\n"],"mappings":";;;AAyCA,SAAgB,kBAAkB,SAAmC,SAA6B;CAChG,MAAM,QAAQ,QAAQ,SAAS;CAC/B,IAAI,SAAS,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A,MAAM,iBAAiB,KAAK,UAAU,WAAW;IACjD,MAAM,IAAI,WAAW;IACrB,MAAM,UAAU,GAAG,WAAW,KAAK,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,WAAW,YAAY,SAAS,KAAK,UAAU,WAAW,WAAW,IAAI,GAAG,GAAG,WAAW,EAAE,GAAG,eAAe,GAAG,WAAW,GAAG,WAAW,YAAY,KAAK,UAAU,WAAW,SAAS,IAAI;IAC/Q,IAAI,YAAY,UAAU,MAAM;IAChC,SAAS;IACT,YAAY;IACZ,UAAU;IACV,aAAa;IACb,WAAW;IACX,mBACE,eAAe,SACf,eAAe,cACf,eAAe,cACf,eAAe;IACjB,MAAM,KAAK,QAAQ;GACrB;EACF;EACA,OAAO,OAAO,SAAS;CACzB;CACA,MAAM;CACN,OAAO;AACT"}
|
package/dist/dom/clusters.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
// src/dom/clusters.ts
|
|
2
2
|
var EMOJI_SEQUENCE_HINT = /\u200D|\u20E3|\uFE0E|\uFE0F|[\u{1F1E6}-\u{1F1FF}]|[\u{1F3FB}-\u{1F3FF}]|[\u{E0020}-\u{E007F}]/u;
|
|
3
3
|
var EMOJI_SEQUENCE = /\p{Extended_Pictographic}|\p{Regional_Indicator}|^[#*0-9]\uFE0F?\u20E3$/u;
|
|
4
|
+
var SIMPLE_RUN = /[ -~\u00c0-\u024f\u3000-\u301f\u3041-\u3096\u30a1-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7a3\uff01-\uff5e]{32,}/g;
|
|
4
5
|
var graphemes;
|
|
6
|
+
function appendGraphemes(result, segmenter, text) {
|
|
7
|
+
for (const { segment } of segmenter.segment(text)) if (segment.length > 1 && EMOJI_SEQUENCE.test(segment)) result.push(segment);
|
|
8
|
+
else for (const point of segment) result.push(point);
|
|
9
|
+
}
|
|
5
10
|
/** @internal Code points, except that emoji grapheme sequences stay whole. */
|
|
6
11
|
function glyphClusters(text) {
|
|
7
12
|
if (!EMOJI_SEQUENCE_HINT.test(text) || typeof Intl.Segmenter !== "function") return text;
|
|
8
13
|
graphemes ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
9
14
|
const result = [];
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
let start = 0;
|
|
16
|
+
if (text.length >= 32) for (const run of text.matchAll(SIMPLE_RUN)) {
|
|
17
|
+
const end = run.index + run[0].length - 1;
|
|
18
|
+
appendGraphemes(result, graphemes, text.slice(start, run.index + 1));
|
|
19
|
+
for (let i = run.index + 1; i < end; i++) result.push(text[i]);
|
|
20
|
+
start = end;
|
|
21
|
+
}
|
|
22
|
+
appendGraphemes(result, graphemes, text.slice(start));
|
|
12
23
|
return result;
|
|
13
24
|
}
|
|
14
25
|
var nonAscii = (text) => text.length > 1 || text.charCodeAt(0) >= 169;
|
package/dist/dom/clusters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clusters.js","names":[],"sources":["../../src/dom/clusters.ts"],"sourcesContent":["// Hint-free prose keeps the native string iterator and allocates nothing.\nconst EMOJI_SEQUENCE_HINT =\n /\\u200D|\\u20E3|\\uFE0E|\\uFE0F|[\\u{1F1E6}-\\u{1F1FF}]|[\\u{1F3FB}-\\u{1F3FF}]|[\\u{E0020}-\\u{E007F}]/u\nconst EMOJI_SEQUENCE = /\\p{Extended_Pictographic}|\\p{Regional_Indicator}|^[#*0-9]\\uFE0F?\\u20E3$/u\nlet graphemes: Intl.Segmenter | undefined\n\n/** @internal Code points, except that emoji grapheme sequences stay whole. */\nexport function glyphClusters(text: string): Iterable<string> {\n if (!EMOJI_SEQUENCE_HINT.test(text) || typeof Intl.Segmenter !== 'function') return text\n graphemes ??= new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n const result: string[] = []\n for (
|
|
1
|
+
{"version":3,"file":"clusters.js","names":[],"sources":["../../src/dom/clusters.ts"],"sourcesContent":["// Hint-free prose keeps the native string iterator and allocates nothing.\nconst EMOJI_SEQUENCE_HINT =\n /\\u200D|\\u20E3|\\uFE0E|\\uFE0F|[\\u{1F1E6}-\\u{1F1FF}]|[\\u{1F3FB}-\\u{1F3FF}]|[\\u{E0020}-\\u{E007F}]/u\nconst EMOJI_SEQUENCE = /\\p{Extended_Pictographic}|\\p{Regional_Indicator}|^[#*0-9]\\uFE0F?\\u20E3$/u\n// Every adjacent pair in these BMP ranges has a grapheme break. They contain printable\n// Latin text, CJK punctuation, kana, Han and complete Hangul syllables (no joining jamo).\nconst SIMPLE_RUN =\n /[ -~\\u00c0-\\u024f\\u3000-\\u301f\\u3041-\\u3096\\u30a1-\\u30ff\\u3400-\\u4dbf\\u4e00-\\u9fff\\uac00-\\ud7a3\\uff01-\\uff5e]{32,}/g\nlet graphemes: Intl.Segmenter | undefined\n\nfunction appendGraphemes(result: string[], segmenter: Intl.Segmenter, text: string): void {\n for (const { segment } of segmenter.segment(text)) {\n if (segment.length > 1 && EMOJI_SEQUENCE.test(segment)) result.push(segment)\n else for (const point of segment) result.push(point)\n }\n}\n\n/** @internal Code points, except that emoji grapheme sequences stay whole. */\nexport function glyphClusters(text: string): Iterable<string> {\n if (!EMOJI_SEQUENCE_HINT.test(text) || typeof Intl.Segmenter !== 'function') return text\n graphemes ??= new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n const result: string[] = []\n // Segment both edges with their neighbours for prepend marks, keycaps and joining jamo.\n let start = 0\n if (text.length >= 32) {\n for (const run of text.matchAll(SIMPLE_RUN)) {\n const end = run.index + run[0].length - 1\n appendGraphemes(result, graphemes, text.slice(start, run.index + 1))\n for (let i = run.index + 1; i < end; i++) result.push(text[i]!)\n start = end\n }\n }\n appendGraphemes(result, graphemes, text.slice(start))\n return result\n}\n\nconst nonAscii = (text: string): boolean => text.length > 1 || text.charCodeAt(0) >= 0xa9\n\n/** @internal Matches Pretext's emoji width-correction predicate. */\nexport function isEmojiGrapheme(text: string): boolean {\n return nonAscii(text) && /\\p{Emoji_Presentation}|\\uFE0F/u.test(text)\n}\n\n/** @internal Broad candidate predicate shared by capture and colour rasterization. */\nexport function isEmojiCandidate(text: string): boolean {\n return (\n nonAscii(text) && /[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3\\uFE0F]/u.test(text)\n )\n}\n"],"mappings":";AACA,IAAM,sBACJ;AACF,IAAM,iBAAiB;AAGvB,IAAM,aACJ;AACF,IAAI;AAEJ,SAAS,gBAAgB,QAAkB,WAA2B,MAAoB;CACxF,KAAK,MAAM,EAAE,aAAa,UAAU,QAAQ,IAAI,GAC9C,IAAI,QAAQ,SAAS,KAAK,eAAe,KAAK,OAAO,GAAG,OAAO,KAAK,OAAO;MACtE,KAAK,MAAM,SAAS,SAAS,OAAO,KAAK,KAAK;AAEvD;;AAGA,SAAgB,cAAc,MAAgC;CAC5D,IAAI,CAAC,oBAAoB,KAAK,IAAI,KAAK,OAAO,KAAK,cAAc,YAAY,OAAO;CACpF,cAAc,IAAI,KAAK,UAAU,KAAA,GAAW,EAAE,aAAa,WAAW,CAAC;CACvE,MAAM,SAAmB,CAAC;CAE1B,IAAI,QAAQ;CACZ,IAAI,KAAK,UAAU,IACjB,KAAK,MAAM,OAAO,KAAK,SAAS,UAAU,GAAG;EAC3C,MAAM,MAAM,IAAI,QAAQ,IAAI,EAAE,CAAC,SAAS;EACxC,gBAAgB,QAAQ,WAAW,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,CAAC;EACnE,KAAK,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,KAAK,KAAK,OAAO,KAAK,KAAK,EAAG;EAC9D,QAAQ;CACV;CAEF,gBAAgB,QAAQ,WAAW,KAAK,MAAM,KAAK,CAAC;CACpD,OAAO;AACT;AAEA,IAAM,YAAY,SAA0B,KAAK,SAAS,KAAK,KAAK,WAAW,CAAC,KAAK;;AAGrF,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,SAAS,IAAI,KAAK,iCAAiC,KAAK,IAAI;AACrE;;AAGA,SAAgB,iBAAiB,MAAuB;CACtD,OACE,SAAS,IAAI,KAAK,iEAAiE,KAAK,IAAI;AAEhG"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SdfDropShadowOptions, SdfOutlineOptions } from '../types.js';
|
|
2
|
+
export type CssColorParser = (document: Document, value: string) => [number, number, number, number] | null;
|
|
3
|
+
export declare function parseCssTextShadow(document: Document, parseColor: CssColorParser, style: CSSStyleDeclaration, fontSize: number, invScale: number, opacity: number): SdfDropShadowOptions | undefined;
|
|
4
|
+
export declare function parseCssTextStroke(document: Document, parseColor: CssColorParser, style: CSSStyleDeclaration, fontSize: number, invScale: number, opacity: number): SdfOutlineOptions | undefined;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/dom/cssEffects.ts
|
|
2
|
+
var LENGTH_TOKEN_RE = /^-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px|em|rem|%)?$/i;
|
|
3
|
+
function parsePx(value, ref = 0) {
|
|
4
|
+
const parsed = Number.parseFloat(value);
|
|
5
|
+
return !Number.isFinite(parsed) ? 0 : ref && value.endsWith("%") ? parsed * ref / 100 : ref && (value.endsWith("em") || !/[a-z]/i.test(value)) ? parsed * ref : parsed;
|
|
6
|
+
}
|
|
7
|
+
function parseEffectColor(document, parseColor, value, opacity) {
|
|
8
|
+
const trimmed = value.trim();
|
|
9
|
+
if (!trimmed || /^transparent$/i.test(trimmed)) return null;
|
|
10
|
+
const rgba = parseColor(document, trimmed);
|
|
11
|
+
if (rgba) {
|
|
12
|
+
const alpha = Math.min(1, Math.max(0, rgba[3] * opacity));
|
|
13
|
+
return alpha <= 0 ? null : [(Math.round(Math.min(1, Math.max(0, rgba[0])) * 255) << 16 | Math.round(Math.min(1, Math.max(0, rgba[1])) * 255) << 8 | Math.round(Math.min(1, Math.max(0, rgba[2])) * 255)) >>> 0, alpha];
|
|
14
|
+
}
|
|
15
|
+
return opacity <= 0 ? null : [trimmed, Math.min(1, Math.max(0, opacity))];
|
|
16
|
+
}
|
|
17
|
+
function parseLengthsAndColor(raw, fontSize, invScale, stopAtComma) {
|
|
18
|
+
const lengths = [];
|
|
19
|
+
const colors = [];
|
|
20
|
+
let depth = 0;
|
|
21
|
+
let start = 0;
|
|
22
|
+
for (let i = 0; i <= raw.length; i++) {
|
|
23
|
+
const ch = raw[i];
|
|
24
|
+
if (ch === "(") depth++;
|
|
25
|
+
else if (ch === ")") depth = Math.max(0, depth - 1);
|
|
26
|
+
else if (depth === 0 && (i === raw.length || ch === "," || /\s/.test(ch))) {
|
|
27
|
+
if (i > start) {
|
|
28
|
+
const tok = raw.slice(start, i);
|
|
29
|
+
if (LENGTH_TOKEN_RE.test(tok)) lengths.push(parsePx(tok, fontSize) * invScale);
|
|
30
|
+
else colors.push(tok);
|
|
31
|
+
}
|
|
32
|
+
start = i + 1;
|
|
33
|
+
if (stopAtComma && ch === ",") break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [lengths, colors.join(" ")];
|
|
37
|
+
}
|
|
38
|
+
function parseCssTextShadow(document, parseColor, style, fontSize, invScale, opacity) {
|
|
39
|
+
const raw = style.textShadow.trim();
|
|
40
|
+
if (!raw || raw === "none") return void 0;
|
|
41
|
+
const [lengths, colorStr] = parseLengthsAndColor(raw, fontSize, invScale, true);
|
|
42
|
+
if (lengths.length < 2) return void 0;
|
|
43
|
+
const parsedColor = parseEffectColor(document, parseColor, colorStr || style.color || "#000", opacity);
|
|
44
|
+
if (!parsedColor) return void 0;
|
|
45
|
+
const blur = Math.max(0, lengths[2] ?? 0);
|
|
46
|
+
return {
|
|
47
|
+
offsetX: lengths[0],
|
|
48
|
+
offsetY: -lengths[1],
|
|
49
|
+
...blur > 0 ? { blur } : {},
|
|
50
|
+
color: parsedColor[0],
|
|
51
|
+
opacity: parsedColor[1]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function parseCssTextStroke(document, parseColor, style, fontSize, invScale, opacity) {
|
|
55
|
+
let width = parsePx(style.webkitTextStrokeWidth || style.getPropertyValue("-webkit-text-stroke-width"), fontSize) * invScale;
|
|
56
|
+
let rawColor = style.webkitTextStrokeColor || style.getPropertyValue("-webkit-text-stroke-color");
|
|
57
|
+
if (!(width > 0) && style.webkitTextStroke) {
|
|
58
|
+
const [lengths, colorStr] = parseLengthsAndColor(style.webkitTextStroke.trim(), fontSize, invScale, false);
|
|
59
|
+
width = lengths[0] ?? 0;
|
|
60
|
+
if (colorStr) rawColor = colorStr;
|
|
61
|
+
}
|
|
62
|
+
if (!(width > 0)) return void 0;
|
|
63
|
+
const parsedColor = parseEffectColor(document, parseColor, rawColor || style.color || "#000", opacity);
|
|
64
|
+
return parsedColor ? {
|
|
65
|
+
width,
|
|
66
|
+
color: parsedColor[0],
|
|
67
|
+
opacity: parsedColor[1]
|
|
68
|
+
} : void 0;
|
|
69
|
+
}
|
|
70
|
+
export { parseCssTextShadow, parseCssTextStroke };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=cssEffects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssEffects.js","names":[],"sources":["../../src/dom/cssEffects.ts"],"sourcesContent":["import type { SdfDropShadowOptions, SdfOutlineOptions } from '../types.js'\n\nexport type CssColorParser = (\n document: Document,\n value: string,\n) => [number, number, number, number] | null\n\nconst LENGTH_TOKEN_RE = /^-?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?(?:px|em|rem|%)?$/i\n\nfunction parsePx(value: string | null | undefined, ref = 0): number {\n const parsed = Number.parseFloat(value!)\n return !Number.isFinite(parsed)\n ? 0\n : ref && value!.endsWith('%')\n ? (parsed * ref) / 100\n : ref && (value!.endsWith('em') || !/[a-z]/i.test(value!))\n ? parsed * ref\n : parsed\n}\n\nfunction parseEffectColor(\n document: Document,\n parseColor: CssColorParser,\n value: string,\n opacity: number,\n): readonly [number | string, number] | null {\n const trimmed = value.trim()\n if (!trimmed || /^transparent$/i.test(trimmed)) return null\n const rgba = parseColor(document, trimmed)\n if (rgba) {\n const alpha = Math.min(1, Math.max(0, rgba[3] * opacity))\n return alpha <= 0\n ? null\n : [\n ((Math.round(Math.min(1, Math.max(0, rgba[0])) * 255) << 16) |\n (Math.round(Math.min(1, Math.max(0, rgba[1])) * 255) << 8) |\n Math.round(Math.min(1, Math.max(0, rgba[2])) * 255)) >>>\n 0,\n alpha,\n ]\n }\n return opacity <= 0 ? null : [trimmed, Math.min(1, Math.max(0, opacity))]\n}\n\nfunction parseLengthsAndColor(\n raw: string,\n fontSize: number,\n invScale: number,\n stopAtComma: boolean,\n): readonly [number[], string] {\n const lengths: number[] = []\n const colors: string[] = []\n let depth = 0\n let start = 0\n for (let i = 0; i <= raw.length; i++) {\n const ch = raw[i]\n if (ch === '(') depth++\n else if (ch === ')') depth = Math.max(0, depth - 1)\n else if (depth === 0 && (i === raw.length || ch === ',' || /\\s/.test(ch!))) {\n if (i > start) {\n const tok = raw.slice(start, i)\n if (LENGTH_TOKEN_RE.test(tok)) lengths.push(parsePx(tok, fontSize) * invScale)\n else colors.push(tok)\n }\n start = i + 1\n if (stopAtComma && ch === ',') break\n }\n }\n return [lengths, colors.join(' ')]\n}\n\nexport function parseCssTextShadow(\n document: Document,\n parseColor: CssColorParser,\n style: CSSStyleDeclaration,\n fontSize: number,\n invScale: number,\n opacity: number,\n): SdfDropShadowOptions | undefined {\n const raw = style.textShadow.trim()\n if (!raw || raw === 'none') return undefined\n const [lengths, colorStr] = parseLengthsAndColor(raw, fontSize, invScale, true)\n if (lengths.length < 2) return undefined\n const parsedColor = parseEffectColor(\n document,\n parseColor,\n colorStr || style.color || '#000',\n opacity,\n )\n if (!parsedColor) return undefined\n const blur = Math.max(0, lengths[2] ?? 0)\n return {\n offsetX: lengths[0]!,\n offsetY: -lengths[1]!,\n ...(blur > 0 ? { blur } : {}),\n color: parsedColor[0],\n opacity: parsedColor[1],\n }\n}\n\nexport function parseCssTextStroke(\n document: Document,\n parseColor: CssColorParser,\n style: CSSStyleDeclaration,\n fontSize: number,\n invScale: number,\n opacity: number,\n): SdfOutlineOptions | undefined {\n let width =\n parsePx(\n style.webkitTextStrokeWidth || style.getPropertyValue('-webkit-text-stroke-width'),\n fontSize,\n ) * invScale\n let rawColor = style.webkitTextStrokeColor || style.getPropertyValue('-webkit-text-stroke-color')\n if (!(width > 0) && style.webkitTextStroke) {\n const [lengths, colorStr] = parseLengthsAndColor(\n style.webkitTextStroke.trim(),\n fontSize,\n invScale,\n false,\n )\n width = lengths[0] ?? 0\n if (colorStr) rawColor = colorStr\n }\n if (!(width > 0)) return undefined\n const parsedColor = parseEffectColor(\n document,\n parseColor,\n rawColor || style.color || '#000',\n opacity,\n )\n return parsedColor ? { width, color: parsedColor[0], opacity: parsedColor[1] } : undefined\n}\n"],"mappings":";AAOA,IAAM,kBAAkB;AAExB,SAAS,QAAQ,OAAkC,MAAM,GAAW;CAClE,MAAM,SAAS,OAAO,WAAW,KAAM;CACvC,OAAO,CAAC,OAAO,SAAS,MAAM,IAC1B,IACA,OAAO,MAAO,SAAS,GAAG,IACvB,SAAS,MAAO,MACjB,QAAQ,MAAO,SAAS,IAAI,KAAK,CAAC,SAAS,KAAK,KAAM,KACpD,SAAS,MACT;AACV;AAEA,SAAS,iBACP,UACA,YACA,OACA,SAC2C;CAC3C,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,CAAC,WAAW,iBAAiB,KAAK,OAAO,GAAG,OAAO;CACvD,MAAM,OAAO,WAAW,UAAU,OAAO;CACzC,IAAI,MAAM;EACR,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO,CAAC;EACxD,OAAO,SAAS,IACZ,OACA,EACI,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,EAAE,CAAC,IAAI,GAAG,KAAK,KACtD,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK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C,aAAa,OAAO,KAAA;CACzB,MAAM,OAAO,KAAK,IAAI,GAAG,QAAQ,MAAM,CAAC;CACxC,OAAO;EACL,SAAS,QAAQ;EACjB,SAAS,CAAC,QAAQ;EAClB,GAAI,OAAO,IAAI,EAAE,KAAK,IAAI,CAAC;EAC3B,OAAO,YAAY;EACnB,SAAS,YAAY;CACvB;AACF;AAEA,SAAgB,mBACd,UACA,YACA,OACA,UACA,UACA,SAC+B;CAC/B,IAAI,QACF,QACE,MAAM,yBAAyB,MAAM,iBAAiB,2BAA2B,GACjF,QACF,IAAI;CACN,IAAI,WAAW,MAAM,yBAAyB,MAAM,iBAAiB,2BAA2B;CAChG,IAAI,EAAE,QAAQ,MAAM,MAAM,kBAAkB;EAC1C,MAAM,CAAC,SAAS,YAAY,qBAC1B,MAAM,iBAAiB,KAAK,GAC5B,UACA,UACA,KACF;EACA,QAAQ,QAAQ,MAAM;EACtB,IAAI,UAAU,WAAW;CAC3B;CACA,IAAI,EAAE,QAAQ,IAAI,OAAO,KAAA;CACzB,MAAM,cAAc,iBAClB,UACA,YACA,YAAY,MAAM,SAAS,QAC3B,OACF;CACA,OAAO,cAAc;EAAE;EAAO,OAAO,YAAY;EAAI,SAAS,YAAY;CAAG,IAAI,KAAA;AACnF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Group, type InstancedBufferGeometry, type WebGPURenderer } from 'three/webgpu';
|
|
2
|
+
import type { createExtraTextParts } from '../windfoil/mixed.js';
|
|
3
|
+
import type { WindfoilBackend } from '../windfoil/runtime.js';
|
|
4
|
+
import type { TracedOutlines } from '../windfoil/tracedOutlines.js';
|
|
5
|
+
import type * as SlugRuntime from '../slug/runtime.js';
|
|
6
|
+
import type * as WindfoilRuntime from '../windfoil/runtime.js';
|
|
7
|
+
import type * as TracedOutlinesModule from '../windfoil/tracedOutlines.js';
|
|
8
|
+
import { type GlyphTextMaterial } from '../text/GlyphTextMaterial.js';
|
|
9
|
+
import type { ReflowState } from '../text/reflow.js';
|
|
10
|
+
import type * as ReflowModule from '../text/reflow.js';
|
|
11
|
+
import type { ResolvedTextTone } from '../text/tone.js';
|
|
12
|
+
import type { DomLayoutSnapshot, DomSdfOptions, SdfAtlas, SdfMotionOptions, WindfoilOptions } from '../types.js';
|
|
13
|
+
import type * as DomExtrasModule from './domExtras.js';
|
|
14
|
+
export interface AnalyticRetainedResult {
|
|
15
|
+
readonly retained: WindfoilBackend | null;
|
|
16
|
+
readonly traced: TracedOutlines | null;
|
|
17
|
+
}
|
|
18
|
+
export interface AnalyticBuildCallbacks {
|
|
19
|
+
readonly preloadBackend: Promise<typeof SlugRuntime | typeof WindfoilRuntime | null> | null;
|
|
20
|
+
readonly preloadTraced: Promise<typeof TracedOutlinesModule | null> | null;
|
|
21
|
+
readonly loadTraced: () => Promise<typeof TracedOutlinesModule>;
|
|
22
|
+
readonly buildAtlas: (requests: DomLayoutSnapshot['requests'], signal: AbortSignal, appendable?: boolean | 'headroom') => Promise<SdfAtlas>;
|
|
23
|
+
}
|
|
24
|
+
export declare function buildDomAnalyticBackend(renderer: WebGPURenderer, doc: Document, snapshot: DomLayoutSnapshot, opts: DomSdfOptions, backendKind: 'windfoil' | 'slug', analytic: WindfoilOptions, headroom: boolean, existingTraced: TracedOutlines | null, resetAtlas: boolean, signal: AbortSignal, throwIfAborted: (s: AbortSignal) => void, callbacks: AnalyticBuildCallbacks): Promise<AnalyticRetainedResult>;
|
|
25
|
+
export declare function loadMixedExtras(): Promise<{
|
|
26
|
+
createExtraTextParts: typeof createExtraTextParts;
|
|
27
|
+
}>;
|
|
28
|
+
export interface AnalyticContentBundle {
|
|
29
|
+
readonly g: Group;
|
|
30
|
+
readonly m: GlyphTextMaterial;
|
|
31
|
+
readonly tg: InstancedBufferGeometry;
|
|
32
|
+
readonly a: boolean;
|
|
33
|
+
sm(change: SdfMotionOptions, live: SdfMotionOptions): void;
|
|
34
|
+
st(tone: ResolvedTextTone | null): boolean;
|
|
35
|
+
ud(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, motion: SdfMotionOptions): void;
|
|
36
|
+
rg(geometry: InstancedBufferGeometry): void;
|
|
37
|
+
u(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, motion: SdfMotionOptions, tone?: ResolvedTextTone | null): boolean;
|
|
38
|
+
d(): void;
|
|
39
|
+
}
|
|
40
|
+
export declare function createAnalyticContent(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, options: DomSdfOptions, motion: SdfMotionOptions, tone: ResolvedTextTone | null, makeExtraParts?: typeof createExtraTextParts, extrasMod?: typeof DomExtrasModule | null): AnalyticContentBundle;
|
|
41
|
+
export declare function reflowAnalytic(snapshot: DomLayoutSnapshot, retained: WindfoilBackend, content: AnalyticContentBundle, width: number, motion: SdfMotionOptions, rm: typeof ReflowModule, reflowState: ReflowState | null): {
|
|
42
|
+
readonly width: number;
|
|
43
|
+
readonly height: number;
|
|
44
|
+
readonly lines: number;
|
|
45
|
+
readonly state: ReflowState;
|
|
46
|
+
};
|
|
47
|
+
export declare function countAnalyticStats(snapshot: DomLayoutSnapshot, windfoil: WindfoilBackend): readonly [
|
|
48
|
+
glyphs: number,
|
|
49
|
+
shapes: number,
|
|
50
|
+
colorGlyphs: number,
|
|
51
|
+
fallbackGlyphs: number,
|
|
52
|
+
switchableGlyphs: number
|
|
53
|
+
];
|