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.
- package/README.md +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +164 -50
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +563 -243
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/windfoil/runtime.ts"],"sourcesContent":["import {\n WebGPUBackend,\n type InstancedBufferGeometry,\n type Side,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n GlyphRequest,\n SdfAtlas,\n SdfMotionOptions,\n TextFill,\n TextToneOptions,\n TextVertex,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport type { WindfoilColorPart, WindfoilColorResources } from './color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from './geometry.js'\nimport { WindfoilMaterial } from './WindfoilMaterial.js'\nimport {\n preprocessWindfoilGlyphs,\n type WindfoilGlyphHeader,\n type WindfoilPreprocessStats,\n} from './preprocessCore.js'\nimport type { WindfoilSizeSwitch } from './sizeSwitch.js'\nimport {\n abortable,\n createWindfoilStorage,\n drawnEffects,\n throwIfAborted,\n type TextEffects,\n} from './storage.js'\nexport interface WindfoilBackend {\n readonly kind: 'windfoil' | 'slug'\n readonly layered: boolean\n /**\n * SDF atlas drawn by the companion part: glyphs without outlines plus size-switched glyphs,\n * and with `effects` every drawable outline.\n */\n readonly companion: SdfAtlas | null\n /**\n * The outline and drop shadow that an SDF underlay draws under the analytic glyphs, from\n * their companion slots; null without effects that draw anything.\n */\n readonly effects: TextEffects | null\n readonly color: WindfoilColorPart | null\n /** The `windfoil.sdfBelowPx` switch, or null when no glyph can switch. */\n readonly sizeSwitch: WindfoilSizeSwitch | null\n covers(key: string): boolean\n /** Whether the Windfoil primary batch draws this glyph. */\n primaryCovers(key: string): boolean\n /** Whether the primary batch or the colour part draws this glyph from its outline. */\n analyticCovers(key: string): boolean\n motionOrdinals(snapshot: DomLayoutSnapshot): Float32Array\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly storageBytes: number\n readonly preprocessStats: WindfoilPreprocessStats\n contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean\n createGeometry(\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): number | null\n /** Whether geometry carries each glyph's font size, which a tone that dilates reads. */\n setGlyphEm(value: boolean): void\n createMaterial(options: {\n readonly fill?: TextFill\n readonly vertex?: TextVertex\n readonly shadowCutoff?: number\n readonly side?: Side\n /** `false` builds static text, without the motion graph. */\n readonly motion: SdfMotionOptions | false\n readonly maxSequence: number\n readonly layered?: boolean\n /** Reaches the text ink of the primary batch; colour parts and shapes stay exact. */\n readonly tone?: TextToneOptions | ResolvedTextTone | false\n }): GlyphTextMaterial\n dispose(): void\n}\n\n/** Windfoil or Slug options once `DomSdf` has chosen the outline provider. */\nexport type WindfoilBuildOptions = WindfoilOptions & {\n readonly outlineProvider: WindfoilOutlineProvider\n}\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildWindfoilBackend(\n renderer: WebGPURenderer,\n requests: readonly GlyphRequest[],\n options: WindfoilBuildOptions,\n signal: AbortSignal,\n companionBuilder?: {\n build(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<SdfAtlas>\n /** The caller's outline and drop shadow, which the companion then bakes every glyph for. */\n readonly effects?: TextEffects\n },\n): Promise<WindfoilBackend | null> {\n const sdfBelow = options.sdfBelowPx\n const switchModule =\n sdfBelow === undefined ? null : await abortable(import('./sizeSwitch.js'), signal)\n // Before init, so an invalid threshold fails even where a fallback would be chosen.\n switchModule?.assertThreshold(sdfBelow)\n await abortable(renderer.init(), signal)\n throwIfAborted(signal)\n const fallback = options.fallback === 'sdf' || options.fallback === 'sdf-glyphs'\n if (!(renderer.backend instanceof WebGPUBackend)) {\n if (fallback) return null\n throw new Error(\n 'DomSdf: the Windfoil text backend requires WebGPU; set windfoil.fallback to \"sdf\" to fall back',\n )\n }\n const limit =\n (renderer.backend as unknown as { device?: { limits: { maxVertexBuffers: number } } }).device\n ?.limits.maxVertexBuffers ?? 8\n if (limit < 7) {\n if (fallback) return null\n throw new Error('DomSdf: Windfoil requires at least seven vertex buffers')\n }\n const effects = companionBuilder?.effects ? drawnEffects(companionBuilder.effects) : null\n const extended =\n !!effects ||\n requests.some((request) => request.shape) ||\n options.fallback === 'sdf-glyphs' ||\n options.compositing === 'shader' ||\n sdfBelow !== undefined\n let extensions = extended ? await abortable(import('./requests.js'), signal) : null\n let resolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }[]\n if (extensions) {\n resolved = await abortable(\n Promise.all(\n requests.map(async (request) => ({\n request,\n outline: await extensions!.resolveShapeRequest(request, options, signal),\n })),\n ),\n signal,\n )\n } else {\n const syncResolved: typeof resolved = []\n let pending: Promise<(typeof resolved)[number]>[] | null = null\n for (const request of requests) {\n const out = options.outlineProvider(request, signal)\n if (out instanceof Promise) {\n pending ??= syncResolved.map((item) => Promise.resolve(item))\n pending.push(out.then((outline) => ({ request, outline })))\n } else if (pending) {\n pending.push(Promise.resolve({ request, outline: out }))\n } else {\n syncResolved.push({ request, outline: out })\n }\n }\n resolved = pending ? await abortable(Promise.all(pending), signal) : syncResolved\n }\n throwIfAborted(signal)\n const missing = resolved.filter((item) => item.outline === null)\n if (missing.length) {\n if (\n options.fallback === 'sdf' ||\n (options.fallback === 'sdf-glyphs' && missing.length === resolved.length)\n )\n return null\n if (options.fallback !== 'sdf-glyphs' || !companionBuilder)\n throw new Error(\n `DomSdf: Windfoil outlineProvider returned null for ${JSON.stringify(missing[0]!.request.character)} in ${missing[0]!.request.font.family}`,\n )\n }\n const needsRequests = !extensions && resolved.some((item) => item.outline?.clipBox)\n const needsLayerNormalization = resolved.some(\n (item) => item.outline?.layers !== undefined || item.outline?.clipBox !== undefined,\n )\n const [lateExtensions, layerModule] =\n needsRequests || needsLayerNormalization\n ? await abortable(\n Promise.all([\n needsRequests ? import('./requests.js') : Promise.resolve(null),\n needsLayerNormalization ? import('./layerNormalization.js') : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n const prepared = preprocessWindfoilGlyphs(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\n // Colour glyphs the composite shader draws (see buildWindfoilColorResources).\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n )\n const switchable = companionBuilder\n ? (switchModule?.switchableRequests(resolved, prepared.glyphs) ?? [])\n : []\n // Effects bake every drawable outline for the underlay; an empty one is drawn by nothing.\n const companionReqs = effects\n ? resolved.flatMap((i) =>\n prepared.glyphs.get(i.request.key)?.monotonePieceCount ? [i.request] : [],\n )\n : switchable\n const layered = prepared.layered || missing.length > 0 || companionReqs.length > 0\n if (layered && limit < 8) {\n if (fallback) return null\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n }\n const wantsColor = [...prepared.glyphs.values()].some(\n (header) =>\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox)),\n )\n const colorPromise = wantsColor ? import('./color.js') : null\n const companionResource =\n (missing.length || companionReqs.length) && companionBuilder\n ? await extensions!.buildCompanion(\n companionBuilder,\n [...missing.map((item) => item.request), ...companionReqs],\n signal,\n )\n : null\n let companion = companionResource?.atlas ?? null\n const view =\n companion && switchable.length\n ? switchModule!.companionView(\n companion,\n missing.map((item) => item.request.key),\n switchable,\n )\n : null\n if (view && !effects) {\n companion = view.atlas\n if (!companion) companionResource!.dispose()\n }\n let coverage: ReturnType<typeof createWindfoilStorage> | undefined,\n colorResources: WindfoilColorResources | null = null\n try {\n const colorModule = colorPromise ? await abortable(colorPromise, signal) : null\n throwIfAborted(signal)\n coverage = createWindfoilStorage(renderer, prepared)\n colorResources =\n colorModule?.buildWindfoilColorResources(renderer, prepared, options, coverage, signal) ??\n null\n const plainGlyphs = colorResources?.plainGlyphs ?? prepared.glyphs\n const ordinalsCache = new WeakMap<DomLayoutSnapshot, Float32Array>()\n const motionOrdinals = (snapshot: DomLayoutSnapshot): Float32Array => {\n let cached = ordinalsCache.get(snapshot)\n if (!cached) {\n if (extensions) {\n cached = extensions.motionOrdinals(snapshot, prepared.glyphs, companion)\n } else {\n const count = snapshot.glyphs.length\n cached = new Float32Array(count)\n for (let i = 0; i < count; i++) cached[i] = i\n }\n ordinalsCache.set(snapshot, cached)\n }\n return cached\n }\n const sizeSwitch = view?.keys.size\n ? switchModule!.createSizeSwitch(sdfBelow!, view.keys, prepared.glyphs, motionOrdinals)\n : null\n // A tone that dilates the outline reads each glyph's font size from `sdfMeta.z`: zero or\n // below never switches, so the size switch keeps its own meaning of the sign. An SVG\n // shape has no font size: its outline stays where it is.\n let glyphEm = false\n const sized = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n const withEm = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n let layout = sized.get(snapshot)\n if (!layout) {\n layout = {\n ...snapshot,\n sizeSwitched: true,\n glyphs: snapshot.glyphs.map((glyph) => ({\n ...glyph,\n switchEm: glyph.shapeGroup === undefined ? -glyph.fontSize : 0,\n })),\n }\n sized.set(snapshot, layout)\n }\n return layout\n }\n const switched = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n const layout = glyphEm ? withEm(snapshot) : snapshot\n return sizeSwitch?.layout(layout) ?? layout\n }\n let geometryLayered = layered,\n disposed = false\n const retained = coverage\n return {\n kind: 'windfoil',\n layered,\n companion,\n effects,\n color: colorResources?.composite ?? null,\n sizeSwitch,\n motionOrdinals,\n glyphs: prepared.glyphs,\n covers(key) {\n return prepared.glyphs.has(key) || !!companion?.glyphs.has(key)\n },\n primaryCovers(key) {\n return !!plainGlyphs.get(key)?.monotonePieceCount\n },\n analyticCovers(key) {\n return (\n !!plainGlyphs.get(key)?.monotonePieceCount ||\n !!colorResources?.composite?.glyphs.get(key)?.monotonePieceCount\n )\n },\n storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),\n preprocessStats: prepared.stats,\n contentFits(geometry, snapshot) {\n return windfoilContentFits(geometry, switched(snapshot), plainGlyphs)\n },\n createGeometry(snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n geometryLayered =\n layered || !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n if (geometryLayered && limit < 8)\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n return createWindfoilGlyphGeometry(\n snapshot,\n plainGlyphs,\n padding,\n geometryLayered,\n ordinals,\n )\n },\n updateGeometry(geometry, snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n return updateWindfoilGlyphGeometry(geometry, snapshot, plainGlyphs, padding, ordinals)\n },\n setGlyphEm(value) {\n glyphEm = value\n },\n createMaterial(materialOptions) {\n return new WindfoilMaterial({\n ...retained,\n layered: geometryLayered,\n ...(colorResources ? { paintFunctions: colorResources.paintFunctions } : {}),\n ...materialOptions,\n ...(sizeSwitch ? { keepGlyph: sizeSwitch.windfoil } : {}),\n })\n },\n dispose() {\n if (disposed) return\n disposed = true\n retained.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n },\n }\n } catch (error) {\n coverage?.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;AAmGA,eAAsB,qBACpB,UACA,UACA,SACA,QACA,kBAKiC;CACjC,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,oBAAoB,MAAM;CAEnF,cAAc,gBAAgB,QAAQ;CACtC,MAAM,UAAU,SAAS,KAAK,GAAG,MAAM;CACvC,eAAe,MAAM;CACrB,MAAM,WA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E;GACA,eAAe,UAAU,SAAS,UAAU;IAC1C,WAAW,SAAS,QAAQ;IAC5B,aAAa,aAAa,gBAAgB,YAAY,eAAe,QAAQ,IAAI,KAAA;IACjF,kBACE,WAAW,CAAC,CAAC,YAAY,SAAS,OAAO,MAAM,UAAU,CAAC,CAAC,MAAM,YAAY;IAC/E,IAAI,mBAAmB,QAAQ,GAC7B,MAAM,IAAI,MAAM,wDAAwD;IAC1E,OAAO,4BACL,UACA,aACA,SACA,iBACA,QACF;GACF;GACA,eAAe,UAAU,UAAU,SAAS,UAAU;IACpD,WAAW,SAAS,QAAQ;IAC5B,aAAa,aAAa,gBAAgB,YAAY,eAAe,QAAQ,IAAI,KAAA;IACjF,OAAO,4BAA4B,UAAU,UAAU,aAAa,SAAS,QAAQ;GACvF;GACA,WAAW,OAAO;IAChB,UAAU;GACZ;GACA,eAAe,iBAAiB;IAC9B,OAAO,IAAI,iBAAiB;KAC1B,GAAG;KACH,SAAS;KACT,GAAI,iBAAiB,EAAE,gBAAgB,eAAe,eAAe,IAAI,CAAC;KAC1E,GAAG;KACH,GAAI,aAAa,EAAE,WAAW,WAAW,SAAS,IAAI,CAAC;IACzD,CAAC;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,mBAAmB,QAAQ;GAC7B;EACF;CACF,SAAS,OAAO;EACd,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,mBAAmB,QAAQ;EAC3B,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/windfoil/runtime.ts"],"sourcesContent":["import {\n WebGPUBackend,\n type InstancedBufferGeometry,\n type Side,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n GlyphRequest,\n SdfAtlas,\n SdfMotionOptions,\n TextFill,\n TextToneOptions,\n TextVertex,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport type { WindfoilColorPart, WindfoilColorResources } from './color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from './geometry.js'\nimport { WindfoilMaterial } from './WindfoilMaterial.js'\nimport {\n preprocessWindfoilGlyphsBatch,\n type WindfoilGlyphHeader,\n type WindfoilPreprocessStats,\n} from './preprocessCore.js'\nimport type { WindfoilSizeSwitch } from './sizeSwitch.js'\nimport {\n abortable,\n collectMissingRequests,\n createRetainedWindfoilStorage,\n drawnEffects,\n mergePreprocessStats,\n resolveOutlineRequests,\n throwIfAborted,\n type TextEffects,\n} from './storage.js'\nexport interface WindfoilBackend {\n readonly kind: 'windfoil' | 'slug'\n readonly layered: boolean\n /**\n * SDF atlas drawn by the companion part: glyphs without outlines plus size-switched glyphs,\n * and with `effects` every drawable outline.\n */\n readonly companion: SdfAtlas | null\n /**\n * The outline and drop shadow that an SDF underlay draws under the analytic glyphs, from\n * their companion slots; null without effects that draw anything.\n */\n readonly effects: TextEffects | null\n readonly color: WindfoilColorPart | null\n /** The `windfoil.sdfBelowPx` switch, or null when no glyph can switch. */\n readonly sizeSwitch: WindfoilSizeSwitch | null\n covers(key: string): boolean\n /** Whether the Windfoil primary batch draws this glyph. */\n primaryCovers(key: string): boolean\n /** Whether the primary batch or the colour part draws this glyph from its outline. */\n analyticCovers(key: string): boolean\n motionOrdinals(snapshot: DomLayoutSnapshot): Float32Array\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly storageBytes: number\n readonly preprocessStats: WindfoilPreprocessStats\n contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean\n createGeometry(\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n checked?: boolean,\n ): number | null\n append?(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<boolean>\n /** Whether geometry carries each glyph's font size, which a tone that dilates reads. */\n setGlyphEm(value: boolean): void\n createMaterial(options: {\n readonly fill?: TextFill\n readonly vertex?: TextVertex\n readonly shadowCutoff?: number\n readonly side?: Side\n /** `false` builds static text, without the motion graph. */\n readonly motion: SdfMotionOptions | false\n readonly maxSequence: number\n readonly layered?: boolean\n /** Reaches the text ink of the primary batch; colour parts and shapes stay exact. */\n readonly tone?: TextToneOptions | ResolvedTextTone | false\n }): GlyphTextMaterial\n dispose(): void\n}\n\n/** Windfoil or Slug options once `DomSdf` or `DomSlug` has chosen the outline provider. */\nexport type WindfoilBuildOptions = WindfoilOptions & {\n readonly outlineProvider: WindfoilOutlineProvider\n readonly missingGlyphs?: 'skip' | 'error'\n}\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildWindfoilBackend(\n renderer: WebGPURenderer,\n requests: readonly GlyphRequest[],\n options: WindfoilBuildOptions,\n signal: AbortSignal,\n companionBuilder?: {\n build(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<SdfAtlas>\n /** The caller's outline and drop shadow, which the companion then bakes every glyph for. */\n readonly effects?: TextEffects\n readonly headroom?: boolean\n },\n): Promise<WindfoilBackend | null> {\n const headroom = companionBuilder?.headroom === true\n const sdfBelow = options.sdfBelowPx\n const switchModule =\n sdfBelow === undefined ? null : await abortable(import('./sizeSwitch.js'), signal)\n // Before init, so an invalid threshold fails even where a fallback would be chosen.\n switchModule?.assertThreshold(sdfBelow)\n await abortable(renderer.init(), signal)\n throwIfAborted(signal)\n const fallback = options.fallback === 'sdf' || options.fallback === 'sdf-glyphs'\n if (!(renderer.backend instanceof WebGPUBackend)) {\n if (fallback) return null\n throw new Error(\n 'DomSdf: the Windfoil text backend requires WebGPU; set windfoil.fallback to \"sdf\" to fall back',\n )\n }\n const limit =\n (renderer.backend as unknown as { device?: { limits: { maxVertexBuffers: number } } }).device\n ?.limits.maxVertexBuffers ?? 8\n if (limit < 7) {\n if (fallback) return null\n throw new Error('DomSdf: Windfoil requires at least seven vertex buffers')\n }\n const effects = companionBuilder?.effects ? drawnEffects(companionBuilder.effects) : null\n const extended =\n !!effects ||\n requests.some((request) => request.shape) ||\n options.fallback === 'sdf-glyphs' ||\n options.compositing === 'shader' ||\n sdfBelow !== undefined\n let extensions = extended ? await abortable(import('./requests.js'), signal) : null\n const resolved = await resolveOutlineRequests(requests, options, signal, extensions)\n throwIfAborted(signal)\n const missing = resolved.filter((item) => item.outline === null)\n if (missing.length) {\n if (\n options.fallback === 'sdf' ||\n (options.fallback === 'sdf-glyphs' && missing.length === resolved.length)\n )\n return null\n if (options.fallback !== 'sdf-glyphs' || !companionBuilder)\n throw new Error(\n `DomSdf: Windfoil outlineProvider returned null for ${JSON.stringify(missing[0]!.request.character)} in ${missing[0]!.request.font.family}`,\n )\n }\n const needsRequests = !extensions && resolved.some((item) => item.outline?.clipBox)\n const needsLayerNormalization = resolved.some(\n (item) => item.outline?.layers !== undefined || item.outline?.clipBox !== undefined,\n )\n const [lateExtensions, initialLayerModule] =\n needsRequests || needsLayerNormalization\n ? await abortable(\n Promise.all([\n needsRequests ? import('./requests.js') : Promise.resolve(null),\n needsLayerNormalization ? import('./layerNormalization.js') : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n let layerModule = initialLayerModule\n const prepared = preprocessWindfoilGlyphsBatch(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\n // Colour glyphs the composite shader draws (see buildWindfoilColorResources).\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n )\n const switchable = companionBuilder\n ? (switchModule?.switchableRequests(resolved, prepared.glyphs) ?? [])\n : []\n // Effects bake every drawable outline for the underlay; an empty one is drawn by nothing.\n const companionReqs = effects\n ? resolved.flatMap((i) =>\n prepared.glyphs.get(i.request.key)?.monotonePieceCount ? [i.request] : [],\n )\n : switchable\n const layered = prepared.layered || missing.length > 0 || companionReqs.length > 0\n if (layered && limit < 8) {\n if (fallback) return null\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n }\n const wantsColor = [...prepared.glyphs.values()].some(\n (header) =>\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox)),\n )\n const colorPromise = wantsColor ? import('./color.js') : null\n const companionResource =\n (missing.length || companionReqs.length) && companionBuilder\n ? await extensions!.buildCompanion(\n companionBuilder,\n [...missing.map((item) => item.request), ...companionReqs],\n signal,\n )\n : null\n let companion = companionResource?.atlas ?? null\n const view =\n companion && switchable.length\n ? switchModule!.companionView(\n companion,\n missing.map((item) => item.request.key),\n switchable,\n )\n : null\n if (view && !effects) {\n companion = view.atlas\n if (!companion) companionResource!.dispose()\n }\n let coverage: ReturnType<typeof createRetainedWindfoilStorage> | undefined,\n colorResources: WindfoilColorResources | null = null\n try {\n const colorModule = colorPromise ? await abortable(colorPromise, signal) : null\n throwIfAborted(signal)\n coverage = createRetainedWindfoilStorage(\n renderer,\n prepared,\n headroom ? { minCurveFloats: 4096, minRowUints: 1536, rowAlign: 6 } : false,\n )\n colorResources =\n colorModule?.buildWindfoilColorResources(renderer, prepared, options, coverage, signal) ??\n null\n const glyphs = prepared.glyphs as Map<string, WindfoilGlyphHeader>\n const plainGlyphs = (colorResources?.plainGlyphs ?? prepared.glyphs) as Map<\n string,\n WindfoilGlyphHeader\n >\n let usedCurves = prepared.curves.length\n let usedRows = prepared.rows.length\n let stats = prepared.stats\n const ordinalsCache = new WeakMap<DomLayoutSnapshot, Float32Array>()\n const motionOrdinals = (snapshot: DomLayoutSnapshot): Float32Array => {\n let cached = ordinalsCache.get(snapshot)\n if (!cached) {\n if (extensions) {\n cached = extensions.motionOrdinals(snapshot, glyphs, companion)\n } else {\n const count = snapshot.glyphs.length\n cached = new Float32Array(count)\n for (let i = 0; i < count; i++) cached[i] = i\n }\n ordinalsCache.set(snapshot, cached)\n }\n return cached\n }\n const sizeSwitch = view?.keys.size\n ? switchModule!.createSizeSwitch(sdfBelow!, view.keys, glyphs, motionOrdinals)\n : null\n // A tone that dilates the outline reads each glyph's font size from `sdfMeta.z`: zero or\n // below never switches, so the size switch keeps its own meaning of the sign. An SVG\n // shape has no font size: its outline stays where it is.\n let glyphEm = false\n const sized = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n const withEm = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n let layout = sized.get(snapshot)\n if (!layout) {\n layout = {\n ...snapshot,\n sizeSwitched: true,\n glyphs: snapshot.glyphs.map((glyph) => ({\n ...glyph,\n switchEm: glyph.shapeGroup === undefined ? -glyph.fontSize : 0,\n })),\n }\n sized.set(snapshot, layout)\n }\n return layout\n }\n const switched = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n const layout = glyphEm ? withEm(snapshot) : snapshot\n return sizeSwitch?.layout(layout) ?? layout\n }\n let geometryLayered = layered,\n disposed = false\n const retained = coverage\n return {\n kind: 'windfoil',\n layered,\n companion,\n effects,\n color: colorResources?.composite ?? null,\n sizeSwitch,\n motionOrdinals,\n glyphs,\n covers(key) {\n return glyphs.has(key) || !!companion?.glyphs.has(key)\n },\n primaryCovers(key) {\n return !!plainGlyphs.get(key)?.monotonePieceCount\n },\n analyticCovers(key) {\n return (\n !!plainGlyphs.get(key)?.monotonePieceCount ||\n !!colorResources?.composite?.glyphs.get(key)?.monotonePieceCount\n )\n },\n storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),\n get preprocessStats() {\n return stats\n },\n contentFits(geometry, snapshot) {\n return windfoilContentFits(geometry, switched(snapshot), plainGlyphs)\n },\n createGeometry(snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n geometryLayered =\n layered || !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n if (geometryLayered && limit < 8)\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n return createWindfoilGlyphGeometry(\n snapshot,\n plainGlyphs,\n padding,\n geometryLayered,\n ordinals,\n )\n },\n updateGeometry(geometry, snapshot, padding, ordinals, checked = false) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n return updateWindfoilGlyphGeometry(\n geometry,\n snapshot,\n plainGlyphs,\n padding,\n ordinals,\n checked,\n )\n },\n async append(nextRequests, appendSignal) {\n if (disposed || effects) return false\n const missingReqs = collectMissingRequests(\n nextRequests,\n (key) => glyphs.has(key) || !!companion?.glyphs.has(key),\n )\n if (missingReqs.length === 0) return true\n if (!extensions && missingReqs.some((req) => req.shape !== undefined)) {\n extensions = await abortable(import('./requests.js'), appendSignal)\n }\n const deltaResolved = await resolveOutlineRequests(\n missingReqs,\n options,\n appendSignal,\n extensions,\n )\n throwIfAborted(appendSignal)\n if (deltaResolved.some((item) => item.outline === null)) return false\n const nonNull = deltaResolved as {\n request: GlyphRequest\n outline: NonNullable<(typeof deltaResolved)[number]['outline']>\n }[]\n if (\n !layerModule &&\n nonNull.some(\n (item) => item.outline.layers !== undefined || item.outline.clipBox !== undefined,\n )\n ) {\n layerModule = await abortable(import('./layerNormalization.js'), appendSignal)\n throwIfAborted(appendSignal)\n }\n const delta = preprocessWindfoilGlyphsBatch(\n nonNull,\n {\n signal: appendSignal,\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n usedCurves,\n usedRows,\n )\n if (delta.layered && !layered) return false\n if (\n companionBuilder &&\n switchModule &&\n switchModule.switchableRequests(deltaResolved, delta.glyphs).length > 0\n ) {\n return false\n }\n for (const header of delta.glyphs.values()) {\n if (\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox))\n ) {\n return false\n }\n }\n if (\n usedCurves + delta.curves.length > retained.curveCapacityFloats ||\n usedRows + delta.rows.length > retained.rowCapacityUints\n ) {\n return false\n }\n throwIfAborted(appendSignal)\n retained.writeCurves(usedCurves, delta.curves)\n retained.writeRows(usedRows, delta.rows)\n usedCurves += delta.curves.length\n usedRows += delta.rows.length\n for (const [key, header] of delta.glyphs) {\n glyphs.set(key, header)\n if (plainGlyphs !== glyphs) plainGlyphs.set(key, header)\n }\n stats = mergePreprocessStats(stats, delta.stats, glyphs.size)\n return true\n },\n setGlyphEm(value) {\n glyphEm = value\n },\n createMaterial(materialOptions) {\n return new WindfoilMaterial({\n curves: retained.curves,\n rows: retained.rows,\n layered: geometryLayered,\n ...(colorResources ? { paintFunctions: colorResources.paintFunctions } : {}),\n ...materialOptions,\n ...(sizeSwitch ? { keepGlyph: sizeSwitch.windfoil } : {}),\n })\n },\n dispose() {\n if (disposed) return\n disposed = true\n retained.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n },\n }\n } catch (error) {\n coverage?.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;;AAyGA,eAAsB,qBACpB,UACA,UACA,SACA,QACA,kBAMiC;CACjC,MAAM,WAAW,kBAAkB,aAAa;CAChD,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,oBAAoB,MAAM;CAEnF,cAAc,gBAAgB,QAAQ;CACtC,MAAM,UAAU,SAAS,KAAK,GAAG,MAAM;CACvC,eAAe,MAAM;CACrB,MAAM,WAAW,QAAQ,aAAa,SAAS,Q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AAO;IAGX,IACE,aAAa,MAAM,OAAO,SAAS,SAAS,uBAC5C,WAAW,MAAM,KAAK,SAAS,SAAS,kBAExC,OAAO;IAET,eAAe,YAAY;IAC3B,SAAS,YAAY,YAAY,MAAM,MAAM;IAC7C,SAAS,UAAU,UAAU,MAAM,IAAI;IACvC,cAAc,MAAM,OAAO;IAC3B,YAAY,MAAM,KAAK;IACvB,KAAK,MAAM,CAAC,KAAK,WAAW,MAAM,QAAQ;KACxC,OAAO,IAAI,KAAK,MAAM;KACtB,IAAI,gBAAgB,QAAQ,YAAY,IAAI,KAAK,MAAM;IACzD;IACA,QAAQ,qBAAqB,OAAO,MAAM,OAAO,OAAO,IAAI;IAC5D,OAAO;GACT;GACA,WAAW,OAAO;IAChB,UAAU;GACZ;GACA,eAAe,iBAAiB;IAC9B,OAAO,IAAI,iBAAiB;KAC1B,QAAQ,SAAS;KACjB,MAAM,SAAS;KACf,SAAS;KACT,GAAI,iBAAiB,EAAE,gBAAgB,eAAe,eAAe,IAAI,CAAC;KAC1E,GAAG;KACH,GAAI,aAAa,EAAE,WAAW,WAAW,SAAS,IAAI,CAAC;IACzD,CAAC;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,mBAAmB,QAAQ;GAC7B;EACF;CACF,SAAS,OAAO;EACd,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,mBAAmB,QAAQ;EAC3B,MAAM;CACR;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { abortable,
|
|
1
|
+
import { abortable, throwIfAborted } from "./abortable.js";
|
|
2
|
+
import { createWindfoilStorage } from "./storage.js";
|
|
2
3
|
import { preprocessWindfoilOutlines } from "./preprocess.js";
|
|
3
4
|
// src/windfoil/shapeResources.ts
|
|
4
5
|
var active = /* @__PURE__ */ new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapeResources.js","names":[],"sources":["../../src/windfoil/shapeResources.ts"],"sourcesContent":["import type { WebGPURenderer } from 'three/webgpu'\nimport type { WindfoilColorStop, WindfoilGlyphOutline, WindfoilPaint } from '../types.js'\nimport {\n preprocessWindfoilOutlines,\n WINDFOIL_TARGET_PIECES_PER_BAND,\n type WindfoilPreprocessResult,\n} from './preprocess.js'\nimport type { WindfoilColorResources } from './color.js'\nimport { abortable, createWindfoilStorage, throwIfAborted } from './storage.js'\n\ntype OutlineEntries = readonly (readonly [string, WindfoilGlyphOutline])[]\ntype ShapeStorage = ReturnType<typeof createWindfoilStorage>\ninterface ShapeResources {\n readonly prepared: WindfoilPreprocessResult\n readonly storage: ShapeStorage\n readonly colorResources: WindfoilColorResources | undefined\n readonly preprocessMs: number\n dispose(): void\n}\ninterface CachedResources {\n readonly outlines: OutlineEntries\n readonly shader: boolean\n readonly target: number\n readonly backend: object\n readonly device: object | undefined\n readonly controller: AbortController\n promise: Promise<ShapeResources>\n resources?: ShapeResources\n references: number\n}\n\n// A source only retains resources while a pending build or a live handle leases them.\n// Storage nodes belong to one renderer; sharing them across devices is invalid.\nconst active = new WeakMap<object, WeakMap<WebGPURenderer, Set<CachedResources>>>()\n\n/** Validation/preprocessing read numeric indices; ignore any custom iterator. */\nfunction copyIndexed<T>(value: ArrayLike<T>): T[] {\n const result = new Array<T>(value.length)\n for (let i = 0; i < result.length; i++) result[i] = value[i]!\n return result\n}\n\nfunction copyQuadratics(value: ArrayLike<number>): ArrayLike<number> {\n return value instanceof Float32Array ? value.slice() : copyIndexed(value)\n}\n\n/** Copy supported paint fields without converting invalid gradient tuples into valid arrays. */\nfunction copyPaint(paint: WindfoilPaint): WindfoilPaint {\n const tuple = <T>(value: T): T => (Array.isArray(value) ? copyIndexed(value) : value) as T\n if (paint.type === 'foreground')\n return { type: paint.type, ...(paint.alpha === undefined ? {} : { alpha: paint.alpha }) }\n if (paint.type === 'solid')\n return { type: paint.type, color: copyIndexed(paint.color) as [number, number, number, number] }\n const gradient = {\n ...(paint.extend === undefined ? {} : { extend: paint.extend }),\n ...(paint.transform === undefined ? {} : { transform: tuple(paint.transform) }),\n stops: Array.isArray(paint.stops)\n ? (paint.stops as readonly WindfoilColorStop[]).map((stop) => ({\n offset: stop.offset,\n color: tuple(stop.color),\n }))\n : paint.stops,\n }\n if (paint.type === 'linear')\n return {\n ...gradient,\n type: paint.type,\n p0: tuple(paint.p0),\n p1: tuple(paint.p1),\n ...(paint.p2 === undefined ? {} : { p2: tuple(paint.p2) }),\n }\n if (paint.type === 'radial')\n return {\n ...gradient,\n type: paint.type,\n c0: tuple(paint.c0),\n r0: paint.r0,\n c1: tuple(paint.c1),\n r1: paint.r1,\n }\n return {\n ...gradient,\n type: paint.type,\n center: tuple(paint.center),\n startAngle: paint.startAngle,\n endAngle: paint.endAngle,\n }\n}\n\n/** Validation reads a null layer list from untyped callers as an empty one. */\nfunction layersOf(outline: WindfoilGlyphOutline): WindfoilGlyphOutline['layers'] {\n const layers = outline.layers as WindfoilGlyphOutline['layers'] | null\n return layers === null ? [] : layers\n}\n\nfunction copyOutlines(entries: OutlineEntries): OutlineEntries {\n return entries.map(([key, outline]) => {\n const layers = layersOf(outline)\n return [\n key,\n {\n unitsPerEm: outline.unitsPerEm,\n ascent: outline.ascent,\n descent: outline.descent,\n bbox: copyIndexed(outline.bbox) as [number, number, number, number],\n quadratics: copyQuadratics(outline.quadratics),\n ...(outline.clipBox === undefined\n ? {}\n : { clipBox: copyIndexed(outline.clipBox) as [number, number, number, number] }),\n ...(layers === undefined\n ? {}\n : {\n layers: copyIndexed(layers).map((layer) => ({\n quadratics: copyQuadratics(layer.quadratics),\n ...(layer.bbox === undefined\n ? {}\n : { bbox: copyIndexed(layer.bbox) as [number, number, number, number] }),\n paint: copyPaint(layer.paint),\n })),\n }),\n },\n ]\n })\n}\n\n/** Compare every supported input field exactly; no hash can turn mutations into a cache hit. */\nfunction equalValues(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (!equalValues(a[i], b[i])) return false\n return true\n }\n const left = Object.entries(a),\n right = Object.entries(b)\n return (\n left.length === right.length &&\n left.every(\n ([key, value], index) => key === right[index]![0] && equalValues(value, right[index]![1]),\n )\n )\n}\n\nfunction equalNumbers(a: ArrayLike<number> | undefined, b: ArrayLike<number> | undefined): boolean {\n if (a === undefined || b === undefined) return a === b\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false\n return true\n}\n\nfunction equalPaint(a: WindfoilPaint, raw: WindfoilPaint): boolean {\n if (a.type === 'foreground' && raw.type === 'foreground') return Object.is(a.alpha, raw.alpha)\n if (a.type === 'solid' && raw.type === 'solid') return equalNumbers(a.color, raw.color)\n return equalValues(a, copyPaint(raw))\n}\n\nfunction equalOutlines(snapshot: OutlineEntries, entries: OutlineEntries): boolean {\n if (snapshot.length !== entries.length) return false\n return snapshot.every(([key, a], index) => {\n const [nextKey, b] = entries[index]!\n if (\n key !== nextKey ||\n !Object.is(a.unitsPerEm, b.unitsPerEm) ||\n !Object.is(a.ascent, b.ascent) ||\n !Object.is(a.descent, b.descent) ||\n !equalNumbers(a.bbox, b.bbox) ||\n !equalNumbers(a.quadratics, b.quadratics) ||\n !equalNumbers(a.clipBox, b.clipBox)\n )\n return false\n const layers = layersOf(b)\n if (a.layers === undefined || layers === undefined) return a.layers === layers\n return (\n a.layers.length === layers.length &&\n a.layers.every((layer, i) => {\n const other = layers[i]!\n return (\n equalNumbers(layer.bbox, other.bbox) &&\n equalNumbers(layer.quadratics, other.quadratics) &&\n equalPaint(layer.paint, other.paint)\n )\n })\n )\n })\n}\n\nasync function buildResources(\n renderer: WebGPURenderer,\n entries: OutlineEntries,\n shader: boolean,\n target: number,\n signal: AbortSignal,\n): Promise<ShapeResources> {\n const earlyColorPromise = shader ? import('./color.js') : null\n const start = performance.now(),\n prepared = preprocessWindfoilOutlines(\n entries.map(([key, outline]) => ({\n key,\n outline: shader ? { ...outline, layers: outline.layers ?? [] } : outline,\n })),\n { signal, orientLayers: () => shader, targetPiecesPerBand: target },\n ),\n preprocessMs = performance.now() - start\n const colorModule =\n shader ||\n [...prepared.glyphs.values()].some((header) =>\n header.layers?.some((layer) => layer.paintKind === 2),\n )\n ? await abortable(earlyColorPromise ?? import('./color.js'), signal)\n : null\n throwIfAborted(signal)\n const storage = createWindfoilStorage(renderer, prepared)\n let colorResources: WindfoilColorResources | undefined\n try {\n colorResources = colorModule?.buildWindfoilColorResources(\n renderer,\n prepared,\n { outlineProvider: () => null, ...(shader ? { compositing: 'shader' as const } : {}) },\n storage,\n signal,\n true,\n )\n let disposed = false\n return {\n prepared,\n storage,\n colorResources,\n preprocessMs,\n dispose() {\n if (disposed) return\n disposed = true\n colorResources?.dispose()\n storage.dispose()\n },\n }\n } catch (error) {\n colorResources?.dispose()\n storage.dispose()\n throw error\n }\n}\n\nexport async function acquireWindfoilShapeResources(\n renderer: WebGPURenderer,\n source: object,\n entries: OutlineEntries,\n shader: boolean,\n targetPiecesPerBand?: number,\n signal?: AbortSignal,\n): Promise<Omit<ShapeResources, 'dispose'> & { readonly release: () => void }> {\n throwIfAborted(signal)\n const target = targetPiecesPerBand ?? WINDFOIL_TARGET_PIECES_PER_BAND\n const backend = renderer.backend,\n device = (backend as { device?: object }).device\n let renderers = active.get(source)\n if (!renderers) active.set(source, (renderers = new WeakMap()))\n let bucket = renderers.get(renderer)\n if (!bucket) renderers.set(renderer, (bucket = new Set()))\n let entry = [...bucket].find(\n (candidate) =>\n candidate.shader === shader &&\n candidate.target === target &&\n candidate.backend === backend &&\n candidate.device === device &&\n equalOutlines(candidate.outlines, entries),\n )\n const reused = !!entry\n if (!entry) {\n // Snapshot before any lazy import, so caller mutations cannot change an in-flight build.\n const outlines = copyOutlines(entries)\n const controller = new AbortController()\n entry = {\n outlines,\n shader,\n target,\n backend,\n device,\n controller,\n references: 0,\n promise: buildResources(renderer, outlines, shader, target, controller.signal),\n }\n const created = entry\n entry.promise = entry.promise.then(\n (resources) => {\n created.resources = resources\n if (created.references === 0) resources.dispose()\n return resources\n },\n (error: unknown) => {\n bucket.delete(created)\n throw error\n },\n )\n bucket.add(entry)\n }\n entry.references++\n const leased = entry\n let released = false\n const release = (): void => {\n if (released) return\n released = true\n if (--leased.references === 0) {\n bucket.delete(leased)\n leased.controller.abort()\n leased.resources?.dispose()\n }\n }\n try {\n const resources = await abortable(entry.promise, signal)\n throwIfAborted(signal)\n return {\n prepared: resources.prepared,\n storage: resources.storage,\n colorResources: resources.colorResources,\n preprocessMs: reused ? 0 : resources.preprocessMs,\n release,\n }\n } catch (error) {\n release()\n throw error\n }\n}\n"],"mappings":";;;AAiCA,IAAM,yBAAS,IAAI,QAA+D;;AAGlF,SAAS,YAAe,OAA0B;CAChD,MAAM,SAAS,IAAI,MAAS,MAAM,MAAM;CACxC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;CAC1D,OAAO;AACT;AAEA,SAAS,eAAe,OAA6C;CACnE,OAAO,iBAAiB,eAAe,MAAM,MAAM,IAAI,YAAY,KAAK;AAC1E;;AAGA,SAAS,UAAU,OAAqC;CACtD,MAAM,SAAY,UAAiB,MAAM,QAAQ,KAAK,IAAI,YAAY,KAAK,IAAI;CAC/E,IAAI,MAAM,SAAS,cACjB,OAAO;EAAE,MAAM,MAAM;EAAM,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,MAAM,MAAM;CAAG;CAC1F,IAAI,MAAM,SAAS,SACjB,OAAO;EAAE,MAAM,MAAM;EAAM,OAAO,YAAY,MAAM,KAAK;CAAsC;CACjG,MAAM,WAAW;EACf,GAAI,MAAM,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;EAC7D,GAAI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S,CAAC,CAAC;CACjB,IAAI,CAAC,OAAO;EAEV,MAAM,WAAW,aAAa,OAAO;EACrC,MAAM,aAAa,IAAI,gBAAgB;EACvC,QAAQ;GACN;GACA;GACA;GACA;GACA;GACA;GACA,YAAY;GACZ,SAAS,eAAe,UAAU,UAAU,QAAQ,QAAQ,WAAW,MAAM;EAC/E;EACA,MAAM,UAAU;EAChB,MAAM,UAAU,MAAM,QAAQ,MAC3B,cAAc;GACb,QAAQ,YAAY;GACpB,IAAI,QAAQ,eAAe,GAAG,UAAU,QAAQ;GAChD,OAAO;EACT,IACC,UAAmB;GAClB,OAAO,OAAO,OAAO;GACrB,MAAM;EACR,CACF;EACA,OAAO,IAAI,KAAK;CAClB;CACA,MAAM;CACN,MAAM,SAAS;CACf,IAAI,WAAW;CACf,MAAM,gBAAsB;EAC1B,IAAI,UAAU;EACd,WAAW;EACX,IAAI,EAAE,OAAO,eAAe,GAAG;GAC7B,OAAO,OAAO,MAAM;GACpB,OAAO,WAAW,MAAM;GACxB,OAAO,WAAW,QAAQ;EAC5B;CACF;CACA,IAAI;EACF,MAAM,YAAY,MAAM,UAAU,MAAM,SAAS,MAAM;EACvD,eAAe,MAAM;EACrB,OAAO;GACL,UAAU,UAAU;GACpB,SAAS,UAAU;GACnB,gBAAgB,UAAU;GAC1B,cAAc,SAAS,IAAI,UAAU;GACrC;EACF;CACF,SAAS,OAAO;EACd,QAAQ;EACR,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"shapeResources.js","names":[],"sources":["../../src/windfoil/shapeResources.ts"],"sourcesContent":["import type { WebGPURenderer } from 'three/webgpu'\nimport type { WindfoilColorStop, WindfoilGlyphOutline, WindfoilPaint } from '../types.js'\nimport {\n preprocessWindfoilOutlines,\n WINDFOIL_TARGET_PIECES_PER_BAND,\n type WindfoilPreprocessResult,\n} from './preprocess.js'\nimport type { WindfoilColorResources } from './color.js'\nimport { abortable, createWindfoilStorage, throwIfAborted } from './storage.js'\n\ntype OutlineEntries = readonly (readonly [string, WindfoilGlyphOutline])[]\ntype ShapeStorage = ReturnType<typeof createWindfoilStorage>\ninterface ShapeResources {\n readonly prepared: WindfoilPreprocessResult\n readonly storage: ShapeStorage\n readonly colorResources: WindfoilColorResources | undefined\n readonly preprocessMs: number\n dispose(): void\n}\ninterface CachedResources {\n readonly outlines: OutlineEntries\n readonly shader: boolean\n readonly target: number\n readonly backend: object\n readonly device: object | undefined\n readonly controller: AbortController\n promise: Promise<ShapeResources>\n resources?: ShapeResources\n references: number\n}\n\n// A source only retains resources while a pending build or a live handle leases them.\n// Storage nodes belong to one renderer; sharing them across devices is invalid.\nconst active = new WeakMap<object, WeakMap<WebGPURenderer, Set<CachedResources>>>()\n\n/** Validation/preprocessing read numeric indices; ignore any custom iterator. */\nfunction copyIndexed<T>(value: ArrayLike<T>): T[] {\n const result = new Array<T>(value.length)\n for (let i = 0; i < result.length; i++) result[i] = value[i]!\n return result\n}\n\nfunction copyQuadratics(value: ArrayLike<number>): ArrayLike<number> {\n return value instanceof Float32Array ? value.slice() : copyIndexed(value)\n}\n\n/** Copy supported paint fields without converting invalid gradient tuples into valid arrays. */\nfunction copyPaint(paint: WindfoilPaint): WindfoilPaint {\n const tuple = <T>(value: T): T => (Array.isArray(value) ? copyIndexed(value) : value) as T\n if (paint.type === 'foreground')\n return { type: paint.type, ...(paint.alpha === undefined ? {} : { alpha: paint.alpha }) }\n if (paint.type === 'solid')\n return { type: paint.type, color: copyIndexed(paint.color) as [number, number, number, number] }\n const gradient = {\n ...(paint.extend === undefined ? {} : { extend: paint.extend }),\n ...(paint.transform === undefined ? {} : { transform: tuple(paint.transform) }),\n stops: Array.isArray(paint.stops)\n ? (paint.stops as readonly WindfoilColorStop[]).map((stop) => ({\n offset: stop.offset,\n color: tuple(stop.color),\n }))\n : paint.stops,\n }\n if (paint.type === 'linear')\n return {\n ...gradient,\n type: paint.type,\n p0: tuple(paint.p0),\n p1: tuple(paint.p1),\n ...(paint.p2 === undefined ? {} : { p2: tuple(paint.p2) }),\n }\n if (paint.type === 'radial')\n return {\n ...gradient,\n type: paint.type,\n c0: tuple(paint.c0),\n r0: paint.r0,\n c1: tuple(paint.c1),\n r1: paint.r1,\n }\n return {\n ...gradient,\n type: paint.type,\n center: tuple(paint.center),\n startAngle: paint.startAngle,\n endAngle: paint.endAngle,\n }\n}\n\n/** Validation reads a null layer list from untyped callers as an empty one. */\nfunction layersOf(outline: WindfoilGlyphOutline): WindfoilGlyphOutline['layers'] {\n const layers = outline.layers as WindfoilGlyphOutline['layers'] | null\n return layers === null ? [] : layers\n}\n\nfunction copyOutlines(entries: OutlineEntries): OutlineEntries {\n return entries.map(([key, outline]) => {\n const layers = layersOf(outline)\n return [\n key,\n {\n unitsPerEm: outline.unitsPerEm,\n ascent: outline.ascent,\n descent: outline.descent,\n bbox: copyIndexed(outline.bbox) as [number, number, number, number],\n quadratics: copyQuadratics(outline.quadratics),\n ...(outline.clipBox === undefined\n ? {}\n : { clipBox: copyIndexed(outline.clipBox) as [number, number, number, number] }),\n ...(layers === undefined\n ? {}\n : {\n layers: copyIndexed(layers).map((layer) => ({\n quadratics: copyQuadratics(layer.quadratics),\n ...(layer.bbox === undefined\n ? {}\n : { bbox: copyIndexed(layer.bbox) as [number, number, number, number] }),\n paint: copyPaint(layer.paint),\n })),\n }),\n },\n ]\n })\n}\n\n/** Compare every supported input field exactly; no hash can turn mutations into a cache hit. */\nfunction equalValues(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (!equalValues(a[i], b[i])) return false\n return true\n }\n const left = Object.entries(a),\n right = Object.entries(b)\n return (\n left.length === right.length &&\n left.every(\n ([key, value], index) => key === right[index]![0] && equalValues(value, right[index]![1]),\n )\n )\n}\n\nfunction equalNumbers(a: ArrayLike<number> | undefined, b: ArrayLike<number> | undefined): boolean {\n if (a === undefined || b === undefined) return a === b\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false\n return true\n}\n\nfunction equalPaint(a: WindfoilPaint, raw: WindfoilPaint): boolean {\n if (a.type === 'foreground' && raw.type === 'foreground') return Object.is(a.alpha, raw.alpha)\n if (a.type === 'solid' && raw.type === 'solid') return equalNumbers(a.color, raw.color)\n return equalValues(a, copyPaint(raw))\n}\n\nfunction equalOutlines(snapshot: OutlineEntries, entries: OutlineEntries): boolean {\n if (snapshot.length !== entries.length) return false\n return snapshot.every(([key, a], index) => {\n const [nextKey, b] = entries[index]!\n if (\n key !== nextKey ||\n !Object.is(a.unitsPerEm, b.unitsPerEm) ||\n !Object.is(a.ascent, b.ascent) ||\n !Object.is(a.descent, b.descent) ||\n !equalNumbers(a.bbox, b.bbox) ||\n !equalNumbers(a.quadratics, b.quadratics) ||\n !equalNumbers(a.clipBox, b.clipBox)\n )\n return false\n const layers = layersOf(b)\n if (a.layers === undefined || layers === undefined) return a.layers === layers\n return (\n a.layers.length === layers.length &&\n a.layers.every((layer, i) => {\n const other = layers[i]!\n return (\n equalNumbers(layer.bbox, other.bbox) &&\n equalNumbers(layer.quadratics, other.quadratics) &&\n equalPaint(layer.paint, other.paint)\n )\n })\n )\n })\n}\n\nasync function buildResources(\n renderer: WebGPURenderer,\n entries: OutlineEntries,\n shader: boolean,\n target: number,\n signal: AbortSignal,\n): Promise<ShapeResources> {\n const earlyColorPromise = shader ? import('./color.js') : null\n const start = performance.now(),\n prepared = preprocessWindfoilOutlines(\n entries.map(([key, outline]) => ({\n key,\n outline: shader ? { ...outline, layers: outline.layers ?? [] } : outline,\n })),\n { signal, orientLayers: () => shader, targetPiecesPerBand: target },\n ),\n preprocessMs = performance.now() - start\n const colorModule =\n shader ||\n [...prepared.glyphs.values()].some((header) =>\n header.layers?.some((layer) => layer.paintKind === 2),\n )\n ? await abortable(earlyColorPromise ?? import('./color.js'), signal)\n : null\n throwIfAborted(signal)\n const storage = createWindfoilStorage(renderer, prepared)\n let colorResources: WindfoilColorResources | undefined\n try {\n colorResources = colorModule?.buildWindfoilColorResources(\n renderer,\n prepared,\n { outlineProvider: () => null, ...(shader ? { compositing: 'shader' as const } : {}) },\n storage,\n signal,\n true,\n )\n let disposed = false\n return {\n prepared,\n storage,\n colorResources,\n preprocessMs,\n dispose() {\n if (disposed) return\n disposed = true\n colorResources?.dispose()\n storage.dispose()\n },\n }\n } catch (error) {\n colorResources?.dispose()\n storage.dispose()\n throw error\n }\n}\n\nexport async function acquireWindfoilShapeResources(\n renderer: WebGPURenderer,\n source: object,\n entries: OutlineEntries,\n shader: boolean,\n targetPiecesPerBand?: number,\n signal?: AbortSignal,\n): Promise<Omit<ShapeResources, 'dispose'> & { readonly release: () => void }> {\n throwIfAborted(signal)\n const target = targetPiecesPerBand ?? WINDFOIL_TARGET_PIECES_PER_BAND\n const backend = renderer.backend,\n device = (backend as { device?: object }).device\n let renderers = active.get(source)\n if (!renderers) active.set(source, (renderers = new WeakMap()))\n let bucket = renderers.get(renderer)\n if (!bucket) renderers.set(renderer, (bucket = new Set()))\n let entry = [...bucket].find(\n (candidate) =>\n candidate.shader === shader &&\n candidate.target === target &&\n candidate.backend === backend &&\n candidate.device === device &&\n equalOutlines(candidate.outlines, entries),\n )\n const reused = !!entry\n if (!entry) {\n // Snapshot before any lazy import, so caller mutations cannot change an in-flight build.\n const outlines = copyOutlines(entries)\n const controller = new AbortController()\n entry = {\n outlines,\n shader,\n target,\n backend,\n device,\n controller,\n references: 0,\n promise: buildResources(renderer, outlines, shader, target, controller.signal),\n }\n const created = entry\n entry.promise = entry.promise.then(\n (resources) => {\n created.resources = resources\n if (created.references === 0) resources.dispose()\n return resources\n },\n (error: unknown) => {\n bucket.delete(created)\n throw error\n },\n )\n bucket.add(entry)\n }\n entry.references++\n const leased = entry\n let released = false\n const release = (): void => {\n if (released) return\n released = true\n if (--leased.references === 0) {\n bucket.delete(leased)\n leased.controller.abort()\n leased.resources?.dispose()\n }\n }\n try {\n const resources = await abortable(entry.promise, signal)\n throwIfAborted(signal)\n return {\n prepared: resources.prepared,\n storage: resources.storage,\n colorResources: resources.colorResources,\n preprocessMs: reused ? 0 : resources.preprocessMs,\n release,\n }\n } catch (error) {\n release()\n throw error\n }\n}\n"],"mappings":";;;;AAiCA,IAAM,yBAAS,IAAI,QAA+D;;AAGlF,SAAS,YAAe,OAA0B;CAChD,MAAM,SAAS,IAAI,MAAS,MAAM,MAAM;CACxC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;CAC1D,OAAO;AACT;AAEA,SAAS,eAAe,OAA6C;CACnE,OAAO,iBAAiB,eAAe,MAAM,MAAM,IAAI,YAAY,KAAK;AAC1E;;AAGA,SAAS,UAAU,OAAqC;CACtD,MAAM,SAAY,UAAiB,MAAM,QAAQ,KAAK,IAAI,YAAY,KAAK,IAAI;CAC/E,IAAI,MAAM,SAAS,cACjB,OAAO;EAAE,MAAM,MAAM;EAAM,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,MAAM,MAAM;CAAG;CAC1F,IAAI,MAAM,SAAS,SACjB,OAAO;EAAE,MAAM,MAAM;EAAM,OAAO,YAAY,MAAM,KAAK;CAAsC;CACjG,MAAM,WAAW;EACf,GAAI,MAAM,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;EAC7D,GAAI,MAAM,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,MAAM,MAAM,SAAS,EAAE;EAC7E,OAAO,MAAM,QAAQ,MAAM,KAAK,IAC3B,MAAM,MAAuC,KAAK,UAAU;GAC3D,QAAQ,KAAK;GACb,OAAO,MAAM,KAAK,KAAK;EACzB,EAAE,IACF,MAAM;CACZ;CACA,IAAI,MAAM,SAAS,UACjB,OAAO;EACL,GAAG;EACH,MAAM,MAAM;EACZ,IAA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Y;GACpB,IAAI,QAAQ,eAAe,GAAG,UAAU,QAAQ;GAChD,OAAO;EACT,IACC,UAAmB;GAClB,OAAO,OAAO,OAAO;GACrB,MAAM;EACR,CACF;EACA,OAAO,IAAI,KAAK;CAClB;CACA,MAAM;CACN,MAAM,SAAS;CACf,IAAI,WAAW;CACf,MAAM,gBAAsB;EAC1B,IAAI,UAAU;EACd,WAAW;EACX,IAAI,EAAE,OAAO,eAAe,GAAG;GAC7B,OAAO,OAAO,MAAM;GACpB,OAAO,WAAW,MAAM;GACxB,OAAO,WAAW,QAAQ;EAC5B;CACF;CACA,IAAI;EACF,MAAM,YAAY,MAAM,UAAU,MAAM,SAAS,MAAM;EACvD,eAAe,MAAM;EACrB,OAAO;GACL,UAAU,UAAU;GACpB,SAAS,UAAU;GACnB,gBAAgB,UAAU;GAC1B,cAAc,SAAS,IAAI,UAAU;GACrC;EACF;CACF,SAAS,OAAO;EACd,QAAQ;EACR,MAAM;CACR;AACF"}
|
package/dist/windfoil/shapes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAnimatedMotion } from "../text/GlyphTextMaterial.js";
|
|
2
|
-
import { abortable, throwIfAborted } from "./
|
|
2
|
+
import { abortable, throwIfAborted } from "./abortable.js";
|
|
3
3
|
import { WindfoilMaterial } from "./WindfoilMaterial.js";
|
|
4
4
|
import { validateWindfoilGlyphOutline } from "./preprocess.js";
|
|
5
5
|
import { createWindfoilShapeGeometry, setShapeBounds, shapeGlyphs, updateWindfoilShapeGeometry, validateShapeInstances } from "./shapeGeometry.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Node, UniformNode } from 'three/webgpu';
|
|
2
|
+
export declare const KERNEL_SKIRT_PX = 0.5625;
|
|
3
|
+
export declare const MULTISAMPLE_SKIRT_PX = 0.9375;
|
|
4
|
+
/**
|
|
5
|
+
* The skirt of the pass being drawn, in pixels: one uniform for every Windfoil/Slug 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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { renderGroup, uniform } from "three/tsl";
|
|
2
|
+
// src/windfoil/skirt.ts
|
|
3
|
+
var KERNEL_SKIRT_PX = .5625;
|
|
4
|
+
var MULTISAMPLE_SKIRT_PX = .9375;
|
|
5
|
+
var kernelSkirt;
|
|
6
|
+
/**
|
|
7
|
+
* The skirt of the pass being drawn, in pixels: one uniform for every Windfoil/Slug material, set
|
|
8
|
+
* from the pass's sample count at each render, whenever its shader was compiled. The count is
|
|
9
|
+
* that of the target the pass draws into: a render target, three's frame buffer target in its
|
|
10
|
+
* place, or else an output render target; the renderer's own count only without any.
|
|
11
|
+
*/
|
|
12
|
+
function windfoilKernelSkirt() {
|
|
13
|
+
return kernelSkirt ??= uniform(KERNEL_SKIRT_PX).setName("ultraWindfoilSkirt").setGroup(renderGroup).onRenderUpdate(({ renderer }) => {
|
|
14
|
+
const target = renderer?.getRenderTarget() ?? renderer?.getOutputRenderTarget();
|
|
15
|
+
return (target ? target.samples : renderer?.currentSamples ?? 0) >= 4 ? MULTISAMPLE_SKIRT_PX : KERNEL_SKIRT_PX;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export { KERNEL_SKIRT_PX, MULTISAMPLE_SKIRT_PX, windfoilKernelSkirt };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=skirt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skirt.js","names":[],"sources":["../../src/windfoil/skirt.ts"],"sourcesContent":["import type { Node, UniformNode } from 'three/webgpu'\nimport { renderGroup, uniform } from 'three/tsl'\n\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.\nexport const KERNEL_SKIRT_PX = 0.5625\nexport const MULTISAMPLE_SKIRT_PX = 0.9375\n\nlet kernelSkirt: UniformNode<'float', number> | undefined\n\n/**\n * The skirt of the pass being drawn, in pixels: one uniform for every Windfoil/Slug 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"],"mappings":";;AASA,IAAa,kBAAkB;AAC/B,IAAa,uBAAuB;AAEpC,IAAI;;;;;;;AAQJ,SAAgB,sBAAoD;CAClE,OAAQ,gBAAgB,QAAQ,eAAe,CAAC,CAC7C,QAAQ,oBAAoB,CAAC,CAC7B,SAAS,WAAW,CAAC,CACrB,gBAAgB,EAAE,eAAe;EAChC,MAAM,SAAS,UAAU,gBAAgB,KAAK,UAAU,sBAAsB;EAE9E,QADgB,SAAS,OAAO,UAAW,UAAU,kBAAkB,MACrD,IAAI,uBAAuB;CAC/C,CAAC;AACL"}
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
import { type BufferAttribute, type WebGPURenderer } from 'three/webgpu';
|
|
2
|
-
import type { DomSdfOptions } from '../types.js';
|
|
1
|
+
import { type BufferAttribute, type StorageBufferNode, type WebGPURenderer } from 'three/webgpu';
|
|
2
|
+
import type { DomSdfOptions, GlyphRequest, WindfoilOptions, WindfoilOutlineProvider } from '../types.js';
|
|
3
|
+
import { abortable, throwIfAborted } from './abortable.js';
|
|
4
|
+
import type * as WindfoilRequests from './requests.js';
|
|
3
5
|
import type { WindfoilStorage } from './WindfoilMaterial.js';
|
|
6
|
+
export { abortable, throwIfAborted };
|
|
7
|
+
export interface WindfoilStorageHeadroom {
|
|
8
|
+
readonly minCurveFloats?: number;
|
|
9
|
+
readonly minRowUints?: number;
|
|
10
|
+
readonly rowAlign?: number;
|
|
11
|
+
readonly maxCurveFloats?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RetainedWindfoilStorage extends WindfoilStorage {
|
|
14
|
+
readonly storageBytes: number;
|
|
15
|
+
readonly curveCapacityFloats: number;
|
|
16
|
+
readonly rowCapacityUints: number;
|
|
17
|
+
writeCurves(offsetFloats: number, source: Float32Array): void;
|
|
18
|
+
writeRows(offsetUints: number, source: Uint32Array): void;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
}
|
|
21
|
+
/** Storage buffers retained by one vec4-packed Slug outline atlas. */
|
|
22
|
+
export interface SlugStorage {
|
|
23
|
+
readonly curves: StorageBufferNode<'vec4'>;
|
|
24
|
+
readonly rows: StorageBufferNode<'uint'>;
|
|
25
|
+
}
|
|
26
|
+
export interface RetainedSlugStorage extends SlugStorage {
|
|
27
|
+
readonly storageBytes: number;
|
|
28
|
+
readonly curveCapacityFloats: number;
|
|
29
|
+
readonly rowCapacityUints: number;
|
|
30
|
+
writeCurves(offsetFloats: number, source: Float32Array): void;
|
|
31
|
+
writeRows(offsetUints: number, source: Uint32Array): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
4
34
|
/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */
|
|
5
35
|
export type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>;
|
|
6
36
|
/**
|
|
@@ -9,9 +39,15 @@ export type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>;
|
|
|
9
39
|
* rejects, such as a negative width or a NaN, stay for it to reject.
|
|
10
40
|
*/
|
|
11
41
|
export declare function drawnEffects({ outline, dropShadow }: TextEffects): TextEffects | null;
|
|
12
|
-
export declare function throwIfAborted(signal?: AbortSignal): void;
|
|
13
|
-
export declare function abortable<T>(promise: PromiseLike<T>, signal?: AbortSignal): Promise<T>;
|
|
14
42
|
export declare function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void;
|
|
43
|
+
export declare function createRetainedWindfoilStorage(renderer: WebGPURenderer, data: {
|
|
44
|
+
curves: Float32Array;
|
|
45
|
+
rows: Uint32Array;
|
|
46
|
+
}, headroom?: WindfoilStorageHeadroom | false): RetainedWindfoilStorage;
|
|
47
|
+
export declare function createRetainedSlugStorage(renderer: WebGPURenderer, data: {
|
|
48
|
+
curves: Float32Array;
|
|
49
|
+
rows: Uint32Array;
|
|
50
|
+
}, headroom?: WindfoilStorageHeadroom | false): RetainedSlugStorage;
|
|
15
51
|
export declare function createWindfoilStorage(renderer: WebGPURenderer, data: {
|
|
16
52
|
curves: Float32Array;
|
|
17
53
|
rows: Uint32Array;
|
|
@@ -19,3 +55,25 @@ export declare function createWindfoilStorage(renderer: WebGPURenderer, data: {
|
|
|
19
55
|
storageBytes: number;
|
|
20
56
|
dispose(): void;
|
|
21
57
|
};
|
|
58
|
+
export declare function createSlugStorage(renderer: WebGPURenderer, data: {
|
|
59
|
+
curves: Float32Array;
|
|
60
|
+
rows: Uint32Array;
|
|
61
|
+
}): SlugStorage & {
|
|
62
|
+
storageBytes: number;
|
|
63
|
+
dispose(): void;
|
|
64
|
+
};
|
|
65
|
+
export declare function resolveOutlineRequests(requests: readonly GlyphRequest[], options: WindfoilOptions & {
|
|
66
|
+
readonly outlineProvider: WindfoilOutlineProvider;
|
|
67
|
+
}, signal: AbortSignal, extensions: typeof WindfoilRequests | null): Promise<{
|
|
68
|
+
request: GlyphRequest;
|
|
69
|
+
outline: Awaited<ReturnType<WindfoilOutlineProvider>>;
|
|
70
|
+
}[]>;
|
|
71
|
+
export declare function collectMissingRequests(requests: readonly GlyphRequest[], covered: (key: string) => boolean): GlyphRequest[];
|
|
72
|
+
export declare function mergePreprocessStats<T extends {
|
|
73
|
+
readonly paintLayers: number;
|
|
74
|
+
readonly uniqueGlyphs: number;
|
|
75
|
+
readonly monotonePieces: number;
|
|
76
|
+
readonly bandCount: number;
|
|
77
|
+
readonly bandedPieces: number;
|
|
78
|
+
readonly duplication: number;
|
|
79
|
+
}>(current: T, delta: T, uniqueGlyphs: number): T;
|
package/dist/windfoil/storage.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { abortable, throwIfAborted } from "./abortable.js";
|
|
1
2
|
import { StorageBufferAttribute } from "three/webgpu";
|
|
2
3
|
import { storage } from "three/tsl";
|
|
3
4
|
// src/windfoil/storage.ts
|
|
@@ -12,28 +13,6 @@ function drawnEffects({ outline, dropShadow }) {
|
|
|
12
13
|
if (dropShadow && !((dropShadow.opacity ?? .5) <= 0)) drawn.dropShadow = dropShadow;
|
|
13
14
|
return drawn.outline ?? drawn.dropShadow ? drawn : null;
|
|
14
15
|
}
|
|
15
|
-
function throwIfAborted(signal) {
|
|
16
|
-
if (signal?.aborted) throw signal.reason ?? new DOMException("The Windfoil build was aborted", "AbortError");
|
|
17
|
-
}
|
|
18
|
-
function abortable(promise, signal) {
|
|
19
|
-
throwIfAborted(signal);
|
|
20
|
-
if (!signal) return Promise.resolve(promise);
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
23
|
-
const abort = () => {
|
|
24
|
-
cleanup();
|
|
25
|
-
reject(signal.reason ?? new DOMException("The Windfoil build was aborted", "AbortError"));
|
|
26
|
-
};
|
|
27
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
28
|
-
Promise.resolve(promise).then((value) => {
|
|
29
|
-
cleanup();
|
|
30
|
-
resolve(value);
|
|
31
|
-
}, (error) => {
|
|
32
|
-
cleanup();
|
|
33
|
-
reject(error);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
16
|
function disposeWindfoilStorage(renderer, attribute) {
|
|
38
17
|
attribute.dispose();
|
|
39
18
|
const backend = renderer.backend;
|
|
@@ -42,7 +21,20 @@ function disposeWindfoilStorage(renderer, attribute) {
|
|
|
42
21
|
renderer.info.destroyAttribute(attribute);
|
|
43
22
|
}
|
|
44
23
|
}
|
|
45
|
-
function
|
|
24
|
+
function backendHas(renderer, attribute) {
|
|
25
|
+
return renderer.backend.has?.(attribute) === true;
|
|
26
|
+
}
|
|
27
|
+
function alignUp(value, align) {
|
|
28
|
+
const rem = value % align;
|
|
29
|
+
return rem === 0 ? value : value + align - rem;
|
|
30
|
+
}
|
|
31
|
+
function headroomCapacity(used, minExtra, align, maxAllowed, minNonEmpty) {
|
|
32
|
+
const alignedMax = Math.max(align, Math.floor(maxAllowed / align) * align);
|
|
33
|
+
if (used >= alignedMax) return Math.max(used, minNonEmpty);
|
|
34
|
+
const target = alignUp(Math.max(Math.ceil(used * 1.5), used + minExtra, minNonEmpty), align);
|
|
35
|
+
return Math.max(used, minNonEmpty, Math.min(target, alignedMax));
|
|
36
|
+
}
|
|
37
|
+
function createRetainedCurveStorage(renderer, data, curveType, curveComponents, headroom) {
|
|
46
38
|
const attributes = [];
|
|
47
39
|
let disposed = false;
|
|
48
40
|
const dispose = () => {
|
|
@@ -51,14 +43,61 @@ function createWindfoilStorage(renderer, data) {
|
|
|
51
43
|
for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute);
|
|
52
44
|
};
|
|
53
45
|
try {
|
|
54
|
-
|
|
46
|
+
let curvesData;
|
|
47
|
+
let rowsData;
|
|
48
|
+
if (headroom) {
|
|
49
|
+
const limits = renderer.backend.device?.limits;
|
|
50
|
+
const maxBindingBytes = Math.min(limits?.maxStorageBufferBindingSize ?? 134217728, limits?.maxBufferSize ?? 268435456);
|
|
51
|
+
const curveBytesPerItem = curveComponents * 4;
|
|
52
|
+
const maxCurveFloats = Math.min(Math.floor(maxBindingBytes / curveBytesPerItem) * curveComponents, headroom.maxCurveFloats ?? Number.POSITIVE_INFINITY);
|
|
53
|
+
const rowAlign = headroom.rowAlign ?? 1;
|
|
54
|
+
const maxRowUints = Math.floor(maxBindingBytes / (4 * rowAlign)) * rowAlign;
|
|
55
|
+
const capCurves = headroomCapacity(data.curves.length, headroom.minCurveFloats ?? 4096, curveComponents, maxCurveFloats, curveComponents);
|
|
56
|
+
const capRows = headroomCapacity(data.rows.length, headroom.minRowUints ?? 512, rowAlign, maxRowUints, 1);
|
|
57
|
+
if (capCurves === data.curves.length && data.curves.length > 0) curvesData = data.curves;
|
|
58
|
+
else {
|
|
59
|
+
curvesData = new Float32Array(capCurves);
|
|
60
|
+
if (data.curves.length > 0) curvesData.set(data.curves);
|
|
61
|
+
}
|
|
62
|
+
if (capRows === data.rows.length && data.rows.length > 0) rowsData = data.rows;
|
|
63
|
+
else {
|
|
64
|
+
rowsData = new Uint32Array(capRows);
|
|
65
|
+
if (data.rows.length > 0) rowsData.set(data.rows);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (data.curves.length === 0) curvesData = new Float32Array(curveComponents);
|
|
69
|
+
else if (data.curves.length % curveComponents !== 0) {
|
|
70
|
+
curvesData = new Float32Array(alignUp(data.curves.length, curveComponents));
|
|
71
|
+
curvesData.set(data.curves);
|
|
72
|
+
} else curvesData = data.curves;
|
|
73
|
+
rowsData = data.rows.length ? data.rows : /* @__PURE__ */ new Uint32Array(1);
|
|
74
|
+
}
|
|
75
|
+
const curveAttribute = new StorageBufferAttribute(curvesData, curveComponents);
|
|
55
76
|
attributes.push(curveAttribute);
|
|
56
|
-
const rowAttribute = new StorageBufferAttribute(
|
|
77
|
+
const rowAttribute = new StorageBufferAttribute(rowsData, 1);
|
|
57
78
|
attributes.push(rowAttribute);
|
|
58
79
|
return {
|
|
59
|
-
storageBytes: data.curves.byteLength + data.rows.byteLength,
|
|
60
|
-
|
|
80
|
+
storageBytes: headroom ? curvesData.byteLength + rowsData.byteLength : data.curves.byteLength + data.rows.byteLength,
|
|
81
|
+
curveCapacityFloats: curvesData.length,
|
|
82
|
+
rowCapacityUints: rowsData.length,
|
|
83
|
+
curves: storage(curveAttribute, curveType, curveAttribute.count).toReadOnly().setName("ultraWindfoilCurves"),
|
|
61
84
|
rows: storage(rowAttribute, "uint", rowAttribute.count).toReadOnly().setName("ultraWindfoilRows"),
|
|
85
|
+
writeCurves(offsetFloats, source) {
|
|
86
|
+
if (source.length === 0) return;
|
|
87
|
+
curvesData.set(source, offsetFloats);
|
|
88
|
+
if (backendHas(renderer, curveAttribute)) {
|
|
89
|
+
curveAttribute.addUpdateRange(offsetFloats, source.length);
|
|
90
|
+
curveAttribute.needsUpdate = true;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
writeRows(offsetUints, source) {
|
|
94
|
+
if (source.length === 0) return;
|
|
95
|
+
rowsData.set(source, offsetUints);
|
|
96
|
+
if (backendHas(renderer, rowAttribute)) {
|
|
97
|
+
rowAttribute.addUpdateRange(offsetUints, source.length);
|
|
98
|
+
rowAttribute.needsUpdate = true;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
62
101
|
dispose
|
|
63
102
|
};
|
|
64
103
|
} catch (error) {
|
|
@@ -66,6 +105,82 @@ function createWindfoilStorage(renderer, data) {
|
|
|
66
105
|
throw error;
|
|
67
106
|
}
|
|
68
107
|
}
|
|
69
|
-
|
|
108
|
+
function createRetainedWindfoilStorage(renderer, data, headroom) {
|
|
109
|
+
return createRetainedCurveStorage(renderer, data, "vec2", 2, headroom);
|
|
110
|
+
}
|
|
111
|
+
function createRetainedSlugStorage(renderer, data, headroom) {
|
|
112
|
+
return createRetainedCurveStorage(renderer, data, "vec4", 4, headroom);
|
|
113
|
+
}
|
|
114
|
+
function createWindfoilStorage(renderer, data) {
|
|
115
|
+
const retained = createRetainedWindfoilStorage(renderer, data);
|
|
116
|
+
return {
|
|
117
|
+
storageBytes: retained.storageBytes,
|
|
118
|
+
curves: retained.curves,
|
|
119
|
+
rows: retained.rows,
|
|
120
|
+
dispose: () => {
|
|
121
|
+
retained.dispose();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createSlugStorage(renderer, data) {
|
|
126
|
+
const retained = createRetainedSlugStorage(renderer, data);
|
|
127
|
+
return {
|
|
128
|
+
storageBytes: retained.storageBytes,
|
|
129
|
+
curves: retained.curves,
|
|
130
|
+
rows: retained.rows,
|
|
131
|
+
dispose: () => {
|
|
132
|
+
retained.dispose();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async function resolveOutlineRequests(requests, options, signal, extensions) {
|
|
137
|
+
if (extensions) return abortable(Promise.all(requests.map(async (request) => ({
|
|
138
|
+
request,
|
|
139
|
+
outline: await extensions.resolveShapeRequest(request, options, signal)
|
|
140
|
+
}))), signal);
|
|
141
|
+
const syncResolved = [];
|
|
142
|
+
let pending = null;
|
|
143
|
+
for (const request of requests) {
|
|
144
|
+
const out = options.outlineProvider(request, signal);
|
|
145
|
+
if (out instanceof Promise) {
|
|
146
|
+
pending ??= syncResolved.map((item) => Promise.resolve(item));
|
|
147
|
+
pending.push(out.then((outline) => ({
|
|
148
|
+
request,
|
|
149
|
+
outline
|
|
150
|
+
})));
|
|
151
|
+
} else if (pending) pending.push(Promise.resolve({
|
|
152
|
+
request,
|
|
153
|
+
outline: out
|
|
154
|
+
}));
|
|
155
|
+
else syncResolved.push({
|
|
156
|
+
request,
|
|
157
|
+
outline: out
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return pending ? abortable(Promise.all(pending), signal) : syncResolved;
|
|
161
|
+
}
|
|
162
|
+
function collectMissingRequests(requests, covered) {
|
|
163
|
+
const missing = [];
|
|
164
|
+
const seen = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const req of requests) {
|
|
166
|
+
if (seen.has(req.key) || covered(req.key)) continue;
|
|
167
|
+
seen.add(req.key);
|
|
168
|
+
missing.push(req);
|
|
169
|
+
}
|
|
170
|
+
return missing;
|
|
171
|
+
}
|
|
172
|
+
function mergePreprocessStats(current, delta, uniqueGlyphs) {
|
|
173
|
+
const monotonePieces = current.monotonePieces + delta.monotonePieces;
|
|
174
|
+
const bandedPieces = current.bandedPieces + delta.bandedPieces;
|
|
175
|
+
return {
|
|
176
|
+
paintLayers: current.paintLayers + delta.paintLayers,
|
|
177
|
+
uniqueGlyphs,
|
|
178
|
+
monotonePieces,
|
|
179
|
+
bandCount: current.bandCount + delta.bandCount,
|
|
180
|
+
bandedPieces,
|
|
181
|
+
duplication: monotonePieces > 0 ? bandedPieces / monotonePieces : current.duplication
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export { abortable, collectMissingRequests, createRetainedSlugStorage, createRetainedWindfoilStorage, createSlugStorage, createWindfoilStorage, disposeWindfoilStorage, drawnEffects, mergePreprocessStats, resolveOutlineRequests, throwIfAborted };
|
|
70
185
|
|
|
71
186
|
//# sourceMappingURL=storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","names":[],"sources":["../../src/windfoil/storage.ts"],"sourcesContent":["import { StorageBufferAttribute, type BufferAttribute, type WebGPURenderer } from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type { DomSdfOptions } from '../types.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */\nexport type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>\n/**\n * The effects that draw anything, or null: an outline unless its width is zero or its opacity\n * at most zero, a drop shadow unless its opacity is at most zero. Values the SDF material\n * rejects, such as a negative width or a NaN, stay for it to reject.\n */\nexport function drawnEffects({ outline, dropShadow }: TextEffects): TextEffects | null {\n const drawn: TextEffects = {}\n if (outline && outline.width !== 0 && !((outline.opacity ?? 1) <= 0)) drawn.outline = outline\n if (dropShadow && !((dropShadow.opacity ?? 0.5) <= 0)) drawn.dropShadow = dropShadow\n return (drawn.outline ?? drawn.dropShadow) ? drawn : null\n}\nexport function throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted)\n throw signal.reason ?? new DOMException('The Windfoil build was aborted', 'AbortError')\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}\nexport function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void {\n attribute.dispose()\n const backend = renderer.backend as unknown as {\n has(object: object): boolean\n destroyAttribute(attribute: BufferAttribute): void\n }\n if (backend.has(attribute)) {\n backend.destroyAttribute(attribute)\n renderer.info.destroyAttribute(attribute)\n }\n}\nexport function createWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): WindfoilStorage & { storageBytes: number; dispose(): void } {\n const attributes: StorageBufferAttribute[] = []\n let disposed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n }\n try {\n const curveAttribute = new StorageBufferAttribute(\n data.curves.length ? data.curves : new Float32Array(2),\n 2,\n )\n attributes.push(curveAttribute)\n const rowAttribute = new StorageBufferAttribute(\n data.rows.length ? data.rows : new Uint32Array(1),\n 1,\n )\n attributes.push(rowAttribute)\n return {\n storageBytes: data.curves.byteLength + data.rows.byteLength,\n curves: storage(curveAttribute, 'vec2', curveAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilCurves'),\n rows: storage(rowAttribute, 'uint', rowAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilRows'),\n dispose,\n }\n } catch (error) {\n dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;;AAWA,SAAgB,aAAa,EAAE,SAAS,cAA+C;CACrF,MAAM,QAAqB,CAAC;CAC5B,IAAI,WAAW,QAAQ,UAAU,KAAK,GAAG,QAAQ,WAAW,MAAM,IAAI,MAAM,UAAU;CACtF,IAAI,cAAc,GAAG,WAAW,WAAW,OAAQ,IAAI,MAAM,aAAa;CAC1E,OAAQ,MAAM,WAAW,MAAM,aAAc,QAAQ;AACvD;AACA,SAAgB,eAAe,QAA4B;CACzD,IAAI,QAAQ,SACV,MAAM,OA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AQ,eAAe,KAAK,CAAC,CAC1D,WAAW,CAAC,CACZ,QAAQ,qBAAqB;GAChC,MAAM,QAAQ,cAAc,QAAQ,aAAa,KAAK,CAAC,CACpD,WAAW,CAAC,CACZ,QAAQ,mBAAmB;GAC9B;EACF;CACF,SAAS,OAAO;EACd,QAAQ;EACR,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"storage.js","names":[],"sources":["../../src/windfoil/storage.ts"],"sourcesContent":["import {\n StorageBufferAttribute,\n type BufferAttribute,\n type StorageBufferNode,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type {\n DomSdfOptions,\n GlyphRequest,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './abortable.js'\nimport type * as WindfoilRequests from './requests.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n\nexport { abortable, throwIfAborted }\n\nexport interface WindfoilStorageHeadroom {\n readonly minCurveFloats?: number\n readonly minRowUints?: number\n readonly rowAlign?: number\n readonly maxCurveFloats?: number\n}\n\nexport interface RetainedWindfoilStorage extends WindfoilStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** Storage buffers retained by one vec4-packed Slug outline atlas. */\nexport interface SlugStorage {\n readonly curves: StorageBufferNode<'vec4'>\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface RetainedSlugStorage extends SlugStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */\nexport type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>\n/**\n * The effects that draw anything, or null: an outline unless its width is zero or its opacity\n * at most zero, a drop shadow unless its opacity is at most zero. Values the SDF material\n * rejects, such as a negative width or a NaN, stay for it to reject.\n */\nexport function drawnEffects({ outline, dropShadow }: TextEffects): TextEffects | null {\n const drawn: TextEffects = {}\n if (outline && outline.width !== 0 && !((outline.opacity ?? 1) <= 0)) drawn.outline = outline\n if (dropShadow && !((dropShadow.opacity ?? 0.5) <= 0)) drawn.dropShadow = dropShadow\n return (drawn.outline ?? drawn.dropShadow) ? drawn : null\n}\nexport function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void {\n attribute.dispose()\n const backend = renderer.backend as unknown as {\n has(object: object): boolean\n destroyAttribute(attribute: BufferAttribute): void\n }\n if (backend.has(attribute)) {\n backend.destroyAttribute(attribute)\n renderer.info.destroyAttribute(attribute)\n }\n}\nfunction backendHas(renderer: WebGPURenderer, attribute: BufferAttribute): boolean {\n return (\n (renderer.backend as unknown as { has?(object: object): boolean }).has?.(attribute) === true\n )\n}\n\nfunction alignUp(value: number, align: number): number {\n const rem = value % align\n return rem === 0 ? value : value + align - rem\n}\n\nfunction headroomCapacity(\n used: number,\n minExtra: number,\n align: number,\n maxAllowed: number,\n minNonEmpty: number,\n): number {\n const alignedMax = Math.max(align, Math.floor(maxAllowed / align) * align)\n if (used >= alignedMax) return Math.max(used, minNonEmpty)\n const target = alignUp(Math.max(Math.ceil(used * 1.5), used + minExtra, minNonEmpty), align)\n return Math.max(used, minNonEmpty, Math.min(target, alignedMax))\n}\n\nfunction createRetainedCurveStorage<T extends 'vec2' | 'vec4'>(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n curveType: T,\n curveComponents: 2 | 4,\n headroom?: WindfoilStorageHeadroom | false,\n): {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n readonly curves: StorageBufferNode<T>\n readonly rows: StorageBufferNode<'uint'>\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n} {\n const attributes: StorageBufferAttribute[] = []\n let disposed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n }\n try {\n let curvesData: Float32Array\n let rowsData: Uint32Array\n if (headroom) {\n const limits = (\n renderer.backend as unknown as {\n device?: { limits?: { maxStorageBufferBindingSize?: number; maxBufferSize?: number } }\n }\n ).device?.limits\n const maxBindingBytes = Math.min(\n limits?.maxStorageBufferBindingSize ?? 128 * 1024 * 1024,\n limits?.maxBufferSize ?? 256 * 1024 * 1024,\n )\n const curveBytesPerItem = curveComponents * 4\n const maxCurveFloats = Math.min(\n Math.floor(maxBindingBytes / curveBytesPerItem) * curveComponents,\n headroom.maxCurveFloats ?? Number.POSITIVE_INFINITY,\n )\n const rowAlign = headroom.rowAlign ?? 1\n const maxRowUints = Math.floor(maxBindingBytes / (4 * rowAlign)) * rowAlign\n const capCurves = headroomCapacity(\n data.curves.length,\n headroom.minCurveFloats ?? 4096,\n curveComponents,\n maxCurveFloats,\n curveComponents,\n )\n const capRows = headroomCapacity(\n data.rows.length,\n headroom.minRowUints ?? 512,\n rowAlign,\n maxRowUints,\n 1,\n )\n if (capCurves === data.curves.length && data.curves.length > 0) {\n curvesData = data.curves\n } else {\n curvesData = new Float32Array(capCurves)\n if (data.curves.length > 0) curvesData.set(data.curves)\n }\n if (capRows === data.rows.length && data.rows.length > 0) {\n rowsData = data.rows\n } else {\n rowsData = new Uint32Array(capRows)\n if (data.rows.length > 0) rowsData.set(data.rows)\n }\n } else {\n if (data.curves.length === 0) {\n curvesData = new Float32Array(curveComponents)\n } else if (data.curves.length % curveComponents !== 0) {\n curvesData = new Float32Array(alignUp(data.curves.length, curveComponents))\n curvesData.set(data.curves)\n } else {\n curvesData = data.curves\n }\n rowsData = data.rows.length ? data.rows : new Uint32Array(1)\n }\n const curveAttribute = new StorageBufferAttribute(curvesData, curveComponents)\n attributes.push(curveAttribute)\n const rowAttribute = new StorageBufferAttribute(rowsData, 1)\n attributes.push(rowAttribute)\n return {\n storageBytes: headroom\n ? curvesData.byteLength + rowsData.byteLength\n : data.curves.byteLength + data.rows.byteLength,\n curveCapacityFloats: curvesData.length,\n rowCapacityUints: rowsData.length,\n curves: storage(curveAttribute, curveType, curveAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilCurves'),\n rows: storage(rowAttribute, 'uint', rowAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilRows'),\n writeCurves(offsetFloats, source) {\n if (source.length === 0) return\n curvesData.set(source, offsetFloats)\n if (backendHas(renderer, curveAttribute)) {\n curveAttribute.addUpdateRange(offsetFloats, source.length)\n curveAttribute.needsUpdate = true\n }\n },\n writeRows(offsetUints, source) {\n if (source.length === 0) return\n rowsData.set(source, offsetUints)\n if (backendHas(renderer, rowAttribute)) {\n rowAttribute.addUpdateRange(offsetUints, source.length)\n rowAttribute.needsUpdate = true\n }\n },\n dispose,\n }\n } catch (error) {\n dispose()\n throw error\n }\n}\n\nexport function createRetainedWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedWindfoilStorage {\n return createRetainedCurveStorage(renderer, data, 'vec2', 2, headroom)\n}\n\nexport function createRetainedSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedSlugStorage {\n return createRetainedCurveStorage(renderer, data, 'vec4', 4, headroom)\n}\n\nexport function createWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): WindfoilStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedWindfoilStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport function createSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): SlugStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedSlugStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport async function resolveOutlineRequests(\n requests: readonly GlyphRequest[],\n options: WindfoilOptions & { readonly outlineProvider: WindfoilOutlineProvider },\n signal: AbortSignal,\n extensions: typeof WindfoilRequests | null,\n): Promise<{ request: GlyphRequest; outline: Awaited<ReturnType<WindfoilOutlineProvider>> }[]> {\n if (extensions) {\n return abortable(\n Promise.all(\n requests.map(async (request) => ({\n request,\n outline: await extensions.resolveShapeRequest(request, options, signal),\n })),\n ),\n signal,\n )\n }\n const syncResolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<WindfoilOutlineProvider>>\n }[] = []\n let pending: Promise<(typeof syncResolved)[number]>[] | null = null\n for (const request of requests) {\n const out = options.outlineProvider(request, signal)\n if (out instanceof Promise) {\n pending ??= syncResolved.map((item) => Promise.resolve(item))\n pending.push(out.then((outline) => ({ request, outline })))\n } else if (pending) {\n pending.push(Promise.resolve({ request, outline: out }))\n } else {\n syncResolved.push({ request, outline: out })\n }\n }\n return pending ? abortable(Promise.all(pending), signal) : syncResolved\n}\n\nexport function collectMissingRequests(\n requests: readonly GlyphRequest[],\n covered: (key: string) => boolean,\n): GlyphRequest[] {\n const missing: GlyphRequest[] = []\n const seen = new Set<string>()\n for (const req of requests) {\n if (seen.has(req.key) || covered(req.key)) continue\n seen.add(req.key)\n missing.push(req)\n }\n return missing\n}\n\nexport function mergePreprocessStats<\n T extends {\n readonly paintLayers: number\n readonly uniqueGlyphs: number\n readonly monotonePieces: number\n readonly bandCount: number\n readonly bandedPieces: number\n readonly duplication: number\n },\n>(current: T, delta: T, uniqueGlyphs: number): T {\n const monotonePieces = current.monotonePieces + delta.monotonePieces\n const bandedPieces = current.bandedPieces + delta.bandedPieces\n return {\n paintLayers: current.paintLayers + delta.paintLayers,\n uniqueGlyphs,\n monotonePieces,\n bandCount: current.bandCount + delta.bandCount,\n bandedPieces,\n duplication: monotonePieces > 0 ? bandedPieces / monotonePieces : current.duplication,\n } as T\n}\n"],"mappings":";;;;;;;;;AAyDA,SAAgB,aAAa,EAAE,SAAS,cAA+C;CACrF,MAAM,QAAqB,CAAC;CAC5B,IAAI,WAAW,QAAQ,UAAU,KAAK,GAAG,QAAQ,WAAW,MAAM,IAAI,MAAM,UAAU;CACtF,IAAI,cAAc,GAAG,WAAW,WAAW,OAAQ,IAAI,MAAM,aAAa;CAC1E,OAAQ,MAAM,WAAW,MAAM,aAAc,QAAQ;AACvD;AACA,SAAgB,uBAAuB,UAA0B,WAAkC;CACjG,UAAU,QAAQ;CAClB,MAAM,UAAU,SAAS;CAIzB,IAAI,QAAQ,IAAI,SAAS,GAAG;EAC1B,QAAQ,iBAAiB,SAAS;EAClC,SAAS,KAAK,iBAAiB,SAAS;CAC1C;AACF;AACA,SAAS,WAAW,UAA0B,WAAqC;CACjF,OACG,SAAS,QAAyD,MAAM,SAAS,MAAM;AAE5F;AAEA,SAAS,QAAQ,OAAe,OAAuB;CACrD,MAAM,MAAM,QAAQ;CACpB,OAAO,QAAQ,IAAI,QAAQ,QAAQ,QAAQ;AAC7C;AAEA,SAAS,iBACP,MACA,UACA,OACA,YACA,aACQ;CACR,MAAM,aAAa,KAAK,IAAI,OAAO,KAAK,MAAM,aAAa,KAAK,IAAI,KAAK;CACzE,IAAI,QAAQ,YAAY,OAAO,KAAK,IAAI,MAAM,WAAW;CACzD,MAAM,SAAS,QAAQ,KAAK,IAAI,KAAK,KAAK,OAAO,GAAG,GAAG,OAAO,UAAU,WAAW,GAAG,KAAK;CAC3F,OAAO,KAAK,IAAI,MAAM,aAAa,KAAK,IAAI,QAAQ,UAAU,CAAC;AACjE;AAEA,SAAS,2BACP,UACA,MACA,WACA,iBACA,UAUA;CACA,MAAM,aAAuC,CAAC;CAC9C,IAAI,WAAW;CACf,MAAM,gBAAsB;EAC1B,IAAI,U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,QAAQ,iBAAiB,MAAM;CACtD,MAAM,eAAe,QAAQ,eAAe,MAAM;CAClD,OAAO;EACL,aAAa,QAAQ,cAAc,MAAM;EACzC;EACA;EACA,WAAW,QAAQ,YAAY,MAAM;EACrC;EACA,aAAa,iBAAiB,IAAI,eAAe,iBAAiB,QAAQ;CAC5E;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CoverageMask, Polyline, TraceScratch } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* as needed and every edge mark it holds is cleared again before this returns.
|
|
3
|
+
* Traces 0.5 contours into `scratch.poly` (`[start0, end0, ...]` in `scratch.polyStarts`),
|
|
4
|
+
* returning the number of closed contours written.
|
|
6
5
|
*/
|
|
6
|
+
export declare function marchingSquaresFlat(mask: CoverageMask, scratch: TraceScratch): number;
|
|
7
7
|
export declare function marchingSquares(mask: CoverageMask, scratch: TraceScratch): Polyline[];
|