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.
Files changed (57) hide show
  1. package/API.md +1143 -0
  2. package/CHANGELOG.md +291 -0
  3. package/CONFIG.md +1096 -0
  4. package/CONTRIBUTING.md +571 -0
  5. package/MIGRATION.md +402 -0
  6. package/README.md +634 -0
  7. package/bin/class2css.js +380 -0
  8. package/class2css.config.js +124 -0
  9. package/common.css +3 -0
  10. package/configs/colors.config.js +62 -0
  11. package/configs/layout.config.js +110 -0
  12. package/configs/spacing.config.js +37 -0
  13. package/configs/typography.config.js +41 -0
  14. package/docs/.vitepress/config.mjs +65 -0
  15. package/docs/.vitepress/theme/custom.css +74 -0
  16. package/docs/.vitepress/theme/index.js +7 -0
  17. package/docs/guide/cli.md +97 -0
  18. package/docs/guide/concepts.md +63 -0
  19. package/docs/guide/config-template.md +365 -0
  20. package/docs/guide/config.md +275 -0
  21. package/docs/guide/faq.md +202 -0
  22. package/docs/guide/getting-started.md +83 -0
  23. package/docs/guide/important-and-static.md +67 -0
  24. package/docs/guide/incremental.md +162 -0
  25. package/docs/guide/rules-reference.md +354 -0
  26. package/docs/guide/units.md +57 -0
  27. package/docs/index.md +68 -0
  28. package/package.json +49 -0
  29. package/run.js +90 -0
  30. package/src/README.md +571 -0
  31. package/src/core/CacheManager.js +650 -0
  32. package/src/core/CompatibilityAdapter.js +264 -0
  33. package/src/core/ConfigManager.js +431 -0
  34. package/src/core/ConfigValidator.js +350 -0
  35. package/src/core/EventBus.js +77 -0
  36. package/src/core/FullScanManager.js +430 -0
  37. package/src/core/StateManager.js +631 -0
  38. package/src/docs/DocsServer.js +179 -0
  39. package/src/example.js +106 -0
  40. package/src/generators/DynamicClassGenerator.js +674 -0
  41. package/src/index.js +1046 -0
  42. package/src/parsers/ClassParser.js +572 -0
  43. package/src/parsers/ImportantParser.js +279 -0
  44. package/src/parsers/RegexCompiler.js +200 -0
  45. package/src/utils/ClassChangeTracker.js +366 -0
  46. package/src/utils/ConfigDiagnostics.js +673 -0
  47. package/src/utils/CssFormatter.js +261 -0
  48. package/src/utils/FileUtils.js +230 -0
  49. package/src/utils/Logger.js +150 -0
  50. package/src/utils/Throttle.js +172 -0
  51. package/src/utils/UnitProcessor.js +334 -0
  52. package/src/utils/WxssClassExtractor.js +137 -0
  53. package/src/watchers/ConfigWatcher.js +413 -0
  54. package/src/watchers/FileWatcher.js +133 -0
  55. package/src/writers/FileWriter.js +302 -0
  56. package/src/writers/UnifiedWriter.js +370 -0
  57. package/styles.config.js +250 -0
