dopesheet 0.0.0-stage → 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +78 -2
- package/bin/dopesheet.mjs +50 -0
- package/dist/browser/client.js +9 -0
- package/dist/browser/client.js.map +1 -0
- package/dist/browser/runtime.js +1 -0
- package/dist/browser/src-C-7lxf9e.js +2735 -0
- package/dist/browser/src-C-7lxf9e.js.map +1 -0
- package/dist/browser/src-D2ttZ_j7.js +7089 -0
- package/dist/browser/src-D2ttZ_j7.js.map +1 -0
- package/dist/browser/ui.js +1 -0
- package/dist/index.js +11 -0
- package/dist/loader.cjs +24 -0
- package/dist/next.js +81 -0
- package/dist/shared-CdhNdlQj.js +47 -0
- package/dist/shared-DpUIelWp.js +1454 -0
- package/dist/shared-E9l6ZbF6.js +102 -0
- package/dist/transform.js +2 -0
- package/dist/vite.js +16 -0
- package/docs/agents.md +38 -0
- package/package.json +90 -3
- package/types/next.d.ts +10 -0
- package/types/vite.d.ts +11 -0
- package/types/webpack.d.ts +14 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { a as instrument, i as saveEdits, r as relocateSites, t as SourceCache } from "./shared-DpUIelWp.js";
|
|
3
|
+
import { relative, sep } from "node:path";
|
|
4
|
+
// ../unplugin/src/transform.ts
|
|
5
|
+
var DEFAULT_PORT = 4855;
|
|
6
|
+
var SCRIPT_RE = /\.[cm]?[jt]sx?$/;
|
|
7
|
+
var QUICK_RE = /\.(to|from|fromTo|set|timeline)\s*\(|\.effects\./;
|
|
8
|
+
/** Comments, then at most one directive ("use client"). */
|
|
9
|
+
var PROLOGUE_RE = /^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*(?:(["'])use ([a-z ]+)\1\s*;?)?/;
|
|
10
|
+
var caches = /* @__PURE__ */ new Map();
|
|
11
|
+
function cacheFor(dir) {
|
|
12
|
+
const key = dir ?? "";
|
|
13
|
+
let c = caches.get(key);
|
|
14
|
+
if (!c) caches.set(key, c = new SourceCache(500, dir));
|
|
15
|
+
return c;
|
|
16
|
+
}
|
|
17
|
+
var posix = (p) => p.split(sep).join("/");
|
|
18
|
+
/**
|
|
19
|
+
* The bundler transform: tags GSAP calls like the Vite plugin does, and makes the module import the
|
|
20
|
+
* editor client first (so the runtime is installed before any GSAP call runs). The import goes on
|
|
21
|
+
* the directive's line, so line numbers (and source maps' lines) don't move.
|
|
22
|
+
*/
|
|
23
|
+
function transform(code, id, options = {}) {
|
|
24
|
+
const file = posix(id.split("?")[0]);
|
|
25
|
+
if (!SCRIPT_RE.test(file) || file.includes("/node_modules/") || file.includes("/.next/")) return null;
|
|
26
|
+
if (!QUICK_RE.test(code)) return null;
|
|
27
|
+
const prologue = PROLOGUE_RE.exec(code);
|
|
28
|
+
if (prologue[2] === "server") return null;
|
|
29
|
+
const root = options.root ?? process.cwd();
|
|
30
|
+
const fileId = posix(relative(root, file));
|
|
31
|
+
cacheFor(options.sourcesDir).remember(code);
|
|
32
|
+
const out = instrument(code, file, fileId);
|
|
33
|
+
if (!out) return null;
|
|
34
|
+
const server = options.server ?? `http://127.0.0.1:4855`;
|
|
35
|
+
const boot = `import ${JSON.stringify(options.client ?? "@dopesheet/unplugin/client")}; globalThis.__DOPESHEET_SERVER__ ??= ${JSON.stringify(server)};`;
|
|
36
|
+
const at = prologue[1] ? prologue[0].length : 0;
|
|
37
|
+
return {
|
|
38
|
+
code: at ? `${out.code.slice(0, at)} ${boot}${out.code.slice(at)}` : `${boot} ${out.code}`,
|
|
39
|
+
map: out.map
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// ../unplugin/src/server.ts
|
|
43
|
+
/** Pages on this machine only: the server writes into the project. */
|
|
44
|
+
var LOCAL_ORIGIN = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/;
|
|
45
|
+
async function body(req) {
|
|
46
|
+
const chunks = [];
|
|
47
|
+
for await (const c of req) chunks.push(c);
|
|
48
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
49
|
+
}
|
|
50
|
+
function reply(res, status, data) {
|
|
51
|
+
res.statusCode = status;
|
|
52
|
+
res.setHeader("content-type", "application/json");
|
|
53
|
+
res.end(JSON.stringify(data));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The save server for bundlers without a dev-server hook (webpack, Next.js): the same save and
|
|
57
|
+
* relocate endpoints as the Vite plugin, on 127.0.0.1, for pages served from localhost.
|
|
58
|
+
* Resolves to null when another process already serves the port (Next.js loads its config in
|
|
59
|
+
* several processes).
|
|
60
|
+
*/
|
|
61
|
+
function startServer(options = {}) {
|
|
62
|
+
const root = options.root ?? process.cwd();
|
|
63
|
+
const sources = new SourceCache(500, options.sourcesDir);
|
|
64
|
+
const server = createServer((req, res) => {
|
|
65
|
+
const origin = req.headers.origin;
|
|
66
|
+
if (origin) {
|
|
67
|
+
if (!LOCAL_ORIGIN.test(origin)) return reply(res, 403, {
|
|
68
|
+
ok: false,
|
|
69
|
+
error: "Not a local page"
|
|
70
|
+
});
|
|
71
|
+
res.setHeader("access-control-allow-origin", origin);
|
|
72
|
+
res.setHeader("access-control-allow-methods", "POST, OPTIONS");
|
|
73
|
+
res.setHeader("access-control-allow-headers", "content-type");
|
|
74
|
+
res.setHeader("vary", "origin");
|
|
75
|
+
}
|
|
76
|
+
if (req.method === "OPTIONS") return void (res.statusCode = 204, res.end());
|
|
77
|
+
if (req.method !== "POST") return reply(res, 405, {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: "POST only"
|
|
80
|
+
});
|
|
81
|
+
const path = (req.url ?? "").split("?")[0];
|
|
82
|
+
(async () => {
|
|
83
|
+
if (path === "/__dopesheet/save") return reply(res, 200, await saveEdits(root, JSON.parse(await body(req)), sources));
|
|
84
|
+
if (path === "/__dopesheet/relocate") return reply(res, 200, await relocateSites(root, JSON.parse(await body(req)), sources));
|
|
85
|
+
reply(res, 404, {
|
|
86
|
+
ok: false,
|
|
87
|
+
error: "Not found"
|
|
88
|
+
});
|
|
89
|
+
})().catch((e) => reply(res, 500, {
|
|
90
|
+
ok: false,
|
|
91
|
+
error: String(e?.message ?? e)
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
return new Promise((done) => {
|
|
95
|
+
server.once("error", (e) => done(e.code === "EADDRINUSE" ? null : (console.warn(`[dopesheet] save server: ${e.message}`), null)));
|
|
96
|
+
server.listen(options.port ?? 4855, "127.0.0.1", () => {
|
|
97
|
+
server.unref();
|
|
98
|
+
done(server);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
export { DEFAULT_PORT as n, transform as r, startServer as t };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as dopesheet$1 } from "./shared-DpUIelWp.js";
|
|
2
|
+
// src/vite.ts
|
|
3
|
+
/** Dopesheet for Vite: `plugins: [dopesheet()]`. Only active in `vite dev`. */
|
|
4
|
+
function dopesheet(options = {}) {
|
|
5
|
+
return {
|
|
6
|
+
...dopesheet$1({
|
|
7
|
+
...options,
|
|
8
|
+
modules: {
|
|
9
|
+
runtime: "dopesheet/runtime",
|
|
10
|
+
ui: "dopesheet/ui"
|
|
11
|
+
}
|
|
12
|
+
}),
|
|
13
|
+
config: () => ({ optimizeDeps: { include: ["dopesheet/runtime", "dopesheet/ui"] } })
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { dopesheet as default, dopesheet };
|
package/docs/agents.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Dopesheet: rules for coding agents
|
|
2
|
+
|
|
3
|
+
This project tunes its GSAP animations visually with **Dopesheet**. A person scrubs and edits
|
|
4
|
+
animations in the running page, and Dopesheet writes the changed values back into these source
|
|
5
|
+
files. Code creates animations; people tune them. Follow these rules so both work on the same code.
|
|
6
|
+
|
|
7
|
+
## Write animations that can be tuned
|
|
8
|
+
|
|
9
|
+
- Pass vars as an **object literal** right in the call: `gsap.to(".card", { y: 40, duration: 0.6 })`.
|
|
10
|
+
A variable holding the whole vars object (`gsap.to(el, vars)`) plays, but can't be edited.
|
|
11
|
+
- Use **literal values** (numbers, strings, booleans) for anything a person might want to tune:
|
|
12
|
+
durations, delays, eases, distances, colours. Computed values (`width * 0.5`, `random(...)`,
|
|
13
|
+
functions) show in the editor but are read-only.
|
|
14
|
+
- For a value shared by several calls, use a **`const` in the same file**
|
|
15
|
+
(`const DURATION = 0.6;`). The editor offers "edit const" (every use) or "override here".
|
|
16
|
+
Imported constants are read-only.
|
|
17
|
+
- Shared vars via spread are fine when the spread is a same-file `const` object
|
|
18
|
+
(`const base = { duration: 0.8 }; gsap.to(a, { ...base, x: 100 })`). Keys written **after** the
|
|
19
|
+
spread belong to the call. Keys written before a spread may be overridden by it.
|
|
20
|
+
- In timelines, prefer **position parameters** (`"<"`, `">"`, `"+=0.2"`, `"-=25%"`, labels) over
|
|
21
|
+
absolute times; the editor keeps that form when someone drags a bar (`"<"` becomes `"<0.12"`).
|
|
22
|
+
- Keep `defaults: { ... }` on timelines as an object literal so children's inherited values are
|
|
23
|
+
editable from the timeline.
|
|
24
|
+
|
|
25
|
+
## Don't fight the editor
|
|
26
|
+
|
|
27
|
+
- Each call's identity is its order among the GSAP calls in its file. The editor follows calls
|
|
28
|
+
when code is added above them, but large rewrites while someone is tuning make their unsaved
|
|
29
|
+
edits conflict. Prefer small, local changes.
|
|
30
|
+
- **Re-read a file before editing it**: a person may have just saved new values into it.
|
|
31
|
+
- Don't reformat animation code unasked: Dopesheet's saves are minimal diffs, and reformatting
|
|
32
|
+
turns every later save into a noisy one.
|
|
33
|
+
- Never add Dopesheet code to the source (`__dopesheet` wrappers exist only in the dev build).
|
|
34
|
+
|
|
35
|
+
## When a person pastes a "Copy prompt" from Dopesheet
|
|
36
|
+
|
|
37
|
+
The editor couldn't write those changes itself (for example, the value is computed). Apply exactly
|
|
38
|
+
the listed changes, changing the source of a computed value so the result matches, and nothing else.
|
package/package.json
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dopesheet",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "A visual timeline editor for GSAP: tune animations in your running page, and it writes the changes back into your code.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"gsap",
|
|
9
|
+
"animation",
|
|
10
|
+
"timeline",
|
|
11
|
+
"editor",
|
|
12
|
+
"vite-plugin",
|
|
13
|
+
"webpack-plugin",
|
|
14
|
+
"nextjs",
|
|
15
|
+
"devtools"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"./vite": {
|
|
22
|
+
"types": "./types/vite.d.ts",
|
|
23
|
+
"default": "./dist/vite.js"
|
|
24
|
+
},
|
|
25
|
+
"./next": {
|
|
26
|
+
"types": "./types/next.d.ts",
|
|
27
|
+
"default": "./dist/next.js"
|
|
28
|
+
},
|
|
29
|
+
"./webpack": {
|
|
30
|
+
"types": "./types/webpack.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./rspack": {
|
|
34
|
+
"types": "./types/webpack.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./runtime": "./dist/browser/runtime.js",
|
|
38
|
+
"./ui": "./dist/browser/ui.js",
|
|
39
|
+
"./client": "./dist/browser/client.js",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"bin": {
|
|
43
|
+
"dopesheet": "./bin/dopesheet.mjs"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"types",
|
|
48
|
+
"bin",
|
|
49
|
+
"docs",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"sideEffects": [
|
|
54
|
+
"./dist/browser/client.js"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"magic-string": "~0.30.21",
|
|
58
|
+
"oxc-parser": "0.161.0",
|
|
59
|
+
"unplugin": "3.7.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"gsap": "^3.12.0",
|
|
63
|
+
"next": ">=15",
|
|
64
|
+
"vite": ">=6"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"next": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"vite": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"tag": "beta",
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@dopesheet/codemod": "0.1.0",
|
|
80
|
+
"@dopesheet/protocol": "0.1.0",
|
|
81
|
+
"@dopesheet/runtime": "0.1.0",
|
|
82
|
+
"@dopesheet/ui": "0.1.0",
|
|
83
|
+
"@dopesheet/unplugin": "0.1.0",
|
|
84
|
+
"@dopesheet/vite-plugin": "0.1.0",
|
|
85
|
+
"gsap": "3.15.1",
|
|
86
|
+
"solid-js": "1.9.20",
|
|
87
|
+
"vite": "8.4.1",
|
|
88
|
+
"vite-plugin-solid": "2.11.17"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "node build.mjs"
|
|
92
|
+
}
|
|
6
93
|
}
|
package/types/next.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface NextDopesheetOptions {
|
|
2
|
+
/** The save server's port (default 4855). */
|
|
3
|
+
port?: number;
|
|
4
|
+
/** Project root for file ids (default: the Next.js project directory). */
|
|
5
|
+
root?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Next.js: `export default withDopesheet(nextConfig)`. Only active in `next dev` (Turbopack or webpack). */
|
|
9
|
+
export declare function withDopesheet<T extends Record<string, any>>(config?: T, options?: NextDopesheetOptions): T;
|
|
10
|
+
export default withDopesheet;
|
package/types/vite.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
export interface DopesheetOptions {
|
|
4
|
+
/** Inject the editor UI (default true). The runtime is always injected in dev. */
|
|
5
|
+
ui?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Dopesheet for Vite: `plugins: [dopesheet()]`. Only active in `vite dev`. */
|
|
9
|
+
declare function dopesheet(options?: DopesheetOptions): Plugin;
|
|
10
|
+
export default dopesheet;
|
|
11
|
+
export { dopesheet };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DopesheetOptions {
|
|
2
|
+
/** Project root: file ids are relative to it (default: the compiler's context). */
|
|
3
|
+
root?: string;
|
|
4
|
+
/** The save server's port (default 4855). */
|
|
5
|
+
port?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type PluginFactory = (options?: DopesheetOptions) => any;
|
|
9
|
+
|
|
10
|
+
/** Dopesheet for webpack and Rspack. Only active in watch mode (dev). */
|
|
11
|
+
export declare const dopesheet: { webpack: PluginFactory; rspack: PluginFactory };
|
|
12
|
+
export declare const webpack: PluginFactory;
|
|
13
|
+
export declare const rspack: PluginFactory;
|
|
14
|
+
export default dopesheet;
|