@crup/react-timer-hook 0.0.1-alpha.4 → 0.0.1-alpha.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crup/react-timer-hook",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "Deterministic React timer lifecycle hooks for timers, schedules, and many independent timers.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -42,18 +42,21 @@
42
42
  "react": ">=18.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@astrojs/starlight": "^0.38.2",
46
45
  "@changesets/cli": "^2.29.7",
47
46
  "@commitlint/cli": "^20.2.0",
48
47
  "@commitlint/config-conventional": "^20.2.0",
48
+ "@docusaurus/core": "^3.9.2",
49
+ "@docusaurus/module-type-aliases": "^3.9.2",
50
+ "@docusaurus/preset-classic": "^3.9.2",
51
+ "@docusaurus/tsconfig": "^3.9.2",
49
52
  "@testing-library/react": "^16.3.0",
50
53
  "@types/node": "^24.10.2",
51
54
  "@types/react": "^19.2.7",
52
55
  "@types/react-dom": "^19.2.3",
53
56
  "@vitejs/plugin-react": "^5.1.2",
54
- "astro": "^6.1.4",
55
57
  "husky": "^9.1.7",
56
58
  "jsdom": "^27.3.0",
59
+ "prism-react-renderer": "^2.4.1",
57
60
  "react": "^19.2.3",
58
61
  "react-dom": "^19.2.3",
59
62
  "tsup": "^8.5.1",
@@ -64,9 +67,9 @@
64
67
  "ai:context": "node scripts/ai-context.mjs",
65
68
  "build": "tsup",
66
69
  "changeset": "changeset",
67
- "docs:build": "astro build",
68
- "docs:dev": "astro dev",
69
- "docs:preview": "astro preview",
70
+ "docs:build": "NO_UPDATE_NOTIFIER=1 docusaurus build docs-site",
71
+ "docs:dev": "NO_UPDATE_NOTIFIER=1 docusaurus start docs-site",
72
+ "docs:preview": "NO_UPDATE_NOTIFIER=1 docusaurus serve docs-site/build",
70
73
  "mcp:docs": "node mcp/server.mjs",
71
74
  "readme:check": "node scripts/check-readme.mjs",
