@editframe/elements 0.26.3-beta.0 → 0.26.4-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 (132) hide show
  1. package/package.json +2 -2
  2. package/scripts/build-css.js +3 -3
  3. package/tsdown.config.ts +1 -1
  4. package/src/elements/ContextProxiesController.ts +0 -124
  5. package/src/elements/CrossUpdateController.ts +0 -22
  6. package/src/elements/EFAudio.browsertest.ts +0 -706
  7. package/src/elements/EFAudio.ts +0 -56
  8. package/src/elements/EFCaptions.browsertest.ts +0 -1960
  9. package/src/elements/EFCaptions.ts +0 -823
  10. package/src/elements/EFImage.browsertest.ts +0 -120
  11. package/src/elements/EFImage.ts +0 -113
  12. package/src/elements/EFMedia/AssetIdMediaEngine.test.ts +0 -224
  13. package/src/elements/EFMedia/AssetIdMediaEngine.ts +0 -110
  14. package/src/elements/EFMedia/AssetMediaEngine.browsertest.ts +0 -140
  15. package/src/elements/EFMedia/AssetMediaEngine.ts +0 -385
  16. package/src/elements/EFMedia/BaseMediaEngine.browsertest.ts +0 -400
  17. package/src/elements/EFMedia/BaseMediaEngine.ts +0 -505
  18. package/src/elements/EFMedia/BufferedSeekingInput.browsertest.ts +0 -386
  19. package/src/elements/EFMedia/BufferedSeekingInput.ts +0 -430
  20. package/src/elements/EFMedia/JitMediaEngine.browsertest.ts +0 -226
  21. package/src/elements/EFMedia/JitMediaEngine.ts +0 -256
  22. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.browsertest.ts +0 -679
  23. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.ts +0 -117
  24. package/src/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.ts +0 -246
  25. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.browsertest.ts +0 -59
  26. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.ts +0 -27
  27. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.browsertest.ts +0 -55
  28. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.ts +0 -53
  29. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.chunkboundary.regression.browsertest.ts +0 -207
  30. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.ts +0 -72
  31. package/src/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.ts +0 -32
  32. package/src/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.ts +0 -29
  33. package/src/elements/EFMedia/audioTasks/makeAudioTasksVideoOnly.browsertest.ts +0 -95
  34. package/src/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.ts +0 -184
  35. package/src/elements/EFMedia/shared/AudioSpanUtils.ts +0 -129
  36. package/src/elements/EFMedia/shared/BufferUtils.ts +0 -342
  37. package/src/elements/EFMedia/shared/GlobalInputCache.ts +0 -77
  38. package/src/elements/EFMedia/shared/MediaTaskUtils.ts +0 -44
  39. package/src/elements/EFMedia/shared/PrecisionUtils.ts +0 -46
  40. package/src/elements/EFMedia/shared/RenditionHelpers.browsertest.ts +0 -246
  41. package/src/elements/EFMedia/shared/RenditionHelpers.ts +0 -56
  42. package/src/elements/EFMedia/shared/ThumbnailExtractor.ts +0 -227
  43. package/src/elements/EFMedia/tasks/makeMediaEngineTask.browsertest.ts +0 -167
  44. package/src/elements/EFMedia/tasks/makeMediaEngineTask.ts +0 -88
  45. package/src/elements/EFMedia/videoTasks/MainVideoInputCache.ts +0 -76
  46. package/src/elements/EFMedia/videoTasks/ScrubInputCache.ts +0 -61
  47. package/src/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.ts +0 -114
  48. package/src/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.ts +0 -35
  49. package/src/elements/EFMedia/videoTasks/makeScrubVideoInputTask.ts +0 -52
  50. package/src/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.ts +0 -124
  51. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.ts +0 -44
  52. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.ts +0 -32
  53. package/src/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.ts +0 -370
  54. package/src/elements/EFMedia/videoTasks/makeVideoBufferTask.ts +0 -109
  55. package/src/elements/EFMedia.browsertest.ts +0 -872
  56. package/src/elements/EFMedia.ts +0 -341
  57. package/src/elements/EFSourceMixin.ts +0 -60
  58. package/src/elements/EFSurface.browsertest.ts +0 -151
  59. package/src/elements/EFSurface.ts +0 -142
  60. package/src/elements/EFTemporal.browsertest.ts +0 -215
  61. package/src/elements/EFTemporal.ts +0 -800
  62. package/src/elements/EFThumbnailStrip.browsertest.ts +0 -585
  63. package/src/elements/EFThumbnailStrip.media-engine.browsertest.ts +0 -714
  64. package/src/elements/EFThumbnailStrip.ts +0 -906
  65. package/src/elements/EFTimegroup.browsertest.ts +0 -934
  66. package/src/elements/EFTimegroup.ts +0 -882
  67. package/src/elements/EFVideo.browsertest.ts +0 -1482
  68. package/src/elements/EFVideo.ts +0 -564
  69. package/src/elements/EFWaveform.ts +0 -547
  70. package/src/elements/FetchContext.browsertest.ts +0 -401
  71. package/src/elements/FetchMixin.ts +0 -38
  72. package/src/elements/SampleBuffer.ts +0 -94
  73. package/src/elements/TargetController.browsertest.ts +0 -230
  74. package/src/elements/TargetController.ts +0 -224
  75. package/src/elements/TimegroupController.ts +0 -26
  76. package/src/elements/durationConverter.ts +0 -35
  77. package/src/elements/parseTimeToMs.ts +0 -9
  78. package/src/elements/printTaskStatus.ts +0 -16
  79. package/src/elements/renderTemporalAudio.ts +0 -108
  80. package/src/elements/updateAnimations.browsertest.ts +0 -1884
  81. package/src/elements/updateAnimations.ts +0 -217
  82. package/src/elements/util.ts +0 -24
  83. package/src/gui/ContextMixin.browsertest.ts +0 -860
  84. package/src/gui/ContextMixin.ts +0 -562
  85. package/src/gui/Controllable.browsertest.ts +0 -258
  86. package/src/gui/Controllable.ts +0 -41
  87. package/src/gui/EFConfiguration.ts +0 -40
  88. package/src/gui/EFControls.browsertest.ts +0 -389
  89. package/src/gui/EFControls.ts +0 -195
  90. package/src/gui/EFDial.browsertest.ts +0 -84
  91. package/src/gui/EFDial.ts +0 -172
  92. package/src/gui/EFFilmstrip.browsertest.ts +0 -712
  93. package/src/gui/EFFilmstrip.ts +0 -1349
  94. package/src/gui/EFFitScale.ts +0 -152
  95. package/src/gui/EFFocusOverlay.ts +0 -79
  96. package/src/gui/EFPause.browsertest.ts +0 -202
  97. package/src/gui/EFPause.ts +0 -73
  98. package/src/gui/EFPlay.browsertest.ts +0 -202
  99. package/src/gui/EFPlay.ts +0 -73
  100. package/src/gui/EFPreview.ts +0 -74
  101. package/src/gui/EFResizableBox.browsertest.ts +0 -79
  102. package/src/gui/EFResizableBox.ts +0 -898
  103. package/src/gui/EFScrubber.ts +0 -151
  104. package/src/gui/EFTimeDisplay.browsertest.ts +0 -237
  105. package/src/gui/EFTimeDisplay.ts +0 -55
  106. package/src/gui/EFToggleLoop.ts +0 -35
  107. package/src/gui/EFTogglePlay.ts +0 -70
  108. package/src/gui/EFWorkbench.ts +0 -115
  109. package/src/gui/PlaybackController.ts +0 -527
  110. package/src/gui/TWMixin.css +0 -6
  111. package/src/gui/TWMixin.ts +0 -61
  112. package/src/gui/TargetOrContextMixin.ts +0 -185
  113. package/src/gui/currentTimeContext.ts +0 -5
  114. package/src/gui/durationContext.ts +0 -3
  115. package/src/gui/efContext.ts +0 -6
  116. package/src/gui/fetchContext.ts +0 -5
  117. package/src/gui/focusContext.ts +0 -7
  118. package/src/gui/focusedElementContext.ts +0 -5
  119. package/src/gui/playingContext.ts +0 -5
  120. package/src/otel/BridgeSpanExporter.ts +0 -150
  121. package/src/otel/setupBrowserTracing.ts +0 -73
  122. package/src/otel/tracingHelpers.ts +0 -251
  123. package/src/transcoding/cache/RequestDeduplicator.test.ts +0 -170
  124. package/src/transcoding/cache/RequestDeduplicator.ts +0 -65
  125. package/src/transcoding/cache/URLTokenDeduplicator.test.ts +0 -182
  126. package/src/transcoding/cache/URLTokenDeduplicator.ts +0 -101
  127. package/src/transcoding/types/index.ts +0 -312
  128. package/src/transcoding/utils/MediaUtils.ts +0 -63
  129. package/src/transcoding/utils/UrlGenerator.ts +0 -68
  130. package/src/transcoding/utils/constants.ts +0 -36
  131. package/src/utils/LRUCache.test.ts +0 -274
  132. package/src/utils/LRUCache.ts +0 -696
