@bitcobblers/wod-wiki-lang 0.53.2204 → 0.55.2206

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/react.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { a6 as ScriptRuntime, a$ as MemoryType, v as IRuntimeBlock, b1 as MemoryValueOf, aH as DisplayState, b6 as RoundState, a9 as TimerState, a3 as IScriptRuntime, L as TypedMemoryReference, a0 as ButtonConfig, X as StackSnapshot } from './browserRuntimeNow-JnK2JvJg.cjs';
2
- export { br as createBrowserRuntimeNow, bF as getRuntimeNowMs, bW as runtimeNow } from './browserRuntimeNow-JnK2JvJg.cjs';
1
+ import { a8 as ScriptRuntime, b3 as MemoryType, v as IRuntimeBlock, b5 as MemoryValueOf, aI as DisplayState, bc as RoundState, ab as TimerState, a5 as IScriptRuntime, L as TypedMemoryReference, a2 as ButtonConfig, Y as StackSnapshot, bn as SessionExecutionStatus, bk as SessionClockFrame, a_ as LiveSessionTelemetryFrame, bf as ScriptOutlineNode } from './ScriptOutlineProjection-BnS5Xkgf.cjs';
2
+ export { bF as createBrowserRuntimeNow, bT as getRuntimeNowMs, cg as runtimeNow } from './ScriptOutlineProjection-BnS5Xkgf.cjs';
3
3
  import { IMetricSource, IOutputStatement, MetricContainer, TimeSpan } from '@bitcobblers/wod-wiki-core';
4
4
  import React$1, { ReactNode } from 'react';
5
5
 
