ultra-text 1.0.2 → 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.
Files changed (206) hide show
  1. package/README.md +193 -115
  2. package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
  3. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
  4. package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
  5. package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
  6. package/dist/atlas/appendAtlas.js +35 -11
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +1 -1
  9. package/dist/atlas/buildAtlas.js.map +1 -1
  10. package/dist/atlas/colorGlyphs.d.ts +0 -10
  11. package/dist/atlas/colorGlyphs.js +97 -155
  12. package/dist/atlas/colorGlyphs.js.map +1 -1
  13. package/dist/atlas/colorTexture.d.ts +1 -0
  14. package/dist/atlas/colorTexture.js +64 -0
  15. package/dist/atlas/colorTexture.js.map +1 -0
  16. package/dist/atlas/cpuAtlas.js +8 -3
  17. package/dist/atlas/cpuAtlas.js.map +1 -1
  18. package/dist/atlas/cpuSdf.d.ts +1 -1
  19. package/dist/atlas/cpuSdf.js +97 -42
  20. package/dist/atlas/cpuSdf.js.map +1 -1
  21. package/dist/atlas/cpuWorker.d.ts +10 -4
  22. package/dist/atlas/cpuWorker.js +99 -49
  23. package/dist/atlas/cpuWorker.js.map +1 -1
  24. package/dist/atlas/gpuAtlas.js +133 -56
  25. package/dist/atlas/gpuAtlas.js.map +1 -1
  26. package/dist/atlas/gpuCommon.d.ts +140 -18
  27. package/dist/atlas/gpuCommon.js +726 -104
  28. package/dist/atlas/gpuCommon.js.map +1 -1
  29. package/dist/atlas/jfaWgsl.d.ts +1 -1
  30. package/dist/atlas/jfaWgsl.js +232 -61
  31. package/dist/atlas/jfaWgsl.js.map +1 -1
  32. package/dist/atlas/rasterize.d.ts +22 -0
  33. package/dist/atlas/rasterize.js +237 -111
  34. package/dist/atlas/rasterize.js.map +1 -1
  35. package/dist/atlas/vanillaCore.js +156 -103
  36. package/dist/atlas/vanillaCore.js.map +1 -1
  37. package/dist/atlas/vanillaCpuAtlas.js +37 -52
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
  39. package/dist/atlas/vanillaExtras.js +91 -90
  40. package/dist/atlas/vanillaExtras.js.map +1 -1
  41. package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
  42. package/dist/atlas/vanillaGpuHelpers.js +262 -27
  43. package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
  44. package/dist/dom/DomSdf.js +85 -79
  45. package/dist/dom/DomSdf.js.map +1 -1
  46. package/dist/dom/DomSlug.js +23 -18
  47. package/dist/dom/DomSlug.js.map +1 -1
  48. package/dist/dom/Text.d.ts +4 -1
  49. package/dist/dom/Text.js +5 -1
  50. package/dist/dom/Text.js.map +1 -1
  51. package/dist/dom/browserShaping.js +31 -14
  52. package/dist/dom/browserShaping.js.map +1 -1
  53. package/dist/dom/clusters.js +13 -2
  54. package/dist/dom/clusters.js.map +1 -1
  55. package/dist/dom/cssEffects.d.ts +4 -0
  56. package/dist/dom/cssEffects.js +72 -0
  57. package/dist/dom/cssEffects.js.map +1 -0
  58. package/dist/dom/domAnalytic.d.ts +1 -2
  59. package/dist/dom/domAnalytic.js +1 -1
  60. package/dist/dom/domAnalytic.js.map +1 -1
  61. package/dist/dom/fontCanvas.d.ts +16 -0
  62. package/dist/dom/fontCanvas.js +4 -4
  63. package/dist/dom/fontCanvas.js.map +1 -1
  64. package/dist/dom/layoutSignature.js +28 -12
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/markup.d.ts +10 -0
  67. package/dist/dom/markup.js +16 -1
  68. package/dist/dom/markup.js.map +1 -1
  69. package/dist/dom/pretextLayout.js +27 -19
  70. package/dist/dom/pretextLayout.js.map +1 -1
  71. package/dist/dom/snapshot.d.ts +4 -0
  72. package/dist/dom/snapshot.js +747 -505
  73. package/dist/dom/snapshot.js.map +1 -1
  74. package/dist/dom/snapshotsEqual.d.ts +7 -0
  75. package/dist/dom/snapshotsEqual.js +68 -0
  76. package/dist/dom/snapshotsEqual.js.map +1 -0
  77. package/dist/dom/svgCapture.js +30 -27
  78. package/dist/dom/svgCapture.js.map +1 -1
  79. package/dist/dom/textTransform.d.ts +13 -1
  80. package/dist/dom/textTransform.js +31 -13
  81. package/dist/dom/textTransform.js.map +1 -1
  82. package/dist/dom/tone.js +15 -8
  83. package/dist/dom/tone.js.map +1 -1
  84. package/dist/slug/SlugMaterial.d.ts +6 -0
  85. package/dist/slug/SlugMaterial.js +48 -20
  86. package/dist/slug/SlugMaterial.js.map +1 -1
  87. package/dist/slug/cff.d.ts +5 -0
  88. package/dist/slug/cff.js +780 -0
  89. package/dist/slug/cff.js.map +1 -0
  90. package/dist/slug/coverage.d.ts +3 -3
  91. package/dist/slug/coverage.js +283 -101
  92. package/dist/slug/coverage.js.map +1 -1
  93. package/dist/slug/preprocessCore.d.ts +1 -1
  94. package/dist/slug/preprocessCore.js +100 -80
  95. package/dist/slug/preprocessCore.js.map +1 -1
  96. package/dist/slug/runtime.js +32 -39
  97. package/dist/slug/runtime.js.map +1 -1
  98. package/dist/slug/standaloneRuntime.js +47 -37
  99. package/dist/slug/standaloneRuntime.js.map +1 -1
  100. package/dist/slug/truetype.d.ts +14 -6
  101. package/dist/slug/truetype.js +190 -62
  102. package/dist/slug/truetype.js.map +1 -1
  103. package/dist/slug/vanillaCore.d.ts +74 -4
  104. package/dist/slug/vanillaCore.js +226 -217
  105. package/dist/slug/vanillaCore.js.map +1 -1
  106. package/dist/slug-vanilla.d.ts +1 -1
  107. package/dist/slug-vanilla.js +5 -4
  108. package/dist/slug.d.ts +1 -1
  109. package/dist/slug.js +3 -3
  110. package/dist/text/GlyphTextMaterial.d.ts +5 -0
  111. package/dist/text/GlyphTextMaterial.js +11 -7
  112. package/dist/text/GlyphTextMaterial.js.map +1 -1
  113. package/dist/text/RectMaterial.js +6 -10
  114. package/dist/text/RectMaterial.js.map +1 -1
  115. package/dist/text/SdfTextMaterial.d.ts +9 -3
  116. package/dist/text/SdfTextMaterial.js +122 -37
  117. package/dist/text/SdfTextMaterial.js.map +1 -1
  118. package/dist/text/decorations.d.ts +7 -2
  119. package/dist/text/decorations.js +187 -96
  120. package/dist/text/decorations.js.map +1 -1
  121. package/dist/text/geometryUtils.d.ts +5 -0
  122. package/dist/text/geometryUtils.js +63 -9
  123. package/dist/text/geometryUtils.js.map +1 -1
  124. package/dist/text/glyphGeometry.d.ts +1 -1
  125. package/dist/text/glyphGeometry.js +281 -200
  126. package/dist/text/glyphGeometry.js.map +1 -1
  127. package/dist/text/rectGeometry.js +46 -42
  128. package/dist/text/rectGeometry.js.map +1 -1
  129. package/dist/text/reflow.d.ts +5 -0
  130. package/dist/text/reflow.js +127 -68
  131. package/dist/text/reflow.js.map +1 -1
  132. package/dist/text/snap.d.ts +15 -1
  133. package/dist/text/snap.js +1 -1
  134. package/dist/text/snap.js.map +1 -1
  135. package/dist/text/tone.js +2 -2
  136. package/dist/text/tone.js.map +1 -1
  137. package/dist/types.d.ts +23 -7
  138. package/dist/vanilla.js +1 -1
  139. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  140. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  141. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  142. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  143. package/dist/windfoil/WindfoilMaterial.js +71 -8
  144. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  145. package/dist/windfoil/compositeGeometry.js +12 -5
  146. package/dist/windfoil/compositeGeometry.js.map +1 -1
  147. package/dist/windfoil/coverage.d.ts +10 -2
  148. package/dist/windfoil/coverage.js +147 -59
  149. package/dist/windfoil/coverage.js.map +1 -1
  150. package/dist/windfoil/geometry.d.ts +15 -0
  151. package/dist/windfoil/geometry.js +154 -64
  152. package/dist/windfoil/geometry.js.map +1 -1
  153. package/dist/windfoil/layerGrid.js +8 -8
  154. package/dist/windfoil/layerGrid.js.map +1 -1
  155. package/dist/windfoil/mixed.js +13 -4
  156. package/dist/windfoil/mixed.js.map +1 -1
  157. package/dist/windfoil/preprocess.js +2 -2
  158. package/dist/windfoil/preprocessCore.d.ts +1 -0
  159. package/dist/windfoil/preprocessCore.js +63 -36
  160. package/dist/windfoil/preprocessCore.js.map +1 -1
  161. package/dist/windfoil/requests.d.ts +1 -1
  162. package/dist/windfoil/requests.js +11 -4
  163. package/dist/windfoil/requests.js.map +1 -1
  164. package/dist/windfoil/resolveOutline.d.ts +9 -0
  165. package/dist/windfoil/resolveOutline.js +20 -0
  166. package/dist/windfoil/resolveOutline.js.map +1 -0
  167. package/dist/windfoil/runtime.d.ts +1 -0
  168. package/dist/windfoil/runtime.js +8 -24
  169. package/dist/windfoil/runtime.js.map +1 -1
  170. package/dist/windfoil/shapeGeometry.js +80 -34
  171. package/dist/windfoil/shapeGeometry.js.map +1 -1
  172. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  173. package/dist/windfoil/sizeSwitch.js +13 -8
  174. package/dist/windfoil/sizeSwitch.js.map +1 -1
  175. package/dist/windfoil/storage.d.ts +23 -9
  176. package/dist/windfoil/storage.js +49 -30
  177. package/dist/windfoil/storage.js.map +1 -1
  178. package/dist/windfoil/svg/curves.d.ts +20 -0
  179. package/dist/windfoil/svg/curves.js +145 -42
  180. package/dist/windfoil/svg/curves.js.map +1 -1
  181. package/dist/windfoil/svg/document.js +10 -1
  182. package/dist/windfoil/svg/document.js.map +1 -1
  183. package/dist/windfoil/svg/pathConverter.js +66 -50
  184. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  185. package/dist/windfoil/svg/pathData.d.ts +9 -0
  186. package/dist/windfoil/svg/pathData.js +142 -109
  187. package/dist/windfoil/svg/pathData.js.map +1 -1
  188. package/dist/windfoil/svg/winding.js +34 -10
  189. package/dist/windfoil/svg/winding.js.map +1 -1
  190. package/dist/windfoil/trace/contours.js +120 -50
  191. package/dist/windfoil/trace/contours.js.map +1 -1
  192. package/dist/windfoil/trace/fit.js +578 -224
  193. package/dist/windfoil/trace/fit.js.map +1 -1
  194. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  195. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  196. package/dist/windfoil/trace/traceWorker.js +192 -0
  197. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  198. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  199. package/dist/windfoil/tracedOutlines.js +335 -70
  200. package/dist/windfoil/tracedOutlines.js.map +1 -1
  201. package/package.json +48 -29
  202. package/skills/ultra-text/SKILL.md +9 -10
  203. package/skills/ultra-text/references/frameworks.md +46 -2
  204. package/skills/ultra-text/references/three-tsl.md +26 -24
  205. package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
  206. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
