three-text 0.4.6 → 0.4.7

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
@@ -63,14 +63,15 @@ npm install three
63
63
 
64
64
  three-text has a framework-agnostic core that processes fonts and generates geometry data. Lightweight adapters convert this data to framework-specific formats:
65
65
 
66
- - **`three-text`** - Core (returns raw arrays)
67
- - **`three-text/three`** - Three.js (returns BufferGeometry)
66
+ - **`three-text`** - Three.js adapter (default export, returns BufferGeometry)
67
+ - **`three-text/three`** - Same as above (explicit alias)
68
68
  - **`three-text/three/react`** - React Three Fiber component
69
+ - **`three-text/core`** - Framework-agnostic core (returns raw arrays)
69
70
  - **`three-text/webgl`** - WebGL buffer utility
70
71
  - **`three-text/webgpu`** - WebGPU buffer utility
71
72
  - **`three-text/p5`** - p5.js adapter
72
73
 
73
- Choose the import that matches your stack. Most users will use `three-text/three` or `three-text/p5`
74
+ Most users will just `import { Text } from 'three-text'` for Three.js projects
74
75
 
75
76
  ### Basic Usage
76
77
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.4.6
2
+ * three-text v0.4.7
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -1997,7 +1997,7 @@ class WoffConverter {
1997
1997
  logger.log('WOFF font decompressed successfully');
1998
1998
  return sfntData.buffer.slice(0, sfntOffset);
1999
1999
  }
2000
- static decompressWoff2(woff2Buffer) {
2000
+ static async decompressWoff2(woff2Buffer) {
2001
2001
  const view = new DataView(woff2Buffer);
2002
2002
  const signature = view.getUint32(0);
2003
2003
  if (signature !== FONT_SIGNATURE_WOFF2) {
@@ -2008,7 +2008,7 @@ class WoffConverter {
2008
2008
  " import { decode } from 'woff2-decode';\n" +
2009
2009
  ' Text.enableWoff2(decode);');
2010
2010
  }
2011
- const decoded = woff2Decoder(woff2Buffer);
2011
+ const decoded = await woff2Decoder(woff2Buffer);
2012
2012
  logger.log('WOFF2 font decompressed successfully');
2013
2013
  return decoded.buffer;
2014
2014
  }
@@ -2043,7 +2043,7 @@ class FontLoader {
2043
2043
  }
2044
2044
  else if (format === 'woff2') {
2045
2045
  logger.log('WOFF2 font detected, decompressing...');
2046
- fontBuffer = WoffConverter.decompressWoff2(fontBuffer);
2046
+ fontBuffer = await WoffConverter.decompressWoff2(fontBuffer);
2047
2047
  }
2048
2048
  const view = new DataView(fontBuffer);
2049
2049
  const sfntVersion = view.getUint32(0);
package/dist/index.d.ts CHANGED
@@ -352,7 +352,7 @@ declare class Text {
352
352
  private static fontCacheMemoryBytes;
353
353
  private static maxFontCacheMemoryBytes;
354
354
  private static fontIdCounter;
355
- static enableWoff2(decoder: (data: ArrayBuffer | Uint8Array) => Uint8Array): void;
355
+ static enableWoff2(decoder: (data: ArrayBuffer | Uint8Array) => Uint8Array | Promise<Uint8Array>): void;
356
356
  private static stableStringify;
357
357
  private fontLoader;
358
358
  private loadedFont?;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.4.6
2
+ * three-text v0.4.7
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -1994,7 +1994,7 @@ class WoffConverter {
1994
1994
  logger.log('WOFF font decompressed successfully');
1995
1995
  return sfntData.buffer.slice(0, sfntOffset);
1996
1996
  }
1997
- static decompressWoff2(woff2Buffer) {
1997
+ static async decompressWoff2(woff2Buffer) {
1998
1998
  const view = new DataView(woff2Buffer);
1999
1999
  const signature = view.getUint32(0);
2000
2000
  if (signature !== FONT_SIGNATURE_WOFF2) {
@@ -2005,7 +2005,7 @@ class WoffConverter {
2005
2005
  " import { decode } from 'woff2-decode';\n" +
2006
2006
  ' Text.enableWoff2(decode);');
2007
2007
  }
2008
- const decoded = woff2Decoder(woff2Buffer);
2008
+ const decoded = await woff2Decoder(woff2Buffer);
2009
2009
  logger.log('WOFF2 font decompressed successfully');
2010
2010
  return decoded.buffer;
2011
2011
  }
@@ -2040,7 +2040,7 @@ class FontLoader {
2040
2040
  }
2041
2041
  else if (format === 'woff2') {
2042
2042
  logger.log('WOFF2 font detected, decompressing...');
2043
- fontBuffer = WoffConverter.decompressWoff2(fontBuffer);
2043
+ fontBuffer = await WoffConverter.decompressWoff2(fontBuffer);
2044
2044
  }
2045
2045
  const view = new DataView(fontBuffer);
2046
2046
  const sfntVersion = view.getUint32(0);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.4.6
2
+ * three-text v0.4.7
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -306,12 +306,12 @@ const e=i.subarray(t.offset,t.offset+t.length),n=await q.Ue(e)
306
306
  if(n.byteLength!==t.Be)throw Error(`Decompression failed: expected ${t.Be} bytes, got ${n.byteLength}`)
307
307
  return new Uint8Array(n)}))