@@ -565,6 +565,31 @@ interface UseTimerElapsedResult {
565
565
  */
566
566
  declare function useTimerElapsed(blockKey: string): UseTimerElapsedResult;
567
567
 
568
+ interface UseSessionClockProjectionOptions {
569
+ readonly runtime?: IScriptRuntime | null;
570
+ readonly executionStatus?: SessionExecutionStatus;
571
+ readonly canNextOverride?: boolean;
572
+ /** False suspends subscriptions and the 60fps loop when hidden/unneeded. */
573
+ readonly active?: boolean;
574
+ }
575
+ /**
576
+ * Single reactive React hook over `projectSessionClock`.
577
+ *
578
+ * Delegates runtime stack, block-memory, and skip-attempt subscriptions to
579
+ * `observeSessionClockInputs` so browser views and the Cast projector share one
580
+ * observation implementation.
581
+ */
582
+ declare function useSessionClockProjection(options?: UseSessionClockProjectionOptions): SessionClockFrame;
583
+
584
+ /**
585
+ * Reactive React hook over `projectLiveSessionTelemetry`.
586
+ *
587
+ * Updates whenever the runtime emits a segment or live analytics change signal.
588
+ */
589
+ declare function useLiveSessionTelemetry(runtimeOverride?: IScriptRuntime | null): LiveSessionTelemetryFrame;
590
+
591
+ declare function useScriptOutline(runtimeOverride?: IScriptRuntime | null): ScriptOutlineNode[];
592
+
568
593
  interface ScriptRuntimeProviderProps {
569
594
  runtime: IScriptRuntime;
570
595
  children: ReactNode;
@@ -595,6 +620,11 @@ declare const ScriptRuntimeProvider: React.FC<ScriptRuntimeProviderProps>;
595
620
  * @returns IScriptRuntime instance
596
621
  */
597
622
  declare function useScriptRuntime(): IScriptRuntime;
623
+ /**
624
+ * Optional variant of `useScriptRuntime` returning `null` when mounted outside
625
+ * `ScriptRuntimeProvider` (e.g. stateless Cast receiver frames or fixture stories).
626
+ */
627
+ declare function useOptionalScriptRuntime(): IScriptRuntime | null;
598
628
 
599
629
  interface BlockTimerDisplayProps {
600
630
  /** The runtime block to display timer for */
@@ -637,4 +667,4 @@ interface BlockTimerDisplayProps {
637
667
  */
638
668
  declare const BlockTimerDisplay: React$1.FC<BlockTimerDisplayProps>;
639
669
 
640
- export { BlockTimerDisplay, type BlockTimerDisplayProps, type ExecutionStatus, type FragmentSourceEntry, type FragmentSourceStatus, type NextPreview, type OutputStatementsData, type RoundDisplayValues, ScriptRuntimeProvider, type ScriptRuntimeProviderProps, type StackDisplayEntry, type StackFragmentEntry, type StackTimerEntry, type TimerDisplayValues, type UseRuntimeExecutionReturn, type UseTimerElapsedResult, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useMemorySubscription, useNextPreview, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptRuntime, useSecondaryTimers, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
670
+ export { BlockTimerDisplay, type BlockTimerDisplayProps, type ExecutionStatus, type FragmentSourceEntry, type FragmentSourceStatus, type NextPreview, type OutputStatementsData, type RoundDisplayValues, ScriptRuntimeProvider, type ScriptRuntimeProviderProps, type StackDisplayEntry, type StackFragmentEntry, type StackTimerEntry, type TimerDisplayValues, type UseRuntimeExecutionReturn, type UseSessionClockProjectionOptions, type UseTimerElapsedResult, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useLiveSessionTelemetry, useMemorySubscription, useNextPreview, useOptionalScriptRuntime, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptOutline, useScriptRuntime, useSecondaryTimers, useSessionClockProjection, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a6 as ScriptRuntime, a$ as MemoryType, v as IRuntimeBlock, b1 as MemoryValueOf, aH as DisplayState, b6 as RoundState, a9 as TimerState, a3 as IScriptRuntime, L as TypedMemoryReference, a0 as ButtonConfig, X as StackSnapshot } from './browserRuntimeNow-JnK2JvJg.js';
2
- export { br as createBrowserRuntimeNow, bF as getRuntimeNowMs, bW as runtimeNow } from './browserRuntimeNow-JnK2JvJg.js';
1
+ import { a8 as ScriptRuntime, b3 as MemoryType, v as IRuntimeBlock, b5 as MemoryValueOf, aI as DisplayState, bc as RoundState, ab as TimerState, a5 as IScriptRuntime, L as TypedMemoryReference, a2 as ButtonConfig, Y as StackSnapshot, bn as SessionExecutionStatus, bk as SessionClockFrame, a_ as LiveSessionTelemetryFrame, bf as ScriptOutlineNode } from './ScriptOutlineProjection-BnS5Xkgf.js';
2
+ export { bF as createBrowserRuntimeNow, bT as getRuntimeNowMs, cg as runtimeNow } from './ScriptOutlineProjection-BnS5Xkgf.js';
3
3
  import { IMetricSource, IOutputStatement, MetricContainer, TimeSpan } from '@bitcobblers/wod-wiki-core';
4
4
  import React$1, { ReactNode } from 'react';
5
5
 
@@ -565,6 +565,31 @@ interface UseTimerElapsedResult {
565
565
  */
566
566
  declare function useTimerElapsed(blockKey: string): UseTimerElapsedResult;
567
567
 
568
+ interface UseSessionClockProjectionOptions {
569
+ readonly runtime?: IScriptRuntime | null;
570
+ readonly executionStatus?: SessionExecutionStatus;
571
+ readonly canNextOverride?: boolean;
572
+ /** False suspends subscriptions and the 60fps loop when hidden/unneeded. */
573
+ readonly active?: boolean;
574
+ }
575
+ /**
576
+ * Single reactive React hook over `projectSessionClock`.
577
+ *
578
+ * Delegates runtime stack, block-memory, and skip-attempt subscriptions to
579
+ * `observeSessionClockInputs` so browser views and the Cast projector share one
580
+ * observation implementation.
581
+ */
582
+ declare function useSessionClockProjection(options?: UseSessionClockProjectionOptions): SessionClockFrame;
583
+
584
+ /**
585
+ * Reactive React hook over `projectLiveSessionTelemetry`.
586
+ *
587
+ * Updates whenever the runtime emits a segment or live analytics change signal.
588
+ */
589
+ declare function useLiveSessionTelemetry(runtimeOverride?: IScriptRuntime | null): LiveSessionTelemetryFrame;
590
+
591
+ declare function useScriptOutline(runtimeOverride?: IScriptRuntime | null): ScriptOutlineNode[];
592
+
568
593
  interface ScriptRuntimeProviderProps {
569
594
  runtime: IScriptRuntime;
570
595
  children: ReactNode;
@@ -595,6 +620,11 @@ declare const ScriptRuntimeProvider: React.FC<ScriptRuntimeProviderProps>;
595
620
  * @returns IScriptRuntime instance
596
621
  */
597
622
  declare function useScriptRuntime(): IScriptRuntime;
623
+ /**
624
+ * Optional variant of `useScriptRuntime` returning `null` when mounted outside
625
+ * `ScriptRuntimeProvider` (e.g. stateless Cast receiver frames or fixture stories).
626
+ */
627
+ declare function useOptionalScriptRuntime(): IScriptRuntime | null;
598
628
 
599
629
  interface BlockTimerDisplayProps {
600
630
  /** The runtime block to display timer for */
@@ -637,4 +667,4 @@ interface BlockTimerDisplayProps {
637
667
  */
638
668
  declare const BlockTimerDisplay: React$1.FC<BlockTimerDisplayProps>;
639
669
 
640
- export { BlockTimerDisplay, type BlockTimerDisplayProps, type ExecutionStatus, type FragmentSourceEntry, type FragmentSourceStatus, type NextPreview, type OutputStatementsData, type RoundDisplayValues, ScriptRuntimeProvider, type ScriptRuntimeProviderProps, type StackDisplayEntry, type StackFragmentEntry, type StackTimerEntry, type TimerDisplayValues, type UseRuntimeExecutionReturn, type UseTimerElapsedResult, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useMemorySubscription, useNextPreview, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptRuntime, useSecondaryTimers, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
670
+ export { BlockTimerDisplay, type BlockTimerDisplayProps, type ExecutionStatus, type FragmentSourceEntry, type FragmentSourceStatus, type NextPreview, type OutputStatementsData, type RoundDisplayValues, ScriptRuntimeProvider, type ScriptRuntimeProviderProps, type StackDisplayEntry, type StackFragmentEntry, type StackTimerEntry, type TimerDisplayValues, type UseRuntimeExecutionReturn, type UseSessionClockProjectionOptions, type UseTimerElapsedResult, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useLiveSessionTelemetry, useMemorySubscription, useNextPreview, useOptionalScriptRuntime, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptOutline, useScriptRuntime, useSecondaryTimers, useSessionClockProjection, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
package/dist/react.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { wallClockNow, calculateDuration, formatDurationSmart, getRuntimeNowMs } from './chunk-27K5HAHU.mjs';
2
- export { createBrowserRuntimeNow, getRuntimeNowMs, wallClockNow as runtimeNow } from './chunk-27K5HAHU.mjs';
1
+ import { wallClockNow, getRuntimeNowMs, calculateDuration, formatDurationSmart, observeSessionClockInputs, projectSessionClock, projectLiveSessionTelemetry, projectScriptOutline } from './chunk-XDMS3U3W.mjs';
2
+ export { createBrowserRuntimeNow, getRuntimeNowMs, wallClockNow as runtimeNow } from './chunk-XDMS3U3W.mjs';
3
3
  import { createContext, useState, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
4
4
  import { MetricContainer } from '@bitcobblers/wod-wiki-core';
5
5
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -34,8 +34,12 @@ var useRuntimeExecution = (runtime) => {
34
34
  clearInterval(intervalRef.current);
35
35
  intervalRef.current = null;
36
36
  }
37
+ if (startTimeRef.current !== null) {
38
+ const now = runtime?.nowProvider?.nowMs() ?? wallClockNow.nowMs();
39
+ setElapsedTime(now - startTimeRef.current);
40
+ }
37
41
  setStatus("idle");
38
- }, []);
42
+ }, [runtime]);
39
43
  const executeStep = useCallback(() => {
40
44
  if (!runtime) return;
41
45
  try {
@@ -55,6 +59,10 @@ var useRuntimeExecution = (runtime) => {
55
59
  clearInterval(intervalRef.current);
56
60
  intervalRef.current = null;
57
61
  }
62
+ if (startTimeRef.current !== null) {
63
+ const now = runtime?.nowProvider?.nowMs() ?? wallClockNow.nowMs();
64
+ setElapsedTime(now - startTimeRef.current);
65
+ }
58
66
  setStatus("completed");
59
67
  }
60
68
  });
@@ -97,10 +105,15 @@ var useRuntimeExecution = (runtime) => {
97
105
  clearInterval(intervalRef.current);
98
106
  intervalRef.current = null;
99
107
  }
108
+ if (startTimeRef.current !== null) {
109
+ const now = runtime?.nowProvider?.nowMs() ?? wallClockNow.nowMs();
110
+ setElapsedTime(now - startTimeRef.current);
111
+ }
100
112
  if (runtime) {
113
+ const pauseDate = runtime.nowProvider?.now() ?? wallClockNow.now();
101
114
  runtime.handle({
102
115
  name: "timer:pause",
103
- timestamp: /* @__PURE__ */ new Date(),
116
+ timestamp: pauseDate,
104
117
  data: {}
105
118
  });
106
119
  }
@@ -195,14 +208,7 @@ function useDisplayState(block) {
195
208
  }
196
209
  function useTimerDisplay(block) {
197
210
  const timer = useTimerState(block);
198
- const getNow = () => {
199
- if (typeof window !== "undefined") {
200
- const receiverClock = window.__chromecast_senderClockTimeMs;
201
- if (typeof receiverClock === "function") return receiverClock();
202
- }
203
- return Date.now();
204
- };
205
- const [now, setNow] = useState(getNow());
211
+ const [now, setNow] = useState(() => getRuntimeNowMs());
206
212
  const isRunning = useMemo(() => {
207
213
  if (!timer || timer.spans.length === 0) return false;
208
214
  const lastSpan = timer.spans[timer.spans.length - 1];
@@ -214,7 +220,7 @@ function useTimerDisplay(block) {
214
220
  let running = true;
215
221
  const tick = () => {
216
222
  if (!running || typeof requestAnimationFrame !== "function") return;
217
- setNow(getNow());
223
+ setNow(getRuntimeNowMs());
218
224
  animationFrameId = requestAnimationFrame(tick);
219
225
  };
220
226
  animationFrameId = requestAnimationFrame(tick);
@@ -285,6 +291,9 @@ function useScriptRuntime() {
285
291
  }
286
292
  return runtime;
287
293
  }
294
+ function useOptionalScriptRuntime() {
295
+ return useContext(ScriptRuntimeContext) ?? null;
296
+ }
288
297
 
289
298
  // src/react/hooks/useOutputStatements.ts
290
299
  function useOutputStatements(runtime) {
@@ -476,7 +485,7 @@ function usePrimaryTimer() {
476
485
  return useMemo(() => {
477
486
  if (timers.length === 0) return void 0;
478
487
  const leaf = timers[0];
479
- if (leaf.block.blockType === "Rest") return leaf;
488
+ if (leaf.block.blockType === "Rest" || leaf.timer.polarity === "rest") return leaf;
480
489
  const pinned = [...timers].reverse().find((t) => t.isPinned);
481
490
  if (pinned) return pinned;
482
491
  return leaf;
@@ -687,6 +696,96 @@ function useTimerElapsed(blockKey) {
687
696
  timeSpans
688
697
  };
689
698
  }
699
+ function useSessionClockProjection(options = {}) {
700
+ const contextRuntime = useOptionalScriptRuntime();
701
+ const runtime = options.runtime !== void 0 ? options.runtime : contextRuntime;
702
+ const enabled = options.active ?? true;
703
+ const [signalState, setSignalState] = useState({
704
+ revision: 0,
705
+ skipFlash: false,
706
+ skipFlashKey: 0
707
+ });
708
+ useEffect(() => {
709
+ if (!runtime || !enabled) return void 0;
710
+ return observeSessionClockInputs(runtime, ({ skipFlash, skipFlashKey }) => {
711
+ setSignalState((prev) => ({
712
+ revision: prev.revision + 1,
713
+ skipFlash,
714
+ skipFlashKey
715
+ }));
716
+ });
717
+ }, [runtime, enabled]);
718
+ const [nowMs, setNowMs] = useState(() => getRuntimeNowMs());
719
+ const structuralFrame = useMemo(() => {
720
+ void signalState.revision;
721
+ return projectSessionClock(runtime, {
722
+ nowMs,
723
+ executionStatus: options.executionStatus,
724
+ canNextOverride: options.canNextOverride,
725
+ skipFlash: signalState.skipFlash,
726
+ skipFlashKey: signalState.skipFlashKey
727
+ });
728
+ }, [
729
+ runtime,
730
+ signalState.revision,
731
+ signalState.skipFlash,
732
+ signalState.skipFlashKey,
733
+ nowMs,
734
+ options.executionStatus,
735
+ options.canNextOverride
736
+ ]);
737
+ useEffect(() => {
738
+ if (!enabled || !structuralFrame.isRunning || structuralFrame.isPaused) return void 0;
739
+ if (typeof requestAnimationFrame !== "function") return void 0;
740
+ let frameId = 0;
741
+ let mounted = true;
742
+ const tick = () => {
743
+ if (!mounted) return;
744
+ setNowMs(getRuntimeNowMs());
745
+ frameId = requestAnimationFrame(tick);
746
+ };
747
+ frameId = requestAnimationFrame(tick);
748
+ return () => {
749
+ mounted = false;
750
+ cancelAnimationFrame(frameId);
751
+ };
752
+ }, [enabled, structuralFrame.isRunning, structuralFrame.isPaused]);
753
+ return structuralFrame;
754
+ }
755
+ function useLiveSessionTelemetry(runtimeOverride) {
756
+ const contextRuntime = useOptionalScriptRuntime();
757
+ const runtime = runtimeOverride !== void 0 ? runtimeOverride : contextRuntime;
758
+ const [version, setVersion] = useState(0);
759
+ useEffect(() => {
760
+ if (!runtime) {
761
+ setVersion(0);
762
+ return void 0;
763
+ }
764
+ return runtime.subscribeToOutput?.(() => {
765
+ setVersion((v) => v + 1);
766
+ });
767
+ }, [runtime]);
768
+ return useMemo(() => {
769
+ return projectLiveSessionTelemetry(runtime);
770
+ }, [runtime, version]);
771
+ }
772
+ function useScriptOutline(runtimeOverride) {
773
+ const contextRuntime = useOptionalScriptRuntime();
774
+ const runtime = runtimeOverride !== void 0 ? runtimeOverride : contextRuntime;
775
+ const [tick, setTick] = useState(0);
776
+ useEffect(() => {
777
+ if (!runtime) return void 0;
778
+ const unsubStack = runtime.subscribeToStack(() => setTick((t) => t + 1));
779
+ const unsubOut = runtime.subscribeToOutput?.(() => setTick((t) => t + 1));
780
+ return () => {
781
+ unsubStack();
782
+ unsubOut?.();
783
+ };
784
+ }, [runtime]);
785
+ return useMemo(() => {
786
+ return projectScriptOutline(runtime);
787
+ }, [runtime, tick]);
788
+ }
690
789
  function cn(...classes) {
691
790
  return classes.filter(Boolean).join(" ");
692
791
  }
@@ -722,6 +821,6 @@ var BlockTimerDisplay = ({
722
821
  ] });
723
822
  };
724
823
 
725
- export { BlockTimerDisplay, ScriptRuntimeProvider, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useMemorySubscription, useNextPreview, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptRuntime, useSecondaryTimers, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
824
+ export { BlockTimerDisplay, ScriptRuntimeProvider, useActiveControls, useBlockMemory, useBlockOutputs, useDisplayState, useFragmentSource, useLiveAnalytics, useLiveSessionTelemetry, useMemorySubscription, useNextPreview, useOptionalScriptRuntime, useOutputHierarchy, useOutputStatement, useOutputStatements, usePrimaryTimer, useRoundDisplay, useRoundState, useRuntimeExecution, useScriptOutline, useScriptRuntime, useSecondaryTimers, useSessionClockProjection, useSnapshotBlocks, useSnapshotCurrentBlock, useStackDisplayRows, useStackFragmentSources, useStackSnapshot, useStackTimers, useTimerDisplay, useTimerElapsed, useTimerState };
726
825
  //# sourceMappingURL=react.mjs.map
727
826
  //# sourceMappingURL=react.mjs.map