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