@animus-ui/vite-plugin 0.1.0-next.1 → 0.1.0-next.10

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":"AAcA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAM3C,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,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;CACnB;AA0RD,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAq5BxE;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":"AAcA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAM3C,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,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;CACnB;AA6RD,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CA+gCxE;AAED,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvE,eAAe,aAAa,CAAC"}
package/dist/index.mjs CHANGED
@@ -65,15 +65,11 @@ function buildVariableCss(theme) {
65
65
  }
66
66
  if (rootLines.length > 0) parts.push(`:root {\n${rootLines.join("\n")}\n}`);
67
67
  }
68
- if (theme._tokens?.modes != null && typeof theme._tokens.modes === "object") {
69
- const defaultMode = typeof theme.mode === "string" ? theme.mode : Object.keys(theme._tokens.modes)[0];
70
- for (const [modeName, modeTokens] of Object.entries(theme._tokens.modes)) {
71
- if (modeName === defaultMode) continue;
72
- if (modeTokens == null || typeof modeTokens !== "object") continue;
73
- const modeLines = [];
74
- flattenModeTokens(modeLines, modeTokens, "");
75
- if (modeLines.length > 0) parts.push(`[data-color-mode="${modeName}"] {\n${modeLines.join("\n")}\n}`);
76
- }
68
+ if (theme._tokens?.modes != null && typeof theme._tokens.modes === "object") for (const [modeName, modeTokens] of Object.entries(theme._tokens.modes)) {
69
+ if (modeTokens == null || typeof modeTokens !== "object") continue;
70
+ const modeLines = [];
71
+ flattenModeTokens(modeLines, modeTokens, "");
72
+ if (modeLines.length > 0) parts.push(`[data-color-mode="${modeName}"] {\n${modeLines.join("\n")}\n}`);
77
73
  }
78
74
  return parts.join("\n\n");
79
75
  }
@@ -118,6 +114,8 @@ const VIRTUAL_COMPONENTS_ID = "virtual:animus/components.js";
118
114
  const RESOLVED_COMPONENTS_ID = "\0virtual:animus/components.js";
119
115
  const VIRTUAL_BRIDGE_ID = "virtual:animus/hmr-bridge.js";
120
116
  const RESOLVED_BRIDGE_ID = "\0virtual:animus/hmr-bridge.js";
