@seyuna/postcss 1.0.0-canary.14 → 1.0.0-canary.16
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/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +15 -0
- package/README.md +275 -0
- package/dist/at-rules/color-scheme.d.ts +4 -0
- package/dist/at-rules/color-scheme.js +43 -0
- package/dist/at-rules/color.d.ts +3 -2
- package/dist/at-rules/color.js +10 -21
- package/dist/at-rules/container.d.ts +2 -1
- package/dist/at-rules/container.js +12 -8
- package/dist/at-rules/index.d.ts +3 -2
- package/dist/at-rules/index.js +14 -23
- package/dist/config.d.ts +18 -0
- package/dist/config.js +47 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +14 -0
- package/dist/functions/color.d.ts +7 -2
- package/dist/functions/color.js +58 -29
- package/dist/functions/index.d.ts +2 -1
- package/dist/functions/index.js +10 -12
- package/dist/functions/theme.d.ts +6 -0
- package/dist/functions/theme.js +17 -0
- package/dist/helpers.d.ts +3 -2
- package/dist/helpers.js +13 -28
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -5
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +59 -0
- package/dist/plugin.d.ts +2 -4
- package/dist/plugin.js +16 -22
- package/dist/types.d.ts +1 -19
- package/dist/types.js +1 -2
- package/package.json +13 -5
- package/release.config.mjs +6 -1
- package/src/at-rules/color-scheme.ts +52 -0
- package/src/at-rules/color.ts +11 -15
- package/src/at-rules/container.ts +13 -3
- package/src/at-rules/index.ts +6 -8
- package/src/config.ts +71 -0
- package/src/errors.ts +23 -0
- package/src/functions/color.ts +70 -29
- package/src/functions/index.ts +9 -4
- package/src/functions/theme.ts +20 -0
- package/src/helpers.ts +23 -22
- package/src/index.ts +3 -1
- package/src/parser.ts +80 -0
- package/src/plugin.ts +12 -21
- package/src/types.ts +1 -19
- package/tests/plugin.test.ts +143 -0
- package/tsconfig.json +2 -2
- package/dist/at-rules/dark.d.ts +0 -23
- package/dist/at-rules/dark.js +0 -65
- package/dist/at-rules/light.d.ts +0 -23
- package/dist/at-rules/light.js +0 -65
- package/dist/functions/spacing.d.ts +0 -1
- package/dist/functions/spacing.js +0 -6
- package/src/at-rules/dark.ts +0 -69
- package/src/at-rules/light.ts +0 -69
- package/src/functions/spacing.ts +0 -3
package/dist/functions/color.js
CHANGED
|
@@ -1,34 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a color name to its CSS variables based on its type (standard or fixed)
|
|
3
|
+
*/
|
|
4
|
+
function getColorVariables(context, color, type) {
|
|
5
|
+
const { config } = context;
|
|
6
|
+
const hues = config?.ui?.theme?.hues || {};
|
|
7
|
+
const colors = config?.ui?.theme?.colors || {};
|
|
8
|
+
const lightColors = config?.ui?.theme?.light?.colors || {};
|
|
9
|
+
const darkColors = config?.ui?.theme?.dark?.colors || {};
|
|
10
|
+
const isStandard = color in hues;
|
|
11
|
+
const isFixed = color in colors || color in lightColors || color in darkColors;
|
|
12
|
+
if (type === 'sc' && !isStandard) {
|
|
13
|
+
throw new Error(`Standard color '${color}' not found in seyuna.json hues`);
|
|
11
14
|
}
|
|
12
|
-
if (
|
|
13
|
-
|
|
15
|
+
if (type === 'fc' && !isFixed) {
|
|
16
|
+
throw new Error(`Fixed color '${color}' not found in seyuna.json colors`);
|
|
14
17
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
18
|
+
if (isStandard) {
|
|
19
|
+
return {
|
|
20
|
+
l: "var(--lightness)",
|
|
21
|
+
c: "var(--chroma)",
|
|
22
|
+
h: `var(--${color}-hue)`,
|
|
23
|
+
};
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (alpha && alpha !== "null") {
|
|
25
|
-
a = alpha;
|
|
26
|
-
}
|
|
27
|
-
if (lightness && lightness !== "null") {
|
|
28
|
-
l = lightness;
|
|
29
|
-
}
|
|
30
|
-
if (chroma && chroma !== "null") {
|
|
31
|
-
c = chroma;
|
|
25
|
+
if (isFixed) {
|
|
26
|
+
return {
|
|
27
|
+
l: `var(--${color}-lightness)`,
|
|
28
|
+
c: `var(--${color}-chroma)`,
|
|
29
|
+
h: `var(--${color}-hue)`,
|
|
30
|
+
};
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
throw new Error(`Color '${color}' not found in seyuna.json`);
|
|
33
|
+
}
|
|
34
|
+
export function sc(context, name, alpha, lightness, chroma) {
|
|
35
|
+
const vars = getColorVariables(context, name, 'sc');
|
|
36
|
+
const a = alpha && alpha !== "null" ? alpha : "1";
|
|
37
|
+
const l = lightness && lightness !== "null" ? lightness : vars.l;
|
|
38
|
+
const c = chroma && chroma !== "null" ? chroma : vars.c;
|
|
39
|
+
return `oklch(${l} ${c} ${vars.h} / ${a})`;
|
|
40
|
+
}
|
|
41
|
+
export function fc(context, name, alpha, lightness, chroma) {
|
|
42
|
+
const vars = getColorVariables(context, name, 'fc');
|
|
43
|
+
const a = alpha && alpha !== "null" ? alpha : "1";
|
|
44
|
+
const l = lightness && lightness !== "null" ? lightness : vars.l;
|
|
45
|
+
const c = chroma && chroma !== "null" ? chroma : vars.c;
|
|
46
|
+
return `oklch(${l} ${c} ${vars.h} / ${a})`;
|
|
47
|
+
}
|
|
48
|
+
export function alpha(context, color, value) {
|
|
49
|
+
const { l, c, h } = getColorVariables(context, color);
|
|
50
|
+
return `oklch(${l} ${c} ${h} / ${value})`;
|
|
51
|
+
}
|
|
52
|
+
export function lighten(context, color, amount) {
|
|
53
|
+
const { l, c, h } = getColorVariables(context, color);
|
|
54
|
+
return `oklch(calc(${l} + ${amount}) ${c} ${h} / 1)`;
|
|
55
|
+
}
|
|
56
|
+
export function darken(context, color, amount) {
|
|
57
|
+
const { l, c, h } = getColorVariables(context, color);
|
|
58
|
+
return `oklch(calc(${l} - ${amount}) ${c} ${h} / 1)`;
|
|
59
|
+
}
|
|
60
|
+
export function contrast(context, color) {
|
|
61
|
+
const { l } = getColorVariables(context, color);
|
|
62
|
+
return `oklch(calc((${l} - 0.6) * -1000) 0 0)`;
|
|
34
63
|
}
|
package/dist/functions/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
fc: color_1.fc,
|
|
12
|
-
spacing: spacing_1.default,
|
|
1
|
+
import { sc, fc, alpha, lighten, darken, contrast } from "./color";
|
|
2
|
+
import { theme } from "./theme";
|
|
3
|
+
export const functions = {
|
|
4
|
+
sc,
|
|
5
|
+
fc,
|
|
6
|
+
alpha,
|
|
7
|
+
lighten,
|
|
8
|
+
darken,
|
|
9
|
+
contrast,
|
|
10
|
+
theme,
|
|
13
11
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses values from the Seyuna configuration using dot notation
|
|
3
|
+
* Example: theme(ui.theme.breakpoints.tablet)
|
|
4
|
+
*/
|
|
5
|
+
export function theme(context, path) {
|
|
6
|
+
const parts = path.split('.');
|
|
7
|
+
let current = context.config;
|
|
8
|
+
for (const part of parts) {
|
|
9
|
+
if (current && typeof current === 'object' && part in current) {
|
|
10
|
+
current = current[part];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return path; // Return original path if not found
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return String(current);
|
|
17
|
+
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Rule, ChildNode, AtRule } from "postcss";
|
|
2
|
+
import { PluginContext } from "./config";
|
|
2
3
|
/**
|
|
3
4
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
4
5
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
5
6
|
*/
|
|
6
|
-
export declare function cloneNodes(nodes: ChildNode[], name: string): ChildNode[];
|
|
7
|
+
export declare function cloneNodes(nodes: ChildNode[], name: string, context: PluginContext): ChildNode[];
|
|
7
8
|
/**
|
|
8
9
|
* Generate CSS rules from a list of names
|
|
9
10
|
*/
|
|
10
|
-
export declare function generateRules(names: string[], atRule: AtRule): Rule[];
|
|
11
|
+
export declare function generateRules(names: string[], atRule: AtRule, context: PluginContext): Rule[];
|
package/dist/helpers.js
CHANGED
|
@@ -1,36 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.cloneNodes = cloneNodes;
|
|
4
|
-
exports.generateRules = generateRules;
|
|
5
|
-
const postcss_1 = require("postcss");
|
|
6
|
-
const color_1 = require("./functions/color");
|
|
1
|
+
import { Rule } from "postcss";
|
|
2
|
+
import { processFunctions } from "./parser";
|
|
7
3
|
/**
|
|
8
4
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
9
5
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
10
6
|
*/
|
|
11
|
-
function cloneNodes(nodes, name) {
|
|
7
|
+
export function cloneNodes(nodes, name, context) {
|
|
8
|
+
const { functions: fnMap } = context;
|
|
12
9
|
return nodes.flatMap((node) => {
|
|
13
10
|
const cloned = node.clone();
|
|
14
11
|
if (cloned.type === "decl") {
|
|
15
12
|
const decl = cloned;
|
|
16
13
|
let value = decl.value.replace(/\{name\}/g, name);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.match(/sc\(([^)]*)\)/)?.[1]
|
|
20
|
-
.split(",")
|
|
21
|
-
.map((s) => s.trim());
|
|
22
|
-
if (args)
|
|
23
|
-
value = (0, color_1.sc)(...args);
|
|
24
|
-
}
|
|
25
|
-
if (/fc\(/.test(value)) {
|
|
26
|
-
const args = value
|
|
27
|
-
.match(/fc\(([^)]*)\)/)?.[1]
|
|
28
|
-
.split(",")
|
|
29
|
-
.map((s) => s.trim());
|
|
30
|
-
if (args)
|
|
31
|
-
value = (0, color_1.fc)(...args);
|
|
32
|
-
}
|
|
33
|
-
decl.value = value;
|
|
14
|
+
// Process functions using the robust parser
|
|
15
|
+
decl.value = processFunctions(value, fnMap, decl, context);
|
|
34
16
|
return decl;
|
|
35
17
|
}
|
|
36
18
|
if (cloned.type === "rule") {
|
|
@@ -39,7 +21,7 @@ function cloneNodes(nodes, name) {
|
|
|
39
21
|
return [];
|
|
40
22
|
rule.selector = rule.selector.replace(/\{name\}/g, name);
|
|
41
23
|
// Recursively clone child nodes and only keep valid rules/decls
|
|
42
|
-
rule.nodes = cloneNodes(rule.nodes || [], name).filter((n) => n.type === "rule" || n.type === "decl");
|
|
24
|
+
rule.nodes = cloneNodes(rule.nodes || [], name, context).filter((n) => n.type === "rule" || n.type === "decl");
|
|
43
25
|
if (!rule.nodes.length)
|
|
44
26
|
return [];
|
|
45
27
|
return rule;
|
|
@@ -51,12 +33,15 @@ function cloneNodes(nodes, name) {
|
|
|
51
33
|
/**
|
|
52
34
|
* Generate CSS rules from a list of names
|
|
53
35
|
*/
|
|
54
|
-
function generateRules(names, atRule) {
|
|
36
|
+
export function generateRules(names, atRule, context) {
|
|
55
37
|
const nodes = atRule.nodes ?? [];
|
|
56
38
|
const generatedRules = [];
|
|
57
39
|
for (const name of names) {
|
|
58
|
-
const rule = new
|
|
59
|
-
|
|
40
|
+
const rule = new Rule({
|
|
41
|
+
selector: `&.${name}`,
|
|
42
|
+
source: atRule.source,
|
|
43
|
+
});
|
|
44
|
+
cloneNodes(nodes, name, context).forEach((n) => {
|
|
60
45
|
if (n.type === "rule" && n.selector && n.nodes?.length)
|
|
61
46
|
rule.append(n);
|
|
62
47
|
if (n.type === "decl")
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const plugin: import("postcss").PluginCreator<import("./config").PluginOptions> & {
|
|
2
2
|
postcss: boolean;
|
|
3
3
|
functions: Record<string, import("./functions").FnHandler>;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { dynamicFunctionsPlugin } from './plugin';
|
|
2
|
+
import { functions } from './functions';
|
|
3
|
+
// CommonJS-friendly export
|
|
4
|
+
const plugin = Object.assign(dynamicFunctionsPlugin, {
|
|
5
5
|
postcss: true,
|
|
6
|
-
functions
|
|
6
|
+
functions
|
|
7
7
|
});
|
|
8
|
+
export default plugin;
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Node } from 'postcss';
|
|
2
|
+
import { PluginContext } from './config';
|
|
3
|
+
export type FunctionMap = Record<string, (context: PluginContext, ...args: string[]) => string>;
|
|
4
|
+
export declare function processFunctions(value: string, fnMap: FunctionMap, node: Node, context: PluginContext): string;
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser';
|
|
2
|
+
import { reportError } from './errors';
|
|
3
|
+
export function processFunctions(value, fnMap, node, context) {
|
|
4
|
+
const parsed = valueParser(value);
|
|
5
|
+
// Helper to process nodes recursively (inner-first)
|
|
6
|
+
function processNode(parsedValue) {
|
|
7
|
+
parsedValue.walk((nodeIter) => {
|
|
8
|
+
// If nested nodes exist (e.g., in a function), process them first
|
|
9
|
+
if (nodeIter.type === 'function' && nodeIter.nodes.length > 0) {
|
|
10
|
+
// Here we recursively process child nodes before handling the current function
|
|
11
|
+
// However, value-parser's walk is already a visitor. To do inner-first,
|
|
12
|
+
// we can either walk in reverse or specifically handle children.
|
|
13
|
+
// A simpler way: since walk visits all, we can check if it's a function
|
|
14
|
+
// and if it's one we handle, we process its arguments.
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
// Actually, a manual walk is safer for inner-first replacement
|
|
18
|
+
function traverse(nodes) {
|
|
19
|
+
for (const nodeIter of nodes) {
|
|
20
|
+
if (nodeIter.type === 'function') {
|
|
21
|
+
// Process inner functions first
|
|
22
|
+
traverse(nodeIter.nodes);
|
|
23
|
+
// Now handle this function if it's in our map
|
|
24
|
+
if (fnMap[nodeIter.value]) {
|
|
25
|
+
const handler = fnMap[nodeIter.value];
|
|
26
|
+
const args = [];
|
|
27
|
+
let currentArg = '';
|
|
28
|
+
nodeIter.nodes.forEach((argNode) => {
|
|
29
|
+
if (argNode.type === 'div' && argNode.value === ',') {
|
|
30
|
+
args.push(currentArg.trim());
|
|
31
|
+
currentArg = '';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
currentArg += valueParser.stringify(argNode);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (currentArg) {
|
|
38
|
+
args.push(currentArg.trim());
|
|
39
|
+
}
|
|
40
|
+
const cleanedArgs = args.map(arg => arg.replace(/^['"]|['"]$/g, ''));
|
|
41
|
+
try {
|
|
42
|
+
const result = handler(context, ...cleanedArgs);
|
|
43
|
+
// Replace function with its result
|
|
44
|
+
nodeIter.type = 'word';
|
|
45
|
+
nodeIter.value = result;
|
|
46
|
+
nodeIter.nodes = []; // Clear children
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
reportError(`Failed to process function "${nodeIter.value}": ${error instanceof Error ? error.message : String(error)}`, node, context);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
traverse(parsedValue.nodes);
|
|
56
|
+
}
|
|
57
|
+
processNode(parsed);
|
|
58
|
+
return parsed.toString();
|
|
59
|
+
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { PluginCreator } from "postcss";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export declare const dynamicFunctionsPlugin: PluginCreator<PluginOptions>;
|
|
2
|
+
import { PluginOptions as ConfigOptions } from "./config";
|
|
3
|
+
export declare const dynamicFunctionsPlugin: PluginCreator<ConfigOptions>;
|
package/dist/plugin.js
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const fnMap = { ...
|
|
1
|
+
import { functions } from "./functions";
|
|
2
|
+
import { atRuleHandlers } from "./at-rules";
|
|
3
|
+
import { loadConfig } from "./config";
|
|
4
|
+
import { processFunctions } from "./parser";
|
|
5
|
+
export const dynamicFunctionsPlugin = (opts = {}) => {
|
|
6
|
+
const { config, options } = loadConfig(opts);
|
|
7
|
+
const fnMap = { ...functions, ...opts.functions };
|
|
8
|
+
const context = {
|
|
9
|
+
config,
|
|
10
|
+
options,
|
|
11
|
+
functions: fnMap,
|
|
12
|
+
};
|
|
8
13
|
return {
|
|
9
14
|
postcssPlugin: "postcss-dynamic-functions",
|
|
10
15
|
Declaration(decl) {
|
|
11
|
-
|
|
12
|
-
for (const fnName in fnMap) {
|
|
13
|
-
const regex = new RegExp(`${fnName}\\(([^)]*)\\)`, "g");
|
|
14
|
-
value = value.replace(regex, (_match, argsStr) => {
|
|
15
|
-
const args = argsStr
|
|
16
|
-
.split(",")
|
|
17
|
-
.map((a) => a.trim().replace(/^['"]|['"]$/g, ""));
|
|
18
|
-
return fnMap[fnName](...args);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
decl.value = value;
|
|
16
|
+
decl.value = processFunctions(decl.value, fnMap, decl, context);
|
|
22
17
|
},
|
|
23
18
|
// Override AtRule handler to ensure ordered execution
|
|
24
19
|
AtRule(atRule) {
|
|
25
20
|
// Iterate over handlers in order (array) instead of object spread
|
|
26
|
-
for (const { name, handler } of
|
|
21
|
+
for (const { name, handler } of atRuleHandlers) {
|
|
27
22
|
if (atRule.name === name) {
|
|
28
|
-
handler(atRule);
|
|
23
|
+
handler(atRule, context);
|
|
29
24
|
}
|
|
30
25
|
}
|
|
31
26
|
},
|
|
32
27
|
};
|
|
33
28
|
};
|
|
34
|
-
|
|
35
|
-
exports.dynamicFunctionsPlugin.postcss = true;
|
|
29
|
+
dynamicFunctionsPlugin.postcss = true;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
ui: {
|
|
3
|
-
theme: {
|
|
4
|
-
hues: Record<string, number>;
|
|
5
|
-
light: {
|
|
6
|
-
colors: Record<string, Color>;
|
|
7
|
-
};
|
|
8
|
-
dark: {
|
|
9
|
-
colors: Record<string, Color>;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
type Color = {
|
|
15
|
-
lightness: number;
|
|
16
|
-
chroma: number;
|
|
17
|
-
hue: number;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
1
|
+
export type { Config as SeyunaConfig, Color } from "@seyuna/cli/types";
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seyuna/postcss",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.16",
|
|
4
4
|
"description": "Seyuna UI's postcss plugin",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"dev": "tsc -w"
|
|
9
|
+
"dev": "tsc -w",
|
|
10
|
+
"test": "vitest",
|
|
11
|
+
"test:run": "vitest run"
|
|
10
12
|
},
|
|
11
13
|
"keywords": [
|
|
12
14
|
"postcss",
|
|
@@ -18,6 +20,10 @@
|
|
|
18
20
|
"type": "git",
|
|
19
21
|
"url": "git+https://github.com/seyuna-corp/seyuna-postcss.git"
|
|
20
22
|
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@seyuna/cli": "^1.0.0-canary.28",
|
|
25
|
+
"postcss-value-parser": "^4.2.0"
|
|
26
|
+
},
|
|
21
27
|
"peerDependencies": {
|
|
22
28
|
"postcss": "^8.5.6"
|
|
23
29
|
},
|
|
@@ -27,12 +33,14 @@
|
|
|
27
33
|
"@semantic-release/exec": "^7.1.0",
|
|
28
34
|
"@semantic-release/git": "^10.0.1",
|
|
29
35
|
"@semantic-release/github": "^11.0.3",
|
|
30
|
-
"@semantic-release/npm": "^
|
|
36
|
+
"@semantic-release/npm": "^13.1.3",
|
|
31
37
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
32
38
|
"@types/node": "^20.0.0",
|
|
39
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
33
40
|
"postcss": "^8.5.6",
|
|
34
41
|
"postcss-selector-parser": "^7.1.0",
|
|
35
|
-
"semantic-release": "^
|
|
36
|
-
"typescript": "^5.0.0"
|
|
42
|
+
"semantic-release": "^25.0.2",
|
|
43
|
+
"typescript": "^5.0.0",
|
|
44
|
+
"vitest": "^4.0.16"
|
|
37
45
|
}
|
|
38
46
|
}
|
package/release.config.mjs
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
export default {
|
|
5
5
|
branches: [{ name: "canary", prerelease: "canary" }, "main"],
|
|
6
6
|
plugins: [
|
|
7
|
-
|
|
7
|
+
[
|
|
8
|
+
"@semantic-release/commit-analyzer",
|
|
9
|
+
{
|
|
10
|
+
preset: "conventionalcommits",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
8
13
|
"@semantic-release/release-notes-generator",
|
|
9
14
|
["@semantic-release/changelog", { changelogFile: "CHANGELOG.md" }],
|
|
10
15
|
[
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Rule, AtRule, ChildNode } from "postcss";
|
|
2
|
+
import { PluginContext } from "../config";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom PostCSS plugin handler factory for `@light` and `@dark` at-rules.
|
|
6
|
+
*/
|
|
7
|
+
function createColorSchemeHandler(scheme: 'light' | 'dark') {
|
|
8
|
+
return (atRule: AtRule, context: PluginContext) => {
|
|
9
|
+
const { options } = context;
|
|
10
|
+
const modeAttribute = options.modeAttribute;
|
|
11
|
+
const clonedNodes: ChildNode[] = [];
|
|
12
|
+
|
|
13
|
+
// Clone all child nodes inside the block
|
|
14
|
+
atRule.each((node: ChildNode) => {
|
|
15
|
+
clonedNodes.push(node.clone());
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
|
|
20
|
+
*/
|
|
21
|
+
const explicitRule = new Rule({
|
|
22
|
+
selector: `[${modeAttribute}="${scheme}"] &`,
|
|
23
|
+
source: atRule.source,
|
|
24
|
+
});
|
|
25
|
+
clonedNodes.forEach((node) => explicitRule.append(node.clone()));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
|
|
29
|
+
*/
|
|
30
|
+
const mediaAtRule = new AtRule({
|
|
31
|
+
name: "media",
|
|
32
|
+
params: `(prefers-color-scheme: ${scheme})`,
|
|
33
|
+
source: atRule.source,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const systemRule = new Rule({
|
|
37
|
+
selector: `[${modeAttribute}="system"] &`,
|
|
38
|
+
source: atRule.source,
|
|
39
|
+
});
|
|
40
|
+
clonedNodes.forEach((node) => systemRule.append(node.clone()));
|
|
41
|
+
|
|
42
|
+
mediaAtRule.append(systemRule);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Replace the original at-rule with the generated rules.
|
|
46
|
+
*/
|
|
47
|
+
atRule.replaceWith(mediaAtRule, explicitRule);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const light = createColorSchemeHandler('light');
|
|
52
|
+
export const dark = createColorSchemeHandler('dark');
|
package/src/at-rules/color.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { AtRule
|
|
2
|
-
import
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { SeyunaConfig } from "../types";
|
|
1
|
+
import { AtRule } from "postcss";
|
|
2
|
+
import { PluginContext } from "../config";
|
|
5
3
|
import { generateRules } from "../helpers";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Handler for @each-standard-color
|
|
9
7
|
*/
|
|
10
|
-
export function eachStandardColor(atRule: AtRule) {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const hueNames = Object.keys(data.ui.theme.hues);
|
|
8
|
+
export function eachStandardColor(atRule: AtRule, context: PluginContext) {
|
|
9
|
+
const { config } = context;
|
|
10
|
+
const hueNames = config.ui ? Object.keys(config.ui.theme.hues) : [];
|
|
14
11
|
|
|
15
|
-
const rules = generateRules(hueNames, atRule);
|
|
12
|
+
const rules = generateRules(hueNames, atRule, context);
|
|
16
13
|
if (rules.length) atRule.replaceWith(...rules);
|
|
17
14
|
else atRule.remove();
|
|
18
15
|
}
|
|
@@ -20,18 +17,17 @@ export function eachStandardColor(atRule: AtRule) {
|
|
|
20
17
|
/**
|
|
21
18
|
* Handler for @each-fixed-color
|
|
22
19
|
*/
|
|
23
|
-
export function eachFixedColor(atRule: AtRule) {
|
|
24
|
-
const
|
|
25
|
-
const data: SeyunaConfig = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
|
|
20
|
+
export function eachFixedColor(atRule: AtRule, context: PluginContext) {
|
|
21
|
+
const { config } = context;
|
|
26
22
|
|
|
27
23
|
const mergedNames = [
|
|
28
24
|
...new Set([
|
|
29
|
-
...Object.keys(
|
|
30
|
-
...Object.keys(
|
|
25
|
+
...(config.ui ? Object.keys(config.ui.theme.light.colors) : []),
|
|
26
|
+
...(config.ui ? Object.keys(config.ui.theme.dark.colors) : []),
|
|
31
27
|
]),
|
|
32
28
|
];
|
|
33
29
|
|
|
34
|
-
const rules = generateRules(mergedNames, atRule);
|
|
30
|
+
const rules = generateRules(mergedNames, atRule, context);
|
|
35
31
|
if (rules.length) atRule.replaceWith(...rules);
|
|
36
32
|
else atRule.remove();
|
|
37
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AtRule, ChildNode } from "postcss";
|
|
2
|
+
import { PluginContext } from "../config";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Custom PostCSS plugin handler for responsive at-rules.
|
|
@@ -16,9 +17,11 @@ import { AtRule, ChildNode } from "postcss";
|
|
|
16
17
|
* }
|
|
17
18
|
*
|
|
18
19
|
*/
|
|
19
|
-
export default function container(atRule: AtRule) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
export default function container(atRule: AtRule, context: PluginContext) {
|
|
21
|
+
const { config } = context;
|
|
22
|
+
|
|
23
|
+
// Default breakpoints
|
|
24
|
+
const defaultBreakpoints: Record<string, string> = {
|
|
22
25
|
xs: "20rem",
|
|
23
26
|
sm: "40rem",
|
|
24
27
|
md: "48rem",
|
|
@@ -27,6 +30,12 @@ export default function container(atRule: AtRule) {
|
|
|
27
30
|
"2xl": "96rem",
|
|
28
31
|
};
|
|
29
32
|
|
|
33
|
+
// Merge with config if available (assuming config.ui.breakpoints exists)
|
|
34
|
+
const breakpoints = {
|
|
35
|
+
...defaultBreakpoints,
|
|
36
|
+
...((config as any).ui?.theme?.breakpoints || {}),
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
if (Object.keys(breakpoints).includes(atRule.name)) {
|
|
31
40
|
const minWidth = breakpoints[atRule.name];
|
|
32
41
|
|
|
@@ -38,6 +47,7 @@ export default function container(atRule: AtRule) {
|
|
|
38
47
|
const containerAtRule = new AtRule({
|
|
39
48
|
name: "container",
|
|
40
49
|
params: `(min-width: ${minWidth})`,
|
|
50
|
+
source: atRule.source,
|
|
41
51
|
});
|
|
42
52
|
|
|
43
53
|
clonedNodes.forEach((node) => containerAtRule.append(node));
|
package/src/at-rules/index.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import dark from "./dark";
|
|
3
|
-
import light from "./light";
|
|
4
|
-
import container from "./container";
|
|
1
|
+
import { AtRule } from "postcss";
|
|
5
2
|
import { eachStandardColor, eachFixedColor } from "./color";
|
|
6
|
-
import
|
|
3
|
+
import container from "./container";
|
|
4
|
+
import { light, dark } from "./color-scheme";
|
|
5
|
+
import { PluginContext } from "../config";
|
|
7
6
|
|
|
8
7
|
// Each handler has a name (matches the at-rule) and the function
|
|
9
8
|
export interface AtRuleHandler {
|
|
10
9
|
name: string;
|
|
11
|
-
handler: (atRule: AtRule) => void;
|
|
10
|
+
handler: (atRule: AtRule, context: PluginContext) => void;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
// Ordered array ensures execution order
|
|
15
14
|
export const atRuleHandlers: AtRuleHandler[] = [
|
|
16
|
-
{ name: "each-standard-color", handler: eachStandardColor },
|
|
15
|
+
{ name: "each-standard-color", handler: eachStandardColor },
|
|
17
16
|
{ name: "each-fixed-color", handler: eachFixedColor },
|
|
18
17
|
{ name: "light", handler: light },
|
|
19
18
|
{ name: "dark", handler: dark },
|
|
@@ -23,5 +22,4 @@ export const atRuleHandlers: AtRuleHandler[] = [
|
|
|
23
22
|
{ name: "lg", handler: container },
|
|
24
23
|
{ name: "xl", handler: container },
|
|
25
24
|
{ name: "2xl", handler: container },
|
|
26
|
-
// add more handlers here as needed
|
|
27
25
|
];
|