three-text 0.5.0 → 0.5.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 +15 -16
- package/dist/index.cjs +66 -20
- package/dist/index.d.ts +6 -0
- package/dist/index.js +66 -20
- package/dist/index.min.cjs +310 -307
- package/dist/index.min.js +265 -262
- package/dist/index.umd.js +68 -21
- package/dist/index.umd.min.js +268 -265
- package/dist/three/index.cjs +2 -1
- package/dist/three/index.d.ts +1 -0
- package/dist/three/index.js +2 -1
- package/dist/three/react.cjs +35 -17
- package/dist/three/react.d.ts +6 -0
- package/dist/three/react.js +35 -17
- package/dist/types/core/Text.d.ts +6 -0
- package/dist/types/three/index.d.ts +1 -0
- package/dist/types/vector/core.d.ts +27 -0
- package/dist/types/vector/index.d.ts +30 -24
- package/dist/types/vector/loopBlinnTSL.d.ts +14 -3
- package/dist/types/vector/react.d.ts +4 -6
- package/dist/vector/all.cjs +21 -0
- package/dist/vector/all.d.ts +134 -0
- package/dist/vector/all.js +2 -0
- package/dist/vector/core.cjs +1310 -0
- package/dist/vector/core.d.ts +112 -0
- package/dist/vector/core.js +1306 -0
- package/dist/vector/index.cjs +41 -1265
- package/dist/vector/index.d.ts +335 -20
- package/dist/vector/index.js +28 -1239
- package/dist/vector/loopBlinnTSL.cjs +229 -0
- package/dist/vector/loopBlinnTSL.d.ts +69 -0
- package/dist/vector/loopBlinnTSL.js +207 -0
- package/dist/vector/react.cjs +45 -60
- package/dist/vector/react.d.ts +9 -3
- package/dist/vector/react.js +46 -42
- package/dist/vector/webgl/index.cjs +3 -1
- package/dist/vector/webgl/index.js +3 -1
- package/package.json +1 -1
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VectorGlyphInfo, TextQueryOptions, TextRange, LoadedFont, TextOptions } from '../core/types';
|
|
1
|
+
import { VectorGlyphInfo, TextQueryOptions, TextRange, LoadedFont as LoadedFont$1, TextOptions as TextOptions$1 } from '../core/types';
|
|
3
2
|
export { LoadedFont, TextOptions, VectorGlyphInfo } from '../core/types';
|
|
4
3
|
import * as THREE from 'three';
|
|
5
4
|
|
|
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
|
+
}
|
|
6
33
|
interface BoundingBox {
|
|
7
34
|
min: {
|
|
8
35
|
x: number;
|
|
@@ -16,6 +43,274 @@ interface BoundingBox {
|
|
|
16
43
|
};
|
|
17
44
|
}
|
|
18
45
|
|
|
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];
|
|
199
|
+
};
|
|
200
|
+
byCharRange?: ColorByRange[];
|
|
201
|
+
}
|
|
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;
|
|
212
|
+
};
|
|
213
|
+
fontFeatures?: {
|
|
214
|
+
[tag: string]: boolean | number;
|
|
215
|
+
};
|
|
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;
|
|
312
|
+
}
|
|
313
|
+
|
|
19
314
|
interface QuadraticSegment {
|
|
20
315
|
p0x: number;
|
|
21
316
|
p0y: number;
|
|
@@ -83,30 +378,50 @@ interface LoopBlinnInput {
|
|
|
83
378
|
declare function extractContours(segments: QuadraticSegment[]): VectorContour[];
|
|
84
379
|
declare function buildVectorGeometry(input: LoopBlinnInput): VectorGeometryData;
|
|
85
380
|
|
|
86
|
-
interface
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
381
|
+
interface VectorTextResult {
|
|
382
|
+
glyphs: VectorGlyphInfo[];
|
|
383
|
+
geometryData: VectorGeometryData;
|
|
384
|
+
query(options: TextQueryOptions): TextRange[];
|
|
385
|
+
getLoadedFont(): LoadedFont$1 | undefined;
|
|
386
|
+
measureTextWidth(text: string, letterSpacing?: number): number;
|
|
387
|
+
update(options: Partial<TextOptions$1>): Promise<VectorTextResult>;
|
|
388
|
+
dispose(): void;
|
|
91
389
|
}
|
|
92
390
|
|
|
391
|
+
interface VectorMeshOptions {
|
|
392
|
+
color?: THREE.ColorRepresentation;
|
|
393
|
+
positionNode?: any;
|
|
394
|
+
colorNode?: any;
|
|
395
|
+
center?: boolean;
|
|
396
|
+
}
|
|
93
397
|
interface VectorMeshes {
|
|
94
|
-
|
|
95
|
-
|
|
398
|
+
group: THREE.Group;
|
|
399
|
+
interiorMesh: THREE.Object3D;
|
|
400
|
+
curveMesh: THREE.Object3D;
|
|
96
401
|
fillMesh: THREE.Mesh;
|
|
402
|
+
interiorGeometry: THREE.BufferGeometry;
|
|
403
|
+
curveGeometry: THREE.BufferGeometry;
|
|
404
|
+
fillGeometry: THREE.BufferGeometry;
|
|
97
405
|
setOffset(x: number, y: number, z?: number): void;
|
|
406
|
+
updateMaterials(options?: VectorMeshOptions): void;
|
|
98
407
|
dispose(): void;
|
|
99
408
|
}
|
|
100
|
-
declare
|
|
409
|
+
declare const loopBlinnFragment: any;
|
|
410
|
+
declare function createVectorMeshes(data: VectorGeometryData, options?: VectorMeshOptions | THREE.ColorRepresentation): VectorMeshes;
|
|
101
411
|
|
|
102
|
-
interface
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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>;
|
|
110
425
|
}
|
|
111
426
|
declare class Text {
|
|
112
427
|
static setHarfBuzzPath: typeof Text$1.setHarfBuzzPath;
|
|
@@ -116,7 +431,7 @@ declare class Text {
|
|
|
116
431
|
static preloadPatterns: typeof Text$1.preloadPatterns;
|
|
117
432
|
static setMaxFontCacheMemoryMB: typeof Text$1.setMaxFontCacheMemoryMB;
|
|
118
433
|
static enableWoff2: typeof Text$1.enableWoff2;
|
|
119
|
-
static create(options:
|
|
434
|
+
static create(options: VectorTextOptions): Promise<VectorResult>;
|
|
120
435
|
}
|
|
121
436
|
|
|
122
|
-
export { GlyphRange, HyphenationTrieNode, LoopBlinnGlyphInput, LoopBlinnInput, QuadraticSegment, Text,
|
|
437
|
+
export { GlyphRange, HyphenationTrieNode, LoopBlinnGlyphInput, LoopBlinnInput, QuadraticSegment, Text, VectorContour, VectorGeometryData, VectorGlyphAttributes, VectorMeshOptions, VectorMeshes, VectorResult, VectorTextOptions, VectorTextResult, buildVectorGeometry, createVectorMeshes, extractContours, loopBlinnFragment };
|