72
75
  "release": "changeset publish",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/durationParts.ts","../src/useTimer.ts","../src/debug.ts","../src/clocks.ts","../src/state.ts","../src/useTimerGroup.ts"],"sourcesContent":["export { durationParts } from './durationParts';\nexport { useTimer } from './useTimer';\nexport { useTimerGroup } from './useTimerGroup';\n\nexport type {\n DurationParts,\n TimerControls,\n TimerDebug,\n TimerDebugEvent,\n TimerDebugLogger,\n TimerEndPredicate,\n TimerGroupItem,\n TimerGroupItemControls,\n TimerGroupResult,\n TimerSchedule,\n TimerSnapshot,\n TimerStatus,\n UseTimerGroupOptions,\n UseTimerOptions,\n} from './types';\n","import type { DurationParts } from './types';\n\nconst SECOND = 1000;\nconst MINUTE = 60 * SECOND;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\nexport function durationParts(milliseconds: number): DurationParts {\n const totalMilliseconds = Math.max(0, Math.trunc(Number.isFinite(milliseconds) ? milliseconds : 0));\n const days = Math.floor(totalMilliseconds / DAY);\n const afterDays = totalMilliseconds % DAY;\n const hours = Math.floor(afterDays / HOUR);\n const afterHours = afterDays % HOUR;\n const minutes = Math.floor(afterHours / MINUTE);\n const afterMinutes = afterHours % MINUTE;\n const seconds = Math.floor(afterMinutes / SECOND);\n\n return {\n totalMilliseconds,\n totalSeconds: Math.floor(totalMilliseconds / SECOND),\n milliseconds: afterMinutes % SECOND,\n seconds,\n minutes,\n hours,\n days,\n };\n}\n","import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';\nimport { baseDebugEvent, emitDebug } from './debug';\nimport { readClock, validatePositiveFinite } from './clocks';\nimport {\n cancelTimerState,\n createTimerState,\n endTimerState,\n pauseTimerState,\n resetTimerState,\n restartTimerState,\n resumeTimerState,\n startTimerState,\n tickTimerState,\n toSnapshot,\n type InternalTimerState,\n} from './state';\nimport type { TimerControls, TimerSchedule, TimerSnapshot, UseTimerOptions } from './types';\n\ntype ScheduleState = {\n lastRunAt: number | null;\n pending: boolean;\n leadingGeneration: number | null;\n};\n\nexport function useTimer(options: UseTimerOptions = {}): TimerSnapshot & TimerControls {\n const updateIntervalMs = options.updateIntervalMs ?? 1000;\n validatePositiveFinite(updateIntervalMs, 'updateIntervalMs');\n validateSchedules(options.schedules);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const stateRef = useRef<InternalTimerState | null>(null);\n if (stateRef.current === null) {\n stateRef.current = createTimerState(readClock());\n }\n\n const mountedRef = useRef(false);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const schedulesRef = useRef<Map<string, ScheduleState>>(new Map());\n const endCalledGenerationRef = useRef<number | null>(null);\n const [, rerender] = useReducer((value: number) => value + 1, 0);\n\n const clearScheduledTick = useCallback(() => {\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n const getSnapshot = useCallback((clock = readClock()) => {\n return toSnapshot(stateRef.current!, clock);\n }, []);\n\n const emit = useCallback(\n (type: Parameters<typeof emitDebug>[1]['type'], snapshot: TimerSnapshot, extra: Partial<Parameters<typeof emitDebug>[1]> = {}) => {\n emitDebug(optionsRef.current.debug, {\n type,\n scope: 'timer',\n ...baseDebugEvent(snapshot, stateRef.current!.generation),\n ...extra,\n });\n },\n [],\n );\n\n const controlsRef = useRef<TimerControls | null>(null);\n\n const callOnEnd = useCallback(\n (snapshot: TimerSnapshot) => {\n const generation = stateRef.current!.generation;\n if (endCalledGenerationRef.current === generation) return;\n endCalledGenerationRef.current = generation;\n\n try {\n void optionsRef.current.onEnd?.(snapshot, controlsRef.current!);\n } catch (error) {\n emitDebug(optionsRef.current.debug, {\n type: 'callback:error',\n scope: 'timer',\n ...baseDebugEvent(snapshot, generation),\n error,\n });\n }\n },\n [],\n );\n\n const runSchedule = useCallback(\n (schedule: TimerSchedule, key: string, scheduleState: ScheduleState, snapshot: TimerSnapshot, generation: number) => {\n if (scheduleState.pending && (schedule.overlap ?? 'skip') === 'skip') {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:skip',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n reason: 'overlap',\n ...baseDebugEvent(snapshot, generation),\n });\n return;\n }\n\n scheduleState.lastRunAt = snapshot.now;\n scheduleState.pending = true;\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:start',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n\n Promise.resolve()\n .then(() => schedule.callback(snapshot, controlsRef.current!))\n .then(\n () => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:end',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n error => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:error',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n )\n .finally(() => {\n if (stateRef.current?.generation === generation) {\n scheduleState.pending = false;\n }\n });\n },\n [],\n );\n\n const evaluateSchedules = useCallback(\n (snapshot: TimerSnapshot, generation: number, activation = false) => {\n const schedules = optionsRef.current.schedules ?? [];\n const liveKeys = new Set<string>();\n\n schedules.forEach((schedule, index) => {\n const key = schedule.id ?? String(index);\n liveKeys.add(key);\n let scheduleState = schedulesRef.current.get(key);\n if (!scheduleState) {\n scheduleState = { lastRunAt: null, pending: false, leadingGeneration: null };\n schedulesRef.current.set(key, scheduleState);\n }\n\n if (activation && schedule.leading && scheduleState.leadingGeneration !== generation) {\n scheduleState.leadingGeneration = generation;\n runSchedule(schedule, key, scheduleState, snapshot, generation);\n return;\n }\n\n if (scheduleState.lastRunAt === null) {\n scheduleState.lastRunAt = snapshot.now;\n return;\n }\n\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(schedule, key, scheduleState, snapshot, generation);\n }\n });\n\n for (const key of schedulesRef.current.keys()) {\n if (!liveKeys.has(key)) schedulesRef.current.delete(key);\n }\n },\n [runSchedule],\n );\n\n const processRunningState = useCallback(\n (clock = readClock(), activation = false) => {\n const state = stateRef.current!;\n if (state.status !== 'running') return;\n\n const snapshot = toSnapshot(state, clock);\n const generation = state.generation;\n\n if (optionsRef.current.endWhen?.(snapshot)) {\n if (endTimerState(state, clock)) {\n const endedSnapshot = toSnapshot(state, clock);\n emit('timer:end', endedSnapshot);\n clearScheduledTick();\n callOnEnd(endedSnapshot);\n rerender();\n }\n return;\n }\n\n evaluateSchedules(snapshot, generation, activation);\n },\n [callOnEnd, clearScheduledTick, emit, evaluateSchedules],\n );\n\n const start = useCallback(() => {\n const clock = readClock();\n if (!startTimerState(stateRef.current!, clock)) return;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:start', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [emit, processRunningState]);\n\n const pause = useCallback(() => {\n const clock = readClock();\n if (!pauseTimerState(stateRef.current!, clock)) return;\n clearScheduledTick();\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:pause', snapshot);\n rerender();\n }, [clearScheduledTick, emit]);\n\n const resume = useCallback(() => {\n const clock = readClock();\n if (!resumeTimerState(stateRef.current!, clock)) return;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:resume', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [emit, processRunningState]);\n\n const reset = useCallback(\n (resetOptions: { autoStart?: boolean } = {}) => {\n const clock = readClock();\n clearScheduledTick();\n resetTimerState(stateRef.current!, clock, resetOptions);\n schedulesRef.current.clear();\n endCalledGenerationRef.current = null;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:reset', snapshot);\n if (resetOptions.autoStart) processRunningState(clock, true);\n rerender();\n },\n [clearScheduledTick, emit, processRunningState],\n );\n\n const restart = useCallback(() => {\n const clock = readClock();\n clearScheduledTick();\n restartTimerState(stateRef.current!, clock);\n schedulesRef.current.clear();\n endCalledGenerationRef.current = null;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:restart', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [clearScheduledTick, emit, processRunningState]);\n\n const cancel = useCallback(\n (reason?: string) => {\n const clock = readClock();\n if (!cancelTimerState(stateRef.current!, clock, reason)) return;\n clearScheduledTick();\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:cancel', snapshot, { reason });\n rerender();\n },\n [clearScheduledTick, emit],\n );\n\n controlsRef.current = useMemo(\n () => ({ start, pause, resume, reset, restart, cancel }),\n [cancel, pause, reset, restart, resume, start],\n );\n\n useEffect(() => {\n mountedRef.current = true;\n if (optionsRef.current.autoStart && stateRef.current!.status === 'idle') {\n controlsRef.current!.start();\n }\n\n return () => {\n mountedRef.current = false;\n clearScheduledTick();\n };\n }, [clearScheduledTick]);\n\n const snapshot = getSnapshot();\n const generation = stateRef.current.generation;\n const status = snapshot.status;\n\n useEffect(() => {\n if (!mountedRef.current || status !== 'running') {\n clearScheduledTick();\n return;\n }\n\n clearScheduledTick();\n emit('scheduler:start', getSnapshot());\n timeoutRef.current = setTimeout(() => {\n if (!mountedRef.current) return;\n if (stateRef.current!.generation !== generation) return;\n if (stateRef.current!.status !== 'running') return;\n\n const clock = readClock();\n tickTimerState(stateRef.current!, clock);\n const tickSnapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:tick', tickSnapshot);\n processRunningState(clock);\n rerender();\n }, optionsRef.current.updateIntervalMs ?? 1000);\n\n return () => {\n if (timeoutRef.current !== null) {\n emit('scheduler:stop', getSnapshot());\n }\n clearScheduledTick();\n };\n }, [clearScheduledTick, emit, generation, getSnapshot, processRunningState, snapshot.tick, status]);\n\n return {\n ...snapshot,\n ...controlsRef.current,\n };\n}\n\nfunction validateSchedules(schedules: TimerSchedule[] | undefined): void {\n schedules?.forEach(schedule => validatePositiveFinite(schedule.everyMs, 'schedule.everyMs'));\n}\n","import type { TimerDebug, TimerDebugEvent, TimerDebugLogger, TimerSnapshot } from './types';\n\ntype DebugConfig = {\n enabled: boolean;\n includeTicks: boolean;\n label?: string;\n logger?: TimerDebugLogger;\n};\n\nexport function resolveDebug(debug: TimerDebug | undefined): DebugConfig {\n if (!debug) return { enabled: false, includeTicks: false };\n if (debug === true) return { enabled: true, includeTicks: false, logger: console.debug };\n if (typeof debug === 'function') return { enabled: true, includeTicks: false, logger: debug };\n\n return {\n enabled: debug.enabled !== false,\n includeTicks: debug.includeTicks ?? false,\n label: debug.label,\n logger: debug.logger ?? console.debug,\n };\n}\n\nexport function emitDebug(\n debug: TimerDebug | undefined,\n event: Omit<TimerDebugEvent, 'label'> & { label?: string },\n): void {\n const config = resolveDebug(debug);\n if (!config.enabled || !config.logger) return;\n if (event.type === 'timer:tick' && !config.includeTicks) return;\n\n config.logger({\n ...event,\n label: event.label ?? config.label,\n });\n}\n\nexport function baseDebugEvent(\n snapshot: TimerSnapshot,\n generation: number,\n): Pick<TimerDebugEvent, 'generation' | 'tick' | 'now' | 'elapsedMilliseconds' | 'status'> {\n return {\n generation,\n tick: snapshot.tick,\n now: snapshot.now,\n elapsedMilliseconds: snapshot.elapsedMilliseconds,\n status: snapshot.status,\n };\n}\n","export type ClockRead = {\n wallNow: number;\n monotonicNow: number;\n};\n\nexport function readClock(): ClockRead {\n const wallNow = Date.now();\n const monotonicNow =\n typeof performance !== 'undefined' && typeof performance.now === 'function'\n ? performance.now()\n : wallNow;\n\n return { wallNow, monotonicNow };\n}\n\nexport function validatePositiveFinite(value: number, name: string): void {\n if (!Number.isFinite(value) || value <= 0) {\n throw new RangeError(`${name} must be a finite number greater than 0`);\n }\n}\n","import type { ClockRead } from './clocks';\nimport type { TimerSnapshot, TimerStatus } from './types';\n\nexport type InternalTimerState = {\n status: TimerStatus;\n generation: number;\n tick: number;\n startedAt: number | null;\n pausedAt: number | null;\n endedAt: number | null;\n cancelledAt: number | null;\n cancelReason: string | null;\n baseElapsedMilliseconds: number;\n activeStartedAtMonotonic: number | null;\n now: number;\n};\n\nexport function createTimerState(clock: ClockRead): InternalTimerState {\n return {\n status: 'idle',\n generation: 0,\n tick: 0,\n startedAt: null,\n pausedAt: null,\n endedAt: null,\n cancelledAt: null,\n cancelReason: null,\n baseElapsedMilliseconds: 0,\n activeStartedAtMonotonic: null,\n now: clock.wallNow,\n };\n}\n\nexport function getElapsedMilliseconds(state: InternalTimerState, clock: ClockRead): number {\n if (state.status !== 'running' || state.activeStartedAtMonotonic === null) {\n return state.baseElapsedMilliseconds;\n }\n\n return Math.max(0, state.baseElapsedMilliseconds + clock.monotonicNow - state.activeStartedAtMonotonic);\n}\n\nexport function toSnapshot(state: InternalTimerState, clock: ClockRead): TimerSnapshot {\n const elapsedMilliseconds = getElapsedMilliseconds(state, clock);\n\n return {\n status: state.status,\n now: clock.wallNow,\n tick: state.tick,\n startedAt: state.startedAt,\n pausedAt: state.pausedAt,\n endedAt: state.endedAt,\n cancelledAt: state.cancelledAt,\n cancelReason: state.cancelReason,\n elapsedMilliseconds,\n isIdle: state.status === 'idle',\n isRunning: state.status === 'running',\n isPaused: state.status === 'paused',\n isEnded: state.status === 'ended',\n isCancelled: state.status === 'cancelled',\n };\n}\n\nexport function startTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'idle') return false;\n\n state.status = 'running';\n state.startedAt = clock.wallNow;\n state.pausedAt = null;\n state.endedAt = null;\n state.cancelledAt = null;\n state.cancelReason = null;\n state.activeStartedAtMonotonic = clock.monotonicNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function pauseTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'paused';\n state.pausedAt = clock.wallNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function resumeTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'paused') return false;\n\n state.status = 'running';\n state.pausedAt = null;\n state.activeStartedAtMonotonic = clock.monotonicNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function resetTimerState(\n state: InternalTimerState,\n clock: ClockRead,\n options: { autoStart?: boolean } = {},\n): boolean {\n state.generation += 1;\n state.tick = 0;\n state.status = options.autoStart ? 'running' : 'idle';\n state.startedAt = options.autoStart ? clock.wallNow : null;\n state.pausedAt = null;\n state.endedAt = null;\n state.cancelledAt = null;\n state.cancelReason = null;\n state.baseElapsedMilliseconds = 0;\n state.activeStartedAtMonotonic = options.autoStart ? clock.monotonicNow : null;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function restartTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n return resetTimerState(state, clock, { autoStart: true });\n}\n\nexport function cancelTimerState(state: InternalTimerState, clock: ClockRead, reason?: string): boolean {\n if (state.status === 'ended' || state.status === 'cancelled') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'cancelled';\n state.cancelledAt = clock.wallNow;\n state.cancelReason = reason ?? null;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function endTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'ended';\n state.endedAt = clock.wallNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function tickTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.tick += 1;\n state.now = clock.wallNow;\n return true;\n}\n","import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';\nimport { baseDebugEvent, emitDebug } from './debug';\nimport { readClock, validatePositiveFinite } from './clocks';\nimport {\n cancelTimerState,\n createTimerState,\n endTimerState,\n pauseTimerState,\n resetTimerState,\n restartTimerState,\n resumeTimerState,\n startTimerState,\n tickTimerState,\n toSnapshot,\n type InternalTimerState,\n} from './state';\nimport type {\n TimerControls,\n TimerGroupItem,\n TimerGroupItemControls,\n TimerGroupResult,\n TimerSchedule,\n TimerSnapshot,\n UseTimerGroupOptions,\n} from './types';\n\ntype GroupScheduleState = {\n lastRunAt: number | null;\n pending: boolean;\n leadingGeneration: number | null;\n};\n\ntype InternalGroupItem = {\n id: string;\n state: InternalTimerState;\n definition: TimerGroupItem;\n schedules: Map<string, GroupScheduleState>;\n endCalledGeneration: number | null;\n};\n\nexport function useTimerGroup(options: UseTimerGroupOptions = {}): TimerGroupResult {\n const updateIntervalMs = options.updateIntervalMs ?? 1000;\n validatePositiveFinite(updateIntervalMs, 'updateIntervalMs');\n validateItems(options.items);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const itemsRef = useRef<Map<string, InternalGroupItem>>(new Map());\n const mountedRef = useRef(false);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const [, rerender] = useReducer((value: number) => value + 1, 0);\n\n const clearScheduledTick = useCallback(() => {\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n const getItemSnapshot = useCallback((item: InternalGroupItem, clock = readClock()) => {\n return toSnapshot(item.state, clock);\n }, []);\n\n const emit = useCallback(\n (\n type: Parameters<typeof emitDebug>[1]['type'],\n item: InternalGroupItem | undefined,\n snapshot: TimerSnapshot,\n extra: Partial<Parameters<typeof emitDebug>[1]> = {},\n ) => {\n emitDebug(optionsRef.current.debug, {\n type,\n scope: 'timer-group',\n timerId: item?.id,\n ...baseDebugEvent(snapshot, item?.state.generation ?? 0),\n ...extra,\n });\n },\n [],\n );\n\n const controlsFor = useCallback((id: string): TimerGroupItemControls => {\n return {\n start: () => start(id),\n pause: () => pause(id),\n resume: () => resume(id),\n reset: resetOptions => reset(id, resetOptions),\n restart: () => restart(id),\n cancel: reason => cancel(id, reason),\n };\n }, []);\n\n const callOnEnd = useCallback(\n (item: InternalGroupItem, snapshot: TimerSnapshot) => {\n const generation = item.state.generation;\n if (item.endCalledGeneration === generation) return;\n item.endCalledGeneration = generation;\n\n try {\n void item.definition.onEnd?.(snapshot, controlsFor(item.id));\n } catch (error) {\n emitDebug(optionsRef.current.debug, {\n type: 'callback:error',\n scope: 'timer-group',\n timerId: item.id,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n }\n },\n [controlsFor],\n );\n\n const runSchedule = useCallback(\n (\n item: InternalGroupItem,\n schedule: TimerSchedule,\n key: string,\n scheduleState: GroupScheduleState,\n snapshot: TimerSnapshot,\n generation: number,\n ) => {\n if (scheduleState.pending && (schedule.overlap ?? 'skip') === 'skip') {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:skip',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n reason: 'overlap',\n ...baseDebugEvent(snapshot, generation),\n });\n return;\n }\n\n scheduleState.lastRunAt = snapshot.now;\n scheduleState.pending = true;\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:start',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n\n Promise.resolve()\n .then(() => schedule.callback(snapshot, controlsFor(item.id) as TimerControls))\n .then(\n () => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:end',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n error => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:error',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n )\n .finally(() => {\n const liveItem = itemsRef.current.get(item.id);\n if (liveItem?.state.generation === generation) {\n scheduleState.pending = false;\n }\n });\n },\n [controlsFor],\n );\n\n const evaluateItemSchedules = useCallback(\n (item: InternalGroupItem, snapshot: TimerSnapshot, activation = false) => {\n const schedules = item.definition.schedules ?? [];\n const liveKeys = new Set<string>();\n\n schedules.forEach((schedule, index) => {\n const key = schedule.id ?? String(index);\n liveKeys.add(key);\n let scheduleState = item.schedules.get(key);\n if (!scheduleState) {\n scheduleState = { lastRunAt: null, pending: false, leadingGeneration: null };\n item.schedules.set(key, scheduleState);\n }\n\n if (activation && schedule.leading && scheduleState.leadingGeneration !== item.state.generation) {\n scheduleState.leadingGeneration = item.state.generation;\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n return;\n }\n\n if (scheduleState.lastRunAt === null) {\n scheduleState.lastRunAt = item.state.startedAt ?? snapshot.now;\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n }\n return;\n }\n\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n }\n });\n\n for (const key of item.schedules.keys()) {\n if (!liveKeys.has(key)) item.schedules.delete(key);\n }\n },\n [runSchedule],\n );\n\n const processItem = useCallback(\n (item: InternalGroupItem, clock = readClock(), activation = false) => {\n if (item.state.status !== 'running') return;\n\n const snapshot = toSnapshot(item.state, clock);\n if (item.definition.endWhen?.(snapshot)) {\n if (endTimerState(item.state, clock)) {\n const endedSnapshot = toSnapshot(item.state, clock);\n emit('timer:end', item, endedSnapshot);\n callOnEnd(item, endedSnapshot);\n }\n return;\n }\n\n evaluateItemSchedules(item, snapshot, activation);\n },\n [callOnEnd, emit, evaluateItemSchedules],\n );\n\n const ensureItem = useCallback((definition: TimerGroupItem): { item: InternalGroupItem; added: boolean } => {\n const existing = itemsRef.current.get(definition.id);\n if (existing) {\n existing.definition = definition;\n return { item: existing, added: false };\n }\n\n const item: InternalGroupItem = {\n id: definition.id,\n state: createTimerState(readClock()),\n definition,\n schedules: new Map(),\n endCalledGeneration: null,\n };\n itemsRef.current.set(definition.id, item);\n if (definition.autoStart) {\n startTimerState(item.state, readClock());\n }\n return { item, added: true };\n }, []);\n\n const syncItems = useCallback(() => {\n const definitions = optionsRef.current.items ?? [];\n const liveIds = new Set<string>();\n let changed = false;\n definitions.forEach(definition => {\n liveIds.add(definition.id);\n const { item, added } = ensureItem(definition);\n changed = changed || added;\n if (definition.autoStart && item.state.status === 'idle') {\n changed = startTimerState(item.state, readClock()) || changed;\n }\n });\n\n for (const id of itemsRef.current.keys()) {\n if (!liveIds.has(id)) {\n itemsRef.current.delete(id);\n changed = true;\n }\n }\n\n return changed;\n }, [ensureItem]);\n\n useEffect(() => {\n if (syncItems()) rerender();\n }, [syncItems, options.items]);\n\n const add = useCallback((item: TimerGroupItem) => {\n validateItems([item]);\n if (itemsRef.current.has(item.id)) throw new Error(`Timer item \"${item.id}\" already exists`);\n ensureItem(item);\n rerender();\n }, [ensureItem]);\n\n const update = useCallback((id: string, item: Partial<Omit<TimerGroupItem, 'id'>>) => {\n const existing = itemsRef.current.get(id);\n if (!existing) return;\n const next = { ...existing.definition, ...item, id };\n validateItems([next]);\n existing.definition = next;\n rerender();\n }, []);\n\n const remove = useCallback((id: string) => {\n itemsRef.current.delete(id);\n rerender();\n }, []);\n\n const clear = useCallback(() => {\n itemsRef.current.clear();\n clearScheduledTick();\n rerender();\n }, [clearScheduledTick]);\n\n const start = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!startTimerState(item.state, clock)) return;\n emit('timer:start', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const pause = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!pauseTimerState(item.state, clock)) return;\n emit('timer:pause', item, toSnapshot(item.state, clock));\n rerender();\n }, [emit]);\n\n const resume = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!resumeTimerState(item.state, clock)) return;\n emit('timer:resume', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const reset = useCallback((id: string, resetOptions: { autoStart?: boolean } = {}) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n resetTimerState(item.state, clock, resetOptions);\n item.schedules.clear();\n item.endCalledGeneration = null;\n emit('timer:reset', item, toSnapshot(item.state, clock));\n if (resetOptions.autoStart) processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const restart = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n restartTimerState(item.state, clock);\n item.schedules.clear();\n item.endCalledGeneration = null;\n emit('timer:restart', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const cancel = useCallback((id: string, reason?: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!cancelTimerState(item.state, clock, reason)) return;\n emit('timer:cancel', item, toSnapshot(item.state, clock), { reason });\n rerender();\n }, [emit]);\n\n const ids = Array.from(itemsRef.current.keys());\n const activeSignature = ids\n .map(id => `${id}:${itemsRef.current.get(id)!.state.status}:${itemsRef.current.get(id)!.state.generation}:${itemsRef.current.get(id)!.state.tick}`)\n .join('|');\n\n useEffect(() => {\n mountedRef.current = true;\n const runningItems = Array.from(itemsRef.current.values()).filter(item => item.state.status === 'running');\n if (runningItems.length === 0) {\n clearScheduledTick();\n return;\n }\n\n clearScheduledTick();\n const first = runningItems[0];\n emit('scheduler:start', first, toSnapshot(first.state, readClock()));\n timeoutRef.current = setTimeout(() => {\n if (!mountedRef.current) return;\n\n const clock = readClock();\n for (const item of itemsRef.current.values()) {\n if (item.state.status !== 'running') continue;\n tickTimerState(item.state, clock);\n const snapshot = toSnapshot(item.state, clock);\n emit('timer:tick', item, snapshot);\n processItem(item, clock);\n }\n\n rerender();\n }, optionsRef.current.updateIntervalMs ?? 1000);\n\n return () => {\n if (timeoutRef.current !== null) {\n emit('scheduler:stop', first, toSnapshot(first.state, readClock()));\n }\n clearScheduledTick();\n mountedRef.current = false;\n };\n }, [activeSignature, clearScheduledTick, emit, processItem]);\n\n const get = useCallback(\n (id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return undefined;\n return getItemSnapshot(item);\n },\n [getItemSnapshot],\n );\n\n const now = readClock().wallNow;\n\n return useMemo(\n () => ({\n now,\n size: itemsRef.current.size,\n ids: Array.from(itemsRef.current.keys()),\n get,\n add,\n update,\n remove,\n clear,\n start,\n pause,\n resume,\n reset,\n restart,\n cancel,\n startAll: () => Array.from(itemsRef.current.keys()).forEach(start),\n pauseAll: () => Array.from(itemsRef.current.keys()).forEach(pause),\n resumeAll: () => Array.from(itemsRef.current.keys()).forEach(resume),\n resetAll: (resetOptions?: { autoStart?: boolean }) => Array.from(itemsRef.current.keys()).forEach(id => reset(id, resetOptions)),\n restartAll: () => Array.from(itemsRef.current.keys()).forEach(restart),\n cancelAll: (reason?: string) => Array.from(itemsRef.current.keys()).forEach(id => cancel(id, reason)),\n }),\n [add, cancel, clear, get, now, pause, remove, reset, restart, resume, start, update],\n );\n}\n\nfunction validateItems(items: TimerGroupItem[] | undefined): void {\n const ids = new Set<string>();\n items?.forEach(item => {\n if (ids.has(item.id)) throw new Error(`Duplicate timer item id \"${item.id}\"`);\n ids.add(item.id);\n item.schedules?.forEach(schedule => validatePositiveFinite(schedule.everyMs, 'schedule.everyMs'));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,SAAS;AACf,IAAM,SAAS,KAAK;AACpB,IAAM,OAAO,KAAK;AAClB,IAAM,MAAM,KAAK;AAEV,SAAS,cAAc,cAAqC;AACjE,QAAM,oBAAoB,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,SAAS,YAAY,IAAI,eAAe,CAAC,CAAC;AAClG,QAAM,OAAO,KAAK,MAAM,oBAAoB,GAAG;AAC/C,QAAM,YAAY,oBAAoB;AACtC,QAAM,QAAQ,KAAK,MAAM,YAAY,IAAI;AACzC,QAAM,aAAa,YAAY;AAC/B,QAAM,UAAU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uBAAuB,SAAS,SAAS,kBAAkB,CAAC;AAAA,EAClG,CAAC;AACH;","names":["snapshot","generation","import_react"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/durationParts.ts","../src/useTimer.ts","../src/debug.ts","../src/clocks.ts","../src/state.ts","../src/useTimerGroup.ts"],"sourcesContent":["import type { DurationParts } from './types';\n\nconst SECOND = 1000;\nconst MINUTE = 60 * SECOND;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\nexport function durationParts(milliseconds: number): DurationParts {\n const totalMilliseconds = Math.max(0, Math.trunc(Number.isFinite(milliseconds) ? milliseconds : 0));\n const days = Math.floor(totalMilliseconds / DAY);\n const afterDays = totalMilliseconds % DAY;\n const hours = Math.floor(afterDays / HOUR);\n const afterHours = afterDays % HOUR;\n const minutes = Math.floor(afterHours / MINUTE);\n const afterMinutes = afterHours % MINUTE;\n const seconds = Math.floor(afterMinutes / SECOND);\n\n return {\n totalMilliseconds,\n totalSeconds: Math.floor(totalMilliseconds / SECOND),\n milliseconds: afterMinutes % SECOND,\n seconds,\n minutes,\n hours,\n days,\n };\n}\n","import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';\nimport { baseDebugEvent, emitDebug } from './debug';\nimport { readClock, validatePositiveFinite } from './clocks';\nimport {\n cancelTimerState,\n createTimerState,\n endTimerState,\n pauseTimerState,\n resetTimerState,\n restartTimerState,\n resumeTimerState,\n startTimerState,\n tickTimerState,\n toSnapshot,\n type InternalTimerState,\n} from './state';\nimport type { TimerControls, TimerSchedule, TimerSnapshot, UseTimerOptions } from './types';\n\ntype ScheduleState = {\n lastRunAt: number | null;\n pending: boolean;\n leadingGeneration: number | null;\n};\n\nexport function useTimer(options: UseTimerOptions = {}): TimerSnapshot & TimerControls {\n const updateIntervalMs = options.updateIntervalMs ?? 1000;\n validatePositiveFinite(updateIntervalMs, 'updateIntervalMs');\n validateSchedules(options.schedules);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const stateRef = useRef<InternalTimerState | null>(null);\n if (stateRef.current === null) {\n stateRef.current = createTimerState(readClock());\n }\n\n const mountedRef = useRef(false);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const schedulesRef = useRef<Map<string, ScheduleState>>(new Map());\n const endCalledGenerationRef = useRef<number | null>(null);\n const [, rerender] = useReducer((value: number) => value + 1, 0);\n\n const clearScheduledTick = useCallback(() => {\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n const getSnapshot = useCallback((clock = readClock()) => {\n return toSnapshot(stateRef.current!, clock);\n }, []);\n\n const emit = useCallback(\n (type: Parameters<typeof emitDebug>[1]['type'], snapshot: TimerSnapshot, extra: Partial<Parameters<typeof emitDebug>[1]> = {}) => {\n emitDebug(optionsRef.current.debug, {\n type,\n scope: 'timer',\n ...baseDebugEvent(snapshot, stateRef.current!.generation),\n ...extra,\n });\n },\n [],\n );\n\n const controlsRef = useRef<TimerControls | null>(null);\n\n const callOnEnd = useCallback(\n (snapshot: TimerSnapshot) => {\n const generation = stateRef.current!.generation;\n if (endCalledGenerationRef.current === generation) return;\n endCalledGenerationRef.current = generation;\n\n try {\n void optionsRef.current.onEnd?.(snapshot, controlsRef.current!);\n } catch (error) {\n emitDebug(optionsRef.current.debug, {\n type: 'callback:error',\n scope: 'timer',\n ...baseDebugEvent(snapshot, generation),\n error,\n });\n }\n },\n [],\n );\n\n const runSchedule = useCallback(\n (schedule: TimerSchedule, key: string, scheduleState: ScheduleState, snapshot: TimerSnapshot, generation: number) => {\n if (scheduleState.pending && (schedule.overlap ?? 'skip') === 'skip') {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:skip',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n reason: 'overlap',\n ...baseDebugEvent(snapshot, generation),\n });\n return;\n }\n\n scheduleState.lastRunAt = snapshot.now;\n scheduleState.pending = true;\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:start',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n\n Promise.resolve()\n .then(() => schedule.callback(snapshot, controlsRef.current!))\n .then(\n () => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:end',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n error => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:error',\n scope: 'timer',\n scheduleId: schedule.id ?? key,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n )\n .finally(() => {\n if (stateRef.current?.generation === generation) {\n scheduleState.pending = false;\n }\n });\n },\n [],\n );\n\n const evaluateSchedules = useCallback(\n (snapshot: TimerSnapshot, generation: number, activation = false) => {\n const schedules = optionsRef.current.schedules ?? [];\n const liveKeys = new Set<string>();\n\n schedules.forEach((schedule, index) => {\n const key = schedule.id ?? String(index);\n liveKeys.add(key);\n let scheduleState = schedulesRef.current.get(key);\n if (!scheduleState) {\n scheduleState = { lastRunAt: null, pending: false, leadingGeneration: null };\n schedulesRef.current.set(key, scheduleState);\n }\n\n if (activation && schedule.leading && scheduleState.leadingGeneration !== generation) {\n scheduleState.leadingGeneration = generation;\n runSchedule(schedule, key, scheduleState, snapshot, generation);\n return;\n }\n\n if (scheduleState.lastRunAt === null) {\n scheduleState.lastRunAt = snapshot.now;\n return;\n }\n\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(schedule, key, scheduleState, snapshot, generation);\n }\n });\n\n for (const key of schedulesRef.current.keys()) {\n if (!liveKeys.has(key)) schedulesRef.current.delete(key);\n }\n },\n [runSchedule],\n );\n\n const processRunningState = useCallback(\n (clock = readClock(), activation = false) => {\n const state = stateRef.current!;\n if (state.status !== 'running') return;\n\n const snapshot = toSnapshot(state, clock);\n const generation = state.generation;\n\n if (optionsRef.current.endWhen?.(snapshot)) {\n if (endTimerState(state, clock)) {\n const endedSnapshot = toSnapshot(state, clock);\n emit('timer:end', endedSnapshot);\n clearScheduledTick();\n callOnEnd(endedSnapshot);\n rerender();\n }\n return;\n }\n\n evaluateSchedules(snapshot, generation, activation);\n },\n [callOnEnd, clearScheduledTick, emit, evaluateSchedules],\n );\n\n const start = useCallback(() => {\n const clock = readClock();\n if (!startTimerState(stateRef.current!, clock)) return;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:start', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [emit, processRunningState]);\n\n const pause = useCallback(() => {\n const clock = readClock();\n if (!pauseTimerState(stateRef.current!, clock)) return;\n clearScheduledTick();\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:pause', snapshot);\n rerender();\n }, [clearScheduledTick, emit]);\n\n const resume = useCallback(() => {\n const clock = readClock();\n if (!resumeTimerState(stateRef.current!, clock)) return;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:resume', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [emit, processRunningState]);\n\n const reset = useCallback(\n (resetOptions: { autoStart?: boolean } = {}) => {\n const clock = readClock();\n clearScheduledTick();\n resetTimerState(stateRef.current!, clock, resetOptions);\n schedulesRef.current.clear();\n endCalledGenerationRef.current = null;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:reset', snapshot);\n if (resetOptions.autoStart) processRunningState(clock, true);\n rerender();\n },\n [clearScheduledTick, emit, processRunningState],\n );\n\n const restart = useCallback(() => {\n const clock = readClock();\n clearScheduledTick();\n restartTimerState(stateRef.current!, clock);\n schedulesRef.current.clear();\n endCalledGenerationRef.current = null;\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:restart', snapshot);\n processRunningState(clock, true);\n rerender();\n }, [clearScheduledTick, emit, processRunningState]);\n\n const cancel = useCallback(\n (reason?: string) => {\n const clock = readClock();\n if (!cancelTimerState(stateRef.current!, clock, reason)) return;\n clearScheduledTick();\n const snapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:cancel', snapshot, { reason });\n rerender();\n },\n [clearScheduledTick, emit],\n );\n\n controlsRef.current = useMemo(\n () => ({ start, pause, resume, reset, restart, cancel }),\n [cancel, pause, reset, restart, resume, start],\n );\n\n useEffect(() => {\n mountedRef.current = true;\n if (optionsRef.current.autoStart && stateRef.current!.status === 'idle') {\n controlsRef.current!.start();\n }\n\n return () => {\n mountedRef.current = false;\n clearScheduledTick();\n };\n }, [clearScheduledTick]);\n\n const snapshot = getSnapshot();\n const generation = stateRef.current.generation;\n const status = snapshot.status;\n\n useEffect(() => {\n if (!mountedRef.current || status !== 'running') {\n clearScheduledTick();\n return;\n }\n\n clearScheduledTick();\n emit('scheduler:start', getSnapshot());\n timeoutRef.current = setTimeout(() => {\n if (!mountedRef.current) return;\n if (stateRef.current!.generation !== generation) return;\n if (stateRef.current!.status !== 'running') return;\n\n const clock = readClock();\n tickTimerState(stateRef.current!, clock);\n const tickSnapshot = toSnapshot(stateRef.current!, clock);\n emit('timer:tick', tickSnapshot);\n processRunningState(clock);\n rerender();\n }, optionsRef.current.updateIntervalMs ?? 1000);\n\n return () => {\n if (timeoutRef.current !== null) {\n emit('scheduler:stop', getSnapshot());\n }\n clearScheduledTick();\n };\n }, [clearScheduledTick, emit, generation, getSnapshot, processRunningState, snapshot.tick, status]);\n\n return {\n ...snapshot,\n ...controlsRef.current,\n };\n}\n\nfunction validateSchedules(schedules: TimerSchedule[] | undefined): void {\n schedules?.forEach(schedule => validatePositiveFinite(schedule.everyMs, 'schedule.everyMs'));\n}\n","import type { TimerDebug, TimerDebugEvent, TimerDebugLogger, TimerSnapshot } from './types';\n\ntype DebugConfig = {\n enabled: boolean;\n includeTicks: boolean;\n label?: string;\n logger?: TimerDebugLogger;\n};\n\nexport function resolveDebug(debug: TimerDebug | undefined): DebugConfig {\n if (!debug) return { enabled: false, includeTicks: false };\n if (debug === true) return { enabled: true, includeTicks: false, logger: console.debug };\n if (typeof debug === 'function') return { enabled: true, includeTicks: false, logger: debug };\n\n return {\n enabled: debug.enabled !== false,\n includeTicks: debug.includeTicks ?? false,\n label: debug.label,\n logger: debug.logger ?? console.debug,\n };\n}\n\nexport function emitDebug(\n debug: TimerDebug | undefined,\n event: Omit<TimerDebugEvent, 'label'> & { label?: string },\n): void {\n const config = resolveDebug(debug);\n if (!config.enabled || !config.logger) return;\n if (event.type === 'timer:tick' && !config.includeTicks) return;\n\n config.logger({\n ...event,\n label: event.label ?? config.label,\n });\n}\n\nexport function baseDebugEvent(\n snapshot: TimerSnapshot,\n generation: number,\n): Pick<TimerDebugEvent, 'generation' | 'tick' | 'now' | 'elapsedMilliseconds' | 'status'> {\n return {\n generation,\n tick: snapshot.tick,\n now: snapshot.now,\n elapsedMilliseconds: snapshot.elapsedMilliseconds,\n status: snapshot.status,\n };\n}\n","export type ClockRead = {\n wallNow: number;\n monotonicNow: number;\n};\n\nexport function readClock(): ClockRead {\n const wallNow = Date.now();\n const monotonicNow =\n typeof performance !== 'undefined' && typeof performance.now === 'function'\n ? performance.now()\n : wallNow;\n\n return { wallNow, monotonicNow };\n}\n\nexport function validatePositiveFinite(value: number, name: string): void {\n if (!Number.isFinite(value) || value <= 0) {\n throw new RangeError(`${name} must be a finite number greater than 0`);\n }\n}\n","import type { ClockRead } from './clocks';\nimport type { TimerSnapshot, TimerStatus } from './types';\n\nexport type InternalTimerState = {\n status: TimerStatus;\n generation: number;\n tick: number;\n startedAt: number | null;\n pausedAt: number | null;\n endedAt: number | null;\n cancelledAt: number | null;\n cancelReason: string | null;\n baseElapsedMilliseconds: number;\n activeStartedAtMonotonic: number | null;\n now: number;\n};\n\nexport function createTimerState(clock: ClockRead): InternalTimerState {\n return {\n status: 'idle',\n generation: 0,\n tick: 0,\n startedAt: null,\n pausedAt: null,\n endedAt: null,\n cancelledAt: null,\n cancelReason: null,\n baseElapsedMilliseconds: 0,\n activeStartedAtMonotonic: null,\n now: clock.wallNow,\n };\n}\n\nexport function getElapsedMilliseconds(state: InternalTimerState, clock: ClockRead): number {\n if (state.status !== 'running' || state.activeStartedAtMonotonic === null) {\n return state.baseElapsedMilliseconds;\n }\n\n return Math.max(0, state.baseElapsedMilliseconds + clock.monotonicNow - state.activeStartedAtMonotonic);\n}\n\nexport function toSnapshot(state: InternalTimerState, clock: ClockRead): TimerSnapshot {\n const elapsedMilliseconds = getElapsedMilliseconds(state, clock);\n\n return {\n status: state.status,\n now: clock.wallNow,\n tick: state.tick,\n startedAt: state.startedAt,\n pausedAt: state.pausedAt,\n endedAt: state.endedAt,\n cancelledAt: state.cancelledAt,\n cancelReason: state.cancelReason,\n elapsedMilliseconds,\n isIdle: state.status === 'idle',\n isRunning: state.status === 'running',\n isPaused: state.status === 'paused',\n isEnded: state.status === 'ended',\n isCancelled: state.status === 'cancelled',\n };\n}\n\nexport function startTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'idle') return false;\n\n state.status = 'running';\n state.startedAt = clock.wallNow;\n state.pausedAt = null;\n state.endedAt = null;\n state.cancelledAt = null;\n state.cancelReason = null;\n state.activeStartedAtMonotonic = clock.monotonicNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function pauseTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'paused';\n state.pausedAt = clock.wallNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function resumeTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'paused') return false;\n\n state.status = 'running';\n state.pausedAt = null;\n state.activeStartedAtMonotonic = clock.monotonicNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function resetTimerState(\n state: InternalTimerState,\n clock: ClockRead,\n options: { autoStart?: boolean } = {},\n): boolean {\n state.generation += 1;\n state.tick = 0;\n state.status = options.autoStart ? 'running' : 'idle';\n state.startedAt = options.autoStart ? clock.wallNow : null;\n state.pausedAt = null;\n state.endedAt = null;\n state.cancelledAt = null;\n state.cancelReason = null;\n state.baseElapsedMilliseconds = 0;\n state.activeStartedAtMonotonic = options.autoStart ? clock.monotonicNow : null;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function restartTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n return resetTimerState(state, clock, { autoStart: true });\n}\n\nexport function cancelTimerState(state: InternalTimerState, clock: ClockRead, reason?: string): boolean {\n if (state.status === 'ended' || state.status === 'cancelled') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'cancelled';\n state.cancelledAt = clock.wallNow;\n state.cancelReason = reason ?? null;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function endTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.baseElapsedMilliseconds = getElapsedMilliseconds(state, clock);\n state.activeStartedAtMonotonic = null;\n state.status = 'ended';\n state.endedAt = clock.wallNow;\n state.now = clock.wallNow;\n return true;\n}\n\nexport function tickTimerState(state: InternalTimerState, clock: ClockRead): boolean {\n if (state.status !== 'running') return false;\n\n state.tick += 1;\n state.now = clock.wallNow;\n return true;\n}\n","import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';\nimport { baseDebugEvent, emitDebug } from './debug';\nimport { readClock, validatePositiveFinite } from './clocks';\nimport {\n cancelTimerState,\n createTimerState,\n endTimerState,\n pauseTimerState,\n resetTimerState,\n restartTimerState,\n resumeTimerState,\n startTimerState,\n tickTimerState,\n toSnapshot,\n type InternalTimerState,\n} from './state';\nimport type {\n TimerControls,\n TimerGroupItem,\n TimerGroupItemControls,\n TimerGroupResult,\n TimerSchedule,\n TimerSnapshot,\n UseTimerGroupOptions,\n} from './types';\n\ntype GroupScheduleState = {\n lastRunAt: number | null;\n pending: boolean;\n leadingGeneration: number | null;\n};\n\ntype InternalGroupItem = {\n id: string;\n state: InternalTimerState;\n definition: TimerGroupItem;\n schedules: Map<string, GroupScheduleState>;\n endCalledGeneration: number | null;\n};\n\nexport function useTimerGroup(options: UseTimerGroupOptions = {}): TimerGroupResult {\n const updateIntervalMs = options.updateIntervalMs ?? 1000;\n validatePositiveFinite(updateIntervalMs, 'updateIntervalMs');\n validateItems(options.items);\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const itemsRef = useRef<Map<string, InternalGroupItem>>(new Map());\n const mountedRef = useRef(false);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const [, rerender] = useReducer((value: number) => value + 1, 0);\n\n const clearScheduledTick = useCallback(() => {\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n const getItemSnapshot = useCallback((item: InternalGroupItem, clock = readClock()) => {\n return toSnapshot(item.state, clock);\n }, []);\n\n const emit = useCallback(\n (\n type: Parameters<typeof emitDebug>[1]['type'],\n item: InternalGroupItem | undefined,\n snapshot: TimerSnapshot,\n extra: Partial<Parameters<typeof emitDebug>[1]> = {},\n ) => {\n emitDebug(optionsRef.current.debug, {\n type,\n scope: 'timer-group',\n timerId: item?.id,\n ...baseDebugEvent(snapshot, item?.state.generation ?? 0),\n ...extra,\n });\n },\n [],\n );\n\n const controlsFor = useCallback((id: string): TimerGroupItemControls => {\n return {\n start: () => start(id),\n pause: () => pause(id),\n resume: () => resume(id),\n reset: resetOptions => reset(id, resetOptions),\n restart: () => restart(id),\n cancel: reason => cancel(id, reason),\n };\n }, []);\n\n const callOnEnd = useCallback(\n (item: InternalGroupItem, snapshot: TimerSnapshot) => {\n const generation = item.state.generation;\n if (item.endCalledGeneration === generation) return;\n item.endCalledGeneration = generation;\n\n try {\n void item.definition.onEnd?.(snapshot, controlsFor(item.id));\n } catch (error) {\n emitDebug(optionsRef.current.debug, {\n type: 'callback:error',\n scope: 'timer-group',\n timerId: item.id,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n }\n },\n [controlsFor],\n );\n\n const runSchedule = useCallback(\n (\n item: InternalGroupItem,\n schedule: TimerSchedule,\n key: string,\n scheduleState: GroupScheduleState,\n snapshot: TimerSnapshot,\n generation: number,\n ) => {\n if (scheduleState.pending && (schedule.overlap ?? 'skip') === 'skip') {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:skip',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n reason: 'overlap',\n ...baseDebugEvent(snapshot, generation),\n });\n return;\n }\n\n scheduleState.lastRunAt = snapshot.now;\n scheduleState.pending = true;\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:start',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n\n Promise.resolve()\n .then(() => schedule.callback(snapshot, controlsFor(item.id) as TimerControls))\n .then(\n () => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:end',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n error => {\n emitDebug(optionsRef.current.debug, {\n type: 'schedule:error',\n scope: 'timer-group',\n timerId: item.id,\n scheduleId: schedule.id ?? key,\n error,\n ...baseDebugEvent(snapshot, generation),\n });\n },\n )\n .finally(() => {\n const liveItem = itemsRef.current.get(item.id);\n if (liveItem?.state.generation === generation) {\n scheduleState.pending = false;\n }\n });\n },\n [controlsFor],\n );\n\n const evaluateItemSchedules = useCallback(\n (item: InternalGroupItem, snapshot: TimerSnapshot, activation = false) => {\n const schedules = item.definition.schedules ?? [];\n const liveKeys = new Set<string>();\n\n schedules.forEach((schedule, index) => {\n const key = schedule.id ?? String(index);\n liveKeys.add(key);\n let scheduleState = item.schedules.get(key);\n if (!scheduleState) {\n scheduleState = { lastRunAt: null, pending: false, leadingGeneration: null };\n item.schedules.set(key, scheduleState);\n }\n\n if (activation && schedule.leading && scheduleState.leadingGeneration !== item.state.generation) {\n scheduleState.leadingGeneration = item.state.generation;\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n return;\n }\n\n if (scheduleState.lastRunAt === null) {\n scheduleState.lastRunAt = item.state.startedAt ?? snapshot.now;\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n }\n return;\n }\n\n if (snapshot.now - scheduleState.lastRunAt >= schedule.everyMs) {\n runSchedule(item, schedule, key, scheduleState, snapshot, item.state.generation);\n }\n });\n\n for (const key of item.schedules.keys()) {\n if (!liveKeys.has(key)) item.schedules.delete(key);\n }\n },\n [runSchedule],\n );\n\n const processItem = useCallback(\n (item: InternalGroupItem, clock = readClock(), activation = false) => {\n if (item.state.status !== 'running') return;\n\n const snapshot = toSnapshot(item.state, clock);\n if (item.definition.endWhen?.(snapshot)) {\n if (endTimerState(item.state, clock)) {\n const endedSnapshot = toSnapshot(item.state, clock);\n emit('timer:end', item, endedSnapshot);\n callOnEnd(item, endedSnapshot);\n }\n return;\n }\n\n evaluateItemSchedules(item, snapshot, activation);\n },\n [callOnEnd, emit, evaluateItemSchedules],\n );\n\n const ensureItem = useCallback((definition: TimerGroupItem): { item: InternalGroupItem; added: boolean } => {\n const existing = itemsRef.current.get(definition.id);\n if (existing) {\n existing.definition = definition;\n return { item: existing, added: false };\n }\n\n const item: InternalGroupItem = {\n id: definition.id,\n state: createTimerState(readClock()),\n definition,\n schedules: new Map(),\n endCalledGeneration: null,\n };\n itemsRef.current.set(definition.id, item);\n if (definition.autoStart) {\n startTimerState(item.state, readClock());\n }\n return { item, added: true };\n }, []);\n\n const syncItems = useCallback(() => {\n const definitions = optionsRef.current.items ?? [];\n const liveIds = new Set<string>();\n let changed = false;\n definitions.forEach(definition => {\n liveIds.add(definition.id);\n const { item, added } = ensureItem(definition);\n changed = changed || added;\n if (definition.autoStart && item.state.status === 'idle') {\n changed = startTimerState(item.state, readClock()) || changed;\n }\n });\n\n for (const id of itemsRef.current.keys()) {\n if (!liveIds.has(id)) {\n itemsRef.current.delete(id);\n changed = true;\n }\n }\n\n return changed;\n }, [ensureItem]);\n\n useEffect(() => {\n if (syncItems()) rerender();\n }, [syncItems, options.items]);\n\n const add = useCallback((item: TimerGroupItem) => {\n validateItems([item]);\n if (itemsRef.current.has(item.id)) throw new Error(`Timer item \"${item.id}\" already exists`);\n ensureItem(item);\n rerender();\n }, [ensureItem]);\n\n const update = useCallback((id: string, item: Partial<Omit<TimerGroupItem, 'id'>>) => {\n const existing = itemsRef.current.get(id);\n if (!existing) return;\n const next = { ...existing.definition, ...item, id };\n validateItems([next]);\n existing.definition = next;\n rerender();\n }, []);\n\n const remove = useCallback((id: string) => {\n itemsRef.current.delete(id);\n rerender();\n }, []);\n\n const clear = useCallback(() => {\n itemsRef.current.clear();\n clearScheduledTick();\n rerender();\n }, [clearScheduledTick]);\n\n const start = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!startTimerState(item.state, clock)) return;\n emit('timer:start', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const pause = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!pauseTimerState(item.state, clock)) return;\n emit('timer:pause', item, toSnapshot(item.state, clock));\n rerender();\n }, [emit]);\n\n const resume = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!resumeTimerState(item.state, clock)) return;\n emit('timer:resume', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const reset = useCallback((id: string, resetOptions: { autoStart?: boolean } = {}) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n resetTimerState(item.state, clock, resetOptions);\n item.schedules.clear();\n item.endCalledGeneration = null;\n emit('timer:reset', item, toSnapshot(item.state, clock));\n if (resetOptions.autoStart) processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const restart = useCallback((id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n restartTimerState(item.state, clock);\n item.schedules.clear();\n item.endCalledGeneration = null;\n emit('timer:restart', item, toSnapshot(item.state, clock));\n processItem(item, clock, true);\n rerender();\n }, [emit, processItem]);\n\n const cancel = useCallback((id: string, reason?: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return;\n const clock = readClock();\n if (!cancelTimerState(item.state, clock, reason)) return;\n emit('timer:cancel', item, toSnapshot(item.state, clock), { reason });\n rerender();\n }, [emit]);\n\n const ids = Array.from(itemsRef.current.keys());\n const activeSignature = ids\n .map(id => `${id}:${itemsRef.current.get(id)!.state.status}:${itemsRef.current.get(id)!.state.generation}:${itemsRef.current.get(id)!.state.tick}`)\n .join('|');\n\n useEffect(() => {\n mountedRef.current = true;\n const runningItems = Array.from(itemsRef.current.values()).filter(item => item.state.status === 'running');\n if (runningItems.length === 0) {\n clearScheduledTick();\n return;\n }\n\n clearScheduledTick();\n const first = runningItems[0];\n emit('scheduler:start', first, toSnapshot(first.state, readClock()));\n timeoutRef.current = setTimeout(() => {\n if (!mountedRef.current) return;\n\n const clock = readClock();\n for (const item of itemsRef.current.values()) {\n if (item.state.status !== 'running') continue;\n tickTimerState(item.state, clock);\n const snapshot = toSnapshot(item.state, clock);\n emit('timer:tick', item, snapshot);\n processItem(item, clock);\n }\n\n rerender();\n }, optionsRef.current.updateIntervalMs ?? 1000);\n\n return () => {\n if (timeoutRef.current !== null) {\n emit('scheduler:stop', first, toSnapshot(first.state, readClock()));\n }\n clearScheduledTick();\n mountedRef.current = false;\n };\n }, [activeSignature, clearScheduledTick, emit, processItem]);\n\n const get = useCallback(\n (id: string) => {\n const item = itemsRef.current.get(id);\n if (!item) return undefined;\n return getItemSnapshot(item);\n },\n [getItemSnapshot],\n );\n\n const now = readClock().wallNow;\n\n return useMemo(\n () => ({\n now,\n size: itemsRef.current.size,\n ids: Array.from(itemsRef.current.keys()),\n get,\n add,\n update,\n remove,\n clear,\n start,\n pause,\n resume,\n reset,\n restart,\n cancel,\n startAll: () => Array.from(itemsRef.current.keys()).forEach(start),\n pauseAll: () => Array.from(itemsRef.current.keys()).forEach(pause),\n resumeAll: () => Array.from(itemsRef.current.keys()).forEach(resume),\n resetAll: (resetOptions?: { autoStart?: boolean }) => Array.from(itemsRef.current.keys()).forEach(id => reset(id, resetOptions)),\n restartAll: () => Array.from(itemsRef.current.keys()).forEach(restart),\n cancelAll: (reason?: string) => Array.from(itemsRef.current.keys()).forEach(id => cancel(id, reason)),\n }),\n [add, cancel, clear, get, now, pause, remove, reset, restart, resume, start, update],\n );\n}\n\nfunction validateItems(items: TimerGroupItem[] | undefined): void {\n const ids = new Set<string>();\n items?.forEach(item => {\n if (ids.has(item.id)) throw new Error(`Duplicate timer item id \"${item.id}\"`);\n ids.add(item.id);\n item.schedules?.forEach(schedule => validatePositiveFinite(schedule.everyMs, 'schedule.everyMs'));\n });\n}\n"],"mappings":";AAEA,IAAM,SAAS;AACf,IAAM,SAAS,KAAK;AACpB,IAAM,OAAO,KAAK;AAClB,IAAM,MAAM,KAAK;AAEV,SAAS,cAAc,cAAqC;AACjE,QAAM,oBAAoB,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,SAAS,YAAY,IAAI,eAAe,CAAC,CAAC;AAClG,QAAM,OAAO,KAAK,MAAM,oBAAoB,GAAG;AAC/C,QAAM,YAAY,oBAAoB;AACtC,QAAM,QAAQ,KAAK,MAAM,YAAY,IAAI;AACzC,QAAM,aAAa,YAAY;AAC/B,QAAM,UAAU,KAAK,MAAM,aAAa,MAAM;AAC9C,QAAM,eAAe,aAAa;AAClC,QAAM,UAAU,KAAK,MAAM,eAAe,MAAM;AAEhD,SAAO;AAAA,IACL;AAAA,IACA,cAAc,KAAK,MAAM,oBAAoB,MAAM;AAAA,IACnD,cAAc,eAAe;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;AC1BA,SAAS,aAAa,WAAW,SAAS,YAAY,cAAc;;;ACS7D,SAAS,aAAa,OAA4C;AACvE,MAAI,CAAC,MAAO,QAAO,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