@hyperframes/studio 0.9.58 → 0.9.59

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.
@@ -50,6 +50,7 @@ function described(n: number, extra: Partial<EditingElementDescription> = {}) {
50
50
  handle: h(n),
51
51
  parent: null,
52
52
  tag: "div",
53
+ label: "Text",
53
54
  id: null,
54
55
  selector: null,
55
56
  matchesBefore: null,
@@ -68,6 +69,8 @@ function described(n: number, extra: Partial<EditingElementDescription> = {}) {
68
69
  describe("readPreviewElement", () => {
69
70
  it("takes a description with the wire shape and refuses anything off it", () => {
70
71
  expect(readPreviewElement(described(1))).toEqual(described(1));
72
+ const { label: _label, ...fromAnOlderRuntime } = described(1);
73
+ expect(readPreviewElement(fromAnOlderRuntime)).toEqual(fromAnOlderRuntime);
71
74
  for (const bad of [
72
75
  null,
73
76
  [],
@@ -77,6 +80,7 @@ describe("readPreviewElement", () => {
77
80
  described(1, { handle: `${LOAD.toUpperCase()}:1` }),
78
81
  described(1, { parent: "x" }),
79
82
  described(1, { tag: 1 as never }),
83
+ described(1, { label: 1 as never }),
80
84
  described(1, { source: { file: 1 } as never }),
81
85
  described(1, { locked: "yes" as never }),
82
86
  described(1, { attributes: [["a"]] as never }),
@@ -70,6 +70,7 @@ function readHit(value: unknown): PreviewElementHit | null {
70
70
  export function readPreviewElement(value: unknown): PreviewElement | null {
71
71
  if (!readHit(value) || !isFields(value)) return null;
72
72
  if (value.parent !== null && !isHandle(value.parent)) return null;
73
+ if (value.label !== undefined && !isText(value.label)) return null;
73
74
  if (!isTextOrNull(value.id) || !isTextOrNull(value.selector)) return null;
74
75
  if (!isSource(value.source) || typeof value.locked !== "boolean") return null;
75
76
  if (!isTextRecord(value.inlineStyles) || !isText(value.text)) return null;
@@ -17,4 +17,5 @@ it("exports a sealed preview's checked element reads and stand-ins as the ones S
17
17
  );
18
18
  expect(studio.readable).toBe(selection.readable);
19
19
  expect(studio.standInFor).toBe(selection.standInFor);
20
+ expect(studio.standInHandle).toBe(selection.standInHandle);
20
21
  });
@@ -5,7 +5,9 @@ import {
5
5
  isAudioDomElement,
6
6
  isAudioTimelineElement,
7
7
  isMusicSourceElement,
8
+ fitsBeatAnalysis,
8
9
  isMusicTrack,
10
+ MAX_BEAT_SOURCE_SECONDS,
9
11
  resolveBeatSourceTrack,
10
12
  } from "./timelineInspector";
11
13
  import type { TimelineElement } from "../player";
@@ -15,12 +17,28 @@ function el(
15
17
  overrides: Partial<
16
18
  Pick<
17
19
  TimelineElement,
18
- "tag" | "src" | "id" | "domId" | "timelineRole" | "duration" | "hasAudio" | "muted"
20
+ | "tag"
21
+ | "src"
22
+ | "id"
23
+ | "domId"
24
+ | "timelineRole"
25
+ | "duration"
26
+ | "sourceDuration"
27
+ | "hasAudio"
28
+ | "muted"
19
29
  >
20
30
  >,
21
31
  ): Pick<
22
32
  TimelineElement,
23
- "tag" | "src" | "id" | "domId" | "timelineRole" | "duration" | "hasAudio" | "muted"
33
+ | "tag"
34
+ | "src"
35
+ | "id"
36
+ | "domId"
37
+ | "timelineRole"
38
+ | "duration"
39
+ | "sourceDuration"
40
+ | "hasAudio"
41
+ | "muted"
24
42
  > {
25
43
  return {
26
44
  tag: "audio",
@@ -29,6 +47,7 @@ function el(
29
47
  domId: "el-1",
30
48
  timelineRole: undefined,
31
49
  duration: 10,
50
+ sourceDuration: 120,
32
51
  ...overrides,
33
52
  };
34
53
  }
@@ -127,6 +146,22 @@ describe("resolveBeatSourceTrack", () => {
127
146
  expect(resolveBeatSourceTrack([sfx, vo])).toBeNull();
128
147
  });
129
148
 
149
+ it("falls back to a song over a longer clip whose file's length is not known yet", () => {
150
+ const unread = el({ id: "unread", domId: "unread", duration: 300, sourceDuration: undefined });
151
+ const song = el({ id: "song", domId: "song", duration: 180, sourceDuration: 180 });
152
+ expect(resolveBeatSourceTrack([unread, song])!.element).toBe(song);
153
+ const looped = el({ id: "loop", domId: "loop", duration: 1200, sourceDuration: 180 });
154
+ expect(resolveBeatSourceTrack([looped])!.element).toBe(looped);
155
+ });
156
+
157
+ it("never falls back to a clip, or a clip's file, longer than a song", () => {
158
+ const talk = el({ id: "talk", domId: "talk", duration: 3720, sourceDuration: 3720 });
159
+ const excerpt = el({ id: "cut", domId: "cut", duration: 180, sourceDuration: 3720 });
160
+ expect(resolveBeatSourceTrack([talk, excerpt])).toBeNull();
161
+ const song = el({ id: "song", domId: "song", duration: 200, sourceDuration: 200 });
162
+ expect(resolveBeatSourceTrack([talk, song])!.element).toBe(song);
163
+ });
164
+
130
165
  it("returns isFallback=true for an untagged clip with a non-music id", () => {
131
166
  const clip = el({ id: "my_audio_file", domId: "my_audio_file", timelineRole: undefined });
132
167
  const result = resolveBeatSourceTrack([clip]);
@@ -184,3 +219,15 @@ describe("beat source from a video with sound", () => {
184
219
  expect(resolveBeatSourceTrack([short, long, muted])?.element).toBe(long);
185
220
  });
186
221
  });
222
+
223
+ describe("fitsBeatAnalysis", () => {
224
+ it("fits a file whose length is known and no longer than a song, however long its clip runs", () => {
225
+ expect(fitsBeatAnalysis({ sourceDuration: 180 })).toBe(true);
226
+ expect(fitsBeatAnalysis({ sourceDuration: MAX_BEAT_SOURCE_SECONDS })).toBe(true);
227
+ });
228
+
229
+ it("refuses a file past the cap and a file whose length is unknown", () => {
230
+ expect(fitsBeatAnalysis({ sourceDuration: 3720 })).toBe(false);
231
+ expect(fitsBeatAnalysis({})).toBe(false);
232
+ });
233
+ });
@@ -80,6 +80,16 @@ export function isMusicTrack(
80
80
  return MUSIC_ID_RE.test(id);
81
81
  }
82
82
 
83
+ /** Past a song's length a track is speech or a mix, and beat analysis decodes its whole file (62 min: 1.4 GB). */
84
+ export const MAX_BEAT_SOURCE_SECONDS = 15 * 60;
85
+
86
+ /** The decode reads the whole file, so a source fits once its file's length is known and within the cap. */
87
+ export function fitsBeatAnalysis({
88
+ sourceDuration,
89
+ }: Pick<TimelineElement, "sourceDuration">): boolean {
90
+ return sourceDuration != null && sourceDuration <= MAX_BEAT_SOURCE_SECONDS;
91
+ }
92
+
83
93
  /**
84
94
  * Resolve the best audio source for beat analysis. An explicitly tagged or
85
95
  * named music track wins; when none is present (e.g. an audio file dropped
@@ -94,18 +104,27 @@ export function isMusicTrack(
94
104
  export function resolveBeatSourceTrack(
95
105
  elements: readonly Pick<
96
106
  TimelineElement,
97
- "tag" | "src" | "id" | "domId" | "timelineRole" | "duration" | "hasAudio" | "muted"
107
+ | "tag"
108
+ | "src"
109
+ | "id"
110
+ | "domId"
111
+ | "timelineRole"
112
+ | "duration"
113
+ | "sourceDuration"
114
+ | "hasAudio"
115
+ | "muted"
98
116
  >[],
99
117
  ): { element: (typeof elements)[number]; isFallback: boolean } | null {
100
118
  const explicit = elements.find(isMusicTrack);
101
119
  if (explicit) return { element: explicit, isFallback: false };
102
120
 
103
121
  // Fallback: pick the longest audio clip (skipping explicitly non-music roles
104
- // like "sfx" or "voiceover" to avoid triggering beat analysis on those).
122
+ // like "sfx" or "voiceover", and anything longer than a song, so none is beat-analysed).
105
123
  let best: (typeof elements)[number] | null = null;
106
124
  for (const el of elements) {
107
125
  if (!isMusicSourceElement(el)) continue;
108
126
  if (el.timelineRole && el.timelineRole !== "music") continue;
127
+ if (!fitsBeatAnalysis(el)) continue;
109
128
  if (!best || el.duration > best.duration) best = el;
110
129
  }
111
130
  return best ? { element: best, isFallback: true } : null;