@react-three/fiber 10.0.0-canary.ea31ccd → 10.0.0-canary.ee5a08a

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 (39) hide show
  1. package/dist/chunks/webgl.cjs +27 -0
  2. package/dist/chunks/webgl.mjs +11 -0
  3. package/dist/chunks/webgpu.cjs +37 -0
  4. package/dist/chunks/webgpu.mjs +21 -0
  5. package/dist/extension.cjs +13 -0
  6. package/dist/extension.d.cts +19 -0
  7. package/dist/extension.d.mts +19 -0
  8. package/dist/extension.d.ts +19 -0
  9. package/dist/extension.mjs +1 -0
  10. package/dist/index.cjs +97 -15371
  11. package/dist/index.d.cts +123 -3873
  12. package/dist/index.d.mts +123 -3873
  13. package/dist/index.d.ts +122 -3844
  14. package/dist/index.mjs +10 -15272
  15. package/dist/legacy.cjs +97 -15326
  16. package/dist/legacy.d.cts +114 -3874
  17. package/dist/legacy.d.mts +114 -3874
  18. package/dist/legacy.d.ts +115 -3849
  19. package/dist/legacy.mjs +14 -15230
  20. package/dist/shared/fiber.B0oukOFO.mjs +364 -0
  21. package/dist/shared/fiber.BDWBTuAk.d.mts +2797 -0
  22. package/dist/shared/fiber.BU0vBHc9.d.mts +48 -0
  23. package/dist/shared/fiber.Cx-UAmMb.d.ts +48 -0
  24. package/dist/shared/fiber.DAl4H27x.d.cts +48 -0
  25. package/dist/shared/fiber.DNgUv56V.d.ts +2797 -0
  26. package/dist/shared/fiber.DlTSmVjz.d.cts +2797 -0
  27. package/dist/shared/fiber.I5Q4dVvl.d.cts +778 -0
  28. package/dist/shared/fiber.I5Q4dVvl.d.mts +778 -0
  29. package/dist/shared/fiber.I5Q4dVvl.d.ts +778 -0
  30. package/dist/shared/fiber.khFlPHPf.cjs +397 -0
  31. package/dist/shared/fiber.oKEFddXj.cjs +16059 -0
  32. package/dist/shared/fiber.tsM9NKZ9.mjs +15961 -0
  33. package/dist/webgpu/index.cjs +100 -16211
  34. package/dist/webgpu/index.d.cts +112 -4190
  35. package/dist/webgpu/index.d.mts +112 -4190
  36. package/dist/webgpu/index.d.ts +112 -4162
  37. package/dist/webgpu/index.mjs +15 -16095
  38. package/package.json +11 -8
  39. package/readme.md +1 -1
