three-text 0.2.13 → 0.2.14
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 +3 -3
- package/dist/index.cjs +792 -677
- package/dist/index.d.ts +88 -76
- package/dist/index.js +792 -678
- package/dist/index.min.cjs +861 -2
- package/dist/index.min.js +860 -2
- package/dist/index.umd.js +792 -677
- package/dist/index.umd.min.js +862 -2
- package/dist/three/react.cjs +44 -20
- package/dist/three/react.d.ts +36 -24
- package/dist/three/react.js +45 -21
- package/dist/types/core/Text.d.ts +14 -7
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +12 -5
- package/dist/types/core/cache/sharedCaches.d.ts +12 -0
- package/dist/types/core/font/TableDirectory.d.ts +7 -0
- package/dist/types/core/font/constants.d.ts +0 -1
- package/dist/types/core/geometry/Extruder.d.ts +3 -6
- package/dist/types/core/layout/LineBreak.d.ts +2 -0
- package/dist/types/core/shaping/DrawCallbacks.d.ts +2 -0
- package/dist/types/core/shaping/TextShaper.d.ts +4 -1
- package/dist/types/core/types.d.ts +26 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/three/ThreeText.d.ts +3 -3
- package/dist/types/utils/LRUCache.d.ts +2 -2
- package/dist/types/webgpu/index.d.ts +1 -2
- package/dist/webgpu/index.cjs +3 -4
- package/dist/webgpu/index.d.ts +1 -2
- package/dist/webgpu/index.js +3 -4
- package/package.json +1 -1
- package/dist/types/core/cache/GlyphCache.d.ts +0 -50
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
set(x: number, y: number, z: number): Vec3;
|
|
7
|
-
clone(): Vec3;
|
|
8
|
-
copy(v: Vec3): Vec3;
|
|
9
|
-
add(v: Vec3): Vec3;
|
|
10
|
-
sub(v: Vec3): Vec3;
|
|
11
|
-
multiply(scalar: number): Vec3;
|
|
12
|
-
divide(scalar: number): Vec3;
|
|
13
|
-
length(): number;
|
|
14
|
-
lengthSq(): number;
|
|
15
|
-
normalize(): Vec3;
|
|
16
|
-
dot(v: Vec3): number;
|
|
17
|
-
cross(v: Vec3): Vec3;
|
|
18
|
-
distanceTo(v: Vec3): number;
|
|
19
|
-
distanceToSquared(v: Vec3): number;
|
|
20
|
-
equals(v: Vec3): boolean;
|
|
1
|
+
interface HyphenationTrieNode {
|
|
2
|
+
patterns: number[] | null;
|
|
3
|
+
children: {
|
|
4
|
+
[char: string]: HyphenationTrieNode;
|
|
5
|
+
};
|
|
21
6
|
}
|
|
7
|
+
|
|
22
8
|
interface BoundingBox {
|
|
23
9
|
min: {
|
|
24
10
|
x: number;
|
|
@@ -32,13 +18,6 @@ interface BoundingBox {
|
|
|
32
18
|
};
|
|
33
19
|
}
|
|
34
20
|
|
|
35
|
-
interface HyphenationTrieNode {
|
|
36
|
-
patterns: number[] | null;
|
|
37
|
-
children: {
|
|
38
|
-
[char: string]: HyphenationTrieNode;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
21
|
type TextAlign = 'left' | 'center' | 'right' | 'justify';
|
|
43
22
|
type TextDirection = 'ltr' | 'rtl';
|
|
44
23
|
interface LineInfo {
|
|
@@ -156,6 +135,25 @@ interface ProcessedGeometry {
|
|
|
156
135
|
triangles: Triangles;
|
|
157
136
|
contours: number[][];
|
|
158
137
|
}
|
|
138
|
+
interface GlyphData {
|
|
139
|
+
geometry: ProcessedGeometry;
|
|
140
|
+
vertices: Float32Array;
|
|
141
|
+
normals: Float32Array;
|
|
142
|
+
indices: Uint32Array;
|
|
143
|
+
bounds: {
|
|
144
|
+
min: {
|
|
145
|
+
x: number;
|
|
146
|
+
y: number;
|
|
147
|
+
z: number;
|
|
148
|
+
};
|
|
149
|
+
max: {
|
|
150
|
+
x: number;
|
|
151
|
+
y: number;
|
|
152
|
+
z: number;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
useCount: number;
|
|
156
|
+
}
|
|
159
157
|
interface PathInfo {
|
|
160
158
|
start: number;
|
|
161
159
|
count: number;
|
|
@@ -227,6 +225,13 @@ interface TextGeometryInfo {
|
|
|
227
225
|
query(options: TextQueryOptions): TextRange[];
|
|
228
226
|
coloredRanges?: ColoredRange[];
|
|
229
227
|
}
|
|
228
|
+
interface TextHandle extends TextGeometryInfo {
|
|
229
|
+
getLoadedFont(): LoadedFont | undefined;
|
|
230
|
+
getCacheStatistics(): any;
|
|
231
|
+
clearCache(): void;
|
|
232
|
+
measureTextWidth(text: string, letterSpacing?: number): number;
|
|
233
|
+
update(options: Partial<TextOptions>): Promise<TextHandle>;
|
|
234
|
+
}
|
|
230
235
|
interface ColorByRange {
|
|
231
236
|
start: number;
|
|
232
237
|
end: number;
|
|
@@ -319,48 +324,6 @@ interface LayoutOptions {
|
|
|
319
324
|
shortLineThreshold?: number;
|
|
320
325
|
}
|
|
321
326
|
|
|
322
|
-
interface GlyphData {
|
|
323
|
-
geometry: ProcessedGeometry;
|
|
324
|
-
vertices: Float32Array;
|
|
325
|
-
normals: Float32Array;
|
|
326
|
-
indices: Uint16Array | Uint32Array;
|
|
327
|
-
bounds: {
|
|
328
|
-
min: Vec3;
|
|
329
|
-
max: Vec3;
|
|
330
|
-
};
|
|
331
|
-
useCount: number;
|
|
332
|
-
}
|
|
333
|
-
interface GlyphCacheStats {
|
|
334
|
-
hits: number;
|
|
335
|
-
misses: number;
|
|
336
|
-
totalGlyphs: number;
|
|
337
|
-
uniqueGlyphs: number;
|
|
338
|
-
cacheSize: number;
|
|
339
|
-
saved: number;
|
|
340
|
-
memoryUsage: number;
|
|
341
|
-
}
|
|
342
|
-
declare class GlyphCache {
|
|
343
|
-
private cache;
|
|
344
|
-
private head;
|
|
345
|
-
private tail;
|
|
346
|
-
private stats;
|
|
347
|
-
private maxCacheSize?;
|
|
348
|
-
constructor(maxCacheSizeMB?: number);
|
|
349
|
-
private getCacheKey;
|
|
350
|
-
has(fontId: string, glyphId: number, depth: number, removeOverlaps: boolean): boolean;
|
|
351
|
-
get(fontId: string, glyphId: number, depth: number, removeOverlaps: boolean): GlyphData | undefined;
|
|
352
|
-
set(fontId: string, glyphId: number, depth: number, removeOverlaps: boolean, glyph: GlyphData): void;
|
|
353
|
-
private calculateMemoryUsage;
|
|
354
|
-
private evictLRU;
|
|
355
|
-
private addToHead;
|
|
356
|
-
private removeNode;
|
|
357
|
-
private removeTail;
|
|
358
|
-
private moveToHead;
|
|
359
|
-
clear(): void;
|
|
360
|
-
getStats(): GlyphCacheStats;
|
|
361
|
-
}
|
|
362
|
-
declare const globalGlyphCache: GlyphCache;
|
|
363
|
-
|
|
364
327
|
declare global {
|
|
365
328
|
interface Window {
|
|
366
329
|
hbjs?: any;
|
|
@@ -371,7 +334,10 @@ declare class Text {
|
|
|
371
334
|
private static patternCache;
|
|
372
335
|
private static hbInitPromise;
|
|
373
336
|
private static fontCache;
|
|
337
|
+
private static fontCacheMemoryBytes;
|
|
338
|
+
private static maxFontCacheMemoryBytes;
|
|
374
339
|
private static fontIdCounter;
|
|
340
|
+
private static stableStringify;
|
|
375
341
|
private fontLoader;
|
|
376
342
|
private loadedFont?;
|
|
377
343
|
private currentFontId;
|
|
@@ -382,13 +348,12 @@ declare class Text {
|
|
|
382
348
|
static setHarfBuzzPath(path: string): void;
|
|
383
349
|
static setHarfBuzzBuffer(wasmBuffer: ArrayBuffer): void;
|
|
384
350
|
static init(): Promise<HarfBuzzInstance>;
|
|
385
|
-
static create(options: TextOptions): Promise<
|
|
386
|
-
update: (options: Partial<TextOptions>) => Promise<TextGeometryInfo & Pick<Text, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'> & {
|
|
387
|
-
update: (options: Partial<TextOptions>) => Promise<any>;
|
|
388
|
-
}>;
|
|
389
|
-
}>;
|
|
351
|
+
static create(options: TextOptions): Promise<TextHandle>;
|
|
390
352
|
private static resolveFont;
|
|
391
353
|
private static loadAndCacheFont;
|
|
354
|
+
private static trackFontCacheAdd;
|
|
355
|
+
private static trackFontCacheRemove;
|
|
356
|
+
private static enforceFontCacheMemoryLimit;
|
|
392
357
|
private static generateFontContentHash;
|
|
393
358
|
private setLoadedFont;
|
|
394
359
|
private loadFont;
|
|
@@ -402,9 +367,14 @@ declare class Text {
|
|
|
402
367
|
getFontMetrics(): FontMetrics;
|
|
403
368
|
static preloadPatterns(languages: string[], patternsPath?: string): Promise<void>;
|
|
404
369
|
static registerPattern(language: string, pattern: HyphenationTrieNode): void;
|
|
370
|
+
static clearFontCache(): void;
|
|
371
|
+
static setMaxFontCacheMemoryMB(limitMB: number): void;
|
|
405
372
|
getLoadedFont(): LoadedFont | undefined;
|
|
406
373
|
measureTextWidth(text: string, letterSpacing?: number): number;
|
|
407
|
-
getCacheStatistics():
|
|
374
|
+
getCacheStatistics(): (CacheStats & {
|
|
375
|
+
hitRate: number;
|
|
376
|
+
memoryUsageMB: number;
|
|
377
|
+
}) | null;
|
|
408
378
|
clearCache(): void;
|
|
409
379
|
private createGlyphAttributes;
|
|
410
380
|
private resetHelpers;
|
|
@@ -466,4 +436,46 @@ declare class FontMetadataExtractor {
|
|
|
466
436
|
static getFontMetrics(metrics: ExtractedMetrics): FontMetrics;
|
|
467
437
|
}
|
|
468
438
|
|
|
469
|
-
|
|
439
|
+
interface LRUCacheOptions<K, V> {
|
|
440
|
+
maxEntries?: number;
|
|
441
|
+
maxMemoryBytes?: number;
|
|
442
|
+
calculateSize?: (value: V) => number;
|
|
443
|
+
onEvict?: (key: K, value: V) => void;
|
|
444
|
+
}
|
|
445
|
+
interface CacheStats {
|
|
446
|
+
hits: number;
|
|
447
|
+
misses: number;
|
|
448
|
+
evictions: number;
|
|
449
|
+
size: number;
|
|
450
|
+
memoryUsage: number;
|
|
451
|
+
}
|
|
452
|
+
declare class LRUCache<K, V> {
|
|
453
|
+
private cache;
|
|
454
|
+
private head;
|
|
455
|
+
private tail;
|
|
456
|
+
private stats;
|
|
457
|
+
private options;
|
|
458
|
+
constructor(options?: LRUCacheOptions<K, V>);
|
|
459
|
+
get(key: K): V | undefined;
|
|
460
|
+
has(key: K): boolean;
|
|
461
|
+
set(key: K, value: V): void;
|
|
462
|
+
delete(key: K): boolean;
|
|
463
|
+
clear(): void;
|
|
464
|
+
getStats(): CacheStats & {
|
|
465
|
+
hitRate: number;
|
|
466
|
+
memoryUsageMB: number;
|
|
467
|
+
};
|
|
468
|
+
keys(): K[];
|
|
469
|
+
get size(): number;
|
|
470
|
+
private evictIfNeeded;
|
|
471
|
+
private evictTail;
|
|
472
|
+
private addToHead;
|
|
473
|
+
private removeNode;
|
|
474
|
+
private removeTail;
|
|
475
|
+
private moveToHead;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
declare const globalGlyphCache: LRUCache<string, GlyphData>;
|
|
479
|
+
declare function createGlyphCache(maxCacheSizeMB?: number): LRUCache<string, GlyphData>;
|
|
480
|
+
|
|
481
|
+
export { CacheStats, ColorByRange, ColorOptions, ColoredRange, CurveFidelityConfig, DEFAULT_CURVE_FIDELITY, ExtractedMetrics, FontMetadataExtractor, FontMetrics, GeometryOptimizationOptions, GlyphData, GlyphGeometryInfo, HarfBuzzAPI, HarfBuzzBlob, HarfBuzzBuffer, HarfBuzzFace, HarfBuzzFont, HarfBuzzInstance, HarfBuzzModule, HyphenationPatternsMap, HyphenationTrieNode, LayoutOptions, LineInfo, LoadedFont, PathInfo, ProcessedGeometry, Text, TextAlign, TextDirection, TextGeometryInfo, TextHandle, TextOptions, TextQueryOptions, TextRange, Triangles, VariationAxis, VerticalMetrics, createGlyphCache, globalGlyphCache };
|