three-text 0.2.8 → 0.2.10

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.
@@ -3,6 +3,41 @@ import { Text as Text$1 } from '../index.js';
3
3
 
4
4
  // Three.js adapter - wraps core text processing and returns BufferGeometry
5
5
  // This is a thin convenience layer for Three.js users
6
+ function convertToThree(result) {
7
+ // Create BufferGeometry from raw arrays
8
+ const geometry = new BufferGeometry();
9
+ geometry.setAttribute('position', new Float32BufferAttribute(result.vertices, 3));
10
+ geometry.setAttribute('normal', new Float32BufferAttribute(result.normals, 3));
11
+ geometry.setIndex(new Uint32BufferAttribute(result.indices, 1));
12
+ // Add optional color attribute (only if provided)
13
+ if (result.colors) {
14
+ geometry.setAttribute('color', new Float32BufferAttribute(result.colors, 3));
15
+ }
16
+ if (result.glyphAttributes) {
17
+ geometry.setAttribute('glyphCenter', new Float32BufferAttribute(result.glyphAttributes.glyphCenter, 3));
18
+ geometry.setAttribute('glyphIndex', new Float32BufferAttribute(result.glyphAttributes.glyphIndex, 1));
19
+ geometry.setAttribute('glyphLineIndex', new Float32BufferAttribute(result.glyphAttributes.glyphLineIndex, 1));
20
+ }
21
+ geometry.computeBoundingBox();
22
+ // Return Three.js specific interface with utility methods
23
+ return {
24
+ geometry,
25
+ glyphs: result.glyphs,
26
+ planeBounds: result.planeBounds,
27
+ stats: result.stats,
28
+ query: result.query,
29
+ coloredRanges: result.coloredRanges,
30
+ // Pass through utility methods from core
31
+ getLoadedFont: result.getLoadedFont,
32
+ getCacheStatistics: result.getCacheStatistics,
33
+ clearCache: result.clearCache,
34
+ measureTextWidth: result.measureTextWidth,
35
+ update: async (newOptions) => {
36
+ const newCoreResult = await result.update(newOptions);
37
+ return convertToThree(newCoreResult);
38
+ }
39
+ };
40
+ }
6
41
  class Text {
7
42
  // Delegate static methods to core
8
43
  static { this.setHarfBuzzPath = Text$1.setHarfBuzzPath; }
@@ -13,35 +48,7 @@ class Text {
13
48
  // Main API - wraps core result in BufferGeometry
14
49
  static async create(options) {
15
50
  const coreResult = await Text$1.create(options);
16
- // Create BufferGeometry from raw arrays
17
- const geometry = new BufferGeometry();
18
- geometry.setAttribute('position', new Float32BufferAttribute(coreResult.vertices, 3));
19
- geometry.setAttribute('normal', new Float32BufferAttribute(coreResult.normals, 3));
20
- geometry.setIndex(new Uint32BufferAttribute(coreResult.indices, 1));
21
- // Add optional color attribute (only if provided)
22
- if (coreResult.colors) {
23
- geometry.setAttribute('color', new Float32BufferAttribute(coreResult.colors, 3));
24
- }
25
- if (coreResult.glyphAttributes) {
26
- geometry.setAttribute('glyphCenter', new Float32BufferAttribute(coreResult.glyphAttributes.glyphCenter, 3));
27
- geometry.setAttribute('glyphIndex', new Float32BufferAttribute(coreResult.glyphAttributes.glyphIndex, 1));
28
- geometry.setAttribute('glyphLineIndex', new Float32BufferAttribute(coreResult.glyphAttributes.glyphLineIndex, 1));
29
- }
30
- geometry.computeBoundingBox();
31
- // Return Three.js specific interface with utility methods
32
- return {
33
- geometry,
34
- glyphs: coreResult.glyphs,
35
- planeBounds: coreResult.planeBounds,
36
- stats: coreResult.stats,
37
- query: coreResult.query,
38
- coloredRanges: coreResult.coloredRanges,
39
- // Pass through utility methods from core
40
- getLoadedFont: coreResult.getLoadedFont,
41
- getCacheStatistics: coreResult.getCacheStatistics,
42
- clearCache: coreResult.clearCache,
43
- measureTextWidth: coreResult.measureTextWidth
44
- };
51
+ return convertToThree(coreResult);
45
52
  }
46
53
  }
47
54
 
@@ -310,7 +310,12 @@ declare class Text$1 {
310
310
  static setHarfBuzzPath(path: string): void;
311
311
  static setHarfBuzzBuffer(wasmBuffer: ArrayBuffer): void;
312
312
  static init(): Promise<HarfBuzzInstance>;
313
- static create(options: TextOptions): Promise<TextGeometryInfo & Pick<Text$1, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'>>;
313
+ static create(options: TextOptions): Promise<TextGeometryInfo & Pick<Text$1, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'> & {
314
+ update: (options: Partial<TextOptions>) => Promise<TextGeometryInfo & Pick<Text$1, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'> & {
315
+ update: (options: Partial<TextOptions>) => Promise<any>;
316
+ }>;
317
+ }>;
318
+ private static resolveFont;
314
319
  private static loadAndCacheFont;