117
+ const VIRTUAL_SYSTEM_PROPS_ID = "virtual:animus/system-props";
118
+ const RESOLVED_SYSTEM_PROPS_ID = "\0virtual:animus/system-props";
121
119
  const DEFAULT_EXTENSIONS = new Set([
122
120
  ".ts",
123
121
  ".tsx",
@@ -226,7 +224,7 @@ const UNITLESS_PROPERTIES = new Set([
226
224
  * Numbers inside CSS function calls (cubic-bezier, rgb, calc, etc.) are skipped.
227
225
  */
228
226
  function applyUnitFallback(css) {
229
- return css.replace(/([a-z-]+)\s*:\s*([^;]+);/g, (match, prop, value) => {
227
+ return css.replace(/([a-z-]+)\s*:\s*([^;{}]+);/g, (match, prop, value) => {
230
228
  if (UNITLESS_PROPERTIES.has(prop)) return match;
231
229
  let depth = 0;
232
230
  let fixed = "";
@@ -332,6 +330,9 @@ function animusExtract(options = {}) {
332
330
  let storedManifestJson = "";
333
331
  let resolvedComponentCss = "";
334
332
  let storedSheets = null;
333
+ let storedSystemPropMapJson = "{}";
334
+ let storedDynamicPropsJson = "{}";
335
+ let storedTransformsSource = "";
335
336
  const fileCache = /* @__PURE__ */ new Map();
336
337
  let packageMap = {};
337
338
  let bridgeInjected = false;
@@ -424,7 +425,7 @@ function animusExtract(options = {}) {
424
425
  const ts = Date.now();
425
426
  const tmpScript = join(tmpdir(), `animus-system-${ts}.js`);
426
427
  const tmpOut = join(tmpdir(), `animus-system-${ts}.json`);
427
- writeFileSync(tmpScript, `const m = require(${JSON.stringify(resolvedSystemPath)});\nconst ds = m.ds || m.default || m.system;\nif (!ds || !ds.serialize) { throw new Error('Module does not export a SystemInstance with .serialize()'); }\nconst cfg = ds.serialize();\nrequire('fs').writeFileSync(${JSON.stringify(tmpOut)}, JSON.stringify({\n propConfig: cfg.propConfig,\n groupRegistry: cfg.groupRegistry,\n tokens: cfg.tokens,\n transformNames: Object.keys(cfg.transforms || {}),\n globalStyles: cfg.globalStyles || null\n}));\n`);
428
+ writeFileSync(tmpScript, `const m = require(${JSON.stringify(resolvedSystemPath)});\nconst ds = m.ds || m.default || m.system;\nif (!ds || !ds.serialize) { throw new Error('Module does not export a SystemInstance with .serialize()'); }\nconst cfg = ds.serialize();\nconst tokens = m.tokens || m.theme || null;\nrequire('fs').writeFileSync(${JSON.stringify(tmpOut)}, JSON.stringify({\n propConfig: cfg.propConfig,\n groupRegistry: cfg.groupRegistry,\n tokens: tokens,\n transformNames: Object.keys(cfg.transforms || {}),\n globalStyles: cfg.globalStyles || null\n}));\n`);
428
429
  execSync(`bun run "${tmpScript}"`, {
429
430
  cwd: rootDir,
430
431
  encoding: "utf-8"
@@ -442,7 +443,7 @@ function animusExtract(options = {}) {
442
443
  themeJson = result.scalesJson;
443
444
  variableMapJson = result.variableMapJson;
444
445
  variableCss = result.variableCss;
445
- }
446
+ } else if (logger) logger.warn("[animus] No tokens export found in system module — CSS variables will not be generated. Export your theme as `tokens` or `theme`.");
446
447
  if (parsed.globalStyles) {
447
448
  const hasReset = parsed.globalStyles.reset && Object.keys(parsed.globalStyles.reset).length > 0;
448
449
  const hasGlobal = parsed.globalStyles.global && Object.keys(parsed.globalStyles.global).length > 0;
@@ -494,6 +495,32 @@ function animusExtract(options = {}) {
494
495
  const manifestJson = analyzeProject(JSON.stringify(fileEntries), themeJson, variableMapJson, configJson, groupRegistryJson, JSON.stringify(packageMap), !isProd);
495
496
  storedManifest = JSON.parse(manifestJson);
496
497
  storedManifestJson = manifestJson;
498
+ storedSystemPropMapJson = JSON.stringify(storedManifest?.system_prop_map ?? {});
499
+ const dynamicProps = storedManifest?.dynamic_props ?? {};
500
+ const newDynamicPropsJson = JSON.stringify(dynamicProps);
501
+ if (newDynamicPropsJson !== storedDynamicPropsJson) {
502
+ storedDynamicPropsJson = newDynamicPropsJson;
503
+ const usedTransformNames = /* @__PURE__ */ new Set();
504
+ for (const meta of Object.values(dynamicProps)) if (meta.transform_name) usedTransformNames.add(meta.transform_name);
505
+ if (storedManifest?.components) {
506
+ for (const comp of Object.values(storedManifest.components)) if (comp.replacement) {
507
+ const matches = comp.replacement.matchAll(/transforms\.(\w+)/g);
508
+ for (const match of matches) usedTransformNames.add(match[1]);
509
+ }
510
+ }
511
+ if (usedTransformNames.size > 0 && transformRegistry.size > 0) {
512
+ const transformParts = [];
513
+ for (const name of usedTransformNames) {
514
+ const fn = transformRegistry.get(name);
515
+ if (fn) try {
516
+ transformParts.push(`${JSON.stringify(name)}: ${fn.toString()}`);
517
+ } catch {
518
+ console.warn(`[animus-extract] Could not serialize transform "${name}" — dynamic props using it will fall back to raw values`);
519
+ }
520
+ }
521
+ storedTransformsSource = transformParts.length > 0 ? `{ ${transformParts.join(", ")} }` : "{}";
522
+ } else storedTransformsSource = "{}";
523
+ }
497
524
  bridgeInjected = false;
498
525
  storedSheets = storedManifest?.sheets ?? null;
499
526
  const rawCss = storedManifest?.css || "";
@@ -643,6 +670,7 @@ function animusExtract(options = {}) {
643
670
  if (id === VIRTUAL_CSS_ID) return RESOLVED_CSS_ID;
644
671
  if (id === VIRTUAL_COMPONENTS_ID) return RESOLVED_COMPONENTS_ID;
645
672
  if (id === VIRTUAL_BRIDGE_ID) return RESOLVED_BRIDGE_ID;
673
+ if (id === VIRTUAL_SYSTEM_PROPS_ID) return RESOLVED_SYSTEM_PROPS_ID;
646
674
  return null;
647
675
  },
648
676
  load(id) {
@@ -694,6 +722,22 @@ if (import.meta.hot) {
694
722
  });
695
723
  }
696
724
  `;
725
+ if (id === RESOLVED_SYSTEM_PROPS_ID) {
726
+ let moduleSource = `export const systemPropMap = ${storedSystemPropMapJson};\nexport const systemPropGroups = ${groupRegistryJson};`;
727
+ if (storedDynamicPropsJson !== "{}") {
728
+ const dynamicProps = JSON.parse(storedDynamicPropsJson);
729
+ const configEntries = {};
730
+ for (const [propName, meta] of Object.entries(dynamicProps)) configEntries[propName] = {
731
+ varName: meta.var_name,
732
+ slotClass: meta.slot_class,
733
+ ...meta.transform_name ? { transformName: meta.transform_name } : {},
734
+ ...meta.scale_values && Object.keys(meta.scale_values).length > 0 ? { scaleValues: meta.scale_values } : {}
735
+ };
736
+ moduleSource += `\nexport const dynamicPropConfig = ${JSON.stringify(configEntries)};`;
737
+ moduleSource += `\nexport const transforms = ${storedTransformsSource};`;
738
+ }
739
+ return moduleSource;
740
+ }
697
741
  return null;
698
742
  },
699
743
  transform(code, id) {
@@ -764,6 +808,11 @@ if (import.meta.hot) {
764
808
  hmrServer.moduleGraph.invalidateModule(compModule);
765
809
  geologicalModules.push(compModule);
766
810
  }
811
+ const sysPropModule = hmrServer.moduleGraph.getModuleById(RESOLVED_SYSTEM_PROPS_ID);
812
+ if (sysPropModule) {
813
+ hmrServer.moduleGraph.invalidateModule(sysPropModule);
814
+ geologicalModules.push(sysPropModule);
815
+ }
767
816
  return geologicalModules;
768
817
  }
769
818
  let source;
@@ -794,6 +843,11 @@ if (import.meta.hot) {
794
843
  hmrServer.moduleGraph.invalidateModule(compModule);
795
844
  modulesToUpdate.push(compModule);
796
845
  }
846
+ const sysPropModule = hmrServer.moduleGraph.getModuleById(RESOLVED_SYSTEM_PROPS_ID);
847
+ if (sysPropModule) {
848
+ hmrServer.moduleGraph.invalidateModule(sysPropModule);
849
+ modulesToUpdate.push(sysPropModule);
850
+ }
797
851
  if (storedManifest?.components) {
798
852
  const staleFiles = /* @__PURE__ */ new Set();
799
853
  for (const [id, desc] of Object.entries(storedManifest.components)) if ((desc.replacement ?? "") !== (prevReplacements.get(id) ?? "")) staleFiles.add(desc.file);
@@ -1 +1 @@
1
- {"version":3,"file":"theme-evaluator.d.ts","sourceRoot":"","sources":["../src/theme-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAuCA;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC5D,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAWD;AA6KD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EACjD,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAC1C,MAAM,CAiCR"}
1
+ {"version":3,"file":"theme-evaluator.d.ts","sourceRoot":"","sources":["../src/theme-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAuCA;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC5D,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAWD;AAuKD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EACjD,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAC1C,MAAM,CAiCR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animus-ui/vite-plugin",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0-next.10",
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/core": "0.1.0-next.1",
29
- "@animus-ui/extract": "0.1.0-next.1"
28
+ "@animus-ui/core": "0.1.0-next.10",
29
+ "@animus-ui/extract": "0.1.0-next.10"
30
30
  }
31
31
  }