@hyperframes/studio 0.6.100 → 0.6.102

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 (44) hide show
  1. package/dist/assets/index-BITwbxi-.css +1 -0
  2. package/dist/assets/{index-CKWBqyRd.js → index-BZKngETE.js} +1 -1
  3. package/dist/assets/index-BzjItfjX.js +296 -0
  4. package/dist/assets/{index-gpSohHUn.js → index-C0vMHtMH.js} +1 -1
  5. package/dist/index.html +2 -2
  6. package/package.json +5 -5
  7. package/src/App.tsx +2 -1
  8. package/src/components/editor/PropertyPanel.tsx +24 -16
  9. package/src/components/editor/manualEditingAvailability.ts +5 -3
  10. package/src/components/nle/NLELayout.tsx +89 -1
  11. package/src/hooks/gsapKeyframeCacheHelpers.test.ts +121 -0
  12. package/src/hooks/gsapKeyframeCacheHelpers.ts +48 -2
  13. package/src/hooks/gsapScriptCommitHelpers.ts +8 -5
  14. package/src/hooks/gsapScriptCommitTypes.ts +6 -0
  15. package/src/hooks/gsapTargetCache.ts +65 -0
  16. package/src/hooks/useAppHotkeys.ts +10 -0
  17. package/src/hooks/useDomEditCommits.ts +6 -5
  18. package/src/hooks/useDomEditSession.ts +6 -1
  19. package/src/hooks/useDomGeometryCommits.ts +1 -36
  20. package/src/hooks/useElementLifecycleOps.ts +5 -0
  21. package/src/hooks/useGsapAnimationOps.ts +46 -9
  22. package/src/hooks/useGsapScriptCommits.ts +22 -3
  23. package/src/hooks/useGsapTweenCache.ts +10 -12
  24. package/src/hooks/useRazorSplit.ts +3 -0
  25. package/src/hooks/useSafeGsapCommitMutation.ts +1 -14
  26. package/src/hooks/useSdkSession.ts +15 -12
  27. package/src/hooks/useTimelineEditing.ts +23 -3
  28. package/src/player/components/Timeline.tsx +31 -18
  29. package/src/player/components/TimelineClip.tsx +3 -3
  30. package/src/player/components/useResolvedTimelineEditCallbacks.ts +30 -0
  31. package/src/player/hooks/useExpandedTimelineElements.test.ts +91 -0
  32. package/src/player/hooks/useExpandedTimelineElements.ts +153 -0
  33. package/src/player/hooks/useTimelineSyncCallbacks.ts +22 -0
  34. package/src/player/store/playerStore.ts +22 -8
  35. package/src/telemetry/events.test.ts +16 -1
  36. package/src/telemetry/events.ts +15 -0
  37. package/src/utils/blockCategories.ts +2 -2
  38. package/src/utils/sdkShadow.test.ts +232 -2
  39. package/src/utils/sdkShadow.ts +230 -2
  40. package/src/utils/sdkShadowGsapFidelity.ts +208 -0
  41. package/src/utils/studioHelpers.test.ts +25 -1
  42. package/src/utils/studioHelpers.ts +54 -28
  43. package/dist/assets/index-B62bDCQv.css +0 -1
  44. package/dist/assets/index-BkT9VKwz.js +0 -296
