@animus-ui/next-plugin 0.1.0-next.32 → 0.1.0-next.36
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.mjs +17 -9
- package/dist/plugin.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSy
|
|
|
3
3
|
import { dirname, extname, join, relative, resolve, sep } from "path";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
|
-
import { applyPrefix, applyUnitFallback, detectRuntime, execSubprocess, extractSystemFilePackages, resolveGlobalStyles } from "@animus-ui/extract/pipeline";
|
|
6
|
+
import { applyPrefix, applyUnitFallback, assembleStylesheet, detectRuntime, execSubprocess, extractSystemFilePackages, resolveGlobalStyles } from "@animus-ui/extract/pipeline";
|
|
7
7
|
//#region src/plugin.ts
|
|
8
8
|
const PLUGIN_NAME = "AnimusWebpackPlugin";
|
|
9
9
|
var AnimusWebpackPlugin = class {
|
|
@@ -184,11 +184,12 @@ var AnimusWebpackPlugin = class {
|
|
|
184
184
|
let componentCss = manifest?.css || "";
|
|
185
185
|
if (this.systemResolveScript && componentCss.includes("__TRANSFORM__")) componentCss = this.resolveTransforms(rootDir, componentCss);
|
|
186
186
|
componentCss = applyUnitFallback(componentCss);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
const fullCss = assembleStylesheet({
|
|
188
|
+
layers: this.options.layers,
|
|
189
|
+
variableCss: this.variableCss,
|
|
190
|
+
globalCss: this.globalCss,
|
|
191
|
+
componentCss
|
|
192
|
+
});
|
|
192
193
|
const cssHash = createHash("md5").update(fullCss).digest("hex");
|
|
193
194
|
if (cssHash !== this.lastCssHash) {
|
|
194
195
|
const animusDir = join(rootDir, ".animus");
|
|
@@ -223,7 +224,7 @@ var AnimusWebpackPlugin = class {
|
|
|
223
224
|
}
|
|
224
225
|
loadSystem(rootDir, systemPath) {
|
|
225
226
|
const tmpOut = join(tmpdir(), `animus-system-${Date.now()}.json`);
|
|
226
|
-
execSubprocess(`const m = require(${JSON.stringify(systemPath)});\nconst
|
|
227
|
+
execSubprocess(`const m = require(${JSON.stringify(systemPath)});\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}\nconst transformSources = {};\nfor (const [name, fn] of Object.entries(cfg.transforms || {})) {\n transformSources[name] = fn.toString();\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 transformSources: transformSources,\n globalStyleBlocks: Object.keys(globalStyleBlocks).length > 0 ? globalStyleBlocks : null\n}));\n`, rootDir);
|
|
227
228
|
const result = readFileSync(tmpOut, "utf-8");
|
|
228
229
|
try {
|
|
229
230
|
__require("fs").unlinkSync(tmpOut);
|
|
@@ -237,18 +238,25 @@ var AnimusWebpackPlugin = class {
|
|
|
237
238
|
this.variableCss = parsed.serialized.variableCss;
|
|
238
239
|
this.contextualVarsJson = parsed.serialized.contextualVarsJson;
|
|
239
240
|
if (this.options.prefix) {
|
|
240
|
-
const prefixed = applyPrefix(this.options.prefix, this.variableMapJson, this.variableCss);
|
|
241
|
+
const prefixed = applyPrefix(this.options.prefix, this.variableMapJson, this.variableCss, this.themeJson, this.contextualVarsJson || void 0);
|
|
241
242
|
this.variableMapJson = prefixed.variableMapJson;
|
|
242
243
|
this.variableCss = prefixed.variableCss;
|
|
244
|
+
if (prefixed.themeJson) this.themeJson = prefixed.themeJson;
|
|
245
|
+
if (prefixed.contextualVarsJson) this.contextualVarsJson = prefixed.contextualVarsJson;
|
|
243
246
|
}
|
|
244
247
|
} else throw new Error("[animus-extract] Theme must be built with createTheme().build(). No .serialize() method found on tokens export.");
|
|
245
248
|
if (parsed.globalStyleBlocks) {
|
|
246
249
|
if (Object.keys(parsed.globalStyleBlocks).length > 0) try {
|
|
250
|
+
const hasTransforms = parsed.transformNames && parsed.transformNames.length > 0;
|
|
247
251
|
const flat = JSON.parse(this.themeJson);
|
|
248
252
|
const propConfig = JSON.parse(this.configJson);
|
|
249
253
|
const variableMap = {};
|
|
250
254
|
for (const [tokenPath, value] of Object.entries(flat)) if (typeof value === "string" && value.startsWith("var(") && value.endsWith(")")) variableMap[tokenPath] = value.slice(4, -1);
|
|
251
|
-
const
|
|
255
|
+
const transforms = {};
|
|
256
|
+
if (hasTransforms && parsed.transformSources) for (const [name, src] of Object.entries(parsed.transformSources)) try {
|
|
257
|
+
transforms[name] = new Function(`return (${src})`)();
|
|
258
|
+
} catch {}
|
|
259
|
+
const gsResult = resolveGlobalStyles(parsed.globalStyleBlocks, propConfig, flat, variableMap, transforms);
|
|
252
260
|
const parts = Object.values(gsResult).filter(Boolean);
|
|
253
261
|
if (parts.length > 0) this.globalCss = `@layer global {\n${parts.join("\n\n")}\n}`;
|
|
254
262
|
} catch (e) {
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,KAAK,QAAQ,GAAG;IACd,KAAK,EAAE;QACL,GAAG,EAAE;YACH,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;SACxE,CAAC;QACF,QAAQ,EAAE;YACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;SACxE,CAAC;KACH,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAuB;IAGtC,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,iBAAiB,CAAM;IAC/B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,mBAAmB,CAAuB;IAGlD,OAAO,CAAC,SAAS,CAAuD;IACxE,OAAO,CAAC,WAAW,CAAuB;IAG1C,OAAO,CAAC,mBAAmB,CAAgB;IAG3C,OAAO,CAAC,qBAAqB,CAA6B;gBAE9C,OAAO,EAAE,iBAAiB;IAItC,OAAO,CAAC,WAAW,CAAS;IAE5B,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;YA2CjB,iBAAiB;YAwDjB,eAAe;IA8M7B,OAAO,CAAC,UAAU;IAoKlB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,aAAa;IAyCrB,OAAO,CAAC,qBAAqB;IAmD7B;;OAEG;IACH,WAAW,IAAI,IAAI;IASnB,iDAAiD;IACjD,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7D,oCAAoC;IACpC,UAAU,IAAI,iBAAiB;IAI/B,0EAA0E;IAC1E,sBAAsB,IAAI,MAAM,EAAE;IAIlC,uEAAuE;IACvE,wBAAwB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAGhD"}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,5 +9,13 @@ export interface AnimusNextOptions {
|
|
|
9
9
|
verbose?: boolean;
|
|
10
10
|
/** Namespace prefix for CSS variables and class names. */
|
|
11
11
|
prefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Full `@layer` declaration order. Must include all 7 Animus layers
|
|
14
|
+
* (`global`, `base`, `variants`, `compounds`, `states`, `system`, `custom`)
|
|
15
|
+
* as a subsequence. Consumer layers may be interleaved.
|
|
16
|
+
*
|
|
17
|
+
* @example ['reset', 'global', 'base', 'variants', 'compounds', 'states', 'system', 'custom', 'overrides']
|
|
18
|
+
*/
|
|
19
|
+
layers?: string[];
|
|
12
20
|
}
|
|
13
21
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/next-plugin",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.36",
|
|
4
4
|
"description": "Animus static CSS extraction for Next.js (webpack)",
|
|
5
5
|
"author": "codecaaron <airrobb@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"url": "git+https://github.com/codecaaron/animus"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "
|
|
33
|
+
"build": "bun run build:ts",
|
|
34
|
+
"build:ts": "tsdown && tsc -p tsconfig.build.json",
|
|
34
35
|
"compile": "tsc --noEmit"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
@@ -38,6 +39,6 @@
|
|
|
38
39
|
"webpack": ">=5.0.0"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@animus-ui/extract": "0.1.0-next.
|
|
42
|
+
"@animus-ui/extract": "0.1.0-next.36"
|
|
42
43
|
}
|
|
43
44
|
}
|