three-text 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE_THIRD_PARTY +15 -0
  2. package/README.md +73 -42
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +1 -1
  6. package/dist/index.min.cjs +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.umd.js +1 -1
  9. package/dist/index.umd.min.js +1 -1
  10. package/dist/three/react.d.ts +2 -0
  11. package/dist/types/core/types.d.ts +2 -33
  12. package/dist/types/vector/{core.d.ts → core/index.d.ts} +8 -7
  13. package/dist/types/vector/index.d.ts +22 -25
  14. package/dist/types/vector/react.d.ts +4 -3
  15. package/dist/types/vector/slug/SlugPacker.d.ts +2 -0
  16. package/dist/types/vector/slug/curveUtils.d.ts +6 -0
  17. package/dist/types/vector/slug/index.d.ts +8 -0
  18. package/dist/types/vector/slug/shaderStrings.d.ts +4 -0
  19. package/dist/types/vector/slug/slugGLSL.d.ts +21 -0
  20. package/dist/types/vector/slug/slugTSL.d.ts +13 -0
  21. package/dist/types/vector/slug/types.d.ts +30 -0
  22. package/dist/types/vector/slug/unpackVertices.d.ts +11 -0
  23. package/dist/types/vector/webgl/index.d.ts +7 -3
  24. package/dist/types/vector/webgpu/index.d.ts +4 -4
  25. package/dist/vector/core/index.cjs +856 -0
  26. package/dist/vector/core/index.d.ts +63 -0
  27. package/dist/vector/core/index.js +854 -0
  28. package/dist/vector/core.cjs +4419 -240
  29. package/dist/vector/core.d.ts +361 -71
  30. package/dist/vector/core.js +4406 -226
  31. package/dist/vector/index.cjs +5 -229
  32. package/dist/vector/index.d.ts +45 -396
  33. package/dist/vector/index.js +3 -223
  34. package/dist/vector/index2.cjs +287 -0
  35. package/dist/vector/index2.js +264 -0
  36. package/dist/vector/react.cjs +37 -8
  37. package/dist/vector/react.d.ts +6 -3
  38. package/dist/vector/react.js +18 -8
  39. package/dist/vector/slugTSL.cjs +252 -0
  40. package/dist/vector/slugTSL.js +231 -0
  41. package/dist/vector/webgl/index.cjs +131 -201
  42. package/dist/vector/webgl/index.d.ts +19 -44
  43. package/dist/vector/webgl/index.js +131 -201
  44. package/dist/vector/webgpu/index.cjs +100 -283
  45. package/dist/vector/webgpu/index.d.ts +16 -45
  46. package/dist/vector/webgpu/index.js +100 -283
  47. package/package.json +6 -1
  48. package/dist/types/vector/GlyphVectorGeometryBuilder.d.ts +0 -26
  49. package/dist/types/vector/LoopBlinnGeometry.d.ts +0 -68
  50. package/dist/types/vector/loopBlinnTSL.d.ts +0 -22
  51. package/dist/vector/loopBlinnTSL.cjs +0 -229
  52. package/dist/vector/loopBlinnTSL.js +0 -207
@@ -1,35 +1,8 @@
1
- import { VectorGlyphInfo, TextQueryOptions, TextRange, LoadedFont as LoadedFont$1, TextOptions as TextOptions$1 } from '../core/types';
1
+ import { Text as Text$1 } from '../core/Text';
2
+ import { VectorGlyphInfo, TextQueryOptions, TextRange, LoadedFont, TextOptions } from '../core/types';
2
3
  export { LoadedFont, TextOptions, VectorGlyphInfo } from '../core/types';
3
4
  import * as THREE from 'three';
4
5
 
