@aihu/css-engine 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,6 +34,39 @@ as a per-platform `optionalDependencies` package
|
|
|
34
34
|
resolved automatically at build time — no Rust toolchain required. In a monorepo
|
|
35
35
|
dev clone the engine falls back to the workspace `target/release` binary.
|
|
36
36
|
|
|
37
|
+
### Usage with `viteAihuPlugin`
|
|
38
|
+
|
|
39
|
+
When `@aihu/css-engine` is installed alongside `@aihu/app`, the compiler hook
|
|
40
|
+
inside `viteAihuPlugin` automatically scans every `.aihu` SFC and folds the
|
|
41
|
+
generated utility CSS into the build. **No additional plugin wiring is needed.**
|
|
42
|
+
|
|
43
|
+
There is one configuration knob you almost certainly want: **`shadowMode: 'none'`**.
|
|
44
|
+
Utility classes rely on the global cascade, so they must escape the per-component
|
|
45
|
+
shadow root. Forward this through `viteAihuPlugin`'s `css` option:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// vite.config.ts
|
|
49
|
+
import { viteAihuPlugin } from '@aihu/app'
|
|
50
|
+
import { defineConfig } from 'vite'
|
|
51
|
+
|
|
52
|
+
export default defineConfig({
|
|
53
|
+
plugins: [
|
|
54
|
+
viteAihuPlugin({
|
|
55
|
+
css: { shadowMode: 'none' },
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
If `compileSfc()` fails at build time (e.g. the native `aihu-css-core` binary
|
|
62
|
+
is unresolvable in your install), the compiler emits a one-shot warning to the
|
|
63
|
+
console — utility classes will not appear in the output until the binary is
|
|
64
|
+
restored. The build itself still succeeds.
|
|
65
|
+
|
|
66
|
+
See [`examples/css-engine-utility/`](../../examples/css-engine-utility) for a
|
|
67
|
+
minimal end-to-end demonstration, including an acceptance script that greps
|
|
68
|
+
the built CSS for the expected `.flex { display: flex }` rule.
|
|
69
|
+
|
|
37
70
|
### Local development
|
|
38
71
|
|
|
39
72
|
```bash
|
|
@@ -60,7 +93,7 @@ npm install @aihu/css-engine
|
|
|
60
93
|
bun add @aihu/css-engine
|
|
61
94
|
```
|
|
62
95
|
|
|
63
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
96
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
64
97
|
|
|
65
98
|
<!-- END_AUTOGEN: install -->
|
|
66
99
|
|
|
@@ -71,12 +104,12 @@ bun add @aihu/css-engine
|
|
|
71
104
|
|
|
72
105
|
| | |
|
|
73
106
|
|---|---|
|
|
74
|
-
| **Version** | `0.2.
|
|
107
|
+
| **Version** | `0.2.4` |
|
|
75
108
|
| **Tier** | D — Compiler — CSS engine (Tailwind v4 hard fork, WC-native scoped output) |
|
|
76
109
|
| **Published files** | 5 entries |
|
|
77
110
|
| **License** | MIT |
|
|
78
111
|
|
|
79
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
112
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
80
113
|
|
|
81
114
|
<!-- END_AUTOGEN: stats -->
|
|
82
115
|
|
|
@@ -95,7 +128,7 @@ bun add @aihu/css-engine
|
|
|
95
128
|
| `./runtime/cn` | `./dist/runtime/cn.js` | `—` |
|
|
96
129
|
| `./runtime/progressive` | `./dist/runtime/progressive.js` | `—` |
|
|
97
130
|
|
|
98
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
131
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
99
132
|
|
|
100
133
|
<!-- END_AUTOGEN: exports -->
|
|
101
134
|
|
|
@@ -115,7 +148,7 @@ bun add @aihu/css-engine
|
|
|
115
148
|
- `@aihu/css-engine-linux-x64-gnu` — `0.1.2`
|
|
116
149
|
- `@aihu/css-engine-win32-x64-msvc` — `0.1.2`
|
|
117
150
|
|
|
118
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
151
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
119
152
|
|
|
120
153
|
<!-- END_AUTOGEN: deps -->
|
|
121
154
|
|
|
@@ -128,7 +161,7 @@ bun add @aihu/css-engine
|
|
|
128
161
|
- [@aihu/compiler](../compiler)
|
|
129
162
|
- [Aihu framework root](../../README.md)
|
|
130
163
|
|
|
131
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
164
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
132
165
|
|
|
133
166
|
<!-- END_AUTOGEN: see-also -->
|
|
134
167
|
|
|
@@ -139,6 +172,6 @@ bun add @aihu/css-engine
|
|
|
139
172
|
|
|
140
173
|
MIT — see [LICENSE](../../LICENSE).
|
|
141
174
|
|
|
142
|
-
<sub><i>Auto-generated against `@aihu/css-engine@0.2.
|
|
175
|
+
<sub><i>Auto-generated against `@aihu/css-engine@0.2.4`.</i></sub>
|
|
143
176
|
|
|
144
177
|
<!-- END_AUTOGEN: license -->
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["r","n","i","t","e","compileToAst"],"sources":["../../compiler/dist/index.js","../src/index.ts"],"sourcesContent":["import{execFileSync as e}from\"node:child_process\";import{basename as t,dirname as n,resolve as r}from\"node:path\";import{fileURLToPath as i}from\"node:url\";const a=process.platform===`win32`?`.exe`:``,o=process.env.SCRIBE_COMPILE_BIN??r(n(i(import.meta.url)),`../bin/aihu-compile${a}`);function s(e,t){return e.replace(/(defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\([^]*\\))\\s*\\)/,(e,n)=>`${n}, { shadowMode: '${t}' })`)}function c(e){return/\\b(?:signal|computed|effect|setSignal|onMount|onCleanup)\\s*\\(/.test(e)?`interactive`:`static`}function l(e){let t=/defineElement\\(\\s*['\"]([^'\"]+)['\"]/m.exec(e);return t?t[1]??null:null}function u(e,t){let n=e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hmrReplace`)||n.push(`_hmrReplace`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}).replace(/\\bdefineComponent\\(/,`defineComponent(__aihu_setup__ = `),r=`\nexport { __aihu_setup__ as default }\n\nif (typeof __DEV__ !== 'undefined' && __DEV__ && import.meta.hot) {\n import.meta.hot.accept((newModule) => {\n if (!newModule) return\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const newSetup = (newModule as any)['default']\n if (typeof newSetup !== 'function') return\n document.querySelectorAll(${JSON.stringify(t)}).forEach((el) => {\n _hmrReplace(el as HTMLElement, newSetup)\n })\n })\n}\n`;return`let __aihu_setup__: ((ctx: any) => any) | undefined\n`+n+r}function d(e,t){let n=e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hydrateOnVisible`)||n.push(`_hydrateOnVisible`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}),r=n.replace(/defineElement\\(\\s*('[^']+'|\"[^\"]+\")\\s*,\\s*defineComponent\\(/,(e,t)=>`defineElement(${t}, __aihu_wrap_defer__(defineComponent(`);if(r===n)return e;let i=r.replace(/\\)\\s*\\)\\s*\\nexport\\s/,`)))\nexport `);return i===r&&(i=r.replace(/\\)\\s*\\)\\s*$/,`)))\n`)),i===r?e:`\n// Plan 3.3 (Islands) — defer attribute support. Wraps the constructor\n// returned by defineComponent so instances bearing the \\`defer\\` attribute\n// hydrate lazily via IntersectionObserver. Bare instances retain the\n// eager Plan 3.2 hydration path.\nfunction __aihu_wrap_defer__<T extends typeof HTMLElement>(Ctor: T): T {\n const orig = (Ctor.prototype as unknown as { connectedCallback?: () => void }).connectedCallback\n if (typeof orig !== 'function') return Ctor\n ;(Ctor.prototype as unknown as { connectedCallback: () => void }).connectedCallback = function (this: HTMLElement) {\n if (this.hasAttribute('defer')) {\n _hydrateOnVisible(this, () => orig.call(this))\n } else {\n orig.call(this)\n }\n }\n return Ctor\n}\n`+i}function f(e,t){if(!/defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\(/.test(e))return e;let n=e.replace(/^\\s*import\\s*\\{[^}]*\\}\\s*from\\s*'@aihu\\/runtime'\\s*;?\\s*$/m,``).replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}),r=JSON.stringify(t);return`// SCRIBE_STATIC_ISLAND — zero @aihu/runtime references\\n${n.replace(/defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\(/,`customElements.define(${r}, class extends HTMLElement {\\n connectedCallback() {\\n const root = this.attachShadow({ mode: 'open' })\\n const __aihu_setup__ = (`).replace(/\\)\\s*\\)\\s*$/,`)\n mount(__aihu_setup__({ host: root, element: this }), root)\n }\n})\n`)}`}function p(n,r,i){let a=[`--stdin`,`--tag`,t(r,`.aihu`),`--path`,r];return i?.sidecarOut&&a.push(`--sidecar-out`,i.sidecarOut),{code:e(o,a,{input:n,encoding:`utf8`}),map:null}}function m(e){return e.replace(/\\\\/g,`\\\\\\\\`).replace(/`/g,\"\\\\`\").replace(/\\$\\{/g,\"\\\\${\")}function h(e,t){if(!t.trim())return e;let n=m(t),r=/(__style__\\.replaceSync\\(`)[^]*?(`\\);)/;if(r.test(e))return e.replace(r,(e,t,r)=>`${t}${n}${r}`);if(/defineComponent\\(\\s*\\((_ctx|ctx)\\)\\s*=>\\s*\\{/.exec(e)==null)return e;let i=e.split(`\n`),a=-1;for(let e=i.length-1;e>=0;e--){let t=(i[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){a=e;break}}let o=`const __style__ = new CSSStyleSheet();\\n__style__.replaceSync(\\`${n}\\`);`;a===-1?i.unshift(o):i.splice(a+1,0,o);let s=i.join(`\n`);return s=s.replace(/defineComponent\\(\\s*\\((?:_ctx|ctx)\\)\\s*=>\\s*\\{/,`defineComponent((ctx) => {\n (ctx.host as ShadowRoot).adoptedStyleSheets = [__style__];`),s}function g(n,r){let i=[`--stdin`,`--tag`,r?t(r,`.aihu`):`Component`,`--ast-json`];r&&i.push(`--path`,r);let a=e(o,i,{input:n,encoding:`utf8`});return JSON.parse(a)}function _(e){let t;t=e.includes(`from '@aihu/arbor'`)?e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}):`import { mount } from '@aihu/arbor'\\n${e}`,/import\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/.test(t)?t=t.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/signals'/,(e,t)=>{if(e.startsWith(`import type`))return e;let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`signal`)||n.push(`signal`),`import { ${n.join(`, `)} } from '@aihu/signals'`}):/import.*from\\s*'@aihu\\/signals'/.test(t)?/import\\s+type\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/.test(t)&&!t.match(/import\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/)&&(t=t.replace(/(import\\s+type\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals')/,(e,t)=>`${t}\\nimport { signal } from '@aihu/signals'`)):t=t.replace(/import\\s*\\{[^}]*\\}\\s*from\\s*'@aihu\\/arbor'/,e=>`${e}\\nimport { signal } from '@aihu/signals'`),t=t.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_setMount`)||n.push(`_setMount`),n.includes(`_setSignal`)||n.push(`_setSignal`),`import { ${n.join(`, `)} } from '@aihu/runtime'`});let n=t.split(`\n`),r=-1;for(let e=n.length-1;e>=0;e--){let t=(n[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){r=e;break}}return r!==-1&&(n.splice(r+1,0,`_setMount(mount)`,`_setSignal(signal)`,``),t=n.join(`\n`)),t}let v;async function y(e,t){if(v===null)return``;if(v===void 0)try{v=await import(`@aihu/css-engine`)}catch{return v=null,``}try{return process.env.SCRIBE_COMPILE_BIN??(process.env.SCRIBE_COMPILE_BIN=o),v.compileSfc(e,t)}catch{return``}}function b(e){let t=e?.islands!==!1,n=e?.shadowMode;return{name:`aihu-compiler`,enforce:`pre`,transform(e,r){let i=r.split(`?`)[0];if(i.endsWith(`.aihu`))return(async()=>{let r=p(e,i,{sidecarOut:`${i}.ts`}),a=n==null?r.code:s(r.code,n),o=await y(e,i);o&&(a=h(a,o));let m=l(a),g;t&&m!==null&&c(a)===`static`?g=f(a,m):m===null?(g=a,g=_(g)):(g=u(a,m),g=d(g,m),g=_(g));try{let e=await import(`vite`);return`transformWithEsbuild`in e&&typeof e.transformWithEsbuild==`function`?{code:(await e.transformWithEsbuild(g,`component.ts`,{target:`esnext`,sourcemap:!1})).code,map:null}:{code:g,moduleType:`ts`,map:null}}catch{return{code:g,map:null}}})()}}}export{d as _buildDeferredHydration,f as _buildStaticIsland,c as _classifyIsland,h as _foldCssEngineStyles,_ as _injectAutoWiring,s as _injectShadowMode,b as aihuCompilerPlugin,g as compileToAst,p as transform};\n//# sourceMappingURL=index.js.map","import { execFileSync } from 'node:child_process'\nimport { accessSync, constants, existsSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { compileToAst } from '@aihu/compiler'\n\nexport {\n defineStylePack,\n type StylePack,\n type StylePackInput,\n type TokenMap,\n} from './define-style-pack.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n// ---------------------------------------------------------------------------\n// Platform support matrix\n// ---------------------------------------------------------------------------\n//\n// Maps process.platform + process.arch to the per-platform npm package that\n// ships the prebuilt `aihu-css-compile` executable, plus the binary's filename\n// inside that package. Mirrors @aihu/server/src/native.ts detectPlatform() and\n// the package directory names under packages/css-engine/npm/<platform>/.\n//\n// Unlike @aihu/server (a napi `.node` addon loaded via require), the css engine\n// invokes `aihu-css-compile` as a CLI SUBPROCESS (execFileSync against the\n// executable on disk). So the platform package exposes a raw executable file,\n// and we resolve its absolute PATH — we never `require()` the binary itself.\n\ninterface PlatformDescriptor {\n readonly platformId: string\n readonly packageName: string\n /** Executable filename inside the platform package. */\n readonly binFile: string\n}\n\nfunction detectPlatform(): PlatformDescriptor | null {\n if (typeof process === 'undefined' || !process.platform || !process.arch) {\n return null\n }\n const key = `${process.platform}-${process.arch}`\n switch (key) {\n case 'darwin-arm64':\n return {\n platformId: 'darwin-arm64',\n packageName: '@aihu/css-engine-darwin-arm64',\n binFile: 'aihu-css-compile',\n }\n case 'darwin-x64':\n return {\n platformId: 'darwin-x64',\n packageName: '@aihu/css-engine-darwin-x64',\n binFile: 'aihu-css-compile',\n }\n case 'linux-x64':\n // We only ship glibc; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-x64-gnu',\n packageName: '@aihu/css-engine-linux-x64-gnu',\n binFile: 'aihu-css-compile',\n }\n case 'win32-x64':\n return {\n platformId: 'win32-x64-msvc',\n packageName: '@aihu/css-engine-win32-x64-msvc',\n binFile: 'aihu-css-compile.exe',\n }\n default:\n return null\n }\n}\n\nlet _binPath: string | null = null\n\n/**\n * Whether `candidate` is a usable `aihu-css-compile` executable — NOT merely a\n * present file.\n *\n * The per-platform packages (`@aihu/css-engine-<platform>`) carry a placeholder\n * `aihu-css-compile` in source; the real prebuilt binary is only injected by\n * the release CI. Once those packages become resolvable in the workspace (e.g.\n * after a `bun.lock` refresh that pins them as optionalDependencies), a bare\n * `existsSync` would happily return the non-executable placeholder, which then\n * blows up with EACCES inside `spawnSync`/`execFileSync`. So we must verify the\n * candidate is actually runnable before accepting it.\n *\n * POSIX: require the execute bit (X_OK). A zero-byte/text placeholder without\n * +x fails here and we fall through to the dev `target/` fallback.\n *\n * Windows: there is no execute bit — `accessSync(_, X_OK)` is effectively\n * always true — so we additionally require a non-empty regular file, which\n * still rejects a zero-byte placeholder.\n */\nexport function isUsableExecutable(candidate: string): boolean {\n try {\n const st = statSync(candidate)\n if (!st.isFile() || st.size === 0) return false\n accessSync(candidate, constants.X_OK)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Resolve the absolute path to the `aihu-css-compile` executable.\n *\n * Resolution order:\n * 1. The per-platform optionalDependency package\n * (`@aihu/css-engine-<platform>`) shipped to npm consumers — resolved via\n * `createRequire(...).resolve('<pkg>/package.json')` so it works in both\n * ESM and CJS and respects the consumer's node_modules layout.\n * 2. Dev fallback: the monorepo workspace `target/release|debug/` — only\n * present in a dev clone with a Rust toolchain (`cargo build --release -p\n * aihu-css-core`). Kept so in-repo builds + tests work without publishing.\n *\n * If the current platform is SUPPORTED but neither path yields a binary, throws\n * a structured error pointing at the missing optionalDependency (mirrors\n * @aihu/server's failure-loud contract). If the platform is UNSUPPORTED, the\n * error lists the dev fallback so source builds still have a clear remedy.\n */\nfunction resolveBinary(): string {\n if (_binPath !== null) return _binPath\n\n const descriptor = detectPlatform()\n\n // 1. Per-platform optionalDependency package (the published-consumer path).\n //\n // Accept the candidate ONLY if it is a usable executable. A present-but-\n // non-executable placeholder (the in-source stub that becomes resolvable once\n // the per-platform packages are pinned in the lockfile) must NOT be returned —\n // doing so spawns a non-executable file and fails with EACCES. In that case we\n // deliberately fall THROUGH to the dev `target/` fallback below.\n if (descriptor) {\n const requireFn = createRequire(import.meta.url)\n try {\n const pkgJson = requireFn.resolve(`${descriptor.packageName}/package.json`)\n const candidate = join(dirname(pkgJson), descriptor.binFile)\n if (isUsableExecutable(candidate)) {\n _binPath = candidate\n return _binPath\n }\n } catch {\n // Package not installed (optionalDependency skipped for this platform, or\n // a partial install). Fall through to the dev/source path, then error.\n }\n }\n\n // 2. Dev fallback: monorepo workspace target/. Only exists in a dev clone.\n const ext = process.platform === 'win32' ? '.exe' : ''\n const devCandidates = [\n resolve(__dirname, '../../../target/release', `aihu-css-compile${ext}`),\n resolve(__dirname, '../../../target/debug', `aihu-css-compile${ext}`),\n ]\n for (const c of devCandidates) {\n if (existsSync(c)) {\n _binPath = c\n return _binPath\n }\n }\n\n throw buildMissingBinaryError(descriptor, devCandidates)\n}\n\nfunction buildMissingBinaryError(\n descriptor: PlatformDescriptor | null,\n devCandidates: string[],\n): Error {\n if (descriptor === null) {\n return new Error(\n `[@aihu/css-engine] No prebuilt aihu-css-compile binary for this platform.\\n\\n` +\n ` Platform: ${typeof process !== 'undefined' ? `${process.platform}-${process.arch}` : 'unknown'}\\n\\n` +\n ` @aihu/css-engine ships prebuilt binaries for darwin-arm64, darwin-x64,\\n` +\n ` linux-x64-gnu (glibc) and win32-x64-msvc. Your platform is not in that set.\\n\\n` +\n ` To build from source you need a Rust toolchain, then run from the repo root:\\n` +\n ` cargo build --release -p aihu-css-core\\n\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n }\n return new Error(\n `[@aihu/css-engine] Native CSS compiler binary not found for this platform.\\n\\n` +\n ` Platform: ${descriptor.platformId}\\n` +\n ` Expected package: ${descriptor.packageName}\\n` +\n ` Expected file: ${descriptor.packageName}/${descriptor.binFile}\\n\\n` +\n ` This binary is distributed as an optionalDependency of @aihu/css-engine.\\n` +\n ` Your package manager may have skipped it (optionalDependencies are\\n` +\n ` silently dropped on install failure).\\n\\n` +\n ` To reinstall:\\n` +\n ` npm install @aihu/css-engine\\n` +\n ` # or: pnpm install or: bun install\\n\\n` +\n ` If you are working in the aihu monorepo, build from source instead:\\n` +\n ` cargo build --release -p aihu-css-core\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n}\n\n/**\n * Compile a list of utility class names to CSS.\n *\n * Plan 1 bootstrap — supports a hardcoded subset; see crates/aihu-css-core/src/tokens.rs.\n * Plan 2 wires the AST scanner so callers pass `.aihu` SFC ASTs instead of raw class lists.\n *\n * @param classes - utility class names like `['bg-primary', 'p-4']`\n * @returns CSS string with one rule per known class\n */\nexport function compile(classes: string[]): string {\n if (classes.length === 0) return ''\n\n const bin = resolveBinary()\n const input = classes.join('\\n')\n const result = execFileSync(bin, [], {\n input,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'inherit'],\n })\n return result\n}\n\n/**\n * Compile a `.aihu` SFC source string to scoped, shadow-DOM-embedded CSS.\n *\n * Pipeline (Plan 2 Task 9): `compileToAst(source)` (from `@aihu/compiler`)\n * → AST JSON → `aihu-css-compile --ast-json` → scoped CSS. The output is the\n * per-SFC stylesheet the compiler folds into the component's shadow `<style>`:\n * `:host`-level theme tokens, variant-resolved utility rules, and the folded\n * authored `@style` block. There is NO global utility stylesheet.\n *\n * @param source - the `.aihu` SFC source text\n * @param id - optional file path/id (used to derive the tag stem + `@route` checks)\n * @returns the scoped CSS string for the SFC\n */\nexport function compileSfc(source: string, id?: string): string {\n const ast = compileToAst(source, id)\n const bin = resolveBinary()\n return execFileSync(bin, ['--ast-json'], {\n input: JSON.stringify(ast),\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'inherit'],\n })\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["r","n","i","t","e","compileToAst"],"sources":["../../compiler/dist/index.js","../src/index.ts"],"sourcesContent":["import{execFileSync as e}from\"node:child_process\";import{basename as t,dirname as n,resolve as r}from\"node:path\";import{fileURLToPath as i}from\"node:url\";const a=process.platform===`win32`?`.exe`:``,o=process.env.SCRIBE_COMPILE_BIN??r(n(i(import.meta.url)),`../bin/aihu-compile${a}`);function s(e,t){return e.replace(/(defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\([^]*\\))\\s*\\)/,(e,n)=>`${n}, { shadowMode: '${t}' })`)}function c(e){return/\\b(?:signal|computed|effect|setSignal|onMount|onCleanup)\\s*\\(/.test(e)?`interactive`:`static`}function l(e){let t=/defineElement\\(\\s*['\"]([^'\"]+)['\"]/m.exec(e);return t?t[1]??null:null}function u(e,t){let n=e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hmrReplace`)||n.push(`_hmrReplace`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}).replace(/\\bdefineComponent\\(/,`defineComponent(__aihu_setup__ = `),r=`\nexport { __aihu_setup__ as default }\n\nif (typeof __DEV__ !== 'undefined' && __DEV__ && import.meta.hot) {\n import.meta.hot.accept((newModule) => {\n if (!newModule) return\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const newSetup = (newModule as any)['default']\n if (typeof newSetup !== 'function') return\n document.querySelectorAll(${JSON.stringify(t)}).forEach((el) => {\n _hmrReplace(el as HTMLElement, newSetup)\n })\n })\n}\n`;return`let __aihu_setup__: ((ctx: any) => any) | undefined\n`+n+r}function d(e,t){let n=e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hydrateOnVisible`)||n.push(`_hydrateOnVisible`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}),r=n.replace(/defineElement\\(\\s*('[^']+'|\"[^\"]+\")\\s*,\\s*defineComponent\\(/,(e,t)=>`defineElement(${t}, __aihu_wrap_defer__(defineComponent(`);if(r===n)return e;let i=r.replace(/\\)\\s*\\)\\s*\\nexport\\s/,`)))\nexport `);return i===r&&(i=r.replace(/\\)\\s*\\)\\s*$/,`)))\n`)),i===r?e:`\n// Plan 3.3 (Islands) — defer attribute support. Wraps the constructor\n// returned by defineComponent so instances bearing the \\`defer\\` attribute\n// hydrate lazily via IntersectionObserver. Bare instances retain the\n// eager Plan 3.2 hydration path.\nfunction __aihu_wrap_defer__<T extends typeof HTMLElement>(Ctor: T): T {\n const orig = (Ctor.prototype as unknown as { connectedCallback?: () => void }).connectedCallback\n if (typeof orig !== 'function') return Ctor\n ;(Ctor.prototype as unknown as { connectedCallback: () => void }).connectedCallback = function (this: HTMLElement) {\n if (this.hasAttribute('defer')) {\n _hydrateOnVisible(this, () => orig.call(this))\n } else {\n orig.call(this)\n }\n }\n return Ctor\n}\n`+i}function f(e,t){if(!/defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\(/.test(e))return e;let n=e.replace(/^\\s*import\\s*\\{[^}]*\\}\\s*from\\s*'@aihu\\/runtime'\\s*;?\\s*$/m,``).replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}),r=JSON.stringify(t);return`// SCRIBE_STATIC_ISLAND — zero @aihu/runtime references\\n${n.replace(/defineElement\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*defineComponent\\(/,`customElements.define(${r}, class extends HTMLElement {\\n connectedCallback() {\\n const root = this.attachShadow({ mode: 'open' })\\n const __aihu_setup__ = (`).replace(/\\)\\s*\\)\\s*$/,`)\n mount(__aihu_setup__({ host: root, element: this }), root)\n }\n})\n`)}`}function p(n,r,i){let a=[`--stdin`,`--tag`,t(r,`.aihu`),`--path`,r];return i?.sidecarOut&&a.push(`--sidecar-out`,i.sidecarOut),{code:e(o,a,{input:n,encoding:`utf8`}),map:null}}function m(e){return e.replace(/\\\\/g,`\\\\\\\\`).replace(/`/g,\"\\\\`\").replace(/\\$\\{/g,\"\\\\${\")}function h(e,t){if(!t.trim())return e;let n=m(t),r=/(__style__\\.replaceSync\\(`)[^]*?(`\\);)/;if(r.test(e))return e.replace(r,(e,t,r)=>`${t}${n}${r}`);if(/defineComponent\\(\\s*\\((_ctx|ctx)\\)\\s*=>\\s*\\{/.exec(e)==null)return e;let i=e.split(`\n`),a=-1;for(let e=i.length-1;e>=0;e--){let t=(i[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){a=e;break}}let o=`const __style__ = new CSSStyleSheet();\\n__style__.replaceSync(\\`${n}\\`);`;a===-1?i.unshift(o):i.splice(a+1,0,o);let s=i.join(`\n`);return s=s.replace(/defineComponent\\(\\s*\\((?:_ctx|ctx)\\)\\s*=>\\s*\\{/,`defineComponent((ctx) => {\n (ctx.host as ShadowRoot).adoptedStyleSheets = [__style__];`),s}function g(n,r){let i=[`--stdin`,`--tag`,r?t(r,`.aihu`):`Component`,`--ast-json`];r&&i.push(`--path`,r);let a=e(o,i,{input:n,encoding:`utf8`});return JSON.parse(a)}function _(e){let t;t=e.includes(`from '@aihu/arbor'`)?e.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}):`import { mount } from '@aihu/arbor'\\n${e}`,/import\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/.test(t)?t=t.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/signals'/,(e,t)=>{if(e.startsWith(`import type`))return e;let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`signal`)||n.push(`signal`),`import { ${n.join(`, `)} } from '@aihu/signals'`}):/import.*from\\s*'@aihu\\/signals'/.test(t)?/import\\s+type\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/.test(t)&&!t.match(/import\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals'/)&&(t=t.replace(/(import\\s+type\\s+\\{[^}]*\\}\\s+from\\s+'@aihu\\/signals')/,(e,t)=>`${t}\\nimport { signal } from '@aihu/signals'`)):t=t.replace(/import\\s*\\{[^}]*\\}\\s*from\\s*'@aihu\\/arbor'/,e=>`${e}\\nimport { signal } from '@aihu/signals'`),t=t.replace(/import\\s*\\{([^}]*)\\}\\s*from\\s*'@aihu\\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_setMount`)||n.push(`_setMount`),n.includes(`_setSignal`)||n.push(`_setSignal`),`import { ${n.join(`, `)} } from '@aihu/runtime'`});let n=t.split(`\n`),r=-1;for(let e=n.length-1;e>=0;e--){let t=(n[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){r=e;break}}return r!==-1&&(n.splice(r+1,0,`_setMount(mount)`,`_setSignal(signal)`,``),t=n.join(`\n`)),t}let v,y=!1;async function b(e,t){if(v===null)return``;if(v===void 0)try{v=await import(`@aihu/css-engine`)}catch{return v=null,``}try{return process.env.SCRIBE_COMPILE_BIN??(process.env.SCRIBE_COMPILE_BIN=o),v.compileSfc(e,t)}catch(e){if(!y){y=!0;let t=e instanceof Error?e.message:String(e);console.warn(`[@aihu/compiler] @aihu/css-engine is installed but compileSfc() failed; utility classes will not emit. Original error: ${t}\\nHint: ensure the native css-core binary is installed (install/upgrade @aihu/css-engine + its per-platform optional dep, or run \\`cargo build --release -p aihu-css-core\\` in a dev clone).`)}return``}}function x(e){let t=e?.islands!==!1,n=e?.shadowMode;return{name:`aihu-compiler`,enforce:`pre`,transform(e,r){let i=r.split(`?`)[0];if(i.endsWith(`.aihu`))return(async()=>{let r=p(e,i,{sidecarOut:`${i}.ts`}),a=n==null?r.code:s(r.code,n),o=await b(e,i);o&&(a=h(a,o));let m=l(a),g;t&&m!==null&&c(a)===`static`?g=f(a,m):m===null?(g=a,g=_(g)):(g=u(a,m),g=d(g,m),g=_(g));try{let e=await import(`vite`);return`transformWithEsbuild`in e&&typeof e.transformWithEsbuild==`function`?{code:(await e.transformWithEsbuild(g,`component.ts`,{target:`esnext`,sourcemap:!1})).code,map:null}:{code:g,moduleType:`ts`,map:null}}catch{return{code:g,map:null}}})()}}}export{d as _buildDeferredHydration,f as _buildStaticIsland,c as _classifyIsland,h as _foldCssEngineStyles,_ as _injectAutoWiring,s as _injectShadowMode,x as aihuCompilerPlugin,g as compileToAst,p as transform};\n//# sourceMappingURL=index.js.map","import { execFileSync } from 'node:child_process'\nimport { accessSync, constants, existsSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { compileToAst } from '@aihu/compiler'\n\nexport {\n defineStylePack,\n type StylePack,\n type StylePackInput,\n type TokenMap,\n} from './define-style-pack.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n// ---------------------------------------------------------------------------\n// Platform support matrix\n// ---------------------------------------------------------------------------\n//\n// Maps process.platform + process.arch to the per-platform npm package that\n// ships the prebuilt `aihu-css-compile` executable, plus the binary's filename\n// inside that package. Mirrors @aihu/server/src/native.ts detectPlatform() and\n// the package directory names under packages/css-engine/npm/<platform>/.\n//\n// Unlike @aihu/server (a napi `.node` addon loaded via require), the css engine\n// invokes `aihu-css-compile` as a CLI SUBPROCESS (execFileSync against the\n// executable on disk). So the platform package exposes a raw executable file,\n// and we resolve its absolute PATH — we never `require()` the binary itself.\n\ninterface PlatformDescriptor {\n readonly platformId: string\n readonly packageName: string\n /** Executable filename inside the platform package. */\n readonly binFile: string\n}\n\nfunction detectPlatform(): PlatformDescriptor | null {\n if (typeof process === 'undefined' || !process.platform || !process.arch) {\n return null\n }\n const key = `${process.platform}-${process.arch}`\n switch (key) {\n case 'darwin-arm64':\n return {\n platformId: 'darwin-arm64',\n packageName: '@aihu/css-engine-darwin-arm64',\n binFile: 'aihu-css-compile',\n }\n case 'darwin-x64':\n return {\n platformId: 'darwin-x64',\n packageName: '@aihu/css-engine-darwin-x64',\n binFile: 'aihu-css-compile',\n }\n case 'linux-x64':\n // We only ship glibc; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-x64-gnu',\n packageName: '@aihu/css-engine-linux-x64-gnu',\n binFile: 'aihu-css-compile',\n }\n case 'win32-x64':\n return {\n platformId: 'win32-x64-msvc',\n packageName: '@aihu/css-engine-win32-x64-msvc',\n binFile: 'aihu-css-compile.exe',\n }\n default:\n return null\n }\n}\n\nlet _binPath: string | null = null\n\n/**\n * Whether `candidate` is a usable `aihu-css-compile` executable — NOT merely a\n * present file.\n *\n * The per-platform packages (`@aihu/css-engine-<platform>`) carry a placeholder\n * `aihu-css-compile` in source; the real prebuilt binary is only injected by\n * the release CI. Once those packages become resolvable in the workspace (e.g.\n * after a `bun.lock` refresh that pins them as optionalDependencies), a bare\n * `existsSync` would happily return the non-executable placeholder, which then\n * blows up with EACCES inside `spawnSync`/`execFileSync`. So we must verify the\n * candidate is actually runnable before accepting it.\n *\n * POSIX: require the execute bit (X_OK). A zero-byte/text placeholder without\n * +x fails here and we fall through to the dev `target/` fallback.\n *\n * Windows: there is no execute bit — `accessSync(_, X_OK)` is effectively\n * always true — so we additionally require a non-empty regular file, which\n * still rejects a zero-byte placeholder.\n */\nexport function isUsableExecutable(candidate: string): boolean {\n try {\n const st = statSync(candidate)\n if (!st.isFile() || st.size === 0) return false\n accessSync(candidate, constants.X_OK)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Resolve the absolute path to the `aihu-css-compile` executable.\n *\n * Resolution order:\n * 1. The per-platform optionalDependency package\n * (`@aihu/css-engine-<platform>`) shipped to npm consumers — resolved via\n * `createRequire(...).resolve('<pkg>/package.json')` so it works in both\n * ESM and CJS and respects the consumer's node_modules layout.\n * 2. Dev fallback: the monorepo workspace `target/release|debug/` — only\n * present in a dev clone with a Rust toolchain (`cargo build --release -p\n * aihu-css-core`). Kept so in-repo builds + tests work without publishing.\n *\n * If the current platform is SUPPORTED but neither path yields a binary, throws\n * a structured error pointing at the missing optionalDependency (mirrors\n * @aihu/server's failure-loud contract). If the platform is UNSUPPORTED, the\n * error lists the dev fallback so source builds still have a clear remedy.\n */\nfunction resolveBinary(): string {\n if (_binPath !== null) return _binPath\n\n const descriptor = detectPlatform()\n\n // 1. Per-platform optionalDependency package (the published-consumer path).\n //\n // Accept the candidate ONLY if it is a usable executable. A present-but-\n // non-executable placeholder (the in-source stub that becomes resolvable once\n // the per-platform packages are pinned in the lockfile) must NOT be returned —\n // doing so spawns a non-executable file and fails with EACCES. In that case we\n // deliberately fall THROUGH to the dev `target/` fallback below.\n if (descriptor) {\n const requireFn = createRequire(import.meta.url)\n try {\n const pkgJson = requireFn.resolve(`${descriptor.packageName}/package.json`)\n const candidate = join(dirname(pkgJson), descriptor.binFile)\n if (isUsableExecutable(candidate)) {\n _binPath = candidate\n return _binPath\n }\n } catch {\n // Package not installed (optionalDependency skipped for this platform, or\n // a partial install). Fall through to the dev/source path, then error.\n }\n }\n\n // 2. Dev fallback: monorepo workspace target/. Only exists in a dev clone.\n const ext = process.platform === 'win32' ? '.exe' : ''\n const devCandidates = [\n resolve(__dirname, '../../../target/release', `aihu-css-compile${ext}`),\n resolve(__dirname, '../../../target/debug', `aihu-css-compile${ext}`),\n ]\n for (const c of devCandidates) {\n if (existsSync(c)) {\n _binPath = c\n return _binPath\n }\n }\n\n throw buildMissingBinaryError(descriptor, devCandidates)\n}\n\nfunction buildMissingBinaryError(\n descriptor: PlatformDescriptor | null,\n devCandidates: string[],\n): Error {\n if (descriptor === null) {\n return new Error(\n `[@aihu/css-engine] No prebuilt aihu-css-compile binary for this platform.\\n\\n` +\n ` Platform: ${typeof process !== 'undefined' ? `${process.platform}-${process.arch}` : 'unknown'}\\n\\n` +\n ` @aihu/css-engine ships prebuilt binaries for darwin-arm64, darwin-x64,\\n` +\n ` linux-x64-gnu (glibc) and win32-x64-msvc. Your platform is not in that set.\\n\\n` +\n ` To build from source you need a Rust toolchain, then run from the repo root:\\n` +\n ` cargo build --release -p aihu-css-core\\n\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n }\n return new Error(\n `[@aihu/css-engine] Native CSS compiler binary not found for this platform.\\n\\n` +\n ` Platform: ${descriptor.platformId}\\n` +\n ` Expected package: ${descriptor.packageName}\\n` +\n ` Expected file: ${descriptor.packageName}/${descriptor.binFile}\\n\\n` +\n ` This binary is distributed as an optionalDependency of @aihu/css-engine.\\n` +\n ` Your package manager may have skipped it (optionalDependencies are\\n` +\n ` silently dropped on install failure).\\n\\n` +\n ` To reinstall:\\n` +\n ` npm install @aihu/css-engine\\n` +\n ` # or: pnpm install or: bun install\\n\\n` +\n ` If you are working in the aihu monorepo, build from source instead:\\n` +\n ` cargo build --release -p aihu-css-core\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n}\n\n/**\n * Compile a list of utility class names to CSS.\n *\n * Plan 1 bootstrap — supports a hardcoded subset; see crates/aihu-css-core/src/tokens.rs.\n * Plan 2 wires the AST scanner so callers pass `.aihu` SFC ASTs instead of raw class lists.\n *\n * @param classes - utility class names like `['bg-primary', 'p-4']`\n * @returns CSS string with one rule per known class\n */\nexport function compile(classes: string[]): string {\n if (classes.length === 0) return ''\n\n const bin = resolveBinary()\n const input = classes.join('\\n')\n const result = execFileSync(bin, [], {\n input,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'inherit'],\n })\n return result\n}\n\n/**\n * Compile a `.aihu` SFC source string to scoped, shadow-DOM-embedded CSS.\n *\n * Pipeline (Plan 2 Task 9): `compileToAst(source)` (from `@aihu/compiler`)\n * → AST JSON → `aihu-css-compile --ast-json` → scoped CSS. The output is the\n * per-SFC stylesheet the compiler folds into the component's shadow `<style>`:\n * `:host`-level theme tokens, variant-resolved utility rules, and the folded\n * authored `@style` block. There is NO global utility stylesheet.\n *\n * @param source - the `.aihu` SFC source text\n * @param id - optional file path/id (used to derive the tag stem + `@route` checks)\n * @returns the scoped CSS string for the SFC\n */\nexport function compileSfc(source: string, id?: string): string {\n const ast = compileToAst(source, id)\n const bin = resolveBinary()\n return execFileSync(bin, ['--ast-json'], {\n input: JSON.stringify(ast),\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'inherit'],\n })\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aihu/css-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aihu/compiler": "0.5.
|
|
40
|
+
"@aihu/compiler": "0.5.3"
|
|
41
41
|
},
|
|
42
42
|
"optionalDependencies": {
|
|
43
43
|
"@aihu/css-engine-darwin-arm64": "0.1.2",
|