@editframe/elements 0.6.0-beta.16 → 0.6.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,766 @@
1
+ import { EFTimegroup } from "../elements/EFTimegroup";
2
+ import {
3
+ LitElement,
4
+ html,
5
+ css,
6
+ nothing,
7
+ type TemplateResult,
8
+ type ReactiveController,
9
+ type PropertyValueMap,
10
+ } from "lit";
11
+ import {
12
+ customElement,
13
+ property,
14
+ eventOptions,
15
+ state,
16
+ } from "lit/decorators.js";
17
+ import { styleMap } from "lit/directives/style-map.js";
18
+ import { ref, createRef } from "lit/directives/ref.js";
19
+ import { EFImage } from "../elements/EFImage";
20
+ import { EFAudio } from "../elements/EFAudio";
21
+ import { EFVideo } from "../elements/EFVideo";
22
+ import { EFCaptions, EFCaptionsActiveWord } from "../elements/EFCaptions";
23
+ import { EFWaveform } from "../elements/EFWaveform";
24
+ import type { TemporalMixinInterface } from "../elements/EFTemporal";
25
+ import { TimegroupController } from "../elements/TimegroupController";
26
+ import { consume } from "@lit/context";
27
+ import { type FocusContext, focusContext, focusedElement } from "./EFWorkbench";
28
+ import { TWMixin } from "./TWMixin";
29
+ import { msToTimeCode } from "@/av/msToTimeCode";
30
+
31
+ class ElementFilmstripController implements ReactiveController {
32
+ constructor(
33
+ private host: LitElement,
34
+ private filmstrip: FilmstripItem,
35
+ ) {
36
+ this.host.addController(this);
37
+ }
38
+
39
+ remove() {
40
+ this.host.removeController(this);
41
+ }
42
+
43
+ hostDisconnected() {
44
+ this.host.removeController(this);
45
+ }
46
+
47
+ hostUpdated(): void {
48
+ this.filmstrip.requestUpdate();
49
+ }
50
+ }
51
+
52
+ const CommonEffectKeys = new Set([
53
+ "offset",
54
+ "easing",
55
+ "composite",
56
+ "computedOffset",
57
+ ]);
58
+
59
+ class FilmstripItem extends TWMixin(LitElement) {
60
+ static styles = [
61
+ css`
62
+ :host {
63
+ display: block;
64
+ }
65
+ `,
66
+ ];
67
+
68
+ @consume({ context: focusContext })
69
+ focusContext?: FocusContext;
70
+
71
+ @consume({ context: focusedElement, subscribe: true })
72
+ focusedElement?: HTMLElement | null;
73
+
74
+ get isFocused() {
75
+ return this.element && this.focusedElement === this.element;
76
+ }
77
+
78
+ @property({ type: HTMLElement, attribute: false })
79
+ element: TemporalMixinInterface & LitElement = new EFTimegroup();
80
+
81
+ @property({ type: Number })
82
+ pixelsPerMs = 0.04;
83
+
84
+ get styles() {
85
+ return {
86
+ position: "relative",
87
+ left: `${this.pixelsPerMs * this.element.startTimeWithinParentMs}px`,
88
+ width: `${this.pixelsPerMs * this.element.durationMs}px`,
89
+ };
90
+ }
91
+
92
+ render() {
93
+ return html` <div class="" style=${styleMap(this.styles)}>
94
+ <div
95
+ @mouseenter=${() => {
96
+ if (this.focusContext) {
97
+ this.focusContext.focusedElement = this.element;
98
+ }
99
+ }}
100
+ @mouseleave=${() => {
101
+ if (this.focusContext) {
102
+ this.focusContext.focusedElement = null;
103
+ }
104
+ }}
105
+ ?data-focused=${this.isFocused}
106
+ class="border-outset relative mb-[1px] block h-[1.25rem] text-nowrap border border-slate-500 bg-blue-200 text-sm data-[focused]:bg-slate-400"
107
+ >
108
+ ${this.animations()}
109
+ </div>
110
+ ${this.renderChildren()}
111
+ </div>`;
112
+ }
113
+
114
+ renderChildren(): Array<TemplateResult<1> | typeof nothing> | typeof nothing {
115
+ return renderFilmStripChildren(
116
+ Array.from(this.element.children),
117
+ this.pixelsPerMs,
118
+ );
119
+ }
120
+
121
+ contents() {
122
+ return html``;
123
+ }
124
+
125
+ animations() {
126
+ const animations = this.element.getAnimations();
127
+ return animations.map((animation) => {
128
+ const effect = animation.effect;
129
+ if (!(effect instanceof KeyframeEffect)) {
130
+ return nothing;
131
+ }
132
+ const start = effect.getTiming().delay ?? 0;
133
+ const duration = effect.getTiming().duration;
134
+ if (duration === null) {
135
+ return nothing;
136
+ }
137
+ const keyframes = effect.getKeyframes();
138
+ const firstKeyframe = keyframes[0];
139
+ if (!firstKeyframe) {
140
+ return nothing;
141
+ }
142
+ const properties = new Set(Object.keys(firstKeyframe));
143
+ for (const key of CommonEffectKeys) {
144
+ properties.delete(key);
145
+ }
146
+
147
+ return html`<div
148
+ class="relative h-[5px] bg-blue-500 opacity-50"
149
+ label="animation"
150
+ style=${styleMap({
151
+ left: `${this.pixelsPerMs * start}px`,
152
+ width: `${this.pixelsPerMs * Number(duration)}px`,
153
+ })}
154
+ >
155
+ <!-- <div class="text-nowrap">${Array.from(properties).join(" ")}</div> -->
156
+ ${effect.getKeyframes().map((keyframe) => {
157
+ return html`<div
158
+ class="absolute top-0 h-full w-1 bg-red-500"
159
+ style=${styleMap({
160
+ left: `${
161
+ this.pixelsPerMs * keyframe.computedOffset * Number(duration)
162
+ }px`,
163
+ })}
164
+ ></div>`;
165
+ })}
166
+ </div>`;
167
+ });
168
+ }
169
+
170
+ protected filmstripController?: ElementFilmstripController;
171
+
172
+ update(changedProperties: Map<string | number | symbol, unknown>) {
173
+ if (
174
+ changedProperties.has("element") &&
175
+ this.element instanceof LitElement
176
+ ) {
177
+ this.filmstripController?.remove();
178
+ this.filmstripController = new ElementFilmstripController(
179
+ this.element,
180
+ this,
181
+ );
182
+ }
183
+ super.update(changedProperties);
184
+ }
185
+ }
186
+
187
+ @customElement("ef-audio-filmstrip")
188
+ export class EFAudioFilmstrip extends FilmstripItem {
189
+ contents() {
190
+ return html``;
191
+ }
192
+ }
193
+
194
+ @customElement("ef-video-filmstrip")
195
+ export class EFVideoFilmstrip extends FilmstripItem {
196
+ contents() {
197
+ return html` 📼 `;
198
+ }
199
+ }
200
+
201
+ @customElement("ef-captions-filmstrip")
202
+ export class EFCaptionsFilmstrip extends FilmstripItem {
203
+ contents() {
204
+ return html` 📝 `;
205
+ }
206
+ }
207
+
208
+ @customElement("ef-waveform-filmstrip")
209
+ export class EFWaveformFilmstrip extends FilmstripItem {
210
+ contents() {
211
+ return html` 🌊 `;
212
+ }
213
+
214
+ renderChildren(): typeof nothing {
215
+ return nothing;
216
+ }
217
+ }
218
+
219
+ @customElement("ef-image-filmstrip")
220
+ export class EFImageFilmstrip extends FilmstripItem {
221
+ contents() {
222
+ return html` 🖼️ `;
223
+ }
224
+ }
225
+
226
+ @customElement("ef-timegroup-filmstrip")
227
+ export class EFTimegroupFilmstrip extends FilmstripItem {
228
+ contents() {
229
+ return html`
230
+ <span>TIME GROUP</span>
231
+ ${renderFilmStripChildren(
232
+ Array.from(this.element.children || []),
233
+ this.pixelsPerMs,
234
+ )}
235
+ </div>
236
+ `;
237
+ }
238
+ }
239
+
240
+ @customElement("ef-html-filmstrip")
241
+ export class EFHTMLFilmstrip extends FilmstripItem {
242
+ contents() {
243
+ return html`
244
+ <span>${this.element.tagName}</span>
245
+ ${renderFilmStripChildren(
246
+ Array.from(this.element.children || []),
247
+ this.pixelsPerMs,
248
+ )}
249
+ `;
250
+ }
251
+ }
252
+
253
+ @customElement("ef-hierarchy-item")
254
+ class EFHierarchyItem<
255
+ ElementType extends HTMLElement = HTMLElement,
256
+ > extends TWMixin(LitElement) {
257
+ @property({ type: HTMLElement, attribute: false })
258
+ // @ts-expect-error This could be initialzed with any HTMLElement
259
+ element: ElementType = new EFTimegroup();
260
+
261
+ @consume({ context: focusContext })
262
+ focusContext?: FocusContext;
263
+
264
+ @consume({ context: focusedElement, subscribe: true })
265
+ focusedElement?: HTMLElement | null;
266
+
267
+ get icon(): TemplateResult<1> | string {
268
+ return "📼";
269
+ }
270
+
271
+ get isFocused() {
272
+ return this.element && this.focusedElement === this.element;
273
+ }
274
+
275
+ displayLabel(): TemplateResult<1> | string | typeof nothing {
276
+ return nothing;
277
+ }
278
+
279
+ render() {
280
+ return html`
281
+ <div>
282
+ <div
283
+ ?data-focused=${this.isFocused}
284
+ class="peer
285
+ flex h-[1.25rem] items-center overflow-hidden text-nowrap border border-slate-500
286
+ bg-slate-200 pl-2 text-sm hover:bg-slate-400 data-[focused]:bg-slate-400"
287
+ @mouseenter=${() => {
288
+ if (this.focusContext) {
289
+ this.focusContext.focusedElement = this.element;
290
+ }
291
+ }}
292
+ @mouseleave=${() => {
293
+ if (this.focusContext) {
294
+ this.focusContext.focusedElement = null;
295
+ }
296
+ }}
297
+ >
298
+ ${this.icon} ${this.displayLabel()}
299
+ </div>
300
+ <div
301
+ class="p-[1px] pb-0 pl-2 pr-0 peer-hover:bg-slate-300 peer-data-[focused]:bg-slate-300 peer-hover:border-slate-400 peer-data-[focused]:border-slate-400""
302
+ >
303
+ ${this.renderChildren()}
304
+ </div>
305
+ </div>`;
306
+ }
307
+
308
+ renderChildren(): Array<TemplateResult<1>> | typeof nothing {
309
+ return renderHierarchyChildren(Array.from(this.element.children));
310
+ }
311
+ }
312
+
313
+ @customElement("ef-timegroup-hierarchy-item")
314
+ class EFTimegroupHierarchyItem extends EFHierarchyItem<EFTimegroup> {
315
+ get icon() {
316
+ return "🕒";
317
+ }
318
+
319
+ displayLabel(): string | TemplateResult<1> | typeof nothing {
320
+ return this.element.mode ?? "(no mode)";
321
+ }
322
+ }
323
+
324
+ @customElement("ef-audio-hierarchy-item")
325
+ class EFAudioHierarchyItem extends EFHierarchyItem {
326
+ get icon() {
327
+ return "🔊";
328
+ }
329
+
330
+ displayLabel() {
331
+ return this.element.getAttribute("src") ?? "(no src)";
332
+ }
333
+ }
334
+
335
+ @customElement("ef-video-hierarchy-item")
336
+ class EFVideoHierarchyItem extends EFHierarchyItem {
337
+ get icon() {
338
+ return "📼";
339
+ }
340
+
341
+ displayLabel() {
342
+ return this.element.getAttribute("src") ?? "(no src)";
343
+ }
344
+ }
345
+
346
+ @customElement("ef-captions-hierarchy-item")
347
+ class EFCaptionsHierarchyItem extends EFHierarchyItem {
348
+ get icon() {
349
+ return "📝 Captions";
350
+ }
351
+ }
352
+
353
+ @customElement("ef-captions-active-word-hierarchy-item")
354
+ class EFCaptionsActiveWordHierarchyItem extends EFHierarchyItem {
355
+ get icon() {
356
+ return "🗣️ Active Word";
357
+ }
358
+ }
359
+
360
+ @customElement("ef-waveform-hierarchy-item")
361
+ class EFWaveformHierarchyItem extends EFHierarchyItem {
362
+ get icon() {
363
+ return "🌊";
364
+ }
365
+
366
+ renderChildren(): typeof nothing {
367
+ return nothing;
368
+ }
369
+ }
370
+
371
+ @customElement("ef-image-hierarchy-item")
372
+ class EFImageHierarchyItem extends EFHierarchyItem {
373
+ get icon() {
374
+ return "🖼️";
375
+ }
376
+
377
+ displayLabel() {
378
+ return this.element.getAttribute("src") ?? "(no src)";
379
+ }
380
+ }
381
+
382
+ @customElement("ef-html-hierarchy-item")
383
+ class EFHTMLHierarchyItem extends EFHierarchyItem {
384
+ get icon() {
385
+ return html`<code>${`<${this.element.tagName.toLowerCase()}>`}</code>`;
386
+ }
387
+ }
388
+
389
+ const renderHierarchyChildren = (
390
+ children: Element[],
391
+ ): Array<TemplateResult<1>> => {
392
+ return children.map((child) => {
393
+ if (child instanceof EFTimegroup) {
394
+ return html`<ef-timegroup-hierarchy-item
395
+ .element=${child}
396
+ ></ef-timegroup-hierarchy-item>`;
397
+ }
398
+ if (child instanceof EFImage) {
399
+ return html`<ef-image-hierarchy-item
400
+ .element=${child}
401
+ ></ef-image-hierarchy-item>`;
402
+ }
403
+ if (child instanceof EFAudio) {
404
+ return html`<ef-audio-hierarchy-item
405
+ .element=${child}
406
+ ></ef-audio-hierarchy-item>`;
407
+ }
408
+ if (child instanceof EFVideo) {
409
+ return html`<ef-video-hierarchy-item
410
+ .element=${child}
411
+ ></ef-video-hierarchy-item>`;
412
+ }
413
+ if (child instanceof EFCaptions) {
414
+ return html`<ef-captions-hierarchy-item
415
+ .element=${child}
416
+ ></ef-captions-hierarchy-item>`;
417
+ }
418
+ if (child instanceof EFCaptionsActiveWord) {
419
+ return html`<ef-captions-active-word-hierarchy-item
420
+ .element=${child}
421
+ ></ef-captions-active-word-hierarchy-item>`;
422
+ }
423
+ if (child instanceof EFWaveform) {
424
+ return html`<ef-waveform-hierarchy-item
425
+ .element=${child}
426
+ ></ef-waveform-hierarchy-item>`;
427
+ }
428
+ return html`<ef-html-hierarchy-item
429
+ .element=${child}
430
+ ></ef-html-hierarchy-item>`;
431
+ });
432
+ };
433
+
434
+ const renderFilmStripChildren = (
435
+ children: Element[],
436
+ pixelsPerMs: number,
437
+ ): Array<TemplateResult<1> | typeof nothing> => {
438
+ return children.map((child) => {
439
+ if (child instanceof EFTimegroup) {
440
+ return html`<ef-timegroup-filmstrip
441
+ .element=${child}
442
+ .pixelsPerMs=${pixelsPerMs}
443
+ >
444
+ </ef-timegroup-filmstrip>`;
445
+ }
446
+ if (child instanceof EFImage) {
447
+ return html`<ef-image-filmstrip
448
+ .element=${child}
449
+ .pixelsPerMs=${pixelsPerMs}
450
+ ></ef-image-filmstrip>`;
451
+ }
452
+ if (child instanceof EFAudio) {
453
+ return html`<ef-audio-filmstrip
454
+ .element=${child}
455
+ .pixelsPerMs=${pixelsPerMs}
456
+ ></ef-audio-filmstrip>`;
457
+ }
458
+ if (child instanceof EFVideo) {
459
+ return html`<ef-video-filmstrip
460
+ .element=${child}
461
+ .pixelsPerMs=${pixelsPerMs}
462
+ ></ef-video-filmstrip>`;
463
+ }
464
+ if (child instanceof EFCaptions) {
465
+ return html`<ef-captions-filmstrip
466
+ .element=${child}
467
+ .pixelsPerMs=${pixelsPerMs}
468
+ ></ef-captions-filmstrip>`;
469
+ }
470
+ if (child instanceof EFWaveform) {
471
+ return html`<ef-waveform-filmstrip
472
+ .element=${child}
473
+ .pixelsPerMs=${pixelsPerMs}
474
+ ></ef-waveform-filmstrip>`;
475
+ }
476
+ return html`<ef-html-filmstrip
477
+ .element=${child}
478
+ .pixelsPerMs=${pixelsPerMs}
479
+ ></ef-html-filmstrip>`;
480
+ });
481
+ };
482
+
483
+ @customElement("ef-filmstrip")
484
+ export class EFFilmStrip extends TWMixin(LitElement) {
485
+ @property({ type: Number })
486
+ pixelsPerMs = 0.04;
487
+
488
+ @property({ type: Number })
489
+ currentTimeMs = 0;
490
+
491
+ @property({ type: String, attribute: "target" })
492
+ targetSelector = "";
493
+
494
+ @state()
495
+ scrubbing = false;
496
+
497
+ @state()
498
+ playing = false;
499
+
500
+ @state()
501
+ timelineScrolltop = 0;
502
+
503
+ timegroupController?: TimegroupController;
504
+
505
+ connectedCallback(): void {
506
+ super.connectedCallback();
507
+ const target = this.target;
508
+ if (target) {
509
+ this.timegroupController = new TimegroupController(target, this);
510
+ // Set the current time to the last saved time to avoid a cycle
511
+ // where the filmstrip clobbers the time loaded from localStorage
512
+ this.currentTimeMs = target.currentTimeMs;
513
+ }
514
+ }
515
+
516
+ @eventOptions({ passive: false })
517
+ syncGutterScroll() {
518
+ if (this.gutter && this.hierarchyRef.value) {
519
+ this.hierarchyRef.value.scrollTop = this.gutter.scrollTop;
520
+ this.timelineScrolltop = this.gutter.scrollTop;
521
+ }
522
+ }
523
+
524
+ @eventOptions({ passive: false })
525
+ syncHierarchyScroll() {
526
+ if (this.gutter && this.hierarchyRef.value) {
527
+ this.gutter.scrollTop = this.hierarchyRef.value.scrollTop;
528
+ this.timelineScrolltop = this.hierarchyRef.value.scrollTop;
529
+ }
530
+ }
531
+
532
+ #lastTick?: DOMHighResTimeStamp;
533
+
534
+ advancePlayhead = (tick?: DOMHighResTimeStamp) => {
535
+ if (this.#lastTick && tick && this.target) {
536
+ this.target.currentTimeMs += tick - this.#lastTick;
537
+ if (this.target.currentTimeMs >= this.target.durationMs) {
538
+ this.playing = false;
539
+ }
540
+ }
541
+ this.#lastTick = tick;
542
+
543
+ if (this.playing) {
544
+ requestAnimationFrame(this.advancePlayhead);
545
+ }
546
+ };
547
+
548
+ @eventOptions({ capture: false })
549
+ scrub(e: MouseEvent) {
550
+ if (this.playing) {
551
+ return;
552
+ }
553
+ if (!this.scrubbing) {
554
+ return;
555
+ }
556
+ const gutter = this.shadowRoot?.querySelector("#gutter");
557
+ if (!gutter) {
558
+ return;
559
+ }
560
+ const rect = gutter.getBoundingClientRect();
561
+ if (this.target) {
562
+ const layerX = e.pageX - rect.left + gutter.scrollLeft;
563
+ this.target.currentTimeMs = layerX / this.pixelsPerMs;
564
+ }
565
+ }
566
+
567
+ @eventOptions({ capture: false })
568
+ startScrub(e: MouseEvent) {
569
+ e.preventDefault();
570
+ this.scrubbing = true;
571
+ // Running scrub in the current microtask doesn't
572
+ // result in an actual update. Not sure why.
573
+ queueMicrotask(() => {
574
+ const gutter = this.shadowRoot?.querySelector("#gutter");
575
+ if (!gutter) {
576
+ return;
577
+ }
578
+ const rect = gutter.getBoundingClientRect();
579
+ if (this.target) {
580
+ const layerX = e.pageX - rect.left + gutter.scrollLeft;
581
+ this.target.currentTimeMs = layerX / this.pixelsPerMs;
582
+ }
583
+ });
584
+ addEventListener(
585
+ "mouseup",
586
+ () => {
587
+ this.scrubbing = false;
588
+ },
589
+ { once: true },
590
+ );
591
+ }
592
+
593
+ @eventOptions({ passive: false })
594
+ scrollScrub(e: WheelEvent) {
595
+ if (this.target && this.gutter && !this.playing) {
596
+ e.preventDefault();
597
+ // Avoid over-scrolling to the left
598
+ if (
599
+ this.gutterRef.value &&
600
+ this.gutterRef.value.scrollLeft === 0 &&
601
+ e.deltaX < 0
602
+ ) {
603
+ this.gutter.scrollBy(0, e.deltaY);
604
+ return;
605
+ }
606
+
607
+ // Avoid over-scrolling to the right
608
+ if (
609
+ this.gutter.scrollWidth - this.gutter.scrollLeft ===
610
+ this.gutter.clientWidth &&
611
+ e.deltaX > 0
612
+ ) {
613
+ this.gutter.scrollBy(0, e.deltaY);
614
+ return;
615
+ }
616
+
617
+ if (this) {
618
+ this.gutter.scrollBy(e.deltaX, e.deltaY);
619
+ this.target.currentTimeMs += e.deltaX / this.pixelsPerMs;
620
+ }
621
+ }
622
+ }
623
+
624
+ gutterRef = createRef<HTMLDivElement>();
625
+ hierarchyRef = createRef<HTMLDivElement>();
626
+ playheadRef = createRef<HTMLDivElement>();
627
+
628
+ get gutter() {
629
+ return this.gutterRef.value;
630
+ }
631
+
632
+ render() {
633
+ const target = this.target;
634
+
635
+ return html` <div
636
+ class="grid h-full bg-slate-100"
637
+ style=${styleMap({
638
+ gridTemplateColumns: "200px 1fr",
639
+ gridTemplateRows: "1.5rem 1fr",
640
+ })}
641
+ >
642
+ <div
643
+ class="z-20 col-span-2 border-b-slate-600 bg-slate-100 shadow shadow-slate-300"
644
+ >
645
+ <input
646
+ type="range"
647
+ .value=${this.pixelsPerMs}
648
+ min="0.01"
649
+ max="0.1"
650
+ step="0.001"
651
+ @input=${(e: Event) => {
652
+ const target = e.target as HTMLInputElement;
653
+ this.pixelsPerMs = Number.parseFloat(target.value);
654
+ }}
655
+ />
656
+ <code>${msToTimeCode(this.currentTimeMs, true)} </code> /
657
+ <code>${msToTimeCode(target?.durationMs ?? 0, true)}</code>
658
+ ${
659
+ this.playing
660
+ ? html`<button
661
+ @click=${() => {
662
+ this.playing = false;
663
+ }}
664
+ >
665
+ ⏸️
666
+ </button>`
667
+ : html`<button
668
+ @click=${() => {
669
+ this.playing = true;
670
+ }}
671
+ >
672
+ ▶️
673
+ </button>`
674
+ }
675
+ </div>
676
+ <div
677
+ class="z-10 pl-1 pr-1 pt-2 shadow shadow-slate-600 overflow-auto"
678
+ ${ref(this.hierarchyRef)}
679
+ @scroll=${this.syncHierarchyScroll}
680
+ >
681
+ ${renderHierarchyChildren(Array.from(target?.children ?? []))}
682
+ </div>
683
+ <div
684
+ class="h-full w-full cursor-crosshair overflow-auto bg-slate-200 pt-2"
685
+ id="gutter"
686
+ ${ref(this.gutterRef)}
687
+ @scroll=${this.syncGutterScroll}
688
+ @wheel=${this.scrollScrub}
689
+ >
690
+ <div
691
+ class="relative h-full w-full"
692
+ style="width: ${this.pixelsPerMs * (target?.durationMs ?? 0)}px;"
693
+ @mousemove=${this.scrub}
694
+ @mousedown=${this.startScrub}
695
+ >
696
+ <div
697
+ class="border-red pointer-events-none absolute z-10 h-full w-[2px] border-r-2 border-red-700"
698
+ style=${styleMap({
699
+ left: `${this.pixelsPerMs * this.currentTimeMs}px`,
700
+ top: `${this.timelineScrolltop}px`,
701
+ })}
702
+ ${ref(this.playheadRef)}
703
+ ></div>
704
+
705
+ ${renderFilmStripChildren(
706
+ Array.from(target?.children || []),
707
+ this.pixelsPerMs,
708
+ )}
709
+ </div>
710
+ </div>
711
+ </div>`;
712
+ }
713
+
714
+ update(changedProperties: Map<string | number | symbol, unknown>) {
715
+ if (changedProperties.has("playing")) {
716
+ if (this.playing) {
717
+ this.advancePlayhead(0);
718
+ }
719
+ }
720
+ super.update(changedProperties);
721
+ }
722
+
723
+ updated(changes: PropertyValueMap<any> | Map<PropertyKey, unknown>) {
724
+ if (!this.target) {
725
+ return;
726
+ }
727
+ if (changes.has("currentTimeMs")) {
728
+ if (this.target.currentTimeMs !== this.currentTimeMs) {
729
+ this.target.currentTimeMs = this.currentTimeMs;
730
+ }
731
+ }
732
+ }
733
+
734
+ get target() {
735
+ if (this.getAttribute("target")) {
736
+ const target = document.querySelector(this.getAttribute("target") ?? "");
737
+ if (target instanceof EFTimegroup) {
738
+ return target;
739
+ }
740
+
741
+ throw new Error("Invalid target, must be an EFTimegroup element");
742
+ }
743
+ return undefined;
744
+ }
745
+ }
746
+
747
+ declare global {
748
+ interface HTMLElementTagNameMap {
749
+ "ef-filmstrip": EFFilmStrip;
750
+ "ef-timegroup-hierarchy-item": EFTimegroupHierarchyItem;
751
+ "ef-audio-hierarchy-item": EFAudioHierarchyItem;
752
+ "ef-video-hierarchy-item": EFVideoHierarchyItem;
753
+ "ef-captions-hierarchy-item": EFCaptionsHierarchyItem;
754
+ "ef-captions-active-word-hierarchy-item": EFCaptionsActiveWordHierarchyItem;
755
+ "ef-waveform-hierarchy-item": EFWaveformHierarchyItem;
756
+ "ef-image-hierarchy-item": EFImageHierarchyItem;
757
+ "ef-html-hierarchy-item": EFHTMLHierarchyItem;
758
+ "ef-timegroup-filmstrip": EFTimegroupFilmstrip;
759
+ "ef-audio-filmstrip": EFAudioFilmstrip;
760
+ "ef-video-filmstrip": EFVideoFilmstrip;
761
+ "ef-captions-filmstrip": EFCaptionsFilmstrip;
762
+ "ef-waveform-filmstrip": EFWaveformFilmstrip;
763
+ "ef-image-filmstrip": EFImageFilmstrip;
764
+ "ef-html-filmstrip": EFHTMLFilmstrip;
765
+ }
766
+ }