truecanvas 0.2.0 → 0.3.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/README.md CHANGED
@@ -4,199 +4,98 @@
4
4
 
5
5
  **A Figma-like canvas for your real React components. The code is the document.**
6
6
 
7
- [truecanvas.dev](https://truecanvas.dev)
7
+ [![npm](https://img.shields.io/npm/v/truecanvas)](https://www.npmjs.com/package/truecanvas)
8
+ [![CI](https://github.com/Nathandona/truecanvas/actions/workflows/ci.yml/badge.svg)](https://github.com/Nathandona/truecanvas/actions/workflows/ci.yml)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/Nathandona/truecanvas/blob/main/LICENSE)
10
+
11
+ Truecanvas renders your actual `.tsx` components on an infinite canvas and writes every change back to plain TSX in your repo. It has no built-in AI: it is agent-first through **MCP**, so Claude Code, Cursor, Codex or any MCP client can read your design system, edit frames and take screenshots while you watch and steer.
8
12
 
9
- Truecanvas renders your actual `.tsx` components on an infinite canvas, lets you compose them visually, and writes every change back to plain TSX in your repo. There is no built-in AI: it is **agent-first through MCP**, so Claude Code, Cursor, Codex or any MCP client can read your design system, edit frames and take screenshots, while you watch and steer in the editor.
13
+ [truecanvas.dev](https://truecanvas.dev)
10
14
 
11
15
  ![Truecanvas editor](https://raw.githubusercontent.com/Nathandona/truecanvas/main/docs/screenshot.png)
12
16
 
13
- - **Real components, not drawings.** Layers are instances of your components. The props panel is generated from their TypeScript types (`status: "working" | "idle"` becomes a dropdown).
14
- - **Code is the document.** A canvas is `canvas/<name>.canvas.tsx`. Edits are minimal text patches that keep your formatting, so diffs are reviewable and your editor and the canvas stay in sync both ways.
15
- - **Agent-first.** 44 MCP tools: read the tree, list components and design tokens, insert JSX, set props, wrap in auto layout, create variant grids, add shader backgrounds, screenshot frames, and see what the user has selected.
16
- - **Shaders.** Install [`@paper-design/shaders-react`](https://github.com/paper-design/shaders) and its ~30 animated shaders show up in the Components panel, with color pickers, sliders from their documented ranges and one-click presets. Add one behind any frame with "Shader background". Pause all motion with `⇧P` to save battery.
17
- - **Design on your real pages.** "Add a page from your app" (Pages +) adds any App Router page as a **linked frame**: its layers are the page's own JSX, and editing them edits `page.tsx` (and the layout, for things like the navbar) directly. Right-click → **Explore a copy** to try ideas without touching the page, then **Apply to page** to write the result back as a minimal diff.
18
- - **Build with plain elements and components.** The Insert menu (+ in the toolbar, `T` for text) and the Basics in Assets add text, headings, links, buttons, lists, stacks, rows, grids, sections, images and inputs as Tailwind-styled JSX. **New component** creates a component file; select layers and press `Ctrl/⌘+Alt+K` to turn them into a component (imports come along). Right-click any component → **Edit main component** opens it on the `components` page: its layers are the component's own JSX, edits go to its file, and every instance follows. `className={cn("…", className)}` stays merged: only the static classes change.
19
- - **Pages, layers, assets.** Pages are canvas files you can add, rename, duplicate and delete (with undo). Layers have search, editor-only hide and lock, and custom names stored as `data-name` so your agent sees them too. Assets shows live thumbnails of your components, rendered by your app, plus every shader preset.
20
- - **Icons and shadcn/ui.** Assets → Libraries (or + → Icon…) installs an icon set (Lucide, Tabler, Phosphor, Heroicons, Radix) with your package manager, then search and insert icons with their import. The shadcn/ui tab runs the official shadcn CLI to copy components into your project (setting shadcn up first if needed); they show up in Assets with their typed variants like any component. Your agent can do the same through MCP.
21
- - **Motion.** Play a frame (▶ on its label) to scroll inside it at screen height, so scroll reveals run like on the site, and replay entrance animations anytime. Paused frames and agent screenshots show every animation finished, never half faded. The Motion section adds a scroll reveal (fade up, blur in, scale in…) or a text animation (word by word, letter by letter, typewriter…) to any layer: Truecanvas adds `Reveal` and `TextAnimate` to your components once (plain React, no dependencies) and wraps the layer in them.
22
- - **Mobile presets.** iPhone, Pixel, Galaxy, iPad and desktop frame sizes, with device chrome (status bar, Dynamic Island, home indicator) and touch emulation in agent screenshots.
23
- - **Everything is undoable.** Edits from you, your agent and your code editor land in one activity feed with undo/redo.
24
- - **Light, dark, system.** Per-frame theme (Inherit / Light / Dark) and a canvas-wide theme, applied live without reloading frames.
25
- - **Lightweight.** No second dev server. Frames render through your existing `next dev`, the editor is a static bundle, and headless Chromium only starts when an agent asks for a screenshot.
26
-
27
- > Status: early (v0.1). Next.js App Router + Tailwind first. Linux-first, tested on Fedora 43.
17
+ ## Features
18
+
19
+ - **Real components.** Layers are instances of your components, with a props panel generated from their TypeScript types.
20
+ - **Code is the document.** A canvas is a `.canvas.tsx` file. Edits are minimal patches that keep your formatting, so diffs stay reviewable.
21
+ - **Agent-first.** 44 MCP tools to read the tree, insert JSX, set props and classes, create frames and variants, and take screenshots.
22
+ - **Design on real pages.** Link any Next.js page as a frame: editing its layers edits `page.tsx` and its layouts.
23
+ - **Components and libraries.** Turn a selection into a component, edit main components, install icon sets (Lucide, Tabler, Phosphor, Heroicons, Radix) and add shadcn/ui components.
24
+ - **Git built in.** Per-frame change summaries, branches, commits, pull requests with before/after images, visual compare and comments that travel with branches.
25
+ - **Motion, devices, themes.** Scroll reveals and text animations, iPhone/Pixel/iPad presets with device chrome, and per-frame light and dark themes.
26
+ - **Lightweight.** Frames render through your existing dev server. Headless Chromium only starts when an agent asks for a screenshot.
28
27
 
29
28
  ## Quick start
30
29
 
31
- **In a Next.js app** (App Router, Next 15.3+):
30
+ In a **Next.js** (App Router, 15.3+) or **Vite + React** (5+) app:
32
31
 
33
32
  ```bash
34
33
  npx truecanvas
35
34
  ```
36
35
 
37
- That's it. The first time, it asks once, then adds the dev dependency, wraps `next.config`, adds a `canvas` script, links your homepage as the first canvas and offers to connect your agents. Then it starts your app (if it isn't running) and opens the editor. After that, anyone on the project starts it with `npm run canvas`.
36
+ The first run sets the project up: the dev dependency, the plugin in `next.config` or `vite.config`, a `canvas` script and a first canvas. It then starts your app and opens the editor. After that, use `npm run canvas`.
38
37
 
39
- **A new app:**
38
+ Start a new app instead:
40
39
 
41
40
  ```bash
42
- npm create truecanvas@latest my-app
43
- cd my-app && npm run canvas
41
+ npm create truecanvas@latest my-app # asks Next.js or Vite
42
+ npm create truecanvas@latest my-app -- --vite
44
43
  ```
45
44
 
46
- A Next.js app (TypeScript, Tailwind, App Router) with Truecanvas set up and committed. `pnpm create truecanvas`, `yarn create truecanvas` and `bun create truecanvas` work too.
47
-
48
- **Something off?** `npx truecanvas doctor` checks Node, Next, React, Tailwind, the config, agents, screenshots and git, with a one-line fix for each problem.
45
+ Run `npx truecanvas doctor` if anything looks off: it checks every requirement and prints a fix for each problem.
49
46
 
50
- **Prefer an app to a terminal?** `npx truecanvas open` opens the Truecanvas window: your projects, one tab each, "Clone from GitHub" and "New project". `npx truecanvas desktop` adds it to your app launcher (Linux).
51
-
52
- ### Connect your agent
47
+ ## Connect your agent
53
48
 
54
49
  ```bash
55
50
  npx truecanvas connect
56
51
  ```
57
52
 
58
- This writes the Truecanvas MCP server into the project's **`.mcp.json`** (and `.cursor/mcp.json` / `.vscode/mcp.json` when the project uses those editors). **Commit it**: everyone who clones the repo gets Truecanvas in Claude Code, Cursor or VS Code with no setup.
53
+ This adds Truecanvas to the project's `.mcp.json`. Commit it and every teammate's agent is connected.
59
54
 
60
55
  | Client | Config |
61
56
  | --- | --- |
62
- | Claude Code | `.mcp.json` from `truecanvas connect`, or for all your projects: `claude mcp add --scope user --transport http truecanvas http://localhost:4800/mcp` |
63
- | Cursor | `.cursor/mcp.json` → `{ "mcpServers": { "truecanvas": { "url": "http://localhost:4800/mcp" } } }` |
64
- | VS Code | `.vscode/mcp.json` → `{ "servers": { "truecanvas": { "type": "http", "url": "http://localhost:4800/mcp" } } }` |
65
- | Codex | `~/.codex/config.toml` → `[mcp_servers.truecanvas]` `url = "http://localhost:4800/mcp"` |
66
- | stdio-only clients | `{ "command": "npx", "args": ["truecanvas", "mcp"] }` (bridges to a running server, or starts one) |
67
-
68
- Then select something on the canvas and ask: *"Make my selection denser"*, *"Create a dark copy of the Chat frame and check it with a screenshot"*, *"Show every status of SessionRow"*.
69
-
70
- ## The Truecanvas window
71
-
72
- ```bash
73
- npx truecanvas desktop # adds Truecanvas to your app launcher (GNOME, KDE…)
74
- npx truecanvas hub # or start it from a terminal
75
- ```
76
-
77
- One window for all your projects, with tabs like a browser. The **Dashboard** lists your recent projects (with their favicons) and the Next.js apps it finds on your computer. You can open a folder, set up Truecanvas in an existing app, or create a new project. Each tab is a project's editor. Opening a tab starts that project's app on free ports, and closing it stops the app and frees the memory (the tab bar shows how much is in use).
78
-
79
- The hub serves MCP at the same `http://localhost:4800/mcp`, and your agent works on the project in the active tab. It can also call `list_projects` and `open_project` to switch itself.
80
-
81
- ## Collaborate
82
-
83
- Everything Truecanvas makes is a file in your repo: canvases, comments, linked pages, the motion components they use, and `.mcp.json`. So git is the collaboration layer, and a team works on design the way it works on code.
84
-
85
- ### The workflow
86
-
87
- 1. **Set up once, commit it.** `npx truecanvas` in the repo, then commit `package.json`, `canvas/`, `next.config` and `.mcp.json`. Teammates run their usual install and `npm run canvas`; their agents are already connected.
88
- 2. **Design on real pages.** Linked frames are your production pages: editing them edits `page.tsx`. For bigger ideas, right-click → **Explore a copy**, iterate freely (you or your agent), then **Apply to page**. Delete explorations once applied.
89
- 3. **One branch per change.** On `main`, Truecanvas offers to start a branch and brings your edits along.
90
- 4. **Commit from the Git panel.** It lists what changed per frame in plain words and drafts the message.
91
- 5. **Open a pull request** from the panel: the description shows each changed frame, before and after.
92
- 6. **Review in Truecanvas too.** In the Truecanvas window, a project's menu → **Pull requests…** checks out any PR and shows it on the canvas, live, not just as pictures. Leave comments on frames; they're saved in the branch, and agents can read and resolve them.
93
- 7. **Merge.** There's no handoff: the design is already the code.
94
-
95
- Designers who don't use a terminal can do all of it from the Truecanvas window: **Clone from GitHub** (clones, installs, sets up), open the project, branch, commit, open and review PRs.
57
+ | Claude Code | `.mcp.json`, or `claude mcp add --scope user --transport http truecanvas http://localhost:4800/mcp` |
58
+ | Cursor | `.cursor/mcp.json`: `{ "mcpServers": { "truecanvas": { "url": "http://localhost:4800/mcp" } } }` |
59
+ | VS Code | `.vscode/mcp.json`: `{ "servers": { "truecanvas": { "type": "http", "url": "http://localhost:4800/mcp" } } }` |
60
+ | Codex | `~/.codex/config.toml`: `[mcp_servers.truecanvas]` with `url = "http://localhost:4800/mcp"` |
61
+ | stdio clients | `{ "command": "npx", "args": ["truecanvas", "mcp"] }` |
96
62
 
97
- ### What's in the Git panel
98
-
99
-
100
- - **Git panel** (the branch pill at the top left): what changed, frame by frame, in plain words ("Restyled h1 (+text-orange-600)", "Added a fade-up reveal to p"), with a commit message drafted from it. Changed frames get a dot on the canvas. Design commits include canvases, comments, linked pages and the motion components they use.
101
- - **Review changes**: a full-screen before/after of each changed frame against the last commit (rendered by your app), plus the code diff.
102
- - **Branch first**: on `main` with changes, Truecanvas offers to start a branch (named from the page and frames) and carries your edits over.
103
- - **Pull requests** (GitHub, through the `gh` CLI): push and open a PR in one step. Its description lists the changes per frame, optionally with before/after images stored on a `truecanvas-previews` branch of the same repo. The branch pill then shows the PR's state: open, checks running or failing, approved, merged. No GitHub remote yet? "Publish" creates the repo (private by default).
104
- - **Compare**: render this page as it was on another branch or commit, side by side or as an overlay with an opacity slider. Changed and new frames are flagged. This works because Truecanvas renders any version of the code.
105
- - **Comments** (`C`): pin a comment on a frame or layer. Threads are saved in `canvas/<page>.comments.json`, so they travel with branches and show up in pull requests. Agents read them with `list_comments` (including the current source of the commented layer), fix things, and `resolve_comment` with a note.
106
-
107
- ### Good to know
108
-
109
- - **Async, like code.** Collaboration happens through branches and pull requests. Live multiplayer on one canvas isn't supported; the live cursors you see are agents working on your machine.
110
- - **Merges.** Canvas files are TSX with one block per frame and minimal edits, so two people changing different frames merge cleanly. When both change the same frame, resolve it like any code conflict and Truecanvas re-renders the result.
111
- - **One agent config for everyone.** `.mcp.json` points at `http://localhost:4800/mcp`, which works whether each person runs `npm run canvas` or the Truecanvas window.
112
-
113
- ## Linked frames
114
-
115
- A new project's first canvas links your homepage. Any page can be linked from Pages + or with the `import_page` tool:
116
-
117
- ```tsx
118
- <Frame name="Home" x={0} y={0} width={1440} page="src/app/(marketing)/page.tsx">
119
- <MarketingLayout>
120
- <HomePage />
121
- </MarketingLayout>
122
- </Frame>
123
- ```
124
-
125
- - The frame renders the real page through its layouts. Its layers are the JSX of `page.tsx` and of the layouts around it, and every edit goes to the file that layer lives in, keeping that file's formatting. The frame label shows **Live · page.tsx**.
126
- - Undo, the Git panel (linked pages count as design files) and Compare (the page is rendered as it was at that commit) all work on the page files.
127
- - Only plain composition is editable: a page whose component fetches data or has logic before its `return` is shown as one layer, **View only**. Explore a copy to design on it.
128
- - **Explore a copy** creates `<Frame from="src/app/…/page.tsx">` with the page's JSX inline, in the canvas file. **Apply to page** replaces the page's returned JSX with the exploration's, adds the imports it needs and removes the ones it no longer uses.
129
- - Page and layout layers get ids like `src/app/page.tsx#12:8`, stamped only in `next dev`. Production builds are untouched.
63
+ Then select something and ask: *"Make my selection denser"* or *"Show every status of SessionRow in a variants frame"*.
130
64
 
131
65
  ## A canvas file
132
66
 
133
67
  ```tsx
134
68
  "use client";
135
69
  import { Canvas, Frame } from "truecanvas";
136
- import { SessionRow } from "@/components/app/session-row";
70
+ import { SessionRow } from "@/components/session-row";
137
71
 
138
72
  export default function ChatCanvas() {
139
73
  return (
140
74
  <Canvas>
141
75
  <Frame name="Sessions" x={0} y={0} width={320}>
142
- <div className="flex flex-col gap-1 p-3">
143
- <SessionRow title="Review release readiness" status="working" elapsed="2m" active />
144
- <SessionRow title="Draft the Q4 changelog" status="review" source="slack" elapsed="3h" />
145
- </div>
76
+ <SessionRow title="Review release readiness" status="working" />
146
77
  </Frame>
147
78
  <Frame name="Sessions dark" x={360} y={0} width={320} theme="dark">
148
- {/* … */}
79
+ <SessionRow title="Draft the changelog" status="review" />
149
80
  </Frame>
150
81
  </Canvas>
151
82
  );
152
83
  }
153
84
  ```
154
85
 
155
- - `<Frame>`: `name`, `x`, `y`, `width`, optional `height` (omit to hug content), optional `theme` (`"light" | "dark"`, omit to inherit), optional `device` (`"iphone-16"`, `"pixel-9"`, `"ipad-mini"`…), optional `page` (linked frame) or `from` (exploration of a page).
156
- - Each frame renders in its own iframe at its own width, so media queries, portals and `position: fixed` behave like the real app.
157
- - Keep props literal (`status="working"`) to make them editable. Expressions such as `{items.map(…)}` still render, but they are read-only in the inspector.
158
-
159
- ## MCP tools
160
-
161
- | Read | Write | Look & show |
162
- | --- | --- | --- |
163
- | `list_canvases` | `set_props` · `set_text` · `set_class_name` | `screenshot_frame` |
164
- | `get_canvas` (compact outline with ids) | `insert_jsx` · `replace_node` | `focus` (select + zoom in the user's editor) |
165
- | `get_node` (exact TSX source) | `duplicate_nodes` · `delete_nodes` · `move_node` | `undo` · `redo` |
166
- | `list_components` · `get_component` | `wrap_nodes` (auto layout) | |
167
- | `get_design_tokens` (Tailwind `@theme`) | `create_frame` · `update_frame` (both take `device`) | |
168
- | | `create_canvas` · `rename_canvas` · `delete_canvas` | |
169
- | `get_selection` (what the user selected) | `create_variants_frame` · `add_background` · `apply_preset` | |
170
- | `list_comments` | `reply_comment` · `resolve_comment` | |
171
- | | `import_page` (linked by default) · `explore_copy` · `apply_to_page` | |
172
- | | `add_animation` · `remove_animation` | `play_frame` (play, replay, stop) |
173
- | | `create_component` · `open_component` | |
174
- | `list_libraries` · `search_icons` | `install_library` · `insert_icon` · `add_shadcn_components` | |
175
-
176
- Node ids are `line:col` of the JSX tag (`file#line:col` for layers of a linked page) and change after edits. Every write returns the fresh ids of the affected frame. Catalog components are imported automatically.
86
+ `<Frame>` takes `name`, `x`, `y`, `width`, and optionally `height`, `theme`, `device`, `page` (a linked page) or `component` (a main component). Each frame renders in its own iframe at its own width, so media queries, portals and `position: fixed` behave as in your app. Literal props are editable in the inspector; expressions still render but are read-only.
177
87
 
178
88
  ## How it works
179
89
 
180
- ```
181
- your browser truecanvas dev (Node, 127.0.0.1:4800)
182
- ┌───────────────────────────┐ REST/SSE ┌──────────────────────────────────┐
183
- │ editor UI (static bundle) │◀─────────▶│ Workspace: parse → patch → write │◀── MCP ── your agent
184
- │ ┌──────┐ ┌──────┐ │ │ (Babel + magic-string, undo log) │
185
- │ │iframe│ │iframe│ frames │ │ Catalog: TS checker → prop types │
186
- │ └──┬───┘ └──┬───┘ │ └───────────────┬──────────────────┘
187
- └─────┼────────┼────────────┘ │ writes canvas/*.canvas.tsx
188
- │ └── postMessage: hit-test, rects, theme ▼
189
- └──────────── /truecanvas/[canvas]?frame=… ── your `next dev` (HMR)
190
- ```
90
+ 1. A dev-only plugin (Turbopack/webpack loader for Next.js, Vite plugin for Vite) stamps each JSX element with its source position. Production builds are untouched.
91
+ 2. Each frame loads `/truecanvas/<canvas>` from your dev server, where a small runtime maps what's under the pointer back to that position.
92
+ 3. Your gestures and your agent's MCP calls become the same commands. The server patches the source and your dev server hot-reloads the frame.
191
93
 
192
- 1. A Turbopack/webpack loader stamps each JSX element in `*.canvas.tsx` with `data-tc="line:col"` (dev only, same line, no layout impact).
193
- 2. In the iframe, a tiny runtime answers "what's under this point?" by walking React's fiber tree to the nearest stamped element. No wrapper elements, and it works with portals and components that don't forward props.
194
- 3. The editor turns your gestures into commands. The server patches the source text and writes it, and Next's HMR re-renders the frame.
195
- 4. Agents use the same commands over MCP, so whatever you can do, they can do.
94
+ Collaboration goes through git: canvases, comments and linked pages are files, so design changes are branched, reviewed and merged like code. The **Truecanvas window** (`npx truecanvas open`) manages several projects in tabs, clones from GitHub and reviews pull requests on the canvas.
196
95
 
197
96
  ## Configuration
198
97
 
199
- Optional `truecanvas.config.json` at the project root:
98
+ Everything is optional. Add a `truecanvas.config.json` at the project root:
200
99
 
201
100
  ```json
202
101
  {
@@ -205,63 +104,35 @@ Optional `truecanvas.config.json` at the project root:
205
104
  "canvasDir": "canvas",
206
105
  "components": ["components/**/*.tsx"],
207
106
  "darkMode": { "strategy": "class", "value": "dark" },
208
- "libraries": ["@paper-design/shaders-react"],
107
+ "css": ["/src/index.css"],
209
108
  "editor": "code"
210
109
  }
211
110
  ```
212
111
 
213
- `libraries` adds npm packages to the Components panel (Paper shaders are detected automatically when installed). `darkMode` tells frames how your app switches themes: a class on `<html>` (`strategy: "class"`), or an attribute (`{ "strategy": "attribute", "attribute": "data-theme", "value": "dark", "lightValue": "light" }`).
214
-
215
- ## Shortcuts
216
-
217
- | | |
218
- | --- | --- |
219
- | Select / Frame / Hand / Interact | `V` `F` `H` `P` |
220
- | Duplicate · Delete | `⌘D` · `⌫` |
221
- | Wrap in auto layout | `⇧A` |
222
- | Reorder in parent | `↑` `↓` or drag on the canvas |
223
- | Parent / child | `⇧↵` / `↵` (or `Esc`) |
224
- | Edit text | double-click or `↵` |
225
- | Rename layer or page | double-click its name |
226
- | Copy as JSX | `⌘C` |
227
- | Pause / play animations | `⇧P` |
228
- | Comment | `C` |
229
- | Zoom to fit · selection · 100% | `⇧1` · `⇧2` · `⇧0` |
230
- | Undo · Redo | `⌘Z` · `⇧⌘Z` |
231
-
232
- On Linux, `⌘` is `Ctrl`. Pan with space-drag, middle mouse or two-finger scroll. Zoom with Ctrl+scroll or pinch.
112
+ `darkMode` describes how your app switches themes (a class, or `{ "strategy": "attribute", "attribute": "data-theme", "value": "dark" }`). `css` (Vite only) lists the stylesheets frames load; by default, the ones your entry module imports.
233
113
 
234
114
  ## Requirements
235
115
 
236
- - Node 20+, Next.js 15.3+ (App Router), React 19. Tailwind is optional but the style controls write Tailwind classes.
237
- - Linux and macOS. Windows is untested.
238
- - For screenshots and PR images: Chrome/Chromium, or a Playwright browser in `~/.cache/ms-playwright`. Set `TRUECANVAS_CHROME` to point at one.
239
- - For pull requests: the GitHub CLI (`gh auth login`).
116
+ - Node 22+ (24 LTS recommended) and React 19
117
+ - Next.js 15.3+ (App Router) or Vite 5+. Tailwind is optional; the style controls write Tailwind classes.
118
+ - macOS, Linux or Windows
119
+ - Screenshots: Chrome, Edge or Chromium, or `npx playwright install chromium-headless-shell`
120
+ - Pull requests: the GitHub CLI (`gh auth login`)
240
121
 
241
- `npx truecanvas doctor` checks all of this.
122
+ Linked page frames need Next.js file-based routes. Everything else works the same in Vite apps.
242
123
 
243
- ## Develop
124
+ ## Development
244
125
 
245
126
  ```bash
246
127
  pnpm install
247
- pnpm build # library + editor bundle
248
- pnpm --filter truecanvas test # engine tests
249
- pnpm dev # builds, then starts the playground app + editor
250
- pnpm --filter truecanvas dev:editor # editor with Vite HMR on :4801 (proxies the API)
251
- pnpm pack:local # an installable build, plus the command to add it to a project
128
+ pnpm build # library and editor
129
+ pnpm --filter truecanvas test # tests
130
+ pnpm dev # playground app and editor
131
+ pnpm --filter truecanvas dev:editor # editor with HMR on :4801
252
132
  ```
253
133
 
254
- Running the CLI from this checkout (`node packages/truecanvas/dist/cli.js`) installs a tarball of your local build into projects instead of the npm release.
255
-
256
- **Releasing:** `pnpm release 0.2.0` bumps `truecanvas` and `create-truecanvas`, commits and tags; `git push --follow-tags` runs the release workflow, which tests and publishes both to npm with provenance (needs an `NPM_TOKEN` secret in the GitHub repo).
257
-
258
- ## Roadmap
259
-
260
- - Multi-frame drag and reparenting by dragging on the canvas
261
- - Vite + React Router support, then CSS Modules
262
- - Inline prop editing for `ReactNode` slots
263
- - Desktop shell (AppImage / Flatpak) once the web version settles
134
+ Releases: `pnpm release <version>` bumps both packages and tags; `git push --follow-tags` publishes to npm from GitHub Actions with provenance.
264
135
 
265
136
  ## License
266
137
 
267
- MIT
138
+ [MIT](https://github.com/Nathandona/truecanvas/blob/main/LICENSE)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  analyzeComponents
3
- } from "./chunk-T2TCBSTG.js";
3
+ } from "./chunk-WU7NBTJH.js";
4
4
 
5
5
  // src/core/catalog-worker.ts
6
6
  import { parentPort, workerData } from "worker_threads";
@@ -0,0 +1,97 @@
1
+ // src/core/config.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ function loadConfig(root, overrides = {}) {
5
+ let file = {};
6
+ const configPath = path.join(root, "truecanvas.config.json");
7
+ if (fs.existsSync(configPath)) file = JSON.parse(fs.readFileSync(configPath, "utf8"));
8
+ let deps = {};
9
+ try {
10
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
11
+ deps = { ...pkg.dependencies, ...pkg.devDependencies };
12
+ } catch {
13
+ deps = {};
14
+ }
15
+ const framework = file.framework ?? detectFramework(deps);
16
+ const vite = framework === "vite";
17
+ const appDir = file.appDir ?? (vite ? fs.existsSync(path.join(root, "src")) ? "src" : "." : fs.existsSync(path.join(root, "src/app")) ? "src/app" : "app");
18
+ const srcPrefix = appDir === "src" || appDir.startsWith("src/") ? "src/" : "";
19
+ const knownLibraries = ["@paper-design/shaders-react"].filter((l) => l in deps);
20
+ return {
21
+ root,
22
+ framework,
23
+ appUrl: vite ? "http://localhost:5173" : "http://localhost:3000",
24
+ port: 4800,
25
+ canvasDir: `${srcPrefix}canvas`,
26
+ appDir,
27
+ routeDir: vite ? ".truecanvas" : `${appDir}/truecanvas`,
28
+ components: [`${srcPrefix}components/**/*.tsx`],
29
+ darkMode: { strategy: "class", value: "dark" },
30
+ ...file,
31
+ libraries: [.../* @__PURE__ */ new Set([...knownLibraries, ...file.libraries ?? []])],
32
+ ...stripUndefined(overrides)
33
+ };
34
+ }
35
+ function stripUndefined(o) {
36
+ return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
37
+ }
38
+ function detectFramework(deps) {
39
+ return !("next" in deps) && "vite" in deps ? "vite" : "next";
40
+ }
41
+
42
+ // src/core/ast.ts
43
+ import { parse } from "@babel/parser";
44
+ function parseModule(source) {
45
+ return parse(source, {
46
+ sourceType: "module",
47
+ plugins: ["typescript", "jsx"],
48
+ errorRecovery: false
49
+ });
50
+ }
51
+ function idOf(node) {
52
+ const loc = node.loc.start;
53
+ return `${loc.line}:${loc.column}`;
54
+ }
55
+ function jsxName(name) {
56
+ if (name.type === "JSXIdentifier") return name.name;
57
+ if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
58
+ return `${jsxName(name.object)}.${name.property.name}`;
59
+ }
60
+ function walk(node, visit, parent = null) {
61
+ if (!node || typeof node !== "object") return;
62
+ if (Array.isArray(node)) {
63
+ for (const child of node) walk(child, visit, parent);
64
+ return;
65
+ }
66
+ const n = node;
67
+ if (typeof n.type !== "string") return;
68
+ if (visit(n, parent) === false) return;
69
+ for (const key of Object.keys(n)) {
70
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments" || key === "extra") continue;
71
+ const value = n[key];
72
+ if (value && typeof value === "object") walk(value, visit, n);
73
+ }
74
+ }
75
+ function isComponentName(name) {
76
+ return /^[A-Z]/.test(name) || name.includes(".");
77
+ }
78
+ function rewriteImportSource(statement, from, to) {
79
+ if (from === to) return statement;
80
+ for (const q of ['"', "'"]) {
81
+ const needle = `${q}${from}${q}`;
82
+ const i = statement.indexOf(needle);
83
+ if (i >= 0) return `${statement.slice(0, i)}${q}${to}${q}${statement.slice(i + needle.length)}`;
84
+ }
85
+ return statement;
86
+ }
87
+
88
+ export {
89
+ loadConfig,
90
+ detectFramework,
91
+ parseModule,
92
+ idOf,
93
+ jsxName,
94
+ walk,
95
+ isComponentName,
96
+ rewriteImportSource
97
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ idOf,
3
+ parseModule,
4
+ walk
5
+ } from "./chunk-PBKX3SBC.js";
6
+
7
+ // src/core/inject.ts
8
+ import MagicString from "magic-string";
9
+ function injectIds(source, file) {
10
+ let ast;
11
+ try {
12
+ ast = parseModule(source);
13
+ } catch {
14
+ return source;
15
+ }
16
+ const s = new MagicString(source);
17
+ walk(ast, (node) => {
18
+ if (node.type !== "JSXOpeningElement") return;
19
+ if (node.attributes.some((a) => a.type === "JSXAttribute" && a.name.name === "data-tc")) return;
20
+ const id = file ? `${file}#${idOf(node)}` : idOf(node);
21
+ s.appendLeft((node.typeParameters ?? node.name).end, ` data-tc="${id}"`);
22
+ });
23
+ return s.toString();
24
+ }
25
+
26
+ export {
27
+ injectIds
28
+ };
@@ -1,9 +1,15 @@
1
1
  // src/core/catalog.ts
2
2
  import fs from "fs";
3
- import path from "path";
3
+ import path2 from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import { createRequire } from "module";
6
6
  import { globSync } from "tinyglobby";
7
+
8
+ // src/core/paths.ts
9
+ import path from "path";
10
+ var posix = (p) => p.split(path.sep).join("/");
11
+
12
+ // src/core/catalog.ts
7
13
  var require2 = createRequire(import.meta.url);
8
14
  var Catalog = class {
9
15
  constructor(root, globs, libraries = []) {
@@ -51,8 +57,8 @@ var Catalog = class {
51
57
  }
52
58
  };
53
59
  async function runAnalysis(root, globs, libraries) {
54
- const here = path.dirname(fileURLToPath(import.meta.url));
55
- const worker = [path.join(here, "catalog-worker.js"), path.join(here, "..", "catalog-worker.js")].find((p) => fs.existsSync(p));
60
+ const here = path2.dirname(fileURLToPath(import.meta.url));
61
+ const worker = [path2.join(here, "catalog-worker.js"), path2.join(here, "..", "catalog-worker.js")].find((p) => fs.existsSync(p));
56
62
  if (!worker) return analyzeComponents(root, globs, libraries);
57
63
  const { Worker } = await import("worker_threads");
58
64
  return new Promise((resolve, reject) => {
@@ -68,7 +74,7 @@ async function analyzeComponents(root, globs, libraries = []) {
68
74
  const options = compilerOptions(ts, root);
69
75
  const libEntries = /* @__PURE__ */ new Map();
70
76
  for (const lib of libraries) {
71
- const res = ts.resolveModuleName(lib, path.join(root, "index.ts"), options, ts.sys).resolvedModule;
77
+ const res = ts.resolveModuleName(lib, path2.join(root, "index.ts"), options, ts.sys).resolvedModule;
72
78
  if (res) libEntries.set(res.resolvedFileName, lib);
73
79
  }
74
80
  const program = ts.createProgram({ rootNames: [...files, ...libEntries.keys()], options });
@@ -91,7 +97,7 @@ async function analyzeComponents(root, globs, libraries = []) {
91
97
  if (!sig) continue;
92
98
  const ret = checker.typeToString(sig.getReturnType());
93
99
  if (!/Element|ReactNode|ReactPortal|null|any/.test(ret) || /^Promise</.test(ret)) continue;
94
- out.push(describe(ts, checker, sym, decl, sig, library ?? path.relative(root, file), library));
100
+ out.push(describe(ts, checker, sym, decl, sig, library ?? posix(path2.relative(root, file)), library));
95
101
  }
96
102
  }
97
103
  for (const spec of out) applyProfile(spec);
@@ -115,7 +121,7 @@ function applyProfile(spec) {
115
121
  async function attachPresets(root, specs) {
116
122
  const byLib = /* @__PURE__ */ new Map();
117
123
  for (const s of specs) if (s.library) byLib.set(s.library, [...byLib.get(s.library) ?? [], s]);
118
- const projectRequire = createRequire(path.join(root, "package.json"));
124
+ const projectRequire = createRequire(path2.join(root, "package.json"));
119
125
  for (const [lib, list] of byLib) {
120
126
  let mod;
121
127
  try {
@@ -148,7 +154,7 @@ function compilerOptions(ts, root) {
148
154
  const base = { jsx: ts.JsxEmit.ReactJSX, strict: true, skipLibCheck: true, noEmit: true, allowJs: false };
149
155
  if (!configPath) return base;
150
156
  const read = ts.readConfigFile(configPath, ts.sys.readFile);
151
- const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configPath));
157
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path2.dirname(configPath));
152
158
  return { ...parsed.options, noEmit: true, skipLibCheck: true, incremental: false, plugins: [] };
153
159
  }
154
160
  function describe(ts, checker, sym, decl, sig, file, library) {
@@ -273,25 +279,25 @@ function readDefaults(ts, decl) {
273
279
  }
274
280
  function importSpecifier(root, canvasFile, componentFile) {
275
281
  if (!/\.(tsx|ts|jsx|js)$/.test(componentFile) && !componentFile.startsWith(".")) return componentFile;
276
- const abs = path.resolve(root, componentFile);
277
- const noExt = abs.replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\/index$/, "");
282
+ const abs = path2.resolve(root, componentFile);
283
+ const noExt = posix(abs).replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\/index$/, "");
278
284
  const alias = readAlias(root);
279
285
  if (alias) {
280
- const rel2 = path.relative(alias.dir, noExt);
281
- if (!rel2.startsWith("..")) return `${alias.prefix}${rel2}`;
286
+ const rel2 = path2.relative(alias.dir, noExt);
287
+ if (!rel2.startsWith("..")) return `${alias.prefix}${posix(rel2)}`;
282
288
  }
283
- let rel = path.relative(path.dirname(path.resolve(root, canvasFile)), noExt);
289
+ let rel = posix(path2.relative(path2.dirname(path2.resolve(root, canvasFile)), noExt));
284
290
  if (!rel.startsWith(".")) rel = `./${rel}`;
285
291
  return rel;
286
292
  }
287
293
  function resolveAliasPath(root, spec) {
288
294
  const alias = readAlias(root);
289
- if (alias && spec.startsWith(alias.prefix)) return path.join(alias.dir, spec.slice(alias.prefix.length));
290
- return path.resolve(root, spec);
295
+ if (alias && spec.startsWith(alias.prefix)) return path2.join(alias.dir, spec.slice(alias.prefix.length));
296
+ return path2.resolve(root, spec);
291
297
  }
292
298
  var aliasCache = null;
293
299
  function readAlias(root) {
294
- const configFile = path.join(root, "tsconfig.json");
300
+ const configFile = path2.join(root, "tsconfig.json");
295
301
  let key = `${root}\0none`;
296
302
  try {
297
303
  key = `${root}\0${fs.statSync(configFile).mtimeMs}`;
@@ -304,12 +310,12 @@ function readAlias(root) {
304
310
  const configPath = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
305
311
  if (configPath) {
306
312
  const read = ts.readConfigFile(configPath, ts.sys.readFile);
307
- const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configPath));
313
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path2.dirname(configPath));
308
314
  const paths = parsed.options.paths ?? {};
309
- const base = parsed.options.pathsBasePath ?? parsed.options.baseUrl ?? path.dirname(configPath);
315
+ const base = parsed.options.pathsBasePath ?? parsed.options.baseUrl ?? path2.dirname(configPath);
310
316
  for (const [k, targets] of Object.entries(paths)) {
311
317
  if (k.endsWith("/*") && targets[0]?.endsWith("/*")) {
312
- value = { prefix: k.slice(0, -1), dir: path.resolve(base, targets[0].slice(0, -2)) };
318
+ value = { prefix: k.slice(0, -1), dir: path2.resolve(base, targets[0].slice(0, -2)) };
313
319
  break;
314
320
  }
315
321
  }
@@ -322,6 +328,7 @@ function readAlias(root) {
322
328
  }
323
329
 
324
330
  export {
331
+ posix,
325
332
  Catalog,
326
333
  analyzeComponents,
327
334
  importSpecifier,