@@ -1,4 +1,4 @@
1
- import{n as Qi}from"./index-BkT9VKwz.js";/*!
1
+ import{n as Qi}from"./index-BzjItfjX.js";/*!
2
2
  * Copyright (c) 2026-present, Vanilagy and contributors
3
3
  *
4
4
  * This Source Code Form is subject to the terms of the Mozilla Public
package/dist/index.html CHANGED
@@ -5,8 +5,8 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <title>HyperFrames Studio</title>
8
- <script type="module" crossorigin src="/assets/index-BkT9VKwz.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-B62bDCQv.css">
8
+ <script type="module" crossorigin src="/assets/index-BzjItfjX.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-BITwbxi-.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.6.100",
3
+ "version": "0.6.102",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,9 +33,9 @@
33
33
  "@phosphor-icons/react": "^2.1.10",
34
34
  "bpm-detective": "^2.0.5",
35
35
  "mediabunny": "^1.45.3",
36
- "@hyperframes/core": "0.6.100",
37
- "@hyperframes/sdk": "0.6.100",
38
- "@hyperframes/player": "0.6.100"
36
+ "@hyperframes/core": "0.6.102",
37
+ "@hyperframes/player": "0.6.102",
38
+ "@hyperframes/sdk": "0.6.102"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "19",
@@ -49,7 +49,7 @@
49
49
  "vite": "^6.4.2",
50
50
  "vitest": "^3.2.4",
51
51
  "zustand": "^5.0.0",
52
- "@hyperframes/producer": "0.6.100"
52
+ "@hyperframes/producer": "0.6.102"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": "19",
package/src/App.tsx CHANGED
@@ -175,6 +175,7 @@ export function StudioApp() {
175
175
  reloadPreview: () => setRefreshKey((k) => k + 1),
176
176
  pendingTimelineEditPathRef,
177
177
  });
178
+ const sdkSession = useSdkSession(projectId, activeCompPath);
178
179
  const timelineEditing = useTimelineEditing({
179
180
  projectId,
180
181
  activeCompPath,
@@ -188,6 +189,7 @@ export function StudioApp() {
188
189
  pendingTimelineEditPathRef,
189
190
  uploadProjectFiles: fileManager.uploadProjectFiles,
190
191
  isRecordingRef: isGestureRecordingRef,
192
+ sdkSession,
191
193
  });
192
194
  const {
193
195
  activeBlockParams,
@@ -267,7 +269,6 @@ export function StudioApp() {
267
269
  () => leftSidebarRef.current?.getTab() ?? "compositions",
268
270
  [],
269
271
  );
270
- const sdkSession = useSdkSession(projectId, activeCompPath);
271
272
  const domEditSession = useDomEditSession({
272
273
  projectId,
273
274
  activeCompPath,
@@ -1,4 +1,4 @@
1
- import { memo, useEffect, useRef, useState } from "react";
1
+ import { memo, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { Eye, Layers, Move, X } from "../../icons/SystemIcons";
3
3
  import { useStudioShellContext } from "../../contexts/StudioContext";
4
4
  import { readStudioBoxSize, readStudioPathOffset, readStudioRotation } from "./manualEdits";
@@ -111,6 +111,29 @@ export const PropertyPanel = memo(function PropertyPanel({
111
111
  const cacheElementKey = element?.id ?? element?.selector ?? "";
112
112
  const cacheEntry = usePlayerStore((s) => s.keyframeCache.get(cacheElementKey));
113
113
 
114
+ const iframeRef = previewIframeRef ?? { current: null };
115
+ const gsapAnimIdForMemo = element
116
+ ? (gsapAnimations?.find((a: { keyframes?: unknown }) => a.keyframes)?.id ??
117
+ gsapAnimations?.[0]?.id ??
118
+ null)
119
+ : null;
120
+ const gsapRuntimeValues = useMemo(
121
+ () =>
122
+ element
123
+ ? readGsapRuntimeValuesForPanel(gsapAnimIdForMemo, gsapAnimations, element, iframeRef)
124
+ : null,
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- iframeRef is stable; currentTime drives re-reads during playback
126
+ [gsapAnimIdForMemo, gsapAnimations, element, currentTime],
127
+ );
128
+ const gsapBorderRadius = useMemo(
129
+ () =>
130
+ element
131
+ ? readGsapBorderRadiusForPanel(gsapRuntimeValues, gsapAnimations, element, iframeRef)
132
+ : null,
133
+ // eslint-disable-next-line react-hooks/exhaustive-deps
134
+ [gsapRuntimeValues, gsapAnimations, element, currentTime],
135
+ );
136
+
114
137
  if (!element) {
115
138
  return (
116
139
  <div className="flex h-full flex-col bg-neutral-900">
@@ -194,21 +217,6 @@ export const PropertyPanel = memo(function PropertyPanel({
194
217
  return gsapAnimId ?? "";
195
218
  };
196
219
 
197
- // Read ALL GSAP-interpolated values at the current seek time.
198
- const gsapRuntimeValues = readGsapRuntimeValuesForPanel(
199
- gsapAnimId,
200
- gsapAnimations,
201
- element,
202
- previewIframeRef ?? { current: null },
203
- );
204
-
205
- const gsapBorderRadius = readGsapBorderRadiusForPanel(
206
- gsapRuntimeValues,
207
- gsapAnimations,
208
- element,
209
- previewIframeRef ?? { current: null },
210
- );
211
-
212
220
  const displayX = gsapRuntimeValues?.x ?? manualOffset.x;
213
221
  const displayY = gsapRuntimeValues?.y ?? manualOffset.y;
214
222
  const displayW = gsapRuntimeValues?.width ?? resolvedWidth;
@@ -73,7 +73,7 @@ export const STUDIO_KEYFRAMES_ENABLED = resolveStudioBooleanEnvFlag(
73
73
  export const STUDIO_RAZOR_TOOL_ENABLED = resolveStudioBooleanEnvFlag(
74
74
  env,
75
75
  ["VITE_STUDIO_ENABLE_RAZOR_TOOL", "VITE_STUDIO_RAZOR_TOOL_ENABLED"],
76
- false,
76
+ true,
77
77
  );
78
78
 
79
79
  // When disabled (the default), drag/resize/rotate commits always take the CSS
@@ -90,11 +90,13 @@ export const STUDIO_PREVIEW_SELECTION_ENABLED = STUDIO_INSPECTOR_PANELS_ENABLED;
90
90
 
91
91
  // Stage 7 Step 3b: shadow dispatch parity mode — dispatches ops to the SDK
92
92
  // session alongside the server patch path and logs mismatches via telemetry.
93
- // Default false in production; enable via VITE_STUDIO_SDK_SHADOW_ENABLED=true.
93
+ // Default on: server stays authoritative (no user-visible change), so we want
94
+ // the sdk_shadow_dispatch parity signal from all traffic. Disable via
95
+ // VITE_STUDIO_SDK_SHADOW_ENABLED=false.
94
96
  export const STUDIO_SDK_SHADOW_ENABLED = resolveStudioBooleanEnvFlag(
95
97
  env,
96
98
  ["VITE_STUDIO_SDK_SHADOW_ENABLED"],
97
- false,
99
+ true,
98
100
  );
99
101
 
100
102
  export const STUDIO_MANUAL_EDITING_DISABLED_TITLE = "Manual editing is temporarily disabled";
@@ -10,10 +10,13 @@ import {
10
10
  import { useMountEffect } from "../../hooks/useMountEffect";
11
11
  import { useTimelinePlayer, PlayerControls, Timeline, usePlayerStore } from "../../player";
12
12
  import type { TimelineElement } from "../../player";
13
+ import type { BlockedTimelineEditIntent } from "../../player/components/timelineEditing";
13
14
  import { NLEPreview } from "./NLEPreview";
14
15
  import { CompositionBreadcrumb } from "./CompositionBreadcrumb";
15
16
  import { usePreviewBlockDrop } from "./usePreviewBlockDrop";
16
17
  import { useCompositionStack } from "./useCompositionStack";
18
+ import { useTimelineEditContext } from "../../contexts/TimelineEditContext";
19
+ import { trackStudioExpandedClipEdit } from "../../telemetry/events";
17
20
  import {
18
21
  TIMELINE_TOGGLE_SHORTCUT_LABEL,
19
22
  getTimelineToggleTitle,
@@ -58,6 +61,7 @@ interface NLELayoutProps {
58
61
  blockName: string,
59
62
  position: { left: number; top: number },
60
63
  ) => Promise<void> | void;
64
+ onBlockedEditAttempt?: (element: TimelineElement, intent: BlockedTimelineEditIntent) => void;
61
65
  onSelectTimelineElement?: (element: TimelineElement | null) => void;
62
66
  /** Exposes the compIdToSrc map for parent components (e.g., useRenderClipContent) */
