@react-three/fiber 10.0.0-canary.d6fdf72 → 10.0.0-canary.f046a54

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/legacy.d.cts CHANGED
@@ -6,6 +6,8 @@ import * as three_webgpu from 'three/webgpu';
6
6
  import { WebGPURenderer as WebGPURenderer$1, Node, StorageTexture, Data3DTexture, CanvasTarget, ShaderNodeObject } from 'three/webgpu';
7
7
  import { StoreApi } from 'zustand';
8
8
  import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
9
+ import { FrameTimingState, FrameCallback as FrameCallback$1, SchedulerApi, UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
10
+ export { AddPhaseOptions, FrameControls, FrameNextControls, FrameTimingState, RootOptions, Scheduler, SchedulerApi, UseFrameNextOptions, UseFrameOptions, getScheduler } from '@pmndrs/scheduler';
9
11
  import { Options } from 'react-use-measure';
10
12
  import * as react_jsx_runtime from 'react/jsx-runtime';
11
13
  import { ThreeElement as ThreeElement$1, Euler as Euler$2 } from '@react-three/fiber';
@@ -291,228 +293,33 @@ interface VisibilityEntry {
291
293
  }
292
294
 
293
295
  //* Scheduler Types (useFrame) ==============================
296
+ //
297
+ // The generic, framework-agnostic scheduler types now live in @pmndrs/scheduler.
298
+ // This file re-exports them and layers r3f's RootState-aware frame state on top,
299
+ // so existing `#types` imports across the codebase keep resolving unchanged.
294
300
 
295
301
 
296
302
 
297
- // Public Options --------------------------------
303
+ // Frame State (r3f-specific) --------------------------------
298
304
 
299
305
  /**
300
- * Options for useFrame hook
301
- */
302
- interface UseFrameNextOptions {
303
- /** Optional stable id for the job. Auto-generated if not provided */
304
- id?: string
305
- /** Named phase to run in. Default: 'update' */
306
- phase?: string
307
- /** Run before this phase or job id */
308
- before?: string | string[]
309
- /** Run after this phase or job id */
310
- after?: string | string[]
311
- /** Priority within phase. Higher runs first. Default: 0 */
312
- priority?: number
313
- /** Max frames per second for this job */
314
- fps?: number
315
- /** If true, skip frames when behind. If false, try to catch up. Default: true */
316
- drop?: boolean
317
- /** Enable/disable without unregistering. Default: true */
318
- enabled?: boolean
319
- }
320
-
321
- /** Alias for UseFrameNextOptions */
322
- type UseFrameOptions = UseFrameNextOptions
323
-
324
- /**
325
- * Options for addPhase
326
- */
327
- interface AddPhaseOptions {
328
- /** Insert this phase before the specified phase */
329
- before?: string
330
- /** Insert this phase after the specified phase */
331
- after?: string
332
- }
333
-
334
- // Frame State --------------------------------
335
-
336
- /**
337
- * Timing-only state for independent/outside mode (no RootState)
338
- */
339
- interface FrameTimingState {
340
- /** High-resolution timestamp from RAF (ms) */
341
- time: number
342
- /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
343
- delta: number
344
- /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
345
- elapsed: number
346
- /** Incrementing frame counter */
347
- frame: number
348
- }
349
-
350
- /**
351
- * State passed to useFrame callbacks (extends RootState with timing)
306
+ * State passed to useFrame callbacks (extends RootState with timing).
352
307
  */
353
308
  interface FrameNextState extends RootState, FrameTimingState {}
354
309
 
355
310
  /** Alias for FrameNextState */
356
311
  type FrameState = FrameNextState
357
312
 
358
- // Root Options --------------------------------
313
+ // Callback Types (r3f-specific) --------------------------------
359
314
 
360
315
  /**
361
- * Options for registerRoot
316
+ * Callback function for useFrame. Receives the full r3f RootState plus timing.
362
317
  */
363
- interface RootOptions {
364
- /** State provider for callbacks. Optional in independent mode. */
365
- getState?: () => any
366
- /** Error handler for job errors. Falls back to console.error if not provided. */
367
- onError?: (error: Error) => void
368
- }
369
-
370
- // Callback Types --------------------------------
371
-
372
- /**
373
- * Callback function for useFrame
374
- */
375
- type FrameNextCallback = (state: FrameNextState, delta: number) => void
318
+ type FrameNextCallback = FrameCallback$1<RootState>
376
319
 
377
320
  /** Alias for FrameNextCallback */
378
321
  type FrameCallback = FrameNextCallback
379
322
 
380
- // Controls returned from useFrame --------------------------------
381
-
382
- /**
383
- * Controls object returned from useFrame hook
384
- */
385
- interface FrameNextControls {
386
- /** The job's unique ID */
387
- id: string
388
- /** Access to the global scheduler for frame loop control */
389
- scheduler: SchedulerApi
390
- /** Manually step this job only (bypasses FPS limiting) */
391
- step(timestamp?: number): void
392
- /** Manually step ALL jobs in the scheduler */
393
- stepAll(timestamp?: number): void
394
- /** Pause this job (set enabled=false) */
395
- pause(): void
396
- /** Resume this job (set enabled=true) */
397
- resume(): void
398
- /** Reactive paused state - automatically triggers re-render when changed */
399
- isPaused: boolean
400
- }
401
-
402
- /** Alias for FrameNextControls */
403
- type FrameControls = FrameNextControls
404
-
405
- // Scheduler Interface --------------------------------
406
-
407
- /**
408
- * Public interface for the global Scheduler
409
- */
410
- interface SchedulerApi {
411
- //* Phase Management --------------------------------
412
-
413
- /** Add a named phase to the scheduler */
414
- addPhase(name: string, options?: AddPhaseOptions): void
415
- /** Get the ordered list of phase names */
416
- readonly phases: string[]
417
- /** Check if a phase exists */
418
- hasPhase(name: string): boolean
419
-
420
- //* Root Management --------------------------------
421
-
422
- /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
423
- registerRoot(id: string, options?: RootOptions): () => void
424
- /** Unregister a root */
425
- unregisterRoot(id: string): void
426
- /** Generate a unique root ID */
427
- generateRootId(): string
428
- /** Get the number of registered roots */
429
- getRootCount(): number
430
- /** Check if any root is registered and ready */
431
- readonly isReady: boolean
432
- /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
433
- onRootReady(callback: () => void): () => void
434
-
435
- //* Job Registration --------------------------------
436
-
437
- /** Register a job with the scheduler (returns unsubscribe function) */
438
- register(
439
- callback: FrameNextCallback,
440
- options?: {
441
- id?: string
442
- rootId?: string
443
- phase?: string
444
- before?: string | string[]
445
- after?: string | string[]
446
- priority?: number
447
- fps?: number
448
- drop?: boolean
449
- enabled?: boolean
450
- },
451
- ): () => void
452
- /** Update a job's options */
453
- updateJob(
454
- id: string,
455
- options: {
456
- priority?: number
457
- fps?: number
458
- drop?: boolean
459
- enabled?: boolean
460
- phase?: string
461
- before?: string | string[]
462
- after?: string | string[]
463
- },
464
- ): void
465
- /** Unregister a job by ID */
466
- unregister(id: string, rootId?: string): void
467
- /** Get the number of registered jobs */
468
- getJobCount(): number
469
- /** Get all job IDs */
470
- getJobIds(): string[]
471
-
472
- //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
473
-
474
- /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
475
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
476
-
477
- //* Idle Callbacks (for legacy addTail) --------------------------------
478
-
479
- /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
480
- onIdle(callback: (timestamp: number) => void): () => void
481
-
482
- //* Frame Loop Control --------------------------------
483
-
484
- /** Start the scheduler loop */
485
- start(): void
486
- /** Stop the scheduler loop */
487
- stop(): void
488
- /** Check if the scheduler is running */
489
- readonly isRunning: boolean
490
- /** Get/set the frameloop mode ('always', 'demand', 'never') */
491
- frameloop: Frameloop
492
- /** Independent mode - runs without Canvas, callbacks receive timing-only state */
493
- independent: boolean
494
-
495
- //* Manual Stepping --------------------------------
496
-
497
- /** Manually step all jobs once (for frameloop='never' or testing) */
498
- step(timestamp?: number): void
499
- /** Manually step a single job by ID */
500
- stepJob(id: string, timestamp?: number): void
501
- /** Request frame(s) to be rendered (for frameloop='demand') */
502
- invalidate(frames?: number): void
503
-
504
- //* Per-Job Control --------------------------------
505
-
506
- /** Check if a job is paused */
507
- isJobPaused(id: string): boolean
508
- /** Pause a job */
509
- pauseJob(id: string): void
510
- /** Resume a job */
511
- resumeJob(id: string): void
512
- /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
513
- subscribeJobState(id: string, listener: () => void): () => void
514
- }
515
-
516
323
  //* Buffer Types (useBuffers) ========================================
517
324
 
518
325
  /**
@@ -1517,146 +1324,6 @@ declare global {
1517
1324
  }
1518
1325
  }
1519
1326
 
1520
- //* useFrameNext Types ==============================
1521
-
1522
-
1523
-
1524
- //* Global Type Declarations ==============================
1525
-
1526
- declare global {
1527
- // Job --------------------------------
1528
-
1529
- /**
1530
- * Internal job representation in the scheduler
1531
- */
1532
- interface Job {
1533
- /** Unique identifier */
1534
- id: string
1535
- /** The callback to execute */
1536
- callback: FrameNextCallback
1537
- /** Phase this job belongs to */
1538
- phase: string
1539
- /** Run before these phases/job ids */
1540
- before: Set<string>
1541
- /** Run after these phases/job ids */
1542
- after: Set<string>
1543
- /** Priority within phase (higher first) */
1544
- priority: number
1545
- /** Insertion order for deterministic tie-breaking */
1546
- index: number
1547
- /** Max FPS for this job (undefined = no limit) */
1548
- fps?: number
1549
- /** Drop frames when behind (true) or catch up (false) */
1550
- drop: boolean
1551
- /** Last run timestamp (ms) */
1552
- lastRun?: number
1553
- /** Whether job is enabled */
1554
- enabled: boolean
1555
- /** Internal flag: system jobs (like default render) don't block user render takeover */
1556
- system?: boolean
1557
- }
1558
-
1559
- // Phase Graph --------------------------------
1560
-
1561
- /**
1562
- * A node in the phase graph
1563
- */
1564
- interface PhaseNode {
1565
- /** Phase name */
1566
- name: string
1567
- /** Whether this was auto-generated from a before/after constraint */
1568
- isAutoGenerated: boolean
1569
- }
1570
-
1571
- /**
1572
- * Options for creating a job from hook options
1573
- */
1574
- interface JobOptions {
1575
- id?: string
1576
- phase?: string
1577
- before?: string | string[]
1578
- after?: string | string[]
1579
- priority?: number
1580
- fps?: number
1581
- drop?: boolean
1582
- enabled?: boolean
1583
- }
1584
-
1585
- // Frame Loop State --------------------------------
1586
-
1587
- /**
1588
- * Internal frame loop state
1589
- */
1590
- interface FrameLoopState {
1591
- /** Whether the loop is running */
1592
- running: boolean
1593
- /** Current RAF handle */
1594
- rafHandle: number | null
1595
- /** Last frame timestamp in ms (null = uninitialized) */
1596
- lastTime: number | null
1597
- /** Frame counter */
1598
- frameCount: number
1599
- /** Elapsed time since first frame in ms */
1600
- elapsedTime: number
1601
- /** createdAt timestamp in ms */
1602
- createdAt: number
1603
- }
1604
-
1605
- // Root Entry --------------------------------
1606
-
1607
- /**
1608
- * Internal representation of a registered root (Canvas).
1609
- * Tracks jobs and manages rebuild state for this root.
1610
- * @internal
1611
- */
1612
- interface RootEntry {
1613
- /** Unique identifier for this root */
1614
- id: string
1615
- /** Function to get the root's current state. Returns any to support independent mode. */
1616
- getState: () => any
1617
- /** Map of job IDs to Job objects */
1618
- jobs: Map<string, Job>
1619
- /** Cached sorted job list for execution order */
1620
- sortedJobs: Job[]
1621
- /** Whether sortedJobs needs rebuilding */
1622
- needsRebuild: boolean
1623
- }
1624
-
1625
- /**
1626
- * Internal representation of a global job (deprecated API).
1627
- * Global jobs run once per frame, not per-root.
1628
- * Used by legacy addEffect/addAfterEffect APIs.
1629
- * @internal
1630
- * @deprecated Use useFrame with phases instead
1631
- */
1632
- interface GlobalJob {
1633
- /** Unique identifier for this global job */
1634
- id: string
1635
- /** Callback invoked with RAF timestamp in ms */
1636
- callback: (timestamp: number) => void
1637
- }
1638
-
1639
- // HMR Support --------------------------------
1640
-
1641
- /**
1642
- * Hot Module Replacement data structure for preserving scheduler state
1643
- * @internal
1644
- */
1645
- interface HMRData {
1646
- /** Shared data object for storing values across reloads */
1647
- data: Record<string, any>
1648
- /** Optional function to accept HMR updates */
1649
- accept?: () => void
1650
- }
1651
-
1652
- // Default Phases --------------------------------
1653
-
1654
- /**
1655
- * Default phase names for the scheduler
1656
- */
1657
- type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1658
- }
1659
-
1660
1327
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1661
1328
 
