@editframe/elements 0.6.0-beta.9 → 0.7.0-beta.10

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.
Files changed (98) hide show
  1. package/dist/lib/av/EncodedAsset.cjs +577 -0
  2. package/dist/lib/av/EncodedAsset.js +560 -0
  3. package/dist/lib/av/MP4File.cjs +187 -0
  4. package/dist/lib/av/MP4File.js +170 -0
  5. package/dist/lib/av/msToTimeCode.cjs +15 -0
  6. package/dist/lib/av/msToTimeCode.js +15 -0
  7. package/dist/lib/util/awaitMicrotask.cjs +4 -0
  8. package/dist/lib/util/awaitMicrotask.js +4 -0
  9. package/dist/lib/util/memoize.cjs +14 -0
  10. package/dist/lib/util/memoize.js +14 -0
  11. package/dist/packages/elements/src/EF_FRAMEGEN.cjs +197 -0
  12. package/dist/packages/elements/src/EF_FRAMEGEN.d.ts +44 -0
  13. package/dist/packages/elements/src/EF_FRAMEGEN.js +197 -0
  14. package/dist/packages/elements/src/EF_INTERACTIVE.cjs +4 -0
  15. package/dist/packages/elements/src/EF_INTERACTIVE.d.ts +1 -0
  16. package/dist/packages/elements/src/EF_INTERACTIVE.js +4 -0
  17. package/dist/packages/elements/src/elements/CrossUpdateController.cjs +16 -0
  18. package/dist/packages/elements/src/elements/CrossUpdateController.d.ts +9 -0
  19. package/dist/packages/elements/src/elements/CrossUpdateController.js +16 -0
  20. package/dist/packages/elements/src/elements/EFAudio.cjs +53 -0
  21. package/dist/packages/elements/src/elements/EFAudio.d.ts +10 -0
  22. package/dist/packages/elements/src/elements/EFAudio.js +54 -0
  23. package/dist/packages/elements/src/elements/EFCaptions.cjs +164 -0
  24. package/dist/packages/elements/src/elements/EFCaptions.d.ts +38 -0
  25. package/dist/packages/elements/src/elements/EFCaptions.js +166 -0
  26. package/dist/packages/elements/src/elements/EFImage.cjs +79 -0
  27. package/dist/packages/elements/src/elements/EFImage.d.ts +14 -0
  28. package/dist/packages/elements/src/elements/EFImage.js +80 -0
  29. package/dist/packages/elements/src/elements/EFMedia.cjs +336 -0
  30. package/dist/packages/elements/src/elements/EFMedia.d.ts +61 -0
  31. package/dist/packages/elements/src/elements/EFMedia.js +336 -0
  32. package/dist/packages/elements/src/elements/EFSourceMixin.cjs +55 -0
  33. package/dist/packages/elements/src/elements/EFSourceMixin.d.ts +12 -0
  34. package/dist/packages/elements/src/elements/EFSourceMixin.js +55 -0
  35. package/dist/packages/elements/src/elements/EFTemporal.cjs +199 -0
  36. package/dist/packages/elements/src/elements/EFTemporal.d.ts +38 -0
  37. package/dist/packages/elements/src/elements/EFTemporal.js +199 -0
  38. package/dist/packages/elements/src/elements/EFTimegroup.browsertest.d.ts +12 -0
  39. package/dist/packages/elements/src/elements/EFTimegroup.cjs +352 -0
  40. package/dist/packages/elements/src/elements/EFTimegroup.d.ts +39 -0
  41. package/dist/packages/elements/src/elements/EFTimegroup.js +353 -0
  42. package/dist/packages/elements/src/elements/EFVideo.cjs +109 -0
  43. package/dist/packages/elements/src/elements/EFVideo.d.ts +14 -0
  44. package/dist/packages/elements/src/elements/EFVideo.js +110 -0
  45. package/dist/packages/elements/src/elements/EFWaveform.cjs +242 -0
  46. package/dist/packages/elements/src/elements/EFWaveform.d.ts +30 -0
  47. package/dist/packages/elements/src/elements/EFWaveform.js +226 -0
  48. package/dist/packages/elements/src/elements/FetchMixin.cjs +28 -0
  49. package/dist/packages/elements/src/elements/FetchMixin.d.ts +8 -0
  50. package/dist/packages/elements/src/elements/FetchMixin.js +28 -0
  51. package/dist/packages/elements/src/elements/TimegroupController.cjs +20 -0
  52. package/dist/packages/elements/src/elements/TimegroupController.d.ts +14 -0
  53. package/dist/packages/elements/src/elements/TimegroupController.js +20 -0
  54. package/dist/packages/elements/src/elements/durationConverter.cjs +8 -0
  55. package/dist/packages/elements/src/elements/durationConverter.d.ts +4 -0
  56. package/dist/packages/elements/src/elements/durationConverter.js +8 -0
  57. package/dist/packages/elements/src/elements/parseTimeToMs.cjs +12 -0
  58. package/dist/packages/elements/src/elements/parseTimeToMs.d.ts +1 -0
  59. package/dist/packages/elements/src/elements/parseTimeToMs.js +12 -0
  60. package/dist/packages/elements/src/elements/util.cjs +11 -0
  61. package/dist/packages/elements/src/elements/util.d.ts +4 -0
  62. package/dist/packages/elements/src/elements/util.js +11 -0
  63. package/dist/packages/elements/src/gui/EFFilmstrip.cjs +825 -0
  64. package/dist/packages/elements/src/gui/EFFilmstrip.d.ts +147 -0
  65. package/dist/packages/elements/src/gui/EFFilmstrip.js +833 -0
  66. package/dist/packages/elements/src/gui/EFWorkbench.cjs +214 -0
  67. package/dist/packages/elements/src/gui/EFWorkbench.d.ts +45 -0
  68. package/dist/packages/elements/src/gui/EFWorkbench.js +215 -0
  69. package/dist/packages/elements/src/gui/TWMixin.cjs +28 -0
  70. package/dist/packages/elements/src/gui/TWMixin.css.cjs +3 -0
  71. package/dist/packages/elements/src/gui/TWMixin.css.js +4 -0
  72. package/dist/packages/elements/src/gui/TWMixin.d.ts +3 -0
  73. package/dist/packages/elements/src/gui/TWMixin.js +28 -0
  74. package/dist/packages/elements/src/index.cjs +50 -0
  75. package/dist/packages/elements/src/index.d.ts +10 -0
  76. package/dist/packages/elements/src/index.js +23 -0
  77. package/dist/style.css +791 -0
  78. package/package.json +14 -8
  79. package/src/elements/CrossUpdateController.ts +22 -0
  80. package/src/elements/EFAudio.ts +40 -0
  81. package/src/elements/EFCaptions.ts +188 -0
  82. package/src/elements/EFImage.ts +68 -0
  83. package/src/elements/EFMedia.ts +389 -0
  84. package/src/elements/EFSourceMixin.ts +57 -0
  85. package/src/elements/EFTemporal.ts +234 -0
  86. package/src/elements/EFTimegroup.browsertest.ts +333 -0
  87. package/src/elements/EFTimegroup.ts +393 -0
  88. package/src/elements/EFVideo.ts +103 -0
  89. package/src/elements/EFWaveform.ts +417 -0
  90. package/src/elements/FetchMixin.ts +19 -0
  91. package/src/elements/TimegroupController.ts +25 -0
  92. package/src/elements/durationConverter.ts +6 -0
  93. package/src/elements/parseTimeToMs.ts +9 -0
  94. package/src/elements/util.ts +24 -0
  95. package/src/gui/EFFilmstrip.ts +884 -0
  96. package/src/gui/EFWorkbench.ts +233 -0
  97. package/src/gui/TWMixin.css +3 -0
  98. package/src/gui/TWMixin.ts +30 -0
