@react-three/fiber 10.0.0-canary.54ec785 → 10.0.0-canary.58acabc

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.
Files changed (42) hide show
  1. package/dist/extension.cjs +8 -8
  2. package/dist/extension.d.cts +50 -6
  3. package/dist/extension.d.mts +50 -6
  4. package/dist/extension.d.ts +50 -6
  5. package/dist/extension.mjs +1 -1
  6. package/dist/index.cjs +17 -19
  7. package/dist/index.d.cts +15 -47
  8. package/dist/index.d.mts +15 -47
  9. package/dist/index.d.ts +15 -47
  10. package/dist/index.mjs +7 -8
  11. package/dist/legacy.cjs +37 -15
  12. package/dist/legacy.d.cts +10 -7
  13. package/dist/legacy.d.mts +10 -7
  14. package/dist/legacy.d.ts +10 -7
  15. package/dist/legacy.mjs +13 -5
  16. package/dist/shared/{fiber.BcNm6NAg.d.cts → fiber.34TOMPo3.d.cts} +83 -464
  17. package/dist/shared/fiber.BFuGd7gN.d.cts +90 -0
  18. package/dist/shared/{fiber.khFlPHPf.cjs → fiber.BO8-26r8.cjs} +206 -62
  19. package/dist/shared/fiber.BSXtODQl.cjs +14 -0
  20. package/dist/shared/fiber.Bll9fqKA.d.mts +90 -0
  21. package/dist/shared/{fiber.5Q8N6Hhq.mjs → fiber.BuWl08aJ.mjs} +2375 -1941
  22. package/dist/shared/{fiber.CUKAa7Rv.mjs → fiber.C-3TIsF8.mjs} +200 -64
  23. package/dist/shared/{fiber.CQDCACCJ.d.mts → fiber.CjMAAsJy.d.ts} +83 -464
  24. package/dist/shared/fiber.DEWBFQJe.mjs +9 -0
  25. package/dist/shared/{fiber.CZLeHcML.d.cts → fiber.DQTSZ24m.d.cts} +469 -29
  26. package/dist/shared/{fiber.CZLeHcML.d.mts → fiber.DQTSZ24m.d.mts} +469 -29
  27. package/dist/shared/{fiber.CZLeHcML.d.ts → fiber.DQTSZ24m.d.ts} +469 -29
  28. package/dist/shared/fiber.DuA4F8L5.d.ts +90 -0
  29. package/dist/shared/{fiber.DeBIf2pk.d.ts → fiber.Dy7Uz273.d.mts} +83 -464
  30. package/dist/shared/{fiber.BegWBc5_.cjs → fiber.TRm3lZ7I.cjs} +2407 -1973
  31. package/dist/webgpu/index.cjs +16 -18
  32. package/dist/webgpu/index.d.cts +17 -78
  33. package/dist/webgpu/index.d.mts +17 -78
  34. package/dist/webgpu/index.d.ts +17 -78
  35. package/dist/webgpu/index.mjs +7 -9
  36. package/package.json +3 -3
  37. package/readme.md +10 -1
  38. package/dist/chunks/webgl.cjs +0 -27
  39. package/dist/chunks/webgl.mjs +0 -11
  40. package/dist/shared/fiber.B_GGVI86.d.ts +0 -48
  41. package/dist/shared/fiber.ColkapKS.d.mts +0 -48
  42. package/dist/shared/fiber.DRfTw2kk.d.cts +0 -48
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useContext } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
- import { useFiber, useContextBridge, traverseFiber } from 'its-fine';
4
+ import { useFiber, useContextBridge, useActivityBridge as useActivityBridge$1, traverseFiber } from 'its-fine';
5
5
  import { getScheduler } from '@pmndrs/scheduler';
6
6
 
7
7
  var __defProp = Object.defineProperty;
@@ -13,16 +13,18 @@ function useMutableCallback(fn) {
13
13
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
14
14
  return ref;
15
15
  }
