@westopp/windo 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-5RM2VYAM.js → chunk-IBJ6MG77.js} +2 -1
- package/dist/chunk-IBJ6MG77.js.map +1 -0
- package/dist/cli.cjs +1 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs +1 -0
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +1 -1
- package/src/client/App.tsx +18 -1
- package/src/client/bridge.ts +3 -0
- package/src/client/internal-types.ts +2 -0
- package/src/plugin/index.ts +1 -0
- package/src/preview/index.ts +1 -0
- package/src/protocol.ts +2 -0
- package/src/types.ts +2 -0
- package/dist/chunk-5RM2VYAM.js.map +0 -1
|
@@ -24,6 +24,7 @@ var CHROME_HTML = `<!doctype html>
|
|
|
24
24
|
<meta charset="utf-8" />
|
|
25
25
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
26
26
|
<title>windo</title>
|
|
27
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E" />
|
|
27
28
|
</head>
|
|
28
29
|
<body>
|
|
29
30
|
<div id="root"></div>
|
|
@@ -147,4 +148,4 @@ export {
|
|
|
147
148
|
windoPlugin,
|
|
148
149
|
plugin_default
|
|
149
150
|
};
|
|
150
|
-
//# sourceMappingURL=chunk-
|
|
151
|
+
//# sourceMappingURL=chunk-IBJ6MG77.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 <link rel=\"icon\" type=\"image/svg+xml\" href=\"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E\" />\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":";AAKA,SAAS,kBAAkB;AAC3B,SAAS,YAAY,WAAW,mBAAmB;AACnD,OAAO,iBAAiB;AASxB,IAAM,aAAa;AACnB,IAAM,sBAAsB,KAAK,UAAU;AAE3C,IAAM,oBAAoB,CAAC,mBAAmB,oBAAoB,oBAAoB,mBAAmB,kBAAkB;AAE3H,SAAS,WAAW,MAAc,WAAmC;AACnE,MAAI,UAAW,QAAO,WAAW,SAAS,IAAI,YAAY,YAAY,MAAM,SAAS;AACrF,aAAW,aAAa,mBAAmB;AACzC,UAAM,OAAO,YAAY,MAAM,SAAS;AACxC,QAAI,WAAW,IAAI,EAAG,QAAO;AAAA,EAC/B;AACA,SAAO;AACT;AAEA,SAAS,OAAO,SAAqC;AACnD,QAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,QAAQ,CAAC,IAAI;AACpD,QAAM,UAAU,SAAS;AACzB,SAAO,QAAQ,WAAW,GAAG,IAAI,UAAU,IAAI,OAAO;AACxD;AAEA,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBpB,SAAS,QAAQ,MAAc;AAC7B,SAAO;AAAA,IACL,OAAO,YAAY,MAAM,YAAY;AAAA,IACrC,QAAQ,YAAY,MAAM,qBAAqB;AAAA,EACjD;AACF;AAEO,SAAS,MAAM,UAA8B,CAAC,GAAmB;AACtE,M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B,qBAAe,SAAS;AACxB,YAAM,QAAQ,YAAY;AAAA,IAC5B;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,WAAY,QAAO;AAC9B,UAAI,OAAO,IAAI,SAAS,OAAO,IAAI,OAAQ,QAAO;AAClD,aAAO;AAAA,IACT;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,oBAAqB,QAAO,eAAe;AACtD,UAAI,OAAO,IAAI,MAAO,QAAO;AAC7B,UAAI,OAAO,IAAI,OAAQ,QAAO;AAC9B,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,QAAuB;AACrC,aAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;AAC/C,YAAI,IAAI,WAAW,MAAO,QAAO,KAAK;AACtC,cAAM,OAAO,IAAI,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC;AACxC,YAAI,OAAsB;AAC1B,YAAI,QAAQ,OAAO,QAAQ,cAAe,QAAO;AAAA,iBACxC,IAAI,WAAW,iBAAiB,EAAG,QAAO;AACnD,YAAI,SAAS,KAAM,QAAO,KAAK;AAC/B,YAAI;AACF,gBAAM,cAAc,MAAM,OAAO,mBAAmB,KAAK,IAAI;AAC7D,cAAI,aAAa;AACjB,cAAI,UAAU,gBAAgB,WAAW;AACzC,cAAI,IAAI,WAAW;AAAA,QACrB,SAAS,KAAK;AACZ,eAAK,GAAG;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,CAAC,YAAY,GAAG,MAAM;AAC/B;AAEO,IAAM,cAAc;AAE3B,IAAO,iBAAQ;","names":[]}
|
package/dist/cli.cjs
CHANGED
|
@@ -54,6 +54,7 @@ var CHROME_HTML = `<!doctype html>
|
|
|
54
54
|
<meta charset="utf-8" />
|
|
55
55
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
56
56
|
<title>windo</title>
|
|
57
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E" />
|
|
57
58
|
</head>
|
|
58
59
|
<body>
|
|
59
60
|
<div id="root"></div>
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/index.ts","../src/plugin/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// The package bin. `windo [command] [root] [options]`:\n// dev boot a Vite dev server wired with the windo plugin (default)\n// build emit a static canvas to windo-static/ (drop on any static host)\n// preview serve a built canvas locally\n\nimport { parseArgs } from 'node:util'\nimport pc from 'picocolors'\nimport { build, createServer, preview } from 'vite'\nimport { windoPlugin } from '../plugin'\n\nconst VERSION = '0.1.2'\n\nconst USAGE = `\n${pc.bold('windo')} ${pc.dim(`v${VERSION}`)} — zero-infra component canvas\n\n${pc.bold('Usage')}\n windo [command] [root] [options]\n\n${pc.bold('Commands')}\n dev Start the dev server (default)\n build Emit a static canvas to windo-static/\n preview Serve a built canvas locally\n\n${pc.bold('Options')}\n -p, --port <n> Port to listen on (dev, preview)\n --host [host] Expose on the network (dev, preview)\n -o, --open Open the workbench in the browser (dev, preview)\n -c, --config <p> Path to windo.config.ts (dev, build)\n -d, --outDir <p> Output directory (build, preview) ${pc.dim('[windo-static]')}\n -b, --base <p> Public base path for the build ${pc.dim('[./]')}\n -h, --help Show this help\n`\n\nconst COMMANDS = new Set(['dev', 'build', 'preview'])\n\nasync function main() {\n const argv = process.argv.slice(2)\n const first = argv[0]\n\n if (first === '-h' || first === '--help') {\n console.log(USAGE)\n return\n }\n\n // A leading token that names a command selects it; no token (or a flag)\n // defaults to `dev`. Any other leading token is a mistyped command — fail\n // loudly rather than silently treating it as a dev root.\n let command = 'dev'\n let rest = argv\n if (first !== undefined && !first.startsWith('-')) {\n if (!COMMANDS.has(first)) {\n console.error(`${pc.red(`windo: unknown command \"${first}\".`)}\\n${USAGE}`)\n process.exitCode = 1\n return\n }\n command = first\n rest = argv.slice(1)\n }\n\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n port: { type: 'string', short: 'p' },\n host: { type: 'string' },\n open: { type: 'boolean', short: 'o' },\n config: { type: 'string', short: 'c' },\n outDir: { type: 'string', short: 'd' },\n base: { type: 'string', short: 'b' },\n help: { type: 'boolean', short: 'h' },\n },\n })\n\n if (values.help) {\n console.log(USAGE)\n return\n }\n\n // Each command accepts only its own flags; reject the rest so a misplaced\n // `windo build --port` fails instead of silently doing nothing.\n const ALLOWED: Record<string, Set<string>> = {\n dev: new Set(['port', 'host', 'open', 'config', 'help']),\n build: new Set(['config', 'outDir', 'base', 'help']),\n preview: new Set(['port', 'host', 'open', 'outDir', 'help']),\n }\n const stray = Object.keys(values).filter(k => !ALLOWED[command].has(k))\n if (stray.length > 0) {\n console.error(`${pc.red(`windo ${command}: unsupported option${stray.length > 1 ? 's' : ''} ${stray.map(s => `--${s}`).join(', ')}.`)}\\n${USAGE}`)\n process.exitCode = 1\n return\n }\n\n const root = positionals[0] ? String(positionals[0]) : process.cwd()\n const config = values.config\n\n if (command === 'build') {\n const outDir = values.outDir ?? 'windo-static'\n const base = values.base ?? './'\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)} ${pc.dim('build')}`)\n console.log()\n await build({\n root,\n base,\n // Self-contained: don't merge an unrelated vite.config from the project.\n configFile: false,\n plugins: [windoPlugin({ config })],\n build: { outDir, emptyOutDir: true },\n })\n console.log()\n console.log(` ${pc.green('✓')} canvas written to ${pc.cyan(outDir)}`)\n console.log(` ${pc.dim('preview it with')} ${pc.bold('windo preview')}${outDir === 'windo-static' ? '' : ` -d ${outDir}`}`)\n console.log()\n return\n }\n\n if (command === 'preview') {\n const outDir = values.outDir ?? 'windo-static'\n const port = values.port === undefined ? undefined : Number(values.port)\n const host = values.host === '' ? true : values.host\n const open = values.open ?? false\n const server = await preview({\n root,\n configFile: false,\n build: { outDir },\n preview: { port, host, open },\n })\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)} ${pc.dim('preview')}`)\n console.log()\n server.printUrls()\n return\n }\n\n // dev\n const port = values.port === undefined ? undefined : Number(values.port)\n const host = values.host === '' ? true : values.host\n const open = values.open ?? false\n\n const server = await createServer({\n root,\n plugins: [windoPlugin({ config })],\n server: { port, host, open },\n })\n\n await server.listen()\n\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)}`)\n console.log()\n server.printUrls()\n}\n\nmain().catch(err => {\n process.exitCode = 1\n console.error(pc.red('windo: command failed.'))\n console.error(err)\n})\n","// 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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,uBAA0B;AAC1B,wBAAe;AACf,kBAA6C;;;ACJ7C,qBAA2B;AAC3B,uBAAmD;AACnD,0BAAwB;AASxB,IAAM,aAAa;AACnB,IAAM,sBAAsB,KAAK,UAAU;AAE3C,IAAM,oBAAoB,CAAC,mBAAmB,oBAAoB,oBAAoB,mBAAmB,kBAAkB;AAE3H,SAAS,WAAW,MAAc,WAAmC;AACnE,MAAI,UAAW,YAAO,6BAAW,SAAS,IAAI,gBAAY,iBAAAA,SAAY,MAAM,SAAS;AACrF,aAAW,aAAa,mBAAmB;AACzC,UAAM,WAAO,iBAAAA,SAAY,MAAM,SAAS;AACxC,YAAI,2BAAW,IAAI,EAAG,QAAO;AAAA,EAC/B;AACA,SAAO;AACT;AAEA,SAAS,OAAO,SAAqC;AACnD,QAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,QAAQ,CAAC,IAAI;AACpD,QAAM,UAAU,SAAS;AACzB,SAAO,QAAQ,WAAW,GAAG,IAAI,UAAU,IAAI,OAAO;AACxD;AAEA,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBpB,SAAS,QAAQ,MAAc;AAC7B,SAAO;AAAA,IACL,WAAO,iBAAAA,SAAY,MAA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SAAS,UAAM,0BAAa;AAAA,IAChC;AAAA,IACA,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAAA,IACjC,QAAQ,EAAE,MAAM,MAAM,KAAK;AAAA,EAC7B,CAAC;AAED,QAAM,OAAO,OAAO;AAEpB,UAAQ,IAAI;AACZ,UAAQ,IAAI,KAAK,kBAAAJ,QAAG,KAAK,kBAAAA,QAAG,KAAK,OAAO,CAAC,CAAC,IAAI,kBAAAA,QAAG,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE;AACrE,UAAQ,IAAI;AACZ,SAAO,UAAU;AACnB;AAEA,KAAK,EAAE,MAAM,SAAO;AAClB,UAAQ,WAAW;AACnB,UAAQ,MAAM,kBAAAA,QAAG,IAAI,wBAAwB,CAAC;AAC9C,UAAQ,MAAM,GAAG;AACnB,CAAC;","names":["resolvePath","reactPlugin","pc","port","host","open","server"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli/index.ts","../src/plugin/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// The package bin. `windo [command] [root] [options]`:\n// dev boot a Vite dev server wired with the windo plugin (default)\n// build emit a static canvas to windo-static/ (drop on any static host)\n// preview serve a built canvas locally\n\nimport { parseArgs } from 'node:util'\nimport pc from 'picocolors'\nimport { build, createServer, preview } from 'vite'\nimport { windoPlugin } from '../plugin'\n\nconst VERSION = '0.1.2'\n\nconst USAGE = `\n${pc.bold('windo')} ${pc.dim(`v${VERSION}`)} — zero-infra component canvas\n\n${pc.bold('Usage')}\n windo [command] [root] [options]\n\n${pc.bold('Commands')}\n dev Start the dev server (default)\n build Emit a static canvas to windo-static/\n preview Serve a built canvas locally\n\n${pc.bold('Options')}\n -p, --port <n> Port to listen on (dev, preview)\n --host [host] Expose on the network (dev, preview)\n -o, --open Open the workbench in the browser (dev, preview)\n -c, --config <p> Path to windo.config.ts (dev, build)\n -d, --outDir <p> Output directory (build, preview) ${pc.dim('[windo-static]')}\n -b, --base <p> Public base path for the build ${pc.dim('[./]')}\n -h, --help Show this help\n`\n\nconst COMMANDS = new Set(['dev', 'build', 'preview'])\n\nasync function main() {\n const argv = process.argv.slice(2)\n const first = argv[0]\n\n if (first === '-h' || first === '--help') {\n console.log(USAGE)\n return\n }\n\n // A leading token that names a command selects it; no token (or a flag)\n // defaults to `dev`. Any other leading token is a mistyped command — fail\n // loudly rather than silently treating it as a dev root.\n let command = 'dev'\n let rest = argv\n if (first !== undefined && !first.startsWith('-')) {\n if (!COMMANDS.has(first)) {\n console.error(`${pc.red(`windo: unknown command \"${first}\".`)}\\n${USAGE}`)\n process.exitCode = 1\n return\n }\n command = first\n rest = argv.slice(1)\n }\n\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n port: { type: 'string', short: 'p' },\n host: { type: 'string' },\n open: { type: 'boolean', short: 'o' },\n config: { type: 'string', short: 'c' },\n outDir: { type: 'string', short: 'd' },\n base: { type: 'string', short: 'b' },\n help: { type: 'boolean', short: 'h' },\n },\n })\n\n if (values.help) {\n console.log(USAGE)\n return\n }\n\n // Each command accepts only its own flags; reject the rest so a misplaced\n // `windo build --port` fails instead of silently doing nothing.\n const ALLOWED: Record<string, Set<string>> = {\n dev: new Set(['port', 'host', 'open', 'config', 'help']),\n build: new Set(['config', 'outDir', 'base', 'help']),\n preview: new Set(['port', 'host', 'open', 'outDir', 'help']),\n }\n const stray = Object.keys(values).filter(k => !ALLOWED[command].has(k))\n if (stray.length > 0) {\n console.error(`${pc.red(`windo ${command}: unsupported option${stray.length > 1 ? 's' : ''} ${stray.map(s => `--${s}`).join(', ')}.`)}\\n${USAGE}`)\n process.exitCode = 1\n return\n }\n\n const root = positionals[0] ? String(positionals[0]) : process.cwd()\n const config = values.config\n\n if (command === 'build') {\n const outDir = values.outDir ?? 'windo-static'\n const base = values.base ?? './'\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)} ${pc.dim('build')}`)\n console.log()\n await build({\n root,\n base,\n // Self-contained: don't merge an unrelated vite.config from the project.\n configFile: false,\n plugins: [windoPlugin({ config })],\n build: { outDir, emptyOutDir: true },\n })\n console.log()\n console.log(` ${pc.green('✓')} canvas written to ${pc.cyan(outDir)}`)\n console.log(` ${pc.dim('preview it with')} ${pc.bold('windo preview')}${outDir === 'windo-static' ? '' : ` -d ${outDir}`}`)\n console.log()\n return\n }\n\n if (command === 'preview') {\n const outDir = values.outDir ?? 'windo-static'\n const port = values.port === undefined ? undefined : Number(values.port)\n const host = values.host === '' ? true : values.host\n const open = values.open ?? false\n const server = await preview({\n root,\n configFile: false,\n build: { outDir },\n preview: { port, host, open },\n })\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)} ${pc.dim('preview')}`)\n console.log()\n server.printUrls()\n return\n }\n\n // dev\n const port = values.port === undefined ? undefined : Number(values.port)\n const host = values.host === '' ? true : values.host\n const open = values.open ?? false\n\n const server = await createServer({\n root,\n plugins: [windoPlugin({ config })],\n server: { port, host, open },\n })\n\n await server.listen()\n\n console.log()\n console.log(` ${pc.bold(pc.cyan('windo'))} ${pc.dim(`v${VERSION}`)}`)\n console.log()\n server.printUrls()\n}\n\nmain().catch(err => {\n process.exitCode = 1\n console.error(pc.red('windo: command failed.'))\n console.error(err)\n})\n","// 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 <link rel=\"icon\" type=\"image/svg+xml\" href=\"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E\" />\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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,uBAA0B;AAC1B,wBAAe;AACf,kBAA6C;;;ACJ7C,qBAA2B;AAC3B,uBAAmD;AACnD,0BAAwB;AASxB,IAAM,aAAa;AACnB,IAAM,sBAAsB,KAAK,UAAU;AAE3C,IAAM,oBAAoB,CAAC,mBAAmB,oBAAoB,oBAAoB,mBAAmB,kBAAkB;AAE3H,SAAS,WAAW,MAAc,WAAmC;AACnE,MAAI,UAAW,YAAO,6BAAW,SAAS,IAAI,gBAAY,iBAAAA,SAAY,MAAM,SAAS;AACrF,aAAW,aAAa,mBAAmB;AACzC,UAAM,WAAO,iBAAAA,SAAY,MAAM,SA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;AAAA,MACZ,OAAO,EAAE,OAAO;AAAA,MAChB,SAAS,EAAE,MAAAH,OAAM,MAAAC,OAAM,MAAAC,MAAK;AAAA,IAC9B,CAAC;AACD,YAAQ,IAAI;AACZ,YAAQ,IAAI,KAAK,kBAAAH,QAAG,KAAK,kBAAAA,QAAG,KAAK,OAAO,CAAC,CAAC,IAAI,kBAAAA,QAAG,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,kBAAAA,QAAG,IAAI,SAAS,CAAC,EAAE;AAC1F,YAAQ,IAAI;AACZ,IAAAI,QAAO,UAAU;AACjB;AAAA,EACF;AAGA,QAAM,OAAO,OAAO,SAAS,SAAY,SAAY,OAAO,OAAO,IAAI;AACvE,QAAM,OAAO,OAAO,SAAS,KAAK,OAAO,OAAO;AAChD,QAAM,OAAO,OAAO,QAAQ;AAE5B,QAAM,SAAS,UAAM,0BAAa;AAAA,IAChC;AAAA,IACA,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAAA,IACjC,QAAQ,EAAE,MAAM,MAAM,KAAK;AAAA,EAC7B,CAAC;AAED,QAAM,OAAO,OAAO;AAEpB,UAAQ,IAAI;AACZ,UAAQ,IAAI,KAAK,kBAAAJ,QAAG,KAAK,kBAAAA,QAAG,KAAK,OAAO,CAAC,CAAC,IAAI,kBAAAA,QAAG,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE;AACrE,UAAQ,IAAI;AACZ,SAAO,UAAU;AACnB;AAEA,KAAK,EAAE,MAAM,SAAO;AAClB,UAAQ,WAAW;AACnB,UAAQ,MAAM,kBAAAA,QAAG,IAAI,wBAAwB,CAAC;AAC9C,UAAQ,MAAM,GAAG;AACnB,CAAC;","names":["resolvePath","reactPlugin","pc","port","host","open","server"]}
|
package/dist/cli.js
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/define-config.ts","../src/descriptor.ts","../src/protocol.ts","../src/types.ts"],"sourcesContent":["// Public authoring API. This is the isomorphic entry point users import from\n// their `*.windo.tsx` and `windo.config.ts` files. No DOM or Node code lives\n// here — the chrome (`/client`), preview (`/preview`), plugin (`/plugin`), and\n// CLI (`bin`) are separate entry points.\n\nexport type { DefineWindoConfigResult } from './define-config'\nexport { configurableProps, defineContext, defineWindoConfig } from './define-config'\nexport { describeSchema } from './descriptor'\nexport type { WindoHostMessage, WindoMessage, WindoPreviewMessage } from './protocol'\nexport {\n isHostMessage,\n isPreviewMessage,\n isWindoMessage,\n WINDO_MSG,\n} from './protocol'\nexport type {\n Ctxual,\n WindoAction,\n WindoActionMeta,\n WindoActionTrigger,\n WindoConfig,\n WindoContextControlMeta,\n WindoContextDefinition,\n WindoContextMap,\n WindoContextMeta,\n WindoControlDescriptor,\n WindoControlKind,\n WindoControlMap,\n WindoControlSpec,\n WindoControlType,\n WindoControlValues,\n WindoDefaultProps,\n WindoDefinition,\n WindoEnvState,\n WindoFactoryArg,\n WindoFieldError,\n WindoGroup,\n WindoInitContext,\n WindoLogEntry,\n WindoLogger,\n WindoManifestEntry,\n WindoModule,\n WindoPlacement,\n WindoPropDoc,\n WindoRenderContext,\n WindoSchemaDescriptor,\n WindoStatus,\n WindoVariant,\n WindoVariantMeta,\n WindoViewport,\n} from './types'\nexport {\n WINDO_ACTION_TRIGGERS,\n WINDO_PLACEMENTS,\n WINDO_STATUSES,\n} from './types'\n","// The authoring API. `defineWindoConfig` is the single entry point: it captures\n// the project's groups + contexts and hands back a `windo` factory whose `group`\n// field is type-checked against the configured slugs.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\nimport type { WindoConfig, WindoContextDefinition, WindoContextMap, WindoControlMap, WindoControlValues, WindoDefinition, WindoFactoryArg, WindoGroup, WindoModule, WindoRenderContext } from './types'\n\nexport interface DefineWindoConfigResult<Groups extends readonly WindoGroup[], Tags extends readonly string[], Contexts extends WindoContextMap> {\n config: WindoConfig<Groups, Contexts, Tags>\n windo: <Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ) => WindoModule<Props, State>\n}\n\nexport function defineWindoConfig<const Groups extends readonly WindoGroup[], const Tags extends readonly string[] = readonly [], Contexts extends WindoContextMap = Record<string, never>>(\n config: WindoConfig<Groups, Contexts, Tags>\n): DefineWindoConfigResult<Groups, Tags, Contexts> {\n function windo<Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ): WindoModule<Props, State> {\n return {\n __windo: true,\n resolve: w => factory(w as unknown as WindoFactoryArg<Groups, Contexts, Tags>),\n }\n }\n return { config, windo }\n}\n\n/**\n * Define a named context. A context can contribute ambient `controls` (values +\n * UI), a `provider` (mounted inside the iframe for components that opt in via\n * `uses`), or both.\n *\n * No cast: `def` is already structurally a `WindoContextDefinition<WindoControlValues<C>,\n * Provided>` (only `controls` widens, covariantly). The unavoidable variance — TS has\n * no existential type to hold contexts heterogeneous in `C` — is absorbed once, in\n * `WindoContextMap`, not here and not at call sites.\n */\nexport function defineContext<C extends WindoControlMap, Provided = WindoControlValues<C>>(def: {\n label?: string\n description?: string\n controls?: C\n provider?: ComponentType<{ children: ReactNode; values: WindoControlValues<C>; ctx: WindoRenderContext }>\n resolve?: (values: WindoControlValues<C>, ctx: WindoRenderContext) => Provided\n}): WindoContextDefinition<WindoControlValues<C>, Provided> {\n return def\n}\n\n/**\n * Bind a zod schema to a component's props. The generic carries the component's\n * prop type so the schema's output stays a subset of it; the returned schema is\n * the runtime validator + parser (`z.input` is the JSON edit surface, `z.output`\n * is what the component receives).\n */\nexport function configurableProps<P>() {\n return <S extends z.ZodType<Partial<P>>>(schema: S): S => schema\n}\n","// Walk a zod schema into a serialisable descriptor that can cross the iframe\n// boundary and render the Controls/Schema UI. We lean on `z.toJSONSchema` (zod\n// v4) for the input shape (enum options, min/max, optionality), then enrich the\n// kind from the zod node's own type tag — some types (Date, Map, Set) are\n// unrepresentable in JSON Schema and come back as `{}`, but their zod `def.type`\n// is exact. The live schema (with transforms/coerce/refine) stays in the iframe\n// and does the actual parsing — only this descriptor travels.\n\nimport { z } from 'zod'\nimport type { WindoControlDescriptor, WindoControlKind, WindoSchemaDescriptor } from './types'\n\ninterface JsonNode {\n type?: string | string[]\n enum?: unknown[]\n const?: unknown\n format?: string\n properties?: Record<string, JsonNode>\n required?: string[]\n items?: JsonNode\n anyOf?: JsonNode[]\n oneOf?: JsonNode[]\n allOf?: JsonNode[]\n minimum?: number\n maximum?: number\n description?: string\n}\n\nexport function describeSchema(schema: z.ZodType | undefined | null): WindoSchemaDescriptor {\n if (!schema) return { fields: [] }\n let json: JsonNode\n try {\n json = z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) as JsonNode\n } catch {\n return { fields: [] }\n }\n const root = unwrap(json)\n const properties = root.properties ?? {}\n const required = new Set(root.required ?? [])\n const zodKinds = shapeKinds(schema)\n const fields: WindoControlDescriptor[] = Object.keys(properties).map(key => fieldFrom(key, properties[key], required.has(key), zodKinds[key]))\n return { fields }\n}\n\n// JSON Schema often wraps the object in anyOf (for optional/nullable). Find the\n// node that actually carries the object's properties.\nfunction unwrap(node: JsonNode): JsonNode {\n if (node.properties) return node\n const branches = node.anyOf ?? node.oneOf ?? node.allOf\n if (branches) {\n const withProps = branches.find(b => b.properties)\n if (withProps) return withProps\n }\n return node\n}\n\nfunction fieldFrom(key: string, node: JsonNode, isRequired: boolean, zodKind?: WindoControlKind): WindoControlDescriptor {\n const inner = collapseNullable(node)\n let kind = kindOf(inner)\n // The zod tag wins for types JSON Schema can't express (date/array/object that\n // came back as {}), and as a fallback whenever the JSON kind is unknown.\n if (zodKind && (kind === 'unknown' || zodKind === 'date')) kind = zodKind\n const descriptor: WindoControlDescriptor = {\n key,\n kind,\n optional: !isRequired || isNullable(node),\n }\n if (inner.description) descriptor.description = inner.description\n const options = enumOptions(inner)\n if (options) descriptor.options = options\n if (typeof inner.minimum === 'number') descriptor.min = inner.minimum\n if (typeof inner.maximum === 'number') descriptor.max = inner.maximum\n return descriptor\n}\n\nfunction isNullable(node: JsonNode): boolean {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return false\n return branches.some(b => b.type === 'null')\n}\n\n// Strip a `{ anyOf: [T, null] }` wrapper down to T.\nfunction collapseNullable(node: JsonNode): JsonNode {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return node\n const nonNull = branches.filter(b => b.type !== 'null')\n if (nonNull.length === 1) return nonNull[0]\n return node\n}\n\nfunction enumOptions(node: JsonNode): string[] | undefined {\n if (Array.isArray(node.enum)) return node.enum.map(v => String(v))\n const branches = node.anyOf ?? node.oneOf\n if (branches?.every(b => b.const !== undefined)) {\n return branches.map(b => String(b.const))\n }\n return undefined\n}\n\nfunction kindOf(node: JsonNode): WindoControlKind {\n if (Array.isArray(node.enum) || (node.anyOf?.every(b => b.const !== undefined) ?? false)) return 'enum'\n if (node.format === 'date-time' || node.format === 'date') return 'date'\n const type = Array.isArray(node.type) ? node.type.find(t => t !== 'null') : node.type\n switch (type) {\n case 'string':\n return 'string'\n case 'number':\n case 'integer':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n default:\n return 'unknown'\n }\n}\n\n/* ------------------------------------------------------------------ *\n * zod node introspection (the kind source of truth for unrepresentable types)\n * ------------------------------------------------------------------ */\n\ninterface ZodDefLike {\n type?: string\n innerType?: unknown\n}\n\nfunction zodDef(node: unknown): ZodDefLike | undefined {\n const n = node as { def?: ZodDefLike; _zod?: { def?: ZodDefLike } } | null\n if (!n || typeof n !== 'object') return undefined\n return n.def ?? n._zod?.def\n}\n\nconst ZOD_WRAPPERS = new Set(['optional', 'nullable', 'default', 'prefault', 'catch', 'readonly', 'nonoptional', 'lazy'])\n\n// Unwrap optional/nullable/default/... down to the meaningful inner node.\nfunction unwrapZodDef(node: unknown): ZodDefLike | undefined {\n let def = zodDef(node)\n let guard = 0\n while (def && def.innerType && ZOD_WRAPPERS.has(def.type ?? '') && guard++ < 16) {\n def = zodDef(def.innerType)\n }\n return def\n}\n\nfunction mapZodType(type: string | undefined): WindoControlKind | undefined {\n switch (type) {\n case 'date':\n return 'date'\n case 'string':\n return 'string'\n case 'number':\n case 'int':\n case 'bigint':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n case 'set':\n case 'tuple':\n return 'array'\n case 'object':\n case 'record':\n case 'map':\n return 'object'\n case 'enum':\n case 'literal':\n return 'enum'\n default:\n return undefined\n }\n}\n\n// Per-field kind read straight from the zod object's shape.\nfunction shapeKinds(schema: z.ZodType): Record<string, WindoControlKind> {\n const shape = (schema as { shape?: Record<string, unknown> }).shape\n if (!shape || typeof shape !== 'object') return {}\n const out: Record<string, WindoControlKind> = {}\n for (const key of Object.keys(shape)) {\n const kind = mapZodType(unwrapZodDef(shape[key])?.type)\n if (kind) out[key] = kind\n }\n return out\n}\n","// The chrome <-> iframe postMessage contract. The schema itself never crosses\n// the boundary: the iframe walks it into a serialisable descriptor, the chrome\n// sends candidate JSON down, the iframe parses and reports back. Every payload\n// here is plain JSON.\n\nimport type { WindoContextMeta, WindoEnvState, WindoFieldError, WindoGroup, WindoLogEntry, WindoManifestEntry, WindoPropDoc, WindoSchemaDescriptor, WindoVariantMeta } from './types'\n\nexport const WINDO_MSG = 'windo'\n\n/** chrome -> iframe */\nexport type WindoHostMessage =\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'request-manifest' }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'select'; id: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-props'; id: string; json: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-env'; env: WindoEnvState }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'invoke-action'; id: string; actionId: string }\n\n/** iframe -> chrome */\nexport type WindoPreviewMessage =\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ready' }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'manifest'\n title: string\n entries: WindoManifestEntry[]\n groups: WindoGroup[]\n tags: string[]\n contexts: WindoContextMeta[]\n /** Initial shared state from the config — seeds the chrome's editable strip. */\n ctxState: Record<string, unknown>\n }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'describe'\n id: string\n descriptor: WindoSchemaDescriptor\n props: WindoPropDoc[]\n variants: WindoVariantMeta[]\n defaults: unknown\n code: string | null\n }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-ok'; id: string }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-error'; id: string; errors: WindoFieldError[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'log'; entry: WindoLogEntry }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'state'; id: string; state: Record<string, unknown>; actions: { id: string; disabled: boolean }[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'color-scheme'; colorScheme: 'light' | 'dark' }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'render-error'; id: string; message: string; stack?: string }\n\nexport type WindoMessage = WindoHostMessage | WindoPreviewMessage\n\nexport function isWindoMessage(data: unknown): data is WindoMessage {\n return typeof data === 'object' && data !== null && (data as { source?: unknown }).source === WINDO_MSG\n}\n\nexport function isHostMessage(msg: WindoMessage): msg is WindoHostMessage {\n return msg.dir === 'host'\n}\n\nexport function isPreviewMessage(msg: WindoMessage): msg is WindoPreviewMessage {\n return msg.dir === 'preview'\n}\n","// Core type system for windo. Everything — the authoring API, the iframe\n// preview runtime, the chrome UI, and the postMessage protocol — is typed\n// against the contracts in this file.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\n\n/* ------------------------------------------------------------------ *\n * Primitives\n * ------------------------------------------------------------------ */\n\nexport type WindoStatus = 'stable' | 'beta' | 'deprecated'\n\nexport const WINDO_STATUSES: readonly WindoStatus[] = ['stable', 'beta', 'deprecated']\n\n/** Anchor a component within the canvas frame. */\nexport type WindoPlacementBase = 'center' | 'fill' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\n/**\n * Where a component renders inside the canvas frame. Placements render flush by\n * default; append `-padding` to inset the component from the frame edges\n * (e.g. `top` sits flush at the top, `top-padding` adds breathing room).\n */\nexport type WindoPlacement = WindoPlacementBase | `${WindoPlacementBase}-padding`\n\nconst WINDO_PLACEMENT_BASE: readonly WindoPlacementBase[] = ['center', 'fill', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right']\n\nexport const WINDO_PLACEMENTS: readonly WindoPlacement[] = [...WINDO_PLACEMENT_BASE, ...WINDO_PLACEMENT_BASE.map(p => `${p}-padding` as WindoPlacement)]\n\n/** A configured group. Components reference a group by its `slug`. */\nexport interface WindoGroup {\n name: string\n slug: string\n description?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context system\n * ------------------------------------------------------------------ */\n\nexport type WindoControlType = 'enum' | 'boolean' | 'string' | 'number'\n\n/** A single ambient control: a value plus the metadata to render its toggle. */\nexport interface WindoControlSpec<T = unknown> {\n type: WindoControlType\n label?: string\n default: T\n options?: readonly string[]\n min?: number\n max?: number\n step?: number\n}\n\nexport type WindoControlMap = Record<string, WindoControlSpec>\n\n/** Resolve a control map to the value object it produces. */\nexport type WindoControlValues<C extends WindoControlMap> = {\n [K in keyof C]: C[K] extends WindoControlSpec<infer T> ? T : never\n}\n\n/**\n * A named context. Two capabilities, either or both:\n * - `controls` → ambient values + UI toggles (free, no opt-in needed)\n * - `provider` → a React wrapper, mounted inside the iframe around components\n * that opt in via `uses`\n */\nexport interface WindoContextDefinition<Values = unknown, Provided = Values> {\n label?: string\n description?: string\n controls?: WindoControlMap\n provider?: ComponentType<{ children: ReactNode; values: Values; ctx: WindoRenderContext }>\n /** Derive the value exposed on `ctx.contexts[name]`. Defaults to the control values. */\n resolve?: (values: Values, ctx: WindoRenderContext) => Provided\n}\n\n// Contexts are each generic over a different control map `C`; TS has no existential\n// to hold `exists C. WindoContextDefinition<WindoControlValues<C>>`. `Values` sits in\n// contravariant positions (provider props, resolve arg) so no precise common supertype\n// exists — `any` is the single, contained variance hatch for this heterogeneous\n// registry. Mirrors WindoModule. Definition sites stay precise; this only erases at the\n// point of collection.\n// biome-ignore lint/suspicious/noExplicitAny: existential variance hatch for the heterogeneous context registry\nexport type WindoContextMap = Record<string, WindoContextDefinition<any, any>>\n\n/* ------------------------------------------------------------------ *\n * Render-time context\n * ------------------------------------------------------------------ */\n\nexport interface WindoViewport {\n width: number\n height: number\n name: 'mobile' | 'tablet' | 'desktop'\n}\n\n/** Console channel: `ctx.logger.log(…)` posts an entry to the chrome's Console tab. */\nexport interface WindoLogger {\n log: (...args: unknown[]) => void\n}\n\n/** How an action fires. `click` renders a toolbar button; the rest bind to the stage's pointer events. */\nexport type WindoActionTrigger = 'click' | 'enter' | 'exit' | 'hover'\n\nexport const WINDO_ACTION_TRIGGERS: readonly WindoActionTrigger[] = ['click', 'enter', 'exit', 'hover']\n\n/**\n * An out-of-band action that drives a component's state. `click` actions render as\n * toolbar buttons; `enter`/`exit`/`hover` bind to the stage's pointer events. `run`\n * receives the live ctx and an `active` flag — for `hover` it is `true` on\n * pointer-enter and `false` on pointer-leave; for the others it is always `true`.\n */\nexport interface WindoAction<State = unknown> {\n label: string\n /** Defaults to `click`. */\n on?: WindoActionTrigger\n run: (ctx: WindoRenderContext<State>, active: boolean) => void\n /** Greys out a `click` action's toolbar button. Evaluated against the live state. */\n disabled?: (ctx: WindoRenderContext<State>) => boolean\n}\n\n/** Live environment handed to every render-time function inside the iframe. */\nexport interface WindoRenderContext<State = unknown> {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n logger: WindoLogger\n /** Current component-local state, typed by the windo's `State` generic. */\n state: State\n /** Merge a patch into the component-local state and re-render. */\n setState: (patch: Partial<State>) => void\n /** Resolved values of opted-in contexts, keyed by context name. */\n contexts: Record<string, unknown>\n /**\n * Shared, cross-component state seeded from the config's `ctxState`. Unlike\n * `state` (per-windo, reset on selection), this persists across selection and\n * is global: any component can read it and write it via `setCtxState`. Use it\n * to drive providers that wrap every component — e.g. a theme provider toggled\n * from any component on the canvas.\n */\n ctxState: Record<string, unknown>\n /** Merge a patch into the shared `ctxState` and re-render every consumer. */\n setCtxState: (patch: Record<string, unknown>) => void\n /** Set the canvas colour scheme from a component or action. */\n setColorScheme: (scheme: 'light' | 'dark') => void\n /** Flip the canvas colour scheme between light and dark. */\n toggleTheme: () => void\n}\n\n/* ------------------------------------------------------------------ *\n * Authoring API\n * ------------------------------------------------------------------ */\n\n/** A variant: a label plus a partial prop patch. Renders in the gallery and is click-to-apply. */\nexport interface WindoVariant<Props> {\n label: string\n props: Partial<Props>\n}\n\n/** A row in the authored Props documentation table. */\nexport interface WindoPropDoc {\n name: string\n type: string\n default?: string\n desc?: string\n}\n\n/** A value that may be authored statically or as a context-aware `ctx => value` function resolved at render-time. */\nexport type Ctxual<T, State = unknown> = T | ((ctx: WindoRenderContext<State>) => T)\n\n/** The ctx surface available while resolving a windo's initial state — the render-time `state`/`setState` pair is excluded because it does not exist yet. */\nexport type WindoInitContext<State = unknown> = Omit<WindoRenderContext<State>, 'state' | 'setState'>\n\nexport type WindoDefaultProps<Props, State = unknown> = Ctxual<Props, State>\n\n/**\n * The object returned by a `windo(...)` factory.\n *\n * Keystone rule: the surrounding factory runs ONCE (definition-time) for static\n * fields (title, group, schema). Every function field below — `defaultProps`,\n * `actions`, `providers`, `component` — runs at render-time with the live `ctx`.\n * Never close over live values in the static factory body.\n */\nexport interface WindoDefinition<Props = unknown, State = unknown, GroupSlug extends string = string, Tag extends string = string> {\n title: string\n group: GroupSlug\n /** Tags this component carries. Each must be one of the config's declared `tags`. Drives the sidebar's tag filter. */\n tags?: Tag[]\n status?: WindoStatus\n description?: string\n deprecation?: string\n /** Where the component anchors in the canvas frame. Either a static placement or a function resolved with the live `ctx`. */\n placement?: Ctxual<WindoPlacement, State>\n /** Initial component-local state. Its shape is the `State` generic; `ctx.state`/`ctx.setState` derive from it. Either a static value or a function resolved with the init `ctx` (no `state`/`setState`) when the component is selected. */\n state?: State | ((ctx: WindoInitContext<State>) => State)\n /** Out-of-band actions that drive state: toolbar buttons (`click`) and stage pointer triggers (`enter`/`exit`/`hover`). */\n actions?: WindoAction<State>[]\n /** zod schema: validator + parser for the JSON-editable prop subset. `z.output ⊆ Props`. */\n configurableProps?: z.ZodType\n /** Full props incl. functions/JSX. The editor's JSON overrides merge on top. */\n defaultProps: WindoDefaultProps<Props, State>\n /** Names of provider contexts this component opts into. */\n uses?: string[]\n /** Gallery variants. Either a static array or a function resolved with the live `ctx` when the component is selected. */\n variants?: Ctxual<WindoVariant<Props>[], State>\n /** Authored documentation table (not derived from the schema). Either a static array or a function resolved with the live `ctx` when the component is selected. */\n props?: Ctxual<WindoPropDoc[], State>\n /** Optional authored code snippet for the Code tab, resolved with the JSON-editable values and the live `ctx`. */\n code?: (values: Props, ctx: WindoRenderContext<State>) => string\n /** A local provider wrapping just this windo (in addition to `uses`). */\n providers?: ComponentType<{ children: ReactNode; ctx: WindoRenderContext<State> }>\n component: (props: Props, ctx: WindoRenderContext<State>) => ReactNode\n}\n\n/** Argument handed to the `windo(w => ...)` factory. */\nexport interface WindoFactoryArg<Groups extends readonly WindoGroup[], Contexts extends WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups keyed by slug. */\n groups: Record<Groups[number]['slug'], WindoGroup>\n contexts: Contexts\n /** The config's declared tags, in declaration order. */\n tags: Tags\n}\n\n/**\n * The default export of a `*.windo.tsx` file. A branded, lazily-resolved\n * definition — the runtime calls `resolve(w)` with the config-derived factory arg.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance escape hatch for the heterogeneous WindoModule registry\nexport interface WindoModule<Props = any, State = any> {\n readonly __windo: true\n resolve: (w: WindoFactoryArg<readonly WindoGroup[], WindoContextMap>) => WindoDefinition<Props, State>\n}\n\n/* ------------------------------------------------------------------ *\n * Config\n * ------------------------------------------------------------------ */\n\nexport interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup[], Contexts extends WindoContextMap = WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups. A component's `group` must be one of these slugs. */\n groups: Groups\n /** Named contexts available to components. */\n contexts?: Contexts\n /** The set of tags components may be assigned. A component's `tags` must be drawn from this list; the sidebar filters by them. */\n tags?: Tags\n /** Initial shared state exposed on `ctx.ctxState`. Global across every component and persisted across selection — write it from any component via `ctx.setCtxState`. */\n ctxState?: Record<string, unknown>\n /** Glob(s) for discovery, relative to project root. Default `**\\/*.windo.tsx`. */\n include?: string | string[]\n /** Title shown in the workbench chrome. */\n title?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Schema descriptor (crosses the iframe boundary; renders the controls)\n * ------------------------------------------------------------------ */\n\nexport type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown'\n\nexport interface WindoControlDescriptor {\n key: string\n kind: WindoControlKind\n optional: boolean\n options?: string[]\n min?: number\n max?: number\n description?: string\n}\n\nexport interface WindoSchemaDescriptor {\n fields: WindoControlDescriptor[]\n}\n\n/* ------------------------------------------------------------------ *\n * Runtime manifest + protocol payloads\n * ------------------------------------------------------------------ */\n\n/** Serialisable metadata for one action — drives the canvas toolbar. */\nexport interface WindoActionMeta {\n id: string\n label: string\n on: WindoActionTrigger\n}\n\n/** Static, serialisable metadata for one windo — drives the sidebar. */\nexport interface WindoManifestEntry {\n id: string\n title: string\n group: string\n tags: string[]\n status: WindoStatus\n description?: string\n deprecation?: string\n placement: WindoPlacement\n uses: string[]\n hasVariants: boolean\n actions: WindoActionMeta[]\n hasState: boolean\n}\n\nexport interface WindoVariantMeta {\n label: string\n props: Record<string, unknown>\n}\n\n/** Ambient environment pushed from the chrome down into the iframe. */\nexport interface WindoEnvState {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n /** Per-context control values, keyed by context name then control key. */\n contexts: Record<string, Record<string, unknown>>\n}\n\nexport interface WindoLogEntry {\n ts: number\n args: unknown[]\n}\n\nexport interface WindoFieldError {\n path: string\n message: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context metadata (serialisable; drives the chrome's Context panel)\n * ------------------------------------------------------------------ */\n\nexport interface WindoContextControlMeta {\n key: string\n type: WindoControlType\n label?: string\n options?: string[]\n default: unknown\n min?: number\n max?: number\n step?: number\n}\n\nexport interface WindoContextMeta {\n name: string\n label?: string\n description?: string\n /** True when the context contributes controls (ambient values). */\n ambient: boolean\n /** True when the context mounts a provider (opt-in via `uses`). */\n hasProvider: boolean\n controls: WindoContextControlMeta[]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,kBACd,QACiD;AACjD,WAAS,MACP,SAC2B;AAC3B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS,OAAK,QAAQ,CAAuD;AAAA,IAC/E;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,MAAM;AACzB;AAYO,SAAS,cAA2E,KAM/B;AAC1D,SAAO;AACT;AAQO,SAAS,oBAAuB;AACrC,SAAO,CAAkC,WAAiB;AAC5D;;;ACjDA,iBAAkB;AAmBX,SAAS,eAAe,QAA6D;AAC1F,MAAI,CAAC,OAAQ,QAAO,EAAE,QAAQ,CAAC,EAAE;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,aAAE,aAAa,QAAQ,EAAE,IAAI,SAAS,iBAAiB,MAAM,CAAC;AAAA,E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U,QAAQ,SAAS,YAAY,aAAa,eAAe,cAAc;AAEhK,IAAM,mBAA8C,CAAC,GAAG,sBAAsB,GAAG,qBAAqB,IAAI,OAAK,GAAG,CAAC,UAA4B,CAAC;AA2EhJ,IAAM,wBAAuD,CAAC,SAAS,SAAS,QAAQ,OAAO;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/define-config.ts","../src/descriptor.ts","../src/protocol.ts","../src/types.ts"],"sourcesContent":["// Public authoring API. This is the isomorphic entry point users import from\n// their `*.windo.tsx` and `windo.config.ts` files. No DOM or Node code lives\n// here — the chrome (`/client`), preview (`/preview`), plugin (`/plugin`), and\n// CLI (`bin`) are separate entry points.\n\nexport type { DefineWindoConfigResult } from './define-config'\nexport { configurableProps, defineContext, defineWindoConfig } from './define-config'\nexport { describeSchema } from './descriptor'\nexport type { WindoHostMessage, WindoMessage, WindoPreviewMessage } from './protocol'\nexport {\n isHostMessage,\n isPreviewMessage,\n isWindoMessage,\n WINDO_MSG,\n} from './protocol'\nexport type {\n Ctxual,\n WindoAction,\n WindoActionMeta,\n WindoActionTrigger,\n WindoConfig,\n WindoContextControlMeta,\n WindoContextDefinition,\n WindoContextMap,\n WindoContextMeta,\n WindoControlDescriptor,\n WindoControlKind,\n WindoControlMap,\n WindoControlSpec,\n WindoControlType,\n WindoControlValues,\n WindoDefaultProps,\n WindoDefinition,\n WindoEnvState,\n WindoFactoryArg,\n WindoFieldError,\n WindoGroup,\n WindoInitContext,\n WindoLogEntry,\n WindoLogger,\n WindoManifestEntry,\n WindoModule,\n WindoPlacement,\n WindoPropDoc,\n WindoRenderContext,\n WindoSchemaDescriptor,\n WindoStatus,\n WindoVariant,\n WindoVariantMeta,\n WindoViewport,\n} from './types'\nexport {\n WINDO_ACTION_TRIGGERS,\n WINDO_PLACEMENTS,\n WINDO_STATUSES,\n} from './types'\n","// The authoring API. `defineWindoConfig` is the single entry point: it captures\n// the project's groups + contexts and hands back a `windo` factory whose `group`\n// field is type-checked against the configured slugs.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\nimport type { WindoConfig, WindoContextDefinition, WindoContextMap, WindoControlMap, WindoControlValues, WindoDefinition, WindoFactoryArg, WindoGroup, WindoModule, WindoRenderContext } from './types'\n\nexport interface DefineWindoConfigResult<Groups extends readonly WindoGroup[], Tags extends readonly string[], Contexts extends WindoContextMap> {\n config: WindoConfig<Groups, Contexts, Tags>\n windo: <Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ) => WindoModule<Props, State>\n}\n\nexport function defineWindoConfig<const Groups extends readonly WindoGroup[], const Tags extends readonly string[] = readonly [], Contexts extends WindoContextMap = Record<string, never>>(\n config: WindoConfig<Groups, Contexts, Tags>\n): DefineWindoConfigResult<Groups, Tags, Contexts> {\n function windo<Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ): WindoModule<Props, State> {\n return {\n __windo: true,\n resolve: w => factory(w as unknown as WindoFactoryArg<Groups, Contexts, Tags>),\n }\n }\n return { config, windo }\n}\n\n/**\n * Define a named context. A context can contribute ambient `controls` (values +\n * UI), a `provider` (mounted inside the iframe for components that opt in via\n * `uses`), or both.\n *\n * No cast: `def` is already structurally a `WindoContextDefinition<WindoControlValues<C>,\n * Provided>` (only `controls` widens, covariantly). The unavoidable variance — TS has\n * no existential type to hold contexts heterogeneous in `C` — is absorbed once, in\n * `WindoContextMap`, not here and not at call sites.\n */\nexport function defineContext<C extends WindoControlMap, Provided = WindoControlValues<C>>(def: {\n label?: string\n description?: string\n controls?: C\n provider?: ComponentType<{ children: ReactNode; values: WindoControlValues<C>; ctx: WindoRenderContext }>\n resolve?: (values: WindoControlValues<C>, ctx: WindoRenderContext) => Provided\n}): WindoContextDefinition<WindoControlValues<C>, Provided> {\n return def\n}\n\n/**\n * Bind a zod schema to a component's props. The generic carries the component's\n * prop type so the schema's output stays a subset of it; the returned schema is\n * the runtime validator + parser (`z.input` is the JSON edit surface, `z.output`\n * is what the component receives).\n */\nexport function configurableProps<P>() {\n return <S extends z.ZodType<Partial<P>>>(schema: S): S => schema\n}\n","// Walk a zod schema into a serialisable descriptor that can cross the iframe\n// boundary and render the Controls/Schema UI. We lean on `z.toJSONSchema` (zod\n// v4) for the input shape (enum options, min/max, optionality), then enrich the\n// kind from the zod node's own type tag — some types (Date, Map, Set) are\n// unrepresentable in JSON Schema and come back as `{}`, but their zod `def.type`\n// is exact. The live schema (with transforms/coerce/refine) stays in the iframe\n// and does the actual parsing — only this descriptor travels.\n\nimport { z } from 'zod'\nimport type { WindoControlDescriptor, WindoControlKind, WindoSchemaDescriptor } from './types'\n\ninterface JsonNode {\n type?: string | string[]\n enum?: unknown[]\n const?: unknown\n format?: string\n properties?: Record<string, JsonNode>\n required?: string[]\n items?: JsonNode\n anyOf?: JsonNode[]\n oneOf?: JsonNode[]\n allOf?: JsonNode[]\n minimum?: number\n maximum?: number\n description?: string\n}\n\nexport function describeSchema(schema: z.ZodType | undefined | null): WindoSchemaDescriptor {\n if (!schema) return { fields: [] }\n let json: JsonNode\n try {\n json = z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) as JsonNode\n } catch {\n return { fields: [] }\n }\n const root = unwrap(json)\n const properties = root.properties ?? {}\n const required = new Set(root.required ?? [])\n const zodKinds = shapeKinds(schema)\n const fields: WindoControlDescriptor[] = Object.keys(properties).map(key => fieldFrom(key, properties[key], required.has(key), zodKinds[key]))\n return { fields }\n}\n\n// JSON Schema often wraps the object in anyOf (for optional/nullable). Find the\n// node that actually carries the object's properties.\nfunction unwrap(node: JsonNode): JsonNode {\n if (node.properties) return node\n const branches = node.anyOf ?? node.oneOf ?? node.allOf\n if (branches) {\n const withProps = branches.find(b => b.properties)\n if (withProps) return withProps\n }\n return node\n}\n\nfunction fieldFrom(key: string, node: JsonNode, isRequired: boolean, zodKind?: WindoControlKind): WindoControlDescriptor {\n const inner = collapseNullable(node)\n let kind = kindOf(inner)\n // The zod tag wins for types JSON Schema can't express (date/array/object that\n // came back as {}), and as a fallback whenever the JSON kind is unknown.\n if (zodKind && (kind === 'unknown' || zodKind === 'date')) kind = zodKind\n const descriptor: WindoControlDescriptor = {\n key,\n kind,\n optional: !isRequired || isNullable(node),\n }\n if (inner.description) descriptor.description = inner.description\n const options = enumOptions(inner)\n if (options) descriptor.options = options\n if (typeof inner.minimum === 'number') descriptor.min = inner.minimum\n if (typeof inner.maximum === 'number') descriptor.max = inner.maximum\n return descriptor\n}\n\nfunction isNullable(node: JsonNode): boolean {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return false\n return branches.some(b => b.type === 'null')\n}\n\n// Strip a `{ anyOf: [T, null] }` wrapper down to T.\nfunction collapseNullable(node: JsonNode): JsonNode {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return node\n const nonNull = branches.filter(b => b.type !== 'null')\n if (nonNull.length === 1) return nonNull[0]\n return node\n}\n\nfunction enumOptions(node: JsonNode): string[] | undefined {\n if (Array.isArray(node.enum)) return node.enum.map(v => String(v))\n const branches = node.anyOf ?? node.oneOf\n if (branches?.every(b => b.const !== undefined)) {\n return branches.map(b => String(b.const))\n }\n return undefined\n}\n\nfunction kindOf(node: JsonNode): WindoControlKind {\n if (Array.isArray(node.enum) || (node.anyOf?.every(b => b.const !== undefined) ?? false)) return 'enum'\n if (node.format === 'date-time' || node.format === 'date') return 'date'\n const type = Array.isArray(node.type) ? node.type.find(t => t !== 'null') : node.type\n switch (type) {\n case 'string':\n return 'string'\n case 'number':\n case 'integer':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n default:\n return 'unknown'\n }\n}\n\n/* ------------------------------------------------------------------ *\n * zod node introspection (the kind source of truth for unrepresentable types)\n * ------------------------------------------------------------------ */\n\ninterface ZodDefLike {\n type?: string\n innerType?: unknown\n}\n\nfunction zodDef(node: unknown): ZodDefLike | undefined {\n const n = node as { def?: ZodDefLike; _zod?: { def?: ZodDefLike } } | null\n if (!n || typeof n !== 'object') return undefined\n return n.def ?? n._zod?.def\n}\n\nconst ZOD_WRAPPERS = new Set(['optional', 'nullable', 'default', 'prefault', 'catch', 'readonly', 'nonoptional', 'lazy'])\n\n// Unwrap optional/nullable/default/... down to the meaningful inner node.\nfunction unwrapZodDef(node: unknown): ZodDefLike | undefined {\n let def = zodDef(node)\n let guard = 0\n while (def && def.innerType && ZOD_WRAPPERS.has(def.type ?? '') && guard++ < 16) {\n def = zodDef(def.innerType)\n }\n return def\n}\n\nfunction mapZodType(type: string | undefined): WindoControlKind | undefined {\n switch (type) {\n case 'date':\n return 'date'\n case 'string':\n return 'string'\n case 'number':\n case 'int':\n case 'bigint':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n case 'set':\n case 'tuple':\n return 'array'\n case 'object':\n case 'record':\n case 'map':\n return 'object'\n case 'enum':\n case 'literal':\n return 'enum'\n default:\n return undefined\n }\n}\n\n// Per-field kind read straight from the zod object's shape.\nfunction shapeKinds(schema: z.ZodType): Record<string, WindoControlKind> {\n const shape = (schema as { shape?: Record<string, unknown> }).shape\n if (!shape || typeof shape !== 'object') return {}\n const out: Record<string, WindoControlKind> = {}\n for (const key of Object.keys(shape)) {\n const kind = mapZodType(unwrapZodDef(shape[key])?.type)\n if (kind) out[key] = kind\n }\n return out\n}\n","// The chrome <-> iframe postMessage contract. The schema itself never crosses\n// the boundary: the iframe walks it into a serialisable descriptor, the chrome\n// sends candidate JSON down, the iframe parses and reports back. Every payload\n// here is plain JSON.\n\nimport type { WindoContextMeta, WindoEnvState, WindoFieldError, WindoGroup, WindoLogEntry, WindoManifestEntry, WindoPropDoc, WindoSchemaDescriptor, WindoVariantMeta } from './types'\n\nexport const WINDO_MSG = 'windo'\n\n/** chrome -> iframe */\nexport type WindoHostMessage =\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'request-manifest' }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'select'; id: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-props'; id: string; json: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-env'; env: WindoEnvState }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'invoke-action'; id: string; actionId: string }\n\n/** iframe -> chrome */\nexport type WindoPreviewMessage =\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ready' }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'manifest'\n title: string\n /** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */\n faviconUrl: string | null\n entries: WindoManifestEntry[]\n groups: WindoGroup[]\n tags: string[]\n contexts: WindoContextMeta[]\n /** Initial shared state from the config — seeds the chrome's editable strip. */\n ctxState: Record<string, unknown>\n }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'describe'\n id: string\n descriptor: WindoSchemaDescriptor\n props: WindoPropDoc[]\n variants: WindoVariantMeta[]\n defaults: unknown\n code: string | null\n }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-ok'; id: string }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-error'; id: string; errors: WindoFieldError[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'log'; entry: WindoLogEntry }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'state'; id: string; state: Record<string, unknown>; actions: { id: string; disabled: boolean }[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'color-scheme'; colorScheme: 'light' | 'dark' }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'render-error'; id: string; message: string; stack?: string }\n\nexport type WindoMessage = WindoHostMessage | WindoPreviewMessage\n\nexport function isWindoMessage(data: unknown): data is WindoMessage {\n return typeof data === 'object' && data !== null && (data as { source?: unknown }).source === WINDO_MSG\n}\n\nexport function isHostMessage(msg: WindoMessage): msg is WindoHostMessage {\n return msg.dir === 'host'\n}\n\nexport function isPreviewMessage(msg: WindoMessage): msg is WindoPreviewMessage {\n return msg.dir === 'preview'\n}\n","// Core type system for windo. Everything — the authoring API, the iframe\n// preview runtime, the chrome UI, and the postMessage protocol — is typed\n// against the contracts in this file.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\n\n/* ------------------------------------------------------------------ *\n * Primitives\n * ------------------------------------------------------------------ */\n\nexport type WindoStatus = 'stable' | 'beta' | 'deprecated'\n\nexport const WINDO_STATUSES: readonly WindoStatus[] = ['stable', 'beta', 'deprecated']\n\n/** Anchor a component within the canvas frame. */\nexport type WindoPlacementBase = 'center' | 'fill' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\n/**\n * Where a component renders inside the canvas frame. Placements render flush by\n * default; append `-padding` to inset the component from the frame edges\n * (e.g. `top` sits flush at the top, `top-padding` adds breathing room).\n */\nexport type WindoPlacement = WindoPlacementBase | `${WindoPlacementBase}-padding`\n\nconst WINDO_PLACEMENT_BASE: readonly WindoPlacementBase[] = ['center', 'fill', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right']\n\nexport const WINDO_PLACEMENTS: readonly WindoPlacement[] = [...WINDO_PLACEMENT_BASE, ...WINDO_PLACEMENT_BASE.map(p => `${p}-padding` as WindoPlacement)]\n\n/** A configured group. Components reference a group by its `slug`. */\nexport interface WindoGroup {\n name: string\n slug: string\n description?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context system\n * ------------------------------------------------------------------ */\n\nexport type WindoControlType = 'enum' | 'boolean' | 'string' | 'number'\n\n/** A single ambient control: a value plus the metadata to render its toggle. */\nexport interface WindoControlSpec<T = unknown> {\n type: WindoControlType\n label?: string\n default: T\n options?: readonly string[]\n min?: number\n max?: number\n step?: number\n}\n\nexport type WindoControlMap = Record<string, WindoControlSpec>\n\n/** Resolve a control map to the value object it produces. */\nexport type WindoControlValues<C extends WindoControlMap> = {\n [K in keyof C]: C[K] extends WindoControlSpec<infer T> ? T : never\n}\n\n/**\n * A named context. Two capabilities, either or both:\n * - `controls` → ambient values + UI toggles (free, no opt-in needed)\n * - `provider` → a React wrapper, mounted inside the iframe around components\n * that opt in via `uses`\n */\nexport interface WindoContextDefinition<Values = unknown, Provided = Values> {\n label?: string\n description?: string\n controls?: WindoControlMap\n provider?: ComponentType<{ children: ReactNode; values: Values; ctx: WindoRenderContext }>\n /** Derive the value exposed on `ctx.contexts[name]`. Defaults to the control values. */\n resolve?: (values: Values, ctx: WindoRenderContext) => Provided\n}\n\n// Contexts are each generic over a different control map `C`; TS has no existential\n// to hold `exists C. WindoContextDefinition<WindoControlValues<C>>`. `Values` sits in\n// contravariant positions (provider props, resolve arg) so no precise common supertype\n// exists — `any` is the single, contained variance hatch for this heterogeneous\n// registry. Mirrors WindoModule. Definition sites stay precise; this only erases at the\n// point of collection.\n// biome-ignore lint/suspicious/noExplicitAny: existential variance hatch for the heterogeneous context registry\nexport type WindoContextMap = Record<string, WindoContextDefinition<any, any>>\n\n/* ------------------------------------------------------------------ *\n * Render-time context\n * ------------------------------------------------------------------ */\n\nexport interface WindoViewport {\n width: number\n height: number\n name: 'mobile' | 'tablet' | 'desktop'\n}\n\n/** Console channel: `ctx.logger.log(…)` posts an entry to the chrome's Console tab. */\nexport interface WindoLogger {\n log: (...args: unknown[]) => void\n}\n\n/** How an action fires. `click` renders a toolbar button; the rest bind to the stage's pointer events. */\nexport type WindoActionTrigger = 'click' | 'enter' | 'exit' | 'hover'\n\nexport const WINDO_ACTION_TRIGGERS: readonly WindoActionTrigger[] = ['click', 'enter', 'exit', 'hover']\n\n/**\n * An out-of-band action that drives a component's state. `click` actions render as\n * toolbar buttons; `enter`/`exit`/`hover` bind to the stage's pointer events. `run`\n * receives the live ctx and an `active` flag — for `hover` it is `true` on\n * pointer-enter and `false` on pointer-leave; for the others it is always `true`.\n */\nexport interface WindoAction<State = unknown> {\n label: string\n /** Defaults to `click`. */\n on?: WindoActionTrigger\n run: (ctx: WindoRenderContext<State>, active: boolean) => void\n /** Greys out a `click` action's toolbar button. Evaluated against the live state. */\n disabled?: (ctx: WindoRenderContext<State>) => boolean\n}\n\n/** Live environment handed to every render-time function inside the iframe. */\nexport interface WindoRenderContext<State = unknown> {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n logger: WindoLogger\n /** Current component-local state, typed by the windo's `State` generic. */\n state: State\n /** Merge a patch into the component-local state and re-render. */\n setState: (patch: Partial<State>) => void\n /** Resolved values of opted-in contexts, keyed by context name. */\n contexts: Record<string, unknown>\n /**\n * Shared, cross-component state seeded from the config's `ctxState`. Unlike\n * `state` (per-windo, reset on selection), this persists across selection and\n * is global: any component can read it and write it via `setCtxState`. Use it\n * to drive providers that wrap every component — e.g. a theme provider toggled\n * from any component on the canvas.\n */\n ctxState: Record<string, unknown>\n /** Merge a patch into the shared `ctxState` and re-render every consumer. */\n setCtxState: (patch: Record<string, unknown>) => void\n /** Set the canvas colour scheme from a component or action. */\n setColorScheme: (scheme: 'light' | 'dark') => void\n /** Flip the canvas colour scheme between light and dark. */\n toggleTheme: () => void\n}\n\n/* ------------------------------------------------------------------ *\n * Authoring API\n * ------------------------------------------------------------------ */\n\n/** A variant: a label plus a partial prop patch. Renders in the gallery and is click-to-apply. */\nexport interface WindoVariant<Props> {\n label: string\n props: Partial<Props>\n}\n\n/** A row in the authored Props documentation table. */\nexport interface WindoPropDoc {\n name: string\n type: string\n default?: string\n desc?: string\n}\n\n/** A value that may be authored statically or as a context-aware `ctx => value` function resolved at render-time. */\nexport type Ctxual<T, State = unknown> = T | ((ctx: WindoRenderContext<State>) => T)\n\n/** The ctx surface available while resolving a windo's initial state — the render-time `state`/`setState` pair is excluded because it does not exist yet. */\nexport type WindoInitContext<State = unknown> = Omit<WindoRenderContext<State>, 'state' | 'setState'>\n\nexport type WindoDefaultProps<Props, State = unknown> = Ctxual<Props, State>\n\n/**\n * The object returned by a `windo(...)` factory.\n *\n * Keystone rule: the surrounding factory runs ONCE (definition-time) for static\n * fields (title, group, schema). Every function field below — `defaultProps`,\n * `actions`, `providers`, `component` — runs at render-time with the live `ctx`.\n * Never close over live values in the static factory body.\n */\nexport interface WindoDefinition<Props = unknown, State = unknown, GroupSlug extends string = string, Tag extends string = string> {\n title: string\n group: GroupSlug\n /** Tags this component carries. Each must be one of the config's declared `tags`. Drives the sidebar's tag filter. */\n tags?: Tag[]\n status?: WindoStatus\n description?: string\n deprecation?: string\n /** Where the component anchors in the canvas frame. Either a static placement or a function resolved with the live `ctx`. */\n placement?: Ctxual<WindoPlacement, State>\n /** Initial component-local state. Its shape is the `State` generic; `ctx.state`/`ctx.setState` derive from it. Either a static value or a function resolved with the init `ctx` (no `state`/`setState`) when the component is selected. */\n state?: State | ((ctx: WindoInitContext<State>) => State)\n /** Out-of-band actions that drive state: toolbar buttons (`click`) and stage pointer triggers (`enter`/`exit`/`hover`). */\n actions?: WindoAction<State>[]\n /** zod schema: validator + parser for the JSON-editable prop subset. `z.output ⊆ Props`. */\n configurableProps?: z.ZodType\n /** Full props incl. functions/JSX. The editor's JSON overrides merge on top. */\n defaultProps: WindoDefaultProps<Props, State>\n /** Names of provider contexts this component opts into. */\n uses?: string[]\n /** Gallery variants. Either a static array or a function resolved with the live `ctx` when the component is selected. */\n variants?: Ctxual<WindoVariant<Props>[], State>\n /** Authored documentation table (not derived from the schema). Either a static array or a function resolved with the live `ctx` when the component is selected. */\n props?: Ctxual<WindoPropDoc[], State>\n /** Optional authored code snippet for the Code tab, resolved with the JSON-editable values and the live `ctx`. */\n code?: (values: Props, ctx: WindoRenderContext<State>) => string\n /** A local provider wrapping just this windo (in addition to `uses`). */\n providers?: ComponentType<{ children: ReactNode; ctx: WindoRenderContext<State> }>\n component: (props: Props, ctx: WindoRenderContext<State>) => ReactNode\n}\n\n/** Argument handed to the `windo(w => ...)` factory. */\nexport interface WindoFactoryArg<Groups extends readonly WindoGroup[], Contexts extends WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups keyed by slug. */\n groups: Record<Groups[number]['slug'], WindoGroup>\n contexts: Contexts\n /** The config's declared tags, in declaration order. */\n tags: Tags\n}\n\n/**\n * The default export of a `*.windo.tsx` file. A branded, lazily-resolved\n * definition — the runtime calls `resolve(w)` with the config-derived factory arg.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance escape hatch for the heterogeneous WindoModule registry\nexport interface WindoModule<Props = any, State = any> {\n readonly __windo: true\n resolve: (w: WindoFactoryArg<readonly WindoGroup[], WindoContextMap>) => WindoDefinition<Props, State>\n}\n\n/* ------------------------------------------------------------------ *\n * Config\n * ------------------------------------------------------------------ */\n\nexport interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup[], Contexts extends WindoContextMap = WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups. A component's `group` must be one of these slugs. */\n groups: Groups\n /** Named contexts available to components. */\n contexts?: Contexts\n /** The set of tags components may be assigned. A component's `tags` must be drawn from this list; the sidebar filters by them. */\n tags?: Tags\n /** Initial shared state exposed on `ctx.ctxState`. Global across every component and persisted across selection — write it from any component via `ctx.setCtxState`. */\n ctxState?: Record<string, unknown>\n /** Glob(s) for discovery, relative to project root. Default `**\\/*.windo.tsx`. */\n include?: string | string[]\n /** Title shown in the workbench chrome. */\n title?: string\n /** Icon URL for the workbench logo and the browser favicon. When set, it replaces the built-in `wn` mark in both places. Any `<img>`/favicon source — a path, URL, or data URI. */\n faviconUrl?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Schema descriptor (crosses the iframe boundary; renders the controls)\n * ------------------------------------------------------------------ */\n\nexport type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown'\n\nexport interface WindoControlDescriptor {\n key: string\n kind: WindoControlKind\n optional: boolean\n options?: string[]\n min?: number\n max?: number\n description?: string\n}\n\nexport interface WindoSchemaDescriptor {\n fields: WindoControlDescriptor[]\n}\n\n/* ------------------------------------------------------------------ *\n * Runtime manifest + protocol payloads\n * ------------------------------------------------------------------ */\n\n/** Serialisable metadata for one action — drives the canvas toolbar. */\nexport interface WindoActionMeta {\n id: string\n label: string\n on: WindoActionTrigger\n}\n\n/** Static, serialisable metadata for one windo — drives the sidebar. */\nexport interface WindoManifestEntry {\n id: string\n title: string\n group: string\n tags: string[]\n status: WindoStatus\n description?: string\n deprecation?: string\n placement: WindoPlacement\n uses: string[]\n hasVariants: boolean\n actions: WindoActionMeta[]\n hasState: boolean\n}\n\nexport interface WindoVariantMeta {\n label: string\n props: Record<string, unknown>\n}\n\n/** Ambient environment pushed from the chrome down into the iframe. */\nexport interface WindoEnvState {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n /** Per-context control values, keyed by context name then control key. */\n contexts: Record<string, Record<string, unknown>>\n}\n\nexport interface WindoLogEntry {\n ts: number\n args: unknown[]\n}\n\nexport interface WindoFieldError {\n path: string\n message: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context metadata (serialisable; drives the chrome's Context panel)\n * ------------------------------------------------------------------ */\n\nexport interface WindoContextControlMeta {\n key: string\n type: WindoControlType\n label?: string\n options?: string[]\n default: unknown\n min?: number\n max?: number\n step?: number\n}\n\nexport interface WindoContextMeta {\n name: string\n label?: string\n description?: string\n /** True when the context contributes controls (ambient values). */\n ambient: boolean\n /** True when the context mounts a provider (opt-in via `uses`). */\n hasProvider: boolean\n controls: WindoContextControlMeta[]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,kBACd,QACi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AG;AACpC,UAAM,OAAO,WAAW,aAAa,MAAM,GAAG,CAAC,GAAG,IAAI;AACtD,QAAI,KAAM,KAAI,GAAG,IAAI;AAAA,EACvB;AACA,SAAO;AACT;;;ACjLO,IAAM,YAAY;AAiDlB,SAAS,eAAe,MAAqC;AAClE,SAAO,OAAO,SAAS,YAAY,SAAS,QAAS,KAA8B,WAAW;AAChG;AAEO,SAAS,cAAc,KAA4C;AACxE,SAAO,IAAI,QAAQ;AACrB;AAEO,SAAS,iBAAiB,KAA+C;AAC9E,SAAO,IAAI,QAAQ;AACrB;;;ACrDO,IAAM,iBAAyC,CAAC,UAAU,QAAQ,YAAY;AAYrF,IAAM,uBAAsD,CAAC,UAAU,QAAQ,OAAO,UAAU,QAAQ,SAAS,YAAY,aAAa,eAAe,cAAc;AAEhK,IAAM,mBAA8C,CAAC,GAAG,sBAAsB,GAAG,qBAAqB,IAAI,OAAK,GAAG,CAAC,UAA4B,CAAC;AA2EhJ,IAAM,wBAAuD,CAAC,SAAS,SAAS,QAAQ,OAAO;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -195,6 +195,8 @@ interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup
|
|
|
195
195
|
include?: string | string[];
|
|
196
196
|
/** Title shown in the workbench chrome. */
|
|
197
197
|
title?: string;
|
|
198
|
+
/** Icon URL for the workbench logo and the browser favicon. When set, it replaces the built-in `wn` mark in both places. Any `<img>`/favicon source — a path, URL, or data URI. */
|
|
199
|
+
faviconUrl?: string;
|
|
198
200
|
}
|
|
199
201
|
type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown';
|
|
200
202
|
interface WindoControlDescriptor {
|
|
@@ -353,6 +355,8 @@ type WindoPreviewMessage = {
|
|
|
353
355
|
dir: 'preview';
|
|
354
356
|
type: 'manifest';
|
|
355
357
|
title: string;
|
|
358
|
+
/** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */
|
|
359
|
+
faviconUrl: string | null;
|
|
356
360
|
entries: WindoManifestEntry[];
|
|
357
361
|
groups: WindoGroup[];
|
|
358
362
|
tags: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -195,6 +195,8 @@ interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup
|
|
|
195
195
|
include?: string | string[];
|
|
196
196
|
/** Title shown in the workbench chrome. */
|
|
197
197
|
title?: string;
|
|
198
|
+
/** Icon URL for the workbench logo and the browser favicon. When set, it replaces the built-in `wn` mark in both places. Any `<img>`/favicon source — a path, URL, or data URI. */
|
|
199
|
+
faviconUrl?: string;
|
|
198
200
|
}
|
|
199
201
|
type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown';
|
|
200
202
|
interface WindoControlDescriptor {
|
|
@@ -353,6 +355,8 @@ type WindoPreviewMessage = {
|
|
|
353
355
|
dir: 'preview';
|
|
354
356
|
type: 'manifest';
|
|
355
357
|
title: string;
|
|
358
|
+
/** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */
|
|
359
|
+
faviconUrl: string | null;
|
|
356
360
|
entries: WindoManifestEntry[];
|
|
357
361
|
groups: WindoGroup[];
|
|
358
362
|
tags: string[];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/define-config.ts","../src/descriptor.ts","../src/protocol.ts","../src/types.ts"],"sourcesContent":["// The authoring API. `defineWindoConfig` is the single entry point: it captures\n// the project's groups + contexts and hands back a `windo` factory whose `group`\n// field is type-checked against the configured slugs.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\nimport type { WindoConfig, WindoContextDefinition, WindoContextMap, WindoControlMap, WindoControlValues, WindoDefinition, WindoFactoryArg, WindoGroup, WindoModule, WindoRenderContext } from './types'\n\nexport interface DefineWindoConfigResult<Groups extends readonly WindoGroup[], Tags extends readonly string[], Contexts extends WindoContextMap> {\n config: WindoConfig<Groups, Contexts, Tags>\n windo: <Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ) => WindoModule<Props, State>\n}\n\nexport function defineWindoConfig<const Groups extends readonly WindoGroup[], const Tags extends readonly string[] = readonly [], Contexts extends WindoContextMap = Record<string, never>>(\n config: WindoConfig<Groups, Contexts, Tags>\n): DefineWindoConfigResult<Groups, Tags, Contexts> {\n function windo<Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ): WindoModule<Props, State> {\n return {\n __windo: true,\n resolve: w => factory(w as unknown as WindoFactoryArg<Groups, Contexts, Tags>),\n }\n }\n return { config, windo }\n}\n\n/**\n * Define a named context. A context can contribute ambient `controls` (values +\n * UI), a `provider` (mounted inside the iframe for components that opt in via\n * `uses`), or both.\n *\n * No cast: `def` is already structurally a `WindoContextDefinition<WindoControlValues<C>,\n * Provided>` (only `controls` widens, covariantly). The unavoidable variance — TS has\n * no existential type to hold contexts heterogeneous in `C` — is absorbed once, in\n * `WindoContextMap`, not here and not at call sites.\n */\nexport function defineContext<C extends WindoControlMap, Provided = WindoControlValues<C>>(def: {\n label?: string\n description?: string\n controls?: C\n provider?: ComponentType<{ children: ReactNode; values: WindoControlValues<C>; ctx: WindoRenderContext }>\n resolve?: (values: WindoControlValues<C>, ctx: WindoRenderContext) => Provided\n}): WindoContextDefinition<WindoControlValues<C>, Provided> {\n return def\n}\n\n/**\n * Bind a zod schema to a component's props. The generic carries the component's\n * prop type so the schema's output stays a subset of it; the returned schema is\n * the runtime validator + parser (`z.input` is the JSON edit surface, `z.output`\n * is what the component receives).\n */\nexport function configurableProps<P>() {\n return <S extends z.ZodType<Partial<P>>>(schema: S): S => schema\n}\n","// Walk a zod schema into a serialisable descriptor that can cross the iframe\n// boundary and render the Controls/Schema UI. We lean on `z.toJSONSchema` (zod\n// v4) for the input shape (enum options, min/max, optionality), then enrich the\n// kind from the zod node's own type tag — some types (Date, Map, Set) are\n// unrepresentable in JSON Schema and come back as `{}`, but their zod `def.type`\n// is exact. The live schema (with transforms/coerce/refine) stays in the iframe\n// and does the actual parsing — only this descriptor travels.\n\nimport { z } from 'zod'\nimport type { WindoControlDescriptor, WindoControlKind, WindoSchemaDescriptor } from './types'\n\ninterface JsonNode {\n type?: string | string[]\n enum?: unknown[]\n const?: unknown\n format?: string\n properties?: Record<string, JsonNode>\n required?: string[]\n items?: JsonNode\n anyOf?: JsonNode[]\n oneOf?: JsonNode[]\n allOf?: JsonNode[]\n minimum?: number\n maximum?: number\n description?: string\n}\n\nexport function describeSchema(schema: z.ZodType | undefined | null): WindoSchemaDescriptor {\n if (!schema) return { fields: [] }\n let json: JsonNode\n try {\n json = z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) as JsonNode\n } catch {\n return { fields: [] }\n }\n const root = unwrap(json)\n const properties = root.properties ?? {}\n const required = new Set(root.required ?? [])\n const zodKinds = shapeKinds(schema)\n const fields: WindoControlDescriptor[] = Object.keys(properties).map(key => fieldFrom(key, properties[key], required.has(key), zodKinds[key]))\n return { fields }\n}\n\n// JSON Schema often wraps the object in anyOf (for optional/nullable). Find the\n// node that actually carries the object's properties.\nfunction unwrap(node: JsonNode): JsonNode {\n if (node.properties) return node\n const branches = node.anyOf ?? node.oneOf ?? node.allOf\n if (branches) {\n const withProps = branches.find(b => b.properties)\n if (withProps) return withProps\n }\n return node\n}\n\nfunction fieldFrom(key: string, node: JsonNode, isRequired: boolean, zodKind?: WindoControlKind): WindoControlDescriptor {\n const inner = collapseNullable(node)\n let kind = kindOf(inner)\n // The zod tag wins for types JSON Schema can't express (date/array/object that\n // came back as {}), and as a fallback whenever the JSON kind is unknown.\n if (zodKind && (kind === 'unknown' || zodKind === 'date')) kind = zodKind\n const descriptor: WindoControlDescriptor = {\n key,\n kind,\n optional: !isRequired || isNullable(node),\n }\n if (inner.description) descriptor.description = inner.description\n const options = enumOptions(inner)\n if (options) descriptor.options = options\n if (typeof inner.minimum === 'number') descriptor.min = inner.minimum\n if (typeof inner.maximum === 'number') descriptor.max = inner.maximum\n return descriptor\n}\n\nfunction isNullable(node: JsonNode): boolean {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return false\n return branches.some(b => b.type === 'null')\n}\n\n// Strip a `{ anyOf: [T, null] }` wrapper down to T.\nfunction collapseNullable(node: JsonNode): JsonNode {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return node\n const nonNull = branches.filter(b => b.type !== 'null')\n if (nonNull.length === 1) return nonNull[0]\n return node\n}\n\nfunction enumOptions(node: JsonNode): string[] | undefined {\n if (Array.isArray(node.enum)) return node.enum.map(v => String(v))\n const branches = node.anyOf ?? node.oneOf\n if (branches?.every(b => b.const !== undefined)) {\n return branches.map(b => String(b.const))\n }\n return undefined\n}\n\nfunction kindOf(node: JsonNode): WindoControlKind {\n if (Array.isArray(node.enum) || (node.anyOf?.every(b => b.const !== undefined) ?? false)) return 'enum'\n if (node.format === 'date-time' || node.format === 'date') return 'date'\n const type = Array.isArray(node.type) ? node.type.find(t => t !== 'null') : node.type\n switch (type) {\n case 'string':\n return 'string'\n case 'number':\n case 'integer':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n default:\n return 'unknown'\n }\n}\n\n/* ------------------------------------------------------------------ *\n * zod node introspection (the kind source of truth for unrepresentable types)\n * ------------------------------------------------------------------ */\n\ninterface ZodDefLike {\n type?: string\n innerType?: unknown\n}\n\nfunction zodDef(node: unknown): ZodDefLike | undefined {\n const n = node as { def?: ZodDefLike; _zod?: { def?: ZodDefLike } } | null\n if (!n || typeof n !== 'object') return undefined\n return n.def ?? n._zod?.def\n}\n\nconst ZOD_WRAPPERS = new Set(['optional', 'nullable', 'default', 'prefault', 'catch', 'readonly', 'nonoptional', 'lazy'])\n\n// Unwrap optional/nullable/default/... down to the meaningful inner node.\nfunction unwrapZodDef(node: unknown): ZodDefLike | undefined {\n let def = zodDef(node)\n let guard = 0\n while (def && def.innerType && ZOD_WRAPPERS.has(def.type ?? '') && guard++ < 16) {\n def = zodDef(def.innerType)\n }\n return def\n}\n\nfunction mapZodType(type: string | undefined): WindoControlKind | undefined {\n switch (type) {\n case 'date':\n return 'date'\n case 'string':\n return 'string'\n case 'number':\n case 'int':\n case 'bigint':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n case 'set':\n case 'tuple':\n return 'array'\n case 'object':\n case 'record':\n case 'map':\n return 'object'\n case 'enum':\n case 'literal':\n return 'enum'\n default:\n return undefined\n }\n}\n\n// Per-field kind read straight from the zod object's shape.\nfunction shapeKinds(schema: z.ZodType): Record<string, WindoControlKind> {\n const shape = (schema as { shape?: Record<string, unknown> }).shape\n if (!shape || typeof shape !== 'object') return {}\n const out: Record<string, WindoControlKind> = {}\n for (const key of Object.keys(shape)) {\n const kind = mapZodType(unwrapZodDef(shape[key])?.type)\n if (kind) out[key] = kind\n }\n return out\n}\n","// The chrome <-> iframe postMessage contract. The schema itself never crosses\n// the boundary: the iframe walks it into a serialisable descriptor, the chrome\n// sends candidate JSON down, the iframe parses and reports back. Every payload\n// here is plain JSON.\n\nimport type { WindoContextMeta, WindoEnvState, WindoFieldError, WindoGroup, WindoLogEntry, WindoManifestEntry, WindoPropDoc, WindoSchemaDescriptor, WindoVariantMeta } from './types'\n\nexport const WINDO_MSG = 'windo'\n\n/** chrome -> iframe */\nexport type WindoHostMessage =\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'request-manifest' }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'select'; id: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-props'; id: string; json: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-env'; env: WindoEnvState }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'invoke-action'; id: string; actionId: string }\n\n/** iframe -> chrome */\nexport type WindoPreviewMessage =\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ready' }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'manifest'\n title: string\n entries: WindoManifestEntry[]\n groups: WindoGroup[]\n tags: string[]\n contexts: WindoContextMeta[]\n /** Initial shared state from the config — seeds the chrome's editable strip. */\n ctxState: Record<string, unknown>\n }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'describe'\n id: string\n descriptor: WindoSchemaDescriptor\n props: WindoPropDoc[]\n variants: WindoVariantMeta[]\n defaults: unknown\n code: string | null\n }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-ok'; id: string }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-error'; id: string; errors: WindoFieldError[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'log'; entry: WindoLogEntry }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'state'; id: string; state: Record<string, unknown>; actions: { id: string; disabled: boolean }[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'color-scheme'; colorScheme: 'light' | 'dark' }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'render-error'; id: string; message: string; stack?: string }\n\nexport type WindoMessage = WindoHostMessage | WindoPreviewMessage\n\nexport function isWindoMessage(data: unknown): data is WindoMessage {\n return typeof data === 'object' && data !== null && (data as { source?: unknown }).source === WINDO_MSG\n}\n\nexport function isHostMessage(msg: WindoMessage): msg is WindoHostMessage {\n return msg.dir === 'host'\n}\n\nexport function isPreviewMessage(msg: WindoMessage): msg is WindoPreviewMessage {\n return msg.dir === 'preview'\n}\n","// Core type system for windo. Everything — the authoring API, the iframe\n// preview runtime, the chrome UI, and the postMessage protocol — is typed\n// against the contracts in this file.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\n\n/* ------------------------------------------------------------------ *\n * Primitives\n * ------------------------------------------------------------------ */\n\nexport type WindoStatus = 'stable' | 'beta' | 'deprecated'\n\nexport const WINDO_STATUSES: readonly WindoStatus[] = ['stable', 'beta', 'deprecated']\n\n/** Anchor a component within the canvas frame. */\nexport type WindoPlacementBase = 'center' | 'fill' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\n/**\n * Where a component renders inside the canvas frame. Placements render flush by\n * default; append `-padding` to inset the component from the frame edges\n * (e.g. `top` sits flush at the top, `top-padding` adds breathing room).\n */\nexport type WindoPlacement = WindoPlacementBase | `${WindoPlacementBase}-padding`\n\nconst WINDO_PLACEMENT_BASE: readonly WindoPlacementBase[] = ['center', 'fill', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right']\n\nexport const WINDO_PLACEMENTS: readonly WindoPlacement[] = [...WINDO_PLACEMENT_BASE, ...WINDO_PLACEMENT_BASE.map(p => `${p}-padding` as WindoPlacement)]\n\n/** A configured group. Components reference a group by its `slug`. */\nexport interface WindoGroup {\n name: string\n slug: string\n description?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context system\n * ------------------------------------------------------------------ */\n\nexport type WindoControlType = 'enum' | 'boolean' | 'string' | 'number'\n\n/** A single ambient control: a value plus the metadata to render its toggle. */\nexport interface WindoControlSpec<T = unknown> {\n type: WindoControlType\n label?: string\n default: T\n options?: readonly string[]\n min?: number\n max?: number\n step?: number\n}\n\nexport type WindoControlMap = Record<string, WindoControlSpec>\n\n/** Resolve a control map to the value object it produces. */\nexport type WindoControlValues<C extends WindoControlMap> = {\n [K in keyof C]: C[K] extends WindoControlSpec<infer T> ? T : never\n}\n\n/**\n * A named context. Two capabilities, either or both:\n * - `controls` → ambient values + UI toggles (free, no opt-in needed)\n * - `provider` → a React wrapper, mounted inside the iframe around components\n * that opt in via `uses`\n */\nexport interface WindoContextDefinition<Values = unknown, Provided = Values> {\n label?: string\n description?: string\n controls?: WindoControlMap\n provider?: ComponentType<{ children: ReactNode; values: Values; ctx: WindoRenderContext }>\n /** Derive the value exposed on `ctx.contexts[name]`. Defaults to the control values. */\n resolve?: (values: Values, ctx: WindoRenderContext) => Provided\n}\n\n// Contexts are each generic over a different control map `C`; TS has no existential\n// to hold `exists C. WindoContextDefinition<WindoControlValues<C>>`. `Values` sits in\n// contravariant positions (provider props, resolve arg) so no precise common supertype\n// exists — `any` is the single, contained variance hatch for this heterogeneous\n// registry. Mirrors WindoModule. Definition sites stay precise; this only erases at the\n// point of collection.\n// biome-ignore lint/suspicious/noExplicitAny: existential variance hatch for the heterogeneous context registry\nexport type WindoContextMap = Record<string, WindoContextDefinition<any, any>>\n\n/* ------------------------------------------------------------------ *\n * Render-time context\n * ------------------------------------------------------------------ */\n\nexport interface WindoViewport {\n width: number\n height: number\n name: 'mobile' | 'tablet' | 'desktop'\n}\n\n/** Console channel: `ctx.logger.log(…)` posts an entry to the chrome's Console tab. */\nexport interface WindoLogger {\n log: (...args: unknown[]) => void\n}\n\n/** How an action fires. `click` renders a toolbar button; the rest bind to the stage's pointer events. */\nexport type WindoActionTrigger = 'click' | 'enter' | 'exit' | 'hover'\n\nexport const WINDO_ACTION_TRIGGERS: readonly WindoActionTrigger[] = ['click', 'enter', 'exit', 'hover']\n\n/**\n * An out-of-band action that drives a component's state. `click` actions render as\n * toolbar buttons; `enter`/`exit`/`hover` bind to the stage's pointer events. `run`\n * receives the live ctx and an `active` flag — for `hover` it is `true` on\n * pointer-enter and `false` on pointer-leave; for the others it is always `true`.\n */\nexport interface WindoAction<State = unknown> {\n label: string\n /** Defaults to `click`. */\n on?: WindoActionTrigger\n run: (ctx: WindoRenderContext<State>, active: boolean) => void\n /** Greys out a `click` action's toolbar button. Evaluated against the live state. */\n disabled?: (ctx: WindoRenderContext<State>) => boolean\n}\n\n/** Live environment handed to every render-time function inside the iframe. */\nexport interface WindoRenderContext<State = unknown> {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n logger: WindoLogger\n /** Current component-local state, typed by the windo's `State` generic. */\n state: State\n /** Merge a patch into the component-local state and re-render. */\n setState: (patch: Partial<State>) => void\n /** Resolved values of opted-in contexts, keyed by context name. */\n contexts: Record<string, unknown>\n /**\n * Shared, cross-component state seeded from the config's `ctxState`. Unlike\n * `state` (per-windo, reset on selection), this persists across selection and\n * is global: any component can read it and write it via `setCtxState`. Use it\n * to drive providers that wrap every component — e.g. a theme provider toggled\n * from any component on the canvas.\n */\n ctxState: Record<string, unknown>\n /** Merge a patch into the shared `ctxState` and re-render every consumer. */\n setCtxState: (patch: Record<string, unknown>) => void\n /** Set the canvas colour scheme from a component or action. */\n setColorScheme: (scheme: 'light' | 'dark') => void\n /** Flip the canvas colour scheme between light and dark. */\n toggleTheme: () => void\n}\n\n/* ------------------------------------------------------------------ *\n * Authoring API\n * ------------------------------------------------------------------ */\n\n/** A variant: a label plus a partial prop patch. Renders in the gallery and is click-to-apply. */\nexport interface WindoVariant<Props> {\n label: string\n props: Partial<Props>\n}\n\n/** A row in the authored Props documentation table. */\nexport interface WindoPropDoc {\n name: string\n type: string\n default?: string\n desc?: string\n}\n\n/** A value that may be authored statically or as a context-aware `ctx => value` function resolved at render-time. */\nexport type Ctxual<T, State = unknown> = T | ((ctx: WindoRenderContext<State>) => T)\n\n/** The ctx surface available while resolving a windo's initial state — the render-time `state`/`setState` pair is excluded because it does not exist yet. */\nexport type WindoInitContext<State = unknown> = Omit<WindoRenderContext<State>, 'state' | 'setState'>\n\nexport type WindoDefaultProps<Props, State = unknown> = Ctxual<Props, State>\n\n/**\n * The object returned by a `windo(...)` factory.\n *\n * Keystone rule: the surrounding factory runs ONCE (definition-time) for static\n * fields (title, group, schema). Every function field below — `defaultProps`,\n * `actions`, `providers`, `component` — runs at render-time with the live `ctx`.\n * Never close over live values in the static factory body.\n */\nexport interface WindoDefinition<Props = unknown, State = unknown, GroupSlug extends string = string, Tag extends string = string> {\n title: string\n group: GroupSlug\n /** Tags this component carries. Each must be one of the config's declared `tags`. Drives the sidebar's tag filter. */\n tags?: Tag[]\n status?: WindoStatus\n description?: string\n deprecation?: string\n /** Where the component anchors in the canvas frame. Either a static placement or a function resolved with the live `ctx`. */\n placement?: Ctxual<WindoPlacement, State>\n /** Initial component-local state. Its shape is the `State` generic; `ctx.state`/`ctx.setState` derive from it. Either a static value or a function resolved with the init `ctx` (no `state`/`setState`) when the component is selected. */\n state?: State | ((ctx: WindoInitContext<State>) => State)\n /** Out-of-band actions that drive state: toolbar buttons (`click`) and stage pointer triggers (`enter`/`exit`/`hover`). */\n actions?: WindoAction<State>[]\n /** zod schema: validator + parser for the JSON-editable prop subset. `z.output ⊆ Props`. */\n configurableProps?: z.ZodType\n /** Full props incl. functions/JSX. The editor's JSON overrides merge on top. */\n defaultProps: WindoDefaultProps<Props, State>\n /** Names of provider contexts this component opts into. */\n uses?: string[]\n /** Gallery variants. Either a static array or a function resolved with the live `ctx` when the component is selected. */\n variants?: Ctxual<WindoVariant<Props>[], State>\n /** Authored documentation table (not derived from the schema). Either a static array or a function resolved with the live `ctx` when the component is selected. */\n props?: Ctxual<WindoPropDoc[], State>\n /** Optional authored code snippet for the Code tab, resolved with the JSON-editable values and the live `ctx`. */\n code?: (values: Props, ctx: WindoRenderContext<State>) => string\n /** A local provider wrapping just this windo (in addition to `uses`). */\n providers?: ComponentType<{ children: ReactNode; ctx: WindoRenderContext<State> }>\n component: (props: Props, ctx: WindoRenderContext<State>) => ReactNode\n}\n\n/** Argument handed to the `windo(w => ...)` factory. */\nexport interface WindoFactoryArg<Groups extends readonly WindoGroup[], Contexts extends WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups keyed by slug. */\n groups: Record<Groups[number]['slug'], WindoGroup>\n contexts: Contexts\n /** The config's declared tags, in declaration order. */\n tags: Tags\n}\n\n/**\n * The default export of a `*.windo.tsx` file. A branded, lazily-resolved\n * definition — the runtime calls `resolve(w)` with the config-derived factory arg.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance escape hatch for the heterogeneous WindoModule registry\nexport interface WindoModule<Props = any, State = any> {\n readonly __windo: true\n resolve: (w: WindoFactoryArg<readonly WindoGroup[], WindoContextMap>) => WindoDefinition<Props, State>\n}\n\n/* ------------------------------------------------------------------ *\n * Config\n * ------------------------------------------------------------------ */\n\nexport interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup[], Contexts extends WindoContextMap = WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups. A component's `group` must be one of these slugs. */\n groups: Groups\n /** Named contexts available to components. */\n contexts?: Contexts\n /** The set of tags components may be assigned. A component's `tags` must be drawn from this list; the sidebar filters by them. */\n tags?: Tags\n /** Initial shared state exposed on `ctx.ctxState`. Global across every component and persisted across selection — write it from any component via `ctx.setCtxState`. */\n ctxState?: Record<string, unknown>\n /** Glob(s) for discovery, relative to project root. Default `**\\/*.windo.tsx`. */\n include?: string | string[]\n /** Title shown in the workbench chrome. */\n title?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Schema descriptor (crosses the iframe boundary; renders the controls)\n * ------------------------------------------------------------------ */\n\nexport type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown'\n\nexport interface WindoControlDescriptor {\n key: string\n kind: WindoControlKind\n optional: boolean\n options?: string[]\n min?: number\n max?: number\n description?: string\n}\n\nexport interface WindoSchemaDescriptor {\n fields: WindoControlDescriptor[]\n}\n\n/* ------------------------------------------------------------------ *\n * Runtime manifest + protocol payloads\n * ------------------------------------------------------------------ */\n\n/** Serialisable metadata for one action — drives the canvas toolbar. */\nexport interface WindoActionMeta {\n id: string\n label: string\n on: WindoActionTrigger\n}\n\n/** Static, serialisable metadata for one windo — drives the sidebar. */\nexport interface WindoManifestEntry {\n id: string\n title: string\n group: string\n tags: string[]\n status: WindoStatus\n description?: string\n deprecation?: string\n placement: WindoPlacement\n uses: string[]\n hasVariants: boolean\n actions: WindoActionMeta[]\n hasState: boolean\n}\n\nexport interface WindoVariantMeta {\n label: string\n props: Record<string, unknown>\n}\n\n/** Ambient environment pushed from the chrome down into the iframe. */\nexport interface WindoEnvState {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n /** Per-context control values, keyed by context name then control key. */\n contexts: Record<string, Record<string, unknown>>\n}\n\nexport interface WindoLogEntry {\n ts: number\n args: unknown[]\n}\n\nexport interface WindoFieldError {\n path: string\n message: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context metadata (serialisable; drives the chrome's Context panel)\n * ------------------------------------------------------------------ */\n\nexport interface WindoContextControlMeta {\n key: string\n type: WindoControlType\n label?: string\n options?: string[]\n default: unknown\n min?: number\n max?: number\n step?: number\n}\n\nexport interface WindoContextMeta {\n name: string\n label?: string\n description?: string\n /** True when the context contributes controls (ambient values). */\n ambient: boolean\n /** True when the context mounts a provider (opt-in via `uses`). */\n hasProvider: boolean\n controls: WindoContextControlMeta[]\n}\n"],"mappings":";AAeO,SAAS,kBACd,QACiD;AACjD,WAAS,MACP,SAC2B;AAC3B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS,OAAK,QAAQ,CAAuD;AAAA,IAC/E;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,MAAM;AACzB;AAYO,SAAS,cAA2E,KAM/B;AAC1D,SAAO;AACT;AAQO,SAAS,oBAAuB;AACrC,SAAO,CAAkC,WAAiB;AAC5D;;;ACjDA,SAAS,SAAS;AAmBX,SAAS,eAAe,QAA6D;AAC1F,MAAI,CAAC,OAAQ,QAAO,EAAE,QAAQ,CAAC,EAAE;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,EAAE,aAAa,QAAQ,EAAE,IAAI,SAAS,iBAAiB,MAAM,CAAC;AAAA,EACvE,QAAQ;AACN,WAAO,EAAE,QAAQ,CAAC,EAAE;AAAA,EACtB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C,CAAC,GAAG,sBAAsB,GAAG,qBAAqB,IAAI,OAAK,GAAG,CAAC,UAA4B,CAAC;AA2EhJ,IAAM,wBAAuD,CAAC,SAAS,SAAS,QAAQ,OAAO;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/define-config.ts","../src/descriptor.ts","../src/protocol.ts","../src/types.ts"],"sourcesContent":["// The authoring API. `defineWindoConfig` is the single entry point: it captures\n// the project's groups + contexts and hands back a `windo` factory whose `group`\n// field is type-checked against the configured slugs.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\nimport type { WindoConfig, WindoContextDefinition, WindoContextMap, WindoControlMap, WindoControlValues, WindoDefinition, WindoFactoryArg, WindoGroup, WindoModule, WindoRenderContext } from './types'\n\nexport interface DefineWindoConfigResult<Groups extends readonly WindoGroup[], Tags extends readonly string[], Contexts extends WindoContextMap> {\n config: WindoConfig<Groups, Contexts, Tags>\n windo: <Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ) => WindoModule<Props, State>\n}\n\nexport function defineWindoConfig<const Groups extends readonly WindoGroup[], const Tags extends readonly string[] = readonly [], Contexts extends WindoContextMap = Record<string, never>>(\n config: WindoConfig<Groups, Contexts, Tags>\n): DefineWindoConfigResult<Groups, Tags, Contexts> {\n function windo<Props, State = Record<string, never>>(\n factory: (w: WindoFactoryArg<Groups, Contexts, Tags>) => WindoDefinition<Props, State, Groups[number]['slug'], Tags[number]>\n ): WindoModule<Props, State> {\n return {\n __windo: true,\n resolve: w => factory(w as unknown as WindoFactoryArg<Groups, Contexts, Tags>),\n }\n }\n return { config, windo }\n}\n\n/**\n * Define a named context. A context can contribute ambient `controls` (values +\n * UI), a `provider` (mounted inside the iframe for components that opt in via\n * `uses`), or both.\n *\n * No cast: `def` is already structurally a `WindoContextDefinition<WindoControlValues<C>,\n * Provided>` (only `controls` widens, covariantly). The unavoidable variance — TS has\n * no existential type to hold contexts heterogeneous in `C` — is absorbed once, in\n * `WindoContextMap`, not here and not at call sites.\n */\nexport function defineContext<C extends WindoControlMap, Provided = WindoControlValues<C>>(def: {\n label?: string\n description?: string\n controls?: C\n provider?: ComponentType<{ children: ReactNode; values: WindoControlValues<C>; ctx: WindoRenderContext }>\n resolve?: (values: WindoControlValues<C>, ctx: WindoRenderContext) => Provided\n}): WindoContextDefinition<WindoControlValues<C>, Provided> {\n return def\n}\n\n/**\n * Bind a zod schema to a component's props. The generic carries the component's\n * prop type so the schema's output stays a subset of it; the returned schema is\n * the runtime validator + parser (`z.input` is the JSON edit surface, `z.output`\n * is what the component receives).\n */\nexport function configurableProps<P>() {\n return <S extends z.ZodType<Partial<P>>>(schema: S): S => schema\n}\n","// Walk a zod schema into a serialisable descriptor that can cross the iframe\n// boundary and render the Controls/Schema UI. We lean on `z.toJSONSchema` (zod\n// v4) for the input shape (enum options, min/max, optionality), then enrich the\n// kind from the zod node's own type tag — some types (Date, Map, Set) are\n// unrepresentable in JSON Schema and come back as `{}`, but their zod `def.type`\n// is exact. The live schema (with transforms/coerce/refine) stays in the iframe\n// and does the actual parsing — only this descriptor travels.\n\nimport { z } from 'zod'\nimport type { WindoControlDescriptor, WindoControlKind, WindoSchemaDescriptor } from './types'\n\ninterface JsonNode {\n type?: string | string[]\n enum?: unknown[]\n const?: unknown\n format?: string\n properties?: Record<string, JsonNode>\n required?: string[]\n items?: JsonNode\n anyOf?: JsonNode[]\n oneOf?: JsonNode[]\n allOf?: JsonNode[]\n minimum?: number\n maximum?: number\n description?: string\n}\n\nexport function describeSchema(schema: z.ZodType | undefined | null): WindoSchemaDescriptor {\n if (!schema) return { fields: [] }\n let json: JsonNode\n try {\n json = z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) as JsonNode\n } catch {\n return { fields: [] }\n }\n const root = unwrap(json)\n const properties = root.properties ?? {}\n const required = new Set(root.required ?? [])\n const zodKinds = shapeKinds(schema)\n const fields: WindoControlDescriptor[] = Object.keys(properties).map(key => fieldFrom(key, properties[key], required.has(key), zodKinds[key]))\n return { fields }\n}\n\n// JSON Schema often wraps the object in anyOf (for optional/nullable). Find the\n// node that actually carries the object's properties.\nfunction unwrap(node: JsonNode): JsonNode {\n if (node.properties) return node\n const branches = node.anyOf ?? node.oneOf ?? node.allOf\n if (branches) {\n const withProps = branches.find(b => b.properties)\n if (withProps) return withProps\n }\n return node\n}\n\nfunction fieldFrom(key: string, node: JsonNode, isRequired: boolean, zodKind?: WindoControlKind): WindoControlDescriptor {\n const inner = collapseNullable(node)\n let kind = kindOf(inner)\n // The zod tag wins for types JSON Schema can't express (date/array/object that\n // came back as {}), and as a fallback whenever the JSON kind is unknown.\n if (zodKind && (kind === 'unknown' || zodKind === 'date')) kind = zodKind\n const descriptor: WindoControlDescriptor = {\n key,\n kind,\n optional: !isRequired || isNullable(node),\n }\n if (inner.description) descriptor.description = inner.description\n const options = enumOptions(inner)\n if (options) descriptor.options = options\n if (typeof inner.minimum === 'number') descriptor.min = inner.minimum\n if (typeof inner.maximum === 'number') descriptor.max = inner.maximum\n return descriptor\n}\n\nfunction isNullable(node: JsonNode): boolean {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return false\n return branches.some(b => b.type === 'null')\n}\n\n// Strip a `{ anyOf: [T, null] }` wrapper down to T.\nfunction collapseNullable(node: JsonNode): JsonNode {\n const branches = node.anyOf ?? node.oneOf\n if (!branches) return node\n const nonNull = branches.filter(b => b.type !== 'null')\n if (nonNull.length === 1) return nonNull[0]\n return node\n}\n\nfunction enumOptions(node: JsonNode): string[] | undefined {\n if (Array.isArray(node.enum)) return node.enum.map(v => String(v))\n const branches = node.anyOf ?? node.oneOf\n if (branches?.every(b => b.const !== undefined)) {\n return branches.map(b => String(b.const))\n }\n return undefined\n}\n\nfunction kindOf(node: JsonNode): WindoControlKind {\n if (Array.isArray(node.enum) || (node.anyOf?.every(b => b.const !== undefined) ?? false)) return 'enum'\n if (node.format === 'date-time' || node.format === 'date') return 'date'\n const type = Array.isArray(node.type) ? node.type.find(t => t !== 'null') : node.type\n switch (type) {\n case 'string':\n return 'string'\n case 'number':\n case 'integer':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n default:\n return 'unknown'\n }\n}\n\n/* ------------------------------------------------------------------ *\n * zod node introspection (the kind source of truth for unrepresentable types)\n * ------------------------------------------------------------------ */\n\ninterface ZodDefLike {\n type?: string\n innerType?: unknown\n}\n\nfunction zodDef(node: unknown): ZodDefLike | undefined {\n const n = node as { def?: ZodDefLike; _zod?: { def?: ZodDefLike } } | null\n if (!n || typeof n !== 'object') return undefined\n return n.def ?? n._zod?.def\n}\n\nconst ZOD_WRAPPERS = new Set(['optional', 'nullable', 'default', 'prefault', 'catch', 'readonly', 'nonoptional', 'lazy'])\n\n// Unwrap optional/nullable/default/... down to the meaningful inner node.\nfunction unwrapZodDef(node: unknown): ZodDefLike | undefined {\n let def = zodDef(node)\n let guard = 0\n while (def && def.innerType && ZOD_WRAPPERS.has(def.type ?? '') && guard++ < 16) {\n def = zodDef(def.innerType)\n }\n return def\n}\n\nfunction mapZodType(type: string | undefined): WindoControlKind | undefined {\n switch (type) {\n case 'date':\n return 'date'\n case 'string':\n return 'string'\n case 'number':\n case 'int':\n case 'bigint':\n return 'number'\n case 'boolean':\n return 'boolean'\n case 'array':\n case 'set':\n case 'tuple':\n return 'array'\n case 'object':\n case 'record':\n case 'map':\n return 'object'\n case 'enum':\n case 'literal':\n return 'enum'\n default:\n return undefined\n }\n}\n\n// Per-field kind read straight from the zod object's shape.\nfunction shapeKinds(schema: z.ZodType): Record<string, WindoControlKind> {\n const shape = (schema as { shape?: Record<string, unknown> }).shape\n if (!shape || typeof shape !== 'object') return {}\n const out: Record<string, WindoControlKind> = {}\n for (const key of Object.keys(shape)) {\n const kind = mapZodType(unwrapZodDef(shape[key])?.type)\n if (kind) out[key] = kind\n }\n return out\n}\n","// The chrome <-> iframe postMessage contract. The schema itself never crosses\n// the boundary: the iframe walks it into a serialisable descriptor, the chrome\n// sends candidate JSON down, the iframe parses and reports back. Every payload\n// here is plain JSON.\n\nimport type { WindoContextMeta, WindoEnvState, WindoFieldError, WindoGroup, WindoLogEntry, WindoManifestEntry, WindoPropDoc, WindoSchemaDescriptor, WindoVariantMeta } from './types'\n\nexport const WINDO_MSG = 'windo'\n\n/** chrome -> iframe */\nexport type WindoHostMessage =\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'request-manifest' }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'select'; id: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-props'; id: string; json: string }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-env'; env: WindoEnvState }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'set-ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'host'; type: 'invoke-action'; id: string; actionId: string }\n\n/** iframe -> chrome */\nexport type WindoPreviewMessage =\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ready' }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'manifest'\n title: string\n /** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */\n faviconUrl: string | null\n entries: WindoManifestEntry[]\n groups: WindoGroup[]\n tags: string[]\n contexts: WindoContextMeta[]\n /** Initial shared state from the config — seeds the chrome's editable strip. */\n ctxState: Record<string, unknown>\n }\n | {\n source: typeof WINDO_MSG\n dir: 'preview'\n type: 'describe'\n id: string\n descriptor: WindoSchemaDescriptor\n props: WindoPropDoc[]\n variants: WindoVariantMeta[]\n defaults: unknown\n code: string | null\n }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-ok'; id: string }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'parse-error'; id: string; errors: WindoFieldError[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'log'; entry: WindoLogEntry }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'state'; id: string; state: Record<string, unknown>; actions: { id: string; disabled: boolean }[] }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'ctx-state'; state: Record<string, unknown> }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'color-scheme'; colorScheme: 'light' | 'dark' }\n | { source: typeof WINDO_MSG; dir: 'preview'; type: 'render-error'; id: string; message: string; stack?: string }\n\nexport type WindoMessage = WindoHostMessage | WindoPreviewMessage\n\nexport function isWindoMessage(data: unknown): data is WindoMessage {\n return typeof data === 'object' && data !== null && (data as { source?: unknown }).source === WINDO_MSG\n}\n\nexport function isHostMessage(msg: WindoMessage): msg is WindoHostMessage {\n return msg.dir === 'host'\n}\n\nexport function isPreviewMessage(msg: WindoMessage): msg is WindoPreviewMessage {\n return msg.dir === 'preview'\n}\n","// Core type system for windo. Everything — the authoring API, the iframe\n// preview runtime, the chrome UI, and the postMessage protocol — is typed\n// against the contracts in this file.\n\nimport type { ComponentType, ReactNode } from 'react'\nimport type { z } from 'zod'\n\n/* ------------------------------------------------------------------ *\n * Primitives\n * ------------------------------------------------------------------ */\n\nexport type WindoStatus = 'stable' | 'beta' | 'deprecated'\n\nexport const WINDO_STATUSES: readonly WindoStatus[] = ['stable', 'beta', 'deprecated']\n\n/** Anchor a component within the canvas frame. */\nexport type WindoPlacementBase = 'center' | 'fill' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\n/**\n * Where a component renders inside the canvas frame. Placements render flush by\n * default; append `-padding` to inset the component from the frame edges\n * (e.g. `top` sits flush at the top, `top-padding` adds breathing room).\n */\nexport type WindoPlacement = WindoPlacementBase | `${WindoPlacementBase}-padding`\n\nconst WINDO_PLACEMENT_BASE: readonly WindoPlacementBase[] = ['center', 'fill', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right']\n\nexport const WINDO_PLACEMENTS: readonly WindoPlacement[] = [...WINDO_PLACEMENT_BASE, ...WINDO_PLACEMENT_BASE.map(p => `${p}-padding` as WindoPlacement)]\n\n/** A configured group. Components reference a group by its `slug`. */\nexport interface WindoGroup {\n name: string\n slug: string\n description?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context system\n * ------------------------------------------------------------------ */\n\nexport type WindoControlType = 'enum' | 'boolean' | 'string' | 'number'\n\n/** A single ambient control: a value plus the metadata to render its toggle. */\nexport interface WindoControlSpec<T = unknown> {\n type: WindoControlType\n label?: string\n default: T\n options?: readonly string[]\n min?: number\n max?: number\n step?: number\n}\n\nexport type WindoControlMap = Record<string, WindoControlSpec>\n\n/** Resolve a control map to the value object it produces. */\nexport type WindoControlValues<C extends WindoControlMap> = {\n [K in keyof C]: C[K] extends WindoControlSpec<infer T> ? T : never\n}\n\n/**\n * A named context. Two capabilities, either or both:\n * - `controls` → ambient values + UI toggles (free, no opt-in needed)\n * - `provider` → a React wrapper, mounted inside the iframe around components\n * that opt in via `uses`\n */\nexport interface WindoContextDefinition<Values = unknown, Provided = Values> {\n label?: string\n description?: string\n controls?: WindoControlMap\n provider?: ComponentType<{ children: ReactNode; values: Values; ctx: WindoRenderContext }>\n /** Derive the value exposed on `ctx.contexts[name]`. Defaults to the control values. */\n resolve?: (values: Values, ctx: WindoRenderContext) => Provided\n}\n\n// Contexts are each generic over a different control map `C`; TS has no existential\n// to hold `exists C. WindoContextDefinition<WindoControlValues<C>>`. `Values` sits in\n// contravariant positions (provider props, resolve arg) so no precise common supertype\n// exists — `any` is the single, contained variance hatch for this heterogeneous\n// registry. Mirrors WindoModule. Definition sites stay precise; this only erases at the\n// point of collection.\n// biome-ignore lint/suspicious/noExplicitAny: existential variance hatch for the heterogeneous context registry\nexport type WindoContextMap = Record<string, WindoContextDefinition<any, any>>\n\n/* ------------------------------------------------------------------ *\n * Render-time context\n * ------------------------------------------------------------------ */\n\nexport interface WindoViewport {\n width: number\n height: number\n name: 'mobile' | 'tablet' | 'desktop'\n}\n\n/** Console channel: `ctx.logger.log(…)` posts an entry to the chrome's Console tab. */\nexport interface WindoLogger {\n log: (...args: unknown[]) => void\n}\n\n/** How an action fires. `click` renders a toolbar button; the rest bind to the stage's pointer events. */\nexport type WindoActionTrigger = 'click' | 'enter' | 'exit' | 'hover'\n\nexport const WINDO_ACTION_TRIGGERS: readonly WindoActionTrigger[] = ['click', 'enter', 'exit', 'hover']\n\n/**\n * An out-of-band action that drives a component's state. `click` actions render as\n * toolbar buttons; `enter`/`exit`/`hover` bind to the stage's pointer events. `run`\n * receives the live ctx and an `active` flag — for `hover` it is `true` on\n * pointer-enter and `false` on pointer-leave; for the others it is always `true`.\n */\nexport interface WindoAction<State = unknown> {\n label: string\n /** Defaults to `click`. */\n on?: WindoActionTrigger\n run: (ctx: WindoRenderContext<State>, active: boolean) => void\n /** Greys out a `click` action's toolbar button. Evaluated against the live state. */\n disabled?: (ctx: WindoRenderContext<State>) => boolean\n}\n\n/** Live environment handed to every render-time function inside the iframe. */\nexport interface WindoRenderContext<State = unknown> {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n logger: WindoLogger\n /** Current component-local state, typed by the windo's `State` generic. */\n state: State\n /** Merge a patch into the component-local state and re-render. */\n setState: (patch: Partial<State>) => void\n /** Resolved values of opted-in contexts, keyed by context name. */\n contexts: Record<string, unknown>\n /**\n * Shared, cross-component state seeded from the config's `ctxState`. Unlike\n * `state` (per-windo, reset on selection), this persists across selection and\n * is global: any component can read it and write it via `setCtxState`. Use it\n * to drive providers that wrap every component — e.g. a theme provider toggled\n * from any component on the canvas.\n */\n ctxState: Record<string, unknown>\n /** Merge a patch into the shared `ctxState` and re-render every consumer. */\n setCtxState: (patch: Record<string, unknown>) => void\n /** Set the canvas colour scheme from a component or action. */\n setColorScheme: (scheme: 'light' | 'dark') => void\n /** Flip the canvas colour scheme between light and dark. */\n toggleTheme: () => void\n}\n\n/* ------------------------------------------------------------------ *\n * Authoring API\n * ------------------------------------------------------------------ */\n\n/** A variant: a label plus a partial prop patch. Renders in the gallery and is click-to-apply. */\nexport interface WindoVariant<Props> {\n label: string\n props: Partial<Props>\n}\n\n/** A row in the authored Props documentation table. */\nexport interface WindoPropDoc {\n name: string\n type: string\n default?: string\n desc?: string\n}\n\n/** A value that may be authored statically or as a context-aware `ctx => value` function resolved at render-time. */\nexport type Ctxual<T, State = unknown> = T | ((ctx: WindoRenderContext<State>) => T)\n\n/** The ctx surface available while resolving a windo's initial state — the render-time `state`/`setState` pair is excluded because it does not exist yet. */\nexport type WindoInitContext<State = unknown> = Omit<WindoRenderContext<State>, 'state' | 'setState'>\n\nexport type WindoDefaultProps<Props, State = unknown> = Ctxual<Props, State>\n\n/**\n * The object returned by a `windo(...)` factory.\n *\n * Keystone rule: the surrounding factory runs ONCE (definition-time) for static\n * fields (title, group, schema). Every function field below — `defaultProps`,\n * `actions`, `providers`, `component` — runs at render-time with the live `ctx`.\n * Never close over live values in the static factory body.\n */\nexport interface WindoDefinition<Props = unknown, State = unknown, GroupSlug extends string = string, Tag extends string = string> {\n title: string\n group: GroupSlug\n /** Tags this component carries. Each must be one of the config's declared `tags`. Drives the sidebar's tag filter. */\n tags?: Tag[]\n status?: WindoStatus\n description?: string\n deprecation?: string\n /** Where the component anchors in the canvas frame. Either a static placement or a function resolved with the live `ctx`. */\n placement?: Ctxual<WindoPlacement, State>\n /** Initial component-local state. Its shape is the `State` generic; `ctx.state`/`ctx.setState` derive from it. Either a static value or a function resolved with the init `ctx` (no `state`/`setState`) when the component is selected. */\n state?: State | ((ctx: WindoInitContext<State>) => State)\n /** Out-of-band actions that drive state: toolbar buttons (`click`) and stage pointer triggers (`enter`/`exit`/`hover`). */\n actions?: WindoAction<State>[]\n /** zod schema: validator + parser for the JSON-editable prop subset. `z.output ⊆ Props`. */\n configurableProps?: z.ZodType\n /** Full props incl. functions/JSX. The editor's JSON overrides merge on top. */\n defaultProps: WindoDefaultProps<Props, State>\n /** Names of provider contexts this component opts into. */\n uses?: string[]\n /** Gallery variants. Either a static array or a function resolved with the live `ctx` when the component is selected. */\n variants?: Ctxual<WindoVariant<Props>[], State>\n /** Authored documentation table (not derived from the schema). Either a static array or a function resolved with the live `ctx` when the component is selected. */\n props?: Ctxual<WindoPropDoc[], State>\n /** Optional authored code snippet for the Code tab, resolved with the JSON-editable values and the live `ctx`. */\n code?: (values: Props, ctx: WindoRenderContext<State>) => string\n /** A local provider wrapping just this windo (in addition to `uses`). */\n providers?: ComponentType<{ children: ReactNode; ctx: WindoRenderContext<State> }>\n component: (props: Props, ctx: WindoRenderContext<State>) => ReactNode\n}\n\n/** Argument handed to the `windo(w => ...)` factory. */\nexport interface WindoFactoryArg<Groups extends readonly WindoGroup[], Contexts extends WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups keyed by slug. */\n groups: Record<Groups[number]['slug'], WindoGroup>\n contexts: Contexts\n /** The config's declared tags, in declaration order. */\n tags: Tags\n}\n\n/**\n * The default export of a `*.windo.tsx` file. A branded, lazily-resolved\n * definition — the runtime calls `resolve(w)` with the config-derived factory arg.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance escape hatch for the heterogeneous WindoModule registry\nexport interface WindoModule<Props = any, State = any> {\n readonly __windo: true\n resolve: (w: WindoFactoryArg<readonly WindoGroup[], WindoContextMap>) => WindoDefinition<Props, State>\n}\n\n/* ------------------------------------------------------------------ *\n * Config\n * ------------------------------------------------------------------ */\n\nexport interface WindoConfig<Groups extends readonly WindoGroup[] = readonly WindoGroup[], Contexts extends WindoContextMap = WindoContextMap, Tags extends readonly string[] = readonly string[]> {\n /** Configured groups. A component's `group` must be one of these slugs. */\n groups: Groups\n /** Named contexts available to components. */\n contexts?: Contexts\n /** The set of tags components may be assigned. A component's `tags` must be drawn from this list; the sidebar filters by them. */\n tags?: Tags\n /** Initial shared state exposed on `ctx.ctxState`. Global across every component and persisted across selection — write it from any component via `ctx.setCtxState`. */\n ctxState?: Record<string, unknown>\n /** Glob(s) for discovery, relative to project root. Default `**\\/*.windo.tsx`. */\n include?: string | string[]\n /** Title shown in the workbench chrome. */\n title?: string\n /** Icon URL for the workbench logo and the browser favicon. When set, it replaces the built-in `wn` mark in both places. Any `<img>`/favicon source — a path, URL, or data URI. */\n faviconUrl?: string\n}\n\n/* ------------------------------------------------------------------ *\n * Schema descriptor (crosses the iframe boundary; renders the controls)\n * ------------------------------------------------------------------ */\n\nexport type WindoControlKind = 'string' | 'number' | 'boolean' | 'enum' | 'date' | 'array' | 'object' | 'unknown'\n\nexport interface WindoControlDescriptor {\n key: string\n kind: WindoControlKind\n optional: boolean\n options?: string[]\n min?: number\n max?: number\n description?: string\n}\n\nexport interface WindoSchemaDescriptor {\n fields: WindoControlDescriptor[]\n}\n\n/* ------------------------------------------------------------------ *\n * Runtime manifest + protocol payloads\n * ------------------------------------------------------------------ */\n\n/** Serialisable metadata for one action — drives the canvas toolbar. */\nexport interface WindoActionMeta {\n id: string\n label: string\n on: WindoActionTrigger\n}\n\n/** Static, serialisable metadata for one windo — drives the sidebar. */\nexport interface WindoManifestEntry {\n id: string\n title: string\n group: string\n tags: string[]\n status: WindoStatus\n description?: string\n deprecation?: string\n placement: WindoPlacement\n uses: string[]\n hasVariants: boolean\n actions: WindoActionMeta[]\n hasState: boolean\n}\n\nexport interface WindoVariantMeta {\n label: string\n props: Record<string, unknown>\n}\n\n/** Ambient environment pushed from the chrome down into the iframe. */\nexport interface WindoEnvState {\n colorScheme: 'light' | 'dark'\n viewport: WindoViewport\n reducedMotion: boolean\n direction: 'ltr' | 'rtl'\n locale: string\n /** Per-context control values, keyed by context name then control key. */\n contexts: Record<string, Record<string, unknown>>\n}\n\nexport interface WindoLogEntry {\n ts: number\n args: unknown[]\n}\n\nexport interface WindoFieldError {\n path: string\n message: string\n}\n\n/* ------------------------------------------------------------------ *\n * Context metadata (serialisable; drives the chrome's Context panel)\n * ------------------------------------------------------------------ */\n\nexport interface WindoContextControlMeta {\n key: string\n type: WindoControlType\n label?: string\n options?: string[]\n default: unknown\n min?: number\n max?: number\n step?: number\n}\n\nexport interface WindoContextMeta {\n name: string\n label?: string\n description?: string\n /** True when the context contributes controls (ambient values). */\n ambient: boolean\n /** True when the context mounts a provider (opt-in via `uses`). */\n hasProvider: boolean\n controls: WindoContextControlMeta[]\n}\n"],"mappings":";AAeO,SAAS,kBACd,QACiD;AACjD,WAAS,MACP,SAC2B;AAC3B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS,OAAK,QAAQ,CAAuD;AAAA,IAC/E;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,MAAM;AACzB;AAYO,SAAS,cAA2E,KAM/B;AAC1D,SAAO;AACT;AAQO,SAAS,oBAAuB;AACrC,SAAO,CAAkC,WAAiB;AAC5D;;;ACjDA,SAAS,SAAS;AAmBX,SAAS,eAAe,QAA6D;AAC1F,MAAI,CAAC,OAAQ,QAAO,EAAE,QAAQ,CAAC,EAAE;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,EAAE,aAAa,QAAQ,EAAE,IAAI,SAAS,iBAAiB,MAAM,CAAC;AAAA,EACvE,QAAQ;AACN,WAAO,EAAE,QAAQ,CAAC,EAAE;AAAA,EACtB;AACA,QAAM,OAAO,OAAO,IAAI;AACxB,QAAM,aAAa,KAAK,cAAc,CAAC;AACvC,QAAM,WAAW,IAAI,IAAI,KAAK,YAAY,CAAC,CAAC;AAC5C,QAAM,WAAW,WAAW,MAAM;AAClC,QAAM,SAAmC,OAAO,KAAK,UAAU,EAAE,IAAI,SAAO,UAAU,KAAK,WAAW,GAAG,GAAG,SAAS,IAAI,GAAG,GAAG,SAAS,GAAG,CAAC,CAAC;AAC7I,SAAO,EAAE,OAAO;AAClB;AAIA,SAAS,OAAO,MAA0B;AACxC,MAAI,KAAK,WAAY,QAAO;AAC5B,QAAM,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK;AAClD,MAAI,UAAU;AACZ,UAAM,YAAY,SAAS,KAAK,OAAK,EAAE,UAAU;AACjD,QAAI,UAAW,QAAO;AAAA,EACxB;AACA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AAO;AAAA,EACX;AACF;AAGA,SAAS,WAAW,QAAqD;AACvE,QAAM,QAAS,OAA+C;AAC9D,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO,CAAC;AACjD,QAAM,MAAwC,CAAC;AAC/C,aAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,UAAM,OAAO,WAAW,aAAa,MAAM,GAAG,CAAC,GAAG,IAAI;AACtD,QAAI,KAAM,KAAI,GAAG,IAAI;AAAA,EACvB;AACA,SAAO;AACT;;;ACjLO,IAAM,YAAY;AAiDlB,SAAS,eAAe,MAAqC;AAClE,SAAO,OAAO,SAAS,YAAY,SAAS,QAAS,KAA8B,WAAW;AAChG;AAEO,SAAS,cAAc,KAA4C;AACxE,SAAO,IAAI,QAAQ;AACrB;AAEO,SAAS,iBAAiB,KAA+C;AAC9E,SAAO,IAAI,QAAQ;AACrB;;;ACrDO,IAAM,iBAAyC,CAAC,UAAU,QAAQ,YAAY;AAYrF,IAAM,uBAAsD,CAAC,UAAU,QAAQ,OAAO,UAAU,QAAQ,SAAS,YAAY,aAAa,eAAe,cAAc;AAEhK,IAAM,mBAA8C,CAAC,GAAG,sBAAsB,GAAG,qBAAqB,IAAI,OAAK,GAAG,CAAC,UAA4B,CAAC;AA2EhJ,IAAM,wBAAuD,CAAC,SAAS,SAAS,QAAQ,OAAO;","names":[]}
|
package/dist/plugin.cjs
CHANGED
|
@@ -60,6 +60,7 @@ var CHROME_HTML = `<!doctype html>
|
|
|
60
60
|
<meta charset="utf-8" />
|
|
61
61
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
62
62
|
<title>windo</title>
|
|
63
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E" />
|
|
63
64
|
</head>
|
|
64
65
|
<body>
|
|
65
66
|
<div id="root"></div>
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA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;AACP,UAAI,OAAO,oBAAqB,QAAO,eAAe;AACtD,UAAI,OAAO,IAAI,MAAO,QAAO;AAC7B,UAAI,OAAO,IAAI,OAAQ,QAAO;AAC9B,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,QAAuB;AACrC,aAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;AAC/C,YAAI,IAAI,WAAW,MAAO,QAAO,KAAK;AACtC,cAAM,OAAO,IAAI,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC;AACxC,YAAI,OAAsB;AAC1B,YAAI,QAAQ,OAAO,QAAQ,cAAe,QAAO;AAAA,iBACxC,IAAI,WAAW,iBAAiB,EAAG,QAAO;AACnD,YAAI,SAAS,KAAM,QAAO,KAAK;AAC/B,YAAI;AACF,gBAAM,cAAc,MAAM,OAAO,mBAAmB,KAAK,IAAI;AAC7D,cAAI,aAAa;AACjB,cAAI,UAAU,gBAAgB,WAAW;AACzC,cAAI,IAAI,WAAW;AAAA,QACrB,SAAS,KAAK;AACZ,eAAK,GAAG;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,KAAC,oBAAAC,SAAY,GAAG,MAAM;AAC/B;AAEO,IAAM,cAAc;AAE3B,IAAO,iBAAQ;","names":["resolvePath","reactPlugin"]}
|
|
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 <link rel=\"icon\" type=\"image/svg+xml\" href=\"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E\" />\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,qBAA2B;AAC3B,uBAAmD;AACnD,0BAAwB;AASxB,IAAM,aAAa;AACnB,IAAM,sBAAsB,KAAK,UAAU;AAE3C,IAAM,oBAAoB,CAAC,mBAAmB,oBAAoB,oBAAoB,mBAAmB,kBAAkB;AAE3H,SAAS,WAAW,MAAc,WAAmC;AACnE,MAAI,UAAW,YAAO,6BAAW,SAAS,IAAI,gBAAY,iBAAAA,SAAY,MAAM,SAAS;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AAG,EAAE,CAAC;AACxC,YAAI,OAAsB;AAC1B,YAAI,QAAQ,OAAO,QAAQ,cAAe,QAAO;AAAA,iBACxC,IAAI,WAAW,iBAAiB,EAAG,QAAO;AACnD,YAAI,SAAS,KAAM,QAAO,KAAK;AAC/B,YAAI;AACF,gBAAM,cAAc,MAAM,OAAO,mBAAmB,KAAK,IAAI;AAC7D,cAAI,aAAa;AACjB,cAAI,UAAU,gBAAgB,WAAW;AACzC,cAAI,IAAI,WAAW;AAAA,QACrB,SAAS,KAAK;AACZ,eAAK,GAAG;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,KAAC,oBAAAC,SAAY,GAAG,MAAM;AAC/B;AAEO,IAAM,cAAc;AAE3B,IAAO,iBAAQ;","names":["resolvePath","reactPlugin"]}
|
package/dist/plugin.js
CHANGED
package/package.json
CHANGED
package/src/client/App.tsx
CHANGED
|
@@ -102,6 +102,23 @@ export function App() {
|
|
|
102
102
|
document.documentElement.setAttribute('data-theme', theme)
|
|
103
103
|
saveString('windo:theme', theme)
|
|
104
104
|
}, [theme])
|
|
105
|
+
// Reflect the configured title in the browser tab once the manifest arrives
|
|
106
|
+
// (the served HTML ships a static `windo` title; this updates it after hydration).
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
document.title = bridge.title || 'windo'
|
|
109
|
+
}, [bridge.title])
|
|
110
|
+
// A configured `faviconUrl` overrides the browser favicon; with none, the built-in
|
|
111
|
+
// `wn` mark baked into the served HTML stays in place.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!bridge.faviconUrl) return
|
|
114
|
+
let link = document.querySelector<HTMLLinkElement>("link[rel='icon']")
|
|
115
|
+
if (!link) {
|
|
116
|
+
link = document.createElement('link')
|
|
117
|
+
link.rel = 'icon'
|
|
118
|
+
document.head.appendChild(link)
|
|
119
|
+
}
|
|
120
|
+
link.href = bridge.faviconUrl
|
|
121
|
+
}, [bridge.faviconUrl])
|
|
105
122
|
useEffect(() => saveJSON('windo:selected', selected), [selected])
|
|
106
123
|
useEffect(() => saveJSON('windo:tags', selectedTags), [selectedTags])
|
|
107
124
|
useEffect(() => saveJSON('windo:tag-match', tagMatch), [tagMatch])
|
|
@@ -337,7 +354,7 @@ export function App() {
|
|
|
337
354
|
<div className="wb-app" style={accentVars} data-screen-label="Workbench">
|
|
338
355
|
<header className="wb-topbar">
|
|
339
356
|
<span className="wb-logo">
|
|
340
|
-
<WindoMark />
|
|
357
|
+
{bridge.faviconUrl ? <img className="wb-logo-mark" src={bridge.faviconUrl} alt="" /> : <WindoMark />}
|
|
341
358
|
{title}
|
|
342
359
|
<span className="wb-logo-sub">/ Workbench</span>
|
|
343
360
|
</span>
|
package/src/client/bridge.ts
CHANGED
|
@@ -15,6 +15,7 @@ export function useWindoBridge(iframeRef: RefObject<HTMLIFrameElement | null>):
|
|
|
15
15
|
const [ready, setReady] = useState(false)
|
|
16
16
|
const [readyNonce, setReadyNonce] = useState(0)
|
|
17
17
|
const [title, setTitle] = useState('')
|
|
18
|
+
const [faviconUrl, setFaviconUrl] = useState<string | null>(null)
|
|
18
19
|
const [groups, setGroups] = useState<WindoGroup[]>([])
|
|
19
20
|
const [tags, setTags] = useState<string[]>([])
|
|
20
21
|
const [contexts, setContexts] = useState<WindoContextMeta[]>([])
|
|
@@ -58,6 +59,7 @@ export function useWindoBridge(iframeRef: RefObject<HTMLIFrameElement | null>):
|
|
|
58
59
|
break
|
|
59
60
|
case 'manifest':
|
|
60
61
|
setTitle(msg.title)
|
|
62
|
+
setFaviconUrl(msg.faviconUrl)
|
|
61
63
|
setManifest(msg.entries)
|
|
62
64
|
setGroups(msg.groups)
|
|
63
65
|
setTags(msg.tags)
|
|
@@ -125,6 +127,7 @@ export function useWindoBridge(iframeRef: RefObject<HTMLIFrameElement | null>):
|
|
|
125
127
|
ready,
|
|
126
128
|
readyNonce,
|
|
127
129
|
title,
|
|
130
|
+
faviconUrl,
|
|
128
131
|
groups,
|
|
129
132
|
tags,
|
|
130
133
|
contexts,
|
|
@@ -30,6 +30,8 @@ export interface BridgeApi {
|
|
|
30
30
|
/** Increments each time the preview (re)signals ready — e.g. after an HMR or dep-optimize reload. The chrome re-syncs selection/props/env when it changes. */
|
|
31
31
|
readyNonce: number
|
|
32
32
|
title: string
|
|
33
|
+
/** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */
|
|
34
|
+
faviconUrl: string | null
|
|
33
35
|
groups: WindoGroup[]
|
|
34
36
|
/** The config's declared tag set (filter options for the sidebar). */
|
|
35
37
|
tags: string[]
|
package/src/plugin/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ const CHROME_HTML = `<!doctype html>
|
|
|
40
40
|
<meta charset="utf-8" />
|
|
41
41
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
42
42
|
<title>windo</title>
|
|
43
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22%23d83a2e%22%2F%3E%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-size%3D%2216%22%20font-weight%3D%22800%22%20font-family%3D%22system-ui%2C-apple-system%2CHelvetica%2CArial%2Csans-serif%22%20fill%3D%22%23f5c518%22%3Ewn%3C%2Ftext%3E%3C%2Fsvg%3E" />
|
|
43
44
|
</head>
|
|
44
45
|
<body>
|
|
45
46
|
<div id="root"></div>
|
package/src/preview/index.ts
CHANGED
package/src/protocol.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type WindoPreviewMessage =
|
|
|
24
24
|
dir: 'preview'
|
|
25
25
|
type: 'manifest'
|
|
26
26
|
title: string
|
|
27
|
+
/** Config `faviconUrl` — drives the chrome logo + browser favicon. `null` falls back to the built-in `wn` mark. */
|
|
28
|
+
faviconUrl: string | null
|
|
27
29
|
entries: WindoManifestEntry[]
|
|
28
30
|
groups: WindoGroup[]
|
|
29
31
|
tags: string[]
|
package/src/types.ts
CHANGED
|
@@ -248,6 +248,8 @@ export interface WindoConfig<Groups extends readonly WindoGroup[] = readonly Win
|
|
|
248
248
|
include?: string | string[]
|
|
249
249
|
/** Title shown in the workbench chrome. */
|
|
250
250
|
title?: string
|
|
251
|
+
/** Icon URL for the workbench logo and the browser favicon. When set, it replaces the built-in `wn` mark in both places. Any `<img>`/favicon source — a path, URL, or data URI. */
|
|
252
|
+
faviconUrl?: string
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
/* ------------------------------------------------------------------ *
|
|
@@ -1 +0,0 @@
|
|
|
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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