308
308
  for(let t=0;s>t;t++){const e=l[t],i=12+16*t
309
- a.setUint32(i,e.tag),a.setUint32(i+4,e.t),a.setUint32(i+8,c),a.setUint32(i+12,e.Be),o.set(u[t],c),c+=e.Be,c+=(4-e.Be%4)%4}return o.buffer.slice(0,c)}static Ne(t){if(new DataView(t).getUint32(0)!==C)throw Error("Not a valid WOFF2 font")
309
+ a.setUint32(i,e.tag),a.setUint32(i+4,e.t),a.setUint32(i+8,c),a.setUint32(i+12,e.Be),o.set(u[t],c),c+=e.Be,c+=(4-e.Be%4)%4}return o.buffer.slice(0,c)}static async Ne(t){if(new DataView(t).getUint32(0)!==C)throw Error("Not a valid WOFF2 font")
310
310
  if(!V)throw Error("WOFF2 fonts require enabling the decoder. Add to your code:\n import { decode } from 'woff2-decode';\n Text.enableWoff2(decode);")
311
- return V(t).buffer}static async Ue(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"))
311
+ return(await V(t)).buffer}static async Ue(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"))
312
312
  return new Response(e).arrayBuffer()}}class Y{constructor(t){this.$e=t}async Pe(t,e){if(!t||12>t.byteLength)throw Error("Invalid font buffer: too small to be a valid font file")
313
313
  const i=q.ke(t)
314
- "woff"===i?t=await q.De(t):"woff2"===i&&(t=q.Ne(t))
314
+ "woff"===i?t=await q.De(t):"woff2"===i&&(t=await q.Ne(t))
315
315
  const n=new DataView(t).getUint32(0)
316
316
  if(![L,G].includes(n))throw Error("Invalid font format. Expected TTF/OTF/WOFF/WOFF2, got signature: 0x"+n.toString(16))
317
317
  const{hb:s,module:r}=await this.$e()
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.4.6
2
+ * three-text v0.4.7
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -305,12 +305,12 @@ const e=i.subarray(t.offset,t.offset+t.length),n=await q.Ne(e)
305
305
  if(n.byteLength!==t.Be)throw Error(`Decompression failed: expected ${t.Be} bytes, got ${n.byteLength}`)
306
306
  return new Uint8Array(n)}))
307
307
  for(let t=0;s>t;t++){const e=l[t],i=12+16*t
308
- a.setUint32(i,e.tag),a.setUint32(i+4,e.t),a.setUint32(i+8,c),a.setUint32(i+12,e.Be),o.set(u[t],c),c+=e.Be,c+=(4-e.Be%4)%4}return o.buffer.slice(0,c)}static Ue(t){if(new DataView(t).getUint32(0)!==C)throw Error("Not a valid WOFF2 font")
308
+ a.setUint32(i,e.tag),a.setUint32(i+4,e.t),a.setUint32(i+8,c),a.setUint32(i+12,e.Be),o.set(u[t],c),c+=e.Be,c+=(4-e.Be%4)%4}return o.buffer.slice(0,c)}static async Ue(t){if(new DataView(t).getUint32(0)!==C)throw Error("Not a valid WOFF2 font")
309
309
  if(!V)throw Error("WOFF2 fonts require enabling the decoder. Add to your code:\n import { decode } from 'woff2-decode';\n Text.enableWoff2(decode);")
310
- return V(t).buffer}static async Ne(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"))
310
+ return(await V(t)).buffer}static async Ne(t){const e=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream("deflate"))
311
311
  return new Response(e).arrayBuffer()}}class Y{constructor(t){this.$e=t}async Pe(t,e){if(!t||12>t.byteLength)throw Error("Invalid font buffer: too small to be a valid font file")
312
312
  const i=q.ke(t)
313
- "woff"===i?t=await q.De(t):"woff2"===i&&(t=q.Ue(t))
313
+ "woff"===i?t=await q.De(t):"woff2"===i&&(t=await q.Ue(t))
314
314
  const n=new DataView(t).getUint32(0)
315
315
  if(![L,G].includes(n))throw Error("Invalid font format. Expected TTF/OTF/WOFF/WOFF2, got signature: 0x"+n.toString(16))
316
316
  const{hb:s,module:r}=await this.$e()
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.4.6
2
+ * three-text v0.4.7
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -1999,7 +1999,7 @@
1999
1999
  logger.log('WOFF font decompressed successfully');
2000
2000
  return sfntData.buffer.slice(0, sfntOffset);
2001
2001
  }
2002
- static decompressWoff2(woff2Buffer) {
2002
+ static async decompressWoff2(woff2Buffer) {
2003
2003
  const view = new DataView(woff2Buffer);
2004
2004
  const signature = view.getUint32(0);
2005
2005
  if (signature !== FONT_SIGNATURE_WOFF2) {
@@ -2010,7 +2010,7 @@
2010
2010
  " import { decode } from 'woff2-decode';\n" +
2011
2011
  ' Text.enableWoff2(decode);');
2012
2012
  }
2013
- const decoded = woff2Decoder(woff2Buffer);
2013
+ const decoded = await woff2Decoder(woff2Buffer);
2014
2014
  logger.log('WOFF2 font decompressed successfully');
2015
2015
  return decoded.buffer;
2016
2016
  }
@@ -2045,7 +2045,7 @@
2045
2045
  }
2046
2046
  else if (format === 'woff2') {
2047
2047
  logger.log('WOFF2 font detected, decompressing...');
2048
- fontBuffer = WoffConverter.decompressWoff2(fontBuffer);
2048
+ fontBuffer = await WoffConverter.decompressWoff2(fontBuffer);
2049
2049
  }
2050
2050
  const view = new DataView(fontBuffer);
2051
2051
  const sfntVersion = view.getUint32(0);