@@ -0,0 +1,833 @@
1
+ import { EFTimegroup } from "../elements/EFTimegroup.js";
2
+ import { css, html, nothing, LitElement } from "lit";
3
+ import { property, customElement, state, eventOptions } from "lit/decorators.js";
4
+ import { styleMap } from "lit/directives/style-map.js";
5
+ import { createRef, ref } from "lit/directives/ref.js";
6
+ import { EFImage } from "../elements/EFImage.js";
7
+ import { EFAudio } from "../elements/EFAudio.js";
8
+ import { EFVideo } from "../elements/EFVideo.js";
9
+ import { EFCaptions, EFCaptionsActiveWord } from "../elements/EFCaptions.js";
10
+ import { EFWaveform } from "../elements/EFWaveform.js";
11
+ import { TimegroupController } from "../elements/TimegroupController.js";
12
+ import { consume } from "@lit/context";
13
+ import { focusContext, focusedElement } from "./EFWorkbench.js";
14
+ import { TWMixin } from "./TWMixin.js";
15
+ import { msToTimeCode } from "../../../../lib/av/msToTimeCode.js";
16
+ var __defProp = Object.defineProperty;
17
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
18
+ var __typeError = (msg) => {
19
+ throw TypeError(msg);
20
+ };
21
+ var __decorateClass = (decorators, target, key, kind) => {
22
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
23
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
24
+ if (decorator = decorators[i])
25
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
26
+ if (kind && result) __defProp(target, key, result);
27
+ return result;
28
+ };
29
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
30
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
31
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
33
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
34
+ var _EFFilmstrip_instances, bindToTargetTimegroup_fn, _handleKeyPress, _lastTick, _playbackAudioContext, _playbackAnimationFrameRequest, _AUDIO_PLAYBACK_SLICE_MS, syncPlayheadToAudioContext_fn, stopPlayback_fn, startPlayback_fn;
35
+ class ElementFilmstripController {
36
+ constructor(host, filmstrip) {
37
+ this.host = host;
38
+ this.filmstrip = filmstrip;
39
+ this.host.addController(this);
40
+ }
41
+ remove() {
42
+ this.host.removeController(this);
43
+ }
44
+ hostDisconnected() {
45
+ this.host.removeController(this);
46
+ }
47
+ hostUpdated() {
48
+ this.filmstrip.requestUpdate();
49
+ }
50
+ }
51
+ const CommonEffectKeys = /* @__PURE__ */ new Set([
52
+ "offset",
53
+ "easing",
54
+ "composite",
55
+ "computedOffset"
56
+ ]);
57
+ class FilmstripItem extends TWMixin(LitElement) {
58
+ constructor() {
59
+ super(...arguments);
60
+ this.element = new EFTimegroup();
61
+ this.pixelsPerMs = 0.04;
62
+ }
63
+ static {
64
+ this.styles = [
65
+ css`
66
+ :host {
67
+ display: block;
68
+ }
69
+ `
70
+ ];
71
+ }
72
+ get isFocused() {
73
+ return this.element && this.focusContext?.focusedElement === this.element;
74
+ }
75
+ get styles() {
76
+ return {
77
+ position: "relative",
78
+ left: `${this.pixelsPerMs * this.element.startTimeWithinParentMs}px`,
79
+ width: `${this.pixelsPerMs * this.element.durationMs}px`
80
+ };
81
+ }
82
+ render() {
83
+ return html` <div class="" style=${styleMap(this.styles)}>
84
+ <div
85
+ class="border-outset relative mb-[1px] block h-[1.1rem] text-nowrap border border-slate-500 bg-blue-200 hover:bg-blue-400 text-sm data-[focused]:bg-slate-400"
86
+ ?data-focused=${this.isFocused}
87
+ @mouseenter=${() => {
88
+ if (this.focusContext) {
89
+ this.focusContext.focusedElement = this.element;
90
+ }
91
+ }}
92
+ @mouseleave=${() => {
93
+ if (this.focusContext) {
94
+ this.focusContext.focusedElement = null;
95
+ }
96
+ }}
97
+ >
98
+ ${this.animations()}
99
+ </div>
100
+ ${this.renderChildren()}
101
+ </div>`;
102
+ }
103
+ renderChildren() {
104
+ return renderFilmstripChildren(
105
+ Array.from(this.element.children),
106
+ this.pixelsPerMs
107
+ );
108
+ }
109
+ contents() {
110
+ return html``;
111
+ }
112
+ animations() {
113
+ const animations = this.element.getAnimations();
114
+ return animations.map((animation) => {
115
+ const effect = animation.effect;
116
+ if (!(effect instanceof KeyframeEffect)) {
117
+ return nothing;
118
+ }
119
+ const start = effect.getTiming().delay ?? 0;
120
+ const duration = effect.getTiming().duration;
121
+ if (duration === null) {
122
+ return nothing;
123
+ }
124
+ const keyframes = effect.getKeyframes();
125
+ const firstKeyframe = keyframes[0];
126
+ if (!firstKeyframe) {
127
+ return nothing;
128
+ }
129
+ const properties = new Set(Object.keys(firstKeyframe));
130
+ for (const key of CommonEffectKeys) {
131
+ properties.delete(key);
132
+ }
133
+ return html`<div
134
+ class="relative h-[5px] bg-blue-500 opacity-50"
135
+ label="animation"
136
+ style=${styleMap({
137
+ left: `${this.pixelsPerMs * start}px`,
138
+ width: `${this.pixelsPerMs * Number(duration)}px`
139
+ })}
140
+ >
141
+ <!-- <div class="text-nowrap">${Array.from(properties).join(" ")}</div> -->
142
+ ${effect.getKeyframes().map((keyframe) => {
143
+ return html`<div
144
+ class="absolute top-0 h-full w-1 bg-red-500"
145
+ style=${styleMap({
146
+ left: `${this.pixelsPerMs * keyframe.computedOffset * Number(duration)}px`
147
+ })}
148
+ ></div>`;
149
+ })}
150
+ </div>`;
151
+ });
152
+ }
153
+ update(changedProperties) {
154
+ if (changedProperties.has("element") && this.element instanceof LitElement) {
155
+ this.filmstripController?.remove();
156
+ this.filmstripController = new ElementFilmstripController(
157
+ this.element,
158
+ this
159
+ );
160
+ }
161
+ super.update(changedProperties);
162
+ }
163
+ }
164
+ __decorateClass([
165
+ consume({ context: focusContext, subscribe: true })
166
+ ], FilmstripItem.prototype, "focusContext", 2);
167
+ __decorateClass([
168
+ consume({ context: focusedElement, subscribe: true })
169
+ ], FilmstripItem.prototype, "focusedElement", 2);
170
+ __decorateClass([
171
+ property({ type: HTMLElement, attribute: false })
172
+ ], FilmstripItem.prototype, "element", 2);
173
+ __decorateClass([
174
+ property({ type: Number })
175
+ ], FilmstripItem.prototype, "pixelsPerMs", 2);
176
+ let EFAudioFilmstrip = class extends FilmstripItem {
177
+ contents() {
178
+ return html``;
179
+ }
180
+ };
181
+ EFAudioFilmstrip = __decorateClass([
182
+ customElement("ef-audio-filmstrip")
183
+ ], EFAudioFilmstrip);
184
+ let EFVideoFilmstrip = class extends FilmstripItem {
185
+ contents() {
186
+ return html` 📼 `;
187
+ }
188
+ };
189
+ EFVideoFilmstrip = __decorateClass([
190
+ customElement("ef-video-filmstrip")
191
+ ], EFVideoFilmstrip);
192
+ let EFCaptionsFilmstrip = class extends FilmstripItem {
193
+ contents() {
194
+ return html` 📝 `;
195
+ }
196
+ };
197
+ EFCaptionsFilmstrip = __decorateClass([
198
+ customElement("ef-captions-filmstrip")
199
+ ], EFCaptionsFilmstrip);
200
+ let EFWaveformFilmstrip = class extends FilmstripItem {
201
+ contents() {
202
+ return html` 🌊 `;
203
+ }
204
+ renderChildren() {
205
+ return nothing;
206
+ }
207
+ };
208
+ EFWaveformFilmstrip = __decorateClass([
209
+ customElement("ef-waveform-filmstrip")
210
+ ], EFWaveformFilmstrip);
211
+ let EFImageFilmstrip = class extends FilmstripItem {
212
+ contents() {
213
+ return html` 🖼️ `;
214
+ }
215
+ };
216
+ EFImageFilmstrip = __decorateClass([
217
+ customElement("ef-image-filmstrip")
218
+ ], EFImageFilmstrip);
219
+ let EFTimegroupFilmstrip = class extends FilmstripItem {
220
+ contents() {
221
+ return html`
222
+ <span>TIME GROUP</span>
223
+ ${renderFilmstripChildren(
224
+ Array.from(this.element.children || []),
225
+ this.pixelsPerMs
226
+ )}
227
+ </div>
228
+ `;
229
+ }
230
+ };
231
+ EFTimegroupFilmstrip = __decorateClass([
232
+ customElement("ef-timegroup-filmstrip")
233
+ ], EFTimegroupFilmstrip);
234
+ let EFHTMLFilmstrip = class extends FilmstripItem {
235
+ contents() {
236
+ return html`
237
+ <span>${this.element.tagName}</span>
238
+ ${renderFilmstripChildren(
239
+ Array.from(this.element.children || []),
240
+ this.pixelsPerMs
241
+ )}
242
+ `;
243
+ }
244
+ };
245
+ EFHTMLFilmstrip = __decorateClass([
246
+ customElement("ef-html-filmstrip")
247
+ ], EFHTMLFilmstrip);
248
+ let EFHierarchyItem = class extends TWMixin(LitElement) {
249
+ constructor() {
250
+ super(...arguments);
251
+ this.element = new EFTimegroup();
252
+ }
253
+ get icon() {
254
+ return "📼";
255
+ }
256
+ get isFocused() {
257
+ return this.element && this.focusContext?.focusedElement === this.element;
258
+ }
259
+ displayLabel() {
260
+ return nothing;
261
+ }
262
+ render() {
263
+ return html`
264
+ <div>
265
+ <div
266
+ class="peer
267
+ flex h-[1.1rem] items-center overflow-hidden text-nowrap border border-slate-500
268
+ bg-slate-200 pl-2 text-xs font-mono hover:bg-slate-400 data-[focused]:bg-slate-400"
269
+ ?data-focused=${this.isFocused}
270
+ @mouseenter=${() => {
271
+ if (this.focusContext) {
272
+ this.focusContext.focusedElement = this.element;
273
+ }
274
+ }}
275
+ @mouseleave=${() => {
276
+ if (this.focusContext) {
277
+ this.focusContext.focusedElement = null;
278
+ }
279
+ }}
280
+ >
281
+ ${this.icon} ${this.displayLabel()}
282
+ </div>
283
+ <div
284
+ 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""
285
+ >
286
+ ${this.renderChildren()}
287
+ </div>
288
+ </div>`;
289
+ }
290
+ renderChildren() {
291
+ return renderHierarchyChildren(Array.from(this.element.children));
292
+ }
293
+ };
294
+ __decorateClass([
295
+ property({ type: HTMLElement, attribute: false })
296
+ ], EFHierarchyItem.prototype, "element", 2);
297
+ __decorateClass([
298
+ consume({ context: focusContext })
299
+ ], EFHierarchyItem.prototype, "focusContext", 2);
300
+ __decorateClass([
301
+ consume({ context: focusedElement, subscribe: true })
302
+ ], EFHierarchyItem.prototype, "focusedElement", 2);
303
+ EFHierarchyItem = __decorateClass([
304
+ customElement("ef-hierarchy-item")
305
+ ], EFHierarchyItem);
306
+ let EFTimegroupHierarchyItem = class extends EFHierarchyItem {
307
+ get icon() {
308
+ return "🕒";
309
+ }
310
+ displayLabel() {
311
+ return this.element.mode ?? "(no mode)";
312
+ }
313
+ };
314
+ EFTimegroupHierarchyItem = __decorateClass([
315
+ customElement("ef-timegroup-hierarchy-item")
316
+ ], EFTimegroupHierarchyItem);
317
+ let EFAudioHierarchyItem = class extends EFHierarchyItem {
318
+ get icon() {
319
+ return "🔊";
320
+ }
321
+ displayLabel() {
322
+ return this.element.src ?? "(no src)";
323
+ }
324
+ };
325
+ EFAudioHierarchyItem = __decorateClass([
326
+ customElement("ef-audio-hierarchy-item")
327
+ ], EFAudioHierarchyItem);
328
+ let EFVideoHierarchyItem = class extends EFHierarchyItem {
329
+ get icon() {
330
+ return "📼";
331
+ }
332
+ displayLabel() {
333
+ return this.element.src ?? "(no src)";
334
+ }
335
+ };
336
+ EFVideoHierarchyItem = __decorateClass([
337
+ customElement("ef-video-hierarchy-item")
338
+ ], EFVideoHierarchyItem);
339
+ let EFCaptionsHierarchyItem = class extends EFHierarchyItem {
340
+ get icon() {
341
+ return "📝 Captions";
342
+ }
343
+ };
344
+ EFCaptionsHierarchyItem = __decorateClass([
345
+ customElement("ef-captions-hierarchy-item")
346
+ ], EFCaptionsHierarchyItem);
347
+ let EFCaptionsActiveWordHierarchyItem = class extends EFHierarchyItem {
348
+ get icon() {
349
+ return "🗣️ Active Word";
350
+ }
351
+ };
352
+ EFCaptionsActiveWordHierarchyItem = __decorateClass([
353
+ customElement("ef-captions-active-word-hierarchy-item")
354
+ ], EFCaptionsActiveWordHierarchyItem);
355
+ let EFWaveformHierarchyItem = class extends EFHierarchyItem {
356
+ get icon() {
357
+ return "🌊";
358
+ }
359
+ renderChildren() {
360
+ return nothing;
361
+ }
362
+ };
363
+ EFWaveformHierarchyItem = __decorateClass([
364
+ customElement("ef-waveform-hierarchy-item")
365
+ ], EFWaveformHierarchyItem);
366
+ let EFImageHierarchyItem = class extends EFHierarchyItem {
367
+ get icon() {
368
+ return "🖼️";
369
+ }
370
+ displayLabel() {
371
+ return this.element.src ?? "(no src)";
372
+ }
373
+ };
374
+ EFImageHierarchyItem = __decorateClass([
375
+ customElement("ef-image-hierarchy-item")
376
+ ], EFImageHierarchyItem);
377
+ let EFHTMLHierarchyItem = class extends EFHierarchyItem {
378
+ get icon() {
379
+ return html`<code>${`<${this.element.tagName.toLowerCase()}>`}</code>`;
380
+ }
381
+ };
382
+ EFHTMLHierarchyItem = __decorateClass([
383
+ customElement("ef-html-hierarchy-item")
384
+ ], EFHTMLHierarchyItem);
385
+ const renderHierarchyChildren = (children) => {
386
+ return children.map((child) => {
387
+ if (child instanceof EFTimegroup) {
388
+ return html`<ef-timegroup-hierarchy-item
389
+ .element=${child}
390
+ ></ef-timegroup-hierarchy-item>`;
391
+ }
392
+ if (child instanceof EFImage) {
393
+ return html`<ef-image-hierarchy-item
394
+ .element=${child}
395
+ ></ef-image-hierarchy-item>`;
396
+ }
397
+ if (child instanceof EFAudio) {
398
+ return html`<ef-audio-hierarchy-item
399
+ .element=${child}
400
+ ></ef-audio-hierarchy-item>`;
401
+ }
402
+ if (child instanceof EFVideo) {
403
+ return html`<ef-video-hierarchy-item
404
+ .element=${child}
405
+ ></ef-video-hierarchy-item>`;
406
+ }
407
+ if (child instanceof EFCaptions) {
408
+ return html`<ef-captions-hierarchy-item
409
+ .element=${child}
410
+ ></ef-captions-hierarchy-item>`;
411
+ }
412
+ if (child instanceof EFCaptionsActiveWord) {
413
+ return html`<ef-captions-active-word-hierarchy-item
414
+ .element=${child}
415
+ ></ef-captions-active-word-hierarchy-item>`;
416
+ }
417
+ if (child instanceof EFWaveform) {
418
+ return html`<ef-waveform-hierarchy-item
419
+ .element=${child}
420
+ ></ef-waveform-hierarchy-item>`;
421
+ }
422
+ return html`<ef-html-hierarchy-item
423
+ .element=${child}
424
+ ></ef-html-hierarchy-item>`;
425
+ });
426
+ };
427
+ const renderFilmstripChildren = (children, pixelsPerMs) => {
428
+ return children.map((child) => {
429
+ if (child instanceof EFTimegroup) {
430
+ return html`<ef-timegroup-filmstrip
431
+ .element=${child}
432
+ .pixelsPerMs=${pixelsPerMs}
433
+ >
434
+ </ef-timegroup-filmstrip>`;
435
+ }
436
+ if (child instanceof EFImage) {
437
+ return html`<ef-image-filmstrip
438
+ .element=${child}
439
+ .pixelsPerMs=${pixelsPerMs}
440
+ ></ef-image-filmstrip>`;
441
+ }
442
+ if (child instanceof EFAudio) {
443
+ return html`<ef-audio-filmstrip
444
+ .element=${child}
445
+ .pixelsPerMs=${pixelsPerMs}
446
+ ></ef-audio-filmstrip>`;
447
+ }
448
+ if (child instanceof EFVideo) {
449
+ return html`<ef-video-filmstrip
450
+ .element=${child}
451
+ .pixelsPerMs=${pixelsPerMs}
452
+ ></ef-video-filmstrip>`;
453
+ }
454
+ if (child instanceof EFCaptions) {
455
+ return html`<ef-captions-filmstrip
456
+ .element=${child}
457
+ .pixelsPerMs=${pixelsPerMs}
458
+ ></ef-captions-filmstrip>`;
459
+ }
460
+ if (child instanceof EFWaveform) {
461
+ return html`<ef-waveform-filmstrip
462
+ .element=${child}
463
+ .pixelsPerMs=${pixelsPerMs}
464
+ ></ef-waveform-filmstrip>`;
465
+ }
466
+ return html`<ef-html-filmstrip
467
+ .element=${child}
468
+ .pixelsPerMs=${pixelsPerMs}
469
+ ></ef-html-filmstrip>`;
470
+ });
471
+ };
472
+ let EFFilmstrip = class extends TWMixin(LitElement) {
473
+ constructor() {
474
+ super(...arguments);
475
+ __privateAdd(this, _EFFilmstrip_instances);
476
+ this.pixelsPerMs = 0.04;
477
+ this.currentTimeMs = 0;
478
+ this.targetSelector = "";
479
+ this.scrubbing = false;
480
+ this.playing = false;
481
+ this.timelineScrolltop = 0;
482
+ __privateAdd(this, _handleKeyPress, (event) => {
483
+ if (event.key === " ") {
484
+ const interactiveSelector = "input, textarea, button, select, a, [contenteditable]";
485
+ const closestInteractive = event.target?.closest(
486
+ interactiveSelector
487
+ );
488
+ if (closestInteractive) {
489
+ return;
490
+ }
491
+ event.preventDefault();
492
+ this.playing = !this.playing;
493
+ }
494
+ });
495
+ __privateAdd(this, _lastTick);
496
+ __privateAdd(this, _playbackAudioContext, null);
497
+ __privateAdd(this, _playbackAnimationFrameRequest, null);
498
+ __privateAdd(this, _AUDIO_PLAYBACK_SLICE_MS, 1e3);
499
+ this.advancePlayhead = (tick) => {
500
+ if (__privateGet(this, _lastTick) && tick && this.targetTimegroup) {
501
+ this.targetTimegroup.currentTimeMs += tick - __privateGet(this, _lastTick);
502
+ if (this.targetTimegroup.currentTimeMs >= this.targetTimegroup.durationMs) {
503
+ this.playing = false;
504
+ }
505
+ }
506
+ __privateSet(this, _lastTick, tick);
507
+ if (this.playing) {
508
+ requestAnimationFrame(this.advancePlayhead);
509
+ }
510
+ };
511
+ this.gutterRef = createRef();
512
+ this.hierarchyRef = createRef();
513
+ this.playheadRef = createRef();
514
+ }
515
+ connectedCallback() {
516
+ super.connectedCallback();
517
+ __privateMethod(this, _EFFilmstrip_instances, bindToTargetTimegroup_fn).call(this);
518
+ window.addEventListener("keypress", __privateGet(this, _handleKeyPress));
519
+ }
520
+ disconnectedCallback() {
521
+ super.disconnectedCallback();
522
+ window.removeEventListener("keypress", __privateGet(this, _handleKeyPress));
523
+ }
524
+ syncGutterScroll() {
525
+ if (this.gutter && this.hierarchyRef.value) {
526
+ this.hierarchyRef.value.scrollTop = this.gutter.scrollTop;
527
+ this.timelineScrolltop = this.gutter.scrollTop;
528
+ }
529
+ }
530
+ syncHierarchyScroll() {
531
+ if (this.gutter && this.hierarchyRef.value) {
532
+ this.gutter.scrollTop = this.hierarchyRef.value.scrollTop;
533
+ this.timelineScrolltop = this.hierarchyRef.value.scrollTop;
534
+ }
535
+ }
536
+ scrub(e) {
537
+ if (this.playing) {
538
+ return;
539
+ }
540
+ if (!this.scrubbing) {
541
+ return;
542
+ }
543
+ const gutter = this.shadowRoot?.querySelector("#gutter");
544
+ if (!gutter) {
545
+ return;
546
+ }
547
+ const rect = gutter.getBoundingClientRect();
548
+ if (this.targetTimegroup) {
549
+ const layerX = e.pageX - rect.left + gutter.scrollLeft;
550
+ this.targetTimegroup.currentTimeMs = layerX / this.pixelsPerMs;
551
+ }
552
+ }
553
+ startScrub(e) {
554
+ e.preventDefault();
555
+ this.scrubbing = true;
556
+ queueMicrotask(() => {
557
+ const gutter = this.shadowRoot?.querySelector("#gutter");
558
+ if (!gutter) {
559
+ return;
560
+ }
561
+ const rect = gutter.getBoundingClientRect();
562
+ if (this.targetTimegroup) {
563
+ const layerX = e.pageX - rect.left + gutter.scrollLeft;
564
+ this.targetTimegroup.currentTimeMs = layerX / this.pixelsPerMs;
565
+ }
566
+ });
567
+ addEventListener(
568
+ "mouseup",
569
+ () => {
570
+ this.scrubbing = false;
571
+ },
572
+ { once: true }
573
+ );
574
+ }
575
+ scrollScrub(e) {
576
+ if (this.targetTimegroup && this.gutter && !this.playing) {
577
+ e.preventDefault();
578
+ if (this.gutterRef.value && this.gutterRef.value.scrollLeft === 0 && e.deltaX < 0) {
579
+ this.gutter.scrollBy(0, e.deltaY);
580
+ return;
581
+ }
582
+ if (this.gutter.scrollWidth - this.gutter.scrollLeft === this.gutter.clientWidth && e.deltaX > 0) {
583
+ this.gutter.scrollBy(0, e.deltaY);
584
+ return;
585
+ }
586
+ if (this) {
587
+ this.gutter.scrollBy(e.deltaX, e.deltaY);
588
+ this.targetTimegroup.currentTimeMs += e.deltaX / this.pixelsPerMs;
589
+ }
590
+ }
591
+ }
592
+ get gutter() {
593
+ return this.gutterRef.value;
594
+ }
595
+ render() {
596
+ const target = this.targetTimegroup;
597
+ return html` <div
598
+ class="grid h-full bg-slate-100"
599
+ style=${styleMap({
600
+ gridTemplateColumns: "200px 1fr",
601
+ gridTemplateRows: "1.5rem 1fr"
602
+ })}
603
+ >
604
+ <div
605
+ class="z-20 col-span-2 border-b-slate-600 bg-slate-100 shadow shadow-slate-300"
606
+ >
607
+ <input
608
+ type="range"
609
+ .value=${this.pixelsPerMs}
610
+ min="0.01"
611
+ max="0.1"
612
+ step="0.001"
613
+ @input=${(e) => {
614
+ const target2 = e.target;
615
+ this.pixelsPerMs = Number.parseFloat(target2.value);
616
+ }}
617
+ />
618
+ <code>${msToTimeCode(this.currentTimeMs, true)} </code> /
619
+ <code>${msToTimeCode(target?.durationMs ?? 0, true)}</code>
620
+ ${this.playing ? html`<button
621
+ @click=${() => {
622
+ this.playing = false;
623
+ }}
624
+ >
625
+ ⏸️
626
+ </button>` : html`<button
627
+ @click=${() => {
628
+ this.playing = true;
629
+ }}
630
+ >
631
+ ▶️
632
+ </button>`}
633
+ </div>
634
+ <div
635
+ class="z-10 pl-1 pr-1 pt-2 shadow shadow-slate-600 overflow-auto"
636
+ ${ref(this.hierarchyRef)}
637
+ @scroll=${this.syncHierarchyScroll}
638
+ >
639
+ ${renderHierarchyChildren(target ? [target] : [])}
640
+ </div>
641
+ <div
642
+ class="h-full w-full cursor-crosshair overflow-auto bg-slate-200 pt-2"
643
+ id="gutter"
644
+ ${ref(this.gutterRef)}
645
+ @scroll=${this.syncGutterScroll}
646
+ @wheel=${this.scrollScrub}
647
+ >
648
+ <div
649
+ class="relative h-full w-full"
650
+ style="width: ${this.pixelsPerMs * (target?.durationMs ?? 0)}px;"
651
+ @mousemove=${this.scrub}
652
+ @mousedown=${this.startScrub}
653
+ >
654
+ <div
655
+ class="border-red pointer-events-none absolute z-10 h-full w-[2px] border-r-2 border-red-700"
656
+ style=${styleMap({
657
+ left: `${this.pixelsPerMs * this.currentTimeMs}px`,
658
+ top: `${this.timelineScrolltop}px`
659
+ })}
660
+ ${ref(this.playheadRef)}
661
+ ></div>
662
+
663
+ ${renderFilmstripChildren(target ? [target] : [], this.pixelsPerMs)}
664
+ </div>
665
+ </div>
666
+ </div>`;
667
+ }
668
+ update(changedProperties) {
669
+ if (changedProperties.has("playing")) {
670
+ if (this.playing) {
671
+ __privateMethod(this, _EFFilmstrip_instances, startPlayback_fn).call(this);
672
+ } else {
673
+ __privateMethod(this, _EFFilmstrip_instances, stopPlayback_fn).call(this);
674
+ }
675
+ }
676
+ super.update(changedProperties);
677
+ }
678
+ updated(changes) {
679
+ if (!this.targetTimegroup) {
680
+ return;
681
+ }
682
+ if (changes.has("currentTimeMs")) {
683
+ if (this.targetTimegroup.currentTimeMs !== this.currentTimeMs) {
684
+ this.targetTimegroup.currentTimeMs = this.currentTimeMs;
685
+ }
686
+ }
687
+ if (changes.has("target")) {
688
+ __privateMethod(this, _EFFilmstrip_instances, bindToTargetTimegroup_fn).call(this);
689
+ }
690
+ }
691
+ get targetTimegroup() {
692
+ if (this.getAttribute("target")) {
693
+ const target = document.getElementById(this.getAttribute("target") ?? "");
694
+ if (target instanceof EFTimegroup) {
695
+ return target;
696
+ }
697
+ }
698
+ return void 0;
699
+ }
700
+ };
701
+ _EFFilmstrip_instances = /* @__PURE__ */ new WeakSet();
702
+ bindToTargetTimegroup_fn = function() {
703
+ if (this.timegroupController) {
704
+ this.timegroupController.remove();
705
+ }
706
+ const target = this.targetTimegroup;
707
+ if (target) {
708
+ this.timegroupController = new TimegroupController(target, this);
709
+ this.currentTimeMs = target.currentTimeMs;
710
+ }
711
+ };
712
+ _handleKeyPress = /* @__PURE__ */ new WeakMap();
713
+ _lastTick = /* @__PURE__ */ new WeakMap();
714
+ _playbackAudioContext = /* @__PURE__ */ new WeakMap();
715
+ _playbackAnimationFrameRequest = /* @__PURE__ */ new WeakMap();
716
+ _AUDIO_PLAYBACK_SLICE_MS = /* @__PURE__ */ new WeakMap();
717
+ syncPlayheadToAudioContext_fn = function(target, startMs) {
718
+ target.currentTimeMs = startMs + (__privateGet(this, _playbackAudioContext)?.currentTime ?? 0) * 1e3;
719
+ __privateSet(this, _playbackAnimationFrameRequest, requestAnimationFrame(() => {
720
+ __privateMethod(this, _EFFilmstrip_instances, syncPlayheadToAudioContext_fn).call(this, target, startMs);
721
+ }));
722
+ };
723
+ stopPlayback_fn = async function() {
724
+ if (__privateGet(this, _playbackAudioContext)) {
725
+ if (__privateGet(this, _playbackAudioContext).state !== "closed") {
726
+ await __privateGet(this, _playbackAudioContext).close();
727
+ }
728
+ }
729
+ if (__privateGet(this, _playbackAnimationFrameRequest)) {
730
+ cancelAnimationFrame(__privateGet(this, _playbackAnimationFrameRequest));
731
+ }
732
+ __privateSet(this, _playbackAudioContext, null);
733
+ };
734
+ startPlayback_fn = async function() {
735
+ await __privateMethod(this, _EFFilmstrip_instances, stopPlayback_fn).call(this);
736
+ const timegroup = this.targetTimegroup;
737
+ if (!timegroup) {
738
+ return;
739
+ }
740
+ let currentMs = timegroup.currentTimeMs;
741
+ let bufferCount = 0;
742
+ __privateSet(this, _playbackAudioContext, new AudioContext({
743
+ latencyHint: "playback"
744
+ }));
745
+ if (__privateGet(this, _playbackAnimationFrameRequest)) {
746
+ cancelAnimationFrame(__privateGet(this, _playbackAnimationFrameRequest));
747
+ }
748
+ __privateMethod(this, _EFFilmstrip_instances, syncPlayheadToAudioContext_fn).call(this, timegroup, currentMs);
749
+ const playbackContext = __privateGet(this, _playbackAudioContext);
750
+ await playbackContext.suspend();
751
+ const fillBuffer = async () => {
752
+ if (bufferCount > 1) {
753
+ return;
754
+ }
755
+ const canFillBuffer = await queueBufferSource();
756
+ if (canFillBuffer) {
757
+ fillBuffer();
758
+ }
759
+ };
760
+ const fromMs = currentMs;
761
+ const toMs = timegroup.endTimeMs;
762
+ const queueBufferSource = async () => {
763
+ if (currentMs >= toMs) {
764
+ return false;
765
+ }
766
+ const startMs = currentMs;
767
+ const endMs = currentMs + __privateGet(this, _AUDIO_PLAYBACK_SLICE_MS);
768
+ currentMs += __privateGet(this, _AUDIO_PLAYBACK_SLICE_MS);
769
+ const audioBuffer = await timegroup.renderAudio(startMs, endMs);
770
+ bufferCount++;
771
+ const source = playbackContext.createBufferSource();
772
+ source.buffer = audioBuffer;
773
+ source.connect(playbackContext.destination);
774
+ source.start((startMs - fromMs) / 1e3);
775
+ source.onended = () => {
776
+ bufferCount--;
777
+ if (endMs >= toMs) {
778
+ this.playing = false;
779
+ } else {
780
+ fillBuffer();
781
+ }
782
+ };
783
+ return true;
784
+ };
785
+ await fillBuffer();
786
+ await playbackContext.resume();
787
+ };
788
+ __decorateClass([
789
+ property({ type: Number })
790
+ ], EFFilmstrip.prototype, "pixelsPerMs", 2);
791
+ __decorateClass([
792
+ property({ type: Number })
793
+ ], EFFilmstrip.prototype, "currentTimeMs", 2);
794
+ __decorateClass([
795
+ property({ type: String, attribute: "target", reflect: true })
796
+ ], EFFilmstrip.prototype, "targetSelector", 2);
797
+ __decorateClass([
798
+ state()
799
+ ], EFFilmstrip.prototype, "scrubbing", 2);
800
+ __decorateClass([
801
+ state()
802
+ ], EFFilmstrip.prototype, "playing", 2);
803
+ __decorateClass([
804
+ state()
805
+ ], EFFilmstrip.prototype, "timelineScrolltop", 2);
806
+ __decorateClass([
807
+ eventOptions({ passive: false })
808
+ ], EFFilmstrip.prototype, "syncGutterScroll", 1);
809
+ __decorateClass([
810
+ eventOptions({ passive: false })
811
+ ], EFFilmstrip.prototype, "syncHierarchyScroll", 1);
812
+ __decorateClass([
813
+ eventOptions({ capture: false })
814
+ ], EFFilmstrip.prototype, "scrub", 1);
815
+ __decorateClass([
816
+ eventOptions({ capture: false })
817
+ ], EFFilmstrip.prototype, "startScrub", 1);
818
+ __decorateClass([
819
+ eventOptions({ passive: false })
820
+ ], EFFilmstrip.prototype, "scrollScrub", 1);
821
+ EFFilmstrip = __decorateClass([
822
+ customElement("ef-filmstrip")
823
+ ], EFFilmstrip);
824
+ export {
825
+ EFAudioFilmstrip,
826
+ EFCaptionsFilmstrip,
827
+ EFFilmstrip,
828
+ EFHTMLFilmstrip,
829
+ EFImageFilmstrip,
830
+ EFTimegroupFilmstrip,
831
+ EFVideoFilmstrip,
832
+ EFWaveformFilmstrip
833
+ };