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

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 (40) hide show
  1. package/dist/lib/av/EncodedAsset.cjs +4 -1
  2. package/dist/lib/av/EncodedAsset.js +4 -1
  3. package/dist/packages/elements/src/EF_FRAMEGEN.d.ts +1 -1
  4. package/dist/packages/elements/src/elements/EFMedia.cjs +1 -1
  5. package/dist/packages/elements/src/elements/EFMedia.d.ts +1 -1
  6. package/dist/packages/elements/src/elements/EFMedia.js +1 -1
  7. package/dist/packages/elements/src/elements/EFTimegroup.cjs +38 -31
  8. package/dist/packages/elements/src/elements/EFTimegroup.d.ts +1 -1
  9. package/dist/packages/elements/src/elements/EFTimegroup.js +38 -31
  10. package/dist/packages/elements/src/gui/EFFilmstrip.cjs +128 -27
  11. package/dist/packages/elements/src/gui/EFFilmstrip.d.ts +7 -6
  12. package/dist/packages/elements/src/gui/EFFilmstrip.js +129 -28
  13. package/dist/packages/elements/src/gui/TWMixin.css.cjs +1 -1
  14. package/dist/packages/elements/src/gui/TWMixin.css.js +1 -1
  15. package/dist/packages/elements/src/index.cjs +6 -2
  16. package/dist/packages/elements/src/index.d.ts +2 -2
  17. package/dist/packages/elements/src/index.js +4 -3
  18. package/dist/style.css +21 -3
  19. package/package.json +2 -2
  20. package/src/elements/CrossUpdateController.ts +22 -0
  21. package/src/elements/EFAudio.ts +40 -0
  22. package/src/elements/EFCaptions.ts +188 -0
  23. package/src/elements/EFImage.ts +68 -0
  24. package/src/elements/EFMedia.ts +384 -0
  25. package/src/elements/EFSourceMixin.ts +57 -0
  26. package/src/elements/EFTemporal.ts +231 -0
  27. package/src/elements/EFTimegroup.browsertest.ts +333 -0
  28. package/src/elements/EFTimegroup.ts +389 -0
  29. package/src/elements/EFTimeline.ts +13 -0
  30. package/src/elements/EFVideo.ts +103 -0
  31. package/src/elements/EFWaveform.ts +409 -0
  32. package/src/elements/FetchMixin.ts +19 -0
  33. package/src/elements/TimegroupController.ts +25 -0
  34. package/src/elements/durationConverter.ts +6 -0
  35. package/src/elements/parseTimeToMs.ts +9 -0
  36. package/src/elements/util.ts +24 -0
  37. package/src/gui/EFFilmstrip.ts +878 -0
  38. package/src/gui/EFWorkbench.ts +231 -0
  39. package/src/gui/TWMixin.css +3 -0
  40. package/src/gui/TWMixin.ts +30 -0