5
- interface HyphenationTrieNode {
6
- patterns: number[] | null;
7
- children: {
8
- [char: string]: HyphenationTrieNode;
9
- };
10
- }
11
-
12
- declare class Vec3 {
13
- x: number;
14
- y: number;
15
- z: number;
16
- constructor(x?: number, y?: number, z?: number);
17
- set(x: number, y: number, z: number): Vec3;
18
- clone(): Vec3;
19
- copy(v: Vec3): Vec3;
20
- add(v: Vec3): Vec3;
21
- sub(v: Vec3): Vec3;
22
- multiply(scalar: number): Vec3;
23
- divide(scalar: number): Vec3;
24
- length(): number;
25
- lengthSq(): number;
26
- normalize(): Vec3;
27
- dot(v: Vec3): number;
28
- cross(v: Vec3): Vec3;
29
- distanceTo(v: Vec3): number;
30
- distanceToSquared(v: Vec3): number;
31
- equals(v: Vec3): boolean;
32
- }
33
6
  interface BoundingBox {
34
7
  min: {
35
8
  x: number;
@@ -43,386 +16,62 @@ interface BoundingBox {
43
16
  };
44
17
  }
45
18
 
46
- interface HarfBuzzGlyph {
47
- g: number;
48
- cl: number;
49
- ax: number;
50
- ay: number;
51
- dx: number;
52
- dy: number;
53
- x?: number;
54
- y?: number;
55
- lineIndex: number;
56
- absoluteTextIndex: number;
57
- }
58
- interface GlyphCluster {
59
- text: string;
60
- glyphs: HarfBuzzGlyph[];
61
- position: Vec3;
62
- }
63
- type TextAlign = 'left' | 'center' | 'right' | 'justify';
64
- type TextDirection = 'ltr' | 'rtl';
65
- interface LineInfo {
66
- text: string;
67
- originalStart: number;
68
- originalEnd: number;
69
- xOffset: number;
70
- adjustmentRatio?: number;
71
- isLastLine?: boolean;
72
- naturalWidth?: number;
73
- endedWithHyphen?: boolean;
74
- }
75
- interface LoadedFont {
76
- hb: HarfBuzzAPI;
77
- fontBlob: HarfBuzzBlob;
78
- face: HarfBuzzFace;
79
- font: HarfBuzzFont;
80
- module: HarfBuzzModule;
81
- upem: number;
82
- metrics: ExtractedMetrics;
83
- fontVariations?: {
84
- [key: string]: number;
85
- };
86
- fontFeatures?: {
87
- [tag: string]: boolean | number;
88
- };
89
- isVariable?: boolean;
90
- variationAxes?: {
91
- [key: string]: VariationAxis;
92
- };
93
- availableFeatures?: string[];
94
- featureNames?: {
95
- [tag: string]: string;
96
- };
97
- _buffer?: ArrayBuffer;
98
- }
99
- interface HarfBuzzModule {
100
- addFunction: (func: Function, signature: string) => number;
101
- exports: any;
102
- removeFunction: (ptr: number) => void;
103
- }
104
- interface VariationAxis {
105
- min: number;
106
- default: number;
107
- max: number;
108
- name?: string;
109
- }
110
- interface HarfBuzzAPI {
111
- createBlob: (data: Uint8Array) => HarfBuzzBlob;
112
- createFace: (blob: HarfBuzzBlob, index: number) => HarfBuzzFace;
113
- createFont: (face: HarfBuzzFace) => HarfBuzzFont;
114
- createBuffer: () => HarfBuzzBuffer;
115
- shape: (font: HarfBuzzFont, buffer: HarfBuzzBuffer, features?: string) => void;
116
- }
117
- interface HarfBuzzBlob {
118
- destroy: () => void;
119
- }
120
- interface HarfBuzzFace {
121
- destroy: () => void;
122
- getAxisInfos: () => {
123
- [tag: string]: VariationAxis;
124
- };
125
- }
126
- interface HarfBuzzFont {
127
- ptr: number;
128
- destroy: () => void;
129
- setScale: (xScale: number, yScale: number) => void;
130
- setVariations: (variations: {
131
- [key: string]: number;
132
- }) => void;
133
- }
134
- interface HarfBuzzBuffer {
135
- addText: (text: string) => void;
136
- guessSegmentProperties: () => void;
137
- setDirection: (direction: string) => void;
138
- json: (font: HarfBuzzFont) => any[];
139
- destroy: () => void;
140
- }
141
- interface HarfBuzzInstance {
142
- hb: HarfBuzzAPI;
143
- module: HarfBuzzModule;
144
- }
145
- interface ExtractedMetrics {
146
- isCFF: boolean;
147
- unitsPerEm: number;
148
- hheaAscender: number | null;
149
- hheaDescender: number | null;
150
- hheaLineGap: number | null;
151
- typoAscender: number | null;
152
- typoDescender: number | null;
153
- typoLineGap: number | null;
154
- winAscent: number | null;
155
- winDescent: number | null;
156
- axisNames: {
157
- [tag: string]: string;
158
- } | null;
159
- }
160
- interface FontMetrics {
161
- ascender: number;
162
- descender: number;
163
- lineGap: number;
164
- unitsPerEm: number;
165
- naturalLineHeight: number;
166
- }
167
- interface TextLayoutData {
168
- lines: LineInfo[];
169
- scaledLineHeight: number;
170
- letterSpacing: number;
171
- align: string;
172
- direction: TextDirection;
173
- depth: number;
174
- size: number;
175
- pixelsPerFontUnit: number;
176
- }
177
- interface TextLayoutResult {
178
- clustersByLine: GlyphCluster[][];
179
- layoutData: TextLayoutData;
180
- options: TextOptions;
181
- loadedFont: LoadedFont;
182
- fontId: string;
183
- }
184
- interface TextLayoutHandle extends TextLayoutResult {
185
- getLoadedFont(): LoadedFont | undefined;
186
- measureTextWidth(text: string, letterSpacing?: number): number;
187
- update(options: Partial<TextOptions>): Promise<TextLayoutHandle>;
188
- dispose(): void;
189
- }
190
- interface ColorByRange {
191
- start: number;
192
- end: number;
193
- color: [number, number, number];
194
- }
195
- interface ColorOptions {
196
- default?: [number, number, number];
197
- byText?: {
198
- [text: string]: [number, number, number];
19
+ interface HyphenationTrieNode {
20
+ patterns: number[] | null;
21
+ children: {
22
+ [char: string]: HyphenationTrieNode;
199
23
  };
200
- byCharRange?: ColorByRange[];
201
24
  }
202
- interface TextOptions {
203
- text: string;
204
- font: string | ArrayBuffer;
205
- size?: number;
206
- depth?: number;
207
- lineHeight?: number;
208
- letterSpacing?: number;
209
- perGlyphAttributes?: boolean;
210
- fontVariations?: {
211
- [key: string]: number;
25
+
26
+ interface SlugPackedTexture {
27
+ data: Float32Array | Uint32Array;
28
+ width: number;
29
+ height: number;
30
+ }
31
+ interface SlugGPUData {
32
+ curveTexture: SlugPackedTexture & {
33
+ data: Float32Array;
212
34
  };
213
- fontFeatures?: {
214
- [tag: string]: boolean | number;
35
+ bandTexture: SlugPackedTexture & {
36
+ data: Uint32Array;
215
37
  };
216
- maxTextLength?: number;
217
- removeOverlaps?: boolean;
218
- curveSteps?: number;
219
- curveFidelity?: CurveFidelityConfig;
220
- geometryOptimization?: GeometryOptimizationOptions;
221
- layout?: LayoutOptions;
222
- color?: [number, number, number] | ColorOptions;
223
- }
224
- interface HyphenationPatternsMap {
225
- [language: string]: HyphenationTrieNode;
226
- }
227
- interface CurveFidelityConfig {
228
- distanceTolerance?: number;
229
- angleTolerance?: number;
230
- cuspLimit?: number;
231
- collinearityEpsilon?: number;
232
- recursionLimit?: number;
233
- }
234
- interface GeometryOptimizationOptions {
235
- enabled?: boolean;
236
- areaThreshold?: number;
237
- }
238
- interface LayoutOptions {
239
- width?: number;
240
- align?: TextAlign;
241
- direction?: TextDirection;
242
- respectExistingBreaks?: boolean;
243
- hyphenate?: boolean;
244
- language?: string;
245
- patternsPath?: string;
246
- tolerance?: number;
247
- pretolerance?: number;
248
- emergencyStretch?: number;
249
- autoEmergencyStretch?: number;
250
- hyphenationPatterns?: HyphenationPatternsMap;
251
- lefthyphenmin?: number;
252
- righthyphenmin?: number;
253
- linepenalty?: number;
254
- adjdemerits?: number;
255
- hyphenpenalty?: number;
256
- exhyphenpenalty?: number;
257
- doublehyphendemerits?: number;
258
- }
259
-
260
- declare global {
261
- interface Window {
262
- hbjs?: any;
263
- createHarfBuzz?: () => Promise<any>;
264
- }
265
- }
266
- declare class Text$1 {
267
- private static patternCache;
268
- private static hbInitPromise;
269
- private static fontCache;
270
- private static fontLoadPromises;
271
- private static fontRefCounts;
272
- private static fontCacheMemoryBytes;
273
- private static maxFontCacheMemoryBytes;
274
- private static fontIdCounter;
275
- static enableWoff2(decoder: (data: ArrayBuffer | Uint8Array) => Uint8Array | Promise<Uint8Array>): void;
276
- private static stableStringify;
277
- private fontLoader;
278
- private loadedFont?;
279
- private currentFontId;
280
- private currentFontCacheKey?;
281
- private textShaper?;
282
- private textLayout?;
283
- private constructor();
284
- static setHarfBuzzPath(path: string): void;
285
- static setHarfBuzzBuffer(wasmBuffer: ArrayBuffer): void;
286
- static init(): Promise<HarfBuzzInstance>;
287
- static create(options: TextOptions): Promise<TextLayoutHandle>;
288
- private static retainFont;
289
- private static releaseFont;
290
- private static resolveFont;
291
- private static loadAndCacheFont;
292
- private static trackFontCacheAdd;
293
- private static trackFontCacheRemove;
294
- private static enforceFontCacheMemoryLimit;
295
- private static generateFontContentHash;
296
- private setLoadedFont;
297
- private releaseCurrentFont;
298
- private loadFont;
299
- private createLayout;
300
- private prepareHyphenation;
301
- private validateOptions;
302
- private updateFontVariations;
303
- private prepareLayout;
304
- getFontMetrics(): FontMetrics;
305
- static preloadPatterns(languages: string[], patternsPath?: string): Promise<void>;
306
- static registerPattern(language: string, pattern: HyphenationTrieNode): void;
307
- static setMaxFontCacheMemoryMB(limitMB: number): void;
308
- getLoadedFont(): LoadedFont | undefined;
309
- measureTextWidth(text: string, letterSpacing?: number): number;
310
- private resetHelpers;
311
- destroy(): void;
38
+ vertices: Float32Array;
39
+ indices: Uint16Array;
40
+ shapeCount: number;
312
41
  }
313
42
 
314
- interface QuadraticSegment {
315
- p0x: number;
316
- p0y: number;
317
- p1x: number;
318
- p1y: number;
319
- p2x: number;
320
- p2y: number;
321
- }
322
- interface ContourVertex {
323
- x: number;
324
- y: number;
325
- }
326
- interface VectorContour {
327
- vertices: ContourVertex[];
328
- segments: QuadraticSegment[];
329
- }
330
- interface VectorGlyphAttributes {
331
- glyphCenter: Float32Array;
332
- glyphIndex: Float32Array;
333
- glyphProgress: Float32Array;
334
- glyphLineIndex: Float32Array;
335
- glyphBaselineY: Float32Array;
336
- }
337
- interface GlyphRange {
338
- interiorIndexStart: number;
339
- interiorIndexCount: number;
340
- curveVertexStart: number;
341
- curveVertexCount: number;
342
- }
343
- interface VectorGeometryData {
344
- interiorPositions: Float32Array;
345
- interiorIndices: Uint32Array;
346
- curvePositions: Float32Array;
347
- fillPositions: Float32Array;
348
- fillIndices: Uint32Array;
349
- glyphRanges: GlyphRange[];
350
- interiorGlyphAttrs?: VectorGlyphAttributes;
351
- curveGlyphAttrs?: VectorGlyphAttributes;
352
- fillGlyphAttrs?: VectorGlyphAttributes;
353
- planeBounds: BoundingBox;
354
- stats: {
355
- glyphCount: number;
356
- contourCount: number;
357
- interiorTriangleCount: number;
358
- curveTriangleCount: number;
359
- };
360
- }
361
- interface LoopBlinnGlyphInput {
362
- offsetX: number;
363
- offsetY: number;
364
- segments: QuadraticSegment[];
365
- bounds: {
366
- minX: number;
367
- minY: number;
368
- maxX: number;
369
- maxY: number;
43
+ interface SlugGLSLMeshOptions {
44
+ color?: {
45
+ r: number;
46
+ g: number;
47
+ b: number;
370
48
  };
371
- lineIndex: number;
372
- baselineY: number;
373
- }
374
- interface LoopBlinnInput {
375
- glyphs: LoopBlinnGlyphInput[];
376
- planeBounds: BoundingBox;
49
+ animationDeclarations?: string;
50
+ animationBody?: string;
51
+ uniforms?: Record<string, THREE.IUniform>;
52
+ adaptiveSupersampling?: boolean;
53
+ }
54
+ interface SlugGLSLMesh {
55
+ mesh: THREE.Mesh;
56
+ uniforms: Record<string, THREE.IUniform>;
57
+ setOffset(x: number, y: number, z?: number): void;
58
+ setColor(r: number, g: number, b: number): void;
59
+ dispose(): void;
377
60
  }
378
- declare function extractContours(segments: QuadraticSegment[]): VectorContour[];
379
- declare function buildVectorGeometry(input: LoopBlinnInput): VectorGeometryData;
61
+ declare function createSlugGLSLMesh(gpuData: SlugGPUData, options?: SlugGLSLMeshOptions): SlugGLSLMesh;
380
62
 
381
63
  interface VectorTextResult {
64
+ group: THREE.Group;
65
+ mesh: THREE.Mesh;
66
+ gpuData: SlugGPUData;
382
67
  glyphs: VectorGlyphInfo[];
383
- geometryData: VectorGeometryData;
68
+ planeBounds: BoundingBox;
384
69
  query(options: TextQueryOptions): TextRange[];
385
- getLoadedFont(): LoadedFont$1 | undefined;
70
+ getLoadedFont(): LoadedFont | undefined;
386
71
  measureTextWidth(text: string, letterSpacing?: number): number;
387
- update(options: Partial<TextOptions$1>): Promise<VectorTextResult>;
388
- dispose(): void;
389
- }
390
-
391
- interface VectorMeshOptions {
392
- color?: THREE.ColorRepresentation;
393
- positionNode?: any;
394
- colorNode?: any;
395
- center?: boolean;
396
- }
397
- interface VectorMeshes {
398
- group: THREE.Group;
399
- interiorMesh: THREE.Object3D;
400
- curveMesh: THREE.Object3D;
401
- fillMesh: THREE.Mesh;
402
- interiorGeometry: THREE.BufferGeometry;
403
- curveGeometry: THREE.BufferGeometry;
404
- fillGeometry: THREE.BufferGeometry;
405
- setOffset(x: number, y: number, z?: number): void;
406
- updateMaterials(options?: VectorMeshOptions): void;
72
+ update(options: Partial<TextOptions>): Promise<VectorTextResult>;
407
73
  dispose(): void;
408
74
  }
409
- declare const loopBlinnFragment: any;
410
- declare function createVectorMeshes(data: VectorGeometryData, options?: VectorMeshOptions | THREE.ColorRepresentation): VectorMeshes;
411
-
412
- interface VectorTextOptions extends TextOptions$1 {
413
- color?: any;
414
- positionNode?: any;
415
- colorNode?: any;
416
- center?: boolean;
417
- }
418
- interface VectorResult extends VectorTextResult {
419
- group: THREE.Group;
420
- interiorGeometry: THREE.BufferGeometry;
421
- curveGeometry: THREE.BufferGeometry;
422
- fillGeometry: THREE.BufferGeometry;
423
- updateMaterials(options?: VectorMeshOptions): void;
424
- update(newOptions: Partial<VectorTextOptions>): Promise<VectorResult>;
425
- }
426
75
  declare class Text {
427
76
  static setHarfBuzzPath: typeof Text$1.setHarfBuzzPath;
428
77
  static setHarfBuzzBuffer: typeof Text$1.setHarfBuzzBuffer;
@@ -431,7 +80,7 @@ declare class Text {
431
80
  static preloadPatterns: typeof Text$1.preloadPatterns;
432
81
  static setMaxFontCacheMemoryMB: typeof Text$1.setMaxFontCacheMemoryMB;
433
82
  static enableWoff2: typeof Text$1.enableWoff2;
434
- static create(options: VectorTextOptions): Promise<VectorResult>;
83
+ static create(options: TextOptions): Promise<VectorTextResult>;
435
84
  }
436
85
 
437
- export { GlyphRange, HyphenationTrieNode, LoopBlinnGlyphInput, LoopBlinnInput, QuadraticSegment, Text, VectorContour, VectorGeometryData, VectorGlyphAttributes, VectorMeshOptions, VectorMeshes, VectorResult, VectorTextOptions, VectorTextResult, buildVectorGeometry, createVectorMeshes, extractContours, loopBlinnFragment };
86
+ export { HyphenationTrieNode, SlugGLSLMesh, SlugGLSLMeshOptions, SlugGPUData, Text, VectorTextResult as TextGeometryInfo, VectorTextResult, createSlugGLSLMesh };
@@ -1,223 +1,3 @@
1
- import { Text as Text$1 } from './core.js';
2
- import { createVectorMeshes } from './loopBlinnTSL.js';
3
- export { createVectorMeshes, loopBlinnFragment } from './loopBlinnTSL.js';
4
-
5
- const CONTOUR_EPSILON = 0.001;
6
- const CURVE_LINEARITY_EPSILON = 1e-5;
7
- function nearlyEqual(a, b, epsilon) {
8
- return Math.abs(a - b) < epsilon;
9
- }
10
- function extractContours(segments) {
11
- const contours = [];
12
- let contourVertices = [];
13
- let contourSegments = [];
14
- const pushCurrentContour = () => {
15
- if (contourVertices.length < 3) {
16
- contourVertices = [];
17
- contourSegments = [];
18
- return;
19
- }
20
- const first = contourVertices[0];
21
- const last = contourVertices[contourVertices.length - 1];
22
- if (nearlyEqual(first.x, last.x, CONTOUR_EPSILON) &&
23
- nearlyEqual(first.y, last.y, CONTOUR_EPSILON)) {
24
- contourVertices.pop();
25
- }
26
- if (contourVertices.length >= 3) {
27
- contours.push({
28
- vertices: contourVertices,
29
- segments: contourSegments
30
- });
31
- }
32
- contourVertices = [];
33
- contourSegments = [];
34
- };
35
- for (const segment of segments) {
36
- if (contourVertices.length === 0) {
37
- contourVertices.push({ x: segment.p0x, y: segment.p0y }, { x: segment.p2x, y: segment.p2y });
38
- contourSegments.push(segment);
39
- continue;
40
- }
41
- const previousEnd = contourVertices[contourVertices.length - 1];
42
- if (nearlyEqual(segment.p0x, previousEnd.x, CONTOUR_EPSILON) &&
43
- nearlyEqual(segment.p0y, previousEnd.y, CONTOUR_EPSILON)) {
44
- contourVertices.push({ x: segment.p2x, y: segment.p2y });
45
- contourSegments.push(segment);
46
- continue;
47
- }
48
- pushCurrentContour();
49
- contourVertices.push({ x: segment.p0x, y: segment.p0y }, { x: segment.p2x, y: segment.p2y });
50
- contourSegments.push(segment);
51
- }
52
- pushCurrentContour();
53
- return contours;
54
- }
55
- function triangulateContourFan(vertices, offsetX, offsetY, positions, indices) {
56
- const baseIndex = positions.length / 3;
57
- for (const vertex of vertices) {
58
- positions.push(vertex.x + offsetX, vertex.y + offsetY, 0);
59
- }
60
- if (vertices.length < 3)
61
- return 0;
62
- for (let index = 1; index < vertices.length - 1; index++) {
63
- indices.push(baseIndex, baseIndex + index, baseIndex + index + 1);
64
- }
65
- return vertices.length - 2;
66
- }
67
- function shouldSkipCurveSegment(segment) {
68
- const dx = segment.p2x - segment.p0x;
69
- const dy = segment.p2y - segment.p0y;
70
- const lenSq = dx * dx + dy * dy;
71
- if (lenSq <= 0)
72
- return true;
73
- const cross = (segment.p1x - segment.p0x) * dy - (segment.p1y - segment.p0y) * dx;
74
- return Math.abs(cross) < CURVE_LINEARITY_EPSILON * lenSq;
75
- }
76
- function fillGlyphAttrs(center, idx, progress, lineIdx, baselineY, vertCount, gc, gi, gp, gl, gb) {
77
- for (let v = 0; v < vertCount; v++) {
78
- gc.push(center[0], center[1], center[2]);
79
- gi.push(idx);
80
- gp.push(progress);
81
- gl.push(lineIdx);
82
- gb.push(baselineY);
83
- }
84
- }
85
- function packAttrs(gc, gi, gp, gl, gb) {
86
- return {
87
- glyphCenter: new Float32Array(gc),
88
- glyphIndex: new Float32Array(gi),
89
- glyphProgress: new Float32Array(gp),
90
- glyphLineIndex: new Float32Array(gl),
91
- glyphBaselineY: new Float32Array(gb)
92
- };
93
- }
94
- function buildVectorGeometry(input) {
95
- const interiorPositions = [];
96
- const interiorIndices = [];
97
- const curvePositions = [];
98
- const iGC = [], iGI = [], iGP = [], iGL = [], iGB = [];
99
- const cGC = [], cGI = [], cGP = [], cGL = [], cGB = [];
100
- const fGC = [], fGI = [], fGP = [], fGL = [], fGB = [];
101
- const glyphCount = input.glyphs.length;
102
- let contourCount = 0;
103
- let interiorTriangleCount = 0;
104
- let curveTriangleCount = 0;
105
- const glyphRanges = [];
106
- const fillPositions = new Float32Array(glyphCount * 12);
107
- const fillIndices = new Uint32Array(glyphCount * 6);
108
- for (let i = 0; i < glyphCount; i++) {
109
- const glyph = input.glyphs[i];
110
- const { minX, minY, maxX, maxY } = glyph.bounds;
111
- const cx = glyph.offsetX + (minX + maxX) * 0.5;
112
- const cy = glyph.offsetY + (minY + maxY) * 0.5;
113
- const center = [cx, cy, 0];
114
- const progress = glyphCount > 1 ? i / (glyphCount - 1) : 0;
115
- const intIdxStart = interiorIndices.length;
116
- const curveVertStart = curvePositions.length / 3;
117
- const contours = extractContours(glyph.segments);
118
- contourCount += contours.length;
119
- for (const contour of contours) {
120
- const intVertsBefore = interiorPositions.length / 3;
121
- interiorTriangleCount += triangulateContourFan(contour.vertices, glyph.offsetX, glyph.offsetY, interiorPositions, interiorIndices);
122
- const intVertsAfter = interiorPositions.length / 3;
123
- fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, intVertsAfter - intVertsBefore, iGC, iGI, iGP, iGL, iGB);
124
- for (const segment of contour.segments) {
125
- if (shouldSkipCurveSegment(segment))
126
- continue;
127
- curvePositions.push(glyph.offsetX + segment.p0x, glyph.offsetY + segment.p0y, 0, glyph.offsetX + segment.p1x, glyph.offsetY + segment.p1y, 0, glyph.offsetX + segment.p2x, glyph.offsetY + segment.p2y, 0);
128
- curveTriangleCount++;
129
- fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, 3, cGC, cGI, cGP, cGL, cGB);
130
- }
131
- }
132
- glyphRanges.push({
133
- interiorIndexStart: intIdxStart,
134
- interiorIndexCount: interiorIndices.length - intIdxStart,
135
- curveVertexStart: curveVertStart,
136
- curveVertexCount: (curvePositions.length / 3) - curveVertStart
137
- });
138
- const fp = i * 12;
139
- fillPositions[fp] = glyph.offsetX + minX;
140
- fillPositions[fp + 1] = glyph.offsetY + minY;
141
- fillPositions[fp + 2] = 0;
142
- fillPositions[fp + 3] = glyph.offsetX + maxX;
143
- fillPositions[fp + 4] = glyph.offsetY + minY;
144
- fillPositions[fp + 5] = 0;
145
- fillPositions[fp + 6] = glyph.offsetX + maxX;
146
- fillPositions[fp + 7] = glyph.offsetY + maxY;
147
- fillPositions[fp + 8] = 0;
148
- fillPositions[fp + 9] = glyph.offsetX + minX;
149
- fillPositions[fp + 10] = glyph.offsetY + maxY;
150
- fillPositions[fp + 11] = 0;
151
- fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, 4, fGC, fGI, fGP, fGL, fGB);
152
- const fi = i * 6;
153
- const fv = i * 4;
154
- fillIndices[fi] = fv;
155
- fillIndices[fi + 1] = fv + 1;
156
- fillIndices[fi + 2] = fv + 2;
157
- fillIndices[fi + 3] = fv;
158
- fillIndices[fi + 4] = fv + 2;
159
- fillIndices[fi + 5] = fv + 3;
160
- }
161
- return {
162
- interiorPositions: new Float32Array(interiorPositions),
163
- interiorIndices: new Uint32Array(interiorIndices),
164
- curvePositions: new Float32Array(curvePositions),
165
- fillPositions,
166
- fillIndices,
167
- glyphRanges,
168
- interiorGlyphAttrs: packAttrs(iGC, iGI, iGP, iGL, iGB),
169
- curveGlyphAttrs: packAttrs(cGC, cGI, cGP, cGL, cGB),
170
- fillGlyphAttrs: packAttrs(fGC, fGI, fGP, fGL, fGB),
171
- planeBounds: input.planeBounds,
172
- stats: {
173
- glyphCount,
174
- contourCount,
175
- interiorTriangleCount,
176
- curveTriangleCount
177
- }
178
- };
179
- }
180
-
181
- function wrapResult(coreResult, opts) {
182
- const meshes = createVectorMeshes(coreResult.geometryData, {
183
- color: opts.color,
184
- positionNode: opts.positionNode,
185
- colorNode: opts.colorNode,
186
- center: opts.center,
187
- });
188
- return {
189
- glyphs: coreResult.glyphs,
190
- geometryData: coreResult.geometryData,
191
- group: meshes.group,
192
- interiorGeometry: meshes.interiorGeometry,
193
- curveGeometry: meshes.curveGeometry,
194
- fillGeometry: meshes.fillGeometry,
195
- query: coreResult.query,
196
- getLoadedFont: coreResult.getLoadedFont,
197
- measureTextWidth: coreResult.measureTextWidth,
198
- updateMaterials: meshes.updateMaterials,
199
- async update(newOptions) {
200
- const newCore = await coreResult.update(newOptions);
201
- return wrapResult(newCore, { ...opts, ...newOptions });
202
- },
203
- dispose() {
204
- meshes.dispose();
205
- coreResult.dispose();
206
- }
207
- };
208
- }
209
- class Text {
210
- static { this.setHarfBuzzPath = Text$1.setHarfBuzzPath; }
211
- static { this.setHarfBuzzBuffer = Text$1.setHarfBuzzBuffer; }
212
- static { this.init = Text$1.init; }
213
- static { this.registerPattern = Text$1.registerPattern; }
214
- static { this.preloadPatterns = Text$1.preloadPatterns; }
215
- static { this.setMaxFontCacheMemoryMB = Text$1.setMaxFontCacheMemoryMB; }
216
- static { this.enableWoff2 = Text$1.enableWoff2; }
217
- static async create(options) {
218
- const coreResult = await Text$1.create(options);
219
- return wrapResult(coreResult, options);
220
- }
221
- }
222
-
223
- export { Text, buildVectorGeometry, extractContours };
1
+ import './core/index.js';
2
+ export { T as Text, c as createSlugGLSLMesh } from './index2.js';
3
+ import 'three';