@hyperframes/studio 0.9.43 → 0.9.45

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 (37) hide show
  1. package/dist/assets/{codec-DHChmhF2.js → codec-DQ7n-U_9.js} +1 -1
  2. package/dist/assets/{hyperframes-player-CdbweVDs.js → hyperframes-player-C7JtYIRD.js} +1 -1
  3. package/dist/assets/{index-CjWDrWWG.js → index-C7EGuz1n.js} +120 -120
  4. package/dist/assets/{index-l-ti2dV8.js → index-CByWY7fK.js} +1 -1
  5. package/dist/assets/{index-4VGEAZyf.css → index-CU24FmKd.css} +1 -1
  6. package/dist/assets/{pausedVideoDecoder-xqOQ0ciK.js → pausedVideoDecoder-Bnvo9NIs.js} +1 -1
  7. package/dist/{chunk-4QQMX4BX.js → chunk-67DSVBEI.js} +1 -1
  8. package/dist/{chunk-52AJB4PN.js → chunk-ZNUWV4FN.js} +1 -1
  9. package/dist/index.html +2 -2
  10. package/dist/index.js +653 -627
  11. package/dist/player.js +2 -2
  12. package/dist/styles.css +1 -1
  13. package/dist/ui.js +1 -1
  14. package/package.json +8 -8
  15. package/src/components/StudioOverlays.tsx +15 -13
  16. package/src/components/StudioToast.test.tsx +41 -0
  17. package/src/components/StudioToast.tsx +23 -39
  18. package/src/components/feedback/StudioFeedbackCard.tsx +5 -2
  19. package/src/components/ui/Menu.test.tsx +30 -1
  20. package/src/components/ui/Menu.tsx +1 -1
  21. package/src/hooks/timelineEditingHelpers.test.ts +48 -0
  22. package/src/hooks/timelineEditingHelpers.ts +2 -0
  23. package/src/hooks/timelineElementsAttribute.test.ts +46 -0
  24. package/src/hooks/timelineElementsAttribute.ts +14 -16
  25. package/src/hooks/timelineTrackVisibility.test.ts +34 -0
  26. package/src/hooks/useElementPicker.test.ts +9 -2
  27. package/src/hooks/useElementPicker.ts +4 -2
  28. package/src/hooks/useToast.ts +6 -18
  29. package/src/player/lib/thumbnailFrameSink.test.ts +92 -0
  30. package/src/player/lib/thumbnailFrameSink.ts +83 -0
  31. package/src/player/lib/thumbnailVideoDecoder.test.ts +43 -16
  32. package/src/player/lib/thumbnailVideoDecoder.ts +6 -6
  33. package/src/styles/components.css +19 -1
  34. package/src/styles/theme.css +3 -0
  35. package/src/utils/previewSafeMargins.ts +6 -10
  36. package/src/utils/sourcePatcher.test.ts +21 -0
  37. package/src/utils/sourcePatcher.ts +16 -8
package/dist/ui.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  fieldBase,
31
31
  fieldText,
32
32
  popupSurface
33
- } from "./chunk-52AJB4PN.js";
33
+ } from "./chunk-ZNUWV4FN.js";
34
34
  import "./chunk-MLKGABMK.js";
35
35
  export {
36
36
  Button,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.43",
3
+ "version": "0.9.45",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,12 +64,12 @@
64
64
  "dockview-react": "8.3.1",
65
65
  "gsap": "^3.13.0",
66
66
  "mediabunny": "^1.65.2",
67
- "@hyperframes/core": "0.9.43",
68
- "@hyperframes/parsers": "0.9.43",
69
- "@hyperframes/player": "0.9.43",
70
- "@hyperframes/shader-transitions": "0.9.43",
71
- "@hyperframes/sdk": "0.9.43",
72
- "@hyperframes/studio-server": "0.9.43"
67
+ "@hyperframes/core": "0.9.45",
68
+ "@hyperframes/sdk": "0.9.45",
69
+ "@hyperframes/shader-transitions": "0.9.45",
70
+ "@hyperframes/player": "0.9.45",
71
+ "@hyperframes/studio-server": "0.9.45",
72
+ "@hyperframes/parsers": "0.9.45"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@tailwindcss/vite": "^4.3.3",
@@ -86,7 +86,7 @@
86
86
  "vite": "^6.4.5",
87
87
  "vitest": "^4.1.12",
88
88
  "zustand": "^5.0.0",
89
- "@hyperframes/producer": "0.9.43"
89
+ "@hyperframes/producer": "0.9.45"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "react": "19",
@@ -75,19 +75,21 @@ export const StudioOverlays = memo(function StudioOverlays({
75
75
  }}
76
76
  />
77
77
  )}
