@hyperframes/studio 0.6.110 → 0.6.111
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.
- package/dist/assets/index-B7S86vK1.js +370 -0
- package/dist/assets/index-DP8pPIk2.css +1 -0
- package/dist/assets/{index-CfiyaR7G.js → index-_IV-vm9l.js} +1 -1
- package/dist/assets/{index-CXy_mWnP.js → index-x0c2-zQN.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +8 -5
- package/src/App.tsx +133 -141
- package/src/components/StudioHeader.tsx +44 -0
- package/src/components/StudioOverlays.tsx +70 -0
- package/src/components/editor/SourceEditor.tsx +19 -16
- package/src/components/editor/manualEditingAvailability.ts +25 -7
- package/src/components/storyboard/FramePoster.tsx +56 -0
- package/src/components/storyboard/StoryboardDirection.tsx +45 -0
- package/src/components/storyboard/StoryboardFrameFocus.tsx +262 -0
- package/src/components/storyboard/StoryboardFrameTile.tsx +88 -0
- package/src/components/storyboard/StoryboardGrid.tsx +33 -0
- package/src/components/storyboard/StoryboardLoaded.tsx +136 -0
- package/src/components/storyboard/StoryboardScriptPanel.tsx +26 -0
- package/src/components/storyboard/StoryboardSourceEditor.tsx +231 -0
- package/src/components/storyboard/StoryboardStatusLegend.tsx +21 -0
- package/src/components/storyboard/StoryboardView.tsx +78 -0
- package/src/components/storyboard/frameStatus.ts +36 -0
- package/src/contexts/ViewModeContext.tsx +98 -0
- package/src/hooks/gsapScriptCommitTypes.ts +4 -7
- package/src/hooks/sdkSelfWriteRegistry.test.ts +67 -0
- package/src/hooks/sdkSelfWriteRegistry.ts +77 -0
- package/src/hooks/timelineEditingHelpers.ts +2 -0
- package/src/hooks/useAppHotkeys.ts +20 -0
- package/src/hooks/useDomEditCommits.ts +43 -14
- package/src/hooks/useDomEditSession.test.ts +41 -0
- package/src/hooks/useDomEditSession.ts +38 -6
- package/src/hooks/useDomGeometryCommits.ts +5 -9
- package/src/hooks/useElementLifecycleOps.ts +30 -0
- package/src/hooks/useGsapAnimationOps.ts +78 -51
- package/src/hooks/useGsapKeyframeOps.ts +127 -43
- package/src/hooks/useGsapPropertyDebounce.test.ts +70 -0
- package/src/hooks/useGsapPropertyDebounce.ts +201 -23
- package/src/hooks/useGsapPropertyDebounceFlush.test.ts +85 -0
- package/src/hooks/useGsapScriptCommits.ts +95 -40
- package/src/hooks/useSdkSession.test.ts +12 -0
- package/src/hooks/useSdkSession.ts +91 -25
- package/src/hooks/useStoryboard.ts +80 -0
- package/src/hooks/useTimelineEditing.ts +163 -68
- package/src/utils/gsapSoftReload.ts +14 -0
- package/src/utils/sdkCutover.gate.test.ts +61 -0
- package/src/utils/sdkCutover.test.ts +839 -0
- package/src/utils/sdkCutover.ts +465 -0
- package/src/utils/sdkOpMapping.ts +43 -0
- package/src/utils/sdkResolverShadow.test.ts +366 -0
- package/src/utils/sdkResolverShadow.ts +313 -0
- package/dist/assets/index-1C8oFiPi.css +0 -1
- package/dist/assets/index-D-3sGz65.js +0 -296
- package/src/utils/sdkShadow.test.ts +0 -606
- package/src/utils/sdkShadow.ts +0 -517
- package/src/utils/sdkShadowGsapFidelity.ts +0 -296
- package/src/utils/sdkShadowGsapKeyframe.test.ts +0 -265
- package/src/utils/sdkShadowGsapKeyframe.ts +0 -257
- package/src/utils/sdkShadowNumeric.ts +0 -11
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import type { MutableRefObject } from "react";
|
|
2
|
+
import type { Composition, GsapTweenSpec } from "@hyperframes/sdk";
|
|
3
|
+
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
4
|
+
import type { EditHistoryKind } from "./editHistory";
|
|
5
|
+
import type { PatchOperation } from "./sourcePatcher";
|
|
6
|
+
import { STUDIO_SDK_CUTOVER_ENABLED } from "../components/editor/manualEditingAvailability";
|
|
7
|
+
import { trackStudioEvent } from "./studioTelemetry";
|
|
8
|
+
import { markSelfWrite } from "../hooks/sdkSelfWriteRegistry";
|
|
9
|
+
import { patchOpsToSdkEditOps } from "./sdkOpMapping";
|
|
10
|
+
import { recordResolverParity, recordAnimationResolverParity } from "./sdkResolverShadow";
|
|
11
|
+
|
|
12
|
+
const CUTOVER_OP_TYPES = new Set<PatchOperation["type"]>([
|
|
13
|
+
"inline-style",
|
|
14
|
+
"text-content",
|
|
15
|
+
"attribute",
|
|
16
|
+
"html-attribute",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
// Mirrors the SDK's RESERVED_ATTRS (mutate.ts): a bare `attribute` op is
|
|
20
|
+
// force-prefixed `data-`, so e.g. property "end" → "data-end", which the SDK
|
|
21
|
+
// rejects with a throw. Detect that up front and decline the whole batch so it
|
|
22
|
+
// takes the server path cleanly, instead of throwing inside the dispatch and
|
|
23
|
+
// silently falling back per op.
|
|
24
|
+
// ponytail: small mirror of the SDK set; if the SDK adds a reserved attr, a new
|
|
25
|
+
// op for it just reverts to the (working) throw→fallback path until synced.
|
|
26
|
+
const RESERVED_CUTOVER_ATTRS = new Set<string>([
|
|
27
|
+
"data-hf-id",
|
|
28
|
+
"data-composition-id",
|
|
29
|
+
"data-width",
|
|
30
|
+
"data-height",
|
|
31
|
+
"data-start",
|
|
32
|
+
"data-end",
|
|
33
|
+
"data-track-index",
|
|
34
|
+
"data-hold-start",
|
|
35
|
+
"data-hold-end",
|
|
36
|
+
"data-hold-fill",
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
function sdkAttrName(op: PatchOperation): string | null {
|
|
40
|
+
if (op.type === "attribute") {
|
|
41
|
+
return op.property.startsWith("data-") ? op.property : `data-${op.property}`;
|
|
42
|
+
}
|
|
43
|
+
if (op.type === "html-attribute") return op.property;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function mapsToReservedAttr(op: PatchOperation): boolean {
|
|
48
|
+
const name = sdkAttrName(op);
|
|
49
|
+
// Lowercase to match the SDK's validateSetAttribute (it lowercases before the
|
|
50
|
+
// reserved check), so "DATA-START" is declined up front too; covers both
|
|
51
|
+
// `attribute` (prefixed) and `html-attribute` (raw) ops.
|
|
52
|
+
return name !== null && RESERVED_CUTOVER_ATTRS.has(name.toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function shouldUseSdkCutover(
|
|
56
|
+
flagEnabled: boolean,
|
|
57
|
+
hasSession: boolean,
|
|
58
|
+
hfId: string | null | undefined,
|
|
59
|
+
ops: PatchOperation[],
|
|
60
|
+
): boolean {
|
|
61
|
+
return (
|
|
62
|
+
flagEnabled &&
|
|
63
|
+
hasSession &&
|
|
64
|
+
!!hfId &&
|
|
65
|
+
ops.length > 0 &&
|
|
66
|
+
ops.every((o) => CUTOVER_OP_TYPES.has(o.type)) &&
|
|
67
|
+
!ops.some(mapsToReservedAttr)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CutoverDeps {
|
|
72
|
+
editHistory: {
|
|
73
|
+
recordEdit: (entry: {
|
|
74
|
+
label: string;
|
|
75
|
+
kind: EditHistoryKind;
|
|
76
|
+
coalesceKey?: string;
|
|
77
|
+
files: Record<string, { before: string; after: string }>;
|
|
78
|
+
}) => Promise<void>;
|
|
79
|
+
};
|
|
80
|
+
writeProjectFile: (path: string, content: string) => Promise<void>;
|
|
81
|
+
reloadPreview: () => void;
|
|
82
|
+
domEditSaveTimestampRef: MutableRefObject<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Optional post-write refresh. When provided, it REPLACES the default
|
|
85
|
+
* reloadPreview() — the GSAP path passes one that soft-reloads (preserving
|
|
86
|
+
* the playhead) and invalidates the keyframe/gsap panel cache. Receives the
|
|
87
|
+
* serialized document just written.
|
|
88
|
+
*/
|
|
89
|
+
refresh?: (after: string) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Path of the composition the SDK session was opened for. The session models
|
|
92
|
+
* ONLY this file (serialize() emits the whole active composition), so any edit
|
|
93
|
+
* whose targetPath differs (a sub-composition file) must take the server path
|
|
94
|
+
* — otherwise we'd write the full active-comp serialization into that file.
|
|
95
|
+
*/
|
|
96
|
+
compositionPath?: string | null;
|
|
97
|
+
/**
|
|
98
|
+
* Optional per-key task serializer (the same `gsap-file:${file}` serializer the
|
|
99
|
+
* legacy `commitMutation` uses). When provided, every GSAP-op persist routes its
|
|
100
|
+
* read-serialize → dispatch → serialize → write through it so two concurrent
|
|
101
|
+
* same-file flushes can't interleave their read-modify-write and lose an edit.
|
|
102
|
+
* Absent (e.g. in unit tests) → ops run unserialized as before.
|
|
103
|
+
*/
|
|
104
|
+
serialize?: <T>(key: string, task: () => Promise<T>) => Promise<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Optional reader for the on-disk content of targetPath. Timing/GSAP persists
|
|
107
|
+
* use it to capture the EXACT prior bytes as the undo-history `before`, so undo
|
|
108
|
+
* restores the file verbatim instead of a normalized SDK re-emit (which would
|
|
109
|
+
* reformat the whole file). The style/delete paths already thread originalContent
|
|
110
|
+
* in explicitly; this gives timing/GSAP parity without touching every call site.
|
|
111
|
+
* Absent → falls back to the SDK's pre-edit serialize() (the prior behavior).
|
|
112
|
+
*/
|
|
113
|
+
readProjectFile?: (path: string) => Promise<string>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Capture the undo-history `before` baseline for timing/GSAP persists: the exact
|
|
118
|
+
* on-disk bytes when a reader is available (so undo restores them verbatim),
|
|
119
|
+
* falling back to the SDK's pre-edit serialization when it isn't. Never throws —
|
|
120
|
+
* a failed read degrades to the serialized fallback rather than aborting the edit.
|
|
121
|
+
*/
|
|
122
|
+
async function captureOnDiskBefore(
|
|
123
|
+
deps: CutoverDeps,
|
|
124
|
+
targetPath: string,
|
|
125
|
+
serializedFallback: string,
|
|
126
|
+
): Promise<string> {
|
|
127
|
+
if (!deps.readProjectFile) return serializedFallback;
|
|
128
|
+
try {
|
|
129
|
+
return await deps.readProjectFile(targetPath);
|
|
130
|
+
} catch {
|
|
131
|
+
return serializedFallback;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** True when targetPath isn't the composition the SDK session models. */
|
|
136
|
+
function wrongCompositionFile(deps: CutoverDeps, targetPath: string): boolean {
|
|
137
|
+
return deps.compositionPath != null && targetPath !== deps.compositionPath;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface CutoverOptions {
|
|
141
|
+
label?: string;
|
|
142
|
+
coalesceKey?: string;
|
|
143
|
+
/** Skip the preview reload (mirrors the server path's skipRefresh). */
|
|
144
|
+
skipRefresh?: boolean;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ponytail: internal; export only if a third caller appears.
|
|
148
|
+
// `after` is serialized once by the caller (which also did the no-op check
|
|
149
|
+
// against its pre-dispatch snapshot), so this never re-serializes.
|
|
150
|
+
async function persistSdkSerialize(
|
|
151
|
+
after: string,
|
|
152
|
+
targetPath: string,
|
|
153
|
+
originalContent: string,
|
|
154
|
+
deps: CutoverDeps,
|
|
155
|
+
options?: CutoverOptions,
|
|
156
|
+
): Promise<void> {
|
|
157
|
+
deps.domEditSaveTimestampRef.current = Date.now();
|
|
158
|
+
// Tag this write with the exact content (by hash) so the file-change
|
|
159
|
+
// reload-suppression can recognize its own echo by IDENTITY, not just a 2 s
|
|
160
|
+
// clock — an undo write (different bytes, not registered here) then always
|
|
161
|
+
// reloads instead of being swallowed by the time window.
|
|
162
|
+
markSelfWrite(targetPath, after);
|
|
163
|
+
await deps.writeProjectFile(targetPath, after);
|
|
164
|
+
await deps.editHistory.recordEdit({
|
|
165
|
+
label: options?.label ?? "Edit layer",
|
|
166
|
+
kind: "manual",
|
|
167
|
+
...(options?.coalesceKey ? { coalesceKey: options.coalesceKey } : {}),
|
|
168
|
+
files: { [targetPath]: { before: originalContent, after } },
|
|
169
|
+
});
|
|
170
|
+
if (deps.refresh) deps.refresh(after);
|
|
171
|
+
else if (!options?.skipRefresh) deps.reloadPreview();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function sdkCutoverPersist(
|
|
175
|
+
selection: DomEditSelection,
|
|
176
|
+
ops: PatchOperation[],
|
|
177
|
+
originalContent: string,
|
|
178
|
+
targetPath: string,
|
|
179
|
+
sdkSession: Composition | null | undefined,
|
|
180
|
+
deps: CutoverDeps,
|
|
181
|
+
options?: CutoverOptions,
|
|
182
|
+
): Promise<boolean> {
|
|
183
|
+
if (!shouldUseSdkCutover(STUDIO_SDK_CUTOVER_ENABLED, !!sdkSession, selection.hfId, ops))
|
|
184
|
+
return false;
|
|
185
|
+
if (!sdkSession) return false;
|
|
186
|
+
const hfId = selection.hfId;
|
|
187
|
+
if (!hfId) return false;
|
|
188
|
+
if (!sdkSession.getElement(hfId)) return false;
|
|
189
|
+
if (wrongCompositionFile(deps, targetPath)) return false;
|
|
190
|
+
try {
|
|
191
|
+
const before = sdkSession.serialize();
|
|
192
|
+
sdkSession.batch(() => {
|
|
193
|
+
for (const editOp of patchOpsToSdkEditOps(hfId, ops)) {
|
|
194
|
+
sdkSession.dispatch(editOp);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const after = sdkSession.serialize();
|
|
198
|
+
if (after === before) return false;
|
|
199
|
+
await persistSdkSerialize(after, targetPath, originalContent, deps, options);
|
|
200
|
+
trackStudioEvent("sdk_cutover_success", { hfId, opCount: ops.length });
|
|
201
|
+
return true;
|
|
202
|
+
} catch (err) {
|
|
203
|
+
trackStudioEvent("sdk_cutover_fallback", {
|
|
204
|
+
hfId: selection.hfId ?? null,
|
|
205
|
+
error: String(err),
|
|
206
|
+
});
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export async function sdkTimingPersist(
|
|
212
|
+
hfId: string,
|
|
213
|
+
targetPath: string,
|
|
214
|
+
timingUpdate: { start?: number; duration?: number; trackIndex?: number },
|
|
215
|
+
sdkSession: Composition | null | undefined,
|
|
216
|
+
deps: CutoverDeps,
|
|
217
|
+
options?: CutoverOptions,
|
|
218
|
+
): Promise<boolean> {
|
|
219
|
+
// Resolver tripwire — runs BEFORE the cutover gate (decoupled): records when
|
|
220
|
+
// the SDK can't resolve a target the server timing path is addressing.
|
|
221
|
+
recordResolverParity(sdkSession, hfId, "setTiming");
|
|
222
|
+
// Dark-launch gate: without this, timing cutover runs whenever an SDK session
|
|
223
|
+
// exists (it always does, for shadow/selection) — flipping the flag OFF would
|
|
224
|
+
// NOT disable it. Gate here so flag-off routes back to the legacy server path.
|
|
225
|
+
if (!STUDIO_SDK_CUTOVER_ENABLED) return false;
|
|
226
|
+
if (!sdkSession || !sdkSession.getElement(hfId)) return false;
|
|
227
|
+
if (wrongCompositionFile(deps, targetPath)) return false;
|
|
228
|
+
try {
|
|
229
|
+
const serializedBefore = sdkSession.serialize();
|
|
230
|
+
sdkSession.batch(() => sdkSession.setTiming(hfId, timingUpdate));
|
|
231
|
+
const after = sdkSession.serialize();
|
|
232
|
+
if (after === serializedBefore) return false;
|
|
233
|
+
// Undo baseline = exact on-disk bytes (matching the style/delete paths), so
|
|
234
|
+
// undoing a timing edit restores the file verbatim instead of a normalized
|
|
235
|
+
// full-DOM re-emit. Falls back to serializedBefore when no reader is wired.
|
|
236
|
+
const undoBefore = await captureOnDiskBefore(deps, targetPath, serializedBefore);
|
|
237
|
+
await persistSdkSerialize(after, targetPath, undoBefore, deps, options);
|
|
238
|
+
trackStudioEvent("sdk_cutover_success", { hfId, opCount: 1 });
|
|
239
|
+
return true;
|
|
240
|
+
} catch (err) {
|
|
241
|
+
trackStudioEvent("sdk_cutover_fallback", { hfId, error: String(err) });
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
type SdkGsapTweenOp =
|
|
247
|
+
| { kind: "add"; target: string; spec: GsapTweenSpec }
|
|
248
|
+
| { kind: "set"; animationId: string; properties: Partial<GsapTweenSpec> }
|
|
249
|
+
| { kind: "remove"; animationId: string };
|
|
250
|
+
|
|
251
|
+
export function sdkGsapTweenPersist(
|
|
252
|
+
targetPath: string,
|
|
253
|
+
op: SdkGsapTweenOp,
|
|
254
|
+
sdkSession: Composition | null | undefined,
|
|
255
|
+
deps: CutoverDeps,
|
|
256
|
+
options?: CutoverOptions,
|
|
257
|
+
): Promise<boolean> {
|
|
258
|
+
// Resolver tripwire — runs BEFORE this function's own cutover gate (decoupled).
|
|
259
|
+
// add targets an element (element-resolution parity); set/remove target an
|
|
260
|
+
// animationId (animation-resolution parity). Done here, not via
|
|
261
|
+
// dispatchGsapOpAndPersist's resolverTarget, because the gate below returns
|
|
262
|
+
// before that call when cutover is off.
|
|
263
|
+
if (op.kind === "add") recordResolverParity(sdkSession, op.target, "addGsapTween");
|
|
264
|
+
else
|
|
265
|
+
recordAnimationResolverParity(
|
|
266
|
+
sdkSession,
|
|
267
|
+
op.animationId,
|
|
268
|
+
op.kind === "set" ? "setGsapTween" : "removeGsapTween",
|
|
269
|
+
);
|
|
270
|
+
// Leading dark-launch gate so flag-off does no SDK touch (getElement) at all —
|
|
271
|
+
// matches the other three chokepoints' discipline.
|
|
272
|
+
if (!STUDIO_SDK_CUTOVER_ENABLED) return Promise.resolve(false);
|
|
273
|
+
if (op.kind === "add" && sdkSession && !sdkSession.getElement(op.target))
|
|
274
|
+
return Promise.resolve(false);
|
|
275
|
+
// dispatchGsapOpAndPersist returns false on before===after — that catches stale
|
|
276
|
+
// animationIds and unsupported shapes (e.g. from-prop on a plain tween), falling
|
|
277
|
+
// back to the server path. This subsumes explicit existence guards for set/remove.
|
|
278
|
+
return dispatchGsapOpAndPersist(targetPath, sdkSession, deps, options, (s) => {
|
|
279
|
+
s.batch(() => {
|
|
280
|
+
if (op.kind === "add") {
|
|
281
|
+
s.addGsapTween(op.target, op.spec);
|
|
282
|
+
} else if (op.kind === "set") {
|
|
283
|
+
s.setGsapTween(op.animationId, op.properties);
|
|
284
|
+
} else {
|
|
285
|
+
s.removeGsapTween(op.animationId);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function dispatchGsapOpAndPersist(
|
|
292
|
+
targetPath: string,
|
|
293
|
+
sdkSession: Composition | null | undefined,
|
|
294
|
+
deps: CutoverDeps,
|
|
295
|
+
options: CutoverOptions | undefined,
|
|
296
|
+
dispatch: (s: Composition) => void,
|
|
297
|
+
resolverTarget?: { animationId: string; opLabel: string },
|
|
298
|
+
): Promise<boolean> {
|
|
299
|
+
// Resolver tripwire — runs BEFORE the cutover gate (decoupled): records when
|
|
300
|
+
// the SDK can't resolve the animationId the server GSAP path is addressing.
|
|
301
|
+
if (resolverTarget) {
|
|
302
|
+
recordAnimationResolverParity(sdkSession, resolverTarget.animationId, resolverTarget.opLabel);
|
|
303
|
+
}
|
|
304
|
+
// Dark-launch gate (shared chokepoint for every GSAP-op cutover persist):
|
|
305
|
+
// flag OFF → return false → caller falls back to the legacy server path.
|
|
306
|
+
if (!STUDIO_SDK_CUTOVER_ENABLED) return false;
|
|
307
|
+
if (!sdkSession) return false;
|
|
308
|
+
if (wrongCompositionFile(deps, targetPath)) return false;
|
|
309
|
+
const session = sdkSession;
|
|
310
|
+
// Route the whole read-serialize → dispatch → serialize → write through the
|
|
311
|
+
// per-file serializer (when provided) so overlapping same-file flushes can't
|
|
312
|
+
// interleave their read-modify-write and drop an edit, matching the legacy
|
|
313
|
+
// commitMutation path's `gsap-file:${file}` serialization.
|
|
314
|
+
const run = async (): Promise<boolean> => {
|
|
315
|
+
try {
|
|
316
|
+
const serializedBefore = session.serialize();
|
|
317
|
+
dispatch(session);
|
|
318
|
+
const after = session.serialize();
|
|
319
|
+
if (after === serializedBefore) return false;
|
|
320
|
+
// Undo baseline = exact on-disk bytes (matching the style/delete paths), so
|
|
321
|
+
// undoing a GSAP edit restores the file verbatim instead of a normalized
|
|
322
|
+
// full-DOM re-emit. Falls back to serializedBefore when no reader is wired.
|
|
323
|
+
const undoBefore = await captureOnDiskBefore(deps, targetPath, serializedBefore);
|
|
324
|
+
await persistSdkSerialize(after, targetPath, undoBefore, deps, options);
|
|
325
|
+
trackStudioEvent("sdk_cutover_success", { opCount: 1 });
|
|
326
|
+
return true;
|
|
327
|
+
} catch (err) {
|
|
328
|
+
trackStudioEvent("sdk_cutover_fallback", { error: String(err) });
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
return deps.serialize ? deps.serialize(`gsap-file:${targetPath}`, run) : run();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function sdkGsapKeyframePersist(
|
|
336
|
+
targetPath: string,
|
|
337
|
+
animationId: string,
|
|
338
|
+
position: number,
|
|
339
|
+
value: Record<string, unknown>,
|
|
340
|
+
sdkSession: Composition | null | undefined,
|
|
341
|
+
deps: CutoverDeps,
|
|
342
|
+
options?: CutoverOptions,
|
|
343
|
+
): Promise<boolean> {
|
|
344
|
+
return dispatchGsapOpAndPersist(
|
|
345
|
+
targetPath,
|
|
346
|
+
sdkSession,
|
|
347
|
+
deps,
|
|
348
|
+
options,
|
|
349
|
+
(s) => s.batch(() => s.dispatch({ type: "addGsapKeyframe", animationId, position, value })),
|
|
350
|
+
{ animationId, opLabel: "addGsapKeyframe" },
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function sdkGsapRemoveKeyframePersist(
|
|
355
|
+
targetPath: string,
|
|
356
|
+
animationId: string,
|
|
357
|
+
percentage: number,
|
|
358
|
+
sdkSession: Composition | null | undefined,
|
|
359
|
+
deps: CutoverDeps,
|
|
360
|
+
options?: CutoverOptions,
|
|
361
|
+
): Promise<boolean> {
|
|
362
|
+
return dispatchGsapOpAndPersist(
|
|
363
|
+
targetPath,
|
|
364
|
+
sdkSession,
|
|
365
|
+
deps,
|
|
366
|
+
options,
|
|
367
|
+
(s) => s.dispatch({ type: "removeGsapKeyframe", animationId, percentage }),
|
|
368
|
+
{ animationId, opLabel: "removeGsapKeyframe" },
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function sdkGsapRemovePropertyPersist(
|
|
373
|
+
targetPath: string,
|
|
374
|
+
animationId: string,
|
|
375
|
+
property: string,
|
|
376
|
+
from: boolean,
|
|
377
|
+
sdkSession: Composition | null | undefined,
|
|
378
|
+
deps: CutoverDeps,
|
|
379
|
+
options?: CutoverOptions,
|
|
380
|
+
): Promise<boolean> {
|
|
381
|
+
return dispatchGsapOpAndPersist(
|
|
382
|
+
targetPath,
|
|
383
|
+
sdkSession,
|
|
384
|
+
deps,
|
|
385
|
+
options,
|
|
386
|
+
(s) => s.dispatch({ type: "removeGsapProperty", animationId, property, from }),
|
|
387
|
+
{ animationId, opLabel: "removeGsapProperty" },
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export function sdkGsapDeleteAllForSelectorPersist(
|
|
392
|
+
targetPath: string,
|
|
393
|
+
selector: string,
|
|
394
|
+
sdkSession: Composition | null | undefined,
|
|
395
|
+
deps: CutoverDeps,
|
|
396
|
+
options?: CutoverOptions,
|
|
397
|
+
): Promise<boolean> {
|
|
398
|
+
return dispatchGsapOpAndPersist(targetPath, sdkSession, deps, options, (s) =>
|
|
399
|
+
s.dispatch({ type: "deleteAllForSelector", selector }),
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function sdkGsapRemoveAllKeyframesPersist(
|
|
404
|
+
targetPath: string,
|
|
405
|
+
animationId: string,
|
|
406
|
+
sdkSession: Composition | null | undefined,
|
|
407
|
+
deps: CutoverDeps,
|
|
408
|
+
options?: CutoverOptions,
|
|
409
|
+
): Promise<boolean> {
|
|
410
|
+
return dispatchGsapOpAndPersist(
|
|
411
|
+
targetPath,
|
|
412
|
+
sdkSession,
|
|
413
|
+
deps,
|
|
414
|
+
options,
|
|
415
|
+
(s) => s.dispatch({ type: "removeAllKeyframes", animationId }),
|
|
416
|
+
{ animationId, opLabel: "removeAllKeyframes" },
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function sdkGsapConvertToKeyframesPersist(
|
|
421
|
+
targetPath: string,
|
|
422
|
+
animationId: string,
|
|
423
|
+
resolvedFromValues: Record<string, number | string> | undefined,
|
|
424
|
+
sdkSession: Composition | null | undefined,
|
|
425
|
+
deps: CutoverDeps,
|
|
426
|
+
options?: CutoverOptions,
|
|
427
|
+
): Promise<boolean> {
|
|
428
|
+
return dispatchGsapOpAndPersist(
|
|
429
|
+
targetPath,
|
|
430
|
+
sdkSession,
|
|
431
|
+
deps,
|
|
432
|
+
options,
|
|
433
|
+
(s) => s.dispatch({ type: "convertToKeyframes", animationId, resolvedFromValues }),
|
|
434
|
+
{ animationId, opLabel: "convertToKeyframes" },
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export async function sdkDeletePersist(
|
|
439
|
+
hfId: string,
|
|
440
|
+
originalContent: string,
|
|
441
|
+
targetPath: string,
|
|
442
|
+
sdkSession: Composition | null | undefined,
|
|
443
|
+
deps: CutoverDeps,
|
|
444
|
+
): Promise<boolean> {
|
|
445
|
+
// Resolver tripwire — runs BEFORE the cutover gate (decoupled).
|
|
446
|
+
recordResolverParity(sdkSession, hfId, "removeElement");
|
|
447
|
+
// Dark-launch gate: flag OFF → legacy server delete path.
|
|
448
|
+
if (!STUDIO_SDK_CUTOVER_ENABLED) return false;
|
|
449
|
+
if (!sdkSession || !sdkSession.getElement(hfId)) return false;
|
|
450
|
+
if (wrongCompositionFile(deps, targetPath)) return false;
|
|
451
|
+
try {
|
|
452
|
+
const before = sdkSession.serialize();
|
|
453
|
+
sdkSession.batch(() => sdkSession.removeElement(hfId));
|
|
454
|
+
const after = sdkSession.serialize();
|
|
455
|
+
if (after === before) return false;
|
|
456
|
+
await persistSdkSerialize(after, targetPath, originalContent, deps, {
|
|
457
|
+
label: "Delete element",
|
|
458
|
+
});
|
|
459
|
+
trackStudioEvent("sdk_cutover_success", { hfId, opCount: 1 });
|
|
460
|
+
return true;
|
|
461
|
+
} catch (err) {
|
|
462
|
+
trackStudioEvent("sdk_cutover_fallback", { hfId, error: String(err) });
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio PatchOperation[] → SDK EditOp[] mapping.
|
|
3
|
+
*
|
|
4
|
+
* Lives in its own module so both the cutover path (sdkCutover.ts) and the
|
|
5
|
+
* resolver-shadow tripwire (sdkResolverShadow.ts) can use it without a circular
|
|
6
|
+
* import between those two.
|
|
7
|
+
*
|
|
8
|
+
* Multiple inline-style ops are coalesced into a single setStyle (the SDK
|
|
9
|
+
* batches style changes naturally). One SDK op is emitted per non-style op.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { EditOp } from "@hyperframes/sdk";
|
|
13
|
+
import type { PatchOperation } from "./sourcePatcher";
|
|
14
|
+
|
|
15
|
+
export function patchOpsToSdkEditOps(hfId: string, ops: PatchOperation[]): EditOp[] {
|
|
16
|
+
const result: EditOp[] = [];
|
|
17
|
+
const styles: Record<string, string | null> = {};
|
|
18
|
+
let hasStyles = false;
|
|
19
|
+
|
|
20
|
+
for (const op of ops) {
|
|
21
|
+
if (op.type === "inline-style") {
|
|
22
|
+
styles[op.property] = op.value;
|
|
23
|
+
hasStyles = true;
|
|
24
|
+
} else if (op.type === "text-content") {
|
|
25
|
+
result.push({ type: "setText", target: hfId, value: op.value ?? "" });
|
|
26
|
+
} else if (op.type === "attribute") {
|
|
27
|
+
result.push({
|
|
28
|
+
type: "setAttribute",
|
|
29
|
+
target: hfId,
|
|
30
|
+
name: op.property.startsWith("data-") ? op.property : `data-${op.property}`,
|
|
31
|
+
value: op.value,
|
|
32
|
+
});
|
|
33
|
+
} else if (op.type === "html-attribute") {
|
|
34
|
+
result.push({ type: "setAttribute", target: hfId, name: op.property, value: op.value });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (hasStyles) {
|
|
39
|
+
result.unshift({ type: "setStyle", target: hfId, styles });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
}
|