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.
package/README.md CHANGED
@@ -395,7 +395,8 @@ The Knuth-Plass algorithm provides extensive control over line breaking quality:
395
395
  - **tolerance** (800): Maximum badness for the second pass with hyphenation
396
396
  - **emergencyStretch** (0): Additional stretchability for difficult paragraphs
397
397
  - **autoEmergencyStretch** (0.1): Emergency stretch as percentage of line width (e.g., 0.1 = 10%). Defaults to 10% for non-hyphenated text
398
- - **disableSingleWordDetection** (false): Disable automatic prevention of short single-word lines
398
+ - **disableShortLineDetection** (false): Disable automatic prevention of short lines
399
+ - **shortLineThreshold** (0.5): Width ratio threshold for short line detection (0.0 to 1.0)
399
400
 
400
401
  #### Advanced parameters
401
402
 
@@ -416,9 +417,9 @@ The Knuth-Plass algorithm provides extensive control over line breaking quality:
416
417
 
417
418
  Lower penalty/tolerance values produce tighter spacing but may fail to find acceptable breaks for challenging text
418
419
 
419
- #### Single-word line detection
420
+ #### Short line detection
420
421
 
421
- By default, the library detects and prevents short single-word lines (words occupying less than 50% of the line width on non-final lines) by iteratively applying emergency stretch. This can be disabled if needed:
422
+ By default, the library detects and prevents short lines (lines occupying less than 50% of the target width on non-final lines) by iteratively applying emergency stretch. This can be customized or disabled:
422
423
 
423
424
  ```javascript
424
425
  const text = await Text.create({
@@ -426,7 +427,9 @@ const text = await Text.create({
426
427
  font: '/fonts/Font.ttf',
427
428
  layout: {
428
429
  width: 1000,
429
- disableSingleWordDetection: true,
430
+ shortLineThreshold: 0.6, // Only flag lines < 60% width (more lenient)
431
+ // Or disable entirely:
432
+ // disableShortLineDetection: true,
430
433
  },
431
434
  });
432
435
  ```
@@ -672,11 +675,34 @@ Creates text geometry with automatic font loading and HarfBuzz initialization
672
675
  - `getCacheStatistics()` - Cache performance data
673
676
  - `clearCache()` - Clear the glyph cache
674
677
  - `measureTextWidth(text, letterSpacing?)` - Measure text width
678
+ - `update(options)` - Re-render with new options while preserving font/cache state
675
679
 
676
680
  **Three.js adapter (`three-text/three`) returns:**
677
681
  - `geometry: BufferGeometry` - Three.js geometry
678
682
  - Plus all the above except vertices/normals/indices/colors/glyphAttributes
679
683
 
684
+ ##### `update(options: Partial<TextOptions>): Promise<TextGeometryInfo>`
685
+
686
+ Returns new geometry with updated options. Font and glyph data are cached globally by default, so performance is similar to calling `Text.create()` again; the method is provided for ergonomics when working with the same font configuration across multiple renders
687
+
688
+ ```javascript
689
+ const text = await Text.create({
690
+ font: '/fonts/Font.ttf',
691
+ text: 'Hello',
692
+ size: 72
693
+ });
694
+
695
+ const mesh = new THREE.Mesh(text.geometry, material);
696
+ scene.add(mesh);
697
+
698
+ // Later, update the text
699
+ const updated = await text.update({ text: 'World' });
700
+ mesh.geometry.dispose();
701
+ mesh.geometry = updated.geometry;
702
+ ```
703
+
704
+ The method preserves custom cache instances if `maxCacheSizeMB` was specified. For most use cases, this is primarily an API convenience.
705
+
680
706
  ##### `Text.setHarfBuzzPath(path: string): void`
681
707
 
682
708
  **Required.** Sets the path for the HarfBuzz WASM binary. Must be called before `Text.create()`
@@ -754,9 +780,9 @@ interface LayoutOptions {
754
780
  pretolerance?: number; // Maximum badness for first pass (default: 100)
755
781
  emergencyStretch?: number; // Additional stretchability for difficult paragraphs
756
782
  autoEmergencyStretch?: number; // Emergency stretch as percentage of line width (defaults to 10% for non-hyphenated)
757
- disableSingleWordDetection?: boolean; // Disable automatic single-word line prevention (default: false)
758
- lefthyphenmin?: number; // Minimum character
759
- // s before hyphen (default: 2)
783
+ disableShortLineDetection?: boolean; // Disable automatic short line prevention (default: false)
784
+ shortLineThreshold?: number; // Width ratio threshold for short line detection (default: 0.5)
785
+ lefthyphenmin?: number; // Minimum characters before hyphen (default: 2)
760
786
  righthyphenmin?: number; // Minimum characters after hyphen (default: 4)
761
787
  linepenalty?: number; // Base penalty per line (default: 10)
762
788
  adjdemerits?: number; // Penalty for incompatible fitness classes (default: 10000)
@@ -940,9 +966,9 @@ While `three-text` runs on all modern browsers, performance varies significantly
940
966
 
941
967
  **Chrome** provides the best experience
942
968
 
943
- **Firefox** also delivers great performance but may exhibit less responsive mouse interactions in WebGL contexts due to the way it handles events
969
+ **Firefox** also delivers great performance but may exhibit less responsive mouse interactions
944
970
 
945
- **Safari** for macOS shows reduced performance, which is likely due to the platform's conservative resource management, particularly around battery life; 120FPS is not acheivable
971
+ **Safari** for macOS shows reduced performance, which is likely due to the platform's conservative resource management; 120FPS is not acheivable
946
972
 
947
973
  The library was also tested on a Brightsign 223HD, which took a long time to generate the initial geometry but seemed fine after that
948
974