63
67
  onCompIdToSrcChange?: (map: Map<string, string>) => void;
@@ -103,6 +107,7 @@ export const NLELayout = memo(function NLELayout({
103
107
  onAssetDrop,
104
108
  onBlockDrop,
105
109
  onPreviewBlockDrop,
110
+ onBlockedEditAttempt,
106
111
  onSelectTimelineElement,
107
112
  onCompIdToSrcChange,
108
113
  timelineVisible,
@@ -175,6 +180,7 @@ export const NLELayout = memo(function NLELayout({
175
180
  const handleDrillDown = useCallback(
176
181
  (element: TimelineElement) => {
177
182
  if (!element.compositionSrc) return;
183
+ usePlayerStore.getState().setSelectedElementId(null);
178
184
  // Check compIdToSrc map first; then scan iframe DOM; then fall through to drillDown
179
185
  const compId = element.id;
180
186
  let resolvedPath = compIdToSrc.get(compId);
@@ -202,6 +208,73 @@ export const NLELayout = memo(function NLELayout({
202
208
  [compIdToSrc, drillDown, iframeRef_],
203
209
  );
204
210
 
211
+ // Move/resize/split come from the timeline edit context, not props — the
212
+ // wrappers below intercept expanded clips and must call the *real* handlers.
213
+ // (Delete is a direct prop; it stays that way.)
214
+ const { onMoveElement, onResizeElement, onSplitElement } = useTimelineEditContext();
215
+
216
+ // An expanded sub-comp child reaches the normal edit handlers in its own
217
+ // local coordinates: addressed by its real DOM id, with timeline time rebased
218
+ // onto the sub-comp it lives in. The handlers then save + reloadPreview exactly
219
+ // as they do for top-level clips — no separate live-DOM path.
220
+ const toLocalElement = useCallback(
221
+ (element: TimelineElement, basis: number): TimelineElement => ({
222
+ ...element,
223
+ id: element.domId ?? element.id,
224
+ start: element.start - basis,
225
+ }),
226
+ [],
227
+ );
228
+
229
+ const handleMoveElement = useCallback(
230
+ (element: TimelineElement, updates: Pick<TimelineElement, "start" | "track">) => {
231
+ const basis = element.expandedParentStart;
232
+ if (basis === undefined) return onMoveElement?.(element, updates);
233
+ trackStudioExpandedClipEdit({ action: "move" });
234
+ onMoveElement?.(toLocalElement(element, basis), {
235
+ ...updates,
236
+ start: Math.max(0, updates.start - basis),
237
+ });
238
+ },
239
+ [onMoveElement, toLocalElement],
240
+ );
241
+
242
+ const handleResizeElement = useCallback(
243
+ (
244
+ element: TimelineElement,
245
+ updates: Pick<TimelineElement, "start" | "duration" | "playbackStart">,
246
+ ) => {
247
+ const basis = element.expandedParentStart;
248
+ if (basis === undefined) return onResizeElement?.(element, updates);
249
+ trackStudioExpandedClipEdit({ action: "resize" });
250
+ onResizeElement?.(toLocalElement(element, basis), {
251
+ ...updates,
252
+ start: Math.max(0, updates.start - basis),
253
+ });
254
+ },
255
+ [onResizeElement, toLocalElement],
256
+ );
257
+
258
+ const handleDeleteElement = useCallback(
259
+ (element: TimelineElement) => {
260
+ const basis = element.expandedParentStart;
261
+ if (basis === undefined) return onDeleteElement?.(element);
262
+ trackStudioExpandedClipEdit({ action: "delete" });
263
+ return onDeleteElement?.(toLocalElement(element, basis));
264
+ },
265
+ [onDeleteElement, toLocalElement],
266
+ );
267
+
268
+ const handleSplitElement = useCallback(
269
+ (element: TimelineElement, splitTime: number) => {
270
+ const basis = element.expandedParentStart;
271
+ if (basis === undefined) return onSplitElement?.(element, splitTime);
272
+ trackStudioExpandedClipEdit({ action: "split" });
273
+ return onSplitElement?.(toLocalElement(element, basis), Math.max(0, splitTime - basis));
274
+ },
275
+ [onSplitElement, toLocalElement],
276
+ );
277
+
205
278
  // Composition ID → file path map from raw index.html
206
279
  const compIdToSrcRef = useRef(compIdToSrc);
207
280
  compIdToSrcRef.current = compIdToSrc;
@@ -356,6 +429,17 @@ export const NLELayout = memo(function NLELayout({
356
429
  <div
357
430
  className="flex-1 min-h-0 relative"
358
431
  data-preview-pan-surface="true"
432
+ onPointerDown={(e) => {
433
+ const el = iframeRef.current?.parentElement ?? iframeRef.current;
434
+ if (!el) return;
435
+ const rect = el.getBoundingClientRect();
436
+ const inside =
437
+ e.clientX >= rect.left &&
438
+ e.clientX <= rect.right &&
439
+ e.clientY >= rect.top &&
440
+ e.clientY <= rect.bottom;
441
+ if (!inside) onSelectTimelineElement?.(null);
442
+ }}
359
443
  onDragOver={handlePreviewDragOver}
360
444
  onDragLeave={handlePreviewDragLeave}
361
445
  onDrop={handlePreviewDrop}
@@ -429,9 +513,13 @@ export const NLELayout = memo(function NLELayout({
429
513
  onDrillDown={handleDrillDown}
430
514
  renderClipContent={renderClipContent}
431
515
  onFileDrop={onFileDrop}
432
- onDeleteElement={onDeleteElement}
516
+ onDeleteElement={handleDeleteElement}
433
517
  onAssetDrop={onAssetDrop}
434
518
  onBlockDrop={onBlockDrop}
519
+ onMoveElement={handleMoveElement}
520
+ onResizeElement={handleResizeElement}
521
+ onBlockedEditAttempt={onBlockedEditAttempt}
522
+ onSplitElement={handleSplitElement}
435
523
  onSelectElement={onSelectTimelineElement}
436
524
  />
437
525
  </div>
@@ -0,0 +1,121 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
3
+ import { usePlayerStore, type KeyframeCacheEntry } from "../player/store/playerStore";
4
+ import {
5
+ clearKeyframeCacheForElement,
6
+ clearKeyframeCacheForFile,
7
+ updateKeyframeCacheFromParsed,
8
+ } from "./gsapKeyframeCacheHelpers";
9
+
10
+ const entry = (): KeyframeCacheEntry => ({
11
+ format: "percentage",
12
+ keyframes: [{ percentage: 0, properties: { x: 0 } }],
13
+ });
14
+
15
+ const seed = (key: string) => usePlayerStore.getState().setKeyframeCache(key, entry());
16
+ const cache = () => usePlayerStore.getState().keyframeCache;
17
+
18
+ const animWithKeyframes = (id: string): GsapAnimation => ({
19
+ id,
20
+ targetSelector: `#${id}`,
21
+ method: "to",
22
+ position: 0,
23
+ properties: {},
24
+ duration: 1,
25
+ resolvedStart: 0,
26
+ propertyGroup: "position",
27
+ keyframes: { format: "percentage", keyframes: [{ percentage: 50, properties: { x: 100 } }] },
28
+ });
29
+
30
+ beforeEach(() => {
31
+ usePlayerStore.setState({ keyframeCache: new Map(), elements: [] });
32
+ });
33
+
34
+ describe("clearKeyframeCacheForElement", () => {
35
+ it("drops the prefixed, index.html fallback, and bare key for a non-index source", () => {
36
+ seed("comp.html#box");
37
+ seed("index.html#box");
38
+ seed("box");
39
+
40
+ clearKeyframeCacheForElement("comp.html", "box");
41
+
42
+ expect(cache().has("comp.html#box")).toBe(false);
43
+ expect(cache().has("index.html#box")).toBe(false);
44
+ // The bare key is what PropertyPanel's keyframe nav reads (element.id), so
45
+ // it must be cleared too, not just the prefixed variants.
46
+ expect(cache().has("box")).toBe(false);
47
+ });
48
+
49
+ it("drops the prefixed and bare key for an index.html source", () => {
50
+ seed("index.html#hero");
51
+ seed("hero");
52
+
53
+ clearKeyframeCacheForElement("index.html", "hero");
54
+
55
+ expect(cache().has("index.html#hero")).toBe(false);
56
+ expect(cache().has("hero")).toBe(false);
57
+ });
58
+
59
+ it("leaves other elements' keys untouched", () => {
60
+ seed("index.html#box");
61
+ seed("box");
62
+ seed("index.html#other");
63
+ seed("other");
64
+
65
+ clearKeyframeCacheForElement("index.html", "box");
66
+
67
+ expect(cache().has("index.html#other")).toBe(true);
68
+ expect(cache().has("other")).toBe(true);
69
+ });
70
+ });
71
+
72
+ describe("clearKeyframeCacheForFile", () => {
73
+ it("clears the prefixed, fallback, and bare keys for every element of the file", () => {
74
+ seed("comp.html#a");
75
+ seed("index.html#a");
76
+ seed("a");
77
+ seed("comp.html#b");
78
+ seed("b");
79
+
80
+ clearKeyframeCacheForFile("comp.html");
81
+
82
+ for (const key of ["comp.html#a", "index.html#a", "a", "comp.html#b", "b"]) {
83
+ expect(cache().has(key)).toBe(false);
84
+ }
85
+ });
86
+
87
+ it("leaves entries that belong to a different source file", () => {
88
+ seed("comp.html#a");
89
+ seed("a");
90
+ seed("other.html#z");
91
+ seed("z");
92
+
93
+ clearKeyframeCacheForFile("comp.html");
94
+
95
+ expect(cache().has("other.html#z")).toBe(true);
96
+ expect(cache().has("z")).toBe(true);
97
+ });
98
+ });
99
+
100
+ describe("updateKeyframeCacheFromParsed", () => {
101
+ it("clears the bare key when the selected element no longer has keyframes", () => {
102
+ // Element previously had keyframes, so a bare entry exists (writes set both).
103
+ seed("index.html#box");
104
+ seed("box");
105
+
106
+ // A mutation leaves #box without any keyframes in the parsed animations.
107
+ updateKeyframeCacheFromParsed([], "index.html", "box", {});
108
+
109
+ expect(cache().has("index.html#box")).toBe(false);
110
+ // Without the bare-key clear this assertion fails: the stale entry survives
111
+ // and PropertyPanel keeps rendering the removed keyframes.
112
+ expect(cache().has("box")).toBe(false);
113
+ });
114
+
115
+ it("still writes the bare key for elements that have keyframes", () => {
116
+ updateKeyframeCacheFromParsed([animWithKeyframes("hero")], "index.html", "hero", {});
117
+
118
+ expect(cache().has("index.html#hero")).toBe(true);
119
+ expect(cache().has("hero")).toBe(true);
120
+ });
121
+ });
@@ -67,8 +67,54 @@ export function updateKeyframeCacheFromParsed(
67
67
  (mutation as { targetSelector?: string }).targetSelector?.match(/^#([\w-]+)/)?.[1] ??
68
68
  selectionId;
69
69
  if (targetId && !idsWithKeyframes.has(targetId)) {
70
- setKeyframeCache(`${targetPath}#${targetId}`, undefined);
71
- if (targetPath !== "index.html") setKeyframeCache(`index.html#${targetId}`, undefined);
70
+ clearKeyframeCacheForElement(targetPath, targetId);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Clear every keyframe-cache key variant written for an element: the
76
+ * source-prefixed key, the index.html fallback, and the bare element id.
77
+ * Writes set all three (see updateKeyframeCacheFromParsed and
78
+ * usePopulateKeyframeCacheForFile). PropertyPanel's keyframe nav reads the bare
79
+ * id directly (`element.id`), and other consumers (timeline diamonds, the
80
+ * preview overlay) fall back to the bare id when an element has no
81
+ * source-prefixed key — so a clear that drops only the prefixed keys leaves the
82
+ * bare entry behind and those readers keep showing keyframes the element no
83
+ * longer has. Each delete is guarded by `has` so an absent key doesn't allocate
84
+ * a new cache map and re-render every subscriber.
85
+ */
86
+ export function clearKeyframeCacheForElement(sourceFile: string, elementId: string): void {
87
+ const { keyframeCache, setKeyframeCache } = usePlayerStore.getState();
88
+ const keys =
89
+ sourceFile === "index.html"
90
+ ? [`index.html#${elementId}`, elementId]
91
+ : [`${sourceFile}#${elementId}`, `index.html#${elementId}`, elementId];
92
+ for (const key of keys) {
93
+ if (keyframeCache.has(key)) setKeyframeCache(key, undefined);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Clear every cached element of `sourceFile` before a full re-scan repopulates
99
+ * it. Collects the element ids that currently have a prefixed or index.html
100
+ * fallback key for the file and drops each through clearKeyframeCacheForElement
101
+ * so the bare key goes too — an element whose keyframes were removed (and so is
102
+ * absent from the re-scan) leaves no stale bare entry behind.
103
+ */
104
+ export function clearKeyframeCacheForFile(sourceFile: string): void {
105
+ const { keyframeCache } = usePlayerStore.getState();
106
+ const sfPrefix = `${sourceFile}#`;
107
+ const fallbackPrefix = "index.html#";
108
+ const ids = new Set<string>();
109
+ for (const key of keyframeCache.keys()) {
110
+ const matchesFile =
111
+ key.startsWith(sfPrefix) || (sourceFile !== "index.html" && key.startsWith(fallbackPrefix));
112
+ if (!matchesFile) continue;
113
+ const hashIdx = key.indexOf("#");
114
+ if (hashIdx !== -1) ids.add(key.slice(hashIdx + 1));
115
+ }
116
+ for (const id of ids) {
117
+ clearKeyframeCacheForElement(sourceFile, id);
72
118
  }
73
119
  }
74
120
 
@@ -37,6 +37,13 @@ function isRecord(value: unknown): value is Record<string, unknown> {
37
37
  return typeof value === "object" && value !== null;
38
38
  }
39
39
 
40
+ export function formatFieldsSuffix(rawFields: unknown): string {
41
+ const fields = Array.isArray(rawFields)
42
+ ? rawFields.filter((f): f is string => typeof f === "string")
43
+ : [];
44
+ return fields.length > 0 ? ` (${fields.join(", ")})` : "";
45
+ }
46
+
40
47
  export async function readJsonResponseBody(res: Response): Promise<unknown> {
41
48
  const contentType = res.headers.get("content-type") ?? "";
42
49
  if (!contentType.includes("application/json")) {
@@ -55,14 +62,10 @@ function formatGsapMutationHttpErrorMessage(statusCode: number, body: unknown):
55
62
  export function formatGsapMutationRejectionToast(error: GsapMutationHttpError): string {
56
63
  const body = error.responseBody;
57
64
  if (isRecord(body)) {
58
- const fields = Array.isArray(body.fields)
59
- ? body.fields.filter((field): field is string => typeof field === "string")
60
- : [];
61
- const suffix = fields.length > 0 ? ` (${fields.join(", ")})` : "";
62
65
  return `Couldn't save animation: ${formatGsapMutationHttpErrorMessage(
63
66
  error.statusCode,
64
67
  body,
65
- )}${suffix}`;
68
+ )}${formatFieldsSuffix(body.fields)}`;
66
69
  }
67
70
  return `Couldn't save animation: ${error.message}`;
68
71
  }
@@ -1,6 +1,8 @@
1
1
  import type { ParsedGsap } from "@hyperframes/core/gsap-parser";
2
+ import type { Composition } from "@hyperframes/sdk";
2
3
  import type { DomEditSelection } from "../components/editor/domEditingTypes";
3
4
  import type { EditHistoryKind } from "../utils/editHistory";
5
+ import type { ShadowGsapOp } from "../utils/sdkShadow";
4
6
 
5
7
  export interface MutationResult {
6
8
  ok: boolean;
@@ -17,6 +19,8 @@ export interface CommitMutationOptions {
17
19
  softReload?: boolean;
18
20
  skipReload?: boolean;
19
21
  beforeReload?: () => void;
22
+ /** Stage 7 Step 3b: typed SDK equivalent of this mutation for value-fidelity shadow. */
23
+ shadowGsapOp?: ShadowGsapOp;
20
24
  }
21
25
 
22
26
  export type CommitMutation = (
@@ -55,4 +59,6 @@ export interface GsapScriptCommitsParams {
55
59
  onCacheInvalidate: () => void;
56
60
  onFileContentChanged?: (path: string, content: string) => void;
57
61
  showToast: (message: string, tone?: "error" | "info") => void;
62
+ /** Stage 7 Step 3b: SDK session for shadow GSAP dispatch (server stays authoritative). */
63
+ sdkSession?: Composition | null;
58
64
  }
@@ -0,0 +1,65 @@
1
+ import { STUDIO_GSAP_DRAG_INTERCEPT_ENABLED } from "../components/editor/manualEditingAvailability";
2
+
3
+ type TimelineLike = { getChildren?: (nested: boolean) => Array<{ targets?: () => Element[] }> };
4
+
5
+ let _gsapCachedTimelines: Record<string, TimelineLike> | undefined;
6
+ let _gsapTargetIds: Set<string> | undefined;
7
+ let _gsapTargetNodes: WeakSet<Element> | undefined;
8
+
9
+ function addTargetsFromTimeline(tl: TimelineLike, ids: Set<string>, nodes: WeakSet<Element>): void {
10
+ const children = tl.getChildren?.(true);
11
+ if (!children) return;
12
+ for (const child of children) {
13
+ const targets = child.targets?.();
14
+ if (!targets) continue;
15
+ for (const t of targets) {
16
+ nodes.add(t);
17
+ if (t.id) ids.add(t.id);
18
+ }
19
+ }
20
+ }
21
+
22
+ function collectGsapTargets(timelines: Record<string, TimelineLike>): {
23
+ ids: Set<string>;
24
+ nodes: WeakSet<Element>;
25
+ } {
26
+ const ids = new Set<string>();
27
+ const nodes = new WeakSet<Element>();
28
+ for (const tl of Object.values(timelines)) {
29
+ if (!tl) continue;
30
+ try {
31
+ addTargetsFromTimeline(tl, ids, nodes);
32
+ } catch {
33
+ /* teardown race */
34
+ }
35
+ }
36
+ return { ids, nodes };
37
+ }
38
+
39
+ function readTimelines(iframe: HTMLIFrameElement | null): Record<string, TimelineLike> | undefined {
40
+ if (!iframe?.contentWindow) return undefined;
41
+ try {
42
+ return (iframe.contentWindow as Window & { __timelines?: Record<string, TimelineLike> })
43
+ .__timelines;
44
+ } catch {
45
+ return undefined;
46
+ }
47
+ }
48
+
49
+ export function isElementGsapTargeted(
50
+ iframe: HTMLIFrameElement | null,
51
+ element: HTMLElement,
52
+ ): boolean {
53
+ if (!STUDIO_GSAP_DRAG_INTERCEPT_ENABLED) return false;
54
+ const timelines = readTimelines(iframe);
55
+ if (!timelines) return false;
56
+
57
+ if (timelines !== _gsapCachedTimelines) {
58
+ const cache = collectGsapTargets(timelines);
59
+ _gsapTargetIds = cache.ids;
60
+ _gsapTargetNodes = cache.nodes;
61
+ _gsapCachedTimelines = timelines;
62
+ }
63
+
64
+ return _gsapTargetNodes!.has(element) || !!(element.id && _gsapTargetIds!.has(element.id));
65
+ }
@@ -136,6 +136,7 @@ interface HotkeyCallbacks {
136
136
  onToggleRecording?: () => void;
137
137
  leftSidebarRef: React.RefObject<LeftSidebarHandle | null>;
138
138
  domEditSelectionRef: React.MutableRefObject<DomEditSelection | null>;
139
+ showToast: (message: string, tone?: "error" | "info") => void;
139
140
  }
140
141
 
141
142
  function dispatchModifierKey(event: KeyboardEvent, key: string, cb: HotkeyCallbacks): boolean {
@@ -205,6 +206,14 @@ function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCallbacks
205
206
  void cb.handleTimelineElementSplit(el, currentTime);
206
207
  return;
207
208
  }
209
+ // Expanded sub-comp children carry a qualified `sourceFile#id` selection
210
+ // that isn't in the raw `elements` list, so the s-key can't resolve them.
211
+ // Nudge toward the razor tool instead of failing silently.
212
+ if (!el && selectedElementId.includes("#")) {
213
+ event.preventDefault();
214
+ cb.showToast("Use the razor tool (B) to split clips inside a sub-composition", "info");
215
+ return;
216
+ }
208
217
  }
209
218
  }
210
219
 
@@ -376,6 +385,7 @@ export function useAppHotkeys({
376
385
  onToggleRecording,
377
386
  leftSidebarRef,
378
387
  domEditSelectionRef,
388
+ showToast,
379
389
  };
380
390
 
381
391
  // ── Keydown dispatch ──
@@ -14,6 +14,7 @@ import { useDomEditPositionPatchCommit } from "./useDomEditPositionPatchCommit";
14
14
  import { useDomEditTextCommits } from "./useDomEditTextCommits";
15
15
  import { useDomGeometryCommits } from "./useDomGeometryCommits";
16
16
  import { useElementLifecycleOps } from "./useElementLifecycleOps";
17
+ import { formatFieldsSuffix } from "./gsapScriptCommitHelpers";
17
18
 
18
19
  // ── Helpers ──
19
20
 
@@ -31,11 +32,7 @@ async function readErrorResponseBody(
31
32
 
32
33
  function formatPatchRejectionMessage(body: { error?: string; fields?: string[] } | null): string {
33
34
  if (!body?.error) return "Couldn't save edit";
34
- const fields = Array.isArray(body.fields)
35
- ? body.fields.filter((field): field is string => typeof field === "string")
36
- : [];
37
- const suffix = fields.length > 0 ? ` (${fields.join(", ")})` : "";
38
- return `Couldn't save edit: ${body.error}${suffix}`;
35
+ return `Couldn't save edit: ${body.error}${formatFieldsSuffix(body.fields)}`;
39
36
  }
40
37
 
41
38
  interface RecordEditInput {
@@ -73,6 +70,8 @@ export interface UseDomEditCommitsParams {
73
70
  ) => Promise<DomEditSelection | null>;
74
71
  /** Stage 7 Step 3b: called after a successful server-side element patch. */
75
72
  onDomEditPersisted?: (selection: DomEditSelection, operations: PatchOperation[]) => void;
73
+ /** Stage 7 Step 3b: called after a successful server-side element delete. */
74
+ onElementDeleted?: (selection: DomEditSelection) => void;
76
75
  }
77
76
 
78
77
  export function useDomEditCommits({
@@ -94,6 +93,7 @@ export function useDomEditCommits({
94
93
  refreshDomEditSelectionFromPreview,
95
94
  buildDomSelectionFromTarget,
96
95
  onDomEditPersisted,
96
+ onElementDeleted,
97
97
  }: UseDomEditCommitsParams) {
98
98
  const resolveImportedFontAsset = useCallback(
99
99
  (fontFamilyValue: string): ImportedFontAsset | null => {
@@ -290,6 +290,7 @@ export function useDomEditCommits({
290
290
  reloadPreview,
291
291
  clearDomSelection,
292
292
  commitPositionPatchToHtml,
293
+ onElementDeleted,
293
294
  });
294
295
 
295
296
  return {