1662
1329
  interface MathRepresentation {
@@ -2149,383 +1816,21 @@ declare function getLoader<L extends LoaderLike | ConstructorRepresentation<Load
2149
1816
  * Note: this hook's caller must be wrapped with `React.Suspense`
2150
1817
  * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
2151
1818
  */
2152
- declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
1819
+ declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
2153
1820
  declare namespace useLoader {
2154
- var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void) => void;
2155
- var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I) => void;
1821
+ var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike) => void;
1822
+ var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, cacheKey?: InputLike) => void;
2156
1823
  var loader: typeof getLoader;
2157
1824
  }
2158
1825
 
2159
- /**
2160
- * Global Singleton Scheduler - manages the frame loop and job execution for ALL R3F roots.
2161
- *
2162
- * Features:
2163
- * - Single RAF loop for entire application
2164
- * - Root registration (multiple Canvas support)
2165
- * - Global phases for addEffect/addAfterEffect (deprecated)
2166
- * - Per-root job management with phases, priorities, FPS throttling
2167
- * - onIdle callbacks for addTail (deprecated)
2168
- * - Demand mode support via invalidate()
2169
- */
2170
- declare class Scheduler {
2171
- private static readonly INSTANCE_KEY;
2172
- private static get instance();
2173
- private static set instance(value);
2174
- /**
2175
- * Get the global scheduler instance (creates if doesn't exist).
2176
- * Uses HMR data to preserve instance across hot reloads.
2177
- * @returns {Scheduler} The singleton scheduler instance
2178
- */
2179
- static get(): Scheduler;
2180
- /**
2181
- * Reset the singleton instance. Stops the loop and clears all state.
2182
- * Primarily used for testing to ensure clean state between tests.
2183
- * @returns {void}
2184
- */
2185
- static reset(): void;
2186
- private roots;
2187
- private phaseGraph;
2188
- private loopState;
2189
- private stoppedTime;
2190
- private nextRootIndex;
2191
- private globalBeforeJobs;
2192
- private globalAfterJobs;
2193
- private nextGlobalIndex;
2194
- private idleCallbacks;
2195
- private nextJobIndex;
2196
- private jobStateListeners;
2197
- private pendingFrames;
2198
- private _frameloop;
2199
- private _independent;
2200
- private errorHandler;
2201
- private rootReadyCallbacks;
2202
- get phases(): string[];
2203
- get frameloop(): Frameloop;
2204
- set frameloop(mode: Frameloop);
2205
- get isRunning(): boolean;
2206
- get isReady(): boolean;
2207
- get independent(): boolean;
2208
- set independent(value: boolean);
2209
- constructor();
2210
- /**
2211
- * Register a root (Canvas) with the scheduler.
2212
- * The first root to register starts the RAF loop (if frameloop='always').
2213
- * @param {string} id - Unique identifier for this root
2214
- * @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
2215
- * @returns {() => void} Unsubscribe function to remove this root
2216
- */
2217
- registerRoot(id: string, options?: RootOptions): () => void;
2218
- /**
2219
- * Unregister a root from the scheduler.
2220
- * Cleans up all job state listeners for this root's jobs.
2221
- * The last root to unregister stops the RAF loop.
2222
- * @param {string} id - The root ID to unregister
2223
- * @returns {void}
2224
- */
2225
- unregisterRoot(id: string): void;
2226
- /**
2227
- * Subscribe to be notified when a root becomes available.
2228
- * Fires immediately if a root already exists.
2229
- * @param {() => void} callback - Function called when first root registers
2230
- * @returns {() => void} Unsubscribe function
2231
- */
2232
- onRootReady(callback: () => void): () => void;
2233
- /**
2234
- * Notify all registered root-ready callbacks.
2235
- * Called when the first root registers.
2236
- * @returns {void}
2237
- * @private
2238
- */
2239
- private notifyRootReady;
2240
- /**
2241
- * Ensure a default root exists for independent mode.
2242
- * Creates a minimal root with no state provider.
2243
- * @returns {void}
2244
- * @private
2245
- */
2246
- private ensureDefaultRoot;
2247
- /**
2248
- * Trigger error handling for job errors.
2249
- * Uses the bound error handler if available, otherwise logs to console.
2250
- * @param {Error} error - The error to handle
2251
- * @returns {void}
2252
- */
2253
- triggerError(error: Error): void;
2254
- /**
2255
- * Add a named phase to the scheduler's execution order.
2256
- * Marks all roots for rebuild to incorporate the new phase.
2257
- * @param {string} name - The phase name (e.g., 'physics', 'postprocess')
2258
- * @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
2259
- * @returns {void}
2260
- * @example
2261
- * scheduler.addPhase('physics', { before: 'update' });
2262
- * scheduler.addPhase('postprocess', { after: 'render' });
2263
- */
2264
- addPhase(name: string, options?: AddPhaseOptions): void;
2265
- /**
2266
- * Check if a phase exists in the scheduler.
2267
- * @param {string} name - The phase name to check
2268
- * @returns {boolean} True if the phase exists
2269
- */
2270
- hasPhase(name: string): boolean;
2271
- /**
2272
- * Register a global job that runs once per frame (not per-root).
2273
- * Used internally by deprecated addEffect/addAfterEffect APIs.
2274
- * @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
2275
- * @param {string} id - Unique identifier for this global job
2276
- * @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
2277
- * @returns {() => void} Unsubscribe function to remove this global job
2278
- * @deprecated Use useFrame with phases instead
2279
- */
2280
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void;
2281
- /**
2282
- * Register an idle callback that fires when the loop stops.
2283
- * Used internally by deprecated addTail API.
2284
- * @param {(timestamp: number) => void} callback - Function called when loop becomes idle
2285
- * @returns {() => void} Unsubscribe function to remove this idle callback
2286
- * @deprecated Use demand mode with invalidate() instead
2287
- */
2288
- onIdle(callback: (timestamp: number) => void): () => void;
2289
- /**
2290
- * Notify all registered idle callbacks.
2291
- * Called when the loop stops in demand mode.
2292
- * @param {number} timestamp - The RAF timestamp when idle occurred
2293
- * @returns {void}
2294
- * @private
2295
- */
2296
- private notifyIdle;
2297
- /**
2298
- * Register a job (frame callback) with a specific root.
2299
- * This is the core registration method used by useFrame internally.
2300
- * @param {FrameNextCallback} callback - The function to call each frame
2301
- * @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
2302
- * @param {string} [options.rootId] - Target root ID (defaults to first registered root)
2303
- * @param {string} [options.id] - Unique job ID (auto-generated if not provided)
2304
- * @param {string} [options.phase] - Execution phase (defaults to 'update')
2305
- * @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
2306
- * @param {number} [options.fps] - FPS throttle limit
2307
- * @param {boolean} [options.drop] - Drop frames when behind (default true)
2308
- * @param {boolean} [options.enabled] - Whether job is active (default true)
2309
- * @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
2310
- * @returns {() => void} Unsubscribe function to remove this job
2311
- */
2312
- register(callback: FrameNextCallback, options?: JobOptions & {
2313
- rootId?: string;
2314
- system?: boolean;
2315
- }): () => void;
2316
- /**
2317
- * Unregister a job by its ID.
2318
- * Searches all roots if rootId is not provided.
2319
- * @param {string} id - The job ID to unregister
2320
- * @param {string} [rootId] - Optional root ID to search (searches all if not provided)
2321
- * @returns {void}
2322
- */
2323
- unregister(id: string, rootId?: string): void;
2324
- /**
2325
- * Update a job's options dynamically.
2326
- * Searches all roots to find the job by ID.
2327
- * Phase/constraint changes trigger a rebuild of the sorted job list.
2328
- * @param {string} id - The job ID to update
2329
- * @param {Partial<JobOptions>} options - The options to update
2330
- * @returns {void}
2331
- */
2332
- updateJob(id: string, options: Partial<JobOptions>): void;
2333
- /**
2334
- * Check if a job is currently paused (disabled).
2335
- * @param {string} id - The job ID to check
2336
- * @returns {boolean} True if the job exists and is paused
2337
- */
2338
- isJobPaused(id: string): boolean;
2339
- /**
2340
- * Subscribe to state changes for a specific job.
2341
- * Listener is called when job is paused or resumed.
2342
- * @param {string} id - The job ID to subscribe to
2343
- * @param {() => void} listener - Callback invoked on state changes
2344
- * @returns {() => void} Unsubscribe function
2345
- */
2346
- subscribeJobState(id: string, listener: () => void): () => void;
2347
- /**
2348
- * Notify all listeners that a job's state has changed.
2349
- * @param {string} id - The job ID that changed
2350
- * @returns {void}
2351
- * @private
2352
- */
2353
- private notifyJobStateChange;
2354
- /**
2355
- * Pause a job by ID (sets enabled=false).
2356
- * Notifies any subscribed state listeners.
2357
- * @param {string} id - The job ID to pause
2358
- * @returns {void}
2359
- */
2360
- pauseJob(id: string): void;
2361
- /**
2362
- * Resume a paused job by ID (sets enabled=true).
2363
- * Resets job timing to prevent frame accumulation.
2364
- * Notifies any subscribed state listeners.
2365
- * @param {string} id - The job ID to resume
2366
- * @returns {void}
2367
- */
2368
- resumeJob(id: string): void;
2369
- /**
2370
- * Start the requestAnimationFrame loop.
2371
- * Resets timing state (elapsedTime, frameCount) on start.
2372
- * No-op if already running.
2373
- * @returns {void}
2374
- */
2375
- start(): void;
2376
- /**
2377
- * Stop the requestAnimationFrame loop.
2378
- * Cancels any pending RAF callback.
2379
- * No-op if not running.
2380
- * @returns {void}
2381
- */
2382
- stop(): void;
2383
- /**
2384
- * Request frames to be rendered in demand mode.
2385
- * Accumulates pending frames (capped at 60) and starts the loop if not running.
2386
- * No-op if frameloop is not 'demand'.
2387
- * @param {number} [frames=1] - Number of frames to request
2388
- * @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
2389
- * - `false` (default): Sets pending frames to the specified value (replaces existing count)
2390
- * - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
2391
- * @returns {void}
2392
- * @example
2393
- * // Request a single frame render
2394
- * scheduler.invalidate();
2395
- *
2396
- * @example
2397
- * // Request 5 frames (e.g., for animations)
2398
- * scheduler.invalidate(5);
2399
- *
2400
- * @example
2401
- * // Set pending frames to exactly 3 (don't stack with existing)
2402
- * scheduler.invalidate(3, false);
2403
- *
2404
- * @example
2405
- * // Add 2 more frames to existing pending count
2406
- * scheduler.invalidate(2, true);
2407
- */
2408
- invalidate(frames?: number, stackFrames?: boolean): void;
2409
- /**
2410
- * Reset timing state for deterministic testing.
2411
- * Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
2412
- * @returns {void}
2413
- */
2414
- resetTiming(): void;
2415
- /**
2416
- * Manually execute a single frame for all roots.
2417
- * Useful for frameloop='never' mode or testing scenarios.
2418
- * @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
2419
- * @returns {void}
2420
- * @example
2421
- * // Manual control mode
2422
- * scheduler.frameloop = 'never';
2423
- * scheduler.step(); // Execute one frame
2424
- */
2425
- step(timestamp?: number): void;
2426
- /**
2427
- * Manually execute a single job by its ID.
2428
- * Useful for testing individual job callbacks in isolation.
2429
- * @param {string} id - The job ID to step
2430
- * @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
2431
- * @returns {void}
2432
- */
2433
- stepJob(id: string, timestamp?: number): void;
2434
- /**
2435
- * Main RAF loop callback.
2436
- * Executes frame, handles demand mode, and schedules next frame.
2437
- * @param {number} timestamp - RAF timestamp in milliseconds
2438
- * @returns {void}
2439
- * @private
2440
- */
2441
- private loop;
2442
- /**
2443
- * Execute a single frame across all roots.
2444
- * Order: globalBefore → each root's jobs → globalAfter
2445
- * @param {number} timestamp - RAF timestamp in milliseconds
2446
- * @returns {void}
2447
- * @private
2448
- */
2449
- private executeFrame;
2450
- /**
2451
- * Run all global jobs from a job map.
2452
- * Catches and logs errors without stopping execution.
2453
- * @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
2454
- * @param {number} timestamp - RAF timestamp in milliseconds
2455
- * @returns {void}
2456
- * @private
2457
- */
2458
- private runGlobalJobs;
2459
- /**
2460
- * Execute all jobs for a single root in sorted order.
2461
- * Rebuilds sorted job list if needed, then dispatches each job.
2462
- * Errors are caught and propagated via triggerError.
2463
- * @param {RootEntry} root - The root entry to tick
2464
- * @param {number} timestamp - RAF timestamp in milliseconds
2465
- * @param {number} delta - Time since last frame in seconds
2466
- * @returns {void}
2467
- * @private
2468
- */
2469
- private tickRoot;
2470
- /**
2471
- * Get the total number of registered jobs across all roots.
2472
- * Includes both per-root jobs and global before/after jobs.
2473
- * @returns {number} Total job count
2474
- */
2475
- getJobCount(): number;
2476
- /**
2477
- * Get all registered job IDs across all roots.
2478
- * Includes both per-root jobs and global before/after jobs.
2479
- * @returns {string[]} Array of all job IDs
2480
- */
2481
- getJobIds(): string[];
2482
- /**
2483
- * Get the number of registered roots (Canvas instances).
2484
- * @returns {number} Number of registered roots
2485
- */
2486
- getRootCount(): number;
2487
- /**
2488
- * Check if any user (non-system) jobs are registered in a specific phase.
2489
- * Used by the default render job to know if a user has taken over rendering.
2490
- *
2491
- * @param phase The phase to check
2492
- * @param rootId Optional root ID to check (checks all roots if not provided)
2493
- * @returns true if any user jobs exist in the phase
2494
- */
2495
- hasUserJobsInPhase(phase: string, rootId?: string): boolean;
2496
- /**
2497
- * Generate a unique root ID for automatic root registration.
2498
- * @returns {string} A unique root ID in the format 'root_N'
2499
- */
2500
- generateRootId(): string;
2501
- /**
2502
- * Generate a unique job ID.
2503
- * @returns {string} A unique job ID in the format 'job_N'
2504
- * @private
2505
- */
2506
- private generateJobId;
2507
- /**
2508
- * Normalize before/after constraints to a Set.
2509
- * Handles undefined, single string, or array inputs.
2510
- * @param {string | string[] | undefined} value - The constraint value(s)
2511
- * @returns {Set<string>} Normalized Set of constraint strings
2512
- * @private
2513
- */
2514
- private normalizeConstraints;
2515
- }
2516
- /**
2517
- * Get the global scheduler instance.
2518
- * Creates one if it doesn't exist.
2519
- */
2520
- declare const getScheduler: () => Scheduler;
2521
-
2522
1826
  /**
2523
1827
  * Frame hook with phase-based ordering, priority, and FPS throttling.
2524
1828
  *
2525
- * Works both inside and outside Canvas context:
2526
- * - Inside Canvas: Full RootState (gl, scene, camera, etc.)
2527
- * - Outside Canvas (waiting mode): Waits for Canvas to mount, then gets full state
2528
- * - Outside Canvas (independent mode): Fires immediately with timing-only state
1829
+ * Always delivers full RootState — works both inside and outside Canvas context:
1830
+ * - Inside Canvas: Full RootState (renderer, scene, camera, etc.)
1831
+ * - Outside Canvas: The job registers immediately but the callback is held until a
1832
+ * Canvas adopts it, then runs with full RootState. For hostless / standalone
1833
+ * frame loops with no Canvas, use `@pmndrs/scheduler` directly.
2529
1834
  *
2530
1835
  * Returns a controls object for manual stepping, pausing, and resuming.
2531
1836
  *
@@ -2542,16 +1847,16 @@ declare const getScheduler: () => Scheduler;
2542
1847
  * useFrame((state, delta) => { ... }, { phase: 'physics' })
2543
1848
  *
2544
1849
  * @example
2545
- * // Outside Canvas - waits for Canvas to mount
1850
+ * // Outside Canvas - callback waits for a Canvas, then always has full state
2546
1851
  * function UI() {
2547
1852
  * useFrame((state, delta) => { syncUI(state.camera) });
2548
1853
  * return <button>...</button>;
2549
1854
  * }
2550
1855
  *
2551
1856
  * @example
2552
- * // Independent mode - no Canvas needed
2553
- * getScheduler().independent = true;
2554
- * useFrame((state, delta) => { updateGame(delta) });
1857
+ * // Hostless / standalone loop (no Canvas) - use @pmndrs/scheduler directly
1858
+ * import { getScheduler } from '@pmndrs/scheduler'
1859
+ * getScheduler().register((state, delta) => { updateGame(delta) })
2555
1860
  *
2556
1861
  * @example
2557
1862
  * // Scheduler-only access (no callback)
@@ -4404,5 +3709,5 @@ declare function isOnce(value: unknown): value is {
4404
3709
  */
4405
3710
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
4406
3711
 
4407
- export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Scheduler, Texture, _roots, act, 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, getScheduler, 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 };
4408
- export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeProps, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, LegacyRootState as RootState, RootStore, SchedulerApi, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };
3712
+ export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Texture, _roots, act, 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 };
3713
+ export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameNextCallback, FrameNextState, FrameState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeProps, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, LegacyRootState as RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };