ultra-text 1.0.1 → 1.0.2
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 +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- 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 +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -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.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -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 +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- 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/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorations.js","names":[],"sources":["../../src/text/decorations.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { attribute, float, mix } from 'three/tsl'\n\nimport type { DomLayoutSnapshot, TextDecorationLayout } from '../types.js'\nimport { GlyphTextMaterial, type GlyphTextMaterialOptions } from './GlyphTextMaterial.js'\nimport { byte, setBounds, setUnitQuad } from './geometryUtils.js'\n\nexport const GLYPH_RECTS_KEY = 'ultraGlyphRects'\nexport function glyphRectTable(geometry: InstancedBufferGeometry): ArrayLike<number> {\n return (\n (geometry.userData[GLYPH_RECTS_KEY] as Float32Array | undefined) ??\n geometry.getAttribute('sdfRect').array\n )\n}\n\n/** Decoration quads share their source glyph's motion center, index, and clip. */\nexport class TextDecorationMaterial extends GlyphTextMaterial {\n constructor(options: GlyphTextMaterialOptions) {\n super(\n options,\n (quad, rect, position, _depth, scale) => {\n const decoration = attribute<'vec4'>('decorationRect', 'vec4')\n if (options.motion === false) return mix(decoration.xy, decoration.zw, quad)\n const delta = mix(decoration.xy.sub(rect.xy), decoration.zw.sub(rect.zw), quad)\n return position.add(delta.mul(scale))\n },\n attribute<'float'>('decorationIndex', 'float'),\n )\n this.name = 'ultra-text solid text decorations'\n this.applyCoverage(float(1), float(1), float(0.5))\n }\n}\n\nfunction sameDecoration(a: TextDecorationLayout, b: TextDecorationLayout): boolean {\n return (\n a.line === b.line &&\n a.offset === b.offset &&\n a.thickness === b.thickness &&\n a.color.every((v, i) => v === b.color[i])\n )\n}\n\ntype DecorationRecord = readonly [\n stroke: readonly [number, number, number, number],\n rectIndex: number,\n motionIndex: number,\n color: readonly [number, number, number, number],\n clip: readonly [number, number, number, number],\n sequence: number,\n z: number,\n motionOrigin: readonly [number, number, number] | null,\n]\n\nlet cachedSnapshot: DomLayoutSnapshot | null = null\nlet cachedDrawable: ((key: string) => boolean) | null = null\nlet cachedRecords: readonly DecorationRecord[] = []\n\nfunction decorationRecords(\n snapshot: DomLayoutSnapshot,\n drawable: (key: string) => boolean,\n): readonly DecorationRecord[] {\n if (snapshot === cachedSnapshot && drawable === cachedDrawable) return cachedRecords\n const glyphs = snapshot.glyphs\n const records: DecorationRecord[] = []\n if (glyphs.some((glyph) => glyph.decorations?.length)) {\n let glyphIndex = 0\n let motionIndex = -1\n let previousGroup: number | undefined\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n if (!drawable(glyph.glyphKey)) continue\n if (glyph.shapeGroup === undefined || glyph.shapeGroup !== previousGroup) motionIndex++\n previousGroup = glyph.shapeGroup\n const decorations = glyph.decorations\n if (decorations) {\n for (const decoration of decorations) {\n if (decoration.thickness <= 0 || decoration.color[3] <= 0) continue\n const next = glyphs[index + 1]\n let right = glyph.originX + (glyph.decorationWidth ?? Math.abs(glyph.advance))\n if (\n next?.block === glyph.block &&\n next.lineBottom === glyph.lineBottom &&\n next.decorations?.some((candidate) => sameDecoration(decoration, candidate))\n ) {\n right = Math.max(right, next.originX)\n }\n const y = glyph.lineBottom + decoration.offset\n records.push([\n [glyph.originX, y - decoration.thickness / 2, right, y + decoration.thickness / 2],\n glyphIndex,\n glyph.motionOrigin?.[2] ?? motionIndex,\n decoration.color,\n glyph.clip,\n glyph.sequence,\n glyph.z,\n glyph.motionOrigin ?? null,\n ])\n }\n }\n glyphIndex++\n }\n }\n cachedSnapshot = snapshot\n cachedDrawable = drawable\n return (cachedRecords = records)\n}\n\nconst DECORATION_ATTRS = [\n 'sdfRect',\n 'decorationRect',\n 'decorationIndex',\n 'sdfColor',\n 'sdfClip',\n 'sdfMeta',\n] as const\n\nfunction decorationAttributesMatch(\n geometry: InstancedBufferGeometry,\n records: readonly DecorationRecord[],\n): boolean {\n const count = geometry.instanceCount\n if (!count || records.length !== count) return false\n if (\n DECORATION_ATTRS.some(\n (name) => (geometry.getAttribute(name) as { count: number } | undefined)?.count !== count,\n )\n )\n return false\n const run = geometry.getAttribute('sdfRunMotion') as { count: number } | undefined\n return records.some((r) => r[7]) ? run?.count === count : !run\n}\n\nfunction writeDecorationBatch(\n records: readonly DecorationRecord[],\n sourceRects: ArrayLike<number>,\n rects: Float32Array,\n strokes: Float32Array,\n indices: Float32Array,\n colors: Uint8Array,\n clips: Float32Array,\n metadata: Float32Array,\n runMotion: Float32Array | null,\n): [number, number] {\n let minZ = 0\n let maxZ = 0\n for (let index = 0; index < records.length; index++) {\n const [stroke, rectIndex, motionIndex, color, clip, sequence, z, motionOrigin] = records[index]!\n const offset = index * 4\n const srcOffset = rectIndex * 4\n for (let i = 0; i < 4; i++) {\n rects[offset + i] = sourceRects[srcOffset + i] ?? 0\n colors[offset + i] = byte(color[i]!)\n }\n strokes.set(stroke, offset)\n clips.set(clip, offset)\n indices[index] = motionIndex\n metadata[index * 2] = sequence\n metadata[index * 2 + 1] = z\n if (runMotion && motionOrigin) runMotion.set(motionOrigin, index * 3)\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n return [minZ, maxZ]\n}\n\n/**\n * True when an existing decoration batch can be rewritten without allocating.\n * A null geometry matches only an empty decoration list.\n */\nexport function canUpdateDecorationGeometry(\n geometry: InstancedBufferGeometry | null,\n snapshot: DomLayoutSnapshot,\n drawable: (key: string) => boolean,\n): boolean {\n const records = decorationRecords(snapshot, drawable)\n return geometry ? decorationAttributesMatch(geometry, records) : !records.length\n}\n\n/** Rewrites a same-count decoration batch from the current glyph rects. */\nexport function updateDecorationGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n textGeometry: InstancedBufferGeometry,\n drawable: (key: string) => boolean,\n motionPadding: number,\n): boolean {\n const records = decorationRecords(snapshot, drawable)\n if (!decorationAttributesMatch(geometry, records)) return false\n const run = geometry.getAttribute('sdfRunMotion') as InstancedBufferAttribute | undefined\n const arr = <T extends Float32Array | Uint8Array>(n: string): T =>\n geometry.getAttribute(n).array as T\n const [minZ, maxZ] = writeDecorationBatch(\n records,\n glyphRectTable(textGeometry),\n arr('sdfRect'),\n arr('decorationRect'),\n arr('decorationIndex'),\n arr('sdfColor'),\n arr('sdfClip'),\n arr('sdfMeta'),\n run ? (run.array as Float32Array) : null,\n )\n for (const name of DECORATION_ATTRS) {\n geometry.getAttribute(name).needsUpdate = true\n }\n if (run) run.needsUpdate = true\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return true\n}\n\nexport function createDecorationGeometry(\n snapshot: DomLayoutSnapshot,\n textGeometry: InstancedBufferGeometry,\n drawable: (key: string) => boolean,\n motionPadding: number,\n): InstancedBufferGeometry | null {\n const records = decorationRecords(snapshot, drawable)\n const count = records.length\n if (!count) return null\n const rects = new Float32Array(count * 4)\n const strokes = new Float32Array(count * 4)\n const indices = new Float32Array(count)\n const colors = new Uint8Array(count * 4)\n const clips = new Float32Array(count * 4)\n const metadata = new Float32Array(count * 2)\n const runMotion = records.some((record) => record[7] !== null)\n ? new Float32Array(count * 3)\n : null\n const [minZ, maxZ] = writeDecorationBatch(\n records,\n glyphRectTable(textGeometry),\n rects,\n strokes,\n indices,\n colors,\n clips,\n metadata,\n runMotion,\n )\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced solid text decorations'\n setUnitQuad(geometry)\n const attr = (name: string, a: Float32Array | Uint8Array, n: number, norm = false): void => {\n geometry.setAttribute(name, new InstancedBufferAttribute(a, n, norm))\n }\n attr('sdfRect', rects, 4)\n attr('decorationRect', strokes, 4)\n attr('decorationIndex', indices, 1)\n attr('sdfColor', colors, 4, true)\n attr('sdfClip', clips, 4)\n attr('sdfMeta', metadata, 2)\n if (runMotion) attr('sdfRunMotion', runMotion, 3)\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return geometry\n}\n"],"mappings":";;;;;AAOA,IAAa,kBAAkB;AAC/B,SAAgB,eAAe,UAAsD;CACnF,OACG,SAAS,SAAA,sBACV,SAAS,aAAa,SAAS,CAAC,CAAC;AAErC;;AAGA,IAAa,yBAAb,cAA4C,kBAAkB;CAC5D,YAAY,SAAmC;EAC7C,MACE,UACC,MAAM,MAAM,UAAU,QAAQ,UAAU;GACvC,MAAM,aAAa,UAAkB,kBAAkB,MAAM;GAC7D,IAAI,QAAQ,WAAW,OAAO,OAAO,IAAI,WAAW,IAAI,WAAW,IAAI,IAAI;GAC3E,MAAM,QAAQ,IAAI,WAAW,GAAG,IAAI,KAAK,EAAE,GAAG,WAAW,GAAG,IAAI,KAAK,EAAE,GAAG,IAAI;GAC9E,OAAO,SAAS,IAAI,MAAM,IAAI,KAAK,CAAC;EACtC,GACA,UAAmB,mBAAmB,OAAO,CAC/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AAM,YAAY,QAAQ,MAAM,WAAW,OAAO,OAAO,IAAI,IACzD,IAAI,aAAa,QAAQ,CAAC,IAC1B;CACJ,MAAM,CAAC,MAAM,QAAQ,qBACnB,SACA,eAAe,YAAY,GAC3B,OACA,SACA,SACA,QACA,OACA,UACA,SACF;CACA,MAAM,WAAW,IAAI,wBAAwB;CAC7C,SAAS,OAAO;CAChB,YAAY,QAAQ;CACpB,MAAM,QAAQ,MAAc,GAA8B,GAAW,OAAO,UAAgB;EAC1F,SAAS,aAAa,MAAM,IAAI,yBAAyB,GAAG,GAAG,IAAI,CAAC;CACtE;CACA,KAAK,WAAW,OAAO,CAAC;CACxB,KAAK,kBAAkB,SAAS,CAAC;CACjC,KAAK,mBAAmB,SAAS,CAAC;CAClC,KAAK,YAAY,QAAQ,GAAG,IAAI;CAChC,KAAK,WAAW,OAAO,CAAC;CACxB,KAAK,WAAW,UAAU,CAAC;CAC3B,IAAI,WAAW,KAAK,gBAAgB,WAAW,CAAC;CAChD,SAAS,gBAAgB;CACzB,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,MAAM,IAAI;CAC9E,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"decorations.js","names":[],"sources":["../../src/text/decorations.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { attribute, float, mix } from 'three/tsl'\n\nimport type { DomLayoutSnapshot, TextDecorationLayout } from '../types.js'\nimport { GlyphTextMaterial, type GlyphTextMaterialOptions } from './GlyphTextMaterial.js'\nimport { byte, setBounds, setUnitQuad } from './geometryUtils.js'\n\nexport const GLYPH_RECTS_KEY = 'ultraGlyphRects'\nexport function glyphRectTable(geometry: InstancedBufferGeometry): ArrayLike<number> {\n return (\n (geometry.userData[GLYPH_RECTS_KEY] as Float32Array | undefined) ??\n geometry.getAttribute('sdfRect').array\n )\n}\n\n/** Decoration quads share their source glyph's motion center, index, and clip. */\nexport class TextDecorationMaterial extends GlyphTextMaterial {\n constructor(options: GlyphTextMaterialOptions) {\n super(\n options,\n (quad, rect, position, _depth, scale) => {\n const decoration = attribute<'vec4'>('decorationRect', 'vec4')\n if (options.motion === false) return mix(decoration.xy, decoration.zw, quad)\n const delta = mix(decoration.xy.sub(rect.xy), decoration.zw.sub(rect.zw), quad)\n return position.add(delta.mul(scale))\n },\n attribute<'float'>('decorationIndex', 'float'),\n )\n this.name = 'ultra-text solid text decorations'\n this.applyCoverage(float(1), float(1), float(0.5))\n }\n}\n\nfunction sameDecoration(a: TextDecorationLayout, b: TextDecorationLayout): boolean {\n return (\n a.line === b.line &&\n a.offset === b.offset &&\n a.thickness === b.thickness &&\n a.color.every((v, i) => v === b.color[i])\n )\n}\n\ntype DecorationRecord = readonly [\n s0: number,\n s1: number,\n s2: number,\n s3: number,\n rectIndex: number,\n motionIndex: number,\n color: readonly [number, number, number, number],\n clip: readonly [number, number, number, number],\n sequence: number,\n z: number,\n motionOrigin: readonly [number, number, number] | null,\n]\n\nlet cachedSnapshot: DomLayoutSnapshot | null = null\nlet cachedDrawable: ((key: string) => boolean) | null = null\nlet cachedRecords: readonly DecorationRecord[] = []\n\nfunction decorationRecords(\n snapshot: DomLayoutSnapshot,\n drawable: (key: string) => boolean,\n): readonly DecorationRecord[] {\n if (snapshot === cachedSnapshot && drawable === cachedDrawable) return cachedRecords\n const glyphs = snapshot.glyphs\n const records: DecorationRecord[] = []\n if (glyphs.some((glyph) => glyph.decorations?.length)) {\n let glyphIndex = 0\n let motionIndex = -1\n let previousGroup: number | undefined\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n if (!drawable(glyph.glyphKey)) continue\n if (glyph.shapeGroup === undefined || glyph.shapeGroup !== previousGroup) motionIndex++\n previousGroup = glyph.shapeGroup\n const decorations = glyph.decorations\n if (decorations) {\n for (const decoration of decorations) {\n if (decoration.thickness <= 0 || decoration.color[3] <= 0) continue\n const next = glyphs[index + 1]\n let right = glyph.originX + (glyph.decorationWidth ?? Math.abs(glyph.advance))\n if (\n next?.block === glyph.block &&\n next.lineBottom === glyph.lineBottom &&\n next.decorations?.some((candidate) => sameDecoration(decoration, candidate))\n ) {\n right = Math.max(right, next.originX)\n }\n const y = glyph.lineBottom + decoration.offset\n records.push([\n glyph.originX,\n y - decoration.thickness / 2,\n right,\n y + decoration.thickness / 2,\n glyphIndex,\n glyph.motionOrigin?.[2] ?? motionIndex,\n decoration.color,\n glyph.clip,\n glyph.sequence,\n glyph.z,\n glyph.motionOrigin ?? null,\n ])\n }\n }\n glyphIndex++\n }\n }\n cachedSnapshot = snapshot\n cachedDrawable = drawable\n return (cachedRecords = records)\n}\n\nconst DECORATION_ATTRS = [\n 'sdfRect',\n 'decorationRect',\n 'decorationIndex',\n 'sdfColor',\n 'sdfClip',\n 'sdfMeta',\n] as const\n\nfunction decorationAttributesMatch(\n geometry: InstancedBufferGeometry,\n records: readonly DecorationRecord[],\n): boolean {\n const count = geometry.instanceCount\n if (!count || records.length !== count) return false\n if (\n DECORATION_ATTRS.some(\n (name) => (geometry.getAttribute(name) as { count: number } | undefined)?.count !== count,\n )\n )\n return false\n const run = geometry.getAttribute('sdfRunMotion') as { count: number } | undefined\n return records.some((r) => r[10]) ? run?.count === count : !run\n}\n\nfunction writeDecorationBatch(\n records: readonly DecorationRecord[],\n sourceRects: ArrayLike<number>,\n rects: Float32Array,\n strokes: Float32Array,\n indices: Float32Array,\n colors: Uint8Array,\n clips: Float32Array,\n metadata: Float32Array,\n runMotion: Float32Array | null,\n): [number, number] {\n let minZ = 0\n let maxZ = 0\n for (let index = 0; index < records.length; index++) {\n const rec = records[index]!\n const offset = index * 4\n const srcOffset = rec[4] * 4\n rects[offset] = sourceRects[srcOffset] ?? 0\n rects[offset + 1] = sourceRects[srcOffset + 1] ?? 0\n rects[offset + 2] = sourceRects[srcOffset + 2] ?? 0\n rects[offset + 3] = sourceRects[srcOffset + 3] ?? 0\n const color = rec[6]\n colors[offset] = byte(color[0])\n colors[offset + 1] = byte(color[1])\n colors[offset + 2] = byte(color[2])\n colors[offset + 3] = byte(color[3])\n strokes[offset] = rec[0]\n strokes[offset + 1] = rec[1]\n strokes[offset + 2] = rec[2]\n strokes[offset + 3] = rec[3]\n const clip = rec[7]\n clips[offset] = clip[0]\n clips[offset + 1] = clip[1]\n clips[offset + 2] = clip[2]\n clips[offset + 3] = clip[3]\n indices[index] = rec[5]\n metadata[index * 2] = rec[8]\n const z = rec[9]\n metadata[index * 2 + 1] = z\n const motionOrigin = rec[10]\n if (runMotion && motionOrigin) {\n const mOffset = index * 3\n runMotion[mOffset] = motionOrigin[0]\n runMotion[mOffset + 1] = motionOrigin[1]\n runMotion[mOffset + 2] = motionOrigin[2]\n }\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n return [minZ, maxZ]\n}\n\n/**\n * True when an existing decoration batch can be rewritten without allocating.\n * A null geometry matches only an empty decoration list.\n */\nexport function canUpdateDecorationGeometry(\n geometry: InstancedBufferGeometry | null,\n snapshot: DomLayoutSnapshot,\n drawable: (key: string) => boolean,\n): boolean {\n const records = decorationRecords(snapshot, drawable)\n return geometry ? decorationAttributesMatch(geometry, records) : !records.length\n}\n\n/** Rewrites a same-count decoration batch from the current glyph rects. */\nexport function updateDecorationGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n textGeometry: InstancedBufferGeometry,\n drawable: (key: string) => boolean,\n motionPadding: number,\n): boolean {\n const records = decorationRecords(snapshot, drawable)\n if (!decorationAttributesMatch(geometry, records)) return false\n const run = geometry.getAttribute('sdfRunMotion') as InstancedBufferAttribute | undefined\n const arr = <T extends Float32Array | Uint8Array>(n: string): T =>\n geometry.getAttribute(n).array as T\n const [minZ, maxZ] = writeDecorationBatch(\n records,\n glyphRectTable(textGeometry),\n arr('sdfRect'),\n arr('decorationRect'),\n arr('decorationIndex'),\n arr('sdfColor'),\n arr('sdfClip'),\n arr('sdfMeta'),\n run ? (run.array as Float32Array) : null,\n )\n for (const name of DECORATION_ATTRS) {\n geometry.getAttribute(name).needsUpdate = true\n }\n if (run) run.needsUpdate = true\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return true\n}\n\nexport function createDecorationGeometry(\n snapshot: DomLayoutSnapshot,\n textGeometry: InstancedBufferGeometry,\n drawable: (key: string) => boolean,\n motionPadding: number,\n): InstancedBufferGeometry | null {\n const records = decorationRecords(snapshot, drawable)\n const count = records.length\n if (!count) return null\n const rects = new Float32Array(count * 4)\n const strokes = new Float32Array(count * 4)\n const indices = new Float32Array(count)\n const colors = new Uint8Array(count * 4)\n const clips = new Float32Array(count * 4)\n const metadata = new Float32Array(count * 2)\n const runMotion = records.some((record) => record[10] !== null)\n ? new Float32Array(count * 3)\n : null\n const [minZ, maxZ] = writeDecorationBatch(\n records,\n glyphRectTable(textGeometry),\n rects,\n strokes,\n indices,\n colors,\n clips,\n metadata,\n runMotion,\n )\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced solid text decorations'\n setUnitQuad(geometry)\n const attr = (name: string, a: Float32Array | Uint8Array, n: number, norm = false): void => {\n geometry.setAttribute(name, new InstancedBufferAttribute(a, n, norm))\n }\n attr('sdfRect', rects, 4)\n attr('decorationRect', strokes, 4)\n attr('decorationIndex', indices, 1)\n attr('sdfColor', colors, 4, true)\n attr('sdfClip', clips, 4)\n attr('sdfMeta', metadata, 2)\n if (runMotion) attr('sdfRunMotion', runMotion, 3)\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return geometry\n}\n"],"mappings":";;;;;AAOA,IAAa,kBAAkB;AAC/B,SAAgB,eAAe,UAAsD;CACnF,OACG,SAAS,SAAA,sBACV,SAAS,aAAa,SAAS,CAAC,CAAC;AAErC;;AAGA,IAAa,yBAAb,cAA4C,kBAAkB;CAC5D,YAAY,SAAmC;EAC7C,MACE,UACC,MAAM,MAAM,UAAU,QAAQ,UAAU;GACvC,MAAM,aAAa,UAAkB,kBAAkB,MAAM;GAC7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AAK,YAAY,QAAQ,GAAG,IAAI;CAChC,KAAK,WAAW,OAAO,CAAC;CACxB,KAAK,WAAW,UAAU,CAAC;CAC3B,IAAI,WAAW,KAAK,gBAAgB,WAAW,CAAC;CAChD,SAAS,gBAAgB;CACzB,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,MAAM,IAAI;CAC9E,OAAO;AACT"}
|
package/dist/text/geometry.d.ts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function needsRunMotion(snapshot: DomLayoutSnapshot): boolean;
|
|
5
|
-
export declare function createGlyphGeometry(snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): {
|
|
6
|
-
geometry: InstancedBufferGeometry;
|
|
7
|
-
maxSequence: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function updateGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): number | null;
|
|
10
|
-
export declare function glyphContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionOrdinals?: Float32Array): boolean;
|
|
11
|
-
export declare function updateGlyphContent(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array, checked?: boolean): number | null;
|
|
12
|
-
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
13
|
-
export declare function rectContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
14
|
-
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
15
|
-
export declare function updateRectGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
18
|
-
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
19
|
-
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
20
|
-
* must handle the empty case instead of creating a zero-instance mesh.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createRectGeometry(snapshot: DomLayoutSnapshot, receiveShadow: boolean): InstancedBufferGeometry | null;
|
|
1
|
+
export { needsRunMotion } from './geometryUtils.js';
|
|
2
|
+
export { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry, } from './glyphGeometry.js';
|
|
3
|
+
export { createRectGeometry, rectContentFits, updateRectGeometry } from './rectGeometry.js';
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { type InstancedBufferGeometry } from 'three/webgpu';
|
|
1
|
+
import { type InstancedBufferAttribute, type InstancedBufferGeometry } from 'three/webgpu';
|
|
2
2
|
import type { DomLayoutSnapshot, GlyphLayout } from '../types.js';
|
|
3
|
+
/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */
|
|
4
|
+
export declare function put4(target: Float32Array, offset: number, source: readonly number[]): void;
|
|
5
|
+
export declare const attrOf: <T extends Float32Array | Uint16Array | Uint8Array>(geometry: InstancedBufferGeometry, name: string) => (InstancedBufferAttribute & {
|
|
6
|
+
array: T;
|
|
7
|
+
}) | undefined;
|
|
8
|
+
export declare function instanceAttribute(geometry: InstancedBufferGeometry, name: string, itemSize: number): boolean;
|
|
9
|
+
/** Whether a snapshot needs shared animation centres and drawable ordinals. */
|
|
10
|
+
export declare function needsRunMotion(snapshot: DomLayoutSnapshot): boolean;
|
|
11
|
+
/** Whether any glyph in a snapshot carries inline text decorations. */
|
|
12
|
+
export declare function hasDecorations(snapshot: DomLayoutSnapshot): boolean;
|
|
3
13
|
export declare function setUnitQuad(geometry: InstancedBufferGeometry): void;
|
|
4
14
|
export declare function byte(value: number): number;
|
|
5
15
|
/**
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { Box3, Float32BufferAttribute, Sphere, Uint16BufferAttribute } from "three/webgpu";
|
|
2
2
|
// src/text/geometryUtils.ts
|
|
3
|
+
/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */
|
|
4
|
+
function put4(target, offset, source) {
|
|
5
|
+
target[offset] = source[0];
|
|
6
|
+
target[offset + 1] = source[1];
|
|
7
|
+
target[offset + 2] = source[2];
|
|
8
|
+
target[offset + 3] = source[3];
|
|
9
|
+
}
|
|
10
|
+
var attrOf = (geometry, name) => geometry.getAttribute(name);
|
|
11
|
+
function instanceAttribute(geometry, name, itemSize) {
|
|
12
|
+
const attribute = attrOf(geometry, name);
|
|
13
|
+
return attribute?.itemSize === itemSize && attribute.count === geometry.instanceCount;
|
|
14
|
+
}
|
|
15
|
+
/** Whether a snapshot needs shared animation centres and drawable ordinals. */
|
|
16
|
+
function needsRunMotion(snapshot) {
|
|
17
|
+
return snapshot.textShaping === "browser" || snapshot.glyphs.some((glyph) => glyph.motionOrigin !== void 0);
|
|
18
|
+
}
|
|
19
|
+
/** Whether any glyph in a snapshot carries inline text decorations. */
|
|
20
|
+
function hasDecorations(snapshot) {
|
|
21
|
+
for (const glyph of snapshot.glyphs) if (glyph.decorations && glyph.decorations.length > 0) return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
3
24
|
var UNIT_QUAD_POSITIONS = new Float32Array([
|
|
4
25
|
0,
|
|
5
26
|
0,
|
|
@@ -64,6 +85,6 @@ function setBounds(geometry, width, height, padding, minZ, maxZ) {
|
|
|
64
85
|
box.max.set(width + padding, height + padding, maxZ + padding);
|
|
65
86
|
box.getBoundingSphere(geometry.boundingSphere ??= new Sphere());
|
|
66
87
|
}
|
|
67
|
-
export { byte, metaSize, setBounds, setUnitQuad, writeMeta };
|
|
88
|
+
export { attrOf, byte, hasDecorations, instanceAttribute, metaSize, needsRunMotion, put4, setBounds, setUnitQuad, writeMeta };
|
|
68
89
|
|
|
69
90
|
//# sourceMappingURL=geometryUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometryUtils.js","names":[],"sources":["../../src/text/geometryUtils.ts"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n type InstancedBufferGeometry,\n Sphere,\n Uint16BufferAttribute,\n} from 'three/webgpu'\n\nimport type { DomLayoutSnapshot, GlyphLayout } from '../types.js'\n\nconst UNIT_QUAD_POSITIONS = new Float32Array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0])\nconst UNIT_QUAD_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1])\nconst UNIT_QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3])\n\n// No `uv`: every graph here derives its own texture coordinates from the\n// instanced rect attributes, so the unit quad only needs position and the\n// normal that the lit shadow receiver samples with.\nexport function setUnitQuad(geometry: InstancedBufferGeometry): void {\n geometry.setAttribute('position', new Float32BufferAttribute(UNIT_QUAD_POSITIONS, 3))\n geometry.setAttribute('normal', new Float32BufferAttribute(UNIT_QUAD_NORMALS, 3))\n geometry.setIndex(new Uint16BufferAttribute(UNIT_QUAD_INDICES, 1))\n}\n\nexport function byte(value: number): number {\n return value <= 0 ? 0 : value >= 1 ? 255 : (value * 255 + 0.5) | 0\n}\n\n/**\n * `sdfMeta` gains a third component, the switch em, only on size-switch layouts. A switched\n * layout keeps it even when empty: retained materials read three components, and a pipeline\n * built over a two-wide empty batch would outlive the batch it is later updated with.\n */\nexport function metaSize(snapshot: DomLayoutSnapshot): 2 | 3 {\n return snapshot.sizeSwitched || snapshot.glyphs.some((glyph) => glyph.switchEm !== undefined)\n ? 3\n : 2\n}\n\nexport function writeMeta(\n target: Float32Array,\n index: number,\n size: number,\n glyph: GlyphLayout,\n): void {\n const o = index * size\n target[o] = glyph.sequence\n target[o + 1] = glyph.z\n if (size === 3) target[o + 2] = glyph.switchEm ?? 0\n}\n\nexport function setBounds(\n geometry: InstancedBufferGeometry,\n width: number,\n height: number,\n padding: number,\n minZ: number,\n maxZ: number,\n): void {\n const box = (geometry.boundingBox ??= new Box3())\n box.min.set(-padding, -padding, minZ - padding)\n box.max.set(width + padding, height + padding, maxZ + padding)\n box.getBoundingSphere((geometry.boundingSphere ??= new Sphere()))\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"geometryUtils.js","names":[],"sources":["../../src/text/geometryUtils.ts"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n type InstancedBufferAttribute,\n type InstancedBufferGeometry,\n Sphere,\n Uint16BufferAttribute,\n} from 'three/webgpu'\n\nimport type { DomLayoutSnapshot, GlyphLayout } from '../types.js'\n\n/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */\nexport function put4(target: Float32Array, offset: number, source: readonly number[]): void {\n target[offset] = source[0]!\n target[offset + 1] = source[1]!\n target[offset + 2] = source[2]!\n target[offset + 3] = source[3]!\n}\n\nexport const attrOf = <T extends Float32Array | Uint16Array | Uint8Array>(\n geometry: InstancedBufferGeometry,\n name: string,\n): (InstancedBufferAttribute & { array: T }) | undefined =>\n geometry.getAttribute(name) as (InstancedBufferAttribute & { array: T }) | undefined\n\nexport function instanceAttribute(\n geometry: InstancedBufferGeometry,\n name: string,\n itemSize: number,\n): boolean {\n const attribute = attrOf(geometry, name)\n return attribute?.itemSize === itemSize && attribute.count === geometry.instanceCount\n}\n\n/** Whether a snapshot needs shared animation centres and drawable ordinals. */\nexport function needsRunMotion(snapshot: DomLayoutSnapshot): boolean {\n return (\n snapshot.textShaping === 'browser' ||\n snapshot.glyphs.some((glyph) => glyph.motionOrigin !== undefined)\n )\n}\n\n/** Whether any glyph in a snapshot carries inline text decorations. */\nexport function hasDecorations(snapshot: DomLayoutSnapshot): boolean {\n for (const glyph of snapshot.glyphs) {\n if (glyph.decorations && glyph.decorations.length > 0) return true\n }\n return false\n}\n\nconst UNIT_QUAD_POSITIONS = new Float32Array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0])\nconst UNIT_QUAD_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1])\nconst UNIT_QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3])\n\n// No `uv`: every graph here derives its own texture coordinates from the\n// instanced rect attributes, so the unit quad only needs position and the\n// normal that the lit shadow receiver samples with.\nexport function setUnitQuad(geometry: InstancedBufferGeometry): void {\n geometry.setAttribute('position', new Float32BufferAttribute(UNIT_QUAD_POSITIONS, 3))\n geometry.setAttribute('normal', new Float32BufferAttribute(UNIT_QUAD_NORMALS, 3))\n geometry.setIndex(new Uint16BufferAttribute(UNIT_QUAD_INDICES, 1))\n}\n\nexport function byte(value: number): number {\n return value <= 0 ? 0 : value >= 1 ? 255 : (value * 255 + 0.5) | 0\n}\n\n/**\n * `sdfMeta` gains a third component, the switch em, only on size-switch layouts. A switched\n * layout keeps it even when empty: retained materials read three components, and a pipeline\n * built over a two-wide empty batch would outlive the batch it is later updated with.\n */\nexport function metaSize(snapshot: DomLayoutSnapshot): 2 | 3 {\n return snapshot.sizeSwitched || snapshot.glyphs.some((glyph) => glyph.switchEm !== undefined)\n ? 3\n : 2\n}\n\nexport function writeMeta(\n target: Float32Array,\n index: number,\n size: number,\n glyph: GlyphLayout,\n): void {\n const o = index * size\n target[o] = glyph.sequence\n target[o + 1] = glyph.z\n if (size === 3) target[o + 2] = glyph.switchEm ?? 0\n}\n\nexport function setBounds(\n geometry: InstancedBufferGeometry,\n width: number,\n height: number,\n padding: number,\n minZ: number,\n maxZ: number,\n): void {\n const box = (geometry.boundingBox ??= new Box3())\n box.min.set(-padding, -padding, minZ - padding)\n box.max.set(width + padding, height + padding, maxZ + padding)\n box.getBoundingSphere((geometry.boundingSphere ??= new Sphere()))\n}\n"],"mappings":";;;AAYA,SAAgB,KAAK,QAAsB,QAAgB,QAAiC;CAC1F,OAAO,UAAU,OAAO;CACxB,OAAO,SAAS,KAAK,OAAO;CAC5B,OAAO,SAAS,KAAK,OAAO;CAC5B,OAAO,SAAS,KAAK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QAAQ;CAClB,OAAO,KAAK,MAAM;CAClB,OAAO,IAAI,KAAK,MAAM;CACtB,IAAI,SAAS,GAAG,OAAO,IAAI,KAAK,MAAM,YAAY;AACpD;AAEA,SAAgB,UACd,UACA,OACA,QACA,SACA,MACA,MACM;CACN,MAAM,MAAO,SAAS,gBAAgB,IAAI,KAAK;CAC/C,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,OAAO,OAAO;CAC9C,IAAI,IAAI,IAAI,QAAQ,SAAS,SAAS,SAAS,OAAO,OAAO;CAC7D,IAAI,kBAAmB,SAAS,mBAAmB,IAAI,OAAO,CAAE;AAClE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InstancedBufferGeometry } from 'three/webgpu';
|
|
2
|
+
import type { DomLayoutSnapshot, SdfAtlas } from '../types.js';
|
|
3
|
+
export declare function createGlyphGeometry(snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): {
|
|
4
|
+
geometry: InstancedBufferGeometry;
|
|
5
|
+
maxSequence: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function updateGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): number | null;
|
|
8
|
+
export declare function glyphContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionOrdinals?: Float32Array): boolean;
|
|
9
|
+
export declare function updateGlyphContent(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array, checked?: boolean): number | null;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { attrOf, byte, instanceAttribute, metaSize, needsRunMotion, setBounds, setUnitQuad } from "./geometryUtils.js";
|
|
2
|
+
import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
|
|
3
|
+
// src/text/glyphGeometry.ts
|
|
4
|
+
function shapeOrdinals(snapshot) {
|
|
5
|
+
const glyphs = snapshot.glyphs;
|
|
6
|
+
if (!glyphs.some((glyph) => glyph.shapeGroup !== void 0)) return void 0;
|
|
7
|
+
const out = new Float32Array(glyphs.length);
|
|
8
|
+
let ordinal = -1, previous;
|
|
9
|
+
for (let index = 0; index < glyphs.length; index++) {
|
|
10
|
+
const glyph = glyphs[index];
|
|
11
|
+
if (glyph.shapeGroup === void 0 || glyph.shapeGroup !== previous) ordinal++;
|
|
12
|
+
previous = glyph.shapeGroup;
|
|
13
|
+
out[index] = glyph.motionOrigin?.[2] ?? ordinal;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
var clamp16 = (v) => Math.min(65535, Math.max(0, v));
|
|
18
|
+
function writeDirty4(arr, o, a, b, c, d, dirty, slot) {
|
|
19
|
+
if (arr[o] !== a || arr[o + 1] !== b || arr[o + 2] !== c || arr[o + 3] !== d) {
|
|
20
|
+
arr[o] = a;
|
|
21
|
+
arr[o + 1] = b;
|
|
22
|
+
arr[o + 2] = c;
|
|
23
|
+
arr[o + 3] = d;
|
|
24
|
+
if (dirty[slot + 1] < 0) dirty[slot] = o;
|
|
25
|
+
dirty[slot + 1] = o + 4;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function writeGlyphBatch(snapshot, atlas, rects, clips, metadata, metaItemSize, runMotion, motionOrdinals, uvRects, trims, colors, maxCount = Infinity, dirty) {
|
|
29
|
+
const glyphs = snapshot.glyphs;
|
|
30
|
+
const total = glyphs.length;
|
|
31
|
+
const shaped = snapshot.textShaping === "browser";
|
|
32
|
+
const invBakeSize = 1 / atlas.bakeSize;
|
|
33
|
+
const atlasGlyphs = atlas.glyphs;
|
|
34
|
+
const packUvs = uvRects !== void 0 && colors !== void 0;
|
|
35
|
+
const hasTrims = trims !== void 0 && trims !== null;
|
|
36
|
+
let count = 0;
|
|
37
|
+
let maxSequence = 0;
|
|
38
|
+
let minZ = 0;
|
|
39
|
+
let maxZ = 0;
|
|
40
|
+
let prevKey;
|
|
41
|
+
let prevSlot;
|
|
42
|
+
let prevUvSlot;
|
|
43
|
+
let pu0 = 0;
|
|
44
|
+
let pv1 = 0;
|
|
45
|
+
let pu1 = 0;
|
|
46
|
+
let pv0 = 0;
|
|
47
|
+
let pt0 = 0;
|
|
48
|
+
let pt1 = 0;
|
|
49
|
+
let pt2 = 0;
|
|
50
|
+
let pt3 = 0;
|
|
51
|
+
let prevColor;
|
|
52
|
+
let c0 = 0;
|
|
53
|
+
let c1 = 0;
|
|
54
|
+
let c2 = 0;
|
|
55
|
+
let c3 = 0;
|
|
56
|
+
let prevClip;
|
|
57
|
+
let fc0 = 0;
|
|
58
|
+
let fc1 = 0;
|
|
59
|
+
let fc2 = 0;
|
|
60
|
+
let fc3 = 0;
|
|
61
|
+
if (dirty) for (let i = 0; i < 14; i += 2) {
|
|
62
|
+
dirty[i] = 0;
|
|
63
|
+
dirty[i + 1] = -1;
|
|
64
|
+
}
|
|
65
|
+
for (let ordinal = 0; ordinal < total; ordinal++) {
|
|
66
|
+
const glyph = glyphs[ordinal];
|
|
67
|
+
const gKey = glyph.glyphKey;
|
|
68
|
+
const slot = gKey === prevKey ? prevSlot : (prevKey = gKey, prevSlot = atlasGlyphs.get(gKey));
|
|
69
|
+
if (!slot) continue;
|
|
70
|
+
if (count >= maxCount) return [
|
|
71
|
+
-1,
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
const index = count++;
|
|
77
|
+
const offset = index * 4;
|
|
78
|
+
const scale = glyph.fontSize * invBakeSize;
|
|
79
|
+
const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale;
|
|
80
|
+
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale);
|
|
81
|
+
const rawR0 = glyph.originX + slot.planeX0 * scaleX;
|
|
82
|
+
const rawR1 = baseline + slot.planeY0 * scale;
|
|
83
|
+
const rawR2 = glyph.originX + slot.planeX1 * scaleX;
|
|
84
|
+
const rawR3 = baseline + slot.planeY1 * scale;
|
|
85
|
+
if (dirty) writeDirty4(rects, offset, Math.fround(rawR0), Math.fround(rawR1), Math.fround(rawR2), Math.fround(rawR3), dirty, 0);
|
|
86
|
+
else {
|
|
87
|
+
rects[offset] = rawR0;
|
|
88
|
+
rects[offset + 1] = rawR1;
|
|
89
|
+
rects[offset + 2] = rawR2;
|
|
90
|
+
rects[offset + 3] = rawR3;
|
|
91
|
+
}
|
|
92
|
+
const clip = glyph.clip;
|
|
93
|
+
if (clip !== prevClip) {
|
|
94
|
+
prevClip = clip;
|
|
95
|
+
fc0 = dirty ? Math.fround(clip[0]) : clip[0];
|
|
96
|
+
fc1 = dirty ? Math.fround(clip[1]) : clip[1];
|
|
97
|
+
fc2 = dirty ? Math.fround(clip[2]) : clip[2];
|
|
98
|
+
fc3 = dirty ? Math.fround(clip[3]) : clip[3];
|
|
99
|
+
}
|
|
100
|
+
if (dirty) writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2);
|
|
101
|
+
else {
|
|
102
|
+
clips[offset] = fc0;
|
|
103
|
+
clips[offset + 1] = fc1;
|
|
104
|
+
clips[offset + 2] = fc2;
|
|
105
|
+
clips[offset + 3] = fc3;
|
|
106
|
+
}
|
|
107
|
+
const mOff = index * metaItemSize;
|
|
108
|
+
if (packUvs) {
|
|
109
|
+
if (slot !== prevUvSlot) {
|
|
110
|
+
prevUvSlot = slot;
|
|
111
|
+
pu0 = slot.u0 * 65535 + .5 | 0;
|
|
112
|
+
pv1 = slot.v1 * 65535 + .5 | 0;
|
|
113
|
+
pu1 = slot.u1 * 65535 + .5 | 0;
|
|
114
|
+
pv0 = slot.v0 * 65535 + .5 | 0;
|
|
115
|
+
const s = hasTrims ? slot.support : void 0;
|
|
116
|
+
pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0;
|
|
117
|
+
pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1;
|
|
118
|
+
pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1;
|
|
119
|
+
pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0;
|
|
120
|
+
}
|
|
121
|
+
const color = glyph.color;
|
|
122
|
+
if (color !== prevColor) {
|
|
123
|
+
prevColor = color;
|
|
124
|
+
c0 = byte(color[0]);
|
|
125
|
+
c1 = byte(color[1]);
|
|
126
|
+
c2 = byte(color[2]);
|
|
127
|
+
c3 = byte(color[3]);
|
|
128
|
+
}
|
|
129
|
+
if (dirty) {
|
|
130
|
+
writeDirty4(uvRects, offset, pu0, pv1, pu1, pv0, dirty, 6);
|
|
131
|
+
if (hasTrims) writeDirty4(trims, offset, pt0, pt1, pt2, pt3, dirty, 10);
|
|
132
|
+
writeDirty4(colors, offset, c0, c1, c2, c3, dirty, 8);
|
|
133
|
+
const m0 = Math.fround(glyph.sequence);
|
|
134
|
+
const m1 = Math.fround(glyph.z);
|
|
135
|
+
const m2 = metaItemSize === 3 ? Math.fround(glyph.switchEm ?? 0) : 0;
|
|
136
|
+
if (metadata[mOff] !== m0 || metadata[mOff + 1] !== m1 || metaItemSize === 3 && metadata[mOff + 2] !== m2) {
|
|
137
|
+
metadata[mOff] = m0;
|
|
138
|
+
metadata[mOff + 1] = m1;
|
|
139
|
+
if (metaItemSize === 3) metadata[mOff + 2] = m2;
|
|
140
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
141
|
+
dirty[5] = mOff + metaItemSize;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
uvRects[offset] = pu0;
|
|
145
|
+
uvRects[offset + 1] = pv1;
|
|
146
|
+
uvRects[offset + 2] = pu1;
|
|
147
|
+
uvRects[offset + 3] = pv0;
|
|
148
|
+
if (hasTrims) {
|
|
149
|
+
trims[offset] = pt0;
|
|
150
|
+
trims[offset + 1] = pt1;
|
|
151
|
+
trims[offset + 2] = pt2;
|
|
152
|
+
trims[offset + 3] = pt3;
|
|
153
|
+
}
|
|
154
|
+
colors[offset] = c0;
|
|
155
|
+
colors[offset + 1] = c1;
|
|
156
|
+
colors[offset + 2] = c2;
|
|
157
|
+
colors[offset + 3] = c3;
|
|
158
|
+
metadata[mOff] = glyph.sequence;
|
|
159
|
+
metadata[mOff + 1] = glyph.z;
|
|
160
|
+
if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0;
|
|
161
|
+
}
|
|
162
|
+
} else if (dirty) {
|
|
163
|
+
const m0 = Math.fround(glyph.sequence);
|
|
164
|
+
if (metadata[mOff] !== m0) {
|
|
165
|
+
metadata[mOff] = m0;
|
|
166
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
167
|
+
dirty[5] = mOff + 1;
|
|
168
|
+
}
|
|
169
|
+
} else metadata[mOff] = glyph.sequence;
|
|
170
|
+
if (runMotion) {
|
|
171
|
+
const rOff = index * 3;
|
|
172
|
+
const origin = glyph.motionOrigin;
|
|
173
|
+
if (dirty) {
|
|
174
|
+
const rx = Math.fround(origin ? origin[0] : (rects[offset] + rects[offset + 2]) * .5);
|
|
175
|
+
const ry = Math.fround(origin ? origin[1] : (rects[offset + 1] + rects[offset + 3]) * .5);
|
|
176
|
+
const rz = Math.fround(origin ? origin[2] : motionOrdinals?.[ordinal] ?? ordinal);
|
|
177
|
+
if (runMotion[rOff] !== rx || runMotion[rOff + 1] !== ry || runMotion[rOff + 2] !== rz) {
|
|
178
|
+
runMotion[rOff] = rx;
|
|
179
|
+
runMotion[rOff + 1] = ry;
|
|
180
|
+
runMotion[rOff + 2] = rz;
|
|
181
|
+
if (dirty[13] < 0) dirty[12] = rOff;
|
|
182
|
+
dirty[13] = rOff + 3;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
runMotion[rOff] = origin ? origin[0] : (rects[offset] + rects[offset + 2]) * .5;
|
|
186
|
+
runMotion[rOff + 1] = origin ? origin[1] : (rects[offset + 1] + rects[offset + 3]) * .5;
|
|
187
|
+
runMotion[rOff + 2] = origin ? origin[2] : motionOrdinals?.[ordinal] ?? ordinal;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
191
|
+
if (glyph.z < minZ) minZ = glyph.z;
|
|
192
|
+
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
193
|
+
}
|
|
194
|
+
return [
|
|
195
|
+
count,
|
|
196
|
+
maxSequence,
|
|
197
|
+
minZ,
|
|
198
|
+
maxZ
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
var dirtyBounds = /* @__PURE__ */ new Int32Array(14);
|
|
202
|
+
function flushAttributeUpdate(attribute, dirtyStart, dirtyEnd) {
|
|
203
|
+
if (!attribute) return;
|
|
204
|
+
if (attribute.version === 0) {
|
|
205
|
+
attribute.needsUpdate = true;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (dirtyEnd <= dirtyStart) return;
|
|
209
|
+
let start = dirtyStart;
|
|
210
|
+
let end = dirtyEnd;
|
|
211
|
+
for (const range of attribute.updateRanges) {
|
|
212
|
+
if (range.count < 0) {
|
|
213
|
+
start = 0;
|
|
214
|
+
end = attribute.array.length;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (range.start < start) start = range.start;
|
|
218
|
+
const rangeEnd = range.start + range.count;
|
|
219
|
+
if (rangeEnd > end) end = rangeEnd;
|
|
220
|
+
}
|
|
221
|
+
attribute.clearUpdateRanges();
|
|
222
|
+
attribute.addUpdateRange(start, end - start);
|
|
223
|
+
attribute.needsUpdate = true;
|
|
224
|
+
}
|
|
225
|
+
function createGlyphGeometry(snapshot, atlas, motionPadding, motionOrdinals) {
|
|
226
|
+
const hasRunMotion = needsRunMotion(snapshot);
|
|
227
|
+
motionOrdinals ??= hasRunMotion ? shapeOrdinals(snapshot) : void 0;
|
|
228
|
+
const total = snapshot.glyphs.length;
|
|
229
|
+
const rects = new Float32Array(total * 4);
|
|
230
|
+
const uvRects = new Uint16Array(total * 4);
|
|
231
|
+
const clips = new Float32Array(total * 4);
|
|
232
|
+
const colors = new Uint8Array(total * 4);
|
|
233
|
+
const meta = metaSize(snapshot);
|
|
234
|
+
const metadata = new Float32Array(total * meta);
|
|
235
|
+
const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null;
|
|
236
|
+
const trims = runMotion ? null : new Uint16Array(total * 4);
|
|
237
|
+
const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(snapshot, atlas, rects, clips, metadata, meta, runMotion, motionOrdinals, uvRects, trims, colors);
|
|
238
|
+
const geometry = new InstancedBufferGeometry();
|
|
239
|
+
geometry.name = "ultra-text instanced glyph quads";
|
|
240
|
+
setUnitQuad(geometry);
|
|
241
|
+
for (const [name, array, size, normalized] of [
|
|
242
|
+
[
|
|
243
|
+
"sdfRect",
|
|
244
|
+
rects,
|
|
245
|
+
4,
|
|
246
|
+
false
|
|
247
|
+
],
|
|
248
|
+
[
|
|
249
|
+
"sdfUvRect",
|
|
250
|
+
uvRects,
|
|
251
|
+
4,
|
|
252
|
+
true
|
|
253
|
+
],
|
|
254
|
+
[
|
|
255
|
+
"sdfClip",
|
|
256
|
+
clips,
|
|
257
|
+
4,
|
|
258
|
+
false
|
|
259
|
+
],
|
|
260
|
+
[
|
|
261
|
+
"sdfColor",
|
|
262
|
+
colors,
|
|
263
|
+
4,
|
|
264
|
+
true
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"sdfMeta",
|
|
268
|
+
metadata,
|
|
269
|
+
meta,
|
|
270
|
+
false
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
"sdfRunMotion",
|
|
274
|
+
runMotion,
|
|
275
|
+
3,
|
|
276
|
+
false
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
"sdfTrim",
|
|
280
|
+
trims,
|
|
281
|
+
4,
|
|
282
|
+
true
|
|
283
|
+
]
|
|
284
|
+
]) if (array) geometry.setAttribute(name, new InstancedBufferAttribute(count === total ? array : array.subarray(0, count * size), size, normalized));
|
|
285
|
+
geometry.instanceCount = count;
|
|
286
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
287
|
+
return {
|
|
288
|
+
geometry,
|
|
289
|
+
maxSequence
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function updateGlyphGeometry(geometry, snapshot, atlas, motionPadding, motionOrdinals) {
|
|
293
|
+
const instanceCount = geometry.instanceCount;
|
|
294
|
+
if (snapshot.glyphs.length < instanceCount) return null;
|
|
295
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
296
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
297
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
298
|
+
if (!rectAttribute || !clipAttribute || !metaAttribute) return null;
|
|
299
|
+
motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : void 0;
|
|
300
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
301
|
+
const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(snapshot, atlas, rectAttribute.array, clipAttribute.array, metaAttribute.array, metaAttribute.itemSize, runAttribute ? runAttribute.array : null, motionOrdinals, void 0, void 0, void 0, instanceCount, dirtyBounds);
|
|
302
|
+
if (count !== instanceCount) return null;
|
|
303
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
304
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
305
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
306
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
307
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
308
|
+
return maxSequence;
|
|
309
|
+
}
|
|
310
|
+
function drawableGlyphCountMatches(snapshot, atlas, expectedCount) {
|
|
311
|
+
let count = 0;
|
|
312
|
+
for (const glyph of snapshot.glyphs) if (atlas.glyphs.has(glyph.glyphKey) && ++count > expectedCount) return false;
|
|
313
|
+
return count === expectedCount;
|
|
314
|
+
}
|
|
315
|
+
function glyphContentFits(geometry, snapshot, atlas, motionOrdinals) {
|
|
316
|
+
const instanceCount = geometry.instanceCount;
|
|
317
|
+
if (snapshot.glyphs.length < instanceCount) return false;
|
|
318
|
+
for (const name of [
|
|
319
|
+
"sdfRect",
|
|
320
|
+
"sdfUvRect",
|
|
321
|
+
"sdfClip",
|
|
322
|
+
"sdfColor"
|
|
323
|
+
]) if (!instanceAttribute(geometry, name, 4)) return false;
|
|
324
|
+
if (!instanceAttribute(geometry, "sdfMeta", metaSize(snapshot))) return false;
|
|
325
|
+
const run = attrOf(geometry, "sdfRunMotion");
|
|
326
|
+
const wantsRun = needsRunMotion(snapshot) || !!motionOrdinals;
|
|
327
|
+
const trim = attrOf(geometry, "sdfTrim");
|
|
328
|
+
return (wantsRun ? run?.itemSize === 3 && run.count === instanceCount && trim === void 0 : run === void 0 && (trim === void 0 || instanceAttribute(geometry, "sdfTrim", 4))) && drawableGlyphCountMatches(snapshot, atlas, instanceCount);
|
|
329
|
+
}
|
|
330
|
+
function updateGlyphContent(geometry, snapshot, atlas, motionPadding, motionOrdinals, checked) {
|
|
331
|
+
motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : void 0;
|
|
332
|
+
if (!checked && !glyphContentFits(geometry, snapshot, atlas, motionOrdinals)) return null;
|
|
333
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
334
|
+
const uvAttribute = attrOf(geometry, "sdfUvRect");
|
|
335
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
336
|
+
const colorAttribute = attrOf(geometry, "sdfColor");
|
|
337
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
338
|
+
const trimAttribute = attrOf(geometry, "sdfTrim");
|
|
339
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
340
|
+
const [, maxSequence, minZ, maxZ] = writeGlyphBatch(snapshot, atlas, rectAttribute.array, clipAttribute.array, metaAttribute.array, metaAttribute.itemSize, runAttribute ? runAttribute.array : null, motionOrdinals, uvAttribute.array, trimAttribute ? trimAttribute.array : null, colorAttribute.array, Infinity, dirtyBounds);
|
|
341
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
342
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
343
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
344
|
+
flushAttributeUpdate(uvAttribute, dirtyBounds[6], dirtyBounds[7]);
|
|
345
|
+
flushAttributeUpdate(colorAttribute, dirtyBounds[8], dirtyBounds[9]);
|
|
346
|
+
flushAttributeUpdate(trimAttribute, dirtyBounds[10], dirtyBounds[11]);
|
|
347
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
348
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
349
|
+
return maxSequence;
|
|
350
|
+
}
|
|
351
|
+
export { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry };
|
|
352
|
+
|
|
353
|
+
//# sourceMappingURL=glyphGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glyphGeometry.js","names":[],"sources":["../../src/text/glyphGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport {\n attrOf,\n byte,\n instanceAttribute,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n} from './geometryUtils.js'\n\nimport type { DomLayoutSnapshot, GlyphLayout, GlyphSlot, SdfAtlas } from '../types.js'\n\nfunction shapeOrdinals(snapshot: DomLayoutSnapshot): Float32Array | undefined {\n const glyphs = snapshot.glyphs\n if (!glyphs.some((glyph) => glyph.shapeGroup !== undefined)) return undefined\n const out = new Float32Array(glyphs.length)\n let ordinal = -1,\n previous: number | undefined\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n if (glyph.shapeGroup === undefined || glyph.shapeGroup !== previous) ordinal++\n previous = glyph.shapeGroup\n out[index] = glyph.motionOrigin?.[2] ?? ordinal\n }\n return out\n}\n\nconst clamp16 = (v: number): number => Math.min(65535, Math.max(0, v))\n\nfunction writeDirty4(\n arr: Float32Array | Uint16Array | Uint8Array,\n o: number,\n a: number,\n b: number,\n c: number,\n d: number,\n dirty: Int32Array,\n slot: number,\n): void {\n if (arr[o] !== a || arr[o + 1] !== b || arr[o + 2] !== c || arr[o + 3] !== d) {\n arr[o] = a\n arr[o + 1] = b\n arr[o + 2] = c\n arr[o + 3] = d\n if (dirty[slot + 1]! < 0) dirty[slot] = o\n dirty[slot + 1] = o + 4\n }\n}\n\nfunction writeGlyphBatch(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n rects: Float32Array,\n clips: Float32Array,\n metadata: Float32Array,\n metaItemSize: number,\n runMotion: Float32Array | null,\n motionOrdinals: Float32Array | undefined,\n uvRects?: Uint16Array,\n trims?: Uint16Array | null,\n colors?: Uint8Array,\n maxCount = Infinity,\n dirty?: Int32Array,\n): [number, number, number, number] {\n const glyphs = snapshot.glyphs\n const total = glyphs.length\n const shaped = snapshot.textShaping === 'browser'\n const invBakeSize = 1 / atlas.bakeSize\n const atlasGlyphs = atlas.glyphs\n const packUvs = uvRects !== undefined && colors !== undefined\n const hasTrims = trims !== undefined && trims !== null\n let count = 0\n let maxSequence = 0\n let minZ = 0\n let maxZ = 0\n let prevKey: string | undefined\n let prevSlot: GlyphSlot | undefined\n let prevUvSlot: GlyphSlot | undefined\n let pu0 = 0\n let pv1 = 0\n let pu1 = 0\n let pv0 = 0\n let pt0 = 0\n let pt1 = 0\n let pt2 = 0\n let pt3 = 0\n let prevColor: GlyphLayout['color'] | undefined\n let c0 = 0\n let c1 = 0\n let c2 = 0\n let c3 = 0\n let prevClip: GlyphLayout['clip'] | undefined\n let fc0 = 0\n let fc1 = 0\n let fc2 = 0\n let fc3 = 0\n if (dirty) {\n for (let i = 0; i < 14; i += 2) {\n dirty[i] = 0\n dirty[i + 1] = -1\n }\n }\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) continue\n if (count >= maxCount) return [-1, 0, 0, 0]\n const index = count++\n const offset = index * 4\n\n const scale = glyph.fontSize * invBakeSize\n const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale\n // Range.getBoundingClientRect() reports the text box, not the line box, so\n // lineBottom already sits on the descender line: adding half the CSS\n // leading back on top of it lifted every glyph off its baseline.\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale)\n const rawR0 = glyph.originX + slot.planeX0 * scaleX\n const rawR1 = baseline + slot.planeY0 * scale\n const rawR2 = glyph.originX + slot.planeX1 * scaleX\n const rawR3 = baseline + slot.planeY1 * scale\n if (dirty) {\n writeDirty4(\n rects,\n offset,\n Math.fround(rawR0),\n Math.fround(rawR1),\n Math.fround(rawR2),\n Math.fround(rawR3),\n dirty,\n 0,\n )\n } else {\n rects[offset] = rawR0\n rects[offset + 1] = rawR1\n rects[offset + 2] = rawR2\n rects[offset + 3] = rawR3\n }\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = dirty ? Math.fround(clip[0]) : clip[0]\n fc1 = dirty ? Math.fround(clip[1]) : clip[1]\n fc2 = dirty ? Math.fround(clip[2]) : clip[2]\n fc3 = dirty ? Math.fround(clip[3]) : clip[3]\n }\n if (dirty) {\n writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2)\n } else {\n clips[offset] = fc0\n clips[offset + 1] = fc1\n clips[offset + 2] = fc2\n clips[offset + 3] = fc3\n }\n\n const mOff = index * metaItemSize\n if (packUvs) {\n if (slot !== prevUvSlot) {\n prevUvSlot = slot\n pu0 = (slot.u0 * 65535 + 0.5) | 0\n pv1 = (slot.v1 * 65535 + 0.5) | 0\n pu1 = (slot.u1 * 65535 + 0.5) | 0\n pv0 = (slot.v0 * 65535 + 0.5) | 0\n const s = hasTrims ? slot.support : undefined\n pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0\n pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1\n pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1\n pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0\n }\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n c0 = byte(color[0])\n c1 = byte(color[1])\n c2 = byte(color[2])\n c3 = byte(color[3])\n }\n if (dirty) {\n writeDirty4(uvRects, offset, pu0, pv1, pu1, pv0, dirty, 6)\n if (hasTrims) writeDirty4(trims, offset, pt0, pt1, pt2, pt3, dirty, 10)\n writeDirty4(colors, offset, c0, c1, c2, c3, dirty, 8)\n const m0 = Math.fround(glyph.sequence)\n const m1 = Math.fround(glyph.z)\n const m2 = metaItemSize === 3 ? Math.fround(glyph.switchEm ?? 0) : 0\n if (\n metadata[mOff] !== m0 ||\n metadata[mOff + 1] !== m1 ||\n (metaItemSize === 3 && metadata[mOff + 2] !== m2)\n ) {\n metadata[mOff] = m0\n metadata[mOff + 1] = m1\n if (metaItemSize === 3) metadata[mOff + 2] = m2\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + metaItemSize\n }\n } else {\n uvRects[offset] = pu0\n uvRects[offset + 1] = pv1\n uvRects[offset + 2] = pu1\n uvRects[offset + 3] = pv0\n if (hasTrims) {\n trims[offset] = pt0\n trims[offset + 1] = pt1\n trims[offset + 2] = pt2\n trims[offset + 3] = pt3\n }\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n metadata[mOff] = glyph.sequence\n metadata[mOff + 1] = glyph.z\n if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0\n }\n } else if (dirty) {\n const m0 = Math.fround(glyph.sequence)\n if (metadata[mOff] !== m0) {\n metadata[mOff] = m0\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + 1\n }\n } else {\n metadata[mOff] = glyph.sequence\n }\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n if (dirty) {\n const rx = Math.fround(origin ? origin[0] : (rects[offset]! + rects[offset + 2]!) * 0.5)\n const ry = Math.fround(origin ? origin[1] : (rects[offset + 1]! + rects[offset + 3]!) * 0.5)\n const rz = Math.fround(origin ? origin[2] : (motionOrdinals?.[ordinal] ?? ordinal))\n if (runMotion[rOff] !== rx || runMotion[rOff + 1] !== ry || runMotion[rOff + 2] !== rz) {\n runMotion[rOff] = rx\n runMotion[rOff + 1] = ry\n runMotion[rOff + 2] = rz\n if (dirty[13]! < 0) dirty[12] = rOff\n dirty[13] = rOff + 3\n }\n } else {\n runMotion[rOff] = origin ? origin[0] : (rects[offset]! + rects[offset + 2]!) * 0.5\n runMotion[rOff + 1] = origin ? origin[1] : (rects[offset + 1]! + rects[offset + 3]!) * 0.5\n runMotion[rOff + 2] = origin ? origin[2] : (motionOrdinals?.[ordinal] ?? ordinal)\n }\n }\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return [count, maxSequence, minZ, maxZ]\n}\n\nconst dirtyBounds = new Int32Array(14)\n\nfunction flushAttributeUpdate(\n attribute: InstancedBufferAttribute | undefined,\n dirtyStart: number,\n dirtyEnd: number,\n): void {\n if (!attribute) return\n if (attribute.version === 0) {\n attribute.needsUpdate = true\n return\n }\n if (dirtyEnd <= dirtyStart) return\n let start = dirtyStart\n let end = dirtyEnd\n for (const range of attribute.updateRanges) {\n if (range.count < 0) {\n start = 0\n end = attribute.array.length\n break\n }\n if (range.start < start) start = range.start\n const rangeEnd = range.start + range.count\n if (rangeEnd > end) end = rangeEnd\n }\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(start, end - start)\n attribute.needsUpdate = true\n}\n\nexport function createGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const hasRunMotion = needsRunMotion(snapshot)\n motionOrdinals ??= hasRunMotion ? shapeOrdinals(snapshot) : undefined\n const total = snapshot.glyphs.length\n const rects = new Float32Array(total * 4)\n const uvRects = new Uint16Array(total * 4)\n const clips = new Float32Array(total * 4)\n const colors = new Uint8Array(total * 4)\n const meta = metaSize(snapshot)\n const metadata = new Float32Array(total * meta)\n const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null\n const trims = runMotion ? null : new Uint16Array(total * 4)\n const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(\n snapshot,\n atlas,\n rects,\n clips,\n metadata,\n meta,\n runMotion,\n motionOrdinals,\n uvRects,\n trims,\n colors,\n )\n\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced glyph quads'\n setUnitQuad(geometry)\n for (const [name, array, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfUvRect', uvRects, 4, true],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['sdfRunMotion', runMotion, 3, false],\n ['sdfTrim', trims, 4, true],\n ] as const) {\n if (array)\n geometry.setAttribute(\n name,\n new InstancedBufferAttribute(\n count === total ? array : array.subarray(0, count * size),\n size,\n normalized,\n ),\n )\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return { geometry, maxSequence }\n}\n\nexport function updateGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n): number | null {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return null\n const rectAttribute = attrOf<Float32Array>(geometry, 'sdfRect')\n const clipAttribute = attrOf<Float32Array>(geometry, 'sdfClip')\n const metaAttribute = attrOf<Float32Array>(geometry, 'sdfMeta')\n if (!rectAttribute || !clipAttribute || !metaAttribute) return null\n motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : undefined\n const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(\n snapshot,\n atlas,\n rectAttribute.array,\n clipAttribute.array,\n metaAttribute.array,\n metaAttribute.itemSize,\n runAttribute ? runAttribute.array : null,\n motionOrdinals,\n undefined,\n undefined,\n undefined,\n instanceCount,\n dirtyBounds,\n )\n if (count !== instanceCount) return null\n\n flushAttributeUpdate(rectAttribute, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(clipAttribute, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(metaAttribute, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(runAttribute, dirtyBounds[12]!, dirtyBounds[13]!)\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return maxSequence\n}\n\nfunction drawableGlyphCountMatches(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n expectedCount: number,\n): boolean {\n let count = 0\n for (const glyph of snapshot.glyphs) {\n if (atlas.glyphs.has(glyph.glyphKey) && ++count > expectedCount) return false\n }\n return count === expectedCount\n}\n\nexport function glyphContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionOrdinals?: Float32Array,\n): boolean {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return false\n for (const name of ['sdfRect', 'sdfUvRect', 'sdfClip', 'sdfColor']) {\n if (!instanceAttribute(geometry, name, 4)) return false\n }\n if (!instanceAttribute(geometry, 'sdfMeta', metaSize(snapshot))) return false\n const run = attrOf(geometry, 'sdfRunMotion')\n const wantsRun = needsRunMotion(snapshot) || !!motionOrdinals\n const trim = attrOf(geometry, 'sdfTrim')\n const layoutFits = wantsRun\n ? run?.itemSize === 3 && run.count === instanceCount && trim === undefined\n : run === undefined && (trim === undefined || instanceAttribute(geometry, 'sdfTrim', 4))\n return layoutFits && drawableGlyphCountMatches(snapshot, atlas, instanceCount)\n}\n\nexport function updateGlyphContent(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n checked?: boolean,\n): number | null {\n motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : undefined\n if (!checked && !glyphContentFits(geometry, snapshot, atlas, motionOrdinals)) return null\n const rectAttribute = attrOf<Float32Array>(geometry, 'sdfRect')!\n const uvAttribute = attrOf<Uint16Array>(geometry, 'sdfUvRect')!\n const clipAttribute = attrOf<Float32Array>(geometry, 'sdfClip')!\n const colorAttribute = attrOf<Uint8Array>(geometry, 'sdfColor')!\n const metaAttribute = attrOf<Float32Array>(geometry, 'sdfMeta')!\n const trimAttribute = attrOf<Uint16Array>(geometry, 'sdfTrim')\n const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n const [, maxSequence, minZ, maxZ] = writeGlyphBatch(\n snapshot,\n atlas,\n rectAttribute.array,\n clipAttribute.array,\n metaAttribute.array,\n metaAttribute.itemSize,\n runAttribute ? runAttribute.array : null,\n motionOrdinals,\n uvAttribute.array,\n trimAttribute ? trimAttribute.array : null,\n colorAttribute.array,\n Infinity,\n dirtyBounds,\n )\n flushAttributeUpdate(rectAttribute, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(clipAttribute, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(metaAttribute, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(uvAttribute, dirtyBounds[6]!, dirtyBounds[7]!)\n flushAttributeUpdate(colorAttribute, dirtyBounds[8]!, dirtyBounds[9]!)\n flushAttributeUpdate(trimAttribute, dirtyBounds[10]!, dirtyBounds[11]!)\n flushAttributeUpdate(runAttribute, dirtyBounds[12]!, dirtyBounds[13]!)\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return maxSequence\n}\n"],"mappings":";;;AAaA,SAAS,cAAc,UAAuD;CAC5E,MAAM,SAAS,SAAS;CACxB,IAAI,CAAC,OAAO,MAAM,UAAU,MAAM,eAAe,KAAA,CAAS,GAAG,OAAO,KAAA;CACpE,MAAM,MAAM,IAAI,aAAa,OAAO,MAAM;CAC1C,IAAI,UAAU,IACZ;CACF,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EAClD,MAAM,QAAQ,OAAO;EACrB,IAAI,MAAM,eAAe,KAAA,KAAa,MAAM,eAAe,UAAU;EACrE,WAAW,MAAM;EACjB,IAAI,SAAS,MAAM,eAAe,MAAM;CAC1C;CACA,OAAO;AACT;AAEA,IAAM,WAAW,MAAsB,KAAK,IAAI,OAAO,KAAK,IAAI,GAAG,CAAC,CAAC;AAErE,SAAS,YACP,KACA,GACA,GACA,GACA,GACA,GACA,OACA,MACM;CACN,IAAI,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,GAAG;EAC5E,IAAI,KAAK;EACT,IAAI,IAAI,KAAK;EACb,IAAI,IAAI,KAAK;EACb,IAAI,IAAI,KAAK;EACb,IAAI,MAAM,OAAO,KAAM,GAAG,MAAM,QAAQ;EACxC,MAAM,OAAO,KAAK,IAAI;CACxB;AACF;AAEA,SAAS,gBACP,UACA,OACA,OACA,OACA,UACA,cACA,WACA,gBACA,SACA,OACA,QACA,WAAW,UACX,OACkC;CAClC,MAAM,SAAS,SAAS;CACxB,MAAM,QAAQ,OAA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M,cAAc,OAAoB,UAAU,WAAW;CAC7D,MAAM,gBAAgB,OAAqB,UAAU,SAAS;CAC9D,MAAM,iBAAiB,OAAmB,UAAU,UAAU;CAC9D,MAAM,gBAAgB,OAAqB,UAAU,SAAS;CAC9D,MAAM,gBAAgB,OAAoB,UAAU,SAAS;CAC7D,MAAM,eAAe,OAAqB,UAAU,cAAc;CAClE,MAAM,GAAG,aAAa,MAAM,QAAQ,gBAClC,UACA,OACA,cAAc,OACd,cAAc,OACd,cAAc,OACd,cAAc,UACd,eAAe,aAAa,QAAQ,MACpC,gBACA,YAAY,OACZ,gBAAgB,cAAc,QAAQ,MACtC,eAAe,OACf,UACA,WACF;CACA,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;CACpE,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;CACpE,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;CACpE,qBAAqB,aAAa,YAAY,IAAK,YAAY,EAAG;CAClE,qBAAqB,gBAAgB,YAAY,IAAK,YAAY,EAAG;CACrE,qBAAqB,eAAe,YAAY,KAAM,YAAY,GAAI;CACtE,qBAAqB,cAAc,YAAY,KAAM,YAAY,GAAI;CACrE,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,MAAM,IAAI;CAC9E,OAAO;AACT"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createRectMaterial } from './RectMaterial.js';
|
|
2
2
|
export { SdfTextMaterial } from './SdfTextMaterial.js';
|
|
3
|
-
export { createGlyphGeometry
|
|
3
|
+
export { createGlyphGeometry } from './glyphGeometry.js';
|
|
4
|
+
export { createRectGeometry } from './rectGeometry.js';
|
|
4
5
|
export { reflowSnapshot } from './reflow.js';
|
|
5
6
|
export type { SdfTextMaterialOptions } from './SdfTextMaterial.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InstancedBufferGeometry } from 'three/webgpu';
|
|
2
|
+
import type { DomLayoutSnapshot } from '../types.js';
|
|
3
|
+
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
4
|
+
export declare function rectContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
5
|
+
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
6
|
+
export declare function updateRectGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
9
|
+
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
10
|
+
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
11
|
+
* must handle the empty case instead of creating a zero-instance mesh.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRectGeometry(snapshot: DomLayoutSnapshot, receiveShadow: boolean): InstancedBufferGeometry | null;
|