315
320
  private static generateFontContentHash;
316
321
  private setLoadedFont;
@@ -330,6 +335,7 @@ declare class Text$1 {
330
335
  getCacheStatistics(): GlyphCacheStats | null;
331
336
  clearCache(): void;
332
337
  private createGlyphAttributes;
338
+ private resetHelpers;
333
339
  destroy(): void;
334
340
  }
335
341
 
@@ -21,7 +21,12 @@ export declare class Text {
21
21
  static setHarfBuzzPath(path: string): void;
22
22
  static setHarfBuzzBuffer(wasmBuffer: ArrayBuffer): void;
23
23
  static init(): Promise<HarfBuzzInstance>;
24
- static create(options: TextOptions): Promise<TextGeometryInfo & Pick<Text, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'>>;
24
+ static create(options: TextOptions): Promise<TextGeometryInfo & Pick<Text, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'> & {
25
+ update: (options: Partial<TextOptions>) => Promise<TextGeometryInfo & Pick<Text, 'getLoadedFont' | 'getCacheStatistics' | 'clearCache' | 'measureTextWidth'> & {
26
+ update: (options: Partial<TextOptions>) => Promise<any>;
27
+ }>;
28
+ }>;
29
+ private static resolveFont;
25
30
  private static loadAndCacheFont;
26
31
  private static generateFontContentHash;
27
32
  private setLoadedFont;
@@ -41,5 +46,6 @@ export declare class Text {
41
46
  getCacheStatistics(): import("./cache/GlyphCache").GlyphCacheStats | null;
42
47
  clearCache(): void;
43
48
  private createGlyphAttributes;
49
+ private resetHelpers;
44
50
  destroy(): void;
45
51
  }
@@ -1,6 +1,6 @@
1
1
  export declare const FITNESS_TIGHT_THRESHOLD = 12;
2
2
  export declare const FITNESS_NORMAL_THRESHOLD = 99;
3
- export declare const DEFAULT_TOLERANCE = 200;
3
+ export declare const DEFAULT_TOLERANCE = 800;
4
4
  export declare const DEFAULT_PRETOLERANCE = 100;
5
5
  export declare const DEFAULT_EMERGENCY_STRETCH = 0;
6
6
  export declare const SPACE_STRETCH_RATIO = 0.5;
@@ -8,6 +8,7 @@ export interface ThreeTextGeometryInfo extends Omit<CoreTextGeometryInfo, 'verti
8
8
  getCacheStatistics(): any;
9
9
  clearCache(): void;
10
10
  measureTextWidth(text: string, letterSpacing?: number): number;
11
+ update(options: Partial<TextOptions>): Promise<ThreeTextGeometryInfo>;
11
12
  }
12
13
  export declare class Text {
13
14
  static setHarfBuzzPath: typeof TextCore.setHarfBuzzPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-text",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "3D font rendering and text layout engine for the web",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",