@flare-engine/devtools 0.3.1 → 0.4.1

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/index.d.mts CHANGED
@@ -108,9 +108,6 @@ interface DevtoolsContextValue {
108
108
  scrubber: TimeScrubber<unknown>;
109
109
  selectedEntity: number | null;
110
110
  select(entity: number | null): void;
111
- pause(): void;
112
- step(): void;
113
- resume(): void;
114
111
  }
115
112
  declare const DevtoolsContext: import("react").Context<DevtoolsContextValue | null>;
116
113
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;iBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;cAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;cAEI,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;;;UChGe;;EAEf;;EAEA;;EAEA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;EACP;EACA;EACA;;cAGW,iCAAe,QAAA;;;iBC3BZ;;;;iBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;iBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;iBAIO,gBAAgB;;;;;;;iBC9BhB,eAAe;;;;;;;iBCAf,iBAAiB;;;UCDhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;iBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;iBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;cAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;cAEI,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;;;UChGe;;EAEf;;EAEA;;EAEA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;;cAGI,iCAAe,QAAA;;;iBCxBZ;;;;iBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;iBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;iBAIO,gBAAgB;;;;;;;iBC9BhB,eAAe;;;;;;;iBCAf,iBAAiB;;;UCDhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;iBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
package/dist/index.d.ts CHANGED
@@ -108,9 +108,6 @@ interface DevtoolsContextValue {
108
108
  scrubber: TimeScrubber<unknown>;
109
109
  selectedEntity: number | null;
110
110
  select(entity: number | null): void;
111
- pause(): void;
112
- step(): void;
113
- resume(): void;
114
111
  }
115
112
  declare const DevtoolsContext: import("react").Context<DevtoolsContextValue | null>;
116
113
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;iBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;cAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;cAEI,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;;;UChGe;;EAEf;;EAEA;;EAEA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;EACP;EACA;EACA;;cAGW,iCAAe,QAAA;;;iBC3BZ;;;;iBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;iBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;iBAIO,gBAAgB;;;;;;;iBC9BhB,eAAe;;;;;;;iBCAf,iBAAiB;;;UCDhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;iBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;iBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;cAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;cAEI,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;;;UChGe;;EAEf;;EAEA;;EAEA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;;cAGI,iCAAe,QAAA;;;iBCxBZ;;;;iBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;iBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;iBAIO,gBAAgB;;;;;;;iBC9BhB,eAAe;;;;;;;iBCAf,iBAAiB;;;UCDhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;iBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
package/dist/index.js CHANGED
@@ -381,10 +381,7 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
381
381
  buffer,
382
382
  scrubber,
383
383
  selectedEntity,
384
- select,
385
- pause: () => scrubber.pause(),
386
- step: () => scrubber.step(),
387
- resume: () => scrubber.resume()
384
+ select
388
385
  };
