@editframe/react 0.23.8-beta.0 → 0.25.0-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 (82) hide show
  1. package/dist/components/TimeDisplay.d.ts +8 -0
  2. package/dist/components/TimeDisplay.js +10 -7
  3. package/dist/components/TimeDisplay.js.map +1 -0
  4. package/dist/elements/Audio.d.ts +8 -2
  5. package/dist/elements/Audio.js +10 -7
  6. package/dist/elements/Audio.js.map +1 -0
  7. package/dist/elements/Captions.d.ts +12 -6
  8. package/dist/elements/Captions.js +23 -24
  9. package/dist/elements/Captions.js.map +1 -0
  10. package/dist/elements/Image.d.ts +8 -2
  11. package/dist/elements/Image.js +10 -7
  12. package/dist/elements/Image.js.map +1 -0
  13. package/dist/elements/Surface.d.ts +8 -2
  14. package/dist/elements/Surface.js +12 -9
  15. package/dist/elements/Surface.js.map +1 -0
  16. package/dist/elements/ThumbnailStrip.d.ts +8 -2
  17. package/dist/elements/ThumbnailStrip.js +12 -9
  18. package/dist/elements/ThumbnailStrip.js.map +1 -0
  19. package/dist/elements/Timegroup.d.ts +8 -2
  20. package/dist/elements/Timegroup.js +10 -7
  21. package/dist/elements/Timegroup.js.map +1 -0
  22. package/dist/elements/Video.d.ts +8 -2
  23. package/dist/elements/Video.js +10 -7
  24. package/dist/elements/Video.js.map +1 -0
  25. package/dist/elements/Waveform.d.ts +8 -2
  26. package/dist/elements/Waveform.js +10 -7
  27. package/dist/elements/Waveform.js.map +1 -0
  28. package/dist/gui/Configuration.d.ts +8 -2
  29. package/dist/gui/Configuration.js +10 -7
  30. package/dist/gui/Configuration.js.map +1 -0
  31. package/dist/gui/Controls.d.ts +8 -2
  32. package/dist/gui/Controls.js +10 -7
  33. package/dist/gui/Controls.js.map +1 -0
  34. package/dist/gui/EFDial.d.ts +9 -3
  35. package/dist/gui/EFDial.js +11 -10
  36. package/dist/gui/EFDial.js.map +1 -0
  37. package/dist/gui/EFResizableBox.d.ts +9 -3
  38. package/dist/gui/EFResizableBox.js +11 -10
  39. package/dist/gui/EFResizableBox.js.map +1 -0
  40. package/dist/gui/Filmstrip.d.ts +8 -2
  41. package/dist/gui/Filmstrip.js +10 -7
  42. package/dist/gui/Filmstrip.js.map +1 -0
  43. package/dist/gui/FitScale.d.ts +8 -2
  44. package/dist/gui/FitScale.js +10 -7
  45. package/dist/gui/FitScale.js.map +1 -0
  46. package/dist/gui/FocusOverlay.d.ts +8 -2
  47. package/dist/gui/FocusOverlay.js +10 -7
  48. package/dist/gui/FocusOverlay.js.map +1 -0
  49. package/dist/gui/Pause.d.ts +8 -2
  50. package/dist/gui/Pause.js +10 -7
  51. package/dist/gui/Pause.js.map +1 -0
  52. package/dist/gui/Play.d.ts +8 -2
  53. package/dist/gui/Play.js +10 -7
  54. package/dist/gui/Play.js.map +1 -0
  55. package/dist/gui/Preview.d.ts +8 -2
  56. package/dist/gui/Preview.js +10 -7
  57. package/dist/gui/Preview.js.map +1 -0
  58. package/dist/gui/Scrubber.d.ts +8 -2
  59. package/dist/gui/Scrubber.js +10 -7
  60. package/dist/gui/Scrubber.js.map +1 -0
  61. package/dist/gui/ToggleLoop.d.ts +8 -2
  62. package/dist/gui/ToggleLoop.js +10 -7
  63. package/dist/gui/ToggleLoop.js.map +1 -0
  64. package/dist/gui/TogglePlay.d.ts +8 -2
  65. package/dist/gui/TogglePlay.js +10 -7
  66. package/dist/gui/TogglePlay.js.map +1 -0
  67. package/dist/gui/Workbench.d.ts +8 -2
  68. package/dist/gui/Workbench.js +10 -7
  69. package/dist/gui/Workbench.js.map +1 -0
  70. package/dist/hooks/create-element.d.ts +9 -18
  71. package/dist/hooks/create-element.js +72 -94
  72. package/dist/hooks/create-element.js.map +1 -0
  73. package/dist/hooks/useTimingInfo.d.ts +12 -6
  74. package/dist/hooks/useTimingInfo.js +63 -33
  75. package/dist/hooks/useTimingInfo.js.map +1 -0
  76. package/dist/index.d.ts +25 -24
  77. package/dist/index.js +2 -30
  78. package/package.json +11 -19
  79. package/src/hooks/useTimingInfo.browsertest.tsx +371 -0
  80. package/src/hooks/useTimingInfo.ts +56 -1
  81. package/tsdown.config.ts +36 -0
  82. package/types.json +1 -1
