css2class 2.0.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/API.md +1143 -0
- package/CHANGELOG.md +291 -0
- package/CONFIG.md +1096 -0
- package/CONTRIBUTING.md +571 -0
- package/MIGRATION.md +402 -0
- package/README.md +634 -0
- package/bin/class2css.js +380 -0
- package/class2css.config.js +124 -0
- package/common.css +3 -0
- package/configs/colors.config.js +62 -0
- package/configs/layout.config.js +110 -0
- package/configs/spacing.config.js +37 -0
- package/configs/typography.config.js +41 -0
- package/docs/.vitepress/config.mjs +65 -0
- package/docs/.vitepress/theme/custom.css +74 -0
- package/docs/.vitepress/theme/index.js +7 -0
- package/docs/guide/cli.md +97 -0
- package/docs/guide/concepts.md +63 -0
- package/docs/guide/config-template.md +365 -0
- package/docs/guide/config.md +275 -0
- package/docs/guide/faq.md +202 -0
- package/docs/guide/getting-started.md +83 -0
- package/docs/guide/important-and-static.md +67 -0
- package/docs/guide/incremental.md +162 -0
- package/docs/guide/rules-reference.md +354 -0
- package/docs/guide/units.md +57 -0
- package/docs/index.md +68 -0
- package/package.json +49 -0
- package/run.js +90 -0
- package/src/README.md +571 -0
- package/src/core/CacheManager.js +650 -0
- package/src/core/CompatibilityAdapter.js +264 -0
- package/src/core/ConfigManager.js +431 -0
- package/src/core/ConfigValidator.js +350 -0
- package/src/core/EventBus.js +77 -0
- package/src/core/FullScanManager.js +430 -0
- package/src/core/StateManager.js +631 -0
- package/src/docs/DocsServer.js +179 -0
- package/src/example.js +106 -0
- package/src/generators/DynamicClassGenerator.js +674 -0
- package/src/index.js +1046 -0
- package/src/parsers/ClassParser.js +572 -0
- package/src/parsers/ImportantParser.js +279 -0
- package/src/parsers/RegexCompiler.js +200 -0
- package/src/utils/ClassChangeTracker.js +366 -0
- package/src/utils/ConfigDiagnostics.js +673 -0
- package/src/utils/CssFormatter.js +261 -0
- package/src/utils/FileUtils.js +230 -0
- package/src/utils/Logger.js +150 -0
- package/src/utils/Throttle.js +172 -0
- package/src/utils/UnitProcessor.js +334 -0
- package/src/utils/WxssClassExtractor.js +137 -0
- package/src/watchers/ConfigWatcher.js +413 -0
- package/src/watchers/FileWatcher.js +133 -0
- package/src/writers/FileWriter.js +302 -0
- package/src/writers/UnifiedWriter.js +370 -0
- package/styles.config.js +250 -0
package/styles.config.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// ========== 样式规则配置文件 ==========
|
|
2
|
+
// 此文件包含所有样式解析规则配置,与工具配置分离
|
|
3
|
+
|
|
4
|
+
// ========== 原子化规则配置 ==========
|
|
5
|
+
const atomicRules = {
|
|
6
|
+
"spacing": {
|
|
7
|
+
"m": { "properties": ["margin"], "defaultUnit": "rpx" },
|
|
8
|
+
"mt": { "properties": ["margin-top"], "defaultUnit": "rpx" },
|
|
9
|
+
"mr": { "properties": ["margin-right"], "defaultUnit": "rpx" },
|
|
10
|
+
"mb": { "properties": ["margin-bottom"], "defaultUnit": "rpx" },
|
|
11
|
+
"ml": { "properties": ["margin-left"], "defaultUnit": "rpx" },
|
|
12
|
+
"mx": { "properties": ["margin-left", "margin-right"], "defaultUnit": "rpx" },
|
|
13
|
+
"my": { "properties": ["margin-top", "margin-bottom"], "defaultUnit": "rpx" },
|
|
14
|
+
"p": { "properties": ["padding"], "defaultUnit": "rpx" },
|
|
15
|
+
"pt": { "properties": ["padding-top"], "defaultUnit": "rpx" },
|
|
16
|
+
"pr": { "properties": ["padding-right"], "defaultUnit": "rpx" },
|
|
17
|
+
"pb": { "properties": ["padding-bottom"], "defaultUnit": "rpx" },
|
|
18
|
+
"pl": { "properties": ["padding-left"], "defaultUnit": "rpx" },
|
|
19
|
+
"px": { "properties": ["padding-left", "padding-right"], "defaultUnit": "rpx" },
|
|
20
|
+
"py": { "properties": ["padding-top", "padding-bottom"], "defaultUnit": "rpx" },
|
|
21
|
+
"gap": { "properties": ["gap"], "defaultUnit": "rpx" }
|
|
22
|
+
},
|
|
23
|
+
"sizing": {
|
|
24
|
+
"w": { "properties": ["width"], "defaultUnit": "rpx" },
|
|
25
|
+
"h": { "properties": ["height"], "defaultUnit": "rpx" },
|
|
26
|
+
"max-w": { "properties": ["max-width"], "defaultUnit": "rpx" },
|
|
27
|
+
"max-h": { "properties": ["max-height"], "defaultUnit": "rpx" },
|
|
28
|
+
"min-w": { "properties": ["min-width"], "defaultUnit": "rpx" },
|
|
29
|
+
"min-h": { "properties": ["min-height"], "defaultUnit": "rpx" },
|
|
30
|
+
"size": { "properties": ["width", "height"], "defaultUnit": "rpx" }
|
|
31
|
+
},
|
|
32
|
+
"typography": {
|
|
33
|
+
"text-size": { "properties": ["font-size"], "defaultUnit": "rpx" },
|
|
34
|
+
"text": { "properties": ["font-size"], "defaultUnit": "rpx" },
|
|
35
|
+
"font": { "properties": ["font-weight"], "defaultUnit": "" },
|
|
36
|
+
"leading": { "properties": ["line-height"], "defaultUnit": "" },
|
|
37
|
+
"tracking": { "properties": ["letter-spacing"], "defaultUnit": "rpx" }
|
|
38
|
+
},
|
|
39
|
+
"positioning": {
|
|
40
|
+
"top": { "properties": ["top"], "defaultUnit": "rpx" },
|
|
41
|
+
"right": { "properties": ["right"], "defaultUnit": "rpx" },
|
|
42
|
+
"bottom": { "properties": ["bottom"], "defaultUnit": "rpx" },
|
|
43
|
+
"left": { "properties": ["left"], "defaultUnit": "rpx" },
|
|
44
|
+
"inset": { "properties": ["top", "right", "bottom", "left"], "defaultUnit": "rpx" },
|
|
45
|
+
"inset-x": { "properties": ["left", "right"], "defaultUnit": "rpx" },
|
|
46
|
+
"inset-y": { "properties": ["top", "bottom"], "defaultUnit": "rpx" }
|
|
47
|
+
},
|
|
48
|
+
"borders": {
|
|
49
|
+
"rounded": { "properties": ["border-radius"], "defaultUnit": "rpx" },
|
|
50
|
+
"border": { "properties": ["border-width"], "defaultUnit": "rpx" },
|
|
51
|
+
"bordert": { "properties": ["border-top-width"], "defaultUnit": "rpx" },
|
|
52
|
+
"borderr": { "properties": ["border-right-width"], "defaultUnit": "rpx" },
|
|
53
|
+
"borderb": { "properties": ["border-bottom-width"], "defaultUnit": "rpx" },
|
|
54
|
+
"borderl": { "properties": ["border-left-width"], "defaultUnit": "rpx" },
|
|
55
|
+
"b_r": { "properties": ["border-radius"], "defaultUnit": "rpx" }
|
|
56
|
+
},
|
|
57
|
+
"effects": {
|
|
58
|
+
"opacity": { "properties": ["opacity"], "defaultUnit": "" },
|
|
59
|
+
"transition": { "properties": ["transition"], "defaultUnit": "ms", "skipConversion": true },
|
|
60
|
+
"op": { "properties": ["opacity"], "defaultUnit": "" },
|
|
61
|
+
"z": { "properties": ["z-index"], "defaultUnit": "" }
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// ========== Tailwind风格的基础class配置 ==========
|
|
66
|
+
const baseClassName = {
|
|
67
|
+
"color": { "ABBR": "color" },
|
|
68
|
+
"bg": { "ABBR": "background-color" },
|
|
69
|
+
"bcolor": { "ABBR": "border-color" },
|
|
70
|
+
"block": "display: block;",
|
|
71
|
+
"inline": "display: inline;",
|
|
72
|
+
"inline-block": "display: inline-block;",
|
|
73
|
+
"flex": "display: flex;",
|
|
74
|
+
"flex-1": "flex: 1;",
|
|
75
|
+
"shrink-0": "flex-shrink: 0;",
|
|
76
|
+
"inline-flex": "display: inline-flex;",
|
|
77
|
+
"grid": "display: grid;",
|
|
78
|
+
"inline-grid": "display: inline-grid;",
|
|
79
|
+
"table": "display: table;",
|
|
80
|
+
"hidden": "display: none;",
|
|
81
|
+
"w-full": "width: 100%;",
|
|
82
|
+
"h-full": "height: 100%;",
|
|
83
|
+
"w-screen": "width: 100vw;",
|
|
84
|
+
"h-screen": "height: 100vh;",
|
|
85
|
+
"font-runyuan": "font-family: 'HYRunYuan-BOLD';",
|
|
86
|
+
"flex-cen": "align-items: center;justify-content: center;",
|
|
87
|
+
"flex-row": "flex-direction: row;",
|
|
88
|
+
"flex-col": "flex-direction: column;",
|
|
89
|
+
"flex-wrap": "flex-wrap: wrap;",
|
|
90
|
+
"flex-nowrap": "flex-wrap: nowrap;",
|
|
91
|
+
"items-start": "align-items: flex-start;",
|
|
92
|
+
"items-center": "align-items: center;",
|
|
93
|
+
"items-end": "align-items: flex-end;",
|
|
94
|
+
"items-stretch": "align-items: stretch;",
|
|
95
|
+
"justify-start": "justify-content: flex-start;",
|
|
96
|
+
"justify-center": "justify-content: center;",
|
|
97
|
+
"justify-end": "justify-content: flex-end;",
|
|
98
|
+
"justify-between": "justify-content: space-between;",
|
|
99
|
+
"justify-around": "justify-content: space-around;",
|
|
100
|
+
"justify-evenly": "justify-content: space-evenly;",
|
|
101
|
+
"grid-cols-4": "grid-template-columns: repeat(4, 1fr);",
|
|
102
|
+
"grid-cols-2": "grid-template-columns: repeat(2, 1fr);",
|
|
103
|
+
"grid-cols-3": "grid-template-columns: repeat(3, 1fr);",
|
|
104
|
+
"grid-cols-5": "grid-template-columns: repeat(5, 1fr);",
|
|
105
|
+
"grid-cols-6": "grid-template-columns: repeat(6, 1fr);",
|
|
106
|
+
"grid-cols-7": "grid-template-columns: repeat(7, 1fr);",
|
|
107
|
+
"grid-cols-8": "grid-template-columns: repeat(8, 1fr);",
|
|
108
|
+
"grid-cols-9": "grid-template-columns: repeat(9, 1fr);",
|
|
109
|
+
"grid-cols-10": "grid-template-columns: repeat(10, 1fr);",
|
|
110
|
+
"static": "position: static;",
|
|
111
|
+
"fixed": "position: fixed;",
|
|
112
|
+
"absolute": "position: absolute;",
|
|
113
|
+
"relative": "position: relative;",
|
|
114
|
+
"sticky": "position: sticky;",
|
|
115
|
+
"overflow-auto": "overflow: auto;",
|
|
116
|
+
"overflow-hidden": "overflow: hidden;",
|
|
117
|
+
"overflow-visible": "overflow: visible;",
|
|
118
|
+
"overflow-scroll": "overflow: scroll;",
|
|
119
|
+
"overflow-x-auto": "overflow-x: auto;",
|
|
120
|
+
"overflow-x-hidden": "overflow-x: hidden;",
|
|
121
|
+
"overflow-x-scroll": "overflow-x: scroll;",
|
|
122
|
+
"overflow-y-auto": "overflow-y: auto;",
|
|
123
|
+
"overflow-y-hidden": "overflow-y: hidden;",
|
|
124
|
+
"overflow-y-scroll": "overflow-y: scroll;",
|
|
125
|
+
"bold-thin": "font-weight: 100;",
|
|
126
|
+
"bold-extralight": "font-weight: 200;",
|
|
127
|
+
"bold-light": "font-weight: 300;",
|
|
128
|
+
"bold-normal": "font-weight: 400;",
|
|
129
|
+
"bold-medium": "font-weight: 500;",
|
|
130
|
+
"bold-semibold": "font-weight: 600;",
|
|
131
|
+
"bold-bold": "font-weight: 700;",
|
|
132
|
+
"bold-extrabold": "font-weight: 800;",
|
|
133
|
+
"bold-black": "font-weight: 900;",
|
|
134
|
+
"underline": "text-decoration: underline;",
|
|
135
|
+
"line-through": "text-decoration: line-through;",
|
|
136
|
+
"ellipsis": "overflow: hidden;text-overflow: ellipsis;white-space: nowrap;",
|
|
137
|
+
"text-left": "text-align: left;",
|
|
138
|
+
"text-center": "text-align: center;",
|
|
139
|
+
"text-right": "text-align: right;",
|
|
140
|
+
"text-justify": "text-align: justify;",
|
|
141
|
+
"cursor-auto": "cursor: auto;",
|
|
142
|
+
"cursor-default": "cursor: default;",
|
|
143
|
+
"cursor-pointer": "cursor: pointer;",
|
|
144
|
+
"cursor-wait": "cursor: wait;",
|
|
145
|
+
"cursor-text": "cursor: text;",
|
|
146
|
+
"cursor-move": "cursor: move;",
|
|
147
|
+
"cursor-not-allowed": "cursor: not-allowed;",
|
|
148
|
+
"box-border": "box-sizing: border-box;",
|
|
149
|
+
"box-content": "box-sizing: content-box;",
|
|
150
|
+
"border-solid": "border-style: solid;",
|
|
151
|
+
"border-dashed": "border-style: dashed;",
|
|
152
|
+
"border-dotted": "border-style: dotted;",
|
|
153
|
+
"border-none": "border: none;",
|
|
154
|
+
"bold": "font-weight: bold;"
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// ========== 变体规则(响应式、伪类等) ==========
|
|
158
|
+
const variants = {
|
|
159
|
+
"responsive": ["sm", "md", "lg", "xl", "2xl"],
|
|
160
|
+
"states": ["hover", "focus", "active", "disabled", "first", "last", "odd", "even"],
|
|
161
|
+
"darkMode": ["dark"]
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ========== 响应式断点配置(可选) ==========
|
|
165
|
+
// 如果不配置,将使用默认 Tailwind 断点值
|
|
166
|
+
const breakpoints = {
|
|
167
|
+
sm: '640px', // 小屏幕(手机横屏)
|
|
168
|
+
md: '768px', // 中等屏幕(平板)
|
|
169
|
+
lg: '1024px', // 大屏幕(笔记本)
|
|
170
|
+
xl: '1280px', // 超大屏幕(桌面)
|
|
171
|
+
'2xl': '1536px' // 超超大屏幕(大桌面)
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// ========== 颜色配置 ==========
|
|
175
|
+
const baseColor = {
|
|
176
|
+
"466580": "#466580",
|
|
177
|
+
"818182": "#818182",
|
|
178
|
+
"595959": "#595959",
|
|
179
|
+
"333333": "#333333",
|
|
180
|
+
"666666": "#666666",
|
|
181
|
+
"979797": "#979797",
|
|
182
|
+
"777777": "#777777",
|
|
183
|
+
"142640": "#142640",
|
|
184
|
+
"fafafa": "#fafafa",
|
|
185
|
+
"B3B3B3": "#B3B3B3",
|
|
186
|
+
"F9F9F9": "#F9F9F9",
|
|
187
|
+
"9CA6B4": "#9CA6B4",
|
|
188
|
+
"040404": "#040404",
|
|
189
|
+
"ECF5FF": "#ECF5FF",
|
|
190
|
+
"black07": "rgba(0,0,0,0.7)",
|
|
191
|
+
"fffffe": "#fffffe",
|
|
192
|
+
"B10A32": "#B10A32",
|
|
193
|
+
"f4": "#F4F4F4",
|
|
194
|
+
"f4f4f4": "#f4f4f4",
|
|
195
|
+
"cc": "#CCCCCC",
|
|
196
|
+
"white": "#ffffff",
|
|
197
|
+
"black": "#000000",
|
|
198
|
+
"transparent": "transparent",
|
|
199
|
+
"slate": "#64748b",
|
|
200
|
+
"gray": "#6b7280",
|
|
201
|
+
"gray1": "",
|
|
202
|
+
"gray4": "#CCCCCC",
|
|
203
|
+
"zinc": "#71717a",
|
|
204
|
+
"red": "#ef4444",
|
|
205
|
+
"orange": "#f97316",
|
|
206
|
+
"amber": "#f59e0b",
|
|
207
|
+
"yellow": "#eab308",
|
|
208
|
+
"lime": "#84cc16",
|
|
209
|
+
"green": "#22c55e",
|
|
210
|
+
"emerald": "#10b981",
|
|
211
|
+
"teal": "#14b8a6",
|
|
212
|
+
"cyan": "#06b6d4",
|
|
213
|
+
"sky": "#0ea5e9",
|
|
214
|
+
"blue": "#142640",
|
|
215
|
+
"indigo": "#6366f1",
|
|
216
|
+
"violet": "#8b5cf6",
|
|
217
|
+
"purple": "#a855f7",
|
|
218
|
+
"fuchsia": "#d946ef",
|
|
219
|
+
"pink": "#ec4899",
|
|
220
|
+
"rose": "#f43f5e"
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// ========== Important标识配置 ==========
|
|
224
|
+
const importantFlags = {
|
|
225
|
+
// prefix: ['!', '$$'], // 前缀标识: !w-100, $$w-100
|
|
226
|
+
suffix: ['-i', '_i'], // 后缀标识: w-100_i, w-100-i, w-100__imp
|
|
227
|
+
// custom: ['--important', '##IMP##'] // 自定义标识: w--important-100, w##IMP##-100
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// 处理颜色配置:将 baseColor 合并到 baseClassName 中具有 ABBR 属性的项
|
|
231
|
+
function processStyles() {
|
|
232
|
+
const processedBaseClassName = { ...baseClassName };
|
|
233
|
+
|
|
234
|
+
// 将颜色配置合并到具有 ABBR 的类中
|
|
235
|
+
Object.values(processedBaseClassName).forEach((item) => {
|
|
236
|
+
if (item && item.ABBR) {
|
|
237
|
+
Object.assign(item, baseColor);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
atomicRules,
|
|
243
|
+
baseClassName: processedBaseClassName,
|
|
244
|
+
variants,
|
|
245
|
+
breakpoints,
|
|
246
|
+
importantFlags,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
module.exports = processStyles();
|