ultra-text 1.0.0 → 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.
Files changed (200) hide show
  1. package/README.md +267 -962
  2. package/THIRD_PARTY_NOTICES.md +3 -0
  3. package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
  4. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
  5. package/dist/atlas/appendAtlas.js +69 -26
  6. package/dist/atlas/appendAtlas.js.map +1 -1
  7. package/dist/atlas/buildAtlas.js +5 -15
  8. package/dist/atlas/buildAtlas.js.map +1 -1
  9. package/dist/atlas/cpuAtlas.d.ts +4 -1
  10. package/dist/atlas/cpuAtlas.js +8 -6
  11. package/dist/atlas/cpuAtlas.js.map +1 -1
  12. package/dist/atlas/cpuSdf.js +164 -50
  13. package/dist/atlas/cpuSdf.js.map +1 -1
  14. package/dist/atlas/cpuWorker.d.ts +5 -3
  15. package/dist/atlas/cpuWorker.js +119 -12
  16. package/dist/atlas/cpuWorker.js.map +1 -1
  17. package/dist/atlas/gpuAtlas.d.ts +7 -6
  18. package/dist/atlas/gpuAtlas.js +206 -247
  19. package/dist/atlas/gpuAtlas.js.map +1 -1
  20. package/dist/atlas/gpuCommon.d.ts +135 -0
  21. package/dist/atlas/gpuCommon.js +223 -0
  22. package/dist/atlas/gpuCommon.js.map +1 -0
  23. package/dist/atlas/jfaWgsl.js +59 -125
  24. package/dist/atlas/jfaWgsl.js.map +1 -1
  25. package/dist/atlas/rasterize.d.ts +2 -0
  26. package/dist/atlas/rasterize.js +104 -144
  27. package/dist/atlas/rasterize.js.map +1 -1
  28. package/dist/atlas/shapeRaster.js +2 -1
  29. package/dist/atlas/shapeRaster.js.map +1 -1
  30. package/dist/atlas/vanillaBounds.d.ts +64 -0
  31. package/dist/atlas/vanillaBounds.js +42 -0
  32. package/dist/atlas/vanillaBounds.js.map +1 -0
  33. package/dist/atlas/vanillaCore.d.ts +100 -0
  34. package/dist/atlas/vanillaCore.js +1012 -0
  35. package/dist/atlas/vanillaCore.js.map +1 -0
  36. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  37. package/dist/atlas/vanillaCpuAtlas.js +87 -0
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  39. package/dist/atlas/vanillaExtras.d.ts +8 -0
  40. package/dist/atlas/vanillaExtras.js +166 -0
  41. package/dist/atlas/vanillaExtras.js.map +1 -0
  42. package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
  43. package/dist/atlas/vanillaGpuHelpers.js +119 -0
  44. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  45. package/dist/dom/DomSdf.js +263 -272
  46. package/dist/dom/DomSdf.js.map +1 -1
  47. package/dist/dom/DomSlug.d.ts +26 -0
  48. package/dist/dom/DomSlug.js +564 -0
  49. package/dist/dom/DomSlug.js.map +1 -0
  50. package/dist/dom/SlugText.d.ts +18 -0
  51. package/dist/dom/SlugText.js +94 -0
  52. package/dist/dom/SlugText.js.map +1 -0
  53. package/dist/dom/Text.js +4 -67
  54. package/dist/dom/Text.js.map +1 -1
  55. package/dist/dom/domAnalytic.d.ts +54 -0
  56. package/dist/dom/domAnalytic.js +282 -0
  57. package/dist/dom/domAnalytic.js.map +1 -0
  58. package/dist/dom/domExtras.d.ts +27 -0
  59. package/dist/dom/domExtras.js +137 -0
  60. package/dist/dom/domExtras.js.map +1 -0
  61. package/dist/dom/fontCanvas.d.ts +2 -0
  62. package/dist/dom/fontCanvas.js +119 -0
  63. package/dist/dom/fontCanvas.js.map +1 -0
  64. package/dist/dom/layoutSignature.js +156 -27
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/pretextLayout.js +55 -13
  67. package/dist/dom/pretextLayout.js.map +1 -1
  68. package/dist/dom/snapshot.js +563 -243
  69. package/dist/dom/snapshot.js.map +1 -1
  70. package/dist/dom/svgCapture.d.ts +8 -1
  71. package/dist/dom/svgCapture.js +75 -1
  72. package/dist/dom/svgCapture.js.map +1 -1
  73. package/dist/dom/textHost.d.ts +11 -0
  74. package/dist/dom/textHost.js +68 -0
  75. package/dist/dom/textHost.js.map +1 -0
  76. package/dist/dom/tone.js +76 -36
  77. package/dist/dom/tone.js.map +1 -1
  78. package/dist/index.js +4 -3
  79. package/dist/slug/SlugMaterial.d.ts +13 -4
  80. package/dist/slug/SlugMaterial.js +82 -12
  81. package/dist/slug/SlugMaterial.js.map +1 -1
  82. package/dist/slug/coverage.d.ts +17 -13
  83. package/dist/slug/coverage.js +195 -222
  84. package/dist/slug/coverage.js.map +1 -1
  85. package/dist/slug/preprocessCore.d.ts +6 -3
  86. package/dist/slug/preprocessCore.js +149 -95
  87. package/dist/slug/preprocessCore.js.map +1 -1
  88. package/dist/slug/runtime.d.ts +1 -0
  89. package/dist/slug/runtime.js +94 -46
  90. package/dist/slug/runtime.js.map +1 -1
  91. package/dist/slug/standaloneRuntime.d.ts +40 -0
  92. package/dist/slug/standaloneRuntime.js +175 -0
  93. package/dist/slug/standaloneRuntime.js.map +1 -0
  94. package/dist/slug/truetype.d.ts +22 -0
  95. package/dist/slug/truetype.js +467 -0
  96. package/dist/slug/truetype.js.map +1 -0
  97. package/dist/slug/vanillaCore.d.ts +340 -0
  98. package/dist/slug/vanillaCore.js +1621 -0
  99. package/dist/slug/vanillaCore.js.map +1 -0
  100. package/dist/slug-vanilla.d.ts +13 -0
  101. package/dist/slug-vanilla.js +13 -0
  102. package/dist/slug.d.ts +21 -0
  103. package/dist/slug.js +19 -0
  104. package/dist/text/GlyphTextMaterial.d.ts +11 -11
  105. package/dist/text/GlyphTextMaterial.js +102 -33
  106. package/dist/text/GlyphTextMaterial.js.map +1 -1
  107. package/dist/text/SdfTextMaterial.d.ts +5 -4
  108. package/dist/text/SdfTextMaterial.js +29 -9
  109. package/dist/text/SdfTextMaterial.js.map +1 -1
  110. package/dist/text/decorations.js +36 -19
  111. package/dist/text/decorations.js.map +1 -1
  112. package/dist/text/geometry.d.ts +3 -22
  113. package/dist/text/geometryUtils.d.ts +11 -1
  114. package/dist/text/geometryUtils.js +22 -1
  115. package/dist/text/geometryUtils.js.map +1 -1
  116. package/dist/text/glyphGeometry.d.ts +9 -0
  117. package/dist/text/glyphGeometry.js +353 -0
  118. package/dist/text/glyphGeometry.js.map +1 -0
  119. package/dist/text/index.d.ts +2 -1
  120. package/dist/text/rectGeometry.d.ts +13 -0
  121. package/dist/text/rectGeometry.js +97 -0
  122. package/dist/text/rectGeometry.js.map +1 -0
  123. package/dist/text/reflow.d.ts +18 -1
  124. package/dist/text/reflow.js +108 -38
  125. package/dist/text/reflow.js.map +1 -1
  126. package/dist/text/snap.d.ts +1 -0
  127. package/dist/text/snap.js +26 -0
  128. package/dist/text/snap.js.map +1 -0
  129. package/dist/types.d.ts +63 -14
  130. package/dist/vanilla.d.ts +13 -360
  131. package/dist/vanilla.js +8 -1402
  132. package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
  133. package/dist/windfoil/WindfoilMaterial.js +8 -1
  134. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  135. package/dist/windfoil/abortable.d.ts +2 -0
  136. package/dist/windfoil/abortable.js +26 -0
  137. package/dist/windfoil/abortable.js.map +1 -0
  138. package/dist/windfoil/color.js +2 -1
  139. package/dist/windfoil/color.js.map +1 -1
  140. package/dist/windfoil/coverage.d.ts +3 -20
  141. package/dist/windfoil/coverage.js +7 -20
  142. package/dist/windfoil/coverage.js.map +1 -1
  143. package/dist/windfoil/emoji.js +1 -1
  144. package/dist/windfoil/emoji.js.map +1 -1
  145. package/dist/windfoil/emojiMetrics.js +1 -1
  146. package/dist/windfoil/emojiMetrics.js.map +1 -1
  147. package/dist/windfoil/geometry.d.ts +2 -2
  148. package/dist/windfoil/geometry.js +204 -64
  149. package/dist/windfoil/geometry.js.map +1 -1
  150. package/dist/windfoil/layerGrid.js +14 -10
  151. package/dist/windfoil/layerGrid.js.map +1 -1
  152. package/dist/windfoil/layerNormalization.d.ts +1 -1
  153. package/dist/windfoil/layerNormalization.js +1 -1
  154. package/dist/windfoil/layerNormalization.js.map +1 -1
  155. package/dist/windfoil/mixed.d.ts +1 -0
  156. package/dist/windfoil/mixed.js +44 -25
  157. package/dist/windfoil/mixed.js.map +1 -1
  158. package/dist/windfoil/outlineValidation.d.ts +86 -0
  159. package/dist/windfoil/outlineValidation.js +65 -0
  160. package/dist/windfoil/outlineValidation.js.map +1 -0
  161. package/dist/windfoil/preprocess.js +3 -2
  162. package/dist/windfoil/preprocess.js.map +1 -1
  163. package/dist/windfoil/preprocessCore.d.ts +5 -85
  164. package/dist/windfoil/preprocessCore.js +218 -209
  165. package/dist/windfoil/preprocessCore.js.map +1 -1
  166. package/dist/windfoil/requests.js +1 -1
  167. package/dist/windfoil/requests.js.map +1 -1
  168. package/dist/windfoil/runtime.d.ts +5 -2
  169. package/dist/windfoil/runtime.js +63 -40
  170. package/dist/windfoil/runtime.js.map +1 -1
  171. package/dist/windfoil/shapeResources.js +2 -1
  172. package/dist/windfoil/shapeResources.js.map +1 -1
  173. package/dist/windfoil/shapes.js +1 -1
  174. package/dist/windfoil/skirt.d.ts +22 -0
  175. package/dist/windfoil/skirt.js +20 -0
  176. package/dist/windfoil/skirt.js.map +1 -0
  177. package/dist/windfoil/storage.d.ts +62 -4
  178. package/dist/windfoil/storage.js +143 -28
  179. package/dist/windfoil/storage.js.map +1 -1
  180. package/dist/windfoil/trace/contours.d.ts +3 -3
  181. package/dist/windfoil/trace/contours.js +228 -137
  182. package/dist/windfoil/trace/contours.js.map +1 -1
  183. package/dist/windfoil/trace/fit.d.ts +3 -7
  184. package/dist/windfoil/trace/fit.js +668 -376
  185. package/dist/windfoil/trace/fit.js.map +1 -1
  186. package/dist/windfoil/trace/outline.js +60 -35
  187. package/dist/windfoil/trace/outline.js.map +1 -1
  188. package/dist/windfoil/trace/types.d.ts +15 -3
  189. package/dist/windfoil/tracedOutlines.d.ts +37 -1
  190. package/dist/windfoil/tracedOutlines.js +228 -64
  191. package/dist/windfoil/tracedOutlines.js.map +1 -1
  192. package/package.json +60 -11
  193. package/skills/ultra-text/SKILL.md +114 -0
  194. package/skills/ultra-text/references/frameworks.md +43 -0
  195. package/skills/ultra-text/references/three-tsl.md +78 -0
  196. package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
  197. package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
  198. package/dist/text/geometry.js +0 -348
  199. package/dist/text/geometry.js.map +0 -1
  200. package/dist/vanilla.js.map +0 -1
@@ -19,6 +19,7 @@ export interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMater
19
19
  }
20
20
  /** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */
21
21
  export declare class WindfoilMaterial extends GlyphTextMaterial {
22
- readonly shadowCutoff: UniformNode<'float', number>;
22
+ #private;
23
+ get shadowCutoff(): UniformNode<'float', number>;
23
24
  constructor(options: WindfoilMaterialOptions);
24
25
  }
