Initial project import
This commit is contained in:
24
node_modules/@react-three/drei/core/useFont.js
generated
vendored
Normal file
24
node_modules/@react-three/drei/core/useFont.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { FontLoader } from 'three-stdlib';
|
||||
import { suspend, preload, clear } from 'suspend-react';
|
||||
|
||||
let fontLoader = null;
|
||||
async function loadFontData(font) {
|
||||
return typeof font === 'string' ? await (await fetch(font)).json() : font;
|
||||
}
|
||||
function parseFontData(fontData) {
|
||||
if (!fontLoader) {
|
||||
fontLoader = new FontLoader();
|
||||
}
|
||||
return fontLoader.parse(fontData);
|
||||
}
|
||||
async function loader(font) {
|
||||
const data = await loadFontData(font);
|
||||
return parseFontData(data);
|
||||
}
|
||||
function useFont(font) {
|
||||
return suspend(loader, [font]);
|
||||
}
|
||||
useFont.preload = font => preload(loader, [font]);
|
||||
useFont.clear = font => clear([font]);
|
||||
|
||||
export { useFont };
|
||||
Reference in New Issue
Block a user