@hyperframes/studio 0.6.100 → 0.6.101

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 (38) hide show
  1. package/dist/assets/index-BITwbxi-.css +1 -0
  2. package/dist/assets/{index-gpSohHUn.js → index-CQ3n6Y9q.js} +1 -1
  3. package/dist/assets/{index-BkT9VKwz.js → index-CTiqZ7XQ.js} +165 -165
  4. package/dist/assets/{index-CKWBqyRd.js → index-DvttAtOD.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/gsapScriptCommitHelpers.ts +8 -5
  12. package/src/hooks/gsapScriptCommitTypes.ts +3 -0
  13. package/src/hooks/gsapTargetCache.ts +65 -0
  14. package/src/hooks/useAppHotkeys.ts +10 -0
  15. package/src/hooks/useDomEditCommits.ts +6 -5
  16. package/src/hooks/useDomEditSession.ts +6 -1
  17. package/src/hooks/useDomGeometryCommits.ts +1 -36
  18. package/src/hooks/useElementLifecycleOps.ts +5 -0
  19. package/src/hooks/useGsapAnimationOps.ts +26 -1
  20. package/src/hooks/useGsapScriptCommits.ts +5 -2
  21. package/src/hooks/useRazorSplit.ts +3 -0
  22. package/src/hooks/useSdkSession.ts +15 -12
  23. package/src/hooks/useTimelineEditing.ts +23 -3
  24. package/src/player/components/Timeline.tsx +31 -18
  25. package/src/player/components/TimelineClip.tsx +3 -3
  26. package/src/player/components/useResolvedTimelineEditCallbacks.ts +30 -0
  27. package/src/player/hooks/useExpandedTimelineElements.test.ts +91 -0
  28. package/src/player/hooks/useExpandedTimelineElements.ts +153 -0
  29. package/src/player/hooks/useTimelineSyncCallbacks.ts +22 -0
  30. package/src/player/store/playerStore.ts +22 -8
  31. package/src/telemetry/events.test.ts +16 -1
  32. package/src/telemetry/events.ts +15 -0
  33. package/src/utils/blockCategories.ts +2 -2
  34. package/src/utils/sdkShadow.test.ts +102 -2
  35. package/src/utils/sdkShadow.ts +200 -2
  36. package/src/utils/studioHelpers.test.ts +25 -1
  37. package/src/utils/studioHelpers.ts +54 -28
  38. package/dist/assets/index-B62bDCQv.css +0 -1
@@ -1 +1 @@
1
- import{g as P}from"./index-BkT9VKwz.js";function j(c,d){for(var s=0;s<d.length;s++){const a=d[s];if(typeof a!="string"&&!Array.isArray(a)){for(const i in a)if(i!=="default"&&!(i in c)){const l=Object.getOwnPropertyDescriptor(a,i);l&&Object.defineProperty(c,i,l.get?l:{enumerable:!0,get:()=>a[i]})}}}return Object.freeze(Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}))}var v={},w;function k(){if(w)return v;w=1,Object.defineProperty(v,"__esModule",{value:!0}),v.default=d;var c=window.OfflineAudioContext||window.webkitOfflineAudioContext;function d(e){var r=a(e);return r.start(0),[i,y,O(e.sampleRate),s].reduce(function(t,o){return o(t)},r.buffer.getChannelData(0))}function s(e){return e.sort(function(r,t){return t.count-r.count}).splice(0,5)[0].tempo}function a(e){var r=e.length,t=e.numberOfChannels,o=e.sampleRate,n=new c(t,r,o),u=n.createBufferSource();u.buffer=e;var f=n.createBiquadFilter();return f.type="lowpass",u.connect(f),f.connect(n.destination),u}function i(e){for(var r=[],t=.9,o=.3,n=15;r.length<n&&t>=o;)r=l(e,t),t-=.05;if(r.length<n)throw new Error("Could not find enough samples for a reliable detection.");return r}function l(e,r){for(var t=[],o=0,n=e.length;o<n;o+=1)e[o]>r&&(t.push(o),o+=1e4);return t}function y(e){var r=[];return e.forEach(function(t,o){for(var n=function(x){var g=e[o+x]-t,_=r.some(function(h){if(h.interval===g)return h.count+=1});_||r.push({interval:g,count:1})},u=0;u<10;u+=1)n(u)}),r}function O(e){return function(r){var t=[];return r.forEach(function(o){if(o.interval!==0){for(var n=60/(o.interval/e);n<90;)n*=2;for(;n>180;)n/=2;n=Math.round(n);var u=t.some(function(f){if(f.tempo===n)return f.count+=o.count});u||t.push({tempo:n,count:o.count})}}),t}}return v}var p,b;function q(){return b||(b=1,p=k().default),p}var m=q();const A=P(m),D=j({__proto__:null,default:A},[m]);export{D as i};
1
+ import{g as P}from"./index-CTiqZ7XQ.js";function j(c,d){for(var s=0;s<d.length;s++){const a=d[s];if(typeof a!="string"&&!Array.isArray(a)){for(const i in a)if(i!=="default"&&!(i in c)){const l=Object.getOwnPropertyDescriptor(a,i);l&&Object.defineProperty(c,i,l.get?l:{enumerable:!0,get:()=>a[i]})}}}return Object.freeze(Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}))}var v={},w;function k(){if(w)return v;w=1,Object.defineProperty(v,"__esModule",{value:!0}),v.default=d;var c=window.OfflineAudioContext||window.webkitOfflineAudioContext;function d(e){var r=a(e);return r.start(0),[i,y,O(e.sampleRate),s].reduce(function(t,o){return o(t)},r.buffer.getChannelData(0))}function s(e){return e.sort(function(r,t){return t.count-r.count}).splice(0,5)[0].tempo}function a(e){var r=e.length,t=e.numberOfChannels,o=e.sampleRate,n=new c(t,r,o),u=n.createBufferSource();u.buffer=e;var f=n.createBiquadFilter();return f.type="lowpass",u.connect(f),f.connect(n.destination),u}function i(e){for(var r=[],t=.9,o=.3,n=15;r.length<n&&t>=o;)r=l(e,t),t-=.05;if(r.length<n)throw new Error("Could not find enough samples for a reliable detection.");return r}function l(e,r){for(var t=[],o=0,n=e.length;o<n;o+=1)e[o]>r&&(t.push(o),o+=1e4);return t}function y(e){var r=[];return e.forEach(function(t,o){for(var n=function(x){var g=e[o+x]-t,_=r.some(function(h){if(h.interval===g)return h.count+=1});_||r.push({interval:g,count:1})},u=0;u<10;u+=1)n(u)}),r}function O(e){return function(r){var t=[];return r.forEach(function(o){if(o.interval!==0){for(var n=60/(o.interval/e);n<90;)n*=2;for(;n>180;)n/=2;n=Math.round(n);var u=t.some(function(f){if(f.tempo===n)return f.count+=o.count});u||t.push({tempo:n,count:o.count})}}),t}}return v}var p,b;function q(){return b||(b=1,p=k().default),p}var m=q();const A=P(m),D=j({__proto__:null,default:A},[m]);export{D as i};
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-CTiqZ7XQ.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.101",
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.101",
37
+ "@hyperframes/player": "0.6.101",
38
+ "@hyperframes/sdk": "0.6.101"
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.101"
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>
@@ -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,4 +1,5 @@
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";
4
5
 
