@seyuna/postcss 1.0.0-canary.20 → 1.0.0-canary.21
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/CHANGELOG.md +7 -0
- package/dist/at-rules/color-scheme.d.ts +1 -1
- package/dist/at-rules/color-scheme.js +12 -6
- package/dist/at-rules/color.d.ts +1 -1
- package/dist/at-rules/color.js +9 -5
- package/dist/at-rules/container.d.ts +1 -1
- package/dist/at-rules/container.js +11 -4
- package/dist/at-rules/index.d.ts +1 -1
- package/dist/at-rules/index.js +20 -14
- package/dist/config.js +12 -6
- package/dist/errors.js +6 -2
- package/dist/functions/color.js +19 -10
- package/dist/functions/index.js +13 -10
- package/dist/functions/theme.js +4 -1
- package/dist/helpers.d.ts +3 -2
- package/dist/helpers.js +17 -8
- package/dist/index.js +7 -5
- package/dist/parser.js +12 -6
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +27 -15
- package/dist/types.js +2 -1
- package/package.json +1 -2
- package/src/at-rules/color-scheme.ts +5 -4
- package/src/at-rules/color.ts +1 -1
- package/src/at-rules/container.ts +3 -2
- package/src/at-rules/index.ts +1 -1
- package/src/helpers.ts +7 -6
- package/src/plugin.ts +15 -8
- package/tsconfig.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.0.0-canary.21](https://github.com/seyuna-corp/seyuna-postcss/compare/v1.0.0-canary.20...v1.0.0-canary.21) (2026-01-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* resolve deadlock by switching to CJS and lazy initialization ([5ae6db2](https://github.com/seyuna-corp/seyuna-postcss/commit/5ae6db23e8fdc630787e2feb4c062af0187bf8c4))
|
|
7
|
+
|
|
1
8
|
# [1.0.0-canary.20](https://github.com/seyuna-corp/seyuna-postcss/compare/v1.0.0-canary.19...v1.0.0-canary.20) (2026-01-10)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AtRule } from "postcss";
|
|
1
|
+
import type { AtRule } from "postcss";
|
|
2
2
|
import { PluginContext } from "../types.js";
|
|
3
3
|
export declare const light: (atRule: AtRule, context: PluginContext) => void;
|
|
4
4
|
export declare const dark: (atRule: AtRule, context: PluginContext) => void;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dark = exports.light = void 0;
|
|
7
|
+
const postcss_1 = __importDefault(require("postcss"));
|
|
2
8
|
/**
|
|
3
9
|
* Custom PostCSS plugin handler factory for `@light` and `@dark` at-rules.
|
|
4
10
|
*/
|
|
@@ -14,7 +20,7 @@ function createColorSchemeHandler(scheme) {
|
|
|
14
20
|
/**
|
|
15
21
|
* Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
|
|
16
22
|
*/
|
|
17
|
-
const explicitRule = new Rule({
|
|
23
|
+
const explicitRule = new postcss_1.default.Rule({
|
|
18
24
|
selector: `[${modeAttribute}="${scheme}"] &`,
|
|
19
25
|
source: atRule.source,
|
|
20
26
|
});
|
|
@@ -22,12 +28,12 @@ function createColorSchemeHandler(scheme) {
|
|
|
22
28
|
/**
|
|
23
29
|
* Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
|
|
24
30
|
*/
|
|
25
|
-
const mediaAtRule = new AtRule({
|
|
31
|
+
const mediaAtRule = new postcss_1.default.AtRule({
|
|
26
32
|
name: "media",
|
|
27
33
|
params: `(prefers-color-scheme: ${scheme})`,
|
|
28
34
|
source: atRule.source,
|
|
29
35
|
});
|
|
30
|
-
const systemRule = new Rule({
|
|
36
|
+
const systemRule = new postcss_1.default.Rule({
|
|
31
37
|
selector: `[${modeAttribute}="system"] &`,
|
|
32
38
|
source: atRule.source,
|
|
33
39
|
});
|
|
@@ -39,5 +45,5 @@ function createColorSchemeHandler(scheme) {
|
|
|
39
45
|
atRule.replaceWith(mediaAtRule, explicitRule);
|
|
40
46
|
};
|
|
41
47
|
}
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
exports.light = createColorSchemeHandler('light');
|
|
49
|
+
exports.dark = createColorSchemeHandler('dark');
|
package/dist/at-rules/color.d.ts
CHANGED
package/dist/at-rules/color.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eachStandardColor = eachStandardColor;
|
|
4
|
+
exports.eachFixedColor = eachFixedColor;
|
|
5
|
+
const helpers_js_1 = require("../helpers.js");
|
|
2
6
|
/**
|
|
3
7
|
* Handler for @each-standard-color
|
|
4
8
|
*/
|
|
5
|
-
|
|
9
|
+
function eachStandardColor(atRule, context) {
|
|
6
10
|
const { config } = context;
|
|
7
11
|
const hueNames = config.ui ? Object.keys(config.ui.theme.hues) : [];
|
|
8
|
-
const rules = generateRules(hueNames, atRule, context);
|
|
12
|
+
const rules = (0, helpers_js_1.generateRules)(hueNames, atRule, context);
|
|
9
13
|
if (rules.length)
|
|
10
14
|
atRule.replaceWith(...rules);
|
|
11
15
|
else
|
|
@@ -14,7 +18,7 @@ export function eachStandardColor(atRule, context) {
|
|
|
14
18
|
/**
|
|
15
19
|
* Handler for @each-fixed-color
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
function eachFixedColor(atRule, context) {
|
|
18
22
|
const { config } = context;
|
|
19
23
|
const mergedNames = [
|
|
20
24
|
...new Set([
|
|
@@ -22,7 +26,7 @@ export function eachFixedColor(atRule, context) {
|
|
|
22
26
|
...(config.ui ? Object.keys(config.ui.theme.dark.colors) : []),
|
|
23
27
|
]),
|
|
24
28
|
];
|
|
25
|
-
const rules = generateRules(mergedNames, atRule, context);
|
|
29
|
+
const rules = (0, helpers_js_1.generateRules)(mergedNames, atRule, context);
|
|
26
30
|
if (rules.length)
|
|
27
31
|
atRule.replaceWith(...rules);
|
|
28
32
|
else
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = container;
|
|
7
|
+
const postcss_1 = __importDefault(require("postcss"));
|
|
2
8
|
/**
|
|
3
9
|
* Custom PostCSS plugin handler for responsive at-rules.
|
|
4
10
|
*
|
|
@@ -15,7 +21,8 @@ import { AtRule } from "postcss";
|
|
|
15
21
|
* }
|
|
16
22
|
*
|
|
17
23
|
*/
|
|
18
|
-
|
|
24
|
+
function container(atRule, context) {
|
|
25
|
+
var _a, _b;
|
|
19
26
|
const { config } = context;
|
|
20
27
|
// Default breakpoints
|
|
21
28
|
const defaultBreakpoints = {
|
|
@@ -29,7 +36,7 @@ export default function container(atRule, context) {
|
|
|
29
36
|
// Merge with config if available (assuming config.ui.breakpoints exists)
|
|
30
37
|
const breakpoints = {
|
|
31
38
|
...defaultBreakpoints,
|
|
32
|
-
...(config.ui
|
|
39
|
+
...(((_b = (_a = config.ui) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.breakpoints) || {}),
|
|
33
40
|
};
|
|
34
41
|
if (Object.keys(breakpoints).includes(atRule.name)) {
|
|
35
42
|
const minWidth = breakpoints[atRule.name];
|
|
@@ -37,7 +44,7 @@ export default function container(atRule, context) {
|
|
|
37
44
|
atRule.each((node) => {
|
|
38
45
|
clonedNodes.push(node.clone());
|
|
39
46
|
});
|
|
40
|
-
const containerAtRule = new AtRule({
|
|
47
|
+
const containerAtRule = new postcss_1.default.AtRule({
|
|
41
48
|
name: "container",
|
|
42
49
|
params: `(min-width: ${minWidth})`,
|
|
43
50
|
source: atRule.source,
|
package/dist/at-rules/index.d.ts
CHANGED
package/dist/at-rules/index.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.atRuleHandlers = void 0;
|
|
7
|
+
const color_js_1 = require("./color.js");
|
|
8
|
+
const container_js_1 = __importDefault(require("./container.js"));
|
|
9
|
+
const color_scheme_js_1 = require("./color-scheme.js");
|
|
4
10
|
// Ordered array ensures execution order
|
|
5
|
-
|
|
6
|
-
{ name: "each-standard-color", handler: eachStandardColor },
|
|
7
|
-
{ name: "each-fixed-color", handler: eachFixedColor },
|
|
8
|
-
{ name: "light", handler: light },
|
|
9
|
-
{ name: "dark", handler: dark },
|
|
10
|
-
{ name: "xs", handler:
|
|
11
|
-
{ name: "sm", handler:
|
|
12
|
-
{ name: "md", handler:
|
|
13
|
-
{ name: "lg", handler:
|
|
14
|
-
{ name: "xl", handler:
|
|
15
|
-
{ name: "2xl", handler:
|
|
11
|
+
exports.atRuleHandlers = [
|
|
12
|
+
{ name: "each-standard-color", handler: color_js_1.eachStandardColor },
|
|
13
|
+
{ name: "each-fixed-color", handler: color_js_1.eachFixedColor },
|
|
14
|
+
{ name: "light", handler: color_scheme_js_1.light },
|
|
15
|
+
{ name: "dark", handler: color_scheme_js_1.dark },
|
|
16
|
+
{ name: "xs", handler: container_js_1.default },
|
|
17
|
+
{ name: "sm", handler: container_js_1.default },
|
|
18
|
+
{ name: "md", handler: container_js_1.default },
|
|
19
|
+
{ name: "lg", handler: container_js_1.default },
|
|
20
|
+
{ name: "xl", handler: container_js_1.default },
|
|
21
|
+
{ name: "2xl", handler: container_js_1.default },
|
|
16
22
|
];
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
3
9
|
const DEFAULT_OPTIONS = {
|
|
4
10
|
configPath: 'seyuna.json',
|
|
5
11
|
modeAttribute: 'data-mode',
|
|
@@ -9,18 +15,18 @@ const DEFAULT_OPTIONS = {
|
|
|
9
15
|
};
|
|
10
16
|
let cachedConfig = null;
|
|
11
17
|
let cachedConfigPath = null;
|
|
12
|
-
|
|
18
|
+
function loadConfig(options = {}) {
|
|
13
19
|
const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
|
|
14
20
|
if (mergedOptions.config) {
|
|
15
21
|
return { config: mergedOptions.config, options: mergedOptions };
|
|
16
22
|
}
|
|
17
|
-
const configPath =
|
|
23
|
+
const configPath = path_1.default.resolve(process.cwd(), mergedOptions.configPath);
|
|
18
24
|
// Cache config if it's the same path
|
|
19
25
|
if (cachedConfig && cachedConfigPath === configPath) {
|
|
20
26
|
return { config: cachedConfig, options: mergedOptions };
|
|
21
27
|
}
|
|
22
28
|
try {
|
|
23
|
-
if (!
|
|
29
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
24
30
|
if (mergedOptions.strict) {
|
|
25
31
|
throw new Error(`Seyuna config not found at ${configPath}`);
|
|
26
32
|
}
|
|
@@ -29,7 +35,7 @@ export function loadConfig(options = {}) {
|
|
|
29
35
|
options: mergedOptions,
|
|
30
36
|
};
|
|
31
37
|
}
|
|
32
|
-
const data = JSON.parse(
|
|
38
|
+
const data = JSON.parse(fs_1.default.readFileSync(configPath, 'utf-8'));
|
|
33
39
|
cachedConfig = data;
|
|
34
40
|
cachedConfigPath = configPath;
|
|
35
41
|
return { config: data, options: mergedOptions };
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportError = reportError;
|
|
4
|
+
exports.reportWarning = reportWarning;
|
|
5
|
+
function reportError(message, node, context, options = {}) {
|
|
2
6
|
const { options: pluginOptions } = context;
|
|
3
7
|
const formattedMessage = `[Seyuna PostCSS] ${message}`;
|
|
4
8
|
if (pluginOptions.strict) {
|
|
@@ -8,7 +12,7 @@ export function reportError(message, node, context, options = {}) {
|
|
|
8
12
|
reportWarning(formattedMessage, node);
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
|
-
|
|
15
|
+
function reportWarning(message, node) {
|
|
12
16
|
const result = node.root().toResult();
|
|
13
17
|
node.warn(result, `[Seyuna PostCSS] ${message}`);
|
|
14
18
|
}
|
package/dist/functions/color.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sc = sc;
|
|
4
|
+
exports.fc = fc;
|
|
5
|
+
exports.alpha = alpha;
|
|
6
|
+
exports.lighten = lighten;
|
|
7
|
+
exports.darken = darken;
|
|
8
|
+
exports.contrast = contrast;
|
|
1
9
|
/**
|
|
2
10
|
* Resolves a color name to its CSS variables based on its type (standard or fixed)
|
|
3
11
|
*/
|
|
4
12
|
function getColorVariables(context, color, type) {
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5
14
|
const { config } = context;
|
|
6
|
-
const hues = config
|
|
7
|
-
const colors = config
|
|
8
|
-
const lightColors = config
|
|
9
|
-
const darkColors = config
|
|
15
|
+
const hues = ((_b = (_a = config === null || config === void 0 ? void 0 : config.ui) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.hues) || {};
|
|
16
|
+
const colors = ((_d = (_c = config === null || config === void 0 ? void 0 : config.ui) === null || _c === void 0 ? void 0 : _c.theme) === null || _d === void 0 ? void 0 : _d.colors) || {};
|
|
17
|
+
const lightColors = ((_g = (_f = (_e = config === null || config === void 0 ? void 0 : config.ui) === null || _e === void 0 ? void 0 : _e.theme) === null || _f === void 0 ? void 0 : _f.light) === null || _g === void 0 ? void 0 : _g.colors) || {};
|
|
18
|
+
const darkColors = ((_k = (_j = (_h = config === null || config === void 0 ? void 0 : config.ui) === null || _h === void 0 ? void 0 : _h.theme) === null || _j === void 0 ? void 0 : _j.dark) === null || _k === void 0 ? void 0 : _k.colors) || {};
|
|
10
19
|
const isStandard = color in hues;
|
|
11
20
|
const isFixed = color in colors || color in lightColors || color in darkColors;
|
|
12
21
|
if (type === 'sc' && !isStandard) {
|
|
@@ -31,33 +40,33 @@ function getColorVariables(context, color, type) {
|
|
|
31
40
|
}
|
|
32
41
|
throw new Error(`Color '${color}' not found in seyuna.json`);
|
|
33
42
|
}
|
|
34
|
-
|
|
43
|
+
function sc(context, name, alpha, lightness, chroma) {
|
|
35
44
|
const vars = getColorVariables(context, name, 'sc');
|
|
36
45
|
const a = alpha && alpha !== "null" ? alpha : "1";
|
|
37
46
|
const l = lightness && lightness !== "null" ? lightness : vars.l;
|
|
38
47
|
const c = chroma && chroma !== "null" ? chroma : vars.c;
|
|
39
48
|
return `oklch(${l} ${c} ${vars.h} / ${a})`;
|
|
40
49
|
}
|
|
41
|
-
|
|
50
|
+
function fc(context, name, alpha, lightness, chroma) {
|
|
42
51
|
const vars = getColorVariables(context, name, 'fc');
|
|
43
52
|
const a = alpha && alpha !== "null" ? alpha : "1";
|
|
44
53
|
const l = lightness && lightness !== "null" ? lightness : vars.l;
|
|
45
54
|
const c = chroma && chroma !== "null" ? chroma : vars.c;
|
|
46
55
|
return `oklch(${l} ${c} ${vars.h} / ${a})`;
|
|
47
56
|
}
|
|
48
|
-
|
|
57
|
+
function alpha(context, color, value) {
|
|
49
58
|
const { l, c, h } = getColorVariables(context, color);
|
|
50
59
|
return `oklch(${l} ${c} ${h} / ${value})`;
|
|
51
60
|
}
|
|
52
|
-
|
|
61
|
+
function lighten(context, color, amount) {
|
|
53
62
|
const { l, c, h } = getColorVariables(context, color);
|
|
54
63
|
return `oklch(calc(${l} + ${amount}) ${c} ${h} / 1)`;
|
|
55
64
|
}
|
|
56
|
-
|
|
65
|
+
function darken(context, color, amount) {
|
|
57
66
|
const { l, c, h } = getColorVariables(context, color);
|
|
58
67
|
return `oklch(calc(${l} - ${amount}) ${c} ${h} / 1)`;
|
|
59
68
|
}
|
|
60
|
-
|
|
69
|
+
function contrast(context, color) {
|
|
61
70
|
const { l } = getColorVariables(context, color);
|
|
62
71
|
return `oklch(calc((${l} - 0.6) * -1000) 0 0)`;
|
|
63
72
|
}
|
package/dist/functions/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functions = void 0;
|
|
4
|
+
const color_js_1 = require("./color.js");
|
|
5
|
+
const theme_js_1 = require("./theme.js");
|
|
6
|
+
exports.functions = {
|
|
7
|
+
sc: color_js_1.sc,
|
|
8
|
+
fc: color_js_1.fc,
|
|
9
|
+
alpha: color_js_1.alpha,
|
|
10
|
+
lighten: color_js_1.lighten,
|
|
11
|
+
darken: color_js_1.darken,
|
|
12
|
+
contrast: color_js_1.contrast,
|
|
13
|
+
theme: theme_js_1.theme,
|
|
11
14
|
};
|
package/dist/functions/theme.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.theme = theme;
|
|
1
4
|
/**
|
|
2
5
|
* Accesses values from the Seyuna configuration using dot notation
|
|
3
6
|
* Example: theme(ui.theme.breakpoints.tablet)
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function theme(context, path) {
|
|
6
9
|
const parts = path.split('.');
|
|
7
10
|
let current = context.config;
|
|
8
11
|
for (const part of parts) {
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
import type { ChildNode, AtRule } from "postcss";
|
|
2
3
|
import { PluginContext } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
@@ -8,4 +9,4 @@ export declare function cloneNodes(nodes: ChildNode[], name: string, context: Pl
|
|
|
8
9
|
/**
|
|
9
10
|
* Generate CSS rules from a list of names
|
|
10
11
|
*/
|
|
11
|
-
export declare function generateRules(names: string[], atRule: AtRule, context: PluginContext): Rule[];
|
|
12
|
+
export declare function generateRules(names: string[], atRule: AtRule, context: PluginContext): postcss.Rule[];
|
package/dist/helpers.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cloneNodes = cloneNodes;
|
|
7
|
+
exports.generateRules = generateRules;
|
|
8
|
+
const postcss_1 = __importDefault(require("postcss"));
|
|
9
|
+
const parser_js_1 = require("./parser.js");
|
|
3
10
|
/**
|
|
4
11
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
5
12
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
6
13
|
*/
|
|
7
|
-
|
|
14
|
+
function cloneNodes(nodes, name, context) {
|
|
8
15
|
const { functions: fnMap } = context;
|
|
9
16
|
return nodes.flatMap((node) => {
|
|
10
17
|
const cloned = node.clone();
|
|
@@ -12,7 +19,7 @@ export function cloneNodes(nodes, name, context) {
|
|
|
12
19
|
const decl = cloned;
|
|
13
20
|
let value = decl.value.replace(/\{name\}/g, name);
|
|
14
21
|
// Process functions using the robust parser
|
|
15
|
-
decl.value = processFunctions(value, fnMap, decl, context);
|
|
22
|
+
decl.value = (0, parser_js_1.processFunctions)(value, fnMap, decl, context);
|
|
16
23
|
return decl;
|
|
17
24
|
}
|
|
18
25
|
if (cloned.type === "rule") {
|
|
@@ -33,16 +40,18 @@ export function cloneNodes(nodes, name, context) {
|
|
|
33
40
|
/**
|
|
34
41
|
* Generate CSS rules from a list of names
|
|
35
42
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
function generateRules(names, atRule, context) {
|
|
44
|
+
var _a;
|
|
45
|
+
const nodes = (_a = atRule.nodes) !== null && _a !== void 0 ? _a : [];
|
|
38
46
|
const generatedRules = [];
|
|
39
47
|
for (const name of names) {
|
|
40
|
-
const rule = new Rule({
|
|
48
|
+
const rule = new postcss_1.default.Rule({
|
|
41
49
|
selector: `&.${name}`,
|
|
42
50
|
source: atRule.source,
|
|
43
51
|
});
|
|
44
52
|
cloneNodes(nodes, name, context).forEach((n) => {
|
|
45
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
if (n.type === "rule" && n.selector && ((_a = n.nodes) === null || _a === void 0 ? void 0 : _a.length))
|
|
46
55
|
rule.append(n);
|
|
47
56
|
if (n.type === "decl")
|
|
48
57
|
rule.append(n);
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const plugin_js_1 = require("./plugin.js");
|
|
4
|
+
const index_js_1 = require("./functions/index.js");
|
|
3
5
|
// CommonJS-friendly export
|
|
4
|
-
const plugin = Object.assign(dynamicFunctionsPlugin, {
|
|
6
|
+
const plugin = Object.assign(plugin_js_1.dynamicFunctionsPlugin, {
|
|
5
7
|
postcss: true,
|
|
6
|
-
functions
|
|
8
|
+
functions: index_js_1.functions
|
|
7
9
|
});
|
|
8
|
-
|
|
10
|
+
exports.default = plugin;
|
package/dist/parser.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.processFunctions = processFunctions;
|
|
7
|
+
const postcss_value_parser_1 = __importDefault(require("postcss-value-parser"));
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
function processFunctions(value, fnMap, node, context) {
|
|
10
|
+
const parsed = (0, postcss_value_parser_1.default)(value);
|
|
5
11
|
// Helper to process nodes recursively (inner-first)
|
|
6
12
|
function processNode(parsedValue) {
|
|
7
13
|
parsedValue.walk((nodeIter) => {
|
|
@@ -31,7 +37,7 @@ export function processFunctions(value, fnMap, node, context) {
|
|
|
31
37
|
currentArg = '';
|
|
32
38
|
}
|
|
33
39
|
else {
|
|
34
|
-
currentArg +=
|
|
40
|
+
currentArg += postcss_value_parser_1.default.stringify(argNode);
|
|
35
41
|
}
|
|
36
42
|
});
|
|
37
43
|
if (currentArg) {
|
|
@@ -46,7 +52,7 @@ export function processFunctions(value, fnMap, node, context) {
|
|
|
46
52
|
nodeIter.nodes = []; // Clear children
|
|
47
53
|
}
|
|
48
54
|
catch (error) {
|
|
49
|
-
reportError(`Failed to process function "${nodeIter.value}": ${error instanceof Error ? error.message : String(error)}`, node, context);
|
|
55
|
+
(0, errors_js_1.reportError)(`Failed to process function "${nodeIter.value}": ${error instanceof Error ? error.message : String(error)}`, node, context);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
}
|
package/dist/plugin.d.ts
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
functions: fnMap,
|
|
12
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dynamicFunctionsPlugin = void 0;
|
|
4
|
+
const index_js_1 = require("./functions/index.js");
|
|
5
|
+
const index_js_2 = require("./at-rules/index.js");
|
|
6
|
+
const config_js_1 = require("./config.js");
|
|
7
|
+
const parser_js_1 = require("./parser.js");
|
|
8
|
+
const dynamicFunctionsPlugin = (opts = {}) => {
|
|
9
|
+
let context;
|
|
10
|
+
let fnMap;
|
|
13
11
|
return {
|
|
14
12
|
postcssPlugin: "postcss-dynamic-functions",
|
|
13
|
+
Once() {
|
|
14
|
+
const { config, options } = (0, config_js_1.loadConfig)(opts);
|
|
15
|
+
fnMap = { ...index_js_1.functions, ...opts.functions };
|
|
16
|
+
context = {
|
|
17
|
+
config,
|
|
18
|
+
options,
|
|
19
|
+
functions: fnMap,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
15
22
|
Declaration(decl) {
|
|
16
|
-
|
|
23
|
+
if (!context || !fnMap)
|
|
24
|
+
return;
|
|
25
|
+
decl.value = (0, parser_js_1.processFunctions)(decl.value, fnMap, decl, context);
|
|
17
26
|
},
|
|
18
27
|
// Override AtRule handler to ensure ordered execution
|
|
19
28
|
AtRule(atRule) {
|
|
29
|
+
if (!context)
|
|
30
|
+
return;
|
|
20
31
|
// Iterate over handlers in order (array) instead of object spread
|
|
21
|
-
for (const { name, handler } of atRuleHandlers) {
|
|
32
|
+
for (const { name, handler } of index_js_2.atRuleHandlers) {
|
|
22
33
|
if (atRule.name === name) {
|
|
23
34
|
handler(atRule, context);
|
|
24
35
|
}
|
|
@@ -26,4 +37,5 @@ export const dynamicFunctionsPlugin = (opts = {}) => {
|
|
|
26
37
|
},
|
|
27
38
|
};
|
|
28
39
|
};
|
|
29
|
-
dynamicFunctionsPlugin
|
|
40
|
+
exports.dynamicFunctionsPlugin = dynamicFunctionsPlugin;
|
|
41
|
+
exports.dynamicFunctionsPlugin.postcss = true;
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
import type { AtRule, ChildNode } from "postcss";
|
|
2
3
|
import { PluginContext } from "../types.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -18,7 +19,7 @@ function createColorSchemeHandler(scheme: 'light' | 'dark') {
|
|
|
18
19
|
/**
|
|
19
20
|
* Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
|
|
20
21
|
*/
|
|
21
|
-
const explicitRule = new Rule({
|
|
22
|
+
const explicitRule = new postcss.Rule({
|
|
22
23
|
selector: `[${modeAttribute}="${scheme}"] &`,
|
|
23
24
|
source: atRule.source,
|
|
24
25
|
});
|
|
@@ -27,13 +28,13 @@ function createColorSchemeHandler(scheme: 'light' | 'dark') {
|
|
|
27
28
|
/**
|
|
28
29
|
* Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
|
|
29
30
|
*/
|
|
30
|
-
const mediaAtRule = new AtRule({
|
|
31
|
+
const mediaAtRule = new postcss.AtRule({
|
|
31
32
|
name: "media",
|
|
32
33
|
params: `(prefers-color-scheme: ${scheme})`,
|
|
33
34
|
source: atRule.source,
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
const systemRule = new Rule({
|
|
37
|
+
const systemRule = new postcss.Rule({
|
|
37
38
|
selector: `[${modeAttribute}="system"] &`,
|
|
38
39
|
source: atRule.source,
|
|
39
40
|
});
|
package/src/at-rules/color.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
import type { AtRule, ChildNode } from "postcss";
|
|
2
3
|
import { PluginContext } from "../types.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -44,7 +45,7 @@ export default function container(atRule: AtRule, context: PluginContext) {
|
|
|
44
45
|
clonedNodes.push(node.clone());
|
|
45
46
|
});
|
|
46
47
|
|
|
47
|
-
const containerAtRule = new AtRule({
|
|
48
|
+
const containerAtRule = new postcss.AtRule({
|
|
48
49
|
name: "container",
|
|
49
50
|
params: `(min-width: ${minWidth})`,
|
|
50
51
|
source: atRule.source,
|
package/src/at-rules/index.ts
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
import type { ChildNode, Declaration, AtRule } from "postcss";
|
|
2
3
|
import { processFunctions } from "./parser.js";
|
|
3
4
|
import { PluginContext } from './types.js';
|
|
4
5
|
|
|
@@ -27,7 +28,7 @@ export function cloneNodes(
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
if (cloned.type === "rule") {
|
|
30
|
-
const rule = cloned as Rule;
|
|
31
|
+
const rule = cloned as postcss.Rule;
|
|
31
32
|
if (!rule.selector) return [];
|
|
32
33
|
|
|
33
34
|
rule.selector = rule.selector.replace(/\{name\}/g, name);
|
|
@@ -53,17 +54,17 @@ export function generateRules(
|
|
|
53
54
|
names: string[],
|
|
54
55
|
atRule: AtRule,
|
|
55
56
|
context: PluginContext
|
|
56
|
-
): Rule[] {
|
|
57
|
+
): postcss.Rule[] {
|
|
57
58
|
const nodes = atRule.nodes ?? [];
|
|
58
|
-
const generatedRules: Rule[] = [];
|
|
59
|
+
const generatedRules: postcss.Rule[] = [];
|
|
59
60
|
|
|
60
61
|
for (const name of names) {
|
|
61
|
-
const rule = new Rule({
|
|
62
|
+
const rule = new postcss.Rule({
|
|
62
63
|
selector: `&.${name}`,
|
|
63
64
|
source: atRule.source,
|
|
64
65
|
});
|
|
65
66
|
cloneNodes(nodes, name, context).forEach((n) => {
|
|
66
|
-
if (n.type === "rule" && n.selector && n.nodes?.length) rule.append(n);
|
|
67
|
+
if (n.type === "rule" && n.selector && (n as postcss.Rule).nodes?.length) rule.append(n);
|
|
67
68
|
if (n.type === "decl") rule.append(n);
|
|
68
69
|
});
|
|
69
70
|
|
package/src/plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginCreator } from "postcss";
|
|
1
|
+
import type { PluginCreator } from "postcss";
|
|
2
2
|
import { functions } from "./functions/index.js";
|
|
3
3
|
import { atRuleHandlers } from "./at-rules/index.js";
|
|
4
4
|
import { loadConfig } from "./config.js";
|
|
@@ -8,23 +8,30 @@ import { processFunctions } from "./parser.js";
|
|
|
8
8
|
export const dynamicFunctionsPlugin: PluginCreator<PluginOptions> = (
|
|
9
9
|
opts = {}
|
|
10
10
|
) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const context: PluginContext = {
|
|
14
|
-
config,
|
|
15
|
-
options,
|
|
16
|
-
functions: fnMap,
|
|
17
|
-
};
|
|
11
|
+
let context: PluginContext | undefined;
|
|
12
|
+
let fnMap: FunctionMap | undefined;
|
|
18
13
|
|
|
19
14
|
return {
|
|
20
15
|
postcssPlugin: "postcss-dynamic-functions",
|
|
21
16
|
|
|
17
|
+
Once() {
|
|
18
|
+
const { config, options } = loadConfig(opts);
|
|
19
|
+
fnMap = { ...functions, ...opts.functions };
|
|
20
|
+
context = {
|
|
21
|
+
config,
|
|
22
|
+
options,
|
|
23
|
+
functions: fnMap,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
|
|
22
27
|
Declaration(decl) {
|
|
28
|
+
if (!context || !fnMap) return;
|
|
23
29
|
decl.value = processFunctions(decl.value, fnMap, decl, context);
|
|
24
30
|
},
|
|
25
31
|
|
|
26
32
|
// Override AtRule handler to ensure ordered execution
|
|
27
33
|
AtRule(atRule) {
|
|
34
|
+
if (!context) return;
|
|
28
35
|
// Iterate over handlers in order (array) instead of object spread
|
|
29
36
|
for (const { name, handler } of atRuleHandlers) {
|
|
30
37
|
if (atRule.name === name) {
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
3
|
+
"target": "ES2019",
|
|
4
|
+
"module": "CommonJS",
|
|
5
5
|
"lib": ["ES2020"],
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"outDir": "dist",
|
|
8
8
|
"strict": true,
|
|
9
|
-
"moduleResolution": "
|
|
9
|
+
"moduleResolution": "Node",
|
|
10
10
|
"esModuleInterop": true,
|
|
11
11
|
"skipLibCheck": true
|
|
12
12
|
},
|