@editframe/elements 0.16.7-beta.0 → 0.17.6-beta.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.
Files changed (101) hide show
  1. package/README.md +30 -0
  2. package/dist/DecoderResetFrequency.test.d.ts +1 -0
  3. package/dist/DecoderResetRecovery.test.d.ts +1 -0
  4. package/dist/DelayedLoadingState.d.ts +48 -0
  5. package/dist/DelayedLoadingState.integration.test.d.ts +1 -0
  6. package/dist/DelayedLoadingState.js +113 -0
  7. package/dist/DelayedLoadingState.test.d.ts +1 -0
  8. package/dist/EF_FRAMEGEN.d.ts +10 -1
  9. package/dist/EF_FRAMEGEN.js +199 -179
  10. package/dist/EF_INTERACTIVE.js +2 -6
  11. package/dist/EF_RENDERING.js +1 -3
  12. package/dist/JitTranscodingClient.browsertest.d.ts +1 -0
  13. package/dist/JitTranscodingClient.d.ts +167 -0
  14. package/dist/JitTranscodingClient.js +373 -0
  15. package/dist/JitTranscodingClient.test.d.ts +1 -0
  16. package/dist/LoadingDebounce.test.d.ts +1 -0
  17. package/dist/LoadingIndicator.browsertest.d.ts +0 -0
  18. package/dist/ManualScrubTest.test.d.ts +1 -0
  19. package/dist/ScrubResolvedFlashing.test.d.ts +1 -0
  20. package/dist/ScrubTrackIntegration.test.d.ts +1 -0
  21. package/dist/ScrubTrackManager.d.ts +96 -0
  22. package/dist/ScrubTrackManager.js +216 -0
  23. package/dist/ScrubTrackManager.test.d.ts +1 -0
  24. package/dist/SegmentSwitchLoading.test.d.ts +1 -0
  25. package/dist/VideoSeekFlashing.browsertest.d.ts +0 -0
  26. package/dist/VideoStuckDiagnostic.test.d.ts +1 -0
  27. package/dist/elements/CrossUpdateController.js +13 -15
  28. package/dist/elements/EFAudio.browsertest.d.ts +0 -0
  29. package/dist/elements/EFAudio.d.ts +1 -1
  30. package/dist/elements/EFAudio.js +30 -43
  31. package/dist/elements/EFCaptions.js +337 -373
  32. package/dist/elements/EFImage.js +64 -90
  33. package/dist/elements/EFMedia.d.ts +98 -33
  34. package/dist/elements/EFMedia.js +1169 -678
  35. package/dist/elements/EFSourceMixin.js +31 -48
  36. package/dist/elements/EFTemporal.d.ts +1 -0
  37. package/dist/elements/EFTemporal.js +266 -360
  38. package/dist/elements/EFTimegroup.d.ts +3 -1
  39. package/dist/elements/EFTimegroup.js +262 -323
  40. package/dist/elements/EFVideo.browsertest.d.ts +0 -0
  41. package/dist/elements/EFVideo.d.ts +90 -2
  42. package/dist/elements/EFVideo.js +408 -111
  43. package/dist/elements/EFWaveform.js +375 -411
  44. package/dist/elements/FetchMixin.js +14 -24
  45. package/dist/elements/MediaController.d.ts +30 -0
  46. package/dist/elements/TargetController.js +130 -156
  47. package/dist/elements/TimegroupController.js +17 -19
  48. package/dist/elements/durationConverter.js +15 -4
  49. package/dist/elements/parseTimeToMs.js +4 -10
  50. package/dist/elements/printTaskStatus.d.ts +2 -0
  51. package/dist/elements/printTaskStatus.js +11 -0
  52. package/dist/elements/updateAnimations.js +39 -59
  53. package/dist/getRenderInfo.js +58 -67
  54. package/dist/gui/ContextMixin.js +203 -288
  55. package/dist/gui/EFConfiguration.js +27 -43
  56. package/dist/gui/EFFilmstrip.js +440 -620
  57. package/dist/gui/EFFitScale.js +112 -135
  58. package/dist/gui/EFFocusOverlay.js +45 -61
  59. package/dist/gui/EFPreview.js +30 -49
  60. package/dist/gui/EFScrubber.js +78 -99
  61. package/dist/gui/EFTimeDisplay.js +49 -70
  62. package/dist/gui/EFToggleLoop.js +17 -34
  63. package/dist/gui/EFTogglePlay.js +37 -58
  64. package/dist/gui/EFWorkbench.js +66 -88
  65. package/dist/gui/TWMixin.js +2 -48
  66. package/dist/gui/TWMixin2.js +31 -0
  67. package/dist/gui/efContext.js +2 -6
  68. package/dist/gui/fetchContext.js +1 -3
  69. package/dist/gui/focusContext.js +1 -3
  70. package/dist/gui/focusedElementContext.js +2 -6
  71. package/dist/gui/playingContext.js +1 -4
  72. package/dist/index.js +5 -30
  73. package/dist/msToTimeCode.js +11 -13
  74. package/dist/style.css +2 -1
  75. package/package.json +3 -3
  76. package/src/elements/EFAudio.browsertest.ts +569 -0
  77. package/src/elements/EFAudio.ts +4 -6
  78. package/src/elements/EFCaptions.browsertest.ts +0 -1
  79. package/src/elements/EFImage.browsertest.ts +0 -1
  80. package/src/elements/EFMedia.browsertest.ts +147 -115
  81. package/src/elements/EFMedia.ts +1339 -307
  82. package/src/elements/EFTemporal.browsertest.ts +0 -1
  83. package/src/elements/EFTemporal.ts +11 -0
  84. package/src/elements/EFTimegroup.ts +73 -10
  85. package/src/elements/EFVideo.browsertest.ts +680 -0
  86. package/src/elements/EFVideo.ts +729 -50
  87. package/src/elements/EFWaveform.ts +4 -4
  88. package/src/elements/MediaController.ts +108 -0
  89. package/src/elements/__screenshots__/EFMedia.browsertest.ts/EFMedia-JIT-audio-playback-audioBufferTask-should-work-in-JIT-mode-without-URL-errors-1.png +0 -0
  90. package/src/elements/printTaskStatus.ts +16 -0
  91. package/src/elements/updateAnimations.ts +6 -0
  92. package/src/gui/TWMixin.ts +10 -3
  93. package/test/EFVideo.frame-tasks.browsertest.ts +524 -0
  94. package/test/EFVideo.framegen.browsertest.ts +118 -0
  95. package/test/createJitTestClips.ts +293 -0
  96. package/test/useAssetMSW.ts +49 -0
  97. package/test/useMSW.ts +31 -0
  98. package/types.json +1 -1
  99. package/dist/gui/TWMixin.css.js +0 -4
  100. /package/dist/elements/{TargetController.test.d.ts → TargetController.browsertest.d.ts} +0 -0
  101. /package/src/elements/{TargetController.test.ts → TargetController.browsertest.ts} +0 -0
