@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
@@ -0,0 +1,33 @@
1
+ import type { 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,58 @@
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 for responsive at-rules.
7
+ *
8
+ * Example:
9
+ *
10
+ * @xs {
11
+ * .box { color: red; }
12
+ * }
13
+ *
14
+ * Into:
15
+ *
16
+ * @xs (min-width: 234px) {
17
+ * .box { color: red; }
18
+ * }
19
+ *
20
+ */
21
+ export default function container(atRule: AtRule, context: PluginContext) {
22
+ const { config } = context;
23
+
24
+ // Default breakpoints
25
+ const defaultBreakpoints: Record<string, string> = {
26
+ xs: "20rem",
27
+ sm: "40rem",
28
+ md: "48rem",
29
+ lg: "64rem",
30
+ xl: "80rem",
31
+ "2xl": "96rem",
32
+ };
33
+
34
+ // Merge with config if available (assuming config.ui.breakpoints exists)
35
+ const breakpoints = {
36
+ ...defaultBreakpoints,
37
+ ...((config as any).ui?.theme?.breakpoints || {}),
38
+ };
39
+
40
+ if (Object.keys(breakpoints).includes(atRule.name)) {
41
+ const minWidth = breakpoints[atRule.name];
42
+
43
+ const clonedNodes: ChildNode[] = [];
44
+ atRule.each((node: ChildNode) => {
45
+ clonedNodes.push(node.clone());
46
+ });
47
+
48
+ const containerAtRule = new postcss.AtRule({
49
+ name: "container",
50
+ params: `(min-width: ${minWidth})`,
51
+ source: atRule.source,
52
+ });
53
+
54
+ clonedNodes.forEach((node) => containerAtRule.append(node));
55
+
56
+ atRule.replaceWith(containerAtRule);
57
+ }
58
+ }
@@ -1,11 +1,25 @@
1
- import dark from "./dark";
2
- import light from "./light";
3
1
  import type { AtRule } from "postcss";
2
+ import { eachStandardColor, eachFixedColor } from "./color.js";
3
+ import container from "./container.js";
4
+ import { light, dark } from "./color-scheme.js";
5
+ import { PluginContext } from "../types.js";
4
6
 
5
- export type AtRuleHandler = (atRule: AtRule) => void;
7
+ // Each handler has a name (matches the at-rule) and the function
8
+ export interface AtRuleHandler {
9
+ name: string;
10
+ handler: (atRule: AtRule, context: PluginContext) => void;
11
+ }
6
12
 
7
- export const atRuleHandlers: Record<string, AtRuleHandler> = {
8
- light,
9
- dark,
10
- // add more handlers here as needed
11
- };
13
+ // Ordered array ensures execution order
14
+ export const atRuleHandlers: AtRuleHandler[] = [
15
+ { name: "each-standard-color", handler: eachStandardColor },
16
+ { name: "each-fixed-color", handler: eachFixedColor },
17
+ { name: "light", handler: light },
18
+ { name: "dark", handler: dark },
19
+ { name: "xs", handler: container },
20
+ { name: "sm", handler: container },
21
+ { name: "md", handler: container },
22
+ { name: "lg", handler: container },
23
+ { name: "xl", handler: container },
24
+ { name: "2xl", handler: container },
25
+ ];
package/src/config.ts ADDED
@@ -0,0 +1,59 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { SeyunaConfig, PluginOptions, PluginContext, FunctionMap } from './types.js';
4
+
5
+ // Re-export types for backwards compatibility
6
+ export type { PluginOptions, PluginContext, FunctionMap } from './types.js';
7
+
8
+ const DEFAULT_OPTIONS: Required<PluginOptions> = {
9
+ configPath: 'seyuna.json',
10
+ modeAttribute: 'data-mode',
11
+ strict: false,
12
+ config: undefined as any,
13
+ functions: undefined as any,
14
+ };
15
+
16
+ let cachedConfig: SeyunaConfig | null = null;
17
+ let cachedConfigPath: string | null = null;
18
+
19
+ export function loadConfig(options: PluginOptions = {}): { config: SeyunaConfig, options: Required<PluginOptions> } {
20
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
21
+
22
+ if (mergedOptions.config) {
23
+ return { config: mergedOptions.config, options: mergedOptions };
24
+ }
25
+
26
+ const configPath = path.resolve(process.cwd(), mergedOptions.configPath);
27
+
28
+ // Cache config if it's the same path
29
+ if (cachedConfig && cachedConfigPath === configPath) {
30
+ return { config: cachedConfig, options: mergedOptions };
31
+ }
32
+
33
+ try {
34
+ if (!fs.existsSync(configPath)) {
35
+ if (mergedOptions.strict) {
36
+ throw new Error(`Seyuna config not found at ${configPath}`);
37
+ }
38
+ return {
39
+ config: { ui: { theme: { hues: {}, light: { colors: {} }, dark: { colors: {} } } } } as any,
40
+ options: mergedOptions,
41
+ };
42
+ }
43
+
44
+ const data = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
45
+ cachedConfig = data;
46
+ cachedConfigPath = configPath;
47
+
48
+ return { config: data, options: mergedOptions };
49
+ } catch (error) {
50
+ if (mergedOptions.strict) {
51
+ throw error;
52
+ }
53
+ console.warn(`[Seyuna PostCSS] Warning: Failed to load config: ${error instanceof Error ? error.message : String(error)}`);
54
+ return {
55
+ config: { ui: { theme: { hues: {}, light: { colors: {} }, dark: { colors: {} } } } } as any,
56
+ options: mergedOptions,
57
+ };
58
+ }
59
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { Node } from 'postcss';
2
+ import { PluginContext } from './types.js';
3
+
4
+ export function reportError(
5
+ message: string,
6
+ node: Node,
7
+ context: PluginContext,
8
+ options: { word?: string; index?: number } = {}
9
+ ) {
10
+ const { options: pluginOptions } = context;
11
+ const formattedMessage = `[Seyuna PostCSS] ${message}`;
12
+
13
+ if (pluginOptions.strict) {
14
+ throw node.error(formattedMessage, options);
15
+ } else {
16
+ reportWarning(formattedMessage, node);
17
+ }
18
+ }
19
+
20
+ export function reportWarning(message: string, node: Node) {
21
+ const result = node.root().toResult();
22
+ node.warn(result, `[Seyuna PostCSS] ${message}`);
23
+ }
@@ -1,24 +1,90 @@
1
- export default function color(
1
+ import { PluginContext } from "../types.js";
2
+
3
+ /**
4
+ * Resolves a color name to its CSS variables based on its type (standard or fixed)
5
+ */
6
+ function getColorVariables(context: PluginContext, color: string, type?: 'sc' | 'fc') {
7
+ const { config } = context;
8
+ const hues = config?.ui?.theme?.hues || {};
9
+ const colors = config?.ui?.theme?.colors || {};
10
+ const lightColors = config?.ui?.theme?.light?.colors || {};
11
+ const darkColors = config?.ui?.theme?.dark?.colors || {};
12
+
13
+ const isStandard = color in hues;
14
+ const isFixed = color in colors || color in lightColors || color in darkColors;
15
+
16
+ if (type === 'sc' && !isStandard) {
17
+ throw new Error(`Standard color '${color}' not found in seyuna.json hues`);
18
+ }
19
+ if (type === 'fc' && !isFixed) {
20
+ throw new Error(`Fixed color '${color}' not found in seyuna.json colors`);
21
+ }
22
+
23
+ if (isStandard) {
24
+ return {
25
+ l: "var(--lightness)",
26
+ c: "var(--chroma)",
27
+ h: `var(--${color}-hue)`,
28
+ };
29
+ }
30
+
31
+ if (isFixed) {
32
+ return {
33
+ l: `var(--${color}-lightness)`,
34
+ c: `var(--${color}-chroma)`,
35
+ h: `var(--${color}-hue)`,
36
+ };
37
+ }
38
+
39
+ throw new Error(`Color '${color}' not found in seyuna.json`);
40
+ }
41
+
42
+ export function sc(
43
+ context: PluginContext,
2
44
  name: string,
3
45
  alpha?: string,
4
46
  lightness?: string,
5
47
  chroma?: string
6
48
  ) {
7
- let a: string = "1";
8
- let l: string = "var(--lightness)";
9
- let c: string = "var(--chroma)";
49
+ const vars = getColorVariables(context, name, 'sc');
50
+ const a = alpha && alpha !== "null" ? alpha : "1";
51
+ const l = lightness && lightness !== "null" ? lightness : vars.l;
52
+ const c = chroma && chroma !== "null" ? chroma : vars.c;
10
53
 
11
- if (alpha && alpha !== "null") {
12
- a = alpha;
13
- }
54
+ return `oklch(${l} ${c} ${vars.h} / ${a})`;
55
+ }
14
56
 
15
- if (lightness && lightness !== "null") {
16
- l = lightness;
17
- }
57
+ export function fc(
58
+ context: PluginContext,
59
+ name: string,
60
+ alpha?: string,
61
+ lightness?: string,
62
+ chroma?: string
63
+ ) {
64
+ const vars = getColorVariables(context, name, 'fc');
65
+ const a = alpha && alpha !== "null" ? alpha : "1";
66
+ const l = lightness && lightness !== "null" ? lightness : vars.l;
67
+ const c = chroma && chroma !== "null" ? chroma : vars.c;
18
68
 
19
- if (chroma && chroma !== "null") {
20
- c = chroma;
21
- }
69
+ return `oklch(${l} ${c} ${vars.h} / ${a})`;
70
+ }
71
+
72
+ export function alpha(context: PluginContext, color: string, value: string) {
73
+ const { l, c, h } = getColorVariables(context, color);
74
+ return `oklch(${l} ${c} ${h} / ${value})`;
75
+ }
76
+
77
+ export function lighten(context: PluginContext, color: string, amount: string) {
78
+ const { l, c, h } = getColorVariables(context, color);
79
+ return `oklch(calc(${l} + ${amount}) ${c} ${h} / 1)`;
80
+ }
81
+
82
+ export function darken(context: PluginContext, color: string, amount: string) {
83
+ const { l, c, h } = getColorVariables(context, color);
84
+ return `oklch(calc(${l} - ${amount}) ${c} ${h} / 1)`;
85
+ }
22
86
 
23
- return `oklch(${l} ${c} var(--${name}) / ${a})`;
87
+ export function contrast(context: PluginContext, color: string) {
88
+ const { l } = getColorVariables(context, color);
89
+ return `oklch(calc((${l} - 0.6) * -1000) 0 0)`;
24
90
  }
@@ -1,9 +1,15 @@
1
- import color from "./color";
2
- import spacing from "./spacing";
1
+ import { sc, fc, alpha, lighten, darken, contrast } from "./color.js";
2
+ import { theme } from "./theme.js";
3
+ import { PluginContext } from "../types.js";
3
4
 
4
- export type FnHandler = (...args: string[]) => string;
5
+ export type FnHandler = (context: PluginContext, ...args: string[]) => string;
5
6
 
6
7
  export const functions: Record<string, FnHandler> = {
7
- color,
8
- spacing,
8
+ sc,
9
+ fc,
10
+ alpha,
11
+ lighten,
12
+ darken,
13
+ contrast,
14
+ theme,
9
15
  };
@@ -0,0 +1,20 @@
1
+ import { PluginContext } from "../types.js";
2
+
3
+ /**
4
+ * Accesses values from the Seyuna configuration using dot notation
5
+ * Example: theme(ui.theme.breakpoints.tablet)
6
+ */
7
+ export function theme(context: PluginContext, path: string): string {
8
+ const parts = path.split('.');
9
+ let current: any = context.config;
10
+
11
+ for (const part of parts) {
12
+ if (current && typeof current === 'object' && part in current) {
13
+ current = current[part];
14
+ } else {
15
+ return path; // Return original path if not found
16
+ }
17
+ }
18
+
19
+ return String(current);
20
+ }
package/src/helpers.ts ADDED
@@ -0,0 +1,75 @@
1
+ import postcss from "postcss";
2
+ import type { ChildNode, Declaration, AtRule } from "postcss";
3
+ import { processFunctions } from "./parser.js";
4
+ import { PluginContext } from './types.js';
5
+
6
+ /**
7
+ * Helper: clone nodes and replace {name} placeholders safely
8
+ * Returns only valid Rules or Declarations (never raw AtRules)
9
+ */
10
+ export function cloneNodes(
11
+ nodes: ChildNode[],
12
+ name: string,
13
+ context: PluginContext
14
+ ): ChildNode[] {
15
+ const { functions: fnMap } = context;
16
+
17
+ return nodes.flatMap((node) => {
18
+ const cloned = node.clone();
19
+
20
+ if (cloned.type === "decl") {
21
+ const decl = cloned as Declaration;
22
+ let value = decl.value.replace(/\{name\}/g, name);
23
+
24
+ // Process functions using the robust parser
25
+ decl.value = processFunctions(value, fnMap, decl, context);
26
+
27
+ return decl;
28
+ }
29
+
30
+ if (cloned.type === "rule") {
31
+ const rule = cloned as postcss.Rule;
32
+ if (!rule.selector) return [];
33
+
34
+ rule.selector = rule.selector.replace(/\{name\}/g, name);
35
+
36
+ // Recursively clone child nodes and only keep valid rules/decls
37
+ rule.nodes = cloneNodes(rule.nodes || [], name, context).filter(
38
+ (n) => n.type === "rule" || n.type === "decl"
39
+ );
40
+
41
+ if (!rule.nodes.length) return [];
42
+ return rule;
43
+ }
44
+
45
+ // Ignore AtRules inside rules — they must be processed first
46
+ return [];
47
+ });
48
+ }
49
+
50
+ /**
51
+ * Generate CSS rules from a list of names
52
+ */
53
+ export function generateRules(
54
+ names: string[],
55
+ atRule: AtRule,
56
+ context: PluginContext
57
+ ): postcss.Rule[] {
58
+ const nodes = atRule.nodes ?? [];
59
+ const generatedRules: postcss.Rule[] = [];
60
+
61
+ for (const name of names) {
62
+ const rule = new postcss.Rule({
63
+ selector: `&.${name}`,
64
+ source: atRule.source,
65
+ });
66
+ cloneNodes(nodes, name, context).forEach((n) => {
67
+ if (n.type === "rule" && n.selector && (n as postcss.Rule).nodes?.length) rule.append(n);
68
+ if (n.type === "decl") rule.append(n);
69
+ });
70
+
71
+ if (rule.nodes.length) generatedRules.push(rule);
72
+ }
73
+
74
+ return generatedRules;
75
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { dynamicFunctionsPlugin } from './plugin';
2
- import { functions } from './functions';
1
+ import { dynamicFunctionsPlugin } from './plugin.js';
2
+ import { functions } from './functions/index.js';
3
3
 
4
4
  // CommonJS-friendly export
5
- export = Object.assign(dynamicFunctionsPlugin, {
5
+ const plugin = Object.assign(dynamicFunctionsPlugin, {
6
6
  postcss: true,
7
7
  functions
8
8
  });
9
+
10
+ export default plugin;
package/src/parser.ts ADDED
@@ -0,0 +1,81 @@
1
+ import valueParser from 'postcss-value-parser';
2
+ import { Node } from 'postcss';
3
+ import { PluginContext, FunctionMap } from './types.js';
4
+ import { reportError } from './errors.js';
5
+
6
+ // Re-export FunctionMap for backwards compatibility
7
+ export type { FunctionMap } from './types.js';
8
+
9
+ export function processFunctions(
10
+ value: string,
11
+ fnMap: FunctionMap,
12
+ node: Node,
13
+ context: PluginContext
14
+ ): string {
15
+ const parsed = valueParser(value);
16
+
17
+ // Helper to process nodes recursively (inner-first)
18
+ function processNode(parsedValue: valueParser.ParsedValue) {
19
+ parsedValue.walk((nodeIter) => {
20
+ // If nested nodes exist (e.g., in a function), process them first
21
+ if (nodeIter.type === 'function' && nodeIter.nodes.length > 0) {
22
+ // Here we recursively process child nodes before handling the current function
23
+ // However, value-parser's walk is already a visitor. To do inner-first,
24
+ // we can either walk in reverse or specifically handle children.
25
+ // A simpler way: since walk visits all, we can check if it's a function
26
+ // and if it's one we handle, we process its arguments.
27
+ }
28
+ });
29
+
30
+ // Actually, a manual walk is safer for inner-first replacement
31
+ function traverse(nodes: valueParser.Node[]) {
32
+ for (const nodeIter of nodes) {
33
+ if (nodeIter.type === 'function') {
34
+ // Process inner functions first
35
+ traverse(nodeIter.nodes);
36
+
37
+ // Now handle this function if it's in our map
38
+ if (fnMap[nodeIter.value]) {
39
+ const handler = fnMap[nodeIter.value];
40
+ const args: string[] = [];
41
+ let currentArg = '';
42
+
43
+ nodeIter.nodes.forEach((argNode) => {
44
+ if (argNode.type === 'div' && argNode.value === ',') {
45
+ args.push(currentArg.trim());
46
+ currentArg = '';
47
+ } else {
48
+ currentArg += valueParser.stringify(argNode);
49
+ }
50
+ });
51
+
52
+ if (currentArg) {
53
+ args.push(currentArg.trim());
54
+ }
55
+
56
+ const cleanedArgs = args.map(arg => arg.replace(/^['"]|['"]$/g, ''));
57
+
58
+ try {
59
+ const result = handler(context, ...cleanedArgs);
60
+ // Replace function with its result
61
+ (nodeIter as any).type = 'word';
62
+ (nodeIter as any).value = result;
63
+ (nodeIter as any).nodes = []; // Clear children
64
+ } catch (error) {
65
+ reportError(
66
+ `Failed to process function "${nodeIter.value}": ${error instanceof Error ? error.message : String(error)}`,
67
+ node,
68
+ context
69
+ );
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ traverse(parsedValue.nodes);
77
+ }
78
+
79
+ processNode(parsed);
80
+ return parsed.toString();
81
+ }
package/src/plugin.ts CHANGED
@@ -1,38 +1,43 @@
1
- import { PluginCreator } from "postcss";
2
- import { functions } from "./functions";
3
- import { atRuleHandlers } from "./at-rules";
4
-
5
- export interface PluginOptions {
6
- functions?: Record<string, (...args: string[]) => string>;
7
- }
1
+ import type { PluginCreator } from "postcss";
2
+ import { functions } from "./functions/index.js";
3
+ import { atRuleHandlers } from "./at-rules/index.js";
4
+ import { loadConfig } from "./config.js";
5
+ import { PluginOptions, PluginContext, FunctionMap } from "./types.js";
6
+ import { processFunctions } from "./parser.js";
8
7
 
9
8
  export const dynamicFunctionsPlugin: PluginCreator<PluginOptions> = (
10
9
  opts = {}
11
10
  ) => {
12
- const fnMap = { ...functions, ...opts.functions };
11
+ let context: PluginContext | undefined;
12
+ let fnMap: FunctionMap | undefined;
13
13
 
14
14
  return {
15
15
  postcssPlugin: "postcss-dynamic-functions",
16
16
 
17
- Declaration(decl) {
18
- let value = decl.value;
19
-
20
- for (const fnName in fnMap) {
21
- const regex = new RegExp(`${fnName}\\(([^)]*)\\)`, "g");
22
-
23
- value = value.replace(regex, (_match, argsStr) => {
24
- const args = argsStr
25
- .split(",")
26
- .map((a: string) => a.trim().replace(/^['"]|['"]$/g, ""));
27
- return fnMap[fnName](...args);
28
- });
29
- }
17
+ Once() {
18
+ const { config, options } = loadConfig(opts);
19
+ fnMap = { ...functions, ...opts.functions };
20
+ context = {
21
+ config,
22
+ options,
23
+ functions: fnMap,
24
+ };
25
+ },
30
26
 
31
- decl.value = value;
27
+ Declaration(decl) {
28
+ if (!context || !fnMap) return;
29
+ decl.value = processFunctions(decl.value, fnMap, decl, context);
32
30
  },
33
31
 
34
- AtRule: {
35
- ...atRuleHandlers,
32
+ // Override AtRule handler to ensure ordered execution
33
+ AtRule(atRule) {
34
+ if (!context) return;
35
+ // Iterate over handlers in order (array) instead of object spread
36
+ for (const { name, handler } of atRuleHandlers) {
37
+ if (atRule.name === name) {
38
+ handler(atRule, context);
39
+ }
40
+ }
36
41
  },
37
42
  };
38
43
  };
package/src/types.ts ADDED
@@ -0,0 +1,72 @@
1
+ // Local type definitions to avoid @seyuna/cli runtime import
2
+ // The @seyuna/cli package imports Deno polyfills that conflict with Vite/Astro
3
+
4
+ /**
5
+ * Represents a color in the Oklch color space.
6
+ */
7
+ export interface Color {
8
+ lightness: number;
9
+ chroma: number;
10
+ hue: number;
11
+ }
12
+
13
+ /**
14
+ * A set of colors for a specific theme mode.
15
+ */
16
+ export interface Palette {
17
+ chroma: number;
18
+ lightness: number;
19
+ background: Color;
20
+ text: Color;
21
+ colors: Record<string, Color>;
22
+ }
23
+
24
+ /**
25
+ * The complete theme specification.
26
+ */
27
+ export interface Theme {
28
+ hues: Record<string, number>;
29
+ colors: Record<string, Color>;
30
+ light: Palette;
31
+ dark: Palette;
32
+ }
33
+
34
+ /**
35
+ * Supported color appearance modes.
36
+ */
37
+ export type Mode = "system" | "light" | "dark";
38
+
39
+ /**
40
+ * UI Engine Configuration.
41
+ */
42
+ export interface UI {
43
+ theme: Theme;
44
+ mode: Mode;
45
+ output_dir?: string;
46
+ }
47
+
48
+ /**
49
+ * Root configuration structure for a Seyuna project.
50
+ */
51
+ export interface SeyunaConfig {
52
+ license?: string;
53
+ ui?: UI;
54
+ }
55
+
56
+ // Shared types to avoid circular dependencies between config.ts and parser.ts
57
+
58
+ export type FunctionMap = Record<string, (context: PluginContext, ...args: string[]) => string>;
59
+
60
+ export interface PluginOptions {
61
+ configPath?: string;
62
+ modeAttribute?: string;
63
+ strict?: boolean;
64
+ config?: SeyunaConfig;
65
+ functions?: FunctionMap;
66
+ }
67
+
68
+ export interface PluginContext {
69
+ config: SeyunaConfig;
70
+ options: Required<PluginOptions>;
71
+ functions: FunctionMap;
72
+ }