@@ -5,7 +5,14 @@ import { Fn, If, abs, attribute, clamp, dFdy, float, max, mix, step, uint, unifo
5
5
  // src/windfoil/WindfoilMaterial.ts
6
6
  /** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */
7
7
  var WindfoilMaterial = class extends GlyphTextMaterial {
8
- shadowCutoff = uniform(.5);
8
+ #sc = uniform(.5);
9
+ get shadowCutoff() {
10
+ return this.#sc;
11
+ }
12
+ /** @internal */
13
+ copySubclassUniforms(target) {
14
+ target.shadowCutoff.value = this.#sc.value;
15
+ }
9
16
  constructor(options) {
10
17
  const bounds = attribute("windfoilBounds", "vec4");
11
18
  const band = varying(attribute("windfoilBand", "vec4"), "vUltraWindfoilBand").setInterpolation("flat", "either");
@@ -1 +1 @@
1
- {"version":3,"file":"WindfoilMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilMaterial.ts"],"sourcesContent":["import { createWindfoilCoverage, windfoilVertexExtension, windfoilPixelBox } from './coverage.js'\nimport type { Node, StorageBufferNode, UniformNode } from 'three/webgpu'\nimport {\n Fn,\n If,\n abs,\n attribute,\n clamp,\n dFdy,\n float,\n max,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec3,\n vec4,\n} from 'three/tsl'\n\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n type GlyphVertexExtension,\n} from '../text/GlyphTextMaterial.js'\nimport { resolveTextTone } from '../text/tone.js'\n\n/** Storage buffers retained by one Windfoil outline atlas. */\nexport interface WindfoilStorage {\n /**\n * Three vec2 entries per xy-monotone quadratic piece. Each row stores its pieces\n * by descending x-maximum, followed by the same pieces by ascending x-minimum.\n */\n readonly curves: StorageBufferNode<'vec2'>\n /** Six uint entries per row: start, count, density, x-min, x-max and split bits. */\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMaterialOptions {\n shadowCutoff?: number\n layered?: boolean\n paintFunctions?: {\n evaluatePaint(index: Node<'uint'>, point: Node<'vec2'>, foreground: Node<'vec4'>): Node<'vec4'>\n }\n}\n\n/** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */\nexport class WindfoilMaterial extends GlyphTextMaterial {\n readonly shadowCutoff: UniformNode<'float', number> = uniform(0.5)\n\n constructor(options: WindfoilMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n // The band header's first row and row count, like the paint index below, are integers the\n // fragment truncates. Interpolated, an instance's constant can arrive a hair under itself\n // (Safari's relaxed math on Apple GPUs) and read the previous row: flat keeps them exact. Any\n // vertex of the glyph gives the same value, so `either` serves compatibility-mode devices.\n const band = varying(\n attribute<'vec4'>('windfoilBand', 'vec4'),\n 'vUltraWindfoilBand',\n ).setInterpolation('flat', 'either')\n const glyphPosition = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const layer = options.layered ? attribute<'vec4'>('windfoilLayer', 'vec4') : null\n const paintVarying = layer\n ? varying(layer.w, 'vUltraWindfoilPaint').setInterpolation('flat', 'either')\n : null\n // A tone model that dilates the outline: each glyph's dilation in pixels, below zero from\n // the size where the model stops. Its em is the font size the instance carries in\n // `sdfMeta.z`, whose sign belongs to the size switch. An instance without one, and every\n // colour layer, reads as text of no size: the outline stays where it is.\n const dilation = resolveTextTone(options.tone)?.dilationPx\n ? varyingProperty('float', 'vUltraWindfoilDilation')\n : null\n const extension: GlyphVertexExtension = dilation\n ? (...vertex) => {\n const meta = attribute<'vec3'>('sdfMeta', 'vec3')\n // Attribute nodes are shared by name, and the shared graph may have declared this\n // one two wide: its own identity keeps the third component.\n meta.getHash = () => String(meta.id)\n const em = abs(meta.z)\n // The tone's uniforms exist by the time a shader function first runs.\n return windfoilVertexExtension(bounds, glyphPosition, {\n law: this.tone!.dilation,\n em: layer ? em.mul(step(layer.w, 0.25)) : em,\n amount: dilation,\n })(...vertex)\n }\n : windfoilVertexExtension(bounds, glyphPosition)\n super(options, extension, layer ? { index: layer.z, center: layer.xy } : undefined)\n this.name = 'ultra-text TSL Windfoil text'\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n\n const { integrateFace, profileFace } = createWindfoilCoverage(options)\n const coverageOf = (grown: Node<'float'> | null): Node<'float'> =>\n Fn<Node<'float'>>(() => {\n // The integration box matches the pixel footprint's spread along each\n // outline axis: a box of width w has variance w²/12, as does the footprint\n // when w is the length of that axis's screen gradient. fwidth() would use\n // the footprint's bounding box, blurring rotated or sheared text by up to\n // √2 per axis. Axis-aligned text gets the same box either way.\n const dy = grown ? dFdy(glyphPosition) : undefined\n const pixel = windfoilPixelBox(glyphPosition, dy)\n let size = pixel\n let center: Node<'vec2'> = glyphPosition\n let area = pixel.x.mul(pixel.y)\n if (grown) {\n // A box 2d pixels larger, divided by one growth: a straight edge at x pixels from\n // the centre then covers clamp(0.5 + x + d), the exact coverage of the outline moved\n // out by d. Sampled d pixels lower on screen, edges facing down keep their place\n // and edges facing up rise by 2d. Empty pixels stay 0 and pixels inside the ink 1,\n // but where a corner faces down the box overhangs the ink on two sides: that pixel\n // row gets no dilation from the side, and at worst (1 + d) / (1 + 2d) of its ink.\n const amount = max(grown, 0).toConst()\n const growth = amount.mul(2).add(1).toConst()\n size = pixel.mul(growth).toConst()\n center = glyphPosition.sub(dy!.mul(amount)).toConst()\n area = area.mul(growth)\n }\n const integral = float(0).toVar('windfoilIntegral')\n // Glyphs of a few pixels use their ink profile, whatever the dilation.\n If(pixel.mul(3.7).greaterThanEqual(bounds.zw.sub(bounds.xy)).all(), () => {\n integral.assign(profileFace(band, bounds, center, size))\n }).Else(() => {\n integral.assign(integrateFace(band, bounds.y, center, size))\n })\n return clamp(abs(integral.div(area)), 0, 1)\n })()\n // The exact coverage: every shadow mask, and the beauty pass of the models that keep the\n // outline as it is.\n const coverage = coverageOf(null)\n // Beauty coverage of foreground text ink, toned from the instance colour or from a fill's\n // own colour. Colour layers, paint and every shadow mask keep the exact coverage, and\n // with `tone: false` this is that same node: the graph has no trace of the conversion.\n const tone = this.tone\n // A toned graph reads the exact coverage more than once. One local keeps the integral in\n // one place; a conditional would evaluate it again in each of its branches.\n const exact = tone ? (dilation ? coverageOf(dilation) : coverage).toConst() : coverage\n // The model's table stops where its dilation does.\n const gate = dilation ? step(0, dilation) : undefined\n const inked = (ink?: Node<'vec3'>): Node<'float'> => this.toned(exact, ink, gate)\n // Layered geometry also carries solid colour layers, which stay exact.\n const foreground = (ink?: Node<'vec3'>): Node<'float'> =>\n tone && paintVarying ? mix(exact, inked(ink), step(paintVarying, 0.25)) : inked(ink)\n\n if (paintVarying && options.paintFunctions) {\n // `toning` false rebuilds the exact paint, whose alpha the shadow mask keeps.\n const painted = (toning: boolean): Node<'vec4'> =>\n Fn<Node<'vec4'>>(() => {\n const own = toning ? exact : coverage\n const result = (\n vec4(this.colorVarying.rgb, own).toVar() as unknown as {\n setAssignable(value: boolean): Node<'vec4'>\n }\n ).setAssignable(true)\n If(own.greaterThan(0), () => {\n If(paintVarying.greaterThanEqual(2), () => {\n const encoded = options.paintFunctions!.evaluatePaint(\n uint(paintVarying.sub(2)),\n glyphPosition,\n vec4(0),\n )\n result.assign(\n vec4(\n srgbAttributeToWorking(vec3(encoded.rgb.div(max(encoded.a, 1e-6)))),\n encoded.a.mul(own),\n ),\n )\n }).ElseIf(paintVarying.lessThan(0.5), () => {\n if (this.fillNode)\n result.assign(\n vec4(\n this.fillNode.rgb,\n (toning ? inked(this.fillNode.rgb) : own).mul(clamp(this.fillNode.a, 0, 1)),\n ),\n )\n else if (toning) result.assign(vec4(this.colorVarying.rgb, inked()))\n })\n })\n return result\n })()\n // A shadow pass reads the exact paint alone, so it evaluates one paint.\n const exactPaint = painted(false)\n this.applyCoverage(\n coverage,\n exactPaint.a,\n this.shadowCutoff,\n tone ? painted(true) : exactPaint,\n !!tone,\n )\n } else if (paintVarying && this.fillNode) {\n const solid = paintVarying.greaterThan(0.5).toConst()\n const opacity = solid\n .select(float(1), clamp(this.fillNode.a, 0, 1))\n .context({ uniformFlow: true })\n .toConst()\n const alpha = coverage.mul(opacity).toConst()\n this.applyCoverage(\n coverage,\n alpha,\n this.shadowCutoff,\n vec4(\n solid.select(this.colorVarying.rgb, this.fillNode.rgb).context({ uniformFlow: true }),\n tone ? foreground(this.fillNode.rgb).mul(opacity).toConst() : alpha,\n ),\n !!tone,\n )\n } else {\n this.applyCoverage(\n foreground(this.fillNode?.rgb),\n coverage,\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n // Clip before the analytic coverage loops. A logical AND on the final mask\n // alone materializes coverage first, even for fragments outside the block.\n // Keep the test separate from derivative-dependent coverage: discard retains\n // helper invocations for derivatives at the surviving clip edge.\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;AAiDA,IAAa,mBAAb,cAAsC,kBAAkB;CACtD,eAAsD,QAAQ,EAAG;CAEjE,YAAY,SAAkC;EAC5C,MA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,aAAa,KAAK,CAAC,GACpF,OAAO,WAAW,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,IAAI,KAChE,GACA,CAAC,CAAC,IACJ;EACF,OACE,KAAK,cACH,WAAW,KAAK,UAAU,GAAG,GAC7B,UACA,KAAK,cACL,KAAA,GACA,CAAC,CAAC,IACJ;EAMF,MAAM,OAAO,SAAS;GACpB,KAAK,WAAW,IAAI,CAAC,CAAC,QAAQ;EAChC,CAAC,CAAC,CAAC;EACH,KAAK,WAAW,KAAK,SAAU,OAAO,IAAI;EAC1C,KAAK,iBAAiB,KAAK,eAAgB,OAAO,IAAI;CACxD;AACF"}
1
+ {"version":3,"file":"WindfoilMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilMaterial.ts"],"sourcesContent":["import { createWindfoilCoverage, windfoilVertexExtension, windfoilPixelBox } from './coverage.js'\nimport type { Node, StorageBufferNode, UniformNode } from 'three/webgpu'\nimport {\n Fn,\n If,\n abs,\n attribute,\n clamp,\n dFdy,\n float,\n max,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec3,\n vec4,\n} from 'three/tsl'\n\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n type GlyphVertexExtension,\n} from '../text/GlyphTextMaterial.js'\nimport { resolveTextTone } from '../text/tone.js'\n\n/** Storage buffers retained by one Windfoil outline atlas. */\nexport interface WindfoilStorage {\n /**\n * Three vec2 entries per xy-monotone quadratic piece. Each row stores its pieces\n * by descending x-maximum, followed by the same pieces by ascending x-minimum.\n */\n readonly curves: StorageBufferNode<'vec2'>\n /** Six uint entries per row: start, count, density, x-min, x-max and split bits. */\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMaterialOptions {\n shadowCutoff?: number\n layered?: boolean\n paintFunctions?: {\n evaluatePaint(index: Node<'uint'>, point: Node<'vec2'>, foreground: Node<'vec4'>): Node<'vec4'>\n }\n}\n\n/** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */\nexport class WindfoilMaterial extends GlyphTextMaterial {\n readonly #sc: UniformNode<'float', number> = uniform(0.5)\n\n get shadowCutoff(): UniformNode<'float', number> {\n return this.#sc\n }\n\n /** @internal */\n protected override copySubclassUniforms(target: this): void {\n target.shadowCutoff.value = this.#sc.value\n }\n\n constructor(options: WindfoilMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n // The band header's first row and row count, like the paint index below, are integers the\n // fragment truncates. Interpolated, an instance's constant can arrive a hair under itself\n // (Safari's relaxed math on Apple GPUs) and read the previous row: flat keeps them exact. Any\n // vertex of the glyph gives the same value, so `either` serves compatibility-mode devices.\n const band = varying(\n attribute<'vec4'>('windfoilBand', 'vec4'),\n 'vUltraWindfoilBand',\n ).setInterpolation('flat', 'either')\n const glyphPosition = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const layer = options.layered ? attribute<'vec4'>('windfoilLayer', 'vec4') : null\n const paintVarying = layer\n ? varying(layer.w, 'vUltraWindfoilPaint').setInterpolation('flat', 'either')\n : null\n // A tone model that dilates the outline: each glyph's dilation in pixels, below zero from\n // the size where the model stops. Its em is the font size the instance carries in\n // `sdfMeta.z`, whose sign belongs to the size switch. An instance without one, and every\n // colour layer, reads as text of no size: the outline stays where it is.\n const dilation = resolveTextTone(options.tone)?.dilationPx\n ? varyingProperty('float', 'vUltraWindfoilDilation')\n : null\n const extension: GlyphVertexExtension = dilation\n ? (...vertex) => {\n const meta = attribute<'vec3'>('sdfMeta', 'vec3')\n // Attribute nodes are shared by name, and the shared graph may have declared this\n // one two wide: its own identity keeps the third component.\n meta.getHash = () => String(meta.id)\n const em = abs(meta.z)\n // The tone's uniforms exist by the time a shader function first runs.\n return windfoilVertexExtension(bounds, glyphPosition, {\n law: this.tone!.dilation,\n em: layer ? em.mul(step(layer.w, 0.25)) : em,\n amount: dilation,\n })(...vertex)\n }\n : windfoilVertexExtension(bounds, glyphPosition)\n super(options, extension, layer ? { index: layer.z, center: layer.xy } : undefined)\n this.name = 'ultra-text TSL Windfoil text'\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n\n const { integrateFace, profileFace } = createWindfoilCoverage(options)\n const coverageOf = (grown: Node<'float'> | null): Node<'float'> =>\n Fn<Node<'float'>>(() => {\n // The integration box matches the pixel footprint's spread along each\n // outline axis: a box of width w has variance w²/12, as does the footprint\n // when w is the length of that axis's screen gradient. fwidth() would use\n // the footprint's bounding box, blurring rotated or sheared text by up to\n // √2 per axis. Axis-aligned text gets the same box either way.\n const dy = grown ? dFdy(glyphPosition) : undefined\n const pixel = windfoilPixelBox(glyphPosition, dy)\n let size = pixel\n let center: Node<'vec2'> = glyphPosition\n let area = pixel.x.mul(pixel.y)\n if (grown) {\n // A box 2d pixels larger, divided by one growth: a straight edge at x pixels from\n // the centre then covers clamp(0.5 + x + d), the exact coverage of the outline moved\n // out by d. Sampled d pixels lower on screen, edges facing down keep their place\n // and edges facing up rise by 2d. Empty pixels stay 0 and pixels inside the ink 1,\n // but where a corner faces down the box overhangs the ink on two sides: that pixel\n // row gets no dilation from the side, and at worst (1 + d) / (1 + 2d) of its ink.\n const amount = max(grown, 0).toConst()\n const growth = amount.mul(2).add(1).toConst()\n size = pixel.mul(growth).toConst()\n center = glyphPosition.sub(dy!.mul(amount)).toConst()\n area = area.mul(growth)\n }\n const integral = float(0).toVar('windfoilIntegral')\n // Glyphs of a few pixels use their ink profile, whatever the dilation.\n If(pixel.mul(3.7).greaterThanEqual(bounds.zw.sub(bounds.xy)).all(), () => {\n integral.assign(profileFace(band, bounds, center, size))\n }).Else(() => {\n integral.assign(integrateFace(band, bounds.y, center, size))\n })\n return clamp(abs(integral.div(area)), 0, 1)\n })()\n // The exact coverage: every shadow mask, and the beauty pass of the models that keep the\n // outline as it is.\n const coverage = coverageOf(null)\n // Beauty coverage of foreground text ink, toned from the instance colour or from a fill's\n // own colour. Colour layers, paint and every shadow mask keep the exact coverage, and\n // with `tone: false` this is that same node: the graph has no trace of the conversion.\n const tone = this.tone\n // A toned graph reads the exact coverage more than once. One local keeps the integral in\n // one place; a conditional would evaluate it again in each of its branches.\n const exact = tone ? (dilation ? coverageOf(dilation) : coverage).toConst() : coverage\n // The model's table stops where its dilation does.\n const gate = dilation ? step(0, dilation) : undefined\n const inked = (ink?: Node<'vec3'>): Node<'float'> => this.toned(exact, ink, gate)\n // Layered geometry also carries solid colour layers, which stay exact.\n const foreground = (ink?: Node<'vec3'>): Node<'float'> =>\n tone && paintVarying ? mix(exact, inked(ink), step(paintVarying, 0.25)) : inked(ink)\n\n if (paintVarying && options.paintFunctions) {\n // `toning` false rebuilds the exact paint, whose alpha the shadow mask keeps.\n const painted = (toning: boolean): Node<'vec4'> =>\n Fn<Node<'vec4'>>(() => {\n const own = toning ? exact : coverage\n const result = (\n vec4(this.colorVarying.rgb, own).toVar() as unknown as {\n setAssignable(value: boolean): Node<'vec4'>\n }\n ).setAssignable(true)\n If(own.greaterThan(0), () => {\n If(paintVarying.greaterThanEqual(2), () => {\n const encoded = options.paintFunctions!.evaluatePaint(\n uint(paintVarying.sub(2)),\n glyphPosition,\n vec4(0),\n )\n result.assign(\n vec4(\n srgbAttributeToWorking(vec3(encoded.rgb.div(max(encoded.a, 1e-6)))),\n encoded.a.mul(own),\n ),\n )\n }).ElseIf(paintVarying.lessThan(0.5), () => {\n if (this.fillNode)\n result.assign(\n vec4(\n this.fillNode.rgb,\n (toning ? inked(this.fillNode.rgb) : own).mul(clamp(this.fillNode.a, 0, 1)),\n ),\n )\n else if (toning) result.assign(vec4(this.colorVarying.rgb, inked()))\n })\n })\n return result\n })()\n // A shadow pass reads the exact paint alone, so it evaluates one paint.\n const exactPaint = painted(false)\n this.applyCoverage(\n coverage,\n exactPaint.a,\n this.shadowCutoff,\n tone ? painted(true) : exactPaint,\n !!tone,\n )\n } else if (paintVarying && this.fillNode) {\n const solid = paintVarying.greaterThan(0.5).toConst()\n const opacity = solid\n .select(float(1), clamp(this.fillNode.a, 0, 1))\n .context({ uniformFlow: true })\n .toConst()\n const alpha = coverage.mul(opacity).toConst()\n this.applyCoverage(\n coverage,\n alpha,\n this.shadowCutoff,\n vec4(\n solid.select(this.colorVarying.rgb, this.fillNode.rgb).context({ uniformFlow: true }),\n tone ? foreground(this.fillNode.rgb).mul(opacity).toConst() : alpha,\n ),\n !!tone,\n )\n } else {\n this.applyCoverage(\n foreground(this.fillNode?.rgb),\n coverage,\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n // Clip before the analytic coverage loops. A logical AND on the final mask\n // alone materializes coverage first, even for fragments outside the block.\n // Keep the test separate from derivative-dependent coverage: discard retains\n // helper invocations for derivatives at the surviving clip edge.\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;AAiDA,IAAa,mBAAb,cAAsC,kBAAkB;CACtD,MAA6C,QAAQ,EAAG;CAExD,IAAI,eAA6C;EAC/C,OAAO,KAAK;CACd;;CAGA,qBAAwC,QAAoB;EAC1D,OAAO,aAAa,QAAQ,KAAK,IAAI;CACvC;CAEA,YAAY,SAAkC;EAC5C,MAAM,SAAS,UAAkB,kBAAkB,MAAM;EAKzD,MAAM,OAAO,QACX,UAAkB,gBAAgB,MAAM,GACxC,oBACF,CAAC,CAAC,iBAAiB,QAAQ,QAAQ;EACnC,MAAM,gBAAgB,gBAAgB,QAAQ,wBAAwB;EACtE,MAAM,QAAQ,QAAQ,UAAU,UAAkB,iBAAiB,MAAM,IAAI;EAC7E,MAAM,eAAe,QACjB,QAAQ,MAAM,GAAG,qBAAqB,CAAC,CAAC,iBAAiB,QAAQ,QAAQ,IACzE;EAKJ,MAAM,WAAW,gBAAgB,QAAQ,IAAI,CAAC,EAAE,aAC5C,gBAAgB,SAAS,wBAAwB,IACjD;EACJ,MAAM,YAAk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,0 +1,2 @@
1
+ export declare function throwIfAborted(signal?: AbortSignal): void;
2
+ export declare function abortable<T>(promise: PromiseLike<T>, signal?: AbortSignal): Promise<T>;
@@ -0,0 +1,26 @@
1
+ // src/windfoil/abortable.ts
2
+ function throwIfAborted(signal) {
3
+ if (signal?.aborted) throw signal.reason ?? new DOMException("The Windfoil build was aborted", "AbortError");
4
+ }
5
+ function abortable(promise, signal) {
6
+ throwIfAborted(signal);
7
+ if (!signal) return Promise.resolve(promise);
8
+ return new Promise((resolve, reject) => {
9
+ const cleanup = () => signal.removeEventListener("abort", abort);
10
+ const abort = () => {
11
+ cleanup();
12
+ reject(signal.reason ?? new DOMException("The Windfoil build was aborted", "AbortError"));
13
+ };
14
+ signal.addEventListener("abort", abort, { once: true });
15
+ Promise.resolve(promise).then((value) => {
16
+ cleanup();
17
+ resolve(value);
18
+ }, (error) => {
19
+ cleanup();
20
+ reject(error);
21
+ });
22
+ });
23
+ }
24
+ export { abortable, throwIfAborted };
25
+
26
+ //# sourceMappingURL=abortable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortable.js","names":[],"sources":["../../src/windfoil/abortable.ts"],"sourcesContent":["export function throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted)\n throw signal.reason ?? new DOMException('The Windfoil build was aborted', 'AbortError')\n}\n\nexport function abortable<T>(promise: PromiseLike<T>, signal?: AbortSignal): Promise<T> {\n throwIfAborted(signal)\n if (!signal) return Promise.resolve(promise)\n return new Promise<T>((resolve, reject) => {\n const cleanup = (): void => signal.removeEventListener('abort', abort)\n const abort = (): void => {\n cleanup()\n // Caller-defined AbortSignal reasons propagate verbatim.\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(signal.reason ?? new DOMException('The Windfoil build was aborted', 'AbortError'))\n }\n signal.addEventListener('abort', abort, { once: true })\n void Promise.resolve(promise).then(\n (value) => {\n cleanup()\n resolve(value)\n },\n (error: unknown) => {\n cleanup()\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error)\n },\n )\n })\n}\n"],"mappings":";AAAA,SAAgB,eAAe,QAA4B;CACzD,IAAI,QAAQ,SACV,MAAM,OAAO,UAAU,IAAI,aAAa,kCAAkC,YAAY;AAC1F;AAEA,SAAgB,UAAa,SAAyB,QAAkC;CACtF,eAAe,MAAM;CACrB,IAAI,CAAC,QAAQ,OAAO,QAAQ,QAAQ,OAAO;CAC3C,OAAO,IAAI,SAAY,SAAS,WAAW;EACzC,MAAM,gBAAsB,OAAO,oBAAoB,SAAS,KAAK;EACrE,MAAM,cAAoB;GACxB,QAAQ;GAGR,OAAO,OAAO,UAAU,IAAI,aAAa,kCAAkC,YAAY,CAAC;EAC1F;EACA,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACtD,QAAa,QAAQ,OAAO,CAAC,CAAC,MAC3B,UAAU;GACT,QAAQ;GACR,QAAQ,KAAK;EACf,IACC,UAAmB;GAClB,QAAQ;GAER,OAAO,KAAK;EACd,CACF;CACF,CAAC;AACH"}
@@ -1,4 +1,5 @@
1
- import { disposeWindfoilStorage, throwIfAborted } from "./storage.js";
1
+ import { throwIfAborted } from "./abortable.js";
2
+ import { disposeWindfoilStorage } from "./storage.js";
2
3
  import { createWindfoilCompositeGeometry, updateWindfoilCompositeGeometry, windfoilCompositeContentFits } from "./compositeGeometry.js";
3
4
  import { floatBits, normalizeWindfoilPaint, packWindfoilPaints } from "./paint.js";
4
5
  import { WINDFOIL_TEXT_INDEX, appendWindfoilLayerGrids, windfoilPaintOpaque } from "./layerGrid.js";
@@ -1 +1 @@
1
- {"version":3,"file":"color.js","names":[],"sources":["../../src/windfoil/color.ts"],"sourcesContent":["import {\n StorageBufferAttribute,\n type InstancedBufferGeometry,\n type StorageBufferNode,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type { WindfoilOptions } from '../types.js'\nimport type {\n WindfoilGlyphHeader,\n WindfoilLayerHeader,\n WindfoilPreprocessResult,\n} from './preprocess.js'\nimport type { WindfoilMaterialOptions, WindfoilStorage } from './WindfoilMaterial.js'\nimport { WindfoilCompositeMaterial } from './WindfoilCompositeMaterial.js'\nimport {\n createWindfoilCompositeGeometry,\n updateWindfoilCompositeGeometry,\n windfoilCompositeContentFits,\n type WindfoilCompositeHeader,\n type WindfoilCompositeLayout,\n} from './compositeGeometry.js'\nimport { normalizeWindfoilPaint, packWindfoilPaints, floatBits } from './paint.js'\nimport { createWindfoilPaintFunctions } from './paintNodes.js'\nimport { disposeWindfoilStorage, throwIfAborted } from './storage.js'\nimport {\n appendWindfoilLayerGrids,\n windfoilPaintOpaque,\n WINDFOIL_TEXT_INDEX,\n type WindfoilIndexTuning,\n} from './layerGrid.js'\n\nexport interface WindfoilColorPart {\n readonly glyphs: ReadonlyMap<string, WindfoilCompositeHeader>\n createGeometry(\n snapshot: WindfoilCompositeLayout,\n padding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n padding: number,\n ordinals?: Float32Array,\n ): number | null\n contentFits(geometry: InstancedBufferGeometry, snapshot: WindfoilCompositeLayout): boolean\n createMaterial(\n options: Omit<WindfoilMaterialOptions, 'curves' | 'rows'>,\n ): WindfoilCompositeMaterial\n}\nexport interface WindfoilColorResources {\n readonly storageBytes: number\n readonly paintFunctions: ReturnType<typeof createWindfoilPaintFunctions>\n readonly composite: WindfoilColorPart | null\n readonly plainGlyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n dispose(): void\n}\n/** Pack paint rows and glyph layers in stable key/paint order before allocating. */\nexport function packWindfoilLayers(prepared: WindfoilPreprocessResult, signal?: AbortSignal) {\n const all: WindfoilLayerHeader[] = []\n const glyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of prepared.glyphs) {\n if (!header.layers) continue\n throwIfAborted(signal)\n const first = all.length\n all.push(...header.layers)\n glyphs.set(key, { ...header, layerStart: first, layerCount: all.length - first })\n }\n const normalized = new Array<ReturnType<typeof normalizeWindfoilPaint>>(all.length)\n let solidOnly = true\n for (let index = 0; index < all.length; index++) {\n if ((index & 255) === 0) throwIfAborted(signal)\n const layer = all[index]!\n const paint = normalizeWindfoilPaint(layer.paint, layer.paintLabel)\n normalized[index] = paint\n if (paint.kind >= 2) solidOnly = false\n }\n const packed = packWindfoilPaints(normalized)\n const table = new Uint32Array(all.length * 12),\n opaque: number[] = []\n let tableWords = 0\n const liveGlyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of glyphs) {\n const first = tableWords / 12\n const clip = header.clipBox,\n box = header.bbox\n const clippedOut =\n !!clip &&\n (Math.max(box[0], clip[0]) >= Math.min(box[2], clip[2]) ||\n Math.max(box[1], clip[1]) >= Math.min(box[3], clip[3]))\n const live: WindfoilLayerHeader[] = []\n let monotonePieceCount = 0\n for (let i = header.layerStart; i < header.layerStart + header.layerCount; i++) {\n const layer = all[i]!,\n paint = normalized[i]!,\n paintIndex = packed.indices[i]!\n if (paint.alphaMax === 0 || clippedOut) continue\n layer.paintIndex = paintIndex\n live.push(layer)\n monotonePieceCount += layer.monotonePieceCount\n opaque.push(windfoilPaintOpaque(paint) ? 1 : 0)\n const layerBox = layer.bbox\n table[tableWords] = layer.rowBase\n table[tableWords + 1] = layer.bandCount\n table[tableWords + 2] = floatBits(layer.bandH)\n table[tableWords + 3] = floatBits(layer.invH)\n table[tableWords + 4] = floatBits(layerBox[0])\n table[tableWords + 5] = floatBits(layerBox[1])\n table[tableWords + 6] = floatBits(layerBox[2])\n table[tableWords + 7] = floatBits(layerBox[3])\n table[tableWords + 8] = paintIndex\n table[tableWords + 9] = (layer.paintKind === 0 ? 1 : 0) | (layer.transposed ? 2 : 0)\n table[tableWords + 10] = floatBits(paint.alphaMax)\n tableWords += 12\n }\n const amended = {\n ...header,\n layers: live,\n layerStart: first,\n layerCount: tableWords / 12 - first,\n monotonePieceCount,\n }\n liveGlyphs.set(key, amended)\n // Prepared is private build state. Drop invisible gradient instances before geometry.\n ;(prepared.glyphs as Map<string, WindfoilGlyphHeader>).set(key, amended)\n }\n return {\n ...packed,\n solidOnly,\n layers: tableWords === table.length ? table : table.slice(0, tableWords),\n opaque,\n glyphs: liveGlyphs,\n }\n}\n\nexport function buildWindfoilColorResources(\n renderer: WebGPURenderer,\n prepared: WindfoilPreprocessResult,\n options: WindfoilOptions,\n coverage: WindfoilStorage,\n signal?: AbortSignal,\n artwork = false,\n): WindfoilColorResources {\n const packed = packWindfoilLayers(prepared, signal)\n throwIfAborted(signal)\n const attributes: StorageBufferAttribute[] = []\n const allocate = (data: Uint32Array, name: string): StorageBufferNode<'uint'> => {\n const attribute = new StorageBufferAttribute(data.length ? data : new Uint32Array(1), 1)\n attributes.push(attribute)\n return storage(attribute, 'uint', attribute.count).toReadOnly().setName(name)\n }\n try {\n const paints = allocate(packed.paints, 'ultraWindfoilPaints'),\n stops = allocate(packed.stops, 'ultraWindfoilStops')\n const paintFunctions = createWindfoilPaintFunctions({\n paints,\n stops,\n solidOnly: packed.solidOnly,\n })\n const compositeGlyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of packed.glyphs) {\n if (options.compositing === 'shader' || !!header.clipBox) {\n compositeGlyphs.set(key, header)\n }\n }\n const index = (tuning: WindfoilIndexTuning) =>\n appendWindfoilLayerGrids(\n packed.layers,\n compositeGlyphs.values(),\n prepared,\n packed.opaque,\n signal,\n tuning,\n )\n let table = compositeGlyphs.size ? index(artwork ? {} : WINDFOIL_TEXT_INDEX) : null\n // Past the device's binding limit, keep one unsplit cell per glyph: slower, never unbound.\n const limit = (\n renderer.backend as { device?: { limits: { maxStorageBufferBindingSize: number } } }\n ).device?.limits.maxStorageBufferBindingSize\n if (table && limit && table.byteLength > limit) table = index({ maxNodes: 1 })\n const layers = table ? allocate(table, 'ultraWindfoilLayers') : null\n const composite: WindfoilColorPart | null = layers\n ? {\n glyphs: compositeGlyphs,\n createGeometry(snapshot, padding, ordinals) {\n return createWindfoilCompositeGeometry(snapshot, compositeGlyphs, padding, ordinals)\n },\n updateGeometry(geometry, snapshot, padding, ordinals) {\n return updateWindfoilCompositeGeometry(\n geometry,\n snapshot,\n compositeGlyphs,\n padding,\n ordinals,\n )\n },\n contentFits(geometry, snapshot) {\n return windfoilCompositeContentFits(geometry, snapshot, compositeGlyphs)\n },\n createMaterial(materialOptions) {\n return new WindfoilCompositeMaterial({\n ...coverage,\n ...materialOptions,\n layers,\n paintFunctions,\n })\n },\n }\n : null\n let plainGlyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n if (layers) {\n const filtered = new Map<string, WindfoilGlyphHeader>()\n for (const [key, header] of prepared.glyphs) {\n if (!compositeGlyphs.has(key)) filtered.set(key, header)\n }\n plainGlyphs = filtered\n } else {\n plainGlyphs = prepared.glyphs\n }\n let disposed = false\n return {\n paintFunctions,\n composite,\n plainGlyphs,\n storageBytes: packed.paints.byteLength + packed.stops.byteLength + (table?.byteLength ?? 0),\n dispose() {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n },\n }\n } catch (error) {\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n throw error\n }\n}\n"],"mappings":";;;;;;;;;;AA0DA,SAAgB,mBAAmB,UAAoC,QAAsB;CAC3F,MAAM,MAA6B,CAAC;CACpC,MAAM,yBAAS,IAAI,IAAqC;CACxD,KAAK,MAAM,CAAC,KAAK,WAAW,SAAS,QAAQ;EAC3C,IAAI,CAAC,OAAO,QAAQ;EACpB,eAAe,MAAM;EACrB,MAAM,QAAQ,IAAI;EAClB,IAAI,KAAK,GAAG,OAAO,MAAM;EACzB,OAAO,IAAI,KAAK;GAAE,GAAG;GAAQ,YAAY;GAAO,YAAY,IAAI,SAAS;EAAM,CAAC;CAClF;CACA,MAAM,aAAa,IAAI,MAAiD,IAAI,MAAM;CAClF,IAAI,YAAY;CAChB,KAAK,IAAI,QAAQ,GAAG,QAAQ,IA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version":3,"file":"color.js","names":[],"sources":["../../src/windfoil/color.ts"],"sourcesContent":["import {\n StorageBufferAttribute,\n type InstancedBufferGeometry,\n type StorageBufferNode,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type { WindfoilOptions } from '../types.js'\nimport type {\n WindfoilGlyphHeader,\n WindfoilLayerHeader,\n WindfoilPreprocessResult,\n} from './preprocess.js'\nimport type { WindfoilMaterialOptions, WindfoilStorage } from './WindfoilMaterial.js'\nimport { WindfoilCompositeMaterial } from './WindfoilCompositeMaterial.js'\nimport {\n createWindfoilCompositeGeometry,\n updateWindfoilCompositeGeometry,\n windfoilCompositeContentFits,\n type WindfoilCompositeHeader,\n type WindfoilCompositeLayout,\n} from './compositeGeometry.js'\nimport { normalizeWindfoilPaint, packWindfoilPaints, floatBits } from './paint.js'\nimport { createWindfoilPaintFunctions } from './paintNodes.js'\nimport { disposeWindfoilStorage, throwIfAborted } from './storage.js'\nimport {\n appendWindfoilLayerGrids,\n windfoilPaintOpaque,\n WINDFOIL_TEXT_INDEX,\n type WindfoilIndexTuning,\n} from './layerGrid.js'\n\nexport interface WindfoilColorPart {\n readonly glyphs: ReadonlyMap<string, WindfoilCompositeHeader>\n createGeometry(\n snapshot: WindfoilCompositeLayout,\n padding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n padding: number,\n ordinals?: Float32Array,\n ): number | null\n contentFits(geometry: InstancedBufferGeometry, snapshot: WindfoilCompositeLayout): boolean\n createMaterial(\n options: Omit<WindfoilMaterialOptions, 'curves' | 'rows'>,\n ): WindfoilCompositeMaterial\n}\nexport interface WindfoilColorResources {\n readonly storageBytes: number\n readonly paintFunctions: ReturnType<typeof createWindfoilPaintFunctions>\n readonly composite: WindfoilColorPart | null\n readonly plainGlyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n dispose(): void\n}\n/** Pack paint rows and glyph layers in stable key/paint order before allocating. */\nexport function packWindfoilLayers(prepared: WindfoilPreprocessResult, signal?: AbortSignal) {\n const all: WindfoilLayerHeader[] = []\n const glyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of prepared.glyphs) {\n if (!header.layers) continue\n throwIfAborted(signal)\n const first = all.length\n all.push(...header.layers)\n glyphs.set(key, { ...header, layerStart: first, layerCount: all.length - first })\n }\n const normalized = new Array<ReturnType<typeof normalizeWindfoilPaint>>(all.length)\n let solidOnly = true\n for (let index = 0; index < all.length; index++) {\n if ((index & 255) === 0) throwIfAborted(signal)\n const layer = all[index]!\n const paint = normalizeWindfoilPaint(layer.paint, layer.paintLabel)\n normalized[index] = paint\n if (paint.kind >= 2) solidOnly = false\n }\n const packed = packWindfoilPaints(normalized)\n const table = new Uint32Array(all.length * 12),\n opaque: number[] = []\n let tableWords = 0\n const liveGlyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of glyphs) {\n const first = tableWords / 12\n const clip = header.clipBox,\n box = header.bbox\n const clippedOut =\n !!clip &&\n (Math.max(box[0], clip[0]) >= Math.min(box[2], clip[2]) ||\n Math.max(box[1], clip[1]) >= Math.min(box[3], clip[3]))\n const live: WindfoilLayerHeader[] = []\n let monotonePieceCount = 0\n for (let i = header.layerStart; i < header.layerStart + header.layerCount; i++) {\n const layer = all[i]!,\n paint = normalized[i]!,\n paintIndex = packed.indices[i]!\n if (paint.alphaMax === 0 || clippedOut) continue\n layer.paintIndex = paintIndex\n live.push(layer)\n monotonePieceCount += layer.monotonePieceCount\n opaque.push(windfoilPaintOpaque(paint) ? 1 : 0)\n const layerBox = layer.bbox\n table[tableWords] = layer.rowBase\n table[tableWords + 1] = layer.bandCount\n table[tableWords + 2] = floatBits(layer.bandH)\n table[tableWords + 3] = floatBits(layer.invH)\n table[tableWords + 4] = floatBits(layerBox[0])\n table[tableWords + 5] = floatBits(layerBox[1])\n table[tableWords + 6] = floatBits(layerBox[2])\n table[tableWords + 7] = floatBits(layerBox[3])\n table[tableWords + 8] = paintIndex\n table[tableWords + 9] = (layer.paintKind === 0 ? 1 : 0) | (layer.transposed ? 2 : 0)\n table[tableWords + 10] = floatBits(paint.alphaMax)\n tableWords += 12\n }\n const amended = {\n ...header,\n layers: live,\n layerStart: first,\n layerCount: tableWords / 12 - first,\n monotonePieceCount,\n }\n liveGlyphs.set(key, amended)\n // Prepared is private build state. Drop invisible gradient instances before geometry.\n ;(prepared.glyphs as Map<string, WindfoilGlyphHeader>).set(key, amended)\n }\n return {\n ...packed,\n solidOnly,\n layers: tableWords === table.length ? table : table.slice(0, tableWords),\n opaque,\n glyphs: liveGlyphs,\n }\n}\n\nexport function buildWindfoilColorResources(\n renderer: WebGPURenderer,\n prepared: WindfoilPreprocessResult,\n options: WindfoilOptions,\n coverage: WindfoilStorage,\n signal?: AbortSignal,\n artwork = false,\n): WindfoilColorResources {\n const packed = packWindfoilLayers(prepared, signal)\n throwIfAborted(signal)\n const attributes: StorageBufferAttribute[] = []\n const allocate = (data: Uint32Array, name: string): StorageBufferNode<'uint'> => {\n const attribute = new StorageBufferAttribute(data.length ? data : new Uint32Array(1), 1)\n attributes.push(attribute)\n return storage(attribute, 'uint', attribute.count).toReadOnly().setName(name)\n }\n try {\n const paints = allocate(packed.paints, 'ultraWindfoilPaints'),\n stops = allocate(packed.stops, 'ultraWindfoilStops')\n const paintFunctions = createWindfoilPaintFunctions({\n paints,\n stops,\n solidOnly: packed.solidOnly,\n })\n const compositeGlyphs = new Map<string, WindfoilCompositeHeader>()\n for (const [key, header] of packed.glyphs) {\n if (options.compositing === 'shader' || !!header.clipBox) {\n compositeGlyphs.set(key, header)\n }\n }\n const index = (tuning: WindfoilIndexTuning) =>\n appendWindfoilLayerGrids(\n packed.layers,\n compositeGlyphs.values(),\n prepared,\n packed.opaque,\n signal,\n tuning,\n )\n let table = compositeGlyphs.size ? index(artwork ? {} : WINDFOIL_TEXT_INDEX) : null\n // Past the device's binding limit, keep one unsplit cell per glyph: slower, never unbound.\n const limit = (\n renderer.backend as { device?: { limits: { maxStorageBufferBindingSize: number } } }\n ).device?.limits.maxStorageBufferBindingSize\n if (table && limit && table.byteLength > limit) table = index({ maxNodes: 1 })\n const layers = table ? allocate(table, 'ultraWindfoilLayers') : null\n const composite: WindfoilColorPart | null = layers\n ? {\n glyphs: compositeGlyphs,\n createGeometry(snapshot, padding, ordinals) {\n return createWindfoilCompositeGeometry(snapshot, compositeGlyphs, padding, ordinals)\n },\n updateGeometry(geometry, snapshot, padding, ordinals) {\n return updateWindfoilCompositeGeometry(\n geometry,\n snapshot,\n compositeGlyphs,\n padding,\n ordinals,\n )\n },\n contentFits(geometry, snapshot) {\n return windfoilCompositeContentFits(geometry, snapshot, compositeGlyphs)\n },\n createMaterial(materialOptions) {\n return new WindfoilCompositeMaterial({\n ...coverage,\n ...materialOptions,\n layers,\n paintFunctions,\n })\n },\n }\n : null\n let plainGlyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n if (layers) {\n const filtered = new Map<string, WindfoilGlyphHeader>()\n for (const [key, header] of prepared.glyphs) {\n if (!compositeGlyphs.has(key)) filtered.set(key, header)\n }\n plainGlyphs = filtered\n } else {\n plainGlyphs = prepared.glyphs\n }\n let disposed = false\n return {\n paintFunctions,\n composite,\n plainGlyphs,\n storageBytes: packed.paints.byteLength + packed.stops.byteLength + (table?.byteLength ?? 0),\n dispose() {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n },\n }\n } catch (error) {\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n throw error\n }\n}\n"],"mappings":";;;;;;;;;;;AA0DA,SAAgB,mBAAmB,UAAoC,QAAsB;CAC3F,MAAM,MAA6B,CAAC;CACpC,MAAM,yBAAS,IAAI,IAAqC;CACxD,KAAK,MAAM,CAAC,KAAK,WAAW,SAAS,QAAQ;EAC3C,IAAI,CAAC,OAAO,QAAQ;EACpB,eAAe,MAAM;EACrB,MAAM,QAAQ,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aAAa,OAAO,MAAM,cAAc,OAAO,cAAc;GACzF,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,KAAK,MAAM,aAAa,YAAY,uBAAuB,UAAU,SAAS;GAChF;EACF;CACF,SAAS,OAAO;EACd,KAAK,MAAM,aAAa,YAAY,uBAAuB,UAAU,SAAS;EAC9E,MAAM;CACR;AACF"}
@@ -1,25 +1,8 @@
1
- import type { Node, UniformNode } from 'three/webgpu';
1
+ import type { Node } from 'three/webgpu';
2
2
  import type { GlyphVertexExtension } from '../text/GlyphTextMaterial.js';
3
+ import { windfoilKernelSkirt, type WindfoilDilation } from './skirt.js';
3
4
  import type { WindfoilStorage } from './WindfoilMaterial.js';
4
- /**
5
- * The skirt of the pass being drawn, in pixels: one uniform for every Windfoil material, set
6
- * from the pass's sample count at each render, whenever its shader was compiled. The count is
7
- * that of the target the pass draws into: a render target, three's frame buffer target in its
8
- * place, or else an output render target; the renderer's own count only without any.
9
- */
10
- export declare function windfoilKernelSkirt(): UniformNode<'float', number>;
11
- /** What a tone model that dilates the outline adds to the quad of each glyph. */
12
- export interface WindfoilDilation {
13
- /** (ems, pixels at most, pixels per em from which it stops): `TextTone.dilation`. */
14
- readonly law: Node<'vec3'>;
15
- /** The glyph's font size in local units; zero where the outline must stay as it is. */
16
- readonly em: Node<'float'>;
17
- /**
18
- * Receives the glyph's dilation in pixels of the pass being drawn, for its fragments; below
19
- * zero from the size where the model stops.
20
- */
21
- readonly amount: Node<'float'>;
22
- }
5
+ export { windfoilKernelSkirt, type WindfoilDilation };
23
6
  export declare function windfoilVertexExtension(bounds: Node<'vec4'>, glyphPosition: Node<'vec2'>, dilation?: WindfoilDilation): GlyphVertexExtension;
24
7
  export declare function createWindfoilCoverage(storage: WindfoilStorage): {
25
8
  integrateFace: import("three/tsl").FnNode<[import("three/webgpu").Vector4 | Node<"vec4">, number | Node<"float"> | Node<"uint">, import("three/webgpu").Vector2 | Node<"vec2">, import("three/webgpu").Vector2 | Node<"vec2">], Node<"float">>;
@@ -1,4 +1,5 @@
1
- import { Break, Continue, Fn, If, Loop, abs, bitcast, cameraProjectionMatrix, clamp, dFdx, dFdy, dot, float, floor, length, max, min, mix, modelViewMatrix, renderGroup, step, uint, uniform, vec2, vec4, viewportSize, wgslFn } from "three/tsl";
1
+ import { windfoilKernelSkirt } from "./skirt.js";
2
+ import { Break, Continue, Fn, If, Loop, abs, bitcast, cameraProjectionMatrix, clamp, dFdx, dFdy, dot, float, floor, length, max, min, mix, modelViewMatrix, step, uint, vec2, vec4, viewportSize, wgslFn } from "three/tsl";
2
3
  // src/windfoil/coverage.ts
3
4
  var integratePiece = wgslFn(`
4
5
  fn windfoil_integrate_piece(q1: vec2f, q2: vec2f, q3: vec2f, lo: f32, hi: f32, hx: f32) -> f32 {
@@ -64,22 +65,7 @@ fn windfoil_band_window(origin: f32, halfY: f32, height: f32, count: u32, band:
64
65
  }
65
66
  `);
66
67
  var ROW_STRIDE = 6;
67
- var KERNEL_SKIRT_PX = .5625;
68
- var MULTISAMPLE_SKIRT_PX = .9375;
69
68
  var SKIRT_MAX_SCALE = 16;
70
- var kernelSkirt;
71
- /**
72
- * The skirt of the pass being drawn, in pixels: one uniform for every Windfoil material, set
73
- * from the pass's sample count at each render, whenever its shader was compiled. The count is
74
- * that of the target the pass draws into: a render target, three's frame buffer target in its
75
- * place, or else an output render target; the renderer's own count only without any.
76
- */
77
- function windfoilKernelSkirt() {
78
- return kernelSkirt ??= uniform(KERNEL_SKIRT_PX).setName("ultraWindfoilSkirt").setGroup(renderGroup).onRenderUpdate(({ renderer }) => {
79
- const target = renderer?.getRenderTarget() ?? renderer?.getOutputRenderTarget();
80
- return (target ? target.samples : renderer?.currentSamples ?? 0) >= 4 ? MULTISAMPLE_SKIRT_PX : KERNEL_SKIRT_PX;
81
- });
82
- }
83
69
  function windfoilVertexExtension(bounds, glyphPosition, dilation) {
84
70
  const modelViewProjection = cameraProjectionMatrix.mul(modelViewMatrix);
85
71
  return (quad, rect, position, depth, motionScale) => {
@@ -160,7 +146,8 @@ function createWindfoilCoverage(storage) {
160
146
  const split = bitcast(rows.element(row.add(5)), "float").toConst();
161
147
  const leftward = center.x.lessThan(split).toConst();
162
148
  const leftF = float(leftward).toConst();
163
- const listStart = uint(rows.element(row)).add(uint(leftward).mul(pieceCount)).toConst();
149
+ const listStart = uint(rows.element(row)).add(uint(leftward).mul(pieceCount)).mul(uint(3)).toConst();
150
+ const q2Base = listStart.add(pieceCount.shiftLeft(uint(1))).toConst();
164
151
  const direction = float(1).sub(leftF.mul(2)).toConst();
165
152
  const bandAcc = localVar(float(0));
166
153
  Loop({
@@ -168,9 +155,9 @@ function createWindfoilCoverage(storage) {
168
155
  end: pieceCount,
169
156
  type: "uint"
170
157
  }, ({ i: k }) => {
171
- const base = listStart.add(k).mul(3).toConst();
158
+ const base = listStart.add(k.shiftLeft(uint(1))).toConst();
172
159
  const q1 = vec2(curves.element(base)).sub(center).toConst();
173
- const q3 = vec2(curves.element(base.add(2))).sub(center).toConst();
160
+ const q3 = vec2(curves.element(base.add(uint(1)))).sub(center).toConst();
174
161
  const sx1 = q1.x.mul(direction).toConst();
175
162
  const sx3 = q3.x.mul(direction).toConst();
176
163
  If(max(sx1, sx3).lessThanEqual(halfX.negate()), () => {
@@ -194,7 +181,7 @@ function createWindfoilCoverage(storage) {
194
181
  bandAcc.addAssign(clamp(sx1.add(sx3).mul(.5), halfX.negate(), halfX).add(halfX).mul(rise));
195
182
  Continue();
196
183
  });
197
- const q2 = vec2(curves.element(base.add(1))).sub(center).toConst();
184
+ const q2 = vec2(curves.element(q2Base.add(k))).sub(center).toConst();
198
185
  bandAcc.addAssign(integratePiece({
199
186
  q1: vec2(sx1, q1.y),
200
187
  q2: vec2(q2.x.mul(direction), q2.y),
@@ -1 +1 @@
1
- {"version":3,"file":"coverage.js","names":[],"sources":["../../src/windfoil/coverage.ts"],"sourcesContent":["import type { Node, UniformNode } from 'three/webgpu'\nimport {\n Break,\n Continue,\n Fn,\n If,\n Loop,\n abs,\n bitcast,\n cameraProjectionMatrix,\n clamp,\n dFdx,\n dFdy,\n dot,\n float,\n floor,\n length,\n max,\n min,\n mix,\n modelViewMatrix,\n renderGroup,\n step,\n uint,\n uniform,\n vec2,\n vec4,\n viewportSize,\n wgslFn,\n} from 'three/tsl'\n\nimport type { GlyphVertexExtension } from '../text/GlyphTextMaterial.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n\n/*\n * Adapted from texel-org/windfoil's Apache-2.0 reference implementation,\n * src/windfoil.wgsl (Matt DesLauriers, 2026). The CPU prepass guarantees that\n * each quadratic passed here is monotone in x and y, and the caller mirrors x so\n * that the walk always runs toward -x. This closed form computes the piece's\n * contribution to the pixel's winding integral: one vec4 root solve gives the\n * parameters where the piece meets the row window and the pixel's two sides.\n * `lo` and `hi` are the window already cut to the piece's own extent, so the\n * piece is at `lo` and `hi` exactly at the first two of those parameters.\n */\nconst integratePiece = wgslFn<{\n q1: Node<'vec2'>\n q2: Node<'vec2'>\n q3: Node<'vec2'>\n lo: Node<'float'>\n hi: Node<'float'>\n hx: Node<'float'>\n}>(`\nfn windfoil_integrate_piece(q1: vec2f, q2: vec2f, q3: vec2f, lo: f32, hi: f32, hx: f32) -> f32 {\n let a2 = q1 - 2.0 * q2 + q3;\n let b1 = q2 - q1;\n let y_rising = q3.y >= q1.y;\n let x_rising = q3.x >= q1.x;\n let A2 = a2.yyxx;\n let B1 = b1.yyxx;\n let V = vec4f(\n select(vec2f(hi, lo), vec2f(lo, hi), y_rising),\n select(vec2f(hx, -hx), vec2f(-hx, hx), x_rising)\n );\n let R = vec2<bool>(y_rising, x_rising).xxyy;\n let C = q1.yyxx - V;\n let sat0 = select(C <= vec4f(0.0), C >= vec4f(0.0), R);\n let sat1 = select(q3.yyxx >= V, q3.yyxx <= V, R);\n let sq = sqrt(max(B1 * B1 - A2 * C, vec4f(0.0)));\n let den = B1 + select(-sq, sq, R);\n let raw = clamp(select(vec4f(0.0), -C / den, den != vec4f(0.0)), vec4f(0.0), vec4f(1.0));\n let T = select(select(raw, vec4f(1.0), sat1), vec4f(0.0), sat0);\n if (T.y <= T.x) { return 0.0; }\n let tc = clamp(T.zw, T.xx, T.yy);\n let t1 = tc.x;\n let t2 = max(tc.y, t1);\n var acc = 0.0;\n let dt = t2 - t1;\n if (dt > 0.0) {\n let tm = 0.5 * (t1 + t2);\n let hmid = a2 * tm + b1;\n let x_mid = (hmid.x + b1.x) * tm + q1.x + hx;\n acc = dt * (x_mid * hmid.y + (dt * dt * (1.0 / 12.0)) * (a2.x * hmid.y + 2.0 * a2.y * hmid.x));\n }\n // The stretch right of the pixel spans its full width, times its rise: from the window's\n // start to the crossing of the pixel's right side on a piece moving right, from that crossing\n // to the window's end on one moving left. A crossing outside the window is the window's own\n // bound there, taken as given: a piece that only passes beside the pixel then adds exactly\n // what the full-width shortcut would, and one on the far side exactly nothing. The difference\n // of two roots loses that under magnification, where it is a few units in their last place.\n let tq = select(t1, t2, x_rising);\n let yq = select(select(q1.y + (a2.y * tq + 2.0 * b1.y) * tq, V.y, tq >= T.y), V.x, tq <= T.x);\n acc += select(yq - V.x, V.y - yq, x_rising) * hx;\n return acc + acc;\n}\n`)\n\n// Reciprocal and direct heights round independently. Include a neighbour only\n// if the selected windows miss part of the pixel, matching their shared edges.\nconst bandRange = wgslFn<{\n origin: Node<'float'>\n halfY: Node<'float'>\n height: Node<'float'>\n inverseHeight: Node<'float'>\n count: Node<'uint'>\n}>(`\nfn windfoil_band_range(origin: f32, halfY: f32, height: f32, inverseHeight: f32, count: u32) -> vec2u {\n let limit = f32(count) - 1.0;\n var first = u32(clamp(floor((-origin - halfY) * inverseHeight), 0.0, limit));\n var last = u32(clamp(floor((-origin + halfY) * inverseHeight), 0.0, limit));\n first -= select(0u, 1u, first > 0u && origin + f32(first) * height > -halfY);\n last += select(0u, 1u, last + 1u < count && origin + f32(last + 1u) * height < halfY);\n return vec2u(first, last);\n}\n`)\n\nconst bandWindow = wgslFn<{\n origin: Node<'float'>\n halfY: Node<'float'>\n height: Node<'float'>\n count: Node<'uint'>\n band: Node<'uint'>\n}>(`\nfn windfoil_band_window(origin: f32, halfY: f32, height: f32, count: u32, band: u32) -> vec2f {\n if (count <= 1u) { return vec2f(-halfY, halfY); }\n return vec2f(\n max(-halfY, origin + f32(band) * height),\n min(halfY, origin + f32(band + 1u) * height)\n );\n}\n`)\n\nconst ROW_STRIDE = 6\n// The skirt must leave no ink outside the quad, on single-sampled and 4-sample passes alike.\n// A fragment integrates a box reaching half a pixel from its centre. A multisampled pass also\n// stores it only in the samples its quad covers, and WebGPU's only such count, 4, puts them\n// 1/8 and 3/8 px from the centre along the screen axes: 3/8 px across an axis-aligned edge,\n// √10/8 px across a rotated one at most. Each skirt adds 1/16 px for the rasterizer's\n// sub-pixel grid, which holds that rotated case too.\nconst KERNEL_SKIRT_PX = 0.5625\nconst MULTISAMPLE_SKIRT_PX = 0.9375\nconst SKIRT_MAX_SCALE = 16\n\nlet kernelSkirt: UniformNode<'float', number> | undefined\n/**\n * The skirt of the pass being drawn, in pixels: one uniform for every Windfoil material, set\n * from the pass's sample count at each render, whenever its shader was compiled. The count is\n * that of the target the pass draws into: a render target, three's frame buffer target in its\n * place, or else an output render target; the renderer's own count only without any.\n */\nexport function windfoilKernelSkirt(): UniformNode<'float', number> {\n return (kernelSkirt ??= uniform(KERNEL_SKIRT_PX)\n .setName('ultraWindfoilSkirt')\n .setGroup(renderGroup)\n .onRenderUpdate(({ renderer }) => {\n const target = renderer?.getRenderTarget() ?? renderer?.getOutputRenderTarget()\n const samples = target ? target.samples : (renderer?.currentSamples ?? 0)\n return samples >= 4 ? MULTISAMPLE_SKIRT_PX : KERNEL_SKIRT_PX\n }))\n}\n\n/** What a tone model that dilates the outline adds to the quad of each glyph. */\nexport interface WindfoilDilation {\n /** (ems, pixels at most, pixels per em from which it stops): `TextTone.dilation`. */\n readonly law: Node<'vec3'>\n /** The glyph's font size in local units; zero where the outline must stay as it is. */\n readonly em: Node<'float'>\n /**\n * Receives the glyph's dilation in pixels of the pass being drawn, for its fragments; below\n * zero from the size where the model stops.\n */\n readonly amount: Node<'float'>\n}\n\nexport function windfoilVertexExtension(\n bounds: Node<'vec4'>,\n glyphPosition: Node<'vec2'>,\n dilation?: WindfoilDilation,\n): GlyphVertexExtension {\n const modelViewProjection = cameraProjectionMatrix.mul(modelViewMatrix)\n return (quad, rect, position, depth, motionScale) => {\n const clipAt = (point: Node<'vec2'>): Node<'vec4'> =>\n modelViewProjection.mul(vec4(point, depth, 1))\n // Vertices behind the camera get no skirt below, so only the positive side of w matters.\n const toPixels = (clip: Node<'vec4'>): Node<'vec2'> =>\n clip.xy.div(max(clip.w, 1e-6)).mul(viewportSize).mul(0.5)\n const clip = clipAt(position)\n const clipX = clipAt(position.add(vec2(1, 0)))\n const clipY = clipAt(position.add(vec2(0, 1)))\n const projected = toPixels(clip)\n const screenX = toPixels(clipX).sub(projected)\n const screenY = toPixels(clipY).sub(projected)\n const determinant = screenX.x.mul(screenY.y).sub(screenX.y.mul(screenY.x))\n if (dilation) {\n // The same quad as below, for fragments that integrate a box 2d pixels larger and sample\n // it d pixels lower on screen: the skirt grows by d, and the quad moves by the local\n // vector whose screen image is d pixels up. Each corner still carries the outline\n // coordinate of where it lands, so a pass that ignores d draws the glyph unmoved.\n const pixel = vec2(length(screenY), length(screenX))\n .div(max(abs(determinant), 1e-12))\n .toConst()\n const emPixels = dilation.em.div(max(pixel.x, pixel.y)).toConst()\n // The step sits half a pixel early: text laid out at exactly the limit must not\n // straddle it through the rounding of the screen differences above. A glyph of unknown\n // size reads as one of no size: no dilation, and still below the limit.\n const signed = mix(\n float(-1),\n min(emPixels.mul(dilation.law.x), dilation.law.y),\n step(emPixels, dilation.law.z.sub(0.5)),\n ).toConst()\n dilation.amount.assign(signed)\n const amount = max(signed, 0).toConst()\n const rise = vec2(screenY.x.negate(), screenX.x).mul(\n amount.mul(determinant).div(max(determinant.mul(determinant), 1e-24)),\n )\n const linear = quad\n .mul(2)\n .sub(1)\n .mul(pixel)\n .mul(windfoilKernelSkirt().add(amount))\n .add(rise)\n .toConst()\n const deltaW = dot(linear, vec2(clipX.w, clipY.w).sub(clip.w))\n const local = linear\n .mul(max(clip.w, 0).div(max(clip.w.sub(deltaW), max(clip.w, 1e-6).div(SKIRT_MAX_SCALE))))\n .toConst()\n const size = bounds.zw.sub(bounds.xy)\n glyphPosition.assign(\n bounds.xy\n .add(size.mul(quad))\n .add(\n local.mul(size.div(rect.zw.sub(rect.xy).max(vec2(1e-6)).mul(max(motionScale, 1e-4)))),\n ),\n )\n return position.add(local)\n }\n // A fragment integrates a glyph-space box whose sides are the lengths of\n // each glyph axis's screen gradient (windfoilPixelBox), so it can hold ink\n // only within half that box of the ink bbox. Per pixel those gradients are\n // |screenY| / |det| local units along x and |screenX| / |det| along y, the\n // rows of the inverse 2x2 screen Jacobian. Padding by that skirt keeps\n // rotated, sheared, perspective, beauty, and shadow passes from clipping\n // the partly covered pixels just outside the bbox. The rows' absolute sums\n // would bound a screen-aligned pixel instead, up to √2 further than the box\n // reaches on rotated text.\n const inverseDeterminant = windfoilKernelSkirt().div(max(abs(determinant), 1e-12))\n const linearPadding = vec2(length(screenY), length(screenX)).mul(inverseDeterminant)\n // That Jacobian is local to the vertex, but moving the vertex changes its\n // screen scale by w / w'. Unscaled, a distant glyph seen at a grazing angle\n // pushed its near corners past the camera and drew its quad across dozens of\n // screens of zero-coverage fragments. clip.w is affine in local position, so\n // the differences above are its exact gradient, and scaling the move by\n // w / (w - Δw) lands the corner exactly on the linear screen offset; moving\n // toward the camera, w' = w² / (w - Δw) stays positive. An offset beyond the\n // plane's horizon has no solution, so moves away are capped. Vertices behind\n // the camera are never visible and their edges are clipped at the near plane,\n // so max(w, 0) gives them no skirt; the branch-free form keeps the startup\n // vertex shader small.\n const direction = quad.mul(2).sub(1)\n const deltaW = dot(direction.mul(linearPadding), vec2(clipX.w, clipY.w).sub(clip.w))\n const localPadding = linearPadding.mul(\n max(clip.w, 0).div(max(clip.w.sub(deltaW), max(clip.w, 1e-6).div(SKIRT_MAX_SCALE))),\n )\n const outlinePerLocal = bounds.zw\n .sub(bounds.xy)\n .div(rect.zw.sub(rect.xy).max(vec2(1e-6)).mul(max(motionScale, 1e-4)))\n const outlinePadding = localPadding.mul(outlinePerLocal)\n glyphPosition.assign(\n bounds.xy\n .sub(outlinePadding)\n .add(bounds.zw.sub(bounds.xy).add(outlinePadding.mul(2)).mul(quad)),\n )\n return position.add(direction.mul(localPadding))\n }\n}\n\ntype AssignableNode<T extends string> = Node<T> & {\n toVar(name?: string): Node<T> & { setAssignable(value: boolean): Node<T> }\n}\n\nexport function createWindfoilCoverage(storage: WindfoilStorage) {\n const { curves, rows } = storage\n const localVar = <T extends string>(node: Node<T>, name?: string): Node<T> =>\n (node as AssignableNode<T>).toVar(name).setAssignable(true)\n const overlap = Fn<[Node<'float'>, Node<'float'>, Node<'float'>, Node<'float'>], Node<'float'>>(\n ([a0, a1, b0, b1]) => max(min(a1, b1).sub(max(a0, b0)), 0),\n )\n\n // Left of a row's split, fewer pieces start before the pixel than end after it: the row's\n // second copy, by ascending x-minimum, is walked toward the right edge instead. Mirroring x\n // by `direction` turns that walk into the first one, by descending x-maximum toward the left\n // edge. Every closed contour rises and falls by the same amount inside a row window, so both\n // sums are equal and each walk can stop at the first piece wholly on its far side. Pieces on\n // the near side cost one full-width span.\n const integrateFace = Fn<\n [Node<'vec4'>, Node<'float'>, Node<'vec2'>, Node<'vec2'>],\n Node<'float'>\n >(([header, y0, center, size]) => {\n const rowBase = uint(header.x).toConst()\n const count = uint(header.y).toConst()\n const halfX = size.x.mul(0.5).toConst()\n const halfY = size.y.mul(0.5).toConst()\n const relativeOrigin = y0.sub(center.y).toConst()\n const ulp16 = max(abs(center.x), abs(center.y)).mul(1.92e-6).toConst()\n const range = (\n bandRange({\n origin: relativeOrigin,\n halfY,\n height: header.z,\n inverseHeight: header.w,\n count,\n }) as Node<'uvec2'>\n ).toConst()\n const accumulated = localVar(float(0), 'windfoilFaceIntegral')\n Loop({ start: range.x, end: range.y, type: 'uint', condition: '<=' }, ({ i }) => {\n const win = (\n bandWindow({\n origin: relativeOrigin,\n halfY,\n height: header.z,\n count,\n band: i,\n }) as Node<'vec2'>\n ).toConst()\n const windowLow = win.x\n const windowHigh = win.y\n If(windowHigh.lessThanEqual(windowLow), () => {\n Continue()\n })\n const row = rowBase.add(i).mul(ROW_STRIDE).toConst()\n const pieceCount = uint(rows.element(row.add(1))).toConst()\n const split = (\n bitcast(rows.element(row.add(5)), 'float') as unknown as Node<'float'>\n ).toConst()\n const leftward = center.x.lessThan(split).toConst()\n const leftF = float(leftward).toConst()\n const listStart = uint(rows.element(row)).add(uint(leftward).mul(pieceCount)).toConst()\n const direction = float(1).sub(leftF.mul(2)).toConst()\n const bandAcc = localVar(float(0))\n Loop({ start: uint(0), end: pieceCount, type: 'uint' }, ({ i: k }) => {\n const base = listStart.add(k).mul(3).toConst()\n const q1 = vec2(curves.element(base)).sub(center).toConst()\n const q3 = vec2(curves.element(base.add(2)))\n .sub(center)\n .toConst()\n const sx1 = q1.x.mul(direction).toConst()\n const sx3 = q3.x.mul(direction).toConst()\n If(max(sx1, sx3).lessThanEqual(halfX.negate()), () => {\n Break()\n })\n const yMinimum = min(q1.y, q3.y).toConst()\n const yMaximum = max(q1.y, q3.y).toConst()\n const low = max(windowLow, yMinimum).toConst()\n const high = min(windowHigh, yMaximum).toConst()\n const spanY = high.sub(low).toConst()\n If(spanY.lessThanEqual(0), () => {\n Continue()\n })\n If(min(sx1, sx3).greaterThanEqual(halfX), () => {\n const rise = spanY.mul(float(q3.y.greaterThanEqual(q1.y)).mul(2).sub(1))\n bandAcc.addAssign(size.x.mul(rise))\n Continue()\n })\n If(abs(sx3.sub(sx1)).add(yMaximum.sub(yMinimum)).lessThanEqual(ulp16), () => {\n const rise = spanY.mul(float(q3.y.greaterThanEqual(q1.y)).mul(2).sub(1))\n bandAcc.addAssign(\n clamp(sx1.add(sx3).mul(0.5), halfX.negate(), halfX).add(halfX).mul(rise),\n )\n Continue()\n })\n const q2 = vec2(curves.element(base.add(1)))\n .sub(center)\n .toConst()\n bandAcc.addAssign(\n integratePiece({\n q1: vec2(sx1, q1.y),\n q2: vec2(q2.x.mul(direction), q2.y),\n q3: vec2(sx3, q3.y),\n lo: low,\n hi: high,\n hx: halfX,\n }) as Node<'float'>,\n )\n })\n accumulated.addAssign(direction.mul(bandAcc))\n })\n return accumulated\n })\n\n const profileFace = Fn<[Node<'vec4'>, Node<'vec4'>, Node<'vec2'>, Node<'vec2'>], Node<'float'>>(\n ([header, box, center, size]) => {\n const half = size.mul(0.5).toConst()\n const pixelLow = center.sub(half).toConst()\n const pixelHigh = center.add(half).toConst()\n const ink = localVar(float(0), 'windfoilProfileIntegral')\n If(min(pixelHigh.x, box.z).greaterThan(max(pixelLow.x, box.x)), () => {\n const rowBase = uint(header.x).toConst()\n const limit = header.y.sub(1).toConst()\n const first = uint(clamp(floor(pixelLow.y.sub(box.y).mul(header.w)), 0, limit)).toConst()\n const last = uint(clamp(floor(pixelHigh.y.sub(box.y).mul(header.w)), 0, limit)).toConst()\n Loop({ start: first, end: last, type: 'uint', condition: '<=' }, ({ i }) => {\n const row = rowBase.add(i).mul(ROW_STRIDE).toConst()\n const edgeLow = box.y.add(float(i).mul(header.z)).toConst()\n const edgeHigh = edgeLow.add(header.z)\n const overlapY = overlap(pixelLow.y, pixelHigh.y, edgeLow, edgeHigh)\n const rowXMin = bitcast(rows.element(row.add(3)), 'float') as unknown as Node<'float'>\n const rowXMax = bitcast(rows.element(row.add(4)), 'float') as unknown as Node<'float'>\n const density = bitcast(rows.element(row.add(2)), 'float') as unknown as Node<'float'>\n const overlapX = overlap(pixelLow.x, pixelHigh.x, rowXMin, rowXMax)\n ink.addAssign(density.mul(overlapY).mul(overlapX))\n })\n })\n return ink\n },\n )\n\n return { integrateFace, profileFace }\n}\n\nexport function windfoilPixelBox(\n glyphPosition: Node<'vec2'>,\n dy: Node<'vec2'> = dFdy(glyphPosition),\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AAQ,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,QAAQ;KACnD,MAAM,UAAU,IAAI,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ;KAC1D,MAAM,WAAW,QAAQ,IAAI,OAAO,CAAC;KACrC,MAAM,WAAW,QAAQ,SAAS,GAAG,UAAU,GAAG,SAAS,QAAQ;KACnE,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,WAAW,QAAQ,SAAS,GAAG,UAAU,GAAG,SAAS,OAAO;KAClE,IAAI,UAAU,QAAQ,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC;IACnD,CAAC;GACH,CAAC;GACD,OAAO;EACT,CAGsB;CAAY;AACtC;AAEA,SAAgB,iBACd,eACA,KAAmB,KAAK,aAAa,GACvB;CACd,MAAM,KAAK,KAAK,aAAa;CAC7B,OAAO,KAAK,OAAO,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AAChF"}
1
+ {"version":3,"file":"coverage.js","names":[],"sources":["../../src/windfoil/coverage.ts"],"sourcesContent":["import type { Node } from 'three/webgpu'\nimport {\n Break,\n Continue,\n Fn,\n If,\n Loop,\n abs,\n bitcast,\n cameraProjectionMatrix,\n clamp,\n dFdx,\n dFdy,\n dot,\n float,\n floor,\n length,\n max,\n min,\n mix,\n modelViewMatrix,\n step,\n uint,\n vec2,\n vec4,\n viewportSize,\n wgslFn,\n} from 'three/tsl'\n\nimport type { GlyphVertexExtension } from '../text/GlyphTextMaterial.js'\nimport { windfoilKernelSkirt, type WindfoilDilation } from './skirt.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n\nexport { windfoilKernelSkirt, type WindfoilDilation }\n\n/*\n * Adapted from texel-org/windfoil's Apache-2.0 reference implementation,\n * src/windfoil.wgsl (Matt DesLauriers, 2026). The CPU prepass guarantees that\n * each quadratic passed here is monotone in x and y, and the caller mirrors x so\n * that the walk always runs toward -x. This closed form computes the piece's\n * contribution to the pixel's winding integral: one vec4 root solve gives the\n * parameters where the piece meets the row window and the pixel's two sides.\n * `lo` and `hi` are the window already cut to the piece's own extent, so the\n * piece is at `lo` and `hi` exactly at the first two of those parameters.\n */\nconst integratePiece = wgslFn<{\n q1: Node<'vec2'>\n q2: Node<'vec2'>\n q3: Node<'vec2'>\n lo: Node<'float'>\n hi: Node<'float'>\n hx: Node<'float'>\n}>(`\nfn windfoil_integrate_piece(q1: vec2f, q2: vec2f, q3: vec2f, lo: f32, hi: f32, hx: f32) -> f32 {\n let a2 = q1 - 2.0 * q2 + q3;\n let b1 = q2 - q1;\n let y_rising = q3.y >= q1.y;\n let x_rising = q3.x >= q1.x;\n let A2 = a2.yyxx;\n let B1 = b1.yyxx;\n let V = vec4f(\n select(vec2f(hi, lo), vec2f(lo, hi), y_rising),\n select(vec2f(hx, -hx), vec2f(-hx, hx), x_rising)\n );\n let R = vec2<bool>(y_rising, x_rising).xxyy;\n let C = q1.yyxx - V;\n let sat0 = select(C <= vec4f(0.0), C >= vec4f(0.0), R);\n let sat1 = select(q3.yyxx >= V, q3.yyxx <= V, R);\n let sq = sqrt(max(B1 * B1 - A2 * C, vec4f(0.0)));\n let den = B1 + select(-sq, sq, R);\n let raw = clamp(select(vec4f(0.0), -C / den, den != vec4f(0.0)), vec4f(0.0), vec4f(1.0));\n let T = select(select(raw, vec4f(1.0), sat1), vec4f(0.0), sat0);\n if (T.y <= T.x) { return 0.0; }\n let tc = clamp(T.zw, T.xx, T.yy);\n let t1 = tc.x;\n let t2 = max(tc.y, t1);\n var acc = 0.0;\n let dt = t2 - t1;\n if (dt > 0.0) {\n let tm = 0.5 * (t1 + t2);\n let hmid = a2 * tm + b1;\n let x_mid = (hmid.x + b1.x) * tm + q1.x + hx;\n acc = dt * (x_mid * hmid.y + (dt * dt * (1.0 / 12.0)) * (a2.x * hmid.y + 2.0 * a2.y * hmid.x));\n }\n // The stretch right of the pixel spans its full width, times its rise: from the window's\n // start to the crossing of the pixel's right side on a piece moving right, from that crossing\n // to the window's end on one moving left. A crossing outside the window is the window's own\n // bound there, taken as given: a piece that only passes beside the pixel then adds exactly\n // what the full-width shortcut would, and one on the far side exactly nothing. The difference\n // of two roots loses that under magnification, where it is a few units in their last place.\n let tq = select(t1, t2, x_rising);\n let yq = select(select(q1.y + (a2.y * tq + 2.0 * b1.y) * tq, V.y, tq >= T.y), V.x, tq <= T.x);\n acc += select(yq - V.x, V.y - yq, x_rising) * hx;\n return acc + acc;\n}\n`)\n\n// Reciprocal and direct heights round independently. Include a neighbour only\n// if the selected windows miss part of the pixel, matching their shared edges.\nconst bandRange = wgslFn<{\n origin: Node<'float'>\n halfY: Node<'float'>\n height: Node<'float'>\n inverseHeight: Node<'float'>\n count: Node<'uint'>\n}>(`\nfn windfoil_band_range(origin: f32, halfY: f32, height: f32, inverseHeight: f32, count: u32) -> vec2u {\n let limit = f32(count) - 1.0;\n var first = u32(clamp(floor((-origin - halfY) * inverseHeight), 0.0, limit));\n var last = u32(clamp(floor((-origin + halfY) * inverseHeight), 0.0, limit));\n first -= select(0u, 1u, first > 0u && origin + f32(first) * height > -halfY);\n last += select(0u, 1u, last + 1u < count && origin + f32(last + 1u) * height < halfY);\n return vec2u(first, last);\n}\n`)\n\nconst bandWindow = wgslFn<{\n origin: Node<'float'>\n halfY: Node<'float'>\n height: Node<'float'>\n count: Node<'uint'>\n band: Node<'uint'>\n}>(`\nfn windfoil_band_window(origin: f32, halfY: f32, height: f32, count: u32, band: u32) -> vec2f {\n if (count <= 1u) { return vec2f(-halfY, halfY); }\n return vec2f(\n max(-halfY, origin + f32(band) * height),\n min(halfY, origin + f32(band + 1u) * height)\n );\n}\n`)\n\nconst ROW_STRIDE = 6\nconst SKIRT_MAX_SCALE = 16\n\nexport function windfoilVertexExtension(\n bounds: Node<'vec4'>,\n glyphPosition: Node<'vec2'>,\n dilation?: WindfoilDilation,\n): GlyphVertexExtension {\n const modelViewProjection = cameraProjectionMatrix.mul(modelViewMatrix)\n return (quad, rect, position, depth, motionScale) => {\n const clipAt = (point: Node<'vec2'>): Node<'vec4'> =>\n modelViewProjection.mul(vec4(point, depth, 1))\n // Vertices behind the camera get no skirt below, so only the positive side of w matters.\n const toPixels = (clip: Node<'vec4'>): Node<'vec2'> =>\n clip.xy.div(max(clip.w, 1e-6)).mul(viewportSize).mul(0.5)\n const clip = clipAt(position)\n const clipX = clipAt(position.add(vec2(1, 0)))\n const clipY = clipAt(position.add(vec2(0, 1)))\n const projected = toPixels(clip)\n const screenX = toPixels(clipX).sub(projected)\n const screenY = toPixels(clipY).sub(projected)\n const determinant = screenX.x.mul(screenY.y).sub(screenX.y.mul(screenY.x))\n if (dilation) {\n // The same quad as below, for fragments that integrate a box 2d pixels larger and sample\n // it d pixels lower on screen: the skirt grows by d, and the quad moves by the local\n // vector whose screen image is d pixels up. Each corner still carries the outline\n // coordinate of where it lands, so a pass that ignores d draws the glyph unmoved.\n const pixel = vec2(length(screenY), length(screenX))\n .div(max(abs(determinant), 1e-12))\n .toConst()\n const emPixels = dilation.em.div(max(pixel.x, pixel.y)).toConst()\n // The step sits half a pixel early: text laid out at exactly the limit must not\n // straddle it through the rounding of the screen differences above. A glyph of unknown\n // size reads as one of no size: no dilation, and still below the limit.\n const signed = mix(\n float(-1),\n min(emPixels.mul(dilation.law.x), dilation.law.y),\n step(emPixels, dilation.law.z.sub(0.5)),\n ).toConst()\n dilation.amount.assign(signed)\n const amount = max(signed, 0).toConst()\n const rise = vec2(screenY.x.negate(), screenX.x).mul(\n amount.mul(determinant).div(max(determinant.mul(determinant), 1e-24)),\n )\n const linear = quad\n .mul(2)\n .sub(1)\n .mul(pixel)\n .mul(windfoilKernelSkirt().add(amount))\n .add(rise)\n .toConst()\n const deltaW = dot(linear, vec2(clipX.w, clipY.w).sub(clip.w))\n const local = linear\n .mul(max(clip.w, 0).div(max(clip.w.sub(deltaW), max(clip.w, 1e-6).div(SKIRT_MAX_SCALE))))\n .toConst()\n const size = bounds.zw.sub(bounds.xy)\n glyphPosition.assign(\n bounds.xy\n .add(size.mul(quad))\n .add(\n local.mul(size.div(rect.zw.sub(rect.xy).max(vec2(1e-6)).mul(max(motionScale, 1e-4)))),\n ),\n )\n return position.add(local)\n }\n // A fragment integrates a glyph-space box whose sides are the lengths of\n // each glyph axis's screen gradient (windfoilPixelBox), so it can hold ink\n // only within half that box of the ink bbox. Per pixel those gradients are\n // |screenY| / |det| local units along x and |screenX| / |det| along y, the\n // rows of the inverse 2x2 screen Jacobian. Padding by that skirt keeps\n // rotated, sheared, perspective, beauty, and shadow passes from clipping\n // the partly covered pixels just outside the bbox. The rows' absolute sums\n // would bound a screen-aligned pixel instead, up to √2 further than the box\n // reaches on rotated text.\n const inverseDeterminant = windfoilKernelSkirt().div(max(abs(determinant), 1e-12))\n const linearPadding = vec2(length(screenY), length(screenX)).mul(inverseDeterminant)\n // That Jacobian is local to the vertex, but moving the vertex changes its\n // screen scale by w / w'. Unscaled, a distant glyph seen at a grazing angle\n // pushed its near corners past the camera and drew its quad across dozens of\n // screens of zero-coverage fragments. clip.w is affine in local position, so\n // the differences above are its exact gradient, and scaling the move by\n // w / (w - Δw) lands the corner exactly on the linear screen offset; moving\n // toward the camera, w' = w² / (w - Δw) stays positive. An offset beyond the\n // plane's horizon has no solution, so moves away are capped. Vertices behind\n // the camera are never visible and their edges are clipped at the near plane,\n // so max(w, 0) gives them no skirt; the branch-free form keeps the startup\n // vertex shader small.\n const direction = quad.mul(2).sub(1)\n const deltaW = dot(direction.mul(linearPadding), vec2(clipX.w, clipY.w).sub(clip.w))\n const localPadding = linearPadding.mul(\n max(clip.w, 0).div(max(clip.w.sub(deltaW), max(clip.w, 1e-6).div(SKIRT_MAX_SCALE))),\n )\n const outlinePerLocal = bounds.zw\n .sub(bounds.xy)\n .div(rect.zw.sub(rect.xy).max(vec2(1e-6)).mul(max(motionScale, 1e-4)))\n const outlinePadding = localPadding.mul(outlinePerLocal)\n glyphPosition.assign(\n bounds.xy\n .sub(outlinePadding)\n .add(bounds.zw.sub(bounds.xy).add(outlinePadding.mul(2)).mul(quad)),\n )\n return position.add(direction.mul(localPadding))\n }\n}\n\ntype AssignableNode<T extends string> = Node<T> & {\n toVar(name?: string): Node<T> & { setAssignable(value: boolean): Node<T> }\n}\n\nexport function createWindfoilCoverage(storage: WindfoilStorage) {\n const { curves, rows } = storage\n const localVar = <T extends string>(node: Node<T>, name?: string): Node<T> =>\n (node as AssignableNode<T>).toVar(name).setAssignable(true)\n const overlap = Fn<[Node<'float'>, Node<'float'>, Node<'float'>, Node<'float'>], Node<'float'>>(\n ([a0, a1, b0, b1]) => max(min(a1, b1).sub(max(a0, b0)), 0),\n )\n\n // Left of a row's split, fewer pieces start before the pixel than end after it: the row's\n // second copy, by ascending x-minimum, is walked toward the right edge instead. Mirroring x\n // by `direction` turns that walk into the first one, by descending x-maximum toward the left\n // edge. Every closed contour rises and falls by the same amount inside a row window, so both\n // sums are equal and each walk can stop at the first piece wholly on its far side. Pieces on\n // the near side cost one full-width span.\n const integrateFace = Fn<\n [Node<'vec4'>, Node<'float'>, Node<'vec2'>, Node<'vec2'>],\n Node<'float'>\n >(([header, y0, center, size]) => {\n const rowBase = uint(header.x).toConst()\n const count = uint(header.y).toConst()\n const halfX = size.x.mul(0.5).toConst()\n const halfY = size.y.mul(0.5).toConst()\n const relativeOrigin = y0.sub(center.y).toConst()\n const ulp16 = max(abs(center.x), abs(center.y)).mul(1.92e-6).toConst()\n const range = (\n bandRange({\n origin: relativeOrigin,\n halfY,\n height: header.z,\n inverseHeight: header.w,\n count,\n }) as Node<'uvec2'>\n ).toConst()\n const accumulated = localVar(float(0), 'windfoilFaceIntegral')\n Loop({ start: range.x, end: range.y, type: 'uint', condition: '<=' }, ({ i }) => {\n const win = (\n bandWindow({\n origin: relativeOrigin,\n halfY,\n height: header.z,\n count,\n band: i,\n }) as Node<'vec2'>\n ).toConst()\n const windowLow = win.x\n const windowHigh = win.y\n If(windowHigh.lessThanEqual(windowLow), () => {\n Continue()\n })\n const row = rowBase.add(i).mul(ROW_STRIDE).toConst()\n const pieceCount = uint(rows.element(row.add(1))).toConst()\n const split = (\n bitcast(rows.element(row.add(5)), 'float') as unknown as Node<'float'>\n ).toConst()\n const leftward = center.x.lessThan(split).toConst()\n const leftF = float(leftward).toConst()\n const listStart = uint(rows.element(row))\n .add(uint(leftward).mul(pieceCount))\n .mul(uint(3))\n .toConst()\n const q2Base = listStart.add(pieceCount.shiftLeft(uint(1))).toConst()\n const direction = float(1).sub(leftF.mul(2)).toConst()\n const bandAcc = localVar(float(0))\n Loop({ start: uint(0), end: pieceCount, type: 'uint' }, ({ i: k }) => {\n const base = listStart.add(k.shiftLeft(uint(1))).toConst()\n const q1 = vec2(curves.element(base)).sub(center).toConst()\n const q3 = vec2(curves.element(base.add(uint(1))))\n .sub(center)\n .toConst()\n const sx1 = q1.x.mul(direction).toConst()\n const sx3 = q3.x.mul(direction).toConst()\n If(max(sx1, sx3).lessThanEqual(halfX.negate()), () => {\n Break()\n })\n const yMinimum = min(q1.y, q3.y).toConst()\n const yMaximum = max(q1.y, q3.y).toConst()\n const low = max(windowLow, yMinimum).toConst()\n const high = min(windowHigh, yMaximum).toConst()\n const spanY = high.sub(low).toConst()\n If(spanY.lessThanEqual(0), () => {\n Continue()\n })\n If(min(sx1, sx3).greaterThanEqual(halfX), () => {\n const rise = spanY.mul(float(q3.y.greaterThanEqual(q1.y)).mul(2).sub(1))\n bandAcc.addAssign(size.x.mul(rise))\n Continue()\n })\n If(abs(sx3.sub(sx1)).add(yMaximum.sub(yMinimum)).lessThanEqual(ulp16), () => {\n const rise = spanY.mul(float(q3.y.greaterThanEqual(q1.y)).mul(2).sub(1))\n bandAcc.addAssign(\n clamp(sx1.add(sx3).mul(0.5), halfX.negate(), halfX).add(halfX).mul(rise),\n )\n Continue()\n })\n const q2 = vec2(curves.element(q2Base.add(k)))\n .sub(center)\n .toConst()\n bandAcc.addAssign(\n integratePiece({\n q1: vec2(sx1, q1.y),\n q2: vec2(q2.x.mul(direction), q2.y),\n q3: vec2(sx3, q3.y),\n lo: low,\n hi: high,\n hx: halfX,\n }) as Node<'float'>,\n )\n })\n accumulated.addAssign(direction.mul(bandAcc))\n })\n return accumulated\n })\n\n const profileFace = Fn<[Node<'vec4'>, Node<'vec4'>, Node<'vec2'>, Node<'vec2'>], Node<'float'>>(\n ([header, box, center, size]) => {\n const half = size.mul(0.5).toConst()\n const pixelLow = center.sub(half).toConst()\n const pixelHigh = center.add(half).toConst()\n const ink = localVar(float(0), 'windfoilProfileIntegral')\n If(min(pixelHigh.x, box.z).greaterThan(max(pixelLow.x, box.x)), () => {\n const rowBase = uint(header.x).toConst()\n const limit = header.y.sub(1).toConst()\n const first = uint(clamp(floor(pixelLow.y.sub(box.y).mul(header.w)), 0, limit)).toConst()\n const last = uint(clamp(floor(pixelHigh.y.sub(box.y).mul(header.w)), 0, limit)).toConst()\n Loop({ start: first, end: last, type: 'uint', condition: '<=' }, ({ i }) => {\n const row = rowBase.add(i).mul(ROW_STRIDE).toConst()\n const edgeLow = box.y.add(float(i).mul(header.z)).toConst()\n const edgeHigh = edgeLow.add(header.z)\n const overlapY = overlap(pixelLow.y, pixelHigh.y, edgeLow, edgeHigh)\n const rowXMin = bitcast(rows.element(row.add(3)), 'float') as unknown as Node<'float'>\n const rowXMax = bitcast(rows.element(row.add(4)), 'float') as unknown as Node<'float'>\n const density = bitcast(rows.element(row.add(2)), 'float') as unknown as Node<'float'>\n const overlapX = overlap(pixelLow.x, pixelHigh.x, rowXMin, rowXMax)\n ink.addAssign(density.mul(overlapY).mul(overlapX))\n })\n })\n return ink\n },\n )\n\n return { integrateFace, profileFace }\n}\n\nexport function windfoilPixelBox(\n glyphPosition: Node<'vec2'>,\n dy: Node<'vec2'> = dFdy(glyphPosition),\n): Node<'vec2'> {\n const dx = dFdx(glyphPosition)\n return vec2(length(vec2(dx.x, dy.x)), length(vec2(dx.y, dy.y))).max(vec2(1e-9))\n}\n"],"mappings":";;;AA6CA,IAAM,iBAAiB,OAOpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CF;AAID,IAAM,YAAY,OAMf;;;;;;;;;CASF;AAED,IAAM,aAAa,OAMhB;;;;;;;;CAQF;AAED,IAAM,aAAa;AACnB,IAAM,kBAAkB;AAExB,SAAgB,wBACd,QACA,eACA,UACsB;CACtB,MAAM,sBAAsB,uBAAuB,IAAI,eAAe;CACtE,QAAQ,MAAM,MAAM,UAAU,OAAO,gBAAgB;EACnD,MAAM,UAAU,UACd,oBAAoB,IAAI,KAAK,OAAO,OAAO,CAAC,CAAC;EAE/C,MAAM,YAAY,SAChB,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,IAAI,EAAG;EAC1D,MAAM,OAAO,OAAO,QAAQ;EAC5B,MAAM,QAAQ,OAAO,SAAS,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;EAC7C,MAAM,QAAQ,OAAO,SAAS,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;EAC7C,MAAM,YAAY,SAAS,IAAI;EAC/B,MAAM,UAAU,SAAS,KAAK,CAAC,CAAC,IAAI,SAAS;EAC7C,MAAM,UAAU,SAAS,KAAK,CAAC,CAAC,IAAI,SAAS;EAC7C,MAAM,cAAc,QAAQ,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,IAAI,QAAQ,CAAC,CAAC;EACzE,IAAI,UAAU;GAKZ,MAAM,QA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C,QAAQ;KACnD,MAAM,UAAU,IAAI,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ;KAC1D,MAAM,WAAW,QAAQ,IAAI,OAAO,CAAC;KACrC,MAAM,WAAW,QAAQ,SAAS,GAAG,UAAU,GAAG,SAAS,QAAQ;KACnE,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,UAAU,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;KACzD,MAAM,WAAW,QAAQ,SAAS,GAAG,UAAU,GAAG,SAAS,OAAO;KAClE,IAAI,UAAU,QAAQ,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC;IACnD,CAAC;GACH,CAAC;GACD,OAAO;EACT,CAGsB;CAAY;AACtC;AAEA,SAAgB,iBACd,eACA,KAAmB,KAAK,aAAa,GACvB;CACd,MAAM,KAAK,KAAK,aAAa;CAC7B,OAAO,KAAK,OAAO,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AAChF"}
@@ -1,4 +1,4 @@
1
- import { abortable, throwIfAborted } from "./storage.js";
1
+ import { abortable, throwIfAborted } from "./abortable.js";
2
2
  // src/windfoil/emoji.ts
3
3
  function emojiKey(cluster) {
4
4
  return [...cluster.includes("‍") ? cluster : cluster.replaceAll("️", "")].map((character) => character.codePointAt(0).toString(16)).join("-");
@@ -1 +1 @@
1
- {"version":3,"file":"emoji.js","names":[],"sources":["../../src/windfoil/emoji.ts"],"sourcesContent":["import type { createEmojiConverter } from './emojiMetrics.js'\nimport type {\n GlyphRequest,\n SvgEmojiOutlineProviderOptions,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './storage.js'\n\nfunction emojiKey(cluster: string): string {\n // Twemoji filenames intentionally encode Unicode code points, including joiners.\n // eslint-disable-next-line @typescript-eslint/no-misused-spread\n return [...(cluster.includes('\\u200d') ? cluster : cluster.replaceAll('\\ufe0f', ''))]\n .map((character) => character.codePointAt(0)!.toString(16))\n .join('-')\n}\n\n/** Share work while keeping cancellation local to each interested caller. */\nfunction sharedCache<T>() {\n const values = new Map<string, T>()\n const pending = new Map<\n string,\n { controller: AbortController; promise: Promise<T>; users: number }\n >()\n return async (key: string, signal: AbortSignal, load: (signal: AbortSignal) => Promise<T>) => {\n throwIfAborted(signal)\n if (values.has(key)) return values.get(key)!\n let entry = pending.get(key)\n if (!entry) {\n const controller = new AbortController()\n const created = {\n controller,\n users: 0,\n promise: Promise.resolve().then(async () => {\n throwIfAborted(controller.signal)\n const value = await load(controller.signal)\n throwIfAborted(controller.signal)\n values.set(key, value)\n return value\n }),\n }\n created.promise = created.promise.finally(() => {\n if (pending.get(key) === created) pending.delete(key)\n })\n pending.set(key, created)\n entry = created\n }\n entry.users++\n try {\n return await abortable(entry.promise, signal)\n } finally {\n entry.users--\n if (!entry.users && pending.get(key) === entry) {\n pending.delete(key)\n entry.controller.abort()\n }\n }\n }\n}\n/** App-supplied SVG emoji, sharing the text font's baseline and browser advance. */\nexport function createSvgEmojiOutlineProvider(\n options: SvgEmojiOutlineProviderOptions,\n): WindfoilOutlineProvider {\n const svgCache = sharedCache<string | null>()\n const outlines = sharedCache<WindfoilGlyphOutline | null>()\n let convert: ReturnType<typeof createEmojiConverter> | undefined\n return async (request: GlyphRequest, signal: AbortSignal) => {\n throwIfAborted(signal)\n if (\n request.character.includes('\\ufe0e') ||\n !/\\p{Extended_Pictographic}|\\p{Regional_Indicator}|\\u20e3/u.test(request.character)\n )\n return options.text(request, signal)\n const cluster = emojiKey(request.character)\n const key = `${request.font.key}\\0${cluster}`\n return outlines(key, signal, async (sharedSignal) => {\n const svg = await svgCache(cluster, sharedSignal, async (resolveSignal) =>\n options.resolve(request.character, resolveSignal),\n )\n if (svg === null) return null\n const module = await abortable(import('./emojiMetrics.js'), sharedSignal)\n convert ??= module.createEmojiConverter()\n return convert(svg, request, options, sharedSignal)\n })\n }\n}\n"],"mappings":";;AASA,SAAS,SAAS,SAAyB;CAGzC,OAAO,CAAC,GAAI,QAAQ,SAAS,GAAQ,IAAI,UAAU,QAAQ,WAAW,KAAU,EAAE,CAAE,CAAC,CAClF,KAAK,cAAc,UAAU,YAAY,CAAC,CAAC,CAAE,SAAS,EAAE,CAAC,CAAC,CAC1D,KAAK,GAAG;AACb;;AAGA,SAAS,cAAiB;CACxB,MAAM,yBAAS,IAAI,IAAe;CAClC,MAAM,0BAAU,IAAI,IAGlB;CACF,OAAO,OAAO,KAAa,QAAqB,SAA8C;EAC5F,eAAe,MAAM;EACrB,IAAI,OAAO,IAAI,GAAG,GAAG,OAAO,OAAO,IAAI,GAAG;EAC1C,IAAI,QAAQ,QAAQ,IAAI,GAAG;EAC3B,IAAI,CAAC,OAAO;GACV,MAAM,aAAa,IAAI,gBAAgB;GACvC,MAAM,UAAU;IACd;IACA,OAAO;IACP,SAAS,QAAQ,QAAQ,CAAC,CAAC,KAAK,YAAY;KAC1C,eAAe,WAAW,MAAM;KAChC,MAAM,QAAQ,MAAM,KAAK,WAAW,MAAM;KAC1C,eAAe,WAAW,MAAM;KAChC,OAAO,IAAI,KAAK,KAAK;KACrB,OAAO;IACT,CAAC;GACH;GACA,QAAQ,UAAU,QAAQ,QAAQ,cAAc;IAC9C,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS,QAAQ,OAAO,GAAG;GACtD,CAAC;GACD,QAAQ,IAAI,KAAK,OAAO;GACxB,QAAQ;EACV;EACA,MAAM;EACN,IAAI;GACF,OAAO,MAAM,UAAU,MAAM,SAAS,MAAM;EAC9C,UAAU;GACR,MAAM;GACN,IAAI,CAAC,MAAM,SAAS,QAAQ,IAAI,GAAG,MAAM,OAAO;IAC9C,QAAQ,OAAO,GAAG;IAClB,MAAM,WAAW,MAAM;GACzB;EACF;CACF;AACF;;AAEA,SAAgB,8BACd,SACyB;CACzB,MAAM,WAAW,YAA2B;CAC5C,MAAM,WAAW,YAAyC;CAC1D,IAAI;CACJ,OAAO,OAAO,SAAuB,WAAwB;EAC3D,eAAe,MAAM;EACrB,IACE,QAAQ,UAAU,SAAS,GAAQ,KACnC,CAAC,2DAA2D,KAAK,QAAQ,SAAS,GAElF,OAAO,QAAQ,KAAK,SAAS,MAAM;EACrC,MAAM,UAAU,SAAS,QAAQ,SAAS;EAC1C,MAAM,MAAM,GAAG,QAAQ,KAAK,IAAI,IAAI;EACpC,OAAO,SAAS,KAAK,QAAQ,OAAO,iBAAiB;GACnD,MAAM,MAAM,MAAM,SAAS,SAAS,cAAc,OAAO,kBACvD,QAAQ,QAAQ,QAAQ,WAAW,aAAa,CAClD;GACA,IAAI,QAAQ,MAAM,OAAO;GACzB,MAAM,SAAS,MAAM,UAAU,OAAO,sBAAsB,YAAY;GACxE,YAAY,OAAO,qBAAqB;GACxC,OAAO,QAAQ,KAAK,SAAS,SAAS,YAAY;EACpD,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"emoji.js","names":[],"sources":["../../src/windfoil/emoji.ts"],"sourcesContent":["import type { createEmojiConverter } from './emojiMetrics.js'\nimport type {\n GlyphRequest,\n SvgEmojiOutlineProviderOptions,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './abortable.js'\n\nfunction emojiKey(cluster: string): string {\n // Twemoji filenames intentionally encode Unicode code points, including joiners.\n // eslint-disable-next-line @typescript-eslint/no-misused-spread\n return [...(cluster.includes('\\u200d') ? cluster : cluster.replaceAll('\\ufe0f', ''))]\n .map((character) => character.codePointAt(0)!.toString(16))\n .join('-')\n}\n\n/** Share work while keeping cancellation local to each interested caller. */\nfunction sharedCache<T>() {\n const values = new Map<string, T>()\n const pending = new Map<\n string,\n { controller: AbortController; promise: Promise<T>; users: number }\n >()\n return async (key: string, signal: AbortSignal, load: (signal: AbortSignal) => Promise<T>) => {\n throwIfAborted(signal)\n if (values.has(key)) return values.get(key)!\n let entry = pending.get(key)\n if (!entry) {\n const controller = new AbortController()\n const created = {\n controller,\n users: 0,\n promise: Promise.resolve().then(async () => {\n throwIfAborted(controller.signal)\n const value = await load(controller.signal)\n throwIfAborted(controller.signal)\n values.set(key, value)\n return value\n }),\n }\n created.promise = created.promise.finally(() => {\n if (pending.get(key) === created) pending.delete(key)\n })\n pending.set(key, created)\n entry = created\n }\n entry.users++\n try {\n return await abortable(entry.promise, signal)\n } finally {\n entry.users--\n if (!entry.users && pending.get(key) === entry) {\n pending.delete(key)\n entry.controller.abort()\n }\n }\n }\n}\n/** App-supplied SVG emoji, sharing the text font's baseline and browser advance. */\nexport function createSvgEmojiOutlineProvider(\n options: SvgEmojiOutlineProviderOptions,\n): WindfoilOutlineProvider {\n const svgCache = sharedCache<string | null>()\n const outlines = sharedCache<WindfoilGlyphOutline | null>()\n let convert: ReturnType<typeof createEmojiConverter> | undefined\n return async (request: GlyphRequest, signal: AbortSignal) => {\n throwIfAborted(signal)\n if (\n request.character.includes('\\ufe0e') ||\n !/\\p{Extended_Pictographic}|\\p{Regional_Indicator}|\\u20e3/u.test(request.character)\n )\n return options.text(request, signal)\n const cluster = emojiKey(request.character)\n const key = `${request.font.key}\\0${cluster}`\n return outlines(key, signal, async (sharedSignal) => {\n const svg = await svgCache(cluster, sharedSignal, async (resolveSignal) =>\n options.resolve(request.character, resolveSignal),\n )\n if (svg === null) return null\n const module = await abortable(import('./emojiMetrics.js'), sharedSignal)\n convert ??= module.createEmojiConverter()\n return convert(svg, request, options, sharedSignal)\n })\n }\n}\n"],"mappings":";;AASA,SAAS,SAAS,SAAyB;CAGzC,OAAO,CAAC,GAAI,QAAQ,SAAS,GAAQ,IAAI,UAAU,QAAQ,WAAW,KAAU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K,QAAQ,SAAS,GAElF,OAAO,QAAQ,KAAK,SAAS,MAAM;EACrC,MAAM,UAAU,SAAS,QAAQ,SAAS;EAC1C,MAAM,MAAM,GAAG,QAAQ,KAAK,IAAI,IAAI;EACpC,OAAO,SAAS,KAAK,QAAQ,OAAO,iBAAiB;GACnD,MAAM,MAAM,MAAM,SAAS,SAAS,cAAc,OAAO,kBACvD,QAAQ,QAAQ,QAAQ,WAAW,aAAa,CAClD;GACA,IAAI,QAAQ,MAAM,OAAO;GACzB,MAAM,SAAS,MAAM,UAAU,OAAO,sBAAsB,YAAY;GACxE,YAAY,OAAO,qBAAqB;GACxC,OAAO,QAAQ,KAAK,SAAS,SAAS,YAAY;EACpD,CAAC;CACH;AACF"}
@@ -1,4 +1,4 @@
1
- import { abortable, throwIfAborted } from "./storage.js";
1
+ import { abortable, throwIfAborted } from "./abortable.js";
2
2
  // src/windfoil/emojiMetrics.ts
3
3
  /** Lazily loaded only after an app resolves an emoji SVG. */
4
4
  function createEmojiConverter() {
@@ -1 +1 @@
1
- {"version":3,"file":"emojiMetrics.js","names":[],"sources":["../../src/windfoil/emojiMetrics.ts"],"sourcesContent":["import type {\n GlyphRequest,\n SvgEmojiOutlineProviderOptions,\n WindfoilGlyphOutline,\n WindfoilOutlineLayer,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './storage.js'\n\n/** Lazily loaded only after an app resolves an emoji SVG. */\nexport function createEmojiConverter() {\n const advances = new Map<string, number>()\n let context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null = null\n return async (\n svg: string,\n request: GlyphRequest,\n options: SvgEmojiOutlineProviderOptions,\n signal: AbortSignal,\n ): Promise<WindfoilGlyphOutline | null> => {\n const text = options.em\n ? null\n : await abortable(\n Promise.resolve(\n options.text({ ...request, key: `${request.font.key}\\0M`, character: 'M' }, signal),\n ),\n signal,\n )\n if (!options.em && !text) return null\n const upm = options.em?.unitsPerEm ?? 2048\n const descent = options.em?.descent ?? (text!.descent / text!.unitsPerEm) * upm\n const em = options.em ?? { unitsPerEm: upm, ascent: upm + descent, descent }\n const { svgToWindfoilOutlines } = await abortable(import('./svg/convert.js'), signal)\n throwIfAborted(signal)\n const result = svgToWindfoilOutlines(svg, { em })\n if (\n result.layers.some((layer) => layer.paint.type === 'unsupported') ||\n result.warnings.some((warning) =>\n [\n 'stroke-ignored',\n 'unsupported-element',\n 'clip-path-ignored',\n 'mask-ignored',\n 'filter-ignored',\n 'evenodd-ambiguous',\n ].includes(warning.code),\n )\n ) {\n return null\n }\n let advance = advances.get(`${request.font.canvasFont}\\0${request.character}`)\n if (advance === undefined) {\n context ??=\n typeof OffscreenCanvas !== 'undefined'\n ? new OffscreenCanvas(1, 1).getContext('2d')\n : document.createElement('canvas').getContext('2d')\n if (!context) throw new Error('SVG emoji advance measurement requires a 2D canvas')\n context.font = request.font.canvasFont\n advance = (context.measureText(request.character).width / request.font.size) * upm\n advances.set(`${request.font.canvasFont}\\0${request.character}`, advance)\n }\n const dx = (advance - result.outline.bbox[2] - result.outline.bbox[0]) / 2\n const shiftBox = (bbox: WindfoilGlyphOutline['bbox']): WindfoilGlyphOutline['bbox'] => [\n bbox[0] + dx,\n bbox[1],\n bbox[2] + dx,\n bbox[3],\n ]\n const layers: WindfoilOutlineLayer[] = result.layers.map((layer) => ({\n quadratics: Array.from(\n layer.outline.quadratics,\n (value, index) => value + (index % 2 ? 0 : dx),\n ),\n bbox: shiftBox(layer.outline.bbox),\n paint:\n layer.paint.type === 'linear' ||\n layer.paint.type === 'radial' ||\n layer.paint.type === 'sweep'\n ? {\n ...layer.paint,\n transform: (([a, b, c, d, e, f]) => [a, b, c, d, e + dx, f] as const)(\n layer.paint.transform ?? [1, 0, 0, 1, 0, 0],\n ),\n }\n : (layer.paint as WindfoilOutlineLayer['paint']),\n }))\n const outline: WindfoilGlyphOutline = {\n unitsPerEm: upm,\n ascent: em.ascent,\n descent,\n bbox: shiftBox(result.outline.bbox),\n quadratics: [],\n layers,\n }\n throwIfAborted(signal)\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/E,SAAS,IAAI,GAAG,QAAQ,KAAK,WAAW,IAAI,QAAQ,aAAa,OAAO;EAC1E;EACA,MAAM,MAAM,UAAU,OAAO,QAAQ,KAAK,KAAK,OAAO,QAAQ,KAAK,MAAM;EACzE,MAAM,YAAY,SAAqE;GACrF,KAAK,KAAK;GACV,KAAK;GACL,KAAK,KAAK;GACV,KAAK;EACP;EACA,MAAM,SAAiC,OAAO,OAAO,KAAK,WAAW;GACnE,YAAY,MAAM,KAChB,MAAM,QAAQ,aACb,OAAO,UAAU,SAAS,QAAQ,IAAI,IAAI,GAC7C;GACA,MAAM,SAAS,MAAM,QAAQ,IAAI;GACjC,OACE,MAAM,MAAM,SAAS,YACrB,MAAM,MAAM,SAAS,YACrB,MAAM,MAAM,SAAS,UACjB;IACE,GAAG,MAAM;IACT,aAAa,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO;KAAC;KAAG;KAAG;KAAG;KAAG,IAAI;KAAI;IAAC,EAAA,CACxD,MAAM,MAAM,aAAa;KAAC;KAAG;KAAG;KAAG;KAAG;KAAG;IAAC,CAC5C;GACF,IACC,MAAM;EACf,EAAE;EACF,MAAM,UAAgC;GACpC,YAAY;GACZ,QAAQ,GAAG;GACX;GACA,MAAM,SAAS,OAAO,QAAQ,IAAI;GAClC,YAAY,CAAC;GACb;EACF;EACA,eAAe,MAAM;EACrB,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"emojiMetrics.js","names":[],"sources":["../../src/windfoil/emojiMetrics.ts"],"sourcesContent":["import type {\n GlyphRequest,\n SvgEmojiOutlineProviderOptions,\n WindfoilGlyphOutline,\n WindfoilOutlineLayer,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './abortable.js'\n\n/** Lazily loaded only after an app resolves an emoji SVG. */\nexport function createEmojiConverter() {\n const advances = new Map<string, number>()\n let context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null = null\n return async (\n svg: string,\n request: GlyphRequest,\n options: SvgEmojiOutlineProviderOptions,\n signal: AbortSignal,\n ): Promise<WindfoilGlyphOutline | null> => {\n const text = options.em\n ? null\n : await abortable(\n Promise.resolve(\n options.text({ ...request, key: `${request.font.key}\\0M`, character: 'M' }, signal),\n ),\n signal,\n )\n if (!options.em && !text) return null\n const upm = options.em?.unitsPerEm ?? 2048\n const descent = options.em?.descent ?? (text!.descent / text!.unitsPerEm) * upm\n const em = options.em ?? { unitsPerEm: upm, ascent: upm + descent, descent }\n const { svgToWindfoilOutlines } = await abortable(import('./svg/convert.js'), signal)\n throwIfAborted(signal)\n const result = svgToWindfoilOutlines(svg, { em })\n if (\n result.layers.some((layer) => layer.paint.type === 'unsupported') ||\n result.warnings.some((warning) =>\n [\n 'stroke-ignored',\n 'unsupported-element',\n 'clip-path-ignored',\n 'mask-ignored',\n 'filter-ignored',\n 'evenodd-ambiguous',\n ].includes(warning.code),\n )\n ) {\n return null\n }\n let advance = advances.get(`${request.font.canvasFont}\\0${request.character}`)\n if (advance === undefined) {\n context ??=\n typeof OffscreenCanvas !== 'undefined'\n ? new OffscreenCanvas(1, 1).getContext('2d')\n : document.createElement('canvas').getContext('2d')\n if (!context) throw new Error('SVG emoji advance measurement requires a 2D canvas')\n context.font = request.font.canvasFont\n advance = (context.measureText(request.character).width / request.font.size) * upm\n advances.set(`${request.font.canvasFont}\\0${request.character}`, advance)\n }\n const dx = (advance - result.outline.bbox[2] - result.outline.bbox[0]) / 2\n const shiftBox = (bbox: WindfoilGlyphOutline['bbox']): WindfoilGlyphOutline['bbox'] => [\n bbox[0] + dx,\n bbox[1],\n bbox[2] + dx,\n bbox[3],\n ]\n const layers: WindfoilOutlineLayer[] = result.layers.map((layer) => ({\n quadratics: Array.from(\n layer.outline.quadratics,\n (value, index) => value + (index % 2 ? 0 : dx),\n ),\n bbox: shiftBox(layer.outline.bbox),\n paint:\n layer.paint.type === 'linear' ||\n layer.paint.type === 'radial' ||\n layer.paint.type === 'sweep'\n ? {\n ...layer.paint,\n transform: (([a, b, c, d, e, f]) => [a, b, c, d, e + dx, f] as const)(\n layer.paint.transform ?? [1, 0, 0, 1, 0, 0],\n ),\n }\n : (layer.paint as WindfoilOutlineLayer['paint']),\n }))\n const outline: WindfoilGlyphOutline = {\n unitsPerEm: upm,\n ascent: em.ascent,\n descent,\n bbox: shiftBox(result.outline.bbox),\n quadratics: [],\n layers,\n }\n throwIfAborted(signal)\n return outline\n }\n}\n"],"mappings":";;;AASA,SAAgB,uBAAuB;CACrC,MAAM,2BAAW,IAAI,IAAoB;CACzC,IAAI,UAA+E;CACnF,OAAO,OACL,KACA,SACA,SACA,WACyC;EACzC,MAAM,OAAO,QAAQ,KACjB,OACA,MAAM,UACJ,QAAQ,QACN,QAAQ,KAAK;GAAE,GAAG;GAAS,KAAK,GAAG,QAAQ,KAAK,IAAI;GAAM,WAAW;EAAI,GAAG,MAAM,CACpF,GACA,MACF;EACJ,IAAI,CAAC,QAAQ,MAAM,CAAC,MAAM,OAAO;EACjC,MAAM,MAAM,QAAQ,IAAI,cAAc;EACtC,MAAM,UAAU,QAAQ,IAAI,WAAY,KAAM,UAAU,KAAM,aAAc;EAC5E,MAAM,KAAK,QAAQ,MAAM;GAAE,YAAY;GAAK,QAAQ,MAAM;GAAS;EAAQ;EAC3E,MAAM,EAAE,0BAA0B,MAAM,UAAU,OAAO,qBAAqB,MAAM;EACpF,eAAe,MAAM;EACrB,MAAM,SAAS,sBAAsB,KAAK,EAAE,GAAG,CAAC;EAChD,IACE,OAAO,OAAO,MAAM,UAAU,MAAM,MAAM,SAAS,aAAa,KAChE,OAAO,SAAS,MAAM,YACpB;GACE;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,SAAS,QAAQ,IAAI,CACzB,GAEA,OAAO;EAET,IAAI,UAAU,SAAS,IAAI,GAAG,QAAQ,KAAK,WAAW,IAAI,QAAQ,WAAW;EAC7E,IAAI,YAAY,KAAA,GAAW;GACzB,YACE,OAAO,oBAAoB,cACvB,IAAI,gBAAgB,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,IACzC,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,IAAI;GACtD,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,oDAAoD;GAClF,QAAQ,OAAO,QAAQ,KAAK;GAC5B,UAAW,QAAQ,YAAY,QAAQ,SAAS,CAAC,CAAC,QAAQ,QAAQ,KAAK,OAAQ;GAC/E,SAAS,IAAI,GAAG,QAAQ,KAAK,WAAW,IAAI,QAAQ,aAAa,OAAO;EAC1E;EACA,MAAM,MAAM,UAAU,OAAO,QAAQ,KAAK,KAAK,OAAO,QAAQ,KAAK,MAAM;EACzE,MAAM,YAAY,SAAqE;GACrF,KAAK,KAAK;GACV,KAAK;GACL,KAAK,KAAK;GACV,KAAK;EACP;EACA,MAAM,SAAiC,OAAO,OAAO,KAAK,WAAW;GACnE,YAAY,MAAM,KAChB,MAAM,QAAQ,aACb,OAAO,UAAU,SAAS,QAAQ,IAAI,IAAI,GAC7C;GACA,MAAM,SAAS,MAAM,QAAQ,IAAI;GACjC,OACE,MAAM,MAAM,SAAS,YACrB,MAAM,MAAM,SAAS,YACrB,MAAM,MAAM,SAAS,UACjB;IACE,GAAG,MAAM;IACT,aAAa,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO;KAAC;KAAG;KAAG;KAAG;KAAG,IAAI;KAAI;IAAC,EAAA,CACxD,MAAM,MAAM,aAAa;KAAC;KAAG;KAAG;KAAG;KAAG;KAAG;IAAC,CAC5C;GACF,IACC,MAAM;EACf,EAAE;EACF,MAAM,UAAgC;GACpC,YAAY;GACZ,QAAQ,GAAG;GACX;GACA,MAAM,SAAS,OAAO,QAAQ,IAAI;GAClC,YAAY,CAAC;GACb;EACF;EACA,eAAe,MAAM;EACrB,OAAO;CACT;AACF"}
@@ -16,11 +16,11 @@ export interface MutableWindfoilAttributes {
16
16
  export declare function fillWindfoilGlyphRect(glyph: GlyphLayout, header: WindfoilGlyphHeader, bbox?: WindfoilBoundingBox, out?: [number, number, number, number]): [number, number, number, number];
17
17
  export declare function windfoilGlyphRect(glyph: GlyphLayout, header: WindfoilGlyphHeader, bbox?: WindfoilBoundingBox): readonly [number, number, number, number];
18
18
  /** Shared by text and shape geometry; one layer adds only one vertex attribute. */
19
- export declare function writeLayerInstance(glyph: GlyphLayout, header: WindfoilGlyphHeader, layer: WindfoilGlyphHeader | WindfoilLayerHeader, index: number, ordinal: number, attributes: MutableWindfoilAttributes, glyphRect?: readonly [number, number, number, number]): void;
19
+ export declare function writeLayerInstance(glyph: GlyphLayout, header: WindfoilGlyphHeader, layer: WindfoilGlyphHeader | WindfoilLayerHeader, index: number, ordinal: number, attributes: MutableWindfoilAttributes, glyphRect?: readonly [number, number, number, number], trackDirty?: boolean): void;
20
20
  /** Ordinary outlines retain the original six instance attributes. */
21
21
  export declare function createWindfoilGlyphGeometry(snapshot: DomLayoutSnapshot, glyphs: ReadonlyMap<string, WindfoilGlyphHeader>, motionPadding: number, layered?: boolean, ordinals?: Float32Array): {
22
22
  geometry: InstancedBufferGeometry;
23
23
  maxSequence: number;
24
24
  };
25
25
  export declare function windfoilContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, glyphs: ReadonlyMap<string, WindfoilGlyphHeader>): boolean;
26
- export declare function updateWindfoilGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, glyphs: ReadonlyMap<string, WindfoilGlyphHeader>, motionPadding: number, ordinals?: Float32Array): number | null;
26
+ export declare function updateWindfoilGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, glyphs: ReadonlyMap<string, WindfoilGlyphHeader>, motionPadding: number, ordinals?: Float32Array, checked?: boolean): number | null;