@hyperframes/studio 0.6.27 → 0.6.28

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.
@@ -4,7 +4,6 @@ import {
4
4
  buildPromptCopyText,
5
5
  buildTimelineElementAgentPrompt,
6
6
  buildTimelineAgentPrompt,
7
- canOffsetTrimClipStart,
8
7
  getTimelineEditCapabilities,
9
8
  hasPatchableTimelineTarget,
10
9
  resolveBlockedTimelineEditIntent,
@@ -158,42 +157,6 @@ describe("resolveTimelineMove", () => {
158
157
  });
159
158
  });
160
159
 
161
- describe("canOffsetTrimClipStart", () => {
162
- it("allows front trim for clips that carry playback offset metadata", () => {
163
- expect(
164
- canOffsetTrimClipStart({
165
- tag: "div",
166
- playbackStartAttr: "media-start",
167
- }),
168
- ).toBe(true);
169
- });
170
-
171
- it("allows front trim for media clips with source duration metadata", () => {
172
- expect(
173
- canOffsetTrimClipStart({
174
- tag: "video",
175
- sourceDuration: 12,
176
- }),
177
- ).toBe(true);
178
- });
179
-
180
- it("allows front trim for plain audio clips even before media-start exists", () => {
181
- expect(
182
- canOffsetTrimClipStart({
183
- tag: "audio",
184
- }),
185
- ).toBe(true);
186
- });
187
-
188
- it("blocks front trim for generic motion clips", () => {
189
- expect(
190
- canOffsetTrimClipStart({
191
- tag: "section",
192
- }),
193
- ).toBe(false);
194
- });
195
- });
196
-
197
160
  describe("hasPatchableTimelineTarget", () => {
198
161
  it("returns true when the clip has a DOM id", () => {
199
162
  expect(hasPatchableTimelineTarget({ domId: "hero-card" })).toBe(true);
@@ -224,7 +187,7 @@ describe("getTimelineEditCapabilities", () => {
224
187
  });
225
188
  });
226
189
 
227
- it("allows moving generic motion clips while keeping trims blocked", () => {
190
+ it("allows full editing of generic motion clips with authored timing", () => {
228
191
  expect(
229
192
  getTimelineEditCapabilities({
230
193
  tag: "section",
@@ -233,8 +196,8 @@ describe("getTimelineEditCapabilities", () => {
233
196
  }),
234
197
  ).toEqual({
235
198
  canMove: true,
236
- canTrimStart: false,
237
- canTrimEnd: false,
199
+ canTrimStart: true,
200
+ canTrimEnd: true,
238
201
  });
239
202
  });
240
203
 
@@ -285,7 +248,7 @@ describe("getTimelineEditCapabilities", () => {
285
248
  });
286
249
  });
287
250
 
288
- it("allows move and end trim for patchable composition hosts", () => {
251
+ it("allows full editing for patchable composition hosts", () => {
289
252
  expect(
290
253
  getTimelineEditCapabilities({
291
254
  tag: "div",
@@ -295,7 +258,22 @@ describe("getTimelineEditCapabilities", () => {
295
258
  }),
296
259
  ).toEqual({
297
260
  canMove: true,
298
- canTrimStart: false,
261
+ canTrimStart: true,
262
+ canTrimEnd: true,
263
+ });
264
+ });
265
+
266
+ it("allows full editing of explicitly authored generic elements", () => {
267
+ expect(
268
+ getTimelineEditCapabilities({
269
+ tag: "div",
270
+ duration: 4,
271
+ selector: "#hero-card",
272
+ timingSource: "authored",
273
+ }),
274
+ ).toEqual({
275
+ canMove: true,
276
+ canTrimStart: true,
299
277
  canTrimEnd: true,
300
278
  });
301
279
  });
@@ -576,6 +554,40 @@ describe("resolveTimelineResize", () => {
576
554
  ),
577
555
  ).toEqual({ start: 0.8, duration: 3.2, playbackStart: 0 });
578
556
  });
557
+
558
+ it("trims generic element start without media offset", () => {
559
+ expect(
560
+ resolveTimelineResize(
561
+ {
562
+ start: 2,
563
+ duration: 4,
564
+ originClientX: 100,
565
+ pixelsPerSecond: 100,
566
+ minStart: 0,
567
+ maxEnd: 10,
568
+ },
569
+ "start",
570
+ 200,
571
+ ),
572
+ ).toEqual({ start: 3, duration: 3, playbackStart: undefined });
573
+ });
574
+
575
+ it("extends generic element start leftward to time zero", () => {
576
+ expect(
577
+ resolveTimelineResize(
578
+ {
579
+ start: 1,
580
+ duration: 3,
581
+ originClientX: 100,
582
+ pixelsPerSecond: 100,
583
+ minStart: 0,
584
+ maxEnd: 10,
585
+ },
586
+ "start",
587
+ -200,
588
+ ),
589
+ ).toEqual({ start: 0, duration: 4, playbackStart: undefined });
590
+ });
579
591
  });
580
592
 
581
593
  describe("buildPromptCopyText", () => {
@@ -201,18 +201,6 @@ export function hasPatchableTimelineTarget(input: { domId?: string; selector?: s
201
201
  return Boolean(input.domId || input.selector);
202
202
  }
203
203
 
204
- export function canOffsetTrimClipStart(input: {
205
- tag: string;
206
- playbackStart?: number;
207
- playbackStartAttr?: "media-start" | "playback-start";
208
- sourceDuration?: number;
209
- }): boolean {
210
- if (input.playbackStartAttr != null) return true;
211
- if (input.playbackStart != null) return true;
212
- const normalizedTag = input.tag.toLowerCase();
213
- return ["video", "audio"].includes(normalizedTag);
214
- }
215
-
216
204
  export function getTimelineEditCapabilities(input: {
217
205
  tag: string;
218
206
  duration: number;
@@ -237,8 +225,8 @@ export function getTimelineEditCapabilities(input: {
237
225
  const hasDeterministicWindow = isDeterministicTimelineWindow(input);
238
226
  return {
239
227
  canMove: canPatch && (hasDeterministicWindow || hasFiniteDuration),
240
- canTrimEnd: canPatch && hasFiniteDuration && hasDeterministicWindow,
241
- canTrimStart: canPatch && hasFiniteDuration && canOffsetTrimClipStart(input),
228
+ canTrimEnd: canPatch && hasFiniteDuration,
229
+ canTrimStart: canPatch && hasFiniteDuration,
242
230
  };
243
231
  }
244
232
 
@@ -7,7 +7,7 @@ import { useTimelineSyncCallbacks } from "./useTimelineSyncCallbacks";
7
7
  // Re-export public API consumed by tests and external modules.
8
8
  // All of these were previously defined in this file; they now live in focused
9
9
  // sub-modules but are re-exported here so existing import sites don't change.
10
- export type { PlaybackAdapter, ClipManifestClip } from "../lib/playbackTypes";
10
+ export type { ClipManifestClip } from "../lib/playbackTypes";
11
11
  export { createStaticSeekPlaybackAdapter } from "../lib/playbackAdapter";
12
12
  export {
13
13
  getTimelineElementSelector,
@@ -42,6 +42,7 @@ import {
42
42
  setPreviewPlaybackRate,
43
43
  shouldMutePreviewAudio,
44
44
  } from "../lib/timelineIframeHelpers";
45
+ import { probeMediaUrl, getCachedProbe } from "../lib/mediaProbe";
45
46
 
46
47
  // ---------------------------------------------------------------------------
47
48
  // Hook
@@ -106,6 +107,32 @@ export function useTimelinePlayer() {
106
107
  if (!state.timelineReady) {
107
108
  setTimelineReady(true);
108
109
  }
110
+
111
+ // Asynchronously enrich media elements missing sourceDuration via mediabunny.
112
+ // The probe reads file headers only — no full decode — so this is cheap.
113
+ const needsProbe = mergedElements.filter(
114
+ (el) =>
115
+ el.src &&
116
+ el.sourceDuration == null &&
117
+ ["video", "audio"].includes(el.tag.toLowerCase()) &&
118
+ !getCachedProbe(el.src),
119
+ );
120
+ if (needsProbe.length > 0) {
121
+ void Promise.allSettled(
122
+ needsProbe.map(async (el) => {
123
+ const result = await probeMediaUrl(el.src!);
124
+ if (!result) return;
125
+ const key = el.key ?? el.id;
126
+ usePlayerStore.setState((state) => {
127
+ const idx = state.elements.findIndex((e) => (e.key ?? e.id) === key);
128
+ if (idx === -1 || state.elements[idx].sourceDuration != null) return {};
129
+ const patched = state.elements.slice();
130
+ patched[idx] = { ...state.elements[idx], sourceDuration: result.duration };
131
+ return { elements: patched };
132
+ });
133
+ }),
134
+ );
135
+ }
109
136
  },
110
137
  [setElements, setTimelineReady, setDuration],
111
138
  );
@@ -0,0 +1,68 @@
1
+ import { Input, UrlSource, ALL_FORMATS } from "mediabunny";
2
+
3
+ export interface MediaProbeResult {
4
+ duration: number;
5
+ width?: number;
6
+ height?: number;
7
+ hasVideo: boolean;
8
+ hasAudio: boolean;
9
+ }
10
+
11
+ const cache = new Map<string, MediaProbeResult>();
12
+ const inflight = new Map<string, Promise<MediaProbeResult | null>>();
13
+
14
+ function normalizeUrl(url: string): string {
15
+ try {
16
+ return new URL(url, window.location.href).href;
17
+ } catch {
18
+ return url;
19
+ }
20
+ }
21
+
22
+ async function probeOne(url: string): Promise<MediaProbeResult | null> {
23
+ const input = new Input({
24
+ source: new UrlSource(url),
25
+ formats: ALL_FORMATS,
26
+ });
27
+ try {
28
+ const duration = await input.getDurationFromMetadata();
29
+ if (duration == null || !Number.isFinite(duration) || duration <= 0) return null;
30
+
31
+ const videoTrack = await input.getPrimaryVideoTrack();
32
+ const audioTracks = await input.getAudioTracks();
33
+
34
+ const result: MediaProbeResult = {
35
+ duration,
36
+ width: videoTrack?.displayWidth,
37
+ height: videoTrack?.displayHeight,
38
+ hasVideo: videoTrack != null,
39
+ hasAudio: audioTracks.length > 0,
40
+ };
41
+ return result;
42
+ } catch {
43
+ return null;
44
+ } finally {
45
+ input.dispose();
46
+ }
47
+ }
48
+
49
+ export function getCachedProbe(url: string): MediaProbeResult | undefined {
50
+ return cache.get(normalizeUrl(url));
51
+ }
52
+
53
+ export async function probeMediaUrl(url: string): Promise<MediaProbeResult | null> {
54
+ const key = normalizeUrl(url);
55
+ const cached = cache.get(key);
56
+ if (cached) return cached;
57
+
58
+ let pending = inflight.get(key);
59
+ if (pending) return pending;
60
+
61
+ pending = probeOne(key).then((result) => {
62
+ inflight.delete(key);
63
+ if (result) cache.set(key, result);
64
+ return result;
65
+ });
66
+ inflight.set(key, pending);
67
+ return pending;
68
+ }