three-text 0.2.18 → 0.3.0
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 +14 -10
- package/dist/index.cjs +215 -350
- package/dist/index.d.ts +27 -50
- package/dist/index.js +215 -350
- package/dist/index.min.cjs +704 -723
- package/dist/index.min.js +705 -724
- package/dist/index.umd.js +215 -350
- package/dist/index.umd.min.js +710 -729
- package/dist/three/index.cjs +4 -1
- package/dist/three/index.d.ts +2 -1
- package/dist/three/index.js +4 -1
- package/dist/three/react.cjs +2 -1
- package/dist/three/react.d.ts +15 -17
- package/dist/three/react.js +2 -1
- package/dist/types/core/Text.d.ts +1 -5
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +4 -7
- package/dist/types/core/cache/sharedCaches.d.ts +6 -7
- package/dist/types/core/geometry/Extruder.d.ts +0 -1
- package/dist/types/core/shaping/TextShaper.d.ts +1 -4
- package/dist/types/core/types.d.ts +10 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/three/index.d.ts +2 -1
- package/dist/types/three/react.d.ts +1 -0
- package/dist/types/utils/Cache.d.ts +14 -0
- package/dist/types/webgl/index.d.ts +12 -0
- package/dist/types/webgpu/index.d.ts +10 -0
- package/dist/webgl/index.cjs +18 -0
- package/dist/webgl/index.d.ts +12 -0
- package/dist/webgl/index.js +18 -0
- package/dist/webgpu/index.cjs +80 -1
- package/dist/webgpu/index.d.ts +10 -0
- package/dist/webgpu/index.js +80 -1
- package/package.json +22 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://www.gnu.org/licenses/agpl-3.0)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
High fidelity 3D mesh font geometry and text layout engine for the web
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|
|
|
@@ -15,11 +15,7 @@ A high fidelity 3D font renderer and text layout engine for the web
|
|
|
15
15
|
> [!CAUTION]
|
|
16
16
|
> three-text is an alpha release and the API may break rapidly. This warning will last at least through the end of 2025. If API stability is important to you, consider pinning your version. Community feedback is encouraged; please open an issue if you have any suggestions or feedback, thank you
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
text: `three-text is a 3D font geometry and text layout library for the web. Its supports TTF, OTF, and WOFF font files. For layout, it uses Tex-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates. The library has a framework-agnostic core that returns raw vertex data, with lightweight adapters for Three.js, React Three Fiber, p5.js, WebGL and WebGPU. Under the hood, three-text relies on HarfBuzz for text shaping, Knuth-Plass line breaking, Liang hyphenation, libtess by Eric Veach for tessellation, curve polygonization from Maxim Shemanarev's Anti-Grain Geometry, and Visvalingam-Whyatt line simplification`,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
**three-text** is a 3D font geometry and text layout library for the web. It supports TTF, OTF, and WOFF font files. For layout, it uses [TeX](https://en.wikipedia.org/wiki/TeX)-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates
|
|
18
|
+
**three-text** is a 3D mesh font geometry and text layout library for the web. It supports TTF, OTF, and WOFF font files. For layout, it uses [TeX](https://en.wikipedia.org/wiki/TeX)-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates
|
|
23
19
|
|
|
24
20
|
The library has a framework-agnostic core that returns raw vertex data, with lightweight adapters for [Three.js](https://threejs.org), [React Three Fiber](https://docs.pmnd.rs/react-three-fiber), [p5.js](https://p5js.org), [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API), and [WebGPU](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API)
|
|
25
21
|
|
|
@@ -556,7 +552,7 @@ const text = await Text.create({
|
|
|
556
552
|
|
|
557
553
|
Values can be boolean (`true`/`false`) to enable or disable, or numeric for features accepting variant indices. Explicitly disabling a feature overrides the font's defaults
|
|
558
554
|
|
|
559
|
-
Common tags include [`liga`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#liga) (ligatures),
|
|
555
|
+
Common tags include [`liga`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#liga) (ligatures), [`calt`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#calt) (contextual alternates), [`tnum`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#tnum) (tabular numbers), sylistic alternates [`ss01`-`ss20`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#ss01--ss20) and character variants [`cv01`-`cv99`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#cv01--cv99). Feature availability depends on the font
|
|
560
556
|
|
|
561
557
|
### Per-glyph attributes
|
|
562
558
|
|
|
@@ -566,13 +562,15 @@ For shader-based animations and interactive effects, the library can generate pe
|
|
|
566
562
|
const text = await Text.create({
|
|
567
563
|
text: 'Sample text',
|
|
568
564
|
font: '/fonts/Font.ttf',
|
|
569
|
-
|
|
565
|
+
perGlyphAttributes: true,
|
|
570
566
|
});
|
|
571
567
|
|
|
572
568
|
// Geometry includes these vertex attributes:
|
|
573
569
|
// - glyphCenter (vec3): center point of each glyph
|
|
574
570
|
// - glyphIndex (float): sequential glyph index
|
|
575
571
|
// - glyphLineIndex (float): line number
|
|
572
|
+
// - glyphProgress (float): normalized position (0..1) along text run
|
|
573
|
+
// - glyphBaselineY (float): Y coordinate of glyph baseline
|
|
576
574
|
```
|
|
577
575
|
|
|
578
576
|
This option bypasses overlap-based clustering and adds vertex attributes suitable for per-character manipulation in vertex shaders. Each unique glyph is still tessellated only once and cached for reuse. The tradeoff is potential visual artifacts where glyphs actually overlap (tight kerning, cursive scripts)
|
|
@@ -736,6 +734,10 @@ Initializes HarfBuzz WebAssembly. Called automatically by `create()`, but can be
|
|
|
736
734
|
|
|
737
735
|
Preloads hyphenation patterns for specified languages. Useful for avoiding async pattern loading during text rendering
|
|
738
736
|
|
|
737
|
+
##### `Text.setMaxFontCacheMemoryMB(limitMB: number): void`
|
|
738
|
+
|
|
739
|
+
Sets an upper bound for the font cache, measured by the raw font buffer size, eviction is FIFO by insertion order
|
|
740
|
+
|
|
739
741
|
#### Instance Methods
|
|
740
742
|
|
|
741
743
|
The following methods are available on instances created by `Text.create()`:
|
|
@@ -753,7 +755,7 @@ Below are the most important configuration interfaces. For a complete list of al
|
|
|
753
755
|
```typescript
|
|
754
756
|
interface TextOptions {
|
|
755
757
|
text: string; // Text content to render
|
|
756
|
-
font
|
|
758
|
+
font: string | ArrayBuffer; // Font file path or buffer (TTF, OTF, or WOFF)
|
|
757
759
|
size?: number; // Font size in scene units (default: 72)
|
|
758
760
|
depth?: number; // Extrusion depth (default: 0)
|
|
759
761
|
lineHeight?: number; // Line height multiplier (default: 1.0)
|
|
@@ -761,7 +763,7 @@ interface TextOptions {
|
|
|
761
763
|
fontVariations?: { [key: string]: number }; // Variable font axis settings
|
|
762
764
|
fontFeatures?: { [tag: string]: boolean | number }; // OpenType feature settings
|
|
763
765
|
removeOverlaps?: boolean; // Override default overlap removal (auto-enabled for VF only)
|
|
764
|
-
|
|
766
|
+
perGlyphAttributes?: boolean; // Keep per-glyph identity and add per-glyph shader attributes
|
|
765
767
|
color?: [number, number, number] | ColorOptions; // Text coloring (simple or complex)
|
|
766
768
|
// Configuration for geometry generation and layout
|
|
767
769
|
curveFidelity?: CurveFidelityConfig;
|
|
@@ -842,6 +844,8 @@ interface TextGeometryInfo {
|
|
|
842
844
|
glyphCenter: Float32Array;
|
|
843
845
|
glyphIndex: Float32Array;
|
|
844
846
|
glyphLineIndex: Float32Array;
|
|
847
|
+
glyphProgress: Float32Array;
|
|
848
|
+
glyphBaselineY: Float32Array;
|
|
845
849
|
};
|
|
846
850
|
glyphs: GlyphGeometryInfo[];
|
|
847
851
|
planeBounds: {
|