@animus-ui/extract 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/assemble-stylesheet.d.ts +34 -0
- package/dist/assemble-stylesheet.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +86 -55
- package/dist/prefix.d.ts +5 -2
- package/dist/prefix.d.ts.map +1 -1
- package/dist/unit-fallback.d.ts.map +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 7 Animus cascade layers in required order.
|
|
3
|
+
*/
|
|
4
|
+
export declare const ANIMUS_LAYERS: readonly ["global", "base", "variants", "compounds", "states", "system", "custom"];
|
|
5
|
+
/**
|
|
6
|
+
* Validate that a consumer `layers` array contains all 7 Animus layers
|
|
7
|
+
* in the correct relative order. Consumer layers may be interleaved.
|
|
8
|
+
*
|
|
9
|
+
* @throws Error with descriptive message on violation
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateLayerOrder(layers: string[]): void;
|
|
12
|
+
export interface AssembleStylesheetOptions {
|
|
13
|
+
/** Custom layer order. Must contain all 7 Animus layers as a subsequence. */
|
|
14
|
+
layers?: string[];
|
|
15
|
+
/** Variable CSS: `:root { --color-*: ... }` + color mode selectors */
|
|
16
|
+
variableCss?: string;
|
|
17
|
+
/** Global CSS: `@layer global { reset + global styles }` */
|
|
18
|
+
globalCss?: string;
|
|
19
|
+
/** Component CSS from the Rust crate (may contain embedded @layer declaration) */
|
|
20
|
+
componentCss?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Assemble the final stylesheet in canonical order:
|
|
24
|
+
*
|
|
25
|
+
* 1. `@layer` declaration (cascade ordering)
|
|
26
|
+
* 2. Emitted variables (`:root`, color mode selectors)
|
|
27
|
+
* 3. `@layer global { ... }` (reset + global styles)
|
|
28
|
+
* 4. `@layer base/variants/compounds/states/system/custom { ... }` (components)
|
|
29
|
+
*
|
|
30
|
+
* This is the single source of truth for stylesheet assembly.
|
|
31
|
+
* Both Vite and Next.js plugins must use this function.
|
|
32
|
+
*/
|
|
33
|
+
export declare function assembleStylesheet(options: AssembleStylesheetOptions): string;
|
|
34
|
+
//# sourceMappingURL=assemble-stylesheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assemble-stylesheet.d.ts","sourceRoot":"","sources":["../pipeline/assemble-stylesheet.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,aAAa,oFAQhB,CAAC;AAIX;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAyBzD;AAYD,MAAM,WAAW,yBAAyB;IACxC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAsB7E"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type { AssembleStylesheetOptions } from './assemble-stylesheet';
|
|
2
|
+
export { ANIMUS_LAYERS, assembleStylesheet, validateLayerOrder, } from './assemble-stylesheet';
|
|
1
3
|
export { extractSystemFilePackages } from './discover-packages';
|
|
2
4
|
export { applyPrefix } from './prefix';
|
|
3
5
|
export { resolveGlobalStyles, resolveTokenAliases, resolveValue, } from './resolve-global-styles';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../pipeline/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../pipeline/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,77 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
|
+
import { UNITLESS_PROPERTIES } from "@animus-ui/properties";
|
|
4
5
|
//#region \0rolldown/runtime.js
|
|
5
6
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
6
7
|
//#endregion
|
|
8
|
+
//#region pipeline/assemble-stylesheet.ts
|
|
9
|
+
/**
|
|
10
|
+
* The 7 Animus cascade layers in required order.
|
|
11
|
+
*/
|
|
12
|
+
const ANIMUS_LAYERS = [
|
|
13
|
+
"global",
|
|
14
|
+
"base",
|
|
15
|
+
"variants",
|
|
16
|
+
"compounds",
|
|
17
|
+
"states",
|
|
18
|
+
"system",
|
|
19
|
+
"custom"
|
|
20
|
+
];
|
|
21
|
+
const DEFAULT_LAYER_DECLARATION = `@layer ${ANIMUS_LAYERS.join(", ")};\n`;
|
|
22
|
+
/**
|
|
23
|
+
* Validate that a consumer `layers` array contains all 7 Animus layers
|
|
24
|
+
* in the correct relative order. Consumer layers may be interleaved.
|
|
25
|
+
*
|
|
26
|
+
* @throws Error with descriptive message on violation
|
|
27
|
+
*/
|
|
28
|
+
function validateLayerOrder(layers) {
|
|
29
|
+
let cursor = 0;
|
|
30
|
+
for (const layer of layers) if (cursor < ANIMUS_LAYERS.length && layer === ANIMUS_LAYERS[cursor]) cursor++;
|
|
31
|
+
if (cursor < ANIMUS_LAYERS.length) {
|
|
32
|
+
const missing = ANIMUS_LAYERS.slice(cursor);
|
|
33
|
+
const found = ANIMUS_LAYERS.slice(0, cursor);
|
|
34
|
+
if (!ANIMUS_LAYERS.every((l) => layers.includes(l))) {
|
|
35
|
+
const absent = ANIMUS_LAYERS.filter((l) => !layers.includes(l));
|
|
36
|
+
throw new Error(`[animus-extract] Custom layers missing required layers: ${absent.join(", ")}. All 7 Animus layers must be present: ${ANIMUS_LAYERS.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`[animus-extract] Custom layers have wrong order. Found ${found.join(", ")} but then expected ${missing[0]}. Required order: (${ANIMUS_LAYERS.join(" < ")}). You may interleave custom layers but must preserve this subsequence.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Strip a leading `@layer ...;` declaration line from CSS if present.
|
|
43
|
+
* The Rust crate embeds this in prod-mode output; we strip it so the
|
|
44
|
+
* shared assembler controls placement.
|
|
45
|
+
*/
|
|
46
|
+
function stripLeadingLayerDeclaration(css) {
|
|
47
|
+
return css.replace(/^@layer\s+[^;{]+;\s*\n?/, "");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Assemble the final stylesheet in canonical order:
|
|
51
|
+
*
|
|
52
|
+
* 1. `@layer` declaration (cascade ordering)
|
|
53
|
+
* 2. Emitted variables (`:root`, color mode selectors)
|
|
54
|
+
* 3. `@layer global { ... }` (reset + global styles)
|
|
55
|
+
* 4. `@layer base/variants/compounds/states/system/custom { ... }` (components)
|
|
56
|
+
*
|
|
57
|
+
* This is the single source of truth for stylesheet assembly.
|
|
58
|
+
* Both Vite and Next.js plugins must use this function.
|
|
59
|
+
*/
|
|
60
|
+
function assembleStylesheet(options) {
|
|
61
|
+
let layerDeclaration;
|
|
62
|
+
if (options.layers) {
|
|
63
|
+
validateLayerOrder(options.layers);
|
|
64
|
+
layerDeclaration = `@layer ${options.layers.join(", ")};\n`;
|
|
65
|
+
} else layerDeclaration = DEFAULT_LAYER_DECLARATION;
|
|
66
|
+
const componentCss = options.componentCss ? stripLeadingLayerDeclaration(options.componentCss) : "";
|
|
67
|
+
return [
|
|
68
|
+
layerDeclaration,
|
|
69
|
+
options.variableCss || "",
|
|
70
|
+
options.globalCss || "",
|
|
71
|
+
componentCss
|
|
72
|
+
].filter(Boolean).join("\n");
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
7
75
|
//#region pipeline/discover-packages.ts
|
|
8
76
|
/**
|
|
9
77
|
* Extract external DS package names from `.includes([...])` calls in the system file.
|
|
@@ -59,27 +127,39 @@ function extractSystemFilePackages(systemFilePath) {
|
|
|
59
127
|
//#endregion
|
|
60
128
|
//#region pipeline/prefix.ts
|
|
61
129
|
/**
|
|
62
|
-
* Apply namespace prefix to a variable map
|
|
130
|
+
* Apply namespace prefix to a variable map, CSS variable declarations, and theme JSON.
|
|
63
131
|
*
|
|
64
132
|
* Variable map: `{ "colors.ember": "--color-ember" }` -> `{ "colors.ember": "--prefix-color-ember" }`
|
|
65
133
|
* Variable CSS: `--color-ember: #FF2800` -> `--prefix-color-ember: #FF2800`
|
|
66
134
|
* `var(--color-ember)` -> `var(--prefix-color-ember)`
|
|
135
|
+
* Theme JSON: `{ "colors.ember": "var(--color-ember)" }` -> `{ "colors.ember": "var(--prefix-color-ember)" }`
|
|
67
136
|
*/
|
|
68
|
-
function applyPrefix(prefix, variableMapJson, variableCss) {
|
|
137
|
+
function applyPrefix(prefix, variableMapJson, variableCss, themeJson, contextualVarsJson) {
|
|
69
138
|
if (!prefix) return {
|
|
70
139
|
variableMapJson,
|
|
71
|
-
variableCss
|
|
140
|
+
variableCss,
|
|
141
|
+
themeJson,
|
|
142
|
+
contextualVarsJson
|
|
72
143
|
};
|
|
144
|
+
const varRefRe = /var\(--([a-zA-Z][\w-]*)\)/g;
|
|
73
145
|
const map = JSON.parse(variableMapJson);
|
|
74
146
|
const prefixed = {};
|
|
75
147
|
for (const [key, varName] of Object.entries(map)) prefixed[key] = varName.startsWith("--") ? `--${prefix}-${varName.slice(2)}` : varName;
|
|
76
148
|
let css = variableCss;
|
|
77
149
|
css = css.replace(/--([a-zA-Z][\w-]*)\s*:/g, `--${prefix}-$1:`);
|
|
78
|
-
css = css.replace(
|
|
79
|
-
|
|
150
|
+
css = css.replace(varRefRe, `var(--${prefix}-$1)`);
|
|
151
|
+
const result = {
|
|
80
152
|
variableMapJson: JSON.stringify(prefixed),
|
|
81
153
|
variableCss: css
|
|
82
154
|
};
|
|
155
|
+
if (themeJson) result.themeJson = themeJson.replace(varRefRe, `var(--${prefix}-$1)`);
|
|
156
|
+
if (contextualVarsJson) {
|
|
157
|
+
const ctxVars = JSON.parse(contextualVarsJson);
|
|
158
|
+
const prefixedCtx = {};
|
|
159
|
+
for (const [scale, names] of Object.entries(ctxVars)) prefixedCtx[scale] = names.map((name) => `${prefix}-${name}`);
|
|
160
|
+
result.contextualVarsJson = JSON.stringify(prefixedCtx);
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
83
163
|
}
|
|
84
164
|
//#endregion
|
|
85
165
|
//#region pipeline/utils.ts
|
|
@@ -240,55 +320,6 @@ function execSubprocess(script, cwd, args = []) {
|
|
|
240
320
|
//#endregion
|
|
241
321
|
//#region pipeline/unit-fallback.ts
|
|
242
322
|
/**
|
|
243
|
-
* CSS properties that accept unitless numeric values.
|
|
244
|
-
* Matches @emotion/unitless and React DOM's style handling.
|
|
245
|
-
* Bare numerics on properties NOT in this set receive `px`.
|
|
246
|
-
*/
|
|
247
|
-
const UNITLESS_PROPERTIES = new Set([
|
|
248
|
-
"animation-iteration-count",
|
|
249
|
-
"border-image-outset",
|
|
250
|
-
"border-image-slice",
|
|
251
|
-
"border-image-width",
|
|
252
|
-
"box-flex",
|
|
253
|
-
"box-flex-group",
|
|
254
|
-
"box-ordinal-group",
|
|
255
|
-
"column-count",
|
|
256
|
-
"columns",
|
|
257
|
-
"flex",
|
|
258
|
-
"flex-grow",
|
|
259
|
-
"flex-positive",
|
|
260
|
-
"flex-shrink",
|
|
261
|
-
"flex-negative",
|
|
262
|
-
"flex-order",
|
|
263
|
-
"grid-area",
|
|
264
|
-
"grid-row",
|
|
265
|
-
"grid-row-end",
|
|
266
|
-
"grid-row-span",
|
|
267
|
-
"grid-row-start",
|
|
268
|
-
"grid-column",
|
|
269
|
-
"grid-column-end",
|
|
270
|
-
"grid-column-span",
|
|
271
|
-
"grid-column-start",
|
|
272
|
-
"font-weight",
|
|
273
|
-
"line-clamp",
|
|
274
|
-
"line-height",
|
|
275
|
-
"opacity",
|
|
276
|
-
"order",
|
|
277
|
-
"orphans",
|
|
278
|
-
"tab-size",
|
|
279
|
-
"widows",
|
|
280
|
-
"z-index",
|
|
281
|
-
"zoom",
|
|
282
|
-
"fill-opacity",
|
|
283
|
-
"flood-opacity",
|
|
284
|
-
"stop-opacity",
|
|
285
|
-
"stroke-dasharray",
|
|
286
|
-
"stroke-dashoffset",
|
|
287
|
-
"stroke-miterlimit",
|
|
288
|
-
"stroke-opacity",
|
|
289
|
-
"stroke-width"
|
|
290
|
-
]);
|
|
291
|
-
/**
|
|
292
323
|
* Append `px` to bare numeric values in CSS declarations for properties
|
|
293
324
|
* that expect length units. Unitless properties are preserved as-is.
|
|
294
325
|
* Numbers inside CSS function calls (cubic-bezier, rgb, calc, etc.) are skipped.
|
|
@@ -327,4 +358,4 @@ function applyUnitFallback(css) {
|
|
|
327
358
|
});
|
|
328
359
|
}
|
|
329
360
|
//#endregion
|
|
330
|
-
export { applyPrefix, applyUnitFallback, camelToKebab, detectRuntime, execSubprocess, extractSystemFilePackages, resolveGlobalStyles, resolveTokenAliases, resolveTransformPlaceholders, resolveValue };
|
|
361
|
+
export { ANIMUS_LAYERS, applyPrefix, applyUnitFallback, assembleStylesheet, camelToKebab, detectRuntime, execSubprocess, extractSystemFilePackages, resolveGlobalStyles, resolveTokenAliases, resolveTransformPlaceholders, resolveValue, validateLayerOrder };
|
package/dist/prefix.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Apply namespace prefix to a variable map
|
|
2
|
+
* Apply namespace prefix to a variable map, CSS variable declarations, and theme JSON.
|
|
3
3
|
*
|
|
4
4
|
* Variable map: `{ "colors.ember": "--color-ember" }` -> `{ "colors.ember": "--prefix-color-ember" }`
|
|
5
5
|
* Variable CSS: `--color-ember: #FF2800` -> `--prefix-color-ember: #FF2800`
|
|
6
6
|
* `var(--color-ember)` -> `var(--prefix-color-ember)`
|
|
7
|
+
* Theme JSON: `{ "colors.ember": "var(--color-ember)" }` -> `{ "colors.ember": "var(--prefix-color-ember)" }`
|
|
7
8
|
*/
|
|
8
|
-
export declare function applyPrefix(prefix: string, variableMapJson: string, variableCss: string): {
|
|
9
|
+
export declare function applyPrefix(prefix: string, variableMapJson: string, variableCss: string, themeJson?: string, contextualVarsJson?: string): {
|
|
9
10
|
variableMapJson: string;
|
|
10
11
|
variableCss: string;
|
|
12
|
+
themeJson?: string;
|
|
13
|
+
contextualVarsJson?: string;
|
|
11
14
|
};
|
|
12
15
|
//# sourceMappingURL=prefix.d.ts.map
|
package/dist/prefix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../pipeline/prefix.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../pipeline/prefix.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,MAAM,GAC1B;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CA0CA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit-fallback.d.ts","sourceRoot":"","sources":["../pipeline/unit-fallback.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unit-fallback.d.ts","sourceRoot":"","sources":["../pipeline/unit-fallback.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA2CrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/extract",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.36",
|
|
4
4
|
"description": "Animus static CSS extraction pipeline (Rust/NAPI)",
|
|
5
5
|
"author": "codecaaron <airrobb@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"./pipeline": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.mjs",
|
|
17
18
|
"default": "./dist/index.mjs"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
@@ -39,14 +40,18 @@
|
|
|
39
40
|
]
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
|
-
"build": "napi build --platform --release &&
|
|
43
|
+
"build": "napi build --platform --release && bun run build:ts",
|
|
44
|
+
"build:ts": "tsdown && tsc -p tsconfig.build.json",
|
|
43
45
|
"build:debug": "napi build --platform",
|
|
44
|
-
"
|
|
46
|
+
"compile": "tsc -p tsconfig.build.json --noEmit"
|
|
45
47
|
},
|
|
46
48
|
"optionalDependencies": {
|
|
47
|
-
"@animus-ui/extract-darwin-arm64": "0.1.0-next.
|
|
48
|
-
"@animus-ui/extract-linux-x64-gnu": "0.1.0-next.
|
|
49
|
-
"@animus-ui/extract-linux-arm64-gnu": "0.1.0-next.
|
|
49
|
+
"@animus-ui/extract-darwin-arm64": "0.1.0-next.36",
|
|
50
|
+
"@animus-ui/extract-linux-x64-gnu": "0.1.0-next.36",
|
|
51
|
+
"@animus-ui/extract-linux-arm64-gnu": "0.1.0-next.36"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@animus-ui/properties": "0.1.0-next.36"
|
|
50
55
|
},
|
|
51
56
|
"devDependencies": {
|
|
52
57
|
"@animus-ui/system": "workspace:*",
|