@animus-ui/vite-plugin 0.1.0-next.16 → 0.1.0-next.18
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/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CAo6BnE;AAED,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvE,eAAe,aAAa,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -384,7 +384,7 @@ function animusExtract(options) {
|
|
|
384
384
|
let storedSheets = null;
|
|
385
385
|
let storedSystemPropMapJson = "{}";
|
|
386
386
|
let storedDynamicPropsJson = "{}";
|
|
387
|
-
let storedTransformsSource = "";
|
|
387
|
+
let storedTransformsSource = "{}";
|
|
388
388
|
let layerDeclaration = "";
|
|
389
389
|
const fileCache = /* @__PURE__ */ new Map();
|
|
390
390
|
let packageMap = {};
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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"
|
|
@@ -722,8 +730,8 @@ if (import.meta.hot) {
|
|
|
722
730
|
...meta.scale_values && Object.keys(meta.scale_values).length > 0 ? { scaleValues: meta.scale_values } : {}
|
|
723
731
|
};
|
|
724
732
|
moduleSource += `\nexport const dynamicPropConfig = ${JSON.stringify(configEntries)};`;
|
|
725
|
-
|
|
726
|
-
}
|
|
733
|
+
} else moduleSource += `\nexport const dynamicPropConfig = {};`;
|
|
734
|
+
moduleSource += `\nexport const transforms = ${storedTransformsSource};`;
|
|
727
735
|
return moduleSource;
|
|
728
736
|
}
|
|
729
737
|
return null;
|
|
@@ -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;AAsLH,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
* Resolve {scale.path} and {scale.path/alpha} token aliases in a CSS value string.
|
|
35
|
+
* Mirrors the Rust theme_resolver's resolve_token_aliases logic.
|
|
36
|
+
*/
|
|
37
|
+
function resolveTokenAliases(value) {
|
|
38
|
+
if (!value.includes("{")) return value;
|
|
39
|
+
return value.replace(/\{([^}]+)\}/g, (_match, content) => {
|
|
40
|
+
const slashIdx = content.indexOf("/");
|
|
41
|
+
const tokenPath = slashIdx >= 0 ? content.slice(0, slashIdx) : content;
|
|
42
|
+
const alpha = slashIdx >= 0 ? parseInt(content.slice(slashIdx + 1), 10) : null;
|
|
43
|
+
const dotIdx = tokenPath.indexOf(".");
|
|
44
|
+
const flatKey = dotIdx >= 0 ? tokenPath.slice(0, dotIdx) + "." + tokenPath.slice(dotIdx + 1).replace(/\./g, "-") : tokenPath;
|
|
45
|
+
let resolved;
|
|
46
|
+
if (variableMap[flatKey]) resolved = `var(${variableMap[flatKey]})`;
|
|
47
|
+
else if (flat[flatKey] != null) resolved = flat[flatKey];
|
|
48
|
+
else return `{${content}}`;
|
|
49
|
+
if (alpha === 0) return "transparent";
|
|
50
|
+
if (alpha != null && alpha !== 100) return `color-mix(in srgb, ${resolved} ${alpha}%, transparent)`;
|
|
51
|
+
return resolved;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a block of selectors → style objects using prop config + theme.
|
|
56
|
+
* @keyframes selectors are delegated to serializeRawBlock.
|
|
57
|
+
*/
|
|
58
|
+
function resolveBlock(selectors) {
|
|
59
|
+
const rules = [];
|
|
60
|
+
for (const [selector, styleObj] of Object.entries(selectors)) {
|
|
61
|
+
if (selector.startsWith("@keyframes")) {
|
|
62
|
+
const frames = [];
|
|
63
|
+
for (const [pct, frameStyles] of Object.entries(styleObj)) if (typeof frameStyles === "object" && frameStyles !== null) {
|
|
64
|
+
const decls = [];
|
|
65
|
+
for (const [prop, raw] of Object.entries(frameStyles)) {
|
|
66
|
+
const cfg = propConfig[prop];
|
|
67
|
+
const cssProps = cfg?.properties?.length ? cfg.properties : cfg ? [cfg.property] : [prop];
|
|
68
|
+
let resolved = raw;
|
|
69
|
+
if (cfg?.scale) {
|
|
70
|
+
const key = cfg.scale + "." + raw;
|
|
71
|
+
if (flat[key] != null) resolved = flat[key];
|
|
72
|
+
}
|
|
73
|
+
resolved = resolveTokenAliases(String(resolved));
|
|
74
|
+
for (const cssProp of cssProps) decls.push(` ${camelToKebab(cssProp)}: ${resolved};`);
|
|
75
|
+
}
|
|
76
|
+
frames.push(` ${pct} {\n${decls.join("\n")}\n }`);
|
|
77
|
+
}
|
|
78
|
+
rules.push(`${selector} {\n${frames.join("\n")}\n}`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const decls = [];
|
|
82
|
+
for (const [prop, raw] of Object.entries(styleObj)) {
|
|
83
|
+
const config = propConfig[prop];
|
|
84
|
+
const cssProps = config?.properties?.length ? config.properties : config ? [config.property] : [prop];
|
|
85
|
+
let resolved = raw;
|
|
86
|
+
if (config?.scale) {
|
|
87
|
+
const key = config.scale + "." + raw;
|
|
88
|
+
if (flat[key] != null) resolved = flat[key];
|
|
89
|
+
}
|
|
90
|
+
if (config?.transform && transforms[config.transform]) {
|
|
91
|
+
const fn = transforms[config.transform];
|
|
92
|
+
const input = typeof resolved === "string" && !isNaN(Number(resolved)) ? Number(resolved) : resolved;
|
|
93
|
+
resolved = String(fn(input));
|
|
94
|
+
} else resolved = String(resolved);
|
|
95
|
+
resolved = resolveTokenAliases(resolved);
|
|
96
|
+
for (const cssProp of cssProps) decls.push(` ${camelToKebab(cssProp)}: ${resolved};`);
|
|
97
|
+
}
|
|
98
|
+
if (decls.length) rules.push(`${selector} {\n${decls.join("\n")}\n}`);
|
|
99
|
+
}
|
|
100
|
+
return rules.join("\n\n");
|
|
101
|
+
}
|
|
102
|
+
const result = {};
|
|
103
|
+
if (gs.reset) result.reset = resolveBlock(gs.reset);
|
|
104
|
+
if (gs.global) result.global = resolveBlock(gs.global);
|
|
105
|
+
writeFileSync(outputFile, JSON.stringify(result));
|
|
106
|
+
//#endregion
|
|
107
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/vite-plugin",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.18",
|
|
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.
|
|
28
|
+
"@animus-ui/extract": "0.1.0-next.18",
|
|
29
29
|
"browserslist": "^4.24.0",
|
|
30
30
|
"lightningcss": "^1.29.0"
|
|
31
31
|
}
|