@seyuna/postcss 1.0.0-canary.2 → 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.
Files changed (58) hide show
  1. package/.github/workflows/release.yml +1 -1
  2. package/CHANGELOG.md +146 -0
  3. package/README.md +275 -0
  4. package/dist/at-rules/color-scheme.d.ts +4 -0
  5. package/dist/at-rules/color-scheme.js +49 -0
  6. package/dist/at-rules/color.d.ts +10 -0
  7. package/dist/at-rules/color.js +34 -0
  8. package/dist/at-rules/container.d.ts +19 -0
  9. package/dist/at-rules/container.js +55 -0
  10. package/dist/at-rules/index.d.ts +6 -2
  11. package/dist/at-rules/index.js +16 -7
  12. package/dist/config.d.ts +6 -0
  13. package/dist/config.js +53 -0
  14. package/dist/errors.d.ts +7 -0
  15. package/dist/errors.js +18 -0
  16. package/dist/functions/color.d.ts +7 -1
  17. package/dist/functions/color.js +66 -12
  18. package/dist/functions/index.d.ts +2 -1
  19. package/dist/functions/index.js +9 -7
  20. package/dist/functions/theme.d.ts +6 -0
  21. package/dist/functions/theme.js +20 -0
  22. package/dist/helpers.d.ts +12 -0
  23. package/dist/helpers.js +63 -0
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.js +7 -4
  26. package/dist/parser.d.ts +4 -0
  27. package/dist/parser.js +65 -0
  28. package/dist/plugin.d.ts +2 -4
  29. package/dist/plugin.js +28 -16
  30. package/dist/types.d.ts +59 -0
  31. package/dist/types.js +4 -0
  32. package/package.json +14 -5
  33. package/release.config.mjs +6 -1
  34. package/src/at-rules/color-scheme.ts +53 -0
  35. package/src/at-rules/color.ts +33 -0
  36. package/src/at-rules/container.ts +58 -0
  37. package/src/at-rules/index.ts +22 -8
  38. package/src/config.ts +59 -0
  39. package/src/errors.ts +23 -0
  40. package/src/functions/color.ts +80 -14
  41. package/src/functions/index.ts +11 -5
  42. package/src/functions/theme.ts +20 -0
  43. package/src/helpers.ts +75 -0
  44. package/src/index.ts +5 -3
  45. package/src/parser.ts +81 -0
  46. package/src/plugin.ts +29 -24
  47. package/src/types.ts +72 -0
  48. package/tests/plugin.test.ts +143 -0
  49. package/tsconfig.json +2 -2
  50. package/dist/at-rules/dark.d.ts +0 -2
  51. package/dist/at-rules/dark.js +0 -28
  52. package/dist/at-rules/light.d.ts +0 -2
  53. package/dist/at-rules/light.js +0 -28
  54. package/dist/functions/spacing.d.ts +0 -1
  55. package/dist/functions/spacing.js +0 -6
  56. package/src/at-rules/dark.ts +0 -33
  57. package/src/at-rules/light.ts +0 -33
  58. package/src/functions/spacing.ts +0 -3