78
- {/* One bottom-right stack so the feedback card and toasts queue instead
79
- of covering each other. Empty when nothing is showing. */}
80
- <div className="absolute bottom-6 right-6 z-91 flex flex-col items-end gap-2">
81
- {toasts.map((toast) => (
82
- <StudioToast
83
- key={toast.id}
84
- message={toast.message}
85
- tone={toast.tone}
86
- leaving={toast.leaving}
87
- onDismiss={() => dismissToast(toast.id)}
88
- />
89
- ))}
90
- <StudioFeedbackCard />
78
+ {/* Toasts centre in the room the feedback card leaves, so the two never cover each other. */}
79
+ <div className="pointer-events-none absolute inset-x-6 bottom-6 z-91 flex items-end gap-2">
80
+ <div className="flex min-w-0 flex-1 flex-col items-center gap-2 *:pointer-events-auto">
81
+ {toasts.map((toast) => (
82
+ <StudioToast
83
+ key={toast.id}
84
+ message={toast.message}
85
+ tone={toast.tone}
86
+ onDismiss={() => dismissToast(toast.id)}
87
+ />
88
+ ))}
89
+ </div>
90
+ <div className="pointer-events-auto">
91
+ <StudioFeedbackCard />
92
+ </div>
91
93
  </div>
92
94
  </>
93
95
  );
@@ -0,0 +1,41 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import React, { act } from "react";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { mountReactHarness } from "../hooks/domSelectionTestHarness";
6
+ import { StudioToast } from "./StudioToast";
7
+
8
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
9
+
10
+ afterEach(() => {
11
+ document.body.innerHTML = "";
12
+ });
13
+
14
+ function mount(tone: "error" | "info") {
15
+ const dismissed: string[] = [];
16
+ mountReactHarness(
17
+ <StudioToast message="Saved" tone={tone} onDismiss={() => dismissed.push(tone)} />,
18
+ );
19
+ return dismissed;
20
+ }
21
+
22
+ describe("StudioToast", () => {
23
+ it("dismisses an info toast on a click anywhere on it, with no Dismiss button", () => {
24
+ const dismissed = mount("info");
25
+ expect(document.querySelector("button")).toBeNull();
26
+ act(() => document.querySelector<HTMLElement>("[role=status]")?.click());
27
+ expect(dismissed).toEqual(["info"]);
28
+ });
29
+
30
+ it("keeps an error toast up on a click on it, so its text can be selected and copied", () => {
31
+ const dismissed = mount("error");
32
+ act(() => document.querySelector<HTMLElement>("[role=alert]")?.click());
33
+ expect(dismissed).toEqual([]);
34
+ });
35
+
36
+ it("gives a persisting error toast a Dismiss button that dismisses it once", () => {
37
+ const dismissed = mount("error");
38
+ act(() => document.querySelector<HTMLElement>("[aria-label=Dismiss]")?.click());
39
+ expect(dismissed).toEqual(["error"]);
40
+ });
41
+ });
@@ -1,50 +1,34 @@
1
+ import { X } from "../icons/SystemIcons";
2
+ import { toastPersists } from "../hooks/useToast";
3
+
1
4
  interface StudioToastProps {
2
5
  message: string;
3
- tone?: "error" | "info";
4
- /** Plays the exit animation when true (owner removes the node after ~160ms). */
5
- leaving?: boolean;
6
- onDismiss?: () => void;
6
+ tone: "error" | "info";
7
+ onDismiss: () => void;
7
8
  }
8
9
 
