@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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/components/anchor.tsx","../src/tokens.ts","../src/components/blocking-overlay.tsx","../src/components/completed-tag.tsx","../src/components/content-error-boundary.tsx","../src/components/interactive-video-player.tsx","../src/hooks/use-interactive-media.ts","../src/components/overlay-layer.tsx","../src/utils/preload-scheduler.ts"],"sourcesContent":["export { Anchor } from \"./components/anchor\";\nexport { BlockingOverlay } from \"./components/blocking-overlay\";\nexport { CompletedTag } from \"./components/completed-tag\";\nexport { ContentErrorBoundary } from \"./components/content-error-boundary\";\nexport { InteractiveVideoPlayer } from \"./components/interactive-video-player\";\nexport { OverlayLayer } from \"./components/overlay-layer\";\nexport { useInteractiveMedia } from \"./hooks/use-interactive-media\";\nexport { PreloadScheduler } from \"./utils/preload-scheduler\";\n\nexport type { AnchorProps } from \"./components/anchor\";\nexport type { BlockingOverlayProps } from \"./components/blocking-overlay\";\nexport type { CompletedTagProps } from \"./components/completed-tag\";\nexport type { ContentErrorBoundaryProps } from \"./components/content-error-boundary\";\nexport type { InteractiveVideoPlayerProps } from \"./components/interactive-video-player\";\nexport type { OverlayLayerProps } from \"./components/overlay-layer\";\nexport type { UseInteractiveMediaOptions } from \"./hooks/use-interactive-media\";\n","import React, { useRef } from \"react\";\nimport { COLORS, RADIUS, SHADOWS, SPACE, TYPE } from \"../tokens\";\n\nexport interface AnchorProps {\n id: string;\n placement: { x: number; y: number; width: number; height: number };\n title: string;\n isOpened?: boolean;\n onClick?: () => void;\n}\n\n/**\n * Anchor component - a clickable button for non-blocking content.\n * Positioned absolutely with minimum 44px touch target.\n */\nexport const Anchor = React.forwardRef<HTMLButtonElement, AnchorProps>(\n ({ id, placement, title, isOpened, onClick }, ref) => {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const internalRef =\n (ref as React.MutableRefObject<HTMLButtonElement>) || buttonRef;\n\n // Ensure minimum 44px touch target\n const minSize = 44;\n const width = Math.max(placement.width, minSize / 100);\n const height = Math.max(placement.height, minSize / 100);\n\n return (\n <button\n ref={internalRef}\n onClick={onClick}\n aria-label={title}\n data-content-id={id}\n style={{\n position: \"absolute\",\n left: `${placement.x}%`,\n top: `${placement.y}%`,\n width: `${width}%`,\n height: `${height}%`,\n minWidth: `${minSize}px`,\n minHeight: `${minSize}px`,\n padding: `${SPACE[2]}px ${SPACE[3]}px`,\n fontSize: TYPE.md,\n fontWeight: 600,\n border: `2px solid ${COLORS.accent}`,\n borderRadius: `${RADIUS.sm}px`,\n backgroundColor: isOpened ? COLORS.accent : COLORS.surface,\n color: isOpened ? COLORS.white : COLORS.accent,\n cursor: \"pointer\",\n transition: \"background-color 150ms ease, color 150ms ease, box-shadow 150ms ease\",\n boxShadow: isOpened ? \"0 4px 8px rgba(0, 102, 204, 0.3)\" : SHADOWS.sm,\n zIndex: 2,\n // The anchors layer is pointer-transparent; each anchor\n // re-enables pointer events for itself.\n pointerEvents: \"auto\",\n }}\n >\n {title}\n </button>\n );\n },\n);\n\nAnchor.displayName = \"Anchor\";\n","/**\n * Interlace design tokens.\n *\n * These values mirror the demo app's CSS custom properties so the library\n * surfaces feel like a single system. They are duplicated per package to\n * avoid adding runtime cross-package dependencies.\n */\n\nexport const COLORS = {\n accent: \"#0066cc\",\n accentHover: \"#0052a3\",\n accentLight: \"rgba(0, 102, 204, 0.15)\",\n accentLighter: \"rgba(0, 102, 204, 0.08)\",\n text: \"#0f172a\",\n textMuted: \"#64748b\",\n border: \"#e2e8f0\",\n borderStrong: \"#cbd5e1\",\n surface: \"#ffffff\",\n surfaceRaised: \"#f8fafc\",\n ground: \"#f6f7f9\",\n errorBg: \"#fef2f2\",\n errorText: \"#b91c1c\",\n errorBorder: \"#fecaca\",\n white: \"#ffffff\",\n black: \"#000000\",\n} as const;\n\nexport const FONTS = {\n display: 'Georgia, \"Times New Roman\", Times, serif',\n body: 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif',\n} as const;\n\nexport const SPACE = {\n 1: 4,\n 2: 8,\n 3: 12,\n 4: 16,\n 5: 24,\n} as const;\n\nexport const RADIUS = {\n sm: 4,\n md: 8,\n lg: 12,\n} as const;\n\nexport const SHADOWS = {\n sm: \"0 1px 2px 0 rgba(15, 23, 42, 0.04)\",\n md: \"0 4px 12px -2px rgba(15, 23, 42, 0.08)\",\n} as const;\n\nexport const TYPE = {\n xs: 12,\n sm: 13,\n base: 15,\n md: 16,\n lg: 20,\n xl: 24,\n} as const;\n","import { ContentInstance, ContentType } from \"@interlacejs/core\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { COLORS, FONTS, RADIUS, SPACE, TYPE } from \"../tokens\";\n\nexport interface BlockingOverlayProps {\n content: ContentInstance;\n /**\n * The content type owning `content` — its `renderPlayback` mounts\n * into the overlay body and its `unmountPlayback` tears it down on\n * close/unmount.\n */\n contentType: ContentType;\n /**\n * Skip affordance for NON-blocking content opened in the overlay: the\n * user declines this hook for the current window visit. The parent\n * wires this to `skipContent` (controller-managed skip memory) and\n * clears the selection; blocking content renders no Skip control.\n */\n onSkip?: () => void;\n /**\n * Called with the reported score when the content's playback\n * completes itself via `callbacks.onComplete` (the parent then\n * completes the item through the controller).\n */\n onContentComplete?: (score?: number) => void;\n /**\n * Completing mode: the content body is swapped for a completion\n * surface (animated check + \"Completed\" + score) that persists until\n * the user acknowledges it.\n */\n completing?: boolean;\n /** Score reported by the completed content, shown in completing mode. */\n completingScore?: number;\n /**\n * Completion-acknowledgement control (programmatic owner: the player).\n * The completing surface's ONLY exit is the Continue button that calls\n * this — it is not a dismiss affordance; the parent resumes playback and\n * unmounts the overlay.\n */\n onContinue?: () => void;\n}\n\n/**\n * BlockingOverlay - modal overlay for blocking content.\n * Implements focus trap to keep focus within the overlay.\n * Pauses video while open.\n *\n * Playback mounting (container-identity contract): the content type's\n * `renderPlayback`/`unmountPlayback` receive the same body container\n * element for the overlay's lifetime; React holds the ref stable while\n * the overlay is open.\n */\nexport const BlockingOverlay: React.FC<BlockingOverlayProps> = ({\n content,\n contentType,\n onContentComplete,\n onSkip,\n completing = false,\n completingScore,\n onContinue,\n}) => {\n const overlayRef = useRef<HTMLDivElement>(null);\n const bodyRef = useRef<HTMLDivElement>(null);\n // Drives the completion surface's fade/slide-in transition.\n const [revealed, setRevealed] = useState(false);\n\n // Mount/unmount the content type's playback session. The same body\n // completion callback is ref-stabilized so identity churn cannot\n // tear the session down.\n const onContentCompleteRef = useRef(onContentComplete);\n onContentCompleteRef.current = onContentComplete;\n\n useEffect(() => {\n const body = bodyRef.current;\n if (!body || !contentType) return;\n\n try {\n contentType.renderPlayback(body, content.getData(), {\n onComplete: (score) => {\n onContentCompleteRef.current?.(score);\n },\n });\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n // Render failures surface through the overlay's own body rather\n // than crashing the player: show the error in place.\n body.textContent = error.message;\n return;\n }\n\n return () => {\n contentType.unmountPlayback?.(body);\n };\n }, [contentType, content]);\n\n // When the overlay enters completing mode, flip `revealed` on the next\n // frame so the CSS transitions animate the check + label in.\n useEffect(() => {\n if (!completing) {\n setRevealed(false);\n return;\n }\n const raf = requestAnimationFrame(() => setRevealed(true));\n return () => cancelAnimationFrame(raf);\n }, [completing]);\n\n // Focus trap: keep focus within overlay. Re-runs when completing mode\n // flips so the completion surface's Continue button joins the trap and\n // receives focus as the surface appears (the content body's focusables\n // are gone by then).\n useEffect(() => {\n const overlay = overlayRef.current;\n if (!overlay) return;\n\n const focusableElements = overlay.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0] as HTMLElement;\n const lastElement = focusableElements[\n focusableElements.length - 1\n ] as HTMLElement;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key !== \"Tab\") return;\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n e.preventDefault();\n lastElement.focus();\n }\n } else {\n if (document.activeElement === lastElement) {\n e.preventDefault();\n firstElement.focus();\n }\n }\n };\n\n overlay.addEventListener(\"keydown\", handleKeyDown);\n firstElement.focus();\n\n return () => {\n overlay.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [completing]);\n\n const completionSurface = (\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: `${SPACE[3]}px`,\n padding: `${SPACE[4]}px 0`,\n }}\n >\n <div\n style={{\n width: 56,\n height: 56,\n borderRadius: \"50%\",\n backgroundColor: COLORS.accentLighter,\n color: COLORS.accent,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: TYPE.xl,\n fontWeight: 600,\n lineHeight: 1,\n opacity: revealed ? 1 : 0,\n transform: revealed ? \"scale(1)\" : \"scale(0.6)\",\n transition: \"opacity 200ms ease, transform 200ms ease\",\n }}\n aria-hidden=\"true\"\n >\n ✓\n </div>\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: `${SPACE[1]}px`,\n margin: 0,\n fontFamily: FONTS.display,\n fontSize: TYPE.lg,\n fontWeight: 600,\n color: COLORS.text,\n opacity: revealed ? 1 : 0,\n transform: revealed ? \"none\" : \"translateY(6px)\",\n transition: \"opacity 250ms ease 120ms, transform 250ms ease 120ms\",\n }}\n >\n <span>Completed</span>\n {typeof completingScore === \"number\" && (\n <span\n aria-label={`completion-score-${completingScore}`}\n style={{\n display: \"inline-block\",\n padding: `0 ${SPACE[2]}px`,\n borderRadius: `${RADIUS.sm}px`,\n backgroundColor: COLORS.accent,\n color: COLORS.white,\n fontSize: TYPE.sm,\n fontWeight: 600,\n verticalAlign: \"middle\",\n }}\n >\n Score: {completingScore}/{content.getMaximumScore()}\n </span>\n )}\n </div>\n <button\n type=\"button\"\n onClick={onContinue}\n style={{\n marginTop: `${SPACE[3]}px`,\n padding: `${SPACE[2]}px ${SPACE[5]}px`,\n backgroundColor: COLORS.accent,\n color: COLORS.white,\n border: \"none\",\n borderRadius: `${RADIUS.sm}px`,\n cursor: \"pointer\",\n fontSize: TYPE.md,\n fontWeight: 600,\n transition: \"background-color 150ms ease\",\n opacity: revealed ? 1 : 0,\n }}\n >\n Continue\n </button>\n </div>\n );\n\n return (\n <div\n ref={overlayRef}\n style={{\n position: \"fixed\",\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(0, 0, 0, 0.7)\",\n zIndex: 1000,\n // Re-enable pointer events explicitly: the editor's preview\n // modal mounts the player inside a `pointerEvents: \"none\"`\n // container, and a descendant with `auto` re-enables it.\n pointerEvents: \"auto\",\n }}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={`blocking-content-${content.getId()}`}\n >\n <div\n style={{\n backgroundColor: COLORS.surface,\n borderRadius: `${RADIUS.lg}px`,\n padding: `${SPACE[5]}px`,\n maxWidth: \"500px\",\n width: \"90%\",\n maxHeight: \"80vh\",\n overflowY: \"auto\",\n boxShadow: \"0 16px 48px rgba(0, 0, 0, 0.35)\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n justifyContent: \"space-between\",\n alignItems: \"flex-start\",\n gap: `${SPACE[2]}px`,\n }}\n >\n <h2\n id={`blocking-content-${content.getId()}`}\n style={{\n marginTop: 0,\n fontFamily: FONTS.display,\n fontSize: TYPE.lg,\n fontWeight: 600,\n color: COLORS.text,\n }}\n >\n {content.getTitle()}\n </h2>\n {content.getHook().type === \"non-blocking\" && (\n <button\n type=\"button\"\n onClick={() => {\n content.skip();\n onSkip?.();\n }}\n style={{\n padding: `${SPACE[1]}px ${SPACE[2]}px`,\n backgroundColor: \"red\",\n color: COLORS.white,\n border: \"none\",\n borderRadius: `${RADIUS.sm}px`,\n cursor: \"pointer\",\n fontSize: TYPE.sm,\n fontWeight: 600,\n transition: \"background-color 150ms ease\",\n }}\n >\n Skip\n </button>\n )}\n </div>\n\n {completing ? (\n completionSurface\n ) : (\n <div style={{ margin: `${SPACE[4]}px 0` }}>\n <div ref={bodyRef} />\n </div>\n )}\n </div>\n </div>\n );\n};\n","import React from \"react\";\nimport { COLORS, RADIUS, SHADOWS, SPACE, TYPE } from \"../tokens\";\n\nexport interface CompletedTagProps {\n id: string;\n title: string;\n placement: { x: number; y: number; width: number; height: number };\n}\n\n/**\n * CompletedTag - visual indicator showing that content has been completed.\n * Displayed as a badge overlay on top of the video.\n */\nexport const CompletedTag: React.FC<CompletedTagProps> = ({\n id,\n title,\n placement,\n}) => {\n return (\n <div\n data-content-id={id}\n style={{\n position: \"absolute\",\n left: `${placement.x}%`,\n top: `${placement.y}%`,\n width: `${placement.width}%`,\n height: `${placement.height}%`,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: COLORS.accent,\n color: COLORS.white,\n fontSize: TYPE.xs,\n fontWeight: 700,\n borderRadius: `${RADIUS.sm}px`,\n padding: `${SPACE[1]}px ${SPACE[2]}px`,\n textAlign: \"center\",\n zIndex: 4,\n boxShadow: SHADOWS.sm,\n }}\n >\n ✓ {title}\n </div>\n );\n};\n","import React, { ReactNode } from \"react\";\nimport { COLORS, RADIUS, SPACE, TYPE } from \"../tokens\";\n\nexport interface ContentErrorBoundaryProps {\n children: ReactNode;\n onError?: (error: Error) => void;\n fallback?: ReactNode;\n}\n\ninterface State {\n hasError: boolean;\n error: Error | null;\n}\n\n/**\n * Error boundary for content rendering failures.\n * Catches render errors from content components and displays fallback UI.\n */\nexport class ContentErrorBoundary extends React.Component<\n ContentErrorBoundaryProps,\n State\n> {\n constructor(props: ContentErrorBoundaryProps) {\n super(props);\n this.state = { hasError: false, error: null };\n }\n\n static getDerivedStateFromError(error: Error): State {\n return { hasError: true, error };\n }\n\n componentDidCatch(error: Error) {\n this.props.onError?.(error);\n }\n\n render() {\n if (this.state.hasError) {\n return (\n this.props.fallback || (\n <div\n style={{\n padding: `${SPACE[4]}px`,\n backgroundColor: COLORS.errorBg,\n color: COLORS.errorText,\n border: `1px solid ${COLORS.errorBorder}`,\n borderRadius: `${RADIUS.md}px`,\n fontSize: TYPE.md,\n lineHeight: 1.5,\n }}\n >\n <strong>Content Error</strong>\n <p style={{ margin: `${SPACE[1]}px 0 0 0` }}>\n {this.state.error?.message}\n </p>\n </div>\n )\n );\n }\n\n return this.props.children;\n }\n}\n","import {\n ContentTypeRegistry,\n RenderState,\n SerializedInteractiveMediaDocument,\n VideoAdapter,\n} from \"@interlacejs/core\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useInteractiveMedia } from \"../hooks/use-interactive-media\";\nimport { COLORS, RADIUS, SPACE, TYPE } from \"../tokens\";\nimport { BlockingOverlay } from \"./blocking-overlay\";\nimport { ContentErrorBoundary } from \"./content-error-boundary\";\nimport { OverlayLayer } from \"./overlay-layer\";\n\nexport interface InteractiveVideoPlayerProps {\n adapter: VideoAdapter;\n document: SerializedInteractiveMediaDocument;\n registry: ContentTypeRegistry;\n onError?: (error: Error) => void;\n}\n\n/**\n * InteractiveVideoPlayer - top-level React component for interactive video playback.\n * Integrates:\n * - useInteractiveMedia hook for runtime state management\n * - OverlayLayer for anchor and completed tag rendering\n * - BlockingOverlay for interactive content modals\n * - ContentErrorBoundary for error handling\n */\nexport const InteractiveVideoPlayer: React.FC<InteractiveVideoPlayerProps> = ({\n adapter,\n document: doc,\n registry,\n onError,\n}) => {\n const [renderState, setRenderState] = useState<RenderState>({\n visibleAnchorIds: [],\n completedTagIds: [],\n openedContentIds: [],\n });\n const [activeContentId, setActiveContentId] = useState<string | null>(null);\n // Completing lifecycle: after an item completes, the overlay stays mounted\n // showing the completion surface + Continue until the user acknowledges it\n // (Continue resumes playback and unmounts the overlay).\n const [completingId, setCompletingId] = useState<string | null>(null);\n const [completingScore, setCompletingScore] = useState<number | undefined>(\n undefined,\n );\n const lastAutoOpenedBlockingIdRef = useRef<string | null>(null);\n\n const { controller, items, initialized, error } = useInteractiveMedia({\n adapter,\n document: doc,\n registry,\n onRenderStateChange: setRenderState,\n onError,\n });\n\n const handleAnchorClick = useCallback(\n (contentId: string) => {\n adapter.pause();\n setActiveContentId(contentId);\n },\n [adapter],\n );\n\n // Auto-open the blocking overlay when the controller pauses for blocking\n // content. The ref guard keeps a manually closed overlay closed instead of\n // reopening it on every render state update; the ref re-arms when the\n // controller leaves the blocking frame (scrub, settle, or completion), so\n // re-seeking a dismissed hook re-opens it instead of leaving the player\n // stuck with a paused video and no overlay.\n useEffect(() => {\n const blockingId = renderState.activeBlockingContentId;\n if (blockingId && blockingId !== lastAutoOpenedBlockingIdRef.current) {\n lastAutoOpenedBlockingIdRef.current = blockingId;\n setActiveContentId(blockingId);\n } else if (!blockingId && lastAutoOpenedBlockingIdRef.current) {\n lastAutoOpenedBlockingIdRef.current = null;\n }\n }, [renderState.activeBlockingContentId]);\n\n const handleContentComplete = useCallback(\n (score?: number) => {\n if (!controller || !activeContentId) return;\n const item = (items ?? []).find((it) => it.getId() === activeContentId);\n item?.complete(score ?? 0);\n // Enter the completing lifecycle: the overlay swaps to a completion\n // surface with a Continue button. Playback stays PAUSED until the\n // user acknowledges completion and resumes via Continue.\n setCompletingScore(score ?? 0);\n setCompletingId(activeContentId);\n setActiveContentId(null);\n },\n [controller, items, activeContentId],\n );\n\n // Continue-gated resume: unmount the completion surface and resume\n // playback. This is the ONLY exit from the completing state.\n const handleContinueAfterCompletion = useCallback(() => {\n setCompletingId(null);\n setCompletingScore(undefined);\n void adapter.play();\n }, [adapter]);\n\n if (error) {\n return (\n <div\n style={{\n padding: `${SPACE[4]}px`,\n color: COLORS.errorText,\n backgroundColor: COLORS.errorBg,\n border: `1px solid ${COLORS.errorBorder}`,\n borderRadius: `${RADIUS.md}px`,\n fontSize: TYPE.md,\n lineHeight: 1.5,\n }}\n >\n <strong>Player Error:</strong> {error.message}\n </div>\n );\n }\n\n if (!initialized || !controller) {\n return (\n <div\n style={{\n padding: `${SPACE[4]}px`,\n color: COLORS.textMuted,\n fontSize: TYPE.md,\n }}\n >\n Loading player…\n </div>\n );\n }\n\n // Controller stores plain ContentInstance[]; overlay components expect\n // { content, hook } pairs.\n const overlayItems = (items ?? []).map((content) => ({\n content,\n hook: content.getHook(),\n }));\n // The overlay renders for the active content, or the completing content\n // while the completion surface is showing.\n const overlayContentId = activeContentId ?? completingId;\n const activeItem = overlayItems.find(\n (item) => item.content.getId() === overlayContentId,\n );\n const activeContentType = activeItem\n ? registry.get(activeItem.content.getContentTypeId())\n : undefined;\n\n return (\n <ContentErrorBoundary onError={onError}>\n <div style={{ position: \"relative\", width: \"100%\", height: \"100%\" }}>\n <OverlayLayer\n renderState={renderState}\n items={overlayItems}\n onAnchorClick={handleAnchorClick}\n />\n\n {activeItem && activeContentType && (\n <BlockingOverlay\n content={activeItem.content}\n contentType={activeContentType}\n onSkip={() => {\n // Skipping declines the hook for this viewing (the item is\n // marked skipped; per the controller the anchor can be\n // taken again on re-approach) and closes the overlay.\n const item = (items ?? []).find(\n (it) => it.getId() === overlayContentId,\n );\n item?.skip();\n setActiveContentId(null);\n void adapter.play();\n }}\n onContentComplete={handleContentComplete}\n onContinue={handleContinueAfterCompletion}\n completing={\n completingId !== null && completingId === overlayContentId\n }\n completingScore={completingScore}\n />\n )}\n </div>\n </ContentErrorBoundary>\n );\n};\n","import {\n ContentInstance,\n ContentTypeRegistry,\n deserialize,\n InteractiveMediaController,\n RenderState,\n SerializedInteractiveMediaDocument,\n VideoAdapter,\n} from \"@interlacejs/core\";\nimport { useEffect, useRef, useState } from \"react\";\n\nexport interface UseInteractiveMediaOptions {\n adapter: VideoAdapter;\n document: SerializedInteractiveMediaDocument;\n registry: ContentTypeRegistry;\n onRenderStateChange?: (state: RenderState) => void;\n onError?: (error: Error) => void;\n}\n\n/**\n * Core React hook for interactive video playback.\n * Manages the controller, rAF loop, and adapter event wiring.\n */\nexport function useInteractiveMedia(options: UseInteractiveMediaOptions) {\n const {\n adapter,\n document: doc,\n registry,\n onRenderStateChange,\n onError,\n } = options;\n\n const controllerRef = useRef<InteractiveMediaController | null>(null);\n const rafRef = useRef<number | null>(null);\n const isPlayingRef = useRef(false);\n const [initialized, setInitialized] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [items, setItems] = useState<ContentInstance[] | null>(null);\n\n // Initialize controller from document\n useEffect(() => {\n try {\n const result = deserialize(doc, registry);\n\n if (result.validationErrors.length > 0) {\n throw new Error(\n `Document validation failed: ${result.validationErrors[0]}`,\n );\n }\n\n const controller = new InteractiveMediaController(\n result.items,\n result.videoDuration,\n );\n controllerRef.current = controller;\n // Expose the deserialized instances so consumers complete items\n // without reaching into the controller's private state.\n setItems(result.items);\n setInitialized(true);\n\n return () => {\n controllerRef.current = null;\n setItems(null);\n };\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n onError?.(error);\n }\n }, [doc, registry, onError]);\n\n // Set up adapter event listeners\n useEffect(() => {\n if (!initialized || !controllerRef.current) return;\n\n const controller = controllerRef.current;\n\n // Wire adapter pause events to controller\n const unsubscribePause = adapter.on(\"pause\", () => {\n isPlayingRef.current = false;\n });\n\n // Wire adapter play events to controller\n const unsubscribePlaying = adapter.on(\"play\", () => {\n isPlayingRef.current = true;\n });\n\n // Wire controller commands to adapter\n const unsubscribeRequestPause = controller.on(\"requestPause\", () => {\n adapter.pause();\n });\n\n const unsubscribeRequestSeek = controller.on(\"requestSeek\", (event) => {\n adapter.seek(event.timeInSeconds);\n });\n\n return () => {\n unsubscribePause();\n unsubscribePlaying();\n unsubscribeRequestPause();\n unsubscribeRequestSeek();\n };\n }, [initialized, adapter]);\n\n // Set up rAF tick loop\n useEffect(() => {\n if (!initialized || !controllerRef.current) return;\n\n const controller = controllerRef.current;\n\n const tick = () => {\n const currentTime = adapter.getCurrentTime();\n const isPlayingForward = isPlayingRef.current;\n\n controller.tick(currentTime, isPlayingForward);\n\n // Update render state\n const renderState = controller.getRenderState(currentTime);\n onRenderStateChange?.(renderState);\n\n rafRef.current = requestAnimationFrame(tick);\n };\n\n rafRef.current = requestAnimationFrame(tick);\n\n return () => {\n if (rafRef.current) {\n cancelAnimationFrame(rafRef.current);\n }\n };\n }, [initialized, adapter, onRenderStateChange]);\n\n return {\n controller: controllerRef.current,\n /** The deserialized content instances backing the controller. */\n items,\n initialized,\n error,\n };\n}\n","import { RenderState } from \"@interlacejs/core\";\nimport React, { useMemo } from \"react\";\nimport { Anchor } from \"./anchor\";\nimport { CompletedTag } from \"./completed-tag\";\n\nexport interface OverlayLayerProps {\n renderState: RenderState;\n items: any[];\n onAnchorClick?: (contentId: string) => void;\n}\n\n/**\n * OverlayLayer - manages 4 fixed z-index layers for overlay content.\n * z-index layers:\n * 1: Anchors (clickable buttons for non-blocking content)\n * 2: Active content area\n * 3: Blocking overlay\n * 4: Completed tags\n */\nexport const OverlayLayer: React.FC<OverlayLayerProps> = ({\n renderState,\n items,\n onAnchorClick,\n}) => {\n // Build a map of items by content ID for easy lookup\n const itemMap = useMemo(() => {\n const map = new Map();\n for (const item of items) {\n map.set(item.content.getId(), item);\n }\n return map;\n }, [items]);\n\n return (\n <div\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n zIndex: 10,\n pointerEvents: \"none\",\n }}\n >\n {/* Layer 1: Anchors (z-index 11) — the layer itself is\n click-transparent so native video controls beneath it stay\n reachable; individual anchors re-enable pointer events. */}\n <div\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n }}\n >\n {renderState.visibleAnchorIds?.map((contentId) => {\n const item = itemMap.get(contentId);\n if (!item) return null;\n\n const hook = item.hook;\n if (hook.type !== \"non-blocking\") return null;\n\n return (\n <Anchor\n key={contentId}\n id={contentId}\n placement={hook.placement}\n title={item.content.getTitle()}\n isOpened={renderState.openedContentIds.includes(contentId)}\n onClick={() => {\n item.content.open();\n onAnchorClick?.(contentId);\n }}\n />\n );\n })}\n </div>\n\n {/* Layer 4: Completed Tags (z-index 14) */}\n <div\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n }}\n >\n {renderState.completedTagIds?.map((contentId) => {\n const item = itemMap.get(contentId);\n if (!item) return null;\n\n const hook = item.hook;\n return (\n <CompletedTag\n key={`completed-${contentId}`}\n id={contentId}\n title={item.content.getTitle()}\n placement={hook.placement}\n />\n );\n })}\n </div>\n </div>\n );\n};\n","/**\n * PreloadScheduler manages content preloading with lead time.\n * Requests preload before content is encountered, with interrupt handling on seek.\n */\nexport class PreloadScheduler {\n private leadTimeMs: number;\n private scheduledPreloads = new Map<string, number>();\n\n constructor(leadTimeMs: number = 2000) {\n this.leadTimeMs = leadTimeMs;\n }\n\n /**\n * Get content IDs that should be preloaded at the current time.\n */\n getPreloadQueue(currentTime: number, items: any[]): string[] {\n const queue: string[] = [];\n const cutoffTime = currentTime + this.leadTimeMs / 1000;\n\n for (const item of items) {\n const contentId = item.content.getId();\n const hook = item.hook;\n\n // Non-blocking hooks: preload if start is within lead time\n if (hook.type === \"non-blocking\") {\n if (hook.start <= cutoffTime && hook.start > currentTime) {\n queue.push(contentId);\n }\n }\n\n // Blocking hooks: preload if timestamp is within lead time\n if (hook.type === \"blocking\") {\n if (hook.timestamp <= cutoffTime && hook.timestamp > currentTime) {\n queue.push(contentId);\n }\n }\n }\n\n return queue;\n }\n\n /**\n * Clear all scheduled preloads (e.g., on seek).\n */\n clear(): void {\n this.scheduledPreloads.clear();\n }\n\n /**\n * Set lead time in milliseconds.\n */\n setLeadTime(ms: number): void {\n this.leadTimeMs = ms;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA8B;;;ACQvB,IAAM,SAAS;AAAA,EACpB,QAAQ;AAAA,EACR,aAAa;A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YAAY,aAAa;AAChE,gBAAM,KAAK,SAAS;AAAA,QACtB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,kBAAkB,MAAM;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,IAAkB;AAC5B,SAAK,aAAa;AAAA,EACpB;AACF;","names":["React","import_react","import_jsx_runtime","import_jsx_runtime","import_react","import_jsx_runtime","React","import_react","import_react","error","import_react","import_jsx_runtime","import_jsx_runtime"]}
@@ -0,0 +1,179 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ContentInstance, ContentType, VideoAdapter, SerializedInteractiveMediaDocument, ContentTypeRegistry, RenderState, InteractiveMediaController } from '@interlacejs/core';
3
+
4
+ interface AnchorProps {
5
+ id: string;
6
+ placement: {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ title: string;
13
+ isOpened?: boolean;
14
+ onClick?: () => void;
15
+ }
16
+ /**
17
+ * Anchor component - a clickable button for non-blocking content.
18
+ * Positioned absolutely with minimum 44px touch target.
19
+ */
20
+ declare const Anchor: React.ForwardRefExoticComponent<AnchorProps & React.RefAttributes<HTMLButtonElement>>;
21
+
22
+ interface BlockingOverlayProps {
23
+ content: ContentInstance;
24
+ /**
25
+ * The content type owning `content` — its `renderPlayback` mounts
26
+ * into the overlay body and its `unmountPlayback` tears it down on
27
+ * close/unmount.
28
+ */
29
+ contentType: ContentType;
30
+ /**
31
+ * Skip affordance for NON-blocking content opened in the overlay: the
32
+ * user declines this hook for the current window visit. The parent
33
+ * wires this to `skipContent` (controller-managed skip memory) and
34
+ * clears the selection; blocking content renders no Skip control.
35
+ */
36
+ onSkip?: () => void;
37
+ /**
38
+ * Called with the reported score when the content's playback
39
+ * completes itself via `callbacks.onComplete` (the parent then
40
+ * completes the item through the controller).
41
+ */
42
+ onContentComplete?: (score?: number) => void;
43
+ /**
44
+ * Completing mode: the content body is swapped for a completion
45
+ * surface (animated check + "Completed" + score) that persists until
46
+ * the user acknowledges it.
47
+ */
48
+ completing?: boolean;
49
+ /** Score reported by the completed content, shown in completing mode. */
50
+ completingScore?: number;
51
+ /**
52
+ * Completion-acknowledgement control (programmatic owner: the player).
53
+ * The completing surface's ONLY exit is the Continue button that calls
54
+ * this — it is not a dismiss affordance; the parent resumes playback and
55
+ * unmounts the overlay.
56
+ */
57
+ onContinue?: () => void;
58
+ }
59
+ /**
60
+ * BlockingOverlay - modal overlay for blocking content.
61
+ * Implements focus trap to keep focus within the overlay.
62
+ * Pauses video while open.
63
+ *
64
+ * Playback mounting (container-identity contract): the content type's
65
+ * `renderPlayback`/`unmountPlayback` receive the same body container
66
+ * element for the overlay's lifetime; React holds the ref stable while
67
+ * the overlay is open.
68
+ */
69
+ declare const BlockingOverlay: React.FC<BlockingOverlayProps>;
70
+
71
+ interface CompletedTagProps {
72
+ id: string;
73
+ title: string;
74
+ placement: {
75
+ x: number;
76
+ y: number;
77
+ width: number;
78
+ height: number;
79
+ };
80
+ }
81
+ /**
82
+ * CompletedTag - visual indicator showing that content has been completed.
83
+ * Displayed as a badge overlay on top of the video.
84
+ */
85
+ declare const CompletedTag: React.FC<CompletedTagProps>;
86
+
87
+ interface ContentErrorBoundaryProps {
88
+ children: ReactNode;
89
+ onError?: (error: Error) => void;
90
+ fallback?: ReactNode;
91
+ }
92
+ interface State {
93
+ hasError: boolean;
94
+ error: Error | null;
95
+ }
96
+ /**
97
+ * Error boundary for content rendering failures.
98
+ * Catches render errors from content components and displays fallback UI.
99
+ */
100
+ declare class ContentErrorBoundary extends React.Component<ContentErrorBoundaryProps, State> {
101
+ constructor(props: ContentErrorBoundaryProps);
102
+ static getDerivedStateFromError(error: Error): State;
103
+ componentDidCatch(error: Error): void;
104
+ render(): string | number | bigint | boolean | React.JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null | undefined;
105
+ }
106
+
107
+ interface InteractiveVideoPlayerProps {
108
+ adapter: VideoAdapter;
109
+ document: SerializedInteractiveMediaDocument;
110
+ registry: ContentTypeRegistry;
111
+ onError?: (error: Error) => void;
112
+ }
113
+ /**
114
+ * InteractiveVideoPlayer - top-level React component for interactive video playback.
115
+ * Integrates:
116
+ * - useInteractiveMedia hook for runtime state management
117
+ * - OverlayLayer for anchor and completed tag rendering
118
+ * - BlockingOverlay for interactive content modals
119
+ * - ContentErrorBoundary for error handling
120
+ */
121
+ declare const InteractiveVideoPlayer: React.FC<InteractiveVideoPlayerProps>;
122
+
123
+ interface OverlayLayerProps {
124
+ renderState: RenderState;
125
+ items: any[];
126
+ onAnchorClick?: (contentId: string) => void;
127
+ }
128
+ /**
129
+ * OverlayLayer - manages 4 fixed z-index layers for overlay content.
130
+ * z-index layers:
131
+ * 1: Anchors (clickable buttons for non-blocking content)
132
+ * 2: Active content area
133
+ * 3: Blocking overlay
134
+ * 4: Completed tags
135
+ */
136
+ declare const OverlayLayer: React.FC<OverlayLayerProps>;
137
+
138
+ interface UseInteractiveMediaOptions {
139
+ adapter: VideoAdapter;
140
+ document: SerializedInteractiveMediaDocument;
141
+ registry: ContentTypeRegistry;
142
+ onRenderStateChange?: (state: RenderState) => void;
143
+ onError?: (error: Error) => void;
144
+ }
145
+ /**
146
+ * Core React hook for interactive video playback.
147
+ * Manages the controller, rAF loop, and adapter event wiring.
148
+ */
149
+ declare function useInteractiveMedia(options: UseInteractiveMediaOptions): {
150
+ controller: InteractiveMediaController | null;
151
+ /** The deserialized content instances backing the controller. */
152
+ items: ContentInstance<unknown>[] | null;
153
+ initialized: boolean;
154
+ error: Error | null;
155
+ };
156
+
157
+ /**
158
+ * PreloadScheduler manages content preloading with lead time.
159
+ * Requests preload before content is encountered, with interrupt handling on seek.
160
+ */
161
+ declare class PreloadScheduler {
162
+ private leadTimeMs;
163
+ private scheduledPreloads;
164
+ constructor(leadTimeMs?: number);
165
+ /**
166
+ * Get content IDs that should be preloaded at the current time.
167
+ */
168
+ getPreloadQueue(currentTime: number, items: any[]): string[];
169
+ /**
170
+ * Clear all scheduled preloads (e.g., on seek).
171
+ */
172
+ clear(): void;
173
+ /**
174
+ * Set lead time in milliseconds.
175
+ */
176
+ setLeadTime(ms: number): void;
177
+ }
178
+
179
+ export { Anchor, type AnchorProps, BlockingOverlay, type BlockingOverlayProps, CompletedTag, type CompletedTagProps, ContentErrorBoundary, type ContentErrorBoundaryProps, InteractiveVideoPlayer, type InteractiveVideoPlayerProps, OverlayLayer, type OverlayLayerProps, PreloadScheduler, type UseInteractiveMediaOptions, useInteractiveMedia };
@@ -0,0 +1,179 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ContentInstance, ContentType, VideoAdapter, SerializedInteractiveMediaDocument, ContentTypeRegistry, RenderState, InteractiveMediaController } from '@interlacejs/core';
3
+
4
+ interface AnchorProps {
5
+ id: string;
6
+ placement: {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ title: string;
13
+ isOpened?: boolean;
14
+ onClick?: () => void;
15
+ }
16
+ /**
17
+ * Anchor component - a clickable button for non-blocking content.
18
+ * Positioned absolutely with minimum 44px touch target.
19
+ */
20
+ declare const Anchor: React.ForwardRefExoticComponent<AnchorProps & React.RefAttributes<HTMLButtonElement>>;
21
+
22
+ interface BlockingOverlayProps {
23
+ content: ContentInstance;
24
+ /**
25
+ * The content type owning `content` — its `renderPlayback` mounts
26
+ * into the overlay body and its `unmountPlayback` tears it down on
27
+ * close/unmount.
28
+ */
29
+ contentType: ContentType;
30
+ /**
31
+ * Skip affordance for NON-blocking content opened in the overlay: the
32
+ * user declines this hook for the current window visit. The parent
33
+ * wires this to `skipContent` (controller-managed skip memory) and
34
+ * clears the selection; blocking content renders no Skip control.
35
+ */
36
+ onSkip?: () => void;
37
+ /**
38
+ * Called with the reported score when the content's playback
39
+ * completes itself via `callbacks.onComplete` (the parent then
40
+ * completes the item through the controller).
41
+ */
42
+ onContentComplete?: (score?: number) => void;
43
+ /**
44
+ * Completing mode: the content body is swapped for a completion
45
+ * surface (animated check + "Completed" + score) that persists until
46
+ * the user acknowledges it.
47
+ */
48
+ completing?: boolean;
49
+ /** Score reported by the completed content, shown in completing mode. */
50
+ completingScore?: number;
51
+ /**
52
+ * Completion-acknowledgement control (programmatic owner: the player).
53
+ * The completing surface's ONLY exit is the Continue button that calls
54
+ * this — it is not a dismiss affordance; the parent resumes playback and
55
+ * unmounts the overlay.
56
+ */
57
+ onContinue?: () => void;
58
+ }
59
+ /**
60
+ * BlockingOverlay - modal overlay for blocking content.
61
+ * Implements focus trap to keep focus within the overlay.
62
+ * Pauses video while open.
63
+ *
64
+ * Playback mounting (container-identity contract): the content type's
65
+ * `renderPlayback`/`unmountPlayback` receive the same body container
66
+ * element for the overlay's lifetime; React holds the ref stable while
67
+ * the overlay is open.
68
+ */
69
+ declare const BlockingOverlay: React.FC<BlockingOverlayProps>;
70
+
71
+ interface CompletedTagProps {
72
+ id: string;
73
+ title: string;
74
+ placement: {
75
+ x: number;
76
+ y: number;
77
+ width: number;
78
+ height: number;
79
+ };
80
+ }
81
+ /**
82
+ * CompletedTag - visual indicator showing that content has been completed.
83
+ * Displayed as a badge overlay on top of the video.
84
+ */
85
+ declare const CompletedTag: React.FC<CompletedTagProps>;
86
+
87
+ interface ContentErrorBoundaryProps {
88
+ children: ReactNode;
89
+ onError?: (error: Error) => void;
90
+ fallback?: ReactNode;
91
+ }
92
+ interface State {
93
+ hasError: boolean;
94
+ error: Error | null;
95
+ }
96
+ /**
97
+ * Error boundary for content rendering failures.
98
+ * Catches render errors from content components and displays fallback UI.
99
+ */
100
+ declare class ContentErrorBoundary extends React.Component<ContentErrorBoundaryProps, State> {
101
+ constructor(props: ContentErrorBoundaryProps);
102
+ static getDerivedStateFromError(error: Error): State;
103
+ componentDidCatch(error: Error): void;
104
+ render(): string | number | bigint | boolean | React.JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null | undefined;
105
+ }
106
+
107
+ interface InteractiveVideoPlayerProps {
108
+ adapter: VideoAdapter;
109
+ document: SerializedInteractiveMediaDocument;
110
+ registry: ContentTypeRegistry;
111
+ onError?: (error: Error) => void;
112
+ }
113
+ /**
114
+ * InteractiveVideoPlayer - top-level React component for interactive video playback.
115
+ * Integrates:
116
+ * - useInteractiveMedia hook for runtime state management
117
+ * - OverlayLayer for anchor and completed tag rendering
118
+ * - BlockingOverlay for interactive content modals
119
+ * - ContentErrorBoundary for error handling
120
+ */
121
+ declare const InteractiveVideoPlayer: React.FC<InteractiveVideoPlayerProps>;
122
+
123
+ interface OverlayLayerProps {
124
+ renderState: RenderState;
125
+ items: any[];
126
+ onAnchorClick?: (contentId: string) => void;
127
+ }
128
+ /**
129
+ * OverlayLayer - manages 4 fixed z-index layers for overlay content.
130
+ * z-index layers:
131
+ * 1: Anchors (clickable buttons for non-blocking content)
132
+ * 2: Active content area
133
+ * 3: Blocking overlay
134
+ * 4: Completed tags
135
+ */
136
+ declare const OverlayLayer: React.FC<OverlayLayerProps>;
137
+
138
+ interface UseInteractiveMediaOptions {
139
+ adapter: VideoAdapter;
140
+ document: SerializedInteractiveMediaDocument;
141
+ registry: ContentTypeRegistry;
142
+ onRenderStateChange?: (state: RenderState) => void;
143
+ onError?: (error: Error) => void;
144
+ }
145
+ /**
146
+ * Core React hook for interactive video playback.
147
+ * Manages the controller, rAF loop, and adapter event wiring.
148
+ */
149
+ declare function useInteractiveMedia(options: UseInteractiveMediaOptions): {
150
+ controller: InteractiveMediaController | null;
151
+ /** The deserialized content instances backing the controller. */
152
+ items: ContentInstance<unknown>[] | null;
153
+ initialized: boolean;
154
+ error: Error | null;
155
+ };
156
+
157
+ /**
158
+ * PreloadScheduler manages content preloading with lead time.
159
+ * Requests preload before content is encountered, with interrupt handling on seek.
160
+ */
161
+ declare class PreloadScheduler {
162
+ private leadTimeMs;
163
+ private scheduledPreloads;
164
+ constructor(leadTimeMs?: number);
165
+ /**
166
+ * Get content IDs that should be preloaded at the current time.
167
+ */
168
+ getPreloadQueue(currentTime: number, items: any[]): string[];
169
+ /**
170
+ * Clear all scheduled preloads (e.g., on seek).
171
+ */
172
+ clear(): void;
173
+ /**
174
+ * Set lead time in milliseconds.
175
+ */
176
+ setLeadTime(ms: number): void;
177
+ }
178
+
179
+ export { Anchor, type AnchorProps, BlockingOverlay, type BlockingOverlayProps, CompletedTag, type CompletedTagProps, ContentErrorBoundary, type ContentErrorBoundaryProps, InteractiveVideoPlayer, type InteractiveVideoPlayerProps, OverlayLayer, type OverlayLayerProps, PreloadScheduler, type UseInteractiveMediaOptions, useInteractiveMedia };