@@ -1,305 +1,44 @@
1
- import { provide } from "@lit/context";
2
- import { Task } from "@lit/task";
3
- import debug from "debug";
4
- import { LitElement, html, css } from "lit";
5
- import { property, customElement } from "lit/decorators.js";
6
1
  import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
7
2
  import { isContextMixin } from "../gui/ContextMixin.js";
8
- import { deepGetMediaElements } from "./EFMedia.js";
9
- import { EFTemporal, shallowGetTemporalElements, timegroupContext } from "./EFTemporal.js";
10
- import { TimegroupController } from "./TimegroupController.js";
11
3
  import { durationConverter } from "./durationConverter.js";
4
+ import { EFTemporal, deepGetElementsWithFrameTasks, flushStartTimeMsCache, shallowGetTemporalElements, timegroupContext } from "./EFTemporal.js";
12
5
  import { updateAnimations } from "./updateAnimations.js";
13
- var __defProp = Object.defineProperty;
14
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
- var __typeError = (msg) => {
16
- throw TypeError(msg);
17
- };
18
- var __decorateClass = (decorators, target, key, kind) => {
19
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
- if (decorator = decorators[i])
22
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
- if (kind && result) __defProp(target, key, result);
24
- return result;
25
- };
26
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
27
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
28
- 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);
29
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
30
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
31
- var _currentTime, _resizeObserver, _EFTimegroup_instances, addAudioToContext_fn;
6
+ import { deepGetMediaElements } from "./EFMedia.js";
7
+ import { TimegroupController } from "./TimegroupController.js";
8
+ import { provide } from "@lit/context";
9
+ import { Task, TaskStatus } from "@lit/task";
10
+ import debug from "debug";
11
+ import { LitElement, css, html } from "lit";
12
+ import { customElement, property } from "lit/decorators.js";
13
+ import _decorate from "@oxc-project/runtime/helpers/decorate";
14
+ var _EFTimegroup;
32
15
  const log = debug("ef:elements:EFTimegroup");