package/dist/config.js ADDED
@@ -0,0 +1,53 @@
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"));
9
+ const DEFAULT_OPTIONS = {
10
+ configPath: 'seyuna.json',
11
+ modeAttribute: 'data-mode',
12
+ strict: false,
13
+ config: undefined,
14
+ functions: undefined,
15
+ };
16
+ let cachedConfig = null;
17
+ let cachedConfigPath = null;
18
+ function loadConfig(options = {}) {
19
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
20
+ if (mergedOptions.config) {
21
+ return { config: mergedOptions.config, options: mergedOptions };
22
+ }
23
+ const configPath = path_1.default.resolve(process.cwd(), mergedOptions.configPath);
24
+ // Cache config if it's the same path
25
+ if (cachedConfig && cachedConfigPath === configPath) {
26
+ return { config: cachedConfig, options: mergedOptions };
27
+ }
28
+ try {
29
+ if (!fs_1.default.existsSync(configPath)) {
30
+ if (mergedOptions.strict) {
31
+ throw new Error(`Seyuna config not found at ${configPath}`);
32
+ }
33
+ return {
34
+ config: { ui: { theme: { hues: {}, light: { colors: {} }, dark: { colors: {} } } } },
35
+ options: mergedOptions,
36
+ };
37
+ }
38
+ const data = JSON.parse(fs_1.default.readFileSync(configPath, 'utf-8'));
39
+ cachedConfig = data;
40
+ cachedConfigPath = configPath;
41
+ return { config: data, options: mergedOptions };
42
+ }
43
+ catch (error) {
44
+ if (mergedOptions.strict) {
45
+ throw error;
46
+ }
47
+ console.warn(`[Seyuna PostCSS] Warning: Failed to load config: ${error instanceof Error ? error.message : String(error)}`);
48
+ return {
49
+ config: { ui: { theme: { hues: {}, light: { colors: {} }, dark: { colors: {} } } } },
50
+ options: mergedOptions,
51
+ };
52
+ }
53
+ }
@@ -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,18 @@
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 = {}) {
6
+ const { options: pluginOptions } = context;
7
+ const formattedMessage = `[Seyuna PostCSS] ${message}`;
8
+ if (pluginOptions.strict) {
9
+ throw node.error(formattedMessage, options);
10
+ }
11
+ else {
12
+ reportWarning(formattedMessage, node);
13
+ }
14
+ }
15
+ function reportWarning(message, node) {
16
+ const result = node.root().toResult();
17
+ node.warn(result, `[Seyuna PostCSS] ${message}`);
18
+ }
@@ -1 +1,7 @@
1
- export default function color(name: string, alpha?: string, lightness?: string, chroma?: string): string;
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;
@@ -1,18 +1,72 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = color;
4
- function color(name, alpha, lightness, chroma) {
5
- let a = "1";
6
- let l = "var(--lightness)";
7
- let c = "var(--chroma)";
8
- if (alpha && alpha !== "null") {
9
- a = alpha;
3
+ exports.sc = sc;
4
+ exports.fc = fc;
5
+ exports.alpha = alpha;
6
+ exports.lighten = lighten;
7
+ exports.darken = darken;
8
+ exports.contrast = contrast;
9
+ /**
10
+ * Resolves a color name to its CSS variables based on its type (standard or fixed)
11
+ */
12
+ function getColorVariables(context, color, type) {
13
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
14
+ const { config } = context;
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) || {};
19
+ const isStandard = color in hues;
20
+ const isFixed = color in colors || color in lightColors || color in darkColors;
21
+ if (type === 'sc' && !isStandard) {
22
+ throw new Error(`Standard color '${color}' not found in seyuna.json hues`);
10
23
  }
11
- if (lightness && lightness !== "null") {
12
- l = lightness;
24
+ if (type === 'fc' && !isFixed) {
25
+ throw new Error(`Fixed color '${color}' not found in seyuna.json colors`);
13
26
  }
14
- if (chroma && chroma !== "null") {
15
- c = chroma;
27
+ if (isStandard) {
28
+ return {
29
+ l: "var(--lightness)",
30
+ c: "var(--chroma)",
31
+ h: `var(--${color}-hue)`,
32
+ };
16
33
  }
17
- return `oklch(${l} ${c} var(--${name}) / ${a})`;
34
+ if (isFixed) {
35
+ return {
36
+ l: `var(--${color}-lightness)`,
37
+ c: `var(--${color}-chroma)`,
38
+ h: `var(--${color}-hue)`,
39
+ };
40
+ }
41
+ throw new Error(`Color '${color}' not found in seyuna.json`);
42
+ }
43
+ function sc(context, name, alpha, lightness, chroma) {
44
+ const vars = getColorVariables(context, name, 'sc');
45
+ const a = alpha && alpha !== "null" ? alpha : "1";
46
+ const l = lightness && lightness !== "null" ? lightness : vars.l;
47
+ const c = chroma && chroma !== "null" ? chroma : vars.c;
48
+ return `oklch(${l} ${c} ${vars.h} / ${a})`;
49
+ }
50
+ function fc(context, name, alpha, lightness, chroma) {
51
+ const vars = getColorVariables(context, name, 'fc');
52
+ const a = alpha && alpha !== "null" ? alpha : "1";
53
+ const l = lightness && lightness !== "null" ? lightness : vars.l;
54
+ const c = chroma && chroma !== "null" ? chroma : vars.c;
55
+ return `oklch(${l} ${c} ${vars.h} / ${a})`;
56
+ }
57
+ function alpha(context, color, value) {
58
+ const { l, c, h } = getColorVariables(context, color);
59
+ return `oklch(${l} ${c} ${h} / ${value})`;
60
+ }
61
+ function lighten(context, color, amount) {
62
+ const { l, c, h } = getColorVariables(context, color);
63
+ return `oklch(calc(${l} + ${amount}) ${c} ${h} / 1)`;
64
+ }
65
+ function darken(context, color, amount) {
66
+ const { l, c, h } = getColorVariables(context, color);
67
+ return `oklch(calc(${l} - ${amount}) ${c} ${h} / 1)`;
68
+ }
69
+ function contrast(context, color) {
70
+ const { l } = getColorVariables(context, color);
71
+ return `oklch(calc((${l} - 0.6) * -1000) 0 0)`;
18
72
  }
@@ -1,2 +1,3 @@
1
- export type FnHandler = (...args: string[]) => string;
1
+ import { PluginContext } from "../types.js";
2
+ export type FnHandler = (context: PluginContext, ...args: string[]) => string;
2
3
  export declare const functions: Record<string, FnHandler>;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.functions = void 0;
7
- const color_1 = __importDefault(require("./color"));
8
- const spacing_1 = __importDefault(require("./spacing"));
4
+ const color_js_1 = require("./color.js");
5
+ const theme_js_1 = require("./theme.js");
9
6
  exports.functions = {
10
- color: color_1.default,
11
- spacing: spacing_1.default,
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,
12
14
  };
@@ -0,0 +1,6 @@
1
+ import { PluginContext } from "../types.js";
2
+ /**
3
+ * Accesses values from the Seyuna configuration using dot notation
4
+ * Example: theme(ui.theme.breakpoints.tablet)
5
+ */
6
+ export declare function theme(context: PluginContext, path: string): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.theme = theme;
4
+ /**
5
+ * Accesses values from the Seyuna configuration using dot notation
6
+ * Example: theme(ui.theme.breakpoints.tablet)
7
+ */
8
+ function theme(context, path) {
9
+ const parts = path.split('.');
10
+ let current = context.config;
11
+ for (const part of parts) {
12
+ if (current && typeof current === 'object' && part in current) {
13
+ current = current[part];
14
+ }
15
+ else {
16
+ return path; // Return original path if not found
17
+ }
18
+ }
19
+ return String(current);
20
+ }
@@ -0,0 +1,12 @@
1
+ import postcss from "postcss";
2
+ import type { ChildNode, AtRule } from "postcss";
3
+ import { PluginContext } from './types.js';
4
+ /**
5
+ * Helper: clone nodes and replace {name} placeholders safely
6
+ * Returns only valid Rules or Declarations (never raw AtRules)
7
+ */
8
+ export declare function cloneNodes(nodes: ChildNode[], name: string, context: PluginContext): ChildNode[];
9
+ /**
10
+ * Generate CSS rules from a list of names
11
+ */
12
+ export declare function generateRules(names: string[], atRule: AtRule, context: PluginContext): postcss.Rule[];
@@ -0,0 +1,63 @@
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");
10
+ /**
11
+ * Helper: clone nodes and replace {name} placeholders safely
12
+ * Returns only valid Rules or Declarations (never raw AtRules)
13
+ */
14
+ function cloneNodes(nodes, name, context) {
15
+ const { functions: fnMap } = context;
16
+ return nodes.flatMap((node) => {
17
+ const cloned = node.clone();
18
+ if (cloned.type === "decl") {
19
+ const decl = cloned;
20
+ let value = decl.value.replace(/\{name\}/g, name);
21
+ // Process functions using the robust parser
22
+ decl.value = (0, parser_js_1.processFunctions)(value, fnMap, decl, context);
23
+ return decl;
24
+ }
25
+ if (cloned.type === "rule") {
26
+ const rule = cloned;
27
+ if (!rule.selector)
28
+ return [];
29
+ rule.selector = rule.selector.replace(/\{name\}/g, name);
30
+ // Recursively clone child nodes and only keep valid rules/decls
31
+ rule.nodes = cloneNodes(rule.nodes || [], name, context).filter((n) => n.type === "rule" || n.type === "decl");
32
+ if (!rule.nodes.length)
33
+ return [];
34
+ return rule;
35
+ }
36
+ // Ignore AtRules inside rules — they must be processed first
37
+ return [];
38
+ });
39
+ }
40
+ /**
41
+ * Generate CSS rules from a list of names
42
+ */
43
+ function generateRules(names, atRule, context) {
44
+ var _a;
45
+ const nodes = (_a = atRule.nodes) !== null && _a !== void 0 ? _a : [];
46
+ const generatedRules = [];
47
+ for (const name of names) {
48
+ const rule = new postcss_1.default.Rule({
49
+ selector: `&.${name}`,
50
+ source: atRule.source,
51
+ });
52
+ cloneNodes(nodes, name, context).forEach((n) => {
53
+ var _a;
54
+ if (n.type === "rule" && n.selector && ((_a = n.nodes) === null || _a === void 0 ? void 0 : _a.length))
55
+ rule.append(n);
56
+ if (n.type === "decl")
57
+ rule.append(n);
58
+ });
59
+ if (rule.nodes.length)
60
+ generatedRules.push(rule);
61
+ }
62
+ return generatedRules;
63
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- declare const _default: import("postcss").PluginCreator<import("./plugin").PluginOptions> & {
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 = _default;
5
+ export default plugin;
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
- const plugin_1 = require("./plugin");
3
- const functions_1 = require("./functions");
4
- module.exports = Object.assign(plugin_1.dynamicFunctionsPlugin, {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const plugin_js_1 = require("./plugin.js");
4
+ const index_js_1 = require("./functions/index.js");
5
+ // CommonJS-friendly export
6
+ const plugin = Object.assign(plugin_js_1.dynamicFunctionsPlugin, {
5
7
  postcss: true,
6
- functions: functions_1.functions
8
+ functions: index_js_1.functions
7
9
  });
10
+ exports.default = plugin;
@@ -0,0 +1,4 @@
1
+ import { Node } from 'postcss';
2
+ import { PluginContext, FunctionMap } from './types.js';
3
+ export type { FunctionMap } from './types.js';
4
+ export declare function processFunctions(value: string, fnMap: FunctionMap, node: Node, context: PluginContext): string;
package/dist/parser.js ADDED
@@ -0,0 +1,65 @@
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);
11
+ // Helper to process nodes recursively (inner-first)
12
+ function processNode(parsedValue) {
13
+ parsedValue.walk((nodeIter) => {
14
+ // If nested nodes exist (e.g., in a function), process them first
15
+ if (nodeIter.type === 'function' && nodeIter.nodes.length > 0) {
16
+ // Here we recursively process child nodes before handling the current function
17
+ // However, value-parser's walk is already a visitor. To do inner-first,
18
+ // we can either walk in reverse or specifically handle children.
19
+ // A simpler way: since walk visits all, we can check if it's a function
20
+ // and if it's one we handle, we process its arguments.
21
+ }
22
+ });
23
+ // Actually, a manual walk is safer for inner-first replacement
24
+ function traverse(nodes) {
25
+ for (const nodeIter of nodes) {
26
+ if (nodeIter.type === 'function') {
27
+ // Process inner functions first
28
+ traverse(nodeIter.nodes);
29
+ // Now handle this function if it's in our map
30
+ if (fnMap[nodeIter.value]) {
31
+ const handler = fnMap[nodeIter.value];
32
+ const args = [];
33
+ let currentArg = '';
34
+ nodeIter.nodes.forEach((argNode) => {
35
+ if (argNode.type === 'div' && argNode.value === ',') {
36
+ args.push(currentArg.trim());
37
+ currentArg = '';
38
+ }
39
+ else {
40
+ currentArg += postcss_value_parser_1.default.stringify(argNode);
41
+ }
42
+ });
43
+ if (currentArg) {
44
+ args.push(currentArg.trim());
45
+ }
46
+ const cleanedArgs = args.map(arg => arg.replace(/^['"]|['"]$/g, ''));
47
+ try {
48
+ const result = handler(context, ...cleanedArgs);
49
+ // Replace function with its result
50
+ nodeIter.type = 'word';
51
+ nodeIter.value = result;
52
+ nodeIter.nodes = []; // Clear children
53
+ }
54
+ catch (error) {
55
+ (0, errors_js_1.reportError)(`Failed to process function "${nodeIter.value}": ${error instanceof Error ? error.message : String(error)}`, node, context);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ traverse(parsedValue.nodes);
62
+ }
63
+ processNode(parsed);
64
+ return parsed.toString();
65
+ }
package/dist/plugin.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { PluginCreator } from "postcss";
2
- export interface PluginOptions {
3
- functions?: Record<string, (...args: string[]) => string>;
4
- }
1
+ import type { PluginCreator } from "postcss";
2
+ import { PluginOptions } from "./types.js";
5
3
  export declare const dynamicFunctionsPlugin: PluginCreator<PluginOptions>;
package/dist/plugin.js CHANGED
@@ -1,27 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dynamicFunctionsPlugin = void 0;
4
- const functions_1 = require("./functions");
5
- const at_rules_1 = require("./at-rules");
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");
6
8
  const dynamicFunctionsPlugin = (opts = {}) => {
7
- const fnMap = { ...functions_1.functions, ...opts.functions };
9
+ let context;
10
+ let fnMap;
8
11
  return {
9
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
+ },
10
22
  Declaration(decl) {
11
- let value = decl.value;
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;
23
+ if (!context || !fnMap)
24
+ return;
25
+ decl.value = (0, parser_js_1.processFunctions)(decl.value, fnMap, decl, context);
22
26
  },
23
- AtRule: {
24
- ...at_rules_1.atRuleHandlers,
27
+ // Override AtRule handler to ensure ordered execution
28
+ AtRule(atRule) {
29
+ if (!context)
30
+ return;
31
+ // Iterate over handlers in order (array) instead of object spread
32
+ for (const { name, handler } of index_js_2.atRuleHandlers) {
33
+ if (atRule.name === name) {
34
+ handler(atRule, context);
35
+ }
36
+ }
25
37
  },
26
38
  };
27
39
  };
@@ -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
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Local type definitions to avoid @seyuna/cli runtime import
3
+ // The @seyuna/cli package imports Deno polyfills that conflict with Vite/Astro
4
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@seyuna/postcss",
3
- "version": "1.0.0-canary.2",
3
+ "version": "1.0.0-canary.21",
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
- "build": "tsc"
8
+ "build": "tsc",
9
+ "dev": "tsc -w",
10
+ "test": "vitest",
11
+ "test:run": "vitest run"
9
12
  },
10
13
  "keywords": [
11
14
  "postcss",
@@ -17,6 +20,9 @@
17
20
  "type": "git",
18
21
  "url": "git+https://github.com/seyuna-corp/seyuna-postcss.git"
19
22
  },
23
+ "dependencies": {
24
+ "postcss-value-parser": "^4.2.0"
25
+ },
20
26
  "peerDependencies": {
21
27
  "postcss": "^8.5.6"
22
28
  },
@@ -26,11 +32,14 @@
26
32
  "@semantic-release/exec": "^7.1.0",
27
33
  "@semantic-release/git": "^10.0.1",
28
34
  "@semantic-release/github": "^11.0.3",
29
- "@semantic-release/npm": "^12.0.2",
35
+ "@semantic-release/npm": "^13.1.3",
30
36
  "@semantic-release/release-notes-generator": "^14.0.3",
31
37
  "@types/node": "^20.0.0",
38
+ "conventional-changelog-conventionalcommits": "^9.1.0",
32
39
  "postcss": "^8.5.6",
33
- "semantic-release": "^24.2.7",
34
- "typescript": "^5.0.0"
40
+ "postcss-selector-parser": "^7.1.0",
41
+ "semantic-release": "^25.0.2",
42
+ "typescript": "^5.0.0",
43
+ "vitest": "^4.0.16"
35
44
  }
36
45
  }
@@ -4,7 +4,12 @@
4
4
  export default {
5
5
  branches: [{ name: "canary", prerelease: "canary" }, "main"],
6
6
  plugins: [
7
- "@semantic-release/commit-analyzer",
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,53 @@
1
+ import postcss from "postcss";
2
+ import type { AtRule, ChildNode } from "postcss";
3
+ import { PluginContext } from "../types.js";
4
+
5
+ /**
6
+ * Custom PostCSS plugin handler factory for `@light` and `@dark` at-rules.
7
+ */
8
+ function createColorSchemeHandler(scheme: 'light' | 'dark') {
9
+ return (atRule: AtRule, context: PluginContext) => {
10
+ const { options } = context;
11
+ const modeAttribute = options.modeAttribute;
12
+ const clonedNodes: ChildNode[] = [];
13
+
14
+ // Clone all child nodes inside the block
15
+ atRule.each((node: ChildNode) => {
16
+ clonedNodes.push(node.clone());
17
+ });
18
+
19
+ /**
20
+ * Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
21
+ */
22
+ const explicitRule = new postcss.Rule({
23
+ selector: `[${modeAttribute}="${scheme}"] &`,
24
+ source: atRule.source,
25
+ });
26
+ clonedNodes.forEach((node) => explicitRule.append(node.clone()));
27
+
28
+ /**
29
+ * Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
30
+ */
31
+ const mediaAtRule = new postcss.AtRule({
32
+ name: "media",
33
+ params: `(prefers-color-scheme: ${scheme})`,
34
+ source: atRule.source,
35
+ });
36
+
37
+ const systemRule = new postcss.Rule({
38
+ selector: `[${modeAttribute}="system"] &`,
39
+ source: atRule.source,
40
+ });
41
+ clonedNodes.forEach((node) => systemRule.append(node.clone()));
42
+
43
+ mediaAtRule.append(systemRule);
44
+
45
+ /**
46
+ * Replace the original at-rule with the generated rules.
47
+ */
48
+ atRule.replaceWith(mediaAtRule, explicitRule);
49
+ };
50
+ }
51
+
52
+ export const light = createColorSchemeHandler('light');
53
+ export const dark = createColorSchemeHandler('dark');