@animus-ui/vite-plugin 0.1.0-next.16 → 0.1.0-next.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAM3C,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,8FAA8F;IAC9F,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,qGAAqG;IACrG,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAwUD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA45BnE;AAED,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvE,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAM3C,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,8FAA8F;IAC9F,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,qGAAqG;IACrG,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAwUD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAg6BnE;AAED,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvE,eAAe,aAAa,CAAC"}
package/dist/index.mjs CHANGED
@@ -433,13 +433,21 @@ function animusExtract(options) {
433
433
  const gsThemeFile = join(tmpdir(), `animus-gs-theme-${gsTmp}.json`);
434
434
  const gsOut = join(tmpdir(), `animus-global-${gsTmp}.json`);
435
435
  writeFileSync(gsThemeFile, themeJson);
436
- const gsCandidates = [join(__pluginDir, "resolve-global-styles.ts"), join(__pluginDir, "..", "src", "resolve-global-styles.ts")];
436
+ const gsNames = [
437
+ "resolve-global-styles.mjs",
438
+ "resolve-global-styles.js",
439
+ "resolve-global-styles.ts"
440
+ ];
441
+ const gsCandidates = gsNames.map((n) => join(__pluginDir, n));
437
442
  try {
438
443
  const pkgDir = dirname(__require.resolve("@animus-ui/vite-plugin/package.json", { paths: [rootDir] }));
439
- gsCandidates.push(join(pkgDir, "src", "resolve-global-styles.ts"));
444
+ for (const n of gsNames) {
445
+ gsCandidates.push(join(pkgDir, "dist", n));
446
+ gsCandidates.push(join(pkgDir, "src", n));
447
+ }
440
448
  } catch {}
441
449
  const gsScriptPath = gsCandidates.find((p) => existsSync(p));
442
- if (!gsScriptPath) throw new Error(`resolve-global-styles.ts not found in: ${gsCandidates.join(", ")}`);
450
+ if (!gsScriptPath) throw new Error(`resolve-global-styles not found in: ${gsCandidates.join(", ")}`);
443
451
  execSync(`bun run "${gsScriptPath}" "${resolvedSystemPath}" "${gsThemeFile}" "${gsOut}"`, {
444
452
  cwd: rootDir,
445
453
  encoding: "utf-8"
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-global-styles.d.ts","sourceRoot":"","sources":["../src/resolve-global-styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
1
+ {"version":3,"file":"resolve-global-styles.d.ts","sourceRoot":"","sources":["../src/resolve-global-styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgLH,OAAO,EAAE,CAAC"}
@@ -0,0 +1,104 @@
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ //#region src/resolve-global-styles.ts
3
+ /**
4
+ * Standalone script executed via `bun run` to resolve global styles.
5
+ *
6
+ * Usage: bun run resolve-global-styles.ts <system-path> <theme-json> <output-file>
7
+ *
8
+ * Imports the system module, extracts globalStyles from .serialize(),
9
+ * resolves prop shorthand (bg → background-color, etc.) using the full
10
+ * prop config + theme + transforms, and writes the resolved CSS to output.
11
+ *
12
+ * @keyframes blocks are serialized as raw CSS (no prop resolution needed).
13
+ */
14
+ const [systemPath, themeJsonPath, outputFile] = process.argv.slice(2);
15
+ if (!systemPath || !themeJsonPath || !outputFile) {
16
+ process.stderr.write("Usage: bun run resolve-global-styles.ts <system-path> <theme-json-path> <output-file>\n");
17
+ process.exit(1);
18
+ }
19
+ const mod = await import(systemPath);
20
+ const ds = mod.ds || mod.default || mod.system;
21
+ if (!ds || !ds.serialize) throw new Error("Module does not export a SystemInstance with .serialize()");
22
+ const cfg = ds.serialize();
23
+ const flat = JSON.parse(readFileSync(themeJsonPath, "utf-8"));
24
+ const propConfig = JSON.parse(cfg.propConfig);
25
+ const transforms = cfg.transforms || {};
26
+ const gs = cfg.globalStyles || {};
27
+ const variableMap = {};
28
+ for (const [tokenPath, value] of Object.entries(flat)) if (typeof value === "string" && value.startsWith("var(") && value.endsWith(")")) variableMap[tokenPath] = value.slice(4, -1);
29
+ function camelToKebab(s) {
30
+ if (s.startsWith("Webkit")) return "-webkit-" + camelToKebab(s.slice(6));
31
+ return s.replace(/[A-Z]/g, (m, i) => (i > 0 ? "-" : "") + m.toLowerCase());
32
+ }
33
+ /**
34
+ * Serialize a raw nested block (e.g. @keyframes) without prop resolution.
35
+ * Just camelToKebab on property names — no scale lookups, no transforms.
36
+ */
37
+ function serializeRawBlock(obj, indent) {
38
+ const lines = [];
39
+ for (const [key, val] of Object.entries(obj)) if (typeof val === "object" && val !== null) {
40
+ lines.push(`${indent}${key} {`);
41
+ for (const [p, v] of Object.entries(val)) lines.push(`${indent} ${camelToKebab(p)}: ${v};`);
42
+ lines.push(`${indent}}`);
43
+ }
44
+ return lines.join("\n");
45
+ }
46
+ /**
47
+ * Resolve {scale.path} and {scale.path/alpha} token aliases in a CSS value string.
48
+ * Mirrors the Rust theme_resolver's resolve_token_aliases logic.
49
+ */
50
+ function resolveTokenAliases(value) {
51
+ if (!value.includes("{")) return value;
52
+ return value.replace(/\{([^}]+)\}/g, (_match, content) => {
53
+ const slashIdx = content.indexOf("/");
54
+ const tokenPath = slashIdx >= 0 ? content.slice(0, slashIdx) : content;
55
+ const alpha = slashIdx >= 0 ? parseInt(content.slice(slashIdx + 1), 10) : null;
56
+ const dotIdx = tokenPath.indexOf(".");
57
+ const flatKey = dotIdx >= 0 ? tokenPath.slice(0, dotIdx) + "." + tokenPath.slice(dotIdx + 1).replace(/\./g, "-") : tokenPath;
58
+ let resolved;
59
+ if (variableMap[flatKey]) resolved = `var(${variableMap[flatKey]})`;
60
+ else if (flat[flatKey] != null) resolved = flat[flatKey];
61
+ else return `{${content}}`;
62
+ if (alpha === 0) return "transparent";
63
+ if (alpha != null && alpha !== 100) return `color-mix(in srgb, ${resolved} ${alpha}%, transparent)`;
64
+ return resolved;
65
+ });
66
+ }
67
+ /**
68
+ * Resolve a block of selectors → style objects using prop config + theme.
69
+ * @keyframes selectors are delegated to serializeRawBlock.
70
+ */
71
+ function resolveBlock(selectors) {
72
+ const rules = [];
73
+ for (const [selector, styleObj] of Object.entries(selectors)) {
74
+ if (selector.startsWith("@keyframes")) {
75
+ rules.push(`${selector} {\n${serializeRawBlock(styleObj, " ")}\n}`);
76
+ continue;
77
+ }
78
+ const decls = [];
79
+ for (const [prop, raw] of Object.entries(styleObj)) {
80
+ const config = propConfig[prop];
81
+ const cssProps = config?.properties?.length ? config.properties : config ? [config.property] : [prop];
82
+ let resolved = raw;
83
+ if (config?.scale) {
84
+ const key = config.scale + "." + raw;
85
+ if (flat[key] != null) resolved = flat[key];
86
+ }
87
+ if (config?.transform && transforms[config.transform]) {
88
+ const fn = transforms[config.transform];
89
+ const input = typeof resolved === "string" && !isNaN(Number(resolved)) ? Number(resolved) : resolved;
90
+ resolved = String(fn(input));
91
+ } else resolved = String(resolved);
92
+ resolved = resolveTokenAliases(resolved);
93
+ for (const cssProp of cssProps) decls.push(` ${camelToKebab(cssProp)}: ${resolved};`);
94
+ }
95
+ if (decls.length) rules.push(`${selector} {\n${decls.join("\n")}\n}`);
96
+ }
97
+ return rules.join("\n\n");
98
+ }
99
+ const result = {};
100
+ if (gs.reset) result.reset = resolveBlock(gs.reset);
101
+ if (gs.global) result.global = resolveBlock(gs.global);
102
+ writeFileSync(outputFile, JSON.stringify(result));
103
+ //#endregion
104
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animus-ui/vite-plugin",
3
- "version": "0.1.0-next.16",
3
+ "version": "0.1.0-next.17",
4
4
  "description": "Animus static CSS extraction Vite plugin",
5
5
  "author": "codecaaron <airrobb@gmail.com>",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "vite": ">=5.0.0"
26
26
  },
27
27
  "dependencies": {
28
- "@animus-ui/extract": "0.1.0-next.16",
28
+ "@animus-ui/extract": "0.1.0-next.17",
29
29
  "browserslist": "^4.24.0",
30
30
  "lightningcss": "^1.29.0"
31
31
  }