@react-three/drei 9.116.3 → 9.117.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/core/Text3D.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import * as THREE from 'three';
3
3
  import { MeshProps, Node } from '@react-three/fiber';
4
4
  import { TextGeometryParameters } from 'three-stdlib';
5
- import { FontData } from './useFont';
5
+ import { useFont } from './useFont';
6
6
  import { ForwardRefComponent } from '../helpers/ts-utils';
7
7
  declare global {
8
8
  namespace JSX {
@@ -12,7 +12,7 @@ declare global {
12
12
  }
13
13
  }
14
14
  type Text3DProps = {
15
- font: FontData | string;
15
+ font: Parameters<typeof useFont>[0];
16
16
  bevelSegments?: number;
17
17
  smooth?: number;
18
18
  } & Omit<TextGeometryParameters, 'font'> & MeshProps;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three-stdlib"),r=require("suspend-react");let t=null;async function n(r){const n=await async function(e){return"string"==typeof e?await(await fetch(e)).json():e}(r);return a=n,t||(t=new e.FontLoader),t.parse(a);var a}function a(e){return r.suspend(n,[e])}a.preload=e=>r.preload(n,[e]),a.clear=e=>r.clear([e]),exports.useFont=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three-stdlib"),r=require("suspend-react");let n=null,t=null;async function a(r){if("string"==typeof r){var n;const u=await fetch(r);if(null!=(n=u.headers.get("Content-Type"))&&n.includes("application/json"))return await u.json();{const r=await u.arrayBuffer();return a=r,t||(t=new e.TTFLoader),t.parse(a)}}return r;var a}async function u(r){return function(r){return n||(n=new e.FontLoader),n.parse(r)}(await a(r))}function s(e){return r.suspend(u,[e])}s.preload=e=>r.preload(u,[e]),s.clear=e=>r.clear([e]),exports.useFont=s;
package/core/useFont.js CHANGED
@@ -1,19 +1,37 @@
1
- import { FontLoader } from 'three-stdlib';
1
+ import { FontLoader, TTFLoader } from 'three-stdlib';
2
2
  import { suspend, preload, clear } from 'suspend-react';
3
3
 
4
4
  let fontLoader = null;
5
- async function loadFontData(font) {
6
- return typeof font === 'string' ? await (await fetch(font)).json() : font;
7
- }
5
+ let ttfLoader = null;
8
6
  function parseFontData(fontData) {
9
7
  if (!fontLoader) {
10
8
  fontLoader = new FontLoader();
11
9
  }
12
10
  return fontLoader.parse(fontData);
13
11
  }
12
+ function parseTtfArrayBuffer(ttfData) {
13
+ if (!ttfLoader) {
14
+ ttfLoader = new TTFLoader();
15
+ }
16
+ return ttfLoader.parse(ttfData);
17
+ }
18
+ async function loadFontData(font) {
19
+ if (typeof font === 'string') {
20
+ var _res$headers$get;
21
+ const res = await fetch(font);
22
+ if ((_res$headers$get = res.headers.get('Content-Type')) != null && _res$headers$get.includes('application/json')) {
23
+ return await res.json();
24
+ } else {
25
+ const arrayBuffer = await res.arrayBuffer();
26
+ return parseTtfArrayBuffer(arrayBuffer);
27
+ }
28
+ } else {
29
+ return font;
30
+ }
31
+ }
14
32
  async function loader(font) {
15
- const data = await loadFontData(font);
16
- return parseFontData(data);
33
+ const fontData = await loadFontData(font);
34
+ return parseFontData(fontData);
17
35
  }
18
36
  function useFont(font) {
19
37
  return suspend(loader, [font]);