@hyperframes/studio 0.7.7 → 0.7.9

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 (43) hide show
  1. package/dist/assets/{index-B2YXvFxf.js → index-B7fv-WA3.js} +1 -1
  2. package/dist/assets/{index-BoASKOeE.js → index-C48wGs63.js} +1 -1
  3. package/dist/assets/{index-BeRh2hMe.js → index-e4xyxg7-.js} +187 -187
  4. package/dist/assets/index-svYFaNuq.css +1 -0
  5. package/dist/index.d.ts +4 -1
  6. package/dist/index.html +2 -2
  7. package/dist/index.js +2715 -2061
  8. package/dist/index.js.map +1 -1
  9. package/package.json +5 -5
  10. package/src/components/StudioRightPanel.tsx +5 -1
  11. package/src/components/editor/DomEditOverlay.tsx +4 -12
  12. package/src/components/editor/MarqueeOverlay.tsx +40 -0
  13. package/src/components/editor/OffCanvasIndicators.tsx +2 -7
  14. package/src/components/editor/PropertyPanel.tsx +12 -0
  15. package/src/components/editor/Transform3DCube.tsx +313 -0
  16. package/src/components/editor/gsapAnimationConstants.ts +5 -0
  17. package/src/components/editor/manualOffsetDrag.test.ts +99 -0
  18. package/src/components/editor/manualOffsetDrag.ts +38 -7
  19. package/src/components/editor/marqueeCommit.ts +63 -20
  20. package/src/components/editor/propertyPanel3dTransform.tsx +311 -92
  21. package/src/components/editor/propertyPanelHelpers.ts +43 -21
  22. package/src/components/editor/transform3dProjection.test.ts +99 -0
  23. package/src/components/editor/transform3dProjection.ts +172 -0
  24. package/src/components/sidebar/AssetsTab.tsx +23 -213
  25. package/src/components/sidebar/AudioRow.tsx +202 -0
  26. package/src/contexts/DomEditContext.tsx +4 -0
  27. package/src/hooks/gsapDragCommit.test.ts +9 -5
  28. package/src/hooks/gsapDragCommit.ts +28 -9
  29. package/src/hooks/gsapRuntimeKeyframes.ts +50 -5
  30. package/src/hooks/gsapRuntimePatch.ts +162 -35
  31. package/src/hooks/useAnimatedPropertyCommit.ts +256 -78
  32. package/src/hooks/useDomEditCommits.ts +0 -2
  33. package/src/hooks/useDomEditSession.ts +4 -2
  34. package/src/hooks/useDomGeometryCommits.ts +3 -31
  35. package/src/hooks/useEnableKeyframes.test.ts +40 -0
  36. package/src/hooks/useEnableKeyframes.ts +9 -2
  37. package/src/hooks/useGsapAwareEditing.ts +31 -1
  38. package/src/hooks/useGsapKeyframeOps.ts +4 -1
  39. package/src/hooks/useGsapSelectionHandlers.ts +12 -9
  40. package/src/hooks/useGsapTweenCache.ts +6 -4
  41. package/src/utils/marqueeGeometry.test.ts +15 -98
  42. package/src/utils/marqueeGeometry.ts +1 -158
  43. package/dist/assets/index-BSkUuN8g.css +0 -1
@@ -332,7 +332,7 @@ describe("commitStaticGsapPosition — instantPatch (value-only set)", () => {
332
332
  expect(yPatch.change.props[xMutation.property]).toBe(xMutation.value);
333
333
  });
334
334
 