@@ -1 +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,OAAO;CACrB,MAAM,SAAS,SAAS,gBAAgB;CACxC,MAAM,cAAc,IAAI,MAAM;CAC9B,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,YAAY,KAAA,KAAa,WAAW,KAAA;CACpD,MAAM,WAAW,UAAU,KAAA,KAAa,UAAU;CAClD,IAAI,QAAQ;CACZ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AAe,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"}
1
+ {"version":3,"file":"glyphGeometry.js","names":[],"sources":["../../src/text/glyphGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { atlasRootOf } from '../dom/markup.js'\nimport {\n attrOf,\n byte,\n flushAttributeUpdate,\n instanceAttribute,\n isDomSnapshot,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n writeDirty4,\n} from './geometryUtils.js'\n\nimport type { DomLayoutSnapshot, GlyphLayout, GlyphSlot, SdfAtlas } from '../types.js'\n\nconst prevBatchCache = new WeakMap<\n InstancedBufferGeometry,\n readonly [readonly GlyphLayout[], ReadonlyMap<string, unknown>, number, number]\n>()\n\nconst clamp16 = (v: number): number => Math.min(65535, Math.max(0, v))\n\nconst batchSummary: [number, number, number, number] = [0, 0, 0, 0]\n\nfunction writeGlyphBatchFresh(\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 cache: InstancedBufferGeometry,\n): void {\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 hasTrims = trims !== null\n const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot)\n let groupRepeats = 0\n let previousGroup: number | undefined\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 const dom = isDomSnapshot(snapshot)\n const root = dom ? atlasRootOf(atlasGlyphs) : null\n const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | (metaItemSize << 2)\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n // The source ordinal includes missing atlas slots. Each consecutive shape group counts once.\n if (groupMotion) {\n const group = glyph.shapeGroup\n if (group !== undefined && group === previousGroup) groupRepeats++\n previousGroup = group\n }\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) continue\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 ox = glyph.originX\n const r0 = ox + slot.planeX0 * scaleX\n const r1 = baseline + slot.planeY0 * scale\n const r2 = ox + slot.planeX1 * scaleX\n const r3 = baseline + slot.planeY1 * scale\n rects[offset] = r0\n rects[offset + 1] = r1\n rects[offset + 2] = r2\n rects[offset + 3] = r3\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = clip[0]\n fc1 = clip[1]\n fc2 = clip[2]\n fc3 = clip[3]\n }\n clips[offset] = fc0\n clips[offset + 1] = fc1\n clips[offset + 2] = fc2\n clips[offset + 3] = fc3\n\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 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 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 colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n\n const mOff = index * metaItemSize\n const seq = glyph.sequence\n const z = glyph.z\n metadata[mOff] = seq\n metadata[mOff + 1] = z\n if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats\n runMotion[rOff] = origin ? origin[0] : (r0 + r2) * 0.5\n runMotion[rOff + 1] = origin ? origin[1] : (r1 + r3) * 0.5\n runMotion[rOff + 2] = motionIndex\n }\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (dom && count === total) prevBatchCache.set(cache, [glyphs, root!, atlas.bakeSize, flags])\n else prevBatchCache.delete(cache)\n batchSummary[0] = count\n batchSummary[1] = maxSequence\n batchSummary[2] = minZ\n batchSummary[3] = maxZ\n}\n\nfunction writeGlyphBatchDirty(\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 | undefined,\n trims: Uint16Array | null,\n colors: Uint8Array | undefined,\n maxCount: number,\n dirty: Int32Array,\n cache: InstancedBufferGeometry,\n): boolean {\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 !== null\n const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot)\n let groupRepeats = 0\n let previousGroup: number | undefined\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 const dom = isDomSnapshot(snapshot)\n const root = dom ? atlasRootOf(atlasGlyphs) : null\n const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | (metaItemSize << 2)\n const prev = dom ? prevBatchCache.get(cache) : undefined\n let canSkip = prev?.[1] === root && prev[2] === atlas.bakeSize && prev[3] === flags\n const prevGlyphs = canSkip ? prev![0] : undefined\n for (let i = 0; i < 14; i += 2) {\n dirty[i] = 0\n dirty[i + 1] = -1\n }\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n if (groupMotion) {\n const group = glyph.shapeGroup\n if (group !== undefined && group === previousGroup) groupRepeats++\n previousGroup = group\n }\n if (\n canSkip &&\n count === ordinal &&\n ordinal < prevGlyphs!.length &&\n glyph === prevGlyphs![ordinal]\n ) {\n if (count >= maxCount) {\n prevBatchCache.delete(cache)\n return false\n }\n count++\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 continue\n }\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) {\n canSkip = false\n continue\n }\n if (count >= maxCount) {\n prevBatchCache.delete(cache)\n return false\n }\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 const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale)\n const ox = glyph.originX\n const r0 = Math.fround(ox + slot.planeX0 * scaleX)\n const r1 = Math.fround(baseline + slot.planeY0 * scale)\n const r2 = Math.fround(ox + slot.planeX1 * scaleX)\n const r3 = Math.fround(baseline + slot.planeY1 * scale)\n writeDirty4(rects, offset, r0, r1, r2, r3, dirty, 0)\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = Math.fround(clip[0])\n fc1 = Math.fround(clip[1])\n fc2 = Math.fround(clip[2])\n fc3 = Math.fround(clip[3])\n }\n writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2)\n\n const mOff = index * metaItemSize\n const seq = glyph.sequence\n const z = glyph.z\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 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(seq)\n const m1 = Math.fround(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 const m0 = Math.fround(seq)\n if (metadata[mOff] !== m0) {\n metadata[mOff] = m0\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + 1\n }\n }\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats\n const rx = Math.fround(origin ? origin[0] : (r0 + r2) * 0.5)\n const ry = Math.fround(origin ? origin[1] : (r1 + r3) * 0.5)\n const rz = Math.fround(motionIndex)\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 }\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (dom && count === total) prevBatchCache.set(cache, [glyphs, root!, atlas.bakeSize, flags])\n else prevBatchCache.delete(cache)\n batchSummary[0] = count\n batchSummary[1] = maxSequence\n batchSummary[2] = minZ\n batchSummary[3] = maxZ\n return true\n}\n\nconst dirtyBounds = new Int32Array(14)\n\nfunction setInstancedAttr(\n geometry: InstancedBufferGeometry,\n name: string,\n array: Float32Array | Uint16Array | Uint8Array,\n count: number,\n total: number,\n size: number,\n normalized: boolean,\n): void {\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\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 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 geometry = new InstancedBufferGeometry()\n writeGlyphBatchFresh(\n snapshot,\n atlas,\n rects,\n clips,\n metadata,\n meta,\n runMotion,\n motionOrdinals,\n uvRects,\n trims,\n colors,\n geometry,\n )\n const count = batchSummary[0]\n const maxSequence = batchSummary[1]\n const minZ = batchSummary[2]\n const maxZ = batchSummary[3]\n\n geometry.name = 'ultra-text instanced glyph quads'\n setUnitQuad(geometry)\n setInstancedAttr(geometry, 'sdfRect', rects, count, total, 4, false)\n setInstancedAttr(geometry, 'sdfUvRect', uvRects, count, total, 4, true)\n setInstancedAttr(geometry, 'sdfClip', clips, count, total, 4, false)\n setInstancedAttr(geometry, 'sdfColor', colors, count, total, 4, true)\n setInstancedAttr(geometry, 'sdfMeta', metadata, count, total, meta, false)\n if (runMotion) setInstancedAttr(geometry, 'sdfRunMotion', runMotion, count, total, 3, false)\n if (trims) setInstancedAttr(geometry, 'sdfTrim', trims, count, total, 4, true)\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 const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n const ok = writeGlyphBatchDirty(\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 null,\n undefined,\n instanceCount,\n dirtyBounds,\n geometry,\n )\n if (!ok || batchSummary[0] !== instanceCount) {\n prevBatchCache.delete(geometry)\n return null\n }\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(\n geometry,\n snapshot.width,\n snapshot.height,\n motionPadding,\n batchSummary[2],\n batchSummary[3],\n )\n return batchSummary[1]\n}\n\nfunction drawableGlyphCountMatches(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n expectedCount: number,\n): boolean {\n let count = 0\n const glyphs = snapshot.glyphs\n const total = glyphs.length\n const atlasGlyphs = atlas.glyphs\n const prev = isDomSnapshot(snapshot) ? prevBatchCache.get(geometry) : undefined\n const prevGlyphs =\n prev?.[1] === atlasRootOf(atlasGlyphs) && prev[0].length === total && total === expectedCount\n ? prev[0]\n : undefined\n let prevKey: string | undefined\n let prevHas = false\n if (prevGlyphs !== undefined) {\n for (let i = 0; i < total; i++) {\n const glyph = glyphs[i]!\n if (glyph === prevGlyphs[i]) {\n count++\n continue\n }\n const key = glyph.glyphKey\n const has = key === prevKey ? prevHas : ((prevKey = key), (prevHas = atlasGlyphs.has(key)))\n if (has && ++count > expectedCount) return false\n }\n } else {\n for (let i = 0; i < total; i++) {\n const key = glyphs[i]!.glyphKey\n const has = key === prevKey ? prevHas : ((prevKey = key), (prevHas = atlasGlyphs.has(key)))\n if (has && ++count > expectedCount) return false\n }\n }\n return count === expectedCount\n}\n\nexport function glyphContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionOrdinals?: Float32Array,\n skipDrawableCheck?: boolean,\n): boolean {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return false\n if (\n !instanceAttribute(geometry, 'sdfRect', 4) ||\n !instanceAttribute(geometry, 'sdfUvRect', 4) ||\n !instanceAttribute(geometry, 'sdfClip', 4) ||\n !instanceAttribute(geometry, 'sdfColor', 4)\n ) {\n 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 (\n layoutFits &&\n (Boolean(skipDrawableCheck && snapshot.glyphs.length === instanceCount) ||\n drawableGlyphCountMatches(geometry, snapshot, atlas, instanceCount))\n )\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 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 writeGlyphBatchDirty(\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 geometry,\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(\n geometry,\n snapshot.width,\n snapshot.height,\n motionPadding,\n batchSummary[2],\n batchSummary[3],\n )\n return batchSummary[1]\n}\n"],"mappings":";;;;AAiBA,IAAM,iCAAiB,IAAI,QAGzB;AAEF,IAAM,WAAW,MAAsB,KAAK,IAAI,OAAO,KAAK,IAAI,GAAG,CAAC,CAAC;AAErE,IAAM,eAAiD;CAAC;CAAG;CAAG;CAAG;AAAC;AAElE,SAAS,qBACP,UACA,OACA,OACA,OACA,UACA,cACA,WACA,gBACA,SACA,OACA,QACA,OACM;CACN,MAAM,SAAS,SAAS;CACxB,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,SAAS,gBAAgB;CACxC,MAAM,cAAc,IAAI,MAAM;CAC9B,MAAM,cAAc,MAAM;CAC1B,MAAM,WAAW,UAAU;CAC3B,MAAM,cAAc,CAAC,CAAC,aAAa,CAAC,kBAAkB,eAAe,QAAQ;CAC7E,IAAI,eAAe;CACnB,IAAI;CACJ,IAAI,QAAQ;CACZ,IAAI,cAAc;CAClB,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,I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ACA,YAAY,OACZ,gBAAgB,cAAc,QAAQ,MACtC,eAAe,OACf,UACA,aACA,QACF;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,UACE,UACA,SAAS,OACT,SAAS,QACT,eACA,aAAa,IACb,aAAa,EACf;CACA,OAAO,aAAa;AACtB"}
@@ -1,4 +1,4 @@
1
- import { attrOf, byte, instanceAttribute, put4, setBounds, setUnitQuad } from "./geometryUtils.js";
1
+ import { attrOf, byte, flushAttributeUpdate, instanceAttribute, put4, setBounds, setUnitQuad, writeDirty4 } from "./geometryUtils.js";
2
2
  import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