@@ -0,0 +1,231 @@
1
+ import { createContext, provide } from "@lit/context";
2
+ import { LitElement, html, css, type PropertyValueMap } from "lit";
3
+ import { TaskStatus } from "@lit/task";
4
+ import {
5
+ customElement,
6
+ eventOptions,
7
+ property,
8
+ state,
9
+ } from "lit/decorators.js";
10
+ import { ref, createRef } from "lit/directives/ref.js";
11
+
12
+ import { awaitMicrotask } from "@/util/awaitMicrotask";
13
+ import { deepGetTemporalElements } from "../elements/EFTemporal";
14
+ import { TWMixin } from "./TWMixin";
15
+ import { shallowGetTimegroups } from "../elements/EFTimegroup";
16
+
17
+ export interface FocusContext {
18
+ focusedElement: HTMLElement | null;
19
+ }
20
+ export const focusContext = createContext<FocusContext>(null);
21
+
22
+ export const focusedElement = createContext<HTMLElement | null>(null);
23
+
24
+ export const fetchContext = createContext<typeof fetch>(fetch);
25
+
26
+ export const apiHostContext = createContext<string>(null);
27
+
28
+ @customElement("ef-workbench")
29
+ export class EFWorkbench extends TWMixin(LitElement) {
30
+ static styles = [
31
+ css`
32
+ :host {
33
+ display: block;
34
+ width: 100%;
35
+ height: 100%;
36
+ }
37
+ `,
38
+ ];
39
+ stageRef = createRef<HTMLDivElement>();
40
+ canvasRef = createRef<HTMLSlotElement>();
41
+
42
+ @state()
43
+ stageScale = 1;
44
+
45
+ setStageScale = () => {
46
+ if (this.isConnected && !this.rendering) {
47
+ const canvasElement = this.canvasRef.value;
48
+ const stageElement = this.stageRef.value;
49
+ if (stageElement && canvasElement) {
50
+ // Determine the appropriate scale factor to make the canvas fit into
51
+ // it's parent element.
52
+ const stageWidth = stageElement.clientWidth;
53
+ const stageHeight = stageElement.clientHeight;
54
+ const canvasWidth = canvasElement.clientWidth;
55
+ const canvasHeight = canvasElement.clientHeight;
56
+ const stageRatio = stageWidth / stageHeight;
57
+ const canvasRatio = canvasWidth / canvasHeight;
58
+ if (stageRatio > canvasRatio) {
59
+ const scale = stageHeight / canvasHeight;
60
+ if (this.stageScale !== scale) {
61
+ canvasElement.style.transform = `scale(${scale})`;
62
+ }
63
+ this.stageScale = scale;
64
+ } else {
65
+ const scale = stageWidth / canvasWidth;
66
+ if (this.stageScale !== scale) {
67
+ canvasElement.style.transform = `scale(${scale})`;
68
+ }
69
+ this.stageScale = scale;
70
+ }
71
+ }
72
+ }
73
+ if (this.isConnected) {
74
+ requestAnimationFrame(this.setStageScale);
75
+ }
76
+ };
77
+
78
+ connectedCallback(): void {
79
+ super.connectedCallback();
80
+ // Preferrably we would use a resizeObserver, but it is difficult to get the first resize
81
+ // timed correctl. So we use requestAnimationFrame as a stop-gap.
82
+ requestAnimationFrame(this.setStageScale);
83
+ }
84
+
85
+ disconnectedCallback(): void {
86
+ super.disconnectedCallback();
87
+ }
88
+
89
+ @eventOptions({ passive: false, capture: true })
90
+ handleStageWheel(event: WheelEvent) {
91
+ event.preventDefault();
92
+ }
93
+
94
+ @provide({ context: focusContext })
95
+ focusContext = this;
96
+
97
+ @provide({ context: focusedElement })
98
+ @state()
99
+ focusedElement: HTMLElement | null = null;
100
+
101
+ @provide({ context: fetchContext })
102
+ fetch = (path: URL | RequestInfo, init: RequestInit = {}) => {
103
+ init.headers ||= {};
104
+ Object.assign(init.headers, {
105
+ "Content-Type": "application/json",
106
+ });
107
+
108
+ const bearerToken = this.apiToken;
109
+ if (bearerToken) {
110
+ Object.assign(init.headers, {
111
+ Authorization: `Bearer ${bearerToken}`,
112
+ });
113
+ }
114
+
115
+ return fetch(path, init);
116
+ };
117
+
118
+ @property({ type: String })
119
+ apiToken?: string;
120
+
121
+ @provide({ context: apiHostContext })
122
+ @property({ type: String })
123
+ apiHost = "";
124
+
125
+ @property({ type: Boolean })
126
+ rendering = false;
127
+
128
+ focusOverlay = createRef<HTMLDivElement>();
129
+
130
+ protected update(
131
+ changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>,
132
+ ): void {
133
+ super.update(changedProperties);
134
+
135
+ if (changedProperties.has("focusedElement")) {
136
+ this.drawOverlays();
137
+ }
138
+ }
139
+
140
+ drawOverlays = () => {
141
+ const focusOverlay = this.focusOverlay.value;
142
+ if (focusOverlay) {
143
+ if (this.focusedElement) {
144
+ focusOverlay.style.display = "block";
145
+ const rect = this.focusedElement.getBoundingClientRect();
146
+ Object.assign(focusOverlay.style, {
147
+ position: "absolute",
148
+ top: `${rect.top}px`,
149
+ left: `${rect.left}px`,
150
+ width: `${rect.width}px`,
151
+ height: `${rect.height}px`,
152
+ });
153
+ requestAnimationFrame(this.drawOverlays);
154
+ } else {
155
+ focusOverlay.style.display = "none";
156
+ }
157
+ }
158
+ };
159
+
160
+ render() {
161
+ if (this.rendering) {
162
+ return html`
163
+ <slot
164
+ ${ref(this.canvasRef)}
165
+ class="fixed inset-0 h-full w-full"
166
+ name="canvas"
167
+ ></slot>
168
+ `;
169
+ }
170
+ return html`
171
+ <div
172
+ class="grid h-full w-full"
173
+ style="grid-template-rows: 1fr 300px; grid-template-columns: 100%;"
174
+ >
175
+ <div
176
+ ${ref(this.stageRef)}
177
+ class="relative grid h-full w-full place-content-center place-items-center overflow-hidden"
178
+ @wheel=${this.handleStageWheel}
179
+ >
180
+ <slot
181
+ ${ref(this.canvasRef)}
182
+ class="inline-block"
183
+ name="canvas"
184
+ ></slot>
185
+ <div
186
+ class="border border-blue-500 bg-blue-200 bg-opacity-20"
187
+ ${ref(this.focusOverlay)}
188
+ ></div>
189
+ </div>
190
+
191
+ <slot class="overflow" name="timeline"></slot>
192
+ </div>
193
+ `;
194
+ }
195
+
196
+ async stepThrough() {
197
+ const stepDurationMs = 1000 / 30;
198
+ const timegroups = shallowGetTimegroups(this);
199
+ const firstGroup = timegroups[0];
200
+ if (!firstGroup) {
201
+ throw new Error("No temporal elements found");
202
+ }
203
+ firstGroup.currentTimeMs = 0;
204
+
205
+ const temporals = deepGetTemporalElements(this);
206
+ const frameCount = Math.ceil(firstGroup.durationMs / stepDurationMs);
207
+
208
+ const busyTasks = temporals
209
+ .filter((temporal) => temporal.frameTask.status < TaskStatus.COMPLETE)
210
+ .map((temporal) => temporal.frameTask);
211
+
212
+ await Promise.all(busyTasks.map((task) => task.taskComplete));
213
+
214
+ for (let i = 0; i < frameCount; i++) {
215
+ firstGroup.currentTimeMs = i * stepDurationMs;
216
+ await awaitMicrotask();
217
+ const busyTasks = temporals
218
+ .filter((temporal) => temporal.frameTask.status < TaskStatus.COMPLETE)
219
+ .map((temporal) => temporal.frameTask);
220
+
221
+ await Promise.all(busyTasks.map((task) => task.taskComplete));
222
+ await new Promise((resolve) => requestAnimationFrame(resolve));
223
+ }
224
+ }
225
+ }
226
+
227
+ declare global {
228
+ interface HTMLElementTagNameMap {
229
+ "ef-workbench": EFWorkbench;
230
+ }
231
+ }
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,30 @@
1
+ import type { LitElement } from "lit";
2
+ // @ts-expect-error cannot figure out how to declare this module as a string
3
+ import twStyle from "./TWMixin.css?inline";
4
+
5
+ const twSheet = new CSSStyleSheet();
6
+ twSheet.replaceSync(twStyle);
7
+ export function TWMixin<T extends new (...args: any[]) => LitElement>(Base: T) {
8
+ class TWElement extends Base {
9
+ createRenderRoot() {
10
+ const renderRoot = super.createRenderRoot();
11
+ if (!(renderRoot instanceof ShadowRoot)) {
12
+ throw new Error(
13
+ "TWMixin can only be applied to elements with shadow roots",
14
+ );
15
+ }
16
+
17
+ if (renderRoot?.adoptedStyleSheets) {
18
+ renderRoot.adoptedStyleSheets = [
19
+ twSheet,
20
+ ...renderRoot.adoptedStyleSheets,
21
+ ];
22
+ } else {
23
+ renderRoot.adoptedStyleSheets = [twSheet];
24
+ }
25
+ return renderRoot;
26
+ }
27
+ }
28
+
29
+ return TWElement as T;
30
+ }