@@ -55,4 +56,6 @@ export interface GsapScriptCommitsParams {
55
56
  onCacheInvalidate: () => void;
56
57
  onFileContentChanged?: (path: string, content: string) => void;
57
58
  showToast: (message: string, tone?: "error" | "info") => void;
59
+ /** Stage 7 Step 3b: SDK session for shadow GSAP dispatch (server stays authoritative). */
60
+ sdkSession?: Composition | null;
58
61
  }
@@ -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 {
@@ -9,7 +9,7 @@ import { useAskAgentModal } from "./useAskAgentModal";
9
9
  import { useDomSelection } from "./useDomSelection";
10
10
  import { usePreviewInteraction } from "./usePreviewInteraction";
11
11
  import { useDomEditCommits } from "./useDomEditCommits";
12
- import { runShadowDispatch } from "../utils/sdkShadow";
12
+ import { runShadowDispatch, runShadowDelete } from "../utils/sdkShadow";
13
13
  import { useGsapScriptCommits } from "./useGsapScriptCommits";
14
14
  import { useGsapCacheVersion } from "./useGsapTweenCache";
15
15
  import { useDomEditWiring } from "./useDomEditWiring";
@@ -194,6 +194,7 @@ export function useDomEditSession({
194
194
  onCacheInvalidate: bumpGsapCache,
195
195
  onFileContentChanged: updateEditingFileContent,
196
196
  showToast,
197
+ sdkSession,
197
198
  });
198
199
 
199
200
  // ── DOM commit handlers ──
@@ -235,6 +236,7 @@ export function useDomEditSession({
235
236
  onDomEditPersisted: sdkSession
236
237
  ? (sel, ops) => runShadowDispatch(sdkSession, sel, ops)
237
238
  : undefined,
239
+ onElementDeleted: sdkSession ? (sel) => runShadowDelete(sdkSession, sel.hfId) : undefined,
238
240
  });
239
241
 
240
242
  // ── Wiring: selection sync, GSAP cache, preview sync, selection handlers ──
@@ -263,6 +265,9 @@ export function useDomEditSession({
263
265
  handleGsapRemoveAllKeyframes,
264
266
  handleResetSelectedElementKeyframes,
265
267
  } = useDomEditWiring({
268
+ // Pre-existing prop-drilling clone (same param set forwarded to
269
+ // useDomEditWiring); surfaced by this PR's adjacent edits, not introduced.
270
+ // fallow-ignore-next-line code-duplication
266
271
  projectId,
267
272
  activeCompPath,
268
273
  domEditSelection,
@@ -1,5 +1,4 @@
1
1
  import { useCallback } from "react";
2
- import { STUDIO_GSAP_DRAG_INTERCEPT_ENABLED } from "../components/editor/manualEditingAvailability";
3
2
  import { getDomEditTargetKey, type DomEditSelection } from "../components/editor/domEditing";
4
3
  import {
5
4
  applyStudioPathOffset,
@@ -19,45 +18,11 @@ import {
19
18
  } from "../components/editor/manualEditsDomPatches";
20
19
  import type { DomEditGroupPathOffsetCommit } from "../components/editor/DomEditOverlay";
21
20
  import type { PatchOperation } from "../utils/sourcePatcher";
21
+ import { isElementGsapTargeted } from "./gsapTargetCache";
22
22
 
23
23
  export const GSAP_CSS_FALLBACK_BLOCKED_MESSAGE =
24
24
  "This element is GSAP-animated — dragging via CSS would corrupt keyframes";
25
25
 
26
- // ── Helpers ──
27
-
28
- type TimelineLike = { getChildren?: (nested: boolean) => Array<{ targets?: () => Element[] }> };
29
-
30
- // fallow-ignore-next-line complexity
31
- function isElementGsapTargeted(iframe: HTMLIFrameElement | null, element: HTMLElement): boolean {
32
- // When the GSAP drag intercept is disabled for debugging, treat every
33
- // element as un-targeted so commits take the plain CSS persist path.
34
- if (!STUDIO_GSAP_DRAG_INTERCEPT_ENABLED) return false;
35
- if (!iframe?.contentWindow) return false;
36
- let timelines: Record<string, TimelineLike> | undefined;
37
- try {
38
- timelines = (iframe.contentWindow as Window & { __timelines?: Record<string, TimelineLike> })
39
- .__timelines;
40
- } catch {
41
- return false;
42
- }
43
- if (!timelines) return false;
44
- const id = element.id;
45
- for (const tl of Object.values(timelines)) {
46
- if (!tl?.getChildren) continue;
47
- try {
48
- for (const child of tl.getChildren(true)) {
49
- if (!child.targets) continue;
50
- for (const t of child.targets()) {
51
- if (t === element || (id && t.id === id)) return true;
52
- }
53
- }
54
- } catch {
55
- continue;
56
- }
57
- }
58
- return false;
59
- }
60
-
61
26
  // ── Hook ──
62
27
 
63
28
  interface UseDomGeometryCommitsParams {
@@ -31,6 +31,8 @@ interface UseElementLifecycleOpsParams {
31
31
  patches: PatchOperation[],
32
32
  options: { label: string; coalesceKey: string; skipRefresh?: boolean },
33
33
  ) => Promise<void>;
34
+ /** Stage 7 Step 3b: called after a successful server-side element delete (shadow). */
35
+ onElementDeleted?: (selection: DomEditSelection) => void;
34
36
  }
35
37
 
36
38
  export function useElementLifecycleOps({
@@ -43,6 +45,7 @@ export function useElementLifecycleOps({
43
45
  reloadPreview,
44
46
  clearDomSelection,
45
47
  commitPositionPatchToHtml,
48
+ onElementDeleted,
46
49
  }: UseElementLifecycleOpsParams) {
47
50
  // fallow-ignore-next-line complexity
48
51
  const handleDomEditElementDelete = useCallback(
@@ -103,6 +106,7 @@ export function useElementLifecycleOps({
103
106
  clearDomSelection();
104
107
  usePlayerStore.getState().setSelectedElementId(null);
105
108
  reloadPreview();
109
+ onElementDeleted?.(selection);
106
110
  showToast(`Deleted ${label}. Use Undo to restore it.`, "info");
107
111
  } catch (error) {
108
112
  const message = error instanceof Error ? error.message : "Failed to delete element";
@@ -114,6 +118,7 @@ export function useElementLifecycleOps({
114
118
  clearDomSelection,
115
119
  domEditSaveTimestampRef,
116
120
  editHistory.recordEdit,
121
+ onElementDeleted,
117
122
  projectIdRef,
118
123
  reloadPreview,
119
124
  showToast,
@@ -1,6 +1,8 @@
1
1
  import { useCallback } from "react";
2
+ import type { Composition, GsapTweenSpec } from "@hyperframes/sdk";
2
3
  import type { DomEditSelection } from "../components/editor/domEditingTypes";
3
4
  import { roundTo3 } from "../utils/rounding";
5
+ import { runShadowGsapTween } from "../utils/sdkShadow";
4
6
  import {
5
7
  assignGsapTargetAutoIdIfNeeded,
6
8
  ensureElementAddressable,
@@ -13,6 +15,8 @@ interface GsapAnimationOpsParams {
13
15
  commitMutation: CommitMutation;
14
16
  commitMutationSafely: SafeGsapCommitMutation;
15
17
  showToast: (message: string, tone?: "error" | "info") => void;
18
+ /** Stage 7 Step 3b: SDK session for shadow GSAP dispatch (server stays authoritative). */
19
+ sdkSession?: Composition | null;
16
20
  }
17
21
 
18
22
  export function useGsapAnimationOps({
@@ -21,6 +25,7 @@ export function useGsapAnimationOps({
21
25
  commitMutation,
22
26
  commitMutationSafely,
23
27
  showToast,
28
+ sdkSession,
24
29
  }: GsapAnimationOpsParams) {
25
30
  const updateGsapMeta = useCallback(
26
31
  (
@@ -62,7 +67,10 @@ export function useGsapAnimationOps({
62
67
  [commitMutation],
63
68
  );
64
69
 
70
+ // Pre-existing complexity (auto-id assignment + per-method defaults); this PR
71
+ // adds only a guarded shadow-op construction at the tail.
65
72
  const addGsapAnimation = useCallback(
73
+ // fallow-ignore-next-line complexity
66
74
  async (
67
75
  selection: DomEditSelection,
68
76
  method: "to" | "from" | "set" | "fromTo",
@@ -109,8 +117,25 @@ export function useGsapAnimationOps({
109
117
  },
110
118
  { label: `Add GSAP ${method} animation` },
111
119
  );
120
+
121
+ // Shadow: dispatch the equivalent addGsapTween to the SDK (server stays
122
+ // authoritative). "set" has no SDK method, so it is not shadowed.
123
+ // ponytail: only add is shadowed — delete/update key on the server's
124
+ // animationId, which doesn't resolve in the SDK's independent id-space.
125
+ if (sdkSession && selection.hfId && method !== "set") {
126
+ const tween: GsapTweenSpec = {
127
+ method,
128
+ position,
129
+ duration,
130
+ ease: "power2.out",
131
+ ...(method === "fromTo"
132
+ ? { fromProperties: { opacity: 0 }, toProperties: toDefaults[method] }
133
+ : { properties: toDefaults[method] ?? { opacity: 1 } }),
134
+ };
135
+ runShadowGsapTween(sdkSession, { kind: "add", target: selection.hfId, tween });
136
+ }
112
137
  },
113
- [activeCompPath, commitMutation, projectIdRef, showToast],
138
+ [activeCompPath, commitMutation, projectIdRef, showToast, sdkSession],
114
139
  );
115
140
 
116
141
  return {