@react-three/fiber 10.0.0-canary.604355a → 10.0.0-canary.6d6e5ab
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.cjs +844 -1423
- package/dist/index.d.cts +291 -811
- package/dist/index.d.mts +291 -811
- package/dist/index.d.ts +291 -811
- package/dist/index.mjs +820 -1397
- package/dist/legacy.cjs +799 -1384
- package/dist/legacy.d.cts +292 -811
- package/dist/legacy.d.mts +292 -811
- package/dist/legacy.d.ts +292 -811
- package/dist/legacy.mjs +774 -1357
- package/dist/webgpu/index.cjs +1300 -1738
- package/dist/webgpu/index.d.cts +407 -825
- package/dist/webgpu/index.d.mts +407 -825
- package/dist/webgpu/index.d.ts +407 -825
- package/dist/webgpu/index.mjs +1270 -1710
- package/package.json +4 -3
- package/readme.md +2 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as webgpu from 'three/webgpu';
|
|
2
|
-
import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene,
|
|
3
|
-
import { WebGLRenderTarget, WebGLRenderer } from 'three';
|
|
2
|
+
import { CubeRenderTarget, RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer } from 'three/webgpu';
|
|
3
|
+
import { WebGLCubeRenderTarget, WebGLRenderTarget, WebGLRenderer } from 'three';
|
|
4
4
|
import { Inspector } from 'three/addons/inspector/Inspector.js';
|
|
5
5
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
6
6
|
import * as React from 'react';
|
|
@@ -13,8 +13,10 @@ import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
|
|
|
13
13
|
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
14
14
|
import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
15
15
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
16
|
-
import Tb, {
|
|
16
|
+
import Tb, { unstable_getCurrentPriorityLevel, unstable_IdlePriority, unstable_LowPriority, unstable_NormalPriority, unstable_UserBlockingPriority, unstable_ImmediatePriority, unstable_scheduleCallback } from 'scheduler';
|
|
17
17
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
18
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
19
|
+
export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
18
20
|
import { suspend, preload, clear } from 'suspend-react';
|
|
19
21
|
|
|
20
22
|
function _mergeNamespaces(n, m) {
|
|
@@ -34,10 +36,13 @@ const R3F_BUILD_WEBGPU = true;
|
|
|
34
36
|
|
|
35
37
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
36
38
|
__proto__: null,
|
|
39
|
+
CubeRenderTarget: CubeRenderTarget,
|
|
40
|
+
CubeRenderTargetCompat: CubeRenderTarget,
|
|
37
41
|
Inspector: Inspector,
|
|
38
42
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
39
43
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
40
44
|
RenderTargetCompat: RenderTarget,
|
|
45
|
+
WebGLCubeRenderTarget: WebGLCubeRenderTarget,
|
|
41
46
|
WebGLRenderTarget: WebGLRenderTarget,
|
|
42
47
|
WebGLRenderer: WebGLRenderer
|
|
43
48
|
}, [webgpu]);
|
|
@@ -139,7 +144,7 @@ function useEnvironment({
|
|
|
139
144
|
useLoader$1.clear(loader, multiFile ? [files] : files);
|
|
140
145
|
}
|
|
141
146
|
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
142
|
-
}, [files, renderer.domElement]);
|
|
147
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
143
148
|
const loaderResult = useLoader$1(
|
|
144
149
|
loader,
|
|
145
150
|
multiFile ? [files] : files,
|
|
@@ -311,15 +316,16 @@ function EnvironmentPortal({
|
|
|
311
316
|
preset = void 0,
|
|
312
317
|
extensions
|
|
313
318
|
}) {
|
|
314
|
-
const
|
|
319
|
+
const renderer = useThree$1((state) => state.renderer);
|
|
320
|
+
const isLegacy = useThree$1((state) => state.isLegacy);
|
|
315
321
|
const defaultScene = useThree$1((state) => state.scene);
|
|
316
322
|
const camera = React.useRef(null);
|
|
317
323
|
const [virtualScene] = React.useState(() => new Scene());
|
|
318
324
|
const fbo = React.useMemo(() => {
|
|
319
|
-
const fbo2 = new WebGLCubeRenderTarget(resolution);
|
|
325
|
+
const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
|
|
320
326
|
fbo2.texture.type = HalfFloatType;
|
|
321
327
|
return fbo2;
|
|
322
|
-
}, [resolution]);
|
|
328
|
+
}, [resolution, isLegacy]);
|
|
323
329
|
React.useEffect(() => {
|
|
324
330
|
return () => {
|
|
325
331
|
fbo.dispose();
|
|
@@ -327,10 +333,10 @@ function EnvironmentPortal({
|
|
|
327
333
|
}, [fbo]);
|
|
328
334
|
React.useLayoutEffect(() => {
|
|
329
335
|
if (frames === 1) {
|
|
330
|
-
const autoClear =
|
|
331
|
-
|
|
332
|
-
camera.current.update(
|
|
333
|
-
|
|
336
|
+
const autoClear = renderer.autoClear;
|
|
337
|
+
renderer.autoClear = true;
|
|
338
|
+
camera.current.update(renderer, virtualScene);
|
|
339
|
+
renderer.autoClear = autoClear;
|
|
334
340
|
}
|
|
335
341
|
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
336
342
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
@@ -339,14 +345,29 @@ function EnvironmentPortal({
|
|
|
339
345
|
environmentIntensity,
|
|
340
346
|
environmentRotation
|
|
341
347
|
});
|
|
342
|
-
}, [
|
|
348
|
+
}, [
|
|
349
|
+
children,
|
|
350
|
+
virtualScene,
|
|
351
|
+
fbo.texture,
|
|
352
|
+
scene,
|
|
353
|
+
defaultScene,
|
|
354
|
+
background,
|
|
355
|
+
frames,
|
|
356
|
+
renderer,
|
|
357
|
+
blur,
|
|
358
|
+
backgroundBlurriness,
|
|
359
|
+
backgroundIntensity,
|
|
360
|
+
backgroundRotation,
|
|
361
|
+
environmentIntensity,
|
|
362
|
+
environmentRotation
|
|
363
|
+
]);
|
|
343
364
|
let count = 1;
|
|
344
365
|
useFrame$1(() => {
|
|
345
366
|
if (frames === Infinity || count < frames) {
|
|
346
|
-
const autoClear =
|
|
347
|
-
|
|
348
|
-
camera.current.update(
|
|
349
|
-
|
|
367
|
+
const autoClear = renderer.autoClear;
|
|
368
|
+
renderer.autoClear = true;
|
|
369
|
+
camera.current.update(renderer, virtualScene);
|
|
370
|
+
renderer.autoClear = autoClear;
|
|
350
371
|
count++;
|
|
351
372
|
}
|
|
352
373
|
});
|
|
@@ -410,10 +431,9 @@ function Environment(props) {
|
|
|
410
431
|
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
411
432
|
}
|
|
412
433
|
|
|
413
|
-
var __defProp
|
|
414
|
-
var __defNormalProp
|
|
415
|
-
var __publicField
|
|
416
|
-
const act = React["act"];
|
|
434
|
+
var __defProp = Object.defineProperty;
|
|
435
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
436
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
417
437
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
418
438
|
function useMutableCallback(fn) {
|
|
419
439
|
const ref = React.useRef(fn);
|
|
@@ -444,7 +464,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
444
464
|
return _a = class extends React.Component {
|
|
445
465
|
constructor() {
|
|
446
466
|
super(...arguments);
|
|
447
|
-
__publicField
|
|
467
|
+
__publicField(this, "state", { error: false });
|
|
448
468
|
}
|
|
449
469
|
componentDidCatch(err) {
|
|
450
470
|
this.props.set(err);
|
|
@@ -452,7 +472,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
452
472
|
render() {
|
|
453
473
|
return this.state.error ? null : this.props.children;
|
|
454
474
|
}
|
|
455
|
-
}, __publicField
|
|
475
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
456
476
|
})();
|
|
457
477
|
|
|
458
478
|
const is = {
|
|
@@ -589,8 +609,7 @@ function prepare(target, root, type, props) {
|
|
|
589
609
|
object,
|
|
590
610
|
eventCount: 0,
|
|
591
611
|
handlers: {},
|
|
592
|
-
isHidden: false
|
|
593
|
-
deferredRefs: []
|
|
612
|
+
isHidden: false
|
|
594
613
|
};
|
|
595
614
|
if (object) object.__r3f = instance;
|
|
596
615
|
}
|
|
@@ -747,6 +766,17 @@ function unregisterVisibility(store, object) {
|
|
|
747
766
|
internal.visibilityRegistry.delete(object.uuid);
|
|
748
767
|
internal.occlusionCache.delete(object);
|
|
749
768
|
}
|
|
769
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
770
|
+
const { internal } = store.getState();
|
|
771
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
772
|
+
if (!entry) return false;
|
|
773
|
+
entry.handlers = handlers;
|
|
774
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
775
|
+
object.occlusionTest = true;
|
|
776
|
+
enableOcclusion(store);
|
|
777
|
+
}
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
750
780
|
function checkVisibility(state) {
|
|
751
781
|
const { internal, camera } = state;
|
|
752
782
|
const registry = internal.visibilityRegistry;
|
|
@@ -907,9 +937,9 @@ function diffProps(instance, newProps) {
|
|
|
907
937
|
const { root, key } = resolve(instance.object, prop);
|
|
908
938
|
if (root.constructor && root.constructor.length === 0) {
|
|
909
939
|
const ctor = getMemoizedPrototype(root);
|
|
910
|
-
if (!is.und(ctor)) changedProps[
|
|
940
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
911
941
|
} else {
|
|
912
|
-
changedProps[
|
|
942
|
+
changedProps[prop] = 0;
|
|
913
943
|
}
|
|
914
944
|
}
|
|
915
945
|
return changedProps;
|
|
@@ -934,10 +964,7 @@ function applyProps(object, props) {
|
|
|
934
964
|
continue;
|
|
935
965
|
}
|
|
936
966
|
if (value === void 0) continue;
|
|
937
|
-
if (isFromRef(value))
|
|
938
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
939
|
-
continue;
|
|
940
|
-
}
|
|
967
|
+
if (isFromRef(value)) continue;
|
|
941
968
|
if (isOnce(value)) {
|
|
942
969
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
943
970
|
if (instance) {
|
|
@@ -973,8 +1000,24 @@ function applyProps(object, props) {
|
|
|
973
1000
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
974
1001
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
975
1002
|
else target.set(value);
|
|
1003
|
+
} else if (root instanceof ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1004
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1005
|
+
const uniforms = root.uniforms;
|
|
1006
|
+
const nextUniforms = value;
|
|
1007
|
+
for (const name in nextUniforms) {
|
|
1008
|
+
const uniform = nextUniforms[name];
|
|
1009
|
+
const targetUniform = uniforms[name];
|
|
1010
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1011
|
+
else {
|
|
1012
|
+
const nextUniform = uniform instanceof Uniform ? uniform.clone() : new Uniform(uniform.value);
|
|
1013
|
+
uniforms[name] = nextUniform;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
976
1016
|
} else {
|
|
977
1017
|
root[key] = value;
|
|
1018
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1019
|
+
root.needsUpdate = true;
|
|
1020
|
+
}
|
|
978
1021
|
if (rootState && rootState.renderer?.outputColorSpace === SRGBColorSpace && colorMaps.includes(key) && isTexture(value) && root[key]?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
979
1022
|
root[key].format === RGBAFormat && root[key].type === UnsignedByteType) {
|
|
980
1023
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -988,6 +1031,9 @@ function applyProps(object, props) {
|
|
|
988
1031
|
if (instance.eventCount && object2.raycast !== null) {
|
|
989
1032
|
rootState.internal.interaction.push(object2);
|
|
990
1033
|
}
|
|
1034
|
+
}
|
|
1035
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1036
|
+
const object2 = instance.object;
|
|
991
1037
|
const root = findInitialRoot(instance);
|
|
992
1038
|
const visibilityHandlers = {
|
|
993
1039
|
onFramed: instance.handlers.onFramed,
|
|
@@ -995,7 +1041,9 @@ function applyProps(object, props) {
|
|
|
995
1041
|
onVisible: instance.handlers.onVisible
|
|
996
1042
|
};
|
|
997
1043
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
998
|
-
|
|
1044
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1045
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1046
|
+
}
|
|
999
1047
|
} else {
|
|
1000
1048
|
unregisterVisibility(root, object2);
|
|
1001
1049
|
}
|
|
@@ -1008,38 +1056,60 @@ function applyProps(object, props) {
|
|
|
1008
1056
|
return object;
|
|
1009
1057
|
}
|
|
1010
1058
|
|
|
1059
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1060
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1061
|
+
function getPointerState(internal, pointerId) {
|
|
1062
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1063
|
+
if (!state) {
|
|
1064
|
+
state = {
|
|
1065
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1066
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1067
|
+
initialClick: [0, 0],
|
|
1068
|
+
initialHits: []
|
|
1069
|
+
};
|
|
1070
|
+
internal.pointerMap.set(pointerId, state);
|
|
1071
|
+
}
|
|
1072
|
+
return state;
|
|
1073
|
+
}
|
|
1074
|
+
function getPointerId(event) {
|
|
1075
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1076
|
+
}
|
|
1011
1077
|
function makeId(event) {
|
|
1012
1078
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1013
1079
|
}
|
|
1014
|
-
function releaseInternalPointerCapture(
|
|
1015
|
-
const
|
|
1080
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1081
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1082
|
+
if (!pointerState) return;
|
|
1083
|
+
const captureData = pointerState.captured.get(obj);
|
|
1016
1084
|
if (captureData) {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
capturedMap.delete(pointerId);
|
|
1020
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
1021
|
-
}
|
|
1085
|
+
pointerState.captured.delete(obj);
|
|
1086
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1022
1087
|
}
|
|
1023
1088
|
}
|
|
1024
1089
|
function removeInteractivity(store, object) {
|
|
1025
1090
|
const { internal } = store.getState();
|
|
1026
1091
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1092
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1093
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1094
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1095
|
+
if (value.eventObject === object || value.object === object) {
|
|
1096
|
+
pointerState.hovered.delete(key);
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
if (pointerState.captured.has(object)) {
|
|
1100
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1031
1101
|
}
|
|
1032
|
-
}
|
|
1033
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1034
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1035
|
-
});
|
|
1102
|
+
}
|
|
1036
1103
|
unregisterVisibility(store, object);
|
|
1037
1104
|
}
|
|
1038
1105
|
function createEvents(store) {
|
|
1039
|
-
function calculateDistance(event) {
|
|
1106
|
+
function calculateDistance(event, pointerId) {
|
|
1040
1107
|
const { internal } = store.getState();
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1108
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1109
|
+
if (!pointerState) return 0;
|
|
1110
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1111
|
+
const dx = event.offsetX - initialX;
|
|
1112
|
+
const dy = event.offsetY - initialY;
|
|
1043
1113
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1044
1114
|
}
|
|
1045
1115
|
function filterPointerEvents(objects) {
|
|
@@ -1075,6 +1145,15 @@ function createEvents(store) {
|
|
|
1075
1145
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1076
1146
|
}
|
|
1077
1147
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1148
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1149
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1150
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1151
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1152
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1153
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1154
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1078
1157
|
const aState = getRootState(a.object);
|
|
1079
1158
|
const bState = getRootState(b.object);
|
|
1080
1159
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1096,9 +1175,13 @@ function createEvents(store) {
|
|
|
1096
1175
|
eventObject = eventObject.parent;
|
|
1097
1176
|
}
|
|
1098
1177
|
}
|
|
1099
|
-
if ("pointerId" in event
|
|
1100
|
-
|
|
1101
|
-
|
|
1178
|
+
if ("pointerId" in event) {
|
|
1179
|
+
const pointerId = event.pointerId;
|
|
1180
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1181
|
+
if (pointerState?.captured.size) {
|
|
1182
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1183
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1184
|
+
}
|
|
1102
1185
|
}
|
|
1103
1186
|
}
|
|
1104
1187
|
return intersections;
|
|
@@ -1111,27 +1194,25 @@ function createEvents(store) {
|
|
|
1111
1194
|
if (state) {
|
|
1112
1195
|
const { raycaster, pointer, camera, internal } = state;
|
|
1113
1196
|
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1114
|
-
const hasPointerCapture = (id) =>
|
|
1197
|
+
const hasPointerCapture = (id) => {
|
|
1198
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1199
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1200
|
+
};
|
|
1115
1201
|
const setPointerCapture = (id) => {
|
|
1116
1202
|
const captureData = { intersection: hit, target: event.target };
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
} else {
|
|
1120
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1121
|
-
}
|
|
1203
|
+
const pointerState = getPointerState(internal, id);
|
|
1204
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1122
1205
|
event.target.setPointerCapture(id);
|
|
1123
1206
|
};
|
|
1124
1207
|
const releasePointerCapture = (id) => {
|
|
1125
|
-
|
|
1126
|
-
if (captures) {
|
|
1127
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1128
|
-
}
|
|
1208
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1129
1209
|
};
|
|
1130
1210
|
const extractEventProps = {};
|
|
1131
1211
|
for (const prop in event) {
|
|
1132
1212
|
const property = event[prop];
|
|
1133
1213
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1134
1214
|
}
|
|
1215
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1135
1216
|
const raycastEvent = {
|
|
1136
1217
|
...hit,
|
|
1137
1218
|
...extractEventProps,
|
|
@@ -1142,18 +1223,19 @@ function createEvents(store) {
|
|
|
1142
1223
|
unprojectedPoint,
|
|
1143
1224
|
ray: raycaster.ray,
|
|
1144
1225
|
camera,
|
|
1226
|
+
pointerId: eventPointerId,
|
|
1145
1227
|
// Hijack stopPropagation, which just sets a flag
|
|
1146
1228
|
stopPropagation() {
|
|
1147
|
-
const
|
|
1229
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1148
1230
|
if (
|
|
1149
1231
|
// ...if this pointer hasn't been captured
|
|
1150
|
-
!
|
|
1151
|
-
|
|
1232
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1233
|
+
pointerState.captured.has(hit.eventObject)
|
|
1152
1234
|
) {
|
|
1153
1235
|
raycastEvent.stopped = localState.stopped = true;
|
|
1154
|
-
if (
|
|
1236
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1155
1237
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1156
|
-
cancelPointer([...higher, hit]);
|
|
1238
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1157
1239
|
}
|
|
1158
1240
|
}
|
|
1159
1241
|
},
|
|
@@ -1169,15 +1251,18 @@ function createEvents(store) {
|
|
|
1169
1251
|
}
|
|
1170
1252
|
return intersections;
|
|
1171
1253
|
}
|
|
1172
|
-
function cancelPointer(intersections) {
|
|
1254
|
+
function cancelPointer(intersections, pointerId) {
|
|
1173
1255
|
const { internal } = store.getState();
|
|
1174
|
-
|
|
1256
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1257
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1258
|
+
if (!pointerState) return;
|
|
1259
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1175
1260
|
if (!intersections.length || !intersections.find(
|
|
1176
1261
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1177
1262
|
)) {
|
|
1178
1263
|
const eventObject = hoveredObj.eventObject;
|
|
1179
1264
|
const instance = eventObject.__r3f;
|
|
1180
|
-
|
|
1265
|
+
pointerState.hovered.delete(hoveredId);
|
|
1181
1266
|
if (instance?.eventCount) {
|
|
1182
1267
|
const handlers = instance.handlers;
|
|
1183
1268
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1206,41 +1291,118 @@ function createEvents(store) {
|
|
|
1206
1291
|
instance?.handlers.onDropMissed?.(event);
|
|
1207
1292
|
}
|
|
1208
1293
|
}
|
|
1294
|
+
function cleanupPointer(pointerId) {
|
|
1295
|
+
const { internal } = store.getState();
|
|
1296
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1297
|
+
if (pointerState) {
|
|
1298
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1299
|
+
const eventObject = hoveredObj.eventObject;
|
|
1300
|
+
const instance = eventObject.__r3f;
|
|
1301
|
+
if (instance?.eventCount) {
|
|
1302
|
+
const handlers = instance.handlers;
|
|
1303
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1304
|
+
handlers.onPointerOut?.(data);
|
|
1305
|
+
handlers.onPointerLeave?.(data);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
internal.pointerMap.delete(pointerId);
|
|
1309
|
+
}
|
|
1310
|
+
internal.pointerDirty.delete(pointerId);
|
|
1311
|
+
}
|
|
1312
|
+
function processDeferredPointer(event, pointerId) {
|
|
1313
|
+
const state = store.getState();
|
|
1314
|
+
const { internal } = state;
|
|
1315
|
+
if (!state.events.enabled) return;
|
|
1316
|
+
const filter = filterPointerEvents;
|
|
1317
|
+
const hits = intersect(event, filter);
|
|
1318
|
+
cancelPointer(hits, pointerId);
|
|
1319
|
+
function onIntersect(data) {
|
|
1320
|
+
const eventObject = data.eventObject;
|
|
1321
|
+
const instance = eventObject.__r3f;
|
|
1322
|
+
if (!instance?.eventCount) return;
|
|
1323
|
+
const handlers = instance.handlers;
|
|
1324
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1325
|
+
const id = makeId(data);
|
|
1326
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1327
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1328
|
+
if (!hoveredItem) {
|
|
1329
|
+
pointerState.hovered.set(id, data);
|
|
1330
|
+
handlers.onPointerOver?.(data);
|
|
1331
|
+
handlers.onPointerEnter?.(data);
|
|
1332
|
+
} else if (hoveredItem.stopped) {
|
|
1333
|
+
data.stopPropagation();
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
handlers.onPointerMove?.(data);
|
|
1337
|
+
}
|
|
1338
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1339
|
+
}
|
|
1209
1340
|
function handlePointer(name) {
|
|
1210
1341
|
switch (name) {
|
|
1211
1342
|
case "onPointerLeave":
|
|
1212
|
-
case "onPointerCancel":
|
|
1213
1343
|
case "onDragLeave":
|
|
1214
1344
|
return () => cancelPointer([]);
|
|
1345
|
+
// Global cancel of these events
|
|
1346
|
+
case "onPointerCancel":
|
|
1347
|
+
return (event) => {
|
|
1348
|
+
const pointerId = getPointerId(event);
|
|
1349
|
+
cleanupPointer(pointerId);
|
|
1350
|
+
};
|
|
1215
1351
|
case "onLostPointerCapture":
|
|
1216
1352
|
return (event) => {
|
|
1217
1353
|
const { internal } = store.getState();
|
|
1218
|
-
|
|
1354
|
+
const pointerId = getPointerId(event);
|
|
1355
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1356
|
+
if (pointerState?.captured.size) {
|
|
1219
1357
|
requestAnimationFrame(() => {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1358
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1359
|
+
if (pointerState2?.captured.size) {
|
|
1360
|
+
pointerState2.captured.clear();
|
|
1223
1361
|
}
|
|
1362
|
+
cancelPointer([], pointerId);
|
|
1224
1363
|
});
|
|
1225
1364
|
}
|
|
1226
1365
|
};
|
|
1227
1366
|
}
|
|
1228
1367
|
return function handleEvent(event) {
|
|
1229
1368
|
const state = store.getState();
|
|
1230
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1369
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1370
|
+
const pointerId = getPointerId(event);
|
|
1231
1371
|
internal.lastEvent.current = event;
|
|
1232
|
-
if (!
|
|
1372
|
+
if (!events.enabled) return;
|
|
1233
1373
|
const isPointerMove = name === "onPointerMove";
|
|
1234
1374
|
const isDragOver = name === "onDragOver";
|
|
1235
1375
|
const isDrop = name === "onDrop";
|
|
1236
1376
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1377
|
+
const isPointerDown = name === "onPointerDown";
|
|
1378
|
+
const isPointerUp = name === "onPointerUp";
|
|
1379
|
+
const isWheel = name === "onWheel";
|
|
1380
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1381
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1382
|
+
events.compute?.(event, state);
|
|
1383
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1387
|
+
events.compute?.(event, state);
|
|
1388
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1392
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1393
|
+
internal.pointerDirty.delete(pointerId);
|
|
1394
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1395
|
+
}
|
|
1237
1396
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1238
1397
|
const hits = intersect(event, filter);
|
|
1239
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1240
|
-
if (
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1398
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1399
|
+
if (isPointerDown) {
|
|
1400
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1401
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1402
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1403
|
+
}
|
|
1404
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1405
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1244
1406
|
if (isClickEvent && !hits.length) {
|
|
1245
1407
|
if (delta <= 2) {
|
|
1246
1408
|
pointerMissed(event, internal.interaction);
|
|
@@ -1255,7 +1417,9 @@ function createEvents(store) {
|
|
|
1255
1417
|
dropMissed(event, internal.interaction);
|
|
1256
1418
|
if (onDropMissed) onDropMissed(event);
|
|
1257
1419
|
}
|
|
1258
|
-
if (isPointerMove || isDragOver)
|
|
1420
|
+
if (isPointerMove || isDragOver) {
|
|
1421
|
+
cancelPointer(hits, pointerId);
|
|
1422
|
+
}
|
|
1259
1423
|
function onIntersect(data) {
|
|
1260
1424
|
const eventObject = data.eventObject;
|
|
1261
1425
|
const instance = eventObject.__r3f;
|
|
@@ -1264,9 +1428,10 @@ function createEvents(store) {
|
|
|
1264
1428
|
if (isPointerMove) {
|
|
1265
1429
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1266
1430
|
const id = makeId(data);
|
|
1267
|
-
const
|
|
1431
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1432
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1268
1433
|
if (!hoveredItem) {
|
|
1269
|
-
|
|
1434
|
+
pointerState2.hovered.set(id, data);
|
|
1270
1435
|
handlers.onPointerOver?.(data);
|
|
1271
1436
|
handlers.onPointerEnter?.(data);
|
|
1272
1437
|
} else if (hoveredItem.stopped) {
|
|
@@ -1276,9 +1441,10 @@ function createEvents(store) {
|
|
|
1276
1441
|
handlers.onPointerMove?.(data);
|
|
1277
1442
|
} else if (isDragOver) {
|
|
1278
1443
|
const id = makeId(data);
|
|
1279
|
-
const
|
|
1444
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1445
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1280
1446
|
if (!hoveredItem) {
|
|
1281
|
-
|
|
1447
|
+
pointerState2.hovered.set(id, data);
|
|
1282
1448
|
handlers.onDragOverEnter?.(data);
|
|
1283
1449
|
} else if (hoveredItem.stopped) {
|
|
1284
1450
|
data.stopPropagation();
|
|
@@ -1289,18 +1455,18 @@ function createEvents(store) {
|
|
|
1289
1455
|
} else {
|
|
1290
1456
|
const handler = handlers[name];
|
|
1291
1457
|
if (handler) {
|
|
1292
|
-
if (!isClickEvent ||
|
|
1458
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1293
1459
|
pointerMissed(
|
|
1294
1460
|
event,
|
|
1295
|
-
internal.interaction.filter((object) => !
|
|
1461
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1296
1462
|
);
|
|
1297
1463
|
handler(data);
|
|
1298
1464
|
}
|
|
1299
1465
|
} else {
|
|
1300
|
-
if (isClickEvent &&
|
|
1466
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1301
1467
|
pointerMissed(
|
|
1302
1468
|
event,
|
|
1303
|
-
internal.interaction.filter((object) => !
|
|
1469
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1304
1470
|
);
|
|
1305
1471
|
}
|
|
1306
1472
|
}
|
|
@@ -1309,7 +1475,15 @@ function createEvents(store) {
|
|
|
1309
1475
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1310
1476
|
};
|
|
1311
1477
|
}
|
|
1312
|
-
|
|
1478
|
+
function flushDeferredPointers() {
|
|
1479
|
+
const { internal, events } = store.getState();
|
|
1480
|
+
if (!events.frameTimedRaycasts) return;
|
|
1481
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1482
|
+
processDeferredPointer(event, pointerId);
|
|
1483
|
+
}
|
|
1484
|
+
internal.pointerDirty.clear();
|
|
1485
|
+
}
|
|
1486
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1313
1487
|
}
|
|
1314
1488
|
const DOM_EVENTS = {
|
|
1315
1489
|
onClick: ["click", false],
|
|
@@ -1328,10 +1502,15 @@ const DOM_EVENTS = {
|
|
|
1328
1502
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1329
1503
|
};
|
|
1330
1504
|
function createPointerEvents(store) {
|
|
1331
|
-
const { handlePointer } = createEvents(store);
|
|
1505
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1506
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1507
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1332
1508
|
return {
|
|
1333
1509
|
priority: 1,
|
|
1334
1510
|
enabled: true,
|
|
1511
|
+
frameTimedRaycasts: true,
|
|
1512
|
+
alwaysFireOnScroll: true,
|
|
1513
|
+
updateOnFrame: false,
|
|
1335
1514
|
compute(event, state) {
|
|
1336
1515
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1337
1516
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1341,11 +1520,33 @@ function createPointerEvents(store) {
|
|
|
1341
1520
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1342
1521
|
{}
|
|
1343
1522
|
),
|
|
1344
|
-
update: () => {
|
|
1523
|
+
update: (pointerId) => {
|
|
1345
1524
|
const { events, internal } = store.getState();
|
|
1346
|
-
if (
|
|
1525
|
+
if (!events.handlers) return;
|
|
1526
|
+
if (pointerId !== void 0) {
|
|
1527
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1528
|
+
if (event) {
|
|
1529
|
+
internal.pointerDirty.delete(pointerId);
|
|
1530
|
+
processDeferredPointer(event, pointerId);
|
|
1531
|
+
} else if (internal.lastEvent?.current) {
|
|
1532
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1533
|
+
}
|
|
1534
|
+
} else {
|
|
1535
|
+
flushDeferredPointers();
|
|
1536
|
+
if (internal.lastEvent?.current) {
|
|
1537
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
},
|
|
1541
|
+
flush: () => {
|
|
1542
|
+
const { events, internal } = store.getState();
|
|
1543
|
+
flushDeferredPointers();
|
|
1544
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1545
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1546
|
+
}
|
|
1347
1547
|
},
|
|
1348
1548
|
connect: (target) => {
|
|
1549
|
+
if (!target) return;
|
|
1349
1550
|
const { set, events } = store.getState();
|
|
1350
1551
|
events.disconnect?.();
|
|
1351
1552
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1369,6 +1570,33 @@ function createPointerEvents(store) {
|
|
|
1369
1570
|
}
|
|
1370
1571
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1371
1572
|
}
|
|
1573
|
+
},
|
|
1574
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1575
|
+
registerPointer: (config) => {
|
|
1576
|
+
const pointerId = nextXRPointerId++;
|
|
1577
|
+
xrPointers.set(pointerId, config);
|
|
1578
|
+
const { internal } = store.getState();
|
|
1579
|
+
getPointerState(internal, pointerId);
|
|
1580
|
+
return pointerId;
|
|
1581
|
+
},
|
|
1582
|
+
unregisterPointer: (pointerId) => {
|
|
1583
|
+
xrPointers.delete(pointerId);
|
|
1584
|
+
const { internal } = store.getState();
|
|
1585
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1586
|
+
if (pointerState) {
|
|
1587
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1588
|
+
const eventObject = hoveredObj.eventObject;
|
|
1589
|
+
const instance = eventObject.__r3f;
|
|
1590
|
+
if (instance?.eventCount) {
|
|
1591
|
+
const handlers = instance.handlers;
|
|
1592
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1593
|
+
handlers.onPointerOut?.(data);
|
|
1594
|
+
handlers.onPointerLeave?.(data);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
internal.pointerMap.delete(pointerId);
|
|
1598
|
+
}
|
|
1599
|
+
internal.pointerDirty.delete(pointerId);
|
|
1372
1600
|
}
|
|
1373
1601
|
};
|
|
1374
1602
|
}
|
|
@@ -1430,1036 +1658,11 @@ function notifyAlpha({ message, link }) {
|
|
|
1430
1658
|
}
|
|
1431
1659
|
}
|
|
1432
1660
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
constructor() {
|
|
1439
|
-
/** Ordered list of phase nodes */
|
|
1440
|
-
__publicField$1(this, "phases", []);
|
|
1441
|
-
/** Quick lookup by name */
|
|
1442
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1443
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1444
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1445
|
-
this.initializeDefaultPhases();
|
|
1446
|
-
}
|
|
1447
|
-
//* Initialization --------------------------------
|
|
1448
|
-
initializeDefaultPhases() {
|
|
1449
|
-
for (const name of DEFAULT_PHASES) {
|
|
1450
|
-
const node = { name, isAutoGenerated: false };
|
|
1451
|
-
this.phases.push(node);
|
|
1452
|
-
this.phaseMap.set(name, node);
|
|
1453
|
-
}
|
|
1454
|
-
this.invalidateCache();
|
|
1455
|
-
}
|
|
1456
|
-
//* Public API --------------------------------
|
|
1457
|
-
/**
|
|
1458
|
-
* Add a named phase to the graph
|
|
1459
|
-
* @param name - Phase name (must be unique)
|
|
1460
|
-
* @param options - Position options (before or after another phase)
|
|
1461
|
-
*/
|
|
1462
|
-
addPhase(name, options = {}) {
|
|
1463
|
-
if (this.phaseMap.has(name)) {
|
|
1464
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1465
|
-
return;
|
|
1466
|
-
}
|
|
1467
|
-
const { before, after } = options;
|
|
1468
|
-
const node = { name, isAutoGenerated: false };
|
|
1469
|
-
let insertIndex = this.phases.length;
|
|
1470
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1471
|
-
if (targetIndex !== -1) {
|
|
1472
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1473
|
-
} else {
|
|
1474
|
-
const constraintType = before ? "before" : "after";
|
|
1475
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1476
|
-
}
|
|
1477
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1478
|
-
this.phaseMap.set(name, node);
|
|
1479
|
-
this.invalidateCache();
|
|
1480
|
-
}
|
|
1481
|
-
/**
|
|
1482
|
-
* Get ordered list of phase names
|
|
1483
|
-
*/
|
|
1484
|
-
getOrderedPhases() {
|
|
1485
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1486
|
-
return this.orderedNamesCache;
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Check if a phase exists
|
|
1490
|
-
*/
|
|
1491
|
-
hasPhase(name) {
|
|
1492
|
-
return this.phaseMap.has(name);
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Get the index of a phase (-1 if not found)
|
|
1496
|
-
*/
|
|
1497
|
-
getPhaseIndex(name) {
|
|
1498
|
-
if (!name) return -1;
|
|
1499
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1503
|
-
* Used for resolving before/after constraints.
|
|
1504
|
-
*
|
|
1505
|
-
* @param name - The phase name to ensure exists
|
|
1506
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1507
|
-
*/
|
|
1508
|
-
ensurePhase(name) {
|
|
1509
|
-
if (this.phaseMap.has(name)) return name;
|
|
1510
|
-
const node = { name, isAutoGenerated: true };
|
|
1511
|
-
this.phases.push(node);
|
|
1512
|
-
this.phaseMap.set(name, node);
|
|
1513
|
-
this.invalidateCache();
|
|
1514
|
-
return name;
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* Resolve where a job with before/after constraints should go.
|
|
1518
|
-
* Creates auto-generated phases if needed.
|
|
1519
|
-
*
|
|
1520
|
-
* @param before - Phase(s) to run before
|
|
1521
|
-
* @param after - Phase(s) to run after
|
|
1522
|
-
* @returns The resolved phase name
|
|
1523
|
-
*/
|
|
1524
|
-
resolveConstraintPhase(before, after) {
|
|
1525
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1526
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1527
|
-
if (beforeArr.length > 0) {
|
|
1528
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1529
|
-
}
|
|
1530
|
-
if (afterArr.length > 0) {
|
|
1531
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1532
|
-
}
|
|
1533
|
-
return "update";
|
|
1534
|
-
}
|
|
1535
|
-
/**
|
|
1536
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1537
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1538
|
-
*
|
|
1539
|
-
* @param target - The target phase name to position relative to
|
|
1540
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1541
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1542
|
-
* @returns The auto-generated phase name
|
|
1543
|
-
*/
|
|
1544
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1545
|
-
const autoName = `${prefix}:${target}`;
|
|
1546
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1547
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1548
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1549
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1550
|
-
else this.phases.push(node);
|
|
1551
|
-
this.phaseMap.set(autoName, node);
|
|
1552
|
-
this.invalidateCache();
|
|
1553
|
-
return autoName;
|
|
1554
|
-
}
|
|
1555
|
-
// Internal --------------------------------
|
|
1556
|
-
invalidateCache() {
|
|
1557
|
-
this.orderedNamesCache = null;
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1562
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1563
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1564
|
-
for (const phase of orderedPhases) {
|
|
1565
|
-
buckets.set(phase, []);
|
|
1566
|
-
}
|
|
1567
|
-
for (const job of jobs.values()) {
|
|
1568
|
-
if (!job.enabled) continue;
|
|
1569
|
-
let bucket = buckets.get(job.phase);
|
|
1570
|
-
if (!bucket) {
|
|
1571
|
-
bucket = [];
|
|
1572
|
-
buckets.set(job.phase, bucket);
|
|
1573
|
-
}
|
|
1574
|
-
bucket.push(job);
|
|
1575
|
-
}
|
|
1576
|
-
const sortedBuckets = [];
|
|
1577
|
-
for (const phase of orderedPhases) {
|
|
1578
|
-
const bucket = buckets.get(phase);
|
|
1579
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1580
|
-
bucket.sort((a, b) => {
|
|
1581
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1582
|
-
return a.index - b.index;
|
|
1583
|
-
});
|
|
1584
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1585
|
-
}
|
|
1586
|
-
for (const [phase, bucket] of buckets) {
|
|
1587
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1588
|
-
bucket.sort((a, b) => {
|
|
1589
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1590
|
-
return a.index - b.index;
|
|
1591
|
-
});
|
|
1592
|
-
sortedBuckets.push(bucket);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
return sortedBuckets.flat();
|
|
1596
|
-
}
|
|
1597
|
-
function hasCrossJobConstraints(bucket) {
|
|
1598
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1599
|
-
for (const job of bucket) {
|
|
1600
|
-
for (const ref of job.before) {
|
|
1601
|
-
if (jobIds.has(ref)) return true;
|
|
1602
|
-
}
|
|
1603
|
-
for (const ref of job.after) {
|
|
1604
|
-
if (jobIds.has(ref)) return true;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
return false;
|
|
1608
|
-
}
|
|
1609
|
-
function topologicalSort(jobs) {
|
|
1610
|
-
const n = jobs.length;
|
|
1611
|
-
if (n <= 1) return jobs;
|
|
1612
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1613
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1614
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1615
|
-
for (const job of jobs) {
|
|
1616
|
-
jobMap.set(job.id, job);
|
|
1617
|
-
inDegree.set(job.id, 0);
|
|
1618
|
-
adjacency.set(job.id, []);
|
|
1619
|
-
}
|
|
1620
|
-
for (const job of jobs) {
|
|
1621
|
-
for (const ref of job.before) {
|
|
1622
|
-
if (jobMap.has(ref)) {
|
|
1623
|
-
adjacency.get(job.id).push(ref);
|
|
1624
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
for (const ref of job.after) {
|
|
1628
|
-
if (jobMap.has(ref)) {
|
|
1629
|
-
adjacency.get(ref).push(job.id);
|
|
1630
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
const queue = [];
|
|
1635
|
-
for (const job of jobs) {
|
|
1636
|
-
if (inDegree.get(job.id) === 0) {
|
|
1637
|
-
queue.push(job);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
queue.sort((a, b) => {
|
|
1641
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1642
|
-
return a.index - b.index;
|
|
1643
|
-
});
|
|
1644
|
-
const result = [];
|
|
1645
|
-
while (queue.length > 0) {
|
|
1646
|
-
const job = queue.shift();
|
|
1647
|
-
result.push(job);
|
|
1648
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1649
|
-
for (const neighborId of neighbors) {
|
|
1650
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1651
|
-
inDegree.set(neighborId, newDegree);
|
|
1652
|
-
if (newDegree === 0) {
|
|
1653
|
-
const neighbor = jobMap.get(neighborId);
|
|
1654
|
-
insertSorted(queue, neighbor);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
if (result.length !== n) {
|
|
1659
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1660
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1661
|
-
for (const job of jobs) {
|
|
1662
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return result;
|
|
1666
|
-
}
|
|
1667
|
-
function insertSorted(arr, job) {
|
|
1668
|
-
let i = 0;
|
|
1669
|
-
while (i < arr.length) {
|
|
1670
|
-
const cmp = arr[i];
|
|
1671
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1672
|
-
break;
|
|
1673
|
-
}
|
|
1674
|
-
i++;
|
|
1675
|
-
}
|
|
1676
|
-
arr.splice(i, 0, job);
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
function shouldRun(job, now) {
|
|
1680
|
-
if (!job.enabled) return false;
|
|
1681
|
-
if (!job.fps) return true;
|
|
1682
|
-
const minInterval = 1e3 / job.fps;
|
|
1683
|
-
const lastRun = job.lastRun ?? 0;
|
|
1684
|
-
const elapsed = now - lastRun;
|
|
1685
|
-
if (elapsed < minInterval) return false;
|
|
1686
|
-
if (job.drop) {
|
|
1687
|
-
job.lastRun = now;
|
|
1688
|
-
} else {
|
|
1689
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1690
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1691
|
-
if (job.lastRun < now - minInterval) {
|
|
1692
|
-
job.lastRun = now;
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
return true;
|
|
1696
|
-
}
|
|
1697
|
-
function resetJobTiming(job) {
|
|
1698
|
-
job.lastRun = void 0;
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
var __defProp = Object.defineProperty;
|
|
1702
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1703
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1704
|
-
const hmrData = (() => {
|
|
1705
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1706
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1707
|
-
try {
|
|
1708
|
-
return (0, eval)("import.meta.hot");
|
|
1709
|
-
} catch {
|
|
1710
|
-
return void 0;
|
|
1711
|
-
}
|
|
1712
|
-
})();
|
|
1713
|
-
const _Scheduler = class _Scheduler {
|
|
1714
|
-
//* Constructor ================================
|
|
1715
|
-
constructor() {
|
|
1716
|
-
//* Critical State ================================
|
|
1717
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1718
|
-
__publicField(this, "phaseGraph");
|
|
1719
|
-
__publicField(this, "loopState", {
|
|
1720
|
-
running: false,
|
|
1721
|
-
rafHandle: null,
|
|
1722
|
-
lastTime: null,
|
|
1723
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1724
|
-
frameCount: 0,
|
|
1725
|
-
elapsedTime: 0,
|
|
1726
|
-
createdAt: performance.now()
|
|
1727
|
-
});
|
|
1728
|
-
__publicField(this, "stoppedTime", 0);
|
|
1729
|
-
//* Private State ================================
|
|
1730
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1731
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1732
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1733
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1734
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1735
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1736
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1737
|
-
__publicField(this, "pendingFrames", 0);
|
|
1738
|
-
__publicField(this, "_frameloop", "always");
|
|
1739
|
-
//* Independent Mode & Error Handling State ================================
|
|
1740
|
-
__publicField(this, "_independent", false);
|
|
1741
|
-
__publicField(this, "errorHandler", null);
|
|
1742
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1743
|
-
//* Core Loop Execution Methods ================================
|
|
1744
|
-
/**
|
|
1745
|
-
* Main RAF loop callback.
|
|
1746
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1747
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1748
|
-
* @returns {void}
|
|
1749
|
-
* @private
|
|
1750
|
-
*/
|
|
1751
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1752
|
-
if (!this.loopState.running) return;
|
|
1753
|
-
this.executeFrame(timestamp);
|
|
1754
|
-
if (this._frameloop === "demand") {
|
|
1755
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1756
|
-
if (this.pendingFrames === 0) {
|
|
1757
|
-
this.notifyIdle(timestamp);
|
|
1758
|
-
return this.stop();
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1762
|
-
});
|
|
1763
|
-
this.phaseGraph = new PhaseGraph();
|
|
1764
|
-
}
|
|
1765
|
-
static get instance() {
|
|
1766
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1767
|
-
}
|
|
1768
|
-
static set instance(value) {
|
|
1769
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1773
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1774
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1775
|
-
*/
|
|
1776
|
-
static get() {
|
|
1777
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1778
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1779
|
-
}
|
|
1780
|
-
if (!_Scheduler.instance) {
|
|
1781
|
-
_Scheduler.instance = new _Scheduler();
|
|
1782
|
-
if (hmrData?.data) {
|
|
1783
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
return _Scheduler.instance;
|
|
1787
|
-
}
|
|
1788
|
-
/**
|
|
1789
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1790
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1791
|
-
* @returns {void}
|
|
1792
|
-
*/
|
|
1793
|
-
static reset() {
|
|
1794
|
-
if (_Scheduler.instance) {
|
|
1795
|
-
_Scheduler.instance.stop();
|
|
1796
|
-
_Scheduler.instance = null;
|
|
1797
|
-
}
|
|
1798
|
-
if (hmrData?.data) {
|
|
1799
|
-
hmrData.data.scheduler = null;
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
//* Getters & Setters ================================
|
|
1803
|
-
get phases() {
|
|
1804
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1805
|
-
}
|
|
1806
|
-
get frameloop() {
|
|
1807
|
-
return this._frameloop;
|
|
1808
|
-
}
|
|
1809
|
-
set frameloop(mode) {
|
|
1810
|
-
if (this._frameloop === mode) return;
|
|
1811
|
-
const wasAlways = this._frameloop === "always";
|
|
1812
|
-
this._frameloop = mode;
|
|
1813
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1814
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1815
|
-
}
|
|
1816
|
-
get isRunning() {
|
|
1817
|
-
return this.loopState.running;
|
|
1818
|
-
}
|
|
1819
|
-
get isReady() {
|
|
1820
|
-
return this.roots.size > 0;
|
|
1821
|
-
}
|
|
1822
|
-
get independent() {
|
|
1823
|
-
return this._independent;
|
|
1824
|
-
}
|
|
1825
|
-
set independent(value) {
|
|
1826
|
-
this._independent = value;
|
|
1827
|
-
if (value) this.ensureDefaultRoot();
|
|
1828
|
-
}
|
|
1829
|
-
//* Root Management Methods ================================
|
|
1830
|
-
/**
|
|
1831
|
-
* Register a root (Canvas) with the scheduler.
|
|
1832
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1833
|
-
* @param {string} id - Unique identifier for this root
|
|
1834
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1835
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1836
|
-
*/
|
|
1837
|
-
registerRoot(id, options = {}) {
|
|
1838
|
-
if (this.roots.has(id)) {
|
|
1839
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1840
|
-
return () => this.unregisterRoot(id);
|
|
1841
|
-
}
|
|
1842
|
-
const entry = {
|
|
1843
|
-
id,
|
|
1844
|
-
getState: options.getState ?? (() => ({})),
|
|
1845
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1846
|
-
sortedJobs: [],
|
|
1847
|
-
needsRebuild: false
|
|
1848
|
-
};
|
|
1849
|
-
if (options.onError) {
|
|
1850
|
-
this.errorHandler = options.onError;
|
|
1851
|
-
}
|
|
1852
|
-
this.roots.set(id, entry);
|
|
1853
|
-
if (this.roots.size === 1) {
|
|
1854
|
-
this.notifyRootReady();
|
|
1855
|
-
if (this._frameloop === "always") this.start();
|
|
1856
|
-
}
|
|
1857
|
-
return () => this.unregisterRoot(id);
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
|
-
* Unregister a root from the scheduler.
|
|
1861
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1862
|
-
* The last root to unregister stops the RAF loop.
|
|
1863
|
-
* @param {string} id - The root ID to unregister
|
|
1864
|
-
* @returns {void}
|
|
1865
|
-
*/
|
|
1866
|
-
unregisterRoot(id) {
|
|
1867
|
-
const root = this.roots.get(id);
|
|
1868
|
-
if (!root) return;
|
|
1869
|
-
for (const jobId of root.jobs.keys()) {
|
|
1870
|
-
this.jobStateListeners.delete(jobId);
|
|
1871
|
-
}
|
|
1872
|
-
this.roots.delete(id);
|
|
1873
|
-
if (this.roots.size === 0) {
|
|
1874
|
-
this.stop();
|
|
1875
|
-
this.errorHandler = null;
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
/**
|
|
1879
|
-
* Subscribe to be notified when a root becomes available.
|
|
1880
|
-
* Fires immediately if a root already exists.
|
|
1881
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1882
|
-
* @returns {() => void} Unsubscribe function
|
|
1883
|
-
*/
|
|
1884
|
-
onRootReady(callback) {
|
|
1885
|
-
if (this.roots.size > 0) {
|
|
1886
|
-
callback();
|
|
1887
|
-
return () => {
|
|
1888
|
-
};
|
|
1889
|
-
}
|
|
1890
|
-
this.rootReadyCallbacks.add(callback);
|
|
1891
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1892
|
-
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Notify all registered root-ready callbacks.
|
|
1895
|
-
* Called when the first root registers.
|
|
1896
|
-
* @returns {void}
|
|
1897
|
-
* @private
|
|
1898
|
-
*/
|
|
1899
|
-
notifyRootReady() {
|
|
1900
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1901
|
-
try {
|
|
1902
|
-
cb();
|
|
1903
|
-
} catch (error) {
|
|
1904
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
this.rootReadyCallbacks.clear();
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Ensure a default root exists for independent mode.
|
|
1911
|
-
* Creates a minimal root with no state provider.
|
|
1912
|
-
* @returns {void}
|
|
1913
|
-
* @private
|
|
1914
|
-
*/
|
|
1915
|
-
ensureDefaultRoot() {
|
|
1916
|
-
if (!this.roots.has("__default__")) {
|
|
1917
|
-
this.registerRoot("__default__");
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
/**
|
|
1921
|
-
* Trigger error handling for job errors.
|
|
1922
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1923
|
-
* @param {Error} error - The error to handle
|
|
1924
|
-
* @returns {void}
|
|
1925
|
-
*/
|
|
1926
|
-
triggerError(error) {
|
|
1927
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1928
|
-
else console.error("[Scheduler]", error);
|
|
1929
|
-
}
|
|
1930
|
-
//* Phase Management Methods ================================
|
|
1931
|
-
/**
|
|
1932
|
-
* Add a named phase to the scheduler's execution order.
|
|
1933
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1934
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1935
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1936
|
-
* @returns {void}
|
|
1937
|
-
* @example
|
|
1938
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1939
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1940
|
-
*/
|
|
1941
|
-
addPhase(name, options) {
|
|
1942
|
-
this.phaseGraph.addPhase(name, options);
|
|
1943
|
-
for (const root of this.roots.values()) {
|
|
1944
|
-
root.needsRebuild = true;
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
/**
|
|
1948
|
-
* Check if a phase exists in the scheduler.
|
|
1949
|
-
* @param {string} name - The phase name to check
|
|
1950
|
-
* @returns {boolean} True if the phase exists
|
|
1951
|
-
*/
|
|
1952
|
-
hasPhase(name) {
|
|
1953
|
-
return this.phaseGraph.hasPhase(name);
|
|
1954
|
-
}
|
|
1955
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1956
|
-
/**
|
|
1957
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1958
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1959
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1960
|
-
* @param {string} id - Unique identifier for this global job
|
|
1961
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1962
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1963
|
-
* @deprecated Use useFrame with phases instead
|
|
1964
|
-
*/
|
|
1965
|
-
registerGlobal(phase, id, callback) {
|
|
1966
|
-
const job = { id, callback };
|
|
1967
|
-
if (phase === "before") {
|
|
1968
|
-
this.globalBeforeJobs.set(id, job);
|
|
1969
|
-
} else {
|
|
1970
|
-
this.globalAfterJobs.set(id, job);
|
|
1971
|
-
}
|
|
1972
|
-
return () => {
|
|
1973
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
1974
|
-
else this.globalAfterJobs.delete(id);
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
1978
|
-
/**
|
|
1979
|
-
* Register an idle callback that fires when the loop stops.
|
|
1980
|
-
* Used internally by deprecated addTail API.
|
|
1981
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
1982
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
1983
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
1984
|
-
*/
|
|
1985
|
-
onIdle(callback) {
|
|
1986
|
-
this.idleCallbacks.add(callback);
|
|
1987
|
-
return () => this.idleCallbacks.delete(callback);
|
|
1988
|
-
}
|
|
1989
|
-
/**
|
|
1990
|
-
* Notify all registered idle callbacks.
|
|
1991
|
-
* Called when the loop stops in demand mode.
|
|
1992
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
1993
|
-
* @returns {void}
|
|
1994
|
-
* @private
|
|
1995
|
-
*/
|
|
1996
|
-
notifyIdle(timestamp) {
|
|
1997
|
-
for (const cb of this.idleCallbacks) {
|
|
1998
|
-
try {
|
|
1999
|
-
cb(timestamp);
|
|
2000
|
-
} catch (error) {
|
|
2001
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
//* Job Registration & Management Methods ================================
|
|
2006
|
-
/**
|
|
2007
|
-
* Register a job (frame callback) with a specific root.
|
|
2008
|
-
* This is the core registration method used by useFrame internally.
|
|
2009
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2010
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2011
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2012
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2013
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2014
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2015
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2016
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2017
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2018
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2019
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2020
|
-
*/
|
|
2021
|
-
register(callback, options = {}) {
|
|
2022
|
-
const rootId = options.rootId;
|
|
2023
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2024
|
-
if (!root) {
|
|
2025
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2026
|
-
return () => {
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
const id = options.id ?? this.generateJobId();
|
|
2030
|
-
let phase = options.phase ?? "update";
|
|
2031
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2032
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2033
|
-
}
|
|
2034
|
-
const before = this.normalizeConstraints(options.before);
|
|
2035
|
-
const after = this.normalizeConstraints(options.after);
|
|
2036
|
-
const job = {
|
|
2037
|
-
id,
|
|
2038
|
-
callback,
|
|
2039
|
-
phase,
|
|
2040
|
-
before,
|
|
2041
|
-
after,
|
|
2042
|
-
priority: options.priority ?? 0,
|
|
2043
|
-
index: this.nextJobIndex++,
|
|
2044
|
-
fps: options.fps,
|
|
2045
|
-
drop: options.drop ?? true,
|
|
2046
|
-
enabled: options.enabled ?? true,
|
|
2047
|
-
system: options.system ?? false
|
|
2048
|
-
};
|
|
2049
|
-
if (root.jobs.has(id)) {
|
|
2050
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2051
|
-
}
|
|
2052
|
-
root.jobs.set(id, job);
|
|
2053
|
-
root.needsRebuild = true;
|
|
2054
|
-
return () => this.unregister(id, root.id);
|
|
2055
|
-
}
|
|
2056
|
-
/**
|
|
2057
|
-
* Unregister a job by its ID.
|
|
2058
|
-
* Searches all roots if rootId is not provided.
|
|
2059
|
-
* @param {string} id - The job ID to unregister
|
|
2060
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2061
|
-
* @returns {void}
|
|
2062
|
-
*/
|
|
2063
|
-
unregister(id, rootId) {
|
|
2064
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2065
|
-
if (root?.jobs.delete(id)) {
|
|
2066
|
-
root.needsRebuild = true;
|
|
2067
|
-
this.jobStateListeners.delete(id);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Update a job's options dynamically.
|
|
2072
|
-
* Searches all roots to find the job by ID.
|
|
2073
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2074
|
-
* @param {string} id - The job ID to update
|
|
2075
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2076
|
-
* @returns {void}
|
|
2077
|
-
*/
|
|
2078
|
-
updateJob(id, options) {
|
|
2079
|
-
let job;
|
|
2080
|
-
let root;
|
|
2081
|
-
for (const r of this.roots.values()) {
|
|
2082
|
-
job = r.jobs.get(id);
|
|
2083
|
-
if (job) {
|
|
2084
|
-
root = r;
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
if (!job || !root) return;
|
|
2089
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2090
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2091
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2092
|
-
if (options.enabled !== void 0) {
|
|
2093
|
-
const wasEnabled = job.enabled;
|
|
2094
|
-
job.enabled = options.enabled;
|
|
2095
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2096
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2097
|
-
}
|
|
2098
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2099
|
-
if (options.phase) job.phase = options.phase;
|
|
2100
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2101
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2102
|
-
root.needsRebuild = true;
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
//* Job State Management Methods ================================
|
|
2106
|
-
/**
|
|
2107
|
-
* Check if a job is currently paused (disabled).
|
|
2108
|
-
* @param {string} id - The job ID to check
|
|
2109
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2110
|
-
*/
|
|
2111
|
-
isJobPaused(id) {
|
|
2112
|
-
for (const root of this.roots.values()) {
|
|
2113
|
-
const job = root.jobs.get(id);
|
|
2114
|
-
if (job) return !job.enabled;
|
|
2115
|
-
}
|
|
2116
|
-
return false;
|
|
2117
|
-
}
|
|
2118
|
-
/**
|
|
2119
|
-
* Subscribe to state changes for a specific job.
|
|
2120
|
-
* Listener is called when job is paused or resumed.
|
|
2121
|
-
* @param {string} id - The job ID to subscribe to
|
|
2122
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2123
|
-
* @returns {() => void} Unsubscribe function
|
|
2124
|
-
*/
|
|
2125
|
-
subscribeJobState(id, listener) {
|
|
2126
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2127
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2128
|
-
}
|
|
2129
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2130
|
-
return () => {
|
|
2131
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2132
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2133
|
-
this.jobStateListeners.delete(id);
|
|
2134
|
-
}
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* Notify all listeners that a job's state has changed.
|
|
2139
|
-
* @param {string} id - The job ID that changed
|
|
2140
|
-
* @returns {void}
|
|
2141
|
-
* @private
|
|
2142
|
-
*/
|
|
2143
|
-
notifyJobStateChange(id) {
|
|
2144
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2145
|
-
}
|
|
2146
|
-
/**
|
|
2147
|
-
* Pause a job by ID (sets enabled=false).
|
|
2148
|
-
* Notifies any subscribed state listeners.
|
|
2149
|
-
* @param {string} id - The job ID to pause
|
|
2150
|
-
* @returns {void}
|
|
2151
|
-
*/
|
|
2152
|
-
pauseJob(id) {
|
|
2153
|
-
this.updateJob(id, { enabled: false });
|
|
2154
|
-
this.notifyJobStateChange(id);
|
|
2155
|
-
}
|
|
2156
|
-
/**
|
|
2157
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2158
|
-
* Resets job timing to prevent frame accumulation.
|
|
2159
|
-
* Notifies any subscribed state listeners.
|
|
2160
|
-
* @param {string} id - The job ID to resume
|
|
2161
|
-
* @returns {void}
|
|
2162
|
-
*/
|
|
2163
|
-
resumeJob(id) {
|
|
2164
|
-
this.updateJob(id, { enabled: true });
|
|
2165
|
-
this.notifyJobStateChange(id);
|
|
2166
|
-
}
|
|
2167
|
-
//* Frame Loop Control Methods ================================
|
|
2168
|
-
/**
|
|
2169
|
-
* Start the requestAnimationFrame loop.
|
|
2170
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2171
|
-
* No-op if already running.
|
|
2172
|
-
* @returns {void}
|
|
2173
|
-
*/
|
|
2174
|
-
start() {
|
|
2175
|
-
if (this.loopState.running) return;
|
|
2176
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2177
|
-
let adjustedCreated = 0;
|
|
2178
|
-
if (this.stoppedTime > 0) {
|
|
2179
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2180
|
-
this.stoppedTime = 0;
|
|
2181
|
-
}
|
|
2182
|
-
Object.assign(this.loopState, {
|
|
2183
|
-
running: true,
|
|
2184
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2185
|
-
lastTime: performance.now(),
|
|
2186
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2187
|
-
frameCount: 0,
|
|
2188
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2189
|
-
});
|
|
2190
|
-
}
|
|
2191
|
-
/**
|
|
2192
|
-
* Stop the requestAnimationFrame loop.
|
|
2193
|
-
* Cancels any pending RAF callback.
|
|
2194
|
-
* No-op if not running.
|
|
2195
|
-
* @returns {void}
|
|
2196
|
-
*/
|
|
2197
|
-
stop() {
|
|
2198
|
-
if (!this.loopState.running) return;
|
|
2199
|
-
this.loopState.running = false;
|
|
2200
|
-
if (this.loopState.rafHandle !== null) {
|
|
2201
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2202
|
-
this.loopState.rafHandle = null;
|
|
2203
|
-
}
|
|
2204
|
-
this.stoppedTime = performance.now();
|
|
2205
|
-
}
|
|
2206
|
-
/**
|
|
2207
|
-
* Request frames to be rendered in demand mode.
|
|
2208
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2209
|
-
* No-op if frameloop is not 'demand'.
|
|
2210
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2211
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2212
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2213
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2214
|
-
* @returns {void}
|
|
2215
|
-
* @example
|
|
2216
|
-
* // Request a single frame render
|
|
2217
|
-
* scheduler.invalidate();
|
|
2218
|
-
*
|
|
2219
|
-
* @example
|
|
2220
|
-
* // Request 5 frames (e.g., for animations)
|
|
2221
|
-
* scheduler.invalidate(5);
|
|
2222
|
-
*
|
|
2223
|
-
* @example
|
|
2224
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2225
|
-
* scheduler.invalidate(3, false);
|
|
2226
|
-
*
|
|
2227
|
-
* @example
|
|
2228
|
-
* // Add 2 more frames to existing pending count
|
|
2229
|
-
* scheduler.invalidate(2, true);
|
|
2230
|
-
*/
|
|
2231
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2232
|
-
if (this._frameloop !== "demand") return;
|
|
2233
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2234
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2235
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2236
|
-
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Reset timing state for deterministic testing.
|
|
2239
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2240
|
-
* @returns {void}
|
|
2241
|
-
*/
|
|
2242
|
-
resetTiming() {
|
|
2243
|
-
this.loopState.lastTime = null;
|
|
2244
|
-
this.loopState.frameCount = 0;
|
|
2245
|
-
this.loopState.elapsedTime = 0;
|
|
2246
|
-
this.loopState.createdAt = performance.now();
|
|
2247
|
-
}
|
|
2248
|
-
//* Manual Stepping Methods ================================
|
|
2249
|
-
/**
|
|
2250
|
-
* Manually execute a single frame for all roots.
|
|
2251
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2252
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2253
|
-
* @returns {void}
|
|
2254
|
-
* @example
|
|
2255
|
-
* // Manual control mode
|
|
2256
|
-
* scheduler.frameloop = 'never';
|
|
2257
|
-
* scheduler.step(); // Execute one frame
|
|
2258
|
-
*/
|
|
2259
|
-
step(timestamp) {
|
|
2260
|
-
const now = timestamp ?? performance.now();
|
|
2261
|
-
this.executeFrame(now);
|
|
2262
|
-
}
|
|
2263
|
-
/**
|
|
2264
|
-
* Manually execute a single job by its ID.
|
|
2265
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2266
|
-
* @param {string} id - The job ID to step
|
|
2267
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2268
|
-
* @returns {void}
|
|
2269
|
-
*/
|
|
2270
|
-
stepJob(id, timestamp) {
|
|
2271
|
-
let job;
|
|
2272
|
-
let root;
|
|
2273
|
-
for (const r of this.roots.values()) {
|
|
2274
|
-
job = r.jobs.get(id);
|
|
2275
|
-
if (job) {
|
|
2276
|
-
root = r;
|
|
2277
|
-
break;
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
if (!job || !root) {
|
|
2281
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2282
|
-
return;
|
|
2283
|
-
}
|
|
2284
|
-
const now = timestamp ?? performance.now();
|
|
2285
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2286
|
-
const delta = deltaMs / 1e3;
|
|
2287
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2288
|
-
const providedState = root.getState?.() ?? {};
|
|
2289
|
-
const frameState = {
|
|
2290
|
-
...providedState,
|
|
2291
|
-
time: now,
|
|
2292
|
-
delta,
|
|
2293
|
-
elapsed,
|
|
2294
|
-
frame: this.loopState.frameCount
|
|
2295
|
-
};
|
|
2296
|
-
try {
|
|
2297
|
-
job.callback(frameState, delta);
|
|
2298
|
-
} catch (error) {
|
|
2299
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2300
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
/**
|
|
2304
|
-
* Execute a single frame across all roots.
|
|
2305
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2306
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2307
|
-
* @returns {void}
|
|
2308
|
-
* @private
|
|
2309
|
-
*/
|
|
2310
|
-
executeFrame(timestamp) {
|
|
2311
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2312
|
-
const delta = deltaMs / 1e3;
|
|
2313
|
-
this.loopState.lastTime = timestamp;
|
|
2314
|
-
this.loopState.frameCount++;
|
|
2315
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2316
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2317
|
-
for (const root of this.roots.values()) {
|
|
2318
|
-
this.tickRoot(root, timestamp, delta);
|
|
2319
|
-
}
|
|
2320
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2321
|
-
}
|
|
2322
|
-
/**
|
|
2323
|
-
* Run all global jobs from a job map.
|
|
2324
|
-
* Catches and logs errors without stopping execution.
|
|
2325
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2326
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2327
|
-
* @returns {void}
|
|
2328
|
-
* @private
|
|
2329
|
-
*/
|
|
2330
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2331
|
-
for (const job of jobs.values()) {
|
|
2332
|
-
try {
|
|
2333
|
-
job.callback(timestamp);
|
|
2334
|
-
} catch (error) {
|
|
2335
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
/**
|
|
2340
|
-
* Execute all jobs for a single root in sorted order.
|
|
2341
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2342
|
-
* Errors are caught and propagated via triggerError.
|
|
2343
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2344
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2345
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2346
|
-
* @returns {void}
|
|
2347
|
-
* @private
|
|
2348
|
-
*/
|
|
2349
|
-
tickRoot(root, timestamp, delta) {
|
|
2350
|
-
if (root.needsRebuild) {
|
|
2351
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2352
|
-
root.needsRebuild = false;
|
|
2353
|
-
}
|
|
2354
|
-
const providedState = root.getState?.() ?? {};
|
|
2355
|
-
const frameState = {
|
|
2356
|
-
...providedState,
|
|
2357
|
-
time: timestamp,
|
|
2358
|
-
delta,
|
|
2359
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2360
|
-
// Convert ms to seconds
|
|
2361
|
-
frame: this.loopState.frameCount
|
|
2362
|
-
};
|
|
2363
|
-
for (const job of root.sortedJobs) {
|
|
2364
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2365
|
-
try {
|
|
2366
|
-
job.callback(frameState, delta);
|
|
2367
|
-
} catch (error) {
|
|
2368
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2369
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
//* Debug & Inspection Methods ================================
|
|
2374
|
-
/**
|
|
2375
|
-
* Get the total number of registered jobs across all roots.
|
|
2376
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2377
|
-
* @returns {number} Total job count
|
|
2378
|
-
*/
|
|
2379
|
-
getJobCount() {
|
|
2380
|
-
let count = 0;
|
|
2381
|
-
for (const root of this.roots.values()) {
|
|
2382
|
-
count += root.jobs.size;
|
|
2383
|
-
}
|
|
2384
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2385
|
-
}
|
|
2386
|
-
/**
|
|
2387
|
-
* Get all registered job IDs across all roots.
|
|
2388
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2389
|
-
* @returns {string[]} Array of all job IDs
|
|
2390
|
-
*/
|
|
2391
|
-
getJobIds() {
|
|
2392
|
-
const ids = [];
|
|
2393
|
-
for (const root of this.roots.values()) {
|
|
2394
|
-
ids.push(...root.jobs.keys());
|
|
2395
|
-
}
|
|
2396
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2397
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2398
|
-
return ids;
|
|
2399
|
-
}
|
|
2400
|
-
/**
|
|
2401
|
-
* Get the number of registered roots (Canvas instances).
|
|
2402
|
-
* @returns {number} Number of registered roots
|
|
2403
|
-
*/
|
|
2404
|
-
getRootCount() {
|
|
2405
|
-
return this.roots.size;
|
|
2406
|
-
}
|
|
2407
|
-
/**
|
|
2408
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2409
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2410
|
-
*
|
|
2411
|
-
* @param phase The phase to check
|
|
2412
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2413
|
-
* @returns true if any user jobs exist in the phase
|
|
2414
|
-
*/
|
|
2415
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2416
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2417
|
-
return rootsToCheck.some((root) => {
|
|
2418
|
-
if (!root) return false;
|
|
2419
|
-
for (const job of root.jobs.values()) {
|
|
2420
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2421
|
-
}
|
|
2422
|
-
return false;
|
|
2423
|
-
});
|
|
2424
|
-
}
|
|
2425
|
-
//* Utility Methods ================================
|
|
2426
|
-
/**
|
|
2427
|
-
* Generate a unique root ID for automatic root registration.
|
|
2428
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2429
|
-
*/
|
|
2430
|
-
generateRootId() {
|
|
2431
|
-
return `root_${this.nextRootIndex++}`;
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Generate a unique job ID.
|
|
2435
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2436
|
-
* @private
|
|
2437
|
-
*/
|
|
2438
|
-
generateJobId() {
|
|
2439
|
-
return `job_${this.nextJobIndex}`;
|
|
2440
|
-
}
|
|
2441
|
-
/**
|
|
2442
|
-
* Normalize before/after constraints to a Set.
|
|
2443
|
-
* Handles undefined, single string, or array inputs.
|
|
2444
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2445
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2446
|
-
* @private
|
|
2447
|
-
*/
|
|
2448
|
-
normalizeConstraints(value) {
|
|
2449
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2450
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2451
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2452
|
-
}
|
|
2453
|
-
};
|
|
2454
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2455
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2456
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2457
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2458
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2459
|
-
let Scheduler = _Scheduler;
|
|
2460
|
-
const getScheduler = () => Scheduler.get();
|
|
2461
|
-
if (hmrData) {
|
|
2462
|
-
hmrData.accept?.();
|
|
1661
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1662
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1663
|
+
if (!stack) return false;
|
|
1664
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1665
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
2463
1666
|
}
|
|
2464
1667
|
|
|
2465
1668
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2499,7 +1702,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2499
1702
|
frustum: new Frustum(),
|
|
2500
1703
|
autoUpdateFrustum: true,
|
|
2501
1704
|
raycaster: null,
|
|
2502
|
-
events: {
|
|
1705
|
+
events: {
|
|
1706
|
+
priority: 1,
|
|
1707
|
+
enabled: true,
|
|
1708
|
+
connected: false,
|
|
1709
|
+
frameTimedRaycasts: true,
|
|
1710
|
+
alwaysFireOnScroll: true,
|
|
1711
|
+
updateOnFrame: false
|
|
1712
|
+
},
|
|
2503
1713
|
scene: null,
|
|
2504
1714
|
rootScene: null,
|
|
2505
1715
|
xr: null,
|
|
@@ -2587,14 +1797,18 @@ const createStore = (invalidate, advance) => {
|
|
|
2587
1797
|
}),
|
|
2588
1798
|
setFrameloop: (frameloop = "always") => {
|
|
2589
1799
|
set(() => ({ frameloop }));
|
|
1800
|
+
getScheduler().frameloop = frameloop;
|
|
2590
1801
|
},
|
|
2591
1802
|
setError: (error) => set(() => ({ error })),
|
|
2592
1803
|
error: null,
|
|
2593
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1804
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2594
1805
|
uniforms: {},
|
|
2595
1806
|
nodes: {},
|
|
1807
|
+
buffers: {},
|
|
1808
|
+
gpuStorage: {},
|
|
2596
1809
|
textures: /* @__PURE__ */ new Map(),
|
|
2597
|
-
|
|
1810
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1811
|
+
renderPipeline: null,
|
|
2598
1812
|
passes: {},
|
|
2599
1813
|
_hmrVersion: 0,
|
|
2600
1814
|
_sizeImperative: false,
|
|
@@ -2603,12 +1817,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2603
1817
|
internal: {
|
|
2604
1818
|
// Events
|
|
2605
1819
|
interaction: [],
|
|
2606
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2607
1820
|
subscribers: [],
|
|
1821
|
+
// Per-pointer state (new unified structure)
|
|
1822
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1823
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1824
|
+
lastEvent: React.createRef(),
|
|
1825
|
+
// Deprecated but kept for backwards compatibility
|
|
1826
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2608
1827
|
initialClick: [0, 0],
|
|
2609
1828
|
initialHits: [],
|
|
2610
1829
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2611
|
-
lastEvent: React.createRef(),
|
|
2612
1830
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2613
1831
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2614
1832
|
// Occlusion system (WebGPU only)
|
|
@@ -2647,8 +1865,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2647
1865
|
const currentState = rootStore.getState();
|
|
2648
1866
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2649
1867
|
const stack = new Error().stack || "";
|
|
2650
|
-
|
|
2651
|
-
if (!isInternalAccess) {
|
|
1868
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2652
1869
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2653
1870
|
notifyDepreciated({
|
|
2654
1871
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -2696,14 +1913,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2696
1913
|
oldSize = size;
|
|
2697
1914
|
oldDpr = viewport.dpr;
|
|
2698
1915
|
updateCamera(camera, size);
|
|
2699
|
-
if (canvasTarget) {
|
|
1916
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2700
1917
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2701
|
-
|
|
2702
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1918
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2703
1919
|
} else {
|
|
2704
1920
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2705
|
-
|
|
2706
|
-
|
|
1921
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1922
|
+
if (canvasTarget) {
|
|
1923
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1924
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1925
|
+
}
|
|
2707
1926
|
}
|
|
2708
1927
|
}
|
|
2709
1928
|
if (camera !== oldCamera) {
|
|
@@ -2759,19 +1978,25 @@ function loadingFn(extensions, onProgress) {
|
|
|
2759
1978
|
);
|
|
2760
1979
|
};
|
|
2761
1980
|
}
|
|
2762
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
2763
|
-
const
|
|
1981
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1982
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1983
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2764
1984
|
const fn = loadingFn(extensions, onProgress);
|
|
2765
|
-
const results =
|
|
1985
|
+
const results = cacheKeys.map(
|
|
1986
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1987
|
+
);
|
|
2766
1988
|
return Array.isArray(input) ? results : results[0];
|
|
2767
1989
|
}
|
|
2768
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
2769
|
-
const
|
|
2770
|
-
|
|
1990
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1991
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1992
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1993
|
+
cacheKeys.forEach(
|
|
1994
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1995
|
+
);
|
|
2771
1996
|
};
|
|
2772
|
-
useLoader.clear = function(loader, input) {
|
|
2773
|
-
const
|
|
2774
|
-
|
|
1997
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1998
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1999
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
2775
2000
|
};
|
|
2776
2001
|
useLoader.loader = getLoader;
|
|
2777
2002
|
|
|
@@ -2847,20 +2072,14 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2847
2072
|
}
|
|
2848
2073
|
};
|
|
2849
2074
|
} else {
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
unregisterJob = registerOutside();
|
|
2859
|
-
});
|
|
2860
|
-
return () => {
|
|
2861
|
-
unsubReady();
|
|
2862
|
-
unregisterJob?.();
|
|
2863
|
-
};
|
|
2075
|
+
return scheduler.register(
|
|
2076
|
+
(state, delta) => {
|
|
2077
|
+
const frameState = state;
|
|
2078
|
+
if (!frameState.renderer) return;
|
|
2079
|
+
callbackRef.current?.(frameState, delta);
|
|
2080
|
+
},
|
|
2081
|
+
{ id, ...options }
|
|
2082
|
+
);
|
|
2864
2083
|
}
|
|
2865
2084
|
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2866
2085
|
const isPaused = React.useSyncExternalStore(
|
|
@@ -2951,18 +2170,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2951
2170
|
function useTexture(input, optionsOrOnLoad) {
|
|
2952
2171
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2953
2172
|
const store = useStore();
|
|
2954
|
-
const textureCache = useThree((state) => state.textures);
|
|
2955
2173
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2956
|
-
const { onLoad, cache =
|
|
2174
|
+
const { onLoad, cache = true } = options;
|
|
2957
2175
|
const onLoadRef = useRef(onLoad);
|
|
2958
2176
|
onLoadRef.current = onLoad;
|
|
2959
2177
|
const onLoadCalledForRef = useRef(null);
|
|
2960
2178
|
const urls = useMemo(() => getUrls(input), [input]);
|
|
2961
2179
|
const cachedResult = useMemo(() => {
|
|
2962
2180
|
if (!cache) return null;
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2181
|
+
const textures = store.getState().textures;
|
|
2182
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2183
|
+
return buildFromCache(input, textures);
|
|
2184
|
+
}, [cache, urls, input, store]);
|
|
2966
2185
|
const loadedTextures = useLoader(
|
|
2967
2186
|
TextureLoader,
|
|
2968
2187
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3006,8 +2225,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3006
2225
|
}, [input, loadedTextures, cachedResult]);
|
|
3007
2226
|
useEffect(() => {
|
|
3008
2227
|
if (!cache) return;
|
|
3009
|
-
if (cachedResult) return;
|
|
3010
|
-
const set = store.setState;
|
|
3011
2228
|
const urlTextureMap = [];
|
|
3012
2229
|
if (typeof input === "string") {
|
|
3013
2230
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3021,18 +2238,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3021
2238
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3022
2239
|
}
|
|
3023
2240
|
}
|
|
3024
|
-
|
|
3025
|
-
const
|
|
3026
|
-
let
|
|
2241
|
+
store.setState((state) => {
|
|
2242
|
+
const refs = new Map(state._textureRefs);
|
|
2243
|
+
let textures = state.textures;
|
|
2244
|
+
let added = false;
|
|
3027
2245
|
for (const [url, texture] of urlTextureMap) {
|
|
3028
|
-
if (!
|
|
3029
|
-
|
|
3030
|
-
|
|
2246
|
+
if (!textures.has(url)) {
|
|
2247
|
+
if (!added) {
|
|
2248
|
+
textures = new Map(textures);
|
|
2249
|
+
added = true;
|
|
2250
|
+
}
|
|
2251
|
+
textures.set(url, texture);
|
|
3031
2252
|
}
|
|
2253
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3032
2254
|
}
|
|
3033
|
-
return
|
|
2255
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
3034
2256
|
});
|
|
3035
|
-
|
|
2257
|
+
return () => store.setState((state) => {
|
|
2258
|
+
const refs = new Map(state._textureRefs);
|
|
2259
|
+
for (const [url] of urlTextureMap) {
|
|
2260
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2261
|
+
if (next <= 0) refs.delete(url);
|
|
2262
|
+
else refs.set(url, next);
|
|
2263
|
+
}
|
|
2264
|
+
return { _textureRefs: refs };
|
|
2265
|
+
});
|
|
2266
|
+
}, [cache, input, mappedTextures, store]);
|
|
3036
2267
|
return mappedTextures;
|
|
3037
2268
|
}
|
|
3038
2269
|
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
@@ -3048,96 +2279,63 @@ const Texture = ({
|
|
|
3048
2279
|
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
3049
2280
|
};
|
|
3050
2281
|
|
|
3051
|
-
function
|
|
3052
|
-
if (entry instanceof Texture$1) return entry;
|
|
3053
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof Texture$1) {
|
|
3054
|
-
return entry.value;
|
|
3055
|
-
}
|
|
3056
|
-
return null;
|
|
3057
|
-
}
|
|
3058
|
-
function useTextures() {
|
|
2282
|
+
function useTextures(selector) {
|
|
3059
2283
|
const store = useStore();
|
|
3060
|
-
|
|
3061
|
-
const set = store.setState;
|
|
2284
|
+
const registry = useMemo(() => {
|
|
3062
2285
|
const getState = store.getState;
|
|
3063
|
-
const
|
|
3064
|
-
|
|
3065
|
-
const newMap = new Map(state.textures);
|
|
3066
|
-
newMap.set(key, value);
|
|
3067
|
-
return { textures: newMap };
|
|
3068
|
-
});
|
|
3069
|
-
};
|
|
3070
|
-
const addMultiple = (items) => {
|
|
3071
|
-
set((state) => {
|
|
3072
|
-
const newMap = new Map(state.textures);
|
|
3073
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3074
|
-
for (const [key, value] of entries) {
|
|
3075
|
-
newMap.set(key, value);
|
|
3076
|
-
}
|
|
3077
|
-
return { textures: newMap };
|
|
3078
|
-
});
|
|
3079
|
-
};
|
|
3080
|
-
const remove = (key) => {
|
|
3081
|
-
set((state) => {
|
|
3082
|
-
const newMap = new Map(state.textures);
|
|
3083
|
-
newMap.delete(key);
|
|
3084
|
-
return { textures: newMap };
|
|
3085
|
-
});
|
|
3086
|
-
};
|
|
3087
|
-
const removeMultiple = (keys) => {
|
|
3088
|
-
set((state) => {
|
|
3089
|
-
const newMap = new Map(state.textures);
|
|
3090
|
-
for (const key of keys) newMap.delete(key);
|
|
3091
|
-
return { textures: newMap };
|
|
3092
|
-
});
|
|
3093
|
-
};
|
|
3094
|
-
const dispose = (key) => {
|
|
3095
|
-
const entry = getState().textures.get(key);
|
|
3096
|
-
if (entry) {
|
|
3097
|
-
const tex = getTextureValue(entry);
|
|
3098
|
-
tex?.dispose();
|
|
3099
|
-
}
|
|
3100
|
-
remove(key);
|
|
3101
|
-
};
|
|
3102
|
-
const disposeMultiple = (keys) => {
|
|
3103
|
-
const textures = getState().textures;
|
|
3104
|
-
for (const key of keys) {
|
|
3105
|
-
const entry = textures.get(key);
|
|
3106
|
-
if (entry) {
|
|
3107
|
-
const tex = getTextureValue(entry);
|
|
3108
|
-
tex?.dispose();
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
removeMultiple(keys);
|
|
3112
|
-
};
|
|
3113
|
-
const disposeAll = () => {
|
|
3114
|
-
const textures = getState().textures;
|
|
3115
|
-
for (const entry of textures.values()) {
|
|
3116
|
-
const tex = getTextureValue(entry);
|
|
3117
|
-
tex?.dispose();
|
|
3118
|
-
}
|
|
3119
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3120
|
-
};
|
|
2286
|
+
const setState = store.setState;
|
|
2287
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3121
2288
|
return {
|
|
3122
|
-
|
|
3123
|
-
get textures() {
|
|
2289
|
+
get all() {
|
|
3124
2290
|
return getState().textures;
|
|
3125
2291
|
},
|
|
3126
|
-
|
|
3127
|
-
|
|
2292
|
+
get(input) {
|
|
2293
|
+
if (typeof input === "string") return getOne(input);
|
|
2294
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2295
|
+
const out = {};
|
|
2296
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2297
|
+
return out;
|
|
2298
|
+
},
|
|
3128
2299
|
has: (key) => getState().textures.has(key),
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
2300
|
+
add(keyOrRecord, texture) {
|
|
2301
|
+
setState((state) => {
|
|
2302
|
+
const textures = new Map(state.textures);
|
|
2303
|
+
if (typeof keyOrRecord === "string") {
|
|
2304
|
+
textures.set(keyOrRecord, texture);
|
|
2305
|
+
} else {
|
|
2306
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2307
|
+
}
|
|
2308
|
+
return { textures };
|
|
2309
|
+
});
|
|
2310
|
+
},
|
|
2311
|
+
dispose(key, options) {
|
|
2312
|
+
const state = getState();
|
|
2313
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2314
|
+
if (refs > 0 && !options?.force) {
|
|
2315
|
+
console.warn(
|
|
2316
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2317
|
+
);
|
|
2318
|
+
return false;
|
|
2319
|
+
}
|
|
2320
|
+
state.textures.get(key)?.dispose();
|
|
2321
|
+
setState((s) => {
|
|
2322
|
+
const textures = new Map(s.textures);
|
|
2323
|
+
textures.delete(key);
|
|
2324
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2325
|
+
nextRefs.delete(key);
|
|
2326
|
+
return { textures, _textureRefs: nextRefs };
|
|
2327
|
+
});
|
|
2328
|
+
return true;
|
|
2329
|
+
},
|
|
2330
|
+
disposeAll() {
|
|
2331
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2332
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2333
|
+
}
|
|
3139
2334
|
};
|
|
3140
2335
|
}, [store]);
|
|
2336
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2337
|
+
const selected = useThree(subscribe);
|
|
2338
|
+
return selector ? selected : registry;
|
|
3141
2339
|
}
|
|
3142
2340
|
|
|
3143
2341
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3220,7 +2418,7 @@ function advance(timestamp) {
|
|
|
3220
2418
|
getScheduler().step(timestamp);
|
|
3221
2419
|
}
|
|
3222
2420
|
|
|
3223
|
-
const version = "10.0.0-alpha.
|
|
2421
|
+
const version = "10.0.0-alpha.3";
|
|
3224
2422
|
const packageData = {
|
|
3225
2423
|
version: version};
|
|
3226
2424
|
|
|
@@ -14476,7 +13674,7 @@ function n0() {
|
|
|
14476
13674
|
var t0 = n0();
|
|
14477
13675
|
const r0 = Xb(t0);
|
|
14478
13676
|
|
|
14479
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13677
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
14480
13678
|
|
|
14481
13679
|
function createReconciler(config) {
|
|
14482
13680
|
const reconciler2 = r0(config);
|
|
@@ -14641,7 +13839,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
14641
13839
|
}
|
|
14642
13840
|
}
|
|
14643
13841
|
const reconstructed = [];
|
|
14644
|
-
function
|
|
13842
|
+
function flushReconstructedInstances() {
|
|
13843
|
+
if (reconstructed.length === 0) return;
|
|
13844
|
+
try {
|
|
13845
|
+
swapReconstructedInstances();
|
|
13846
|
+
} finally {
|
|
13847
|
+
reconstructed.length = 0;
|
|
13848
|
+
}
|
|
13849
|
+
}
|
|
13850
|
+
function swapReconstructedInstances() {
|
|
14645
13851
|
for (const [instance] of reconstructed) {
|
|
14646
13852
|
const parent = instance.parent;
|
|
14647
13853
|
if (parent) {
|
|
@@ -14659,6 +13865,7 @@ function swapInstances() {
|
|
|
14659
13865
|
}
|
|
14660
13866
|
}
|
|
14661
13867
|
if (instance.isHidden) unhideInstance(instance);
|
|
13868
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14662
13869
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14663
13870
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14664
13871
|
}
|
|
@@ -14671,6 +13878,8 @@ function swapInstances() {
|
|
|
14671
13878
|
instance.object.__r3f = instance;
|
|
14672
13879
|
setFiberRef(fiber, instance.object);
|
|
14673
13880
|
delete instance.appliedOnce;
|
|
13881
|
+
instance.eventCount = 0;
|
|
13882
|
+
instance.handlers = {};
|
|
14674
13883
|
applyProps(instance.object, instance.props);
|
|
14675
13884
|
if (instance.props.attach) {
|
|
14676
13885
|
attach(parent, instance);
|
|
@@ -14687,14 +13896,114 @@ function swapInstances() {
|
|
|
14687
13896
|
invalidateInstance(instance);
|
|
14688
13897
|
}
|
|
14689
13898
|
}
|
|
14690
|
-
reconstructed.length = 0;
|
|
14691
13899
|
}
|
|
14692
13900
|
const handleTextInstance = () => {
|
|
14693
13901
|
};
|
|
14694
13902
|
const NO_CONTEXT = {};
|
|
14695
13903
|
let currentUpdatePriority = NoEventPriority;
|
|
14696
|
-
|
|
14697
|
-
|
|
13904
|
+
function getEventPriority(type) {
|
|
13905
|
+
switch (type) {
|
|
13906
|
+
case "beforetoggle":
|
|
13907
|
+
case "cancel":
|
|
13908
|
+
case "click":
|
|
13909
|
+
case "close":
|
|
13910
|
+
case "contextmenu":
|
|
13911
|
+
case "copy":
|
|
13912
|
+
case "cut":
|
|
13913
|
+
case "auxclick":
|
|
13914
|
+
case "dblclick":
|
|
13915
|
+
case "dragend":
|
|
13916
|
+
case "dragstart":
|
|
13917
|
+
case "drop":
|
|
13918
|
+
case "focusin":
|
|
13919
|
+
case "focusout":
|
|
13920
|
+
case "input":
|
|
13921
|
+
case "invalid":
|
|
13922
|
+
case "keydown":
|
|
13923
|
+
case "keypress":
|
|
13924
|
+
case "keyup":
|
|
13925
|
+
case "mousedown":
|
|
13926
|
+
case "mouseup":
|
|
13927
|
+
case "paste":
|
|
13928
|
+
case "pause":
|
|
13929
|
+
case "play":
|
|
13930
|
+
case "pointercancel":
|
|
13931
|
+
case "pointerdown":
|
|
13932
|
+
case "pointerup":
|
|
13933
|
+
case "ratechange":
|
|
13934
|
+
case "reset":
|
|
13935
|
+
case "resize":
|
|
13936
|
+
case "seeked":
|
|
13937
|
+
case "submit":
|
|
13938
|
+
case "touchcancel":
|
|
13939
|
+
case "touchend":
|
|
13940
|
+
case "touchstart":
|
|
13941
|
+
case "volumechange":
|
|
13942
|
+
case "change":
|
|
13943
|
+
case "selectionchange":
|
|
13944
|
+
case "compositionstart":
|
|
13945
|
+
case "compositionend":
|
|
13946
|
+
case "compositionupdate":
|
|
13947
|
+
case "beforeinput":
|
|
13948
|
+
case "blur":
|
|
13949
|
+
case "fullscreenchange":
|
|
13950
|
+
case "focus":
|
|
13951
|
+
case "hashchange":
|
|
13952
|
+
case "popstate":
|
|
13953
|
+
case "select":
|
|
13954
|
+
case "selectstart":
|
|
13955
|
+
return e;
|
|
13956
|
+
case "drag":
|
|
13957
|
+
case "dragenter":
|
|
13958
|
+
case "dragexit":
|
|
13959
|
+
case "dragleave":
|
|
13960
|
+
case "dragover":
|
|
13961
|
+
case "mousemove":
|
|
13962
|
+
case "mouseout":
|
|
13963
|
+
case "mouseover":
|
|
13964
|
+
case "pointermove":
|
|
13965
|
+
case "pointerout":
|
|
13966
|
+
case "pointerover":
|
|
13967
|
+
case "scroll":
|
|
13968
|
+
case "touchmove":
|
|
13969
|
+
case "wheel":
|
|
13970
|
+
case "mouseenter":
|
|
13971
|
+
case "mouseleave":
|
|
13972
|
+
case "pointerenter":
|
|
13973
|
+
case "pointerleave":
|
|
13974
|
+
return o;
|
|
13975
|
+
case "message": {
|
|
13976
|
+
switch (unstable_getCurrentPriorityLevel()) {
|
|
13977
|
+
case unstable_ImmediatePriority:
|
|
13978
|
+
return e;
|
|
13979
|
+
case unstable_UserBlockingPriority:
|
|
13980
|
+
return o;
|
|
13981
|
+
case unstable_NormalPriority:
|
|
13982
|
+
case unstable_LowPriority:
|
|
13983
|
+
return r;
|
|
13984
|
+
case unstable_IdlePriority:
|
|
13985
|
+
return i$1;
|
|
13986
|
+
default:
|
|
13987
|
+
return r;
|
|
13988
|
+
}
|
|
13989
|
+
}
|
|
13990
|
+
default:
|
|
13991
|
+
return r;
|
|
13992
|
+
}
|
|
13993
|
+
}
|
|
13994
|
+
function scheduleMicrotask(callback) {
|
|
13995
|
+
if (typeof queueMicrotask === "function") {
|
|
13996
|
+
queueMicrotask(callback);
|
|
13997
|
+
} else if (typeof Promise !== "undefined") {
|
|
13998
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
13999
|
+
setTimeout(() => {
|
|
14000
|
+
throw error;
|
|
14001
|
+
});
|
|
14002
|
+
});
|
|
14003
|
+
} else {
|
|
14004
|
+
setTimeout(callback);
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14698
14007
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
14699
14008
|
isPrimaryRenderer: false,
|
|
14700
14009
|
warnsIfNotActing: false,
|
|
@@ -14733,16 +14042,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14733
14042
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
14734
14043
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
14735
14044
|
if (reconstruct) {
|
|
14736
|
-
reconstructed.push([instance,
|
|
14045
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
14737
14046
|
} else {
|
|
14738
14047
|
const changedProps = diffProps(instance, newProps);
|
|
14739
|
-
|
|
14740
|
-
|
|
14741
|
-
|
|
14742
|
-
|
|
14048
|
+
const attach2 = instance.props.attach;
|
|
14049
|
+
instance.props = getInstanceProps(newProps);
|
|
14050
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
14051
|
+
else delete instance.props.attach;
|
|
14052
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
14743
14053
|
}
|
|
14744
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14745
|
-
if (isTailSibling) swapInstances();
|
|
14746
14054
|
},
|
|
14747
14055
|
finalizeInitialChildren: (instance) => {
|
|
14748
14056
|
for (const prop in instance.props) {
|
|
@@ -14767,8 +14075,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14767
14075
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
14768
14076
|
return prepare(target, container, "", {});
|
|
14769
14077
|
},
|
|
14770
|
-
|
|
14771
|
-
|
|
14078
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
14079
|
+
// before layout effects run so refs point to the new objects
|
|
14080
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
14772
14081
|
shouldSetTextContent: () => false,
|
|
14773
14082
|
clearContainer: () => false,
|
|
14774
14083
|
hideInstance,
|
|
@@ -14776,6 +14085,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14776
14085
|
createTextInstance: handleTextInstance,
|
|
14777
14086
|
hideTextInstance: handleTextInstance,
|
|
14778
14087
|
unhideTextInstance: handleTextInstance,
|
|
14088
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
14089
|
+
supportsMicrotasks: true,
|
|
14090
|
+
scheduleMicrotask,
|
|
14779
14091
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
14780
14092
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
14781
14093
|
noTimeout: -1,
|
|
@@ -14816,28 +14128,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14816
14128
|
},
|
|
14817
14129
|
resolveUpdatePriority() {
|
|
14818
14130
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
|
|
14822
|
-
case "dblclick":
|
|
14823
|
-
case "dragenter":
|
|
14824
|
-
case "dragleave":
|
|
14825
|
-
case "drop":
|
|
14826
|
-
case "pointercancel":
|
|
14827
|
-
case "pointerdown":
|
|
14828
|
-
case "pointerup":
|
|
14829
|
-
return e;
|
|
14830
|
-
case "dragover":
|
|
14831
|
-
case "pointermove":
|
|
14832
|
-
case "pointerout":
|
|
14833
|
-
case "pointerover":
|
|
14834
|
-
case "pointerenter":
|
|
14835
|
-
case "pointerleave":
|
|
14836
|
-
case "wheel":
|
|
14837
|
-
return o;
|
|
14838
|
-
default:
|
|
14839
|
-
return r;
|
|
14840
|
-
}
|
|
14131
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14132
|
+
if (eventType === void 0) return r;
|
|
14133
|
+
return getEventPriority(eventType);
|
|
14841
14134
|
},
|
|
14842
14135
|
resetFormInstance() {
|
|
14843
14136
|
},
|
|
@@ -14886,11 +14179,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14886
14179
|
cloneMutableTextInstance(textInstance) {
|
|
14887
14180
|
return textInstance;
|
|
14888
14181
|
},
|
|
14182
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14183
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14184
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14185
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14186
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14187
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
14889
14188
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14890
|
-
throw new Error("Not implemented.");
|
|
14891
14189
|
},
|
|
14892
14190
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14893
|
-
throw new Error("Not implemented.");
|
|
14894
14191
|
},
|
|
14895
14192
|
// https://github.com/facebook/react/pull/32465
|
|
14896
14193
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14975,6 +14272,7 @@ function createRoot(canvas) {
|
|
|
14975
14272
|
const lastConfiguredProps = {};
|
|
14976
14273
|
let configured = false;
|
|
14977
14274
|
let pending = null;
|
|
14275
|
+
let rendererSetup = null;
|
|
14978
14276
|
return {
|
|
14979
14277
|
async configure(props = {}) {
|
|
14980
14278
|
let resolve;
|
|
@@ -14990,7 +14288,6 @@ function createRoot(canvas) {
|
|
|
14990
14288
|
events,
|
|
14991
14289
|
onCreated: onCreatedCallback,
|
|
14992
14290
|
shadows = false,
|
|
14993
|
-
textureColorSpace = SRGBColorSpace,
|
|
14994
14291
|
orthographic = false,
|
|
14995
14292
|
frameloop = "always",
|
|
14996
14293
|
dpr = [1, 2],
|
|
@@ -15005,7 +14302,8 @@ function createRoot(canvas) {
|
|
|
15005
14302
|
_sizeProps,
|
|
15006
14303
|
forceEven
|
|
15007
14304
|
} = props;
|
|
15008
|
-
const
|
|
14305
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
14306
|
+
let state = store.getState();
|
|
15009
14307
|
const defaultGLProps = {
|
|
15010
14308
|
canvas,
|
|
15011
14309
|
powerPreference: "high-performance",
|
|
@@ -15033,50 +14331,68 @@ function createRoot(canvas) {
|
|
|
15033
14331
|
"The `primaryCanvas` prop for multi-canvas rendering cannot be used with WebGL. Remove the `gl` prop or use WebGPU."
|
|
15034
14332
|
);
|
|
15035
14333
|
}
|
|
15036
|
-
if (
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
14334
|
+
if (!state.internal.actualRenderer) {
|
|
14335
|
+
if (!rendererSetup) {
|
|
14336
|
+
rendererSetup = (async () => {
|
|
14337
|
+
if (wantsGL) {
|
|
14338
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, WebGLRenderer);
|
|
14339
|
+
state.internal.actualRenderer = renderer;
|
|
14340
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14341
|
+
} else if (!wantsGL && primaryCanvas) {
|
|
14342
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14343
|
+
renderer = primary.renderer;
|
|
14344
|
+
state.internal.actualRenderer = renderer;
|
|
14345
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14346
|
+
primary.store.setState((prev) => ({
|
|
14347
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14348
|
+
}));
|
|
14349
|
+
state.set((prev) => ({
|
|
14350
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14351
|
+
renderer,
|
|
14352
|
+
primaryStore: primary.store,
|
|
14353
|
+
internal: {
|
|
14354
|
+
...prev.internal,
|
|
14355
|
+
canvasTarget,
|
|
14356
|
+
isMultiCanvas: true,
|
|
14357
|
+
isSecondary: true,
|
|
14358
|
+
targetId: primaryCanvas
|
|
14359
|
+
}
|
|
14360
|
+
}));
|
|
14361
|
+
} else if (!wantsGL) {
|
|
14362
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, WebGPURenderer);
|
|
14363
|
+
if (!renderer.hasInitialized?.()) {
|
|
14364
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14365
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14366
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14367
|
+
canvas.width = size2.width * pixelRatio;
|
|
14368
|
+
canvas.height = size2.height * pixelRatio;
|
|
14369
|
+
}
|
|
14370
|
+
await renderer.init();
|
|
14371
|
+
}
|
|
14372
|
+
const backend = renderer.backend;
|
|
14373
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14374
|
+
state.internal.actualRenderer = renderer;
|
|
14375
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14376
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14377
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14378
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14379
|
+
state.set((prev) => ({
|
|
14380
|
+
internal: {
|
|
14381
|
+
...prev.internal,
|
|
14382
|
+
canvasTarget,
|
|
14383
|
+
unregisterPrimary
|
|
14384
|
+
}
|
|
14385
|
+
}));
|
|
14386
|
+
}
|
|
15077
14387
|
}
|
|
15078
|
-
}))
|
|
14388
|
+
})().catch((err) => {
|
|
14389
|
+
rendererSetup = null;
|
|
14390
|
+
throw err;
|
|
14391
|
+
});
|
|
15079
14392
|
}
|
|
14393
|
+
await rendererSetup;
|
|
14394
|
+
state = store.getState();
|
|
14395
|
+
renderer = state.internal.actualRenderer;
|
|
15080
14396
|
}
|
|
15081
14397
|
let raycaster = state.raycaster;
|
|
15082
14398
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
@@ -15169,7 +14485,7 @@ function createRoot(canvas) {
|
|
|
15169
14485
|
lastConfiguredProps.performance = performance;
|
|
15170
14486
|
}
|
|
15171
14487
|
if (!state.xr) {
|
|
15172
|
-
const handleXRFrame = (timestamp,
|
|
14488
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15173
14489
|
const state2 = store.getState();
|
|
15174
14490
|
if (state2.frameloop === "never") return;
|
|
15175
14491
|
advance(timestamp);
|
|
@@ -15205,15 +14521,22 @@ function createRoot(canvas) {
|
|
|
15205
14521
|
const oldType = renderer.shadowMap.type;
|
|
15206
14522
|
renderer.shadowMap.enabled = !!shadows;
|
|
15207
14523
|
if (is.boo(shadows)) {
|
|
15208
|
-
renderer.shadowMap.type =
|
|
14524
|
+
renderer.shadowMap.type = PCFShadowMap;
|
|
15209
14525
|
} else if (is.str(shadows)) {
|
|
14526
|
+
if (shadows === "soft") {
|
|
14527
|
+
notifyDepreciated({
|
|
14528
|
+
heading: 'shadows="soft" is deprecated',
|
|
14529
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14530
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14531
|
+
});
|
|
14532
|
+
}
|
|
15210
14533
|
const types = {
|
|
15211
14534
|
basic: BasicShadowMap,
|
|
15212
14535
|
percentage: PCFShadowMap,
|
|
15213
|
-
soft:
|
|
14536
|
+
soft: PCFShadowMap,
|
|
15214
14537
|
variance: VSMShadowMap
|
|
15215
14538
|
};
|
|
15216
|
-
renderer.shadowMap.type = types[shadows] ??
|
|
14539
|
+
renderer.shadowMap.type = types[shadows] ?? PCFShadowMap;
|
|
15217
14540
|
} else if (is.obj(shadows)) {
|
|
15218
14541
|
Object.assign(renderer.shadowMap, shadows);
|
|
15219
14542
|
}
|
|
@@ -15229,13 +14552,24 @@ function createRoot(canvas) {
|
|
|
15229
14552
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15230
14553
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15231
14554
|
}
|
|
14555
|
+
const r3fProps = ["textureColorSpace"];
|
|
14556
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14557
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15232
14558
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15233
|
-
|
|
14559
|
+
const glProps = {};
|
|
14560
|
+
for (const key in glConfig) {
|
|
14561
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14562
|
+
}
|
|
14563
|
+
applyProps(renderer, glProps);
|
|
15234
14564
|
}
|
|
15235
14565
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15236
14566
|
const currentRenderer = state.renderer;
|
|
15237
14567
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15238
|
-
|
|
14568
|
+
const rendererProps = {};
|
|
14569
|
+
for (const key in rendererConfig) {
|
|
14570
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14571
|
+
}
|
|
14572
|
+
applyProps(currentRenderer, rendererProps);
|
|
15239
14573
|
}
|
|
15240
14574
|
}
|
|
15241
14575
|
const scheduler = getScheduler();
|
|
@@ -15261,6 +14595,18 @@ function createRoot(canvas) {
|
|
|
15261
14595
|
system: true
|
|
15262
14596
|
}
|
|
15263
14597
|
);
|
|
14598
|
+
const unregisterEventsFlush = scheduler.register(
|
|
14599
|
+
() => {
|
|
14600
|
+
const state2 = store.getState();
|
|
14601
|
+
state2.events.flush?.();
|
|
14602
|
+
},
|
|
14603
|
+
{
|
|
14604
|
+
id: `${newRootId}_events`,
|
|
14605
|
+
rootId: newRootId,
|
|
14606
|
+
phase: "input",
|
|
14607
|
+
system: true
|
|
14608
|
+
}
|
|
14609
|
+
);
|
|
15264
14610
|
const unregisterFrustum = scheduler.register(
|
|
15265
14611
|
() => {
|
|
15266
14612
|
const state2 = store.getState();
|
|
@@ -15271,7 +14617,7 @@ function createRoot(canvas) {
|
|
|
15271
14617
|
{
|
|
15272
14618
|
id: `${newRootId}_frustum`,
|
|
15273
14619
|
rootId: newRootId,
|
|
15274
|
-
|
|
14620
|
+
before: "render",
|
|
15275
14621
|
system: true
|
|
15276
14622
|
}
|
|
15277
14623
|
);
|
|
@@ -15283,7 +14629,7 @@ function createRoot(canvas) {
|
|
|
15283
14629
|
{
|
|
15284
14630
|
id: `${newRootId}_visibility`,
|
|
15285
14631
|
rootId: newRootId,
|
|
15286
|
-
|
|
14632
|
+
before: "render",
|
|
15287
14633
|
system: true,
|
|
15288
14634
|
after: `${newRootId}_frustum`
|
|
15289
14635
|
}
|
|
@@ -15295,7 +14641,7 @@ function createRoot(canvas) {
|
|
|
15295
14641
|
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
15296
14642
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15297
14643
|
try {
|
|
15298
|
-
if (state2.
|
|
14644
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15299
14645
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15300
14646
|
} catch (error) {
|
|
15301
14647
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15320,6 +14666,7 @@ function createRoot(canvas) {
|
|
|
15320
14666
|
unregisterRoot: () => {
|
|
15321
14667
|
unregisterRoot();
|
|
15322
14668
|
unregisterCanvasTarget();
|
|
14669
|
+
unregisterEventsFlush();
|
|
15323
14670
|
unregisterFrustum();
|
|
15324
14671
|
unregisterVisibility();
|
|
15325
14672
|
unregisterRender();
|
|
@@ -15395,7 +14742,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
15395
14742
|
dispose(state.scene);
|
|
15396
14743
|
_roots.delete(canvas);
|
|
15397
14744
|
if (callback) callback(canvas);
|
|
15398
|
-
} catch {
|
|
14745
|
+
} catch (error) {
|
|
14746
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
15399
14747
|
}
|
|
15400
14748
|
}, 500);
|
|
15401
14749
|
}
|
|
@@ -15458,6 +14806,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15458
14806
|
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
15459
14807
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15460
14808
|
}
|
|
14809
|
+
const set = injectState.set;
|
|
15461
14810
|
return {
|
|
15462
14811
|
// The intersect consists of the previous root state
|
|
15463
14812
|
...rootState,
|
|
@@ -15476,7 +14825,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15476
14825
|
size: resolvedSize,
|
|
15477
14826
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15478
14827
|
// Layers are allowed to override events
|
|
15479
|
-
setEvents: (events2) =>
|
|
14828
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15480
14829
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15481
14830
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15482
14831
|
};
|
|
@@ -15485,9 +14834,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15485
14834
|
const store = createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15486
14835
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15487
14836
|
onMutate(previousRoot.getState());
|
|
15488
|
-
previousRoot.subscribe(onMutate);
|
|
15489
14837
|
return store;
|
|
15490
14838
|
}, [previousRoot, container]);
|
|
14839
|
+
useIsomorphicLayoutEffect(() => {
|
|
14840
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14841
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14842
|
+
return unsubscribe;
|
|
14843
|
+
}, [previousRoot, usePortalStore]);
|
|
15491
14844
|
return (
|
|
15492
14845
|
// @ts-ignore, reconciler types are not maintained
|
|
15493
14846
|
/* @__PURE__ */ jsx(Fragment, { children: reconciler.createPortal(
|
|
@@ -15501,6 +14854,81 @@ function flushSync(fn) {
|
|
|
15501
14854
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15502
14855
|
}
|
|
15503
14856
|
|
|
14857
|
+
function parseBackground(background) {
|
|
14858
|
+
if (!background) return null;
|
|
14859
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14860
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14861
|
+
return {
|
|
14862
|
+
...rest,
|
|
14863
|
+
preset,
|
|
14864
|
+
files: envMap || files,
|
|
14865
|
+
backgroundFiles: backgroundMap,
|
|
14866
|
+
background: true
|
|
14867
|
+
};
|
|
14868
|
+
}
|
|
14869
|
+
if (typeof background === "number") {
|
|
14870
|
+
return { color: background, background: true };
|
|
14871
|
+
}
|
|
14872
|
+
if (typeof background === "string") {
|
|
14873
|
+
if (background in presetsObj) {
|
|
14874
|
+
return { preset: background, background: true };
|
|
14875
|
+
}
|
|
14876
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14877
|
+
return { files: background, background: true };
|
|
14878
|
+
}
|
|
14879
|
+
return { color: background, background: true };
|
|
14880
|
+
}
|
|
14881
|
+
if (background.isColor) {
|
|
14882
|
+
return { color: background, background: true };
|
|
14883
|
+
}
|
|
14884
|
+
return null;
|
|
14885
|
+
}
|
|
14886
|
+
|
|
14887
|
+
function parseRendererConfig(rendererProp) {
|
|
14888
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14889
|
+
if (isRendererConfig) {
|
|
14890
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14891
|
+
return {
|
|
14892
|
+
primaryCanvas: pc,
|
|
14893
|
+
scheduler: sc,
|
|
14894
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14895
|
+
};
|
|
14896
|
+
}
|
|
14897
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14898
|
+
}
|
|
14899
|
+
|
|
14900
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14901
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14902
|
+
function getKindRegistry(store, kind) {
|
|
14903
|
+
let registry = registries.get(store);
|
|
14904
|
+
if (!registry) {
|
|
14905
|
+
registry = {
|
|
14906
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14907
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14908
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14909
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14910
|
+
};
|
|
14911
|
+
registries.set(store, registry);
|
|
14912
|
+
}
|
|
14913
|
+
return registry[kind];
|
|
14914
|
+
}
|
|
14915
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14916
|
+
const registry = getKindRegistry(store, kind);
|
|
14917
|
+
{
|
|
14918
|
+
registry.valid.clear();
|
|
14919
|
+
registry.staged.clear();
|
|
14920
|
+
}
|
|
14921
|
+
}
|
|
14922
|
+
function invalidateAllResources(store) {
|
|
14923
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14924
|
+
}
|
|
14925
|
+
|
|
14926
|
+
function clearHmrCaches(store) {
|
|
14927
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14928
|
+
invalidateAllResources(primary);
|
|
14929
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14930
|
+
}
|
|
14931
|
+
|
|
15504
14932
|
function CanvasImpl({
|
|
15505
14933
|
ref,
|
|
15506
14934
|
children,
|
|
@@ -15521,6 +14949,8 @@ function CanvasImpl({
|
|
|
15521
14949
|
raycaster,
|
|
15522
14950
|
camera,
|
|
15523
14951
|
scene,
|
|
14952
|
+
autoUpdateFrustum,
|
|
14953
|
+
occlusion,
|
|
15524
14954
|
onPointerMissed,
|
|
15525
14955
|
onDragOverMissed,
|
|
15526
14956
|
onDropMissed,
|
|
@@ -15532,39 +14962,10 @@ function CanvasImpl({
|
|
|
15532
14962
|
forceEven,
|
|
15533
14963
|
...props
|
|
15534
14964
|
}) {
|
|
15535
|
-
const { primaryCanvas, scheduler,
|
|
15536
|
-
const renderer = Object.keys(rendererConfig).length > 0 ? rendererConfig : rendererProp;
|
|
14965
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15537
14966
|
React.useMemo(() => extend(THREE), []);
|
|
15538
14967
|
const Bridge = useBridge();
|
|
15539
|
-
const backgroundProps = React.useMemo(() =>
|
|
15540
|
-
if (!background) return null;
|
|
15541
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15542
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15543
|
-
return {
|
|
15544
|
-
...rest,
|
|
15545
|
-
preset,
|
|
15546
|
-
files: envMap || files,
|
|
15547
|
-
backgroundFiles: backgroundMap,
|
|
15548
|
-
background: true
|
|
15549
|
-
};
|
|
15550
|
-
}
|
|
15551
|
-
if (typeof background === "number") {
|
|
15552
|
-
return { color: background, background: true };
|
|
15553
|
-
}
|
|
15554
|
-
if (typeof background === "string") {
|
|
15555
|
-
if (background in presetsObj) {
|
|
15556
|
-
return { preset: background, background: true };
|
|
15557
|
-
}
|
|
15558
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15559
|
-
return { files: background, background: true };
|
|
15560
|
-
}
|
|
15561
|
-
return { color: background, background: true };
|
|
15562
|
-
}
|
|
15563
|
-
if (background.isColor) {
|
|
15564
|
-
return { color: background, background: true };
|
|
15565
|
-
}
|
|
15566
|
-
return null;
|
|
15567
|
-
}, [background]);
|
|
14968
|
+
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15568
14969
|
const hasInitialSizeRef = React.useRef(false);
|
|
15569
14970
|
const measureConfig = React.useMemo(() => {
|
|
15570
14971
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15606,6 +15007,7 @@ function CanvasImpl({
|
|
|
15606
15007
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15607
15008
|
const [block, setBlock] = React.useState(false);
|
|
15608
15009
|
const [error, setError] = React.useState(false);
|
|
15010
|
+
const [fallbackVisible, setFallbackVisible] = React.useState(false);
|
|
15609
15011
|
if (block) throw block;
|
|
15610
15012
|
if (error) throw error;
|
|
15611
15013
|
const root = React.useRef(null);
|
|
@@ -15613,6 +15015,7 @@ function CanvasImpl({
|
|
|
15613
15015
|
const unsubscribeErrorRef = React.useRef(null);
|
|
15614
15016
|
useIsomorphicLayoutEffect(() => {
|
|
15615
15017
|
effectActiveRef.current = true;
|
|
15018
|
+
if (fallbackVisible) return;
|
|
15616
15019
|
const canvas = canvasRef.current;
|
|
15617
15020
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15618
15021
|
if (!root.current) {
|
|
@@ -15633,7 +15036,7 @@ function CanvasImpl({
|
|
|
15633
15036
|
}
|
|
15634
15037
|
async function run() {
|
|
15635
15038
|
if (!effectActiveRef.current || !root.current) return;
|
|
15636
|
-
await root.current.configure({
|
|
15039
|
+
const configured = await root.current.configure({
|
|
15637
15040
|
id,
|
|
15638
15041
|
primaryCanvas,
|
|
15639
15042
|
scheduler,
|
|
@@ -15648,6 +15051,8 @@ function CanvasImpl({
|
|
|
15648
15051
|
performance,
|
|
15649
15052
|
raycaster,
|
|
15650
15053
|
camera,
|
|
15054
|
+
autoUpdateFrustum,
|
|
15055
|
+
occlusion,
|
|
15651
15056
|
size: effectiveSize,
|
|
15652
15057
|
// Store size props for reset functionality
|
|
15653
15058
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15672,8 +15077,20 @@ function CanvasImpl({
|
|
|
15672
15077
|
}
|
|
15673
15078
|
onCreated?.(state);
|
|
15674
15079
|
}
|
|
15675
|
-
})
|
|
15676
|
-
|
|
15080
|
+
}).then(
|
|
15081
|
+
() => true,
|
|
15082
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15083
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15084
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15085
|
+
(setupError) => {
|
|
15086
|
+
if (effectActiveRef.current) {
|
|
15087
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15088
|
+
else setError(setupError);
|
|
15089
|
+
}
|
|
15090
|
+
return false;
|
|
15091
|
+
}
|
|
15092
|
+
);
|
|
15093
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15677
15094
|
root.current.render(
|
|
15678
15095
|
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
15679
15096
|
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
@@ -15707,20 +15124,13 @@ function CanvasImpl({
|
|
|
15707
15124
|
const handleHMR = () => {
|
|
15708
15125
|
queueMicrotask(() => {
|
|
15709
15126
|
const rootEntry = _roots.get(canvas);
|
|
15710
|
-
if (rootEntry?.store)
|
|
15711
|
-
rootEntry.store.setState((state) => ({
|
|
15712
|
-
nodes: {},
|
|
15713
|
-
uniforms: {},
|
|
15714
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15715
|
-
}));
|
|
15716
|
-
}
|
|
15127
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15717
15128
|
});
|
|
15718
15129
|
};
|
|
15719
15130
|
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
15720
15131
|
const hot = import.meta.hot;
|
|
15721
15132
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15722
|
-
return () => hot.
|
|
15723
|
-
});
|
|
15133
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15724
15134
|
}
|
|
15725
15135
|
if (typeof module !== "undefined" && module.hot) {
|
|
15726
15136
|
const hot = module.hot;
|
|
@@ -15743,7 +15153,20 @@ function CanvasImpl({
|
|
|
15743
15153
|
...style
|
|
15744
15154
|
},
|
|
15745
15155
|
...props,
|
|
15746
|
-
children:
|
|
15156
|
+
children: fallbackVisible ? (
|
|
15157
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15158
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15159
|
+
fallback
|
|
15160
|
+
) : /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
15161
|
+
"canvas",
|
|
15162
|
+
{
|
|
15163
|
+
ref: canvasRef,
|
|
15164
|
+
id,
|
|
15165
|
+
className: "r3f-canvas",
|
|
15166
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
15167
|
+
children: fallback
|
|
15168
|
+
}
|
|
15169
|
+
) })
|
|
15747
15170
|
}
|
|
15748
15171
|
);
|
|
15749
15172
|
}
|
|
@@ -15753,4 +15176,4 @@ function Canvas(props) {
|
|
|
15753
15176
|
|
|
15754
15177
|
extend(THREE);
|
|
15755
15178
|
|
|
15756
|
-
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS,
|
|
15179
|
+
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, reconciler, registerPrimary, removeInteractivity, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
|