@@ -1,800 +0,0 @@
1
- import { consume, createContext } from "@lit/context";
2
- import { Task } from "@lit/task";
3
- import type { LitElement, ReactiveController } from "lit";
4
- import { property, state } from "lit/decorators.js";
5
- import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
6
- import { PlaybackController } from "../gui/PlaybackController.js";
7
- import { durationConverter } from "./durationConverter.js";
8
- import type { EFTimegroup } from "./EFTimegroup.js";
9
-
10
- export const timegroupContext = createContext<EFTimegroup>(
11
- Symbol("timeGroupContext"),
12
- );
13
-
14
- export declare class TemporalMixinInterface {
15
- playbackController?: PlaybackController;
16
- playing: boolean;
17
- loop: boolean;
18
- play(): void;
19
- pause(): void;
20
-
21
- get hasOwnDuration(): boolean;
22
- /**
23
- * Whether the element has a duration set as an attribute.
24
- */
25
- get hasExplicitDuration(): boolean;
26
-
27
- get sourceStartMs(): number;
28
-
29
- /**
30
- * Used to trim the start of the media.
31
- *
32
- * This can be set in either seconds or milliseconds.
33
- *
34
- * For example, `trimstart="10s"` is equivalent to `trimstart="10000ms"`.
35
- *
36
- * @domAttribute "trimstart"
37
- */
38
- get trimStartMs(): number | undefined;
39
-
40
- /**
41
- * Used to trim the end of the media.
42
- *
43
- * This can be set in either seconds or milliseconds.
44
- *
45
- * For example, `trimend="10s"` is equivalent to `trimend="10000ms"`.
46
- *
47
- * @domAttribute "trimend"
48
- */
49
- get trimEndMs(): number;
50
-
51
- set trimStartMs(value: number | undefined);
52
- set trimEndMs(value: number | undefined);
53
- set trimstart(value: string | undefined);
54
- set trimend(value: string | undefined);
55
-
56
- /**
57
- * The source in time of the element.
58
- *
59
- * This is an amount of time to trim off the beginning of the media.
60
- *
61
- * This can be set in either seconds or milliseconds.
62
- *
63
- * For example, `sourcein="10s"` is equivalent to `sourcein="10000ms"`.
64
- *
65
- * If the sourcein time is greater than the duration of the media, the media
66
- * will not be played.
67
- *
68
- * If the media is 20 seconds long, and the `sourcein` value is set to `10s`, the
69
- * media will play for 10 seconds, starting at the 10 second mark.
70
- *
71
- * Can be used in conjunction with `sourceout` to create a trimmed media.
72
- *
73
- * @domAttribute "sourcein"
74
- */
75
- get sourceInMs(): number | undefined;
76
-
77
- /**
78
- * The source out time of the element.
79
- *
80
- * This is the point in time in the media that will be treated as the end of
81
- * the media.
82
- *
83
- * This can be set in either seconds or milliseconds.
84
- *
85
- * For example, `sourceout="10s"` is equivalent to `sourceout="10000ms"`.
86
- *
87
- * If the sourceout time is greater than the duration of the media, the media
88
- * will play until the end of the media.
89
- *
90
- * If the media is 20 seconds long, and the `sourceout` value is set to `10s`,
91
- * the media will play for 10 seconds, starting at zero seconds and ending at
92
- * the 10 second mark.
93
- *
94
- * Can be used in conjunction with `sourcein` to create a trimmed media.
95
- *
96
- * @domAttribute "sourceout"
97
- */
98
- get sourceOutMs(): number | undefined;
99
-
100
- set sourceInMs(value: number | undefined);
101
- set sourceOutMs(value: number | undefined);
102
- set sourcein(value: string | undefined);
103
- set sourceout(value: string | undefined);
104
-
105
- /**
106
- * @domAttribute "duration"
107
- */
108
- get durationMs(): number;
109
-
110
- get explicitDurationMs(): number | undefined;
111
-
112
- get intrinsicDurationMs(): number | undefined;
113
-
114
- /**
115
- * The start time of the element within its root timegroup in milliseconds.
116
- *
117
- * This is an absolute time according to the highest scoped timegroup the media element is contained within.
118
- *
119
- * The calculated value will depend on the mode of the timegroup and the offset of the media element.
120
- *
121
- * If the parent time group is in `sequence` mode, the start time will be the
122
- * start time of the previous sibling element plus the previous sibling's duration
123
- * minus the overlap of the previous sibling and the current sibling.
124
- *
125
- * If the parent time group is in `contain` or `fixed` mode, the start time will be
126
- * the start time of the parent time group plus the offset of the media element.
127
- */
128
- get startTimeMs(): number;
129
- /**
130
- * The end time of the element within its root timegroup in milliseconds.
131
- *
132
- * This is an absolute time according to the highest scoped timegroup the media
133
- * element is contained within. Computed by adding the media's duration to its
134
- * start time.
135
- *
136
- * If the media element has been trimmed, its end time will be calculated according it
137
- * its trimmed duration, not its original duration.
138
- */
139
- get endTimeMs(): number;
140
- /**
141
- * The start time of the element within its parent timegroup in milliseconds.
142
- *
143
- * This is a relative time according to the closest timegroup the media element
144
- * is contained within. Unless the media element has been given any kind of specific offset
145
- * it is common for this time to be zero.
146
- */
147
- get startTimeWithinParentMs(): number;
148
-
149
- /**
150
- * The current time of the element in milliseconds.
151
- *
152
- * This is a relative time according to the closest timegroup the media element
153
- * is contained within.
154
- *
155
- * This is suitable for determining the percentage of the media that has been
156
- * played.
157
- */
158
- get ownCurrentTimeMs(): number;
159
-
160
- /**
161
- * Element's current time for progress calculation.
162
- * For timegroups: their timeline currentTimeMs
163
- * For other temporal elements: their ownCurrentTimeMs
164
- */
165
- get currentTimeMs(): number;
166
- set currentTimeMs(value: number);
167
- /**
168
- * The current time of the element in milliseconds, adjusted for trimming.
169
- *
170
- * This is suitable for mapping to internal media time codes for audio/video
171
- * elements.
172
- *
173
- * For example, if the media has a `sourcein` value of 10s, when `ownCurrentTimeMs` is 0s,
174
- * `currentSourceTimeMs` will be 10s.
175
- *
176
- * sourcein=10s sourceout=10s
177
- * / / /
178
- * |--------|=================|---------|
179
- * ^
180
- * |_
181
- * currentSourceTimeMs === 10s
182
- * |_
183
- * ownCurrentTimeMs === 0s
184
- */
185
- get currentSourceTimeMs(): number;
186
-
187
- set duration(value: string);
188
- get duration(): string;
189
-
190
- /**
191
- * The offset of the element within its parent timegroup in milliseconds.
192
- *
193
- * This can be set in either seconds or milliseconds.
194
- *
195
- * For example, `offset="10s"` is equivalent to `offset="10000ms"`.
196
- *
197
- * This can be used to create a negative or positive offset for the start time of the media.
198
- *
199
- * This will change the start time of the media relative to it's otherwise normal start time.
200
- *
201
- * The duration of the element, or it's parent, or the start and end time of it's temporal siblings will not
202
- * be affected by this offset.
203
- *
204
- * @domAttribute "offset"
205
- */
206
- set offset(value: string);
207
- get offset(): string;
208
-
209
- /**
210
- * A convenience property for getting the nearest containing timegroup of the media element.
211
- */
212
- parentTimegroup?: EFTimegroup;
213
-
214
- /**
215
- * A convenience property for getting the root timegroup of the media element.
216
- */
217
- rootTimegroup?: EFTimegroup;
218
-
219
- frameTask: Task<readonly unknown[], unknown>;
220
-
221
- didBecomeRoot(): void;
222
- didBecomeChild(): void;
223
-
224
- updateComplete: Promise<boolean>;
225
- }
226
-
227
- export const isEFTemporal = (obj: any): obj is TemporalMixinInterface =>
228
- obj[EF_TEMPORAL];
229
-
230
- const EF_TEMPORAL = Symbol("EF_TEMPORAL");
231
-
232
- export const deepGetTemporalElements = (
233
- element: Element,
234
- temporals: Array<TemporalMixinInterface & HTMLElement> = [],
235
- ) => {
236
- for (const child of element.children) {
237
- if (isEFTemporal(child)) {
238
- temporals.push(child as TemporalMixinInterface & HTMLElement);
239
- }
240
- deepGetTemporalElements(child, temporals);
241
- }
242
- return temporals;
243
- };
244
-
245
- export const deepGetElementsWithFrameTasks = (
246
- element: Element,
247
- elements: Array<TemporalMixinInterface & HTMLElement> = [],
248
- ) => {
249
- for (const child of element.children) {
250
- if ("frameTask" in child && child.frameTask instanceof Task) {
251
- elements.push(child as TemporalMixinInterface & HTMLElement);
252
- }
253
- deepGetElementsWithFrameTasks(child, elements);
254
- }
255
- return elements;
256
- };
257
-
258
- let temporalCache: Map<Element, TemporalMixinInterface[]>;
259
- let temporalCacheResetScheduled = false;
260
- export const resetTemporalCache = () => {
261
- temporalCache = new Map();
262
- if (
263
- typeof requestAnimationFrame !== "undefined" &&
264
- !temporalCacheResetScheduled
265
- ) {
266
- temporalCacheResetScheduled = true;
267
- requestAnimationFrame(() => {
268
- temporalCacheResetScheduled = false;
269
- resetTemporalCache();
270
- });
271
- }
272
- };
273
- resetTemporalCache();
274
-
275
- export const shallowGetTemporalElements = (
276
- element: Element,
277
- temporals: TemporalMixinInterface[] = [],
278
- ) => {
279
- const cachedResult = temporalCache.get(element);
280
- if (cachedResult) {
281
- return cachedResult;
282
- }
283
- for (const child of element.children) {
284
- if (isEFTemporal(child)) {
285
- temporals.push(child);
286
- } else {
287
- shallowGetTemporalElements(child, temporals);
288
- }
289
- }
290
- temporalCache.set(element, temporals);
291
- return temporals;
292
- };
293
-
294
- export class OwnCurrentTimeController implements ReactiveController {
295
- constructor(
296
- private host: EFTimegroup,
297
- private temporal: TemporalMixinInterface & LitElement,
298
- ) {
299
- host.addController(this);
300
- }
301
-
302
- hostUpdated() {
303
- this.temporal.requestUpdate("ownCurrentTimeMs");
304
- }
305
-
306
- remove() {
307
- this.host.removeController(this);
308
- }
309
- }
310
-
311
- type Constructor<T = {}> = new (...args: any[]) => T;
312
-
313
- let startTimeMsCache = new WeakMap<Element, number>();
314
- let startTimeMsCacheResetScheduled = false;
315
- const resetStartTimeMsCache = () => {
316
- startTimeMsCache = new WeakMap();
317
- if (
318
- typeof requestAnimationFrame !== "undefined" &&
319
- !startTimeMsCacheResetScheduled
320
- ) {
321
- startTimeMsCacheResetScheduled = true;
322
- requestAnimationFrame(() => {
323
- startTimeMsCacheResetScheduled = false;
324
- resetStartTimeMsCache();
325
- });
326
- }
327
- };
328
- resetStartTimeMsCache();
329
-
330
- export const flushStartTimeMsCache = () => {
331
- startTimeMsCache = new WeakMap();
332
- };
333
-
334
- export const EFTemporal = <T extends Constructor<LitElement>>(
335
- superClass: T,
336
- ) => {
337
- class TemporalMixinClass extends superClass {
338
- ownCurrentTimeController?: OwnCurrentTimeController;
339
-
340
- #parentTimegroup?: EFTimegroup;
341
- @consume({ context: timegroupContext, subscribe: true })
342
- set parentTimegroup(value: EFTimegroup | undefined) {
343
- const oldParent = this.#parentTimegroup;
344
- this.#parentTimegroup = value;
345
-
346
- this.ownCurrentTimeController?.remove();
347
- this.rootTimegroup = this.getRootTimegroup();
348
- if (this.rootTimegroup) {
349
- this.ownCurrentTimeController = new OwnCurrentTimeController(
350
- this.rootTimegroup,
351
- this as InstanceType<Constructor<TemporalMixinInterface> & T>,
352
- );
353
- }
354
-
355
- // Only trigger callbacks if parent status actually changed
356
- if (oldParent !== value) {
357
- if (!value) {
358
- this.didBecomeRoot();
359
- } else {
360
- this.didBecomeChild();
361
- }
362
- }
363
- }
364
-
365
- disconnectedCallback() {
366
- super.disconnectedCallback();
367
- this.ownCurrentTimeController?.remove();
368
-
369
- if (this.playbackController) {
370
- this.playbackController.remove();
371
- this.playbackController = undefined;
372
- }
373
- }
374
-
375
- connectedCallback() {
376
- super.connectedCallback();
377
- // Initialize playback controller for root elements
378
- // The parentTimegroup setter may have already called this, but the guard prevents double-creation
379
- if (!this.parentTimegroup) {
380
- this.didBecomeRoot();
381
- }
382
- }
383
-
384
- get parentTimegroup() {
385
- return this.#parentTimegroup;
386
- }
387
-
388
- playbackController?: PlaybackController;
389
-
390
- get playing(): boolean {
391
- if (!this.playbackController) {
392
- return false;
393
- }
394
- return this.playbackController.playing;
395
- }
396
-
397
- set playing(value: boolean) {
398
- if (!this.playbackController) {
399
- console.warn("Cannot set playing on non-root temporal element", this);
400
- return;
401
- }
402
- this.playbackController.setPlaying(value);
403
- }
404
-
405
- play(): void {
406
- if (!this.playbackController) {
407
- console.warn("play() called on non-root temporal element", this);
408
- return;
409
- }
410
- this.playbackController.play();
411
- }
412
-
413
- pause(): void {
414
- if (!this.playbackController) {
415
- console.warn("pause() called on non-root temporal element", this);
416
- return;
417
- }
418
- this.playbackController.pause();
419
- }
420
-
421
- @property({ type: Boolean, reflect: true, attribute: "loop" })
422
- get loop(): boolean {
423
- return this.playbackController?.loop ?? this.#loop;
424
- }
425
-
426
- set loop(value: boolean) {
427
- const oldValue = this.#loop;
428
- this.#loop = value;
429
- if (this.playbackController) {
430
- this.playbackController.setLoop(value);
431
- }
432
- this.requestUpdate("loop", oldValue);
433
- }
434
-
435
- @property({
436
- type: String,
437
- attribute: "offset",
438
- converter: durationConverter,
439
- })
440
- private _offsetMs = 0;
441
-
442
- @property({
443
- type: Number,
444
- attribute: "duration",
445
- converter: durationConverter,
446
- })
447
- private _durationMs?: number;
448
-
449
- set duration(value: string | undefined) {
450
- if (value !== undefined) {
451
- this.setAttribute("duration", value);
452
- } else {
453
- this.removeAttribute("duration");
454
- }
455
- }
456
-
457
- @property({
458
- type: Number,
459
- attribute: "trimstart",
460
- converter: durationConverter,
461
- })
462
- _trimStartMs: number | undefined = undefined;
463
-
464
- get trimStartMs() {
465
- if (this._trimStartMs === undefined) {
466
- return undefined;
467
- }
468
- return Math.min(
469
- Math.max(this._trimStartMs, 0),
470
- this.intrinsicDurationMs ?? 0,
471
- );
472
- }
473
-
474
- set trimStartMs(value: number | undefined) {
475
- this._trimStartMs = value;
476
- }
477
-
478
- @property({
479
- type: Number,
480
- attribute: "trimend",
481
- converter: durationConverter,
482
- })
483
- _trimEndMs: number | undefined = undefined;
484
-
485
- get trimEndMs() {
486
- if (this._trimEndMs === undefined) {
487
- return undefined;
488
- }
489
- return Math.min(this._trimEndMs, this.intrinsicDurationMs ?? 0);
490
- }
491
-
492
- set trimEndMs(value: number | undefined) {
493
- this._trimEndMs = value;
494
- }
495
-
496
- @property({
497
- type: Number,
498
- attribute: "sourcein",
499
- converter: durationConverter,
500
- })
501
- _sourceInMs: number | undefined = undefined;
502
-
503
- get sourceInMs() {
504
- if (this._sourceInMs === undefined) {
505
- return undefined;
506
- }
507
- return Math.max(this._sourceInMs, 0);
508
- }
509
-
510
- set sourceInMs(value: number | undefined) {
511
- this._sourceInMs = value;
512
- }
513
-
514
- @property({
515
- type: Number,
516
- attribute: "sourceout",
517
- converter: durationConverter,
518
- })
519
- _sourceOutMs: number | undefined = undefined;
520
-
521
- get sourceOutMs() {
522
- if (this._sourceOutMs === undefined) {
523
- return undefined;
524
- }
525
- if (
526
- this.intrinsicDurationMs &&
527
- this._sourceOutMs > this.intrinsicDurationMs
528
- ) {
529
- return this.intrinsicDurationMs;
530
- }
531
- return Math.max(this._sourceOutMs, 0);
532
- }
533
-
534
- set sourceOutMs(value: number | undefined) {
535
- this._sourceOutMs = value;
536
- }
537
-
538
- @property({
539
- type: Number,
540
- attribute: "startoffset",
541
- converter: durationConverter,
542
- })
543
- private _startOffsetMs = 0;
544
- public get startOffsetMs(): number {
545
- return this._startOffsetMs;
546
- }
547
-
548
- @state()
549
- rootTimegroup?: EFTimegroup = this.getRootTimegroup();
550
-
551
- private getRootTimegroup(): EFTimegroup | undefined {
552
- let parent =
553
- this.tagName === "EF-TIMEGROUP" ? this : this.parentTimegroup;
554
- while (parent?.parentTimegroup) {
555
- parent = parent.parentTimegroup;
556
- }
557
- return parent as EFTimegroup | undefined;
558
- }
559
-
560
- get hasExplicitDuration() {
561
- return this._durationMs !== undefined;
562
- }
563
-
564
- get explicitDurationMs() {
565
- if (this.hasExplicitDuration) {
566
- return this._durationMs;
567
- }
568
- return undefined;
569
- }
570
-
571
- get hasOwnDuration() {
572
- return this.intrinsicDurationMs !== undefined || this.hasExplicitDuration;
573
- }
574
-
575
- get intrinsicDurationMs() {
576
- return undefined;
577
- }
578
-
579
- get durationMs() {
580
- // Get the base duration - either intrinsic or explicit
581
- const baseDurationMs =
582
- this.intrinsicDurationMs ??
583
- this._durationMs ??
584
- this.parentTimegroup?.durationMs ??
585
- 0;
586
-
587
- if (baseDurationMs === 0) {
588
- return 0;
589
- }
590
-
591
- // Apply trimming logic to any duration source
592
- if (this.trimStartMs || this.trimEndMs) {
593
- const trimmedDurationMs =
594
- baseDurationMs - (this.trimStartMs ?? 0) - (this.trimEndMs ?? 0);
595
- if (trimmedDurationMs < 0) {
596
- return 0;
597
- }
598
- return trimmedDurationMs;
599
- }
600
-
601
- if (this.sourceInMs || this.sourceOutMs) {
602
- const sourceInMs = this.sourceInMs ?? 0;
603
- const sourceOutMs = this.sourceOutMs ?? baseDurationMs;
604
- if (sourceInMs >= sourceOutMs) {
605
- return 0;
606
- }
607
- return sourceOutMs - sourceInMs;
608
- }
609
-
610
- return baseDurationMs;
611
- }
612
-
613
- get sourceStartMs() {
614
- return this.trimStartMs ?? this.sourceInMs ?? 0;
615
- }
616
-
617
- get offsetMs() {
618
- return this._offsetMs || 0;
619
- }
620
-
621
- get parentTemporal() {
622
- let parent = this.parentElement;
623
- while (parent && !isEFTemporal(parent)) {
624
- parent = parent.parentElement;
625
- }
626
- return parent;
627
- }
628
-
629
- /**
630
- * The start time of the element within its parent timegroup.
631
- */
632
- get startTimeWithinParentMs() {
633
- if (!this.parentTemporal) {
634
- return 0;
635
- }
636
- return this.startTimeMs - this.parentTemporal.startTimeMs;
637
- }
638
-
639
- #loop = false;
640
-
641
- get startTimeMs(): number {
642
- const cachedStartTime = startTimeMsCache.get(this);
643
- if (cachedStartTime !== undefined) {
644
- return cachedStartTime;
645
- }
646
- const parentTimegroup = this.parentTimegroup;
647
- if (!parentTimegroup) {
648
- startTimeMsCache.set(this, 0);
649
- return 0;
650
- }
651
- switch (parentTimegroup.mode) {
652
- case "sequence": {
653
- const siblingTemorals = shallowGetTemporalElements(parentTimegroup);
654
- const ownIndex = siblingTemorals?.indexOf(
655
- this as InstanceType<Constructor<TemporalMixinInterface> & T>,
656
- );
657
- if (ownIndex === -1) {
658
- return 0;
659
- }
660
- if (ownIndex === 0) {
661
- startTimeMsCache.set(this, parentTimegroup.startTimeMs);
662
- return parentTimegroup.startTimeMs;
663
- }
664
- const previous = siblingTemorals?.[(ownIndex ?? 0) - 1];
665
- if (!previous) {
666
- console.error("Previous temporal element not found", {
667
- ownIndex,
668
- siblingTemorals,
669
- });
670
- throw new Error("Previous temporal element not found");
671
- }
672
- startTimeMsCache.set(
673
- this,
674
- previous.startTimeMs +
675
- previous.durationMs -
676
- parentTimegroup.overlapMs,
677
- );
678
- return (
679
- previous.startTimeMs +
680
- previous.durationMs -
681
- parentTimegroup.overlapMs
682
- );
683
- }
684
- case "fit":
685
- case "contain":
686
- case "fixed":
687
- startTimeMsCache.set(
688
- this,
689
- parentTimegroup.startTimeMs + this.offsetMs,
690
- );
691
- return parentTimegroup.startTimeMs + this.offsetMs;
692
- default:
693
- throw new Error(`Invalid time mode: ${parentTimegroup.mode}`);
694
- }
695
- }
696
-
697
- get endTimeMs(): number {
698
- return this.startTimeMs + this.durationMs;
699
- }
700
-
701
- #currentTimeMs = 0;
702
-
703
- /**
704
- * The current time of the element within itself.
705
- * Compare with `currentTimeMs` to see the current time with respect to the root timegroup
706
- */
707
- get ownCurrentTimeMs(): number {
708
- // If we have a playback controller, read from it
709
- if (this.playbackController) {
710
- return Math.min(
711
- Math.max(0, this.playbackController.currentTimeMs),
712
- this.durationMs,
713
- );
714
- }
715
-
716
- if (
717
- this.rootTimegroup &&
718
- this.rootTimegroup !== (this as any as EFTimegroup)
719
- ) {
720
- return Math.min(
721
- Math.max(0, this.rootTimegroup.currentTimeMs - this.startTimeMs),
722
- this.durationMs,
723
- );
724
- }
725
- // We are the root (or no root), use stored time
726
- return Math.min(Math.max(0, this.#currentTimeMs), this.durationMs);
727
- }
728
-
729
- /**
730
- * Element's current time for progress calculation.
731
- * Non-timegroup temporal elements use their local time (ownCurrentTimeMs)
732
- */
733
- get currentTimeMs() {
734
- return this.ownCurrentTimeMs;
735
- }
736
-
737
- set currentTimeMs(value: number) {
738
- // If we have a playback controller, delegate to it
739
- if (this.playbackController) {
740
- this.playbackController.currentTime = value / 1000;
741
- return;
742
- }
743
-
744
- // If we have a root timegroup, delegate to it
745
- if (
746
- this.rootTimegroup &&
747
- this.rootTimegroup !== (this as any as EFTimegroup)
748
- ) {
749
- this.rootTimegroup.currentTimeMs = value;
750
- } else {
751
- // We are the root, store the time locally
752
- this.#currentTimeMs = value;
753
- this.requestUpdate("currentTimeMs");
754
- }
755
- }
756
-
757
- /**
758
- * Used to calculate the internal currentTimeMs of the element. This is useful
759
- * for mapping to internal media time codes for audio/video elements.
760
- */
761
- get currentSourceTimeMs() {
762
- const leadingTrimMs = this.sourceInMs || this.trimStartMs || 0;
763
- return this.ownCurrentTimeMs + leadingTrimMs;
764
- }
765
-
766
- frameTask = new Task(this, {
767
- autoRun: EF_INTERACTIVE,
768
- args: () => [this.ownCurrentTimeMs] as const,
769
- task: async ([], { signal: _signal }) => {
770
- let fullyUpdated = await this.updateComplete;
771
- while (!fullyUpdated) {
772
- fullyUpdated = await this.updateComplete;
773
- }
774
- },
775
- });
776
-
777
- didBecomeRoot() {
778
- if (!this.playbackController) {
779
- this.playbackController = new PlaybackController(this as any);
780
- if (this.#loop) {
781
- this.playbackController.setLoop(this.#loop);
782
- }
783
- }
784
- }
785
-
786
- didBecomeChild() {
787
- if (this.playbackController) {
788
- this.playbackController.remove();
789
- this.playbackController = undefined;
790
- }
791
- }
792
- }
793
-
794
- Object.defineProperty(TemporalMixinClass.prototype, EF_TEMPORAL, {
795
- value: true,
796
- });
797
-
798
- return TemporalMixinClass as unknown as Constructor<TemporalMixinInterface> &
799
- T;
800
- };