@interlacejs/editor 1.0.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.cjs ADDED
@@ -0,0 +1,3405 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ContentTypeEditor: () => ContentTypeEditor,
24
+ ContentTypeEditorSlot: () => ContentTypeEditorSlot,
25
+ ContentTypePicker: () => ContentTypePicker,
26
+ DEFAULT_EDITOR_STRINGS: () => DEFAULT_EDITOR_STRINGS,
27
+ DEFAULT_INSPECTOR_PANEL_STRINGS: () => DEFAULT_INSPECTOR_PANEL_STRINGS,
28
+ DEFAULT_KEYFRAME_TIMELINE_STRINGS: () => DEFAULT_KEYFRAME_TIMELINE_STRINGS,
29
+ DEFAULT_VIDEO_SOURCE_INPUT_STRINGS: () => DEFAULT_VIDEO_SOURCE_INPUT_STRINGS,
30
+ InspectorPanel: () => InspectorPanel,
31
+ InterlaceEditor: () => InterlaceEditor,
32
+ KeyframeTimeline: () => KeyframeTimeline,
33
+ PLACEMENT_MIN_SIZE: () => PLACEMENT_MIN_SIZE,
34
+ PlacementEditor: () => PlacementEditor,
35
+ PlacementInputs: () => PlacementInputs,
36
+ VideoSourceInput: () => VideoSourceInput,
37
+ clampPlacement: () => clampPlacement,
38
+ useAuthoringStore: () => useAuthoringStore
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/components/interlace-editor.tsx
43
+ var import_core6 = require("@interlacejs/core");
44
+ var import_react10 = require("react");
45
+
46
+ // src/tokens.ts
47
+ var COLORS = {
48
+ accent: "#0066cc",
49
+ accentHover: "#0052a3",
50
+ accentLight: "rgba(0, 102, 204, 0.15)",
51
+ accentLighter: "rgba(0, 102, 204, 0.08)",
52
+ text: "#0f172a",
53
+ textMuted: "#64748b",
54
+ border: "#e2e8f0",
55
+ borderStrong: "#cbd5e1",
56
+ surface: "#ffffff",
57
+ surfaceRaised: "#f8fafc",
58
+ ground: "#f6f7f9",
59
+ errorBg: "#fef2f2",
60
+ errorText: "#b91c1c",
61
+ errorBorder: "#fecaca",
62
+ white: "#ffffff",
63
+ black: "#000000"
64
+ };
65
+ var FONTS = {
66
+ display: 'Georgia, "Times New Roman", Times, serif',
67
+ body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
68
+ };
69
+ var SPACE = {
70
+ 1: 4,
71
+ 2: 8,
72
+ 3: 12,
73
+ 4: 16,
74
+ 5: 24
75
+ };
76
+ var RADIUS = {
77
+ sm: 4,
78
+ md: 8,
79
+ lg: 12
80
+ };
81
+ var SHADOWS = {
82
+ sm: "0 1px 2px 0 rgba(15, 23, 42, 0.04)",
83
+ md: "0 4px 12px -2px rgba(15, 23, 42, 0.08)"
84
+ };
85
+ var TYPE = {
86
+ xs: 12,
87
+ sm: 13,
88
+ base: 15,
89
+ md: 16,
90
+ lg: 20,
91
+ xl: 24
92
+ };
93
+
94
+ // src/hooks/use-authoring-store.ts
95
+ var import_core = require("@interlacejs/core");
96
+ var import_react = require("react");
97
+ function useAuthoringStore(initialVideoSrc, initialDuration) {
98
+ const [state, setState] = (0, import_react.useState)({
99
+ items: [],
100
+ videoSrc: initialVideoSrc,
101
+ videoDuration: initialDuration
102
+ });
103
+ const addItem = (0, import_react.useCallback)((item) => {
104
+ setState((prev) => ({
105
+ ...prev,
106
+ items: [...prev.items, item]
107
+ }));
108
+ }, []);
109
+ const removeItem = (0, import_react.useCallback)((id) => {
110
+ setState((prev) => ({
111
+ ...prev,
112
+ items: prev.items.filter((item) => item.content.getId() !== id)
113
+ }));
114
+ }, []);
115
+ const updateItem = (0, import_react.useCallback)(
116
+ (id, newItem) => {
117
+ setState((prev) => ({
118
+ ...prev,
119
+ items: prev.items.map(
120
+ (item) => item.content.getId() === id ? newItem : item
121
+ )
122
+ }));
123
+ },
124
+ []
125
+ );
126
+ const doSerialize = (0, import_react.useCallback)(
127
+ () => (0, import_core.serialize)(
128
+ state.items.map((item) => item.content),
129
+ state.videoSrc,
130
+ state.videoDuration
131
+ ),
132
+ [state]
133
+ );
134
+ const loadDocument = (0, import_react.useCallback)(
135
+ (doc, registry) => {
136
+ const { items, videoSrc, videoDuration, validationErrors, warnings } = (0, import_core.deserialize)(doc, registry);
137
+ setState({
138
+ items: items.map((content) => ({ content, hook: content.getHook() })),
139
+ videoSrc,
140
+ videoDuration
141
+ });
142
+ return { validationErrors, warnings };
143
+ },
144
+ []
145
+ );
146
+ const setVideoMetadata = (0, import_react.useCallback)((src, duration) => {
147
+ setState((prev) => ({
148
+ ...prev,
149
+ videoSrc: src,
150
+ videoDuration: duration
151
+ }));
152
+ }, []);
153
+ return {
154
+ state,
155
+ addItem,
156
+ removeItem,
157
+ updateItem,
158
+ serialize: doSerialize,
159
+ loadDocument,
160
+ setVideoMetadata
161
+ };
162
+ }
163
+
164
+ // src/components/content-type-editor.tsx
165
+ var import_react3 = require("react");
166
+
167
+ // src/components/content-type-editor-mount.ts
168
+ var import_react2 = require("react");
169
+ function useContentTypeEditorMount({
170
+ containerRef,
171
+ active,
172
+ contentTypeId,
173
+ registry,
174
+ data,
175
+ onChange
176
+ }) {
177
+ const mountedSessionRef = (0, import_react2.useRef)(null);
178
+ const onChangeRef = (0, import_react2.useRef)(onChange);
179
+ onChangeRef.current = onChange;
180
+ const contentType = contentTypeId ? registry.get(contentTypeId) : void 0;
181
+ (0, import_react2.useEffect)(() => {
182
+ const session = mountedSessionRef.current;
183
+ if (session && (!active || !contentType)) {
184
+ session.contentType.unmount?.(session.container);
185
+ mountedSessionRef.current = null;
186
+ return;
187
+ }
188
+ const container = containerRef.current;
189
+ if (!container) return;
190
+ if (!active || !contentType) return;
191
+ if (session && session.contentType !== contentType) {
192
+ session.contentType.unmount?.(session.container);
193
+ mountedSessionRef.current = null;
194
+ }
195
+ const currentSession = mountedSessionRef.current;
196
+ const isNewSession = !currentSession || currentSession.contentType !== contentType;
197
+ if (isNewSession) {
198
+ container.innerHTML = "";
199
+ contentType.renderEditor(container, data, onChangeRef.current);
200
+ mountedSessionRef.current = { container, contentType };
201
+ } else if (contentType.updateEditor) {
202
+ contentType.updateEditor(container, data, onChangeRef.current);
203
+ } else {
204
+ contentType.unmount?.(container);
205
+ container.innerHTML = "";
206
+ contentType.renderEditor(container, data, onChangeRef.current);
207
+ mountedSessionRef.current = { container, contentType };
208
+ }
209
+ }, [active, contentTypeId, contentType, data, containerRef]);
210
+ (0, import_react2.useEffect)(() => {
211
+ return () => {
212
+ const session = mountedSessionRef.current;
213
+ if (session) {
214
+ session.contentType.unmount?.(session.container);
215
+ mountedSessionRef.current = null;
216
+ }
217
+ };
218
+ }, []);
219
+ }
220
+
221
+ // src/components/content-type-editor.tsx
222
+ var import_jsx_runtime = require("react/jsx-runtime");
223
+ function ContentTypeEditor({
224
+ contentTypeId,
225
+ registry,
226
+ data,
227
+ onChange
228
+ }) {
229
+ const containerRef = (0, import_react3.useRef)(null);
230
+ useContentTypeEditorMount({
231
+ containerRef,
232
+ active: contentTypeId != null,
233
+ contentTypeId,
234
+ registry,
235
+ data,
236
+ onChange
237
+ });
238
+ const contentType = contentTypeId ? registry.get(contentTypeId) : void 0;
239
+ if (!contentTypeId || !contentType) return null;
240
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
241
+ "div",
242
+ {
243
+ ref: containerRef,
244
+ className: "content-type-editor",
245
+ "data-testid": "content-type-editor",
246
+ style: { minHeight: 60 }
247
+ }
248
+ );
249
+ }
250
+
251
+ // src/components/inspector-panel.tsx
252
+ var import_core2 = require("@interlacejs/core");
253
+ var import_react6 = require("react");
254
+
255
+ // src/components/content-type-picker.tsx
256
+ var import_react4 = require("react");
257
+ var import_jsx_runtime2 = require("react/jsx-runtime");
258
+ var ContentTypePicker = ({
259
+ registeredTypes,
260
+ selectedType,
261
+ onSelect
262
+ }) => {
263
+ const [isOpen, setIsOpen] = (0, import_react4.useState)(false);
264
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { position: "relative" }, children: [
265
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
266
+ "button",
267
+ {
268
+ onClick: () => setIsOpen(!isOpen),
269
+ style: {
270
+ width: "100%",
271
+ padding: `${SPACE[2]}px ${SPACE[3]}px`,
272
+ backgroundColor: COLORS.surface,
273
+ border: `1px solid ${COLORS.borderStrong}`,
274
+ borderRadius: `${RADIUS.sm}px`,
275
+ cursor: "pointer",
276
+ textAlign: "left",
277
+ display: "flex",
278
+ justifyContent: "space-between",
279
+ alignItems: "center",
280
+ fontSize: TYPE.base,
281
+ color: COLORS.text,
282
+ transition: "border-color 150ms ease, background-color 150ms ease"
283
+ },
284
+ children: [
285
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: selectedType || "Select content type..." }),
286
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: isOpen ? "\u25BC" : "\u25B6" })
287
+ ]
288
+ }
289
+ ),
290
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
291
+ "div",
292
+ {
293
+ style: {
294
+ position: "absolute",
295
+ top: "100%",
296
+ left: 0,
297
+ right: 0,
298
+ backgroundColor: COLORS.surface,
299
+ border: `1px solid ${COLORS.borderStrong}`,
300
+ borderTop: "none",
301
+ borderRadius: `0 0 ${RADIUS.sm}px ${RADIUS.sm}px`,
302
+ maxHeight: "200px",
303
+ overflowY: "auto",
304
+ zIndex: 10,
305
+ boxShadow: SHADOWS.md
306
+ },
307
+ children: registeredTypes.map((typeId) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
308
+ "div",
309
+ {
310
+ onClick: () => {
311
+ onSelect(typeId);
312
+ setIsOpen(false);
313
+ },
314
+ style: {
315
+ padding: `${SPACE[2]}px ${SPACE[3]}px`,
316
+ cursor: "pointer",
317
+ backgroundColor: selectedType === typeId ? COLORS.accentLighter : COLORS.surface,
318
+ borderBottom: `1px solid ${COLORS.border}`,
319
+ color: selectedType === typeId ? COLORS.accent : COLORS.text,
320
+ fontSize: TYPE.base,
321
+ transition: "background-color 150ms ease"
322
+ },
323
+ children: typeId
324
+ },
325
+ typeId
326
+ ))
327
+ }
328
+ )
329
+ ] });
330
+ };
331
+
332
+ // src/components/placement-editor.tsx
333
+ var import_react5 = require("react");
334
+ var import_jsx_runtime3 = require("react/jsx-runtime");
335
+ var PLACEMENT_MIN_SIZE = 1;
336
+ function clampValue(value, min, max) {
337
+ return Math.max(min, Math.min(value, max));
338
+ }
339
+ function clampPlacement(next, intent) {
340
+ if (intent === "move") {
341
+ const width = Math.max(PLACEMENT_MIN_SIZE, next.width);
342
+ const height = Math.max(PLACEMENT_MIN_SIZE, next.height);
343
+ return {
344
+ ...next,
345
+ width,
346
+ height,
347
+ x: clampValue(next.x, 0, 100 - width),
348
+ y: clampValue(next.y, 0, 100 - height)
349
+ };
350
+ }
351
+ const x = clampValue(next.x, 0, 100 - PLACEMENT_MIN_SIZE);
352
+ const y = clampValue(next.y, 0, 100 - PLACEMENT_MIN_SIZE);
353
+ return {
354
+ ...next,
355
+ x,
356
+ y,
357
+ width: clampValue(next.width, PLACEMENT_MIN_SIZE, 100 - x),
358
+ height: clampValue(next.height, PLACEMENT_MIN_SIZE, 100 - y)
359
+ };
360
+ }
361
+ function resizeCandidate(handle, start, px, py) {
362
+ const right = start.x + start.width;
363
+ const bottom = start.y + start.height;
364
+ const anchorX = Math.min(px, right - PLACEMENT_MIN_SIZE);
365
+ const anchorY = Math.min(py, bottom - PLACEMENT_MIN_SIZE);
366
+ switch (handle) {
367
+ case "e":
368
+ return { ...start, width: px - start.x };
369
+ case "w":
370
+ return { ...start, x: anchorX, width: right - anchorX };
371
+ case "s":
372
+ return { ...start, height: py - start.y };
373
+ case "n":
374
+ return { ...start, y: anchorY, height: bottom - anchorY };
375
+ case "se":
376
+ return { ...start, width: px - start.x, height: py - start.y };
377
+ case "ne":
378
+ return {
379
+ ...start,
380
+ width: px - start.x,
381
+ y: anchorY,
382
+ height: bottom - anchorY
383
+ };
384
+ case "sw":
385
+ return {
386
+ ...start,
387
+ x: anchorX,
388
+ width: right - anchorX,
389
+ height: py - start.y
390
+ };
391
+ case "nw":
392
+ return {
393
+ ...start,
394
+ x: anchorX,
395
+ width: right - anchorX,
396
+ y: anchorY,
397
+ height: bottom - anchorY
398
+ };
399
+ }
400
+ }
401
+ var HANDLE_SIZE = 10;
402
+ var HANDLE_DEFS = [
403
+ {
404
+ id: "nw",
405
+ label: "Resize north-west",
406
+ cursor: "nwse-resize",
407
+ style: { top: -HANDLE_SIZE / 2, left: -HANDLE_SIZE / 2 }
408
+ },
409
+ {
410
+ id: "n",
411
+ label: "Resize north",
412
+ cursor: "ns-resize",
413
+ style: { top: -HANDLE_SIZE / 2, left: "50%", marginLeft: -HANDLE_SIZE / 2 }
414
+ },
415
+ {
416
+ id: "ne",
417
+ label: "Resize north-east",
418
+ cursor: "nesw-resize",
419
+ style: { top: -HANDLE_SIZE / 2, right: -HANDLE_SIZE / 2 }
420
+ },
421
+ {
422
+ id: "e",
423
+ label: "Resize east",
424
+ cursor: "ew-resize",
425
+ style: {
426
+ top: "50%",
427
+ right: -HANDLE_SIZE / 2,
428
+ marginTop: -HANDLE_SIZE / 2
429
+ }
430
+ },
431
+ {
432
+ id: "se",
433
+ label: "Resize south-east",
434
+ cursor: "nwse-resize",
435
+ style: { bottom: -HANDLE_SIZE / 2, right: -HANDLE_SIZE / 2 }
436
+ },
437
+ {
438
+ id: "s",
439
+ label: "Resize south",
440
+ cursor: "ns-resize",
441
+ style: {
442
+ bottom: -HANDLE_SIZE / 2,
443
+ left: "50%",
444
+ marginLeft: -HANDLE_SIZE / 2
445
+ }
446
+ },
447
+ {
448
+ id: "sw",
449
+ label: "Resize south-west",
450
+ cursor: "nesw-resize",
451
+ style: { bottom: -HANDLE_SIZE / 2, left: -HANDLE_SIZE / 2 }
452
+ },
453
+ {
454
+ id: "w",
455
+ label: "Resize west",
456
+ cursor: "ew-resize",
457
+ style: {
458
+ top: "50%",
459
+ left: -HANDLE_SIZE / 2,
460
+ marginTop: -HANDLE_SIZE / 2
461
+ }
462
+ }
463
+ ];
464
+ var PlacementEditor = ({
465
+ placement,
466
+ onPlacementChange
467
+ }) => {
468
+ const frameRef = (0, import_react5.useRef)(null);
469
+ const dragRef = (0, import_react5.useRef)(null);
470
+ const placementRef = (0, import_react5.useRef)(placement);
471
+ placementRef.current = placement;
472
+ const onPlacementChangeRef = (0, import_react5.useRef)(onPlacementChange);
473
+ onPlacementChangeRef.current = onPlacementChange;
474
+ (0, import_react5.useEffect)(() => {
475
+ return () => {
476
+ dragRef.current?.cleanup();
477
+ };
478
+ }, []);
479
+ const beginDrag = (0, import_react5.useCallback)(
480
+ (e, handle) => {
481
+ if (typeof e.button === "number" && e.button !== 0) return;
482
+ if (dragRef.current) return;
483
+ const frame = frameRef.current;
484
+ const target = e.currentTarget;
485
+ if (!frame) return;
486
+ const frameRect = frame.getBoundingClientRect();
487
+ if (frameRect.width <= 0 || frameRect.height <= 0) return;
488
+ e.preventDefault();
489
+ e.stopPropagation();
490
+ const start = placementRef.current;
491
+ const startPointerPct = {
492
+ x: (e.clientX - frameRect.left) / frameRect.width * 100,
493
+ y: (e.clientY - frameRect.top) / frameRect.height * 100
494
+ };
495
+ const intent = handle === "move" ? "move" : "resize";
496
+ const onMove = (ev) => {
497
+ const px = (ev.clientX - frameRect.left) / frameRect.width * 100;
498
+ const py = (ev.clientY - frameRect.top) / frameRect.height * 100;
499
+ let candidate;
500
+ if (handle === "move") {
501
+ candidate = {
502
+ ...start,
503
+ x: start.x + (px - startPointerPct.x),
504
+ y: start.y + (py - startPointerPct.y)
505
+ };
506
+ } else {
507
+ candidate = resizeCandidate(handle, start, px, py);
508
+ }
509
+ onPlacementChangeRef.current(clampPlacement(candidate, intent));
510
+ };
511
+ const cleanup = () => {
512
+ target.removeEventListener("pointermove", onMove);
513
+ target.removeEventListener("pointerup", onUp);
514
+ target.removeEventListener("pointercancel", onUp);
515
+ window.removeEventListener("pointerup", onUp);
516
+ window.removeEventListener("pointercancel", onUp);
517
+ try {
518
+ target.releasePointerCapture?.(pointerId);
519
+ } catch {
520
+ }
521
+ dragRef.current = null;
522
+ };
523
+ const onUp = () => {
524
+ cleanup();
525
+ };
526
+ const pointerId = e.pointerId;
527
+ try {
528
+ target.setPointerCapture?.(pointerId);
529
+ } catch {
530
+ }
531
+ target.addEventListener("pointermove", onMove);
532
+ target.addEventListener("pointerup", onUp);
533
+ target.addEventListener("pointercancel", onUp);
534
+ window.addEventListener("pointerup", onUp);
535
+ window.addEventListener("pointercancel", onUp);
536
+ dragRef.current = { cleanup };
537
+ },
538
+ []
539
+ );
540
+ const handleKeyDown = (0, import_react5.useCallback)(
541
+ (e) => {
542
+ const step = e.shiftKey ? 5 : 1;
543
+ let next = null;
544
+ switch (e.key) {
545
+ case "ArrowLeft":
546
+ next = { ...placementRef.current, x: placementRef.current.x - step };
547
+ break;
548
+ case "ArrowRight":
549
+ next = { ...placementRef.current, x: placementRef.current.x + step };
550
+ break;
551
+ case "ArrowUp":
552
+ next = { ...placementRef.current, y: placementRef.current.y - step };
553
+ break;
554
+ case "ArrowDown":
555
+ next = { ...placementRef.current, y: placementRef.current.y + step };
556
+ break;
557
+ default:
558
+ return;
559
+ }
560
+ e.preventDefault();
561
+ e.stopPropagation();
562
+ onPlacementChangeRef.current(clampPlacement(next, "move"));
563
+ },
564
+ []
565
+ );
566
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
567
+ "div",
568
+ {
569
+ ref: frameRef,
570
+ className: "placement-editor",
571
+ "data-testid": "placement-editor",
572
+ style: {
573
+ position: "absolute",
574
+ inset: 0,
575
+ pointerEvents: "none"
576
+ },
577
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
578
+ "div",
579
+ {
580
+ tabIndex: 0,
581
+ role: "application",
582
+ "aria-label": `Placement: x ${placement.x.toFixed(0)}%, y ${placement.y.toFixed(0)}%, width ${placement.width.toFixed(0)}%, height ${placement.height.toFixed(0)}%. Arrow keys nudge.`,
583
+ "data-testid": "placement-editor-rect",
584
+ onPointerDown: (e) => beginDrag(e, "move"),
585
+ onKeyDown: handleKeyDown,
586
+ style: {
587
+ position: "absolute",
588
+ left: `${placement.x}%`,
589
+ top: `${placement.y}%`,
590
+ width: `${placement.width}%`,
591
+ height: `${placement.height}%`,
592
+ backgroundColor: COLORS.accentLight,
593
+ border: `2px solid ${COLORS.accent}`,
594
+ borderRadius: `${RADIUS.sm}px`,
595
+ boxSizing: "border-box",
596
+ cursor: "move",
597
+ pointerEvents: "auto",
598
+ touchAction: "none",
599
+ transition: "box-shadow 150ms ease",
600
+ boxShadow: SHADOWS.sm
601
+ },
602
+ children: HANDLE_DEFS.map((handle) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
603
+ "div",
604
+ {
605
+ role: "separator",
606
+ "aria-label": handle.label,
607
+ "aria-orientation": "horizontal",
608
+ "data-testid": `placement-editor-handle-${handle.id}`,
609
+ onPointerDown: (e) => beginDrag(e, handle.id),
610
+ style: {
611
+ position: "absolute",
612
+ width: HANDLE_SIZE,
613
+ height: HANDLE_SIZE,
614
+ backgroundColor: COLORS.surface,
615
+ border: `2px solid ${COLORS.accent}`,
616
+ borderRadius: `${RADIUS.sm}px`,
617
+ boxSizing: "border-box",
618
+ cursor: handle.cursor,
619
+ pointerEvents: "auto",
620
+ touchAction: "none",
621
+ ...handle.style
622
+ }
623
+ },
624
+ handle.id
625
+ ))
626
+ }
627
+ )
628
+ }
629
+ );
630
+ };
631
+ var PLACEMENT_INPUT_STYLE = {
632
+ width: "60px",
633
+ padding: `${SPACE[1]}px`,
634
+ border: `1px solid ${COLORS.borderStrong}`,
635
+ borderRadius: RADIUS.sm,
636
+ fontSize: TYPE.sm,
637
+ color: COLORS.text
638
+ };
639
+ var PlacementInputs = ({
640
+ placement,
641
+ onPlacementChange
642
+ }) => {
643
+ const placementRef = (0, import_react5.useRef)(placement);
644
+ placementRef.current = placement;
645
+ const onChangeRef = (0, import_react5.useRef)(onPlacementChange);
646
+ onChangeRef.current = onPlacementChange;
647
+ const commit = (0, import_react5.useCallback)(
648
+ (partial, intent) => {
649
+ onChangeRef.current(
650
+ clampPlacement({ ...placementRef.current, ...partial }, intent)
651
+ );
652
+ },
653
+ []
654
+ );
655
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
656
+ "div",
657
+ {
658
+ "data-testid": "placement-editor-inputs",
659
+ style: {
660
+ display: "flex",
661
+ gap: SPACE[2],
662
+ padding: `${SPACE[2]}px 0`,
663
+ fontSize: TYPE.xs,
664
+ alignItems: "center",
665
+ flexWrap: "wrap",
666
+ color: COLORS.textMuted
667
+ },
668
+ children: [
669
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
670
+ "X:",
671
+ " ",
672
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
673
+ "input",
674
+ {
675
+ type: "number",
676
+ "data-testid": "placement-editor-input-x",
677
+ value: placement.x.toFixed(1),
678
+ onChange: (e) => commit({ x: parseFloat(e.target.value) || 0 }, "move"),
679
+ style: PLACEMENT_INPUT_STYLE
680
+ }
681
+ )
682
+ ] }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
684
+ "Y:",
685
+ " ",
686
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
687
+ "input",
688
+ {
689
+ type: "number",
690
+ "data-testid": "placement-editor-input-y",
691
+ value: placement.y.toFixed(1),
692
+ onChange: (e) => commit({ y: parseFloat(e.target.value) || 0 }, "move"),
693
+ style: PLACEMENT_INPUT_STYLE
694
+ }
695
+ )
696
+ ] }),
697
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
698
+ "W:",
699
+ " ",
700
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
701
+ "input",
702
+ {
703
+ type: "number",
704
+ "data-testid": "placement-editor-input-w",
705
+ value: placement.width.toFixed(1),
706
+ onChange: (e) => commit({ width: parseFloat(e.target.value) || 0 }, "resize"),
707
+ style: PLACEMENT_INPUT_STYLE
708
+ }
709
+ )
710
+ ] }),
711
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
712
+ "H:",
713
+ " ",
714
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
715
+ "input",
716
+ {
717
+ type: "number",
718
+ "data-testid": "placement-editor-input-h",
719
+ value: placement.height.toFixed(1),
720
+ onChange: (e) => commit({ height: parseFloat(e.target.value) || 0 }, "resize"),
721
+ style: PLACEMENT_INPUT_STYLE
722
+ }
723
+ )
724
+ ] })
725
+ ]
726
+ }
727
+ );
728
+ };
729
+
730
+ // src/components/inspector-panel.tsx
731
+ var import_jsx_runtime4 = require("react/jsx-runtime");
732
+ var DEFAULT_INSPECTOR_PANEL_STRINGS = {
733
+ ...import_core2.DEFAULT_STRINGS,
734
+ inspectorHeading: "Hook details",
735
+ titleLabel: "Title",
736
+ deleteLabel: "Delete",
737
+ hookTypeLabel: "Type",
738
+ blockingTypeLabel: "Blocking",
739
+ nonBlockingTypeLabel: "Non-blocking",
740
+ timestampLabel: "Timestamp (s)",
741
+ startLabel: "Start (s)",
742
+ endLabel: "End (s)",
743
+ placementLabel: "Placement",
744
+ contentTypeLabel: "Content type"
745
+ };
746
+ var INPUT_STYLE = {
747
+ width: "70px",
748
+ padding: `${SPACE[1]}px ${SPACE[2]}px`,
749
+ border: `1px solid ${COLORS.borderStrong}`,
750
+ borderRadius: RADIUS.sm,
751
+ fontSize: TYPE.sm,
752
+ color: COLORS.text
753
+ };
754
+ var InspectorPanel = ({
755
+ entry,
756
+ onTitleChange,
757
+ onTimeChange,
758
+ onContentTypeSelect,
759
+ placement,
760
+ onPlacementChange,
761
+ onDelete,
762
+ strings: stringsOverride
763
+ }) => {
764
+ const strings = { ...DEFAULT_INSPECTOR_PANEL_STRINGS, ...stringsOverride };
765
+ const onChangeRef = (0, import_react6.useRef)(onTitleChange);
766
+ onChangeRef.current = onTitleChange;
767
+ const onDeleteRef = (0, import_react6.useRef)(onDelete);
768
+ onDeleteRef.current = onDelete;
769
+ const handleKeyDown = (0, import_react6.useCallback)(
770
+ (e) => {
771
+ if (e.key === "Delete" || e.key === "Backspace") {
772
+ if (e.target.tagName === "INPUT") return;
773
+ e.preventDefault();
774
+ onDeleteRef.current();
775
+ }
776
+ },
777
+ []
778
+ );
779
+ const isBlocking = entry.hookType === "blocking";
780
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
781
+ "div",
782
+ {
783
+ className: "inspector-panel",
784
+ "data-testid": "inspector-panel",
785
+ tabIndex: 0,
786
+ onKeyDown: handleKeyDown,
787
+ style: {
788
+ border: `1px solid ${COLORS.border}`,
789
+ borderRadius: RADIUS.md,
790
+ backgroundColor: COLORS.surfaceRaised,
791
+ padding: SPACE[3],
792
+ display: "flex",
793
+ flexDirection: "column",
794
+ gap: SPACE[2],
795
+ fontSize: TYPE.sm
796
+ },
797
+ children: [
798
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
799
+ "h4",
800
+ {
801
+ style: {
802
+ margin: 0,
803
+ fontFamily: FONTS.display,
804
+ fontSize: TYPE.md,
805
+ fontWeight: 600,
806
+ color: COLORS.text
807
+ },
808
+ children: strings.inspectorHeading
809
+ }
810
+ ),
811
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
812
+ strings.titleLabel,
813
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
814
+ "input",
815
+ {
816
+ type: "text",
817
+ "data-testid": "inspector-panel-title",
818
+ value: entry.title,
819
+ onChange: (e) => onTitleChange(e.target.value),
820
+ "aria-label": strings.titleLabel,
821
+ style: {
822
+ padding: `${SPACE[2]}px ${SPACE[2]}px`,
823
+ border: `1px solid ${COLORS.borderStrong}`,
824
+ borderRadius: RADIUS.sm,
825
+ fontSize: TYPE.sm,
826
+ color: COLORS.text
827
+ }
828
+ }
829
+ )
830
+ ] }),
831
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { display: "flex", gap: 16, color: COLORS.textMuted }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
832
+ strings.hookTypeLabel,
833
+ ":",
834
+ " ",
835
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { "data-testid": "inspector-panel-type", children: isBlocking ? strings.blockingTypeLabel : strings.nonBlockingTypeLabel })
836
+ ] }) }),
837
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { display: "flex", gap: 12, alignItems: "flex-end" }, children: isBlocking ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
838
+ strings.timestampLabel,
839
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
840
+ "input",
841
+ {
842
+ type: "number",
843
+ "data-testid": "inspector-panel-timestamp",
844
+ value: (entry.timestamp ?? 0).toFixed(1),
845
+ onChange: (e) => onTimeChange({ timestamp: parseFloat(e.target.value) || 0 }),
846
+ style: INPUT_STYLE
847
+ }
848
+ )
849
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
850
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
851
+ strings.startLabel,
852
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
853
+ "input",
854
+ {
855
+ type: "number",
856
+ "data-testid": "inspector-panel-start",
857
+ value: (entry.start ?? 0).toFixed(1),
858
+ onChange: (e) => onTimeChange({ start: parseFloat(e.target.value) || 0 }),
859
+ style: INPUT_STYLE
860
+ }
861
+ )
862
+ ] }),
863
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
864
+ strings.endLabel,
865
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
866
+ "input",
867
+ {
868
+ type: "number",
869
+ "data-testid": "inspector-panel-end",
870
+ value: (entry.end ?? 0).toFixed(1),
871
+ onChange: (e) => onTimeChange({ end: parseFloat(e.target.value) || 0 }),
872
+ style: INPUT_STYLE
873
+ }
874
+ )
875
+ ] })
876
+ ] }) }),
877
+ placement && onPlacementChange ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
878
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
879
+ "div",
880
+ {
881
+ style: {
882
+ color: COLORS.textMuted,
883
+ marginBottom: SPACE[1],
884
+ fontWeight: 600
885
+ },
886
+ children: strings.placementLabel
887
+ }
888
+ ),
889
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
890
+ PlacementInputs,
891
+ {
892
+ placement,
893
+ onPlacementChange
894
+ }
895
+ )
896
+ ] }) : null,
897
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
898
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
899
+ "div",
900
+ {
901
+ style: {
902
+ color: COLORS.textMuted,
903
+ marginBottom: SPACE[1],
904
+ fontWeight: 600
905
+ },
906
+ children: strings.contentTypeLabel
907
+ }
908
+ ),
909
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
910
+ ContentTypePicker,
911
+ {
912
+ registeredTypes: entry.registeredTypes,
913
+ selectedType: entry.contentTypeId ?? null,
914
+ onSelect: onContentTypeSelect
915
+ }
916
+ )
917
+ ] }),
918
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { display: "flex", justifyContent: "flex-end" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
919
+ "button",
920
+ {
921
+ type: "button",
922
+ onClick: onDelete,
923
+ "data-testid": "inspector-panel-delete",
924
+ style: {
925
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
926
+ backgroundColor: COLORS.errorBg,
927
+ border: `1px solid ${COLORS.errorBorder}`,
928
+ borderRadius: RADIUS.sm,
929
+ color: COLORS.errorText,
930
+ cursor: "pointer",
931
+ fontSize: TYPE.sm,
932
+ fontWeight: 600,
933
+ transition: "background-color 150ms ease"
934
+ },
935
+ children: strings.deleteLabel
936
+ }
937
+ ) })
938
+ ]
939
+ }
940
+ );
941
+ };
942
+
943
+ // src/components/keyframe-timeline.tsx
944
+ var import_core3 = require("@interlacejs/core");
945
+ var import_react7 = require("react");
946
+ var import_jsx_runtime5 = require("react/jsx-runtime");
947
+ var DEFAULT_KEYFRAME_TIMELINE_STRINGS = {
948
+ ...import_core3.DEFAULT_STRINGS,
949
+ addBlockingLabel: "+ Blocking at playhead",
950
+ addNonBlockingLabel: "+ Non-blocking at playhead",
951
+ zoomInLabel: "Zoom in",
952
+ zoomOutLabel: "Zoom out",
953
+ playLabel: "Play",
954
+ pauseLabel: "Pause",
955
+ playheadLabel: "Playhead",
956
+ emptyLabel: "No hooks yet. Add one at the playhead to get started.",
957
+ rulerLabel: "Timeline ruler",
958
+ trackLabel: "Hook track",
959
+ blockingKeyframeLabel: "blocking at",
960
+ nonBlockingRangeLabel: "non-blocking from"
961
+ };
962
+ var MIN_ZOOM = 2;
963
+ var MAX_ZOOM = 100;
964
+ var DEFAULT_ZOOM = 8;
965
+ var MIN_RANGE = 1;
966
+ var LANE_HEIGHT = 28;
967
+ var MIN_LANE_HEIGHT = 14;
968
+ var TRACK_PADDING = 6;
969
+ var TRACK_HEIGHT_BUDGET = 96;
970
+ var RULER_HEIGHT = 24;
971
+ var KEYFRAME_WIDTH_PX = 14;
972
+ var RANGE_MIN_WIDTH_PX = 12;
973
+ function clampValue2(value, min, max) {
974
+ return Math.max(min, Math.min(value, max));
975
+ }
976
+ function snapTime(time, bypass) {
977
+ return bypass ? time : Math.round(time);
978
+ }
979
+ function tickInterval(zoom) {
980
+ for (const candidate of [1, 2, 5, 10, 15, 30, 60, 120, 300, 600]) {
981
+ if (candidate * zoom >= 56) return candidate;
982
+ }
983
+ return 600;
984
+ }
985
+ function formatTick(seconds) {
986
+ if (seconds < 60) return `${seconds}s`;
987
+ const m = Math.floor(seconds / 60);
988
+ const s = seconds % 60;
989
+ return s === 0 ? `${m}m` : `${m}m ${s}s`;
990
+ }
991
+ function anchorOf(entry) {
992
+ return entry.hookType === "blocking" ? entry.timestamp ?? 0 : entry.start ?? 0;
993
+ }
994
+ function extentOf(entry, zoom) {
995
+ if (entry.hookType === "blocking") {
996
+ return KEYFRAME_WIDTH_PX / zoom;
997
+ }
998
+ const span = (entry.end ?? 0) - (entry.start ?? 0);
999
+ return Math.max(RANGE_MIN_WIDTH_PX / zoom, span);
1000
+ }
1001
+ var KeyframeTimeline = ({
1002
+ entries,
1003
+ selectedId,
1004
+ videoDuration,
1005
+ currentTime,
1006
+ isPlaying,
1007
+ onSeek,
1008
+ onTogglePlay,
1009
+ onSelectEntry,
1010
+ onUpdateEntry,
1011
+ onAddEntry,
1012
+ onDeselect,
1013
+ strings: stringsOverride
1014
+ }) => {
1015
+ const strings = { ...DEFAULT_KEYFRAME_TIMELINE_STRINGS, ...stringsOverride };
1016
+ const [zoom, setZoom] = (0, import_react7.useState)(DEFAULT_ZOOM);
1017
+ const dragRef = (0, import_react7.useRef)(null);
1018
+ const scrollRef = (0, import_react7.useRef)(null);
1019
+ const stripRef = (0, import_react7.useRef)(null);
1020
+ const userZoomedRef = (0, import_react7.useRef)(false);
1021
+ const propsRef = (0, import_react7.useRef)({ zoom, videoDuration, currentTime });
1022
+ propsRef.current = { zoom, videoDuration, currentTime };
1023
+ (0, import_react7.useLayoutEffect)(() => {
1024
+ const el = scrollRef.current;
1025
+ if (!el) return;
1026
+ const measureAndFit = () => {
1027
+ const width = el.clientWidth;
1028
+ if (width <= 0 || videoDuration <= 0) return;
1029
+ if (!userZoomedRef.current) {
1030
+ setZoom(clampValue2(width / videoDuration, MIN_ZOOM, MAX_ZOOM));
1031
+ }
1032
+ };
1033
+ measureAndFit();
1034
+ if (typeof ResizeObserver !== "undefined") {
1035
+ const observer = new ResizeObserver(() => measureAndFit());
1036
+ observer.observe(el);
1037
+ return () => observer.disconnect();
1038
+ }
1039
+ return void 0;
1040
+ }, [videoDuration]);
1041
+ const stripWidth = Math.max(videoDuration * zoom, 320);
1042
+ const pxToTime = (0, import_react7.useCallback)(
1043
+ (clientX, stripRect) => (clientX - stripRect.left) / propsRef.current.zoom,
1044
+ []
1045
+ );
1046
+ const beginDrag = (0, import_react7.useCallback)(
1047
+ (e, onMoveDrag) => {
1048
+ if (typeof e.button === "number" && e.button !== 0) return;
1049
+ if (dragRef.current) return;
1050
+ const strip = stripRef.current;
1051
+ const target = e.currentTarget;
1052
+ if (!strip) return;
1053
+ const stripRect = strip.getBoundingClientRect();
1054
+ if (stripRect.width <= 0) return;
1055
+ e.preventDefault();
1056
+ e.stopPropagation();
1057
+ const onMove = (ev) => onMoveDrag(ev, stripRect);
1058
+ const cleanup = () => {
1059
+ target.removeEventListener("pointermove", onMove);
1060
+ target.removeEventListener("pointerup", onUp);
1061
+ target.removeEventListener("pointercancel", onUp);
1062
+ window.removeEventListener("pointerup", onUp);
1063
+ window.removeEventListener("pointercancel", onUp);
1064
+ try {
1065
+ target.releasePointerCapture?.(e.pointerId);
1066
+ } catch {
1067
+ }
1068
+ dragRef.current = null;
1069
+ };
1070
+ const onUp = () => {
1071
+ cleanup();
1072
+ };
1073
+ try {
1074
+ target.setPointerCapture?.(e.pointerId);
1075
+ } catch {
1076
+ }
1077
+ target.addEventListener("pointermove", onMove);
1078
+ target.addEventListener("pointerup", onUp);
1079
+ target.addEventListener("pointercancel", onUp);
1080
+ window.addEventListener("pointerup", onUp);
1081
+ window.addEventListener("pointercancel", onUp);
1082
+ dragRef.current = { cleanup };
1083
+ },
1084
+ []
1085
+ );
1086
+ (0, import_react7.useEffect)(() => {
1087
+ return () => {
1088
+ dragRef.current?.cleanup();
1089
+ };
1090
+ }, []);
1091
+ const beginPlayheadDrag = (0, import_react7.useCallback)(
1092
+ (e) => {
1093
+ beginDrag(e, (ev, stripRect) => {
1094
+ const t = pxToTime(ev.clientX, stripRect);
1095
+ onSeek(
1096
+ snapTime(
1097
+ clampValue2(t, 0, propsRef.current.videoDuration),
1098
+ ev.shiftKey
1099
+ )
1100
+ );
1101
+ });
1102
+ },
1103
+ [beginDrag, onSeek, pxToTime]
1104
+ );
1105
+ const beginKeyframeDrag = (0, import_react7.useCallback)(
1106
+ (id, startTime) => (e) => {
1107
+ const startX = e.clientX;
1108
+ beginDrag(e, (ev) => {
1109
+ const dt = (ev.clientX - startX) / propsRef.current.zoom;
1110
+ const t = snapTime(
1111
+ clampValue2(startTime + dt, 0, propsRef.current.videoDuration),
1112
+ ev.shiftKey
1113
+ );
1114
+ onUpdateEntry(id, { timestamp: t });
1115
+ });
1116
+ },
1117
+ [beginDrag, onUpdateEntry]
1118
+ );
1119
+ const beginRangeDrag = (0, import_react7.useCallback)(
1120
+ (id, edge, startStart, startEnd) => (e) => {
1121
+ const startX = e.clientX;
1122
+ const duration = startEnd - startStart;
1123
+ beginDrag(e, (ev) => {
1124
+ const dt = (ev.clientX - startX) / propsRef.current.zoom;
1125
+ if (edge === "body") {
1126
+ const nextStart = snapTime(
1127
+ clampValue2(
1128
+ startStart + dt,
1129
+ 0,
1130
+ propsRef.current.videoDuration - duration
1131
+ ),
1132
+ ev.shiftKey
1133
+ );
1134
+ onUpdateEntry(id, {
1135
+ start: nextStart,
1136
+ end: nextStart + duration
1137
+ });
1138
+ } else if (edge === "start") {
1139
+ const nextStart = snapTime(
1140
+ clampValue2(startStart + dt, 0, startEnd - MIN_RANGE),
1141
+ ev.shiftKey
1142
+ );
1143
+ onUpdateEntry(id, { start: nextStart });
1144
+ } else {
1145
+ const nextEnd = snapTime(
1146
+ clampValue2(
1147
+ startEnd + dt,
1148
+ startStart + MIN_RANGE,
1149
+ propsRef.current.videoDuration
1150
+ ),
1151
+ ev.shiftKey
1152
+ );
1153
+ onUpdateEntry(id, { end: nextEnd });
1154
+ }
1155
+ });
1156
+ },
1157
+ [beginDrag, onUpdateEntry]
1158
+ );
1159
+ (0, import_react7.useEffect)(() => {
1160
+ const el = scrollRef.current;
1161
+ if (!el) return;
1162
+ const onWheel = (e) => {
1163
+ e.preventDefault();
1164
+ userZoomedRef.current = true;
1165
+ setZoom(
1166
+ (z) => clampValue2(e.deltaY < 0 ? z * 1.2 : z / 1.2, MIN_ZOOM, MAX_ZOOM)
1167
+ );
1168
+ };
1169
+ el.addEventListener("wheel", onWheel, { passive: false });
1170
+ return () => el.removeEventListener("wheel", onWheel);
1171
+ }, []);
1172
+ const handleZoom = (0, import_react7.useCallback)((direction) => {
1173
+ userZoomedRef.current = true;
1174
+ setZoom(
1175
+ (z) => clampValue2(direction > 0 ? z * 1.5 : z / 1.5, MIN_ZOOM, MAX_ZOOM)
1176
+ );
1177
+ }, []);
1178
+ const handleKeyframeKeyDown = (0, import_react7.useCallback)(
1179
+ (entry) => (e) => {
1180
+ const step = e.shiftKey ? 5 : 1;
1181
+ let updates = null;
1182
+ if (entry.hookType === "blocking") {
1183
+ const base = Math.round(entry.timestamp ?? 0);
1184
+ if (e.key === "ArrowLeft")
1185
+ updates = {
1186
+ timestamp: clampValue2(
1187
+ base - step,
1188
+ 0,
1189
+ propsRef.current.videoDuration
1190
+ )
1191
+ };
1192
+ if (e.key === "ArrowRight")
1193
+ updates = {
1194
+ timestamp: clampValue2(
1195
+ base + step,
1196
+ 0,
1197
+ propsRef.current.videoDuration
1198
+ )
1199
+ };
1200
+ } else {
1201
+ const s = Math.round(entry.start ?? 0);
1202
+ const en = Math.round(entry.end ?? 0);
1203
+ const dur = en - s;
1204
+ if (e.key === "ArrowLeft") {
1205
+ const next = clampValue2(
1206
+ s - step,
1207
+ 0,
1208
+ propsRef.current.videoDuration - dur
1209
+ );
1210
+ updates = { start: next, end: next + dur };
1211
+ }
1212
+ if (e.key === "ArrowRight") {
1213
+ const next = clampValue2(
1214
+ s + step,
1215
+ 0,
1216
+ propsRef.current.videoDuration - dur
1217
+ );
1218
+ updates = { start: next, end: next + dur };
1219
+ }
1220
+ }
1221
+ if (!updates) return;
1222
+ e.preventDefault();
1223
+ e.stopPropagation();
1224
+ onUpdateEntry(entry.id, updates);
1225
+ },
1226
+ [onUpdateEntry]
1227
+ );
1228
+ const handlePlayheadKeyDown = (0, import_react7.useCallback)(
1229
+ (e) => {
1230
+ const step = e.shiftKey ? 5 : 1;
1231
+ let t = null;
1232
+ if (e.key === "ArrowLeft")
1233
+ t = clampValue2(
1234
+ propsRef.current.currentTime - step,
1235
+ 0,
1236
+ propsRef.current.videoDuration
1237
+ );
1238
+ if (e.key === "ArrowRight")
1239
+ t = clampValue2(
1240
+ propsRef.current.currentTime + step,
1241
+ 0,
1242
+ propsRef.current.videoDuration
1243
+ );
1244
+ if (t == null) return;
1245
+ e.preventDefault();
1246
+ e.stopPropagation();
1247
+ onSeek(t);
1248
+ },
1249
+ [onSeek]
1250
+ );
1251
+ const handleRulerSeek = (0, import_react7.useCallback)(
1252
+ (e) => {
1253
+ if (typeof e.button === "number" && e.button !== 0) return;
1254
+ const strip = stripRef.current;
1255
+ if (!strip) return;
1256
+ const stripRect = strip.getBoundingClientRect();
1257
+ if (stripRect.width <= 0) return;
1258
+ const t = (e.clientX - stripRect.left) / propsRef.current.zoom;
1259
+ onSeek(
1260
+ snapTime(clampValue2(t, 0, propsRef.current.videoDuration), e.shiftKey)
1261
+ );
1262
+ },
1263
+ [onSeek]
1264
+ );
1265
+ const layout = (0, import_react7.useMemo)(() => {
1266
+ const sorted = [...entries].sort((a, b) => anchorOf(a) - anchorOf(b));
1267
+ const laneEnds = [];
1268
+ const lanes = /* @__PURE__ */ new Map();
1269
+ for (const entry of sorted) {
1270
+ const start = anchorOf(entry);
1271
+ const end = start + extentOf(entry, zoom);
1272
+ let lane = laneEnds.findIndex((laneEnd) => laneEnd <= start);
1273
+ if (lane === -1) {
1274
+ lane = laneEnds.length;
1275
+ laneEnds.push(end);
1276
+ } else {
1277
+ laneEnds[lane] = end;
1278
+ }
1279
+ lanes.set(entry.id, lane);
1280
+ }
1281
+ return { lanes, laneCount: Math.max(laneEnds.length, 1) };
1282
+ }, [entries, zoom]);
1283
+ const interval = tickInterval(zoom);
1284
+ const ticks = [];
1285
+ for (let t = 0; t <= videoDuration; t += interval) {
1286
+ ticks.push(Math.round(t * 100) / 100);
1287
+ }
1288
+ const playheadPx = currentTime * zoom;
1289
+ const laneHeight = clampValue2(
1290
+ Math.floor(
1291
+ (TRACK_HEIGHT_BUDGET - TRACK_PADDING) / Math.max(1, layout.laneCount)
1292
+ ),
1293
+ MIN_LANE_HEIGHT,
1294
+ LANE_HEIGHT
1295
+ );
1296
+ const trackHeight = Math.max(
1297
+ 48,
1298
+ layout.laneCount * laneHeight + TRACK_PADDING
1299
+ );
1300
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1301
+ "div",
1302
+ {
1303
+ className: "keyframe-timeline",
1304
+ "data-testid": "keyframe-timeline",
1305
+ style: {
1306
+ border: `1px solid ${COLORS.border}`,
1307
+ borderRadius: RADIUS.md,
1308
+ backgroundColor: COLORS.surfaceRaised,
1309
+ padding: SPACE[2],
1310
+ display: "flex",
1311
+ flexDirection: "column",
1312
+ gap: SPACE[2]
1313
+ },
1314
+ children: [
1315
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1316
+ "div",
1317
+ {
1318
+ "data-testid": "keyframe-timeline-controls",
1319
+ style: {
1320
+ display: "flex",
1321
+ gap: SPACE[2],
1322
+ alignItems: "center",
1323
+ flexWrap: "wrap"
1324
+ },
1325
+ children: [
1326
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1327
+ "button",
1328
+ {
1329
+ type: "button",
1330
+ onClick: onTogglePlay,
1331
+ "data-testid": "keyframe-timeline-play",
1332
+ "aria-label": isPlaying ? strings.pauseLabel : strings.playLabel,
1333
+ style: {
1334
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
1335
+ backgroundColor: COLORS.accent,
1336
+ color: COLORS.white,
1337
+ border: "none",
1338
+ borderRadius: RADIUS.sm,
1339
+ cursor: "pointer",
1340
+ fontSize: TYPE.sm,
1341
+ fontWeight: 600,
1342
+ transition: "background-color 150ms ease"
1343
+ },
1344
+ children: isPlaying ? strings.pauseLabel : strings.playLabel
1345
+ }
1346
+ ),
1347
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1348
+ "button",
1349
+ {
1350
+ type: "button",
1351
+ onClick: () => onAddEntry("blocking"),
1352
+ "data-testid": "keyframe-timeline-add-blocking",
1353
+ style: {
1354
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
1355
+ backgroundColor: COLORS.accent,
1356
+ color: COLORS.white,
1357
+ border: "none",
1358
+ borderRadius: RADIUS.sm,
1359
+ cursor: "pointer",
1360
+ fontSize: TYPE.sm,
1361
+ fontWeight: 600,
1362
+ transition: "background-color 150ms ease"
1363
+ },
1364
+ children: strings.addBlockingLabel
1365
+ }
1366
+ ),
1367
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1368
+ "button",
1369
+ {
1370
+ type: "button",
1371
+ onClick: () => onAddEntry("non-blocking"),
1372
+ "data-testid": "keyframe-timeline-add-non-blocking",
1373
+ style: {
1374
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
1375
+ backgroundColor: COLORS.accent,
1376
+ color: COLORS.white,
1377
+ border: "none",
1378
+ borderRadius: RADIUS.sm,
1379
+ cursor: "pointer",
1380
+ fontSize: TYPE.sm,
1381
+ fontWeight: 600,
1382
+ transition: "background-color 150ms ease"
1383
+ },
1384
+ children: strings.addNonBlockingLabel
1385
+ }
1386
+ ),
1387
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { flex: 1 } }),
1388
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1389
+ "button",
1390
+ {
1391
+ type: "button",
1392
+ onClick: () => handleZoom(-1),
1393
+ "data-testid": "keyframe-timeline-zoom-out",
1394
+ "aria-label": strings.zoomOutLabel,
1395
+ style: {
1396
+ padding: `${SPACE[1]}px 10px`,
1397
+ backgroundColor: COLORS.surface,
1398
+ border: `1px solid ${COLORS.borderStrong}`,
1399
+ borderRadius: RADIUS.sm,
1400
+ cursor: "pointer",
1401
+ fontSize: TYPE.sm,
1402
+ color: COLORS.text,
1403
+ transition: "background-color 150ms ease"
1404
+ },
1405
+ children: "\u2212"
1406
+ }
1407
+ ),
1408
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1409
+ "button",
1410
+ {
1411
+ type: "button",
1412
+ onClick: () => handleZoom(1),
1413
+ "data-testid": "keyframe-timeline-zoom-in",
1414
+ "aria-label": strings.zoomInLabel,
1415
+ style: {
1416
+ padding: `${SPACE[1]}px 10px`,
1417
+ backgroundColor: COLORS.surface,
1418
+ border: `1px solid ${COLORS.borderStrong}`,
1419
+ borderRadius: RADIUS.sm,
1420
+ cursor: "pointer",
1421
+ fontSize: TYPE.sm,
1422
+ color: COLORS.text,
1423
+ transition: "background-color 150ms ease"
1424
+ },
1425
+ children: "+"
1426
+ }
1427
+ )
1428
+ ]
1429
+ }
1430
+ ),
1431
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1432
+ "div",
1433
+ {
1434
+ ref: scrollRef,
1435
+ "data-testid": "keyframe-timeline-scroll",
1436
+ style: {
1437
+ overflowX: "auto",
1438
+ overflowY: "hidden",
1439
+ position: "relative",
1440
+ maxHeight: RULER_HEIGHT + TRACK_HEIGHT_BUDGET
1441
+ },
1442
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1443
+ "div",
1444
+ {
1445
+ ref: stripRef,
1446
+ "data-testid": "keyframe-timeline-strip",
1447
+ style: { position: "relative", width: stripWidth, minWidth: "100%" },
1448
+ children: [
1449
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1450
+ "div",
1451
+ {
1452
+ role: "slider",
1453
+ "aria-label": strings.rulerLabel,
1454
+ "aria-valuemin": 0,
1455
+ "aria-valuemax": Math.round(videoDuration),
1456
+ "aria-valuenow": Math.round(currentTime),
1457
+ tabIndex: 0,
1458
+ "data-testid": "keyframe-timeline-ruler",
1459
+ onPointerDown: (e) => {
1460
+ handleRulerSeek(e);
1461
+ beginPlayheadDrag(e);
1462
+ },
1463
+ onKeyDown: handlePlayheadKeyDown,
1464
+ style: {
1465
+ position: "relative",
1466
+ height: 24,
1467
+ backgroundColor: COLORS.surfaceRaised,
1468
+ borderBottom: `1px solid ${COLORS.border}`,
1469
+ cursor: "pointer",
1470
+ userSelect: "none",
1471
+ touchAction: "none"
1472
+ },
1473
+ children: ticks.map((t) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1474
+ "div",
1475
+ {
1476
+ "data-testid": `keyframe-timeline-tick-${t}`,
1477
+ style: {
1478
+ position: "absolute",
1479
+ left: t * zoom,
1480
+ top: 0,
1481
+ bottom: 0,
1482
+ borderLeft: `1px solid ${COLORS.borderStrong}`,
1483
+ paddingLeft: SPACE[1],
1484
+ fontSize: TYPE.xs,
1485
+ color: COLORS.textMuted,
1486
+ lineHeight: "24px",
1487
+ whiteSpace: "nowrap"
1488
+ },
1489
+ children: formatTick(t)
1490
+ },
1491
+ t
1492
+ ))
1493
+ }
1494
+ ),
1495
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1496
+ "div",
1497
+ {
1498
+ role: "listbox",
1499
+ "aria-label": strings.trackLabel,
1500
+ "data-testid": "keyframe-timeline-track",
1501
+ onPointerDown: (e) => {
1502
+ if (e.target !== e.currentTarget) return;
1503
+ onDeselect?.();
1504
+ },
1505
+ style: {
1506
+ position: "relative",
1507
+ height: trackHeight
1508
+ },
1509
+ children: entries.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1510
+ "p",
1511
+ {
1512
+ "data-testid": "keyframe-timeline-empty",
1513
+ style: {
1514
+ margin: 0,
1515
+ padding: "14px 12px",
1516
+ color: COLORS.textMuted,
1517
+ fontSize: TYPE.sm
1518
+ },
1519
+ children: strings.emptyLabel
1520
+ }
1521
+ ) : entries.map((entry) => {
1522
+ const selected = entry.id === selectedId;
1523
+ const accent = COLORS.accent;
1524
+ const lane = layout.lanes.get(entry.id) ?? 0;
1525
+ const laneTop = 3 + lane * laneHeight;
1526
+ if (entry.hookType === "blocking") {
1527
+ const px = (entry.timestamp ?? 0) * zoom;
1528
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1529
+ "button",
1530
+ {
1531
+ type: "button",
1532
+ "data-testid": "timeline-keyframe",
1533
+ "data-content-id": entry.id,
1534
+ "aria-label": `${entry.title} \u2014 ${strings.blockingKeyframeLabel} ${formatTick(Math.round(entry.timestamp ?? 0))}`,
1535
+ onClick: () => onSelectEntry(entry.id),
1536
+ onKeyDown: handleKeyframeKeyDown(entry),
1537
+ style: {
1538
+ position: "absolute",
1539
+ left: px - 7,
1540
+ top: laneTop + 5,
1541
+ width: 14,
1542
+ height: 14,
1543
+ transform: "rotate(45deg)",
1544
+ backgroundColor: selected ? accent : COLORS.surface,
1545
+ border: `2px solid ${accent}`,
1546
+ borderRadius: 2,
1547
+ cursor: "grab",
1548
+ padding: 0,
1549
+ touchAction: "none",
1550
+ boxShadow: selected ? SHADOWS.sm : "none"
1551
+ },
1552
+ onPointerDown: beginKeyframeDrag(
1553
+ entry.id,
1554
+ entry.timestamp ?? 0
1555
+ ),
1556
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1557
+ "span",
1558
+ {
1559
+ style: {
1560
+ position: "absolute",
1561
+ left: 16,
1562
+ top: -2,
1563
+ transform: "rotate(-45deg)",
1564
+ fontSize: TYPE.xs,
1565
+ color: selected ? COLORS.accent : COLORS.text,
1566
+ whiteSpace: "nowrap",
1567
+ fontWeight: selected ? 700 : 400
1568
+ },
1569
+ children: entry.title
1570
+ }
1571
+ )
1572
+ },
1573
+ entry.id
1574
+ );
1575
+ }
1576
+ const startPx = (entry.start ?? 0) * zoom;
1577
+ const widthPx = Math.max(
1578
+ ((entry.end ?? 0) - (entry.start ?? 0)) * zoom,
1579
+ 12
1580
+ );
1581
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1582
+ "div",
1583
+ {
1584
+ "data-testid": "timeline-range",
1585
+ "data-content-id": entry.id,
1586
+ style: {
1587
+ position: "absolute",
1588
+ left: startPx,
1589
+ width: widthPx,
1590
+ top: laneTop,
1591
+ height: laneHeight - 4,
1592
+ backgroundColor: selected ? COLORS.accentLight : COLORS.accentLighter,
1593
+ border: `2px solid ${COLORS.accent}`,
1594
+ borderRadius: RADIUS.sm,
1595
+ boxSizing: "border-box",
1596
+ display: "flex",
1597
+ alignItems: "center",
1598
+ overflow: "hidden",
1599
+ touchAction: "none"
1600
+ },
1601
+ children: [
1602
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1603
+ "div",
1604
+ {
1605
+ role: "separator",
1606
+ "aria-label": `${entry.title} \u2014 resize start`,
1607
+ "data-testid": "timeline-range-start",
1608
+ onPointerDown: beginRangeDrag(
1609
+ entry.id,
1610
+ "start",
1611
+ entry.start ?? 0,
1612
+ entry.end ?? 0
1613
+ ),
1614
+ style: {
1615
+ width: 8,
1616
+ alignSelf: "stretch",
1617
+ cursor: "ew-resize",
1618
+ backgroundColor: COLORS.accent,
1619
+ touchAction: "none"
1620
+ }
1621
+ }
1622
+ ),
1623
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1624
+ "button",
1625
+ {
1626
+ type: "button",
1627
+ "data-testid": "timeline-keyframe",
1628
+ "data-content-id": entry.id,
1629
+ "aria-label": `${entry.title} \u2014 ${strings.nonBlockingRangeLabel} ${formatTick(Math.round(entry.start ?? 0))} to ${formatTick(Math.round(entry.end ?? 0))}`,
1630
+ onClick: () => onSelectEntry(entry.id),
1631
+ onKeyDown: handleKeyframeKeyDown(entry),
1632
+ onPointerDown: beginRangeDrag(
1633
+ entry.id,
1634
+ "body",
1635
+ entry.start ?? 0,
1636
+ entry.end ?? 0
1637
+ ),
1638
+ style: {
1639
+ flex: 1,
1640
+ alignSelf: "stretch",
1641
+ backgroundColor: "transparent",
1642
+ border: "none",
1643
+ cursor: "grab",
1644
+ fontSize: TYPE.xs,
1645
+ color: COLORS.text,
1646
+ padding: `0 ${SPACE[1]}px`,
1647
+ textAlign: "left",
1648
+ whiteSpace: "nowrap",
1649
+ overflow: "hidden",
1650
+ textOverflow: "ellipsis",
1651
+ fontWeight: selected ? 700 : 400,
1652
+ touchAction: "none"
1653
+ },
1654
+ children: entry.title
1655
+ }
1656
+ ),
1657
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1658
+ "div",
1659
+ {
1660
+ role: "separator",
1661
+ "aria-label": `${entry.title} \u2014 resize end`,
1662
+ "data-testid": "timeline-range-end",
1663
+ onPointerDown: beginRangeDrag(
1664
+ entry.id,
1665
+ "end",
1666
+ entry.start ?? 0,
1667
+ entry.end ?? 0
1668
+ ),
1669
+ style: {
1670
+ width: 8,
1671
+ alignSelf: "stretch",
1672
+ cursor: "ew-resize",
1673
+ backgroundColor: COLORS.accent,
1674
+ touchAction: "none"
1675
+ }
1676
+ }
1677
+ )
1678
+ ]
1679
+ },
1680
+ entry.id
1681
+ );
1682
+ })
1683
+ }
1684
+ ),
1685
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1686
+ "div",
1687
+ {
1688
+ "data-testid": "keyframe-timeline-playhead",
1689
+ style: {
1690
+ position: "absolute",
1691
+ left: playheadPx,
1692
+ top: 0,
1693
+ bottom: 0,
1694
+ width: 0,
1695
+ borderLeft: `2px solid ${COLORS.accent}`,
1696
+ pointerEvents: "none"
1697
+ },
1698
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1699
+ "div",
1700
+ {
1701
+ role: "slider",
1702
+ "aria-label": strings.playheadLabel,
1703
+ "aria-valuemin": 0,
1704
+ "aria-valuemax": Math.round(videoDuration),
1705
+ "aria-valuenow": Math.round(currentTime),
1706
+ "aria-valuetext": `${currentTime.toFixed(1)}s`,
1707
+ tabIndex: 0,
1708
+ "data-testid": "keyframe-timeline-playhead-handle",
1709
+ onPointerDown: beginPlayheadDrag,
1710
+ onKeyDown: handlePlayheadKeyDown,
1711
+ style: {
1712
+ position: "absolute",
1713
+ left: -7,
1714
+ top: 0,
1715
+ width: 12,
1716
+ height: 14,
1717
+ backgroundColor: COLORS.accent,
1718
+ borderRadius: "2px 2px 4px 4px",
1719
+ cursor: "ew-resize",
1720
+ pointerEvents: "auto",
1721
+ touchAction: "none"
1722
+ }
1723
+ }
1724
+ )
1725
+ }
1726
+ )
1727
+ ]
1728
+ }
1729
+ )
1730
+ }
1731
+ )
1732
+ ]
1733
+ }
1734
+ );
1735
+ };
1736
+
1737
+ // src/components/preview-modal.tsx
1738
+ var import_core4 = require("@interlacejs/core");
1739
+ var import_player = require("@interlacejs/player");
1740
+ var import_native_adapter = require("@interlacejs/native-adapter");
1741
+ var import_react8 = require("react");
1742
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1743
+ var DEFAULT_PREVIEW_MODAL_STRINGS = {
1744
+ ...import_core4.DEFAULT_STRINGS,
1745
+ title: "Preview",
1746
+ loadingLabel: "Loading player\u2026"
1747
+ };
1748
+ function PreviewModal({
1749
+ isOpen,
1750
+ videoSrc,
1751
+ document,
1752
+ contentTypeRegistry,
1753
+ onClose,
1754
+ strings: stringsOverride,
1755
+ onError
1756
+ }) {
1757
+ const strings = { ...DEFAULT_PREVIEW_MODAL_STRINGS, ...stringsOverride };
1758
+ const videoRef = (0, import_react8.useRef)(null);
1759
+ const closeButtonRef = (0, import_react8.useRef)(null);
1760
+ const previouslyFocusedRef = (0, import_react8.useRef)(null);
1761
+ const onErrorRef = (0, import_react8.useRef)(onError);
1762
+ onErrorRef.current = onError;
1763
+ const onCloseRef = (0, import_react8.useRef)(onClose);
1764
+ onCloseRef.current = onClose;
1765
+ const [adapter, setAdapter] = (0, import_react8.useState)(null);
1766
+ const [aspectRatio, setAspectRatio] = (0, import_react8.useState)(null);
1767
+ (0, import_react8.useEffect)(() => {
1768
+ if (!isOpen) {
1769
+ setAdapter(null);
1770
+ return;
1771
+ }
1772
+ const video = videoRef.current;
1773
+ if (!video) {
1774
+ return;
1775
+ }
1776
+ let native = null;
1777
+ try {
1778
+ native = new import_native_adapter.NativeVideoAdapter(video);
1779
+ setAdapter(native);
1780
+ } catch (err) {
1781
+ const error = err instanceof Error ? err : new Error(String(err));
1782
+ onErrorRef.current?.(error);
1783
+ setAdapter(null);
1784
+ return;
1785
+ }
1786
+ return () => {
1787
+ try {
1788
+ native?.destroy();
1789
+ } catch {
1790
+ }
1791
+ setAdapter(null);
1792
+ };
1793
+ }, [isOpen, videoSrc]);
1794
+ (0, import_react8.useEffect)(() => {
1795
+ if (!isOpen) return;
1796
+ previouslyFocusedRef.current = globalThis.document?.activeElement ?? null;
1797
+ closeButtonRef.current?.focus();
1798
+ return () => {
1799
+ const prev = previouslyFocusedRef.current;
1800
+ if (prev && typeof prev.focus === "function") {
1801
+ prev.focus();
1802
+ }
1803
+ };
1804
+ }, [isOpen]);
1805
+ (0, import_react8.useEffect)(() => {
1806
+ if (!isOpen) return;
1807
+ const handleKey = (e) => {
1808
+ if (e.key === "Escape") onCloseRef.current();
1809
+ };
1810
+ window.addEventListener("keydown", handleKey);
1811
+ return () => window.removeEventListener("keydown", handleKey);
1812
+ }, [isOpen]);
1813
+ const handleBackdropClick = (0, import_react8.useCallback)(
1814
+ (e) => {
1815
+ if (e.target === e.currentTarget) onCloseRef.current();
1816
+ },
1817
+ []
1818
+ );
1819
+ const handleLoadedMetadata = (0, import_react8.useCallback)(
1820
+ (e) => {
1821
+ const v = e.currentTarget;
1822
+ if (v.videoWidth > 0 && v.videoHeight > 0) {
1823
+ setAspectRatio(v.videoWidth / v.videoHeight);
1824
+ }
1825
+ },
1826
+ []
1827
+ );
1828
+ if (!isOpen) return null;
1829
+ const containerAspectRatio = aspectRatio ?? 16 / 9;
1830
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1831
+ "div",
1832
+ {
1833
+ className: "preview-modal-backdrop",
1834
+ "data-testid": "preview-modal-backdrop",
1835
+ role: "presentation",
1836
+ onClick: handleBackdropClick,
1837
+ style: {
1838
+ position: "fixed",
1839
+ top: 0,
1840
+ left: 0,
1841
+ right: 0,
1842
+ bottom: 0,
1843
+ backgroundColor: "rgba(0, 0, 0, 0.7)",
1844
+ zIndex: 1e3,
1845
+ display: "flex",
1846
+ alignItems: "center",
1847
+ justifyContent: "center"
1848
+ },
1849
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1850
+ "div",
1851
+ {
1852
+ className: "preview-modal",
1853
+ "data-testid": "preview-modal",
1854
+ role: "dialog",
1855
+ "aria-modal": "true",
1856
+ "aria-label": strings.title,
1857
+ onClick: handleBackdropClick,
1858
+ style: {
1859
+ position: "relative",
1860
+ backgroundColor: COLORS.black,
1861
+ borderRadius: RADIUS.lg,
1862
+ padding: SPACE[4],
1863
+ maxWidth: "90vw",
1864
+ maxHeight: "90vh",
1865
+ display: "flex",
1866
+ flexDirection: "column",
1867
+ gap: SPACE[2],
1868
+ boxShadow: "0 16px 48px rgba(0, 0, 0, 0.35)"
1869
+ },
1870
+ children: [
1871
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1872
+ "div",
1873
+ {
1874
+ style: {
1875
+ display: "flex",
1876
+ justifyContent: "space-between",
1877
+ alignItems: "center",
1878
+ color: COLORS.white
1879
+ },
1880
+ children: [
1881
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1882
+ "h3",
1883
+ {
1884
+ style: {
1885
+ margin: 0,
1886
+ fontFamily: FONTS.display,
1887
+ fontSize: TYPE.md,
1888
+ fontWeight: 600
1889
+ },
1890
+ children: strings.title
1891
+ }
1892
+ ),
1893
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1894
+ "button",
1895
+ {
1896
+ ref: closeButtonRef,
1897
+ type: "button",
1898
+ onClick: onClose,
1899
+ "data-testid": "preview-modal-close",
1900
+ "aria-label": strings.closeLabel,
1901
+ style: {
1902
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
1903
+ backgroundColor: "transparent",
1904
+ border: `1px solid ${COLORS.borderStrong}`,
1905
+ color: COLORS.white,
1906
+ borderRadius: RADIUS.sm,
1907
+ cursor: "pointer",
1908
+ fontSize: TYPE.sm,
1909
+ transition: "background-color 150ms ease, border-color 150ms ease"
1910
+ },
1911
+ children: strings.closeLabel
1912
+ }
1913
+ )
1914
+ ]
1915
+ }
1916
+ ),
1917
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1918
+ "div",
1919
+ {
1920
+ className: "preview-modal-content",
1921
+ "data-testid": "preview-modal-content",
1922
+ style: {
1923
+ position: "relative",
1924
+ width: "min(80vw, 960px)",
1925
+ aspectRatio: String(containerAspectRatio),
1926
+ backgroundColor: "#000"
1927
+ },
1928
+ children: [
1929
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1930
+ "div",
1931
+ {
1932
+ className: "preview-modal-video-container",
1933
+ "data-testid": "preview-modal-video-container",
1934
+ style: { width: "100%", height: "100%" },
1935
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1936
+ "video",
1937
+ {
1938
+ ref: videoRef,
1939
+ src: videoSrc,
1940
+ controls: true,
1941
+ preload: "metadata",
1942
+ onLoadedMetadata: handleLoadedMetadata,
1943
+ "data-testid": "preview-modal-video",
1944
+ style: {
1945
+ width: "100%",
1946
+ height: "100%",
1947
+ display: "block"
1948
+ }
1949
+ }
1950
+ )
1951
+ }
1952
+ ),
1953
+ adapter ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1954
+ "div",
1955
+ {
1956
+ className: "preview-modal-player-container",
1957
+ "data-testid": "preview-modal-player-container",
1958
+ style: {
1959
+ position: "absolute",
1960
+ top: 0,
1961
+ left: 0,
1962
+ width: "100%",
1963
+ height: "100%",
1964
+ pointerEvents: "none"
1965
+ },
1966
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1967
+ import_player.InteractiveVideoPlayer,
1968
+ {
1969
+ adapter,
1970
+ document,
1971
+ registry: contentTypeRegistry,
1972
+ onError: onErrorRef.current
1973
+ }
1974
+ )
1975
+ }
1976
+ ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1977
+ "div",
1978
+ {
1979
+ "data-testid": "preview-modal-loading",
1980
+ style: {
1981
+ position: "absolute",
1982
+ top: 0,
1983
+ left: 0,
1984
+ width: "100%",
1985
+ height: "100%",
1986
+ display: "flex",
1987
+ alignItems: "center",
1988
+ justifyContent: "center",
1989
+ color: COLORS.textMuted,
1990
+ fontSize: TYPE.sm
1991
+ },
1992
+ children: strings.loadingLabel
1993
+ }
1994
+ )
1995
+ ]
1996
+ }
1997
+ )
1998
+ ]
1999
+ }
2000
+ )
2001
+ }
2002
+ );
2003
+ }
2004
+
2005
+ // src/components/video-source-input.tsx
2006
+ var import_core5 = require("@interlacejs/core");
2007
+ var import_react9 = require("react");
2008
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2009
+ var DEFAULT_VIDEO_SOURCE_INPUT_STRINGS = {
2010
+ ...import_core5.DEFAULT_STRINGS,
2011
+ uploadLabel: "Upload a video file",
2012
+ uploadButtonLabel: "Choose file",
2013
+ uploadingLabel: "Uploading\u2026",
2014
+ uploadFailedLabel: "Upload failed.",
2015
+ retryLabel: "Retry",
2016
+ urlLabel: "\u2026or paste a video URL",
2017
+ urlPlaceholder: "https://example.com/video.mp4",
2018
+ applyUrlLabel: "Use URL",
2019
+ noVideoSelectedLabel: "No video selected yet.",
2020
+ currentSourceLabel: "Current source"
2021
+ };
2022
+ function VideoSourceInput({
2023
+ value,
2024
+ onChange,
2025
+ onUpload,
2026
+ onError,
2027
+ strings: stringsOverride,
2028
+ disabled = false
2029
+ }) {
2030
+ const strings = { ...DEFAULT_VIDEO_SOURCE_INPUT_STRINGS, ...stringsOverride };
2031
+ const [urlDraft, setUrlDraft] = (0, import_react9.useState)(value?.src ?? "");
2032
+ const [uploadState, setUploadState] = (0, import_react9.useState)({ kind: "idle" });
2033
+ const fileInputRef = (0, import_react9.useRef)(null);
2034
+ const uploadTokenRef = (0, import_react9.useRef)(0);
2035
+ (0, import_react9.useEffect)(() => {
2036
+ setUrlDraft(value?.src ?? "");
2037
+ }, [value?.src]);
2038
+ (0, import_react9.useEffect)(() => {
2039
+ return () => {
2040
+ uploadTokenRef.current += 1;
2041
+ };
2042
+ }, []);
2043
+ const handleApplyUrl = (0, import_react9.useCallback)(() => {
2044
+ const trimmed = urlDraft.trim();
2045
+ if (!trimmed) return;
2046
+ onChange({ src: trimmed });
2047
+ }, [urlDraft, onChange]);
2048
+ const handleFileSelected = (0, import_react9.useCallback)(
2049
+ async (event) => {
2050
+ const file = event.target.files?.[0];
2051
+ event.target.value = "";
2052
+ if (!file) return;
2053
+ const token = ++uploadTokenRef.current;
2054
+ setUploadState({ kind: "uploading", fileName: file.name });
2055
+ let url;
2056
+ try {
2057
+ url = await onUpload(file);
2058
+ } catch (err) {
2059
+ if (token !== uploadTokenRef.current) return;
2060
+ const error = err instanceof Error ? err : new Error(String(err));
2061
+ setUploadState({ kind: "error", message: error.message });
2062
+ onError?.(error);
2063
+ return;
2064
+ }
2065
+ if (token !== uploadTokenRef.current) return;
2066
+ setUploadState({ kind: "idle" });
2067
+ onChange({ src: url });
2068
+ },
2069
+ [onUpload, onChange, onError]
2070
+ );
2071
+ const handleRetryUpload = (0, import_react9.useCallback)(() => {
2072
+ setUploadState({ kind: "idle" });
2073
+ fileInputRef.current?.click();
2074
+ }, []);
2075
+ const isUploading = uploadState.kind === "uploading";
2076
+ const hasError = uploadState.kind === "error";
2077
+ const isDisabled = disabled || isUploading;
2078
+ const applyDisabled = isDisabled || urlDraft.trim().length === 0;
2079
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2080
+ "div",
2081
+ {
2082
+ className: "video-source-input",
2083
+ style: {
2084
+ display: "flex",
2085
+ flexDirection: "column",
2086
+ gap: `${SPACE[4]}px`,
2087
+ padding: `${SPACE[4]}px`,
2088
+ border: `1px solid ${COLORS.border}`,
2089
+ borderRadius: `${RADIUS.md}px`,
2090
+ backgroundColor: COLORS.surfaceRaised
2091
+ },
2092
+ children: [
2093
+ value?.src ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2094
+ "div",
2095
+ {
2096
+ style: {
2097
+ padding: `${SPACE[3]}px ${SPACE[4]}px`,
2098
+ backgroundColor: COLORS.surface,
2099
+ border: `1px solid ${COLORS.border}`,
2100
+ borderRadius: `${RADIUS.sm}px`,
2101
+ fontSize: TYPE.sm,
2102
+ color: COLORS.text
2103
+ },
2104
+ children: [
2105
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { style: { color: COLORS.textMuted }, children: [
2106
+ strings.currentSourceLabel,
2107
+ ":"
2108
+ ] }),
2109
+ " ",
2110
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("code", { "data-testid": "video-source-input-current-src", children: value.src })
2111
+ ]
2112
+ }
2113
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2114
+ "p",
2115
+ {
2116
+ "data-testid": "video-source-input-empty",
2117
+ style: { margin: 0, color: COLORS.textMuted },
2118
+ children: strings.noVideoSelectedLabel
2119
+ }
2120
+ ),
2121
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
2122
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2123
+ "h4",
2124
+ {
2125
+ style: {
2126
+ margin: `0 0 ${SPACE[2]}px 0`,
2127
+ fontSize: TYPE.md,
2128
+ fontWeight: 600,
2129
+ color: COLORS.text
2130
+ },
2131
+ children: strings.uploadLabel
2132
+ }
2133
+ ),
2134
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2135
+ "input",
2136
+ {
2137
+ ref: fileInputRef,
2138
+ type: "file",
2139
+ accept: "video/*",
2140
+ onChange: handleFileSelected,
2141
+ disabled: isDisabled,
2142
+ "data-testid": "video-source-input-file",
2143
+ style: { display: "none" }
2144
+ }
2145
+ ),
2146
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2147
+ "button",
2148
+ {
2149
+ type: "button",
2150
+ onClick: () => fileInputRef.current?.click(),
2151
+ disabled: isDisabled,
2152
+ "data-testid": "video-source-input-file-button",
2153
+ style: {
2154
+ padding: `${SPACE[2]}px ${SPACE[4]}px`,
2155
+ backgroundColor: isDisabled ? COLORS.borderStrong : COLORS.accent,
2156
+ color: COLORS.white,
2157
+ border: "none",
2158
+ borderRadius: `${RADIUS.sm}px`,
2159
+ cursor: isDisabled ? "not-allowed" : "pointer",
2160
+ fontSize: TYPE.md,
2161
+ fontWeight: 600,
2162
+ transition: "background-color 150ms ease"
2163
+ },
2164
+ children: isUploading ? `${strings.uploadingLabel} (${uploadState.fileName})` : strings.uploadButtonLabel
2165
+ }
2166
+ ),
2167
+ isUploading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2168
+ "span",
2169
+ {
2170
+ "data-testid": "video-source-input-uploading",
2171
+ style: { marginLeft: `${SPACE[2]}px`, color: COLORS.textMuted, fontSize: TYPE.sm },
2172
+ "aria-live": "polite",
2173
+ children: strings.uploadingLabel
2174
+ }
2175
+ ) : null,
2176
+ hasError ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2177
+ "div",
2178
+ {
2179
+ "data-testid": "video-source-input-error",
2180
+ role: "alert",
2181
+ style: {
2182
+ marginTop: `${SPACE[2]}px`,
2183
+ color: COLORS.errorText,
2184
+ backgroundColor: COLORS.errorBg,
2185
+ padding: `${SPACE[2]}px`,
2186
+ borderRadius: `${RADIUS.sm}px`,
2187
+ border: `1px solid ${COLORS.errorBorder}`,
2188
+ fontSize: TYPE.sm
2189
+ },
2190
+ children: [
2191
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("strong", { children: strings.uploadFailedLabel }),
2192
+ " ",
2193
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: uploadState.message }),
2194
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2195
+ "button",
2196
+ {
2197
+ type: "button",
2198
+ onClick: handleRetryUpload,
2199
+ "data-testid": "video-source-input-retry",
2200
+ style: {
2201
+ marginLeft: `${SPACE[2]}px`,
2202
+ padding: `${SPACE[1]}px ${SPACE[2]}px`,
2203
+ backgroundColor: COLORS.surface,
2204
+ border: `1px solid ${COLORS.errorBorder}`,
2205
+ color: COLORS.errorText,
2206
+ borderRadius: `${RADIUS.sm}px`,
2207
+ cursor: "pointer",
2208
+ fontSize: TYPE.xs,
2209
+ fontWeight: 600
2210
+ },
2211
+ children: strings.retryLabel
2212
+ }
2213
+ )
2214
+ ]
2215
+ }
2216
+ ) : null
2217
+ ] }),
2218
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
2219
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2220
+ "label",
2221
+ {
2222
+ style: {
2223
+ display: "block",
2224
+ fontSize: TYPE.md,
2225
+ fontWeight: 600,
2226
+ marginBottom: `${SPACE[1]}px`,
2227
+ color: COLORS.text
2228
+ },
2229
+ children: strings.urlLabel
2230
+ }
2231
+ ),
2232
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
2233
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2234
+ "input",
2235
+ {
2236
+ type: "url",
2237
+ value: urlDraft,
2238
+ onChange: (e) => setUrlDraft(e.target.value),
2239
+ placeholder: strings.urlPlaceholder,
2240
+ disabled: isDisabled,
2241
+ "data-testid": "video-source-input-url",
2242
+ style: {
2243
+ flex: 1,
2244
+ padding: `${SPACE[2]}px ${SPACE[3]}px`,
2245
+ border: `1px solid ${COLORS.borderStrong}`,
2246
+ borderRadius: `${RADIUS.sm}px`,
2247
+ fontSize: TYPE.md,
2248
+ color: COLORS.text
2249
+ },
2250
+ onKeyDown: (e) => {
2251
+ if (e.key === "Enter" && !applyDisabled) {
2252
+ e.preventDefault();
2253
+ handleApplyUrl();
2254
+ }
2255
+ }
2256
+ }
2257
+ ),
2258
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2259
+ "button",
2260
+ {
2261
+ type: "button",
2262
+ onClick: handleApplyUrl,
2263
+ disabled: applyDisabled,
2264
+ "data-testid": "video-source-input-apply",
2265
+ style: {
2266
+ padding: `${SPACE[2]}px ${SPACE[4]}px`,
2267
+ backgroundColor: applyDisabled ? COLORS.borderStrong : COLORS.accent,
2268
+ color: COLORS.white,
2269
+ border: "none",
2270
+ borderRadius: `${RADIUS.sm}px`,
2271
+ cursor: applyDisabled ? "not-allowed" : "pointer",
2272
+ fontSize: TYPE.md,
2273
+ fontWeight: 600,
2274
+ transition: "background-color 150ms ease"
2275
+ },
2276
+ children: strings.applyUrlLabel
2277
+ }
2278
+ )
2279
+ ] })
2280
+ ] })
2281
+ ]
2282
+ }
2283
+ );
2284
+ }
2285
+
2286
+ // src/components/interlace-editor.tsx
2287
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2288
+ var DEFAULT_EDITOR_STRINGS = {
2289
+ ...import_core6.DEFAULT_STRINGS,
2290
+ videoSourceInputTitle: "Add a video",
2291
+ previewTitle: "Preview",
2292
+ previewLabel: "Preview",
2293
+ replaceVideoLabel: "Replace video",
2294
+ replaceCancelLabel: "Cancel replace",
2295
+ saveLabel: "Save",
2296
+ noItemSelectedLabel: "Select an item to edit its placement.",
2297
+ placementLabel: "Placement",
2298
+ timelineHeading: "Hooks",
2299
+ addContentHeading: "Add content",
2300
+ hookHeading: "Hook",
2301
+ contentEditorHeading: "Content",
2302
+ editContentLabel: "Edit content",
2303
+ loadErrorTitle: "Could not load the document",
2304
+ durationUnknownLabel: "Duration unknown"
2305
+ };
2306
+ var DEFAULT_PLACEMENT = { x: 50, y: 50, width: 20, height: 20 };
2307
+ function makeDefaultData(contentTypeId) {
2308
+ if (contentTypeId === "quiz" || contentTypeId === "quiz-editor") {
2309
+ return {
2310
+ questions: [
2311
+ {
2312
+ id: "q-0",
2313
+ text: "",
2314
+ options: [
2315
+ { id: "opt-0", text: "" },
2316
+ { id: "opt-1", text: "" }
2317
+ ],
2318
+ correctOptionId: "opt-0"
2319
+ }
2320
+ ]
2321
+ };
2322
+ }
2323
+ return {};
2324
+ }
2325
+ function makeHook(hookType, atTime, videoDuration) {
2326
+ if (hookType === "blocking") {
2327
+ return {
2328
+ type: "blocking",
2329
+ timestamp: Math.max(0, atTime),
2330
+ placement: DEFAULT_PLACEMENT
2331
+ };
2332
+ }
2333
+ const start = Math.max(0, Math.min(atTime, videoDuration - 1));
2334
+ const end = Math.min(start + 10, Math.max(videoDuration, start + 1));
2335
+ return {
2336
+ type: "non-blocking",
2337
+ start,
2338
+ end,
2339
+ placement: DEFAULT_PLACEMENT,
2340
+ revealBehavior: "click"
2341
+ };
2342
+ }
2343
+ function buildContentInstance(id, title, contentType, hook, data) {
2344
+ const record = {
2345
+ id,
2346
+ title,
2347
+ contentTypeId: contentType.getId(),
2348
+ data,
2349
+ state: "pending",
2350
+ hook
2351
+ };
2352
+ return new import_core6.ContentInstance(record, contentType);
2353
+ }
2354
+ function rebuildContentInstance(content, contentType, overrides) {
2355
+ const record = {
2356
+ id: content.getId(),
2357
+ title: overrides.title ?? content.getTitle(),
2358
+ contentTypeId: content.getContentTypeId(),
2359
+ data: overrides.data !== void 0 ? overrides.data : content.getData(),
2360
+ state: content.getState(),
2361
+ // The hook override is load-bearing: core's `serialize` reads the
2362
+ // hook from the instance's record (`content.getHook()`), NOT from
2363
+ // the store wrapper's parallel `hook` field. Every time/placement
2364
+ // edit must be rebuilt into the record or `Save` persists the old
2365
+ // hook.
2366
+ hook: overrides.hook ?? content.getHook()
2367
+ };
2368
+ return new import_core6.ContentInstance(record, contentType);
2369
+ }
2370
+ function clampTimeUpdates(hook, updates, videoDuration) {
2371
+ if (hook.type === "blocking") {
2372
+ const t = updates.timestamp ?? hook.timestamp;
2373
+ return { timestamp: Math.max(0, Math.min(t, videoDuration)) };
2374
+ }
2375
+ const start = updates.start ?? hook.start;
2376
+ const end = updates.end ?? hook.end;
2377
+ const nextStart = Math.max(0, Math.min(start, videoDuration - 1));
2378
+ const nextEnd = Math.max(nextStart + 1, Math.min(end, videoDuration));
2379
+ return { start: nextStart, end: nextEnd };
2380
+ }
2381
+ function EditorVideoToolbar({
2382
+ duration,
2383
+ strings,
2384
+ onReplaceVideo,
2385
+ onOpenPreview,
2386
+ theme,
2387
+ hint
2388
+ }) {
2389
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2390
+ "div",
2391
+ {
2392
+ "data-testid": "interlace-editor-video-toolbar",
2393
+ style: {
2394
+ display: "flex",
2395
+ justifyContent: "space-between",
2396
+ alignItems: "center",
2397
+ padding: `${SPACE[2]}px 0`,
2398
+ fontSize: TYPE.sm,
2399
+ color: theme?.mutedTextColor ?? COLORS.textMuted
2400
+ },
2401
+ children: [
2402
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2403
+ "span",
2404
+ {
2405
+ style: {
2406
+ display: "flex",
2407
+ alignItems: "center",
2408
+ gap: 8
2409
+ },
2410
+ children: [
2411
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-testid": "interlace-editor-video-duration", children: duration === void 0 || !Number.isFinite(duration) ? strings.durationUnknownLabel : `${duration.toFixed(1)}s` }),
2412
+ hint ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-testid": "interlace-editor-selection-hint", children: hint }) : null
2413
+ ]
2414
+ }
2415
+ ),
2416
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { display: "flex", gap: 8 }, children: [
2417
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2418
+ "button",
2419
+ {
2420
+ type: "button",
2421
+ onClick: onReplaceVideo,
2422
+ "data-testid": "interlace-editor-replace-video",
2423
+ style: {
2424
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
2425
+ backgroundColor: "transparent",
2426
+ border: `1px solid ${COLORS.borderStrong}`,
2427
+ borderRadius: RADIUS.sm,
2428
+ cursor: "pointer",
2429
+ fontSize: TYPE.sm,
2430
+ color: COLORS.text,
2431
+ transition: "background-color 150ms ease, border-color 150ms ease"
2432
+ },
2433
+ children: strings.replaceVideoLabel
2434
+ }
2435
+ ),
2436
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2437
+ "button",
2438
+ {
2439
+ type: "button",
2440
+ onClick: onOpenPreview,
2441
+ "data-testid": "interlace-editor-open-preview",
2442
+ style: {
2443
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
2444
+ backgroundColor: theme?.accentColor ?? COLORS.accent,
2445
+ color: COLORS.white,
2446
+ border: "none",
2447
+ borderRadius: RADIUS.sm,
2448
+ cursor: "pointer",
2449
+ fontSize: TYPE.sm,
2450
+ fontWeight: 600,
2451
+ transition: "background-color 150ms ease"
2452
+ },
2453
+ children: strings.previewLabel
2454
+ }
2455
+ )
2456
+ ] })
2457
+ ]
2458
+ }
2459
+ );
2460
+ }
2461
+ function InterlaceEditor({
2462
+ contentTypeRegistry,
2463
+ document,
2464
+ onUpload,
2465
+ onSave,
2466
+ strings: stringsOverride,
2467
+ theme,
2468
+ onError
2469
+ }) {
2470
+ const strings = { ...DEFAULT_EDITOR_STRINGS, ...stringsOverride };
2471
+ const {
2472
+ state,
2473
+ addItem,
2474
+ removeItem,
2475
+ updateItem,
2476
+ loadDocument,
2477
+ serialize,
2478
+ setVideoMetadata
2479
+ } = useAuthoringStore(
2480
+ document?.video?.src ?? "",
2481
+ document?.video?.duration ?? 0
2482
+ );
2483
+ const [selectedItemId, setSelectedItemId] = (0, import_react10.useState)(null);
2484
+ const [pendingHook, setPendingHook] = (0, import_react10.useState)(null);
2485
+ const [replaceMode, setReplaceMode] = (0, import_react10.useState)(false);
2486
+ const [previewOpen, setPreviewOpen] = (0, import_react10.useState)(false);
2487
+ const [currentTime, setCurrentTime] = (0, import_react10.useState)(0);
2488
+ const [isPlaying, setIsPlaying] = (0, import_react10.useState)(false);
2489
+ const nextIdRef = (0, import_react10.useRef)(1);
2490
+ const registryRef = (0, import_react10.useRef)(contentTypeRegistry);
2491
+ registryRef.current = contentTypeRegistry;
2492
+ const loadedInitialDocRef = (0, import_react10.useRef)(
2493
+ null
2494
+ );
2495
+ const videoRef = (0, import_react10.useRef)(null);
2496
+ const lastDurationForSrcRef = (0, import_react10.useRef)(null);
2497
+ const pendingSeekRef = (0, import_react10.useRef)(null);
2498
+ (0, import_react10.useEffect)(() => {
2499
+ if (!document) {
2500
+ if (loadedInitialDocRef.current !== null) {
2501
+ loadedInitialDocRef.current = null;
2502
+ setPendingHook(null);
2503
+ }
2504
+ return;
2505
+ }
2506
+ if (loadedInitialDocRef.current === document) return;
2507
+ loadedInitialDocRef.current = document;
2508
+ setPendingHook(null);
2509
+ const { validationErrors, warnings } = loadDocument(
2510
+ document,
2511
+ registryRef.current
2512
+ );
2513
+ if (validationErrors.length > 0) {
2514
+ onError?.(
2515
+ new Error(`${strings.loadErrorTitle}: ${validationErrors.join("; ")}`)
2516
+ );
2517
+ }
2518
+ for (const warning of warnings) {
2519
+ onError?.(new Error(warning));
2520
+ }
2521
+ }, [document, loadDocument, onError, strings.loadErrorTitle]);
2522
+ (0, import_react10.useEffect)(() => {
2523
+ const last = lastDurationForSrcRef.current;
2524
+ if (!last) return;
2525
+ if (last.src !== state.videoSrc) return;
2526
+ if (Math.abs(last.duration - state.videoDuration) < 1e-3) return;
2527
+ setVideoMetadata(last.src, last.duration);
2528
+ }, [state.videoSrc, state.videoDuration, setVideoMetadata]);
2529
+ const hasVideo = Boolean(state.videoSrc);
2530
+ const showSourceStep = !hasVideo || replaceMode;
2531
+ const selectedStoreItem = (0, import_react10.useMemo)(
2532
+ () => state.items.find((item) => item.content.getId() === selectedItemId) ?? null,
2533
+ [state.items, selectedItemId]
2534
+ );
2535
+ const isPendingSelected = !selectedStoreItem && pendingHook != null && pendingHook.id === selectedItemId;
2536
+ const selectedHook = isPendingSelected ? pendingHook?.hook ?? null : selectedStoreItem?.hook ?? null;
2537
+ const selectedTitle = isPendingSelected ? pendingHook?.title ?? null : selectedStoreItem?.content.getTitle() ?? null;
2538
+ const selectedContentTypeId = isPendingSelected ? null : selectedStoreItem?.content.getContentTypeId() ?? null;
2539
+ const selectedContent = selectedStoreItem?.content ?? null;
2540
+ const selectedData = (0, import_react10.useMemo)(
2541
+ () => selectedContent ? selectedContent.getData() : null,
2542
+ [selectedContent]
2543
+ );
2544
+ const registeredTypeIds = (0, import_react10.useMemo)(
2545
+ () => contentTypeRegistry.getAll().map((ct) => ct.getId()),
2546
+ [contentTypeRegistry]
2547
+ );
2548
+ const timelineEntries = (0, import_react10.useMemo)(() => {
2549
+ const fromStore = state.items.map((item) => {
2550
+ const hook2 = item.hook;
2551
+ if (hook2.type === "blocking") {
2552
+ return {
2553
+ id: item.content.getId(),
2554
+ title: item.content.getTitle(),
2555
+ hookType: "blocking",
2556
+ timestamp: hook2.timestamp
2557
+ };
2558
+ }
2559
+ return {
2560
+ id: item.content.getId(),
2561
+ title: item.content.getTitle(),
2562
+ hookType: "non-blocking",
2563
+ start: hook2.start,
2564
+ end: hook2.end
2565
+ };
2566
+ });
2567
+ if (!pendingHook) return fromStore;
2568
+ const hook = pendingHook.hook;
2569
+ return [
2570
+ ...fromStore,
2571
+ hook.type === "blocking" ? {
2572
+ id: pendingHook.id,
2573
+ title: pendingHook.title,
2574
+ hookType: "blocking",
2575
+ timestamp: hook.timestamp
2576
+ } : {
2577
+ id: pendingHook.id,
2578
+ title: pendingHook.title,
2579
+ hookType: "non-blocking",
2580
+ start: hook.start,
2581
+ end: hook.end
2582
+ }
2583
+ ];
2584
+ }, [state.items, pendingHook]);
2585
+ const previewDocument = (0, import_react10.useMemo)(() => {
2586
+ if (!state.videoSrc) {
2587
+ return { video: { src: "" }, items: [] };
2588
+ }
2589
+ return {
2590
+ video: {
2591
+ src: state.videoSrc,
2592
+ duration: state.videoDuration
2593
+ },
2594
+ items: state.items.map((item) => ({
2595
+ id: item.content.getId(),
2596
+ title: item.content.getTitle(),
2597
+ hook: item.hook,
2598
+ content: {
2599
+ contentTypeId: item.content.getContentTypeId(),
2600
+ version: item.content.getContentTypeVersion(),
2601
+ data: item.content.getData()
2602
+ }
2603
+ }))
2604
+ };
2605
+ }, [state.videoSrc, state.videoDuration, state.items]);
2606
+ const handleSelectEntry = (0, import_react10.useCallback)(
2607
+ (id) => {
2608
+ setSelectedItemId(id);
2609
+ const item = state.items.find((it) => it.content.getId() === id);
2610
+ const hook = item ? item.content.getHook() : pendingHook?.id === id ? pendingHook.hook : null;
2611
+ if (!hook) return;
2612
+ const target = hook.type === "blocking" ? hook.timestamp : hook.start;
2613
+ if (!Number.isFinite(target)) return;
2614
+ const video = videoRef.current;
2615
+ if (video) {
2616
+ try {
2617
+ video.currentTime = Math.max(0, target);
2618
+ } catch {
2619
+ pendingSeekRef.current = Math.max(0, target);
2620
+ }
2621
+ } else {
2622
+ pendingSeekRef.current = Math.max(0, target);
2623
+ }
2624
+ setCurrentTime(Math.max(0, target));
2625
+ },
2626
+ [state.items, pendingHook, setCurrentTime]
2627
+ );
2628
+ const handleDeselect = (0, import_react10.useCallback)(() => {
2629
+ setSelectedItemId(null);
2630
+ }, []);
2631
+ const handleAddEntry = (0, import_react10.useCallback)(
2632
+ (hookType) => {
2633
+ const id = `pending-${nextIdRef.current++}`;
2634
+ const hook = makeHook(hookType, currentTime, state.videoDuration);
2635
+ setPendingHook({ id, title: "New hook", hook });
2636
+ setSelectedItemId(id);
2637
+ },
2638
+ [currentTime, state.videoDuration]
2639
+ );
2640
+ const handleDeleteEntry = (0, import_react10.useCallback)(
2641
+ (id) => {
2642
+ if (pendingHook?.id === id) {
2643
+ setPendingHook(null);
2644
+ setSelectedItemId((prev) => prev === id ? null : prev);
2645
+ return;
2646
+ }
2647
+ removeItem(id);
2648
+ setSelectedItemId((prev) => prev === id ? null : prev);
2649
+ },
2650
+ [pendingHook, removeItem]
2651
+ );
2652
+ const handleUpdateEntry = (0, import_react10.useCallback)(
2653
+ (id, updates) => {
2654
+ if (pendingHook?.id === id) {
2655
+ setPendingHook((prev) => {
2656
+ if (!prev || prev.id !== id) return prev;
2657
+ const hook2 = prev.hook;
2658
+ const nextHook = hook2.type === "blocking" ? { ...hook2, timestamp: updates.timestamp ?? hook2.timestamp } : {
2659
+ ...hook2,
2660
+ start: updates.start ?? hook2.start,
2661
+ end: updates.end ?? hook2.end
2662
+ };
2663
+ return {
2664
+ ...prev,
2665
+ title: typeof updates.title === "string" ? updates.title : prev.title,
2666
+ hook: nextHook
2667
+ };
2668
+ });
2669
+ return;
2670
+ }
2671
+ const current = state.items.find((item) => item.content.getId() === id);
2672
+ if (!current) return;
2673
+ const contentType = contentTypeRegistry.get(
2674
+ current.content.getContentTypeId()
2675
+ );
2676
+ if (!contentType) return;
2677
+ const title = typeof updates.title === "string" ? updates.title : current.content.getTitle();
2678
+ let hook = current.hook;
2679
+ if (hook.type === "blocking") {
2680
+ hook = { ...hook, timestamp: updates.timestamp ?? hook.timestamp };
2681
+ } else {
2682
+ hook = {
2683
+ ...hook,
2684
+ start: updates.start ?? hook.start,
2685
+ end: updates.end ?? hook.end
2686
+ };
2687
+ }
2688
+ updateItem(id, {
2689
+ content: rebuildContentInstance(current.content, contentType, {
2690
+ title,
2691
+ hook
2692
+ }),
2693
+ hook
2694
+ });
2695
+ },
2696
+ [pendingHook, state.items, contentTypeRegistry, updateItem]
2697
+ );
2698
+ const handlePlacementChange = (0, import_react10.useCallback)(
2699
+ (nextPlacement) => {
2700
+ if (!selectedItemId) return;
2701
+ if (pendingHook?.id === selectedItemId) {
2702
+ setPendingHook(
2703
+ (prev) => prev && prev.id === selectedItemId ? { ...prev, hook: { ...prev.hook, placement: nextPlacement } } : prev
2704
+ );
2705
+ return;
2706
+ }
2707
+ const current = state.items.find(
2708
+ (item) => item.content.getId() === selectedItemId
2709
+ );
2710
+ if (!current) return;
2711
+ const contentType = contentTypeRegistry.get(
2712
+ current.content.getContentTypeId()
2713
+ );
2714
+ if (!contentType) return;
2715
+ const nextHook = { ...current.hook, placement: nextPlacement };
2716
+ updateItem(selectedItemId, {
2717
+ content: rebuildContentInstance(current.content, contentType, {
2718
+ hook: nextHook
2719
+ }),
2720
+ hook: nextHook
2721
+ });
2722
+ },
2723
+ [selectedItemId, pendingHook, state.items, contentTypeRegistry, updateItem]
2724
+ );
2725
+ const handleContentChange = (0, import_react10.useCallback)(
2726
+ (newData) => {
2727
+ if (!selectedItemId) return;
2728
+ const current = state.items.find(
2729
+ (item) => item.content.getId() === selectedItemId
2730
+ );
2731
+ if (!current) return;
2732
+ const contentType = contentTypeRegistry.get(
2733
+ current.content.getContentTypeId()
2734
+ );
2735
+ if (!contentType) return;
2736
+ const updatedContent = rebuildContentInstance(
2737
+ current.content,
2738
+ contentType,
2739
+ { data: newData }
2740
+ );
2741
+ const updatedItem = {
2742
+ content: updatedContent,
2743
+ hook: current.hook
2744
+ };
2745
+ updateItem(selectedItemId, updatedItem);
2746
+ },
2747
+ [selectedItemId, state.items, contentTypeRegistry, updateItem]
2748
+ );
2749
+ const handleContentTypeSelect = (0, import_react10.useCallback)(
2750
+ (typeId) => {
2751
+ if (!selectedItemId) return;
2752
+ const contentType = contentTypeRegistry.get(typeId);
2753
+ if (!contentType) return;
2754
+ if (pendingHook?.id === selectedItemId) {
2755
+ const id = `hook-${nextIdRef.current++}`;
2756
+ const item = buildContentInstance(
2757
+ id,
2758
+ pendingHook.title,
2759
+ contentType,
2760
+ pendingHook.hook,
2761
+ makeDefaultData(contentType.getId())
2762
+ );
2763
+ addItem({ content: item, hook: pendingHook.hook });
2764
+ setPendingHook(null);
2765
+ setSelectedItemId(id);
2766
+ return;
2767
+ }
2768
+ const current = state.items.find(
2769
+ (item) => item.content.getId() === selectedItemId
2770
+ );
2771
+ if (!current) return;
2772
+ if (current.content.getContentTypeId() === typeId) return;
2773
+ const rebuilt = buildContentInstance(
2774
+ current.content.getId(),
2775
+ current.content.getTitle(),
2776
+ contentType,
2777
+ current.hook,
2778
+ makeDefaultData(contentType.getId())
2779
+ );
2780
+ updateItem(selectedItemId, { content: rebuilt, hook: current.hook });
2781
+ },
2782
+ [
2783
+ pendingHook,
2784
+ selectedItemId,
2785
+ contentTypeRegistry,
2786
+ addItem,
2787
+ state.items,
2788
+ updateItem
2789
+ ]
2790
+ );
2791
+ const handleTimeChange = (0, import_react10.useCallback)(
2792
+ (updates) => {
2793
+ if (!selectedItemId) return;
2794
+ const isPending = pendingHook?.id === selectedItemId;
2795
+ const hook = isPending ? pendingHook?.hook : state.items.find((it) => it.content.getId() === selectedItemId)?.hook;
2796
+ if (!hook) return;
2797
+ const clamped = clampTimeUpdates(hook, updates, state.videoDuration);
2798
+ if (isPending) {
2799
+ setPendingHook(
2800
+ (prev) => prev && prev.id === selectedItemId ? { ...prev, hook: { ...prev.hook, ...clamped } } : prev
2801
+ );
2802
+ return;
2803
+ }
2804
+ handleUpdateEntry(selectedItemId, clamped);
2805
+ },
2806
+ [
2807
+ selectedItemId,
2808
+ pendingHook,
2809
+ state.items,
2810
+ state.videoDuration,
2811
+ handleUpdateEntry
2812
+ ]
2813
+ );
2814
+ const handleVideoSourceChange = (0, import_react10.useCallback)(
2815
+ (next) => {
2816
+ const preserveDuration = next.src === state.videoSrc ? state.videoDuration : 0;
2817
+ const duration = next.duration ?? preserveDuration;
2818
+ setVideoMetadata(next.src, duration);
2819
+ setReplaceMode(false);
2820
+ setPendingHook(null);
2821
+ setPreviewOpen(false);
2822
+ },
2823
+ [setVideoMetadata, setPendingHook, state.videoSrc, state.videoDuration]
2824
+ );
2825
+ const handleReplaceVideo = (0, import_react10.useCallback)(() => {
2826
+ setReplaceMode(true);
2827
+ }, []);
2828
+ const handleCancelReplace = (0, import_react10.useCallback)(() => {
2829
+ setReplaceMode(false);
2830
+ }, []);
2831
+ const handleTimeUpdate = (0, import_react10.useCallback)(
2832
+ (e) => {
2833
+ setCurrentTime(e.currentTarget.currentTime);
2834
+ },
2835
+ []
2836
+ );
2837
+ const handleTimelineSeek = (0, import_react10.useCallback)((time) => {
2838
+ const t = Math.max(0, time);
2839
+ const video = videoRef.current;
2840
+ if (video) {
2841
+ try {
2842
+ video.currentTime = t;
2843
+ } catch {
2844
+ pendingSeekRef.current = t;
2845
+ }
2846
+ } else {
2847
+ pendingSeekRef.current = t;
2848
+ }
2849
+ setCurrentTime(t);
2850
+ }, []);
2851
+ const handleTogglePlay = (0, import_react10.useCallback)(() => {
2852
+ const video = videoRef.current;
2853
+ if (!video) return;
2854
+ if (video.paused) {
2855
+ try {
2856
+ const p = video.play();
2857
+ p?.catch?.(() => {
2858
+ });
2859
+ } catch {
2860
+ }
2861
+ } else {
2862
+ try {
2863
+ video.pause();
2864
+ } catch {
2865
+ }
2866
+ }
2867
+ }, []);
2868
+ const handleOpenPreview = (0, import_react10.useCallback)(() => {
2869
+ setPreviewOpen(true);
2870
+ }, []);
2871
+ const handleClosePreview = (0, import_react10.useCallback)(() => {
2872
+ setPreviewOpen(false);
2873
+ }, []);
2874
+ (0, import_react10.useEffect)(() => {
2875
+ if (previewOpen && videoRef.current) {
2876
+ try {
2877
+ videoRef.current.pause();
2878
+ } catch {
2879
+ }
2880
+ }
2881
+ }, [previewOpen]);
2882
+ const handlePreviewLoadedMetadata = (0, import_react10.useCallback)(
2883
+ (duration) => {
2884
+ if (state.videoSrc) {
2885
+ lastDurationForSrcRef.current = {
2886
+ src: state.videoSrc,
2887
+ duration
2888
+ };
2889
+ }
2890
+ setVideoMetadata(state.videoSrc, duration);
2891
+ const pending = pendingSeekRef.current;
2892
+ if (pending != null && videoRef.current) {
2893
+ try {
2894
+ videoRef.current.currentTime = pending;
2895
+ } catch {
2896
+ }
2897
+ pendingSeekRef.current = null;
2898
+ }
2899
+ },
2900
+ [state.videoSrc, setVideoMetadata]
2901
+ );
2902
+ const handleSave = (0, import_react10.useCallback)(() => {
2903
+ onSave(serialize());
2904
+ }, [onSave, serialize]);
2905
+ const rootStyle = {
2906
+ backgroundColor: theme?.backgroundColor ?? COLORS.surface,
2907
+ color: theme?.textColor ?? COLORS.text,
2908
+ borderColor: theme?.borderColor ?? COLORS.border
2909
+ };
2910
+ const saveButtonStyle = {
2911
+ backgroundColor: theme?.accentColor ?? COLORS.accent,
2912
+ color: COLORS.white
2913
+ };
2914
+ const surfaceStyle = {
2915
+ backgroundColor: theme?.surfaceColor ?? COLORS.surfaceRaised,
2916
+ borderColor: theme?.borderColor ?? COLORS.border
2917
+ };
2918
+ if (showSourceStep) {
2919
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2920
+ "div",
2921
+ {
2922
+ className: "interlace-editor",
2923
+ style: {
2924
+ ...rootStyle,
2925
+ padding: 16,
2926
+ borderRadius: 8,
2927
+ border: "1px solid"
2928
+ },
2929
+ children: [
2930
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2931
+ "div",
2932
+ {
2933
+ style: {
2934
+ display: "flex",
2935
+ justifyContent: "space-between",
2936
+ alignItems: "center",
2937
+ marginBottom: 16
2938
+ },
2939
+ children: [
2940
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2941
+ "h2",
2942
+ {
2943
+ style: {
2944
+ margin: 0,
2945
+ fontFamily: FONTS.display,
2946
+ fontSize: TYPE.lg,
2947
+ fontWeight: 600
2948
+ },
2949
+ children: strings.videoSourceInputTitle
2950
+ }
2951
+ ),
2952
+ replaceMode ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2953
+ "button",
2954
+ {
2955
+ type: "button",
2956
+ onClick: handleCancelReplace,
2957
+ "data-testid": "interlace-editor-cancel-replace",
2958
+ style: {
2959
+ padding: `${SPACE[1]}px ${SPACE[3]}px`,
2960
+ backgroundColor: COLORS.surface,
2961
+ border: `1px solid ${COLORS.borderStrong}`,
2962
+ borderRadius: RADIUS.sm,
2963
+ cursor: "pointer",
2964
+ fontSize: TYPE.sm,
2965
+ color: COLORS.text,
2966
+ transition: "background-color 150ms ease"
2967
+ },
2968
+ children: strings.replaceCancelLabel
2969
+ }
2970
+ ) : null
2971
+ ]
2972
+ }
2973
+ ),
2974
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2975
+ VideoSourceInput,
2976
+ {
2977
+ value: {
2978
+ src: state.videoSrc || void 0,
2979
+ duration: state.videoDuration || void 0
2980
+ },
2981
+ onChange: handleVideoSourceChange,
2982
+ onUpload,
2983
+ onError,
2984
+ strings: strings.videoSource
2985
+ }
2986
+ )
2987
+ ]
2988
+ }
2989
+ );
2990
+ }
2991
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2992
+ "div",
2993
+ {
2994
+ className: "interlace-editor",
2995
+ style: {
2996
+ ...rootStyle,
2997
+ padding: 16,
2998
+ borderRadius: 8,
2999
+ border: "1px solid"
3000
+ },
3001
+ children: [
3002
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3003
+ "header",
3004
+ {
3005
+ style: {
3006
+ display: "flex",
3007
+ justifyContent: "space-between",
3008
+ alignItems: "center",
3009
+ marginBottom: 16
3010
+ },
3011
+ children: [
3012
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3013
+ "h2",
3014
+ {
3015
+ style: {
3016
+ margin: 0,
3017
+ fontFamily: FONTS.display,
3018
+ fontSize: TYPE.lg,
3019
+ fontWeight: 600
3020
+ },
3021
+ children: strings.previewTitle
3022
+ }
3023
+ ),
3024
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3025
+ "button",
3026
+ {
3027
+ type: "button",
3028
+ onClick: handleSave,
3029
+ "data-testid": "interlace-editor-save",
3030
+ style: {
3031
+ ...saveButtonStyle,
3032
+ padding: `${SPACE[2]}px ${SPACE[4]}px`,
3033
+ border: "none",
3034
+ borderRadius: RADIUS.sm,
3035
+ cursor: "pointer",
3036
+ fontSize: TYPE.md,
3037
+ fontWeight: 600,
3038
+ boxShadow: SHADOWS.sm,
3039
+ transition: "background-color 150ms ease"
3040
+ },
3041
+ children: strings.saveLabel
3042
+ }
3043
+ )
3044
+ ]
3045
+ }
3046
+ ),
3047
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3048
+ "section",
3049
+ {
3050
+ className: "interlace-editor-video",
3051
+ style: {
3052
+ width: "100%",
3053
+ maxWidth: 720,
3054
+ margin: "0 auto"
3055
+ },
3056
+ children: [
3057
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3058
+ "div",
3059
+ {
3060
+ "data-testid": "interlace-editor-video",
3061
+ style: { position: "relative" },
3062
+ children: [
3063
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3064
+ "video",
3065
+ {
3066
+ ref: videoRef,
3067
+ src: state.videoSrc,
3068
+ controls: true,
3069
+ preload: "metadata",
3070
+ onLoadedMetadata: (e) => handlePreviewLoadedMetadata(e.currentTarget.duration),
3071
+ onTimeUpdate: handleTimeUpdate,
3072
+ onPlay: () => setIsPlaying(true),
3073
+ onPause: () => setIsPlaying(false),
3074
+ "data-testid": "interlace-editor-preview-video",
3075
+ style: {
3076
+ width: "100%",
3077
+ height: "auto",
3078
+ display: "block",
3079
+ backgroundColor: "#000"
3080
+ }
3081
+ },
3082
+ state.videoSrc
3083
+ ),
3084
+ selectedHook ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3085
+ PlacementEditor,
3086
+ {
3087
+ placement: selectedHook.placement,
3088
+ onPlacementChange: handlePlacementChange
3089
+ }
3090
+ ) : null
3091
+ ]
3092
+ }
3093
+ ),
3094
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3095
+ EditorVideoToolbar,
3096
+ {
3097
+ duration: state.videoDuration || void 0,
3098
+ strings,
3099
+ onReplaceVideo: handleReplaceVideo,
3100
+ onOpenPreview: handleOpenPreview,
3101
+ theme,
3102
+ hint: selectedHook ? void 0 : strings.noItemSelectedLabel
3103
+ }
3104
+ )
3105
+ ]
3106
+ }
3107
+ ),
3108
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3109
+ PreviewModal,
3110
+ {
3111
+ isOpen: previewOpen,
3112
+ videoSrc: state.videoSrc,
3113
+ document: previewDocument,
3114
+ contentTypeRegistry,
3115
+ onClose: handleClosePreview,
3116
+ onError,
3117
+ strings: strings.previewModal
3118
+ }
3119
+ ),
3120
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3121
+ "section",
3122
+ {
3123
+ className: "interlace-editor-timeline",
3124
+ style: {
3125
+ ...surfaceStyle,
3126
+ marginTop: 16,
3127
+ padding: 16,
3128
+ borderRadius: 8,
3129
+ border: "1px solid"
3130
+ },
3131
+ children: [
3132
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3133
+ "h3",
3134
+ {
3135
+ style: {
3136
+ marginTop: 0,
3137
+ fontFamily: FONTS.display,
3138
+ fontSize: TYPE.md,
3139
+ fontWeight: 600
3140
+ },
3141
+ children: strings.timelineHeading
3142
+ }
3143
+ ),
3144
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3145
+ KeyframeTimeline,
3146
+ {
3147
+ entries: timelineEntries,
3148
+ selectedId: selectedItemId ?? void 0,
3149
+ videoDuration: state.videoDuration || 0,
3150
+ currentTime,
3151
+ isPlaying,
3152
+ onSeek: handleTimelineSeek,
3153
+ onTogglePlay: handleTogglePlay,
3154
+ onSelectEntry: handleSelectEntry,
3155
+ onUpdateEntry: handleUpdateEntry,
3156
+ onDeleteEntry: handleDeleteEntry,
3157
+ onAddEntry: handleAddEntry,
3158
+ onDeselect: handleDeselect
3159
+ }
3160
+ )
3161
+ ]
3162
+ }
3163
+ ),
3164
+ selectedItemId && selectedHook ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3165
+ "section",
3166
+ {
3167
+ className: "interlace-editor-hook",
3168
+ "data-testid": "interlace-editor-hook",
3169
+ style: {
3170
+ ...surfaceStyle,
3171
+ marginTop: 16,
3172
+ padding: 16,
3173
+ borderRadius: 8,
3174
+ border: "1px solid"
3175
+ },
3176
+ children: [
3177
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3178
+ "h3",
3179
+ {
3180
+ style: {
3181
+ marginTop: 0,
3182
+ fontFamily: FONTS.display,
3183
+ fontSize: TYPE.md,
3184
+ fontWeight: 600
3185
+ },
3186
+ children: strings.hookHeading
3187
+ }
3188
+ ),
3189
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3190
+ InspectorPanel,
3191
+ {
3192
+ entry: {
3193
+ id: selectedItemId,
3194
+ title: selectedTitle ?? "",
3195
+ hookType: selectedHook.type,
3196
+ timestamp: selectedHook.type === "blocking" ? selectedHook.timestamp : void 0,
3197
+ start: selectedHook.type === "non-blocking" ? selectedHook.start : void 0,
3198
+ end: selectedHook.type === "non-blocking" ? selectedHook.end : void 0,
3199
+ videoDuration: state.videoDuration || 0,
3200
+ contentTypeId: selectedContentTypeId,
3201
+ registeredTypes: registeredTypeIds
3202
+ },
3203
+ onTitleChange: (title) => handleUpdateEntry(selectedItemId, { title }),
3204
+ onTimeChange: handleTimeChange,
3205
+ onContentTypeSelect: handleContentTypeSelect,
3206
+ placement: selectedHook.placement,
3207
+ onPlacementChange: handlePlacementChange,
3208
+ onDelete: () => handleDeleteEntry(selectedItemId)
3209
+ }
3210
+ ),
3211
+ selectedContentTypeId ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { marginTop: 12 }, children: [
3212
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3213
+ "h4",
3214
+ {
3215
+ style: {
3216
+ margin: `0 0 ${SPACE[1]}px 0`,
3217
+ fontSize: TYPE.sm,
3218
+ color: theme?.mutedTextColor ?? COLORS.textMuted,
3219
+ fontWeight: 600
3220
+ },
3221
+ children: strings.contentEditorHeading
3222
+ }
3223
+ ),
3224
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3225
+ ContentTypeEditor,
3226
+ {
3227
+ contentTypeId: selectedContentTypeId,
3228
+ registry: contentTypeRegistry,
3229
+ data: selectedData,
3230
+ onChange: handleContentChange
3231
+ }
3232
+ )
3233
+ ] }) : null
3234
+ ]
3235
+ }
3236
+ ) : null
3237
+ ]
3238
+ }
3239
+ );
3240
+ }
3241
+
3242
+ // src/components/content-type-editor-slot.tsx
3243
+ var import_react11 = require("react");
3244
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3245
+ function ContentTypeEditorSlot({
3246
+ contentTypeId,
3247
+ isOpen,
3248
+ onClose,
3249
+ onSave,
3250
+ registry,
3251
+ data,
3252
+ onChange
3253
+ }) {
3254
+ const containerRef = (0, import_react11.useRef)(null);
3255
+ useContentTypeEditorMount({
3256
+ containerRef,
3257
+ active: isOpen,
3258
+ contentTypeId,
3259
+ registry,
3260
+ data,
3261
+ onChange
3262
+ });
3263
+ const contentType = contentTypeId ? registry.get(contentTypeId) : void 0;
3264
+ if (!isOpen || !contentTypeId) {
3265
+ return null;
3266
+ }
3267
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3268
+ "div",
3269
+ {
3270
+ className: "content-type-editor-slot",
3271
+ style: {
3272
+ position: "fixed",
3273
+ top: 0,
3274
+ left: 0,
3275
+ right: 0,
3276
+ bottom: 0,
3277
+ backgroundColor: "rgba(15, 23, 42, 0.5)",
3278
+ display: "flex",
3279
+ alignItems: "center",
3280
+ justifyContent: "center",
3281
+ zIndex: 999
3282
+ },
3283
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3284
+ "div",
3285
+ {
3286
+ className: "content-type-editor-container",
3287
+ style: {
3288
+ backgroundColor: COLORS.surface,
3289
+ borderRadius: `${RADIUS.lg}px`,
3290
+ padding: `${SPACE[5]}px`,
3291
+ maxWidth: "600px",
3292
+ width: "90%",
3293
+ maxHeight: "80vh",
3294
+ overflowY: "auto",
3295
+ boxShadow: SHADOWS.md
3296
+ },
3297
+ children: [
3298
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3299
+ "h2",
3300
+ {
3301
+ className: "content-type-editor-title",
3302
+ style: {
3303
+ marginTop: 0,
3304
+ fontFamily: FONTS.display,
3305
+ fontSize: TYPE.lg,
3306
+ fontWeight: 600
3307
+ },
3308
+ children: [
3309
+ "Edit ",
3310
+ contentTypeId
3311
+ ]
3312
+ }
3313
+ ),
3314
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3315
+ "div",
3316
+ {
3317
+ className: "content-type-editor-body",
3318
+ style: { margin: "16px 0", minHeight: "100px" },
3319
+ children: contentType ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { ref: containerRef }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("p", { style: { color: COLORS.textMuted }, children: [
3320
+ 'Content type "',
3321
+ contentTypeId,
3322
+ '" is not registered'
3323
+ ] })
3324
+ }
3325
+ ),
3326
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3327
+ "div",
3328
+ {
3329
+ className: "content-type-editor-footer",
3330
+ style: {
3331
+ display: "flex",
3332
+ gap: `${SPACE[2]}px`,
3333
+ justifyContent: "flex-end",
3334
+ marginTop: `${SPACE[5]}px`
3335
+ },
3336
+ children: [
3337
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3338
+ "button",
3339
+ {
3340
+ className: "content-type-editor-cancel-button",
3341
+ onClick: onClose,
3342
+ style: {
3343
+ padding: `${SPACE[2]}px ${SPACE[4]}px`,
3344
+ backgroundColor: COLORS.surfaceRaised,
3345
+ border: `1px solid ${COLORS.borderStrong}`,
3346
+ borderRadius: `${RADIUS.sm}px`,
3347
+ cursor: "pointer",
3348
+ fontSize: TYPE.md,
3349
+ color: COLORS.text,
3350
+ transition: "background-color 150ms ease"
3351
+ },
3352
+ children: "Cancel"
3353
+ }
3354
+ ),
3355
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3356
+ "button",
3357
+ {
3358
+ className: "content-type-editor-save-button",
3359
+ onClick: () => {
3360
+ onSave?.(data);
3361
+ onClose();
3362
+ },
3363
+ style: {
3364
+ padding: `${SPACE[2]}px ${SPACE[4]}px`,
3365
+ backgroundColor: COLORS.accent,
3366
+ color: COLORS.white,
3367
+ border: "none",
3368
+ borderRadius: `${RADIUS.sm}px`,
3369
+ cursor: "pointer",
3370
+ fontSize: TYPE.md,
3371
+ fontWeight: 600,
3372
+ transition: "background-color 150ms ease"
3373
+ },
3374
+ children: "Save"
3375
+ }
3376
+ )
3377
+ ]
3378
+ }
3379
+ )
3380
+ ]
3381
+ }
3382
+ )
3383
+ }
3384
+ );
3385
+ }
3386
+ // Annotate the CommonJS export names for ESM import in node:
3387
+ 0 && (module.exports = {
3388
+ ContentTypeEditor,
3389
+ ContentTypeEditorSlot,
3390
+ ContentTypePicker,
3391
+ DEFAULT_EDITOR_STRINGS,
3392
+ DEFAULT_INSPECTOR_PANEL_STRINGS,
3393
+ DEFAULT_KEYFRAME_TIMELINE_STRINGS,
3394
+ DEFAULT_VIDEO_SOURCE_INPUT_STRINGS,
3395
+ InspectorPanel,
3396
+ InterlaceEditor,
3397
+ KeyframeTimeline,
3398
+ PLACEMENT_MIN_SIZE,
3399
+ PlacementEditor,
3400
+ PlacementInputs,
3401
+ VideoSourceInput,
3402
+ clampPlacement,
3403
+ useAuthoringStore
3404
+ });
3405
+ //# sourceMappingURL=index.cjs.map