three-text 0.2.7 → 0.2.9

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
 
@@ -275,7 +275,8 @@ interface LayoutOptions {
275
275
  exhyphenpenalty?: number;
276
276
  doublehyphendemerits?: number;
277
277
  looseness?: number;
278
- disableSingleWordDetection?: boolean;
278
+ disableShortLineDetection?: boolean;
279
+ shortLineThreshold?: number;
279
280
  }
280
281
 
281
282
  interface GlyphCacheStats {
@@ -309,7 +310,12 @@ declare class Text$1 {
309
310
  static setHarfBuzzPath(path: string): void;
310
311
  static setHarfBuzzBuffer(wasmBuffer: ArrayBuffer): void;
311
312
  static init(): Promise<HarfBuzzInstance>;
312
- 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;
313
319
  private static loadAndCacheFont;
314
320
  private static generateFontContentHash;
315
321
  private setLoadedFont;
@@ -329,6 +335,7 @@ declare class Text$1 {
329
335
  getCacheStatistics(): GlyphCacheStats | null;
330
336
  clearCache(): void;
331
337
  private createGlyphAttributes;
338
+ private resetHelpers;
332
339
  destroy(): void;
333
340
  }
334
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
  }
@@ -62,7 +62,8 @@ export interface LineBreakOptions {
62
62
  exhyphenpenalty?: number;
63
63
  doublehyphendemerits?: number;
64
64
  looseness?: number;
65
- disableSingleWordDetection?: boolean;
65
+ disableShortLineDetection?: boolean;
66
+ shortLineThreshold?: number;
66
67
  }
67
68
  interface LineBreakContext {
68
69
  linePenalty: number;
@@ -78,8 +79,14 @@ export declare class LineBreak {
78
79
  static findHyphenationPoints(word: string, language?: string, availablePatterns?: HyphenationPatternsMap, lefthyphenmin?: number, righthyphenmin?: number): number[];
79
80
  static itemizeText(text: string, measureText: (text: string) => number, // function to measure text width
80
81
  hyphenate?: boolean, language?: string, availablePatterns?: HyphenationPatternsMap, lefthyphenmin?: number, righthyphenmin?: number, context?: LineBreakContext): Item[];
82
+ static isCJK(char: string): boolean;
83
+ static isCJClosingPunctuation(char: string): boolean;
84
+ static isCJOpeningPunctuation(char: string): boolean;
85
+ static isCJPunctuation(char: string): boolean;
86
+ private static itemizeCJKText;
81
87
  private static itemizeParagraph;
82
- private static hasSingleWordLines;
88
+ private static itemizeWordBased;
89
+ private static hasShortLines;
83
90
  static breakText(options: LineBreakOptions): LineInfo[];
84
91
  private static findBreakpoints;
85
92
  private static considerBreak;
@@ -29,6 +29,7 @@ export declare class TextShaper {
29
29
  shapeLines(lineInfos: LineInfo[], scaledLineHeight: number, letterSpacing: number, align: string, direction: TextDirection, color?: [number, number, number] | ColorOptions, originalText?: string): GlyphCluster[][];
30
30
  private shapeLineIntoClusters;
31
31
  private calculateSpaceAdjustment;
32
+ private calculateCJKAdjustment;
32
33
  clearCache(): void;
33
34
  getCacheStats(): import("../..").GlyphCacheStats;
34
35
  }
@@ -322,5 +322,6 @@ export interface LayoutOptions {
322
322
  exhyphenpenalty?: number;
323
323
  doublehyphendemerits?: number;
324
324
  looseness?: number;
325
- disableSingleWordDetection?: boolean;
325
+ disableShortLineDetection?: boolean;
326
+ shortLineThreshold?: number;
326
327
  }
@@ -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;
@@ -13,7 +13,6 @@ declare class PerformanceLogger {
13
13
  printSummary(): void;
14
14
  printBaseline(): void;
15
15
  clear(): void;
16
- reset(): void;
17
16
  time<T>(name: string, fn: () => T, metadata?: Record<string, any>): T;
18
17
  timeAsync<T>(name: string, fn: () => Promise<T>, metadata?: Record<string, any>): Promise<T>;
19
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-text",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
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",