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