9
- export function StudioToast({ message, tone, leaving, onDismiss }: StudioToastProps) {
10
- const isError = tone === "error";
10
+ export function StudioToast({ message, tone, onDismiss }: StudioToastProps) {
11
+ const persists = toastPersists(tone);
11
12
  return (
12
13
  <div
13
- role={isError ? "alert" : "status"}
14
- className={`motion-reduce:animate-none ${leaving ? "hf-toast-exit" : "hf-toast-enter"}`}
14
+ role={tone === "error" ? "alert" : "status"}
15
+ onClick={persists ? undefined : onDismiss}
16
+ onKeyDown={(event) => {
17
+ if (event.key === "Escape") onDismiss();
18
+ }}
19
+ className={`hf-notice-in flex min-h-12 w-fit max-w-[min(680px,100%)] items-center gap-1.5 rounded-3xl bg-text-0 py-1.5 pr-1.5 pl-5 text-[14px] leading-5 font-medium wrap-anywhere text-bg-0 shadow-notice not-has-[button]:pr-5 ${persists ? "" : "cursor-pointer"}`}
15
20
  >
16
- <div
17
- className={`relative flex max-w-[min(420px,calc(100vw-48px))] items-center gap-3 overflow-hidden rounded-2xl py-3 pl-4 pr-2 text-[12px] ${toastSurface(isError)}`}
18
- >
19
- <span
20
- className={`min-w-0 wrap-break-word leading-5 ${isError ? "text-danger-ink" : "text-text-0"}`}
21
+ <span className="min-w-0 flex-1 text-pretty">{message}</span>
22
+ {persists && (
23
+ <button
24
+ type="button"
25
+ onClick={onDismiss}
26
+ className="relative ml-2 grid h-9 w-9 shrink-0 place-items-center rounded-full text-bg-0/72 transition-[background-color,color,scale] duration-hover ease-out hover:bg-bg-0/16 hover:text-bg-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-bg-0 active:scale-[0.96]"
27
+ aria-label="Dismiss"
21
28
  >
22
- {message}
23
- </span>
24
- {onDismiss && (
25
- <button
26
- type="button"
27
- onClick={onDismiss}
28
- className="flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-neutral-500 transition-colors hover:bg-hover hover:text-neutral-300"
29
- aria-label="Dismiss"
30
- >
31
- <svg
32
- width="10"
33
- height="10"
34
- viewBox="0 0 10 10"
35
- fill="none"
36
- stroke="currentColor"
37
- strokeWidth="1.5"
38
- >
39
- <path d="M2 2l6 6M8 2l-6 6" />
40
- </svg>
41
- </button>
42
- )}
43
- </div>
29
+ <X size={14} />
30
+ </button>
31
+ )}
44
32
  </div>
45
33
  );
46
34
  }
47
-
48
- export function toastSurface(isError: boolean): string {
49
- return `border shadow-popover bg-raised ${isError ? "border-danger/40" : "border-border"}`;
50
- }
@@ -1,5 +1,4 @@
1
1
  import { memo, useState, useCallback, useRef, useEffect } from "react";
2
- import { toastSurface } from "../StudioToast";
3
2
  import {
4
3
  trackStudioFeedback,
5
4
  trackStudioFeedbackShown,
@@ -213,7 +212,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() {
213
212
  }}
214
213
  >
215
214
  <div
216
- className={`flex w-[min(340px,calc(100vw-48px))] flex-col gap-2.5 overflow-hidden rounded-2xl px-3.5 py-3 ${toastSurface(failed)}`}
215
+ className={`flex w-[min(340px,calc(100vw-48px))] flex-col gap-2.5 overflow-hidden rounded-2xl px-3.5 py-3 ${cardSurface(failed)}`}
217
216
  >
218
217
  <div className="flex items-start gap-3">
219
218
  <p
@@ -359,3 +358,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() {
359
358
  </div>
360
359
  );
361
360
  });
361
+
362
+ function cardSurface(isError: boolean): string {
363
+ return `border shadow-popover bg-raised ${isError ? "border-danger/40" : "border-border"}`;
364
+ }
@@ -6,7 +6,15 @@ import React, { act, useState } from "react";
6
6
  import { compile } from "tailwindcss";