335
- it("does NOT attach instantPatch when ADDING a new set (structural new tween)", async () => {
335
+ it("ADDS a global gsap.set with a global-set instantPatch (off-timeline, no flash)", async () => {
336
336
  const { commits, callbacks } = optionRecordingCallbacks();
337
337
 
338
338
  await commitStaticGsapPosition(
@@ -340,13 +340,15 @@ describe("commitStaticGsapPosition — instantPatch (value-only set)", () => {
340
340
  { x: -50, y: 30 },
341
341
  { x: 0, y: 0 },
342
342
  "#puck-a",
343
- null, // no existing set → `add` a new tween
343
+ null, // no existing set → `add` a new base gsap.set
344
344
  callbacks,
345
345
  );
346
346
 
347
347
  expect(commits).toHaveLength(1);
348
348
  expect(commits[0].mutation.type).toBe("add");
349
- expect(commits[0].options.instantPatch).toBeUndefined();
349
+ expect((commits[0].mutation as { global?: boolean }).global).toBe(true);
350
+ const patch = commits[0].options.instantPatch as { change: { kind: string } } | undefined;
351
+ expect(patch?.change.kind).toBe("global-set");
350
352
  });
351
353
  });
352
354
 
@@ -372,14 +374,16 @@ describe("commitStaticGsapRotation — instantPatch (value-only set)", () => {
372
374
  expect(patch.change.props[m.property]).toBe(m.value);
373
375
  });
374
376
 
375
- it("does NOT attach instantPatch when ADDING a new rotation set (structural)", async () => {
377
+ it("ADDS a global gsap.set with a global-set instantPatch (off-timeline, no flash)", async () => {
376
378
  const { commits, callbacks } = optionRecordingCallbacks();
377
379
 
378
380
  await commitStaticGsapRotation(selection(), 42, "#puck-a", null, callbacks);
379
381
 
380
382
  expect(commits).toHaveLength(1);
381
383
  expect(commits[0].mutation.type).toBe("add");
382
- expect(commits[0].options.instantPatch).toBeUndefined();
384
+ expect((commits[0].mutation as { global?: boolean }).global).toBe(true);
385
+ const patch = commits[0].options.instantPatch as { change: { kind: string } } | undefined;
386
+ expect(patch?.change.kind).toBe("global-set");
383
387
  });
384
388
  });
385
389
 
@@ -120,18 +120,22 @@ interface UpdatePropertyMutation {
120
120
  function setPatchFromUpdateProperties(
121
121
  selector: string,
122
122
  mutations: UpdatePropertyMutation[],
123
+ global = false,
123
124
  ): { selector: string; change: RuntimeTweenChange } {
124
125
  const props: SetPatchProps = {};
125
126
  for (const m of mutations) props[m.property as keyof SetPatchProps] = m.value;
126
- return { selector, change: { kind: "set", props } };
127
+ // An off-timeline `gsap.set` has no runtime tween to patch — apply it to the
128
+ // element directly. An on-timeline `tl.set` mutates its tween (so a re-seek keeps it).
129
+ return { selector, change: { kind: global ? "global-set" : "set", props } };
127
130
  }
128
131
 
129
132
  /** Single-mutation convenience over {@link setPatchFromUpdateProperties}. */
130
133
  function setPatchFromUpdateProperty(
131
134
  selector: string,
132
135
  mutation: UpdatePropertyMutation,
136
+ global = false,
133
137
  ): { selector: string; change: RuntimeTweenChange } {
134
- return setPatchFromUpdateProperties(selector, [mutation]);
138
+ return setPatchFromUpdateProperties(selector, [mutation], global);
135
139
  }
136
140
 
137
141
  /**
@@ -194,22 +198,25 @@ export async function commitStaticGsapPosition(
194
198
  // preview still reflects what DID persist. The x commit carries skipReload
195
199
  // (no reload), so its instantPatch gives instant feedback without a reload;
196
200
  // the y commit triggers the soft reload (skipped when the patch applies).
201
+ const global = !!existingSet.global;
197
202
  await callbacks.commitMutation(selection, xMutation, {
198
203
  label: "Move layer",
199
204
  skipReload: true,
200
205
  coalesceKey,
201
- instantPatch: setPatchFromUpdateProperty(selector, xMutation),
206
+ instantPatch: setPatchFromUpdateProperty(selector, xMutation, global),
202
207
  });
203
208
  await callbacks.commitMutation(selection, yMutation, {
204
209
  label: "Move layer",
205
210
  softReload: true,
206
211
  coalesceKey,
207
212
  // Final commit of the coalesced x/y pair: carry both channels so the
208
- // runtime `tl.set` lands the complete {x,y} pose in place.
209
- instantPatch: setPatchFromUpdateProperties(selector, [xMutation, yMutation]),
213
+ // runtime set lands the complete {x,y} pose in place.
214
+ instantPatch: setPatchFromUpdateProperties(selector, [xMutation, yMutation], global),
210
215
  });
211
216
  return;
212
217
  }
218
+ // New static hold → a base `gsap.set` (off-timeline, no 0% keyframe marker), with
219
+ // an instant patch so the first nudge shows immediately (no soft-reload flash).
213
220
  await callbacks.commitMutation(
214
221
  selection,
215
222
  {
@@ -218,8 +225,13 @@ export async function commitStaticGsapPosition(
218
225
  method: "set",
219
226
  position: 0,
220
227
  properties: { x: newX, y: newY },
228
+ global: true,
229
+ },
230
+ {
231
+ label: "Move layer",
232
+ softReload: true,
233
+ instantPatch: { selector, change: { kind: "global-set", props: { x: newX, y: newY } } },
221
234
  },
222
- { label: "Move layer", softReload: true },
223
235
  );
224
236
  }
225
237
 
@@ -264,11 +276,13 @@ export async function commitStaticGsapRotation(
264
276
  await callbacks.commitMutation(selection, rotationMutation, {
265
277
  label: "Rotate layer",
266
278
  softReload: true,
267
- // Value-only rotation set: patch the runtime `tl.set` rotation in place.
268
- instantPatch: setPatchFromUpdateProperty(selector, rotationMutation),
279
+ // Value-only rotation set patch the runtime in place (off-timeline gsap.set
280
+ // applies to the element directly; on-timeline tl.set patches its tween).
281
+ instantPatch: setPatchFromUpdateProperty(selector, rotationMutation, !!existingSet.global),
269
282
  });
270
283
  return;
271
284
  }
285
+ // New static hold → off-timeline `gsap.set` (no 0% keyframe marker) + instant patch.
272
286
  await callbacks.commitMutation(
273
287
  selection,
274
288
  {
@@ -277,8 +291,13 @@ export async function commitStaticGsapRotation(
277
291
  method: "set",
278
292
  position: 0,
279
293
  properties: { rotation: newRotation },
294
+ global: true,
295
+ },
296
+ {
297
+ label: "Rotate layer",
298
+ softReload: true,
299
+ instantPatch: { selector, change: { kind: "global-set", props: { rotation: newRotation } } },
280
300
  },
281
- { label: "Rotate layer", softReload: true },
282
301
  );
283
302
  }
284
303
 
@@ -12,12 +12,23 @@ import { buildArcPath, type ArcPathConfig } from "@hyperframes/core/gsap-parser-
12
12
  import { parsePercentageKeyframes, toAbsoluteTime } from "./gsapShared";
13
13
  import { roundTo3 } from "../utils/rounding";
14
14
 
15
+ /**
16
+ * A GSAP tween's `vars` object — intentionally open: it mixes channel values
17
+ * (numbers), easing (strings), flags (booleans), nested keyframes (objects) and
18
+ * callbacks. Named so call sites read as "GSAP config", not an untyped escape hatch.
19
+ */
20
+ export type GsapVars = Record<string, unknown>;
21
+
15
22
  export interface RuntimeTween {
16
23
  targets?: () => Element[];
17
- vars?: Record<string, unknown>;
24
+ vars?: GsapVars;
18
25
  duration?: () => number;
19
26
  startTime?: () => number;
20
27
  invalidate?: () => RuntimeTween;
28
+ /** Remove this tween from its parent timeline (GSAP `kill()`). */
29
+ kill?: () => void;
30
+ /** The timeline this tween lives in — used to re-insert a rebuilt tween. */
31
+ parent?: RuntimeTimeline;
21
32
  }
22
33
 
23
34
  export interface RuntimeTimeline {
@@ -25,6 +36,8 @@ export interface RuntimeTimeline {
25
36
  duration?: () => number;
26
37
  time?: () => number;
27
38
  invalidate?: () => RuntimeTimeline;
39
+ /** Add a tween at an absolute position — used to rebuild a keyframe tween in place. */
40
+ to?: (targets: Element[], vars: GsapVars, position?: number) => RuntimeTween;
28
41
  }
29
42
 
30
43
  type Pct = { percentage: number; properties: Record<string, number | string> };
@@ -184,6 +197,26 @@ function varsCarryChannel(vars: Record<string, unknown> | undefined, channels: s
184
197
  return false;
185
198
  }
186
199
 
200
+ /**
201
+ * Like `varsCarryChannel` but for a keyframe tween: the channels live inside the
202
+ * keyframe steps (`vars.keyframes`), not as own props of `vars`. Handles the object
203
+ * form (`{ "0%": {...} }`) and the array form (`[{...}, ...]`).
204
+ */
205
+ function keyframeVarsCarryChannel(
206
+ vars: Record<string, unknown> | undefined,
207
+ channels: string[],
208
+ ): boolean {
209
+ const kf = vars?.keyframes;
210
+ if (!kf || typeof kf !== "object") return false;
211
+ const steps = Array.isArray(kf) ? kf : Object.values(kf);
212
+ return steps.some(
213
+ (step) =>
214
+ step != null &&
215
+ typeof step === "object" &&
216
+ channels.some((ch) => Object.prototype.hasOwnProperty.call(step, ch)),
217
+ );
218
+ }
219
+
187
220
  /**
188
221
  * Resolve the live tween targeting `selector` using the SAME all-timelines scan
189
222
  * `readRuntimeKeyframes` uses, so read and write agree on "which tween". With
@@ -197,6 +230,7 @@ function varsCarryChannel(vars: Record<string, unknown> | undefined, channels: s
197
230
  * on a rotation-only set). With no channel-matching set, it falls back to the
198
231
  * first matching set (back-compat). `channels` is ignored for `kind: "keyframe"`.
199
232
  */
233
+ // fallow-ignore-next-line complexity
200
234
  export function resolveRuntimeTween(
201
235
  iframe: HTMLIFrameElement | null,
202
236
  selector: string,
@@ -219,7 +253,12 @@ export function resolveRuntimeTween(
219
253
  ? [compositionId]
220
254
  : Object.keys(timelines).filter((k) => typeof timelines[k]?.getChildren === "function");
221
255
 
222
- const wantChannels = kind === "set" && channels && channels.length > 0 ? channels : null;
256
+ // Channels disambiguate co-located tweens for BOTH kinds: a `set` carries them as
257
+ // own vars props, a keyframe tween carries them inside its keyframe steps. An
258
+ // element can have a rotation keyframe tween AND a position keyframe tween; a
259
+ // rotation edit must land on the former. The reader passes no channels, so its
260
+ // playhead-containment path below is unchanged.
261
+ const wantChannels = channels && channels.length > 0 ? channels : null;
223
262
 
224
263
  let first: ResolvedRuntimeTween | null = null;
225
264
  let channelMatch: ResolvedRuntimeTween | null = null;
@@ -233,11 +272,15 @@ export function resolveRuntimeTween(
233
272
  const isSet = !(dur > 0);
234
273
  if (kind === "set" ? !isSet : isSet) continue;
235
274
  if (wantChannels) {
236
- if (varsCarryChannel(tween.vars, wantChannels)) {
275
+ const carries =
276
+ kind === "set"
277
+ ? varsCarryChannel(tween.vars, wantChannels)
278
+ : keyframeVarsCarryChannel(tween.vars, wantChannels);
279
+ if (carries) {
237
280
  if (channelMatch === null) channelMatch = { tween, timeline };
238
281
  } else if (first === null) {
239
- // A set carrying only disjoint channels: remember as last-resort
240
- // fallback, but never prefer it over a channel-matching set.
282
+ // A tween carrying only disjoint channels: remember as last-resort
283
+ // fallback, but never prefer it over a channel-matching one.
241
284
  first = { tween, timeline };
242
285
  }
243
286
  continue;
@@ -267,6 +310,7 @@ function readCarriesChannel(read: ReadTween, channels: string[]): boolean {
267
310
  * whenever the playhead sits in that tween's range but outside the position
268
311
  * tween's). Omitted → any keyframed tween qualifies (back-compat).
269
312
  */
313
+ // fallow-ignore-next-line complexity
270
314
  export function readRuntimeKeyframes(
271
315
  iframe: HTMLIFrameElement | null,
272
316
  selector: string,
@@ -334,6 +378,7 @@ export function readRuntimeKeyframes(
334
378
  * only a hold may remain, and resurrecting the deleted tween from the stale parse
335
379
  * must be avoided.
336
380
  */
381
+ // fallow-ignore-next-line complexity
337
382
  export function hasNonHoldTweenForElement(
338
383
  iframe: HTMLIFrameElement | null,
339
384
  selector: string,
@@ -13,13 +13,22 @@
13
13
  * "Which tween" is resolved by the same all-timelines scan `readRuntimeKeyframes`
14
14
  * uses (`resolveRuntimeTween`), so read and write agree on the target.
15
15
  */
16
- import { resolveRuntimeTween, type RuntimeTween } from "./gsapRuntimeKeyframes";
16
+ import {
17
+ resolveRuntimeTween,
18
+ type RuntimeTween,
19
+ type RuntimeTimeline,
20
+ } from "./gsapRuntimeKeyframes";
17
21
 
18
22
  /** Value-only channels a `tl.set(...)` patch may touch. */
19
23
  export interface SetPatchProps {
20
24
  x?: number;
21
25
  y?: number;
22
26
  rotation?: number;
27
+ rotationX?: number;
28
+ rotationY?: number;
29
+ rotationZ?: number;
30
+ z?: number;
31
+ transformPerspective?: number;
23
32
  scaleX?: number;
24
33
  scaleY?: number;
25
34
  scale?: number;
@@ -31,12 +40,28 @@ export type KeyframeStep = Record<string, number>;
31
40
 
32
41
  export type RuntimeTweenChange =
33
42
  | { kind: "set"; props: SetPatchProps }
34
- | { kind: "keyframes"; keyframes: KeyframeStep[] };
43
+ | { kind: "keyframes"; keyframes: KeyframeStep[] }
44
+ // Edit ONE step (at `pct`) of an object-form keyframe tween — the form the studio
45
+ // writes (`keyframes: { "0%": {...} }`). GSAP pre-compiles those into sub-tweens
46
+ // and won't re-read `vars.keyframes` on `invalidate()`, so this REBUILDS the tween
47
+ // (kill + recreate at the same position) instead of mutating it. Lets a design-panel
48
+ // keyframe edit show instantly rather than soft-reloading the iframe (a flash).
49
+ | { kind: "keyframe-rebuild"; pct: number; props: KeyframeStep }
50
+ // Apply a base `gsap.set` value to the element directly (`gsap.set(el, props)`).
51
+ // A base set lives OFF the timeline, so there's no runtime tween to patch — but
52
+ // the element is static on these channels, so setting them immediately reflects
53
+ // the edit with no soft reload (no flash) and leaves no keyframe marker.
54
+ | { kind: "global-set"; props: SetPatchProps };
35
55
 
36
56
  const SET_CHANNELS: Array<keyof SetPatchProps> = [
37
57
  "x",
38
58
  "y",
39
59
  "rotation",
60
+ "rotationX",
61
+ "rotationY",
62
+ "rotationZ",
63
+ "z",
64
+ "transformPerspective",
40
65
  "scaleX",
41
66
  "scaleY",
42
67
  "scale",
@@ -45,8 +70,42 @@ const SET_CHANNELS: Array<keyof SetPatchProps> = [
45
70
 
46
71
  type IframeWindow = Window & {
47
72
  __player?: { getTime?: () => number; seek?: (t: number) => void };
73
+ gsap?: { set?: (target: Element, vars: Record<string, number>) => void };
48
74
  };
49
75
 
76
+ /**
77
+ * Apply a base `gsap.set` value to the element in the live runtime. Returns `true`
78
+ * if applied. Used for off-timeline static holds (position / 3D transform) — there's
79
+ * no tween to patch, so we set the channels directly. Safe because the element is
80
+ * static on these channels (the caller only uses this for non-animated values).
81
+ */
82
+ /** The props as finite numbers, or null if any value is non-finite / none present. */
83
+ function finiteNumericProps(props: SetPatchProps): Record<string, number> | null {
84
+ const numeric: Record<string, number> = {};
85
+ for (const [k, v] of Object.entries(props)) {
86
+ if (typeof v !== "number" || !Number.isFinite(v)) return null;
87
+ numeric[k] = v;
88
+ }
89
+ return Object.keys(numeric).length > 0 ? numeric : null;
90
+ }
91
+
92
+ function applyGlobalSet(
93
+ iframe: HTMLIFrameElement,
94
+ selector: string,
95
+ props: SetPatchProps,
96
+ ): boolean {
97
+ try {
98
+ const gsapLib = (iframe.contentWindow as IframeWindow | null)?.gsap;
99
+ const el = iframe.contentDocument?.querySelector(selector) ?? null;
100
+ const numeric = finiteNumericProps(props);
101
+ if (!gsapLib?.set || !el || !numeric) return false;
102
+ gsapLib.set(el, numeric);
103
+ return true;
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+
50
109
  function playerOf(iframe: HTMLIFrameElement): IframeWindow["__player"] | null {
51
110
  try {
52
111
  return (iframe.contentWindow as IframeWindow | null)?.__player ?? null;
@@ -100,10 +159,95 @@ function patchKeyframes(tween: RuntimeTween, keyframes: KeyframeStep[]): boolean
100
159
  return true;
101
160
  }
102
161
 
162
+ /** The object-form keyframes map with `props` merged into the step at `pct`. */
163
+ function mergeKeyframeStep(
164
+ map: Record<string, Record<string, number>>,
165
+ pct: number,
166
+ props: KeyframeStep,
167
+ ): Record<string, Record<string, number>> {
168
+ const next: Record<string, Record<string, number>> = {};
169
+ for (const [k, step] of Object.entries(map)) next[k] = { ...step };
170
+ // Match the existing percentage key numerically ("50%" ≡ pct 50), else add one.
171
+ let key: string | null = null;
172
+ for (const k of Object.keys(next)) {
173
+ const n = parseFloat(k);
174
+ if (Number.isFinite(n) && Math.abs(n - pct) < 0.05) {
175
+ key = k;
176
+ break;
177
+ }
178
+ }
179
+ if (key === null) key = `${pct}%`;
180
+ next[key] = { ...(next[key] ?? {}), ...props };
181
+ return next;
182
+ }
183
+
184
+ /**
185
+ * Rebuild an object-form keyframe tween with `props` merged into the step at `pct`,
186
+ * in place: kill the old tween and recreate it on the SAME parent timeline at the
187
+ * SAME position, with all other vars (duration, ease, repeat, …) preserved. This
188
+ * is the only way to reflect an object-form keyframe edit live — GSAP compiles
189
+ * those keyframes into sub-tweens at creation and ignores later `vars.keyframes`
190
+ * mutations. Declines (→ caller soft-reloads) for array-form, motionPath arcs,
191
+ * non-finite/dynamic values, or a tween whose parent/targets can't be resolved.
192
+ */
193
+ // fallow-ignore-next-line complexity
194
+ function rebuildKeyframeTween(tween: RuntimeTween, pct: number, props: KeyframeStep): boolean {
195
+ const vars = tween.vars;
196
+ if (!vars || "motionPath" in vars) return false;
197
+ const kf = vars.keyframes;
198
+ if (!kf || typeof kf !== "object" || Array.isArray(kf)) return false;
199
+ for (const v of Object.values(props)) {
200
+ if (typeof v !== "number" || !Number.isFinite(v)) return false;
201
+ }
202
+ const parent = tween.parent;
203
+ const targets = tween.targets?.();
204
+ if (!parent?.to || !targets || targets.length === 0) return false;
205
+ if (typeof tween.startTime !== "function" || typeof tween.kill !== "function") return false;
206
+
207
+ const next = mergeKeyframeStep(kf as Record<string, Record<string, number>>, pct, props);
208
+ const newVars = { ...vars, keyframes: next };
209
+ const position = tween.startTime();
210
+ tween.kill();
211
+ parent.to(targets, newVars, position);
212
+ return true;
213
+ }
214
+
215
+ /** The channels a change writes, for the resolver to disambiguate co-located tweens. */
216
+ function changeChannels(change: RuntimeTweenChange): string[] | undefined {
217
+ if (change.kind === "set") {
218
+ return Object.keys(change.props).filter(
219
+ (k) => change.props[k as keyof SetPatchProps] !== undefined,
220
+ );
221
+ }
222
+ if (change.kind === "keyframe-rebuild") return Object.keys(change.props);
223
+ return undefined;
224
+ }
225
+
226
+ /** Re-render the timeline at the current playhead after an in-place edit. */
227
+ function seekToCurrent(iframe: HTMLIFrameElement, timeline: RuntimeTimeline): void {
228
+ const player = playerOf(iframe);
229
+ const currentTime =
230
+ typeof player?.getTime === "function"
231
+ ? player.getTime()
232
+ : typeof timeline.time === "function"
233
+ ? timeline.time()
234
+ : 0;
235
+ player?.seek?.(Number.isFinite(currentTime) ? currentTime : 0);
236
+ }
237
+
238
+ /** Apply `change` to the resolved tween. `true` if applied, `false` to soft-reload.
239
+ * `global-set` is handled before this (no tween) and never reaches here. */
240
+ function applyChange(tween: RuntimeTween, change: RuntimeTweenChange): boolean {
241
+ if (change.kind === "set") return patchSet(tween, change.props);
242
+ if (change.kind === "keyframes") return patchKeyframes(tween, change.keyframes);
243
+ if (change.kind === "keyframe-rebuild")
244
+ return rebuildKeyframeTween(tween, change.pct, change.props);
245
+ return false;
246
+ }
247
+
103
248
  /**
104
- * Update one tween's values in `window.__timelines` in place + re-seek to the
105
- * current playhead. Returns `true` on a confident patch, `false` otherwise
106
- * (caller falls back to a soft reload).
249
+ * Edit one tween in `window.__timelines` in place + re-seek to the current playhead.
250
+ * Returns `true` on a confident patch, `false` otherwise (caller soft-reloads).
107
251
  */
108
252
  export function patchRuntimeTweenInPlace(
109
253
  iframe: HTMLIFrameElement | null,
@@ -112,46 +256,29 @@ export function patchRuntimeTweenInPlace(
112
256
  compositionId?: string,
113
257
  ): boolean {
114
258
  if (!iframe) return false;
259
+ // A base `gsap.set` has no timeline tween to resolve — apply the value straight
260
+ // to the element so the edit shows instantly (no soft reload, no flash).
261
+ if (change.kind === "global-set") return applyGlobalSet(iframe, selector, change.props);
115
262
  try {
116
- // For a `set` patch, hand the resolver the channels actually being written so
117
- // it picks the set whose vars carry them — an element can have separate
118
- // {x,y} and {rotation} sets, and a position patch must not corrupt the
119
- // rotation set (channel-blind resolution would return the first match).
120
- const channels =
121
- change.kind === "set"
122
- ? Object.keys(change.props).filter(
123
- (k) => change.props[k as keyof SetPatchProps] !== undefined,
124
- )
125
- : undefined;
126
263
  const resolved = resolveRuntimeTween(
127
264
  iframe,
128
265
  selector,
129
266
  change.kind === "set" ? "set" : "keyframe",
130
267
  compositionId,
131
- channels,
268
+ changeChannels(change),
132
269
  );
133
270
  if (!resolved) return false;
134
271
  const { tween, timeline } = resolved;
135
272
 
136
- const applied =
137
- change.kind === "set"
138
- ? patchSet(tween, change.props)
139
- : patchKeyframes(tween, change.keyframes);
140
- if (!applied) return false;
141
-
142
- // Recompute the tween (and its timeline) from the new vars, then re-render at
143
- // the current playhead. `invalidate()` makes GSAP re-read vars on the next render.
144
- tween.invalidate?.();
145
- timeline.invalidate?.();
146
-
147
- const player = playerOf(iframe);
148
- const currentTime =
149
- typeof player?.getTime === "function"
150
- ? player.getTime()
151
- : typeof timeline.time === "function"
152
- ? timeline.time()
153
- : 0;
154
- player?.seek?.(Number.isFinite(currentTime) ? currentTime : 0);
273
+ if (!applyChange(tween, change)) return false;
274
+
275
+ // A rebuild already recreated the tween; set/keyframes mutate vars in place, so
276
+ // invalidate to make GSAP re-read them on the next render. Either way, re-seek.
277
+ if (change.kind !== "keyframe-rebuild") {
278
+ tween.invalidate?.();
279
+ timeline.invalidate?.();
280
+ }
281
+ seekToCurrent(iframe, timeline);
155
282
  return true;
156
283
  } catch {
157
284
  return false;