389
386
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DevtoolsContext.Provider, {
390
387
  value,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Platform","View","Text","Pressable","Platform","View","Text","Pressable"],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n pause(): void;\n step(): void;\n resume(): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n pause: () => scrubber.pause(),\n step: () => scrubber.step(),\n resume: () => scrubber.resume(),\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;;AA6BA,MAAa,mBAAA,GAAA,MAAA,cAAA,CAA6D,IAAI;;;AC3B9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,OAAA,GAAA,MAAA,WAAA,CAAiB,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EAAgB;EAAQ;CAAS;AACtD;;AAaA,SAAgB,eAA8B;CAC5C,MAAM,EAAE,aAAa,YAAY;CACjC,OAAO;EACL,QAAQ,SAAS;EACjB,WAAW,SAAS;EACpB,WAAW,SAAS;EACpB,aAAa,SAAS,MAAM;EAC5B,cAAc,SAAS,OAAO;EAC9B,YAAY,SAAS,KAAK;EAC1B,SAAS,cAAsB;GAC7B,SAAS,OAAO,SAAS;EAC3B;CACF;AACF;;;;;;;AC3CA,SAAgB,cAAyB;CACvC,IAAIA,aAAAA,SAAS,OAAO,OAAO,OAAO;CAClC,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD,CAAU,CAAA;AACnB;AAEA,SAAS,UAAqB;CAC5B,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,QAAQ,aAAa;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACC,aAAAA,MAAD;EACE,OAAO;GACL,UAAU;GACV,QAAQ;GACR,OAAO;GACP,eAAe;GACf,YAAY;GACZ,SAAS;GACT,iBAAiB;GACjB,cAAc;EAChB;YAVF;GAYE,iBAAA,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AC,gBAAgB,WAAA,GAAA,MAAA,SAAA,CAAkC,IAAI;CAI7D,MAAM,eAAA,GAAA,MAAA,OAAA,CAAqB,QAAQ;CACnC,YAAY,UAAU;CACtB,MAAM,cAAA,GAAA,MAAA,OAAA,CAAoB,OAAO;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,cAAA,GAAA,MAAA,QAAA,OAA2B;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;CAAe,CAAC;CAElC,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;EACA,aAAa,SAAS,MAAM;EAC5B,YAAY,SAAS,KAAK;EAC1B,cAAc,SAAS,OAAO;CAChC;CAEA,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
1
+ {"version":3,"file":"index.js","names":["Platform","View","Text","Pressable","Platform","View","Text","Pressable"],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;;AA0BA,MAAa,mBAAA,GAAA,MAAA,cAAA,CAA6D,IAAI;;;ACxB9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,OAAA,GAAA,MAAA,WAAA,CAAiB,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EAAgB;EAAQ;CAAS;AACtD;;AAaA,SAAgB,eAA8B;CAC5C,MAAM,EAAE,aAAa,YAAY;CACjC,OAAO;EACL,QAAQ,SAAS;EACjB,WAAW,SAAS;EACpB,WAAW,SAAS;EACpB,aAAa,SAAS,MAAM;EAC5B,cAAc,SAAS,OAAO;EAC9B,YAAY,SAAS,KAAK;EAC1B,SAAS,cA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AC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
package/dist/index.mjs CHANGED
@@ -380,10 +380,7 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
380
380
  buffer,
381
381
  scrubber,
382
382
  selectedEntity,
383
- select,
384
- pause: () => scrubber.pause(),
385
- step: () => scrubber.step(),
386
- resume: () => scrubber.resume()
383
+ select
387
384
  };
388
385
  return /* @__PURE__ */ jsx(DevtoolsContext.Provider, {
389
386
  value,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n pause(): void;\n step(): void;\n resume(): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n pause: () => scrubber.pause(),\n step: () => scrubber.step(),\n resume: () => scrubber.resume(),\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue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ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;AA0BA,MAAa,kBAAkB,cAA2C,IAAI;;;ACxB9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,MAAM,WAAW,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EAAgB;EAAQ;CAAS;AACt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M,cAAc,OAAO,QAAQ;CACnC,YAAY,UAAU;CACtB,MAAM,aAAa,OAAO,OAAO;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,aAAa,cAAc;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,gBAAgB;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;CAAe,CAAC;CAElC,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;CACF;CAEA,OAAO,oBAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/devtools",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Devtools partial — entity inspector, time scrub, pause/step",
5
5
  "keywords": ["flare-engine", "devtools", "inspector", "debug"],
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  "files": ["dist", "README.md", "LICENSE", "NOTICE"],
33
33
  "scripts": {
34
34
  "build": "tsdown",
35
- "test": "bun test",
35
+ "test": "bun ../../scripts/test-isolated.mjs",
36
36
  "lint": "biome check src/",
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
@@ -40,8 +40,8 @@
40
40
  "@types/react": "^19.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "@flare-engine/core": "^0.3.1",
44
- "@flare-engine/ecs": "^0.3.1"
43
+ "@flare-engine/core": "^0.4.1",
44
+ "@flare-engine/ecs": "^0.4.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": ">=19.0.0",