@westopp/windo 0.1.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 +146 -0
- package/dist/chunk-5RM2VYAM.js +150 -0
- package/dist/chunk-5RM2VYAM.js.map +1 -0
- package/dist/cli.cjs +303 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +138 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +219 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +374 -0
- package/dist/index.d.ts +374 -0
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.cjs +185 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +11 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.js +11 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +95 -0
- package/src/cli/index.ts +160 -0
- package/src/client/App.tsx +310 -0
- package/src/client/Canvas.tsx +358 -0
- package/src/client/Inspector.tsx +586 -0
- package/src/client/Sidebar.tsx +108 -0
- package/src/client/bridge.ts +124 -0
- package/src/client/chrome.css +1966 -0
- package/src/client/icons.tsx +110 -0
- package/src/client/index.ts +15 -0
- package/src/client/internal-types.ts +147 -0
- package/src/client/persist.ts +38 -0
- package/src/define-config.ts +54 -0
- package/src/descriptor.test.ts +59 -0
- package/src/descriptor.ts +185 -0
- package/src/globals.d.ts +9 -0
- package/src/index.ts +54 -0
- package/src/plugin/index.ts +181 -0
- package/src/preview/ctx.ts +43 -0
- package/src/preview/index.ts +283 -0
- package/src/preview/preview.css +81 -0
- package/src/preview/registry.ts +159 -0
- package/src/preview/render.tsx +90 -0
- package/src/preview/virtual.d.ts +8 -0
- package/src/protocol.ts +59 -0
- package/src/types.ts +319 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 westopp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# windo
|
|
2
|
+
|
|
3
|
+
Zero-infra component canvas. Point it at your `*.windo.tsx` files and get a resizable iframe preview with live JSON props, variants, and ambient contexts — no Storybook config, no build step to maintain.
|
|
4
|
+
|
|
5
|
+
Each component renders inside a real iframe, so its styles, layout, and media queries are isolated from the workbench chrome. Props are edited as JSON and validated by your zod schema before they reach the component.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i -D @westopp/windo zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react`, `react-dom`, `zod`, and (optionally) `vite` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
### 1. Add a `windo.config.ts`
|
|
18
|
+
|
|
19
|
+
`defineWindoConfig` is the single entry point. It captures your **groups** (the sidebar sections) and **contexts** (ambient controls + providers), and hands back a `windo` factory whose `group` field is type-checked against your configured slugs.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { defineWindoConfig, defineContext } from '@westopp/windo'
|
|
23
|
+
import { z } from 'zod'
|
|
24
|
+
|
|
25
|
+
export const { config, windo } = defineWindoConfig({
|
|
26
|
+
title: 'Acme UI',
|
|
27
|
+
groups: [
|
|
28
|
+
{ name: 'Primitives', slug: 'primitives' },
|
|
29
|
+
{ name: 'Forms', slug: 'forms', description: 'Inputs and controls' },
|
|
30
|
+
],
|
|
31
|
+
contexts: {
|
|
32
|
+
theme: defineContext({
|
|
33
|
+
label: 'Theme',
|
|
34
|
+
controls: {
|
|
35
|
+
accent: { type: 'enum', default: 'indigo', options: ['indigo', 'teal', 'rose'] },
|
|
36
|
+
},
|
|
37
|
+
// Optional: mount a provider inside the iframe for components that opt in via `uses`
|
|
38
|
+
provider: ({ children, values }) => <ThemeProvider accent={values.accent}>{children}</ThemeProvider>,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
A context can contribute ambient `controls` (free toggles, always available), a `provider` (mounted in the iframe, opt-in per component), or both.
|
|
45
|
+
|
|
46
|
+
### 2. Write a `Button.windo.tsx`
|
|
47
|
+
|
|
48
|
+
Import the `windo` factory from your config and default-export the result. `configurableProps<Props>()(schema)` binds a zod schema to your prop type — its `z.input` is the JSON edit surface, its `z.output` is what the component receives.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { z } from 'zod'
|
|
52
|
+
import { configurableProps } from '@westopp/windo'
|
|
53
|
+
import { windo } from '../windo.config'
|
|
54
|
+
import { Button, type ButtonProps } from './Button'
|
|
55
|
+
|
|
56
|
+
const props = configurableProps<ButtonProps>()(
|
|
57
|
+
z.object({
|
|
58
|
+
label: z.string(),
|
|
59
|
+
variant: z.enum(['primary', 'secondary', 'ghost']),
|
|
60
|
+
disabled: z.boolean().optional(),
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
export default windo<ButtonProps>(w => ({
|
|
65
|
+
title: 'Button',
|
|
66
|
+
group: w.groups.primitives.slug,
|
|
67
|
+
placement: 'center',
|
|
68
|
+
configurableProps: props,
|
|
69
|
+
defaultProps: { label: 'Click me', variant: 'primary' },
|
|
70
|
+
variants: [
|
|
71
|
+
{ label: 'Secondary', props: { variant: 'secondary' } },
|
|
72
|
+
{ label: 'Disabled', props: { disabled: true } },
|
|
73
|
+
],
|
|
74
|
+
component: props => <Button {...props} />,
|
|
75
|
+
}))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The factory runs **once** at definition time for static fields (`title`, `group`, `configurableProps`). Function fields — `defaultProps`, `component`, `providers`, `code` — run at render time with the live `ctx` (color scheme, viewport, locale, resolved contexts, `action`/`log`). Never close over live values in the static factory body.
|
|
79
|
+
|
|
80
|
+
### 3. Run the dev server
|
|
81
|
+
|
|
82
|
+
Via the bin:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
windo dev # defaults to cwd; serves the workbench
|
|
86
|
+
windo dev ./src -p 6006 --open
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or wire the Vite plugin yourself:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// vite.config.ts
|
|
93
|
+
import { defineConfig } from 'vite'
|
|
94
|
+
import { windo } from '@westopp/windo/plugin'
|
|
95
|
+
|
|
96
|
+
export default defineConfig({
|
|
97
|
+
plugins: [windo({ config: 'windo.config.ts' })],
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The plugin pairs `@vitejs/plugin-react` with windo, serves the chrome + iframe HTML, and discovers every `*.windo.tsx` matching your `include` glob.
|
|
102
|
+
|
|
103
|
+
## Authoring API
|
|
104
|
+
|
|
105
|
+
`windo(w => definition)` — the factory returns a `WindoDefinition`:
|
|
106
|
+
|
|
107
|
+
| Field | Type | Notes |
|
|
108
|
+
|-------|------|-------|
|
|
109
|
+
| `title` | `string` | Display name in the sidebar. **Required.** |
|
|
110
|
+
| `group` | group slug | Type-checked against configured slugs. **Required.** |
|
|
111
|
+
| `component` | `(props, ctx) => ReactNode` | Renders the component. **Required.** |
|
|
112
|
+
| `defaultProps` | `Props` or `ctx => Props` | Full props incl. functions/JSX; JSON edits merge on top. **Required.** |
|
|
113
|
+
| `configurableProps` | zod schema | Validator + parser for the JSON-editable prop subset. |
|
|
114
|
+
| `placement` | `WindoPlacement` | Where it sits in the canvas frame (see below). |
|
|
115
|
+
| `variants` | `{ label, props }[]` | Click-to-apply prop patches shown in the gallery. |
|
|
116
|
+
| `uses` | `string[]` | Context names whose `provider` should wrap this component. |
|
|
117
|
+
| `status` | `'stable' \| 'beta' \| 'deprecated'` | Badge in the sidebar. |
|
|
118
|
+
| `description` / `deprecation` | `string` | Shown in the chrome. |
|
|
119
|
+
| `props` | `{ name, type, default?, desc? }[]` | Authored docs table (not derived from the schema). |
|
|
120
|
+
| `code` | `(values) => string` | Optional snippet for the Code tab. |
|
|
121
|
+
| `providers` | `({ children, ctx }) => ReactNode` | A local provider wrapping just this windo. |
|
|
122
|
+
|
|
123
|
+
Config-level helpers:
|
|
124
|
+
|
|
125
|
+
- `defineWindoConfig({ groups, contexts?, include?, title? })` → `{ config, windo }`
|
|
126
|
+
- `defineContext({ label?, description?, controls?, provider?, resolve? })`
|
|
127
|
+
- `configurableProps<Props>()(schema)` — identity helper that constrains the schema to `Partial<Props>`
|
|
128
|
+
|
|
129
|
+
## Placement
|
|
130
|
+
|
|
131
|
+
`placement` positions the component within the resizable canvas frame:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
center fill top bottom left right
|
|
135
|
+
top-left top-right bottom-left bottom-right
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Defaults to `center`.
|
|
139
|
+
|
|
140
|
+
## How props editing works
|
|
141
|
+
|
|
142
|
+
The `configurableProps` zod schema lives in the iframe and does the real parsing. Its **input** shape is flattened into a serialisable descriptor (via `describeSchema`) that the chrome uses to render controls and the Schema panel. When you edit props as JSON, the iframe validates them with the live schema (transforms, `coerce`, `refine` and all) and either renders the parsed output or surfaces per-field errors. Whatever the JSON omits falls back to `defaultProps`.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/plugin/index.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { isAbsolute, resolve as resolvePath } from "path";
|
|
4
|
+
import reactPlugin from "@vitejs/plugin-react";
|
|
5
|
+
var VIRTUAL_ID = "virtual:windo-registry";
|
|
6
|
+
var RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
|
|
7
|
+
var CONFIG_CANDIDATES = ["windo.config.ts", "windo.config.tsx", "windo.config.mts", "windo.config.js", "windo.config.mjs"];
|
|
8
|
+
function findConfig(root, configOpt) {
|
|
9
|
+
if (configOpt) return isAbsolute(configOpt) ? configOpt : resolvePath(root, configOpt);
|
|
10
|
+
for (const candidate of CONFIG_CANDIDATES) {
|
|
11
|
+
const full = resolvePath(root, candidate);
|
|
12
|
+
if (existsSync(full)) return full;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function toGlob(include) {
|
|
17
|
+
const first = Array.isArray(include) ? include[0] : include;
|
|
18
|
+
const pattern = first ?? "**/*.windo.tsx";
|
|
19
|
+
return pattern.startsWith("/") ? pattern : `/${pattern}`;
|
|
20
|
+
}
|
|
21
|
+
var CHROME_HTML = `<!doctype html>
|
|
22
|
+
<html data-theme="light">
|
|
23
|
+
<head>
|
|
24
|
+
<meta charset="utf-8" />
|
|
25
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
26
|
+
<title>windo</title>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<div id="root"></div>
|
|
30
|
+
<script type="module">
|
|
31
|
+
import('@westopp/windo/client')
|
|
32
|
+
</script>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
`;
|
|
36
|
+
var IFRAME_HTML = `<!doctype html>
|
|
37
|
+
<html>
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="utf-8" />
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
41
|
+
</head>
|
|
42
|
+
<body style="background: transparent">
|
|
43
|
+
<div id="root"></div>
|
|
44
|
+
<script type="module">
|
|
45
|
+
import('@westopp/windo/preview')
|
|
46
|
+
</script>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|
|
49
|
+
`;
|
|
50
|
+
function htmlIds(root) {
|
|
51
|
+
return {
|
|
52
|
+
index: resolvePath(root, "index.html"),
|
|
53
|
+
iframe: resolvePath(root, "__windo/iframe.html")
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function windo(options = {}) {
|
|
57
|
+
let resolvedRoot = process.cwd();
|
|
58
|
+
let ids = htmlIds(resolvedRoot);
|
|
59
|
+
const registryModule = () => {
|
|
60
|
+
const root = options.root ?? resolvedRoot ?? process.cwd();
|
|
61
|
+
const configPath = findConfig(root, options.config);
|
|
62
|
+
const glob = toGlob(options.include);
|
|
63
|
+
const importPath = configPath ? JSON.stringify(configPath) : "null";
|
|
64
|
+
const globLiteral = JSON.stringify(glob);
|
|
65
|
+
return [
|
|
66
|
+
`import * as __cfg from ${importPath}`,
|
|
67
|
+
"const config = __cfg.config ?? (__cfg.default && __cfg.default.config) ?? __cfg.default",
|
|
68
|
+
"export { config }",
|
|
69
|
+
`export const modules = import.meta.glob(${globLiteral})`,
|
|
70
|
+
""
|
|
71
|
+
].join("\n");
|
|
72
|
+
};
|
|
73
|
+
const plugin = {
|
|
74
|
+
name: "windo",
|
|
75
|
+
// `pre` so our resolveId/load claim the virtual registry and the two HTML
|
|
76
|
+
// entries before Vite's filesystem fallback tries (and fails) to read them.
|
|
77
|
+
enforce: "pre",
|
|
78
|
+
config(userConfig, { command, isPreview }) {
|
|
79
|
+
const root = resolvePath(options.root ?? userConfig.root ?? ".");
|
|
80
|
+
ids = htmlIds(root);
|
|
81
|
+
const base = {
|
|
82
|
+
// Dev serves the chrome + iframe HTML from `configureServer`, so it runs
|
|
83
|
+
// headless (`custom`). Build and preview want the normal SPA behaviour so
|
|
84
|
+
// `/` resolves to the emitted index.html.
|
|
85
|
+
appType: command === "serve" && !isPreview ? "custom" : "spa",
|
|
86
|
+
define: {
|
|
87
|
+
__WINDO_IFRAME_SRC__: JSON.stringify(command === "build" ? "./__windo/iframe.html" : "./__windo/iframe")
|
|
88
|
+
},
|
|
89
|
+
resolve: {
|
|
90
|
+
dedupe: ["react", "react-dom"]
|
|
91
|
+
},
|
|
92
|
+
optimizeDeps: {
|
|
93
|
+
// Pre-bundle every React entrypoint in one pass so React's identity is
|
|
94
|
+
// fixed up front. If `react-dom/client` (the preview renderer) is
|
|
95
|
+
// discovered late, Vite re-optimizes and can split React across two
|
|
96
|
+
// instances — fine until a component calls a hook, then "invalid hook
|
|
97
|
+
// call". Keeping them all here prevents that re-optimize.
|
|
98
|
+
include: ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
if (command === "build" && !userConfig.build?.rollupOptions?.input) {
|
|
102
|
+
base.build = { rollupOptions: { input: { index: ids.index, iframe: ids.iframe } } };
|
|
103
|
+
}
|
|
104
|
+
return base;
|
|
105
|
+
},
|
|
106
|
+
configResolved(resolved) {
|
|
107
|
+
resolvedRoot = resolved.root;
|
|
108
|
+
ids = htmlIds(resolvedRoot);
|
|
109
|
+
},
|
|
110
|
+
resolveId(id) {
|
|
111
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
112
|
+
if (id === ids.index || id === ids.iframe) return id;
|
|
113
|
+
return null;
|
|
114
|
+
},
|
|
115
|
+
load(id) {
|
|
116
|
+
if (id === RESOLVED_VIRTUAL_ID) return registryModule();
|
|
117
|
+
if (id === ids.index) return CHROME_HTML;
|
|
118
|
+
if (id === ids.iframe) return IFRAME_HTML;
|
|
119
|
+
return null;
|
|
120
|
+
},
|
|
121
|
+
configureServer(server) {
|
|
122
|
+
server.middlewares.use(async (req, res, next) => {
|
|
123
|
+
if (req.method !== "GET") return next();
|
|
124
|
+
const url = (req.url ?? "").split("?")[0];
|
|
125
|
+
let html = null;
|
|
126
|
+
if (url === "/" || url === "/index.html") html = CHROME_HTML;
|
|
127
|
+
else if (url.startsWith("/__windo/iframe")) html = IFRAME_HTML;
|
|
128
|
+
if (html === null) return next();
|
|
129
|
+
try {
|
|
130
|
+
const transformed = await server.transformIndexHtml(url, html);
|
|
131
|
+
res.statusCode = 200;
|
|
132
|
+
res.setHeader("Content-Type", "text/html");
|
|
133
|
+
res.end(transformed);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
next(err);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return [reactPlugin(), plugin];
|
|
141
|
+
}
|
|
142
|
+
var windoPlugin = windo;
|
|
143
|
+
var plugin_default = windo;
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
windo,
|
|
147
|
+
windoPlugin,
|
|
148
|
+
plugin_default
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=chunk-5RM2VYAM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin/index.ts"],"sourcesContent":["// Vite plugin (node side). Pairs `@vitejs/plugin-react` with the windo plugin:\n// serves the chrome + iframe HTML documents ourselves (appType custom) and\n// exposes a `virtual:windo-registry` module that re-exports the user config and\n// glob-imports every `*.windo.tsx` file.\n\nimport { existsSync } from 'node:fs'\nimport { isAbsolute, resolve as resolvePath } from 'node:path'\nimport reactPlugin from '@vitejs/plugin-react'\nimport type { Plugin, PluginOption, UserConfig, ViteDevServer } from 'vite'\n\nexport interface WindoPluginOptions {\n include?: string | string[]\n config?: string\n root?: string\n}\n\nconst VIRTUAL_ID = 'virtual:windo-registry'\nconst RESOLVED_VIRTUAL_ID = `\\0${VIRTUAL_ID}`\n\nconst CONFIG_CANDIDATES = ['windo.config.ts', 'windo.config.tsx', 'windo.config.mts', 'windo.config.js', 'windo.config.mjs'] as const\n\nfunction findConfig(root: string, configOpt?: string): string | null {\n if (configOpt) return isAbsolute(configOpt) ? configOpt : resolvePath(root, configOpt)\n for (const candidate of CONFIG_CANDIDATES) {\n const full = resolvePath(root, candidate)\n if (existsSync(full)) return full\n }\n return null\n}\n\nfunction toGlob(include?: string | string[]): string {\n const first = Array.isArray(include) ? include[0] : include\n const pattern = first ?? '**/*.windo.tsx'\n return pattern.startsWith('/') ? pattern : `/${pattern}`\n}\n\nconst CHROME_HTML = `<!doctype html>\n<html data-theme=\"light\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>windo</title>\n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"module\">\n import('@westopp/windo/client')\n </script>\n </body>\n</html>\n`\n\nconst IFRAME_HTML = `<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n </head>\n <body style=\"background: transparent\">\n <div id=\"root\"></div>\n <script type=\"module\">\n import('@westopp/windo/preview')\n </script>\n </body>\n</html>\n`\n\n// Absolute ids for the two HTML entry documents, relative to the project root.\n// They are virtual — the files need not exist on disk; the plugin's `load`\n// returns their contents. Keeping them rooted at `<root>/index.html` and\n// `<root>/__windo/iframe.html` makes `vite build` emit them at the matching\n// paths in the output directory (Vite derives an HTML asset's output path from\n// the input id's path relative to root).\nfunction htmlIds(root: string) {\n return {\n index: resolvePath(root, 'index.html'),\n iframe: resolvePath(root, '__windo/iframe.html'),\n }\n}\n\nexport function windo(options: WindoPluginOptions = {}): PluginOption[] {\n let resolvedRoot = process.cwd()\n let ids = htmlIds(resolvedRoot)\n\n const registryModule = (): string => {\n const root = options.root ?? resolvedRoot ?? process.cwd()\n const configPath = findConfig(root, options.config)\n const glob = toGlob(options.include)\n const importPath = configPath ? JSON.stringify(configPath) : 'null'\n const globLiteral = JSON.stringify(glob)\n return [\n `import * as __cfg from ${importPath}`,\n 'const config = __cfg.config ?? (__cfg.default && __cfg.default.config) ?? __cfg.default',\n 'export { config }',\n `export const modules = import.meta.glob(${globLiteral})`,\n '',\n ].join('\\n')\n }\n\n const plugin: Plugin = {\n name: 'windo',\n // `pre` so our resolveId/load claim the virtual registry and the two HTML\n // entries before Vite's filesystem fallback tries (and fails) to read them.\n enforce: 'pre',\n\n config(userConfig: UserConfig, { command, isPreview }) {\n const root = resolvePath(options.root ?? userConfig.root ?? '.')\n ids = htmlIds(root)\n const base: UserConfig = {\n // Dev serves the chrome + iframe HTML from `configureServer`, so it runs\n // headless (`custom`). Build and preview want the normal SPA behaviour so\n // `/` resolves to the emitted index.html.\n appType: command === 'serve' && !isPreview ? 'custom' : 'spa',\n define: {\n __WINDO_IFRAME_SRC__: JSON.stringify(command === 'build' ? './__windo/iframe.html' : './__windo/iframe'),\n },\n resolve: {\n dedupe: ['react', 'react-dom'],\n },\n optimizeDeps: {\n // Pre-bundle every React entrypoint in one pass so React's identity is\n // fixed up front. If `react-dom/client` (the preview renderer) is\n // discovered late, Vite re-optimizes and can split React across two\n // instances — fine until a component calls a hook, then \"invalid hook\n // call\". Keeping them all here prevents that re-optimize.\n include: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime', 'react/jsx-dev-runtime'],\n },\n }\n\n // Wire the chrome + iframe as build inputs unless the user supplied their\n // own. Both are emitted as static HTML the canvas can be hosted from.\n if (command === 'build' && !userConfig.build?.rollupOptions?.input) {\n base.build = { rollupOptions: { input: { index: ids.index, iframe: ids.iframe } } }\n }\n return base\n },\n\n configResolved(resolved) {\n resolvedRoot = resolved.root\n ids = htmlIds(resolvedRoot)\n },\n\n resolveId(id) {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID\n if (id === ids.index || id === ids.iframe) return id\n return null\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) return registryModule()\n if (id === ids.index) return CHROME_HTML\n if (id === ids.iframe) return IFRAME_HTML\n return null\n },\n\n configureServer(server: ViteDevServer) {\n server.middlewares.use(async (req, res, next) => {\n if (req.method !== 'GET') return next()\n const url = (req.url ?? '').split('?')[0]\n let html: string | null = null\n if (url === '/' || url === '/index.html') html = CHROME_HTML\n else if (url.startsWith('/__windo/iframe')) html = IFRAME_HTML\n if (html === null) return next()\n try {\n const transformed = await server.transformIndexHtml(url, html)\n res.statusCode = 200\n res.setHeader('Content-Type', 'text/html')\n res.end(transformed)\n } catch (err) {\n next(err)\n }\n })\n },\n }\n\n return [reactPlugin(), plugin]\n}\n\nexport const windoPlugin = windo\n\nexport default windo\n"],"mappings":"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","names":[]}
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/cli/index.ts
|
|
27
|
+
var import_node_util = require("util");
|
|
28
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
29
|
+
var import_vite = require("vite");
|
|
30
|
+
|
|
31
|
+
// src/plugin/index.ts
|
|
32
|
+
var import_node_fs = require("fs");
|
|
33
|
+
var import_node_path = require("path");
|
|
34
|
+
var import_plugin_react = __toESM(require("@vitejs/plugin-react"), 1);
|
|
35
|
+
var VIRTUAL_ID = "virtual:windo-registry";
|
|
36
|
+
var RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
|
|
37
|
+
var CONFIG_CANDIDATES = ["windo.config.ts", "windo.config.tsx", "windo.config.mts", "windo.config.js", "windo.config.mjs"];
|
|
38
|
+
function findConfig(root, configOpt) {
|
|
39
|
+
if (configOpt) return (0, import_node_path.isAbsolute)(configOpt) ? configOpt : (0, import_node_path.resolve)(root, configOpt);
|
|
40
|
+
for (const candidate of CONFIG_CANDIDATES) {
|
|
41
|
+
const full = (0, import_node_path.resolve)(root, candidate);
|
|
42
|
+
if ((0, import_node_fs.existsSync)(full)) return full;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function toGlob(include) {
|
|
47
|
+
const first = Array.isArray(include) ? include[0] : include;
|
|
48
|
+
const pattern = first ?? "**/*.windo.tsx";
|
|
49
|
+
return pattern.startsWith("/") ? pattern : `/${pattern}`;
|
|
50
|
+
}
|
|
51
|
+
var CHROME_HTML = `<!doctype html>
|
|
52
|
+
<html data-theme="light">
|
|
53
|
+
<head>
|
|
54
|
+
<meta charset="utf-8" />
|
|
55
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
56
|
+
<title>windo</title>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<div id="root"></div>
|
|
60
|
+
<script type="module">
|
|
61
|
+
import('@westopp/windo/client')
|
|
62
|
+
</script>
|
|
63
|
+
</body>
|
|
64
|
+
</html>
|
|
65
|
+
`;
|
|
66
|
+
var IFRAME_HTML = `<!doctype html>
|
|
67
|
+
<html>
|
|
68
|
+
<head>
|
|
69
|
+
<meta charset="utf-8" />
|
|
70
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
71
|
+
</head>
|
|
72
|
+
<body style="background: transparent">
|
|
73
|
+
<div id="root"></div>
|
|
74
|
+
<script type="module">
|
|
75
|
+
import('@westopp/windo/preview')
|
|
76
|
+
</script>
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
|
+
`;
|
|
80
|
+
function htmlIds(root) {
|
|
81
|
+
return {
|
|
82
|
+
index: (0, import_node_path.resolve)(root, "index.html"),
|
|
83
|
+
iframe: (0, import_node_path.resolve)(root, "__windo/iframe.html")
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function windo(options = {}) {
|
|
87
|
+
let resolvedRoot = process.cwd();
|
|
88
|
+
let ids = htmlIds(resolvedRoot);
|
|
89
|
+
const registryModule = () => {
|
|
90
|
+
const root = options.root ?? resolvedRoot ?? process.cwd();
|
|
91
|
+
const configPath = findConfig(root, options.config);
|
|
92
|
+
const glob = toGlob(options.include);
|
|
93
|
+
const importPath = configPath ? JSON.stringify(configPath) : "null";
|
|
94
|
+
const globLiteral = JSON.stringify(glob);
|
|
95
|
+
return [
|
|
96
|
+
`import * as __cfg from ${importPath}`,
|
|
97
|
+
"const config = __cfg.config ?? (__cfg.default && __cfg.default.config) ?? __cfg.default",
|
|
98
|
+
"export { config }",
|
|
99
|
+
`export const modules = import.meta.glob(${globLiteral})`,
|
|
100
|
+
""
|
|
101
|
+
].join("\n");
|
|
102
|
+
};
|
|
103
|
+
const plugin = {
|
|
104
|
+
name: "windo",
|
|
105
|
+
// `pre` so our resolveId/load claim the virtual registry and the two HTML
|
|
106
|
+
// entries before Vite's filesystem fallback tries (and fails) to read them.
|
|
107
|
+
enforce: "pre",
|
|
108
|
+
config(userConfig, { command, isPreview }) {
|
|
109
|
+
const root = (0, import_node_path.resolve)(options.root ?? userConfig.root ?? ".");
|
|
110
|
+
ids = htmlIds(root);
|
|
111
|
+
const base = {
|
|
112
|
+
// Dev serves the chrome + iframe HTML from `configureServer`, so it runs
|
|
113
|
+
// headless (`custom`). Build and preview want the normal SPA behaviour so
|
|
114
|
+
// `/` resolves to the emitted index.html.
|
|
115
|
+
appType: command === "serve" && !isPreview ? "custom" : "spa",
|
|
116
|
+
define: {
|
|
117
|
+
__WINDO_IFRAME_SRC__: JSON.stringify(command === "build" ? "./__windo/iframe.html" : "./__windo/iframe")
|
|
118
|
+
},
|
|
119
|
+
resolve: {
|
|
120
|
+
dedupe: ["react", "react-dom"]
|
|
121
|
+
},
|
|
122
|
+
optimizeDeps: {
|
|
123
|
+
// Pre-bundle every React entrypoint in one pass so React's identity is
|
|
124
|
+
// fixed up front. If `react-dom/client` (the preview renderer) is
|
|
125
|
+
// discovered late, Vite re-optimizes and can split React across two
|
|
126
|
+
// instances — fine until a component calls a hook, then "invalid hook
|
|
127
|
+
// call". Keeping them all here prevents that re-optimize.
|
|
128
|
+
include: ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
if (command === "build" && !userConfig.build?.rollupOptions?.input) {
|
|
132
|
+
base.build = { rollupOptions: { input: { index: ids.index, iframe: ids.iframe } } };
|
|
133
|
+
}
|
|
134
|
+
return base;
|
|
135
|
+
},
|
|
136
|
+
configResolved(resolved) {
|
|
137
|
+
resolvedRoot = resolved.root;
|
|
138
|
+
ids = htmlIds(resolvedRoot);
|
|
139
|
+
},
|
|
140
|
+
resolveId(id) {
|
|
141
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
142
|
+
if (id === ids.index || id === ids.iframe) return id;
|
|
143
|
+
return null;
|
|
144
|
+
},
|
|
145
|
+
load(id) {
|
|
146
|
+
if (id === RESOLVED_VIRTUAL_ID) return registryModule();
|
|
147
|
+
if (id === ids.index) return CHROME_HTML;
|
|
148
|
+
if (id === ids.iframe) return IFRAME_HTML;
|
|
149
|
+
return null;
|
|
150
|
+
},
|
|
151
|
+
configureServer(server) {
|
|
152
|
+
server.middlewares.use(async (req, res, next) => {
|
|
153
|
+
if (req.method !== "GET") return next();
|
|
154
|
+
const url = (req.url ?? "").split("?")[0];
|
|
155
|
+
let html = null;
|
|
156
|
+
if (url === "/" || url === "/index.html") html = CHROME_HTML;
|
|
157
|
+
else if (url.startsWith("/__windo/iframe")) html = IFRAME_HTML;
|
|
158
|
+
if (html === null) return next();
|
|
159
|
+
try {
|
|
160
|
+
const transformed = await server.transformIndexHtml(url, html);
|
|
161
|
+
res.statusCode = 200;
|
|
162
|
+
res.setHeader("Content-Type", "text/html");
|
|
163
|
+
res.end(transformed);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
next(err);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return [(0, import_plugin_react.default)(), plugin];
|
|
171
|
+
}
|
|
172
|
+
var windoPlugin = windo;
|
|
173
|
+
|
|
174
|
+
// src/cli/index.ts
|
|
175
|
+
var VERSION = "0.1.0";
|
|
176
|
+
var USAGE = `
|
|
177
|
+
${import_picocolors.default.bold("windo")} ${import_picocolors.default.dim(`v${VERSION}`)} \u2014 zero-infra component canvas
|
|
178
|
+
|
|
179
|
+
${import_picocolors.default.bold("Usage")}
|
|
180
|
+
windo [command] [root] [options]
|
|
181
|
+
|
|
182
|
+
${import_picocolors.default.bold("Commands")}
|
|
183
|
+
dev Start the dev server (default)
|
|
184
|
+
build Emit a static canvas to windo-static/
|
|
185
|
+
preview Serve a built canvas locally
|
|
186
|
+
|
|
187
|
+
${import_picocolors.default.bold("Options")}
|
|
188
|
+
-p, --port <n> Port to listen on (dev, preview)
|
|
189
|
+
--host [host] Expose on the network (dev, preview)
|
|
190
|
+
-o, --open Open the workbench in the browser (dev, preview)
|
|
191
|
+
-c, --config <p> Path to windo.config.ts (dev, build)
|
|
192
|
+
-d, --outDir <p> Output directory (build, preview) ${import_picocolors.default.dim("[windo-static]")}
|
|
193
|
+
-b, --base <p> Public base path for the build ${import_picocolors.default.dim("[./]")}
|
|
194
|
+
-h, --help Show this help
|
|
195
|
+
`;
|
|
196
|
+
var COMMANDS = /* @__PURE__ */ new Set(["dev", "build", "preview"]);
|
|
197
|
+
async function main() {
|
|
198
|
+
const argv = process.argv.slice(2);
|
|
199
|
+
const first = argv[0];
|
|
200
|
+
if (first === "-h" || first === "--help") {
|
|
201
|
+
console.log(USAGE);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let command = "dev";
|
|
205
|
+
let rest = argv;
|
|
206
|
+
if (first !== void 0 && !first.startsWith("-")) {
|
|
207
|
+
if (!COMMANDS.has(first)) {
|
|
208
|
+
console.error(`${import_picocolors.default.red(`windo: unknown command "${first}".`)}
|
|
209
|
+
${USAGE}`);
|
|
210
|
+
process.exitCode = 1;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
command = first;
|
|
214
|
+
rest = argv.slice(1);
|
|
215
|
+
}
|
|
216
|
+
const { values, positionals } = (0, import_node_util.parseArgs)({
|
|
217
|
+
args: rest,
|
|
218
|
+
allowPositionals: true,
|
|
219
|
+
options: {
|
|
220
|
+
port: { type: "string", short: "p" },
|
|
221
|
+
host: { type: "string" },
|
|
222
|
+
open: { type: "boolean", short: "o" },
|
|
223
|
+
config: { type: "string", short: "c" },
|
|
224
|
+
outDir: { type: "string", short: "d" },
|
|
225
|
+
base: { type: "string", short: "b" },
|
|
226
|
+
help: { type: "boolean", short: "h" }
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
if (values.help) {
|
|
230
|
+
console.log(USAGE);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const ALLOWED = {
|
|
234
|
+
dev: /* @__PURE__ */ new Set(["port", "host", "open", "config", "help"]),
|
|
235
|
+
build: /* @__PURE__ */ new Set(["config", "outDir", "base", "help"]),
|
|
236
|
+
preview: /* @__PURE__ */ new Set(["port", "host", "open", "outDir", "help"])
|
|
237
|
+
};
|
|
238
|
+
const stray = Object.keys(values).filter((k) => !ALLOWED[command].has(k));
|
|
239
|
+
if (stray.length > 0) {
|
|
240
|
+
console.error(`${import_picocolors.default.red(`windo ${command}: unsupported option${stray.length > 1 ? "s" : ""} ${stray.map((s) => `--${s}`).join(", ")}.`)}
|
|
241
|
+
${USAGE}`);
|
|
242
|
+
process.exitCode = 1;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const root = positionals[0] ? String(positionals[0]) : process.cwd();
|
|
246
|
+
const config = values.config;
|
|
247
|
+
if (command === "build") {
|
|
248
|
+
const outDir = values.outDir ?? "windo-static";
|
|
249
|
+
const base = values.base ?? "./";
|
|
250
|
+
console.log();
|
|
251
|
+
console.log(` ${import_picocolors.default.bold(import_picocolors.default.cyan("windo"))} ${import_picocolors.default.dim(`v${VERSION}`)} ${import_picocolors.default.dim("build")}`);
|
|
252
|
+
console.log();
|
|
253
|
+
await (0, import_vite.build)({
|
|
254
|
+
root,
|
|
255
|
+
base,
|
|
256
|
+
// Self-contained: don't merge an unrelated vite.config from the project.
|
|
257
|
+
configFile: false,
|
|
258
|
+
plugins: [windoPlugin({ config })],
|
|
259
|
+
build: { outDir, emptyOutDir: true }
|
|
260
|
+
});
|
|
261
|
+
console.log();
|
|
262
|
+
console.log(` ${import_picocolors.default.green("\u2713")} canvas written to ${import_picocolors.default.cyan(outDir)}`);
|
|
263
|
+
console.log(` ${import_picocolors.default.dim("preview it with")} ${import_picocolors.default.bold("windo preview")}${outDir === "windo-static" ? "" : ` -d ${outDir}`}`);
|
|
264
|
+
console.log();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (command === "preview") {
|
|
268
|
+
const outDir = values.outDir ?? "windo-static";
|
|
269
|
+
const port2 = values.port === void 0 ? void 0 : Number(values.port);
|
|
270
|
+
const host2 = values.host === "" ? true : values.host;
|
|
271
|
+
const open2 = values.open ?? false;
|
|
272
|
+
const server2 = await (0, import_vite.preview)({
|
|
273
|
+
root,
|
|
274
|
+
configFile: false,
|
|
275
|
+
build: { outDir },
|
|
276
|
+
preview: { port: port2, host: host2, open: open2 }
|
|
277
|
+
});
|
|
278
|
+
console.log();
|
|
279
|
+
console.log(` ${import_picocolors.default.bold(import_picocolors.default.cyan("windo"))} ${import_picocolors.default.dim(`v${VERSION}`)} ${import_picocolors.default.dim("preview")}`);
|
|
280
|
+
console.log();
|
|
281
|
+
server2.printUrls();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const port = values.port === void 0 ? void 0 : Number(values.port);
|
|
285
|
+
const host = values.host === "" ? true : values.host;
|
|
286
|
+
const open = values.open ?? false;
|
|
287
|
+
const server = await (0, import_vite.createServer)({
|
|
288
|
+
root,
|
|
289
|
+
plugins: [windoPlugin({ config })],
|
|
290
|
+
server: { port, host, open }
|
|
291
|
+
});
|
|
292
|
+
await server.listen();
|
|
293
|
+
console.log();
|
|
294
|
+
console.log(` ${import_picocolors.default.bold(import_picocolors.default.cyan("windo"))} ${import_picocolors.default.dim(`v${VERSION}`)}`);
|
|
295
|
+
console.log();
|
|
296
|
+
server.printUrls();
|
|
297
|
+
}
|
|
298
|
+
main().catch((err) => {
|
|
299
|
+
process.exitCode = 1;
|
|
300
|
+
console.error(import_picocolors.default.red("windo: command failed."));
|
|
301
|
+
console.error(err);
|
|
302
|
+
});
|
|
303
|
+
//# sourceMappingURL=cli.cjs.map
|