tailwind-preset-antd 0.0.1 → 0.0.2
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/dist/_virtual/_@oxc-project_runtime@0.127.0/helpers/defineProperty.js +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.127.0/helpers/objectSpread2.js +25 -0
- package/dist/_virtual/_@oxc-project_runtime@0.127.0/helpers/toPrimitive.js +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.127.0/helpers/toPropertyKey.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.127.0/helpers/typeof.js +11 -0
- package/dist/components.d.ts +7 -0
- package/dist/components.js +23 -0
- package/dist/core/genCssVarByTokens.js +31 -0
- package/dist/core/genTailwindTheme.js +46 -0
- package/dist/plugin.d.ts +28 -0
- package/dist/plugin.js +32 -0
- package/dist/preset/tokens/borderRadius.d.ts +4 -0
- package/dist/preset/tokens/borderRadius.js +9 -0
- package/dist/preset/tokens/colorPalettes.d.ts +7 -0
- package/dist/preset/tokens/colorPalettes.js +19 -0
- package/dist/preset/tokens/fontSizes.d.ts +4 -0
- package/dist/preset/tokens/fontSizes.js +9 -0
- package/dist/preset/tokens/functionalColors.d.ts +4 -0
- package/dist/preset/tokens/functionalColors.js +70 -0
- package/dist/preset/tokens/margins.d.ts +4 -0
- package/dist/preset/tokens/margins.js +13 -0
- package/dist/preset/tokens/semanticColors.d.ts +4 -0
- package/dist/preset/tokens/semanticColors.js +26 -0
- package/dist/preset.d.ts +11 -0
- package/dist/preset.js +14 -0
- package/dist/utils/index.js +11 -0
- package/package.json +12 -1
- package/.github/workflows/gh-pages.yml +0 -49
- package/.vscode/settings.json +0 -25
- package/oxfmt.config.ts +0 -22
- package/oxlint.config.ts +0 -6
- package/playground/index.html +0 -12
- package/playground/src/App.tsx +0 -226
- package/playground/src/global.css +0 -4
- package/playground/src/index.tsx +0 -15
- package/src/components.test.tsx +0 -56
- package/src/components.tsx +0 -33
- package/src/constants/index.ts +0 -1
- package/src/core/genCssVarByToken.test.ts +0 -46
- package/src/core/genCssVarByTokens.ts +0 -45
- package/src/core/genTailwindTheme.test.ts +0 -95
- package/src/core/genTailwindTheme.ts +0 -62
- package/src/plugin.ts +0 -71
- package/src/preset/index.ts +0 -13
- package/src/preset/tokens/borderRadius.ts +0 -6
- package/src/preset/tokens/colorPalettes.ts +0 -24
- package/src/preset/tokens/fontSizes.ts +0 -6
- package/src/preset/tokens/functionalColors.ts +0 -72
- package/src/preset/tokens/margins.ts +0 -11
- package/src/preset/tokens/semanticColors.ts +0 -29
- package/src/utils/index.ts +0 -10
- package/tsconfig.json +0 -21
- package/tsdown.config.ts +0 -14
- package/vite.config.ts +0 -23
- package/vitest.setup.ts +0 -11
package/playground/src/App.tsx
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { Divider } from "antd";
|
|
2
|
-
|
|
3
|
-
const colorPalettes = [
|
|
4
|
-
"red",
|
|
5
|
-
"volcano",
|
|
6
|
-
"orange",
|
|
7
|
-
"lime",
|
|
8
|
-
"gold",
|
|
9
|
-
"yellow",
|
|
10
|
-
"green",
|
|
11
|
-
"cyan",
|
|
12
|
-
"blue",
|
|
13
|
-
"geekblue",
|
|
14
|
-
"purple",
|
|
15
|
-
"magenta",
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
const getColorClass = (color: string, index: number) => {
|
|
19
|
-
const classes = {
|
|
20
|
-
red: [
|
|
21
|
-
"bg-red-1",
|
|
22
|
-
"bg-red-2",
|
|
23
|
-
"bg-red-3",
|
|
24
|
-
"bg-red-4",
|
|
25
|
-
"bg-red-5",
|
|
26
|
-
"bg-red-6",
|
|
27
|
-
"bg-red-7",
|
|
28
|
-
"bg-red-8",
|
|
29
|
-
"bg-red-9",
|
|
30
|
-
"bg-red-10",
|
|
31
|
-
],
|
|
32
|
-
volcano: [
|
|
33
|
-
"bg-volcano-1",
|
|
34
|
-
"bg-volcano-2",
|
|
35
|
-
"bg-volcano-3",
|
|
36
|
-
"bg-volcano-4",
|
|
37
|
-
"bg-volcano-5",
|
|
38
|
-
"bg-volcano-6",
|
|
39
|
-
"bg-volcano-7",
|
|
40
|
-
"bg-volcano-8",
|
|
41
|
-
"bg-volcano-9",
|
|
42
|
-
"bg-volcano-10",
|
|
43
|
-
],
|
|
44
|
-
orange: [
|
|
45
|
-
"bg-orange-1",
|
|
46
|
-
"bg-orange-2",
|
|
47
|
-
"bg-orange-3",
|
|
48
|
-
"bg-orange-4",
|
|
49
|
-
"bg-orange-5",
|
|
50
|
-
"bg-orange-6",
|
|
51
|
-
"bg-orange-7",
|
|
52
|
-
"bg-orange-8",
|
|
53
|
-
"bg-orange-9",
|
|
54
|
-
"bg-orange-10",
|
|
55
|
-
],
|
|
56
|
-
lime: [
|
|
57
|
-
"bg-lime-1",
|
|
58
|
-
"bg-lime-2",
|
|
59
|
-
"bg-lime-3",
|
|
60
|
-
"bg-lime-4",
|
|
61
|
-
"bg-lime-5",
|
|
62
|
-
"bg-lime-6",
|
|
63
|
-
"bg-lime-7",
|
|
64
|
-
"bg-lime-8",
|
|
65
|
-
"bg-lime-9",
|
|
66
|
-
"bg-lime-10",
|
|
67
|
-
],
|
|
68
|
-
gold: [
|
|
69
|
-
"bg-gold-1",
|
|
70
|
-
"bg-gold-2",
|
|
71
|
-
"bg-gold-3",
|
|
72
|
-
"bg-gold-4",
|
|
73
|
-
"bg-gold-5",
|
|
74
|
-
"bg-gold-6",
|
|
75
|
-
"bg-gold-7",
|
|
76
|
-
"bg-gold-8",
|
|
77
|
-
"bg-gold-9",
|
|
78
|
-
"bg-gold-10",
|
|
79
|
-
],
|
|
80
|
-
yellow: [
|
|
81
|
-
"bg-yellow-1",
|
|
82
|
-
"bg-yellow-2",
|
|
83
|
-
"bg-yellow-3",
|
|
84
|
-
"bg-yellow-4",
|
|
85
|
-
"bg-yellow-5",
|
|
86
|
-
"bg-yellow-6",
|
|
87
|
-
"bg-yellow-7",
|
|
88
|
-
"bg-yellow-8",
|
|
89
|
-
"bg-yellow-9",
|
|
90
|
-
"bg-yellow-10",
|
|
91
|
-
],
|
|
92
|
-
green: [
|
|
93
|
-
"bg-green-1",
|
|
94
|
-
"bg-green-2",
|
|
95
|
-
"bg-green-3",
|
|
96
|
-
"bg-green-4",
|
|
97
|
-
"bg-green-5",
|
|
98
|
-
"bg-green-6",
|
|
99
|
-
"bg-green-7",
|
|
100
|
-
"bg-green-8",
|
|
101
|
-
"bg-green-9",
|
|
102
|
-
"bg-green-10",
|
|
103
|
-
],
|
|
104
|
-
cyan: [
|
|
105
|
-
"bg-cyan-1",
|
|
106
|
-
"bg-cyan-2",
|
|
107
|
-
"bg-cyan-3",
|
|
108
|
-
"bg-cyan-4",
|
|
109
|
-
"bg-cyan-5",
|
|
110
|
-
"bg-cyan-6",
|
|
111
|
-
"bg-cyan-7",
|
|
112
|
-
"bg-cyan-8",
|
|
113
|
-
"bg-cyan-9",
|
|
114
|
-
"bg-cyan-10",
|
|
115
|
-
],
|
|
116
|
-
blue: [
|
|
117
|
-
"bg-blue-1",
|
|
118
|
-
"bg-blue-2",
|
|
119
|
-
"bg-blue-3",
|
|
120
|
-
"bg-blue-4",
|
|
121
|
-
"bg-blue-5",
|
|
122
|
-
"bg-blue-6",
|
|
123
|
-
"bg-blue-7",
|
|
124
|
-
"bg-blue-8",
|
|
125
|
-
"bg-blue-9",
|
|
126
|
-
"bg-blue-10",
|
|
127
|
-
],
|
|
128
|
-
geekblue: [
|
|
129
|
-
"bg-geekblue-1",
|
|
130
|
-
"bg-geekblue-2",
|
|
131
|
-
"bg-geekblue-3",
|
|
132
|
-
"bg-geekblue-4",
|
|
133
|
-
"bg-geekblue-5",
|
|
134
|
-
"bg-geekblue-6",
|
|
135
|
-
"bg-geekblue-7",
|
|
136
|
-
"bg-geekblue-8",
|
|
137
|
-
"bg-geekblue-9",
|
|
138
|
-
"bg-geekblue-10",
|
|
139
|
-
],
|
|
140
|
-
purple: [
|
|
141
|
-
"bg-purple-1",
|
|
142
|
-
"bg-purple-2",
|
|
143
|
-
"bg-purple-3",
|
|
144
|
-
"bg-purple-4",
|
|
145
|
-
"bg-purple-5",
|
|
146
|
-
"bg-purple-6",
|
|
147
|
-
"bg-purple-7",
|
|
148
|
-
"bg-purple-8",
|
|
149
|
-
"bg-purple-9",
|
|
150
|
-
"bg-purple-10",
|
|
151
|
-
],
|
|
152
|
-
magenta: [
|
|
153
|
-
"bg-magenta-1",
|
|
154
|
-
"bg-magenta-2",
|
|
155
|
-
"bg-magenta-3",
|
|
156
|
-
"bg-magenta-4",
|
|
157
|
-
"bg-magenta-5",
|
|
158
|
-
"bg-magenta-6",
|
|
159
|
-
"bg-magenta-7",
|
|
160
|
-
"bg-magenta-8",
|
|
161
|
-
"bg-magenta-9",
|
|
162
|
-
"bg-magenta-10",
|
|
163
|
-
],
|
|
164
|
-
};
|
|
165
|
-
return classes[color as keyof typeof classes][index];
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export default function App() {
|
|
169
|
-
return (
|
|
170
|
-
<div className="text-fontSize p-8">
|
|
171
|
-
<Divider>Tailwindcss color palettes for antd</Divider>
|
|
172
|
-
<div className="flex flex-col items-center gap-4 p-4">
|
|
173
|
-
{colorPalettes.map((color) => (
|
|
174
|
-
<div key={color} className="flex gap-1">
|
|
175
|
-
<div className="w-16 text-sm font-bold">{color}</div>
|
|
176
|
-
<div className="flex gap-1">
|
|
177
|
-
{Array.from({ length: 10 }, (_, i) => (
|
|
178
|
-
<div
|
|
179
|
-
key={i}
|
|
180
|
-
className={`${getColorClass(color, i)} text-colorTextLightSolid flex h-8 w-8 items-center justify-center rounded text-xs`}
|
|
181
|
-
>
|
|
182
|
-
{i + 1}
|
|
183
|
-
</div>
|
|
184
|
-
))}
|
|
185
|
-
</div>
|
|
186
|
-
</div>
|
|
187
|
-
))}
|
|
188
|
-
</div>
|
|
189
|
-
|
|
190
|
-
<Divider>Rewrite antd component use plugin</Divider>
|
|
191
|
-
<div className="flex justify-center gap-6">
|
|
192
|
-
{/* Card */}
|
|
193
|
-
<div
|
|
194
|
-
style={{ width: 300 }}
|
|
195
|
-
className="text-colorTextHeading border-colorBorderSecondary rounded-borderRadiusLG flex flex-col justify-center border border-solid"
|
|
196
|
-
>
|
|
197
|
-
{/* header */}
|
|
198
|
-
<div className="px-marginLG border-colorBorderSecondary flex h-14 items-center border-b border-solid font-semibold">
|
|
199
|
-
<div className="flex w-full items-center">
|
|
200
|
-
<div className="inline-block flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
|
|
201
|
-
Default size card
|
|
202
|
-
</div>
|
|
203
|
-
<div className="text-fontSize font-normal">
|
|
204
|
-
<a className="text-colorPrimary cursor-pointer">More</a>
|
|
205
|
-
</div>
|
|
206
|
-
</div>
|
|
207
|
-
</div>
|
|
208
|
-
{/* content */}
|
|
209
|
-
<div className="p-marginLG">
|
|
210
|
-
<p>Card content</p>
|
|
211
|
-
<p>Card content</p>
|
|
212
|
-
<p>Card content</p>
|
|
213
|
-
</div>
|
|
214
|
-
</div>
|
|
215
|
-
|
|
216
|
-
{/* Button */}
|
|
217
|
-
<button
|
|
218
|
-
type="button"
|
|
219
|
-
className="px-margin rounded-borderRadius bg-colorPrimary text-colorTextLightSolid hover:bg-colorPrimaryHover active:bg-colorPrimaryActive h-8 cursor-pointer transition-colors"
|
|
220
|
-
>
|
|
221
|
-
Primary Button
|
|
222
|
-
</button>
|
|
223
|
-
</div>
|
|
224
|
-
</div>
|
|
225
|
-
);
|
|
226
|
-
}
|
package/playground/src/index.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { StrictMode } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { ConfigProvider } from "antd";
|
|
4
|
-
import App from "./App";
|
|
5
|
-
import AntdTokenCssVar from "../../src/components";
|
|
6
|
-
import "./global.css";
|
|
7
|
-
|
|
8
|
-
createRoot(document.querySelector("#app")!).render(
|
|
9
|
-
<StrictMode>
|
|
10
|
-
<ConfigProvider>
|
|
11
|
-
<AntdTokenCssVar />
|
|
12
|
-
<App />
|
|
13
|
-
</ConfigProvider>
|
|
14
|
-
</StrictMode>
|
|
15
|
-
);
|
package/src/components.test.tsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { render, cleanup } from "@testing-library/react";
|
|
2
|
-
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
3
|
-
import AntdTokenCssVar from "./components";
|
|
4
|
-
|
|
5
|
-
describe("AntdTokenCssVar", () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
document.head.innerHTML = "";
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
cleanup();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("should render correctly", () => {
|
|
15
|
-
const { container } = render(<AntdTokenCssVar />);
|
|
16
|
-
expect(container).toBeDefined();
|
|
17
|
-
const style = document.querySelector("style#antd-token-inject");
|
|
18
|
-
expect(style?.textContent).toContain("--a-");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should inject style element with CSS variables", () => {
|
|
22
|
-
render(<AntdTokenCssVar />);
|
|
23
|
-
const style = document.querySelector("style#antd-token-inject");
|
|
24
|
-
expect(style).toBeTruthy();
|
|
25
|
-
expect(style?.getAttribute("plugin-name")).toBe("tailwind-preset-antd");
|
|
26
|
-
expect(style?.textContent).toContain(":root{");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should use custom cssVarPrefix", () => {
|
|
30
|
-
render(<AntdTokenCssVar cssVarPrefix="custom" />);
|
|
31
|
-
const style = document.querySelector("style#antd-token-inject");
|
|
32
|
-
expect(style?.textContent).toContain("--custom-");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should remove style element on unmount", () => {
|
|
36
|
-
const { unmount } = render(<AntdTokenCssVar />);
|
|
37
|
-
let style = document.querySelector("style#antd-token-inject");
|
|
38
|
-
expect(style).toBeTruthy();
|
|
39
|
-
|
|
40
|
-
unmount();
|
|
41
|
-
style = document.querySelector("style#antd-token-inject");
|
|
42
|
-
expect(style).toBeFalsy();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should update CSS variables when token changes", () => {
|
|
46
|
-
const { rerender } = render(<AntdTokenCssVar cssVarPrefix="test" />);
|
|
47
|
-
const style = document.querySelector("style#antd-token-inject");
|
|
48
|
-
const firstContent = style?.textContent;
|
|
49
|
-
expect(firstContent).toContain("--test-");
|
|
50
|
-
|
|
51
|
-
rerender(<AntdTokenCssVar cssVarPrefix="test2" />);
|
|
52
|
-
const style2 = document.querySelector("style#antd-token-inject");
|
|
53
|
-
const secondContent = style2?.textContent;
|
|
54
|
-
expect(secondContent).toContain("--test2-");
|
|
55
|
-
});
|
|
56
|
-
});
|
package/src/components.tsx
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { theme } from "antd";
|
|
2
|
-
import { useInsertionEffect } from "react";
|
|
3
|
-
|
|
4
|
-
import { genCSSVarByTokens } from "./core/genCssVarByTokens";
|
|
5
|
-
|
|
6
|
-
const styleId = "antd-token-inject";
|
|
7
|
-
|
|
8
|
-
interface AntdTokenCssVarProps {
|
|
9
|
-
cssVarPrefix?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default function AntdTokenCssVar(props: AntdTokenCssVarProps) {
|
|
13
|
-
const { cssVarPrefix } = props;
|
|
14
|
-
const { token } = theme.useToken();
|
|
15
|
-
|
|
16
|
-
useInsertionEffect(() => {
|
|
17
|
-
const cssVar = genCSSVarByTokens(token, cssVarPrefix);
|
|
18
|
-
|
|
19
|
-
const style = document.querySelector(`#${styleId}`) || document.createElement("style");
|
|
20
|
-
style.id = styleId;
|
|
21
|
-
style.setAttribute("plugin-name", "tailwind-preset-antd");
|
|
22
|
-
|
|
23
|
-
style.textContent = `:root{${cssVar}}`;
|
|
24
|
-
document.head.appendChild(style);
|
|
25
|
-
|
|
26
|
-
return () => {
|
|
27
|
-
document.head.removeChild(style);
|
|
28
|
-
};
|
|
29
|
-
}, [token, cssVarPrefix]);
|
|
30
|
-
|
|
31
|
-
// return <style id={styleId}>{`:root{${cssVar}}`}</style>;
|
|
32
|
-
return null;
|
|
33
|
-
}
|
package/src/constants/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_CSS_VAR_PREFIX = "a";
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { genCSSVarByTokens } from "./genCssVarByTokens";
|
|
3
|
-
|
|
4
|
-
describe("createColorPalettes", () => {
|
|
5
|
-
it("should generate css variables correctly", () => {
|
|
6
|
-
const tokens = {
|
|
7
|
-
colorPrimary: "#ff0000",
|
|
8
|
-
colorSuccess: "#00ff00",
|
|
9
|
-
} as any;
|
|
10
|
-
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
11
|
-
expect(result).toContain("--css-var-colorPrimary:255, 0, 0;");
|
|
12
|
-
expect(result).toContain("--css-var-colorSuccess:0, 255, 0;");
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("should generate css variables for color palettes", () => {
|
|
16
|
-
const tokens = {
|
|
17
|
-
red: "#ff0000",
|
|
18
|
-
"red-1": "#ff7875",
|
|
19
|
-
blue: "#1890ff",
|
|
20
|
-
"blue-5": "#096dd9",
|
|
21
|
-
} as any;
|
|
22
|
-
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
23
|
-
expect(result).toContain("--css-var-red:255, 0, 0;");
|
|
24
|
-
expect(result).toContain("--css-var-red-1:255, 120, 117;");
|
|
25
|
-
expect(result).toContain("--css-var-blue:24, 144, 255;");
|
|
26
|
-
expect(result).toContain("--css-var-blue-5:9, 109, 217;");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should ignore startWith rgb", () => {
|
|
30
|
-
const tokens = { colorText: "rgb(255, 255, 255)" } as any;
|
|
31
|
-
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
32
|
-
expect(result).toContain("--css-var-colorText:rgb(255, 255, 255);");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should generate CSS variables for fontSize, margin, and borderRadius tokens", () => {
|
|
36
|
-
const tokens = {
|
|
37
|
-
fontSize: 14,
|
|
38
|
-
margin: 8,
|
|
39
|
-
borderRadius: 6,
|
|
40
|
-
} as any;
|
|
41
|
-
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
42
|
-
expect(result).toContain("--css-var-fontSize:14px;");
|
|
43
|
-
expect(result).toContain("--css-var-margin:8px;");
|
|
44
|
-
expect(result).toContain("--css-var-borderRadius:6px;");
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { GlobalToken } from "antd";
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_CSS_VAR_PREFIX } from "../constants";
|
|
4
|
-
|
|
5
|
-
import { hexToRgb, isRGBColor } from "../utils";
|
|
6
|
-
import {
|
|
7
|
-
borderRadius,
|
|
8
|
-
colorPalettes,
|
|
9
|
-
fontSizes,
|
|
10
|
-
functionalColors,
|
|
11
|
-
margins,
|
|
12
|
-
semanticColors,
|
|
13
|
-
} from "../preset";
|
|
14
|
-
|
|
15
|
-
export function genCSSVarByTokens(
|
|
16
|
-
tokens: GlobalToken,
|
|
17
|
-
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX
|
|
18
|
-
) {
|
|
19
|
-
let colorsVariables = "";
|
|
20
|
-
|
|
21
|
-
for (const [key, value] of Object.entries(tokens)) {
|
|
22
|
-
// https://v3.tailwindcss.com/docs/customizing-colors#using-css-variables
|
|
23
|
-
if (colorPalettes.includes(key)) {
|
|
24
|
-
colorsVariables += `--${cssVarPrefix}-${key}:${hexToRgb(value)};`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (functionalColors.includes(key)) {
|
|
28
|
-
const rgb = hexToRgb(value);
|
|
29
|
-
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (semanticColors.includes(key)) {
|
|
34
|
-
const rgb = isRGBColor(value) ? value : `rgb(${hexToRgb(value)})`;
|
|
35
|
-
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (fontSizes.includes(key) || margins.includes(key) || borderRadius.includes(key)) {
|
|
40
|
-
colorsVariables += `--${cssVarPrefix}-${key}:${value}px;`;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return colorsVariables;
|
|
45
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createColorPalettes,
|
|
4
|
-
createFontSize,
|
|
5
|
-
createSpacing,
|
|
6
|
-
createBorderRadius,
|
|
7
|
-
} from "../core/genTailwindTheme";
|
|
8
|
-
import { colorPalettes } from "../preset";
|
|
9
|
-
|
|
10
|
-
describe("createColorPalettes", () => {
|
|
11
|
-
it("should create color palette variables with default prefix", () => {
|
|
12
|
-
const result = createColorPalettes();
|
|
13
|
-
|
|
14
|
-
expect(result["red"]).toBe("rgb(var(--a-red))");
|
|
15
|
-
expect(result["blue"]).toBe("rgb(var(--a-blue))");
|
|
16
|
-
expect(result["colorPrimary"]).toBe("rgb(var(--a-colorPrimary))");
|
|
17
|
-
expect(result["colorSuccess"]).toBe("rgb(var(--a-colorSuccess))");
|
|
18
|
-
expect(result["colorText"]).toBe("var(--a-colorText)");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should create color palette variables with custom cssVarPrefix", () => {
|
|
22
|
-
const result = createColorPalettes("custom");
|
|
23
|
-
|
|
24
|
-
expect(result["red"]).toBe("rgb(var(--custom-red))");
|
|
25
|
-
expect(result["blue"]).toBe("rgb(var(--custom-blue))");
|
|
26
|
-
expect(result["colorPrimary"]).toBe("rgb(var(--custom-colorPrimary))");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should create color palette variables with custom twPrefix", () => {
|
|
30
|
-
const result = createColorPalettes("a", "ant");
|
|
31
|
-
|
|
32
|
-
expect(result["ant-red"]).toBe("rgb(var(--a-red))");
|
|
33
|
-
expect(result["ant-blue"]).toBe("rgb(var(--a-blue))");
|
|
34
|
-
expect(result["ant-colorPrimary"]).toBe("rgb(var(--a-colorPrimary))");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should use rgb() wrapper for colorPalettes", () => {
|
|
38
|
-
const result = createColorPalettes();
|
|
39
|
-
colorPalettes.forEach((color) => {
|
|
40
|
-
expect(result[color]).toMatch(/^rgb\(var\(--a-[^)]+\)\)$/);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("createFontSize", () => {
|
|
46
|
-
it("should create font size variables with default prefix", () => {
|
|
47
|
-
const result = createFontSize();
|
|
48
|
-
|
|
49
|
-
expect(result["fontSizeSM"]).toBe("var(--a-fontSizeSM)");
|
|
50
|
-
expect(result["fontSize"]).toBe("var(--a-fontSize)");
|
|
51
|
-
expect(result["fontSizeLG"]).toBe("var(--a-fontSizeLG)");
|
|
52
|
-
expect(result["fontSizeXL"]).toBe("var(--a-fontSizeXL)");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should create font size variables with custom cssVarPrefix", () => {
|
|
56
|
-
const result = createFontSize("custom");
|
|
57
|
-
|
|
58
|
-
expect(result["fontSizeSM"]).toBe("var(--custom-fontSizeSM)");
|
|
59
|
-
expect(result["fontSize"]).toBe("var(--custom-fontSize)");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should create font size variables with custom twPrefix", () => {
|
|
63
|
-
const result = createFontSize("a", "ant");
|
|
64
|
-
|
|
65
|
-
expect(result["ant-fontSizeSM"]).toBe("var(--a-fontSizeSM)");
|
|
66
|
-
expect(result["ant-fontSize"]).toBe("var(--a-fontSize)");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should create all font size entries", () => {
|
|
70
|
-
const result = createFontSize();
|
|
71
|
-
expect(Object.keys(result).length).toBe(4);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe("createSpacing", () => {
|
|
76
|
-
it("should create spacing variables with default prefix", () => {
|
|
77
|
-
const result = createSpacing();
|
|
78
|
-
|
|
79
|
-
expect(result["marginXXS"]).toBe("var(--a-marginXXS)");
|
|
80
|
-
expect(result["marginXS"]).toBe("var(--a-marginXS)");
|
|
81
|
-
expect(result["marginSM"]).toBe("var(--a-marginSM)");
|
|
82
|
-
expect(result["margin"]).toBe("var(--a-margin)");
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe("createBorderRadius", () => {
|
|
87
|
-
it("should create border radius variables with default prefix", () => {
|
|
88
|
-
const result = createBorderRadius();
|
|
89
|
-
|
|
90
|
-
expect(result["borderRadiusXS"]).toBe("var(--a-borderRadiusXS)");
|
|
91
|
-
expect(result["borderRadiusSM"]).toBe("var(--a-borderRadiusSM)");
|
|
92
|
-
expect(result["borderRadius"]).toBe("var(--a-borderRadius)");
|
|
93
|
-
expect(result["borderRadiusLG"]).toBe("var(--a-borderRadiusLG)");
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_CSS_VAR_PREFIX } from "../constants";
|
|
2
|
-
import {
|
|
3
|
-
borderRadius,
|
|
4
|
-
fontSizes,
|
|
5
|
-
functionalColors,
|
|
6
|
-
margins,
|
|
7
|
-
semanticColors,
|
|
8
|
-
colorPalettes,
|
|
9
|
-
} from "../preset";
|
|
10
|
-
|
|
11
|
-
function genTwPrefixKey(key: string, prefix?: string) {
|
|
12
|
-
return prefix ? `${prefix}-${key}` : key;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createColorPalettes(
|
|
16
|
-
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX,
|
|
17
|
-
twPrefix?: string
|
|
18
|
-
) {
|
|
19
|
-
// eg: twPrefix='ant': bg-ant-colorPrimary --> background-color: var(--a-colorPrimary)
|
|
20
|
-
const colorPaletteVar: Record<string, string> = {};
|
|
21
|
-
|
|
22
|
-
colorPalettes.forEach((color) => {
|
|
23
|
-
colorPaletteVar[genTwPrefixKey(color, twPrefix)] = `rgb(var(--${cssVarPrefix}-${color}))`;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
functionalColors.forEach((key) => {
|
|
27
|
-
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `rgb(var(--${cssVarPrefix}-${key}))`;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
semanticColors.forEach((key) => {
|
|
31
|
-
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return colorPaletteVar;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function createFontSize(cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX, twPrefix?: string) {
|
|
38
|
-
const fontSizeVar: Record<string, string> = {};
|
|
39
|
-
fontSizes.forEach((key) => {
|
|
40
|
-
fontSizeVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
41
|
-
});
|
|
42
|
-
return fontSizeVar;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function createSpacing(cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX, twPrefix?: string) {
|
|
46
|
-
const spacingVar: Record<string, string> = {};
|
|
47
|
-
margins.forEach((key) => {
|
|
48
|
-
spacingVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
49
|
-
});
|
|
50
|
-
return spacingVar;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function createBorderRadius(
|
|
54
|
-
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX,
|
|
55
|
-
twPrefix?: string
|
|
56
|
-
) {
|
|
57
|
-
const radiusVar: Record<string, string> = {};
|
|
58
|
-
borderRadius.forEach((key) => {
|
|
59
|
-
radiusVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
60
|
-
});
|
|
61
|
-
return radiusVar;
|
|
62
|
-
}
|
package/src/plugin.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Config } from "tailwindcss";
|
|
2
|
-
// import type { PluginAPI } from "tailwindcss/plugin";
|
|
3
|
-
import plugin from "tailwindcss/plugin";
|
|
4
|
-
|
|
5
|
-
import { DEFAULT_CSS_VAR_PREFIX } from "./constants";
|
|
6
|
-
import {
|
|
7
|
-
createBorderRadius,
|
|
8
|
-
createColorPalettes,
|
|
9
|
-
createFontSize,
|
|
10
|
-
createSpacing,
|
|
11
|
-
} from "./core/genTailwindTheme";
|
|
12
|
-
|
|
13
|
-
interface PluginOptions {
|
|
14
|
-
/**
|
|
15
|
-
* @description tw class prefix
|
|
16
|
-
* @default '''
|
|
17
|
-
*/
|
|
18
|
-
twPrefix?: string;
|
|
19
|
-
/**
|
|
20
|
-
* @description css variables prefix
|
|
21
|
-
* @default 'a'
|
|
22
|
-
*/
|
|
23
|
-
cssVarPrefix?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// override private plugin interface
|
|
27
|
-
interface PluginWithOptions<T> {
|
|
28
|
-
(options?: T): {
|
|
29
|
-
handler: (api: any) => void;
|
|
30
|
-
};
|
|
31
|
-
__isOptionsFunction: true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @description 使用 Ant Design 的 Design Token 扩展 Tailwind CSS 类名,相关扩展有 color radius fontSize padding
|
|
36
|
-
* @example `bg-colorPrimary` --> `backgroundColor: token.colorPrimary`;
|
|
37
|
-
* @see https://ant-design.antgroup.com/docs/react/customize-theme-cn#seedtoken
|
|
38
|
-
* @see https://github.com/tailwindlabs/tailwindcss/discussions/13292#discussioncomment-14256365
|
|
39
|
-
*/
|
|
40
|
-
const twAntdPresetPlugin: PluginWithOptions<PluginOptions> = plugin.withOptions(
|
|
41
|
-
() => () => {
|
|
42
|
-
/* empty */
|
|
43
|
-
},
|
|
44
|
-
(options: PluginOptions = {}) => {
|
|
45
|
-
const { cssVarPrefix = DEFAULT_CSS_VAR_PREFIX, twPrefix = "" } = options;
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
theme: {
|
|
49
|
-
/**
|
|
50
|
-
* @see https://tailwindcss.com/docs/customizing-colors#using-css-variables
|
|
51
|
-
*/
|
|
52
|
-
extend: {
|
|
53
|
-
colors: {
|
|
54
|
-
...createColorPalettes(cssVarPrefix, twPrefix),
|
|
55
|
-
white: "rgb(255 255 255)",
|
|
56
|
-
black: "rgb(0 0 0)",
|
|
57
|
-
current: "currentColor",
|
|
58
|
-
inherit: "inherit",
|
|
59
|
-
transparent: "transparent",
|
|
60
|
-
},
|
|
61
|
-
fontSize: { ...createFontSize(cssVarPrefix, twPrefix) },
|
|
62
|
-
radius: { ...createBorderRadius(cssVarPrefix, twPrefix) }, // v4
|
|
63
|
-
borderRadius: { ...createBorderRadius(cssVarPrefix, twPrefix) }, // v3
|
|
64
|
-
spacing: { ...createSpacing(cssVarPrefix, twPrefix) },
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
} satisfies Partial<Config>;
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
export default twAntdPresetPlugin;
|
package/src/preset/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { functionalColors } from "./tokens/functionalColors";
|
|
2
|
-
import { colorPalettes } from "./tokens/colorPalettes";
|
|
3
|
-
import { semanticColors } from "./tokens/semanticColors";
|
|
4
|
-
|
|
5
|
-
export { margins } from "./tokens/margins";
|
|
6
|
-
export { fontSizes } from "./tokens/fontSizes";
|
|
7
|
-
export { borderRadius } from "./tokens/borderRadius";
|
|
8
|
-
|
|
9
|
-
export { functionalColors };
|
|
10
|
-
export { colorPalettes };
|
|
11
|
-
export { semanticColors };
|
|
12
|
-
|
|
13
|
-
export const colorPresets = [...colorPalettes, ...functionalColors, ...semanticColors];
|