@marver-design/marver 0.2.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 +202 -0
- package/NOTICE +4 -0
- package/README.md +38 -0
- package/dist/build-D0GnIR4G.mjs +244 -0
- package/dist/cli.mjs +58 -0
- package/dist/config-DMBEpdEN.mjs +132 -0
- package/dist/dev-BK4x3PBr.mjs +76 -0
- package/dist/init-DcOy1krf.mjs +168 -0
- package/dist/plugin-DB5t2WUl.mjs +437 -0
- package/dist/serve-BPNmWeJx.mjs +200 -0
- package/package.json +59 -0
- package/src/client/const.ts +5 -0
- package/src/client/frame-host/bridge.js +37 -0
- package/src/client/frame-host/index.html +11 -0
- package/src/client/frame-host/main.tsx +73 -0
- package/src/client/frame-host/registry.ts +40 -0
- package/src/client/runtime/index.ts +8 -0
- package/src/client/shell/App.tsx +633 -0
- package/src/client/shell/Play.tsx +399 -0
- package/src/client/shell/Tip.tsx +43 -0
- package/src/client/shell/canvas/Canvas.tsx +285 -0
- package/src/client/shell/canvas/FrameNode.tsx +194 -0
- package/src/client/shell/favicon/android-chrome-192x192-interactive.png +0 -0
- package/src/client/shell/favicon/android-chrome-192x192.png +0 -0
- package/src/client/shell/favicon/android-chrome-512x512-interactive.png +0 -0
- package/src/client/shell/favicon/android-chrome-512x512.png +0 -0
- package/src/client/shell/favicon/apple-touch-icon-interactive.png +0 -0
- package/src/client/shell/favicon/apple-touch-icon.png +0 -0
- package/src/client/shell/favicon/favicon-16x16-interactive.png +0 -0
- package/src/client/shell/favicon/favicon-16x16.png +0 -0
- package/src/client/shell/favicon/favicon-32x32-interactive.png +0 -0
- package/src/client/shell/favicon/favicon-32x32.png +0 -0
- package/src/client/shell/favicon/favicon.ico +0 -0
- package/src/client/shell/favicon/site.webmanifest +11 -0
- package/src/client/shell/hash.ts +67 -0
- package/src/client/shell/icons.tsx +53 -0
- package/src/client/shell/index.html +17 -0
- package/src/client/shell/main.tsx +9 -0
- package/src/client/shell/store.ts +540 -0
- package/src/client/shell/styles.css +508 -0
- package/src/client/shell/tidy.ts +24 -0
- package/src/client/stage/index.html +11 -0
- package/src/client/stage/main.tsx +160 -0
- package/templates/AGENTS-embedded.md +76 -0
- package/templates/AGENTS-studio.md +76 -0
- package/templates/demo/_fixtures.ts +9 -0
- package/templates/demo/dark.tsx +17 -0
- package/templates/demo/form.tsx +51 -0
- package/templates/demo/welcome.tsx +21 -0
- package/templates/design-tsconfig.json +8 -0
- package/templates/root-layout.tsx +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Marver
|
|
2
|
+
|
|
3
|
+
The agent-native design canvas. A `design/` folder in your repo, one command, and a canvas of live frames built from your app's real components and theme. Your coding agent designs by writing files; the tool ships no AI.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i -D @marver-design/marver
|
|
7
|
+
npx marver init # scaffolds design/ (detects shadcn, Tailwind, your router)
|
|
8
|
+
npx marver dev # canvas at localhost:5199
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then, to your agent:
|
|
12
|
+
|
|
13
|
+
> Read design/AGENTS.md. Build an onboarding scene - welcome, form, done - mobile-first, using our components.
|
|
14
|
+
|
|
15
|
+
- **Frames** are plain TSX/HTML files - zero imports from this package required.
|
|
16
|
+
- **Everything hot-reloads**; frames appear on the canvas the moment the file lands.
|
|
17
|
+
- Drag a frame's edge and the real breakpoints fire - each frame is a true iframe viewport.
|
|
18
|
+
- **Boards**: one canvas on screen at a time. Agents write `design/boards/<name>.json` (a frame list is enough); switch boards at the top of the sidebar. `all-scenes` is auto-managed.
|
|
19
|
+
- **Devices view**: the Devices menu (or hotkeys `1`-`5`) sizes every frame to mobile / tablet / laptop / monitor / tv to sweep your breakpoints; `0` restores your own layout exactly. Widths live in `design/config.ts`.
|
|
20
|
+
- `data-goto="scene/frame"` on any element links frames into a walkable prototype.
|
|
21
|
+
- Uninstall: delete `design/`, remove the dependency. (If `init` patched your tsconfig `exclude`, revert that one line.)
|
|
22
|
+
|
|
23
|
+
The implementation contract is [SPEC.md](./SPEC.md). Deviations live in [DECISIONS.md](./DECISIONS.md).
|
|
24
|
+
|
|
25
|
+
; private; TNEP4.
|
|
26
|
+
|
|
27
|
+
## Shortcuts
|
|
28
|
+
|
|
29
|
+
**Canvas** - two-finger scroll pans · pinch or ctrl/cmd+scroll zooms · space+drag pans from anywhere · click empty canvas deselects / exits interact.
|
|
30
|
+
|
|
31
|
+
**Zoom** - `⇧0` 100% · `⇧1` fit all · `⇧2` fit selection · click the % readout for presets (200-10%).
|
|
32
|
+
|
|
33
|
+
**Device views** - plain digits, auto-tidy + refit every time. Scoped to the selection when frames are selected, board-wide otherwise.
|
|
34
|
+
`0` default sizes (restores your free-form layout) · `1` mobile · `2` tablet · `3` laptop · `4` monitor · `5` tv (when enabled in design/config.ts).
|
|
35
|
+
|
|
36
|
+
**Board & chrome** - `t` tidy · `d` toggle light/dark for the board · `⌘\` (ctrl+\) collapse/open sidebar.
|
|
37
|
+
|
|
38
|
+
**Selection** - click selects · shift+click (canvas or sidebar) builds a multi-selection · `⌘A` selects every frame on the board · `c` copies the selected frames' file paths · double-click enters interact mode (`esc` or click outside leaves) · drag the title bar to move, edges to resize (widths snap to devices).
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { r as ROUTE, t as NAME } from "./cli.mjs";
|
|
2
|
+
import { n as loadConfig, r as detectHost } from "./config-DMBEpdEN.mjs";
|
|
3
|
+
import { i as scanFrames, n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-DB5t2WUl.mjs";
|
|
4
|
+
import { basename, dirname, join, sep } from "node:path";
|
|
5
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { build } from "vite";
|
|
8
|
+
import react from "@vitejs/plugin-react";
|
|
9
|
+
//#region src/server/build.ts
|
|
10
|
+
/**
|
|
11
|
+
* `marver build` - the static adapter (SPEC.md §12 + SPEC-M2 §4a).
|
|
12
|
+
*
|
|
13
|
+
* Same Vite pipeline as dev (theme wrapper, tailwind, virtuals) with three JS entries
|
|
14
|
+
* (shell / frame-host / stage); the html pages are generated from the build output, so
|
|
15
|
+
* the routes middleware has no static counterpart to maintain. `virtual:sh-data` inlines
|
|
16
|
+
* manifest + boards - a published canvas fetches nothing and writes nothing.
|
|
17
|
+
*
|
|
18
|
+
* `--boards a,b` is the privacy boundary and it is enforced at BUILD time: the manifest
|
|
19
|
+
* is filtered to the frames those boards reference, and the frame-host registry module
|
|
20
|
+
* is replaced by a generated one whose only imports are the published frames - excluded
|
|
21
|
+
* frame modules never enter the bundle. Runtime hiding would not be security.
|
|
22
|
+
*/
|
|
23
|
+
const posix = (p) => p.split(sep).join("/");
|
|
24
|
+
function packageDir() {
|
|
25
|
+
return join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
26
|
+
}
|
|
27
|
+
/** Read every board file; returns name -> parsed json. Bad JSON fails the build loudly. */
|
|
28
|
+
function readBoards(root) {
|
|
29
|
+
const dir = join(root, "design", "boards");
|
|
30
|
+
const out = {};
|
|
31
|
+
if (!existsSync(dir)) return out;
|
|
32
|
+
for (const f of readdirSync(dir)) {
|
|
33
|
+
if (!f.endsWith(".json")) continue;
|
|
34
|
+
const name = f.replace(/\.json$/, "");
|
|
35
|
+
try {
|
|
36
|
+
out[name] = JSON.parse(readFileSync(join(dir, f), "utf8"));
|
|
37
|
+
} catch {
|
|
38
|
+
throw new Error(`design/boards/${f} is not valid JSON`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** The generated registry for filtered builds: explicit imports only, same exports. */
|
|
44
|
+
function registrySource(root, frameKeys) {
|
|
45
|
+
const bases = ["/design/scenes", "/design/components"];
|
|
46
|
+
const layouts = /* @__PURE__ */ new Set();
|
|
47
|
+
for (const key of frameKeys) {
|
|
48
|
+
const base = bases.find((b) => key.startsWith(b + "/")) ?? bases[0];
|
|
49
|
+
let dir = key.slice(0, key.lastIndexOf("/"));
|
|
50
|
+
while (dir.length >= base.length) {
|
|
51
|
+
for (const ext of ["tsx", "jsx"]) if (existsSync(join(root, `${dir}/_layout.${ext}`.slice(1)))) layouts.add(`${dir}/_layout.${ext}`);
|
|
52
|
+
if (dir === base) break;
|
|
53
|
+
dir = dir.slice(0, dir.lastIndexOf("/"));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const providers = ["tsx", "jsx"].map((e) => `/design/providers.${e}`).filter((p) => existsSync(join(root, p.slice(1))));
|
|
57
|
+
const map = (keys) => `{ ${[...keys].map((k) => `'${k}': () => import('${k}')`).join(", ")} }`;
|
|
58
|
+
return `// generated by \`${NAME} build --boards\` - only published frames are imported
|
|
59
|
+
export const frames = ${map(frameKeys)}
|
|
60
|
+
export const layouts = ${map(layouts)}
|
|
61
|
+
export const providers = ${map(providers)}
|
|
62
|
+
export function frameFile(frameId) {
|
|
63
|
+
for (const ext of ['tsx', 'jsx']) {
|
|
64
|
+
for (const prefix of ['/design/scenes/', '/design/']) {
|
|
65
|
+
const key = prefix + frameId + '.' + ext
|
|
66
|
+
if (key in frames) return key
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
export function layoutChain(fileKey) {
|
|
72
|
+
const dir = fileKey.slice(0, fileKey.lastIndexOf('/'))
|
|
73
|
+
const chain = []
|
|
74
|
+
const base = fileKey.startsWith('/design/scenes/') ? '/design/scenes' : '/design/components'
|
|
75
|
+
let cur = dir
|
|
76
|
+
while (cur.length >= base.length) {
|
|
77
|
+
for (const ext of ['tsx', 'jsx']) {
|
|
78
|
+
const key = cur + '/_layout.' + ext
|
|
79
|
+
if (key in layouts) { chain.unshift(key); break }
|
|
80
|
+
}
|
|
81
|
+
if (cur === base) break
|
|
82
|
+
cur = cur.slice(0, cur.lastIndexOf('/'))
|
|
83
|
+
}
|
|
84
|
+
return chain
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
async function buildSite(root, boardsFlag) {
|
|
89
|
+
const config = await loadConfig(root);
|
|
90
|
+
const host = detectHost(root);
|
|
91
|
+
const pkgDir = packageDir();
|
|
92
|
+
const clientDir = join(pkgDir, "src", "client");
|
|
93
|
+
const outDir = join(root, "design", ".dist");
|
|
94
|
+
const manifest = scanFrames(root);
|
|
95
|
+
const allBoards = readBoards(root);
|
|
96
|
+
let publishedNames;
|
|
97
|
+
if (boardsFlag !== void 0) {
|
|
98
|
+
publishedNames = boardsFlag.split(",").map((s) => s.trim()).filter(Boolean);
|
|
99
|
+
if (!publishedNames.length) throw new Error("--boards was given but named no boards");
|
|
100
|
+
const missing = publishedNames.filter((n) => n !== "all-scenes" && !allBoards[n]);
|
|
101
|
+
if (missing.length) throw new Error(`--boards names not found in design/boards/: ${missing.join(", ")}`);
|
|
102
|
+
} else publishedNames = ["all-scenes", ...Object.keys(allBoards).filter((n) => n !== "all-scenes")];
|
|
103
|
+
const includeAll = publishedNames.includes("all-scenes");
|
|
104
|
+
const boards = {};
|
|
105
|
+
for (const n of publishedNames) if (allBoards[n]) boards[n] = allBoards[n];
|
|
106
|
+
let frames = manifest.frames;
|
|
107
|
+
if (!includeAll) {
|
|
108
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
109
|
+
for (const b of Object.values(boards)) for (const node of Array.isArray(b?.nodes) ? b.nodes : []) if (typeof node?.frame === "string") wanted.add(node.frame);
|
|
110
|
+
frames = manifest.frames.filter((f) => wanted.has(f.id));
|
|
111
|
+
}
|
|
112
|
+
const data = {
|
|
113
|
+
manifest: {
|
|
114
|
+
frames,
|
|
115
|
+
scenes: [...new Set(frames.map((f) => f.scene))].sort().map((name) => ({
|
|
116
|
+
name,
|
|
117
|
+
frames: frames.filter((f) => f.scene === name).length
|
|
118
|
+
}))
|
|
119
|
+
},
|
|
120
|
+
boards,
|
|
121
|
+
names: publishedNames,
|
|
122
|
+
default: publishedNames[0]
|
|
123
|
+
};
|
|
124
|
+
const registryFile = posix(join(clientDir, "frame-host", "registry.ts"));
|
|
125
|
+
const plugins = [{
|
|
126
|
+
name: "marver-build",
|
|
127
|
+
enforce: "pre",
|
|
128
|
+
resolveId(id) {
|
|
129
|
+
if (id === "virtual:sh-data") return "\0sh-data-build";
|
|
130
|
+
},
|
|
131
|
+
load(id) {
|
|
132
|
+
if (id === "\0sh-data-build") return `export default ${JSON.stringify(data)}`;
|
|
133
|
+
if (!includeAll && posix(id) === registryFile) return registrySource(root, frames.filter((f) => f.kind === "tsx").map((f) => "/" + posix(f.file)));
|
|
134
|
+
}
|
|
135
|
+
}, react()];
|
|
136
|
+
if (host.tailwind === 4) {
|
|
137
|
+
const tw = await tailwind4Plugin(root);
|
|
138
|
+
if (tw) plugins.push(...tw);
|
|
139
|
+
}
|
|
140
|
+
let css;
|
|
141
|
+
if (host.tailwind === 3) css = await tailwind3Css(root) ?? void 0;
|
|
142
|
+
plugins.push(marverPlugin({
|
|
143
|
+
root,
|
|
144
|
+
clientDir,
|
|
145
|
+
config,
|
|
146
|
+
detectedThemeCss: host.themeCss
|
|
147
|
+
}));
|
|
148
|
+
const result = await build({
|
|
149
|
+
configFile: false,
|
|
150
|
+
root,
|
|
151
|
+
css,
|
|
152
|
+
plugins,
|
|
153
|
+
resolve: {
|
|
154
|
+
dedupe: ["react", "react-dom"],
|
|
155
|
+
tsconfigPaths: true
|
|
156
|
+
},
|
|
157
|
+
build: {
|
|
158
|
+
outDir,
|
|
159
|
+
emptyOutDir: true,
|
|
160
|
+
cssCodeSplit: true,
|
|
161
|
+
cssMinify: false,
|
|
162
|
+
rollupOptions: {
|
|
163
|
+
input: {
|
|
164
|
+
shell: join(clientDir, "shell", "main.tsx"),
|
|
165
|
+
frame: join(clientDir, "frame-host", "main.tsx"),
|
|
166
|
+
stage: join(clientDir, "stage", "main.tsx")
|
|
167
|
+
},
|
|
168
|
+
output: {
|
|
169
|
+
entryFileNames: "assets/[name]-[hash].js",
|
|
170
|
+
chunkFileNames: "assets/[name]-[hash].js",
|
|
171
|
+
assetFileNames: "assets/[name]-[hash][extname]"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
logLevel: "warn"
|
|
176
|
+
});
|
|
177
|
+
const chunks = (Array.isArray(result) ? result[0] : result).output.filter((o) => o.type === "chunk");
|
|
178
|
+
const byFile = new Map(chunks.map((c) => [c.fileName, c]));
|
|
179
|
+
const cssFor = (entryName) => {
|
|
180
|
+
const entry = chunks.find((c) => c.isEntry && c.name === entryName);
|
|
181
|
+
const seen = /* @__PURE__ */ new Set(), css = /* @__PURE__ */ new Set();
|
|
182
|
+
const walk = (c) => {
|
|
183
|
+
if (!c || seen.has(c.fileName)) return;
|
|
184
|
+
seen.add(c.fileName);
|
|
185
|
+
for (const f of c.viteMetadata?.importedCss ?? []) css.add(f);
|
|
186
|
+
for (const imp of c.imports) walk(byFile.get(imp));
|
|
187
|
+
};
|
|
188
|
+
walk(entry);
|
|
189
|
+
return [...css];
|
|
190
|
+
};
|
|
191
|
+
const page = (srcDir, entryName, outPath) => {
|
|
192
|
+
const entry = chunks.find((c) => c.isEntry && c.name === entryName);
|
|
193
|
+
const links = cssFor(entryName).map((f) => `<link rel="stylesheet" href="/${f}" />`).join("\n ");
|
|
194
|
+
const html = readFileSync(join(clientDir, srcDir, "index.html"), "utf8").replaceAll("{{ROUTE}}", ROUTE).replace("<script type=\"module\" src=\"{{ENTRY}}\"><\/script>", `${links}\n <script type="module" src="/${entry.fileName}"><\/script>`);
|
|
195
|
+
mkdirSync(dirname(join(outDir, outPath)), { recursive: true });
|
|
196
|
+
writeFileSync(join(outDir, outPath), html);
|
|
197
|
+
};
|
|
198
|
+
page("shell", "shell", "index.html");
|
|
199
|
+
page("frame-host", "frame", `${ROUTE.slice(1)}/frame/index.html`);
|
|
200
|
+
page("stage", "stage", `${ROUTE.slice(1)}/stage/index.html`);
|
|
201
|
+
cpSync(join(clientDir, "shell", "favicon"), join(outDir, ROUTE.slice(1), "favicon"), { recursive: true });
|
|
202
|
+
cpSync(join(clientDir, "frame-host", "bridge.js"), join(outDir, "assets", "bridge.js"));
|
|
203
|
+
const frameCss = cssFor("frame").map((f) => `<link rel="stylesheet" href="/${f}" />`).join("\n");
|
|
204
|
+
for (const f of frames.filter((x) => x.kind === "html")) {
|
|
205
|
+
const src = readFileSync(join(root, f.file), "utf8");
|
|
206
|
+
const inject = `${frameCss}\n<script type="module" src="/assets/bridge.js?html=1"><\/script>\n`;
|
|
207
|
+
const html = src.includes("</head>") ? src.replace("</head>", `${inject}</head>`) : inject + src;
|
|
208
|
+
mkdirSync(dirname(join(outDir, f.file)), { recursive: true });
|
|
209
|
+
writeFileSync(join(outDir, f.file), html);
|
|
210
|
+
}
|
|
211
|
+
let name = basename(root);
|
|
212
|
+
try {
|
|
213
|
+
name = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).name ?? name;
|
|
214
|
+
} catch {}
|
|
215
|
+
if (config.share.name) name = config.share.name;
|
|
216
|
+
let logo;
|
|
217
|
+
const logoLadder = [
|
|
218
|
+
...config.share.logo ? [config.share.logo] : [],
|
|
219
|
+
"design/logo.svg",
|
|
220
|
+
"design/logo.png",
|
|
221
|
+
"public/logo.svg",
|
|
222
|
+
"public/logo.png",
|
|
223
|
+
"public/favicon.svg"
|
|
224
|
+
];
|
|
225
|
+
for (const cand of logoLadder) {
|
|
226
|
+
if (!existsSync(join(root, cand))) continue;
|
|
227
|
+
const ext = cand.endsWith(".png") ? "png" : "svg";
|
|
228
|
+
cpSync(join(root, cand), join(outDir, ROUTE.slice(1), `logo.${ext}`));
|
|
229
|
+
logo = `${ROUTE}/logo.${ext}`;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
writeFileSync(join(outDir, "meta.json"), JSON.stringify({
|
|
233
|
+
name,
|
|
234
|
+
branding: config.share.branding,
|
|
235
|
+
logo
|
|
236
|
+
}));
|
|
237
|
+
console.log(`\n ${NAME} build → design/.dist`);
|
|
238
|
+
console.log(` boards: ${publishedNames.join(", ")}`);
|
|
239
|
+
console.log(` frames: ${frames.length}${includeAll ? "" : ` of ${manifest.frames.length} (build-time filter)`}`);
|
|
240
|
+
if (!includeAll && existsSync(join(root, "public"))) console.log(` note: the host public/ directory ships in full - the --boards filter covers frames, not public assets`);
|
|
241
|
+
console.log(`\n serve it: npx ${NAME} serve (set MARVER_PASSWORD to gate it)\n`);
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
export { buildSite };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cac } from "cac";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
//#region src/client/const.ts
|
|
5
|
+
/** Client-safe constants. The single source - src/cli/name.ts re-exports for node-side code.
|
|
6
|
+
* Lives under src/client because that is the only source directory shipped in the package. */
|
|
7
|
+
const NAME = "marver";
|
|
8
|
+
const PKG = "@marver-design/marver";
|
|
9
|
+
const ROUTE = "/__mv";
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/cli/index.ts
|
|
12
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
13
|
+
if (major < 22 || major === 22 && minor < 18) {
|
|
14
|
+
console.error(`${NAME} needs Node >= 22.18 (native TypeScript config loading). You have ${process.versions.node}.`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const cli = cac(NAME);
|
|
18
|
+
cli.command("init", "Scaffold design/ in this repo").option("--mode <mode>", "studio | embedded", { default: "studio" }).option("--no-demo", "Skip the demo scene").option("--root <dir>", "Host repo root", { default: "." }).action(async (opts) => {
|
|
19
|
+
const { init } = await import("./init-DcOy1krf.mjs");
|
|
20
|
+
init(resolve(opts.root), {
|
|
21
|
+
mode: opts.mode === "embedded" ? "embedded" : "studio",
|
|
22
|
+
demo: opts.demo !== false
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
cli.command("dev", "Start the canvas").option("--root <dir>", "Host repo root", { default: "." }).option("--port <port>", "Port (default 5199)").action(async (opts) => {
|
|
26
|
+
const { dev } = await import("./dev-BK4x3PBr.mjs");
|
|
27
|
+
let port;
|
|
28
|
+
if (opts.port !== void 0) {
|
|
29
|
+
const n = Number(opts.port);
|
|
30
|
+
if (Number.isInteger(n) && n > 0 && n < 65536) port = n;
|
|
31
|
+
else console.warn(`[${NAME}] ignoring invalid --port "${opts.port}"`);
|
|
32
|
+
}
|
|
33
|
+
await dev(resolve(opts.root), port);
|
|
34
|
+
});
|
|
35
|
+
cli.command("build", "Static export → design/.dist").option("--boards <names>", "Publish only these boards (comma-separated); the frame filter is applied at build time").option("--root <dir>", "Host repo root", { default: "." }).action(async (opts) => {
|
|
36
|
+
const { buildSite } = await import("./build-D0GnIR4G.mjs");
|
|
37
|
+
try {
|
|
38
|
+
const boards = opts.boards === void 0 ? void 0 : typeof opts.boards === "string" ? opts.boards : "";
|
|
39
|
+
await buildSite(resolve(opts.root), boards);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error(`[${NAME}] build failed: ${err.message}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
cli.command("serve", "Serve design/.dist (set MARVER_PASSWORD to gate it)").option("--root <dir>", "Host repo root", { default: "." }).option("--port <port>", "Port (default $PORT or 4199)").action(async (opts) => {
|
|
46
|
+
const { serve } = await import("./serve-BPNmWeJx.mjs");
|
|
47
|
+
let port;
|
|
48
|
+
if (opts.port !== void 0) {
|
|
49
|
+
const n = Number(opts.port);
|
|
50
|
+
if (Number.isInteger(n) && n > 0 && n < 65536) port = n;
|
|
51
|
+
}
|
|
52
|
+
serve(resolve(opts.root), port);
|
|
53
|
+
});
|
|
54
|
+
cli.help();
|
|
55
|
+
cli.version("0.1.0");
|
|
56
|
+
cli.parse();
|
|
57
|
+
//#endregion
|
|
58
|
+
export { PKG as n, ROUTE as r, NAME as t };
|