@bendyline/squisq-react 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +563 -0
- package/dist/index.js +3180 -0
- package/dist/index.js.map +1 -0
- package/dist/squisq-player.css +2 -0
- package/dist/squisq-player.css.map +1 -0
- package/dist/squisq-player.global.js +6 -0
- package/dist/squisq-player.global.js.map +1 -0
- package/dist/standalone-source.d.ts +2 -0
- package/dist/standalone-source.js +2 -0
- package/package.json +69 -0
- package/src/BlockRenderer.tsx +146 -0
- package/src/CaptionOverlay.tsx +86 -0
- package/src/DocControlsBottom.tsx +103 -0
- package/src/DocControlsOverlay.tsx +178 -0
- package/src/DocControlsSidebar.tsx +107 -0
- package/src/DocControlsSlideshow.tsx +132 -0
- package/src/DocPlayer.tsx +1005 -0
- package/src/DocPlayerWithSidebar.tsx +138 -0
- package/src/DocProgressBar.tsx +200 -0
- package/src/LinearDocView.tsx +313 -0
- package/src/MarkdownRenderer.tsx +360 -0
- package/src/__tests__/BlockRenderer.test.tsx +105 -0
- package/src/__tests__/DocControlsSlideshow.test.tsx +127 -0
- package/src/__tests__/LinearDocView.test.tsx +180 -0
- package/src/__tests__/MarkdownRenderer.test.tsx +234 -0
- package/src/__tests__/exports.test.ts +55 -0
- package/src/hooks/AudioProvider.ts +114 -0
- package/src/hooks/MediaContext.tsx +81 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useAudioSync.ts +390 -0
- package/src/hooks/useDocPlayback.ts +251 -0
- package/src/hooks/useViewportOrientation.ts +117 -0
- package/src/index.ts +46 -0
- package/src/layers/ImageLayer.tsx +182 -0
- package/src/layers/MapLayer.tsx +184 -0
- package/src/layers/ShapeLayer.tsx +107 -0
- package/src/layers/TextLayer.tsx +197 -0
- package/src/layers/VideoLayer.tsx +150 -0
- package/src/layers/index.ts +5 -0
- package/src/standalone-entry.tsx +228 -0
- package/src/styles/doc-animations.css +458 -0
- package/src/types.ts +152 -0
- package/src/utils/animationUtils.ts +13 -0
- package/src/utils/layerUtils.ts +42 -0
- package/src/utils/mapTileUtils.ts +375 -0
|
@@ -0,0 +1,1005 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DocPlayer Component
|
|
3
|
+
*
|
|
4
|
+
* Main component for playing visual stories. Combines audio playback
|
|
5
|
+
* with synchronized SVG block animations. Supports both interactive
|
|
6
|
+
* browser playback and headless rendering for video export.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Audio synchronization with multiple MP3 segments
|
|
10
|
+
* - Block transitions (fade, dissolve, slide)
|
|
11
|
+
* - Playback controls (play/pause, seek, next/prev)
|
|
12
|
+
* - Progress display
|
|
13
|
+
* - Render mode for video capture (via window.seekTo)
|
|
14
|
+
* - Pluggable audio provider for different environments (browser, EFB)
|
|
15
|
+
* - Multiple control layouts: overlay (default), sidebar, bottom
|
|
16
|
+
*
|
|
17
|
+
* Related Files:
|
|
18
|
+
* - DocControlsOverlay.tsx -- Default overlay controls
|
|
19
|
+
* - DocProgressBar.tsx -- Extracted progress bar
|
|
20
|
+
* - DocControlsSidebar.tsx -- Vertical sidebar controls
|
|
21
|
+
* - DocPlayerWithSidebar.tsx -- Wrapper for sidebar layout
|
|
22
|
+
* - types.ts -- Shared control types
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { Fragment, useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
26
|
+
import type { Doc, Block, TextLayer, StartBlockConfig, DocBlock } from '@bendyline/squisq/schemas';
|
|
27
|
+
import { isTemplateBlock, getCaptionAtTime } from '@bendyline/squisq/schemas';
|
|
28
|
+
import type { Theme } from '@bendyline/squisq/schemas';
|
|
29
|
+
import { BlockRenderer } from './BlockRenderer';
|
|
30
|
+
import { CaptionOverlay } from './CaptionOverlay';
|
|
31
|
+
import { useAudioSync } from './hooks/useAudioSync';
|
|
32
|
+
import { useDocPlayback } from './hooks/useDocPlayback';
|
|
33
|
+
import { useViewportOrientation } from './hooks/useViewportOrientation';
|
|
34
|
+
import type { AudioProvider } from './hooks/AudioProvider';
|
|
35
|
+
import {
|
|
36
|
+
expandCoverBlock,
|
|
37
|
+
createTemplateContext,
|
|
38
|
+
DEFAULT_THEME,
|
|
39
|
+
VIEWPORT_PRESETS,
|
|
40
|
+
type ViewportConfig,
|
|
41
|
+
} from '@bendyline/squisq/doc';
|
|
42
|
+
import { DocControlsOverlay } from './DocControlsOverlay';
|
|
43
|
+
import { DocControlsSlideshow } from './DocControlsSlideshow';
|
|
44
|
+
import { DocProgressBar } from './DocProgressBar';
|
|
45
|
+
import { LinearDocView } from './LinearDocView';
|
|
46
|
+
import type {
|
|
47
|
+
PlaybackState,
|
|
48
|
+
PlaybackActions,
|
|
49
|
+
BlockMarker,
|
|
50
|
+
DisplayMode,
|
|
51
|
+
SlideNavActions,
|
|
52
|
+
SquisqWindow,
|
|
53
|
+
} from './types';
|
|
54
|
+
|
|
55
|
+
const SMALL_WORDS = new Set([
|
|
56
|
+
'a',
|
|
57
|
+
'an',
|
|
58
|
+
'the',
|
|
59
|
+
'and',
|
|
60
|
+
'but',
|
|
61
|
+
'or',
|
|
62
|
+
'for',
|
|
63
|
+
'nor',
|
|
64
|
+
'on',
|
|
65
|
+
'at',
|
|
66
|
+
'to',
|
|
67
|
+
'in',
|
|
68
|
+
'of',
|
|
69
|
+
'by',
|
|
70
|
+
'is',
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Build a map of audio segment index -> display-friendly title.
|
|
75
|
+
* Uses sectionHeader blocks to find real titles, with fallbacks
|
|
76
|
+
* for "intro" and slug-based names.
|
|
77
|
+
*/
|
|
78
|
+
function buildSegmentTitleMap(script: Doc): Map<number, string> {
|
|
79
|
+
const map = new Map<number, string>();
|
|
80
|
+
|
|
81
|
+
// Scan blocks for sectionHeader templates which carry the real title
|
|
82
|
+
for (const block of script.blocks as DocBlock[]) {
|
|
83
|
+
if (isTemplateBlock(block) && block.template === 'sectionHeader' && 'title' in block) {
|
|
84
|
+
const segIdx = block.audioSegment;
|
|
85
|
+
if (!map.has(segIdx)) {
|
|
86
|
+
map.set(segIdx, (block as { title: string }).title);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Fill in any segments that weren't covered by sectionHeader blocks
|
|
92
|
+
for (let i = 0; i < script.audio.segments.length; i++) {
|
|
93
|
+
if (!map.has(i)) {
|
|
94
|
+
const name = script.audio.segments[i].name;
|
|
95
|
+
if (name === 'intro' || name.includes('intro')) {
|
|
96
|
+
map.set(i, 'Introduction');
|
|
97
|
+
} else if (name === 'flight-context' || name.includes('flight-context')) {
|
|
98
|
+
map.set(i, 'Flight Context');
|
|
99
|
+
} else {
|
|
100
|
+
// Title-case the slug: "hands-on-history" -> "Hands on History"
|
|
101
|
+
const words = name.split('-');
|
|
102
|
+
const titled = words
|
|
103
|
+
.map((w, idx) =>
|
|
104
|
+
idx === 0 || !SMALL_WORDS.has(w) ? w.charAt(0).toUpperCase() + w.slice(1) : w,
|
|
105
|
+
)
|
|
106
|
+
.join(' ');
|
|
107
|
+
map.set(i, titled);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return map;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface DocPlayerProps {
|
|
116
|
+
/** Doc script to play */
|
|
117
|
+
script: Doc;
|
|
118
|
+
/** Base path for resolving media URLs */
|
|
119
|
+
basePath: string;
|
|
120
|
+
/** Render mode for video capture (hides controls, exposes seekTo) */
|
|
121
|
+
renderMode?: boolean;
|
|
122
|
+
/** Auto-play when loaded */
|
|
123
|
+
autoPlay?: boolean;
|
|
124
|
+
/** Callback when playback ends */
|
|
125
|
+
onEnded?: () => void;
|
|
126
|
+
/** Callback for time updates */
|
|
127
|
+
onTimeUpdate?: (time: number) => void;
|
|
128
|
+
/** Optional audio provider (if not provided, uses default HTML5 audio) */
|
|
129
|
+
audioProvider?: AudioProvider;
|
|
130
|
+
/** Show built-in controls (default: true). Set to false for custom controls. */
|
|
131
|
+
showControls?: boolean;
|
|
132
|
+
/** Show only the progress bar/scrubber at bottom (no other controls).
|
|
133
|
+
* Only takes effect when showControls is false. Allows external controls
|
|
134
|
+
* while keeping the scrubber in-video. */
|
|
135
|
+
showScrubber?: boolean;
|
|
136
|
+
/** Mute audio (default: false) */
|
|
137
|
+
muted?: boolean;
|
|
138
|
+
/** Enable captions (default: true) */
|
|
139
|
+
captionsEnabled?: boolean;
|
|
140
|
+
/** Callback when captions enabled state is toggled */
|
|
141
|
+
onCaptionsToggle?: (enabled: boolean) => void;
|
|
142
|
+
/** Callback for playback state changes (for external controls) */
|
|
143
|
+
onPlaybackStateChange?: (state: PlaybackState) => void;
|
|
144
|
+
/** Callback when playback controls are ready (for external controls) */
|
|
145
|
+
onControlsReady?: (
|
|
146
|
+
controls: PlaybackActions & {
|
|
147
|
+
play: () => void;
|
|
148
|
+
pause: () => void;
|
|
149
|
+
},
|
|
150
|
+
) => void;
|
|
151
|
+
/** Whether the player is currently in fullscreen mode */
|
|
152
|
+
isFullscreen?: boolean;
|
|
153
|
+
/** Callback to toggle fullscreen mode */
|
|
154
|
+
onFullscreenToggle?: () => void;
|
|
155
|
+
/** Callback when block markers are computed (for external progress bars) */
|
|
156
|
+
onBlockMarkers?: (markers: BlockMarker[]) => void;
|
|
157
|
+
/** Force a specific viewport preset, bypassing window-based orientation detection.
|
|
158
|
+
* Used when the player is rendered in a constrained container (e.g., map overlay panel)
|
|
159
|
+
* whose shape differs from the window's. */
|
|
160
|
+
forceViewport?: ViewportConfig;
|
|
161
|
+
/** Theme to use for rendering (default: DEFAULT_THEME from the theme library) */
|
|
162
|
+
theme?: Theme;
|
|
163
|
+
/**
|
|
164
|
+
* Display mode for the player.
|
|
165
|
+
* - `'video'` (default) — Traditional video playback with play/pause, scrub bar, auto-advance.
|
|
166
|
+
* - `'slideshow'` — PowerPoint-style with prev/next buttons. Blocks are static slides
|
|
167
|
+
* that only change on user click. No auto-advance, no scrub bar.
|
|
168
|
+
* - `'linear'` — Long-scrolling document view. Renders markdown as readable HTML with
|
|
169
|
+
* template-annotated sections as inline SVG cards. No audio, no timeline.
|
|
170
|
+
*/
|
|
171
|
+
displayMode?: DisplayMode;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function DocPlayer({
|
|
175
|
+
script,
|
|
176
|
+
basePath,
|
|
177
|
+
renderMode = false,
|
|
178
|
+
autoPlay = false,
|
|
179
|
+
onEnded,
|
|
180
|
+
onTimeUpdate,
|
|
181
|
+
audioProvider: externalAudioProvider,
|
|
182
|
+
showControls = true,
|
|
183
|
+
showScrubber = false,
|
|
184
|
+
muted = false,
|
|
185
|
+
captionsEnabled: captionsEnabledProp,
|
|
186
|
+
onCaptionsToggle,
|
|
187
|
+
onPlaybackStateChange,
|
|
188
|
+
onControlsReady,
|
|
189
|
+
isFullscreen = false,
|
|
190
|
+
onFullscreenToggle,
|
|
191
|
+
onBlockMarkers,
|
|
192
|
+
forceViewport,
|
|
193
|
+
displayMode = 'video',
|
|
194
|
+
theme,
|
|
195
|
+
}: DocPlayerProps) {
|
|
196
|
+
const isSlideshowMode = displayMode === 'slideshow';
|
|
197
|
+
const isLinearMode = displayMode === 'linear';
|
|
198
|
+
const audioRef = useRef<HTMLAudioElement>(null);
|
|
199
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
200
|
+
|
|
201
|
+
// Tap-to-toggle play/pause feedback animation
|
|
202
|
+
const [tapFeedback, setTapFeedback] = useState<'play' | 'pause' | null>(null);
|
|
203
|
+
const tapFeedbackTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
204
|
+
|
|
205
|
+
// Detect viewport orientation for responsive docs
|
|
206
|
+
// forceViewport takes precedence (used by render mode with explicit viewport and constrained panels)
|
|
207
|
+
// In render mode without forceViewport, default to landscape for backward compatibility
|
|
208
|
+
const { viewport, orientation } = useViewportOrientation();
|
|
209
|
+
const activeViewport = forceViewport || (renderMode ? VIEWPORT_PRESETS.landscape : viewport);
|
|
210
|
+
|
|
211
|
+
// Check for debug mode via URL parameter
|
|
212
|
+
const isDebugMode = useMemo(() => {
|
|
213
|
+
if (typeof window === 'undefined') return false;
|
|
214
|
+
const params = new URLSearchParams(window.location.search);
|
|
215
|
+
return params.get('debug') === 'true';
|
|
216
|
+
}, []);
|
|
217
|
+
|
|
218
|
+
// Use internal HTML5 audio sync if no external provider is given
|
|
219
|
+
const internalAudio = useAudioSync(audioRef, script.audio, basePath);
|
|
220
|
+
|
|
221
|
+
// Use external provider if provided, otherwise fall back to internal
|
|
222
|
+
const audio = externalAudioProvider || internalAudio;
|
|
223
|
+
|
|
224
|
+
// Destructure for convenience
|
|
225
|
+
const {
|
|
226
|
+
currentTime,
|
|
227
|
+
isPlaying,
|
|
228
|
+
currentSegment,
|
|
229
|
+
totalDuration,
|
|
230
|
+
isEnded,
|
|
231
|
+
isReady: isAudioReady,
|
|
232
|
+
isAvailable,
|
|
233
|
+
unavailableMessage,
|
|
234
|
+
play,
|
|
235
|
+
pause,
|
|
236
|
+
toggle,
|
|
237
|
+
seekTo,
|
|
238
|
+
skipToSegment: _skipToSegment,
|
|
239
|
+
restart,
|
|
240
|
+
} = audio;
|
|
241
|
+
|
|
242
|
+
// Refs for frequently-changing values used in the keyboard handler,
|
|
243
|
+
// so the handler callback doesn't need to be recreated every frame.
|
|
244
|
+
const currentTimeRef = useRef(currentTime);
|
|
245
|
+
currentTimeRef.current = currentTime;
|
|
246
|
+
const totalDurationRef = useRef(totalDuration);
|
|
247
|
+
totalDurationRef.current = totalDuration;
|
|
248
|
+
const expandedBlocksLenRef = useRef(0);
|
|
249
|
+
|
|
250
|
+
// Tap the player surface to toggle play/pause (disabled in slideshow and linear mode)
|
|
251
|
+
const handleContainerClick = useCallback(
|
|
252
|
+
(e: React.MouseEvent) => {
|
|
253
|
+
if (renderMode || isSlideshowMode || isLinearMode) return;
|
|
254
|
+
const target = e.target as HTMLElement;
|
|
255
|
+
// Don't toggle if user clicked a control element
|
|
256
|
+
if (
|
|
257
|
+
target.closest(
|
|
258
|
+
'button, a, input, .doc-player__controls, .doc-player__scrubber, .doc-controls-sidebar, .doc-controls-slideshow',
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
return;
|
|
262
|
+
toggle();
|
|
263
|
+
// Show visual feedback (show the state we're transitioning TO)
|
|
264
|
+
const nextState = isPlaying ? 'play' : 'pause';
|
|
265
|
+
setTapFeedback(nextState);
|
|
266
|
+
clearTimeout(tapFeedbackTimer.current);
|
|
267
|
+
tapFeedbackTimer.current = setTimeout(() => setTapFeedback(null), 600);
|
|
268
|
+
},
|
|
269
|
+
[renderMode, toggle, isPlaying, isSlideshowMode, isLinearMode],
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
// Doc playback hook - pass viewport for responsive template expansion
|
|
273
|
+
const {
|
|
274
|
+
currentBlock,
|
|
275
|
+
currentBlockIndex,
|
|
276
|
+
previousBlock,
|
|
277
|
+
isEntering,
|
|
278
|
+
isExiting,
|
|
279
|
+
blockTime,
|
|
280
|
+
blockProgress: _blockProgress,
|
|
281
|
+
docProgress,
|
|
282
|
+
nextBlock: _nextBlock,
|
|
283
|
+
prevBlock: _prevBlock,
|
|
284
|
+
blocks: expandedBlocks,
|
|
285
|
+
} = useDocPlayback(script, currentTime, activeViewport, renderMode, theme);
|
|
286
|
+
|
|
287
|
+
// Expand cover block (startBlock) if present - uses active viewport
|
|
288
|
+
const coverBlock = useMemo((): Block | null => {
|
|
289
|
+
const startBlockConfig = script.startBlock as StartBlockConfig | undefined;
|
|
290
|
+
if (!startBlockConfig) return null;
|
|
291
|
+
|
|
292
|
+
const context = createTemplateContext(theme ?? DEFAULT_THEME, 0, 1, activeViewport);
|
|
293
|
+
const layers = expandCoverBlock(startBlockConfig, context);
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
id: 'cover-block',
|
|
297
|
+
startTime: -1, // Not part of timeline
|
|
298
|
+
duration: 0, // Static
|
|
299
|
+
audioSegment: -1,
|
|
300
|
+
layers,
|
|
301
|
+
};
|
|
302
|
+
}, [script.startBlock, activeViewport, theme]);
|
|
303
|
+
|
|
304
|
+
// Render-mode cover block control: allows Playwright to force-show the cover block
|
|
305
|
+
const [coverForced, setCoverForced] = useState(false);
|
|
306
|
+
|
|
307
|
+
// Grace period: keep cover block visible for 3s after first play press
|
|
308
|
+
const [coverGraceActive, setCoverGraceActive] = useState(false);
|
|
309
|
+
const coverGraceTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
310
|
+
const coverWasShowing = useRef(false);
|
|
311
|
+
|
|
312
|
+
// Track when cover is showing at rest (before play)
|
|
313
|
+
const atRest = !!(coverBlock && !isPlaying && currentTime === 0 && !renderMode && !autoPlay);
|
|
314
|
+
if (atRest) coverWasShowing.current = true;
|
|
315
|
+
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
if (isPlaying && coverWasShowing.current && coverBlock && !renderMode) {
|
|
318
|
+
coverWasShowing.current = false;
|
|
319
|
+
setCoverGraceActive(true);
|
|
320
|
+
coverGraceTimer.current = setTimeout(() => setCoverGraceActive(false), 3000);
|
|
321
|
+
return () => clearTimeout(coverGraceTimer.current);
|
|
322
|
+
}
|
|
323
|
+
}, [isPlaying, coverBlock, renderMode]);
|
|
324
|
+
|
|
325
|
+
// Determine if we should show the cover block
|
|
326
|
+
// Show cover when: has cover block, not playing, at time 0, not in render mode
|
|
327
|
+
// OR during the grace period after first play, OR when coverForced (render mode)
|
|
328
|
+
// Cover block is suppressed in slideshow and linear mode — start directly on content
|
|
329
|
+
const showCoverBlock =
|
|
330
|
+
!isSlideshowMode &&
|
|
331
|
+
!isLinearMode &&
|
|
332
|
+
coverBlock &&
|
|
333
|
+
(coverForced ||
|
|
334
|
+
coverGraceActive ||
|
|
335
|
+
(!isPlaying && currentTime === 0 && !renderMode && !autoPlay));
|
|
336
|
+
|
|
337
|
+
// Auto-play if enabled (wait for audio to be ready)
|
|
338
|
+
// Use a ref to track if we've already auto-played to avoid repeating on every render
|
|
339
|
+
const hasAutoPlayed = useRef(false);
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
if (isAudioReady && autoPlay && !hasAutoPlayed.current) {
|
|
342
|
+
hasAutoPlayed.current = true;
|
|
343
|
+
play();
|
|
344
|
+
}
|
|
345
|
+
}, [isAudioReady, autoPlay, play]);
|
|
346
|
+
|
|
347
|
+
// Callback for time updates
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
onTimeUpdate?.(currentTime);
|
|
350
|
+
}, [currentTime, onTimeUpdate]);
|
|
351
|
+
|
|
352
|
+
// Callback for ended
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
if (isEnded) {
|
|
355
|
+
onEnded?.();
|
|
356
|
+
}
|
|
357
|
+
}, [isEnded, onEnded]);
|
|
358
|
+
|
|
359
|
+
// Expose seekTo globally for render mode (Playwright) and debug mode (testing)
|
|
360
|
+
useEffect(() => {
|
|
361
|
+
if ((renderMode || isDebugMode) && typeof window !== 'undefined') {
|
|
362
|
+
const w = window as SquisqWindow;
|
|
363
|
+
w.seekTo = (time: number) => {
|
|
364
|
+
seekTo(time);
|
|
365
|
+
// After React renders the correct block, advance CSS animations
|
|
366
|
+
// (Ken Burns, transitions) to match the doc timeline position.
|
|
367
|
+
// Without this, animations restart from zero on each seekTo because
|
|
368
|
+
// they run on the browser's real clock, not doc time.
|
|
369
|
+
return new Promise<void>((resolve) => {
|
|
370
|
+
requestAnimationFrame(() => {
|
|
371
|
+
// Find the current block's start time
|
|
372
|
+
let blockStartTime = 0;
|
|
373
|
+
for (let i = expandedBlocks.length - 1; i >= 0; i--) {
|
|
374
|
+
if (time >= expandedBlocks[i].startTime) {
|
|
375
|
+
blockStartTime = expandedBlocks[i].startTime;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const elapsedMs = (time - blockStartTime) * 1000;
|
|
380
|
+
|
|
381
|
+
// Set all CSS animations to the correct timeline position
|
|
382
|
+
document.getAnimations().forEach((anim) => {
|
|
383
|
+
const target = (anim.effect as KeyframeEffect)?.target as Element | null;
|
|
384
|
+
if (!target) return;
|
|
385
|
+
|
|
386
|
+
// Animations on the active block: use current block elapsed time
|
|
387
|
+
if (target.closest('.doc-player__block--active')) {
|
|
388
|
+
anim.currentTime = Math.max(0, elapsedMs);
|
|
389
|
+
}
|
|
390
|
+
// Animations on the exiting block (during crossfade): use current
|
|
391
|
+
// block elapsed for transition animations, keep Ken Burns at their
|
|
392
|
+
// natural position based on when that block started
|
|
393
|
+
// eslint-disable-next-line sonarjs/no-duplicated-branches
|
|
394
|
+
else if (target.closest('.doc-player__block--previous')) {
|
|
395
|
+
anim.currentTime = Math.max(0, elapsedMs);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// Seek <video> elements in the active block to the correct clip position.
|
|
400
|
+
// Each <video> carries data-clip-start/data-clip-end attributes set by
|
|
401
|
+
// VideoLayer.tsx; we calculate targetTime = clipStart + blockElapsed.
|
|
402
|
+
const blockElapsed = time - blockStartTime;
|
|
403
|
+
const videoSeekPromises: Promise<void>[] = [];
|
|
404
|
+
const activeBlockEl = document.querySelector('.doc-player__block--active');
|
|
405
|
+
if (activeBlockEl) {
|
|
406
|
+
const videos = activeBlockEl.querySelectorAll('video[data-clip-start]');
|
|
407
|
+
videos.forEach((el) => {
|
|
408
|
+
const video = el as HTMLVideoElement;
|
|
409
|
+
const clipStart = parseFloat(video.dataset.clipStart || '0');
|
|
410
|
+
const clipEnd = parseFloat(video.dataset.clipEnd || '0');
|
|
411
|
+
const targetTime = Math.min(clipStart + Math.max(0, blockElapsed), clipEnd);
|
|
412
|
+
|
|
413
|
+
video.pause();
|
|
414
|
+
video.currentTime = targetTime;
|
|
415
|
+
|
|
416
|
+
videoSeekPromises.push(
|
|
417
|
+
new Promise<void>((r) => {
|
|
418
|
+
if (Math.abs(video.currentTime - targetTime) < 0.1) {
|
|
419
|
+
r();
|
|
420
|
+
} else {
|
|
421
|
+
video.addEventListener('seeked', () => r(), { once: true });
|
|
422
|
+
setTimeout(r, 200); // Fallback if seeked never fires
|
|
423
|
+
}
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Wait for video seeks + one more frame for the browser to render
|
|
430
|
+
Promise.all(videoSeekPromises).then(() => {
|
|
431
|
+
requestAnimationFrame(() => resolve());
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
w.getDuration = () => totalDuration;
|
|
437
|
+
// Expose block metadata for testing -- allows tests to find specific templates
|
|
438
|
+
w.getBlocks = () =>
|
|
439
|
+
expandedBlocks.map((s: Block) => ({
|
|
440
|
+
id: s.id,
|
|
441
|
+
template: (s as DocBlock).template ?? 'raw',
|
|
442
|
+
startTime: s.startTime,
|
|
443
|
+
duration: s.duration,
|
|
444
|
+
}));
|
|
445
|
+
// Audio segment info for video production -- returns the actual files in composition order
|
|
446
|
+
w.getAudioSegments = () =>
|
|
447
|
+
script.audio.segments.map((seg) => ({
|
|
448
|
+
src: seg.src,
|
|
449
|
+
name: seg.name,
|
|
450
|
+
duration: seg.duration,
|
|
451
|
+
startTime: seg.startTime,
|
|
452
|
+
}));
|
|
453
|
+
// Caption phrases for SRT/subtitle export
|
|
454
|
+
w.getCaptions = () =>
|
|
455
|
+
script.captions?.phrases?.map((p) => ({
|
|
456
|
+
text: p.text,
|
|
457
|
+
startTime: p.startTime,
|
|
458
|
+
endTime: p.endTime,
|
|
459
|
+
})) || [];
|
|
460
|
+
// Chapter markers for YouTube timestamps -- uses segment titles from sectionHeader blocks
|
|
461
|
+
w.getChapters = () => {
|
|
462
|
+
const titleMap = buildSegmentTitleMap(script);
|
|
463
|
+
return script.audio.segments.map((seg, i) => ({
|
|
464
|
+
title: titleMap.get(i) || seg.name,
|
|
465
|
+
startTime: seg.startTime,
|
|
466
|
+
duration: seg.duration,
|
|
467
|
+
}));
|
|
468
|
+
};
|
|
469
|
+
// Cover block control for video pre-roll -- force-show or hide the cover block
|
|
470
|
+
w.showCover = () => {
|
|
471
|
+
setCoverForced(true);
|
|
472
|
+
return new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
|
|
473
|
+
};
|
|
474
|
+
w.hideCover = () => {
|
|
475
|
+
setCoverForced(false);
|
|
476
|
+
return new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
|
|
477
|
+
};
|
|
478
|
+
w.hasCoverBlock = () => !!coverBlock;
|
|
479
|
+
}
|
|
480
|
+
return () => {
|
|
481
|
+
if (typeof window !== 'undefined') {
|
|
482
|
+
const w = window as SquisqWindow;
|
|
483
|
+
delete w.seekTo;
|
|
484
|
+
delete w.getDuration;
|
|
485
|
+
delete w.getBlocks;
|
|
486
|
+
delete w.getAudioSegments;
|
|
487
|
+
delete w.getCaptions;
|
|
488
|
+
delete w.getChapters;
|
|
489
|
+
delete w.showCover;
|
|
490
|
+
delete w.hideCover;
|
|
491
|
+
delete w.hasCoverBlock;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- script is a stable prop; re-registering on every script change is unnecessary
|
|
495
|
+
}, [renderMode, isDebugMode, seekTo, totalDuration, expandedBlocks, coverBlock]);
|
|
496
|
+
|
|
497
|
+
// Captions state: use prop if provided, otherwise default to true
|
|
498
|
+
const captionsEnabled = captionsEnabledProp !== undefined ? captionsEnabledProp : true;
|
|
499
|
+
const setCaptionsEnabled = useCallback(
|
|
500
|
+
(enabled: boolean) => {
|
|
501
|
+
onCaptionsToggle?.(enabled);
|
|
502
|
+
},
|
|
503
|
+
[onCaptionsToggle],
|
|
504
|
+
);
|
|
505
|
+
const hasCaptions = script.captions && script.captions.phrases.length > 0;
|
|
506
|
+
|
|
507
|
+
// Map segment indices to human-readable titles (from sectionHeader blocks)
|
|
508
|
+
const segmentTitleMap = useMemo(() => buildSegmentTitleMap(script), [script]);
|
|
509
|
+
|
|
510
|
+
// Build shared playback state for extracted controls
|
|
511
|
+
const playbackState: PlaybackState = useMemo(
|
|
512
|
+
() => ({
|
|
513
|
+
isPlaying,
|
|
514
|
+
currentTime,
|
|
515
|
+
totalDuration,
|
|
516
|
+
currentBlockIndex,
|
|
517
|
+
totalBlocks: expandedBlocks.length,
|
|
518
|
+
docProgress,
|
|
519
|
+
hasCaptions: !!hasCaptions,
|
|
520
|
+
captionsEnabled,
|
|
521
|
+
isFullscreen,
|
|
522
|
+
currentSegmentIndex: currentSegment,
|
|
523
|
+
currentSegmentName:
|
|
524
|
+
segmentTitleMap.get(currentSegment) ?? script.audio.segments[currentSegment]?.name ?? null,
|
|
525
|
+
currentBlock: currentBlock ?? null,
|
|
526
|
+
}),
|
|
527
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- script.audio.segments is stable within a given script
|
|
528
|
+
[
|
|
529
|
+
isPlaying,
|
|
530
|
+
currentTime,
|
|
531
|
+
totalDuration,
|
|
532
|
+
currentBlockIndex,
|
|
533
|
+
expandedBlocks.length,
|
|
534
|
+
docProgress,
|
|
535
|
+
hasCaptions,
|
|
536
|
+
captionsEnabled,
|
|
537
|
+
isFullscreen,
|
|
538
|
+
currentSegment,
|
|
539
|
+
segmentTitleMap,
|
|
540
|
+
currentBlock,
|
|
541
|
+
],
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
// Build shared playback actions for extracted controls
|
|
545
|
+
const playbackActions: PlaybackActions = useMemo(
|
|
546
|
+
() => ({
|
|
547
|
+
toggle,
|
|
548
|
+
restart,
|
|
549
|
+
seekTo,
|
|
550
|
+
setCaptionsEnabled,
|
|
551
|
+
toggleFullscreen: onFullscreenToggle,
|
|
552
|
+
}),
|
|
553
|
+
[toggle, restart, seekTo, setCaptionsEnabled, onFullscreenToggle],
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
// Slide navigation actions for slideshow mode
|
|
557
|
+
// These seek to the target block's startTime and keep the player paused.
|
|
558
|
+
const slideNavActions: SlideNavActions = useMemo(
|
|
559
|
+
() => ({
|
|
560
|
+
nextSlide: () => {
|
|
561
|
+
if (currentBlockIndex < expandedBlocks.length - 1) {
|
|
562
|
+
const target = expandedBlocks[currentBlockIndex + 1];
|
|
563
|
+
if (target) {
|
|
564
|
+
seekTo(target.startTime);
|
|
565
|
+
pause();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
prevSlide: () => {
|
|
570
|
+
if (currentBlockIndex > 0) {
|
|
571
|
+
const target = expandedBlocks[currentBlockIndex - 1];
|
|
572
|
+
if (target) {
|
|
573
|
+
seekTo(target.startTime);
|
|
574
|
+
pause();
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
goToSlide: (index: number) => {
|
|
579
|
+
if (index >= 0 && index < expandedBlocks.length) {
|
|
580
|
+
const target = expandedBlocks[index];
|
|
581
|
+
if (target) {
|
|
582
|
+
seekTo(target.startTime);
|
|
583
|
+
pause();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
}),
|
|
588
|
+
[currentBlockIndex, expandedBlocks, seekTo, pause],
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
// Callback for playback state changes (for external controls)
|
|
592
|
+
useEffect(() => {
|
|
593
|
+
onPlaybackStateChange?.(playbackState);
|
|
594
|
+
}, [playbackState, onPlaybackStateChange]);
|
|
595
|
+
|
|
596
|
+
// Callback when controls are ready (for external controls)
|
|
597
|
+
// Fires every time playbackActions change so the external sidebar always holds
|
|
598
|
+
// fresh function references (toggle closes over isPlaying, so it changes often).
|
|
599
|
+
useEffect(() => {
|
|
600
|
+
onControlsReady?.({ play, pause, ...playbackActions });
|
|
601
|
+
}, [play, pause, playbackActions, onControlsReady]);
|
|
602
|
+
|
|
603
|
+
// Extract display title from a block (handles both template and expanded blocks)
|
|
604
|
+
const getBlockTitle = useCallback((block: Block): string => {
|
|
605
|
+
// For template blocks, extract title from template-specific properties first
|
|
606
|
+
const docBlock = block as DocBlock;
|
|
607
|
+
if (isTemplateBlock(docBlock)) {
|
|
608
|
+
const props = docBlock as unknown as Record<string, unknown>;
|
|
609
|
+
if (typeof props.title === 'string') return props.title;
|
|
610
|
+
if (typeof props.stat === 'string') return props.stat;
|
|
611
|
+
if (typeof props.quote === 'string') {
|
|
612
|
+
const firstLine = props.quote.split('\n')[0];
|
|
613
|
+
if (firstLine.length <= 30) return firstLine;
|
|
614
|
+
return firstLine.slice(0, 27) + '...';
|
|
615
|
+
}
|
|
616
|
+
if (typeof props.date === 'string') return props.date;
|
|
617
|
+
if (typeof props.fact === 'string') return props.fact;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// For expanded blocks with layers, try to find text content
|
|
621
|
+
if (block.layers && Array.isArray(block.layers)) {
|
|
622
|
+
const textLayer = block.layers.find((l): l is TextLayer => l.type === 'text');
|
|
623
|
+
if (textLayer?.content?.text) {
|
|
624
|
+
// Get first line of text, truncate if too long
|
|
625
|
+
const firstLine = textLayer.content.text.split('\n')[0];
|
|
626
|
+
if (firstLine.length <= 30) return firstLine;
|
|
627
|
+
return firstLine.slice(0, 27) + '...';
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// Fallback to formatted id
|
|
632
|
+
return block.id.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
633
|
+
}, []);
|
|
634
|
+
|
|
635
|
+
// Compute block markers for progress bar (using expanded blocks)
|
|
636
|
+
const blockMarkers = useMemo(() => {
|
|
637
|
+
if (!totalDuration || !expandedBlocks.length) return [];
|
|
638
|
+
let prevSegment = -1;
|
|
639
|
+
return expandedBlocks.map((block, index) => {
|
|
640
|
+
const isSectionStart = block.audioSegment !== prevSegment;
|
|
641
|
+
prevSegment = block.audioSegment;
|
|
642
|
+
return {
|
|
643
|
+
block,
|
|
644
|
+
index,
|
|
645
|
+
position: (block.startTime / totalDuration) * 100,
|
|
646
|
+
title: getBlockTitle(block),
|
|
647
|
+
isSectionStart,
|
|
648
|
+
};
|
|
649
|
+
});
|
|
650
|
+
}, [expandedBlocks, totalDuration, getBlockTitle]);
|
|
651
|
+
|
|
652
|
+
// Notify parent when block markers are computed
|
|
653
|
+
useEffect(() => {
|
|
654
|
+
if (blockMarkers.length > 0) {
|
|
655
|
+
onBlockMarkers?.(blockMarkers);
|
|
656
|
+
}
|
|
657
|
+
}, [blockMarkers, onBlockMarkers]);
|
|
658
|
+
|
|
659
|
+
// Keep expandedBlocks length in a ref so keyboard handler stays stable
|
|
660
|
+
expandedBlocksLenRef.current = expandedBlocks.length;
|
|
661
|
+
|
|
662
|
+
// Handle keyboard controls — uses refs for frequently-changing values
|
|
663
|
+
// (currentTime, totalDuration, expandedBlocks.length) to avoid
|
|
664
|
+
// re-registering the event listener on every animation frame.
|
|
665
|
+
const handleKeyDown = useCallback(
|
|
666
|
+
(e: KeyboardEvent) => {
|
|
667
|
+
// Don't capture keyboard events when focus is on an input/textarea
|
|
668
|
+
const activeEl = document.activeElement;
|
|
669
|
+
if (
|
|
670
|
+
activeEl &&
|
|
671
|
+
(activeEl.tagName === 'INPUT' ||
|
|
672
|
+
activeEl.tagName === 'TEXTAREA' ||
|
|
673
|
+
activeEl.tagName === 'SELECT')
|
|
674
|
+
) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Linear mode: no keyboard shortcuts (native scrolling handles it)
|
|
679
|
+
if (isLinearMode) return;
|
|
680
|
+
|
|
681
|
+
if (isSlideshowMode) {
|
|
682
|
+
// Slideshow mode: arrow keys navigate slides
|
|
683
|
+
switch (e.key) {
|
|
684
|
+
case 'ArrowRight':
|
|
685
|
+
case 'ArrowDown':
|
|
686
|
+
case ' ':
|
|
687
|
+
e.preventDefault();
|
|
688
|
+
slideNavActions.nextSlide();
|
|
689
|
+
break;
|
|
690
|
+
case 'ArrowLeft':
|
|
691
|
+
case 'ArrowUp':
|
|
692
|
+
e.preventDefault();
|
|
693
|
+
slideNavActions.prevSlide();
|
|
694
|
+
break;
|
|
695
|
+
case 'Home':
|
|
696
|
+
e.preventDefault();
|
|
697
|
+
slideNavActions.goToSlide(0);
|
|
698
|
+
break;
|
|
699
|
+
case 'End':
|
|
700
|
+
e.preventDefault();
|
|
701
|
+
slideNavActions.goToSlide(expandedBlocksLenRef.current - 1);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
// Video mode: standard playback controls
|
|
706
|
+
switch (e.key) {
|
|
707
|
+
case ' ':
|
|
708
|
+
e.preventDefault();
|
|
709
|
+
toggle();
|
|
710
|
+
break;
|
|
711
|
+
case 'ArrowRight':
|
|
712
|
+
seekTo(Math.min(currentTimeRef.current + 10, totalDurationRef.current));
|
|
713
|
+
break;
|
|
714
|
+
case 'ArrowLeft':
|
|
715
|
+
seekTo(Math.max(currentTimeRef.current - 10, 0));
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
[isSlideshowMode, isLinearMode, toggle, seekTo, slideNavActions],
|
|
721
|
+
);
|
|
722
|
+
|
|
723
|
+
useEffect(() => {
|
|
724
|
+
if (renderMode) return; // No keyboard in render mode
|
|
725
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
726
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
727
|
+
}, [handleKeyDown, renderMode]);
|
|
728
|
+
|
|
729
|
+
// ── Linear mode: render as scrollable document ──────────────────
|
|
730
|
+
if (isLinearMode) {
|
|
731
|
+
return (
|
|
732
|
+
<div
|
|
733
|
+
ref={containerRef}
|
|
734
|
+
className="doc-player doc-player--linear"
|
|
735
|
+
style={{
|
|
736
|
+
position: 'relative',
|
|
737
|
+
width: '100%',
|
|
738
|
+
height: '100%',
|
|
739
|
+
overflow: 'hidden',
|
|
740
|
+
}}
|
|
741
|
+
>
|
|
742
|
+
<LinearDocView doc={script} basePath={basePath} viewport={activeViewport} />
|
|
743
|
+
</div>
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return (
|
|
748
|
+
<div
|
|
749
|
+
ref={containerRef}
|
|
750
|
+
className="doc-player"
|
|
751
|
+
onClick={handleContainerClick}
|
|
752
|
+
style={{
|
|
753
|
+
position: 'relative',
|
|
754
|
+
width: '100%',
|
|
755
|
+
aspectRatio: `${activeViewport.width} / ${activeViewport.height}`,
|
|
756
|
+
margin: '0 auto',
|
|
757
|
+
overflow: 'hidden',
|
|
758
|
+
cursor: renderMode ? undefined : 'pointer',
|
|
759
|
+
}}
|
|
760
|
+
>
|
|
761
|
+
{/* Hidden audio element */}
|
|
762
|
+
<audio ref={audioRef} preload="auto" muted={muted} />
|
|
763
|
+
|
|
764
|
+
{/* Block viewport */}
|
|
765
|
+
<div className="doc-player__viewport">
|
|
766
|
+
{/* Cover block (shown at rest before playback) */}
|
|
767
|
+
{showCoverBlock && coverBlock && (
|
|
768
|
+
<div className="doc-player__block doc-player__block--cover">
|
|
769
|
+
<BlockRenderer
|
|
770
|
+
block={coverBlock}
|
|
771
|
+
blockTime={0}
|
|
772
|
+
basePath={basePath}
|
|
773
|
+
isEntering={false}
|
|
774
|
+
viewport={activeViewport}
|
|
775
|
+
/>
|
|
776
|
+
</div>
|
|
777
|
+
)}
|
|
778
|
+
|
|
779
|
+
{/* Previous block (during transition) */}
|
|
780
|
+
{!showCoverBlock && previousBlock && isExiting && (
|
|
781
|
+
<div className="doc-player__block doc-player__block--previous">
|
|
782
|
+
<BlockRenderer
|
|
783
|
+
block={previousBlock}
|
|
784
|
+
blockTime={blockTime}
|
|
785
|
+
basePath={basePath}
|
|
786
|
+
isExiting={true}
|
|
787
|
+
viewport={activeViewport}
|
|
788
|
+
/>
|
|
789
|
+
</div>
|
|
790
|
+
)}
|
|
791
|
+
|
|
792
|
+
{/* Current block */}
|
|
793
|
+
{!showCoverBlock && currentBlock && (
|
|
794
|
+
<div className="doc-player__block doc-player__block--active">
|
|
795
|
+
<BlockRenderer
|
|
796
|
+
block={currentBlock}
|
|
797
|
+
blockTime={blockTime}
|
|
798
|
+
basePath={basePath}
|
|
799
|
+
isEntering={isEntering}
|
|
800
|
+
viewport={activeViewport}
|
|
801
|
+
isPlaying={isPlaying}
|
|
802
|
+
/>
|
|
803
|
+
</div>
|
|
804
|
+
)}
|
|
805
|
+
|
|
806
|
+
{/* Caption overlay -- hidden in render mode and when stopped on cover block */}
|
|
807
|
+
{hasCaptions && !renderMode && (
|
|
808
|
+
<CaptionOverlay
|
|
809
|
+
captions={script.captions}
|
|
810
|
+
currentTime={currentTime}
|
|
811
|
+
enabled={captionsEnabled && (isPlaying || currentTime > 0)}
|
|
812
|
+
fontSize={16}
|
|
813
|
+
/>
|
|
814
|
+
)}
|
|
815
|
+
|
|
816
|
+
{/* Debug overlay (when ?debug=true) */}
|
|
817
|
+
{isDebugMode && (
|
|
818
|
+
<div
|
|
819
|
+
className="doc-player__debug"
|
|
820
|
+
style={{
|
|
821
|
+
position: 'absolute',
|
|
822
|
+
top: '8px',
|
|
823
|
+
right: '8px',
|
|
824
|
+
padding: '8px 12px',
|
|
825
|
+
background: 'rgba(0, 0, 0, 0.85)',
|
|
826
|
+
borderRadius: '6px',
|
|
827
|
+
color: '#00ff00',
|
|
828
|
+
fontFamily: 'monospace',
|
|
829
|
+
fontSize: '11px',
|
|
830
|
+
lineHeight: '1.5',
|
|
831
|
+
zIndex: 200,
|
|
832
|
+
maxWidth: '280px',
|
|
833
|
+
pointerEvents: 'none',
|
|
834
|
+
textAlign: 'left',
|
|
835
|
+
}}
|
|
836
|
+
>
|
|
837
|
+
<div style={{ color: '#ffcc00', fontWeight: 'bold', marginBottom: '4px' }}>
|
|
838
|
+
DEBUG MODE
|
|
839
|
+
</div>
|
|
840
|
+
<div>
|
|
841
|
+
<span style={{ color: '#888' }}>template:</span>{' '}
|
|
842
|
+
<span style={{ color: '#ff6b6b' }}>
|
|
843
|
+
{(currentBlock as DocBlock | null)?.template ?? 'raw'}
|
|
844
|
+
</span>
|
|
845
|
+
</div>
|
|
846
|
+
<div>
|
|
847
|
+
<span style={{ color: '#888' }}>block:</span> {currentBlockIndex + 1}/
|
|
848
|
+
{expandedBlocks.length}{' '}
|
|
849
|
+
<span style={{ color: '#666' }}>({currentBlock?.id || 'none'})</span>
|
|
850
|
+
</div>
|
|
851
|
+
<div>
|
|
852
|
+
<span style={{ color: '#888' }}>time:</span> {currentTime.toFixed(2)}s /{' '}
|
|
853
|
+
{totalDuration.toFixed(1)}s
|
|
854
|
+
</div>
|
|
855
|
+
<div>
|
|
856
|
+
<span style={{ color: '#888' }}>blockTime:</span> {blockTime.toFixed(2)}s /{' '}
|
|
857
|
+
{(currentBlock?.duration || 0).toFixed(1)}s
|
|
858
|
+
</div>
|
|
859
|
+
<div>
|
|
860
|
+
<span style={{ color: '#888' }}>segment:</span> {currentSegment}/
|
|
861
|
+
{script.audio.segments.length - 1}{' '}
|
|
862
|
+
<span style={{ color: '#666' }}>
|
|
863
|
+
({script.audio.segments[currentSegment]?.name || 'none'})
|
|
864
|
+
</span>
|
|
865
|
+
</div>
|
|
866
|
+
<div>
|
|
867
|
+
<span style={{ color: '#888' }}>viewport:</span>{' '}
|
|
868
|
+
{activeViewport.name || `${activeViewport.width}x${activeViewport.height}`}{' '}
|
|
869
|
+
<span style={{ color: '#666' }}>({orientation})</span>
|
|
870
|
+
</div>
|
|
871
|
+
<div>
|
|
872
|
+
<span style={{ color: '#888' }}>playing:</span>{' '}
|
|
873
|
+
<span style={{ color: isPlaying ? '#4ade80' : '#f87171' }}>
|
|
874
|
+
{isPlaying ? 'yes' : 'no'}
|
|
875
|
+
</span>
|
|
876
|
+
{showCoverBlock && <span style={{ color: '#60a5fa' }}> (cover)</span>}
|
|
877
|
+
</div>
|
|
878
|
+
{hasCaptions &&
|
|
879
|
+
(() => {
|
|
880
|
+
const debugPhrase = getCaptionAtTime(script.captions!, currentTime);
|
|
881
|
+
const debugEnabled = captionsEnabled && (isPlaying || currentTime > 0);
|
|
882
|
+
return (
|
|
883
|
+
<Fragment>
|
|
884
|
+
<div>
|
|
885
|
+
<span style={{ color: '#888' }}>captions:</span>{' '}
|
|
886
|
+
{script.captions?.phrases.length || 0} phrases{' '}
|
|
887
|
+
<span style={{ color: captionsEnabled ? '#4ade80' : '#666' }}>
|
|
888
|
+
({captionsEnabled ? 'on' : 'off'})
|
|
889
|
+
</span>
|
|
890
|
+
</div>
|
|
891
|
+
<div>
|
|
892
|
+
<span style={{ color: '#888' }}>cc.enabled:</span>{' '}
|
|
893
|
+
<span style={{ color: debugEnabled ? '#4ade80' : '#f87171' }}>
|
|
894
|
+
{String(debugEnabled)}
|
|
895
|
+
</span>{' '}
|
|
896
|
+
<span style={{ color: '#666' }}>
|
|
897
|
+
(playing={String(isPlaying)} t>0={String(currentTime > 0)})
|
|
898
|
+
</span>
|
|
899
|
+
</div>
|
|
900
|
+
<div>
|
|
901
|
+
<span style={{ color: '#888' }}>cc.phrase:</span>{' '}
|
|
902
|
+
<span style={{ color: debugPhrase ? '#4ade80' : '#f87171' }}>
|
|
903
|
+
{debugPhrase ? `"${debugPhrase.text.slice(0, 30)}..."` : 'null'}
|
|
904
|
+
</span>
|
|
905
|
+
</div>
|
|
906
|
+
{debugPhrase && (
|
|
907
|
+
<div>
|
|
908
|
+
<span style={{ color: '#888' }}>cc.range:</span>{' '}
|
|
909
|
+
<span style={{ color: '#60a5fa' }}>
|
|
910
|
+
{debugPhrase.startTime.toFixed(2)}-{debugPhrase.endTime.toFixed(2)}
|
|
911
|
+
</span>
|
|
912
|
+
</div>
|
|
913
|
+
)}
|
|
914
|
+
</Fragment>
|
|
915
|
+
);
|
|
916
|
+
})()}
|
|
917
|
+
</div>
|
|
918
|
+
)}
|
|
919
|
+
</div>
|
|
920
|
+
|
|
921
|
+
{/* Audio unavailable overlay */}
|
|
922
|
+
{!isAvailable && unavailableMessage && (
|
|
923
|
+
<div
|
|
924
|
+
className="doc-player__unavailable"
|
|
925
|
+
style={{
|
|
926
|
+
position: 'absolute',
|
|
927
|
+
top: 0,
|
|
928
|
+
left: 0,
|
|
929
|
+
right: 0,
|
|
930
|
+
bottom: 0,
|
|
931
|
+
display: 'flex',
|
|
932
|
+
alignItems: 'center',
|
|
933
|
+
justifyContent: 'center',
|
|
934
|
+
flexDirection: 'column',
|
|
935
|
+
gap: '16px',
|
|
936
|
+
background: 'rgba(0, 0, 0, 0.7)',
|
|
937
|
+
color: 'rgba(255, 255, 255, 0.9)',
|
|
938
|
+
fontSize: '14px',
|
|
939
|
+
zIndex: 50,
|
|
940
|
+
}}
|
|
941
|
+
>
|
|
942
|
+
<span style={{ fontSize: '32px' }}>🔊</span>
|
|
943
|
+
<span>{unavailableMessage}</span>
|
|
944
|
+
</div>
|
|
945
|
+
)}
|
|
946
|
+
|
|
947
|
+
{/* Full overlay controls (default video layout) */}
|
|
948
|
+
{!renderMode && !isSlideshowMode && showControls && (
|
|
949
|
+
<DocControlsOverlay
|
|
950
|
+
state={playbackState}
|
|
951
|
+
actions={playbackActions}
|
|
952
|
+
blockMarkers={blockMarkers}
|
|
953
|
+
expandedBlocks={expandedBlocks}
|
|
954
|
+
getBlockTitle={getBlockTitle}
|
|
955
|
+
/>
|
|
956
|
+
)}
|
|
957
|
+
|
|
958
|
+
{/* Scrubber-only mode (for sidebar/bottom layouts where other controls are external) */}
|
|
959
|
+
{!renderMode && !isSlideshowMode && !showControls && showScrubber && (
|
|
960
|
+
<div
|
|
961
|
+
className="doc-player__scrubber"
|
|
962
|
+
style={{
|
|
963
|
+
position: 'absolute',
|
|
964
|
+
bottom: 0,
|
|
965
|
+
left: 0,
|
|
966
|
+
right: 0,
|
|
967
|
+
padding: '12px 16px 8px',
|
|
968
|
+
background: 'linear-gradient(transparent, rgba(0,0,0,0.6))',
|
|
969
|
+
display: 'flex',
|
|
970
|
+
alignItems: 'center',
|
|
971
|
+
zIndex: 100,
|
|
972
|
+
}}
|
|
973
|
+
>
|
|
974
|
+
<DocProgressBar
|
|
975
|
+
state={playbackState}
|
|
976
|
+
actions={playbackActions}
|
|
977
|
+
blockMarkers={blockMarkers}
|
|
978
|
+
expandedBlocks={expandedBlocks}
|
|
979
|
+
getBlockTitle={getBlockTitle}
|
|
980
|
+
/>
|
|
981
|
+
</div>
|
|
982
|
+
)}
|
|
983
|
+
|
|
984
|
+
{/* Slideshow controls (prev / counter / next) */}
|
|
985
|
+
{!renderMode && isSlideshowMode && (
|
|
986
|
+
<DocControlsSlideshow state={playbackState} slideNav={slideNavActions} />
|
|
987
|
+
)}
|
|
988
|
+
|
|
989
|
+
{/* Tap feedback animation -- shows play/pause icon briefly on tap (video mode only) */}
|
|
990
|
+
{!isSlideshowMode && tapFeedback && (
|
|
991
|
+
<div className="doc-player__tap-feedback" key={Date.now()}>
|
|
992
|
+
<svg viewBox="0 0 24 24" fill="white" width="48" height="48">
|
|
993
|
+
{tapFeedback === 'pause' ? (
|
|
994
|
+
<path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z" />
|
|
995
|
+
) : (
|
|
996
|
+
<path d="M8 5v14l11-7z" />
|
|
997
|
+
)}
|
|
998
|
+
</svg>
|
|
999
|
+
</div>
|
|
1000
|
+
)}
|
|
1001
|
+
</div>
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
export default DocPlayer;
|