@@ -0,0 +1,37 @@
1
+ // 间距配置模块
2
+ module.exports = {
3
+ // Margin 配置
4
+ margin: {
5
+ m: 'margin',
6
+ mt: 'margin-top',
7
+ mr: 'margin-right',
8
+ mb: 'margin-bottom',
9
+ ml: 'margin-left',
10
+ mx: {
11
+ classArr: ['margin-left', 'margin-right'],
12
+ },
13
+ my: {
14
+ classArr: ['margin-top', 'margin-bottom'],
15
+ },
16
+ },
17
+
18
+ // Padding 配置
19
+ padding: {
20
+ p: 'padding',
21
+ pt: 'padding-top',
22
+ pr: 'padding-right',
23
+ pb: 'padding-bottom',
24
+ pl: 'padding-left',
25
+ px: {
26
+ classArr: ['padding-left', 'padding-right'],
27
+ },
28
+ py: {
29
+ classArr: ['padding-top', 'padding-bottom'],
30
+ },
31
+ },
32
+
33
+ // Gap 配置
34
+ gap: {
35
+ gap: 'gap',
36
+ },
37
+ };
@@ -0,0 +1,41 @@
1
+ // 字体排版配置模块
2
+ module.exports = {
3
+ // 字体大小
4
+ fontSize: {
5
+ text: 'font-size',
6
+ },
7
+
8
+ // 字体粗细
9
+ fontWeight: {
10
+ font: 'font-weight',
11
+ 'font-thin': 'font-weight: 100;',
12
+ 'font-extralight': 'font-weight: 200;',
13
+ 'font-light': 'font-weight: 300;',
14
+ 'font-normal': 'font-weight: 400;',
15
+ 'font-medium': 'font-weight: 500;',
16
+ 'font-semibold': 'font-weight: 600;',
17
+ 'font-bold': 'font-weight: 700;',
18
+ 'font-extrabold': 'font-weight: 800;',
19
+ 'font-black': 'font-weight: 900;',
20
+ bold: 'font-weight: bold;',
21
+ },
22
+
23
+ // 行高
24
+ lineHeight: {
25
+ leading: 'line-height',
26
+ },
27
+
28
+ // 字间距
29
+ letterSpacing: {
30
+ spacing: 'letter-spacing',
31
+ tracking: 'letter-spacing',
32
+ },
33
+
34
+ // 文本对齐
35
+ textAlign: {
36
+ 'text-left': 'text-align: left;',
37
+ 'text-center': 'text-align: center;',
38
+ 'text-right': 'text-align: right;',
39
+ 'text-justify': 'text-align: justify;',
40
+ },
41
+ };
@@ -0,0 +1,65 @@
1
+ /*
2
+ * @LastEditors: biz
3
+ */
4
+ import { defineConfig } from 'vitepress';
5
+
6
+ export default defineConfig({
7
+ title: 'Class2CSS',
8
+ description: '企业级原子化CSS生成工具,支持智能单位处理、配置验证、性能缓存和向后兼容',
9
+ lang: 'zh-CN',
10
+
11
+ themeConfig: {
12
+ nav: [
13
+ { text: '文档', link: '/guide/getting-started' },
14
+ { text: '参考', link: '/guide/config' },
15
+ { text: 'FAQ', link: '/guide/faq' },
16
+ ],
17
+
18
+ sidebar: {
19
+ '/guide/': [
20
+ {
21
+ text: '开始',
22
+ items: [
23
+ { text: '快速开始', link: '/guide/getting-started' },
24
+ ],
25
+ },
26
+ {
27
+ text: '核心概念',
28
+ items: [
29
+ { text: '类名语法与生成规则', link: '/guide/concepts' },
30
+ { text: '单位与转换策略', link: '/guide/units' },
31
+ { text: 'Important 与静态类', link: '/guide/important-and-static' },
32
+ ],
33
+ },
34
+ {
35
+ text: '参考',
36
+ items: [
37
+ { text: 'CLI', link: '/guide/cli' },
38
+ { text: '规则参考', link: '/guide/rules-reference' },
39
+ { text: '配置模板(可复制)', link: '/guide/config-template' },
40
+ { text: '配置', link: '/guide/config' },
41
+ ],
42
+ },
43
+ {
44
+ text: '进阶',
45
+ items: [
46
+ { text: '增量模式(只增不删)', link: '/guide/incremental' },
47
+ ],
48
+ },
49
+ {
50
+ text: '帮助',
51
+ items: [{ text: '常见问题', link: '/guide/faq' }],
52
+ },
53
+ ],
54
+ },
55
+
56
+ socialLinks: [{ icon: 'github', link: 'https://github.com/wnagchi/css2class' }],
57
+
58
+ search: {
59
+ provider: 'local',
60
+ },
61
+
62
+ outline: { level: [2, 3] },
63
+ },
64
+ });
65
+
@@ -0,0 +1,74 @@
1
+ :root {
2
+ /* Tailwind-ish brand */
3
+ --vp-c-brand-1: #0ea5e9; /* sky-500 */
4
+ --vp-c-brand-2: #38bdf8; /* sky-400 */
5
+ --vp-c-brand-3: #0284c7; /* sky-600 */
6
+
7
+ --vp-home-hero-name-color: transparent;
8
+ --vp-home-hero-name-background: linear-gradient(120deg, #38bdf8 30%, #a78bfa);
9
+ --vp-home-hero-image-background-image: radial-gradient(
10
+ circle at 50% 50%,
11
+ rgba(56, 189, 248, 0.35) 0%,
12
+ rgba(167, 139, 250, 0.25) 35%,
13
+ rgba(2, 132, 199, 0.15) 70%,
14
+ rgba(0, 0, 0, 0) 100%
15
+ );
16
+ --vp-home-hero-image-filter: blur(60px);
17
+ }
18
+
19
+ /* Make home look more like "product docs" */
20
+ .VPHome {
21
+ padding-bottom: 48px;
22
+ }
23
+
24
+ .VPHomeHero .name {
25
+ letter-spacing: -0.02em;
26
+ }
27
+
28
+ .VPHomeHero .text {
29
+ max-width: 46rem;
30
+ }
31
+
32
+ .VPHomeHero .tagline {
33
+ max-width: 52rem;
34
+ }
35
+
36
+ .VPFeatures .VPFeature {
37
+ border: 1px solid var(--vp-c-divider);
38
+ background: color-mix(in srgb, var(--vp-c-bg-soft) 85%, transparent);
39
+ }
40
+
41
+ .VPFeatures .VPFeature:hover {
42
+ border-color: color-mix(in srgb, var(--vp-c-brand-1) 45%, var(--vp-c-divider));
43
+ }
44
+
45
+ /* Code blocks: slightly closer to Tailwind docs vibe */
46
+ .vp-doc div[class*='language-'] {
47
+ border: 1px solid var(--vp-c-divider);
48
+ box-shadow: none;
49
+ }
50
+
51
+ .vp-doc :not(pre) > code {
52
+ border: 1px solid var(--vp-c-divider);
53
+ background: color-mix(in srgb, var(--vp-c-bg-soft) 78%, transparent);
54
+ padding: 0.15em 0.35em;
55
+ border-radius: 6px;
56
+ }
57
+
58
+ /* Callouts */
59
+ .vp-doc .custom-block {
60
+ border: 1px solid var(--vp-c-divider);
61
+ }
62
+
63
+ .vp-doc .custom-block.tip {
64
+ border-color: color-mix(in srgb, var(--vp-c-brand-1) 40%, var(--vp-c-divider));
65
+ }
66
+
67
+ .vp-doc .custom-block.warning {
68
+ border-color: color-mix(in srgb, #f59e0b 45%, var(--vp-c-divider));
69
+ }
70
+
71
+ .vp-doc .custom-block.danger {
72
+ border-color: color-mix(in srgb, #ef4444 45%, var(--vp-c-divider));
73
+ }
74
+
@@ -0,0 +1,7 @@
1
+ import DefaultTheme from 'vitepress/theme';
2
+ import './custom.css';
3
+
4
+ export default {
5
+ extends: DefaultTheme,
6
+ };
7
+
@@ -0,0 +1,97 @@
1
+ # CLI 使用说明
2
+
3
+ CLI 适合在 CI 或本地快速覆盖配置(例如临时换输入/输出目录)。你可以直接运行 `class2css`,或者在项目里通过 npm scripts 间接运行。
4
+
5
+ ## 基本用法
6
+
7
+ ```bash
8
+ class2css [options]
9
+ ```
10
+
11
+ :::tip
12
+ 如果你是通过本项目自带脚本运行(例如 `npm run start`),本质上也是把参数传给 `class2css`。
13
+ :::
14
+
15
+ ## 参数一览
16
+
17
+ ### 配置与模式
18
+
19
+ - **`-c, --config <path>`**:指定配置文件路径(默认 `./class2css.config.js`)
20
+ - **`--no-watch`**:关闭监听模式(执行一次扫描后退出)
21
+
22
+ ### 运行时覆盖(覆盖配置文件)
23
+
24
+ - **`-i, --input <path>`**:覆盖输入目录(扫描/监听入口)
25
+ - 目前该参数为**单路径**覆盖(对应 `multiFile.entry.path` 的单值用法)
26
+ - 如需多目录/多文件入口,请在配置中使用 `multiFile.entry.path: string[]`
27
+ - **`-o, --output <path>`**:覆盖输出目录
28
+ - **`-f, --output-file <name>`**:覆盖输出文件名
29
+ - **`-t, --output-type <type>`**:覆盖输出类型(`filePath` 或 `uniFile`)
30
+
31
+ ### 文档服务
32
+
33
+ - **`--docs`**:启用文档服务(与主程序并行运行)
34
+ - **`--docs-port <port>`**:指定文档服务端口(默认 5173;若占用则自动寻找下一个可用端口)
35
+ - **`--docs-host <host>`**:指定文档服务主机(默认 `127.0.0.1`)
36
+ - **`--docs-open`**:启动后自动打开浏览器
37
+ - **`--docs-only`**:只启动文档服务,不启动 class2css 主流程
38
+
39
+ ### 其他
40
+
41
+ - **`-h, --help`**:显示帮助信息
42
+ - **`-v, --version`**:显示版本信息
43
+
44
+ ## 使用示例
45
+
46
+ ### 基本使用
47
+
48
+ ```bash
49
+ # 默认配置启动(监听模式)
50
+ class2css
51
+
52
+ # 使用自定义配置文件
53
+ class2css -c ./my-config.js
54
+
55
+ # 单次构建(不监听)
56
+ class2css --no-watch
57
+ ```
58
+
59
+ ### 运行时覆盖
60
+
61
+ ```bash
62
+ # 覆盖输入和输出目录
63
+ class2css -i ./src -o ./dist
64
+
65
+ # 覆盖输入、输出和文件名
66
+ class2css -i ./pages -o ./styles -f app.wxss
67
+
68
+ # 覆盖输出类型
69
+ class2css -i ./src -o ./dist -t uniFile
70
+ ```
71
+
72
+ ### 文档服务
73
+
74
+ ```bash
75
+ # 启动工具并同时开启文档服务
76
+ class2css --docs
77
+
78
+ # 启动文档服务并自动打开浏览器
79
+ class2css --docs --docs-open
80
+
81
+ # 指定文档服务端口
82
+ class2css --docs --docs-port 8080
83
+
84
+ # 只启动文档服务(不运行主程序)
85
+ class2css --docs-only
86
+ ```
87
+
88
+ ## 注意事项
89
+
90
+ 1. 运行时覆盖的参数会覆盖配置文件中的对应设置
91
+ 2. 文档服务默认监听 `127.0.0.1`,只能本地访问
92
+ 3. 如果指定端口被占用,工具会自动寻找下一个可用端口
93
+ 4. 使用 `--docs-only` 时,不会执行任何 CSS 生成操作
94
+
95
+ ## 下一步
96
+
97
+ - 了解配置结构与最佳实践:阅读 [配置指南](./config.md)
@@ -0,0 +1,63 @@
1
+ # 类名语法与生成规则
2
+
3
+ Class2CSS 的核心是:**把“类名”解析成一条 CSS 规则**。你只需要定义“前缀 → CSS 属性”的映射(`cssName`),剩下的值解析、单位策略、Important、排序/压缩等由工具处理。
4
+
5
+ ## 基本语法
6
+
7
+ 最常用的形式是:
8
+
9
+ `<key>-<value>`
10
+
11
+ - **`key`**:在 `cssName` 里定义的前缀(例如 `m`、`w`、`text`)
12
+ - **`value`**:数值 / 特殊值 / 带单位值(例如 `10`、`50px`、`auto`)
13
+
14
+ 示例:
15
+
16
+ ```html
17
+ <view class="m-10 w-100 h-200"></view>
18
+ ```
19
+
20
+ 对应(以 `baseUnit=rpx`、`unitConversion=2` 为例):
21
+
22
+ ```css
23
+ .m-10 { margin: 20rpx; }
24
+ .w-100 { width: 200rpx; }
25
+ .h-200 { height: 400rpx; }
26
+ ```
27
+
28
+ ## 带单位值 vs 自动单位
29
+
30
+ 在 `unitStrategy.autoDetect=true` 时:
31
+
32
+ - **写了单位**:保持你写的单位(例如 `w-50px` → `50px`)
33
+ - **没写单位**:使用配置的默认单位和转换比例(例如 `w-100` → `200rpx`)
34
+
35
+ ```html
36
+ <view class="w-50px h-auto"></view>
37
+ ```
38
+
39
+ ## 重要性(Important)
40
+
41
+ 可以通过后缀标识生成 `!important`,例如:
42
+
43
+ ```html
44
+ <view class="m-10-i p-20-i"></view>
45
+ ```
46
+
47
+ 具体后缀规则由 `importantFlags.suffix` 控制,详见 [Important 与静态类](./important-and-static.md)。
48
+
49
+ ## 静态类(预设片段)
50
+
51
+ 你也可以把一段固定 CSS 作为“静态类”注册到 `baseClassName`,例如:
52
+
53
+ ```html
54
+ <view class="container flex-center"></view>
55
+ ```
56
+
57
+ 详见 [Important 与静态类](./important-and-static.md)。
58
+
59
+ ## 下一步
60
+
61
+ - 想把单位处理写得更稳:阅读 [单位与转换策略](./units.md)
62
+ - 想系统了解所有配置:阅读 [配置指南](./config.md)
63
+