css2class 2.0.0 → 2.0.1

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 (40) hide show
  1. package/.github/workflows/deploy-docs.yml +53 -0
  2. package/.head_config.mjs +68 -0
  3. package/CONFIG.md +38 -1
  4. package/README.md +595 -633
  5. package/bin/class2css.js +32 -4
  6. package/common.css +1 -1
  7. package/configs/typography.config.js +1 -0
  8. package/docs/.vitepress/config.mjs +68 -65
  9. package/docs/guide/cli.md +97 -97
  10. package/docs/guide/config-template.md +16 -1
  11. package/docs/guide/config.md +129 -64
  12. package/docs/guide/faq.md +202 -202
  13. package/docs/guide/getting-started.md +86 -83
  14. package/docs/guide/incremental.md +164 -162
  15. package/docs/guide/rules-reference.md +73 -1
  16. package/docs/index.md +71 -68
  17. package/examples/weapp/README.md +15 -0
  18. package/examples/weapp/class2css.config.js +70 -0
  19. package/examples/weapp/src/placeholder.wxml +0 -0
  20. package/examples/weapp/styles.config.js +201 -0
  21. package/examples/web/README.md +25 -0
  22. package/examples/web/class2css.config.js +70 -0
  23. package/examples/web/demo.html +105 -0
  24. package/examples/web/src/placeholder.html +5 -0
  25. package/examples/web/styles.config.js +201 -0
  26. package/package.json +7 -2
  27. package/src/README.md +99 -0
  28. package/src/core/ConfigManager.js +440 -431
  29. package/src/core/FullScanManager.js +438 -430
  30. package/src/generators/DynamicClassGenerator.js +270 -72
  31. package/src/index.js +1091 -1046
  32. package/src/parsers/ClassParser.js +8 -2
  33. package/src/utils/CssFormatter.js +400 -47
  34. package/src/utils/UnitProcessor.js +4 -3
  35. package/src/watchers/ConfigWatcher.js +413 -413
  36. package/src/watchers/FileWatcher.js +148 -133
  37. package/src/writers/FileWriter.js +444 -302
  38. package/src/writers/UnifiedWriter.js +413 -370
  39. package/class2css.config.js +0 -124
  40. package/styles.config.js +0 -250