@@ -0,0 +1,397 @@
1
+ 'use strict';
2
+
3
+ const React = require('react');
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const itsFine = require('its-fine');
6
+ const scheduler = require('@pmndrs/scheduler');
7
+
8
+ function _interopNamespaceCompat(e) {
9
+ if (e && typeof e === 'object' && 'default' in e) return e;
10
+ const n = Object.create(null);
11
+ if (e) {
12
+ for (const k in e) {
13
+ n[k] = e[k];
14
+ }
15
+ }
16
+ n.default = e;
17
+ return n;
18
+ }
19
+
20
+ const React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
21
+
22
+ var __defProp = Object.defineProperty;
23
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
25
+ const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
26
+ function useMutableCallback(fn) {
27
+ const ref = React__namespace.useRef(fn);
28
+ useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
29
+ return ref;
30
+ }
31
+ function useBridge() {
32
+ const fiber = itsFine.useFiber();
33
+ const ContextBridge = itsFine.useContextBridge();
34
+ return React__namespace.useMemo(
35
+ () => ({ children }) => {
36
+ const strict = !!itsFine.traverseFiber(fiber, true, (node) => node.type === React__namespace.StrictMode);
37
+ const Root = strict ? React__namespace.StrictMode : React__namespace.Fragment;
38
+ return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) });
39
+ },
40
+ [fiber, ContextBridge]
41
+ );
42
+ }
43
+ function Block({ set }) {
44
+ useIsomorphicLayoutEffect(() => {
45
+ set(new Promise(() => null));
46
+ return () => set(false);
47
+ }, [set]);
48
+ return null;
49
+ }
50
+ const ErrorBoundary = /* @__PURE__ */ (() => {
51
+ var _a;
52
+ return _a = class extends React__namespace.Component {
53
+ constructor() {
54
+ super(...arguments);
55
+ __publicField(this, "state", { error: false });
56
+ }
57
+ componentDidCatch(err) {
58
+ this.props.set(err);
59
+ }
60
+ render() {
61
+ return this.state.error ? null : this.props.children;
62
+ }
63
+ }, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
64
+ })();
65
+
66
+ const shownNotices = /* @__PURE__ */ new Set();
67
+ function notifyDepreciated({ heading, body, link }) {
68
+ if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
69
+ return;
70
+ }
71
+ if (shownNotices.has(heading)) return;
72
+ shownNotices.add(heading);
73
+ const caller = getCallerFrame();
74
+ if (caller) {
75
+ console.log();
76
+ }
77
+ const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
78
+ if (caller) {
79
+ console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
80
+ }
81
+ if (body || link) {
82
+ let message = "";
83
+ if (body) message += body;
84
+ if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
85
+ console.warn(`%c${message}`, "font-weight: bold;");
86
+ }
87
+ }
88
+ function getCallerFrame(depth = 3) {
89
+ const stack = new Error().stack;
90
+ if (!stack) return null;
91
+ const lines = stack.split("\n");
92
+ const frame = lines[depth];
93
+ if (!frame) return null;
94
+ let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
95
+ if (!match) {
96
+ match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
97
+ }
98
+ if (!match) return null;
99
+ const [, fn, url, line] = match;
100
+ return {
101
+ functionName: fn ?? "<anonymous>",
102
+ location: formatLocation(url, Number(line))
103
+ };
104
+ }
105
+ function formatLocation(url, line) {
106
+ const clean = url.split("?")[0];
107
+ const file = clean.split("/").pop() ?? clean;
108
+ return `${file}:${line}`;
109
+ }
110
+ function notifyAlpha({ message, link }) {
111
+ if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
112
+ return;
113
+ }
114
+ if (shownNotices.has(message)) return;
115
+ shownNotices.add(message);
116
+ const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
117
+ console.log(`%c\u{1F52C} ${message}`, boxStyle);
118
+ {
119
+ console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
120
+ }
121
+ }
122
+
123
+ const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
124
+ const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
125
+
126
+ function useStore() {
127
+ const store = React.useContext(context);
128
+ if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
129
+ return store;
130
+ }
131
+ function useThree(selector = (state) => state, equalityFn) {
132
+ return useStore()(selector, equalityFn);
133
+ }
134
+
135
+ function useFrame(callback, priorityOrOptions) {
136
+ const store = React__namespace.useContext(context);
137
+ const isInsideCanvas = store !== null;
138
+ const scheduler$1 = scheduler.getScheduler();
139
+ const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
140
+ id: priorityOrOptions.id,
141
+ phase: priorityOrOptions.phase,
142
+ priority: priorityOrOptions.priority,
143
+ fps: priorityOrOptions.fps,
144
+ drop: priorityOrOptions.drop,
145
+ enabled: priorityOrOptions.enabled,
146
+ before: priorityOrOptions.before,
147
+ after: priorityOrOptions.after
148
+ }) : "";
149
+ const options = React__namespace.useMemo(() => {
150
+ return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
151
+ }, [optionsKey]);
152
+ const reactId = React__namespace.useId();
153
+ const id = options.id ?? reactId;
154
+ const callbackRef = useMutableCallback(callback);
155
+ const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
156
+ const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
157
+ useIsomorphicLayoutEffect(() => {
158
+ if (!callback) return;
159
+ if (isLegacyOrdering) {
160
+ notifyDepreciated({
161
+ heading: "useFrame numeric priority order is reversed in v10",
162
+ body: "useFrame(callback, number) is deprecated and its ordering direction is reversed from v9: v9 ran lower numbers first, v10 maps the number to { priority } and runs higher numbers first, so a negative priority now runs after default-priority jobs.\n\nUse { before, after } to name the dependency, or { priority } with the v10 direction (higher = earlier).",
163
+ link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
164
+ });
165
+ }
166
+ if (isInsideCanvas) {
167
+ const state = store.getState();
168
+ const rootId = state.internal.rootId;
169
+ if (isLegacyPriority) {
170
+ state.internal.priority++;
171
+ let parentRoot = state.previousRoot;
172
+ while (parentRoot) {
173
+ const parentState = parentRoot.getState();
174
+ if (parentState?.internal) parentState.internal.priority++;
175
+ parentRoot = parentState?.previousRoot;
176
+ }
177
+ notifyDepreciated({
178
+ heading: "useFrame with numeric priority is deprecated",
179
+ body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within a phase, use: useFrame(callback, { priority: number }) \u2014 higher runs first, the reverse of v9',
180
+ link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
181
+ });
182
+ }
183
+ const wrappedCallback = (frameState, delta) => {
184
+ const localState = store.getState();
185
+ const mergedState = {
186
+ ...localState,
187
+ time: frameState.time,
188
+ delta: frameState.delta,
189
+ elapsed: frameState.elapsed,
190
+ frame: frameState.frame
191
+ };
192
+ callbackRef.current?.(mergedState, delta);
193
+ };
194
+ const unregister = scheduler$1.register(wrappedCallback, {
195
+ id,
196
+ rootId,
197
+ ...options
198
+ });
199
+ return () => {
200
+ unregister();
201
+ if (isLegacyPriority) {
202
+ const currentState = store.getState();
203
+ if (currentState.internal) {
204
+ currentState.internal.priority--;
205
+ let parentRoot = currentState.previousRoot;
206
+ while (parentRoot) {
207
+ const parentState = parentRoot.getState();
208
+ if (parentState?.internal) parentState.internal.priority--;
209
+ parentRoot = parentState?.previousRoot;
210
+ }
211
+ }
212
+ }
213
+ };
214
+ } else {
215
+ return scheduler$1.register(
216
+ (state, delta) => {
217
+ const frameState = state;
218
+ if (!frameState.renderer) return;
219
+ callbackRef.current?.(frameState, delta);
220
+ },
221
+ { id, ...options }
222
+ );
223
+ }
224
+ }, [store, scheduler$1, id, optionsKey, isLegacyPriority, isLegacyOrdering, isInsideCanvas]);
225
+ const isPaused = React__namespace.useSyncExternalStore(
226
+ // Subscribe function
227
+ React__namespace.useCallback(
228
+ (onStoreChange) => {
229
+ return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
230
+ },
231
+ [id]
232
+ ),
233
+ // getSnapshot function
234
+ React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
235
+ // getServerSnapshot function (SSR)
236
+ React__namespace.useCallback(() => false, [])
237
+ );
238
+ const controls = React__namespace.useMemo(() => {
239
+ const scheduler2 = scheduler.getScheduler();
240
+ return {
241
+ /** The job's unique ID */
242
+ id,
243
+ /**
244
+ * Access to the global scheduler for frame loop control.
245
+ * Use for controlling the entire frame loop, adding phases, etc.
246
+ */
247
+ scheduler: scheduler2,
248
+ /**
249
+ * The root that currently owns this job. Resolve on access because ambient
250
+ * jobs can be adopted by a Canvas after the controls object is created.
251
+ */
252
+ get rootId() {
253
+ return scheduler.getScheduler().getJobRootId(id);
254
+ },
255
+ /**
256
+ * Manually step this job only.
257
+ * Bypasses FPS limiting - always runs.
258
+ * @param timestamp Optional timestamp (defaults to performance.now())
259
+ */
260
+ step: (timestamp) => {
261
+ scheduler.getScheduler().stepJob(id, timestamp);
262
+ },
263
+ /**
264
+ * Manually step ALL jobs in the scheduler.
265
+ * Useful for frameloop='never' mode.
266
+ * @param timestamp Optional timestamp (defaults to performance.now())
267
+ */
268
+ stepAll: (timestamp) => {
269
+ scheduler.getScheduler().step(timestamp);
270
+ },
271
+ /**
272
+ * Request frames for this job's owning root without waking sibling roots.
273
+ */
274
+ invalidate: (frames, stackFrames) => {
275
+ const scheduler3 = scheduler.getScheduler();
276
+ const rootId = scheduler3.getJobRootId(id);
277
+ if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
278
+ },
279
+ /**
280
+ * Pause this job (set enabled=false).
281
+ * Job remains registered but won't run.
282
+ */
283
+ pause: () => {
284
+ scheduler.getScheduler().pauseJob(id);
285
+ },
286
+ /**
287
+ * Resume this job (set enabled=true).
288
+ */
289
+ resume: () => {
290
+ scheduler.getScheduler().resumeJob(id);
291
+ },
292
+ /**
293
+ * Reactive paused state - automatically updates when pause/resume is called.
294
+ * No need for forceUpdate() in your components.
295
+ */
296
+ isPaused
297
+ };
298
+ }, [id, isPaused]);
299
+ return controls;
300
+ }
301
+
302
+ const R3F_STAGED_TEXTURES = Symbol.for("@react-three/fiber.stagedTextures");
303
+ const globalStaging = globalThis;
304
+ const staging = globalStaging[R3F_STAGED_TEXTURES] ?? (globalStaging[R3F_STAGED_TEXTURES] = /* @__PURE__ */ new WeakMap());
305
+ function stageTextures(store, entries) {
306
+ const registered = store.getState().textures;
307
+ let staged = staging.get(store);
308
+ for (const [url, texture] of entries) {
309
+ if (registered.has(url)) continue;
310
+ if (!staged) staging.set(store, staged = /* @__PURE__ */ new Map());
311
+ staged.set(url, texture);
312
+ }
313
+ }
314
+ function unstageTextures(store, urls) {
315
+ const staged = staging.get(store);
316
+ if (!staged) return;
317
+ for (const url of urls) staged.delete(url);
318
+ if (staged.size === 0) staging.delete(store);
319
+ }
320
+ function getTextureView(store) {
321
+ const registered = store.getState().textures;
322
+ const staged = staging.get(store);
323
+ if (!staged) return registered;
324
+ const view = new Map(registered);
325
+ for (const [url, texture] of staged) if (!view.has(url)) view.set(url, texture);
326
+ return view;
327
+ }
328
+
329
+ const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
330
+ function getRegistry() {
331
+ return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
332
+ extensions: /* @__PURE__ */ new Map(),
333
+ roots: /* @__PURE__ */ new Set(),
334
+ applied: /* @__PURE__ */ new WeakMap()
335
+ });
336
+ }
337
+ function setupRoot(registry, store, extension) {
338
+ let applied = registry.applied.get(store);
339
+ if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
340
+ if (applied.has(extension.name)) return;
341
+ applied.set(extension.name, extension);
342
+ const patch = extension.setup?.(store);
343
+ if (patch) store.setState(patch);
344
+ }
345
+ function registerRootExtension(extension) {
346
+ const registry = getRegistry();
347
+ registry.extensions.set(extension.name, extension);
348
+ for (const store of registry.roots) setupRoot(registry, store, extension);
349
+ return () => {
350
+ if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
351
+ };
352
+ }
353
+ function setRenderOverride(store, render) {
354
+ store.getState().internal.renderOverride = render;
355
+ }
356
+ function attachRootExtensions(store) {
357
+ const registry = getRegistry();
358
+ registry.roots.add(store);
359
+ for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
360
+ }
361
+ function current(registry, setUpBy) {
362
+ return registry.extensions.get(setUpBy.name) ?? setUpBy;
363
+ }
364
+ function detachRootExtensions(store) {
365
+ const registry = getRegistry();
366
+ if (!registry.roots.delete(store)) return;
367
+ const applied = registry.applied.get(store);
368
+ registry.applied.delete(store);
369
+ if (!applied) return;
370
+ for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
371
+ }
372
+ function notifyRootExtensionsHmr(store) {
373
+ const registry = getRegistry();
374
+ const applied = registry.applied.get(store);
375
+ if (!applied) return;
376
+ for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
377
+ }
378
+
379
+ exports.Block = Block;
380
+ exports.ErrorBoundary = ErrorBoundary;
381
+ exports.attachRootExtensions = attachRootExtensions;
382
+ exports.context = context;
383
+ exports.detachRootExtensions = detachRootExtensions;
384
+ exports.getTextureView = getTextureView;
385
+ exports.notifyAlpha = notifyAlpha;
386
+ exports.notifyDepreciated = notifyDepreciated;
387
+ exports.notifyRootExtensionsHmr = notifyRootExtensionsHmr;
388
+ exports.registerRootExtension = registerRootExtension;
389
+ exports.setRenderOverride = setRenderOverride;
390
+ exports.stageTextures = stageTextures;
391
+ exports.unstageTextures = unstageTextures;
392
+ exports.useBridge = useBridge;
393
+ exports.useFrame = useFrame;
394
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
395
+ exports.useMutableCallback = useMutableCallback;
396
+ exports.useStore = useStore;
397
+ exports.useThree = useThree;