@editframe/elements 0.12.0-beta.3 → 0.12.0-beta.6

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.
@@ -47,7 +47,6 @@ export declare class EFMedia extends EFMedia_base {
47
47
  protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
48
48
  get hasOwnDuration(): boolean;
49
49
  get durationMs(): number;
50
- get startTimeMs(): number;
51
50
  audioBufferTask: Task<readonly [Record<string, File> | undefined, Record<string, {
52
51
  segment: TrackSegment;
53
52
  track: MP4Box.TrackInfo;
@@ -10,9 +10,8 @@ import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
10
10
  import { EF_RENDERING } from "../EF_RENDERING.js";
11
11
  import { apiHostContext } from "../gui/apiHostContext.js";
12
12
  import { EFSourceMixin } from "./EFSourceMixin.js";
13
- import { EFTemporal } from "./EFTemporal.js";
13
+ import { EFTemporal, isEFTemporal } from "./EFTemporal.js";
14
14
  import { FetchMixin } from "./FetchMixin.js";
15
- import { getStartTimeMs } from "./util.js";
16
15
  var __defProp = Object.defineProperty;
17
16
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
18
17
  var __decorateClass = (decorators, target, key, kind) => {
@@ -270,6 +269,67 @@ class EFMedia extends EFSourceMixin(EFTemporal(FetchMixin(LitElement)), {
270
269
  if (changedProperties.has("ownCurrentTimeMs")) {
271
270
  this.executeSeek(this.trimAdjustedOwnCurrentTimeMs);
272
271
  }
272
+ if (changedProperties.has("currentTime") || changedProperties.has("ownCurrentTimeMs")) {
273
+ const timelineTimeMs = (this.rootTimegroup ?? this).currentTimeMs;
274
+ if (this.startTimeMs > timelineTimeMs || this.endTimeMs < timelineTimeMs) {
275
+ this.style.display = "none";
276
+ return;
277
+ }
278
+ this.style.display = "";
279
+ const animations = this.getAnimations({ subtree: true });
280
+ this.style.setProperty("--ef-duration", `${this.durationMs}ms`);
281
+ this.style.setProperty(
282
+ "--ef-transition--duration",
283
+ `${this.parentTimegroup?.overlapMs ?? 0}ms`
284
+ );
285
+ this.style.setProperty(
286
+ "--ef-transition-out-start",
287
+ `${this.durationMs - (this.parentTimegroup?.overlapMs ?? 0)}ms`
288
+ );
289
+ for (const animation of animations) {
290
+ if (animation.playState === "running") {
291
+ animation.pause();
292
+ }
293
+ const effect = animation.effect;
294
+ if (!(effect && effect instanceof KeyframeEffect)) {
295
+ return;
296
+ }
297
+ const target = effect.target;
298
+ if (!target) {
299
+ return;
300
+ }
301
+ if (target.closest("ef-video, ef-audio") !== this) {
302
+ return;
303
+ }
304
+ if (isEFTemporal(target)) {
305
+ const timing = effect.getTiming();
306
+ const duration = Number(timing.duration) ?? 0;
307
+ const delay = Number(timing.delay);
308
+ const newTime = Math.floor(
309
+ Math.min(target.ownCurrentTimeMs, duration - 1 + delay)
310
+ );
311
+ if (Number.isNaN(newTime)) {
312
+ return;
313
+ }
314
+ animation.currentTime = newTime;
315
+ } else if (target) {
316
+ const nearestTimegroup = target.closest("ef-timegroup");
317
+ if (!nearestTimegroup) {
318
+ return;
319
+ }
320
+ const timing = effect.getTiming();
321
+ const duration = Number(timing.duration) ?? 0;
322
+ const delay = Number(timing.delay);
323
+ const newTime = Math.floor(
324
+ Math.min(nearestTimegroup.ownCurrentTimeMs, duration - 1 + delay)
325
+ );
326
+ if (Number.isNaN(newTime)) {
327
+ return;
328
+ }
329
+ animation.currentTime = newTime;
330
+ }
331
+ }
332
+ }
273
333
  }
274
334
  get hasOwnDuration() {
275
335
  return true;
@@ -300,9 +360,6 @@ class EFMedia extends EFSourceMixin(EFTemporal(FetchMixin(LitElement)), {
300
360
  }
301
361
  return Math.max(...durations) - this.trimStartMs - this.trimEndMs;
302
362
  }
303
- get startTimeMs() {
304
- return getStartTimeMs(this);
305
- }
306
363
  #audioContext;
307
364
  async fetchAudioSpanningTime(fromMs, toMs) {
308
365
  if (this.sourceInMs) {
@@ -83,14 +83,14 @@ function ContextMixin(superClass) {
83
83
  const scale = stageHeight / canvasHeight;
84
84
  if (this.stageScale !== scale) {
85
85
  canvasElement.style.transform = `scale(${scale})`;
86
- canvasElement.style.transformOrigin = "top";
86
+ canvasElement.style.transformOrigin = "center left";
87
87
  }
88
88
  this.stageScale = scale;
89
89
  } else {
90
90
  const scale = stageWidth / canvasWidth;
91
91
  if (this.stageScale !== scale) {
92
92
  canvasElement.style.transform = `scale(${scale})`;
93
- canvasElement.style.transformOrigin = "top";
93
+ canvasElement.style.transformOrigin = "center left";
94
94
  }
95
95
  this.stageScale = scale;
96
96
  }
@@ -1,8 +1,8 @@
1
1
  import { html, css, LitElement } from "lit";
2
2
  import { customElement } from "lit/decorators.js";
3
3
  import { ref } from "lit/directives/ref.js";
4
- import { TWMixin } from "./TWMixin.js";
5
4
  import { ContextMixin } from "./ContextMixin.js";
5
+ import { TWMixin } from "./TWMixin.js";
6
6
  var __defProp = Object.defineProperty;
7
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
8
  var __decorateClass = (decorators, target, key, kind) => {
@@ -23,7 +23,9 @@ let EFPreview = class extends ContextMixin(TWMixin(LitElement)) {
23
23
  <slot
24
24
  ${ref(this.canvasRef)}
25
25
  class="inline-block"
26
+ name="canvas"
26
27
  ></slot>
28
+ <slot name="controls"></slot>
27
29
  </div>
28
30
  `;
29
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editframe/elements",
3
- "version": "0.12.0-beta.3",
3
+ "version": "0.12.0-beta.6",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,7 @@
20
20
  "author": "",
21
21
  "license": "UNLICENSED",
22
22
  "dependencies": {
23
- "@editframe/assets": "0.12.0-beta.3",
23
+ "@editframe/assets": "0.12.0-beta.6",
24
24
  "@lit/context": "^1.1.2",
25
25
  "@lit/task": "^1.0.1",
26
26
  "d3": "^7.9.0",
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, test } from "vitest";
4
4
  import { EFMedia } from "./EFMedia.ts";
5
5
  import "../gui/EFWorkbench.ts";
6
6
  import "../gui/EFPreview.ts";
7
+ import "./EFTimegroup.ts";
7
8
  import { createTestFragmentIndex } from "TEST/createTestFragmentIndex.ts";
8
9
  import { useMockWorker } from "TEST/useMockWorker.ts";
9
10
  import { http, HttpResponse } from "msw";
@@ -291,6 +292,7 @@ describe("EFMedia", () => {
291
292
  expect(element.durationMs).toBe(4_000);
292
293
  expect(timegroup.durationMs).toBe(4_000);
293
294
  });
295
+
294
296
  test("Computes duration from track fragment index sourceout and sourcein", async () => {
295
297
  // Mock the request for the track fragment index, responds with a 10 second duration
296
298
  worker.use(
@@ -14,9 +14,8 @@ import { EF_INTERACTIVE } from "../EF_INTERACTIVE.ts";
14
14
  import { EF_RENDERING } from "../EF_RENDERING.ts";
15
15
  import { apiHostContext } from "../gui/apiHostContext.ts";
16
16
  import { EFSourceMixin } from "./EFSourceMixin.ts";
17
- import { EFTemporal } from "./EFTemporal.ts";
17
+ import { EFTemporal, isEFTemporal } from "./EFTemporal.ts";
18
18
  import { FetchMixin } from "./FetchMixin.ts";
19
- import { getStartTimeMs } from "./util.ts";
20
19
 
21
20
  const log = debug("ef:elements:EFMedia");
22
21
 
@@ -297,6 +296,83 @@ export class EFMedia extends EFSourceMixin(EFTemporal(FetchMixin(LitElement)), {
297
296
  if (changedProperties.has("ownCurrentTimeMs")) {
298
297
  this.executeSeek(this.trimAdjustedOwnCurrentTimeMs);
299
298
  }
299
+ // TODO: this is copied straight from EFTimegroup.ts
300
+ // and should be refactored to be shared/reduce bad duplication of
301
+ // critical logic.
302
+ if (
303
+ changedProperties.has("currentTime") ||
304
+ changedProperties.has("ownCurrentTimeMs")
305
+ ) {
306
+ const timelineTimeMs = (this.rootTimegroup ?? this).currentTimeMs;
307
+ if (
308
+ this.startTimeMs > timelineTimeMs ||
309
+ this.endTimeMs < timelineTimeMs
310
+ ) {
311
+ this.style.display = "none";
312
+ return;
313
+ }
314
+ this.style.display = "";
315
+
316
+ const animations = this.getAnimations({ subtree: true });
317
+ this.style.setProperty("--ef-duration", `${this.durationMs}ms`);
318
+ this.style.setProperty(
319
+ "--ef-transition--duration",
320
+ `${this.parentTimegroup?.overlapMs ?? 0}ms`,
321
+ );
322
+ this.style.setProperty(
323
+ "--ef-transition-out-start",
324
+ `${this.durationMs - (this.parentTimegroup?.overlapMs ?? 0)}ms`,
325
+ );
326
+
327
+ for (const animation of animations) {
328
+ if (animation.playState === "running") {
329
+ animation.pause();
330
+ }
331
+ const effect = animation.effect;
332
+ if (!(effect && effect instanceof KeyframeEffect)) {
333
+ return;
334
+ }
335
+ const target = effect.target;
336
+ // TODO: better generalize work avoidance for temporal elements
337
+ if (!target) {
338
+ return;
339
+ }
340
+ if (target.closest("ef-video, ef-audio") !== this) {
341
+ return;
342
+ }
343
+
344
+ // Important to avoid going to the end of the animation
345
+ // or it will reset awkwardly.
346
+ if (isEFTemporal(target)) {
347
+ const timing = effect.getTiming();
348
+ const duration = Number(timing.duration) ?? 0;
349
+ const delay = Number(timing.delay);
350
+ const newTime = Math.floor(
351
+ Math.min(target.ownCurrentTimeMs, duration - 1 + delay),
352
+ );
353
+ if (Number.isNaN(newTime)) {
354
+ return;
355
+ }
356
+ animation.currentTime = newTime;
357
+ } else if (target) {
358
+ const nearestTimegroup = target.closest("ef-timegroup");
359
+ if (!nearestTimegroup) {
360
+ return;
361
+ }
362
+ const timing = effect.getTiming();
363
+ const duration = Number(timing.duration) ?? 0;
364
+ const delay = Number(timing.delay);
365
+ const newTime = Math.floor(
366
+ Math.min(nearestTimegroup.ownCurrentTimeMs, duration - 1 + delay),
367
+ );
368
+
369
+ if (Number.isNaN(newTime)) {
370
+ return;
371
+ }
372
+ animation.currentTime = newTime;
373
+ }
374
+ }
375
+ }
300
376
  }
301
377
 
302
378
  get hasOwnDuration() {
@@ -351,10 +427,6 @@ export class EFMedia extends EFSourceMixin(EFTemporal(FetchMixin(LitElement)), {
351
427
  return Math.max(...durations) - this.trimStartMs - this.trimEndMs;
352
428
  }
353
429
 
354
- get startTimeMs() {
355
- return getStartTimeMs(this);
356
- }
357
-
358
430
  #audioContext = new OfflineAudioContext(2, 48000 / 30, 48000);
359
431
 
360
432
  audioBufferTask = new Task(this, {
@@ -136,18 +136,19 @@ export function ContextMixin<T extends Constructor<LitElement>>(superClass: T) {
136
136
  const canvasHeight = canvasElement.clientHeight;
137
137
  const stageRatio = stageWidth / stageHeight;
138
138
  const canvasRatio = canvasWidth / canvasHeight;
139
+
139
140
  if (stageRatio > canvasRatio) {
140
141
  const scale = stageHeight / canvasHeight;
141
142
  if (this.stageScale !== scale) {
142
143
  canvasElement.style.transform = `scale(${scale})`;
143
- canvasElement.style.transformOrigin = "top";
144
+ canvasElement.style.transformOrigin = "center left";
144
145
  }
145
146
  this.stageScale = scale;
146
147
  } else {
147
148
  const scale = stageWidth / canvasWidth;
148
149
  if (this.stageScale !== scale) {
149
150
  canvasElement.style.transform = `scale(${scale})`;
150
- canvasElement.style.transformOrigin = "top";
151
+ canvasElement.style.transformOrigin = "center left";
151
152
  }
152
153
  this.stageScale = scale;
153
154
  }
@@ -1,9 +1,9 @@
1
- import { LitElement, html, css } from "lit";
1
+ import { LitElement, css, html } from "lit";
2
2
  import { customElement } from "lit/decorators.js";
3
3
  import { ref } from "lit/directives/ref.js";
4
4
 
5
- import { TWMixin } from "./TWMixin.ts";
6
5
  import { ContextMixin } from "./ContextMixin.ts";
6
+ import { TWMixin } from "./TWMixin.ts";
7
7
 
8
8
  @customElement("ef-preview")
9
9
  export class EFPreview extends ContextMixin(TWMixin(LitElement)) {
@@ -26,7 +26,9 @@ export class EFPreview extends ContextMixin(TWMixin(LitElement)) {
26
26
  <slot
27
27
  ${ref(this.canvasRef)}
28
28
  class="inline-block"
29
+ name="canvas"
29
30
  ></slot>
31
+ <slot name="controls"></slot>
30
32
  </div>
31
33
  `;
32
34
  }
@@ -1,11 +0,0 @@
1
- import { EFTimegroup } from "./EFTimegroup.js";
2
- const getStartTimeMs = (element) => {
3
- const nearestTimeGroup = element.closest("ef-timegroup");
4
- if (!(nearestTimeGroup instanceof EFTimegroup)) {
5
- return 0;
6
- }
7
- return nearestTimeGroup.startTimeMs;
8
- };
9
- export {
10
- getStartTimeMs
11
- };