ultra-text 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { type ResolvedTextTone } from '../dom/tone.js';
|
|
2
|
+
import type { ColorGlyphMode, DomLayoutSnapshot, DomSdfStats, DomSvgOptions, DomTextLayoutEngine, GlyphRequest, SdfMotionOptions, TextClass, TextCss, TextToneOptions, WindfoilOutlineProvider } from '../types.js';
|
|
3
|
+
import type { WindfoilGlyphHeader, WindfoilPreprocessStats } from '../windfoil/outlineValidation.js';
|
|
4
|
+
export interface VanillaGpuBuffer {
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
readonly size?: number;
|
|
7
|
+
readonly usage?: number;
|
|
8
|
+
destroy(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface VanillaSlugGpuRenderPass {
|
|
11
|
+
setPipeline(pipeline: unknown): void;
|
|
12
|
+
setBindGroup(index: number, bindGroup: unknown): void;
|
|
13
|
+
setVertexBuffer(slot: number, buffer: VanillaGpuBuffer, offset?: number, size?: number): void;
|
|
14
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
15
|
+
}
|
|
16
|
+
export interface VanillaSlugGpuDevice {
|
|
17
|
+
readonly limits?: {
|
|
18
|
+
readonly maxStorageBufferBindingSize?: number;
|
|
19
|
+
readonly maxBufferSize?: number;
|
|
20
|
+
readonly maxVertexBuffers?: number;
|
|
21
|
+
};
|
|
22
|
+
createBuffer(descriptor: {
|
|
23
|
+
label?: string;
|
|
24
|
+
size: number;
|
|
25
|
+
usage: number;
|
|
26
|
+
mappedAtCreation?: boolean;
|
|
27
|
+
}): VanillaGpuBuffer;
|
|
28
|
+
createShaderModule(descriptor: {
|
|
29
|
+
label?: string;
|
|
30
|
+
code: string;
|
|
31
|
+
}): unknown;
|
|
32
|
+
createRenderPipeline(descriptor: {
|
|
33
|
+
label?: string;
|
|
34
|
+
layout: 'auto';
|
|
35
|
+
vertex: {
|
|
36
|
+
module: unknown;
|
|
37
|
+
entryPoint: string;
|
|
38
|
+
buffers?: readonly {
|
|
39
|
+
arrayStride: number;
|
|
40
|
+
stepMode?: 'vertex' | 'instance';
|
|
41
|
+
attributes: readonly {
|
|
42
|
+
shaderLocation: number;
|
|
43
|
+
offset: number;
|
|
44
|
+
format: string;
|
|
45
|
+
}[];
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
fragment: {
|
|
49
|
+
module: unknown;
|
|
50
|
+
entryPoint: string;
|
|
51
|
+
targets: readonly {
|
|
52
|
+
format: string;
|
|
53
|
+
blend?: {
|
|
54
|
+
color: {
|
|
55
|
+
srcFactor: string;
|
|
56
|
+
dstFactor: string;
|
|
57
|
+
operation?: string;
|
|
58
|
+
};
|
|
59
|
+
alpha: {
|
|
60
|
+
srcFactor: string;
|
|
61
|
+
dstFactor: string;
|
|
62
|
+
operation?: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
primitive?: {
|
|
68
|
+
topology?: string;
|
|
69
|
+
cullMode?: string;
|
|
70
|
+
};
|
|
71
|
+
depthStencil?: {
|
|
72
|
+
format: string;
|
|
73
|
+
depthWriteEnabled?: boolean;
|
|
74
|
+
depthCompare?: string;
|
|
75
|
+
};
|
|
76
|
+
multisample?: {
|
|
77
|
+
count?: number;
|
|
78
|
+
};
|
|
79
|
+
}): {
|
|
80
|
+
getBindGroupLayout(index: number): unknown;
|
|
81
|
+
};
|
|
82
|
+
createBindGroup(descriptor: {
|
|
83
|
+
label?: string;
|
|
84
|
+
layout: unknown;
|
|
85
|
+
entries: readonly {
|
|
86
|
+
binding: number;
|
|
87
|
+
resource: unknown;
|
|
88
|
+
}[];
|
|
89
|
+
}): unknown;
|
|
90
|
+
readonly queue: {
|
|
91
|
+
writeBuffer(buffer: VanillaGpuBuffer, bufferOffset: number, data: ArrayBufferView, dataOffset?: number, size?: number): void;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export type VanillaSlugGpuDeviceSource = VanillaSlugGpuDevice | {
|
|
95
|
+
readonly device?: VanillaSlugGpuDevice | null | undefined;
|
|
96
|
+
} | null | undefined;
|
|
97
|
+
export interface BuildVanillaSlugAtlasOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Maps a captured CSS font request to quadratic outlines. When omitted and a
|
|
100
|
+
* `document` is available, `buildVanillaSlugAtlas` traces glyphs from the
|
|
101
|
+
* browser's Canvas 2D rendering using `createTracedOutlineProvider`.
|
|
102
|
+
*/
|
|
103
|
+
outlineProvider?: WindfoilOutlineProvider;
|
|
104
|
+
/** Document used by the built-in Canvas 2D outline tracer when `outlineProvider` is omitted. */
|
|
105
|
+
document?: Document;
|
|
106
|
+
/** How to handle `null` outlines: `'skip'` (default for traced outlines) or `'error'`. */
|
|
107
|
+
missingGlyphs?: 'skip' | 'error';
|
|
108
|
+
/** Target monotone-piece count per Slug band. Defaults to `2`. */
|
|
109
|
+
targetPiecesPerBand?: number;
|
|
110
|
+
/** Trace resolution in pixels per em when using built-in traced outlines. Defaults to `256`. */
|
|
111
|
+
traceSize?: number;
|
|
112
|
+
/** Quadratic curve fit tolerance in trace pixels when using built-in traced outlines. Defaults to `0.25`. */
|
|
113
|
+
traceTolerance?: number;
|
|
114
|
+
/** Colour-glyph classification for built-in traced outlines. Defaults to `'emoji'`. */
|
|
115
|
+
colorGlyphs?: ColorGlyphMode;
|
|
116
|
+
signal?: AbortSignal;
|
|
117
|
+
}
|
|
118
|
+
export interface VanillaSlugAtlas {
|
|
119
|
+
/** Packed SoA `[p1, p3] | [p2]` `vec2f` control points (`Float32Array`). */
|
|
120
|
+
readonly curves: Float32Array;
|
|
121
|
+
/** Packed single-word `uint32` Slug band headers (`Uint32Array`). */
|
|
122
|
+
readonly rows: Uint32Array;
|
|
123
|
+
/** Retained GPU storage buffer for `curves` when built with a `GPUDevice`. */
|
|
124
|
+
readonly curvesBuffer?: VanillaGpuBuffer;
|
|
125
|
+
/** Retained GPU storage buffer for `rows` when built with a `GPUDevice`. */
|
|
126
|
+
readonly rowsBuffer?: VanillaGpuBuffer;
|
|
127
|
+
/** Glyph and shape headers keyed by `GlyphRequest.key`. */
|
|
128
|
+
readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>;
|
|
129
|
+
/** Keys skipped when `missingGlyphs: 'skip'` is active. */
|
|
130
|
+
readonly skippedKeys: ReadonlySet<string>;
|
|
131
|
+
readonly layered: boolean;
|
|
132
|
+
readonly stats: WindfoilPreprocessStats;
|
|
133
|
+
/** Logical byte length of `curves` + `rows`. */
|
|
134
|
+
readonly byteLength: number;
|
|
135
|
+
covers(key: string): boolean;
|
|
136
|
+
dispose(): void;
|
|
137
|
+
}
|
|
138
|
+
export declare function buildVanillaSlugAtlas(deviceOrRenderer: VanillaSlugGpuDeviceSource, requests: readonly GlyphRequest[], options?: BuildVanillaSlugAtlasOptions): Promise<VanillaSlugAtlas>;
|
|
139
|
+
export { buildVanillaSlugAtlas as buildSlugAtlas };
|
|
140
|
+
export declare const UNIT_QUAD_POSITIONS: Float32Array<ArrayBuffer>;
|
|
141
|
+
export declare const UNIT_QUAD_NORMALS: Float32Array<ArrayBuffer>;
|
|
142
|
+
export declare const UNIT_QUAD_INDICES: Uint16Array<ArrayBuffer>;
|
|
143
|
+
export interface VanillaBounds {
|
|
144
|
+
readonly min: readonly [x: number, y: number, z: number];
|
|
145
|
+
readonly max: readonly [x: number, y: number, z: number];
|
|
146
|
+
readonly center: readonly [x: number, y: number, z: number];
|
|
147
|
+
readonly radius: number;
|
|
148
|
+
}
|
|
149
|
+
export declare function computeInstanceBounds(width: number, height: number, padding?: number, minZ?: number, maxZ?: number): VanillaBounds;
|
|
150
|
+
export interface VanillaSlugGlyphInstances {
|
|
151
|
+
count: number;
|
|
152
|
+
drawableCount: number;
|
|
153
|
+
layered: boolean;
|
|
154
|
+
maxSequence: number;
|
|
155
|
+
/** `[x0, y0, x1, y1]` per instance in local capture units (`count * 4`). */
|
|
156
|
+
rects: Float32Array;
|
|
157
|
+
/** `[x0, y0, x1, y1]` clip box per instance (`count * 4`). */
|
|
158
|
+
clips: Float32Array;
|
|
159
|
+
/** Normalized `unorm8` `[r, g, b, a]` per instance (`count * 4`). */
|
|
160
|
+
colors: Uint8Array;
|
|
161
|
+
/** `[sequence, z]` or `[sequence, z, switchEm]` per instance (`count * metaItemSize`). */
|
|
162
|
+
metadata: Float32Array;
|
|
163
|
+
metaItemSize: 2 | 3;
|
|
164
|
+
/** `[b0, b1, b2, b3]` glyph outline box in font units (`count * 4`). */
|
|
165
|
+
glyphBounds: Float32Array;
|
|
166
|
+
/** `[rowBase, packedCounts, vBandW, invHBandH]` Slug band parameters (`count * 4`). */
|
|
167
|
+
bands: Float32Array;
|
|
168
|
+
/** `[originX, originY, ordinal, paint]` when `layered` is `true`, otherwise `null`. */
|
|
169
|
+
layers: Float32Array | null;
|
|
170
|
+
/** `[x0, y0, x1, y1]` per drawable glyph (`drawableCount * 4`), used by decoration packers. */
|
|
171
|
+
glyphRects: Float32Array;
|
|
172
|
+
bounds: VanillaBounds;
|
|
173
|
+
}
|
|
174
|
+
export interface VanillaRectInstances {
|
|
175
|
+
count: number;
|
|
176
|
+
readonly receiveShadow: boolean;
|
|
177
|
+
rects: Float32Array;
|
|
178
|
+
colors: Uint8Array;
|
|
179
|
+
radii: Float32Array;
|
|
180
|
+
depths: Float32Array;
|
|
181
|
+
bounds: VanillaBounds;
|
|
182
|
+
}
|
|
183
|
+
export interface VanillaDecorationInstances {
|
|
184
|
+
count: number;
|
|
185
|
+
rects: Float32Array;
|
|
186
|
+
decorationRects: Float32Array;
|
|
187
|
+
decorationIndices: Float32Array;
|
|
188
|
+
colors: Uint8Array;
|
|
189
|
+
clips: Float32Array;
|
|
190
|
+
metadata: Float32Array;
|
|
191
|
+
runMotion: Float32Array | null;
|
|
192
|
+
bounds: VanillaBounds;
|
|
193
|
+
}
|
|
194
|
+
export declare function packSlugGlyphInstances(snapshot: DomLayoutSnapshot, atlas: Pick<VanillaSlugAtlas, 'glyphs' | 'layered'>, motionPadding?: number): VanillaSlugGlyphInstances;
|
|
195
|
+
export declare function updateSlugGlyphInstances(instances: VanillaSlugGlyphInstances, snapshot: DomLayoutSnapshot, atlas: Pick<VanillaSlugAtlas, 'glyphs' | 'layered'>, motionPadding?: number): number | null;
|
|
196
|
+
export declare function packRectInstances(snapshot: DomLayoutSnapshot, receiveShadow?: boolean): VanillaRectInstances | null;
|
|
197
|
+
export declare function updateRectInstances(instances: VanillaRectInstances, snapshot: DomLayoutSnapshot, receiveShadow?: boolean): boolean;
|
|
198
|
+
export declare function packDecorationInstances(snapshot: DomLayoutSnapshot, sourceGlyphRects: ArrayLike<number>, drawable: (key: string) => boolean, motionPadding?: number): VanillaDecorationInstances | null;
|
|
199
|
+
export declare function updateDecorationInstances(instances: VanillaDecorationInstances, snapshot: DomLayoutSnapshot, sourceGlyphRects: ArrayLike<number>, drawable: (key: string) => boolean, motionPadding?: number): boolean;
|
|
200
|
+
export declare const SLUG_WGSL = "\nstruct SlugUniforms {\n mvp: mat4x4f,\n viewportAndSkirt: vec4f,\n tintAndFlags: vec4f,\n}\n\n@group(0) @binding(0) var<uniform> slugUniforms: SlugUniforms;\n@group(0) @binding(1) var<storage, read> slugCurves: array<vec4f>;\n@group(0) @binding(2) var<storage, read> slugRows: array<u32>;\n\nstruct SlugVSOut {\n @builtin(position) position: vec4f,\n @location(0) glyphPos: vec2f,\n @location(1) localPos: vec2f,\n @location(2) @interpolate(flat, either) clip: vec4f,\n @location(3) @interpolate(flat, either) color: vec4f,\n @location(4) @interpolate(flat, either) band: vec4f,\n @location(5) @interpolate(flat, either) bandOrigin: vec4f,\n}\n\nfn slug_vertex_skirt(\n colX: vec4f,\n colY: vec4f,\n clip: vec4f,\n viewport: vec2f,\n quad: vec2f,\n skirt: f32,\n) -> vec2f {\n let safeW = max(clip.w, 1e-6);\n let sx = (colX.xy * safeW - clip.xy * colX.w) * viewport;\n let sy = (colY.xy * safeW - clip.xy * colY.w) * viewport;\n let absDet = max(abs(fma(sx.x, sy.y, -sx.y * sy.x)), 1e-20);\n let u = fma(quad, vec2f(2.0), vec2f(-1.0)) * vec2f(length(sy), length(sx)) * (skirt * 2.0 * safeW * safeW);\n let mult = max(clip.w, 0.0) / max(fma(-u.x, colX.w, fma(-u.y, colY.w, absDet * clip.w)), absDet * safeW * 0.0625);\n return u * mult;\n}\n\n@vertex\nfn slugVert(\n @builtin(vertex_index) vertexIndex: u32,\n @location(0) rect: vec4f,\n @location(1) clip: vec4f,\n @location(2) color: vec4f,\n @location(3) glyphBounds: vec4f,\n @location(4) rawBand: vec4f,\n @location(5) sdfMeta: vec4f,\n) -> SlugVSOut {\n let vi = vertexIndex;\n let quad = vec2f(\n select(0.0, 1.0, (vi == 1u) || (vi == 2u) || (vi == 4u)),\n select(0.0, 1.0, (vi >= 2u) && (vi != 3u)),\n );\n let baseLocal = mix(rect.xy, rect.zw, quad);\n let depth = sdfMeta.y;\n let viewport = max(slugUniforms.viewportAndSkirt.xy, vec2f(1.0));\n let skirt = slugUniforms.viewportAndSkirt.z;\n let colX = slugUniforms.mvp[0];\n let colY = slugUniforms.mvp[1];\n let clip0 = slugUniforms.mvp * vec4f(baseLocal, depth, 1.0);\n let localOffset = slug_vertex_skirt(colX, colY, clip0, viewport, quad, skirt);\n let expandedLocal = baseLocal + localOffset;\n let localSize = max(rect.zw - rect.xy, vec2f(1e-6));\n let boundsSize = glyphBounds.zw - glyphBounds.xy;\n\n let packedCounts = u32(rawBand.y);\n let hBandCount = max(packedCounts & 255u, 1u);\n let vBandCount = max(packedCounts >> 8u, 1u);\n\n var out: SlugVSOut;\n out.position = clip0 + colX * localOffset.x + colY * localOffset.y;\n out.glyphPos = glyphBounds.xy + boundsSize * (quad + localOffset / localSize);\n out.localPos = expandedLocal;\n out.clip = clip;\n out.color = vec4f(color.rgb * slugUniforms.tintAndFlags.rgb, color.a * slugUniforms.viewportAndSkirt.w);\n out.band = rawBand;\n out.bandOrigin = vec4f(\n -glyphBounds.y * rawBand.w,\n glyphBounds.z * rawBand.z,\n 16.0 / f32(hBandCount),\n 16.0 / f32(vBandCount),\n );\n return out;\n}\n\nfn slug_pixel_metrics_auto(p: vec2f) -> vec4f {\n let dx = dpdx(p);\n let dy = dpdy(p);\n let lenSq = max(vec2f(fma(dx.x, dx.x, dy.x * dy.x), fma(dx.y, dx.y, dy.y * dy.y)), vec2f(1e-18));\n let inv = inverseSqrt(lenSq);\n return vec4f(lenSq * (inv * 0.5), inv);\n}\n\nfn slug_band_active(\n packedRow: u32,\n orthoBf: f32,\n orthoHalf: f32,\n orthoCount: u32,\n orthoScale16: f32,\n flip: bool,\n) -> bool {\n if ((packedRow & 63u) == 0u) {\n return false;\n }\n let lo = (orthoBf + orthoHalf) * orthoScale16;\n let hi = (f32(orthoCount) - orthoBf + orthoHalf) * orthoScale16;\n let qMin = f32((packedRow >> 6u) & 15u);\n let qMax = f32((packedRow >> 10u) & 15u);\n return select(lo > qMin && hi > qMax, hi > qMin && lo > qMax, flip);\n}\n\nfn slug_solve_linear_straddle(c1: vec2f, c3: vec2f, xLo: f32, dy1: f32, dy3: f32, s: f32, invDiam: f32) -> vec2f {\n let t = dy1 / (dy1 - dy3);\n let u = saturate(fma(c3.x - c1.x, t, c1.x - xLo) * invDiam);\n return vec2f(s * u, fma(-u, u, u));\n}\n\nfn slug_solve_straddle(c1: vec2f, c2: vec2f, c3: vec2f, xLo: f32, dy1: f32, s: f32, invDiam: f32) -> vec2f {\n let b = c1 - c2;\n let a = (c3 - c2) + b;\n let d = sqrt(max(fma(-a.y, dy1, b.y * b.y), 1e-24));\n let t = dy1 / fma(s, d, b.y);\n let u = saturate(fma(fma(a.x, t, -2.0 * b.x), t, c1.x - xLo) * invDiam);\n return vec2f(s * u, fma(-u, u, u));\n}\n\nfn slug_gather_band(\n packedRow: u32,\n rc: vec2f,\n halfPx: f32,\n invDiam: f32,\n) -> vec2f {\n var cw = vec2f(0.0);\n let count = packedRow & 63u;\n let start = packedRow >> 15u;\n let allLinear = (packedRow & 0x4000u) != 0u;\n let c2Base = start + count;\n let xLo = rc.x - halfPx;\n let xHi = rc.x + halfPx;\n for (var i = 0u; i < count; i++) {\n let curve = slugCurves[start + i];\n let c1 = curve.xy;\n let c3 = curve.zw;\n if (max(c1.x, c3.x) <= xLo) {\n break;\n }\n let dy1 = c1.y - rc.y;\n let dy3 = c3.y - rc.y;\n let u1 = bitcast<u32>(dy1);\n let u3 = bitcast<u32>(dy3);\n if ((u1 ^ u3) < 0x80000000u) {\n continue;\n }\n let s = bitcast<f32>((u1 & 0x80000000u) | 0x3f800000u);\n if (min(c1.x, c3.x) >= xHi) {\n cw.x += s;\n continue;\n }\n var hit: vec2f;\n if (allLinear) {\n hit = slug_solve_linear_straddle(c1, c3, xLo, dy1, dy3, s, invDiam);\n } else {\n let c2Pair = slugCurves[c2Base + (i >> 1u)];\n let c2 = select(c2Pair.xy, c2Pair.zw, (i & 1u) != 0u);\n hit = slug_solve_straddle(c1, c2, c3, xLo, dy1, s, invDiam);\n }\n cw.x += hit.x;\n cw.y = max(cw.y, hit.y);\n }\n return cw;\n}\n\nfn slug_combine_rays(xc: vec2f, yc: vec2f) -> f32 {\n let ax = abs(xc.x);\n let ay = abs(yc.x);\n let wx = xc.y * xc.y;\n let wy = yc.y * yc.y;\n let weighted = fma(ax, wx, ay * wy) / max(wx + wy, 1e-12);\n return saturate(max(weighted, min(ax, ay)));\n}\n\n@fragment\nfn slugFrag(input: SlugVSOut) -> @location(0) vec4f {\n let metrics = slug_pixel_metrics_auto(input.glyphPos);\n let insideClip =\n input.localPos.x >= input.clip.x &&\n input.localPos.x <= input.clip.z &&\n input.localPos.y >= input.clip.y &&\n input.localPos.y <= input.clip.w;\n var coverage = 0.0;\n if (insideClip) {\n let center = input.glyphPos;\n let packedCounts = u32(input.band.y);\n let hBandCount = max(packedCounts & 255u, 1u);\n let vBandCount = max(packedCounts >> 8u, 1u);\n let hRowBase = u32(input.band.x);\n let vRowBase = hRowBase + hBandCount;\n let totalBands = vec2f(f32(hBandCount), f32(vBandCount));\n let maxBands = totalBands - vec2f(1.0);\n let bf = vec2f(\n fma(center.y, input.band.w, input.bandOrigin.x),\n input.bandOrigin.y - center.x * input.band.z,\n );\n let halfBand = fma(metrics.yx, input.band.wz, vec2f(1e-4));\n let scale16 = input.bandOrigin.zw;\n\n var xc = vec2f(0.0);\n var earlyZero = false;\n if (bf.x >= -1e-4 && bf.x <= totalBands.x + 1e-4) {\n let hBi = u32(clamp(bf.x, 0.0, maxBands.x));\n let hPackedRow = slugRows[hRowBase + hBi];\n if (slug_band_active(hPackedRow, bf.y, halfBand.y, vBandCount, scale16.y, true)) {\n xc = slug_gather_band(hPackedRow, center, metrics.x, metrics.z);\n } else if (abs((bf.x - f32(hBi)) - 0.5) <= 0.5 - halfBand.x) {\n earlyZero = true;\n }\n }\n\n if (!earlyZero) {\n var yc = vec2f(0.0);\n if (bf.y >= -1e-4 && bf.y <= totalBands.y + 1e-4) {\n let vBi = u32(clamp(bf.y, 0.0, maxBands.y));\n let vPackedRow = slugRows[vRowBase + vBi];\n if (slug_band_active(vPackedRow, bf.x, halfBand.x, hBandCount, scale16.x, false)) {\n yc = slug_gather_band(vPackedRow, vec2f(center.y, -center.x), metrics.y, metrics.w);\n }\n }\n coverage = slug_combine_rays(xc, yc);\n }\n }\n let alpha = coverage * input.color.a;\n if (alpha < 0.001953125) {\n discard;\n }\n return vec4f(input.color.rgb * alpha, alpha);\n}\n";
|
|
201
|
+
export interface VanillaSlugPipelineOptions {
|
|
202
|
+
/** Color target format (e.g. `navigator.gpu.getPreferredCanvasFormat()`). Defaults to `'bgra8unorm'`. */
|
|
203
|
+
format?: string;
|
|
204
|
+
/** Optional depth-stencil attachment format. */
|
|
205
|
+
depthFormat?: string;
|
|
206
|
+
depthWriteEnabled?: boolean;
|
|
207
|
+
depthCompare?: string;
|
|
208
|
+
sampleCount?: number;
|
|
209
|
+
cullMode?: 'none' | 'front' | 'back';
|
|
210
|
+
metaItemSize?: 1 | 2 | 3;
|
|
211
|
+
}
|
|
212
|
+
export interface VanillaSlugGpuInstances {
|
|
213
|
+
readonly count: number;
|
|
214
|
+
readonly rects: VanillaGpuBuffer;
|
|
215
|
+
readonly clips: VanillaGpuBuffer;
|
|
216
|
+
readonly colors: VanillaGpuBuffer;
|
|
217
|
+
readonly glyphBounds: VanillaGpuBuffer;
|
|
218
|
+
readonly bands: VanillaGpuBuffer;
|
|
219
|
+
readonly metadata: VanillaGpuBuffer;
|
|
220
|
+
update(instances: VanillaSlugGlyphInstances): void;
|
|
221
|
+
dispose(): void;
|
|
222
|
+
}
|
|
223
|
+
export interface VanillaSlugDrawUniforms {
|
|
224
|
+
/** Column-major `4x4` model-view-projection matrix (`Float32Array` of 16 floats). */
|
|
225
|
+
mvp: ArrayLike<number>;
|
|
226
|
+
viewportWidth: number;
|
|
227
|
+
viewportHeight: number;
|
|
228
|
+
/** Quad AA skirt in device pixels. Defaults to `0.75`. */
|
|
229
|
+
skirtPx?: number;
|
|
230
|
+
opacity?: number;
|
|
231
|
+
tint?: readonly [r: number, g: number, b: number];
|
|
232
|
+
}
|
|
233
|
+
export interface VanillaSlugPipeline {
|
|
234
|
+
readonly pipeline: {
|
|
235
|
+
getBindGroupLayout(index: number): unknown;
|
|
236
|
+
};
|
|
237
|
+
readonly uniformBuffer: VanillaGpuBuffer;
|
|
238
|
+
writeUniforms(uniforms: VanillaSlugDrawUniforms): void;
|
|
239
|
+
createBindGroup(atlas: Pick<VanillaSlugAtlas, 'curvesBuffer' | 'rowsBuffer'>): unknown;
|
|
240
|
+
draw(pass: VanillaSlugGpuRenderPass, bindGroup: unknown, gpuInstances: VanillaSlugGpuInstances): void;
|
|
241
|
+
dispose(): void;
|
|
242
|
+
}
|
|
243
|
+
/** Uploads packed `VanillaSlugGlyphInstances` into 6 instanced `GPUBuffer`s for `SLUG_WGSL`. */
|
|
244
|
+
export declare function uploadSlugGlyphBuffers(device: VanillaSlugGpuDevice, instances: VanillaSlugGlyphInstances): VanillaSlugGpuInstances;
|
|
245
|
+
/** Creates a ready-to-draw premultiplied-alpha WebGPU render pipeline for `SLUG_WGSL`. */
|
|
246
|
+
export declare function createVanillaSlugPipeline(device: VanillaSlugGpuDevice, options?: VanillaSlugPipelineOptions): VanillaSlugPipeline;
|
|
247
|
+
export type VanillaSlugChangeReason = 'create' | 'rebuild' | 'reflow' | 'motion' | 'dispose';
|
|
248
|
+
export interface VanillaDomSlugRebuildOptions {
|
|
249
|
+
outlines?: boolean;
|
|
250
|
+
atlas?: boolean;
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
}
|
|
253
|
+
export interface VanillaDomSlugOptions {
|
|
254
|
+
colorGlyphs?: ColorGlyphMode;
|
|
255
|
+
svg?: boolean | DomSvgOptions;
|
|
256
|
+
tone?: TextToneOptions | false;
|
|
257
|
+
layoutEngine?: DomTextLayoutEngine;
|
|
258
|
+
textSelector?: string;
|
|
259
|
+
rectSelector?: string;
|
|
260
|
+
ignoreSelector?: string;
|
|
261
|
+
includeRootBackground?: boolean;
|
|
262
|
+
extraGlyphs?: string;
|
|
263
|
+
pixelsPerUnit?: number;
|
|
264
|
+
pixelSnap?: boolean;
|
|
265
|
+
textDepth?: number;
|
|
266
|
+
rectDepth?: number;
|
|
267
|
+
panelDepth?: number;
|
|
268
|
+
cjkLineBreaking?: boolean;
|
|
269
|
+
rtlReflow?: boolean;
|
|
270
|
+
reshape?: (text: string) => string;
|
|
271
|
+
selectable?: boolean;
|
|
272
|
+
motion?: SdfMotionOptions;
|
|
273
|
+
reflowable?: boolean;
|
|
274
|
+
observe?: boolean;
|
|
275
|
+
signal?: AbortSignal;
|
|
276
|
+
onError?: (error: unknown) => void;
|
|
277
|
+
outlineProvider?: WindfoilOutlineProvider;
|
|
278
|
+
missingGlyphs?: 'skip' | 'error';
|
|
279
|
+
targetPiecesPerBand?: number;
|
|
280
|
+
traceSize?: number;
|
|
281
|
+
traceTolerance?: number;
|
|
282
|
+
/** Optional shared `VanillaSlugAtlas` across multiple `VanillaDomSlug` instances. */
|
|
283
|
+
sharedAtlas?: VanillaSlugAtlas;
|
|
284
|
+
/** Called after initial creation, rebuild, reflow, motion update, or disposal. */
|
|
285
|
+
onChange?: (instance: VanillaDomSlug, reason: VanillaSlugChangeReason) => void;
|
|
286
|
+
}
|
|
287
|
+
export declare class VanillaDomSlug {
|
|
288
|
+
#private;
|
|
289
|
+
readonly element: HTMLElement;
|
|
290
|
+
readonly device: VanillaSlugGpuDevice | null;
|
|
291
|
+
readonly options: Readonly<VanillaDomSlugOptions>;
|
|
292
|
+
glyphs: VanillaSlugGlyphInstances;
|
|
293
|
+
plainRects: VanillaRectInstances | null;
|
|
294
|
+
litRects: VanillaRectInstances | null;
|
|
295
|
+
decorations: VanillaDecorationInstances | null;
|
|
296
|
+
tone: ResolvedTextTone | null;
|
|
297
|
+
motion: Required<SdfMotionOptions>;
|
|
298
|
+
protected constructor(element: HTMLElement, deviceOrRenderer: VanillaSlugGpuDeviceSource, options: VanillaDomSlugOptions);
|
|
299
|
+
static create(element: HTMLElement, deviceOrRenderer?: VanillaSlugGpuDeviceSource, options?: VanillaDomSlugOptions): Promise<VanillaDomSlug>;
|
|
300
|
+
get atlas(): VanillaSlugAtlas;
|
|
301
|
+
/** Alias for `element` matching `DomSlug.source`. */
|
|
302
|
+
get source(): HTMLElement;
|
|
303
|
+
get stats(): Readonly<DomSdfStats>;
|
|
304
|
+
get snapshot(): DomLayoutSnapshot | null;
|
|
305
|
+
get width(): number;
|
|
306
|
+
get height(): number;
|
|
307
|
+
get isDisposed(): boolean;
|
|
308
|
+
subscribe(listener: (instance: VanillaDomSlug, reason: VanillaSlugChangeReason) => void): () => void;
|
|
309
|
+
reflow(width: number): this;
|
|
310
|
+
setMotion(motion: SdfMotionOptions): this;
|
|
311
|
+
rebuild(rebuildOptions?: VanillaDomSlugRebuildOptions): Promise<this>;
|
|
312
|
+
dispose(): void;
|
|
313
|
+
protected resolveCaptureTone(snapshot: DomLayoutSnapshot): ResolvedTextTone | null;
|
|
314
|
+
protected notify(reason: VanillaSlugChangeReason): void;
|
|
315
|
+
protected applySelectableAttribute(): void;
|
|
316
|
+
protected setupObservers(): void;
|
|
317
|
+
}
|
|
318
|
+
export { VanillaDomSlug as DomSlug, VanillaDomSlug as DomText, VanillaDomSlug as VanillaDomText };
|
|
319
|
+
export interface VanillaSlugTextOptions extends VanillaDomSlugOptions {
|
|
320
|
+
device?: VanillaSlugGpuDeviceSource;
|
|
321
|
+
renderer?: VanillaSlugGpuDeviceSource;
|
|
322
|
+
css?: TextCss;
|
|
323
|
+
cssClass?: TextClass;
|
|
324
|
+
parent?: HTMLElement;
|
|
325
|
+
}
|
|
326
|
+
export declare class VanillaSlugText extends VanillaDomSlug {
|
|
327
|
+
#private;
|
|
328
|
+
readonly ready: Promise<this>;
|
|
329
|
+
constructor(text: string, options?: VanillaSlugTextOptions);
|
|
330
|
+
static create(text: string, options?: VanillaSlugTextOptions): Promise<VanillaSlugText>;
|
|
331
|
+
static create(element: HTMLElement, deviceOrRenderer?: VanillaSlugGpuDeviceSource, options?: VanillaDomSlugOptions): Promise<VanillaDomSlug>;
|
|
332
|
+
get text(): string;
|
|
333
|
+
set text(value: string);
|
|
334
|
+
setText(value: string, options?: VanillaDomSlugRebuildOptions): Promise<this>;
|
|
335
|
+
setCss(css: TextCss | undefined, options?: VanillaDomSlugRebuildOptions): Promise<this>;
|
|
336
|
+
setClass(cssClass: TextClass | undefined, options?: VanillaDomSlugRebuildOptions): Promise<this>;
|
|
337
|
+
dispose(): void;
|
|
338
|
+
protected resolveCaptureTone(snapshot: DomLayoutSnapshot): ResolvedTextTone | null;
|
|
339
|
+
}
|
|
340
|
+
export { VanillaSlugText as SlugText, VanillaSlugText as Text, VanillaSlugText as VanillaText };
|