@seyuna/postcss 1.0.0-canary.2 → 1.0.0-canary.20
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 +139 -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 +10 -0
- package/dist/at-rules/color.js +30 -0
- package/dist/at-rules/container.d.ts +19 -0
- package/dist/at-rules/container.js +48 -0
- package/dist/at-rules/index.d.ts +7 -3
- package/dist/at-rules/index.js +16 -13
- package/dist/config.d.ts +6 -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 -1
- package/dist/functions/color.js +59 -14
- package/dist/functions/index.d.ts +2 -1
- package/dist/functions/index.js +10 -11
- package/dist/functions/theme.d.ts +6 -0
- package/dist/functions/theme.js +17 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.js +54 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -5
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +59 -0
- package/dist/plugin.d.ts +1 -3
- package/dist/plugin.js +22 -22
- package/dist/types.d.ts +59 -0
- package/dist/types.js +3 -0
- package/package.json +15 -5
- package/release.config.mjs +6 -1
- package/src/at-rules/color-scheme.ts +52 -0
- package/src/at-rules/color.ts +33 -0
- package/src/at-rules/container.ts +57 -0
- package/src/at-rules/index.ts +23 -9
- package/src/config.ts +59 -0
- package/src/errors.ts +23 -0
- package/src/functions/color.ts +80 -14
- package/src/functions/index.ts +11 -5
- package/src/functions/theme.ts +20 -0
- package/src/helpers.ts +74 -0
- package/src/index.ts +5 -3
- package/src/parser.ts +81 -0
- package/src/plugin.ts +21 -23
- package/src/types.ts +72 -0
- package/tests/plugin.test.ts +143 -0
- package/tsconfig.json +2 -2
- package/dist/at-rules/dark.d.ts +0 -2
- package/dist/at-rules/dark.js +0 -28
- package/dist/at-rules/light.d.ts +0 -2
- package/dist/at-rules/light.js +0 -28
- package/dist/functions/spacing.d.ts +0 -1
- package/dist/functions/spacing.js +0 -6
- package/src/at-rules/dark.ts +0 -33
- package/src/at-rules/light.ts +0 -33
- package/src/functions/spacing.ts +0 -3
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Node } from 'postcss';
|
|
2
|
+
import { PluginContext } from './types.js';
|
|
3
|
+
export declare function reportError(message: string, node: Node, context: PluginContext, options?: {
|
|
4
|
+
word?: string;
|
|
5
|
+
index?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
export declare function reportWarning(message: string, node: Node): void;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function reportError(message, node, context, options = {}) {
|
|
2
|
+
const { options: pluginOptions } = context;
|
|
3
|
+
const formattedMessage = `[Seyuna PostCSS] ${message}`;
|
|
4
|
+
if (pluginOptions.strict) {
|
|
5
|
+
throw node.error(formattedMessage, options);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
reportWarning(formattedMessage, node);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function reportWarning(message, node) {
|
|
12
|
+
const result = node.root().toResult();
|
|
13
|
+
node.warn(result, `[Seyuna PostCSS] ${message}`);
|
|
14
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { PluginContext } from "../types.js";
|
|
2
|
+
export declare function sc(context: PluginContext, name: string, alpha?: string, lightness?: string, chroma?: string): string;
|
|
3
|
+
export declare function fc(context: PluginContext, name: string, alpha?: string, lightness?: string, chroma?: string): string;
|
|
4
|
+
export declare function alpha(context: PluginContext, color: string, value: string): string;
|
|
5
|
+
export declare function lighten(context: PluginContext, color: string, amount: string): string;
|
|
6
|
+
export declare function darken(context: PluginContext, color: string, amount: string): string;
|
|
7
|
+
export declare function contrast(context: PluginContext, color: string): string;
|
package/dist/functions/color.js
CHANGED
|
@@ -1,18 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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`);
|
|
10
14
|
}
|
|
11
|
-
if (
|
|
12
|
-
|
|
15
|
+
if (type === 'fc' && !isFixed) {
|
|
16
|
+
throw new Error(`Fixed color '${color}' not found in seyuna.json colors`);
|
|
13
17
|
}
|
|
14
|
-
if (
|
|
15
|
-
|
|
18
|
+
if (isStandard) {
|
|
19
|
+
return {
|
|
20
|
+
l: "var(--lightness)",
|
|
21
|
+
c: "var(--chroma)",
|
|
22
|
+
h: `var(--${color}-hue)`,
|
|
23
|
+
};
|
|
16
24
|
}
|
|
17
|
-
|
|
25
|
+
if (isFixed) {
|
|
26
|
+
return {
|
|
27
|
+
l: `var(--${color}-lightness)`,
|
|
28
|
+
c: `var(--${color}-chroma)`,
|
|
29
|
+
h: `var(--${color}-hue)`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
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)`;
|
|
18
63
|
}
|
package/dist/functions/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
spacing: spacing_1.default,
|
|
1
|
+
import { sc, fc, alpha, lighten, darken, contrast } from "./color.js";
|
|
2
|
+
import { theme } from "./theme.js";
|
|
3
|
+
export const functions = {
|
|
4
|
+
sc,
|
|
5
|
+
fc,
|
|
6
|
+
alpha,
|
|
7
|
+
lighten,
|
|
8
|
+
darken,
|
|
9
|
+
contrast,
|
|
10
|
+
theme,
|
|
12
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Rule, ChildNode, AtRule } from "postcss";
|
|
2
|
+
import { PluginContext } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Helper: clone nodes and replace {name} placeholders safely
|
|
5
|
+
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
6
|
+
*/
|
|
7
|
+
export declare function cloneNodes(nodes: ChildNode[], name: string, context: PluginContext): ChildNode[];
|
|
8
|
+
/**
|
|
9
|
+
* Generate CSS rules from a list of names
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateRules(names: string[], atRule: AtRule, context: PluginContext): Rule[];
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Rule } from "postcss";
|
|
2
|
+
import { processFunctions } from "./parser.js";
|
|
3
|
+
/**
|
|
4
|
+
* Helper: clone nodes and replace {name} placeholders safely
|
|
5
|
+
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
6
|
+
*/
|
|
7
|
+
export function cloneNodes(nodes, name, context) {
|
|
8
|
+
const { functions: fnMap } = context;
|
|
9
|
+
return nodes.flatMap((node) => {
|
|
10
|
+
const cloned = node.clone();
|
|
11
|
+
if (cloned.type === "decl") {
|
|
12
|
+
const decl = cloned;
|
|
13
|
+
let value = decl.value.replace(/\{name\}/g, name);
|
|
14
|
+
// Process functions using the robust parser
|
|
15
|
+
decl.value = processFunctions(value, fnMap, decl, context);
|
|
16
|
+
return decl;
|
|
17
|
+
}
|
|
18
|
+
if (cloned.type === "rule") {
|
|
19
|
+
const rule = cloned;
|
|
20
|
+
if (!rule.selector)
|
|
21
|
+
return [];
|
|
22
|
+
rule.selector = rule.selector.replace(/\{name\}/g, name);
|
|
23
|
+
// Recursively clone child nodes and only keep valid rules/decls
|
|
24
|
+
rule.nodes = cloneNodes(rule.nodes || [], name, context).filter((n) => n.type === "rule" || n.type === "decl");
|
|
25
|
+
if (!rule.nodes.length)
|
|
26
|
+
return [];
|
|
27
|
+
return rule;
|
|
28
|
+
}
|
|
29
|
+
// Ignore AtRules inside rules — they must be processed first
|
|
30
|
+
return [];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generate CSS rules from a list of names
|
|
35
|
+
*/
|
|
36
|
+
export function generateRules(names, atRule, context) {
|
|
37
|
+
const nodes = atRule.nodes ?? [];
|
|
38
|
+
const generatedRules = [];
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
const rule = new Rule({
|
|
41
|
+
selector: `&.${name}`,
|
|
42
|
+
source: atRule.source,
|
|
43
|
+
});
|
|
44
|
+
cloneNodes(nodes, name, context).forEach((n) => {
|
|
45
|
+
if (n.type === "rule" && n.selector && n.nodes?.length)
|
|
46
|
+
rule.append(n);
|
|
47
|
+
if (n.type === "decl")
|
|
48
|
+
rule.append(n);
|
|
49
|
+
});
|
|
50
|
+
if (rule.nodes.length)
|
|
51
|
+
generatedRules.push(rule);
|
|
52
|
+
}
|
|
53
|
+
return generatedRules;
|
|
54
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const plugin: import("postcss").PluginCreator<import("./types.js").PluginOptions> & {
|
|
2
2
|
postcss: boolean;
|
|
3
|
-
functions: Record<string, import("./functions").FnHandler>;
|
|
3
|
+
functions: Record<string, import("./functions/index.js").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.js';
|
|
2
|
+
import { functions } from './functions/index.js';
|
|
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
package/dist/parser.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser';
|
|
2
|
+
import { reportError } from './errors.js';
|
|
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
package/dist/plugin.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const fnMap = { ...
|
|
1
|
+
import { functions } from "./functions/index.js";
|
|
2
|
+
import { atRuleHandlers } from "./at-rules/index.js";
|
|
3
|
+
import { loadConfig } from "./config.js";
|
|
4
|
+
import { processFunctions } from "./parser.js";
|
|
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
|
-
AtRule
|
|
24
|
-
|
|
18
|
+
// Override AtRule handler to ensure ordered execution
|
|
19
|
+
AtRule(atRule) {
|
|
20
|
+
// Iterate over handlers in order (array) instead of object spread
|
|
21
|
+
for (const { name, handler } of atRuleHandlers) {
|
|
22
|
+
if (atRule.name === name) {
|
|
23
|
+
handler(atRule, context);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
25
26
|
},
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
-
exports.dynamicFunctionsPlugin.postcss = true;
|
|
29
|
+
dynamicFunctionsPlugin.postcss = true;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a color in the Oklch color space.
|
|
3
|
+
*/
|
|
4
|
+
export interface Color {
|
|
5
|
+
lightness: number;
|
|
6
|
+
chroma: number;
|
|
7
|
+
hue: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A set of colors for a specific theme mode.
|
|
11
|
+
*/
|
|
12
|
+
export interface Palette {
|
|
13
|
+
chroma: number;
|
|
14
|
+
lightness: number;
|
|
15
|
+
background: Color;
|
|
16
|
+
text: Color;
|
|
17
|
+
colors: Record<string, Color>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The complete theme specification.
|
|
21
|
+
*/
|
|
22
|
+
export interface Theme {
|
|
23
|
+
hues: Record<string, number>;
|
|
24
|
+
colors: Record<string, Color>;
|
|
25
|
+
light: Palette;
|
|
26
|
+
dark: Palette;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Supported color appearance modes.
|
|
30
|
+
*/
|
|
31
|
+
export type Mode = "system" | "light" | "dark";
|
|
32
|
+
/**
|
|
33
|
+
* UI Engine Configuration.
|
|
34
|
+
*/
|
|
35
|
+
export interface UI {
|
|
36
|
+
theme: Theme;
|
|
37
|
+
mode: Mode;
|
|
38
|
+
output_dir?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Root configuration structure for a Seyuna project.
|
|
42
|
+
*/
|
|
43
|
+
export interface SeyunaConfig {
|
|
44
|
+
license?: string;
|
|
45
|
+
ui?: UI;
|
|
46
|
+
}
|
|
47
|
+
export type FunctionMap = Record<string, (context: PluginContext, ...args: string[]) => string>;
|
|
48
|
+
export interface PluginOptions {
|
|
49
|
+
configPath?: string;
|
|
50
|
+
modeAttribute?: string;
|
|
51
|
+
strict?: boolean;
|
|
52
|
+
config?: SeyunaConfig;
|
|
53
|
+
functions?: FunctionMap;
|
|
54
|
+
}
|
|
55
|
+
export interface PluginContext {
|
|
56
|
+
config: SeyunaConfig;
|
|
57
|
+
options: Required<PluginOptions>;
|
|
58
|
+
functions: FunctionMap;
|
|
59
|
+
}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seyuna/postcss",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.20",
|
|
4
4
|
"description": "Seyuna UI's postcss plugin",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
|
-
"build": "tsc"
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc -w",
|
|
11
|
+
"test": "vitest",
|
|
12
|
+
"test:run": "vitest run"
|
|
9
13
|
},
|
|
10
14
|
"keywords": [
|
|
11
15
|
"postcss",
|
|
@@ -17,6 +21,9 @@
|
|
|
17
21
|
"type": "git",
|
|
18
22
|
"url": "git+https://github.com/seyuna-corp/seyuna-postcss.git"
|
|
19
23
|
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"postcss-value-parser": "^4.2.0"
|
|
26
|
+
},
|
|
20
27
|
"peerDependencies": {
|
|
21
28
|
"postcss": "^8.5.6"
|
|
22
29
|
},
|
|
@@ -26,11 +33,14 @@
|
|
|
26
33
|
"@semantic-release/exec": "^7.1.0",
|
|
27
34
|
"@semantic-release/git": "^10.0.1",
|
|
28
35
|
"@semantic-release/github": "^11.0.3",
|
|
29
|
-
"@semantic-release/npm": "^
|
|
36
|
+
"@semantic-release/npm": "^13.1.3",
|
|
30
37
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
31
38
|
"@types/node": "^20.0.0",
|
|
39
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
32
40
|
"postcss": "^8.5.6",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
41
|
+
"postcss-selector-parser": "^7.1.0",
|
|
42
|
+
"semantic-release": "^25.0.2",
|
|
43
|
+
"typescript": "^5.0.0",
|
|
44
|
+
"vitest": "^4.0.16"
|
|
35
45
|
}
|
|
36
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 "../types.js";
|
|
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');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AtRule } from "postcss";
|
|
2
|
+
import { PluginContext } from "../types.js";
|
|
3
|
+
import { generateRules } from "../helpers.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handler for @each-standard-color
|
|
7
|
+
*/
|
|
8
|
+
export function eachStandardColor(atRule: AtRule, context: PluginContext) {
|
|
9
|
+
const { config } = context;
|
|
10
|
+
const hueNames = config.ui ? Object.keys(config.ui.theme.hues) : [];
|
|
11
|
+
|
|
12
|
+
const rules = generateRules(hueNames, atRule, context);
|
|
13
|
+
if (rules.length) atRule.replaceWith(...rules);
|
|
14
|
+
else atRule.remove();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Handler for @each-fixed-color
|
|
19
|
+
*/
|
|
20
|
+
export function eachFixedColor(atRule: AtRule, context: PluginContext) {
|
|
21
|
+
const { config } = context;
|
|
22
|
+
|
|
23
|
+
const mergedNames = [
|
|
24
|
+
...new Set([
|
|
25
|
+
...(config.ui ? Object.keys(config.ui.theme.light.colors) : []),
|
|
26
|
+
...(config.ui ? Object.keys(config.ui.theme.dark.colors) : []),
|
|
27
|
+
]),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const rules = generateRules(mergedNames, atRule, context);
|
|
31
|
+
if (rules.length) atRule.replaceWith(...rules);
|
|
32
|
+
else atRule.remove();
|
|
33
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AtRule, ChildNode } from "postcss";
|
|
2
|
+
import { PluginContext } from "../types.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom PostCSS plugin handler for responsive at-rules.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
*
|
|
9
|
+
* @xs {
|
|
10
|
+
* .box { color: red; }
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* Into:
|
|
14
|
+
*
|
|
15
|
+
* @xs (min-width: 234px) {
|
|
16
|
+
* .box { color: red; }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export default function container(atRule: AtRule, context: PluginContext) {
|
|
21
|
+
const { config } = context;
|
|
22
|
+
|
|
23
|
+
// Default breakpoints
|
|
24
|
+
const defaultBreakpoints: Record<string, string> = {
|
|
25
|
+
xs: "20rem",
|
|
26
|
+
sm: "40rem",
|
|
27
|
+
md: "48rem",
|
|
28
|
+
lg: "64rem",
|
|
29
|
+
xl: "80rem",
|
|
30
|
+
"2xl": "96rem",
|
|
31
|
+
};
|
|
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
|
+
|
|
39
|
+
if (Object.keys(breakpoints).includes(atRule.name)) {
|
|
40
|
+
const minWidth = breakpoints[atRule.name];
|
|
41
|
+
|
|
42
|
+
const clonedNodes: ChildNode[] = [];
|
|
43
|
+
atRule.each((node: ChildNode) => {
|
|
44
|
+
clonedNodes.push(node.clone());
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const containerAtRule = new AtRule({
|
|
48
|
+
name: "container",
|
|
49
|
+
params: `(min-width: ${minWidth})`,
|
|
50
|
+
source: atRule.source,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
clonedNodes.forEach((node) => containerAtRule.append(node));
|
|
54
|
+
|
|
55
|
+
atRule.replaceWith(containerAtRule);
|
|
56
|
+
}
|
|
57
|
+
}
|