@seyuna/postcss 1.0.0-canary.23 → 1.0.0-canary.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/at-rules/color-scheme.d.ts +2 -3
- package/dist/at-rules/color-scheme.js +5 -4
- package/dist/at-rules/color.d.ts +2 -3
- package/dist/at-rules/container.d.ts +1 -2
- package/dist/at-rules/container.js +2 -2
- package/dist/at-rules/index.d.ts +1 -2
- package/dist/at-rules/index.js +1 -0
- package/dist/errors.d.ts +2 -3
- package/dist/errors.js +9 -4
- package/dist/helpers.d.ts +5 -4
- package/dist/helpers.js +8 -5
- package/dist/index.d.ts +1 -4
- package/dist/parser.d.ts +1 -2
- package/dist/plugin.d.ts +1 -3
- package/dist/plugin.js +21 -9
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/at-rules/color-scheme.ts +9 -8
- package/src/at-rules/color.ts +3 -3
- package/src/at-rules/container.ts +6 -6
- package/src/at-rules/index.ts +2 -2
- package/src/errors.ts +10 -6
- package/src/helpers.ts +11 -11
- package/src/parser.ts +2 -2
- package/src/plugin.ts +25 -12
- package/src/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.0.0-canary.25](https://github.com/seyuna-corp/seyuna-postcss/compare/v1.0.0-canary.24...v1.0.0-canary.25) (2026-01-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* resolve deadlock by correctly passing Result object for warnings ([f7766a0](https://github.com/seyuna-corp/seyuna-postcss/commit/f7766a0f3914c19368aa2a73dfca4b2217a47072))
|
|
7
|
+
|
|
8
|
+
# [1.0.0-canary.24](https://github.com/seyuna-corp/seyuna-postcss/compare/v1.0.0-canary.23...v1.0.0-canary.24) (2026-01-10)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* resolve deadlock by preventing infinite loop and using deep imports ([b7b552c](https://github.com/seyuna-corp/seyuna-postcss/commit/b7b552cfc52c88e07d12022f27269fee16ccb013))
|
|
14
|
+
|
|
1
15
|
# [1.0.0-canary.23](https://github.com/seyuna-corp/seyuna-postcss/compare/v1.0.0-canary.22...v1.0.0-canary.23) (2026-01-10)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
2
1
|
import { PluginContext } from "../types.js";
|
|
3
|
-
export declare const light: (atRule:
|
|
4
|
-
export declare const dark: (atRule:
|
|
2
|
+
export declare const light: (atRule: any, context: PluginContext) => void;
|
|
3
|
+
export declare const dark: (atRule: any, context: PluginContext) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Rule from "postcss/lib/rule";
|
|
2
|
+
import AtRule from "postcss/lib/at-rule";
|
|
2
3
|
/**
|
|
3
4
|
* Custom PostCSS plugin handler factory for `@light` and `@dark` at-rules.
|
|
4
5
|
*/
|
|
@@ -14,7 +15,7 @@ function createColorSchemeHandler(scheme) {
|
|
|
14
15
|
/**
|
|
15
16
|
* Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
|
|
16
17
|
*/
|
|
17
|
-
const explicitRule = new
|
|
18
|
+
const explicitRule = new Rule({
|
|
18
19
|
selector: `[${modeAttribute}="${scheme}"] &`,
|
|
19
20
|
source: atRule.source,
|
|
20
21
|
});
|
|
@@ -22,12 +23,12 @@ function createColorSchemeHandler(scheme) {
|
|
|
22
23
|
/**
|
|
23
24
|
* Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
|
|
24
25
|
*/
|
|
25
|
-
const mediaAtRule = new
|
|
26
|
+
const mediaAtRule = new AtRule({
|
|
26
27
|
name: "media",
|
|
27
28
|
params: `(prefers-color-scheme: ${scheme})`,
|
|
28
29
|
source: atRule.source,
|
|
29
30
|
});
|
|
30
|
-
const systemRule = new
|
|
31
|
+
const systemRule = new Rule({
|
|
31
32
|
selector: `[${modeAttribute}="system"] &`,
|
|
32
33
|
source: atRule.source,
|
|
33
34
|
});
|
package/dist/at-rules/color.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
2
1
|
import { PluginContext } from "../types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Handler for @each-standard-color
|
|
5
4
|
*/
|
|
6
|
-
export declare function eachStandardColor(atRule:
|
|
5
|
+
export declare function eachStandardColor(atRule: any, context: PluginContext): void;
|
|
7
6
|
/**
|
|
8
7
|
* Handler for @each-fixed-color
|
|
9
8
|
*/
|
|
10
|
-
export declare function eachFixedColor(atRule:
|
|
9
|
+
export declare function eachFixedColor(atRule: any, context: PluginContext): void;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
2
1
|
import { PluginContext } from "../types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Custom PostCSS plugin handler for responsive at-rules.
|
|
@@ -16,4 +15,4 @@ import { PluginContext } from "../types.js";
|
|
|
16
15
|
* }
|
|
17
16
|
*
|
|
18
17
|
*/
|
|
19
|
-
export default function container(atRule:
|
|
18
|
+
export default function container(atRule: any, context: PluginContext): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AtRule from "postcss/lib/at-rule";
|
|
2
2
|
/**
|
|
3
3
|
* Custom PostCSS plugin handler for responsive at-rules.
|
|
4
4
|
*
|
|
@@ -37,7 +37,7 @@ export default function container(atRule, context) {
|
|
|
37
37
|
atRule.each((node) => {
|
|
38
38
|
clonedNodes.push(node.clone());
|
|
39
39
|
});
|
|
40
|
-
const containerAtRule = new
|
|
40
|
+
const containerAtRule = new AtRule({
|
|
41
41
|
name: "container",
|
|
42
42
|
params: `(min-width: ${minWidth})`,
|
|
43
43
|
source: atRule.source,
|
package/dist/at-rules/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
2
1
|
import { PluginContext } from "../types.js";
|
|
3
2
|
export interface AtRuleHandler {
|
|
4
3
|
name: string;
|
|
5
|
-
handler: (atRule:
|
|
4
|
+
handler: (atRule: any, context: PluginContext) => void;
|
|
6
5
|
}
|
|
7
6
|
export declare const atRuleHandlers: AtRuleHandler[];
|
package/dist/at-rules/index.js
CHANGED
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Node } from 'postcss';
|
|
2
1
|
import { PluginContext } from './types.js';
|
|
3
|
-
export declare function reportError(message: string, node:
|
|
2
|
+
export declare function reportError(message: string, node: any, context: PluginContext, options?: {
|
|
4
3
|
word?: string;
|
|
5
4
|
index?: number;
|
|
6
5
|
}): void;
|
|
7
|
-
export declare function reportWarning(message: string, node:
|
|
6
|
+
export declare function reportWarning(message: string, node: any, context?: PluginContext): void;
|
package/dist/errors.js
CHANGED
|
@@ -5,10 +5,15 @@ export function reportError(message, node, context, options = {}) {
|
|
|
5
5
|
throw node.error(formattedMessage, options);
|
|
6
6
|
}
|
|
7
7
|
else {
|
|
8
|
-
reportWarning(formattedMessage, node);
|
|
8
|
+
reportWarning(formattedMessage, node, context);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export function reportWarning(message, node) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export function reportWarning(message, node, context) {
|
|
12
|
+
if (context?.result) {
|
|
13
|
+
node.warn(context.result, `[Seyuna PostCSS] ${message}`);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// Fallback if no result is available (should not happen in main flow)
|
|
17
|
+
console.warn(`[Seyuna PostCSS Warning] ${message}`);
|
|
18
|
+
}
|
|
14
19
|
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ChildNode, AtRule } from "postcss";
|
|
1
|
+
import Rule from "postcss/lib/rule";
|
|
3
2
|
import { PluginContext } from './types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
6
5
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
7
6
|
*/
|
|
8
|
-
export declare function cloneNodes(nodes:
|
|
7
|
+
export declare function cloneNodes(nodes: any[], // ChildNode[]
|
|
8
|
+
name: string, context: PluginContext): any[];
|
|
9
9
|
/**
|
|
10
10
|
* Generate CSS rules from a list of names
|
|
11
11
|
*/
|
|
12
|
-
export declare function generateRules(names: string[], atRule:
|
|
12
|
+
export declare function generateRules(names: string[], atRule: any, // AtRule
|
|
13
|
+
context: PluginContext): Rule[];
|
package/dist/helpers.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Rule from "postcss/lib/rule";
|
|
2
|
+
// import type { ChildNode, Declaration, AtRule } from "postcss";
|
|
2
3
|
import { processFunctions } from "./parser.js";
|
|
3
4
|
/**
|
|
4
5
|
* Helper: clone nodes and replace {name} placeholders safely
|
|
5
6
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
6
7
|
*/
|
|
7
|
-
export function cloneNodes(nodes,
|
|
8
|
+
export function cloneNodes(nodes, // ChildNode[]
|
|
9
|
+
name, context) {
|
|
8
10
|
const { functions: fnMap } = context;
|
|
9
11
|
return nodes.flatMap((node) => {
|
|
10
12
|
const cloned = node.clone();
|
|
11
13
|
if (cloned.type === "decl") {
|
|
12
|
-
const decl = cloned;
|
|
14
|
+
const decl = cloned; // Declaration
|
|
13
15
|
let value = decl.value.replace(/\{name\}/g, name);
|
|
14
16
|
// Process functions using the robust parser
|
|
15
17
|
decl.value = processFunctions(value, fnMap, decl, context);
|
|
@@ -33,11 +35,12 @@ export function cloneNodes(nodes, name, context) {
|
|
|
33
35
|
/**
|
|
34
36
|
* Generate CSS rules from a list of names
|
|
35
37
|
*/
|
|
36
|
-
export function generateRules(names, atRule,
|
|
38
|
+
export function generateRules(names, atRule, // AtRule
|
|
39
|
+
context) {
|
|
37
40
|
const nodes = atRule.nodes ?? [];
|
|
38
41
|
const generatedRules = [];
|
|
39
42
|
for (const name of names) {
|
|
40
|
-
const rule = new
|
|
43
|
+
const rule = new Rule({
|
|
41
44
|
selector: `&.${name}`,
|
|
42
45
|
source: atRule.source,
|
|
43
46
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/parser.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Node } from 'postcss';
|
|
2
1
|
import { PluginContext, FunctionMap } from './types.js';
|
|
3
2
|
export type { FunctionMap } from './types.js';
|
|
4
|
-
export declare function processFunctions(value: string, fnMap: FunctionMap, node:
|
|
3
|
+
export declare function processFunctions(value: string, fnMap: FunctionMap, node: any, context: PluginContext): string;
|
package/dist/plugin.d.ts
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// import type { PluginCreator } from "postcss";
|
|
1
2
|
import { functions } from "./functions/index.js";
|
|
2
3
|
import { atRuleHandlers } from "./at-rules/index.js";
|
|
3
4
|
import { loadConfigAsync } from "./config.js";
|
|
@@ -8,18 +9,29 @@ export const dynamicFunctionsPlugin = (opts = {}) => {
|
|
|
8
9
|
return {
|
|
9
10
|
postcssPlugin: "postcss-dynamic-functions",
|
|
10
11
|
async Once() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
try {
|
|
13
|
+
const { config, options } = await loadConfigAsync(opts);
|
|
14
|
+
fnMap = { ...functions, ...opts.functions };
|
|
15
|
+
context = {
|
|
16
|
+
config,
|
|
17
|
+
options,
|
|
18
|
+
functions: fnMap,
|
|
19
|
+
result: undefined
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
18
25
|
},
|
|
19
|
-
Declaration(decl) {
|
|
26
|
+
Declaration(decl, { result }) {
|
|
20
27
|
if (!context || !fnMap)
|
|
21
28
|
return;
|
|
22
|
-
|
|
29
|
+
// Update context with the current result object
|
|
30
|
+
context.result = result;
|
|
31
|
+
const newValue = processFunctions(decl.value, fnMap, decl, context);
|
|
32
|
+
if (newValue !== decl.value) {
|
|
33
|
+
decl.value = newValue;
|
|
34
|
+
}
|
|
23
35
|
},
|
|
24
36
|
// Override AtRule handler to ensure ordered execution
|
|
25
37
|
AtRule(atRule) {
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import Rule from "postcss/lib/rule";
|
|
2
|
+
import AtRule from "postcss/lib/at-rule";
|
|
3
|
+
// import type { ChildNode } from "postcss";
|
|
3
4
|
import { PluginContext } from "../types.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Custom PostCSS plugin handler factory for `@light` and `@dark` at-rules.
|
|
7
8
|
*/
|
|
8
9
|
function createColorSchemeHandler(scheme: 'light' | 'dark') {
|
|
9
|
-
return (atRule:
|
|
10
|
+
return (atRule: any, context: PluginContext) => {
|
|
10
11
|
const { options } = context;
|
|
11
12
|
const modeAttribute = options.modeAttribute;
|
|
12
|
-
const clonedNodes:
|
|
13
|
+
const clonedNodes: any[] = [];
|
|
13
14
|
|
|
14
15
|
// Clone all child nodes inside the block
|
|
15
|
-
atRule.each((node:
|
|
16
|
+
atRule.each((node: any) => {
|
|
16
17
|
clonedNodes.push(node.clone());
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Rule 1: [data-mode="scheme"] & { ... } (Explicit mode)
|
|
21
22
|
*/
|
|
22
|
-
const explicitRule = new
|
|
23
|
+
const explicitRule = new Rule({
|
|
23
24
|
selector: `[${modeAttribute}="${scheme}"] &`,
|
|
24
25
|
source: atRule.source,
|
|
25
26
|
});
|
|
@@ -28,13 +29,13 @@ function createColorSchemeHandler(scheme: 'light' | 'dark') {
|
|
|
28
29
|
/**
|
|
29
30
|
* Rule 2: @media (prefers-color-scheme: scheme) { [data-mode="system"] & { ... } } (System preference)
|
|
30
31
|
*/
|
|
31
|
-
const mediaAtRule = new
|
|
32
|
+
const mediaAtRule = new AtRule({
|
|
32
33
|
name: "media",
|
|
33
34
|
params: `(prefers-color-scheme: ${scheme})`,
|
|
34
35
|
source: atRule.source,
|
|
35
36
|
});
|
|
36
37
|
|
|
37
|
-
const systemRule = new
|
|
38
|
+
const systemRule = new Rule({
|
|
38
39
|
selector: `[${modeAttribute}="system"] &`,
|
|
39
40
|
source: atRule.source,
|
|
40
41
|
});
|
package/src/at-rules/color.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
1
|
+
// import type { AtRule } from "postcss";
|
|
2
2
|
import { PluginContext } from "../types.js";
|
|
3
3
|
import { generateRules } from "../helpers.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Handler for @each-standard-color
|
|
7
7
|
*/
|
|
8
|
-
export function eachStandardColor(atRule:
|
|
8
|
+
export function eachStandardColor(atRule: any, context: PluginContext) {
|
|
9
9
|
const { config } = context;
|
|
10
10
|
const hueNames = config.ui ? Object.keys(config.ui.theme.hues) : [];
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ export function eachStandardColor(atRule: AtRule, context: PluginContext) {
|
|
|
17
17
|
/**
|
|
18
18
|
* Handler for @each-fixed-color
|
|
19
19
|
*/
|
|
20
|
-
export function eachFixedColor(atRule:
|
|
20
|
+
export function eachFixedColor(atRule: any, context: PluginContext) {
|
|
21
21
|
const { config } = context;
|
|
22
22
|
|
|
23
23
|
const mergedNames = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import AtRule from "postcss/lib/at-rule";
|
|
2
|
+
// import type { ChildNode } from "postcss"; // AtRule is now a value import
|
|
3
3
|
import { PluginContext } from "../types.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,7 +18,7 @@ import { PluginContext } from "../types.js";
|
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
export default function container(atRule:
|
|
21
|
+
export default function container(atRule: any, context: PluginContext) {
|
|
22
22
|
const { config } = context;
|
|
23
23
|
|
|
24
24
|
// Default breakpoints
|
|
@@ -40,12 +40,12 @@ export default function container(atRule: AtRule, context: PluginContext) {
|
|
|
40
40
|
if (Object.keys(breakpoints).includes(atRule.name)) {
|
|
41
41
|
const minWidth = breakpoints[atRule.name];
|
|
42
42
|
|
|
43
|
-
const clonedNodes:
|
|
44
|
-
atRule.each((node:
|
|
43
|
+
const clonedNodes: any[] = [];
|
|
44
|
+
atRule.each((node: any) => {
|
|
45
45
|
clonedNodes.push(node.clone());
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const containerAtRule = new
|
|
48
|
+
const containerAtRule = new AtRule({
|
|
49
49
|
name: "container",
|
|
50
50
|
params: `(min-width: ${minWidth})`,
|
|
51
51
|
source: atRule.source,
|
package/src/at-rules/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AtRule } from "postcss";
|
|
1
|
+
// import type { AtRule } from "postcss";
|
|
2
2
|
import { eachStandardColor, eachFixedColor } from "./color.js";
|
|
3
3
|
import container from "./container.js";
|
|
4
4
|
import { light, dark } from "./color-scheme.js";
|
|
@@ -7,7 +7,7 @@ import { PluginContext } from "../types.js";
|
|
|
7
7
|
// Each handler has a name (matches the at-rule) and the function
|
|
8
8
|
export interface AtRuleHandler {
|
|
9
9
|
name: string;
|
|
10
|
-
handler: (atRule:
|
|
10
|
+
handler: (atRule: any, context: PluginContext) => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// Ordered array ensures execution order
|
package/src/errors.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Node } from 'postcss';
|
|
1
|
+
// import type { Node } from 'postcss';
|
|
2
2
|
import { PluginContext } from './types.js';
|
|
3
3
|
|
|
4
4
|
export function reportError(
|
|
5
5
|
message: string,
|
|
6
|
-
node:
|
|
6
|
+
node: any,
|
|
7
7
|
context: PluginContext,
|
|
8
8
|
options: { word?: string; index?: number } = {}
|
|
9
9
|
) {
|
|
@@ -13,11 +13,15 @@ export function reportError(
|
|
|
13
13
|
if (pluginOptions.strict) {
|
|
14
14
|
throw node.error(formattedMessage, options);
|
|
15
15
|
} else {
|
|
16
|
-
reportWarning(formattedMessage, node);
|
|
16
|
+
reportWarning(formattedMessage, node, context);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function reportWarning(message: string, node:
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export function reportWarning(message: string, node: any, context?: PluginContext) {
|
|
21
|
+
if (context?.result) {
|
|
22
|
+
node.warn(context.result, `[Seyuna PostCSS] ${message}`);
|
|
23
|
+
} else {
|
|
24
|
+
// Fallback if no result is available (should not happen in main flow)
|
|
25
|
+
console.warn(`[Seyuna PostCSS Warning] ${message}`);
|
|
26
|
+
}
|
|
23
27
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ChildNode, Declaration, AtRule } from "postcss";
|
|
1
|
+
import Rule from "postcss/lib/rule";
|
|
2
|
+
// import type { ChildNode, Declaration, AtRule } from "postcss";
|
|
3
3
|
import { processFunctions } from "./parser.js";
|
|
4
4
|
import { PluginContext } from './types.js';
|
|
5
5
|
|
|
@@ -8,17 +8,17 @@ import { PluginContext } from './types.js';
|
|
|
8
8
|
* Returns only valid Rules or Declarations (never raw AtRules)
|
|
9
9
|
*/
|
|
10
10
|
export function cloneNodes(
|
|
11
|
-
nodes: ChildNode[]
|
|
11
|
+
nodes: any[], // ChildNode[]
|
|
12
12
|
name: string,
|
|
13
13
|
context: PluginContext
|
|
14
|
-
):
|
|
14
|
+
): any[] { // ChildNode[]
|
|
15
15
|
const { functions: fnMap } = context;
|
|
16
16
|
|
|
17
17
|
return nodes.flatMap((node) => {
|
|
18
18
|
const cloned = node.clone();
|
|
19
19
|
|
|
20
20
|
if (cloned.type === "decl") {
|
|
21
|
-
const decl = cloned as Declaration
|
|
21
|
+
const decl = cloned as any; // Declaration
|
|
22
22
|
let value = decl.value.replace(/\{name\}/g, name);
|
|
23
23
|
|
|
24
24
|
// Process functions using the robust parser
|
|
@@ -28,7 +28,7 @@ export function cloneNodes(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (cloned.type === "rule") {
|
|
31
|
-
const rule = cloned as
|
|
31
|
+
const rule = cloned as Rule;
|
|
32
32
|
if (!rule.selector) return [];
|
|
33
33
|
|
|
34
34
|
rule.selector = rule.selector.replace(/\{name\}/g, name);
|
|
@@ -52,19 +52,19 @@ export function cloneNodes(
|
|
|
52
52
|
*/
|
|
53
53
|
export function generateRules(
|
|
54
54
|
names: string[],
|
|
55
|
-
atRule: AtRule
|
|
55
|
+
atRule: any, // AtRule
|
|
56
56
|
context: PluginContext
|
|
57
|
-
):
|
|
57
|
+
): Rule[] {
|
|
58
58
|
const nodes = atRule.nodes ?? [];
|
|
59
|
-
const generatedRules:
|
|
59
|
+
const generatedRules: Rule[] = [];
|
|
60
60
|
|
|
61
61
|
for (const name of names) {
|
|
62
|
-
const rule = new
|
|
62
|
+
const rule = new Rule({
|
|
63
63
|
selector: `&.${name}`,
|
|
64
64
|
source: atRule.source,
|
|
65
65
|
});
|
|
66
66
|
cloneNodes(nodes, name, context).forEach((n) => {
|
|
67
|
-
if (n.type === "rule" && n.selector && (n as
|
|
67
|
+
if (n.type === "rule" && n.selector && (n as Rule).nodes?.length) rule.append(n);
|
|
68
68
|
if (n.type === "decl") rule.append(n);
|
|
69
69
|
});
|
|
70
70
|
|
package/src/parser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import valueParser from 'postcss-value-parser';
|
|
2
|
-
import { Node } from 'postcss';
|
|
2
|
+
// import type { Node } from 'postcss';
|
|
3
3
|
import { PluginContext, FunctionMap } from './types.js';
|
|
4
4
|
import { reportError } from './errors.js';
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ export type { FunctionMap } from './types.js';
|
|
|
9
9
|
export function processFunctions(
|
|
10
10
|
value: string,
|
|
11
11
|
fnMap: FunctionMap,
|
|
12
|
-
node:
|
|
12
|
+
node: any,
|
|
13
13
|
context: PluginContext
|
|
14
14
|
): string {
|
|
15
15
|
const parsed = valueParser(value);
|
package/src/plugin.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { PluginCreator } from "postcss";
|
|
1
|
+
// import type { PluginCreator } from "postcss";
|
|
2
2
|
import { functions } from "./functions/index.js";
|
|
3
3
|
import { atRuleHandlers } from "./at-rules/index.js";
|
|
4
4
|
import { loadConfig, loadConfigAsync } from "./config.js";
|
|
5
5
|
import { PluginOptions, PluginContext, FunctionMap } from "./types.js";
|
|
6
6
|
import { processFunctions } from "./parser.js";
|
|
7
7
|
|
|
8
|
-
export const dynamicFunctionsPlugin:
|
|
8
|
+
export const dynamicFunctionsPlugin: any = (
|
|
9
9
|
opts = {}
|
|
10
10
|
) => {
|
|
11
11
|
let context: PluginContext | undefined;
|
|
@@ -15,22 +15,35 @@ export const dynamicFunctionsPlugin: PluginCreator<PluginOptions> = (
|
|
|
15
15
|
postcssPlugin: "postcss-dynamic-functions",
|
|
16
16
|
|
|
17
17
|
async Once() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
try {
|
|
19
|
+
const { config, options } = await loadConfigAsync(opts);
|
|
20
|
+
fnMap = { ...functions, ...(opts as any).functions };
|
|
21
|
+
context = {
|
|
22
|
+
config,
|
|
23
|
+
options,
|
|
24
|
+
functions: fnMap as FunctionMap,
|
|
25
|
+
result: undefined
|
|
26
|
+
};
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
25
30
|
},
|
|
26
31
|
|
|
27
|
-
Declaration(decl) {
|
|
32
|
+
Declaration(decl: any, { result }: any) {
|
|
28
33
|
if (!context || !fnMap) return;
|
|
29
|
-
|
|
34
|
+
|
|
35
|
+
// Update context with the current result object
|
|
36
|
+
context.result = result;
|
|
37
|
+
|
|
38
|
+
const newValue = processFunctions(decl.value, fnMap, decl, context);
|
|
39
|
+
|
|
40
|
+
if (newValue !== decl.value) {
|
|
41
|
+
decl.value = newValue;
|
|
42
|
+
}
|
|
30
43
|
},
|
|
31
44
|
|
|
32
45
|
// Override AtRule handler to ensure ordered execution
|
|
33
|
-
AtRule(atRule) {
|
|
46
|
+
AtRule(atRule: any) {
|
|
34
47
|
if (!context) return;
|
|
35
48
|
// Iterate over handlers in order (array) instead of object spread
|
|
36
49
|
for (const { name, handler } of atRuleHandlers) {
|