@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.
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +146 -0
- package/README.md +275 -0
- package/dist/at-rules/color-scheme.d.ts +4 -0
- package/dist/at-rules/color-scheme.js +49 -0
- package/dist/at-rules/color.d.ts +10 -0
- package/dist/at-rules/color.js +34 -0
- package/dist/at-rules/container.d.ts +19 -0
- package/dist/at-rules/container.js +55 -0
- package/dist/at-rules/index.d.ts +6 -2
- package/dist/at-rules/index.js +16 -7
- package/dist/config.d.ts +6 -0
- package/dist/config.js +53 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +18 -0
- package/dist/functions/color.d.ts +7 -1
- package/dist/functions/color.js +66 -12
- package/dist/functions/index.d.ts +2 -1
- package/dist/functions/index.js +9 -7
- package/dist/functions/theme.d.ts +6 -0
- package/dist/functions/theme.js +20 -0
- package/dist/helpers.d.ts +12 -0
- package/dist/helpers.js +63 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -4
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +65 -0
- package/dist/plugin.d.ts +2 -4
- package/dist/plugin.js +28 -16
- package/dist/types.d.ts +59 -0
- package/dist/types.js +4 -0
- package/package.json +14 -5
- package/release.config.mjs +6 -1
- package/src/at-rules/color-scheme.ts +53 -0
- package/src/at-rules/color.ts +33 -0
- package/src/at-rules/container.ts +58 -0
- package/src/at-rules/index.ts +22 -8
- 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 +75 -0
- package/src/index.ts +5 -3
- package/src/parser.ts +81 -0
- package/src/plugin.ts +29 -24
- 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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import postcss from 'postcss';
|
|
3
|
+
import plugin from '../src/index';
|
|
4
|
+
|
|
5
|
+
const mockConfig = {
|
|
6
|
+
ui: {
|
|
7
|
+
theme: {
|
|
8
|
+
hues: {
|
|
9
|
+
primary: "200",
|
|
10
|
+
secondary: "100"
|
|
11
|
+
},
|
|
12
|
+
colors: {
|
|
13
|
+
white: { lightness: 1, chroma: 0, hue: 0 },
|
|
14
|
+
black: { lightness: 0, chroma: 0, hue: 0 }
|
|
15
|
+
},
|
|
16
|
+
light: {
|
|
17
|
+
lightness: 0.66,
|
|
18
|
+
colors: {
|
|
19
|
+
surface: { lightness: 1, chroma: 0, hue: 0 }
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
dark: {
|
|
23
|
+
lightness: 0.66,
|
|
24
|
+
colors: {
|
|
25
|
+
surface: { lightness: 0, chroma: 0, hue: 0 }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
breakpoints: {
|
|
29
|
+
tablet: "48rem"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async function run(input: string, opts: any = {}) {
|
|
36
|
+
const mergedOpts = { config: mockConfig, ...opts };
|
|
37
|
+
return postcss([plugin(mergedOpts)]).process(input, { from: undefined });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('Seyuna PostCSS Plugin', () => {
|
|
41
|
+
it('processes sc() function', async () => {
|
|
42
|
+
const input = '.test { color: sc(primary); }';
|
|
43
|
+
const output = '.test { color: oklch(var(--lightness) var(--chroma) var(--primary-hue) / 1)';
|
|
44
|
+
const result = await run(input);
|
|
45
|
+
expect(result.css).toContain(output);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('processes sc() with alpha', async () => {
|
|
49
|
+
const input = '.test { color: sc(primary, 0.5); }';
|
|
50
|
+
const output = '.test { color: oklch(var(--lightness) var(--chroma) var(--primary-hue) / 0.5)';
|
|
51
|
+
const result = await run(input);
|
|
52
|
+
expect(result.css).toContain(output);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('processes alpha() function with color name', async () => {
|
|
56
|
+
const input = '.test { color: alpha(primary, 0.5); }';
|
|
57
|
+
const output = 'color: oklch(var(--lightness) var(--chroma) var(--primary-hue) / 0.5)';
|
|
58
|
+
const result = await run(input);
|
|
59
|
+
expect(result.css).toContain(output);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('processes lighten() function with color name', async () => {
|
|
63
|
+
const input = '.test { color: lighten(primary, 0.1); }';
|
|
64
|
+
const output = 'color: oklch(calc(var(--lightness) + 0.1) var(--chroma) var(--primary-hue) / 1)';
|
|
65
|
+
const result = await run(input);
|
|
66
|
+
expect(result.css).toContain(output);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('processes darken() function with color name', async () => {
|
|
70
|
+
const input = '.test { color: darken(primary, 0.1); }';
|
|
71
|
+
const output = 'color: oklch(calc(var(--lightness) - 0.1) var(--chroma) var(--primary-hue) / 1)';
|
|
72
|
+
const result = await run(input);
|
|
73
|
+
expect(result.css).toContain(output);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('processes theme() function', async () => {
|
|
77
|
+
// We pass the config via opts for testing
|
|
78
|
+
const input = '.test { border-radius: theme(ui.theme.breakpoints.tablet); }';
|
|
79
|
+
const result = await run(input, { config: mockConfig });
|
|
80
|
+
expect(result.css).toContain('.test { border-radius: 48rem');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('processes @xs container at-rule', async () => {
|
|
84
|
+
const input = '@xs { .box { color: red; } }';
|
|
85
|
+
const result = await run(input);
|
|
86
|
+
expect(result.css).toContain('@container (min-width: 20rem)');
|
|
87
|
+
expect(result.css).toContain('.box { color: red');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('processes @light at-rule', async () => {
|
|
91
|
+
const input = '@light { .test { color: black; } }';
|
|
92
|
+
const result = await run(input);
|
|
93
|
+
expect(result.css).toContain('@media (prefers-color-scheme: light)');
|
|
94
|
+
expect(result.css).toContain('[data-mode="system"] &');
|
|
95
|
+
expect(result.css).toContain('[data-mode="light"] &');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('processes alpha() with standard color', async () => {
|
|
99
|
+
const input = '.test { color: alpha(primary, 0.5); }';
|
|
100
|
+
const output = 'color: oklch(var(--lightness) var(--chroma) var(--primary-hue) / 0.5)';
|
|
101
|
+
const result = await run(input, { config: mockConfig });
|
|
102
|
+
expect(result.css).toContain(output);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('processes alpha() with fixed color', async () => {
|
|
106
|
+
const input = '.test { color: alpha(surface, 0.5); }';
|
|
107
|
+
const output = 'color: oklch(var(--surface-lightness) var(--surface-chroma) var(--surface-hue) / 0.5)';
|
|
108
|
+
const result = await run(input, { config: mockConfig });
|
|
109
|
+
expect(result.css).toContain(output);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('processes contrast() with fixed color', async () => {
|
|
113
|
+
const input = '.test { color: contrast(surface); }';
|
|
114
|
+
const output = 'color: oklch(calc((var(--surface-lightness) - 0.6) * -1000) 0 0)';
|
|
115
|
+
const result = await run(input, { config: mockConfig });
|
|
116
|
+
expect(result.css).toContain(output);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('processes contrast() with standard color', async () => {
|
|
120
|
+
const input = '.test { color: contrast(primary); }';
|
|
121
|
+
const output = 'color: oklch(calc((var(--lightness) - 0.6) * -1000) 0 0)';
|
|
122
|
+
const result = await run(input, { config: mockConfig });
|
|
123
|
+
expect(result.css).toContain(output);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('throws error for unknown standard color in strict mode', async () => {
|
|
127
|
+
const input = '.test { color: sc(unknown); }';
|
|
128
|
+
await expect(run(input, { config: mockConfig, strict: true }))
|
|
129
|
+
.rejects.toThrow(/Standard color 'unknown' not found/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('throws error for unknown fixed color in strict mode', async () => {
|
|
133
|
+
const input = '.test { color: fc(unknown); }';
|
|
134
|
+
await expect(run(input, { config: mockConfig, strict: true }))
|
|
135
|
+
.rejects.toThrow(/Fixed color 'unknown' not found/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('throws error for unknown color in alpha() in strict mode', async () => {
|
|
139
|
+
const input = '.test { color: alpha(unknown, 0.5); }';
|
|
140
|
+
await expect(run(input, { config: mockConfig, strict: true }))
|
|
141
|
+
.rejects.toThrow(/Color 'unknown' not found in seyuna.json/);
|
|
142
|
+
});
|
|
143
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2019",
|
|
4
4
|
"module": "CommonJS",
|
|
5
5
|
"lib": ["ES2020"],
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"outDir": "dist",
|
|
8
8
|
"strict": true,
|
|
9
|
-
"moduleResolution": "
|
|
9
|
+
"moduleResolution": "Node",
|
|
10
10
|
"esModuleInterop": true,
|
|
11
11
|
"skipLibCheck": true
|
|
12
12
|
},
|
package/dist/at-rules/dark.d.ts
DELETED
package/dist/at-rules/dark.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = dark;
|
|
4
|
-
const postcss_1 = require("postcss");
|
|
5
|
-
function dark(atRule) {
|
|
6
|
-
const clonedNodes = [];
|
|
7
|
-
// Clone all child nodes so we can reuse them
|
|
8
|
-
atRule.each((node) => {
|
|
9
|
-
clonedNodes.push(node.clone());
|
|
10
|
-
});
|
|
11
|
-
// Create `[data-mode="dark"] &` rule
|
|
12
|
-
const dataAttrRule = new postcss_1.Rule({
|
|
13
|
-
selector: `[data-mode="dark"] &`,
|
|
14
|
-
});
|
|
15
|
-
clonedNodes.forEach((node) => dataAttrRule.append(node.clone()));
|
|
16
|
-
// Create `@media (prefers-color-scheme: dark)` wrapper
|
|
17
|
-
const mediaAtRule = new postcss_1.AtRule({
|
|
18
|
-
name: "media",
|
|
19
|
-
params: "(prefers-color-scheme: dark)",
|
|
20
|
-
});
|
|
21
|
-
const mediaRule = new postcss_1.Rule({
|
|
22
|
-
selector: `&`,
|
|
23
|
-
});
|
|
24
|
-
clonedNodes.forEach((node) => mediaRule.append(node.clone()));
|
|
25
|
-
mediaAtRule.append(mediaRule);
|
|
26
|
-
// Replace original @dark rule with both new rules
|
|
27
|
-
atRule.replaceWith(dataAttrRule, mediaAtRule);
|
|
28
|
-
}
|
package/dist/at-rules/light.d.ts
DELETED
package/dist/at-rules/light.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = light;
|
|
4
|
-
const postcss_1 = require("postcss");
|
|
5
|
-
function light(atRule) {
|
|
6
|
-
const clonedNodes = [];
|
|
7
|
-
// Clone all child nodes so we can reuse them
|
|
8
|
-
atRule.each((node) => {
|
|
9
|
-
clonedNodes.push(node.clone());
|
|
10
|
-
});
|
|
11
|
-
// Create `[data-mode="light"] &` rule
|
|
12
|
-
const dataAttrRule = new postcss_1.Rule({
|
|
13
|
-
selector: `[data-mode="light"] &`,
|
|
14
|
-
});
|
|
15
|
-
clonedNodes.forEach((node) => dataAttrRule.append(node.clone()));
|
|
16
|
-
// Create `@media (prefers-color-scheme: light)` wrapper
|
|
17
|
-
const mediaAtRule = new postcss_1.AtRule({
|
|
18
|
-
name: "media",
|
|
19
|
-
params: "(prefers-color-scheme: light)",
|
|
20
|
-
});
|
|
21
|
-
const mediaRule = new postcss_1.Rule({
|
|
22
|
-
selector: `&`,
|
|
23
|
-
});
|
|
24
|
-
clonedNodes.forEach((node) => mediaRule.append(node.clone()));
|
|
25
|
-
mediaAtRule.append(mediaRule);
|
|
26
|
-
// Replace original @light rule with both new rules
|
|
27
|
-
atRule.replaceWith(dataAttrRule, mediaAtRule);
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function spacing(multiplier: string): string;
|
package/src/at-rules/dark.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Rule, AtRule, ChildNode } from "postcss";
|
|
2
|
-
|
|
3
|
-
export default function dark(atRule: AtRule) {
|
|
4
|
-
const clonedNodes: ChildNode[] = [];
|
|
5
|
-
|
|
6
|
-
// Clone all child nodes so we can reuse them
|
|
7
|
-
atRule.each((node: ChildNode) => {
|
|
8
|
-
clonedNodes.push(node.clone());
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// Create `[data-mode="dark"] &` rule
|
|
12
|
-
const dataAttrRule = new Rule({
|
|
13
|
-
selector: `[data-mode="dark"] &`,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
clonedNodes.forEach((node) => dataAttrRule.append(node.clone()));
|
|
17
|
-
|
|
18
|
-
// Create `@media (prefers-color-scheme: dark)` wrapper
|
|
19
|
-
const mediaAtRule = new AtRule({
|
|
20
|
-
name: "media",
|
|
21
|
-
params: "(prefers-color-scheme: dark)",
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const mediaRule = new Rule({
|
|
25
|
-
selector: `&`,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
clonedNodes.forEach((node) => mediaRule.append(node.clone()));
|
|
29
|
-
mediaAtRule.append(mediaRule);
|
|
30
|
-
|
|
31
|
-
// Replace original @dark rule with both new rules
|
|
32
|
-
atRule.replaceWith(dataAttrRule, mediaAtRule);
|
|
33
|
-
}
|
package/src/at-rules/light.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Rule, AtRule, ChildNode } from "postcss";
|
|
2
|
-
|
|
3
|
-
export default function light(atRule: AtRule) {
|
|
4
|
-
const clonedNodes: ChildNode[] = [];
|
|
5
|
-
|
|
6
|
-
// Clone all child nodes so we can reuse them
|
|
7
|
-
atRule.each((node: ChildNode) => {
|
|
8
|
-
clonedNodes.push(node.clone());
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// Create `[data-mode="light"] &` rule
|
|
12
|
-
const dataAttrRule = new Rule({
|
|
13
|
-
selector: `[data-mode="light"] &`,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
clonedNodes.forEach((node) => dataAttrRule.append(node.clone()));
|
|
17
|
-
|
|
18
|
-
// Create `@media (prefers-color-scheme: light)` wrapper
|
|
19
|
-
const mediaAtRule = new AtRule({
|
|
20
|
-
name: "media",
|
|
21
|
-
params: "(prefers-color-scheme: light)",
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const mediaRule = new Rule({
|
|
25
|
-
selector: `&`,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
clonedNodes.forEach((node) => mediaRule.append(node.clone()));
|
|
29
|
-
mediaAtRule.append(mediaRule);
|
|
30
|
-
|
|
31
|
-
// Replace original @light rule with both new rules
|
|
32
|
-
atRule.replaceWith(dataAttrRule, mediaAtRule);
|
|
33
|
-
}
|
package/src/functions/spacing.ts
DELETED