@hyperframes/studio 0.8.99 → 0.8.100

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 (28) hide show
  1. package/dist/assets/{hyperframes-player-Rml34FRW.js → hyperframes-player-fWt87gyh.js} +1 -1
  2. package/dist/assets/{index-C_fi-jTe.js → index-D34Oy5DN.js} +1 -1
  3. package/dist/assets/{index-CVDArg3m.js → index-D6TjRAvz.js} +176 -176
  4. package/dist/assets/{index-D9YzDuBx.js → index-DofdzdxJ.js} +1 -1
  5. package/dist/index.html +1 -1
  6. package/dist/index.js +423 -312
  7. package/dist/index.js.map +1 -1
  8. package/package.json +8 -8
  9. package/src/components/editor/PropertyPanel.tsx +3 -3
  10. package/src/components/editor/domEditOverlayStartGesture.test.ts +83 -0
  11. package/src/components/editor/domEditOverlayStartGesture.ts +6 -4
  12. package/src/components/editor/manualOffsetDrag.test.ts +70 -0
  13. package/src/components/editor/manualOffsetDrag.ts +50 -40
  14. package/src/components/editor/plainTranslate.test.ts +62 -0
  15. package/src/components/editor/plainTranslate.ts +85 -0
  16. package/src/components/editor/propertyPanelTransformCommit.ts +3 -2
  17. package/src/components/editor/useDomEditNudge.ts +1 -1
  18. package/src/hooks/elementOffsetStager.ts +33 -2
  19. package/src/hooks/gsapRuntimeBridge.ts +1 -17
  20. package/src/hooks/gsapRuntimeKeyframes.ts +35 -0
  21. package/src/hooks/useDomEditCommits.test.tsx +12 -3
  22. package/src/hooks/useDomEditCommits.ts +2 -1
  23. package/src/hooks/useDomEditTextCommits.test.tsx +62 -5
  24. package/src/hooks/useDomEditTextCommits.ts +35 -35
  25. package/src/hooks/useDomGeometryCommit.test.tsx +62 -4
  26. package/src/hooks/useDomGeometryCommits.test.tsx +4 -2
  27. package/src/hooks/useGsapAwareEditing.test.tsx +46 -18
  28. package/src/hooks/useGsapAwareEditing.ts +11 -11
@@ -5,6 +5,8 @@ import {
5
5
  } from "../components/editor/elementPositionOffset";
6
6
  import { LAYER_REVEAL_PRIOR_POSITION_ATTR } from "../player/lib/timelineElementHelpers";
7
7
  import type { PatchOperation } from "../utils/sourcePatcher";
8
+ import { translatePatch } from "../components/editor/plainTranslate";
9
+ import { gsapWritesPosition } from "./gsapRuntimeKeyframes";
8
10
 