3
3
  // src/text/rectGeometry.ts
4
4
  function rectCountFor(snapshot, receiveShadow) {
@@ -6,20 +6,43 @@ function rectCountFor(snapshot, receiveShadow) {
6
6
  for (const rect of snapshot.rects) if (rect.receiveShadow === receiveShadow) count++;
7
7
  return count;
8
8
  }
9
- function writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths) {
9
+ var dirtyBounds = /* @__PURE__ */ new Int32Array(8);
10
+ function markDirty(slot, start, count) {
11
+ if (dirtyBounds[slot + 1] < 0) dirtyBounds[slot] = start;
12
+ dirtyBounds[slot + 1] = start + count;
13
+ }
14
+ function writeDirtyScalar(array, index, value, slot) {
15
+ if (Object.is(array[index], Math.fround(value))) return;
16
+ array[index] = value;
17
+ markDirty(slot, index, 1);
18
+ }
19
+ function writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths, trackChanges = false) {
10
20
  let index = 0;
11
21
  let minZ = 0;
12
22
  let maxZ = 0;
13
23
  for (const item of snapshot.rects) {
14
24
  if (item.receiveShadow !== receiveShadow) continue;
15
25
  const offset = index * 4;
16
- put4(rects, offset, item.rect);
17
- colors[offset] = byte(item.color[0]);
18
- colors[offset + 1] = byte(item.color[1]);
19
- colors[offset + 2] = byte(item.color[2]);
20
- colors[offset + 3] = byte(item.color[3]);
21
- radii[index] = item.radius;
22
- depths[index] = item.z;
26
+ const color = item.color;
27
+ const r = byte(color[0]), g = byte(color[1]), b = byte(color[2]), a = byte(color[3]);
28
+ if (trackChanges) {
29
+ const rect = item.rect;
30
+ if (!Object.is(rects[offset], Math.fround(rect[0])) || !Object.is(rects[offset + 1], Math.fround(rect[1])) || !Object.is(rects[offset + 2], Math.fround(rect[2])) || !Object.is(rects[offset + 3], Math.fround(rect[3]))) {
31
+ put4(rects, offset, rect);
32
+ markDirty(0, offset, 4);
33
+ }
34
+ writeDirty4(colors, offset, r, g, b, a, dirtyBounds, 2);
35
+ writeDirtyScalar(radii, index, item.radius, 4);
36
+ writeDirtyScalar(depths, index, item.z, 6);
37
+ } else {
38
+ put4(rects, offset, item.rect);
39
+ colors[offset] = r;
40
+ colors[offset + 1] = g;
41
+ colors[offset + 2] = b;
42
+ colors[offset + 3] = a;
43
+ radii[index] = item.radius;
44
+ depths[index] = item.z;
45
+ }
23
46
  if (item.z < minZ) minZ = item.z;
24
47
  if (item.z > maxZ) maxZ = item.z;
25
48
  index++;
@@ -35,13 +58,16 @@ function rectContentFits(geometry, snapshot, receiveShadow) {
35
58
  /** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
36
59
  function updateRectGeometry(geometry, snapshot, receiveShadow) {
37
60
  if (!rectContentFits(geometry, snapshot, receiveShadow)) return false;
38
- const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, attrOf(geometry, "sdfRect").array, attrOf(geometry, "sdfColor").array, attrOf(geometry, "sdfRadius").array, attrOf(geometry, "sdfZ").array);
39
- for (const name of [
40
- "sdfRect",
41
- "sdfColor",
42
- "sdfRadius",
43
- "sdfZ"
44
- ]) attrOf(geometry, name).needsUpdate = true;
61
+ const rects = attrOf(geometry, "sdfRect");
62
+ const colors = attrOf(geometry, "sdfColor");
63
+ const radii = attrOf(geometry, "sdfRadius");
64
+ const depths = attrOf(geometry, "sdfZ");
65
+ dirtyBounds.fill(-1);
66
+ const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects.array, colors.array, radii.array, depths.array, true);
67
+ flushAttributeUpdate(rects, dirtyBounds[0], dirtyBounds[1]);
68
+ flushAttributeUpdate(colors, dirtyBounds[2], dirtyBounds[3]);
69
+ flushAttributeUpdate(radii, dirtyBounds[4], dirtyBounds[5]);
70
+ flushAttributeUpdate(depths, dirtyBounds[6], dirtyBounds[7]);
45
71
  setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
46
72
  return true;
47
73
  }
@@ -62,32 +88,10 @@ function createRectGeometry(snapshot, receiveShadow) {
62
88
  const geometry = new InstancedBufferGeometry();
63
89
  geometry.name = receiveShadow ? "ultra-text instanced shadow-receiving DOM rects" : "ultra-text instanced DOM rects";
64
90
  setUnitQuad(geometry);
65
- for (const [name, array, size, normalized] of [
66
- [
67
- "sdfRect",
68
- rects,
69
- 4,
70
- false
71
- ],
72
- [
73
- "sdfColor",
74
- colors,
75
- 4,
76
- true
77
- ],
78
- [
79
- "sdfRadius",
80
- radii,
81
- 1,
82
- false
83
- ],
84
- [
85
- "sdfZ",
86
- depths,
87
- 1,
88
- false
89
- ]
90
- ]) geometry.setAttribute(name, new InstancedBufferAttribute(array, size, normalized));
91
+ geometry.setAttribute("sdfRect", new InstancedBufferAttribute(rects, 4, false));
92
+ geometry.setAttribute("sdfColor", new InstancedBufferAttribute(colors, 4, true));
93
+ geometry.setAttribute("sdfRadius", new InstancedBufferAttribute(radii, 1, false));
94
+ geometry.setAttribute("sdfZ", new InstancedBufferAttribute(depths, 1, false));
91
95
  geometry.instanceCount = count;
92
96
  setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
93
97
  return geometry;
@@ -1 +1 @@
1
- {"version":3,"file":"rectGeometry.js","names":[],"sources":["../../src/text/rectGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\n\nimport type { DomLayoutSnapshot } from '../types.js'\nimport { attrOf, byte, instanceAttribute, put4, setBounds, setUnitQuad } from './geometryUtils.js'\n\nfunction rectCountFor(snapshot: DomLayoutSnapshot, receiveShadow: boolean): number {\n let count = 0\n for (const rect of snapshot.rects) if (rect.receiveShadow === receiveShadow) count++\n return count\n}\n\nfunction writeRectBatch(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n rects: Float32Array,\n colors: Uint8Array,\n radii: Float32Array,\n depths: Float32Array,\n): [number, number] {\n let index = 0\n let minZ = 0\n let maxZ = 0\n for (const item of snapshot.rects) {\n if (item.receiveShadow !== receiveShadow) continue\n const offset = index * 4\n put4(rects, offset, item.rect)\n colors[offset] = byte(item.color[0])\n colors[offset + 1] = byte(item.color[1])\n colors[offset + 2] = byte(item.color[2])\n colors[offset + 3] = byte(item.color[3])\n radii[index] = item.radius\n depths[index] = item.z\n if (item.z < minZ) minZ = item.z\n if (item.z > maxZ) maxZ = item.z\n index++\n }\n return [minZ, maxZ]\n}\n\n/** True when a rectangle batch has the same instance count and attribute layout. */\nexport function rectContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (snapshot.rects.length < geometry.instanceCount) return false\n if (\n !instanceAttribute(geometry, 'sdfRect', 4) ||\n !instanceAttribute(geometry, 'sdfColor', 4) ||\n !instanceAttribute(geometry, 'sdfRadius', 1) ||\n !instanceAttribute(geometry, 'sdfZ', 1)\n ) {\n return false\n }\n return rectCountFor(snapshot, receiveShadow) === geometry.instanceCount\n}\n\n/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */\nexport function updateRectGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (!rectContentFits(geometry, snapshot, receiveShadow)) return false\n const [minZ, maxZ] = writeRectBatch(\n snapshot,\n receiveShadow,\n attrOf<Float32Array>(geometry, 'sdfRect')!.array,\n attrOf<Uint8Array>(geometry, 'sdfColor')!.array,\n attrOf<Float32Array>(geometry, 'sdfRadius')!.array,\n attrOf<Float32Array>(geometry, 'sdfZ')!.array,\n )\n for (const name of ['sdfRect', 'sdfColor', 'sdfRadius', 'sdfZ']) {\n attrOf(geometry, name)!.needsUpdate = true\n }\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return true\n}\n\n/**\n * Builds one instanced rectangle batch for a shadow-receiver state: pass\n * `receiveShadow: true` for the lit batch, `false` for the plain one.\n * Returns null when the snapshot has no rectangles in that bucket — callers\n * must handle the empty case instead of creating a zero-instance mesh.\n */\nexport function createRectGeometry(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): InstancedBufferGeometry | null {\n const count = rectCountFor(snapshot, receiveShadow)\n if (count === 0) return null\n const rects = new Float32Array(count * 4)\n const colors = new Uint8Array(count * 4)\n const radii = new Float32Array(count)\n const depths = new Float32Array(count)\n const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths)\n\n const geometry = new InstancedBufferGeometry()\n geometry.name = receiveShadow\n ? 'ultra-text instanced shadow-receiving DOM rects'\n : 'ultra-text instanced DOM rects'\n setUnitQuad(geometry)\n for (const [name, array, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfRadius', radii, 1, false],\n ['sdfZ', depths, 1, false],\n ] as const) {\n geometry.setAttribute(name, new InstancedBufferAttribute(array, size, normalized))\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return geometry\n}\n"],"mappings":";;;AAKA,SAAS,aAAa,UAA6B,eAAgC;CACjF,IAAI,Q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AC,CAAE,OAC7C,OAAqB,UAAU,MAAM,CAAC,CAAE,KAC1C;CACA,KAAK,MAAM,QAAQ;EAAC;EAAW;EAAY;EAAa;CAAM,GAC5D,OAAO,UAAU,IAAI,CAAC,CAAE,cAAc;CAExC,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,GAAG,MAAM,IAAI;CAClE,OAAO;AACT;;;;;;;AAQA,SAAgB,mBACd,UACA,eACgC;CAChC,MAAM,QAAQ,aAAa,UAAU,aAAa;CAClD,IAAI,UAAU,GAAG,OAAO;CACxB,MAAM,QAAQ,IAAI,aAAa,QAAQ,CAAC;CACxC,MAAM,SAAS,IAAI,WAAW,QAAQ,CAAC;CACvC,MAAM,QAAQ,IAAI,aAAa,KAAK;CACpC,MAAM,SAAS,IAAI,aAAa,KAAK;CACrC,MAAM,CAAC,MAAM,QAAQ,eAAe,UAAU,eAAe,OAAO,QAAQ,OAAO,MAAM;CAEzF,MAAM,WAAW,IAAI,wBAAwB;CAC7C,SAAS,OAAO,gBACZ,oDACA;CACJ,YAAY,QAAQ;CACpB,KAAK,MAAM,CAAC,MAAM,OAAO,MAAM,eAAe;EAC5C;GAAC;GAAW;GAAO;GAAG;EAAK;EAC3B;GAAC;GAAY;GAAQ;GAAG;EAAI;EAC5B;GAAC;GAAa;GAAO;GAAG;EAAK;EAC7B;GAAC;GAAQ;GAAQ;GAAG;EAAK;CAC3B,GACE,SAAS,aAAa,MAAM,IAAI,yBAAyB,OAAO,MAAM,UAAU,CAAC;CAEnF,SAAS,gBAAgB;CACzB,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,GAAG,MAAM,IAAI;CAClE,OAAO;AACT"}
1
+ {"version":3,"file":"rectGeometry.js","names":[],"sources":["../../src/text/rectGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\n\nimport type { DomLayoutSnapshot } from '../types.js'\nimport {\n attrOf,\n byte,\n flushAttributeUpdate,\n instanceAttribute,\n put4,\n setBounds,\n setUnitQuad,\n writeDirty4,\n} from './geometryUtils.js'\n\nfunction rectCountFor(snapshot: DomLayoutSnapshot, receiveShadow: boolean): number {\n let count = 0\n for (const rect of snapshot.rects) if (rect.receiveShadow === receiveShadow) count++\n return count\n}\n\n// One range per attribute. Multiple edits before a draw accumulate in the attribute itself.\nconst dirtyBounds = new Int32Array(8)\n\nfunction markDirty(slot: number, start: number, count: number): void {\n if (dirtyBounds[slot + 1]! < 0) dirtyBounds[slot] = start\n dirtyBounds[slot + 1] = start + count\n}\n\nfunction writeDirtyScalar(array: Float32Array, index: number, value: number, slot: number): void {\n if (Object.is(array[index], Math.fround(value))) return\n array[index] = value\n markDirty(slot, index, 1)\n}\n\nfunction writeRectBatch(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n rects: Float32Array,\n colors: Uint8Array,\n radii: Float32Array,\n depths: Float32Array,\n trackChanges = false,\n): [number, number] {\n let index = 0\n let minZ = 0\n let maxZ = 0\n for (const item of snapshot.rects) {\n if (item.receiveShadow !== receiveShadow) continue\n const offset = index * 4\n const color = item.color\n const r = byte(color[0]),\n g = byte(color[1]),\n b = byte(color[2]),\n a = byte(color[3])\n if (trackChanges) {\n const rect = item.rect\n if (\n !Object.is(rects[offset], Math.fround(rect[0])) ||\n !Object.is(rects[offset + 1], Math.fround(rect[1])) ||\n !Object.is(rects[offset + 2], Math.fround(rect[2])) ||\n !Object.is(rects[offset + 3], Math.fround(rect[3]))\n ) {\n put4(rects, offset, rect)\n markDirty(0, offset, 4)\n }\n writeDirty4(colors, offset, r, g, b, a, dirtyBounds, 2)\n writeDirtyScalar(radii, index, item.radius, 4)\n writeDirtyScalar(depths, index, item.z, 6)\n } else {\n put4(rects, offset, item.rect)\n colors[offset] = r\n colors[offset + 1] = g\n colors[offset + 2] = b\n colors[offset + 3] = a\n radii[index] = item.radius\n depths[index] = item.z\n }\n if (item.z < minZ) minZ = item.z\n if (item.z > maxZ) maxZ = item.z\n index++\n }\n return [minZ, maxZ]\n}\n\n/** True when a rectangle batch has the same instance count and attribute layout. */\nexport function rectContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (snapshot.rects.length < geometry.instanceCount) return false\n if (\n !instanceAttribute(geometry, 'sdfRect', 4) ||\n !instanceAttribute(geometry, 'sdfColor', 4) ||\n !instanceAttribute(geometry, 'sdfRadius', 1) ||\n !instanceAttribute(geometry, 'sdfZ', 1)\n ) {\n return false\n }\n return rectCountFor(snapshot, receiveShadow) === geometry.instanceCount\n}\n\n/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */\nexport function updateRectGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (!rectContentFits(geometry, snapshot, receiveShadow)) return false\n const rects = attrOf<Float32Array>(geometry, 'sdfRect')!\n const colors = attrOf<Uint8Array>(geometry, 'sdfColor')!\n const radii = attrOf<Float32Array>(geometry, 'sdfRadius')!\n const depths = attrOf<Float32Array>(geometry, 'sdfZ')!\n dirtyBounds.fill(-1)\n const [minZ, maxZ] = writeRectBatch(\n snapshot,\n receiveShadow,\n rects.array,\n colors.array,\n radii.array,\n depths.array,\n true,\n )\n flushAttributeUpdate(rects, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(colors, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(radii, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(depths, dirtyBounds[6]!, dirtyBounds[7]!)\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return true\n}\n\n/**\n * Builds one instanced rectangle batch for a shadow-receiver state: pass\n * `receiveShadow: true` for the lit batch, `false` for the plain one.\n * Returns null when the snapshot has no rectangles in that bucket — callers\n * must handle the empty case instead of creating a zero-instance mesh.\n */\nexport function createRectGeometry(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): InstancedBufferGeometry | null {\n const count = rectCountFor(snapshot, receiveShadow)\n if (count === 0) return null\n const rects = new Float32Array(count * 4)\n const colors = new Uint8Array(count * 4)\n const radii = new Float32Array(count)\n const depths = new Float32Array(count)\n const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths)\n\n const geometry = new InstancedBufferGeometry()\n geometry.name = receiveShadow\n ? 'ultra-text instanced shadow-receiving DOM rects'\n : 'ultra-text instanced DOM rects'\n setUnitQuad(geometry)\n geometry.setAttribute('sdfRect', new InstancedBufferAttribute(rects, 4, false))\n geometry.setAttribute('sdfColor', new InstancedBufferAttribute(colors, 4, true))\n geometry.setAttribute('sdfRadius', new InstancedBufferAttribute(radii, 1, false))\n geometry.setAttribute('sdfZ', new InstancedBufferAttribute(depths, 1, false))\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return geometry\n}\n"],"mappings":";;;AAcA,SAAS,aAAa,UAA6B,eAAgC;CACjF,IAAI,QAAQ;CACZ,KAAK,MAAM,QAAQ,SAAS,OAAO,IAAI,KAAK,kBAAkB,eAAe;CAC7E,OAAO;AACT;AAGA,IAAM,8BAAc,IAAI,WAAW,CAAC;AAEpC,SAAS,UAAU,MAAc,OAAe,OAAqB;CACnE,IAAI,YAAY,OAAO,KAAM,GAAG,YAAY,QAAQ;CACpD,YAAY,OAAO,KAAK,QAAQ;AAClC;AAEA,SAAS,iBAAiB,OAAqB,OAAe,OAAe,MAAoB;CAC/F,IAAI,OAAO,GAAG,MAAM,QAAQ,KAAK,OAAO,KAAK,CAAC,GAAG;CACjD,MAAM,SAAS;CACf,UAAU,MAAM,OAAO,CAAC;AAC1B;AAEA,SAAS,eACP,UACA,eACA,OACA,QACA,OACA,QACA,eAAe,OACG;CAClB,IAAI,QAAQ;CACZ,IAAI,OAAO;CACX,IAAI,OAAO;CACX,KAAK,MAAM,QAAQ,SAAS,OAAO;EACjC,IAAI,KAAK,kBAAkB,eAAe;EAC1C,MAAM,S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C;CAC9E,SAAS,aAAa,YAAY,IAAI,yBAAyB,QAAQ,GAAG,IAAI,CAAC;CAC/E,SAAS,aAAa,aAAa,IAAI,yBAAyB,OAAO,GAAG,KAAK,CAAC;CAChF,SAAS,aAAa,QAAQ,IAAI,yBAAyB,QAAQ,GAAG,KAAK,CAAC;CAC5E,SAAS,gBAAgB;CACzB,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,GAAG,MAAM,IAAI;CAClE,OAAO;AACT"}
@@ -13,6 +13,11 @@ export interface ReflowState {
13
13
  readonly glyphClips: ([number, number, number, number] | undefined)[];
14
14
  readonly motionOrigins: ([number, number, number] | undefined)[];
15
15
  readonly snaps: ([number, number] | undefined)[];
16
+ /** Contiguous runs and original line counts depend only on the captured layout. */
17
+ readonly runs: {
18
+ end: number;
19
+ lines: number;
20
+ }[];
16
21
  }
17
22
  export declare function createReflowState(snapshot: DomLayoutSnapshot): ReflowState;
18
23
  export declare function reflowSnapshot(snapshot: DomLayoutSnapshot, width: number): DomLayoutSnapshot;