16
+ const useActivityBridge = React["Activity"] ? useActivityBridge$1 : () => React.Fragment;
16
17
  function useBridge() {
17
18
  const fiber = useFiber();
18
19
  const ContextBridge = useContextBridge();
20
+ const ActivityBridge = useActivityBridge();
19
21
  return React.useMemo(
20
22
  () => ({ children }) => {
21
23
  const strict = !!traverseFiber(fiber, true, (node) => node.type === React.StrictMode);
22
24
  const Root = strict ? React.StrictMode : React.Fragment;
23
- return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) });
25
+ return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ActivityBridge, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) }) });
24
26
  },
25
- [fiber, ContextBridge]
27
+ [fiber, ContextBridge, ActivityBridge]
26
28
  );
27
29
  }
28
30
  function Block({ set }) {
@@ -47,6 +49,23 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
47
49
  }
48
50
  }, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
49
51
  })();
52
+ const noop = () => {
53
+ };
54
+ function Gate({ promise, onSettled }) {
55
+ React.use(promise);
56
+ useIsomorphicLayoutEffect(onSettled, [onSettled]);
57
+ return null;
58
+ }
59
+ function useGate() {
60
+ const [promise, setPromise] = React.useState(null);
61
+ const onSettled = React.useCallback(() => setPromise(null), []);
62
+ const waitFor = React.useCallback(
63
+ (next) => setPromise((current) => current ?? Promise.resolve(next).then(noop, noop)),
64
+ []
65
+ );
66
+ const gate = promise ? /* @__PURE__ */ jsx(React.Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Gate, { promise, onSettled }) }) : null;
67
+ return [gate, waitFor];
68
+ }
50
69
 
51
70
  const shownNotices = /* @__PURE__ */ new Set();
52
71
  function notifyDepreciated({ heading, body, link }) {
@@ -104,10 +123,179 @@ function notifyAlpha({ message, link }) {
104
123
  console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
105
124
  }
106
125
  }
126
+ function isDevelopment() {
127
+ try {
128
+ return process.env.NODE_ENV !== "production";
129
+ } catch {
130
+ return true;
131
+ }
132
+ }
133
+
134
+ const INTERNAL_LIB_MARKERS = [
135
+ "zustand",
136
+ "setState",
137
+ "Object.assign",
138
+ "@pmndrs/scheduler",
139
+ "Scheduler.tickRoot",
140
+ "Scheduler.stepJob"
141
+ ];
142
+ function isInternalRendererAccess(stack, callerDepth = 2) {
143
+ if (!stack) return false;
144
+ const caller = stack.split("\n")[callerDepth] ?? "";
145
+ return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
146
+ }
147
+
148
+ const isAccessorDescriptor = (descriptor) => !!descriptor && (descriptor.get !== void 0 || descriptor.set !== void 0);
149
+ const isAccessor = (object, key) => isAccessorDescriptor(Object.getOwnPropertyDescriptor(object, key));
150
+ function cloneState(...sources) {
151
+ const target = {};
152
+ for (const source of sources) {
153
+ if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
154
+ }
155
+ return target;
156
+ }
157
+ function preserveAccessors(rawSet, get) {
158
+ return ((partial, replace) => {
159
+ const previous = get();
160
+ const patch = typeof partial === "function" ? partial(previous) : partial;
161
+ if (replace || !previous || patch == null || Object.is(patch, previous)) {
162
+ return rawSet(patch, replace);
163
+ }
164
+ const next = cloneState(previous);
165
+ const viaSetter = [];
166
+ for (const key of Reflect.ownKeys(patch)) {
167
+ const descriptor = Object.getOwnPropertyDescriptor(patch, key);
168
+ if (!descriptor.enumerable) continue;
169
+ if (isAccessorDescriptor(descriptor)) {
170
+ Object.defineProperty(next, key, descriptor);
171
+ } else if (isAccessor(next, key)) {
172
+ viaSetter.push(key);
173
+ } else {
174
+ Object.defineProperty(next, key, {
175
+ value: descriptor.value,
176
+ writable: true,
177
+ enumerable: true,
178
+ configurable: true
179
+ });
180
+ }
181
+ }
182
+ for (const key of viaSetter) next[key] = patch[key];
183
+ rawSet(next, true);
184
+ });
185
+ }
186
+ const keepAccessors = (initializer) => (rawSet, get, api) => {
187
+ const set = preserveAccessors(rawSet, get);
188
+ api.setState = set;
189
+ return initializer(set, get, api);
190
+ };
191
+ let glNoticeShown = false;
192
+ const schedulerViews = /* @__PURE__ */ new WeakMap();
193
+ function stateForScheduler(state) {
194
+ let view = schedulerViews.get(state);
195
+ if (!view) {
196
+ view = cloneState(state);
197
+ Object.defineProperty(view, "gl", {
198
+ get() {
199
+ return this.internal?.actualRenderer;
200
+ },
201
+ set(value) {
202
+ this.internal.actualRenderer = value;
203
+ },
204
+ enumerable: true,
205
+ configurable: true
206
+ });
207
+ schedulerViews.set(state, view);
208
+ }
209
+ return view;
210
+ }
211
+ function defineRendererAccessors(state) {
212
+ Object.defineProperty(state, "gl", {
213
+ get() {
214
+ const renderer = this.internal?.actualRenderer;
215
+ if (!glNoticeShown && renderer && !this.isLegacy) {
216
+ const stack = new Error().stack || "";
217
+ if (!isInternalRendererAccess(stack)) {
218
+ glNoticeShown = true;
219
+ const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
220
+ notifyDepreciated({
221
+ heading: "Accessing state.gl in WebGPU mode",
222
+ body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
223
+ });
224
+ }
225
+ }
226
+ return renderer;
227
+ },
228
+ set(value) {
229
+ this.internal.actualRenderer = value;
230
+ },
231
+ enumerable: true,
232
+ configurable: true
233
+ });
234
+ Object.defineProperty(state, "renderer", {
235
+ get() {
236
+ return this.internal?.actualRenderer;
237
+ },
238
+ set(value) {
239
+ this.internal.actualRenderer = value;
240
+ },
241
+ enumerable: true,
242
+ configurable: true
243
+ });
244
+ }
107
245
 
