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.
Files changed (58) hide show
  1. package/README.en-US.md +38 -39
  2. package/README.md +40 -41
  3. package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/defineProperty.js +12 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/objectSpread2.js +25 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/toPrimitive.js +14 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/toPropertyKey.js +9 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.129.0/helpers/typeof.js +11 -0
  8. package/dist/components.d.ts +7 -0
  9. package/dist/components.js +23 -0
  10. package/dist/core/genCssVarByTokens.js +48 -0
  11. package/dist/core/genTailwindTheme.js +46 -0
  12. package/dist/plugin.d.ts +28 -0
  13. package/dist/plugin.js +28 -0
  14. package/dist/preset/tokens/borderRadius.d.ts +6 -0
  15. package/dist/preset/tokens/borderRadius.js +9 -0
  16. package/dist/preset/tokens/colorPalettes.d.ts +11 -0
  17. package/dist/preset/tokens/colorPalettes.js +23 -0
  18. package/dist/preset/tokens/fontSizes.d.ts +6 -0
  19. package/dist/preset/tokens/fontSizes.js +9 -0
  20. package/dist/preset/tokens/functionalColors.d.ts +6 -0
  21. package/dist/preset/tokens/functionalColors.js +70 -0
  22. package/dist/preset/tokens/margins.d.ts +6 -0
  23. package/dist/preset/tokens/margins.js +13 -0
  24. package/dist/preset/tokens/semanticColors.d.ts +6 -0
  25. package/dist/preset/tokens/semanticColors.js +26 -0
  26. package/dist/preset.d.ts +11 -0
  27. package/dist/preset.js +14 -0
  28. package/dist/utils/index.js +11 -0
  29. package/dist/utils/type.d.ts +6 -0
  30. package/package.json +23 -6
  31. package/.github/workflows/gh-pages.yml +0 -49
  32. package/.vscode/settings.json +0 -25
  33. package/oxfmt.config.ts +0 -22
  34. package/oxlint.config.ts +0 -6
  35. package/playground/index.html +0 -12
  36. package/playground/src/App.tsx +0 -226
  37. package/playground/src/global.css +0 -4
  38. package/playground/src/index.tsx +0 -15
  39. package/src/components.test.tsx +0 -56
  40. package/src/components.tsx +0 -33
  41. package/src/constants/index.ts +0 -1
  42. package/src/core/genCssVarByToken.test.ts +0 -46
  43. package/src/core/genCssVarByTokens.ts +0 -45
  44. package/src/core/genTailwindTheme.test.ts +0 -95
  45. package/src/core/genTailwindTheme.ts +0 -62
  46. package/src/plugin.ts +0 -71
  47. package/src/preset/index.ts +0 -13
  48. package/src/preset/tokens/borderRadius.ts +0 -6
  49. package/src/preset/tokens/colorPalettes.ts +0 -24
  50. package/src/preset/tokens/fontSizes.ts +0 -6
  51. package/src/preset/tokens/functionalColors.ts +0 -72
  52. package/src/preset/tokens/margins.ts +0 -11
  53. package/src/preset/tokens/semanticColors.ts +0 -29
  54. package/src/utils/index.ts +0 -10
  55. package/tsconfig.json +0 -21
  56. package/tsdown.config.ts +0 -14
  57. package/vite.config.ts +0 -23
  58. package/vitest.setup.ts +0 -11
package/README.en-US.md CHANGED
@@ -1,13 +1,10 @@
1
- A tailwindcss plugin based on antd Design Token.
1
+ Use antd design token like using tailwindcss.
2
2
 
3
- English | [简体中文](./README.zh-CN.md)
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
- # Project Introduction
6
-
7
- Version requirements:
5
+ [简体中文](./README.md) | English
8
6
 
9
- - antd >= 5
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 v3
31
+ ### tailwindcss v4
35
32
 
36
- 1. Register tailwind plugin
33
+ Use plugin in your css
37
34
 
38
- ```js
39
- // tailwind.config.ts
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
- export default config;
38
+ /* or
39
+ @plugin "tailwind-preset-antd/plugin" {
40
+ twPrefix: "ant";
41
+ cssVarPrefix: "abcd";
42
+ }
43
+ */
50
44
  ```
51
45
 
52
- 2. Register global css variables based on antd token
46
+ Inject css variables component in any component
53
47
 
54
- ```jsx
55
- import { AntdTokenCssVar } from "tailwind-preset-antd/components";
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
- If you use the `tailwind-merge` plugin, you need to add `fontSizes` to its configuration. See [Using with tailwind-merge](#using-with-tailwind-merge) for details
60
+ ### tailwindcss v3
67
61
 
68
- ### tailwindcss v4
62
+ Use plugin in your `tailwind.config.ts`
69
63
 
70
- See [How can I pass parameters to a TailwindCSS plugin in a CSS-first configuration?](https://github.com/tailwindlabs/tailwindcss/discussions/15997)
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
- ```css
73
- @plugin "tailwind-preset-antd/plugin";
69
+ const config: Config = {
70
+ // ...
71
+ // or custom plugins config: [tailwindPresetAntd({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
72
+ plugins: [tailwindPresetAntd],
73
+ };
74
74
 
