tailwind-preset-antd 0.0.1 → 0.1.0
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/README.en-US.md +38 -39
- package/README.md +40 -41
- package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/defineProperty.js +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/objectSpread2.js +25 -0
- package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/toPrimitive.js +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/toPropertyKey.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/typeof.js +11 -0
- package/dist/components.d.ts +7 -0
- package/dist/components.js +23 -0
- package/dist/core/genCssVarByTokens.js +48 -0
- package/dist/core/genTailwindTheme.js +46 -0
- package/dist/plugin.d.ts +28 -0
- package/dist/plugin.js +28 -0
- package/dist/preset/tokens/borderRadius.d.ts +6 -0
- package/dist/preset/tokens/borderRadius.js +9 -0
- package/dist/preset/tokens/colorPalettes.d.ts +11 -0
- package/dist/preset/tokens/colorPalettes.js +23 -0
- package/dist/preset/tokens/fontSizes.d.ts +6 -0
- package/dist/preset/tokens/fontSizes.js +9 -0
- package/dist/preset/tokens/functionalColors.d.ts +6 -0
- package/dist/preset/tokens/functionalColors.js +70 -0
- package/dist/preset/tokens/margins.d.ts +6 -0
- package/dist/preset/tokens/margins.js +13 -0
- package/dist/preset/tokens/semanticColors.d.ts +6 -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/dist/utils/type.d.ts +6 -0
- package/package.json +23 -6
- 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/README.en-US.md
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
Use antd design token like using tailwindcss.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provides common antd design token easier to use. Recommended to use antd v6 and tailwindcss v4, but also supports antd v5 and tailwindcss v3.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Version requirements:
|
|
5
|
+
[简体中文](./README.md) | English
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
- tailwindcss >= 3
|
|
7
|
+
# Project Introduction
|
|
11
8
|
|
|
12
9
|
Before:
|
|
13
10
|
|
|
@@ -31,28 +28,25 @@ function App() {
|
|
|
31
28
|
|
|
32
29
|
## Basic Usage
|
|
33
30
|
|
|
34
|
-
### tailwindcss
|
|
31
|
+
### tailwindcss v4
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
Use plugin in your css
|
|
37
34
|
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
import type { Config } from "tailwindcss/types/config";
|
|
41
|
-
import antdThemePreset from "tailwind-preset-antd/plugin";
|
|
42
|
-
|
|
43
|
-
const config: Config = {
|
|
44
|
-
// ...
|
|
45
|
-
// or custom plugins config: [antdThemePreset({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
|
|
46
|
-
plugins: [antdThemePreset],
|
|
47
|
-
};
|
|
35
|
+
```css
|
|
36
|
+
@plugin "tailwind-preset-antd/plugin";
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
/* or
|
|
39
|
+
@plugin "tailwind-preset-antd/plugin" {
|
|
40
|
+
twPrefix: "ant";
|
|
41
|
+
cssVarPrefix: "abcd";
|
|
42
|
+
}
|
|
43
|
+
*/
|
|
50
44
|
```
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
Inject css variables component in any component
|
|
53
47
|
|
|
54
|
-
```
|
|
55
|
-
import
|
|
48
|
+
```tsx
|
|
49
|
+
import AntdTokenCssVar from "tailwind-preset-antd/components";
|
|
56
50
|
|
|
57
51
|
export default function App() {
|
|
58
52
|
return (
|
|
@@ -63,25 +57,28 @@ export default function App() {
|
|
|
63
57
|
}
|
|
64
58
|
```
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
### tailwindcss v3
|
|
67
61
|
|
|
68
|
-
|
|
62
|
+
Use plugin in your `tailwind.config.ts`
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
```ts
|
|
65
|
+
// tailwind.config.ts
|
|
66
|
+
import type { Config } from "tailwindcss/types/config";
|
|
67
|
+
import tailwindPresetAntd from "tailwind-preset-antd/plugin";
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const config: Config = {
|
|
70
|
+
// ...
|
|
71
|
+
// or custom plugins config: [tailwindPresetAntd({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
|
|
72
|
+
plugins: [tailwindPresetAntd],
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
@plugin "tailwind-preset-antd/plugin" {
|
|
77
|
-
twPrefix: "ant";
|
|
78
|
-
cssVarPrefix: "abcd";
|
|
79
|
-
}
|
|
80
|
-
*/
|
|
75
|
+
export default config;
|
|
81
76
|
```
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
Inject css variables component in any component
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import AntdTokenCssVar from "tailwind-preset-antd/components";
|
|
85
82
|
|
|
86
83
|
export default function App() {
|
|
87
84
|
return (
|
|
@@ -92,14 +89,16 @@ export default function App() {
|
|
|
92
89
|
}
|
|
93
90
|
```
|
|
94
91
|
|
|
92
|
+
If you use the `tailwind-merge` plugin, additional configuration is required. See [Using with tailwind-merge](#using-with-tailwind-merge) for details
|
|
93
|
+
|
|
95
94
|
## Configuration Options
|
|
96
95
|
|
|
97
96
|
- `twPrefix`: tw class name prefix, default is `''`
|
|
98
|
-
- `cssVarPrefix`: Generated css var variable prefix, default is `'a'`
|
|
97
|
+
- `cssVarPrefix`: Generated css var variable prefix, default is `'a'` (you must also set `AntdTokenCssVar`'s `cssVarPrefix`)
|
|
99
98
|
|
|
100
99
|
For example: when `twPrefix` is `ant` and `cssVarPrefix` is `abcd`, the generated css var variable and style are as follows:
|
|
101
100
|
|
|
102
|
-
```
|
|
101
|
+
```tsx
|
|
103
102
|
/**
|
|
104
103
|
* :root{
|
|
105
104
|
* --abcd-colorPrimary: 47 84 235;
|
|
@@ -109,7 +108,7 @@ function App() {
|
|
|
109
108
|
return <div className="bg-ant-colorPrimary"></div>;
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
// Generated css: .bg-ant-colorPrimary { background-color: rgb(var(--
|
|
111
|
+
// Generated css: .bg-ant-colorPrimary { background-color: rgb(var(--abcd-colorPrimary)); }
|
|
113
112
|
```
|
|
114
113
|
|
|
115
114
|
### Using with tailwind-merge
|
package/README.md
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
像使用 tailwindcss 一样使用 antd design token。
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
提供常用 antd design token 更易于使用。推荐使用 antd v6 和 tailwindcss v4,但同样支持 antd v5 和 tailwindcss v3。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
版本要求:
|
|
5
|
+
[English](./README.en-US.md) | 简体中文
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
- tailwindcss >= 3
|
|
7
|
+
# 项目介绍
|
|
11
8
|
|
|
12
9
|
以前:
|
|
13
10
|
|
|
@@ -15,9 +12,9 @@
|
|
|
15
12
|
import { theme } from "antd";
|
|
16
13
|
|
|
17
14
|
function App() {
|
|
18
|
-
const {
|
|
15
|
+
const { token } = theme.useToken();
|
|
19
16
|
|
|
20
|
-
return <div style={{ backgroundColor:
|
|
17
|
+
return <div style={{ backgroundColor: token.colorPrimary }}></div>;
|
|
21
18
|
}
|
|
22
19
|
```
|
|
23
20
|
|
|
@@ -31,28 +28,25 @@ function App() {
|
|
|
31
28
|
|
|
32
29
|
## 基础使用
|
|
33
30
|
|
|
34
|
-
### tailwindcss
|
|
31
|
+
### tailwindcss v4
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
在你的 css 中使用插件
|
|
37
34
|
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
import type { Config } from "tailwindcss/types/config";
|
|
41
|
-
import antdThemePreset from "tailwind-preset-antd/plugin";
|
|
42
|
-
|
|
43
|
-
const config: Config = {
|
|
44
|
-
// ...
|
|
45
|
-
// or custom plugins config: [antdThemePreset({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
|
|
46
|
-
plugins: [antdThemePreset],
|
|
47
|
-
};
|
|
35
|
+
```css
|
|
36
|
+
@plugin "tailwind-preset-antd/plugin";
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
/* or
|
|
39
|
+
@plugin "tailwind-preset-antd/plugin" {
|
|
40
|
+
twPrefix: "ant";
|
|
41
|
+
cssVarPrefix: "abcd";
|
|
42
|
+
}
|
|
43
|
+
*/
|
|
50
44
|
```
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
在你的任意组件中注入 css 变量的组件
|
|
53
47
|
|
|
54
|
-
```
|
|
55
|
-
import
|
|
48
|
+
```tsx
|
|
49
|
+
import AntdTokenCssVar from "tailwind-preset-antd/components";
|
|
56
50
|
|
|
57
51
|
export default function App() {
|
|
58
52
|
return (
|
|
@@ -63,25 +57,28 @@ export default function App() {
|
|
|
63
57
|
}
|
|
64
58
|
```
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
### tailwindcss v3
|
|
67
61
|
|
|
68
|
-
|
|
62
|
+
在你的 `tailwind.config.ts` 中使用插件
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
```js
|
|
65
|
+
// tailwind.config.ts
|
|
66
|
+
import type { Config } from "tailwindcss/types/config";
|
|
67
|
+
import tailwindPresetAntd from "tailwind-preset-antd/plugin";
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const config: Config = {
|
|
70
|
+
// ...
|
|
71
|
+
// or custom plugins config: [tailwindPresetAntd({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
|
|
72
|
+
plugins: [tailwindPresetAntd],
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
@plugin "tailwind-preset-antd/plugin" {
|
|
77
|
-
twPrefix: "ant";
|
|
78
|
-
cssVarPrefix: "abcd";
|
|
79
|
-
}
|
|
80
|
-
*/
|
|
75
|
+
export default config;
|
|
81
76
|
```
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
在你的任意组件中注入 css 变量的组件
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import AntdTokenCssVar from "tailwind-preset-antd/components";
|
|
85
82
|
|
|
86
83
|
export default function App() {
|
|
87
84
|
return (
|
|
@@ -92,14 +89,16 @@ export default function App() {
|
|
|
92
89
|
}
|
|
93
90
|
```
|
|
94
91
|
|
|
92
|
+
如果使用了 `tailwind-merge` 插件,则需要进行额外配置,具体使用见 [与 tailwind-merge 配合使用](#与-tailwind-merge-配合使用)
|
|
93
|
+
|
|
95
94
|
## 配置项
|
|
96
95
|
|
|
97
96
|
- `twPrefix`: tw 类名前缀,默认为 `''`
|
|
98
|
-
- `cssVarPrefix`: 生成的 css var 变量前缀,默认为 `'a'`
|
|
97
|
+
- `cssVarPrefix`: 生成的 css var 变量前缀,默认为 `'a'`(你必须同时设置 `AntdTokenCssVar` 的 `cssVarPrefix`)
|
|
99
98
|
|
|
100
99
|
例如:当 twPrefix 为 `ant` 时,`cssVarPrefix` 为 `abcd` 时,生成的 css var 变量及样式如下:
|
|
101
100
|
|
|
102
|
-
```
|
|
101
|
+
```tsx
|
|
103
102
|
/**
|
|
104
103
|
* :root{
|
|
105
104
|
* --abcd-colorPrimary: 47 84 235;
|
|
@@ -109,7 +108,7 @@ function App() {
|
|
|
109
108
|
return <div className="bg-ant-colorPrimary"></div>;
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
// 生成的 css: .bg-ant-colorPrimary { background-color: rgb(var(--
|
|
111
|
+
// 生成的 css: .bg-ant-colorPrimary { background-color: rgb(var(--abcd-colorPrimary)); }
|
|
113
112
|
```
|
|
114
113
|
|
|
115
114
|
### 与 tailwind-merge 配合使用
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toPropertyKey } from "./toPropertyKey.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
3
|
+
function _defineProperty(e, r, t) {
|
|
4
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
5
|
+
value: t,
|
|
6
|
+
enumerable: !0,
|
|
7
|
+
configurable: !0,
|
|
8
|
+
writable: !0
|
|
9
|
+
}) : e[r] = t, e;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { _defineProperty };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { _defineProperty } from "./defineProperty.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
|
|
3
|
+
function ownKeys(e, r) {
|
|
4
|
+
var t = Object.keys(e);
|
|
5
|
+
if (Object.getOwnPropertySymbols) {
|
|
6
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
7
|
+
r && (o = o.filter(function(r) {
|
|
8
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
9
|
+
})), t.push.apply(t, o);
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
13
|
+
function _objectSpread2(e) {
|
|
14
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
15
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
16
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
17
|
+
_defineProperty(e, r, t[r]);
|
|
18
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
19
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { _objectSpread2 };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { _typeof } from "./typeof.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
3
|
+
function toPrimitive(t, r) {
|
|
4
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
5
|
+
var e = t[Symbol.toPrimitive];
|
|
6
|
+
if (void 0 !== e) {
|
|
7
|
+
var i = e.call(t, r || "default");
|
|
8
|
+
if ("object" != _typeof(i)) return i;
|
|
9
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
10
|
+
}
|
|
11
|
+
return ("string" === r ? String : Number)(t);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { toPrimitive };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { _typeof } from "./typeof.js";
|
|
2
|
+
import { toPrimitive } from "./toPrimitive.js";
|
|
3
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
4
|
+
function toPropertyKey(t) {
|
|
5
|
+
var i = toPrimitive(t, "string");
|
|
6
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { toPropertyKey };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
2
|
+
function _typeof(o) {
|
|
3
|
+
"@babel/helpers - typeof";
|
|
4
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
5
|
+
return typeof o;
|
|
6
|
+
} : function(o) {
|
|
7
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
8
|
+
}, _typeof(o);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { _typeof };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { genCSSVarByTokens } from "./core/genCssVarByTokens.js";
|
|
2
|
+
import { theme } from "antd";
|
|
3
|
+
import { useInsertionEffect } from "react";
|
|
4
|
+
//#region src/components.tsx
|
|
5
|
+
const styleId = "antd-token-inject";
|
|
6
|
+
function AntdTokenCssVar(props) {
|
|
7
|
+
const { cssVarPrefix } = props;
|
|
8
|
+
const { token } = theme.useToken();
|
|
9
|
+
useInsertionEffect(() => {
|
|
10
|
+
const cssVar = genCSSVarByTokens(token, cssVarPrefix);
|
|
11
|
+
const style = document.querySelector(`#${styleId}`) || document.createElement("style");
|
|
12
|
+
style.id = styleId;
|
|
13
|
+
style.setAttribute("plugin-name", "tailwind-preset-antd");
|
|
14
|
+
style.textContent = `:root{${cssVar}}`;
|
|
15
|
+
document.head.appendChild(style);
|
|
16
|
+
return () => {
|
|
17
|
+
document.head.removeChild(style);
|
|
18
|
+
};
|
|
19
|
+
}, [token, cssVarPrefix]);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { AntdTokenCssVar as default };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { hexToRgb, isRGBColor } from "../utils/index.js";
|
|
2
|
+
import { functionalColors } from "../preset/tokens/functionalColors.js";
|
|
3
|
+
import { colorPalettes } from "../preset/tokens/colorPalettes.js";
|
|
4
|
+
import { semanticColors } from "../preset/tokens/semanticColors.js";
|
|
5
|
+
import { margins } from "../preset/tokens/margins.js";
|
|
6
|
+
import { fontSizes } from "../preset/tokens/fontSizes.js";
|
|
7
|
+
import { borderRadius } from "../preset/tokens/borderRadius.js";
|
|
8
|
+
//#region src/core/genCssVarByTokens.ts
|
|
9
|
+
function genCSSVarByTokens(tokens, cssVarPrefix = "a") {
|
|
10
|
+
let colorsVariables = "";
|
|
11
|
+
const presetTokens = [
|
|
12
|
+
...colorPalettes,
|
|
13
|
+
...functionalColors,
|
|
14
|
+
...semanticColors,
|
|
15
|
+
...margins,
|
|
16
|
+
...borderRadius,
|
|
17
|
+
...fontSizes
|
|
18
|
+
];
|
|
19
|
+
for (let i = 0; i < presetTokens.length; i++) {
|
|
20
|
+
const key = presetTokens[i];
|
|
21
|
+
const value = tokens[key];
|
|
22
|
+
if (value === void 0 && process.env.NODE_ENV !== "production") {
|
|
23
|
+
console.warn(`[tailwind-preset-antd]: ${key} is not defined in antd design token`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (colorPalettes.includes(key)) {
|
|
27
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${hexToRgb(value)};`;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (functionalColors.includes(key)) {
|
|
31
|
+
const rgb = hexToRgb(value);
|
|
32
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (semanticColors.includes(key)) {
|
|
36
|
+
const rgb = isRGBColor(value) ? value : `rgb(${hexToRgb(value)})`;
|
|
37
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (fontSizes.includes(key) || margins.includes(key) || borderRadius.includes(key)) {
|
|
41
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${value}px;`;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return colorsVariables;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { genCSSVarByTokens };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { functionalColors } from "../preset/tokens/functionalColors.js";
|
|
2
|
+
import { colorPalettes } from "../preset/tokens/colorPalettes.js";
|
|
3
|
+
import { semanticColors } from "../preset/tokens/semanticColors.js";
|
|
4
|
+
import { margins } from "../preset/tokens/margins.js";
|
|
5
|
+
import { fontSizes } from "../preset/tokens/fontSizes.js";
|
|
6
|
+
import { borderRadius } from "../preset/tokens/borderRadius.js";
|
|
7
|
+
//#region src/core/genTailwindTheme.ts
|
|
8
|
+
function genTwPrefixKey(key, prefix) {
|
|
9
|
+
return prefix ? `${prefix}-${key}` : key;
|
|
10
|
+
}
|
|
11
|
+
function createColorPalettes(cssVarPrefix = "a", twPrefix) {
|
|
12
|
+
const colorPaletteVar = {};
|
|
13
|
+
colorPalettes.forEach((color) => {
|
|
14
|
+
colorPaletteVar[genTwPrefixKey(color, twPrefix)] = `rgb(var(--${cssVarPrefix}-${color}))`;
|
|
15
|
+
});
|
|
16
|
+
functionalColors.forEach((key) => {
|
|
17
|
+
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `rgb(var(--${cssVarPrefix}-${key}))`;
|
|
18
|
+
});
|
|
19
|
+
semanticColors.forEach((key) => {
|
|
20
|
+
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
21
|
+
});
|
|
22
|
+
return colorPaletteVar;
|
|
23
|
+
}
|
|
24
|
+
function createFontSize(cssVarPrefix = "a", twPrefix) {
|
|
25
|
+
const fontSizeVar = {};
|
|
26
|
+
fontSizes.forEach((key) => {
|
|
27
|
+
fontSizeVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
28
|
+
});
|
|
29
|
+
return fontSizeVar;
|
|
30
|
+
}
|
|
31
|
+
function createSpacing(cssVarPrefix = "a", twPrefix) {
|
|
32
|
+
const spacingVar = {};
|
|
33
|
+
margins.forEach((key) => {
|
|
34
|
+
spacingVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
35
|
+
});
|
|
36
|
+
return spacingVar;
|
|
37
|
+
}
|
|
38
|
+
function createBorderRadius(cssVarPrefix = "a", twPrefix) {
|
|
39
|
+
const radiusVar = {};
|
|
40
|
+
borderRadius.forEach((key) => {
|
|
41
|
+
radiusVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
42
|
+
});
|
|
43
|
+
return radiusVar;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createBorderRadius, createColorPalettes, createFontSize, createSpacing };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/plugin.d.ts
|
|
2
|
+
interface PluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* @description tw class prefix
|
|
5
|
+
* @default '''
|
|
6
|
+
*/
|
|
7
|
+
twPrefix?: string;
|
|
8
|
+
/**
|
|
9
|
+
* @description css variables prefix
|
|
10
|
+
* @default 'a'
|
|
11
|
+
*/
|
|
12
|
+
cssVarPrefix?: string;
|
|
13
|
+
}
|
|
14
|
+
interface PluginWithOptions<T> {
|
|
15
|
+
(options?: T): {
|
|
16
|
+
handler: (api: any) => void;
|
|
17
|
+
};
|
|
18
|
+
__isOptionsFunction: true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @description Based on Antd Design Token to customize TailwindCSS styles, related extensions include `color`, `borderRadius`, `fontSize`, and `margin(gap)`.
|
|
22
|
+
* @example `bg-colorPrimary` --> `backgroundColor: token.colorPrimary`;
|
|
23
|
+
* @see https://ant.design/docs/react/customize-theme-cn#maptoken
|
|
24
|
+
* @see https://github.com/tailwindlabs/tailwindcss/discussions/13292#discussioncomment-14256365
|
|
25
|
+
*/
|
|
26
|
+
declare const twAntdPresetPlugin: PluginWithOptions<PluginOptions>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { twAntdPresetPlugin as default };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createBorderRadius, createColorPalettes, createFontSize, createSpacing } from "./core/genTailwindTheme.js";
|
|
2
|
+
import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.129.0/helpers/objectSpread2.js";
|
|
3
|
+
import plugin from "tailwindcss/plugin";
|
|
4
|
+
//#region src/plugin.ts
|
|
5
|
+
/**
|
|
6
|
+
* @description Based on Antd Design Token to customize TailwindCSS styles, related extensions include `color`, `borderRadius`, `fontSize`, and `margin(gap)`.
|
|
7
|
+
* @example `bg-colorPrimary` --> `backgroundColor: token.colorPrimary`;
|
|
8
|
+
* @see https://ant.design/docs/react/customize-theme-cn#maptoken
|
|
9
|
+
* @see https://github.com/tailwindlabs/tailwindcss/discussions/13292#discussioncomment-14256365
|
|
10
|
+
*/
|
|
11
|
+
const twAntdPresetPlugin = plugin.withOptions(() => () => {}, (options = {}) => {
|
|
12
|
+
const { cssVarPrefix = "a", twPrefix = "" } = options;
|
|
13
|
+
return { theme: { extend: {
|
|
14
|
+
colors: _objectSpread2(_objectSpread2({}, createColorPalettes(cssVarPrefix, twPrefix)), {}, {
|
|
15
|
+
white: "rgb(255 255 255)",
|
|
16
|
+
black: "rgb(0 0 0)",
|
|
17
|
+
current: "currentColor",
|
|
18
|
+
inherit: "inherit",
|
|
19
|
+
transparent: "transparent"
|
|
20
|
+
}),
|
|
21
|
+
fontSize: _objectSpread2({}, createFontSize(cssVarPrefix, twPrefix)),
|
|
22
|
+
radius: _objectSpread2({}, createBorderRadius(cssVarPrefix, twPrefix)),
|
|
23
|
+
borderRadius: _objectSpread2({}, createBorderRadius(cssVarPrefix, twPrefix)),
|
|
24
|
+
spacing: _objectSpread2({}, createSpacing(cssVarPrefix, twPrefix))
|
|
25
|
+
} } };
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { twAntdPresetPlugin as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PresetColorKey } from "antd/es/theme/internal.js";
|
|
2
|
+
import { ColorPalettes, LegacyColorPalettes } from "antd/es/theme/interface/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/preset/tokens/colorPalettes.d.ts
|
|
5
|
+
type PresetColorPalettes = ColorPalettes & PresetColorKey & LegacyColorPalettes;
|
|
6
|
+
/**
|
|
7
|
+
* `['red', 'red1', 'red2', ……, 'red10', 'magenta',……]`
|
|
8
|
+
*/
|
|
9
|
+
declare const colorPalettes: PresetColorPalettes[];
|
|
10
|
+
//#endregion
|
|
11
|
+
export { colorPalettes };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `['red', 'red1', 'red2', ……, 'red10', 'magenta',……]`
|
|
3
|
+
*/
|
|
4
|
+
const colorPalettes = [
|
|
5
|
+
"red",
|
|
6
|
+
"volcano",
|
|
7
|
+
"orange",
|
|
8
|
+
"lime",
|
|
9
|
+
"gold",
|
|
10
|
+
"yellow",
|
|
11
|
+
"green",
|
|
12
|
+
"cyan",
|
|
13
|
+
"blue",
|
|
14
|
+
"geekblue",
|
|
15
|
+
"purple",
|
|
16
|
+
"magenta"
|
|
17
|
+
].flatMap((color) => [
|
|
18
|
+
color,
|
|
19
|
+
...Array.from({ length: 10 }, (_, i) => `${color}${i + 1}`),
|
|
20
|
+
...Array.from({ length: 10 }, (_, i) => `${color}-${i + 1}`)
|
|
21
|
+
]);
|
|
22
|
+
//#endregion
|
|
23
|
+
export { colorPalettes };
|