108
246
  const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
109
247
  const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
110
248
 
249
+ const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
250
+ function getRegistry() {
251
+ return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
252
+ extensions: /* @__PURE__ */ new Map(),
253
+ roots: /* @__PURE__ */ new Set(),
254
+ applied: /* @__PURE__ */ new WeakMap()
255
+ });
256
+ }
257
+ function setupRoot(registry, store, extension) {
258
+ let applied = registry.applied.get(store);
259
+ if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
260
+ if (applied.has(extension.name)) return;
261
+ applied.set(extension.name, extension);
262
+ const patch = extension.setup?.(store);
263
+ if (patch) store.setState(patch);
264
+ }
265
+ function registerRootExtension(extension) {
266
+ const registry = getRegistry();
267
+ registry.extensions.set(extension.name, extension);
268
+ for (const store of registry.roots) setupRoot(registry, store, extension);
269
+ return () => {
270
+ if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
271
+ };
272
+ }
273
+ function setRenderOverride(store, render) {
274
+ store.getState().internal.renderOverride = render;
275
+ }
276
+ function attachRootExtensions(store) {
277
+ const registry = getRegistry();
278
+ registry.roots.add(store);
279
+ for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
280
+ }
281
+ function current(registry, setUpBy) {
282
+ return registry.extensions.get(setUpBy.name) ?? setUpBy;
283
+ }
284
+ function detachRootExtensions(store) {
285
+ const registry = getRegistry();
286
+ if (!registry.roots.delete(store)) return;
287
+ const applied = registry.applied.get(store);
288
+ registry.applied.delete(store);
289
+ if (!applied) return;
290
+ for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
291
+ }
292
+ function notifyRootExtensionsHmr(store) {
293
+ const registry = getRegistry();
294
+ const applied = registry.applied.get(store);
295
+ if (!applied) return;
296
+ for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
297
+ }
298
+
111
299
  function useStore() {
112
300
  const store = useContext(context);
113
301
  if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
@@ -134,8 +322,8 @@ function useFrame(callback, priorityOrOptions) {
134
322
  const options = React.useMemo(() => {
135
323
  return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
136
324
  }, [optionsKey]);
137
- const reactId = React.useId();
138
- const id = options.id ?? reactId;
325
+ const [generatedId] = React.useState(() => scheduler.generateJobId());
326
+ const id = options.id ?? generatedId;
139
327
  const callbackRef = useMutableCallback(callback);
140
328
  const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
141
329
  const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
@@ -166,14 +354,12 @@ function useFrame(callback, priorityOrOptions) {
166
354
  });
167
355
  }