75
- /* or
76
- @plugin "tailwind-preset-antd/plugin" {
77
- twPrefix: "ant";
78
- cssVarPrefix: "abcd";
79
- }
80
- */
75
+ export default config;
81
76
  ```
82
77
 
83
- ```jsx
84
- import { AntdTokenCssVar } from "tailwind-preset-antd/components";
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
- ```jsx
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(--a-colorPrimary)); }
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
- 基于 Antd Design Token 的 tailwindcss 插件。
1
+ 像使用 tailwindcss 一样使用 antd design token。
2
2
 
3
- [English](./README.md) | 简体中文
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
- - antd >= 5
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 { cssVar } = theme.useToken(); // antd v6
15
+ const { token } = theme.useToken();
19
16
 
20
- return <div style={{ backgroundColor: cssVar.colorPrimary }}></div>;
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 v3
31
+ ### tailwindcss v4
35
32
 
36
- 1. 注册 tailwind 插件
33
+ 在你的 css 中使用插件
37
34
 
38
- ```js
39
- // tailwind.config.ts
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
- export default config;
38
+ /* or
39
+ @plugin "tailwind-preset-antd/plugin" {
40
+ twPrefix: "ant";
41
+ cssVarPrefix: "abcd";
42
+ }
43
+ */
50
44
  ```
51
45
 
52
- 2. 注册基于 antd token 的全局 css 变量
46
+ 在你的任意组件中注入 css 变量的组件
53
47
 
54
- ```jsx
55
- import { AntdTokenCssVar } from "tailwind-preset-antd/components";
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
- 如果使用了 `tailwind-merge` 插件,则需要将 `fontSizes` 添加至其配置中,具体使用见 [与 tailwind-merge 配合使用](#与-tailwind-merge-配合使用)
60
+ ### tailwindcss v3
67
61
 
68
- ### tailwindcss v4
62
+ 在你的 `tailwind.config.ts` 中使用插件
69
63
 
70
- 查看 [How can I pass parameters to a TailwindCSS plugin in a CSS-first configuration?](https://github.com/tailwindlabs/tailwindcss/discussions/15997)
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
- ```css
73
- @plugin "tailwind-preset-antd/plugin";
69
+ const config: Config = {
70
+ // ...
71
+ // or custom plugins config: [tailwindPresetAntd({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
72
+ plugins: [tailwindPresetAntd],
73
+ };
74
74
 
75
- /* or
76
- @plugin "tailwind-preset-antd/plugin" {
77
- twPrefix: "ant";
78
- cssVarPrefix: "abcd";
79
- }
80
- */
75
+ export default config;
81
76
  ```
82
77
 
83
- ```jsx
84
- import { AntdTokenCssVar } from "tailwind-preset-antd/components";
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
- ```jsx
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(--a-colorPrimary)); }
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,7 @@
1
+ //#region src/components.d.ts
2
+ interface AntdTokenCssVarProps {
3
+ cssVarPrefix?: string;
4
+ }
5
+ declare function AntdTokenCssVar(props: AntdTokenCssVarProps): null;
6
+ //#endregion
7
+ export { AntdTokenCssVar as default };
@@ -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 };
@@ -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,6 @@
1
+ import { AliasTokenKey } from "../../utils/type.js";
2
+
3
+ //#region src/preset/tokens/borderRadius.d.ts
4
+ declare const borderRadius: AliasTokenKey[];
5
+ //#endregion
6
+ export { borderRadius };
@@ -0,0 +1,9 @@
1
+ //#region src/preset/tokens/borderRadius.ts
2
+ const borderRadius = [
3
+ "borderRadiusXS",
4
+ "borderRadiusSM",
5
+ "borderRadius",
6
+ "borderRadiusLG"
7
+ ];
8
+ //#endregion
9
+ export { borderRadius };
@@ -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 };
@@ -0,0 +1,6 @@
1
+ import { AliasTokenKey } from "../../utils/type.js";
2
+
3
+ //#region src/preset/tokens/fontSizes.d.ts
4
+ declare const fontSizes: AliasTokenKey[];
5
+ //#endregion
6
+ export { fontSizes };
@@ -0,0 +1,9 @@
1
+ //#region src/preset/tokens/fontSizes.ts
2
+ const fontSizes = [
3
+ "fontSizeSM",
4
+ "fontSize",
5
+ "fontSizeLG",
6
+ "fontSizeXL"
7
+ ];
8
+ //#endregion
9
+ export { fontSizes };
@@ -0,0 +1,6 @@
1
+ import { AliasTokenKey } from "../../utils/type.js";
2
+
3
+ //#region src/preset/tokens/functionalColors.d.ts
4
+ declare const functionalColors: AliasTokenKey[];
5
+ //#endregion
6
+ export { functionalColors };