@hyperframes/studio 0.9.9 → 0.9.10

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.
package/dist/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  document.documentElement.dataset.theme = "paper";
15
15
  }
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-DSRgrCDX.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-DR2eua-L.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/assets/index-RUPGNyct.css">
19
19
  </head>
20
20
  <body>
package/dist/index.js CHANGED
@@ -32580,18 +32580,21 @@ function applyCachedSourceDurations(elements, projectId) {
32580
32580
  });
32581
32581
  }
32582
32582
  async function probeMissingSourceDurations(elements, projectId, apply) {
32583
- const needs = elements.flatMap((el) => {
32583
+ const keysBySource = /* @__PURE__ */ new Map();
32584
+ for (const el of elements) {
32584
32585
  if (!el.src || el.sourceDuration != null || !["video", "audio"].includes(el.tag.toLowerCase())) {
32585
- return [];
32586
+ continue;
32586
32587
  }
32587
32588
  const source = resolveProbeSource(el.src, projectId);
32588
- return !getCachedProbe(source) && !hasFreshFailure(normalizeUrl(source)) ? [{ el, source }] : [];
32589
- });
32590
- if (needs.length === 0) return;
32589
+ if (getCachedProbe(source) || hasFreshFailure(normalizeUrl(source))) continue;
32590
+ const keys = keysBySource.get(source);
32591
+ if (keys) keys.push(el.key ?? el.id);
32592
+ else keysBySource.set(source, [el.key ?? el.id]);
32593
+ }
32591
32594
  await Promise.allSettled(
32592
- needs.map(async ({ el, source }) => {
32595
+ [...keysBySource].map(async ([source, keys]) => {
32593
32596
  const result = await probeMediaUrl(source);
32594
- if (result) apply(el.key ?? el.id, result.duration);
32597
+ if (result) apply(new Map(keys.map((key2) => [key2, result.duration])));
32595
32598
  })
32596
32599
  );
32597
32600
  }
@@ -32840,19 +32843,18 @@ function useTimelinePlayer({
32840
32843
  if (!state.timelineReady) {
32841
32844
  requestTimelineReady(safeContentDocument(iframeRef.current));
32842
32845
  }
32843
- void probeMissingSourceDurations(
32844
- mergedElements,
32845
- state.timelineProjectId,
32846
- (key2, durationSeconds) => {
32847
- usePlayerStore.setState((state2) => {
32848
- const idx = state2.elements.findIndex((e) => (e.key ?? e.id) === key2);
32849
- if (idx === -1 || state2.elements[idx].sourceDuration != null) return state2;
32850
- const patched = state2.elements.slice();
32851
- patched[idx] = { ...state2.elements[idx], sourceDuration: durationSeconds };
32852
- return { elements: patched };
32846
+ void probeMissingSourceDurations(mergedElements, state.timelineProjectId, (durations) => {
32847
+ usePlayerStore.setState((state2) => {
32848
+ let patched = null;
32849
+ state2.elements.forEach((element, idx) => {
32850
+ const durationSeconds = durations.get(element.key ?? element.id);
32851
+ if (durationSeconds === void 0 || element.sourceDuration != null) return;
32852
+ patched ??= state2.elements.slice();
32853
+ patched[idx] = { ...element, sourceDuration: durationSeconds };
32853
32854
  });
32854
- }
32855
- );
32855
+ return patched ? { elements: patched } : state2;
32856
+ });
32857
+ });
32856
32858
  },
32857
32859
  [setElements, requestTimelineReady, setDuration]
32858
32860
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,12 +60,12 @@
60
60
  "dockview-react": "8.3.1",
61
61
  "gsap": "^3.13.0",
62
62
  "mediabunny": "^1.45.3",
63
- "@hyperframes/core": "0.9.9",
64
- "@hyperframes/player": "0.9.9",
65
- "@hyperframes/sdk": "0.9.9",
66
- "@hyperframes/parsers": "0.9.9",
67
- "@hyperframes/studio-server": "0.9.9",
68
- "@hyperframes/shader-transitions": "0.9.9"
63
+ "@hyperframes/core": "0.9.10",
64
+ "@hyperframes/parsers": "0.9.10",
65
+ "@hyperframes/player": "0.9.10",
66
+ "@hyperframes/shader-transitions": "0.9.10",
67
+ "@hyperframes/studio-server": "0.9.10",
68
+ "@hyperframes/sdk": "0.9.10"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@tailwindcss/vite": "^4.3.3",
@@ -82,7 +82,7 @@
82
82
  "vite": "^6.4.2",
83
83
  "vitest": "^4.1.11",
84
84
  "zustand": "^5.0.0",
85
- "@hyperframes/producer": "0.9.9"
85
+ "@hyperframes/producer": "0.9.10"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "react": "19",
@@ -134,7 +134,7 @@ it("publishes resolved metadata only for clips that still need it", async () =>
134
134
  expect(getMediaProbeDiagnostics()).toEqual({ cached: 30, failed: 0, inflight: 0 });
135
135
  expect(elements.slice(0, 20).every((element) => element.sourceDuration === 99)).toBe(true);
136
136
  expect(elements.slice(20).every((element) => element.sourceDuration === 12)).toBe(true);
137
- expect(changed).toBe(560);
137
+ expect(changed).toBe(30); // one write per file
138
138
  expect(unchanged).toBe(0);
139
139
  expect(other).toBe(0);
140
140
  } finally {
@@ -127,19 +127,18 @@ export function useTimelinePlayer({
127
127
 
128
128
  // Asynchronously enrich media elements still missing sourceDuration
129
129
  // (header-only probe, cheap), applying each resolved value to the store.
130
- void probeMissingSourceDurations(
131
- mergedElements,
132
- state.timelineProjectId,
133
- (key, durationSeconds) => {
134
- usePlayerStore.setState((state) => {
135
- const idx = state.elements.findIndex((e) => (e.key ?? e.id) === key);
136
- if (idx === -1 || state.elements[idx].sourceDuration != null) return state;
137
- const patched = state.elements.slice();
138
- patched[idx] = { ...state.elements[idx], sourceDuration: durationSeconds };
139
- return { elements: patched };
130
+ void probeMissingSourceDurations(mergedElements, state.timelineProjectId, (durations) => {
131
+ usePlayerStore.setState((state) => {
132
+ let patched: TimelineElement[] | null = null;
133
+ state.elements.forEach((element, idx) => {
134
+ const durationSeconds = durations.get(element.key ?? element.id);
135
+ if (durationSeconds === undefined || element.sourceDuration != null) return;
136
+ patched ??= state.elements.slice();
137
+ patched[idx] = { ...element, sourceDuration: durationSeconds };
140
138
  });
141
- },
142
- );
139
+ return patched ? { elements: patched } : state;
140
+ });
141
+ });
143
142
  },
144
143
  [setElements, requestTimelineReady, setDuration],
145
144
  );
@@ -109,6 +109,31 @@ describe("media probe registry", () => {
109
109
  expect(getDurationFromMetadata).toHaveBeenCalledTimes(2);
110
110
  });
111
111
 
112
+ it("hands back every clip of one file in a single apply, so the store is written once per file", async () => {
113
+ const apply = vi.fn();
114
+ await probeMissingSourceDurations(
115
+ [
116
+ { id: "a1", tag: "audio", src: "assets/voice.wav" },
117
+ { id: "a2", tag: "audio", src: "assets/voice.wav" },
118
+ { id: "a3", tag: "audio", src: "assets/voice.wav" },
119
+ { id: "v1", tag: "video", src: "assets/clip.mp4" },
120
+ ],
121
+ "project-a",
122
+ apply,
123
+ );
124
+
125
+ expect(requestedSources).toHaveLength(2);
126
+ expect(apply).toHaveBeenCalledTimes(2);
127
+ expect(apply).toHaveBeenCalledWith(
128
+ new Map([
129
+ ["a1", 5],
130
+ ["a2", 5],
131
+ ["a3", 5],
132
+ ]),
133
+ );
134
+ expect(apply).toHaveBeenCalledWith(new Map([["v1", 5]]));
135
+ });
136
+
112
137
  it("probes a dropped clip's URL-spelled src at its own file", async () => {
113
138
  await probeMissingSourceDurations(
114
139
  [{ id: "clip", tag: "video", src: "assets/My%20clip%20%231.mp4" }],
@@ -138,7 +163,7 @@ describe("media probe registry", () => {
138
163
  expect(requestedSources).toEqual([
139
164
  `${window.location.origin}/api/projects/project-a/preview/assets/clip.mp4`,
140
165
  ]);
141
- expect(apply).toHaveBeenCalledWith("clip", 5);
166
+ expect(apply).toHaveBeenCalledWith(new Map([["clip", 5]]));
142
167
  expect(
143
168
  applyCachedSourceDurations(
144
169
  [
@@ -128,34 +128,35 @@ export function applyCachedSourceDurations<
128
128
 
129
129
  /**
130
130
  * Probe (header-only, cheap) any media elements still missing sourceDuration
131
- * after the cache pass, applying each resolved duration via `apply(key, secs)`.
132
- * Skips already-cached srcs.
131
+ * after the cache pass. Each file is probed once and all its clips' durations go to one
132
+ * `apply(durations)`, so a file cut into many clips writes the store once. Skips already-cached srcs.
133
133
  */
134
134
  export async function probeMissingSourceDurations<
135
135
  T extends { src?: string; tag: string; sourceDuration?: number; key?: string; id: string },
136
136
  >(
137
137
  elements: T[],
138
138
  projectId: string | null,
139
- apply: (key: string, durationSeconds: number) => void,
139
+ apply: (durations: ReadonlyMap<string, number>) => void,
140
140
  ): Promise<void> {
141
- const needs = elements.flatMap((el) => {
141
+ const keysBySource = new Map<string, string[]>();
142
+ for (const el of elements) {
142
143
  if (
143
144
  !el.src ||
144
145
  el.sourceDuration != null ||
145
146
  !["video", "audio"].includes(el.tag.toLowerCase())
146
147
  ) {
147
- return [];
148
+ continue;
148
149
  }
149
150
  const source = resolveProbeSource(el.src, projectId);
150
- return !getCachedProbe(source) && !hasFreshFailure(normalizeUrl(source))
151
- ? [{ el, source }]
152
- : [];
153
- });
154
- if (needs.length === 0) return;
151
+ if (getCachedProbe(source) || hasFreshFailure(normalizeUrl(source))) continue;
152
+ const keys = keysBySource.get(source);
153
+ if (keys) keys.push(el.key ?? el.id);
154
+ else keysBySource.set(source, [el.key ?? el.id]);
155
+ }
155
156
  await Promise.allSettled(
156
- needs.map(async ({ el, source }) => {
157
+ [...keysBySource].map(async ([source, keys]) => {
157
158
  const result = await probeMediaUrl(source);
158
- if (result) apply(el.key ?? el.id, result.duration);
159
+ if (result) apply(new Map(keys.map((key) => [key, result.duration])));
159
160
  }),
160
161
  );
161
162
  }