168
356
  const wrappedCallback = (frameState, delta) => {
169
- const localState = store.getState();
170
- const mergedState = {
171
- ...localState,
172
- time: frameState.time,
173
- delta: frameState.delta,
174
- elapsed: frameState.elapsed,
175
- frame: frameState.frame
176
- };
357
+ const mergedState = cloneState(store.getState());
358
+ mergedState.time = frameState.time;
359
+ mergedState.delta = frameState.delta;
360
+ mergedState.elapsed = frameState.elapsed;
361
+ mergedState.frame = frameState.frame;
362
+ mergedState.overstep = frameState.overstep;
177
363
  callbackRef.current?.(mergedState, delta);
178
364
  };
179
365
  const unregister = scheduler.register(wrappedCallback, {
@@ -311,54 +497,4 @@ function getTextureView(store) {
311
497
  return view;
312
498
  }
313
499
 
314
- const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
315
- function getRegistry() {
316
- return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
317
- extensions: /* @__PURE__ */ new Map(),
318
- roots: /* @__PURE__ */ new Set(),
319
- applied: /* @__PURE__ */ new WeakMap()
320
- });
321
- }
322
- function setupRoot(registry, store, extension) {
323
- let applied = registry.applied.get(store);
324
- if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
325
- if (applied.has(extension.name)) return;
326
- applied.set(extension.name, extension);
327
- const patch = extension.setup?.(store);
328
- if (patch) store.setState(patch);
329
- }
330
- function registerRootExtension(extension) {
331
- const registry = getRegistry();
332
- registry.extensions.set(extension.name, extension);
333
- for (const store of registry.roots) setupRoot(registry, store, extension);
334
- return () => {
335
- if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
336
- };
337
- }
338
- function setRenderOverride(store, render) {
339
- store.getState().internal.renderOverride = render;
340
- }
341
- function attachRootExtensions(store) {
342
- const registry = getRegistry();
343
- registry.roots.add(store);
344
- for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
345
- }
346
- function current(registry, setUpBy) {
347
- return registry.extensions.get(setUpBy.name) ?? setUpBy;
348
- }
349
- function detachRootExtensions(store) {
350
- const registry = getRegistry();
351
- if (!registry.roots.delete(store)) return;
352
- const applied = registry.applied.get(store);
353
- registry.applied.delete(store);
354
- if (!applied) return;
355
- for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
356
- }
357
- function notifyRootExtensionsHmr(store) {
358
- const registry = getRegistry();
359
- const applied = registry.applied.get(store);
360
- if (!applied) return;
361
- for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
362
- }
363
-
364
- export { Block as B, ErrorBoundary as E, useThree as a, useFrame as b, context as c, useIsomorphicLayoutEffect as d, useMutableCallback as e, useBridge as f, getTextureView as g, unstageTextures as h, stageTextures as i, attachRootExtensions as j, detachRootExtensions as k, notifyAlpha as l, notifyRootExtensionsHmr as m, notifyDepreciated as n, registerRootExtension as r, setRenderOverride as s, useStore as u };
500
+ export { Block as B, ErrorBoundary as E, useThree as a, useFrame as b, context as c, useIsomorphicLayoutEffect as d, useMutableCallback as e, useBridge as f, getTextureView as g, defineRendererAccessors as h, isDevelopment as i, stateForScheduler as j, detachRootExtensions as k, attachRootExtensions as l, unstageTextures as m, notifyDepreciated as n, stageTextures as o, preserveAccessors as p, isAccessor as q, registerRootExtension as r, setRenderOverride as s, cloneState as t, useStore as u, keepAccessors as v, useGate as w, notifyAlpha as x, notifyRootExtensionsHmr as y };