@@ -1,124 +0,0 @@
1
- // ========== 工具配置文件 ==========
2
- // 此文件包含工具运行相关的配置(系统设置、输出路径等)
3
- // 样式规则配置请查看 styles.config.js
4
-
5
- // 引入样式规则配置
6
- const stylesConfig = require('./styles.config.js');
7
-
8
- const config = {
9
- // ========== 系统基础配置 ==========
10
- system: {
11
- // 基础单位设置
12
- cssFormat: 'compressed', // 'multiLine' | 'singleLine' | 'compressed'
13
- baseUnit: 'rpx',
14
- // 单位转换比例 生成样式单位=设置单位*比例
15
- unitConversion: 2,
16
- // 是否压缩CSS
17
- compression: true,
18
- // 是否对生成的CSS类进行字母排序
19
- sortClasses: true, // true | false,启用后会将CSS规则按选择器名称进行字母排序
20
- // 智能单位处理策略
21
- unitStrategy: {
22
- // 自动检测:如果用户写了单位,保持原单位;如果没写,使用默认单位
23
- autoDetect: true,
24
- // 属性默认单位映射
25
- propertyUnits: {
26
- 'font-size': 'rpx',
27
- 'width|height': 'rpx',
28
- opacity: '', // 无单位
29
- 'z-index': '', // 无单位
30
- 'line-height': '', // 可以无单位
31
- 'border-radius': 'rpx',
32
- },
33
- },
34
- },
35
-
36
- // ========== 输出配置 ==========
37
- output: {
38
- //文件输出目录
39
- path: 'D:/code/membership-weapp/subpackages/portal/lib',
40
- // 输出文件信息 可设置文件名,扩展名
41
- fileName: 'commom12.wxss',
42
- commonCssPath: 'D:/code/css2class/common.css', // 共用CSS文件路径
43
- },
44
-
45
- // ========== Important标识配置(从样式配置引入) ==========
46
- importantFlags: stylesConfig.importantFlags,
47
- // 多文件构建 如果存在该字段 则覆盖 cssOutPath fileName
48
- multiFile: {
49
- entry: {
50
- // 扫描/监听入口:
51
- // - string:单目录/单文件
52
- // - string[]:多目录/多文件(目录与文件可混用)
53
- path: 'D:/code/membership-weapp/subpackages/portal',
54
- // 需要监听的文件名
55
- // fileName:[
56
- // 'index1.html'
57
- // ],
58
- // 文件类型 需要监听的文件扩展名用逗号隔开
59
- fileType: ['html', 'wxml'],
60
- },
61
- // 多文件监听时的导出配置
62
- output: {
63
- // css文件导出目录
64
- // filePath:将css文件导出到监听文件对应的目录下,并且生成同名的样式文件
65
- //uniFile:将所有样式导出到单文件中
66
- cssOutType: 'uniFile',
67
- //文件输出目录
68
- // 如果填写该目录 css文件就会生成到该目录下
69
- path: 'D:/code/membership-weapp/subpackages/portal/lib',
70
- // 输出文件名 cssOutType为uniFile的情况下生效
71
- fileName: 'index.wxss',
72
- // 输出文件格式 在cssOutType为filePath的情况下生效
73
- fileType: 'wxss',
74
-
75
- // ========== 增量模式配置 ==========
76
- // incrementalOnlyAdd: 是否启用"只增不删"增量模式
77
- // 当设置为 true 时:
78
- // 1. 启动时会从输出文件(uniFile)中解析已存在的 class 作为基线
79
- // 2. 后续文件变更时,只会新增 class,不会删除已存在的 class(包括基线中的 class)
80
- // 3. 初次扫描后会提示输出文件中存在但当前项目未使用的 class,由用户决定是否清理
81
- // 默认值: false(标准模式:会删除不再使用的 class)
82
- // 注意:启用此模式后,输出文件可能会随时间增长,建议定期检查未使用的 class
83
- incrementalOnlyAdd: true,
84
-
85
- // incrementalBaseline: 增量基线来源策略(当前仅支持 'fromOutputFile')
86
- // 'fromOutputFile': 从输出文件(uniFile)中解析已存在的 class
87
- incrementalBaseline: 'fromOutputFile',
88
-
89
- // rebuildOnStart: 是否在启动时重建输出文件(仅在 incrementalOnlyAdd=true 时生效)
90
- // 当设置为 true 时:
91
- // 1. 每次启动都会先执行全量扫描,清理上一次运行累积的多余规则
92
- // 2. 重新生成并排序/格式化输出文件,确保输出文件只包含当前扫描到的 class
93
- // 3. 然后进入 watch 增量模式(运行期只增不删)
94
- // 默认值: true(推荐开启,保证每次启动输出文件都是干净且排序好的)
95
- rebuildOnStart: true,
96
-
97
- // unusedReportLimit: 未使用 class 报告的最大显示数量
98
- // 启动重建时,如果发现上一版输出文件中存在但当前项目未使用的 class,会在控制台打印
99
- // 此配置限制打印的示例数量,避免输出过长
100
- // 默认值: 200
101
- unusedReportLimit: 200,
102
-
103
- // ========== uniFile 写入模式配置 ==========
104
- // uniFileWriteMode: uniFile 模式的写入策略
105
- // 'rewrite': 每次写入全量重算并覆盖写文件(默认,保持兼容)
106
- // 'appendDelta': 启动时全量重建写入基础段(已压缩/排序),运行期只把新增 class 的规则追加到文件末尾
107
- // 注意:当 uniFileWriteMode='appendDelta' 时,rebuildOnStart 必须为 true(否则历史垃圾无法自动清理)
108
- // 默认值: 'rewrite'
109
- uniFileWriteMode: 'appendDelta',
110
- },
111
- },
112
-
113
- // ========== 样式规则配置(从 styles.config.js 引入) ==========
114
- atomicRules: stylesConfig.atomicRules,
115
- baseClassName: stylesConfig.baseClassName,
116
- variants: stylesConfig.variants,
117
- breakpoints: stylesConfig.breakpoints,
118
- };
119
-
120
- function getConfig() {
121
- return config;
122
- }
123
-
124
- module.exports = getConfig();
package/styles.config.js DELETED
@@ -1,250 +0,0 @@
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();