33
16
  const shallowGetTimegroups = (element, groups = []) => {
34
- for (const child of Array.from(element.children)) {
35
- if (child instanceof EFTimegroup) {
36
- groups.push(child);
37
- } else {
38
- shallowGetTimegroups(child, groups);
39
- }
40
- }
41
- return groups;
42
- };
43
- let EFTimegroup = class extends EFTemporal(LitElement) {
44
- constructor() {
45
- super(...arguments);
46
- __privateAdd(this, _EFTimegroup_instances);
47
- this._timeGroupContext = this;
48
- __privateAdd(this, _currentTime, 0);
49
- this.mode = "contain";
50
- this.overlapMs = 0;
51
- this.fit = "none";
52
- __privateAdd(this, _resizeObserver);
53
- this.frameTask = new Task(this, {
54
- autoRun: EF_INTERACTIVE,
55
- args: () => [this.ownCurrentTimeMs, this.currentTimeMs],
56
- task: async ([], { signal: _signal }) => {
57
- let fullyUpdated = await this.updateComplete;
58
- while (!fullyUpdated) {
59
- fullyUpdated = await this.updateComplete;
60
- }
61
- }
62
- });
63
- }
64
- set currentTime(time) {
65
- __privateSet(this, _currentTime, Math.max(0, Math.min(time, this.durationMs / 1e3)));
66
- try {
67
- if (this.id) {
68
- if (this.isConnected) {
69
- localStorage.setItem(this.storageKey, time.toString());
70
- }
71
- }
72
- } catch (error) {
73
- log("Failed to save time to localStorage", error);
74
- }
75
- }
76
- get currentTime() {
77
- return __privateGet(this, _currentTime);
78
- }
79
- get currentTimeMs() {
80
- return this.currentTime * 1e3;
81
- }
82
- set currentTimeMs(ms) {
83
- this.currentTime = ms / 1e3;
84
- }
85
- render() {
86
- return html`<slot></slot> `;
87
- }
88
- maybeLoadTimeFromLocalStorage() {
89
- if (this.id) {
90
- try {
91
- return Number.parseFloat(localStorage.getItem(this.storageKey) || "0");
92
- } catch (error) {
93
- log("Failed to load time from localStorage", error);
94
- }
95
- }
96
- return 0;
97
- }
98
- connectedCallback() {
99
- super.connectedCallback();
100
- if (this.id) {
101
- this.waitForMediaDurations().then(() => {
102
- __privateSet(this, _currentTime, this.maybeLoadTimeFromLocalStorage());
103
- });
104
- }
105
- if (this.parentTimegroup) {
106
- new TimegroupController(this.parentTimegroup, this);
107
- }
108
- if (this.shouldWrapWithWorkbench()) {
109
- this.wrapWithWorkbench();
110
- }
111
- requestAnimationFrame(() => {
112
- this.updateAnimations();
113
- });
114
- }
115
- disconnectedCallback() {
116
- super.disconnectedCallback();
117
- __privateGet(this, _resizeObserver)?.disconnect();
118
- }
119
- get storageKey() {
120
- if (!this.id) {
121
- throw new Error("Timegroup must have an id to use localStorage.");
122
- }
123
- return `ef-timegroup-${this.id}`;
124
- }
125
- get intrinsicDurationMs() {
126
- if (this.hasExplicitDuration) {
127
- return this.explicitDurationMs;
128
- }
129
- return void 0;
130
- }
131
- get hasOwnDuration() {
132
- return this.mode === "contain" || this.mode === "sequence" || this.mode === "fixed" && this.hasExplicitDuration;
133
- }
134
- get durationMs() {
135
- switch (this.mode) {
136
- case "fit": {
137
- if (!this.parentTimegroup) {
138
- return 0;
139
- }
140
- return this.parentTimegroup.durationMs;
141
- }
142
- case "fixed":
143
- return super.durationMs;
144
- case "sequence": {
145
- let duration = 0;
146
- this.childTemporals.forEach((child, index) => {
147
- if (child instanceof EFTimegroup && child.mode === "fit") {
148
- return;
149
- }
150
- if (index > 0) {
151
- duration -= this.overlapMs;
152
- }
153
- duration += child.durationMs;
154
- });
155
- return duration;
156
- }
157
- case "contain": {
158
- let maxDuration = 0;
159
- for (const child of this.childTemporals) {
160
- if (child instanceof EFTimegroup && child.mode === "fit") {
161
- continue;
162
- }
163
- if (!child.hasOwnDuration) {
164
- continue;
165
- }
166
- maxDuration = Math.max(maxDuration, child.durationMs);
167
- }
168
- return maxDuration;
169
- }
170
- default:
171
- throw new Error(`Invalid time mode: ${this.mode}`);
172
- }
173
- }
174
- /**
175
- * Wait for all media elements to load their initial segments.
176
- * Ideally we would only need the extracted index json data, but
177
- * that caused issues with constructing audio data. We had negative durations
178
- * in calculations and it was not clear why.
179
- */
180
- async waitForMediaDurations() {
181
- const mediaElements = deepGetMediaElements(this);
182
- return await Promise.all(
183
- mediaElements.map((m) => m.trackFragmentIndexLoader.taskComplete)
184
- );
185
- }
186
- get childTemporals() {
187
- return shallowGetTemporalElements(this);
188
- }
189
- updated(changedProperties) {
190
- super.updated(changedProperties);
191
- if (changedProperties.has("currentTime") || changedProperties.has("ownCurrentTimeMs")) {
192
- this.updateAnimations();
193
- }
194
- }
195
- updateAnimations() {
196
- updateAnimations(this);
197
- }
198
- get contextProvider() {
199
- let parent = this.parentNode;
200
- while (parent) {
201
- if (isContextMixin(parent)) {
202
- return parent;
203
- }
204
- parent = parent.parentNode;
205
- }
206
- return null;
207
- }
208
- /**
209
- * Returns true if the timegroup should be wrapped with a workbench.
210
- *
211
- * A timegroup should be wrapped with a workbench if it is the root-most timegroup
212
- * and EF_INTERACTIVE is true.
213
- *
214
- * If the timegroup is already wrappedin a context provider like ef-preview,
215
- * it should NOT be wrapped in a workbench.
216
- */
217
- shouldWrapWithWorkbench() {
218
- return EF_INTERACTIVE && this.closest("ef-timegroup") === this && this.closest("ef-preview") === null && this.closest("ef-workbench") === null && this.closest("test-context") === null;
219
- }
220
- wrapWithWorkbench() {
221
- const workbench = document.createElement("ef-workbench");
222
- this.parentElement?.append(workbench);
223
- if (!this.hasAttribute("id")) {
224
- this.setAttribute("id", "root-this");
225
- }
226
- this.setAttribute("slot", "canvas");
227
- workbench.append(this);
228
- const filmstrip = document.createElement("ef-filmstrip");
229
- filmstrip.setAttribute("slot", "timeline");
230
- filmstrip.setAttribute("target", this.id);
231
- workbench.append(filmstrip);
232
- }
233
- get efElements() {
234
- return Array.from(
235
- this.querySelectorAll(
236
- "ef-audio, ef-video, ef-image, ef-captions, ef-waveform"
237
- )
238
- );
239
- }
240
- async renderAudio(fromMs, toMs) {
241
- const durationMs = toMs - fromMs;
242
- const audioContext = new OfflineAudioContext(
243
- 2,
244
- Math.round(48e3 * durationMs / 1e3),
245
- 48e3
246
- );
247
- await __privateMethod(this, _EFTimegroup_instances, addAudioToContext_fn).call(this, audioContext, fromMs, toMs);
248
- return await audioContext.startRendering();
249
- }
250
- async loadMd5Sums() {
251
- const efElements = this.efElements;
252
- const loaderTasks = [];
253
- for (const el of efElements) {
254
- const md5SumLoader = el.md5SumLoader;
255
- if (md5SumLoader instanceof Task) {
256
- md5SumLoader.run();
257
- loaderTasks.push(md5SumLoader.taskComplete);
258
- }
259
- }
260
- await Promise.all(loaderTasks);
261
- efElements.map((el) => {
262
- if ("productionSrc" in el && el.productionSrc instanceof Function) {
263
- el.setAttribute("src", el.productionSrc());
264
- }
265
- });
266
- }
267
- };
268
- _currentTime = /* @__PURE__ */ new WeakMap();
269
- _resizeObserver = /* @__PURE__ */ new WeakMap();
270
- _EFTimegroup_instances = /* @__PURE__ */ new WeakSet();
271
- addAudioToContext_fn = async function(audioContext, fromMs, toMs) {
272
- await this.waitForMediaDurations();
273
- await Promise.all(
274
- deepGetMediaElements(this).map(async (mediaElement) => {
275
- const mediaStartsBeforeEnd = mediaElement.startTimeMs <= toMs;
276
- const mediaEndsAfterStart = mediaElement.endTimeMs >= fromMs;
277
- const mediaOverlaps = mediaStartsBeforeEnd && mediaEndsAfterStart;
278
- if (!mediaOverlaps || mediaElement.defaultAudioTrackId === void 0) {
279
- return;
280
- }
281
- const audio = await mediaElement.fetchAudioSpanningTime(fromMs, toMs);
282
- if (!audio) {
283
- throw new Error("Failed to fetch audio");
284
- }
285
- const bufferSource = audioContext.createBufferSource();
286
- bufferSource.buffer = await audioContext.decodeAudioData(
287
- await audio.blob.arrayBuffer()
288
- );
289
- bufferSource.connect(audioContext.destination);
290
- const ctxStartMs = Math.max(0, mediaElement.startTimeMs - fromMs);
291
- const ctxEndMs = mediaElement.endTimeMs - fromMs;
292
- const ctxDurationMs = ctxEndMs - ctxStartMs;
293
- const offset = Math.max(0, fromMs - mediaElement.startTimeMs) - audio.startMs;
294
- bufferSource.start(
295
- ctxStartMs / 1e3,
296
- offset / 1e3,
297
- ctxDurationMs / 1e3
298
- );
299
- })
300
- );
17
+ for (const child of Array.from(element.children)) if (child instanceof EFTimegroup) groups.push(child);
18
+ else shallowGetTimegroups(child, groups);
19
+ return groups;
301
20
  };