9
11
  const ELEMENT_OFFSET_REFUSED: Record<ElementOffsetRefusal, string> = {
10
12
  anchored: "This layer is anchored from its right or bottom edge. Move it in the Code tab.",
@@ -30,8 +32,34 @@ function settleGsapDraftAtGestureStart(el: HTMLElement): void {
30
32
  if (gsap && Number.isFinite(x) && Number.isFinite(y)) gsap.set(el, { x, y });
31
33
  }
32
34
 
33
- /** Applies a shared-tween element's move live now; `save` persists it as left/top on that
34
- * element, `rollback` takes the live move back. Throws, after a toast, when it cannot. */
35
+ let plainMoveCounter = 0;
36
+
37
+ /** GSAP does not position the element: `next` is its whole translate, live now and saved as drawn. */
38
+ function stagePlainTranslate(
39
+ commitPositionPatchToHtml: ElementOffsetStagerDeps["commitPositionPatchToHtml"],
40
+ selection: DomEditSelection,
41
+ next: { x: number; y: number },
42
+ coalesceKey?: string,
43
+ ): { save: () => Promise<void>; rollback: () => void } {
44
+ const style = selection.element.style;
45
+ const before = style.getPropertyValue("translate");
46
+ const patch = translatePatch(next);
47
+ style.setProperty("translate", patch.value);
48
+ const rollback = () => {
49
+ if (style.getPropertyValue("translate") === patch.value) style.setProperty("translate", before);
50
+ };
51
+ const key = coalesceKey ?? `move:${++plainMoveCounter}`;
52
+ const options = { label: "Move layer", coalesceKey: key, coalesceMs: Number.POSITIVE_INFINITY };
53
+ const save = () =>
54
+ commitPositionPatchToHtml(selection, [patch], options).catch((error) => {
55
+ rollback();
56
+ throw error;
57
+ });
58
+ return { save, rollback };
59
+ }
60
+
61
+ /** Applies a move on the element itself live now: its translate when GSAP does not position it,
62
+ * else left/top for a shared-tween element. Throws, after a toast, when it cannot. */
35
63
  export function stageElementOffset(
36
64
  { commitPositionPatchToHtml, showToast, readOnlyPreview }: ElementOffsetStagerDeps,
37
65
  selection: DomEditSelection,
@@ -40,6 +68,9 @@ export function stageElementOffset(
40
68
  ): { save: () => Promise<void>; rollback: () => void } {
41
69
  const el = selection.element;
42
70
  if (readOnlyPreview) return { save: () => Promise.resolve(), rollback: () => undefined };
71
+ if (!gsapWritesPosition(el)) {
72
+ return stagePlainTranslate(commitPositionPatchToHtml, selection, next, coalesceKey);
73
+ }
43
74
  const previous = { position: el.style.position, left: el.style.left, top: el.style.top };
44
75
  const liftMarker = el.getAttribute(LAYER_REVEAL_PRIOR_POSITION_ATTR);
45
76
  const result = applyElementPositionOffset(el, next);
@@ -35,7 +35,7 @@ import {
35
35
  pickClosestToPlayhead,
36
36
  readGsapPositionFromIframe,
37
37
  } from "./gsapPositionDetection";
38
- import { hasNonHoldTweenForElement } from "./gsapRuntimeKeyframes";
38
+ import { hasNonHoldTweenForElement, POSITION_CHANNELS } from "./gsapRuntimeKeyframes";
39
39
  import { getAnimationsForElement } from "./gsapElementMatch";
40
40
  import {
41
41
  animationWritesAnyProperty,
@@ -43,22 +43,6 @@ import {
43
43
  type GsapEditOutcome,
44
44
  } from "./gsapEditOutcome";
45
45
 
46
- // Position channels — used to scope the "has a live position tween?" check so a
47
- // sibling rotation/scale animation never forces a static position hold into the
48
- // keyframe branch (which corrupts it into a frozen duration-0 keyframed tween).
49
- export const POSITION_CHANNELS: string[] = [
50
- "x",
51
- "y",
52
- "xPercent",
53
- "yPercent",
54
- "left",
55
- "top",
56
- // GSAP normalizes translateX/Y to x/y at play time, but readTween reads the
57
- // AUTHORED shape — include them so a hand-authored translateX/Y position tween
58
- // still counts as a live position tween.
59
- "translateX",
60
- "translateY",
61
- ];
62
46
  const POSITION_CHANNEL_SET = new Set<string>(POSITION_CHANNELS);
63
47
 
64
48
  const ROTATION_CHANNELS: string[] = ["rotation", "rotationX", "rotationY", "rotationZ"];
@@ -405,6 +405,41 @@ export function hasNonHoldTweenForElement(
405
405
  return !!targetEl && hasNonHoldTween(timelinesOf(iframe), targetEl, channels, compositionId);
406
406
  }
407
407
 
408
+ // A sibling rotation/scale tween must never push a static position hold into the keyframe branch.
409
+ export const POSITION_CHANNELS: string[] = [
410
+ "x",
411
+ "y",
412
+ "xPercent",
413
+ "yPercent",
414
+ "left",
415
+ "top",
416
+ // readTween reads the authored translateX/Y; GSAP normalizes them to x/y only at play time.
417
+ "translateX",
418
+ "translateY",
419
+ ];
420
+ const MOVE_CHANNELS = [...POSITION_CHANNELS, "motionPath"];
421
+
422
+ /** Whether a live timeline tween or hold writes any of `channels` on `el`. Sync, no fetch. */
423
+ function gsapWritesChannels(el: Element, channels: string[]): boolean {
424
+ const win = el.ownerDocument.defaultView as { __timelines?: Record<string, RuntimeTimeline> };
425
+ return Object.values(win?.__timelines ?? {}).some((tl) =>
426
+ (tl?.getChildren?.(true) ?? []).some(
427
+ (tween) =>
428
+ !!tween.vars &&
429
+ matchesElement(tween, el) &&
430
+ (channels.some((ch) => ch in tween.vars!) ||
431
+ keyframeVarsCarryChannel(tween.vars, channels)),
432
+ ),
433
+ );
434
+ }
435
+
436
+ /** GSAP owns this element's position: a tween or hold writes it, or GSAP already renders its
437
+ * transform (a CSS translate would then apply twice). Everything else moves by plain CSS. */
438
+ export function gsapWritesPosition(el: Element): boolean {
439
+ const cache = (el as { _gsap?: { renderTransform?: unknown } })._gsap;
440
+ return !!cache?.renderTransform || gsapWritesChannels(el, MOVE_CHANNELS);
441
+ }
442
+
408
443
  /** `hasNonHoldTweenForElement` for an element in hand, read from its own window's timelines. */
409
444
  export function elementHasNonHoldTween(el: Element, channels?: string[]): boolean {
410
445
  const win = el.ownerDocument.defaultView as {
@@ -228,7 +228,9 @@ function renderDomEditCommits(
228
228
  applyDomSelection: vi.fn(),
229
229
  clearDomSelection: vi.fn(),
230
230
  refreshDomEditSelectionFromPreview: vi.fn(),
231
- buildDomSelectionFromTarget: vi.fn(async () => null),
231
+ buildDomSelectionFromTarget: vi.fn(async (target: HTMLElement) =>
232
+ target === selection.element ? selection : null,
233
+ ),
232
234
  onTrySdkPersist: options.onTrySdkPersist,
233
235
  readOnlyPreview: false,
234
236
  });
@@ -893,7 +895,7 @@ describe("useDomEditCommits rich-text persist handling", () => {
893
895
  }
894
896
  });
895
897
 
896
- it("does not retarget a commit onto a replacement preview node", async () => {
898
+ it("does not retarget a commit onto a replacement preview node, and says the text was not saved", async () => {
897
899
  const fetchMock = stubPatchFetch({ ok: true, changed: true, matched: true });
898
900
  const html = '<span style="color: blue">After</span>';
899
901
  const { iframe, element } = createPreviewElement(`<div data-hf-id="hf-card">${html}</div>`);
@@ -902,6 +904,7 @@ describe("useDomEditCommits rich-text persist handling", () => {
902
904
  replacement.dataset.hfId = "hf-card";
903
905
  replacement.innerHTML = "Reloaded elsewhere";
904
906
  element.replaceWith(replacement);
907
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
905
908
 
906
909
  try {
907
910
  await act(async () => {
@@ -914,8 +917,14 @@ describe("useDomEditCommits rich-text persist handling", () => {
914
917
 
915
918
  expect(replacement.innerHTML).toBe("Reloaded elsewhere");
916
919
  expect(fetchMock).not.toHaveBeenCalled();
917
- expect(rendered.showToast).not.toHaveBeenCalled();
920
+ expect(rendered.showToast).toHaveBeenCalledWith(
921
+ expect.stringMatching(
922
+ /Couldn't save the text edit: the text's element is gone from the preview/,
923
+ ),
924
+ "error",
925
+ );
918
926
  } finally {
927
+ errorSpy.mockRestore();
919
928
  rendered.cleanup();
920
929
  }
921
930
  });
@@ -7,6 +7,7 @@ import { StudioSaveHttpError, trackStudioSaveFailure } from "../utils/studioSave
7
7
  import type { DomEditSelection } from "../components/editor/domEditing";
8
8
  import { fontFamilyFromAssetPath, type ImportedFontAsset } from "../components/editor/fontAssets";
9
9
  import type { CommitDomEditPatchBatches } from "./domEditCommitTypes";
10
+ import type { ResolveDomSelectionOptions } from "./useDomSelectionTypes";
10
11
  import type { PatchOperation } from "../utils/sourcePatcher";
11
12
  import { DomEditPersistUnsafeValueError } from "./domEditPersistFailure";
12
13
  import { useDomEditPersist, type RecordEditInput } from "./useDomEditPersist";
@@ -46,7 +47,7 @@ export interface UseDomEditCommitsParams {
46
47
  refreshDomEditSelectionFromPreview: (selection: DomEditSelection) => void;
47
48
  buildDomSelectionFromTarget: (
48
49
  target: HTMLElement,
49
- options?: { preferClipAncestor?: boolean },
50
+ options?: ResolveDomSelectionOptions,
50
51
  ) => Promise<DomEditSelection | null>;
51
52
  /** Resync the in-memory SDK session after a SERVER-side write (NOT the SDK
52
53
  * path, whose session is already current) so a later SDK edit doesn't
@@ -125,13 +125,20 @@ afterEach(() => {
125
125
  });
126
126
 
127
127
  describe("useDomEditTextCommits", () => {
128
- function richTextProbe() {
129
- const { iframe, element } = previewElement('<h1 id="t">Old</h1>', "t");
128
+ function richTextProbe(
129
+ html = '<h1 id="t">Old</h1>',
130
+ overrides: (doc: Document) => Partial<UseDomEditTextCommitsParams> = () => ({}),
131
+ ) {
132
+ const { iframe, element } = previewElement(html, "t");
130
133
  const persist = vi.fn().mockResolvedValue(undefined);
134
+ const showToast = vi.fn();
131
135
  const base = commitParams({
132
136
  previewIframeRef: { current: iframe },
133
137
  domEditSelection: selectionFor(element),
138
+ buildDomSelectionFromTarget: vi.fn(async (target: HTMLElement) => selectionFor(target)),
134
139
  persistDomEditOperations: persist,
140
+ showToast,
141
+ ...overrides(element.ownerDocument),
135
142
  });
136
143
  const captured: { hook: ReturnType<typeof useDomEditTextCommits> | null } = { hook: null };
137
144
  function Probe({ readOnlyPreview }: { readOnlyPreview: boolean }) {
@@ -143,13 +150,25 @@ describe("useDomEditTextCommits", () => {
143
150
  const save = captured.hook!.handleDomRichTextCommit;
144
151
  const commit = { element, html: "New", previousHtml: "Old" };
145
152
  element.innerHTML = "New";
146
- return { root, Probe, persist, element, save: () => act(async () => save(commit)) };
153
+ return {
154
+ root,
155
+ Probe,
156
+ persist,
157
+ showToast,
158
+ element,
159
+ save: () => act(async () => save(commit)),
160
+ };
147
161
  }
148
162
 
149
- it("saves in-place text while the preview is editable", async () => {
150
- const { persist, save } = richTextProbe();
163
+ it("saves in-place text while the preview is editable, and refreshes the selection it edited", async () => {
164
+ const applyDomSelection = vi.fn();
165
+ const { persist, element, save } = richTextProbe(undefined, () => ({ applyDomSelection }));
151
166
  await save();
152
167
  expect(persist).toHaveBeenCalledTimes(1);
168
+ expect(applyDomSelection).toHaveBeenCalledWith(
169
+ expect.objectContaining({ element }),
170
+ expect.objectContaining({ preserveGroup: true }),
171
+ );
153
172
  });
154
173
 
155
174
  it("refuses in-place text once the preview turns read-only, through an earlier handler, and puts the old text back", async () => {
@@ -160,6 +179,44 @@ describe("useDomEditTextCommits", () => {
160
179
  expect(element.innerHTML).toBe("Old");
161
180
  });
162
181
 
182
+ it("saves the edited element, and leaves the selection alone, when the selection is another element or none", async () => {
183
+ for (const selected of ["card", null]) {
184
+ const applyDomSelection = vi.fn();
185
+ const { persist, element, save } = richTextProbe(
186
+ '<div id="card"><p id="t">Old</p></div>',
187
+ (doc) => ({
188
+ domEditSelection: selected ? selectionFor(doc.getElementById(selected)!) : null,
189
+ applyDomSelection,
190
+ buildDomSelectionFromTarget: vi.fn(async (target: HTMLElement) => ({
191
+ ...selectionFor(target),
192
+ label: "Resolved from the edited element",
193
+ })),
194
+ }),
195
+ );
196
+ await save();
197
+ expect(persist).toHaveBeenCalledTimes(1);
198
+ expect(persist.mock.calls[0]![0]).toMatchObject({
199
+ element,
200
+ label: "Resolved from the edited element",
201
+ });
202
+ expect(applyDomSelection).not.toHaveBeenCalled();
203
+ cleanup?.();
204
+ cleanup = null;
205
+ }
206
+ });
207
+
208
+ it("says so and puts the old text back when the edited text cannot be saved", async () => {
209
+ const error = vi.spyOn(console, "error").mockImplementation(() => {});
210
+ const { persist, showToast, element, save } = richTextProbe(undefined, () => ({
211
+ buildDomSelectionFromTarget: vi.fn(async () => null),
212
+ }));
213
+ await save();
214
+ expect(persist).not.toHaveBeenCalled();
215
+ expect(showToast).toHaveBeenCalledWith(expect.stringContaining("Couldn't save"), "error");
216
+ expect(error).toHaveBeenCalled();
217
+ expect(element.innerHTML).toBe("Old");
218
+ });
219
+
163
220
  it("keeps concurrent text commit ownership isolated by target", async () => {
164
221
  const { iframe, element: firstElement } = previewElement(
165
222
  "<div id='first'>First</div><div id='second'>Second</div>",
@@ -29,6 +29,7 @@ import {
29
29
  import { commitDomStyles } from "./domStyleCommit";
30
30
  import { useDomEditAttributeCommits } from "./useDomEditAttributeCommits";
31
31
  import type { InlineTextEditCommit } from "./useInlineTextEdit";
32
+ import type { ResolveDomSelectionOptions } from "./useDomSelectionTypes";
32
33
 
33
34
  // ── Types ──
34
35
 
@@ -44,7 +45,7 @@ export interface UseDomEditTextCommitsParams {
44
45
  refreshDomEditSelectionFromPreview: (selection: DomEditSelection) => void;
45
46
  buildDomSelectionFromTarget: (
46
47
  target: HTMLElement,
47
- options?: { preferClipAncestor?: boolean },
48
+ options?: ResolveDomSelectionOptions,
48
49
  ) => Promise<DomEditSelection | null>;
49
50
  persistDomEditOperations: PersistDomEditOperations;
50
51
  resolveImportedFontAsset: (fontFamilyValue: string) => ImportedFontAsset | null;
@@ -56,15 +57,6 @@ function canCommitInlineTextSelection(selection: DomEditSelection, element: HTML
56
57
  return canEditElementTextInline(element);
57
58
  }
58
59
 
59
- function ownsCurrentPreviewElement(
60
- selection: DomEditSelection,
61
- element: HTMLElement,
62
- document: Document | null | undefined,
63
- ): document is Document {
64
- if (!document || !element.isConnected) return false;
65
- return element === selection.element && element.ownerDocument === document;
66
- }
67
-
68
60
  async function resyncDomTextSelectionFromPreview(
69
61
  doc: Document | null | undefined,
70
62
  selection: DomEditSelection,
@@ -96,6 +88,8 @@ export function useDomEditTextCommits({
96
88
  }: UseDomEditTextCommitsParams) {
97
89
  const latestReadOnlyPreviewRef = useRef(readOnlyPreview);
98
90
  latestReadOnlyPreviewRef.current = readOnlyPreview;
91
+ const latestSelectionRef = useRef(domEditSelection);
92
+ latestSelectionRef.current = domEditSelection;
99
93
  const domTextCommitVersionRef = useRef(new Map<string, symbol>());
100
94
  const domStyleCommitVersionRef = useRef(new Map<string, symbol>());
101
95
 
@@ -238,29 +232,36 @@ export function useDomEditTextCommits({
238
232
  */
239
233
  const handleDomRichTextCommit = useCallback(
240
234
  async ({ element, html, previousHtml }: InlineTextEditCommit) => {
241
- if (!domEditSelection) return;
242
- if (latestReadOnlyPreviewRef.current) {
235
+ const putBack = () => {
243
236
  if (element.isConnected && element.innerHTML === html) element.innerHTML = previousHtml;
244
- return;
237
+ };
238
+ if (latestReadOnlyPreviewRef.current) return putBack();
239
+ const refuse = (reason: string) => {
240
+ console.error("[Studio] text edit not saved:", reason, element);
241
+ showToast(`Couldn't save the text edit: ${reason}`, "error");
242
+ putBack();
243
+ };
244
+ // The edited node, not the current selection: a press can open an edit on a child of what
245
+ // is selected, and a host can clear the selection before the edit closes.
246
+ const doc = previewIframeRef.current?.contentDocument;
247
+ if (!doc || !element.isConnected || element.ownerDocument !== doc) {
248
+ return refuse("the text's element is gone from the preview");
249
+ }
250
+ const selection = await buildDomSelectionFromTarget(element, {
251
+ exactTarget: true,
252
+ skipSourceProbe: true,
253
+ });
254
+ if (selection?.element !== element) {
255
+ return refuse("this text was not found in the composition's source");
256
+ }
257
+ // The same gate that let the edit open, not the design panel's field rule: an element
258
+ // whose text holds a line break has no fields, and editing in place rewrites its markup.
259
+ if (!canCommitInlineTextSelection(selection, element)) {
260
+ return refuse("this text can't be edited in place");
245
261
  }
246
- // The same gate that let the edit open, not the design panel's.
247
- //
248
- // The panel's rule is about its text fields, and it has none for an
249
- // element whose text contains a line break: a `<span>` holding `<br>`s
250
- // is not a leaf, so nothing inside is a field and the element reports no
251
- // editable text at all. Editing in place does not use fields — it
252
- // rewrites the element's own markup — so refusing on that rule refused
253
- // elements the caret had just been opened in, and every colour the user
254
- // chose was dropped on the way out with nothing said about it.
255
- if (!canCommitInlineTextSelection(domEditSelection, element)) return;
256
- const iframe = previewIframeRef.current;
257
- const doc = iframe?.contentDocument;
258
- // A preview reload replaces the document. Never resolve this commit onto
259
- // the replacement node: it did not own the edit or its rollback snapshot.
260
- if (!ownsCurrentPreviewElement(domEditSelection, element, doc)) return;
261
262
  const isLatestTextCommit = bumpDomEditCommitMapVersion(
262
263
  domTextCommitVersionRef.current,
263
- getDomEditTargetKey(domEditSelection),
264
+ getDomEditTargetKey(selection),
264
265
  );
265
266
  const operations = [buildDomEditRichTextPatchOperation(html)];
266
267
  let appliedHtml = "";
@@ -274,7 +275,7 @@ export function useDomEditTextCommits({
274
275
  appliedHtml = element.innerHTML;
275
276
  },
276
277
  persist: async () => {
277
- await persistDomEditOperations(domEditSelection, operations, {
278
+ await persistDomEditOperations(selection, operations, {
278
279
  label: "Edit text",
279
280
  skipRefresh: true,
280
281
  shouldSave: isLatestTextCommit,
@@ -288,13 +289,13 @@ export function useDomEditTextCommits({
288
289
  element.innerHTML = previousHtml;
289
290
  }
290
291
  },
291
- onError: (error) =>
292
- reportDomEditPersistFailure(domEditSelection, operations, error, showToast),
293
- shouldResync: isLatestTextCommit,
292
+ onError: (error) => reportDomEditPersistFailure(selection, operations, error, showToast),
293
+ // Re-select only what is still selected: the selection may have moved on, or a host cleared it.
294
+ shouldResync: () => isLatestTextCommit() && latestSelectionRef.current?.element === element,
294
295
  resync: () =>
295
296
  resyncDomTextSelectionFromPreview(
296
297
  doc,
297
- domEditSelection,
298
+ selection,
298
299
  activeCompPath,
299
300
  buildDomSelectionFromTarget,
300
301
  applyDomSelection,
@@ -306,7 +307,6 @@ export function useDomEditTextCommits({
306
307
  activeCompPath,
307
308
  applyDomSelection,
308
309
  buildDomSelectionFromTarget,
309
- domEditSelection,
310
310
  persistDomEditOperations,
311
311
  previewIframeRef,
312
312
  showToast,
@@ -16,6 +16,11 @@ vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
16
16
 
17
17
  const SOURCE = '<div id="card">Card</div><div id="other">Other</div>';
18
18
 
19
+ /** GSAP already renders this element's transform, so a move takes the GSAP writer. */
20
+ function gsapPositioned(element: HTMLElement): HTMLElement {
21
+ return Object.assign(element, { _gsap: { renderTransform: () => {} } });
22
+ }
23
+
19
24
  /** A warm parse where only another element animates, and a GSAP writer answering `status`. */
20
25
  function stubServer(status = 200, parseStatus = 200) {
21
26
  const mutations: unknown[] = [];
@@ -116,7 +121,8 @@ describe("useDomGeometryCommit, from the package entry", () => {
116
121
  onRotationCommit: hook().commitRotation,
117
122
  };
118
123
 
119
- const outcome = await overlayCommits.onPathOffsetCommit(makeSelection("card", element), {
124
+ const card = makeSelection("card", gsapPositioned(element));
125
+ const outcome = await overlayCommits.onPathOffsetCommit(card, {
120
126
  x: 40,
121
127
  y: 20,
122
128
  });
@@ -132,6 +138,56 @@ describe("useDomGeometryCommit, from the package entry", () => {
132
138
  unmount();
133
139
  });
134
140
 
141
+ function stubPatchServer(patchStatus = 200) {
142
+ const calls = { urls: [] as string[], patches: [] as unknown[] };
143
+ vi.stubGlobal(
144
+ "fetch",
145
+ vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
146
+ const url = String(input instanceof Request ? input.url : input);
147
+ calls.urls.push(url);
148
+ if (url.includes("/patch-element/")) calls.patches.push(JSON.parse(String(init?.body)));
149
+ const saved = { ok: true, changed: true, matched: true, content: "AFTER", version: "v2" };
150
+ const body = url.includes("/files/") ? { content: SOURCE } : saved;
151
+ const status = url.includes("/patch-element/") ? patchStatus : 200;
152
+ return new Response(JSON.stringify(body), {
153
+ status,
154
+ headers: { "content-type": "application/json" },
155
+ });
156
+ }),
157
+ );
158
+ return calls;
159
+ }
160
+
161
+ it("saves a GSAP-free move as its inline translate, with no GSAP script and no animation read", async () => {
162
+ const calls = stubPatchServer();
163
+ const { element, recordEdit, hook, unmount } = renderHost();
164
+
165
+ const card = makeSelection("card", element);
166
+ await expect(hook().commitPathOffset(card, { x: 130.5, y: 90 })).resolves.toEqual({ ok: true });
167
+
168
+ expect(element.style.getPropertyValue("translate")).toBe("130.5px 90px");
169
+ expect(calls.patches).toEqual([
170
+ expect.objectContaining({
171
+ operations: [{ type: "inline-style", property: "translate", value: "130.5px 90px" }],
172
+ }),
173
+ ]);
174
+ expect(calls.urls.filter((url) => url.includes("gsap"))).toEqual([]);
175
+ expect(recordEdit).toHaveBeenCalledTimes(1);
176
+ unmount();
177
+ });
178
+
179
+ it("puts a GSAP-free element's translate back when its move cannot be saved", async () => {
180
+ stubPatchServer(500);
181
+ const { element, hook, unmount } = renderHost();
182
+ element.style.setProperty("translate", "40px 30px");
183
+
184
+ await expect(
185
+ hook().commitPathOffset(makeSelection("card", element), { x: 1, y: 2 }),
186
+ ).rejects.toThrow();
187
+ expect(element.style.getPropertyValue("translate")).toBe("40px 30px");
188
+ unmount();
189
+ });
190
+
135
191
  it("keeps the same commits across renders, so the overlay's handlers stay put", () => {
136
192
  stubServer();
137
193
  const { hook, rerender, unmount } = renderHost();
@@ -148,7 +204,7 @@ describe("useDomGeometryCommit, from the package entry", () => {
148
204
  const { element, recordEdit, hook, unmount } = renderHost({ showToast });
149
205
 
150
206
  await expect(
151
- hook().commitPathOffset(makeSelection("card", element), { x: 40, y: 20 }),
207
+ hook().commitPathOffset(makeSelection("card", gsapPositioned(element)), { x: 40, y: 20 }),
152
208
  ).rejects.toThrow();
153
209
  expect(recordEdit).not.toHaveBeenCalled();
154
210
  expect(showToast).toHaveBeenCalledWith(expect.any(String), "error");
@@ -204,7 +260,8 @@ describe("useDomGeometryCommit, from the package entry", () => {
204
260
  const mutations = stubServer();
205
261
  const { element, recordEdit, hook, unmount } = renderHost();
206
262
 
207
- const move = hook().commitPathOffset(makeSelection("card", element), { x: 40, y: 20 });
263
+ const card = makeSelection("card", gsapPositioned(element));
264
+ const move = hook().commitPathOffset(card, { x: 40, y: 20 });
208
265
  await hook().waitForPendingSaves();
209
266
 
210
267
  expect(mutations).toHaveLength(1);
@@ -280,7 +337,8 @@ describe("useDomGeometryCommit, one word of a staggered phrase", () => {
280
337
  offsetLeft: { get: () => 100 + (Number.parseFloat(word.style.left) || 0) },
281
338
  offsetTop: { get: () => 200 + (Number.parseFloat(word.style.top) || 0) },
282
339
  });
283
- return { ...makeSelection("How", word), id: undefined, selector: ".w", hfId: "hf-w0" };
340
+ const selection = makeSelection("How", gsapPositioned(word));
341
+ return { ...selection, id: undefined, selector: ".w", hfId: "hf-w0" };
284
342
  }
285
343
 
286
344
  it("saves left/top on the dragged word only and never rewrites the shared tween", async () => {
@@ -147,8 +147,10 @@ describe("useDomGeometryCommits read-only preview", () => {
147
147
  });
148
148
 
149
149
  describe("useDomGeometryCommits element position offset", () => {
150
- it("persists left/top on the element and no translate offset", async () => {
151
- const element = document.createElement("span");
150
+ it("persists left/top on a word a shared tween positions, and no translate offset", async () => {
151
+ const element = Object.assign(document.createElement("span"), {
152
+ _gsap: { renderTransform: () => {} },
153
+ });
152
154
  Object.defineProperties(element, {
153
155
  offsetLeft: { get: () => 100 + (Number.parseFloat(element.style.left) || 0) },
154
156
  offsetTop: { get: () => 200 + (Number.parseFloat(element.style.top) || 0) },