7
7
  import { afterEach, beforeAll, describe, expect, it } from "vitest";
8
8
  import { loadStylesheet, STYLES_DIR } from "../../styles/styleSources";
9
- import { ContextMenu, Menu, MenuItem, MenuRadioGroup, MenuRadioItem, MenuSeparator } from "./Menu";
9
+ import {
10
+ ContextMenu,
11
+ floatingMotion,
12
+ Menu,
13
+ MenuItem,
14
+ MenuRadioGroup,
15
+ MenuRadioItem,
16
+ MenuSeparator,
17
+ } from "./Menu";
10
18
  import { Popover } from "./Popover";
11
19
  import { isTypingTarget } from "../../utils/typingTarget";
12
20
  import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
@@ -443,3 +451,24 @@ describe("open motion", () => {
443
451
  expect(compileStudioCss([rowRadius])).toMatch(/calc\(var\(--radius-lg\) \+ 6px\)/);
444
452
  });
445
453
  });
454
+
455
+ describe("floatingMotion", () => {
456
+ it("transitions every property its starting and ending styles set", () => {
457
+ const classes = floatingMotion("duration-open").split(/\s+/);
458
+ const transitioned = classes.flatMap(
459
+ (c) => c.match(/^transition-\[(.+)\]$/)?.[1].split(",") ?? [],
460
+ );
461
+ const animated = classes
462
+ .flatMap(
463
+ (c) =>
464
+ c
465
+ .match(
466
+ /^data-\[(?:starting|ending)-style\]:(?:\[([\w-]+):|(opacity|scale|translate|rotate)-)/,
467
+ )
468
+ ?.slice(1) ?? [],
469
+ )
470
+ .filter(Boolean);
471
+ expect(new Set(animated)).toEqual(new Set(["opacity", "scale"]));
472
+ for (const property of animated) expect(transitioned).toContain(property);
473
+ });
474
+ });
@@ -47,7 +47,7 @@ const VIEWPORT_MARGIN = 8;
47
47
  export function floatingMotion(openDuration: "duration-open" | "duration-tooltip") {
48
48
  return cn(
49
49
  "origin-[var(--transform-origin)] outline-hidden",
50
- "transition-[opacity,transform] ease-out-quint",
50
+ "transition-[opacity,scale] ease-out-quint",
51
51
  openDuration,
52
52
  "data-[ending-style]:duration-close data-[ending-style]:ease-in",
53
53
  "data-[starting-style]:[opacity:var(--popup-enter-opacity)]",
@@ -11,8 +11,11 @@ import {
11
11
  persistElementAttribute,
12
12
  persistTimelineBatchEdit,
13
13
  persistTimelineEdit,
14
+ readTargetAttribute,
14
15
  type PersistTimelineBatchChange,
15
16
  } from "./timelineEditingHelpers";
17
+ import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
18
+ import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
16
19
  import type { TimelineElement } from "../player/store/playerStore";
17
20
  import { readMediaOffsetSeconds } from "@hyperframes/parsers/media-duration";
18
21
  import { usePlayerStore } from "../player/store/playerStore";
@@ -684,6 +687,51 @@ describe("persistElementAttribute", () => {
684
687
  });
685
688
  });
686
689
 
690
+ describe("a clip whose file has no ids yet", () => {
691
+ // Added outside Studio: no id, no class, and nothing has stamped the file since. The preview mints its hf-id.
692
+ const ON_DISK = `<div data-composition-id="main" data-start="0" data-duration="10"><img src="a.png" data-start="1" data-duration="3" data-volume="0.5"></div>`;
693
+ const served = () => {
694
+ const doc = document.implementation.createHTMLDocument("");
695
+ doc.body.innerHTML = ensureHfIds(ON_DISK);
696
+ const [clip] = parseTimelineFromDOM(doc, 10);
697
+ if (!clip?.hfId) throw new Error("expected the served clip to carry an hf-id");
698
+ return { hfId: clip.hfId };
699
+ };
700
+
701
+ afterEach(() => {
702
+ vi.unstubAllGlobals();
703
+ });
704
+
705
+ it("saves an attribute on it by the id the preview served it with", async () => {
706
+ vi.stubGlobal(
707
+ "fetch",
708
+ vi.fn(async () => new Response(JSON.stringify({ content: ON_DISK }))),
709
+ );
710
+ const target = served();
711
+ const writes: string[] = [];
712
+
713
+ await persistElementAttribute({
714
+ projectId: "p",
715
+ targetPath: "index.html",
716
+ patchTarget: target,
717
+ attr: "data-volume",
718
+ value: "0.9",
719
+ label: "Set volume",
720
+ writeProjectFile: async (_path, content) => void writes.push(content),
721
+ recordEdit: vi.fn(async () => {}),
722
+ pendingTimelineEditPathRef: { current: new Set() },
723
+ onFileRead: vi.fn(),
724
+ patchLive: vi.fn(),
725
+ });
726
+
727
+ expect(readTargetAttribute(writes[0] ?? "", target, "data-volume")).toBe("0.9");
728
+ });
729
+
730
+ it("reads its attribute by that id", () => {
731
+ expect(readTargetAttribute(ON_DISK, served(), "data-volume")).toBe("0.5");
732
+ });
733
+ });
734
+
687
735
  describe("persistElementAttribute — unwind value", () => {
688
736
  /**
689
737
  * The unwind has to restore the value on DISK, not the one in the preview.
@@ -7,6 +7,7 @@ import {
7
7
  findTagByTarget,
8
8
  readAttributeByTarget,
9
9
  readTagSnippetByTarget,
10
+ servedSource,
10
11
  type PatchOperation,
11
12
  } from "../utils/sourcePatcher";
12
13
  import {
@@ -420,6 +421,7 @@ export function patchTimelineChangesInSource(
420
421
  for (const { element, buildPatches } of changes) {
421
422
  const target = buildPatchTarget(element);
422
423
  if (!target) throw new Error(`Timeline element ${element.id} is missing a patchable target`);
424
+ current = servedSource(current, target);
423
425
  // Resolve first: a member already at its target values patches to the same string, a missing one must throw.
424
426
  if (!findTagByTarget(current, target)) {
425
427
  throw new Error(
@@ -5,6 +5,8 @@ import { describe, expect, it, vi } from "vitest";
5
5
 
6
6
  Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });
7
7
  import type { TimelineElement } from "../player";
8
+ import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
9
+ import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
8
10
 
9
11
  const saved = vi.hoisted(() => ({ inputs: [] as Array<Record<string, unknown>> }));
10
12
  vi.mock("../utils/studioFileHistory", () => ({
@@ -68,6 +70,50 @@ describe("useSetElementsAttribute", () => {
68
70
  expect(out).toMatch(/id="b"[^>]*data-volume="2"/);
69
71
  });
70
72
 
73
+ it("saves clips whose file has no ids yet by the ids the preview served them with, and refuses a clip the file lacks", async () => {
74
+ saved.inputs.length = 0;
75
+ // Added outside Studio: no id, no class, and nothing has stamped the file since.
76
+ const onDisk = `<div data-composition-id="main" data-start="0" data-duration="10"><audio src="a.mp3" data-start="0" data-duration="4" data-track-index="0"></audio><audio src="b.mp3" data-start="4" data-duration="4" data-track-index="1"></audio></div>`;
77
+ const doc = document.implementation.createHTMLDocument("");
78
+ doc.body.innerHTML = ensureHfIds(onDisk);
79
+ const served = parseTimelineFromDOM(doc, 10);
80
+ expect(served.map((element) => element.hfId).every(Boolean)).toBe(true);
81
+ let write: ReturnType<typeof useSetElementsAttribute> | null = null;
82
+ function Probe() {
83
+ write = useSetElementsAttribute({
84
+ projectIdRef: { current: "p1" },
85
+ activeCompPath: "index.html",
86
+ showToast: vi.fn(),
87
+ writeProjectFile: vi.fn(async () => {}),
88
+ recordEdit: vi.fn(async () => {}),
89
+ previewIframeRef: { current: null },
90
+ pendingTimelineEditPathRef: { current: new Set<string>() },
91
+ });
92
+ return null;
93
+ }
94
+ const root = createRoot(document.createElement("div"));
95
+ act(() => root.render(createElement(Probe)));
96
+ await write?.(
97
+ served.map((element) => ({ element, value: "0.3" })),
98
+ "data-volume",
99
+ "Audio Gain",
100
+ );
101
+ await write?.(
102
+ [{ element: { ...served[0]!, hfId: "hf-gone" }, value: "0.3" }],
103
+ "data-volume",
104
+ "Audio Gain",
105
+ );
106
+ act(() => root.unmount());
107
+ const build = (n: number) => {
108
+ const files = saved.inputs[n]?.["files"];
109
+ const fn = typeof files === "object" && files !== null && Reflect.get(files, "index.html");
110
+ if (typeof fn !== "function") throw new Error("no builder for index.html");
111
+ return (html: string) => String(fn(html));
112
+ };
113
+ expect(build(0)(onDisk).match(/data-volume="0\.3"/g)).toHaveLength(2);
114
+ expect(() => build(1)(onDisk)).toThrow("Unable to patch timeline element");
115
+ });
116
+
71
117
  it("refuses while recording, like the single-clip write", async () => {
72
118
  saved.inputs.length = 0;
73
119
  const showToast = vi.fn();
@@ -4,9 +4,10 @@ import { syncStoredElementAttribute } from "../player/lib/automationStoreSync";
4
4
  import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
5
5
  import { applyPatchByTarget } from "../utils/sourcePatcher";
6
6
  import {
7
- buildPatchTarget,
8
7
  findTimelineElementInIframe,
8
+ patchTimelineChangesInSource,
9
9
  readFileContent,
10
+ type PersistTimelineBatchChange,
10
11
  } from "./timelineEditingHelpers";
11
12
  import type { UseTimelineElementVisibilityEditingInput } from "./timelineTrackVisibility";
12
13
  import { projectForTimelineSave, type TimelineEditOutcome } from "./timelineEditPermission";
@@ -15,18 +16,20 @@ type ElementAttributeEdits = Parameters<
15
16
  NonNullable<TimelineEditCallbacks["onSetElementsAttributeQuiet"]>
16
17
  >[0];
17
18
 
18
- type PatchTarget = NonNullable<ReturnType<typeof buildPatchTarget>>;
19
-
20
19
  function editsByFile(
21
20
  edits: ElementAttributeEdits,
21
+ attr: string,
22
22
  activeCompPath: string | null,
23
- ): Map<string, Array<{ target: PatchTarget; value: string | null }>> {
24
- const byFile = new Map<string, Array<{ target: PatchTarget; value: string | null }>>();
23
+ ): Map<string, PersistTimelineBatchChange[]> {
24
+ const byFile = new Map<string, PersistTimelineBatchChange[]>();
25
25
  for (const { element, value } of edits) {
26
- const target = buildPatchTarget(element);
27
- if (!target) throw new Error("A clip has no id to save it by");
28
26
  const path = element.sourceFile || activeCompPath || "index.html";
29
- byFile.set(path, [...(byFile.get(path) ?? []), { target, value }]);
27
+ const change: PersistTimelineBatchChange = {
28
+ element,
29
+ buildPatches: (html, target) =>
30
+ applyPatchByTarget(html, target, { type: "attribute", property: attr, value }),
31
+ };
32
+ byFile.set(path, [...(byFile.get(path) ?? []), change]);
30
33
  }
31
34
  return byFile;
32
35
  }
@@ -70,16 +73,11 @@ export function useSetElementsAttribute({
70
73
  if (typeof projectId !== "string") return projectId;
71
74
  if (edits.length === 0) return { status: "saved" };
72
75
  try {
73
- const byFile = editsByFile(edits, activeCompPath);
76
+ const byFile = editsByFile(edits, attr, activeCompPath);
74
77
  const files = Object.fromEntries(
75
- [...byFile].map(([path, patches]) => [
78
+ [...byFile].map(([path, changes]) => [
76
79
  path,
77
- (before: string) =>
78
- patches.reduce(
79
- (html, { target, value }) =>
80
- applyPatchByTarget(html, target, { type: "attribute", property: attr, value }),
81
- before,
82
- ),
80
+ (before: string) => patchTimelineChangesInSource(before, path, changes),
83
81
  ]),
84
82
  );
85
83
  for (const path of byFile.keys()) pendingTimelineEditPathRef.current.add(path);
@@ -3,6 +3,8 @@
3
3
  import { afterEach, describe, expect, it, vi } from "vitest";
4
4
  import { usePlayerStore, type TimelineElement } from "../player";
5
5
  import { resolveAudioGroups } from "@hyperframes/core/audio-groups";
6
+ import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
7
+ import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
6
8
  import { readTagSnippetByTarget } from "../utils/sourcePatcher";
7
9
  import { createAudioGroupAndAssignMembers } from "./timelineAudioGroupCreate";
8
10
  import { toggleTimelineElementHidden, toggleTimelineTrackHidden } from "./timelineTrackVisibility";
@@ -302,6 +304,38 @@ describe("toggleTimelineTrackHidden", () => {
302
304
  });
303
305
 
304
306
  describe("toggleTimelineElementHidden", () => {
307
+ it("hides a clip whose file has no ids yet, by the id the preview served it with", async () => {
308
+ // A clip added outside Studio: no id, no class, and nothing has stamped the file since.
309
+ const onDisk = `<div data-composition-id="main" data-start="0" data-duration="10"><p data-start="1" data-duration="3" data-track-index="0">Title</p></div>`;
310
+ stubProjectFiles(new Map([["index.html", onDisk]]));
311
+ const iframe = document.createElement("iframe");
312
+ document.body.append(iframe);
313
+ const doc = iframe.contentDocument;
314
+ if (!doc) throw new Error("expected iframe document");
315
+ doc.body.innerHTML = ensureHfIds(onDisk);
316
+ const [clip] = parseTimelineFromDOM(doc, 10);
317
+ if (!clip?.hfId) throw new Error("expected the served clip to carry an hf-id");
318
+ const writes = new Map<string, string>();
319
+
320
+ await toggleTimelineElementHidden({
321
+ projectId: "project-1",
322
+ activeCompPath: "index.html",
323
+ timelineElements: [clip],
324
+ elementKey: clip.key ?? clip.id,
325
+ hidden: true,
326
+ previewIframe: iframe,
327
+ writeProjectFile: async (path, content) => {
328
+ writes.set(path, content);
329
+ },
330
+ recordEdit: vi.fn(),
331
+ pendingTimelineEditPathRef: { current: new Set() },
332
+ });
333
+
334
+ expect(readTagSnippetByTarget(writes.get("index.html") ?? "", { hfId: clip.hfId })).toContain(
335
+ 'data-hidden=""',
336
+ );
337
+ });
338
+
305
339
  it("persists data-hidden for only the selected element and updates the player store", async () => {
306
340
  const iframe = document.createElement("iframe");
307
341
  document.body.append(iframe);
@@ -8,10 +8,11 @@ import { useElementPicker } from "./useElementPicker";
8
8
  import { serveEditingRequests } from "../player/hooks/timelinePlayerTestHarness";
9
9
 
10
10
  // As the host leaves it on disk: hf-ids pinned, no element ids.
11
- const SAVED = ensureHfIds(`<!doctype html><html><body>
11
+ const UNSTAMPED = `<!doctype html><html><body>
12
12
  <div data-composition-id="main" data-start="0" data-duration="10">
13
13
  <h1 class="clip" data-start="2" data-duration="3" data-track-index="0">Title</h1>
14
- </div></body></html>`);
14
+ </div></body></html>`;
15
+ const SAVED = ensureHfIds(UNSTAMPED);
15
16
 
16
17
  let root: Root | null = null;
17
18
  afterEach(() => {
@@ -354,6 +355,12 @@ describe("an edit to a picked element without an id", () => {
354
355
  );
355
356
  });
356
357
 
358
+ it("writes the edit into a file nothing has stamped yet, by the id the preview served", () => {
359
+ const { picker, synced } = mountPicker({ "index.html": UNSTAMPED });
360
+ act(() => picker().setStyle("color", "red"));
361
+ expect(synced[0]?.["index.html"]).toMatch(/<h1 [^>]*style="color: red"[^>]*>Title<\/h1>/);
362
+ });
363
+
357
364
  it("writes nothing when no saved file holds the element", () => {
358
365
  const { picker, synced } = mountPicker({ "index.html": "<div>other</div>" });
359
366
  act(() => picker().setStyle("color", "red"));
@@ -4,7 +4,7 @@ import {
4
4
  resolveSourceFile,
5
5
  applyPatch,
6
6
  applyPatchByTarget,
7
- findTagByTarget,
7
+ readTagSnippetByTarget,
8
8
  type PatchOperation,
9
9
  } from "../utils/sourcePatcher";
10
10
  import {
@@ -554,7 +554,9 @@ function patchByHfId(
554
554
  ownFile: string,
555
555
  op: PatchOperation,
556
556
  ): SourcePatch | null {
557
- const matches = Object.keys(files).filter((file) => findTagByTarget(files[file] ?? "", { hfId }));
557
+ const matches = Object.keys(files).filter(
558
+ (file) => readTagSnippetByTarget(files[file] ?? "", { hfId }) !== undefined,
559
+ );
558
560
  const path = matches.includes(ownFile) ? ownFile : matches.length === 1 ? matches[0] : undefined;
559
561
  const before = path ? files[path] : undefined;
560
562
  return path && before ? { path, before, after: applyPatchByTarget(before, { hfId }, op) } : null;
@@ -4,19 +4,18 @@ import type { AppToast } from "../utils/studioHelpers";
4
4
 
5
5
  interface ToastItem extends AppToast {
6
6
  id: number;
7
- /** True while the exit animation plays, just before removal. */
8
- leaving?: boolean;
9
7
  }
10
8
 
11
9
  const AUTO_DISMISS_MS = 4000;
12
- const EXIT_MS = 160;
13
10
  const MAX_TOASTS = 3;
14
11
 
12
+ /** Error toasts persist until dismissed so failures can't silently vanish. */
13
+ export const toastPersists = (tone: AppToast["tone"]) => tone === "error";
14
+
15
15
  let nextToastId = 1;
16
16
 
17
17
  /**
18
- * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts
19
- * persist until explicitly dismissed so failures can't silently vanish.
18
+ * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts persist.
20
19
  */
21
20
  export function useToast() {
22
21
  const [toasts, setToasts] = useState<ToastItem[]>([]);
@@ -30,7 +29,7 @@ export function useToast() {
30
29
  }
31
30
  }, []);
32
31
 
33
- const removeToast = useCallback(
32
+ const dismissToast = useCallback(
34
33
  (id: number) => {
35
34
  clearTimer(id);
36
35
  setToasts((prev) => prev.filter((t) => t.id !== id));
@@ -38,17 +37,6 @@ export function useToast() {
38
37
  [clearTimer],
39
38
  );
40
39
 
41
- const dismissToast = useCallback(
42
- (id: number) => {
43
- clearTimer(id);
44
- // Mark leaving so the exit animation plays, then remove.
45
- setToasts((prev) => prev.map((t) => (t.id === id ? { ...t, leaving: true } : t)));
46
- const timer = setTimeout(() => removeToast(id), EXIT_MS);
47
- timersRef.current.set(id, timer);
48
- },
49
- [clearTimer, removeToast],
50
- );
51
-
52
40
  const showToast = useCallback(
53
41
  (message: string, tone: AppToast["tone"] = "error"): number => {
54
42
  const id = nextToastId++;
@@ -61,7 +49,7 @@ export function useToast() {
61
49
  }
62
50
  return next;
63
51
  });
64
- if (tone !== "error") {
52
+ if (!toastPersists(tone)) {
65
53
  const timer = setTimeout(() => dismissToast(id), AUTO_DISMISS_MS);
66
54
  timersRef.current.set(id, timer);
67
55
  }