@hyperframes/studio 0.9.3 → 0.9.4

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/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  document.documentElement.dataset.theme = "paper";
15
15
  }
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-CWzE624c.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-h1lPtzPa.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/assets/index-RUPGNyct.css">
19
19
  </head>
20
20
  <body>
package/dist/index.js CHANGED
@@ -17449,6 +17449,7 @@ async function writeProjectFilesWithHistoryInQueue({
17449
17449
 
17450
17450
  // src/utils/gsapSoftReload.ts
17451
17451
  import { COLOR_GRADING_SOURCE_HIDDEN_ATTR as COLOR_GRADING_SOURCE_HIDDEN_ATTR2 } from "@hyperframes/core/color-grading";
17452
+ import { parseGsapScript as parseGsapScript2 } from "@hyperframes/parsers/gsap-parser";
17452
17453
  import { GSAP_BASE_URL_META, motionPathPluginUrl } from "@hyperframes/core/gsap-cdn";
17453
17454
 
17454
17455
  // src/utils/authoredSource.ts
@@ -17828,6 +17829,27 @@ function applySoftReloadFinalization(iframe, currentTime) {
17828
17829
  return false;
17829
17830
  }
17830
17831
  }
17832
+ var animatedBy = (doc, scriptText) => {
17833
+ const animated = /* @__PURE__ */ new Set();
17834
+ for (const { targetSelector } of parseGsapScript2(scriptText).animations) {
17835
+ try {
17836
+ for (const element of doc.querySelectorAll(targetSelector)) animated.add(element);
17837
+ } catch {
17838
+ }
17839
+ }
17840
+ return animated;
17841
+ };
17842
+ function repaintDroppedTweenStyle(win, doc, authored, targetKeys, restoredScript) {
17843
+ const live = findGsapScriptElements(doc).map((script) => script.textContent ?? "").join("");
17844
+ if (live === (restoredScript ?? "")) return;
17845
+ const kept = restoredScript ? animatedBy(doc, restoredScript) : /* @__PURE__ */ new Set();
17846
+ for (const [element, tweened] of collectResetTargets(win, doc, targetKeys)) {
17847
+ if (kept.has(element)) continue;
17848
+ const source = findAuthoredElement(authored, element);
17849
+ const style = source instanceof HTMLElement || source instanceof SVGElement ? source.style : null;
17850
+ restoreAuthoredStyle(element.style, style, tweened);
17851
+ }
17852
+ }
17831
17853
  function timelineKeys(scriptText) {
17832
17854
  return [...scriptText.matchAll(/__timelines\s*\[\s*["'`]([^"'`]+)["'`]\s*\]/g)].map((m) => m[1]).filter((key2) => key2 !== "__proxied");
17833
17855
  }
@@ -76544,6 +76566,17 @@ function readUndoNestedFiles(iframe, activeCompPath, files, readFile) {
76544
76566
  const script = active ? extractGsapScriptText(active.restored) : null;
76545
76567
  return script ? readNestedFiles(iframe, script, readFile) : null;
76546
76568
  }
76569
+ function repaintWhileReloading(win, doc, restored) {
76570
+ const keys = findGsapScriptElements(doc).flatMap((s) => timelineKeys(s.textContent ?? ""));
76571
+ if (!restored || keys.length === 0) return;
76572
+ repaintDroppedTweenStyle(
76573
+ win,
76574
+ doc,
76575
+ parseRestoreSource(restored),
76576
+ keys,
76577
+ extractGsapScriptText(restored)
76578
+ );
76579
+ }
76547
76580
  function applyUndoRestoreToPreview(iframe, activeCompPath, files, currentTime, reload, nestedFiles) {
76548
76581
  const activeDocPath = activeCompPath ?? "index.html";
76549
76582
  const paths = files ? Object.keys(files) : [];
@@ -76555,6 +76588,7 @@ function applyUndoRestoreToPreview(iframe, activeCompPath, files, currentTime, r
76555
76588
  const win = iframe?.contentWindow;
76556
76589
  const plan = doc && files && win ? planRestoreTargets(doc, activeDocPath, files) : null;
76557
76590
  if (!iframe || !doc || !files || !win || !plan) {
76591
+ if (doc && win) repaintWhileReloading(win, doc, files?.[activeDocPath]?.restored);
76558
76592
  reloadPreview();
76559
76593
  return "full";
76560
76594
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,12 +60,12 @@
60
60
  "dockview-react": "8.3.1",
61
61
  "gsap": "^3.13.0",
62
62
  "mediabunny": "^1.45.3",
63
- "@hyperframes/player": "0.9.3",
64
- "@hyperframes/parsers": "0.9.3",
65
- "@hyperframes/shader-transitions": "0.9.3",
66
- "@hyperframes/sdk": "0.9.3",
67
- "@hyperframes/core": "0.9.3",
68
- "@hyperframes/studio-server": "0.9.3"
63
+ "@hyperframes/core": "0.9.4",
64
+ "@hyperframes/player": "0.9.4",
65
+ "@hyperframes/sdk": "0.9.4",
66
+ "@hyperframes/shader-transitions": "0.9.4",
67
+ "@hyperframes/studio-server": "0.9.4",
68
+ "@hyperframes/parsers": "0.9.4"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@tailwindcss/vite": "^4.3.3",
@@ -82,7 +82,7 @@
82
82
  "vite": "^6.4.2",
83
83
  "vitest": "^4.1.11",
84
84
  "zustand": "^5.0.0",
85
- "@hyperframes/producer": "0.9.3"
85
+ "@hyperframes/producer": "0.9.4"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "react": "19",
@@ -1,4 +1,5 @@
1
1
  import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
2
+ import { parseGsapScript } from "@hyperframes/parsers/gsap-parser";
2
3
  import { GSAP_BASE_URL_META, motionPathPluginUrl } from "@hyperframes/core/gsap-cdn";
3
4
  import { findAuthoredElement } from "./authoredSource";
4
5
  import { applyAuthoredInlineOpacity, readStampedAuthoredOpacity } from "./authoredOpacity";
@@ -298,6 +299,40 @@ export function applySoftReloadFinalization(
298
299
  }
299
300
  }
300
301
 
302
+ const animatedBy = (doc: Document, scriptText: string): Set<Element> => {
303
+ const animated = new Set<Element>();
304
+ for (const { targetSelector } of parseGsapScript(scriptText).animations) {
305
+ try {
306
+ for (const element of doc.querySelectorAll(targetSelector)) animated.add(element);
307
+ } catch {
308
+ // A selector this document cannot parse animates nothing in it.
309
+ }
310
+ }
311
+ return animated;
312
+ };
313
+
314
+ /** Authored style back on the elements the restored script stops animating, before a reload lands. */
315
+ export function repaintDroppedTweenStyle(
316
+ win: IframeWindow,
317
+ doc: Document,
318
+ authored: Document,
319
+ targetKeys: string[],
320
+ restoredScript: string | null,
321
+ ): void {
322
+ const live = findGsapScriptElements(doc)
323
+ .map((script) => script.textContent ?? "")
324
+ .join("");
325
+ if (live === (restoredScript ?? "")) return;
326
+ const kept = restoredScript ? animatedBy(doc, restoredScript) : new Set<Element>();
327
+ for (const [element, tweened] of collectResetTargets(win, doc, targetKeys)) {
328
+ if (kept.has(element)) continue;
329
+ const source = findAuthoredElement(authored, element);
330
+ const style =
331
+ source instanceof HTMLElement || source instanceof SVGElement ? source.style : null;
332
+ restoreAuthoredStyle((element as HTMLElement).style, style, tweened);
333
+ }
334
+ }
335
+
301
336
  export function timelineKeys(scriptText: string): string[] {
302
337
  return [...scriptText.matchAll(/__timelines\s*\[\s*["'`]([^"'`]+)["'`]\s*\]/g)]
303
338
  .map((m) => m[1]!)
@@ -115,6 +115,50 @@ function buildLiveIframe(bodyHtml: string) {
115
115
  describe("applyUndoRestoreToPreview", () => {
116
116
  const ROOT = "index.html";
117
117
 
118
+ it("takes GSAP's composed transform off the preview it is about to reload", () => {
119
+ // Undoing "enable keyframes" removes the script: no in-place patch expresses that, so the
120
+ // preview reloads — and until it lands it shows where the timeline last put the box, though
121
+ // the file it is going back to places it with CSS and no inline transform at all.
122
+ const tween = `window.__timelines["root"]=gsap.timeline().to("#a",{x:139.893,y:-195.508});`;
123
+ const film = (box: string, script: string) =>
124
+ `<div data-composition-id="root"><div id="a"${box}>a</div></div>${script}`;
125
+ const composed = ` style="transform: translate(139.893px, -195.508px)"`;
126
+ const { iframe, doc } = buildLiveIframe(film(composed, `<script>${tween}</script>`));
127
+ recordLiveSet(doc.getElementById("a")!, { x: 139.893, y: -195.508 });
128
+ const files = {
129
+ [ROOT]: {
130
+ previous: wrap(film("", `<script>${tween}</script>`)),
131
+ restored: wrap(film("", "")),
132
+ },
133
+ };
134
+
135
+ expect(applyUndoRestoreToPreview(iframe, ROOT, files, 3, vi.fn())).toBe("full");
136
+
137
+ expect(doc.getElementById("a")!.style.transform).toBe("");
138
+ });
139
+
140
+ it("leaves a still-animated element alone when the restore only removes another", () => {
141
+ // Nothing about the animation changed: #a is where the live timeline put it, and the reload
142
+ // re-renders it. Clearing it here would flash the box back to its authored place first.
143
+ const script = `window.__timelines["root"]=gsap.timeline().to("#a",{x:100});`;
144
+ const film = (body: string) =>
145
+ `<div data-composition-id="root">${body}</div><script>${script}</script>`;
146
+ const { iframe, doc } = buildLiveIframe(
147
+ film(`<div id="a" style="transform: translate(100px, 0px)">a</div><div id="b">b</div>`),
148
+ );
149
+ recordLiveSet(doc.getElementById("a")!, { x: 100 });
150
+ const files = {
151
+ [ROOT]: {
152
+ previous: wrap(film(`<div id="a">a</div><div id="b">b</div>`)),
153
+ restored: wrap(film(`<div id="a">a</div>`)),
154
+ },
155
+ };
156
+
157
+ expect(applyUndoRestoreToPreview(iframe, ROOT, files, 3, vi.fn())).toBe("full");
158
+
159
+ expect(doc.getElementById("a")!.style.transform).toBe("translate(100px, 0px)");
160
+ });
161
+
118
162
  it("never stamps an undo whose sides are both already stamped", () => {
119
163
  const film = (color: string) =>
120
164
  `<div id="root" data-composition-id="root"><div id="target" style="background-color: ${color}">T</div><p>caption</p></div>`;
@@ -8,6 +8,8 @@ import {
8
8
  extractGsapScriptText,
9
9
  findGsapScriptElements,
10
10
  readNestedFiles,
11
+ repaintDroppedTweenStyle,
12
+ timelineKeys,
11
13
  } from "./gsapSoftReload";
12
14
  import { ensureHfIds, isCompositionTemplate } from "@hyperframes/parsers/hf-ids";
13
15
  import { findAuthoredElement, parseSavedSource } from "./authoredSource";
@@ -341,6 +343,19 @@ export function readUndoNestedFiles(
341
343
  return script ? readNestedFiles(iframe, script, readFile) : null;
342
344
  }
343
345
 
346
+ /** A preview about to reload still shows the timeline's last composed transform; take it back to the file. */
347
+ function repaintWhileReloading(win: PreviewWindow, doc: Document, restored?: string): void {
348
+ const keys = findGsapScriptElements(doc).flatMap((s) => timelineKeys(s.textContent ?? ""));
349
+ if (!restored || keys.length === 0) return;
350
+ repaintDroppedTweenStyle(
351
+ win,
352
+ doc,
353
+ parseRestoreSource(restored),
354
+ keys,
355
+ extractGsapScriptText(restored),
356
+ );
357
+ }
358
+
344
359
  /**
345
360
  * Soft-apply an undo/redo restore to the live preview WITHOUT a full iframe
346
361
  * remount (which blanks the frame black and re-flashes the WebGL context). Eligible
@@ -391,6 +406,7 @@ export function applyUndoRestoreToPreview(
391
406
  const win = iframe?.contentWindow as PreviewWindow | null;
392
407
  const plan = doc && files && win ? planRestoreTargets(doc, activeDocPath, files) : null;
393
408
  if (!iframe || !doc || !files || !win || !plan) {
409
+ if (doc && win) repaintWhileReloading(win, doc, files?.[activeDocPath]?.restored);
394
410
  reloadPreview();
395
411
  return "full";
396
412
  }