visual-song 0.20.2 → 0.20.3
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/dist/index.js +15 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,6 +2,13 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { forwardRef, useState, useRef, useEffect, createContext, useContext, useCallback, useImperativeHandle } from 'react';
|
|
3
3
|
import VSModule from './wasm_src/visualsong-core.js';
|
|
4
4
|
|
|
5
|
+
const WASM_CDN_BASE_URL = "https://unpkg.com/visual-song@20.0.3/dist/wasm_src";
|
|
6
|
+
const locateWasmFile = (path, scriptDirectory)=>{
|
|
7
|
+
if (path === "visualsong-core.wasm") {
|
|
8
|
+
return `${WASM_CDN_BASE_URL}/${path}`;
|
|
9
|
+
}
|
|
10
|
+
return `${scriptDirectory}${path}`;
|
|
11
|
+
};
|
|
5
12
|
const _generateUID = ()=>{
|
|
6
13
|
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
7
14
|
};
|
|
@@ -47,7 +54,9 @@ function VisualSongProvider({ children }) {
|
|
|
47
54
|
const VSEngineRef = useRef(null);
|
|
48
55
|
useEffect(()=>{
|
|
49
56
|
let mounted = true;
|
|
50
|
-
VSModule(
|
|
57
|
+
VSModule({
|
|
58
|
+
locateFile: locateWasmFile
|
|
59
|
+
}).then((m)=>{
|
|
51
60
|
if (!mounted) return;
|
|
52
61
|
VSEngineRef.current = m;
|
|
53
62
|
setVSEngine(m);
|
|
@@ -224,7 +233,7 @@ const VisualSong = /*#__PURE__*/ forwardRef(function VisualSong({ style, backgro
|
|
|
224
233
|
playerRef.current.setVertexCount(count);
|
|
225
234
|
},
|
|
226
235
|
getLastCompileError () {
|
|
227
|
-
if (!playerRef.current || !isInitialized.current) return
|
|
236
|
+
if (!playerRef.current || !isInitialized.current) return "";
|
|
228
237
|
return playerRef.current.getLastCompileError();
|
|
229
238
|
},
|
|
230
239
|
updateLayout () {
|
|
@@ -301,7 +310,7 @@ const VisualSong = /*#__PURE__*/ forwardRef(function VisualSong({ style, backgro
|
|
|
301
310
|
]);
|
|
302
311
|
useEffect(()=>{
|
|
303
312
|
if (!module.current || !playerRef.current) return;
|
|
304
|
-
if (typeof vertexShader ===
|
|
313
|
+
if (typeof vertexShader === "string") {
|
|
305
314
|
playerRef.current.setVertexShader(vertexShader);
|
|
306
315
|
}
|
|
307
316
|
}, [
|
|
@@ -309,7 +318,7 @@ const VisualSong = /*#__PURE__*/ forwardRef(function VisualSong({ style, backgro
|
|
|
309
318
|
]);
|
|
310
319
|
useEffect(()=>{
|
|
311
320
|
if (!module.current || !playerRef.current) return;
|
|
312
|
-
if (typeof primitiveMode ===
|
|
321
|
+
if (typeof primitiveMode === "number") {
|
|
313
322
|
playerRef.current.setPrimitiveMode(primitiveMode);
|
|
314
323
|
}
|
|
315
324
|
}, [
|
|
@@ -317,7 +326,7 @@ const VisualSong = /*#__PURE__*/ forwardRef(function VisualSong({ style, backgro
|
|
|
317
326
|
]);
|
|
318
327
|
useEffect(()=>{
|
|
319
328
|
if (!module.current || !playerRef.current) return;
|
|
320
|
-
if (typeof vertexCount ===
|
|
329
|
+
if (typeof vertexCount === "number") {
|
|
321
330
|
playerRef.current.setVertexCount(vertexCount);
|
|
322
331
|
}
|
|
323
332
|
}, [
|
|
@@ -425,7 +434,7 @@ const VisualSong = /*#__PURE__*/ forwardRef(function VisualSong({ style, backgro
|
|
|
425
434
|
renderer.destroyPlayer(playerRef.current);
|
|
426
435
|
}
|
|
427
436
|
} catch (e) {
|
|
428
|
-
console.error(
|
|
437
|
+
console.error("[VisualSong] Error destroying player:", e);
|
|
429
438
|
}
|
|
430
439
|
}
|
|
431
440
|
playerRef.current = null;
|