302
- EFTimegroup.styles = css`
21
+ let EFTimegroup = class EFTimegroup$1 extends EFTemporal(LitElement) {
22
+ static {
23
+ _EFTimegroup = this;
24
+ }
25
+ constructor(..._args) {
26
+ super(..._args);
27
+ this._timeGroupContext = this;
28
+ this.mode = "contain";
29
+ this.overlapMs = 0;
30
+ this.fit = "none";
31
+ this.frameTask = new Task(this, {
32
+ autoRun: EF_INTERACTIVE,
33
+ args: () => [this.ownCurrentTimeMs, this.currentTimeMs],
34
+ task: async ([], { signal: _signal }) => {
35
+ let fullyUpdated = await this.updateComplete;
36
+ while (!fullyUpdated) fullyUpdated = await this.updateComplete;
37
+ }
38
+ });
39
+ }
40
+ static {
41
+ this.styles = css`
303
42
  :host {
304
43
  display: block;
305
44
  width: 100%;
@@ -309,32 +48,232 @@ EFTimegroup.styles = css`
309
48
  left: 0;
310
49
  }
311
50
  `;
312
- __decorateClass([
313
- provide({ context: timegroupContext })
314
- ], EFTimegroup.prototype, "_timeGroupContext", 2);
315
- __decorateClass([
316
- property({
317
- type: String,
318
- attribute: "mode"
319
- })
320
- ], EFTimegroup.prototype, "mode", 2);
321
- __decorateClass([
322
- property({
323
- type: Number,
324
- converter: durationConverter,
325
- attribute: "overlap"
326
- })
327
- ], EFTimegroup.prototype, "overlapMs", 2);
328
- __decorateClass([
329
- property({ type: String })
330
- ], EFTimegroup.prototype, "fit", 2);
331
- __decorateClass([
332
- property({ type: Number, attribute: "currenttime" })
333
- ], EFTimegroup.prototype, "currentTime", 1);
334
- EFTimegroup = __decorateClass([
335
- customElement("ef-timegroup")
336
- ], EFTimegroup);
337
- export {
338
- EFTimegroup,
339
- shallowGetTimegroups
51
+ }
52
+ #currentTime = 0;
53
+ #resizeObserver;
54
+ set currentTime(time) {
55
+ this.#currentTime = Math.max(0, Math.min(time, this.durationMs / 1e3));
56
+ try {
57
+ if (this.id) {
58
+ if (this.isConnected) localStorage.setItem(this.storageKey, time.toString());
59
+ }
60
+ } catch (error) {
61
+ log("Failed to save time to localStorage", error);
62
+ }
63
+ }
64
+ get currentTime() {
65
+ return this.#currentTime;
66
+ }
67
+ get currentTimeMs() {
68
+ return this.currentTime * 1e3;
69
+ }
70
+ set currentTimeMs(ms) {
71
+ this.currentTime = ms / 1e3;
72
+ }
73
+ render() {
74
+ return html`<slot></slot> `;
75
+ }
76
+ maybeLoadTimeFromLocalStorage() {
77
+ if (this.id) try {
78
+ return Number.parseFloat(localStorage.getItem(this.storageKey) || "0");
79
+ } catch (error) {
80
+ log("Failed to load time from localStorage", error);
81
+ }
82
+ return 0;
83
+ }
84
+ connectedCallback() {
85
+ super.connectedCallback();
86
+ if (this.id) this.waitForMediaDurations().then(() => {
87
+ this.currentTime = this.maybeLoadTimeFromLocalStorage();
88
+ });
89
+ if (this.parentTimegroup) new TimegroupController(this.parentTimegroup, this);
90
+ if (this.shouldWrapWithWorkbench()) this.wrapWithWorkbench();
91
+ requestAnimationFrame(() => {
92
+ this.updateAnimations();
93
+ });
94
+ }
95
+ disconnectedCallback() {
96
+ super.disconnectedCallback();
97
+ this.#resizeObserver?.disconnect();
98
+ }
99
+ get storageKey() {
100
+ if (!this.id) throw new Error("Timegroup must have an id to use localStorage.");
101
+ return `ef-timegroup-${this.id}`;
102
+ }
103
+ get intrinsicDurationMs() {
104
+ if (this.hasExplicitDuration) return this.explicitDurationMs;
105
+ return void 0;
106
+ }
107
+ get hasOwnDuration() {
108
+ return this.mode === "contain" || this.mode === "sequence" || this.mode === "fixed" && this.hasExplicitDuration;
109
+ }
110
+ get durationMs() {
111
+ switch (this.mode) {
112
+ case "fit": {
113
+ if (!this.parentTimegroup) return 0;
114
+ return this.parentTimegroup.durationMs;
115
+ }
116
+ case "fixed": return super.durationMs;
117
+ case "sequence": {
118
+ let duration = 0;
119
+ this.childTemporals.forEach((child, index) => {
120
+ if (child instanceof _EFTimegroup && child.mode === "fit") return;
121
+ if (index > 0) duration -= this.overlapMs;
122
+ duration += child.durationMs;
123
+ });
124
+ return duration;
125
+ }
126
+ case "contain": {
127
+ let maxDuration = 0;
128
+ for (const child of this.childTemporals) {
129
+ if (child instanceof _EFTimegroup && child.mode === "fit") continue;
130
+ if (!child.hasOwnDuration) continue;
131
+ maxDuration = Math.max(maxDuration, child.durationMs);
132
+ }
133
+ return maxDuration;
134
+ }
135
+ default: throw new Error(`Invalid time mode: ${this.mode}`);
136
+ }
137
+ }
138
+ async getPendingFrameTasks() {
139
+ await this.updateComplete;
140
+ const temporals = deepGetElementsWithFrameTasks(this);
141
+ return temporals.map((temporal) => temporal.frameTask).filter((task) => task.status < TaskStatus.COMPLETE);
142
+ }
143
+ async waitForFrameTasks() {
144
+ const limit = 10;
145
+ let step = 0;
146
+ await this.updateComplete;
147
+ while (step < limit) {
148
+ step++;
149
+ let pendingTasks = await this.getPendingFrameTasks();
150
+ await Promise.all(pendingTasks.map((task) => task.taskComplete));
151
+ await this.updateComplete;
152
+ pendingTasks = await this.getPendingFrameTasks();
153
+ if (pendingTasks.length === 0) break;
154
+ }
155
+ }
156
+ /**
157
+ * Wait for all media elements to load their initial segments.
158
+ * Ideally we would only need the extracted index json data, but
159
+ * that caused issues with constructing audio data. We had negative durations
160
+ * in calculations and it was not clear why.
161
+ */
162
+ async waitForMediaDurations() {
163
+ await this.updateComplete;
164
+ const mediaElements = deepGetMediaElements(this);
165
+ await Promise.all(mediaElements.map((m) => m.fragmentIndexTask.taskComplete));
166
+ flushStartTimeMsCache();
167
+ this.requestUpdate("currentTime");
168
+ await this.updateComplete;
169
+ }
170
+ get childTemporals() {
171
+ return shallowGetTemporalElements(this);
172
+ }
173
+ updated(changedProperties) {
174
+ super.updated(changedProperties);
175
+ if (changedProperties.has("currentTime") || changedProperties.has("ownCurrentTimeMs")) this.updateAnimations();
176
+ }
177
+ updateAnimations() {
178
+ updateAnimations(this);
179
+ }
180
+ get contextProvider() {
181
+ let parent = this.parentNode;
182
+ while (parent) {
183
+ if (isContextMixin(parent)) return parent;
184
+ parent = parent.parentNode;
185
+ }
186
+ return null;
187
+ }
188
+ /**
189
+ * Returns true if the timegroup should be wrapped with a workbench.
190
+ *
191
+ * A timegroup should be wrapped with a workbench if it is the root-most timegroup
192
+ * and EF_INTERACTIVE is true.
193
+ *
194
+ * If the timegroup is already wrappedin a context provider like ef-preview,
195
+ * it should NOT be wrapped in a workbench.
196
+ */
197
+ shouldWrapWithWorkbench() {
198
+ return EF_INTERACTIVE && this.closest("ef-timegroup") === this && this.closest("ef-preview") === null && this.closest("ef-workbench") === null && this.closest("test-context") === null;
199
+ }
200
+ wrapWithWorkbench() {
201
+ const workbench = document.createElement("ef-workbench");
202
+ this.parentElement?.append(workbench);
203
+ if (!this.hasAttribute("id")) this.setAttribute("id", "root-this");
204
+ this.setAttribute("slot", "canvas");
205
+ workbench.append(this);
206
+ const filmstrip = document.createElement("ef-filmstrip");
207
+ filmstrip.setAttribute("slot", "timeline");
208
+ filmstrip.setAttribute("target", this.id);
209
+ workbench.append(filmstrip);
210
+ }
211
+ get efElements() {
212
+ return Array.from(this.querySelectorAll("ef-audio, ef-video, ef-image, ef-captions, ef-waveform"));
213
+ }
214
+ async #addAudioToContext(audioContext, fromMs, toMs) {
215
+ await this.waitForMediaDurations();
216
+ await Promise.all(deepGetMediaElements(this).map(async (mediaElement) => {
217
+ const mediaStartsBeforeEnd = mediaElement.startTimeMs <= toMs;
218
+ const mediaEndsAfterStart = mediaElement.endTimeMs >= fromMs;
219
+ const mediaOverlaps = mediaStartsBeforeEnd && mediaEndsAfterStart;
220
+ if (!mediaOverlaps || mediaElement.defaultAudioTrackId === void 0) return;
221
+ const audio = await mediaElement.fetchAudioSpanningTime(fromMs, toMs);
222
+ if (!audio) throw new Error("Failed to fetch audio");
223
+ const bufferSource = audioContext.createBufferSource();
224
+ bufferSource.buffer = await audioContext.decodeAudioData(await audio.blob.arrayBuffer());
225
+ bufferSource.connect(audioContext.destination);
226
+ const ctxStartMs = Math.max(0, mediaElement.startTimeMs - fromMs);
227
+ const ctxEndMs = mediaElement.endTimeMs - fromMs;
228
+ const ctxDurationMs = ctxEndMs - ctxStartMs;
229
+ const offset = Math.max(0, fromMs - mediaElement.startTimeMs) - audio.startMs;
230
+ bufferSource.start(ctxStartMs / 1e3, offset / 1e3, ctxDurationMs / 1e3);
231
+ }));
232
+ }
233
+ async renderAudio(fromMs, toMs) {
234
+ const durationMs = toMs - fromMs;
235
+ const contextSize = Math.round(48e3 * durationMs / 1e3);
236
+ if (contextSize <= 0) throw new Error(`Duration must be greater than 0 when rendering audio. ${contextSize}ms`);
237
+ let audioContext;
238
+ try {
239
+ audioContext = new OfflineAudioContext(2, contextSize, 48e3);
240
+ } catch (error) {
241
+ throw new Error(`[EFTimegroup.renderAudio] Failed to create OfflineAudioContext(2, ${contextSize}, 48000) for renderAudio(${fromMs}, ${toMs}) with contextSize=${contextSize}: ${error instanceof Error ? error.message : String(error)}. This typically happens when audio parameters are invalid (e.g., contextSize <= 0).`);
242
+ }
243
+ await this.#addAudioToContext(audioContext, fromMs, toMs);
244
+ const renderedBuffer = await audioContext.startRendering();
245
+ return renderedBuffer;
246
+ }
247
+ async loadMd5Sums() {
248
+ const efElements = this.efElements;
249
+ const loaderTasks = [];
250
+ for (const el of efElements) {
251
+ const md5SumLoader = el.md5SumLoader;
252
+ if (md5SumLoader instanceof Task) {
253
+ md5SumLoader.run();
254
+ loaderTasks.push(md5SumLoader.taskComplete);
255
+ }
256
+ }
257
+ await Promise.all(loaderTasks);
258
+ efElements.map((el) => {
259
+ if ("productionSrc" in el && el.productionSrc instanceof Function) el.setAttribute("src", el.productionSrc());
260
+ });
261
+ }
340
262
  };
263
+ _decorate([provide({ context: timegroupContext })], EFTimegroup.prototype, "_timeGroupContext", void 0);
264
+ _decorate([property({
265
+ type: String,
266
+ attribute: "mode"
267
+ })], EFTimegroup.prototype, "mode", void 0);
268
+ _decorate([property({
269
+ type: Number,
270
+ converter: durationConverter,
271
+ attribute: "overlap"
272
+ })], EFTimegroup.prototype, "overlapMs", void 0);
273
+ _decorate([property({ type: String })], EFTimegroup.prototype, "fit", void 0);
274
+ _decorate([property({
275
+ type: Number,
276
+ attribute: "currenttime"
277
+ })], EFTimegroup.prototype, "currentTime", null);
278
+ EFTimegroup = _EFTimegroup = _decorate([customElement("ef-timegroup")], EFTimegroup);
279
+ export { EFTimegroup, shallowGetTimegroups };
File without changes