@animus-ui/vite-plugin 0.1.0-next.38 → 0.1.0-next.40

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 ADDED
@@ -0,0 +1,44 @@
1
+ # @animus-ui/vite-plugin
2
+
3
+ Static CSS extraction plugin for Vite. Transforms `@animus-ui/system` builder chains into static CSS at build time — zero runtime style injection.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @animus-ui/vite-plugin @animus-ui/system
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```tsx
14
+ // vite.config.ts
15
+ import react from '@vitejs/plugin-react';
16
+ import { animusExtract } from '@animus-ui/vite-plugin';
17
+ import { defineConfig } from 'vite';
18
+
19
+ export default defineConfig({
20
+ plugins: [
21
+ react(),
22
+ animusExtract({ system: './src/ds.ts' }),
23
+ ],
24
+ });
25
+ ```
26
+
27
+ The `system` option points to the file that exports your built system instance. The plugin loads this file in a subprocess to serialize the prop config and theme data for the Rust extraction pipeline.
28
+
29
+ ## What It Does
30
+
31
+ 1. **Build time**: Analyzes all files importing from `@animus-ui/system`, extracts static styles into CSS with `@layer` ordering
32
+ 2. **Dev server**: Runs extraction on startup, holds results in memory, serves CSS via virtual module
33
+ 3. **Transforms**: Resolves `__TRANSFORM__` placeholders using your system's named transform functions
34
+ 4. **Global styles**: Emits global styles (reset, base) from your exported `createGlobalStyles()` configuration
35
+
36
+ ## Important
37
+
38
+ - Do **not** add React resolve aliases to `vite.config.ts` — they break the extraction transform pipeline
39
+ - After system config changes, restart the dev server (the subprocess runs at `buildStart`)
40
+ - Run `bun run clean:light` if styles seem stale (clears `.vite` cache)
41
+
42
+ ## License
43
+
44
+ MIT
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAI3C,MAAM,WAAW,oBAAoB;IACnC;;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ACnB;AA6ID,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA4+BnE;AAED,eAAe,aAAa,CAAC"}
package/dist/index.mjs CHANGED
@@ -113,6 +113,8 @@ function animusExtract(options) {
113
113
  let contextualVarsJson = "{}";
114
114
  let configJson = "{}";
115
115
  let groupRegistryJson = "{}";
116
+ let selectorAliasesJson = null;
117
+ let selectorOrderJson = null;
116
118
  let isProd = false;
117
119
  let rootDir = "";
118
120
  const verbose = options.verbose || process.env.ANIMUS_DEBUG === "1" || process.env.ANIMUS_DEBUG === "true";
@@ -150,7 +152,7 @@ function animusExtract(options) {
150
152
  try {
151
153
  const ts = Date.now();
152
154
  const tmpOut = join(tmpdir(), `animus-system-${ts}.json`);
153
- execSubprocess(`const m = require(${JSON.stringify(resolvedSystemPath)});\nconst exportNames = Object.keys(m);\nconst candidates = exportNames.filter(k => m[k] && typeof m[k].toConfig === 'function');\nif (candidates.length === 0) {\n throw new Error('[animus-extract] No SystemInstance found. Exports: [' + exportNames.join(', ') + ']. None have a .toConfig() method. A SystemInstance is created by: export const ds = createSystem().build()');\n}\nif (candidates.length > 1) {\n throw new Error('[animus-extract] Multiple SystemInstance candidates found: [' + candidates.join(', ') + ']. Specify which one to use.');\n}\nconst ds = m[candidates[0]];\nconst cfg = ds.toConfig();\nconst tokens = m.tokens || m.theme || null;\nconst serialized = tokens && typeof tokens.serialize === 'function' ? tokens.serialize() : null;\nconst globalStyleBlocks = {};\nfor (const [key, val] of Object.entries(m)) {\n if (val && typeof val === 'object' && val.__brand === 'GlobalStyleBlock') {\n globalStyleBlocks[key] = val.styles;\n }\n}\nrequire('fs').writeFileSync(${JSON.stringify(tmpOut)}, JSON.stringify({\n propConfig: cfg.propConfig,\n groupRegistry: cfg.groupRegistry,\n serialized: serialized,\n transformNames: Object.keys(cfg.transforms || {}),\n globalStyleBlocks: Object.keys(globalStyleBlocks).length > 0 ? globalStyleBlocks : null\n}));\n`, rootDir);
155
+ execSubprocess(`const m = require(${JSON.stringify(resolvedSystemPath)});\nconst exportNames = Object.keys(m);\nconst candidates = exportNames.filter(k => m[k] && typeof m[k].toConfig === 'function');\nif (candidates.length === 0) {\n throw new Error('[animus-extract] No SystemInstance found. Exports: [' + exportNames.join(', ') + ']. None have a .toConfig() method. A SystemInstance is created by: export const ds = createSystem().build()');\n}\nif (candidates.length > 1) {\n throw new Error('[animus-extract] Multiple SystemInstance candidates found: [' + candidates.join(', ') + ']. Specify which one to use.');\n}\nconst ds = m[candidates[0]];\nconst cfg = ds.toConfig();\nconst tokens = m.tokens || m.theme || null;\nconst serialized = tokens && typeof tokens.serialize === 'function' ? tokens.serialize() : null;\nconst globalStyleBlocks = {};\nfor (const [key, val] of Object.entries(m)) {\n if (val && typeof val === 'object' && val.__brand === 'GlobalStyleBlock') {\n globalStyleBlocks[key] = val.styles;\n }\n}\nrequire('fs').writeFileSync(${JSON.stringify(tmpOut)}, JSON.stringify({\n propConfig: cfg.propConfig,\n groupRegistry: cfg.groupRegistry,\n serialized: serialized,\n transformNames: Object.keys(cfg.transforms || {}),\n selectorAliases: cfg.selectorAliases || null,\n selectorOrder: cfg.selectorOrder || null,\n globalStyleBlocks: Object.keys(globalStyleBlocks).length > 0 ? globalStyleBlocks : null\n}));\n`, rootDir);
154
156
  const result = readFileSync(tmpOut, "utf-8");
155
157
  try {
156
158
  unlinkSync(tmpOut);
@@ -158,6 +160,8 @@ function animusExtract(options) {
158
160
  const parsed = JSON.parse(result);
159
161
  configJson = parsed.propConfig;
160
162
  groupRegistryJson = parsed.groupRegistry;
163
+ selectorAliasesJson = parsed.selectorAliases || null;
164
+ selectorOrderJson = parsed.selectorOrder || null;
161
165
  if (parsed.serialized) {
162
166
  themeJson = parsed.serialized.scalesJson;
163
167
  variableMapJson = parsed.serialized.variableMapJson;
@@ -233,7 +237,7 @@ function animusExtract(options) {
233
237
  runtime_import: "@animus-ui/system",
234
238
  css_module_id: "virtual:animus/styles.css"
235
239
  });
236
- const manifestJson = analyzeProject(JSON.stringify(fileEntries), themeJson, variableMapJson, contextualVarsJson || null, configJson, groupRegistryJson, JSON.stringify(packageMap), !isProd, options.prefix || null, emitterConfig);
240
+ const manifestJson = analyzeProject(JSON.stringify(fileEntries), themeJson, variableMapJson, contextualVarsJson || null, configJson, groupRegistryJson, JSON.stringify(packageMap), !isProd, options.prefix || null, emitterConfig, selectorAliasesJson, selectorOrderJson);
237
241
  storedManifest = JSON.parse(manifestJson);
238
242
  storedManifestJson = manifestJson;
239
243
  storedSystemPropMapJson = JSON.stringify(storedManifest?.system_prop_map ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animus-ui/vite-plugin",
3
- "version": "0.1.0-next.38",
3
+ "version": "0.1.0-next.40",
4
4
  "description": "Animus static CSS extraction Vite plugin",
5
5
  "author": "codecaaron <airrobb@gmail.com>",
6
6
  "license": "MIT",
@@ -13,10 +13,21 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
+ "homepage": "https://github.com/codecaaron/animus/tree/main/packages/vite-plugin#readme",
16
17
  "repository": {
17
18
  "type": "git",
18
- "url": "git+https://github.com/codecaaron/animus"
19
+ "url": "git+https://github.com/codecaaron/animus",
20
+ "directory": "packages/vite-plugin"
19
21
  },
22
+ "keywords": [
23
+ "vite",
24
+ "vite-plugin",
25
+ "css",
26
+ "css-in-js",
27
+ "zero-runtime",
28
+ "styled",
29
+ "animus"
30
+ ],
20
31
  "scripts": {
21
32
  "build": "bun run build:ts",
22
33
  "build:ts": "tsdown && tsc -p tsconfig.build.json",
@@ -26,8 +37,8 @@
26
37
  "vite": ">=5.0.0"
27
38
  },
28
39
  "dependencies": {
29
- "@animus-ui/extract": "0.1.0-next.38",
30
- "@animus-ui/system": "0.1.0-next.38",
40
+ "@animus-ui/extract": "0.1.0-next.40",
41
+ "@animus-ui/system": "0.1.0-next.40",
31
42
  "browserslist": "^4.24.0",
32
43
  "lightningcss": "^1.29.0"
33
44
  }