@hyperframes/studio 0.9.56 → 0.9.58
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/{hyperframes-player-SRLbmEDB.js → hyperframes-player-B78JDyI_.js} +1 -1
- package/dist/assets/{index-CgyBYe2L.js → index-D7ICtobF.js} +178 -178
- package/dist/assets/{index-yuN1pZrv.js → index-ww7-RmuM.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-DtvSF8bV.js → pausedVideoDecoder-Dbe8Cmab.js} +1 -1
- package/dist/index.d.ts +87 -3
- package/dist/index.html +1 -1
- package/dist/index.js +867 -774
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +35 -3
- package/src/components/nle/NLEPreview.tsx +5 -4
- package/src/hooks/gsapRuntimePatch.ts +2 -3
- package/src/hooks/gsapRuntimeReaders.test.ts +5 -40
- package/src/hooks/gsapRuntimeReaders.ts +3 -27
- package/src/hooks/useExternalFileChangeCoordinator.test.tsx +20 -0
- package/src/hooks/useExternalFileChangeCoordinator.ts +1 -1
- package/src/index.ts +17 -0
- package/src/player/components/studioShortcuts.ts +3 -2
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -0
- package/src/player/hooks/timelineSyncHydration.test.ts +28 -2
- package/src/player/hooks/timelineSyncHydration.ts +3 -7
- package/src/player/hooks/usePlaybackKeyboard.test.ts +107 -2
- package/src/player/hooks/usePlaybackKeyboard.ts +38 -1
- package/src/player/hooks/useShadowPreviewReload.ts +131 -14
- package/src/player/hooks/useTimelinePlayer.reloadStill.test.ts +241 -0
- package/src/player/hooks/useTimelinePlayer.ts +13 -1
- package/src/player/hooks/useTimelineSyncCallbacks.ts +4 -0
- package/src/sealedPreviewExports.test.ts +20 -0
- package/src/utils/externalConflictStorage.test.ts +66 -14
- package/src/utils/externalConflictStorage.ts +36 -82
- package/src/utils/gsapSoftReload.ts +2 -14
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { createStudioApi } from "@hyperframes/studio-server";
|
|
1
2
|
import { IDBFactory } from "fake-indexeddb";
|
|
3
|
+
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
2
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
7
|
import {
|
|
4
8
|
createMemoryExternalConflictStorage,
|
|
@@ -9,6 +13,27 @@ import {
|
|
|
9
13
|
} from "./externalConflictStorage";
|
|
10
14
|
import { StudioFileConflictError } from "./studioSaveDiagnostics";
|
|
11
15
|
|
|
16
|
+
const made: string[] = [];
|
|
17
|
+
|
|
18
|
+
/** Studio's real API for one project, "demo", answering the store's fetches. */
|
|
19
|
+
function serveProject(): string {
|
|
20
|
+
const dir = mkdtempSync(join(tmpdir(), "hf-drafts-"));
|
|
21
|
+
made.push(dir);
|
|
22
|
+
const api = createStudioApi({
|
|
23
|
+
listProjects: () => [],
|
|
24
|
+
resolveProject: async (id: string) => (id === "demo" ? { id, dir, title: "Demo" } : null),
|
|
25
|
+
bundle: async () => null,
|
|
26
|
+
lint: async () => ({ findings: [] }),
|
|
27
|
+
runtimeUrl: "/api/runtime.js",
|
|
28
|
+
rendersDir: () => join(dir, "renders"),
|
|
29
|
+
startRender: () => ({ id: "job", status: "rendering", progress: 0, outputPath: "" }),
|
|
30
|
+
});
|
|
31
|
+
vi.stubGlobal("fetch", (input: string, init?: RequestInit) =>
|
|
32
|
+
api.fetch(new Request(`http://localhost${input.replace(/^\/api/, "")}`, init)),
|
|
33
|
+
);
|
|
34
|
+
return dir;
|
|
35
|
+
}
|
|
36
|
+
|
|
12
37
|
describe("external conflict snapshots", () => {
|
|
13
38
|
beforeEach(() => {
|
|
14
39
|
vi.stubGlobal("indexedDB", new IDBFactory());
|
|
@@ -17,6 +42,7 @@ describe("external conflict snapshots", () => {
|
|
|
17
42
|
afterEach(() => {
|
|
18
43
|
vi.restoreAllMocks();
|
|
19
44
|
vi.unstubAllGlobals();
|
|
45
|
+
for (const dir of made.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
20
46
|
});
|
|
21
47
|
|
|
22
48
|
it("durably records both complete file versions before resolution", async () => {
|
|
@@ -54,8 +80,8 @@ describe("external conflict snapshots", () => {
|
|
|
54
80
|
expect(await storage.get("project-a", "index.html")).toEqual(snapshot);
|
|
55
81
|
});
|
|
56
82
|
|
|
57
|
-
it("persists, loads, and deletes a
|
|
58
|
-
|
|
83
|
+
it("persists, loads, and deletes a draft through the project's own server", async () => {
|
|
84
|
+
const project = serveProject();
|
|
59
85
|
const conflict = new StudioFileConflictError({
|
|
60
86
|
filePath: "index.html",
|
|
61
87
|
currentVersion: "v2",
|
|
@@ -63,24 +89,50 @@ describe("external conflict snapshots", () => {
|
|
|
63
89
|
attemptedContent: "studio full file",
|
|
64
90
|
});
|
|
65
91
|
|
|
66
|
-
await persistExternalConflictSnapshot("
|
|
67
|
-
|
|
92
|
+
await persistExternalConflictSnapshot("demo", conflict);
|
|
93
|
+
expect(readdirSync(join(project, ".hyperframes", "recovery"))).toHaveLength(1);
|
|
94
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toMatchObject({
|
|
68
95
|
kind: "conflict",
|
|
69
|
-
projectId: "
|
|
96
|
+
projectId: "demo",
|
|
70
97
|
filePath: "index.html",
|
|
71
98
|
externalVersion: "v2",
|
|
72
99
|
externalContent: "external full file",
|
|
73
100
|
studioContent: "studio full file",
|
|
74
|
-
createdAt: 1234,
|
|
75
101
|
});
|
|
76
|
-
await deleteExternalConflictSnapshot("
|
|
77
|
-
await expect(
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
await deleteExternalConflictSnapshot("demo", "index.html");
|
|
103
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toBeNull();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Every project previewed on a port shares the origin's IndexedDB, and so does each one's composition code.
|
|
107
|
+
it("never offers a draft another project's code planted in the browser's shared IndexedDB", async () => {
|
|
108
|
+
serveProject();
|
|
109
|
+
const open = indexedDB.open("hyperframes-studio-external-conflicts", 1);
|
|
110
|
+
open.onupgradeneeded = () => open.result.createObjectStore("file-conflicts");
|
|
111
|
+
const db = await new Promise<IDBDatabase>(
|
|
112
|
+
(resolve) => (open.onsuccess = () => resolve(open.result)),
|
|
113
|
+
);
|
|
114
|
+
const planted = db.transaction("file-conflicts", "readwrite");
|
|
115
|
+
planted.objectStore("file-conflicts").put(
|
|
116
|
+
{
|
|
117
|
+
kind: "failed",
|
|
118
|
+
projectId: "demo",
|
|
119
|
+
filePath: "index.html",
|
|
120
|
+
externalVersion: null,
|
|
121
|
+
externalContent: null,
|
|
122
|
+
studioContent: "<script>planted</script>",
|
|
123
|
+
failureMessage: "Recovered draft",
|
|
124
|
+
createdAt: Date.now(),
|
|
125
|
+
},
|
|
126
|
+
"demo\0index.html",
|
|
127
|
+
);
|
|
128
|
+
await new Promise((resolve) => (planted.oncomplete = resolve));
|
|
129
|
+
db.close();
|
|
130
|
+
|
|
131
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toBeNull();
|
|
80
132
|
});
|
|
81
133
|
|
|
82
|
-
it("rejects persistence when
|
|
83
|
-
vi.stubGlobal("
|
|
134
|
+
it("rejects persistence when the server cannot keep the draft", async () => {
|
|
135
|
+
vi.stubGlobal("fetch", async () => new Response("{}", { status: 500 }));
|
|
84
136
|
const conflict = new StudioFileConflictError({
|
|
85
137
|
filePath: "index.html",
|
|
86
138
|
currentVersion: "v2",
|
|
@@ -88,8 +140,8 @@ describe("external conflict snapshots", () => {
|
|
|
88
140
|
attemptedContent: "studio",
|
|
89
141
|
});
|
|
90
142
|
|
|
91
|
-
await expect(persistExternalConflictSnapshot("
|
|
92
|
-
"
|
|
143
|
+
await expect(persistExternalConflictSnapshot("demo", conflict)).rejects.toThrow(
|
|
144
|
+
"Recovery draft storage failed (500)",
|
|
93
145
|
);
|
|
94
146
|
});
|
|
95
147
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StudioFileConflictError } from "./studioSaveDiagnostics";
|
|
2
|
+
import { studioApiFetch } from "./studioApiFetch";
|
|
2
3
|
|
|
3
4
|
interface ExternalRecoverySnapshotBase {
|
|
4
5
|
projectId: string;
|
|
@@ -19,10 +20,6 @@ export interface ExternalConflictStorage {
|
|
|
19
20
|
delete(projectId: string, filePath: string): Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const DB_NAME = "hyperframes-studio-external-conflicts";
|
|
23
|
-
const DB_VERSION = 1;
|
|
24
|
-
const STORE_NAME = "file-conflicts";
|
|
25
|
-
|
|
26
23
|
function key(projectId: string, filePath: string): string {
|
|
27
24
|
return `${projectId}\0${filePath}`;
|
|
28
25
|
}
|
|
@@ -43,85 +40,46 @@ export function createMemoryExternalConflictStorage(): ExternalConflictStorage {
|
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
function
|
|
47
|
-
return
|
|
48
|
-
if (!globalThis.indexedDB) {
|
|
49
|
-
reject(new Error("IndexedDB is unavailable; conflict recovery snapshot was not saved"));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const request = globalThis.indexedDB.open(DB_NAME, DB_VERSION);
|
|
53
|
-
request.onupgradeneeded = () => {
|
|
54
|
-
if (!request.result.objectStoreNames.contains(STORE_NAME)) {
|
|
55
|
-
request.result.createObjectStore(STORE_NAME);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
request.onerror = () => reject(request.error ?? new Error("Failed to open conflict storage"));
|
|
59
|
-
request.onsuccess = () => resolve(request.result);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function withStore<T>(
|
|
64
|
-
mode: IDBTransactionMode,
|
|
65
|
-
callback: (store: IDBObjectStore) => IDBRequest<T>,
|
|
66
|
-
): Promise<T> {
|
|
67
|
-
return openDb().then(
|
|
68
|
-
(db) =>
|
|
69
|
-
new Promise<T>((resolve, reject) => {
|
|
70
|
-
const transaction = db.transaction(STORE_NAME, mode);
|
|
71
|
-
const request = callback(transaction.objectStore(STORE_NAME));
|
|
72
|
-
let result!: T;
|
|
73
|
-
request.onerror = () => reject(request.error ?? new Error("Conflict storage failed"));
|
|
74
|
-
request.onsuccess = () => {
|
|
75
|
-
result = request.result;
|
|
76
|
-
};
|
|
77
|
-
transaction.oncomplete = () => {
|
|
78
|
-
db.close();
|
|
79
|
-
resolve(result);
|
|
80
|
-
};
|
|
81
|
-
transaction.onerror = () => {
|
|
82
|
-
db.close();
|
|
83
|
-
reject(transaction.error ?? new Error("Conflict storage transaction failed"));
|
|
84
|
-
};
|
|
85
|
-
transaction.onabort = () => {
|
|
86
|
-
db.close();
|
|
87
|
-
reject(transaction.error ?? new Error("Conflict storage transaction was aborted"));
|
|
88
|
-
};
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
43
|
+
function draftUrl(projectId: string, filePath: string): string {
|
|
44
|
+
return `/api/projects/${encodeURIComponent(projectId)}/recovery-drafts/${encodeURIComponent(filePath)}`;
|
|
91
45
|
}
|
|
92
46
|
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
async set(snapshot) {
|
|
103
|
-
await withStore<IDBValidKey>("readwrite", (store) =>
|
|
104
|
-
store.put(snapshot, key(snapshot.projectId, snapshot.filePath)),
|
|
105
|
-
);
|
|
106
|
-
},
|
|
107
|
-
async delete(projectId, filePath) {
|
|
108
|
-
await withStore<undefined>("readwrite", (store) => store.delete(key(projectId, filePath)));
|
|
109
|
-
},
|
|
110
|
-
};
|
|
47
|
+
async function draftRequest(
|
|
48
|
+
projectId: string,
|
|
49
|
+
filePath: string,
|
|
50
|
+
init?: RequestInit,
|
|
51
|
+
): Promise<Response> {
|
|
52
|
+
const res = await studioApiFetch(draftUrl(projectId, filePath), init);
|
|
53
|
+
if (!res.ok) throw new Error(`Recovery draft storage failed (${res.status})`);
|
|
54
|
+
return res;
|
|
111
55
|
}
|
|
112
56
|
|
|
113
|
-
|
|
57
|
+
/** Kept by the project's own server: an origin-wide browser store is shared with every project on the port. */
|
|
58
|
+
const projectStorage: ExternalConflictStorage = {
|
|
59
|
+
async get(projectId, filePath) {
|
|
60
|
+
const { draft } = (await (await draftRequest(projectId, filePath)).json()) as {
|
|
61
|
+
draft: ExternalConflictSnapshot | null;
|
|
62
|
+
};
|
|
63
|
+
return draft?.projectId === projectId && draft.filePath === filePath ? draft : null;
|
|
64
|
+
},
|
|
65
|
+
async set(snapshot) {
|
|
66
|
+
await draftRequest(snapshot.projectId, snapshot.filePath, {
|
|
67
|
+
method: "PUT",
|
|
68
|
+
headers: { "content-type": "application/json" },
|
|
69
|
+
body: JSON.stringify(snapshot),
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async delete(projectId, filePath) {
|
|
73
|
+
await draftRequest(projectId, filePath, { method: "DELETE" });
|
|
74
|
+
},
|
|
75
|
+
};
|
|
114
76
|
|
|
115
|
-
/**
|
|
116
|
-
* Persist a conflict before offering destructive recovery actions.
|
|
117
|
-
* Callers must await this promise: rejection means the Studio draft was not saved durably and
|
|
118
|
-
* must remain available in memory while the storage failure is surfaced to the user.
|
|
119
|
-
*/
|
|
77
|
+
/** Saved before destructive recovery is offered; on a rejection the draft stays only in memory and the user is told. */
|
|
120
78
|
export async function persistExternalConflictSnapshot(
|
|
121
79
|
projectId: string,
|
|
122
80
|
conflict: StudioFileConflictError,
|
|
123
81
|
): Promise<void> {
|
|
124
|
-
await
|
|
82
|
+
await projectStorage.set({
|
|
125
83
|
kind: "conflict",
|
|
126
84
|
projectId,
|
|
127
85
|
filePath: conflict.filePath,
|
|
@@ -132,11 +90,7 @@ export async function persistExternalConflictSnapshot(
|
|
|
132
90
|
});
|
|
133
91
|
}
|
|
134
92
|
|
|
135
|
-
/**
|
|
136
|
-
* Persist the final Studio candidate after its file write fails.
|
|
137
|
-
* Callers must await this promise: rejection means the Studio draft was not saved durably and
|
|
138
|
-
* must remain available in memory while the storage failure is surfaced to the user.
|
|
139
|
-
*/
|
|
93
|
+
/** Studio's final candidate after its file write failed; awaited like persistExternalConflictSnapshot. */
|
|
140
94
|
export async function persistExternalFailureSnapshot(
|
|
141
95
|
projectId: string,
|
|
142
96
|
filePath: string,
|
|
@@ -145,7 +99,7 @@ export async function persistExternalFailureSnapshot(
|
|
|
145
99
|
externalContent: string | null,
|
|
146
100
|
error: unknown,
|
|
147
101
|
): Promise<void> {
|
|
148
|
-
await
|
|
102
|
+
await projectStorage.set({
|
|
149
103
|
kind: "failed",
|
|
150
104
|
projectId,
|
|
151
105
|
filePath,
|
|
@@ -161,12 +115,12 @@ export async function loadExternalConflictSnapshot(
|
|
|
161
115
|
projectId: string,
|
|
162
116
|
filePath: string,
|
|
163
117
|
): Promise<ExternalConflictSnapshot | null> {
|
|
164
|
-
return
|
|
118
|
+
return projectStorage.get(projectId, filePath);
|
|
165
119
|
}
|
|
166
120
|
|
|
167
121
|
export async function deleteExternalConflictSnapshot(
|
|
168
122
|
projectId: string,
|
|
169
123
|
filePath: string,
|
|
170
124
|
): Promise<void> {
|
|
171
|
-
await
|
|
125
|
+
await projectStorage.delete(projectId, filePath);
|
|
172
126
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
|
|
2
1
|
import { parseGsapScript } from "@hyperframes/parsers/gsap-parser";
|
|
3
2
|
import { GSAP_BASE_URL_META, motionPathPluginUrl } from "@hyperframes/core/gsap-cdn";
|
|
4
3
|
import { findAuthoredElement } from "./authoredSource";
|
|
@@ -464,24 +463,13 @@ export function applySoftReload(
|
|
|
464
463
|
s.cssText = css;
|
|
465
464
|
restoreAuthoredStyle(s, findAuthoredStyle(el), targets.get(el)!);
|
|
466
465
|
// The restored cssText carries RUNTIME opacity, not authored opacity:
|
|
467
|
-
// a mid-flight tween's interpolated value
|
|
468
|
-
// (`opacity: 0 !important`). The re-run script's tweens re-initialize
|
|
466
|
+
// a mid-flight tween's interpolated value. The re-run script's tweens re-initialize
|
|
469
467
|
// against it — a from() captures it as its END, a to() as its START —
|
|
470
468
|
// turning the transient into the tween's permanent bound (dimmed or
|
|
471
469
|
// invisible elements). Put the AUTHORED inline opacity back; the seek
|
|
472
470
|
// below re-renders the correct animated value either way.
|
|
473
471
|
const authored = readAuthoredOpacity(el);
|
|
474
|
-
if (authored !== null)
|
|
475
|
-
applyAuthoredInlineOpacity(s, authored);
|
|
476
|
-
} else if (
|
|
477
|
-
el.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR) &&
|
|
478
|
-
s.getPropertyValue("opacity") === "0" &&
|
|
479
|
-
s.getPropertyPriority("opacity") === "important"
|
|
480
|
-
) {
|
|
481
|
-
// Authored value unknown, but this is definitely the grading hide —
|
|
482
|
-
// never let a from() capture 0; fall back to the CSS cascade.
|
|
483
|
-
s.removeProperty("opacity");
|
|
484
|
-
}
|
|
472
|
+
if (authored !== null) applyAuthoredInlineOpacity(s, authored);
|
|
485
473
|
}
|
|
486
474
|
}
|
|
487
475
|
forgetLiveSets(targets);
|