@interlacejs/player 0.1.0

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.js ADDED
@@ -0,0 +1,818 @@
1
+ // src/components/anchor.tsx
2
+ import React, { useRef } from "react";
3
+
4
+ // src/tokens.ts
5
+ var COLORS = {
6
+ accent: "#0066cc",
7
+ accentHover: "#0052a3",
8
+ accentLight: "rgba(0, 102, 204, 0.15)",
9
+ accentLighter: "rgba(0, 102, 204, 0.08)",
10
+ text: "#0f172a",
11
+ textMuted: "#64748b",
12
+ border: "#e2e8f0",
13
+ borderStrong: "#cbd5e1",
14
+ surface: "#ffffff",
15
+ surfaceRaised: "#f8fafc",
16
+ ground: "#f6f7f9",
17
+ errorBg: "#fef2f2",
18
+ errorText: "#b91c1c",
19
+ errorBorder: "#fecaca",
20
+ white: "#ffffff",
21
+ black: "#000000"
22
+ };
23
+ var FONTS = {
24
+ display: 'Georgia, "Times New Roman", Times, serif',
25
+ body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
26
+ };
27
+ var SPACE = {
28
+ 1: 4,
29
+ 2: 8,
30
+ 3: 12,
31
+ 4: 16,
32
+ 5: 24
33
+ };
34
+ var RADIUS = {
35
+ sm: 4,
36
+ md: 8,
37
+ lg: 12
38
+ };
39
+ var SHADOWS = {
40
+ sm: "0 1px 2px 0 rgba(15, 23, 42, 0.04)",
41
+ md: "0 4px 12px -2px rgba(15, 23, 42, 0.08)"
42
+ };
43
+ var TYPE = {
44
+ xs: 12,
45
+ sm: 13,
46
+ base: 15,
47
+ md: 16,
48
+ lg: 20,
49
+ xl: 24
50
+ };
51
+
52
+ // src/components/anchor.tsx
53
+ import { jsx } from "react/jsx-runtime";
54
+ var Anchor = React.forwardRef(
55
+ ({ id, placement, title, isOpened, onClick }, ref) => {
56
+ const buttonRef = useRef(null);
57
+ const internalRef = ref || buttonRef;
58
+ const minSize = 44;
59
+ const width = Math.max(placement.width, minSize / 100);
60
+ const height = Math.max(placement.height, minSize / 100);
61
+ return /* @__PURE__ */ jsx(
62
+ "button",
63
+ {
64
+ ref: internalRef,
65
+ onClick,
66
+ "aria-label": title,
67
+ "data-content-id": id,
68
+ style: {
69
+ position: "absolute",
70
+ left: `${placement.x}%`,
71
+ top: `${placement.y}%`,
72
+ width: `${width}%`,
73
+ height: `${height}%`,
74
+ minWidth: `${minSize}px`,
75
+ minHeight: `${minSize}px`,
76
+ padding: `${SPACE[2]}px ${SPACE[3]}px`,
77
+ fontSize: TYPE.md,
78
+ fontWeight: 600,
79
+ border: `2px solid ${COLORS.accent}`,
80
+ borderRadius: `${RADIUS.sm}px`,
81
+ backgroundColor: isOpened ? COLORS.accent : COLORS.surface,
82
+ color: isOpened ? COLORS.white : COLORS.accent,
83
+ cursor: "pointer",
84
+ transition: "background-color 150ms ease, color 150ms ease, box-shadow 150ms ease",
85
+ boxShadow: isOpened ? "0 4px 8px rgba(0, 102, 204, 0.3)" : SHADOWS.sm,
86
+ zIndex: 2,
87
+ // The anchors layer is pointer-transparent; each anchor
88
+ // re-enables pointer events for itself.
89
+ pointerEvents: "auto"
90
+ },
91
+ children: title
92
+ }
93
+ );
94
+ }
95
+ );
96
+ Anchor.displayName = "Anchor";
97
+
98
+ // src/components/blocking-overlay.tsx
99
+ import { useEffect, useRef as useRef2, useState } from "react";
100
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
101
+ var BlockingOverlay = ({
102
+ content,
103
+ contentType,
104
+ onContentComplete,
105
+ onSkip,
106
+ completing = false,
107
+ completingScore,
108
+ onContinue
109
+ }) => {
110
+ const overlayRef = useRef2(null);
111
+ const bodyRef = useRef2(null);
112
+ const [revealed, setRevealed] = useState(false);
113
+ const onContentCompleteRef = useRef2(onContentComplete);
114
+ onContentCompleteRef.current = onContentComplete;
115
+ useEffect(() => {
116
+ const body = bodyRef.current;
117
+ if (!body || !contentType) return;
118
+ try {
119
+ contentType.renderPlayback(body, content.getData(), {
120
+ onComplete: (score) => {
121
+ onContentCompleteRef.current?.(score);
122
+ }
123
+ });
124
+ } catch (err) {
125
+ const error = err instanceof Error ? err : new Error(String(err));
126
+ body.textContent = error.message;
127
+ return;
128
+ }
129
+ return () => {
130
+ contentType.unmountPlayback?.(body);
131
+ };
132
+ }, [contentType, content]);
133
+ useEffect(() => {
134
+ if (!completing) {
135
+ setRevealed(false);
136
+ return;
137
+ }
138
+ const raf = requestAnimationFrame(() => setRevealed(true));
139
+ return () => cancelAnimationFrame(raf);
140
+ }, [completing]);
141
+ useEffect(() => {
142
+ const overlay = overlayRef.current;
143
+ if (!overlay) return;
144
+ const focusableElements = overlay.querySelectorAll(
145
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
146
+ );
147
+ if (focusableElements.length === 0) return;
148
+ const firstElement = focusableElements[0];
149
+ const lastElement = focusableElements[focusableElements.length - 1];
150
+ const handleKeyDown = (e) => {
151
+ if (e.key !== "Tab") return;
152
+ if (e.shiftKey) {
153
+ if (document.activeElement === firstElement) {
154
+ e.preventDefault();
155
+ lastElement.focus();
156
+ }
157
+ } else {
158
+ if (document.activeElement === lastElement) {
159
+ e.preventDefault();
160
+ firstElement.focus();
161
+ }
162
+ }
163
+ };
164
+ overlay.addEventListener("keydown", handleKeyDown);
165
+ firstElement.focus();
166
+ return () => {
167
+ overlay.removeEventListener("keydown", handleKeyDown);
168
+ };
169
+ }, [completing]);
170
+ const completionSurface = /* @__PURE__ */ jsxs(
171
+ "div",
172
+ {
173
+ style: {
174
+ display: "flex",
175
+ flexDirection: "column",
176
+ alignItems: "center",
177
+ justifyContent: "center",
178
+ gap: `${SPACE[3]}px`,
179
+ padding: `${SPACE[4]}px 0`
180
+ },
181
+ children: [
182
+ /* @__PURE__ */ jsx2(
183
+ "div",
184
+ {
185
+ style: {
186
+ width: 56,
187
+ height: 56,
188
+ borderRadius: "50%",
189
+ backgroundColor: COLORS.accentLighter,
190
+ color: COLORS.accent,
191
+ display: "flex",
192
+ alignItems: "center",
193
+ justifyContent: "center",
194
+ fontSize: TYPE.xl,
195
+ fontWeight: 600,
196
+ lineHeight: 1,
197
+ opacity: revealed ? 1 : 0,
198
+ transform: revealed ? "scale(1)" : "scale(0.6)",
199
+ transition: "opacity 200ms ease, transform 200ms ease"
200
+ },
201
+ "aria-hidden": "true",
202
+ children: "\u2713"
203
+ }
204
+ ),
205
+ /* @__PURE__ */ jsxs(
206
+ "div",
207
+ {
208
+ style: {
209
+ display: "flex",
210
+ flexDirection: "column",
211
+ alignItems: "center",
212
+ gap: `${SPACE[1]}px`,
213
+ margin: 0,
214
+ fontFamily: FONTS.display,
215
+ fontSize: TYPE.lg,
216
+ fontWeight: 600,
217
+ color: COLORS.text,
218
+ opacity: revealed ? 1 : 0,
219
+ transform: revealed ? "none" : "translateY(6px)",
220
+ transition: "opacity 250ms ease 120ms, transform 250ms ease 120ms"
221
+ },
222
+ children: [
223
+ /* @__PURE__ */ jsx2("span", { children: "Completed" }),
224
+ typeof completingScore === "number" && /* @__PURE__ */ jsxs(
225
+ "span",
226
+ {
227
+ "aria-label": `completion-score-${completingScore}`,
228
+ style: {
229
+ display: "inline-block",
230
+ padding: `0 ${SPACE[2]}px`,
231
+ borderRadius: `${RADIUS.sm}px`,
232
+ backgroundColor: COLORS.accent,
233
+ color: COLORS.white,
234
+ fontSize: TYPE.sm,
235
+ fontWeight: 600,
236
+ verticalAlign: "middle"
237
+ },
238
+ children: [
239
+ "Score: ",
240
+ completingScore,
241
+ "/",
242
+ content.getMaximumScore()
243
+ ]
244
+ }
245
+ )
246
+ ]
247
+ }
248
+ ),
249
+ /* @__PURE__ */ jsx2(
250
+ "button",
251
+ {
252
+ type: "button",
253
+ onClick: onContinue,
254
+ style: {
255
+ marginTop: `${SPACE[3]}px`,
256
+ padding: `${SPACE[2]}px ${SPACE[5]}px`,
257
+ backgroundColor: COLORS.accent,
258
+ color: COLORS.white,
259
+ border: "none",
260
+ borderRadius: `${RADIUS.sm}px`,
261
+ cursor: "pointer",
262
+ fontSize: TYPE.md,
263
+ fontWeight: 600,
264
+ transition: "background-color 150ms ease",
265
+ opacity: revealed ? 1 : 0
266
+ },
267
+ children: "Continue"
268
+ }
269
+ )
270
+ ]
271
+ }
272
+ );
273
+ return /* @__PURE__ */ jsx2(
274
+ "div",
275
+ {
276
+ ref: overlayRef,
277
+ style: {
278
+ position: "fixed",
279
+ top: 0,
280
+ left: 0,
281
+ right: 0,
282
+ bottom: 0,
283
+ display: "flex",
284
+ alignItems: "center",
285
+ justifyContent: "center",
286
+ backgroundColor: "rgba(0, 0, 0, 0.7)",
287
+ zIndex: 1e3,
288
+ // Re-enable pointer events explicitly: the editor's preview
289
+ // modal mounts the player inside a `pointerEvents: "none"`
290
+ // container, and a descendant with `auto` re-enables it.
291
+ pointerEvents: "auto"
292
+ },
293
+ role: "dialog",
294
+ "aria-modal": "true",
295
+ "aria-labelledby": `blocking-content-${content.getId()}`,
296
+ children: /* @__PURE__ */ jsxs(
297
+ "div",
298
+ {
299
+ style: {
300
+ backgroundColor: COLORS.surface,
301
+ borderRadius: `${RADIUS.lg}px`,
302
+ padding: `${SPACE[5]}px`,
303
+ maxWidth: "500px",
304
+ width: "90%",
305
+ maxHeight: "80vh",
306
+ overflowY: "auto",
307
+ boxShadow: "0 16px 48px rgba(0, 0, 0, 0.35)"
308
+ },
309
+ children: [
310
+ /* @__PURE__ */ jsxs(
311
+ "div",
312
+ {
313
+ style: {
314
+ display: "flex",
315
+ justifyContent: "space-between",
316
+ alignItems: "flex-start",
317
+ gap: `${SPACE[2]}px`
318
+ },
319
+ children: [
320
+ /* @__PURE__ */ jsx2(
321
+ "h2",
322
+ {
323
+ id: `blocking-content-${content.getId()}`,
324
+ style: {
325
+ marginTop: 0,
326
+ fontFamily: FONTS.display,
327
+ fontSize: TYPE.lg,
328
+ fontWeight: 600,
329
+ color: COLORS.text
330
+ },
331
+ children: content.getTitle()
332
+ }
333
+ ),
334
+ content.getHook().type === "non-blocking" && /* @__PURE__ */ jsx2(
335
+ "button",
336
+ {
337
+ type: "button",
338
+ onClick: () => {
339
+ content.skip();
340
+ onSkip?.();
341
+ },
342
+ style: {
343
+ padding: `${SPACE[1]}px ${SPACE[2]}px`,
344
+ backgroundColor: "red",
345
+ color: COLORS.white,
346
+ border: "none",
347
+ borderRadius: `${RADIUS.sm}px`,
348
+ cursor: "pointer",
349
+ fontSize: TYPE.sm,
350
+ fontWeight: 600,
351
+ transition: "background-color 150ms ease"
352
+ },
353
+ children: "Skip"
354
+ }
355
+ )
356
+ ]
357
+ }
358
+ ),
359
+ completing ? completionSurface : /* @__PURE__ */ jsx2("div", { style: { margin: `${SPACE[4]}px 0` }, children: /* @__PURE__ */ jsx2("div", { ref: bodyRef }) })
360
+ ]
361
+ }
362
+ )
363
+ }
364
+ );
365
+ };
366
+
367
+ // src/components/completed-tag.tsx
368
+ import { jsxs as jsxs2 } from "react/jsx-runtime";
369
+ var CompletedTag = ({
370
+ id,
371
+ title,
372
+ placement
373
+ }) => {
374
+ return /* @__PURE__ */ jsxs2(
375
+ "div",
376
+ {
377
+ "data-content-id": id,
378
+ style: {
379
+ position: "absolute",
380
+ left: `${placement.x}%`,
381
+ top: `${placement.y}%`,
382
+ width: `${placement.width}%`,
383
+ height: `${placement.height}%`,
384
+ display: "flex",
385
+ alignItems: "center",
386
+ justifyContent: "center",
387
+ backgroundColor: COLORS.accent,
388
+ color: COLORS.white,
389
+ fontSize: TYPE.xs,
390
+ fontWeight: 700,
391
+ borderRadius: `${RADIUS.sm}px`,
392
+ padding: `${SPACE[1]}px ${SPACE[2]}px`,
393
+ textAlign: "center",
394
+ zIndex: 4,
395
+ boxShadow: SHADOWS.sm
396
+ },
397
+ children: [
398
+ "\u2713 ",
399
+ title
400
+ ]
401
+ }
402
+ );
403
+ };
404
+
405
+ // src/components/content-error-boundary.tsx
406
+ import React3 from "react";
407
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
408
+ var ContentErrorBoundary = class extends React3.Component {
409
+ constructor(props) {
410
+ super(props);
411
+ this.state = { hasError: false, error: null };
412
+ }
413
+ static getDerivedStateFromError(error) {
414
+ return { hasError: true, error };
415
+ }
416
+ componentDidCatch(error) {
417
+ this.props.onError?.(error);
418
+ }
419
+ render() {
420
+ if (this.state.hasError) {
421
+ return this.props.fallback || /* @__PURE__ */ jsxs3(
422
+ "div",
423
+ {
424
+ style: {
425
+ padding: `${SPACE[4]}px`,
426
+ backgroundColor: COLORS.errorBg,
427
+ color: COLORS.errorText,
428
+ border: `1px solid ${COLORS.errorBorder}`,
429
+ borderRadius: `${RADIUS.md}px`,
430
+ fontSize: TYPE.md,
431
+ lineHeight: 1.5
432
+ },
433
+ children: [
434
+ /* @__PURE__ */ jsx3("strong", { children: "Content Error" }),
435
+ /* @__PURE__ */ jsx3("p", { style: { margin: `${SPACE[1]}px 0 0 0` }, children: this.state.error?.message })
436
+ ]
437
+ }
438
+ );
439
+ }
440
+ return this.props.children;
441
+ }
442
+ };
443
+
444
+ // src/components/interactive-video-player.tsx
445
+ import { useCallback, useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
446
+
447
+ // src/hooks/use-interactive-media.ts
448
+ import {
449
+ deserialize,
450
+ InteractiveMediaController
451
+ } from "@interlacejs/core";
452
+ import { useEffect as useEffect2, useRef as useRef3, useState as useState2 } from "react";
453
+ function useInteractiveMedia(options) {
454
+ const {
455
+ adapter,
456
+ document: doc,
457
+ registry,
458
+ onRenderStateChange,
459
+ onError
460
+ } = options;
461
+ const controllerRef = useRef3(null);
462
+ const rafRef = useRef3(null);
463
+ const isPlayingRef = useRef3(false);
464
+ const [initialized, setInitialized] = useState2(false);
465
+ const [error, setError] = useState2(null);
466
+ const [items, setItems] = useState2(null);
467
+ useEffect2(() => {
468
+ try {
469
+ const result = deserialize(doc, registry);
470
+ if (result.validationErrors.length > 0) {
471
+ throw new Error(
472
+ `Document validation failed: ${result.validationErrors[0]}`
473
+ );
474
+ }
475
+ const controller = new InteractiveMediaController(
476
+ result.items,
477
+ result.videoDuration
478
+ );
479
+ controllerRef.current = controller;
480
+ setItems(result.items);
481
+ setInitialized(true);
482
+ return () => {
483
+ controllerRef.current = null;
484
+ setItems(null);
485
+ };
486
+ } catch (err) {
487
+ const error2 = err instanceof Error ? err : new Error(String(err));
488
+ setError(error2);
489
+ onError?.(error2);
490
+ }
491
+ }, [doc, registry, onError]);
492
+ useEffect2(() => {
493
+ if (!initialized || !controllerRef.current) return;
494
+ const controller = controllerRef.current;
495
+ const unsubscribePause = adapter.on("pause", () => {
496
+ isPlayingRef.current = false;
497
+ });
498
+ const unsubscribePlaying = adapter.on("play", () => {
499
+ isPlayingRef.current = true;
500
+ });
501
+ const unsubscribeRequestPause = controller.on("requestPause", () => {
502
+ adapter.pause();
503
+ });
504
+ const unsubscribeRequestSeek = controller.on("requestSeek", (event) => {
505
+ adapter.seek(event.timeInSeconds);
506
+ });
507
+ return () => {
508
+ unsubscribePause();
509
+ unsubscribePlaying();
510
+ unsubscribeRequestPause();
511
+ unsubscribeRequestSeek();
512
+ };
513
+ }, [initialized, adapter]);
514
+ useEffect2(() => {
515
+ if (!initialized || !controllerRef.current) return;
516
+ const controller = controllerRef.current;
517
+ const tick = () => {
518
+ const currentTime = adapter.getCurrentTime();
519
+ const isPlayingForward = isPlayingRef.current;
520
+ controller.tick(currentTime, isPlayingForward);
521
+ const renderState = controller.getRenderState(currentTime);
522
+ onRenderStateChange?.(renderState);
523
+ rafRef.current = requestAnimationFrame(tick);
524
+ };
525
+ rafRef.current = requestAnimationFrame(tick);
526
+ return () => {
527
+ if (rafRef.current) {
528
+ cancelAnimationFrame(rafRef.current);
529
+ }
530
+ };
531
+ }, [initialized, adapter, onRenderStateChange]);
532
+ return {
533
+ controller: controllerRef.current,
534
+ /** The deserialized content instances backing the controller. */
535
+ items,
536
+ initialized,
537
+ error
538
+ };
539
+ }
540
+
541
+ // src/components/overlay-layer.tsx
542
+ import { useMemo } from "react";
543
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
544
+ var OverlayLayer = ({
545
+ renderState,
546
+ items,
547
+ onAnchorClick
548
+ }) => {
549
+ const itemMap = useMemo(() => {
550
+ const map = /* @__PURE__ */ new Map();
551
+ for (const item of items) {
552
+ map.set(item.content.getId(), item);
553
+ }
554
+ return map;
555
+ }, [items]);
556
+ return /* @__PURE__ */ jsxs4(
557
+ "div",
558
+ {
559
+ style: {
560
+ position: "absolute",
561
+ top: 0,
562
+ left: 0,
563
+ width: "100%",
564
+ height: "100%",
565
+ zIndex: 10,
566
+ pointerEvents: "none"
567
+ },
568
+ children: [
569
+ /* @__PURE__ */ jsx4(
570
+ "div",
571
+ {
572
+ style: {
573
+ position: "absolute",
574
+ top: 0,
575
+ left: 0,
576
+ width: "100%",
577
+ height: "100%",
578
+ pointerEvents: "none"
579
+ },
580
+ children: renderState.visibleAnchorIds?.map((contentId) => {
581
+ const item = itemMap.get(contentId);
582
+ if (!item) return null;
583
+ const hook = item.hook;
584
+ if (hook.type !== "non-blocking") return null;
585
+ return /* @__PURE__ */ jsx4(
586
+ Anchor,
587
+ {
588
+ id: contentId,
589
+ placement: hook.placement,
590
+ title: item.content.getTitle(),
591
+ isOpened: renderState.openedContentIds.includes(contentId),
592
+ onClick: () => {
593
+ item.content.open();
594
+ onAnchorClick?.(contentId);
595
+ }
596
+ },
597
+ contentId
598
+ );
599
+ })
600
+ }
601
+ ),
602
+ /* @__PURE__ */ jsx4(
603
+ "div",
604
+ {
605
+ style: {
606
+ position: "absolute",
607
+ top: 0,
608
+ left: 0,
609
+ width: "100%",
610
+ height: "100%",
611
+ pointerEvents: "none"
612
+ },
613
+ children: renderState.completedTagIds?.map((contentId) => {
614
+ const item = itemMap.get(contentId);
615
+ if (!item) return null;
616
+ const hook = item.hook;
617
+ return /* @__PURE__ */ jsx4(
618
+ CompletedTag,
619
+ {
620
+ id: contentId,
621
+ title: item.content.getTitle(),
622
+ placement: hook.placement
623
+ },
624
+ `completed-${contentId}`
625
+ );
626
+ })
627
+ }
628
+ )
629
+ ]
630
+ }
631
+ );
632
+ };
633
+
634
+ // src/components/interactive-video-player.tsx
635
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
636
+ var InteractiveVideoPlayer = ({
637
+ adapter,
638
+ document: doc,
639
+ registry,
640
+ onError
641
+ }) => {
642
+ const [renderState, setRenderState] = useState3({
643
+ visibleAnchorIds: [],
644
+ completedTagIds: [],
645
+ openedContentIds: []
646
+ });
647
+ const [activeContentId, setActiveContentId] = useState3(null);
648
+ const [completingId, setCompletingId] = useState3(null);
649
+ const [completingScore, setCompletingScore] = useState3(
650
+ void 0
651
+ );
652
+ const lastAutoOpenedBlockingIdRef = useRef4(null);
653
+ const { controller, items, initialized, error } = useInteractiveMedia({
654
+ adapter,
655
+ document: doc,
656
+ registry,
657
+ onRenderStateChange: setRenderState,
658
+ onError
659
+ });
660
+ const handleAnchorClick = useCallback(
661
+ (contentId) => {
662
+ adapter.pause();
663
+ setActiveContentId(contentId);
664
+ },
665
+ [adapter]
666
+ );
667
+ useEffect3(() => {
668
+ const blockingId = renderState.activeBlockingContentId;
669
+ if (blockingId && blockingId !== lastAutoOpenedBlockingIdRef.current) {
670
+ lastAutoOpenedBlockingIdRef.current = blockingId;
671
+ setActiveContentId(blockingId);
672
+ } else if (!blockingId && lastAutoOpenedBlockingIdRef.current) {
673
+ lastAutoOpenedBlockingIdRef.current = null;
674
+ }
675
+ }, [renderState.activeBlockingContentId]);
676
+ const handleContentComplete = useCallback(
677
+ (score) => {
678
+ if (!controller || !activeContentId) return;
679
+ const item = (items ?? []).find((it) => it.getId() === activeContentId);
680
+ item?.complete(score ?? 0);
681
+ setCompletingScore(score ?? 0);
682
+ setCompletingId(activeContentId);
683
+ setActiveContentId(null);
684
+ },
685
+ [controller, items, activeContentId]
686
+ );
687
+ const handleContinueAfterCompletion = useCallback(() => {
688
+ setCompletingId(null);
689
+ setCompletingScore(void 0);
690
+ void adapter.play();
691
+ }, [adapter]);
692
+ if (error) {
693
+ return /* @__PURE__ */ jsxs5(
694
+ "div",
695
+ {
696
+ style: {
697
+ padding: `${SPACE[4]}px`,
698
+ color: COLORS.errorText,
699
+ backgroundColor: COLORS.errorBg,
700
+ border: `1px solid ${COLORS.errorBorder}`,
701
+ borderRadius: `${RADIUS.md}px`,
702
+ fontSize: TYPE.md,
703
+ lineHeight: 1.5
704
+ },
705
+ children: [
706
+ /* @__PURE__ */ jsx5("strong", { children: "Player Error:" }),
707
+ " ",
708
+ error.message
709
+ ]
710
+ }
711
+ );
712
+ }
713
+ if (!initialized || !controller) {
714
+ return /* @__PURE__ */ jsx5(
715
+ "div",
716
+ {
717
+ style: {
718
+ padding: `${SPACE[4]}px`,
719
+ color: COLORS.textMuted,
720
+ fontSize: TYPE.md
721
+ },
722
+ children: "Loading player\u2026"
723
+ }
724
+ );
725
+ }
726
+ const overlayItems = (items ?? []).map((content) => ({
727
+ content,
728
+ hook: content.getHook()
729
+ }));
730
+ const overlayContentId = activeContentId ?? completingId;
731
+ const activeItem = overlayItems.find(
732
+ (item) => item.content.getId() === overlayContentId
733
+ );
734
+ const activeContentType = activeItem ? registry.get(activeItem.content.getContentTypeId()) : void 0;
735
+ return /* @__PURE__ */ jsx5(ContentErrorBoundary, { onError, children: /* @__PURE__ */ jsxs5("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
736
+ /* @__PURE__ */ jsx5(
737
+ OverlayLayer,
738
+ {
739
+ renderState,
740
+ items: overlayItems,
741
+ onAnchorClick: handleAnchorClick
742
+ }
743
+ ),
744
+ activeItem && activeContentType && /* @__PURE__ */ jsx5(
745
+ BlockingOverlay,
746
+ {
747
+ content: activeItem.content,
748
+ contentType: activeContentType,
749
+ onSkip: () => {
750
+ const item = (items ?? []).find(
751
+ (it) => it.getId() === overlayContentId
752
+ );
753
+ item?.skip();
754
+ setActiveContentId(null);
755
+ void adapter.play();
756
+ },
757
+ onContentComplete: handleContentComplete,
758
+ onContinue: handleContinueAfterCompletion,
759
+ completing: completingId !== null && completingId === overlayContentId,
760
+ completingScore
761
+ }
762
+ )
763
+ ] }) });
764
+ };
765
+
766
+ // src/utils/preload-scheduler.ts
767
+ var PreloadScheduler = class {
768
+ leadTimeMs;
769
+ scheduledPreloads = /* @__PURE__ */ new Map();
770
+ constructor(leadTimeMs = 2e3) {
771
+ this.leadTimeMs = leadTimeMs;
772
+ }
773
+ /**
774
+ * Get content IDs that should be preloaded at the current time.
775
+ */
776
+ getPreloadQueue(currentTime, items) {
777
+ const queue = [];
778
+ const cutoffTime = currentTime + this.leadTimeMs / 1e3;
779
+ for (const item of items) {
780
+ const contentId = item.content.getId();
781
+ const hook = item.hook;
782
+ if (hook.type === "non-blocking") {
783
+ if (hook.start <= cutoffTime && hook.start > currentTime) {
784
+ queue.push(contentId);
785
+ }
786
+ }
787
+ if (hook.type === "blocking") {
788
+ if (hook.timestamp <= cutoffTime && hook.timestamp > currentTime) {
789
+ queue.push(contentId);
790
+ }
791
+ }
792
+ }
793
+ return queue;
794
+ }
795
+ /**
796
+ * Clear all scheduled preloads (e.g., on seek).
797
+ */
798
+ clear() {
799
+ this.scheduledPreloads.clear();
800
+ }
801
+ /**
802
+ * Set lead time in milliseconds.
803
+ */
804
+ setLeadTime(ms) {
805
+ this.leadTimeMs = ms;
806
+ }
807
+ };
808
+ export {
809
+ Anchor,
810
+ BlockingOverlay,
811
+ CompletedTag,
812
+ ContentErrorBoundary,
813
+ InteractiveVideoPlayer,
814
+ OverlayLayer,
815
+ PreloadScheduler,
816
+ useInteractiveMedia
817
+ };
818
+ //# sourceMappingURL=index.js.map