ultra-text 1.0.0 → 1.0.1
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 +168 -85
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker-xS57yQbP.js} +13 -11
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +1 -0
- package/dist/atlas/appendAtlas.js +2 -1
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -14
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +12 -10
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.js +1 -1
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +280 -145
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/jfaWgsl.js +201 -73
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +2 -87
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/dom/DomSdf.js +66 -15
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +640 -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/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +101 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +29 -2
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/snapshot.js +251 -96
- package/dist/dom/snapshot.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/slug/SlugMaterial.d.ts +3 -2
- package/dist/slug/SlugMaterial.js +28 -2
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +1 -1
- package/dist/slug/coverage.js +1 -1
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -2
- package/dist/slug/preprocessCore.js +39 -16
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +6 -4
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +39 -0
- package/dist/slug/standaloneRuntime.js +140 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +494 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug-vanilla.d.ts +364 -0
- package/dist/slug-vanilla.js +1461 -0
- package/dist/slug-vanilla.js.map +1 -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 +98 -29
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +22 -4
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +3 -0
- package/dist/vanilla.js +132 -59
- package/dist/vanilla.js.map +1 -1
- 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.js +100 -33
- 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/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 +4 -85
- package/dist/windfoil/preprocessCore.js +210 -206
- 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 +2 -1
- package/dist/windfoil/runtime.js +3 -2
- 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 +2 -2
- package/dist/windfoil/storage.js +1 -22
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +0 -5
- package/dist/windfoil/trace/contours.js +81 -114
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +0 -6
- package/dist/windfoil/trace/fit.js +304 -308
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +10 -10
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +5 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +172 -33
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +57 -8
- 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 +95 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
package/dist/slug/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/slug/runtime.ts"],"sourcesContent":["import { WebGPUBackend, type WebGPURenderer } from 'three/webgpu'\nimport type { DomLayoutSnapshot, GlyphRequest, SdfAtlas } from '../types.js'\nimport type { WindfoilColorResources } from '../windfoil/color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from '../windfoil/geometry.js'\nimport type { WindfoilBackend, WindfoilBuildOptions } from '../windfoil/runtime.js'\nimport {\n abortable,\n createWindfoilStorage,\n drawnEffects,\n throwIfAborted,\n type TextEffects,\n} from '../windfoil/storage.js'\nimport { preprocessSlugGlyphs } from './preprocessCore.js'\nimport { SlugMaterial } from './SlugMaterial.js'\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildSlugBackend(\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('../windfoil/sizeSwitch.js'), signal)\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 Slug text backend requires WebGPU; set slug.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: Slug 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('../windfoil/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: {\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }[] = []\n let pending:\n | Promise<{\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }>[]\n | 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: Slug 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('../windfoil/requests.js') : Promise.resolve(null),\n needsLayerNormalization\n ? import('../windfoil/layerNormalization.js')\n : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n // Composite shader path (`compositing: 'shader'` or `clipBox`) uses Windfoil's layer grid;\n // layered instances (default) and standard text use Ultra-Slug's dual-band preprocessing.\n const prepared = preprocessSlugGlyphs(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\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 Slug 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('../windfoil/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(\n renderer,\n prepared,\n { ...options, compositing: 'layers' },\n coverage,\n 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 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: 'slug',\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 Slug 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 SlugMaterial({\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":";;;;;;;AAoBA,eAAsB,iBACpB,UACA,UACA,SACA,QACA,kBAKiC;CACjC,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,8BAA8B,MAAM;CAC7F,cAAc,gBAAgB,QAAQ;CACtC,MAAM,UAAU,SAAS,KAAK,GAAG,MAAM;CACvC,eAAe,MAAM;CACrB,MAAM,WAAW,QAAQ,aAAa,SAAS,QAAQ,aAAa;CACpE,IAAI,EAAE,SAAS,mBAAmB,gBAAgB;EAChD,IAAI,UAAU,OAAO;EACrB,MAAM,IAAI,MACR,0FACF;CACF;CACA,MAAM,QACH,SAAS,QAA6E,QACnF,OAAO,oBAAoB;CACjC,IAAI,QAAQ,GAAG;EACb,IAAI,UAAU,OAAO;EACrB,MAAM,IAAI,MAAM,qDAAqD;CACvE;CACA,MAAM,UAAU,kBAAkB,UAAU,aAAa,iBAAiB,OAAO,IAAI;CAOrF,IAAI,aALF,CAAC,CAAC,WACF,SAAS,MAAM,YAAY,QAAQ,KAAK,KACxC,QAAQ,aAAa,gBACrB,QAAQ,gBAAgB,YACxB,aAAa,KAAA,IACa,MAAM,UAAU,OAAO,4BAA4B,MAAM,IAAI;CACzF,IAAI;CAIJ,IAAI,YACF,WAAW,MAAM,UACf,QAAQ,IACN,SAAS,IAAI,OAAO,aAAa;EAC/B;EACA,SAAS,MAAM,WAAY,oBAAoB,SAAS,SAAS,MAAM;CACzE,EAAE,CACJ,GACA,MACF;MACK;EACL,MAAM,eAGA,CAAC;EACP,IAAI,UAKO;EACX,KAAK,MAAM,WAAW,UAAU;GAC9B,MAAM,MAAM,QAAQ,gBAAgB,SAAS,MAAM;GACnD,IAAI,eAAe,SAAS;IAC1B,YAAY,aAAa,KAAK,SAAS,QAAQ,QAAQ,IAAI,CAAC;IAC5D,QAAQ,KAAK,IAAI,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
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/slug/runtime.ts"],"sourcesContent":["import { WebGPUBackend, type WebGPURenderer } from 'three/webgpu'\nimport type { DomLayoutSnapshot, GlyphRequest, SdfAtlas } from '../types.js'\nimport type { WindfoilColorResources } from '../windfoil/color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from '../windfoil/geometry.js'\nimport type { WindfoilBackend, WindfoilBuildOptions } from '../windfoil/runtime.js'\nimport {\n abortable,\n createWindfoilStorage,\n drawnEffects,\n throwIfAborted,\n type TextEffects,\n} from '../windfoil/storage.js'\nimport { preprocessSlugGlyphs } from './preprocessCore.js'\nimport { SlugMaterial } from './SlugMaterial.js'\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildSlugBackend(\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('../windfoil/sizeSwitch.js'), signal)\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 Slug text backend requires WebGPU; set slug.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: Slug 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('../windfoil/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: {\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }[] = []\n let pending:\n | Promise<{\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }>[]\n | 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 const skippedKeys =\n missing.length && !companionBuilder && options.missingGlyphs === 'skip'\n ? new Set(missing.map((item) => item.request.key))\n : null\n if (missing.length && !skippedKeys) {\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: Slug 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('../windfoil/requests.js') : Promise.resolve(null),\n needsLayerNormalization\n ? import('../windfoil/layerNormalization.js')\n : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n // Composite shader path (`compositing: 'shader'` or `clipBox`) uses Windfoil's layer grid;\n // layered instances (default) and standard text use Ultra-Slug's dual-band preprocessing.\n const prepared = preprocessSlugGlyphs(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\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 =\n prepared.layered || (missing.length > 0 && !skippedKeys) || companionReqs.length > 0\n if (layered && limit < 8) {\n if (fallback) return null\n throw new Error('DomSdf: layered Slug 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('../windfoil/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(\n renderer,\n prepared,\n { ...options, compositing: 'layers' },\n coverage,\n 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 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: 'slug',\n layered,\n companion,\n effects,\n color: colorResources?.composite ?? null,\n sizeSwitch,\n motionOrdinals,\n glyphs: prepared.glyphs,\n covers(key) {\n return (\n prepared.glyphs.has(key) ||\n !!companion?.glyphs.has(key) ||\n (skippedKeys?.has(key) ?? false)\n )\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 Slug 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 SlugMaterial({\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":";;;;;;;;AAoBA,eAAsB,iBACpB,UACA,UACA,SACA,QACA,kBAKiC;CACjC,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,8BAA8B,MAAM;CAC7F,cAAc,gBAAgB,QAAQ;CACtC,MA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';
|
|
2
|
+
import type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js';
|
|
3
|
+
import type { ResolvedTextTone } from '../text/tone.js';
|
|
4
|
+
import type { DomLayoutSnapshot, GlyphRequest, SdfMotionOptions, TextFill, TextToneOptions, TextVertex, WindfoilOutlineProvider } from '../types.js';
|
|
5
|
+
import type { WindfoilGlyphHeader, WindfoilPreprocessStats } from '../windfoil/preprocessCore.js';
|
|
6
|
+
export interface StandaloneSlugBuildOptions {
|
|
7
|
+
readonly outlineProvider: WindfoilOutlineProvider;
|
|
8
|
+
readonly missingGlyphs?: 'skip' | 'error';
|
|
9
|
+
readonly targetPiecesPerBand?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface StandaloneSlugBackend {
|
|
12
|
+
readonly kind: 'slug';
|
|
13
|
+
readonly layered: boolean;
|
|
14
|
+
readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>;
|
|
15
|
+
readonly skippedKeys: ReadonlySet<string>;
|
|
16
|
+
readonly storageBytes: number;
|
|
17
|
+
readonly preprocessStats: WindfoilPreprocessStats;
|
|
18
|
+
covers(key: string): boolean;
|
|
19
|
+
analyticCovers(key: string): boolean;
|
|
20
|
+
contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean;
|
|
21
|
+
createGeometry(snapshot: DomLayoutSnapshot, motionPadding: number): {
|
|
22
|
+
geometry: InstancedBufferGeometry;
|
|
23
|
+
maxSequence: number;
|
|
24
|
+
};
|
|
25
|
+
updateGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, motionPadding: number): number | null;
|
|
26
|
+
setGlyphEm(value: boolean): void;
|
|
27
|
+
createMaterial(options: {
|
|
28
|
+
readonly fill?: TextFill;
|
|
29
|
+
readonly vertex?: TextVertex;
|
|
30
|
+
readonly shadowCutoff?: number;
|
|
31
|
+
readonly side?: Side;
|
|
32
|
+
readonly motion: SdfMotionOptions | false;
|
|
33
|
+
readonly maxSequence: number;
|
|
34
|
+
readonly tone?: TextToneOptions | ResolvedTextTone | false;
|
|
35
|
+
}): GlyphTextMaterial;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
/** Builds a pure GPU Slug backend without any SDF companion or atlas dependency. */
|
|
39
|
+
export declare function buildStandaloneSlugBackend(renderer: WebGPURenderer, requests: readonly GlyphRequest[], options: StandaloneSlugBuildOptions, signal: AbortSignal): Promise<StandaloneSlugBackend>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { abortable, throwIfAborted } from "../windfoil/abortable.js";
|
|
2
|
+
import { createWindfoilGlyphGeometry, updateWindfoilGlyphGeometry, windfoilContentFits } from "../windfoil/geometry.js";
|
|
3
|
+
import { createWindfoilStorage } from "../windfoil/storage.js";
|
|
4
|
+
import { preprocessSlugGlyphs } from "./preprocessCore.js";
|
|
5
|
+
import { SlugMaterial } from "./SlugMaterial.js";
|
|
6
|
+
import { WebGPUBackend } from "three/webgpu";
|
|
7
|
+
// src/slug/standaloneRuntime.ts
|
|
8
|
+
/** Builds a pure GPU Slug backend without any SDF companion or atlas dependency. */
|
|
9
|
+
async function buildStandaloneSlugBackend(renderer, requests, options, signal) {
|
|
10
|
+
await abortable(renderer.init(), signal);
|
|
11
|
+
throwIfAborted(signal);
|
|
12
|
+
if (!(renderer.backend instanceof WebGPUBackend)) throw new Error("DomSlug: the Slug text backend requires WebGPU");
|
|
13
|
+
const limit = renderer.backend.device?.limits.maxVertexBuffers ?? 8;
|
|
14
|
+
if (limit < 7) throw new Error("DomSlug: Slug requires at least seven vertex buffers");
|
|
15
|
+
const extensions = requests.some((request) => request.shape !== void 0) ? await abortable(import("../windfoil/requests.js"), signal) : null;
|
|
16
|
+
let resolved;
|
|
17
|
+
if (extensions) resolved = await abortable(Promise.all(requests.map(async (request) => ({
|
|
18
|
+
request,
|
|
19
|
+
outline: await extensions.resolveShapeRequest(request, { outlineProvider: options.outlineProvider }, signal)
|
|
20
|
+
}))), signal);
|
|
21
|
+
else {
|
|
22
|
+
const syncResolved = [];
|
|
23
|
+
let pending = null;
|
|
24
|
+
for (const request of requests) {
|
|
25
|
+
const out = options.outlineProvider(request, signal);
|
|
26
|
+
if (out instanceof Promise) {
|
|
27
|
+
pending ??= syncResolved.map((item) => Promise.resolve(item));
|
|
28
|
+
pending.push(out.then((outline) => ({
|
|
29
|
+
request,
|
|
30
|
+
outline
|
|
31
|
+
})));
|
|
32
|
+
} else if (pending) pending.push(Promise.resolve({
|
|
33
|
+
request,
|
|
34
|
+
outline: out
|
|
35
|
+
}));
|
|
36
|
+
else syncResolved.push({
|
|
37
|
+
request,
|
|
38
|
+
outline: out
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
resolved = pending ? await abortable(Promise.all(pending), signal) : syncResolved;
|
|
42
|
+
}
|
|
43
|
+
throwIfAborted(signal);
|
|
44
|
+
const missing = resolved.filter((item) => item.outline === null);
|
|
45
|
+
const missingMode = options.missingGlyphs ?? "error";
|
|
46
|
+
if (missing.length > 0 && missingMode === "error") throw new Error(`DomSlug: outlineProvider returned null for ${JSON.stringify(missing[0].request.character)} in ${missing[0].request.font.family}`);
|
|
47
|
+
const skippedKeys = new Set(missing.map((item) => item.request.key));
|
|
48
|
+
const layerModule = resolved.some((item) => item.outline?.layers !== void 0 || item.outline?.clipBox !== void 0) ? await abortable(import("../windfoil/layerNormalization.js"), signal) : null;
|
|
49
|
+
const prepared = preprocessSlugGlyphs(resolved.filter((item) => item.outline !== null), {
|
|
50
|
+
signal,
|
|
51
|
+
...layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {},
|
|
52
|
+
...options.targetPiecesPerBand === void 0 ? {} : { targetPiecesPerBand: options.targetPiecesPerBand }
|
|
53
|
+
});
|
|
54
|
+
const layered = prepared.layered;
|
|
55
|
+
if (layered && limit < 8) throw new Error("DomSlug: layered Slug requires eight vertex buffers");
|
|
56
|
+
const colorPromise = [...prepared.glyphs.values()].some((header) => header.layers?.some((layer) => layer.paintKind === 2) ?? false) ? import("../windfoil/color.js") : null;
|
|
57
|
+
let coverage;
|
|
58
|
+
let colorResources = null;
|
|
59
|
+
try {
|
|
60
|
+
const colorModule = colorPromise ? await abortable(colorPromise, signal) : null;
|
|
61
|
+
throwIfAborted(signal);
|
|
62
|
+
coverage = createWindfoilStorage(renderer, prepared);
|
|
63
|
+
colorResources = colorModule?.buildWindfoilColorResources(renderer, prepared, {
|
|
64
|
+
outlineProvider: options.outlineProvider,
|
|
65
|
+
compositing: "layers"
|
|
66
|
+
}, coverage, signal) ?? null;
|
|
67
|
+
const plainGlyphs = colorResources?.plainGlyphs ?? prepared.glyphs;
|
|
68
|
+
let glyphEm = false;
|
|
69
|
+
const sized = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
const withEm = (snapshot) => {
|
|
71
|
+
if (!glyphEm) return snapshot;
|
|
72
|
+
let layout = sized.get(snapshot);
|
|
73
|
+
if (!layout) {
|
|
74
|
+
layout = {
|
|
75
|
+
...snapshot,
|
|
76
|
+
sizeSwitched: true,
|
|
77
|
+
glyphs: snapshot.glyphs.map((glyph) => ({
|
|
78
|
+
...glyph,
|
|
79
|
+
switchEm: glyph.shapeGroup === void 0 ? -glyph.fontSize : 0
|
|
80
|
+
}))
|
|
81
|
+
};
|
|
82
|
+
sized.set(snapshot, layout);
|
|
83
|
+
}
|
|
84
|
+
return layout;
|
|
85
|
+
};
|
|
86
|
+
let geometryLayered = layered;
|
|
87
|
+
let disposed = false;
|
|
88
|
+
const retained = coverage;
|
|
89
|
+
return {
|
|
90
|
+
kind: "slug",
|
|
91
|
+
layered,
|
|
92
|
+
glyphs: prepared.glyphs,
|
|
93
|
+
skippedKeys,
|
|
94
|
+
storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),
|
|
95
|
+
preprocessStats: prepared.stats,
|
|
96
|
+
covers(key) {
|
|
97
|
+
return prepared.glyphs.has(key) || skippedKeys.has(key);
|
|
98
|
+
},
|
|
99
|
+
analyticCovers(key) {
|
|
100
|
+
return !!plainGlyphs.get(key)?.monotonePieceCount;
|
|
101
|
+
},
|
|
102
|
+
contentFits(geometry, snapshot) {
|
|
103
|
+
return windfoilContentFits(geometry, withEm(snapshot), plainGlyphs);
|
|
104
|
+
},
|
|
105
|
+
createGeometry(snapshot, padding) {
|
|
106
|
+
const layout = withEm(snapshot);
|
|
107
|
+
geometryLayered = layered || layout.glyphs.some((glyph) => !!glyph.motionOrigin);
|
|
108
|
+
if (geometryLayered && limit < 8) throw new Error("DomSlug: layered Slug requires eight vertex buffers");
|
|
109
|
+
return createWindfoilGlyphGeometry(layout, plainGlyphs, padding, geometryLayered);
|
|
110
|
+
},
|
|
111
|
+
updateGeometry(geometry, snapshot, padding) {
|
|
112
|
+
return updateWindfoilGlyphGeometry(geometry, withEm(snapshot), plainGlyphs, padding);
|
|
113
|
+
},
|
|
114
|
+
setGlyphEm(value) {
|
|
115
|
+
glyphEm = value;
|
|
116
|
+
},
|
|
117
|
+
createMaterial(materialOptions) {
|
|
118
|
+
return new SlugMaterial({
|
|
119
|
+
...retained,
|
|
120
|
+
layered: geometryLayered,
|
|
121
|
+
...colorResources ? { paintFunctions: colorResources.paintFunctions } : {},
|
|
122
|
+
...materialOptions
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
dispose() {
|
|
126
|
+
if (disposed) return;
|
|
127
|
+
disposed = true;
|
|
128
|
+
retained.dispose();
|
|
129
|
+
colorResources?.dispose();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
} catch (error) {
|
|
133
|
+
coverage?.dispose();
|
|
134
|
+
colorResources?.dispose();
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export { buildStandaloneSlugBackend };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=standaloneRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standaloneRuntime.js","names":[],"sources":["../../src/slug/standaloneRuntime.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 SdfMotionOptions,\n TextFill,\n TextToneOptions,\n TextVertex,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport type { WindfoilColorResources } from '../windfoil/color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from '../windfoil/geometry.js'\nimport type { WindfoilGlyphHeader, WindfoilPreprocessStats } from '../windfoil/preprocessCore.js'\nimport { abortable, createWindfoilStorage, throwIfAborted } from '../windfoil/storage.js'\nimport { preprocessSlugGlyphs } from './preprocessCore.js'\nimport { SlugMaterial } from './SlugMaterial.js'\n\nexport interface StandaloneSlugBuildOptions {\n readonly outlineProvider: WindfoilOutlineProvider\n readonly missingGlyphs?: 'skip' | 'error'\n readonly targetPiecesPerBand?: number\n}\n\nexport interface StandaloneSlugBackend {\n readonly kind: 'slug'\n readonly layered: boolean\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly skippedKeys: ReadonlySet<string>\n readonly storageBytes: number\n readonly preprocessStats: WindfoilPreprocessStats\n covers(key: string): boolean\n analyticCovers(key: string): boolean\n contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean\n createGeometry(\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ): number | null\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 readonly motion: SdfMotionOptions | false\n readonly maxSequence: number\n readonly tone?: TextToneOptions | ResolvedTextTone | false\n }): GlyphTextMaterial\n dispose(): void\n}\n\n/** Builds a pure GPU Slug backend without any SDF companion or atlas dependency. */\nexport async function buildStandaloneSlugBackend(\n renderer: WebGPURenderer,\n requests: readonly GlyphRequest[],\n options: StandaloneSlugBuildOptions,\n signal: AbortSignal,\n): Promise<StandaloneSlugBackend> {\n await abortable(renderer.init(), signal)\n throwIfAborted(signal)\n if (!(renderer.backend instanceof WebGPUBackend)) {\n throw new Error('DomSlug: the Slug text backend requires WebGPU')\n }\n const limit =\n (renderer.backend as unknown as { device?: { limits: { maxVertexBuffers: number } } }).device\n ?.limits.maxVertexBuffers ?? 8\n if (limit < 7) {\n throw new Error('DomSlug: Slug requires at least seven vertex buffers')\n }\n\n const hasShapes = requests.some((request) => request.shape !== undefined)\n const extensions = hasShapes ? await abortable(import('../windfoil/requests.js'), signal) : null\n\n let resolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<WindfoilOutlineProvider>>\n }[]\n if (extensions) {\n resolved = await abortable(\n Promise.all(\n requests.map(async (request) => ({\n request,\n outline: await extensions.resolveShapeRequest(\n request,\n { outlineProvider: options.outlineProvider },\n signal,\n ),\n })),\n ),\n signal,\n )\n } else {\n const syncResolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<WindfoilOutlineProvider>>\n }[] = []\n let pending:\n | Promise<{\n request: GlyphRequest\n outline: Awaited<ReturnType<WindfoilOutlineProvider>>\n }>[]\n | 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\n const missing = resolved.filter((item) => item.outline === null)\n const missingMode = options.missingGlyphs ?? 'error'\n if (missing.length > 0 && missingMode === 'error') {\n throw new Error(\n `DomSlug: outlineProvider returned null for ${JSON.stringify(missing[0]!.request.character)} in ${missing[0]!.request.font.family}`,\n )\n }\n const skippedKeys = new Set(missing.map((item) => item.request.key))\n\n const needsLayerNormalization = resolved.some(\n (item) => item.outline?.layers !== undefined || item.outline?.clipBox !== undefined,\n )\n const layerModule = needsLayerNormalization\n ? await abortable(import('../windfoil/layerNormalization.js'), signal)\n : null\n\n const prepared = preprocessSlugGlyphs(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n )\n\n const layered = prepared.layered\n if (layered && limit < 8) {\n throw new Error('DomSlug: layered Slug requires eight vertex buffers')\n }\n\n const wantsColor = [...prepared.glyphs.values()].some(\n (header) => header.layers?.some((layer) => layer.paintKind === 2) ?? false,\n )\n const colorPromise = wantsColor ? import('../windfoil/color.js') : null\n\n let coverage: ReturnType<typeof createWindfoilStorage> | undefined\n let 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(\n renderer,\n prepared,\n { outlineProvider: options.outlineProvider, compositing: 'layers' },\n coverage,\n signal,\n ) ?? null\n const plainGlyphs = colorResources?.plainGlyphs ?? prepared.glyphs\n\n let glyphEm = false\n const sized = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n const withEm = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n if (!glyphEm) return snapshot\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\n let geometryLayered = layered\n let disposed = false\n const retained = coverage\n return {\n kind: 'slug',\n layered,\n glyphs: prepared.glyphs,\n skippedKeys,\n storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),\n preprocessStats: prepared.stats,\n covers(key) {\n return prepared.glyphs.has(key) || skippedKeys.has(key)\n },\n analyticCovers(key) {\n return !!plainGlyphs.get(key)?.monotonePieceCount\n },\n contentFits(geometry, snapshot) {\n return windfoilContentFits(geometry, withEm(snapshot), plainGlyphs)\n },\n createGeometry(snapshot, padding) {\n const layout = withEm(snapshot)\n geometryLayered = layered || layout.glyphs.some((glyph) => !!glyph.motionOrigin)\n if (geometryLayered && limit < 8) {\n throw new Error('DomSlug: layered Slug requires eight vertex buffers')\n }\n return createWindfoilGlyphGeometry(layout, plainGlyphs, padding, geometryLayered)\n },\n updateGeometry(geometry, snapshot, padding) {\n return updateWindfoilGlyphGeometry(geometry, withEm(snapshot), plainGlyphs, padding)\n },\n setGlyphEm(value) {\n glyphEm = value\n },\n createMaterial(materialOptions) {\n return new SlugMaterial({\n ...retained,\n layered: geometryLayered,\n ...(colorResources ? { paintFunctions: colorResources.paintFunctions } : {}),\n ...materialOptions,\n })\n },\n dispose() {\n if (disposed) return\n disposed = true\n retained.dispose()\n colorResources?.dispose()\n },\n }\n } catch (error) {\n coverage?.dispose()\n colorResources?.dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;;AAmEA,eAAsB,2BACpB,UACA,UACA,SACA,QACgC;CAChC,MAAM,UAAU,SAAS,KAAK,GAAG,MAAM;CACvC,eAAe,MAAM;CACrB,IAAI,EAAE,SAAS,mBAAmB,gBAChC,MAAM,IAAI,MAAM,gDAAgD;CAElE,MAAM,QACH,SAAS,QAA6E,QACnF,OAAO,oBAAoB;CACjC,IAAI,QAAQ,GACV,MAAM,IAAI,MAAM,sDAAsD;CAIxE,MAAM,aADY,SAAS,MAAM,YAAY,QAAQ,UAAU,KAAA,CAC5C,IAAY,MAAM,UAAU,OAAO,4BAA4B,MA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B,SAAS;GAC1B,OAAO,KAAK;IACV,OAAO,SAAS,OAAO,IAAI,GAAG,KAAK,YAAY,IAAI,GAAG;GACxD;GACA,eAAe,KAAK;IAClB,OAAO,CAAC,CAAC,YAAY,IAAI,GAAG,CAAC,EAAE;GACjC;GACA,YAAY,UAAU,UAAU;IAC9B,OAAO,oBAAoB,UAAU,OAAO,QAAQ,GAAG,WAAW;GACpE;GACA,eAAe,UAAU,SAAS;IAChC,MAAM,SAAS,OAAO,QAAQ;IAC9B,kBAAkB,WAAW,OAAO,OAAO,MAAM,UAAU,CAAC,CAAC,MAAM,YAAY;IAC/E,IAAI,mBAAmB,QAAQ,GAC7B,MAAM,IAAI,MAAM,qDAAqD;IAEvE,OAAO,4BAA4B,QAAQ,aAAa,SAAS,eAAe;GAClF;GACA,eAAe,UAAU,UAAU,SAAS;IAC1C,OAAO,4BAA4B,UAAU,OAAO,QAAQ,GAAG,aAAa,OAAO;GACrF;GACA,WAAW,OAAO;IAChB,UAAU;GACZ;GACA,eAAe,iBAAiB;IAC9B,OAAO,IAAI,aAAa;KACtB,GAAG;KACH,SAAS;KACT,GAAI,iBAAiB,EAAE,gBAAgB,eAAe,eAAe,IAAI,CAAC;KAC1E,GAAG;IACL,CAAC;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;GAC1B;EACF;CACF,SAAS,OAAO;EACd,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,MAAM;CACR;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WindfoilGlyphOutline, WindfoilOutlineProvider } from '../types.js';
|
|
2
|
+
export interface TrueTypeFont {
|
|
3
|
+
readonly unitsPerEm: number;
|
|
4
|
+
readonly ascent: number;
|
|
5
|
+
readonly descent: number;
|
|
6
|
+
readonly glyphCount: number;
|
|
7
|
+
has(codePoint: number): boolean;
|
|
8
|
+
outline(character: string): WindfoilGlyphOutline | null;
|
|
9
|
+
outlineForCodePoint(codePoint: number): WindfoilGlyphOutline | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Lightweight runtime TrueType (`.ttf` `glyf` table) outline reader for Slug.
|
|
13
|
+
* Supports Unicode `cmap` formats 4 and 12, simple quadratic contours (including
|
|
14
|
+
* implied midpoints and all-off-curve rings), and offset/affine composite glyphs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseTrueTypeFont(source: ArrayBuffer | ArrayBufferView): TrueTypeFont;
|
|
17
|
+
export type TrueTypeFontSource = ArrayBuffer | ArrayBufferView | TrueTypeFont | ReadonlyMap<string, ArrayBuffer | ArrayBufferView | TrueTypeFont> | Readonly<Record<string, ArrayBuffer | ArrayBufferView | TrueTypeFont>>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a `WindfoilOutlineProvider` from a single `.ttf` buffer/`TrueTypeFont` or a family-keyed
|
|
20
|
+
* map/object of `.ttf` buffers (with optional `'*'` fallback key).
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTrueTypeOutlineProvider(source: TrueTypeFontSource): WindfoilOutlineProvider;
|