@@ -1,35 +1,65 @@
1
- import { useRef, useState, useEffect } from "react";
2
- class CurrentTimeController {
3
- constructor(host, setCurrentTime) {
4
- this.host = host;
5
- this.setCurrentTime = setCurrentTime;
6
- this.host.addController(this);
7
- }
8
- hostDisconnected() {
9
- this.host.removeController(this);
10
- }
11
- hostUpdated() {
12
- this.setCurrentTime({
13
- ownCurrentTimeMs: this.host.ownCurrentTimeMs,
14
- durationMs: this.host.durationMs,
15
- percentComplete: this.host.ownCurrentTimeMs / this.host.durationMs
16
- });
17
- }
18
- }
19
- const useTimingInfo = (timegroupRef = useRef(null)) => {
20
- const [timeInfo, setTimeInfo] = useState({
21
- ownCurrentTimeMs: 0,
22
- durationMs: 0,
23
- percentComplete: 0
24
- });
25
- useEffect(() => {
26
- if (!timegroupRef.current) {
27
- throw new Error("Timegroup ref not set");
28
- }
29
- new CurrentTimeController(timegroupRef.current, setTimeInfo);
30
- }, [timegroupRef.current]);
31
- return { ...timeInfo, ref: timegroupRef };
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ //#region src/hooks/useTimingInfo.ts
4
+ var CurrentTimeController = class {
5
+ #lastTaskPromise = null;
6
+ #isConnected = false;
7
+ constructor(host, setCurrentTime) {
8
+ this.host = host;
9
+ this.setCurrentTime = setCurrentTime;
10
+ this.host.addController(this);
11
+ }
12
+ hostConnected() {
13
+ this.#isConnected = true;
14
+ }
15
+ hostDisconnected() {
16
+ this.#isConnected = false;
17
+ this.#lastTaskPromise = null;
18
+ this.host.removeController(this);
19
+ }
20
+ hostUpdated() {
21
+ const currentTaskPromise = this.host.frameTask.taskComplete;
22
+ if (currentTaskPromise !== this.#lastTaskPromise) {
23
+ this.#lastTaskPromise = currentTaskPromise;
24
+ currentTaskPromise.then(() => {
25
+ if (this.#isConnected) this.#updateReactState();
26
+ }).catch(() => {});
27
+ }
28
+ }
29
+ #updateReactState() {
30
+ this.setCurrentTime({
31
+ ownCurrentTimeMs: this.host.ownCurrentTimeMs,
32
+ durationMs: this.host.durationMs,
33
+ percentComplete: this.host.ownCurrentTimeMs / this.host.durationMs
34
+ });
35
+ }
36
+ syncNow() {
37
+ this.#updateReactState();
38
+ }
32
39
  };
33
- export {
34
- useTimingInfo
40
+ const useTimingInfo = (timegroupRef = useRef(null)) => {
41
+ const [timeInfo, setTimeInfo] = useState({
42
+ ownCurrentTimeMs: 0,
43
+ durationMs: 0,
44
+ percentComplete: 0
45
+ });
46
+ useEffect(() => {
47
+ if (!timegroupRef.current) throw new Error("Timegroup ref not set");
48
+ const controller = new CurrentTimeController(timegroupRef.current, setTimeInfo);
49
+ if (timegroupRef.current.isConnected) {
50
+ controller.hostConnected();
51
+ controller.syncNow();
52
+ }
53
+ return () => {
54
+ controller.hostDisconnected();
55
+ };
56
+ }, [timegroupRef.current]);
57
+ return {
58
+ ...timeInfo,
59
+ ref: timegroupRef
60
+ };
35
61
  };
62
+
63
+ //#endregion
64
+ export { useTimingInfo };
65
+ //# sourceMappingURL=useTimingInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTimingInfo.js","names":["host: {\n ownCurrentTimeMs: number;\n durationMs: number;\n frameTask: Task<readonly unknown[], unknown>;\n } & ReactiveControllerHost","setCurrentTime: React.Dispatch<React.SetStateAction<TimeInfo>>","#isConnected","#lastTaskPromise","#updateReactState"],"sources":["../../src/hooks/useTimingInfo.ts"],"sourcesContent":["import type { EFTimegroup } from \"@editframe/elements\";\nimport type { Task } from \"@lit/task\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport { useEffect, useRef, useState } from \"react\";\n\ninterface TimeInfo {\n ownCurrentTimeMs: number;\n durationMs: number;\n percentComplete: number;\n}\n\nclass CurrentTimeController implements ReactiveController {\n #lastTaskPromise: Promise<unknown> | null = null;\n #isConnected = false;\n\n constructor(\n private host: {\n ownCurrentTimeMs: number;\n durationMs: number;\n frameTask: Task<readonly unknown[], unknown>;\n } & ReactiveControllerHost,\n private setCurrentTime: React.Dispatch<React.SetStateAction<TimeInfo>>,\n ) {\n this.host.addController(this);\n }\n\n hostConnected(): void {\n this.#isConnected = true;\n }\n\n hostDisconnected(): void {\n this.#isConnected = false;\n this.#lastTaskPromise = null;\n this.host.removeController(this);\n }\n\n hostUpdated(): void {\n const currentTaskPromise = this.host.frameTask.taskComplete;\n\n // Detect if a new frame task has started (promise reference changed)\n if (currentTaskPromise !== this.#lastTaskPromise) {\n this.#lastTaskPromise = currentTaskPromise;\n\n // Wait for this specific task to complete, then update React\n // This is async so it doesn't block the update cycle\n currentTaskPromise\n .then(() => {\n // Only update if still connected\n if (this.#isConnected) {\n this.#updateReactState();\n }\n })\n .catch(() => {\n // Ignore task errors - we'll continue observing\n });\n }\n }\n\n #updateReactState(): void {\n // Always update to ensure React has the latest state\n this.setCurrentTime({\n ownCurrentTimeMs: this.host.ownCurrentTimeMs,\n durationMs: this.host.durationMs,\n percentComplete: this.host.ownCurrentTimeMs / this.host.durationMs,\n });\n }\n\n // Public method to manually trigger sync (for initialization)\n syncNow(): void {\n this.#updateReactState();\n }\n}\n\nexport const useTimingInfo = (\n timegroupRef: React.RefObject<EFTimegroup> = useRef<EFTimegroup>(null),\n) => {\n const [timeInfo, setTimeInfo] = useState<TimeInfo>({\n ownCurrentTimeMs: 0,\n durationMs: 0,\n percentComplete: 0,\n });\n\n useEffect(() => {\n if (!timegroupRef.current) {\n throw new Error(\"Timegroup ref not set\");\n }\n\n const controller = new CurrentTimeController(\n timegroupRef.current,\n setTimeInfo,\n );\n\n // Trigger initial update if the timegroup is already connected\n if (timegroupRef.current.isConnected) {\n controller.hostConnected();\n // Sync initial state immediately\n controller.syncNow();\n }\n\n // Cleanup function\n return () => {\n controller.hostDisconnected();\n };\n }, [timegroupRef.current]);\n\n return { ...timeInfo, ref: timegroupRef };\n};\n"],"mappings":";;;AAWA,IAAM,wBAAN,MAA0D;CACxD,mBAA4C;CAC5C,eAAe;CAEf,YACE,AAAQA,MAKR,AAAQC,gBACR;EANQ;EAKA;AAER,OAAK,KAAK,cAAc,KAAK;;CAG/B,gBAAsB;AACpB,QAAKC,cAAe;;CAGtB,mBAAyB;AACvB,QAAKA,cAAe;AACpB,QAAKC,kBAAmB;AACxB,OAAK,KAAK,iBAAiB,KAAK;;CAGlC,cAAoB;EAClB,MAAM,qBAAqB,KAAK,KAAK,UAAU;AAG/C,MAAI,uBAAuB,MAAKA,iBAAkB;AAChD,SAAKA,kBAAmB;AAIxB,sBACG,WAAW;AAEV,QAAI,MAAKD,YACP,OAAKE,kBAAmB;KAE1B,CACD,YAAY,GAEX;;;CAIR,oBAA0B;AAExB,OAAK,eAAe;GAClB,kBAAkB,KAAK,KAAK;GAC5B,YAAY,KAAK,KAAK;GACtB,iBAAiB,KAAK,KAAK,mBAAmB,KAAK,KAAK;GACzD,CAAC;;CAIJ,UAAgB;AACd,QAAKA,kBAAmB;;;AAI5B,MAAa,iBACX,eAA6C,OAAoB,KAAK,KACnE;CACH,MAAM,CAAC,UAAU,eAAe,SAAmB;EACjD,kBAAkB;EAClB,YAAY;EACZ,iBAAiB;EAClB,CAAC;AAEF,iBAAgB;AACd,MAAI,CAAC,aAAa,QAChB,OAAM,IAAI,MAAM,wBAAwB;EAG1C,MAAM,aAAa,IAAI,sBACrB,aAAa,SACb,YACD;AAGD,MAAI,aAAa,QAAQ,aAAa;AACpC,cAAW,eAAe;AAE1B,cAAW,SAAS;;AAItB,eAAa;AACX,cAAW,kBAAkB;;IAE9B,CAAC,aAAa,QAAQ,CAAC;AAE1B,QAAO;EAAE,GAAG;EAAU,KAAK;EAAc"}
package/dist/index.d.ts CHANGED
@@ -1,24 +1,25 @@
1
- export { TimeDisplay } from './components/TimeDisplay.js';
2
- export { Audio } from './elements/Audio.js';
3
- export { Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment, } from './elements/Captions.js';
4
- export { Image } from './elements/Image.js';
5
- export { Surface } from './elements/Surface.js';
6
- export { ThumbnailStrip } from './elements/ThumbnailStrip.js';
7
- export { Timegroup } from './elements/Timegroup.js';
8
- export { Video } from './elements/Video.js';
9
- export { Waveform } from './elements/Waveform.js';
10
- export { Configuration } from './gui/Configuration.js';
11
- export { Controls } from './gui/Controls.js';
12
- export { Dial } from './gui/EFDial.js';
13
- export { ResizableBox } from './gui/EFResizableBox.js';
14
- export { Filmstrip } from './gui/Filmstrip.js';
15
- export { FitScale } from './gui/FitScale.js';
16
- export { FocusOverlay } from './gui/FocusOverlay.js';
17
- export { Pause } from './gui/Pause.js';
18
- export { Play } from './gui/Play.js';
19
- export { Preview } from './gui/Preview.js';
20
- export { Scrubber } from './gui/Scrubber.js';
21
- export { ToggleLoop } from './gui/ToggleLoop.js';
22
- export { TogglePlay } from './gui/TogglePlay.js';
23
- export { Workbench } from './gui/Workbench.js';
24
- export { useTimingInfo } from './hooks/useTimingInfo.js';
1
+ import { TimeDisplay } from "./components/TimeDisplay.js";
2
+ import { Audio } from "./elements/Audio.js";
3
+ import { Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment } from "./elements/Captions.js";
4
+ import { Image } from "./elements/Image.js";
5
+ import { Surface } from "./elements/Surface.js";
6
+ import { ThumbnailStrip } from "./elements/ThumbnailStrip.js";
7
+ import { Timegroup } from "./elements/Timegroup.js";
8
+ import { Video } from "./elements/Video.js";
9
+ import { Waveform } from "./elements/Waveform.js";
10
+ import { Configuration } from "./gui/Configuration.js";
11
+ import { Controls } from "./gui/Controls.js";
12
+ import { Dial } from "./gui/EFDial.js";
13
+ import { ResizableBox } from "./gui/EFResizableBox.js";
14
+ import { Filmstrip } from "./gui/Filmstrip.js";
15
+ import { FitScale } from "./gui/FitScale.js";
16
+ import { FocusOverlay } from "./gui/FocusOverlay.js";
17
+ import { Pause } from "./gui/Pause.js";
18
+ import { Play } from "./gui/Play.js";
19
+ import { Preview } from "./gui/Preview.js";
20
+ import { Scrubber } from "./gui/Scrubber.js";
21
+ import { ToggleLoop } from "./gui/ToggleLoop.js";
22
+ import { TogglePlay } from "./gui/TogglePlay.js";
23
+ import { Workbench } from "./gui/Workbench.js";
24
+ import { useTimingInfo } from "./hooks/useTimingInfo.js";
25
+ export { Audio, Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment, Configuration, Controls, Dial, Filmstrip, FitScale, FocusOverlay, Image, Pause, Play, Preview, ResizableBox, Scrubber, Surface, ThumbnailStrip, TimeDisplay, Timegroup, ToggleLoop, TogglePlay, Video, Waveform, Workbench, useTimingInfo };
package/dist/index.js CHANGED
@@ -22,33 +22,5 @@ import { ToggleLoop } from "./gui/ToggleLoop.js";
22
22
  import { TogglePlay } from "./gui/TogglePlay.js";
23
23
  import { Workbench } from "./gui/Workbench.js";
24
24
  import { useTimingInfo } from "./hooks/useTimingInfo.js";
25
- export {
26
- Audio,
27
- Captions,
28
- CaptionsActiveWord,
29
- CaptionsAfterActiveWord,
30
- CaptionsBeforeActiveWord,
31
- CaptionsSegment,
32
- Configuration,
33
- Controls,
34
- Dial,
35
- Filmstrip,
36
- FitScale,
37
- FocusOverlay,
38
- Image,
39
- Pause,
40
- Play,
41
- Preview,
42
- ResizableBox,
43
- Scrubber,
44
- Surface,
45
- ThumbnailStrip,
46
- TimeDisplay,
47
- Timegroup,
48
- ToggleLoop,
49
- TogglePlay,
50
- Video,
51
- Waveform,
52
- Workbench,
53
- useTimingInfo
54
- };
25
+
26
+ export { Audio, Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment, Configuration, Controls, Dial, Filmstrip, FitScale, FocusOverlay, Image, Pause, Play, Preview, ResizableBox, Scrubber, Surface, ThumbnailStrip, TimeDisplay, Timegroup, ToggleLoop, TogglePlay, Video, Waveform, Workbench, useTimingInfo };
package/package.json CHANGED
@@ -1,32 +1,24 @@
1
1
  {
2
2
  "name": "@editframe/react",
3
- "version": "0.23.8-beta.0",
3
+ "version": "0.25.0-beta.0",
4
4
  "description": "",
5
5
  "exports": {
6
- ".": {
7
- "import": {
8
- "types": "./dist/index.d.ts",
9
- "default": "./dist/index.js"
10
- }
11
- },
12
- "./types.json": {
13
- "import": {
14
- "default": "./types.json"
15
- }
16
- }
6
+ ".": "./dist/index.js",
7
+ "./package.json": "./package.json"
17
8
  },
18
9
  "type": "module",
19
10
  "scripts": {
20
11
  "typecheck": "tsc --noEmit --emitDeclarationOnly false",
21
- "build": "vite build",
22
- "build:watch": "vite build --watch",
12
+ "build": "tsdown",
13
+ "build:watch": "tsdown --watch",
23
14
  "typedoc": "typedoc --json ./types.json --plugin typedoc-plugin-zod --excludeExternals ./src && jq -c . ./types.json > ./types.tmp.json && mv ./types.tmp.json ./types.json"
24
15
  },
25
16
  "author": "",
26
17
  "license": "UNLICENSED",
27
18
  "dependencies": {
28
- "@editframe/elements": "0.23.8-beta.0",
19
+ "@editframe/elements": "0.25.0-beta.0",
29
20
  "@lit/react": "^1.0.8",
21
+ "@lit/task": "^1.0.1",
30
22
  "debug": "^4.3.5",
31
23
  "lit": "^3.3.1",
32
24
  "react": "^18.3.0",
@@ -36,10 +28,10 @@
36
28
  "@types/node": "^22.0.0",
37
29
  "@types/react": "^18.3.0",
38
30
  "@types/react-dom": "^18.3.0",
39
- "rollup-plugin-tsconfig-paths": "^1.5.2",
40
31
  "typescript": "^5.5.4",
41
- "vite-plugin-dts": "^4.5.4",
42
- "vite-tsconfig-paths": "^4.3.2",
43
32
  "vitest": "^1.6.0"
44
- }
33
+ },
34
+ "main": "./dist/index.js",
35
+ "module": "./dist/index.js",
36
+ "types": "./dist/index.d.ts"
45
37
  }
@@ -0,0 +1,371 @@
1
+ import type { EFTimegroup } from "@editframe/elements";
2
+ import { type FC, useEffect } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { assert, beforeEach, describe, test } from "vitest";
5
+ import { Timegroup } from "../elements/Timegroup.js";
6
+ import { Video } from "../elements/Video.js";
7
+ import { Configuration } from "../gui/Configuration.js";
8
+ import { Preview } from "../gui/Preview.js";
9
+ import { useTimingInfo } from "./useTimingInfo.js";
10
+
11
+ beforeEach(() => {
12
+ while (document.body.children.length) {
13
+ document.body.children[0]?.remove();
14
+ }
15
+ });
16
+
17
+ interface TimingDisplayProps {
18
+ onUpdate?: (info: {
19
+ ownCurrentTimeMs: number;
20
+ durationMs: number;
21
+ percentComplete: number;
22
+ }) => void;
23
+ }
24
+
25
+ const TimingDisplay: FC<TimingDisplayProps> = ({ onUpdate }) => {
26
+ const { ownCurrentTimeMs, durationMs, percentComplete, ref } =
27
+ useTimingInfo();
28
+
29
+ useEffect(() => {
30
+ if (onUpdate) {
31
+ onUpdate({ ownCurrentTimeMs, durationMs, percentComplete });
32
+ }
33
+ }, [ownCurrentTimeMs, durationMs, percentComplete, onUpdate]);
34
+
35
+ return (
36
+ // biome-ignore lint/correctness/useUniqueElementIds: OK for test fixture with single instance
37
+ <Preview id="test-preview">
38
+ <Timegroup mode="fixed" duration="3s" ref={ref}>
39
+ <Video
40
+ src="https://editframe-dev-assets.s3.us-east-1.amazonaws.com/test-assets/test_audio.mp4"
41
+ trim="0s-1s"
42
+ />
43
+ </Timegroup>
44
+ </Preview>
45
+ );
46
+ };
47
+
48
+ describe("useTimingInfo", () => {
49
+ test("provides initial timing information", async () => {
50
+ const container = document.createElement("div");
51
+ document.body.appendChild(container);
52
+
53
+ let receivedInfo: {
54
+ ownCurrentTimeMs: number;
55
+ durationMs: number;
56
+ percentComplete: number;
57
+ } | null = null;
58
+
59
+ const root = createRoot(container);
60
+ root.render(
61
+ <Configuration>
62
+ <TimingDisplay
63
+ onUpdate={(info) => {
64
+ receivedInfo = info;
65
+ }}
66
+ />
67
+ </Configuration>,
68
+ );
69
+
70
+ // Wait for the component to mount and update
71
+ await new Promise((resolve) => setTimeout(resolve, 100));
72
+
73
+ const preview = container.querySelector("ef-preview");
74
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
75
+
76
+ assert.ok(timegroup, "Timegroup should be rendered");
77
+ await timegroup.updateComplete;
78
+ await timegroup.waitForMediaDurations();
79
+
80
+ // Wait for initial frame task
81
+ await timegroup.frameTask.run();
82
+
83
+ assert.ok(receivedInfo, "Should receive timing info");
84
+ assert.equal(receivedInfo?.ownCurrentTimeMs, 0);
85
+ assert.equal(receivedInfo?.durationMs, 3000);
86
+ assert.equal(receivedInfo?.percentComplete, 0);
87
+
88
+ root.unmount();
89
+ container.remove();
90
+ }, 5000);
91
+
92
+ test("updates only on frame task completion, not on every Lit update", async () => {
93
+ const container = document.createElement("div");
94
+ document.body.appendChild(container);
95
+
96
+ const updates: number[] = [];
97
+
98
+ const root = createRoot(container);
99
+ root.render(
100
+ <Configuration>
101
+ <TimingDisplay
102
+ onUpdate={(info) => {
103
+ updates.push(info.ownCurrentTimeMs);
104
+ }}
105
+ />
106
+ </Configuration>,
107
+ );
108
+
109
+ // Wait for initial mount
110
+ await new Promise((resolve) => setTimeout(resolve, 100));
111
+
112
+ const preview = container.querySelector("ef-preview");
113
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
114
+
115
+ assert.ok(timegroup, "Timegroup should be rendered");
116
+ await timegroup.updateComplete;
117
+ await timegroup.waitForMediaDurations();
118
+
119
+ // Clear initial updates
120
+ updates.length = 0;
121
+
122
+ // Trigger multiple Lit updates without frame task
123
+ // These should NOT trigger React updates
124
+ timegroup.requestUpdate("mode");
125
+ await timegroup.updateComplete;
126
+ timegroup.requestUpdate("mode");
127
+ await timegroup.updateComplete;
128
+ timegroup.requestUpdate("mode");
129
+ await timegroup.updateComplete;
130
+
131
+ // Should have no updates since no frame tasks ran
132
+ assert.equal(
133
+ updates.length,
134
+ 0,
135
+ "Should not update on Lit property changes",
136
+ );
137
+
138
+ // Now trigger frame task via seek (proper API that triggers both task and update)
139
+ await timegroup.seek(1000);
140
+ // Give React a chance to process the state update
141
+ await new Promise((resolve) => setTimeout(resolve, 50));
142
+
143
+ // Should have exactly one update from frame task
144
+ assert.ok(updates.length >= 1, "Should update once per frame task");
145
+
146
+ root.unmount();
147
+ container.remove();
148
+ }, 5000);
149
+
150
+ test("updates synchronously with frame tasks during seek", async () => {
151
+ const container = document.createElement("div");
152
+ document.body.appendChild(container);
153
+
154
+ const updates: number[] = [];
155
+
156
+ const root = createRoot(container);
157
+ root.render(
158
+ <Configuration>
159
+ <TimingDisplay
160
+ onUpdate={(info) => {
161
+ updates.push(info.ownCurrentTimeMs);
162
+ }}
163
+ />
164
+ </Configuration>,
165
+ );
166
+
167
+ await new Promise((resolve) => setTimeout(resolve, 100));
168
+
169
+ const preview = container.querySelector("ef-preview");
170
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
171
+
172
+ assert.ok(timegroup, "Timegroup should be rendered");
173
+ await timegroup.updateComplete;
174
+ await timegroup.waitForMediaDurations();
175
+
176
+ // Clear initial updates
177
+ updates.length = 0;
178
+
179
+ // Seek to different times
180
+ await timegroup.seek(1000);
181
+ await new Promise((resolve) => setTimeout(resolve, 50));
182
+ const updatesAfterFirstSeek = updates.length;
183
+ assert.ok(updatesAfterFirstSeek > 0, "Should update after first seek");
184
+
185
+ await timegroup.seek(2000);
186
+ await new Promise((resolve) => setTimeout(resolve, 50));
187
+ const updatesAfterSecondSeek = updates.length;
188
+ assert.ok(
189
+ updatesAfterSecondSeek > updatesAfterFirstSeek,
190
+ "Should update after second seek",
191
+ );
192
+
193
+ // Verify the last update has the correct time
194
+ const lastUpdate = updates[updates.length - 1];
195
+ assert.equal(lastUpdate, 2000, "Should reflect the seeked time");
196
+
197
+ root.unmount();
198
+ container.remove();
199
+ }, 5000);
200
+
201
+ test("updates at controlled rate with sequential frame updates", async () => {
202
+ const container = document.createElement("div");
203
+ document.body.appendChild(container);
204
+
205
+ const updateTimestamps: number[] = [];
206
+ const updateTimes: number[] = [];
207
+
208
+ const root = createRoot(container);
209
+ root.render(
210
+ <Configuration>
211
+ <TimingDisplay
212
+ onUpdate={(info) => {
213
+ updateTimestamps.push(performance.now());
214
+ updateTimes.push(info.ownCurrentTimeMs);
215
+ }}
216
+ />
217
+ </Configuration>,
218
+ );
219
+
220
+ await new Promise((resolve) => setTimeout(resolve, 100));
221
+
222
+ const preview = container.querySelector("ef-preview");
223
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
224
+
225
+ assert.ok(timegroup, "Timegroup should be rendered");
226
+ await timegroup.updateComplete;
227
+ await timegroup.waitForMediaDurations();
228
+
229
+ // Clear initial updates
230
+ updateTimestamps.length = 0;
231
+ updateTimes.length = 0;
232
+
233
+ // Simulate frame-by-frame updates at a controlled rate (30fps)
234
+ // Note: We use seek() rather than play() because AudioContext-based playback
235
+ // doesn't work in headless browsers due to autoplay policies that require user interaction
236
+ const FPS = 30;
237
+ const MS_PER_FRAME = 1000 / FPS;
238
+ const DURATION_MS = 500;
239
+ const numFrames = Math.floor(DURATION_MS / MS_PER_FRAME);
240
+
241
+ for (let i = 0; i < numFrames; i++) {
242
+ const targetTime = i * MS_PER_FRAME;
243
+ await timegroup.seek(targetTime);
244
+ await new Promise((resolve) => setTimeout(resolve, MS_PER_FRAME));
245
+ }
246
+
247
+ // Should have received multiple updates during simulated playback
248
+ assert.ok(
249
+ updateTimestamps.length >= 10,
250
+ `Should have at least 10 updates during simulated playback (got ${updateTimestamps.length})`,
251
+ );
252
+
253
+ // Calculate update intervals
254
+ const intervals: number[] = [];
255
+ for (let i = 1; i < updateTimestamps.length; i++) {
256
+ intervals.push(updateTimestamps[i] - updateTimestamps[i - 1]);
257
+ }
258
+
259
+ // Average interval should be around 33ms (30fps) matching our simulated rate
260
+ const avgInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
261
+
262
+ // Should be approximately 33ms per frame
263
+ // Allow generous variance for timing imprecision in CI
264
+ assert.ok(
265
+ avgInterval > 20 && avgInterval < 100,
266
+ `Update interval should be between 20-100ms (got ${avgInterval}ms), indicating controlled rate`,
267
+ );
268
+
269
+ root.unmount();
270
+ container.remove();
271
+ }, 5000);
272
+
273
+ test("continues observing after errors in frame task", async () => {
274
+ const container = document.createElement("div");
275
+ document.body.appendChild(container);
276
+
277
+ const updates: number[] = [];
278
+
279
+ const root = createRoot(container);
280
+ root.render(
281
+ <Configuration>
282
+ <TimingDisplay
283
+ onUpdate={(info) => {
284
+ updates.push(info.ownCurrentTimeMs);
285
+ }}
286
+ />
287
+ </Configuration>,
288
+ );
289
+
290
+ await new Promise((resolve) => setTimeout(resolve, 100));
291
+
292
+ const preview = container.querySelector("ef-preview");
293
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
294
+
295
+ assert.ok(timegroup, "Timegroup should be rendered");
296
+ await timegroup.updateComplete;
297
+ await timegroup.waitForMediaDurations();
298
+
299
+ updates.length = 0;
300
+
301
+ // First seek triggers frame task
302
+ await timegroup.seek(500);
303
+ await new Promise((resolve) => setTimeout(resolve, 50));
304
+ assert.ok(updates.length >= 1, "Should update after first seek");
305
+
306
+ // Even if there's an error or the task rejects, the observer should continue
307
+ // (The implementation catches errors and continues observing)
308
+ const updatesAfterFirst = updates.length;
309
+
310
+ // Second seek triggers another frame task
311
+ await timegroup.seek(1000);
312
+ await new Promise((resolve) => setTimeout(resolve, 50));
313
+ assert.ok(updates.length > updatesAfterFirst, "Should continue updating");
314
+
315
+ root.unmount();
316
+ container.remove();
317
+ }, 5000);
318
+
319
+ test("stops observing when component unmounts", async () => {
320
+ const container = document.createElement("div");
321
+ document.body.appendChild(container);
322
+
323
+ const updates: number[] = [];
324
+
325
+ const root = createRoot(container);
326
+ root.render(
327
+ <Configuration>
328
+ <TimingDisplay
329
+ onUpdate={(info) => {
330
+ updates.push(info.ownCurrentTimeMs);
331
+ }}
332
+ />
333
+ </Configuration>,
334
+ );
335
+
336
+ await new Promise((resolve) => setTimeout(resolve, 100));
337
+
338
+ const preview = container.querySelector("ef-preview");
339
+ const timegroup = preview?.querySelector("ef-timegroup") as EFTimegroup;
340
+
341
+ assert.ok(timegroup, "Timegroup should be rendered");
342
+ await timegroup.updateComplete;
343
+ await timegroup.waitForMediaDurations();
344
+
345
+ updates.length = 0;
346
+
347
+ // Seek before unmount (triggers frame task)
348
+ await timegroup.seek(500);
349
+ await new Promise((resolve) => setTimeout(resolve, 50));
350
+ assert.ok(updates.length >= 1, "Should update before unmount");
351
+
352
+ // Unmount the component
353
+ root.unmount();
354
+ await new Promise((resolve) => setTimeout(resolve, 50));
355
+
356
+ // Seek after unmount should not cause updates
357
+ const updatesBeforePost = updates.length;
358
+ await timegroup.seek(1000);
359
+
360
+ // Give time for any potential updates
361
+ await new Promise((resolve) => setTimeout(resolve, 50));
362
+
363
+ assert.equal(
364
+ updates.length,
365
+ updatesBeforePost,
366
+ "Should not update after unmount",
367
+ );
368
+
369
+ container.remove();
370
+ }, 5000);
371
+ });