@react-three/fiber 10.0.0-alpha.1 → 10.0.0-alpha.2

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.
@@ -46,9 +46,9 @@ const THREE = /*#__PURE__*/_mergeNamespaces({
46
46
  WebGLRenderer: WebGLRenderer
47
47
  }, [webgpu]);
48
48
 
49
- var __defProp$2 = Object.defineProperty;
50
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
51
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
49
+ var __defProp$3 = Object.defineProperty;
50
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
51
+ var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
52
52
  const act = React["act"];
53
53
  const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
54
54
  function useMutableCallback(fn) {
@@ -80,7 +80,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
80
80
  return _a = class extends React.Component {
81
81
  constructor() {
82
82
  super(...arguments);
83
- __publicField$2(this, "state", { error: false });
83
+ __publicField$3(this, "state", { error: false });
84
84
  }
85
85
  componentDidCatch(err) {
86
86
  this.props.set(err);
@@ -88,7 +88,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
88
88
  render() {
89
89
  return this.state.error ? null : this.props.children;
90
90
  }
91
- }, __publicField$2(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
91
+ }, __publicField$3(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
92
92
  })();
93
93
 
94
94
  const is = {
@@ -538,7 +538,7 @@ function applyProps(object, props) {
538
538
  const rootState = instance && findInitialRoot(instance).getState();
539
539
  const prevHandlers = instance?.eventCount;
540
540
  for (const prop in props) {
541
- let value = props[prop];
541
+ const value = props[prop];
542
542
  if (RESERVED_PROPS.includes(prop)) continue;
543
543
  if (instance && EVENT_REGEX.test(prop)) {
544
544
  if (typeof value === "function") instance.handlers[prop] = value;
@@ -690,13 +690,14 @@ function createEvents(store) {
690
690
  for (const hit of hits) {
691
691
  let eventObject = hit.object;
692
692
  while (eventObject) {
693
- if (eventObject.__r3f?.eventCount)
693
+ if (eventObject.__r3f?.eventCount) {
694
694
  intersections.push({ ...hit, eventObject });
695
+ }
695
696
  eventObject = eventObject.parent;
696
697
  }
697
698
  }
698
699
  if ("pointerId" in event && state.internal.capturedMap.has(event.pointerId)) {
699
- for (let captureData of state.internal.capturedMap.get(event.pointerId).values()) {
700
+ for (const captureData of state.internal.capturedMap.get(event.pointerId).values()) {
700
701
  if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
701
702
  }
702
703
  }
@@ -726,12 +727,12 @@ function createEvents(store) {
726
727
  releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
727
728
  }
728
729
  };
729
- let extractEventProps = {};
730
- for (let prop in event) {
731
- let property = event[prop];
730
+ const extractEventProps = {};
731
+ for (const prop in event) {
732
+ const property = event[prop];
732
733
  if (typeof property !== "function") extractEventProps[prop] = property;
733
734
  }
734
- let raycastEvent = {
735
+ const raycastEvent = {
735
736
  ...hit,
736
737
  ...extractEventProps,
737
738
  pointer,
@@ -1114,10 +1115,38 @@ const createStore = (invalidate, advance) => {
1114
1115
  getCurrentViewport
1115
1116
  },
1116
1117
  setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
1117
- setSize: (width, height, top = 0, left = 0) => {
1118
- const camera = get().camera;
1119
- const size = { width, height, top, left };
1120
- set((state2) => ({ size, viewport: { ...state2.viewport, ...getCurrentViewport(camera, defaultTarget, size) } }));
1118
+ setSize: (width, height, top, left) => {
1119
+ const state2 = get();
1120
+ if (width === void 0) {
1121
+ set({ _sizeImperative: false });
1122
+ if (state2._sizeProps) {
1123
+ const { width: propW, height: propH } = state2._sizeProps;
1124
+ if (propW !== void 0 || propH !== void 0) {
1125
+ const currentSize = state2.size;
1126
+ const newSize = {
1127
+ width: propW ?? currentSize.width,
1128
+ height: propH ?? currentSize.height,
1129
+ top: currentSize.top,
1130
+ left: currentSize.left
1131
+ };
1132
+ set((s) => ({
1133
+ size: newSize,
1134
+ viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
1135
+ }));
1136
+ }
1137
+ }
1138
+ return;
1139
+ }
1140
+ const w = width;
1141
+ const h = height ?? width;
1142
+ const t = top ?? state2.size.top;
1143
+ const l = left ?? state2.size.left;
1144
+ const size = { width: w, height: h, top: t, left: l };
1145
+ set((s) => ({
1146
+ size,
1147
+ viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
1148
+ _sizeImperative: true
1149
+ }));
1121
1150
  },
1122
1151
  setDpr: (dpr) => set((state2) => {
1123
1152
  const resolved = calculateDpr(dpr);
@@ -1134,6 +1163,9 @@ const createStore = (invalidate, advance) => {
1134
1163
  textures: /* @__PURE__ */ new Map(),
1135
1164
  postProcessing: null,
1136
1165
  passes: {},
1166
+ _hmrVersion: 0,
1167
+ _sizeImperative: false,
1168
+ _sizeProps: null,
1137
1169
  previousRoot: void 0,
1138
1170
  internal: {
1139
1171
  // Events
@@ -1303,18 +1335,18 @@ useLoader.clear = function(loader, input) {
1303
1335
  };
1304
1336
  useLoader.loader = getLoader;
1305
1337
 
1306
- var __defProp$1 = Object.defineProperty;
1307
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1308
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1338
+ var __defProp$2 = Object.defineProperty;
1339
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1340
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1309
1341
  const DEFAULT_PHASES = ["start", "input", "physics", "update", "render", "finish"];
1310
1342
  class PhaseGraph {
1311
1343
  constructor() {
1312
1344
  /** Ordered list of phase nodes */
1313
- __publicField$1(this, "phases", []);
1345
+ __publicField$2(this, "phases", []);
1314
1346
  /** Quick lookup by name */
1315
- __publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
1347
+ __publicField$2(this, "phaseMap", /* @__PURE__ */ new Map());
1316
1348
  /** Cached ordered names (invalidated on changes) */
1317
- __publicField$1(this, "orderedNamesCache", null);
1349
+ __publicField$2(this, "orderedNamesCache", null);
1318
1350
  this.initializeDefaultPhases();
1319
1351
  }
1320
1352
  //* Initialization --------------------------------
@@ -1341,8 +1373,9 @@ class PhaseGraph {
1341
1373
  const node = { name, isAutoGenerated: false };
1342
1374
  let insertIndex = this.phases.length;
1343
1375
  const targetIndex = this.getPhaseIndex(before ?? after);
1344
- if (targetIndex !== -1) insertIndex = before ? targetIndex : targetIndex + 1;
1345
- else {
1376
+ if (targetIndex !== -1) {
1377
+ insertIndex = before ? targetIndex : targetIndex + 1;
1378
+ } else {
1346
1379
  const constraintType = before ? "before" : "after";
1347
1380
  console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
1348
1381
  }
@@ -1570,9 +1603,9 @@ function resetJobTiming(job) {
1570
1603
  job.lastRun = void 0;
1571
1604
  }
1572
1605
 
1573
- var __defProp = Object.defineProperty;
1574
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1575
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1606
+ var __defProp$1 = Object.defineProperty;
1607
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1608
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1576
1609
  const hmrData = (() => {
1577
1610
  if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
1578
1611
  if (typeof import_meta_hot !== "undefined") return import_meta_hot;
@@ -1586,9 +1619,9 @@ const _Scheduler = class _Scheduler {
1586
1619
  //* Constructor ================================
1587
1620
  constructor() {
1588
1621
  //* Critical State ================================
1589
- __publicField(this, "roots", /* @__PURE__ */ new Map());
1590
- __publicField(this, "phaseGraph");
1591
- __publicField(this, "loopState", {
1622
+ __publicField$1(this, "roots", /* @__PURE__ */ new Map());
1623
+ __publicField$1(this, "phaseGraph");
1624
+ __publicField$1(this, "loopState", {
1592
1625
  running: false,
1593
1626
  rafHandle: null,
1594
1627
  lastTime: null,
@@ -1597,21 +1630,21 @@ const _Scheduler = class _Scheduler {
1597
1630
  elapsedTime: 0,
1598
1631
  createdAt: performance.now()
1599
1632
  });
1600
- __publicField(this, "stoppedTime", 0);
1633
+ __publicField$1(this, "stoppedTime", 0);
1601
1634
  //* Private State ================================
1602
- __publicField(this, "nextRootIndex", 0);
1603
- __publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
1604
- __publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
1605
- __publicField(this, "nextGlobalIndex", 0);
1606
- __publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
1607
- __publicField(this, "nextJobIndex", 0);
1608
- __publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
1609
- __publicField(this, "pendingFrames", 0);
1610
- __publicField(this, "_frameloop", "always");
1635
+ __publicField$1(this, "nextRootIndex", 0);
1636
+ __publicField$1(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
1637
+ __publicField$1(this, "globalAfterJobs", /* @__PURE__ */ new Map());
1638
+ __publicField$1(this, "nextGlobalIndex", 0);
1639
+ __publicField$1(this, "idleCallbacks", /* @__PURE__ */ new Set());
1640
+ __publicField$1(this, "nextJobIndex", 0);
1641
+ __publicField$1(this, "jobStateListeners", /* @__PURE__ */ new Map());
1642
+ __publicField$1(this, "pendingFrames", 0);
1643
+ __publicField$1(this, "_frameloop", "always");
1611
1644
  //* Independent Mode & Error Handling State ================================
1612
- __publicField(this, "_independent", false);
1613
- __publicField(this, "errorHandler", null);
1614
- __publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
1645
+ __publicField$1(this, "_independent", false);
1646
+ __publicField$1(this, "errorHandler", null);
1647
+ __publicField$1(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
1615
1648
  //* Core Loop Execution Methods ================================
1616
1649
  /**
1617
1650
  * Main RAF loop callback.
@@ -1620,7 +1653,7 @@ const _Scheduler = class _Scheduler {
1620
1653
  * @returns {void}
1621
1654
  * @private
1622
1655
  */
1623
- __publicField(this, "loop", (timestamp) => {
1656
+ __publicField$1(this, "loop", (timestamp) => {
1624
1657
  if (!this.loopState.running) return;
1625
1658
  this.executeFrame(timestamp);
1626
1659
  if (this._frameloop === "demand") {
@@ -2327,7 +2360,7 @@ const _Scheduler = class _Scheduler {
2327
2360
  //* Cross-Bundle Singleton Key ==============================
2328
2361
  // Use Symbol.for() to ensure scheduler is shared across bundle boundaries
2329
2362
  // This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
2330
- __publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
2363
+ __publicField$1(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
2331
2364
  let Scheduler = _Scheduler;
2332
2365
  const getScheduler = () => Scheduler.get();
2333
2366
  if (hmrData) {
@@ -2753,24 +2786,14 @@ function advance(timestamp, runGlobalEffects = true, state, frame) {
2753
2786
  getScheduler().step(timestamp);
2754
2787
  }
2755
2788
 
2756
- const version = "10.0.0-alpha.1";
2789
+ const version = "10.0.0-alpha.2";
2757
2790
  const packageData = {
2758
2791
  version: version};
2759
2792
 
2760
2793
  function Xb(Tt) {
2761
2794
  return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
2762
2795
  }
2763
- var Rm = { exports: {} }, Og = { exports: {} };
2764
- /**
2765
- * @license React
2766
- * react-reconciler.production.js
2767
- *
2768
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2769
- *
2770
- * This source code is licensed under the MIT license found in the
2771
- * LICENSE file in the root directory of this source tree.
2772
- */
2773
- var _b;
2796
+ var Rm = { exports: {} }, Og = { exports: {} }, _b;
2774
2797
  function Kb() {
2775
2798
  return _b || (_b = 1, (function(Tt) {
2776
2799
  Tt.exports = function(m) {
@@ -3842,7 +3865,6 @@ Error generating stack: ` + l.message + `
3842
3865
  if (J === cl || J === jc) throw J;
3843
3866
  var Ge = Yn(29, J, null, P.mode);
3844
3867
  return Ge.lanes = H, Ge.return = P, Ge;
3845
- } finally {
3846
3868
  }
3847
3869
  };
3848
3870
  }
@@ -4496,7 +4518,6 @@ Error generating stack: ` + l.message + `
4496
4518
  var h = r.lastRenderedState, y = d(h, a);
4497
4519
  if (c.hasEagerState = true, c.eagerState = y, jn(y, h)) return go(t, r, c, 0), Ne === null && Bn(), false;
4498
4520
  } catch {
4499
- } finally {
4500
4521
  }
4501
4522
  if (a = yo(t, r, c, l), a !== null) return nt(a, t, l), ns(a, r, l), true;
4502
4523
  }
@@ -6917,10 +6938,7 @@ Error generating stack: ` + l.message + `
6917
6938
  function vr(t, r) {
6918
6939
  Sf(t, r), (t = t.alternate) && Sf(t, r);
6919
6940
  }
6920
- var ie = {}, Fm = React__default, tt = Tb, Lt = Object.assign, hc = Symbol.for("react.element"), zs = Symbol.for("react.transitional.element"), sa = Symbol.for("react.portal"), $a = Symbol.for("react.fragment"), kf = Symbol.for("react.strict_mode"), Cs = Symbol.for("react.profiler"), mc = Symbol.for("react.consumer"), Io = Symbol.for("react.context"), Zi = Symbol.for("react.forward_ref"), Va = Symbol.for("react.suspense"), Te = Symbol.for("react.suspense_list"), wf = Symbol.for("react.memo"), ua = Symbol.for("react.lazy");
6921
- var gc = Symbol.for("react.activity");
6922
- var $r = Symbol.for("react.memo_cache_sentinel");
6923
- var Pf = Symbol.iterator, xf = Symbol.for("react.client.reference"), ca = Array.isArray, M = Fm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Yp = m.rendererVersion, zf = m.rendererPackageName, Cf = m.extraDevToolsConfig, Ts = m.getPublicInstance, Hm = m.getRootHostContext, Xp = m.getChildHostContext, Am = m.prepareForCommit, _s = m.resetAfterCommit, Vr = m.createInstance;
6941
+ var ie = {}, Fm = React__default, tt = Tb, Lt = Object.assign, hc = Symbol.for("react.element"), zs = Symbol.for("react.transitional.element"), sa = Symbol.for("react.portal"), $a = Symbol.for("react.fragment"), kf = Symbol.for("react.strict_mode"), Cs = Symbol.for("react.profiler"), mc = Symbol.for("react.consumer"), Io = Symbol.for("react.context"), Zi = Symbol.for("react.forward_ref"), Va = Symbol.for("react.suspense"), Te = Symbol.for("react.suspense_list"), wf = Symbol.for("react.memo"), ua = Symbol.for("react.lazy"), gc = Symbol.for("react.activity"), $r = Symbol.for("react.memo_cache_sentinel"), Pf = Symbol.iterator, xf = Symbol.for("react.client.reference"), ca = Array.isArray, M = Fm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Yp = m.rendererVersion, zf = m.rendererPackageName, Cf = m.extraDevToolsConfig, Ts = m.getPublicInstance, Hm = m.getRootHostContext, Xp = m.getChildHostContext, Am = m.prepareForCommit, _s = m.resetAfterCommit, Vr = m.createInstance;
6924
6942
  m.cloneMutableInstance;
6925
6943
  var yc = m.appendInitialChild, Kp = m.finalizeInitialChildren, Rs = m.shouldSetTextContent, bc = m.createTextInstance;
6926
6944
  m.cloneMutableTextInstance;
@@ -7289,17 +7307,7 @@ No matching component was found for:
7289
7307
  }, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true });
7290
7308
  })(Og)), Og.exports;
7291
7309
  }
7292
- var Mg = { exports: {} };
7293
- /**
7294
- * @license React
7295
- * react-reconciler.development.js
7296
- *
7297
- * Copyright (c) Meta Platforms, Inc. and affiliates.
7298
- *
7299
- * This source code is licensed under the MIT license found in the
7300
- * LICENSE file in the root directory of this source tree.
7301
- */
7302
- var Rb;
7310
+ var Mg = { exports: {} }, Rb;
7303
7311
  function e0() {
7304
7312
  return Rb || (Rb = 1, (function(Tt) {
7305
7313
  process.env.NODE_ENV !== "production" && (Tt.exports = function(m) {
@@ -13066,10 +13074,7 @@ Check the render method of %s.`, G(di) || "Unknown")), i = zo(n), i.payload = {
13066
13074
  function Ic() {
13067
13075
  return di;
13068
13076
  }
13069
- var le = {}, qm = React__default, St = Tb, ze = Object.assign, Uh = Symbol.for("react.element"), Ho = Symbol.for("react.transitional.element"), Ao = Symbol.for("react.portal"), ol = Symbol.for("react.fragment"), Lc = Symbol.for("react.strict_mode"), Uf = Symbol.for("react.profiler"), ei = Symbol.for("react.consumer"), on = Symbol.for("react.context"), jn = Symbol.for("react.forward_ref"), Nc = Symbol.for("react.suspense"), Bf = Symbol.for("react.suspense_list"), al = Symbol.for("react.memo"), kt = Symbol.for("react.lazy");
13070
- var Ds = Symbol.for("react.activity");
13071
- var Bh = Symbol.for("react.memo_cache_sentinel");
13072
- var ni = Symbol.iterator, il = Symbol.for("react.client.reference"), fn = Array.isArray, x = qm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Jt = m.rendererVersion, Zt = m.rendererPackageName, jo = m.extraDevToolsConfig, ot = m.getPublicInstance, Zr = m.getRootHostContext, Dn = m.getChildHostContext, Ws = m.prepareForCommit, pa = m.resetAfterCommit, Fc = m.createInstance;
13077
+ var le = {}, qm = React__default, St = Tb, ze = Object.assign, Uh = Symbol.for("react.element"), Ho = Symbol.for("react.transitional.element"), Ao = Symbol.for("react.portal"), ol = Symbol.for("react.fragment"), Lc = Symbol.for("react.strict_mode"), Uf = Symbol.for("react.profiler"), ei = Symbol.for("react.consumer"), on = Symbol.for("react.context"), jn = Symbol.for("react.forward_ref"), Nc = Symbol.for("react.suspense"), Bf = Symbol.for("react.suspense_list"), al = Symbol.for("react.memo"), kt = Symbol.for("react.lazy"), Ds = Symbol.for("react.activity"), Bh = Symbol.for("react.memo_cache_sentinel"), ni = Symbol.iterator, il = Symbol.for("react.client.reference"), fn = Array.isArray, x = qm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Jt = m.rendererVersion, Zt = m.rendererPackageName, jo = m.extraDevToolsConfig, ot = m.getPublicInstance, Zr = m.getRootHostContext, Dn = m.getChildHostContext, Ws = m.prepareForCommit, pa = m.resetAfterCommit, Fc = m.createInstance;
13073
13078
  m.cloneMutableInstance;
13074
13079
  var bn = m.appendInitialChild, Ue = m.finalizeInitialChildren, ue = m.shouldSetTextContent, Do = m.createTextInstance;
13075
13080
  m.cloneMutableTextInstance;
@@ -14037,15 +14042,6 @@ function n0() {
14037
14042
  var t0 = n0();
14038
14043
  const r0 = Xb(t0);
14039
14044
 
14040
- /**
14041
- * @license React
14042
- * react-reconciler-constants.production.js
14043
- *
14044
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14045
- *
14046
- * This source code is licensed under the MIT license found in the
14047
- * LICENSE file in the root directory of this source tree.
14048
- */
14049
14045
  const t = 1, o = 8, r = 32, e = 2;
14050
14046
 
14051
14047
  function createReconciler(config) {
@@ -14072,10 +14068,11 @@ function extend(objects) {
14072
14068
  function validateInstance(type, props) {
14073
14069
  const name = toPascalCase(type);
14074
14070
  const target = catalogue[name];
14075
- if (type !== "primitive" && !target)
14071
+ if (type !== "primitive" && !target) {
14076
14072
  throw new Error(
14077
14073
  `R3F: ${name} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`
14078
14074
  );
14075
+ }
14079
14076
  if (type === "primitive" && !props.object) throw new Error(`R3F: Primitives without 'object' are invalid!`);
14080
14077
  if (props.args !== void 0 && !Array.isArray(props.args)) throw new Error("R3F: The args prop must be an array!");
14081
14078
  }
@@ -14526,14 +14523,14 @@ function createRoot(canvas) {
14526
14523
  if (!prevRoot) _roots.set(canvas, { fiber, store });
14527
14524
  let onCreated;
14528
14525
  let lastCamera;
14529
- let lastConfiguredProps = {};
14526
+ const lastConfiguredProps = {};
14530
14527
  let configured = false;
14531
14528
  let pending = null;
14532
14529
  return {
14533
14530
  async configure(props = {}) {
14534
14531
  let resolve;
14535
14532
  pending = new Promise((_resolve) => resolve = _resolve);
14536
- let {
14533
+ const {
14537
14534
  gl: glConfig,
14538
14535
  renderer: rendererConfig,
14539
14536
  size: propsSize,
@@ -14555,9 +14552,10 @@ function createRoot(canvas) {
14555
14552
  onDragOverMissed,
14556
14553
  onDropMissed,
14557
14554
  autoUpdateFrustum = true,
14558
- occlusion = false
14555
+ occlusion = false,
14556
+ _sizeProps
14559
14557
  } = props;
14560
- let state = store.getState();
14558
+ const state = store.getState();
14561
14559
  const defaultGPUProps = {
14562
14560
  canvas
14563
14561
  };
@@ -14584,8 +14582,9 @@ function createRoot(canvas) {
14584
14582
  if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
14585
14583
  const { params, ...options } = raycastOptions || {};
14586
14584
  if (!is.equ(options, raycaster, shallowLoose)) applyProps(raycaster, { ...options });
14587
- if (!is.equ(params, raycaster.params, shallowLoose))
14585
+ if (!is.equ(params, raycaster.params, shallowLoose)) {
14588
14586
  applyProps(raycaster, { params: { ...raycaster.params, ...params } });
14587
+ }
14589
14588
  if (!state.camera || state.camera === lastCamera && !is.equ(lastCamera, cameraOptions, shallowLoose)) {
14590
14589
  lastCamera = cameraOptions;
14591
14590
  const isCamera = cameraOptions?.isCamera;
@@ -14636,9 +14635,14 @@ function createRoot(canvas) {
14636
14635
  wasEnabled = enabled;
14637
14636
  });
14638
14637
  }
14638
+ if (_sizeProps !== void 0) {
14639
+ state.set({ _sizeProps });
14640
+ }
14639
14641
  const size = computeInitialSize(canvas, propsSize);
14640
- if (!is.equ(size, state.size, shallowLoose)) {
14642
+ if (!state._sizeImperative && !is.equ(size, state.size, shallowLoose)) {
14643
+ const wasImperative = state._sizeImperative;
14641
14644
  state.setSize(size.width, size.height, size.top, size.left);
14645
+ if (!wasImperative) state.set({ _sizeImperative: false });
14642
14646
  }
14643
14647
  if (dpr !== void 0 && !is.equ(dpr, lastConfiguredProps.dpr, shallowLoose)) {
14644
14648
  state.setDpr(dpr);
@@ -14708,15 +14712,17 @@ function createRoot(canvas) {
14708
14712
  } else if (is.obj(shadows)) {
14709
14713
  Object.assign(renderer.shadowMap, shadows);
14710
14714
  }
14711
- if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type)
14715
+ if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type) {
14712
14716
  renderer.shadowMap.needsUpdate = true;
14717
+ }
14713
14718
  }
14714
14719
  if (textureColorSpace !== lastConfiguredProps.textureColorSpace) {
14715
14720
  if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
14716
14721
  lastConfiguredProps.textureColorSpace = textureColorSpace;
14717
14722
  }
14718
- if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose))
14723
+ if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
14719
14724
  applyProps(renderer, glConfig);
14725
+ }
14720
14726
  if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
14721
14727
  const currentRenderer = state.renderer;
14722
14728
  if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
@@ -14984,6 +14990,9 @@ function CanvasImpl({
14984
14990
  onDragOverMissed,
14985
14991
  onDropMissed,
14986
14992
  onCreated,
14993
+ hmr,
14994
+ width,
14995
+ height,
14987
14996
  ...props
14988
14997
  }) {
14989
14998
  React.useMemo(() => extend(THREE), []);
@@ -15004,7 +15013,16 @@ function CanvasImpl({
15004
15013
  };
15005
15014
  }, [resize, hasInitialSizeRef.current]);
15006
15015
  const [containerRef, containerRect] = useMeasure(measureConfig);
15007
- if (!hasInitialSizeRef.current && containerRect.width > 0 && containerRect.height > 0) {
15016
+ const effectiveSize = React.useMemo(
15017
+ () => ({
15018
+ width: width ?? containerRect.width,
15019
+ height: height ?? containerRect.height,
15020
+ top: containerRect.top,
15021
+ left: containerRect.left
15022
+ }),
15023
+ [width, height, containerRect]
15024
+ );
15025
+ if (!hasInitialSizeRef.current && effectiveSize.width > 0 && effectiveSize.height > 0) {
15008
15026
  hasInitialSizeRef.current = true;
15009
15027
  }
15010
15028
  const canvasRef = React.useRef(null);
@@ -15023,7 +15041,7 @@ function CanvasImpl({
15023
15041
  useIsomorphicLayoutEffect(() => {
15024
15042
  effectActiveRef.current = true;
15025
15043
  const canvas = canvasRef.current;
15026
- if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
15044
+ if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
15027
15045
  if (!root.current) {
15028
15046
  root.current = createRoot(canvas);
15029
15047
  notifyAlpha({
@@ -15057,7 +15075,9 @@ function CanvasImpl({
15057
15075
  performance,
15058
15076
  raycaster,
15059
15077
  camera,
15060
- size: containerRect,
15078
+ size: effectiveSize,
15079
+ // Store size props for reset functionality
15080
+ _sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
15061
15081
  // Pass mutable reference to onPointerMissed so it's free to update
15062
15082
  onPointerMissed: (...args) => handlePointerMissed.current?.(...args),
15063
15083
  onDragOverMissed: (...args) => handleDragOverMissed.current?.(...args),
@@ -15103,6 +15123,33 @@ function CanvasImpl({
15103
15123
  };
15104
15124
  }
15105
15125
  }, []);
15126
+ React.useEffect(() => {
15127
+ if (hmr === false) return;
15128
+ const canvas = canvasRef.current;
15129
+ if (!canvas) return;
15130
+ const handleHMR = () => {
15131
+ const rootEntry = _roots.get(canvas);
15132
+ if (rootEntry?.store) {
15133
+ rootEntry.store.setState((state) => ({
15134
+ nodes: {},
15135
+ uniforms: {},
15136
+ _hmrVersion: state._hmrVersion + 1
15137
+ }));
15138
+ }
15139
+ };
15140
+ if (typeof import.meta !== "undefined" && import.meta.hot) {
15141
+ const hot = import.meta.hot;
15142
+ hot.on("vite:afterUpdate", handleHMR);
15143
+ return () => hot.dispose?.(() => {
15144
+ });
15145
+ }
15146
+ if (typeof module !== "undefined" && module.hot) {
15147
+ const hot = module.hot;
15148
+ hot.addStatusHandler((status) => {
15149
+ if (status === "idle") handleHMR();
15150
+ });
15151
+ }
15152
+ }, [hmr]);
15106
15153
  const pointerEvents = eventSource ? "none" : "auto";
15107
15154
  return /* @__PURE__ */ jsx(
15108
15155
  "div",
@@ -15125,6 +15172,72 @@ function Canvas(props) {
15125
15172
  return /* @__PURE__ */ jsx(FiberProvider, { children: /* @__PURE__ */ jsx(CanvasImpl, { ...props }) });
15126
15173
  }
15127
15174
 
15175
+ var __defProp = Object.defineProperty;
15176
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15177
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15178
+ var _a;
15179
+ const INTERNAL_DATA = Symbol("ScopedStore.data");
15180
+ _a = INTERNAL_DATA;
15181
+ const _ScopedStore = class _ScopedStore {
15182
+ constructor(data) {
15183
+ __publicField(this, _a);
15184
+ this[INTERNAL_DATA] = data;
15185
+ return new Proxy(this, {
15186
+ get(target, prop, receiver) {
15187
+ if (typeof prop === "string") {
15188
+ if (prop === "scope" || prop === "has" || prop === "keys") {
15189
+ return Reflect.get(target, prop, receiver);
15190
+ }
15191
+ return target[INTERNAL_DATA][prop];
15192
+ }
15193
+ return Reflect.get(target, prop, receiver);
15194
+ },
15195
+ has(target, prop) {
15196
+ return typeof prop === "string" ? prop in target[INTERNAL_DATA] : Reflect.has(target, prop);
15197
+ },
15198
+ ownKeys(target) {
15199
+ return Reflect.ownKeys(target[INTERNAL_DATA]);
15200
+ },
15201
+ getOwnPropertyDescriptor(target, prop) {
15202
+ if (typeof prop === "string" && prop in target[INTERNAL_DATA]) {
15203
+ return {
15204
+ configurable: true,
15205
+ enumerable: true,
15206
+ value: target[INTERNAL_DATA][prop]
15207
+ };
15208
+ }
15209
+ return void 0;
15210
+ }
15211
+ });
15212
+ }
15213
+ /**
15214
+ * Access a nested scope by key.
15215
+ * If the key doesn't exist or isn't a scope object, returns an empty ScopedStore.
15216
+ */
15217
+ scope(key) {
15218
+ const data = this[INTERNAL_DATA][key];
15219
+ return new _ScopedStore(
15220
+ data && typeof data === "object" ? data : {}
15221
+ );
15222
+ }
15223
+ /**
15224
+ * Check if a key exists in the store.
15225
+ */
15226
+ has(key) {
15227
+ return key in this[INTERNAL_DATA];
15228
+ }
15229
+ /**
15230
+ * Get all keys in the store.
15231
+ */
15232
+ keys() {
15233
+ return Object.keys(this[INTERNAL_DATA]);
15234
+ }
15235
+ };
15236
+ let ScopedStore = _ScopedStore;
15237
+ function createScopedStore(data) {
15238
+ return new ScopedStore(data);
15239
+ }
15240
+
15128
15241
  function addTexture(set, key, value) {
15129
15242
  set((state) => {
15130
15243
  const newMap = new Map(state.textures);
@@ -15238,21 +15351,52 @@ function useUniforms(creatorOrScope, scope) {
15238
15351
  },
15239
15352
  [store]
15240
15353
  );
15354
+ const rebuildUniforms = useCallback(
15355
+ (targetScope) => {
15356
+ store.setState((state) => {
15357
+ let newUniforms = state.uniforms;
15358
+ if (targetScope && targetScope !== "root") {
15359
+ const { [targetScope]: _, ...rest } = state.uniforms;
15360
+ newUniforms = rest;
15361
+ } else if (targetScope === "root") {
15362
+ newUniforms = {};
15363
+ for (const [key, value] of Object.entries(state.uniforms)) {
15364
+ if (!isUniformNode$1(value)) newUniforms[key] = value;
15365
+ }
15366
+ } else {
15367
+ newUniforms = {};
15368
+ }
15369
+ return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
15370
+ });
15371
+ },
15372
+ [store]
15373
+ );
15241
15374
  const inputForMemoization = useMemo(() => {
15242
- return is.fun(creatorOrScope) ? creatorOrScope(store.getState()) : creatorOrScope;
15375
+ if (is.fun(creatorOrScope)) {
15376
+ const state = store.getState();
15377
+ const wrappedState = {
15378
+ ...state,
15379
+ uniforms: createScopedStore(state.uniforms),
15380
+ nodes: createScopedStore(state.nodes)
15381
+ };
15382
+ return creatorOrScope(wrappedState);
15383
+ }
15384
+ return creatorOrScope;
15243
15385
  }, [creatorOrScope, store]);
15244
15386
  const memoizedInput = useCompareMemoize(inputForMemoization);
15387
+ const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
15388
+ const storeUniforms = useThree((s) => s.uniforms);
15245
15389
  const uniforms = useMemo(() => {
15246
- const state = store.getState();
15247
- const set = store.setState;
15248
15390
  if (memoizedInput === void 0) {
15249
- return state.uniforms;
15391
+ return storeUniforms;
15250
15392
  }
15251
15393
  if (typeof memoizedInput === "string") {
15252
- const scopeData = state.uniforms[memoizedInput];
15394
+ const scopeData = storeUniforms[memoizedInput];
15253
15395
  if (scopeData && !isUniformNode$1(scopeData)) return scopeData;
15254
15396
  return {};
15255
15397
  }
15398
+ const state = store.getState();
15399
+ const set = store.setState;
15256
15400
  if (typeof memoizedInput !== "object" || memoizedInput === null) {
15257
15401
  throw new Error("Invalid uniform input");
15258
15402
  }
@@ -15296,8 +15440,31 @@ function useUniforms(creatorOrScope, scope) {
15296
15440
  }
15297
15441
  }
15298
15442
  return result;
15299
- }, [store, memoizedInput, scope]);
15300
- return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms };
15443
+ }, [
15444
+ store,
15445
+ memoizedInput,
15446
+ scope,
15447
+ // Only include storeUniforms in deps for reader modes to enable reactivity
15448
+ isReader ? storeUniforms : null
15449
+ ]);
15450
+ return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
15451
+ }
15452
+ function rebuildAllUniforms(store, scope) {
15453
+ store.setState((state) => {
15454
+ let newUniforms = state.uniforms;
15455
+ if (scope && scope !== "root") {
15456
+ const { [scope]: _, ...rest } = state.uniforms;
15457
+ newUniforms = rest;
15458
+ } else if (scope === "root") {
15459
+ newUniforms = {};
15460
+ for (const [key, value] of Object.entries(state.uniforms)) {
15461
+ if (!isUniformNode$1(value)) newUniforms[key] = value;
15462
+ }
15463
+ } else {
15464
+ newUniforms = {};
15465
+ }
15466
+ return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
15467
+ });
15301
15468
  }
15302
15469
  function removeUniforms(set, names, scope) {
15303
15470
  set((state) => {
@@ -15431,19 +15598,47 @@ function useNodes(creatorOrScope, scope) {
15431
15598
  },
15432
15599
  [store]
15433
15600
  );
15601
+ const rebuildNodes = useCallback(
15602
+ (targetScope) => {
15603
+ store.setState((state) => {
15604
+ let newNodes = state.nodes;
15605
+ if (targetScope && targetScope !== "root") {
15606
+ const { [targetScope]: _, ...rest } = state.nodes;
15607
+ newNodes = rest;
15608
+ } else if (targetScope === "root") {
15609
+ newNodes = {};
15610
+ for (const [key, value] of Object.entries(state.nodes)) {
15611
+ if (!isTSLNode(value)) newNodes[key] = value;
15612
+ }
15613
+ } else {
15614
+ newNodes = {};
15615
+ }
15616
+ return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
15617
+ });
15618
+ },
15619
+ [store]
15620
+ );
15621
+ const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
15622
+ const storeNodes = useThree((s) => s.nodes);
15623
+ const hmrVersion = useThree((s) => s._hmrVersion);
15434
15624
  const nodes = useMemo(() => {
15435
- const state = store.getState();
15436
- const set = store.setState;
15437
15625
  if (creatorOrScope === void 0) {
15438
- return state.nodes;
15626
+ return storeNodes;
15439
15627
  }
15440
15628
  if (typeof creatorOrScope === "string") {
15441
- const scopeData = state.nodes[creatorOrScope];
15629
+ const scopeData = storeNodes[creatorOrScope];
15442
15630
  if (scopeData && !isTSLNode(scopeData)) return scopeData;
15443
15631
  return {};
15444
15632
  }
15633
+ const state = store.getState();
15634
+ const set = store.setState;
15445
15635
  const creator = creatorOrScope;
15446
- const created = creator(state);
15636
+ const wrappedState = {
15637
+ ...state,
15638
+ uniforms: createScopedStore(state.uniforms),
15639
+ nodes: createScopedStore(state.nodes)
15640
+ };
15641
+ const created = creator(wrappedState);
15447
15642
  const result = {};
15448
15643
  let hasNewNodes = false;
15449
15644
  if (scope) {
@@ -15481,8 +15676,33 @@ function useNodes(creatorOrScope, scope) {
15481
15676
  set((s) => ({ nodes: { ...s.nodes, ...result } }));
15482
15677
  }
15483
15678
  return result;
15484
- }, [store, typeof creatorOrScope === "string" ? creatorOrScope : scope]);
15485
- return { ...nodes, removeNodes: removeNodes2, clearNodes };
15679
+ }, [
15680
+ store,
15681
+ typeof creatorOrScope === "string" ? creatorOrScope : scope,
15682
+ // Only include storeNodes in deps for reader modes to enable reactivity
15683
+ // Creator mode intentionally excludes it to avoid re-running creator on unrelated changes
15684
+ isReader ? storeNodes : null,
15685
+ // Include hmrVersion for creator modes to allow rebuildNodes() to bust the cache
15686
+ isReader ? null : hmrVersion
15687
+ ]);
15688
+ return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
15689
+ }
15690
+ function rebuildAllNodes(store, scope) {
15691
+ store.setState((state) => {
15692
+ let newNodes = state.nodes;
15693
+ if (scope && scope !== "root") {
15694
+ const { [scope]: _, ...rest } = state.nodes;
15695
+ newNodes = rest;
15696
+ } else if (scope === "root") {
15697
+ newNodes = {};
15698
+ for (const [key, value] of Object.entries(state.nodes)) {
15699
+ if (!isTSLNode(value)) newNodes[key] = value;
15700
+ }
15701
+ } else {
15702
+ newNodes = {};
15703
+ }
15704
+ return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
15705
+ });
15486
15706
  }
15487
15707
  function removeNodes(set, names, scope) {
15488
15708
  set((state) => {
@@ -15518,7 +15738,12 @@ function useLocalNodes(creator) {
15518
15738
  const textures = useThree((s) => s.textures);
15519
15739
  return useMemo(() => {
15520
15740
  const state = store.getState();
15521
- return creator(state);
15741
+ const wrappedState = {
15742
+ ...state,
15743
+ uniforms: createScopedStore(state.uniforms),
15744
+ nodes: createScopedStore(state.nodes)
15745
+ };
15746
+ return creator(wrappedState);
15522
15747
  }, [store, creator, uniforms, nodes, textures]);
15523
15748
  }
15524
15749
 
@@ -15532,6 +15757,10 @@ function usePostProcessing(mainCB, setupCB) {
15532
15757
  mainCBRef.current = mainCB;
15533
15758
  setupCBRef.current = setupCB;
15534
15759
  const [rebuildVersion, setRebuildVersion] = useState(0);
15760
+ useEffect(() => {
15761
+ callbacksRanRef.current = false;
15762
+ scenePassCacheRef.current = null;
15763
+ }, []);
15535
15764
  const clearPasses = useCallback(() => {
15536
15765
  store.setState({ passes: {} });
15537
15766
  }, [store]);
@@ -15613,4 +15842,4 @@ function usePostProcessing(mainCB, setupCB) {
15613
15842
 
15614
15843
  extend(THREE);
15615
15844
 
15616
- export { Block, Canvas, ErrorBoundary, IsObject, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Scheduler, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, getInstanceProps, getRootState, getScheduler, getUuidPrefix, hasConstructor, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isObject3D, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, prepare, reconciler, removeInteractivity, removeNodes, removeUniforms, resolve, unmountComponentAtNode, updateCamera, updateFrustum, useBridge, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, usePostProcessing, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms };
15845
+ export { Block, Canvas, ErrorBoundary, IsObject, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Scheduler, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, getInstanceProps, getRootState, getScheduler, getUuidPrefix, hasConstructor, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isObject3D, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, prepare, rebuildAllNodes, rebuildAllUniforms, reconciler, removeInteractivity, removeNodes, removeUniforms, resolve, unmountComponentAtNode, updateCamera, updateFrustum, useBridge, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, usePostProcessing, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms };