ztheme-cli 0.0.5 → 0.0.7
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.md +260 -45
- package/audit.mjs +559 -0
- package/color.mjs +228 -0
- package/package.json +8 -2
- package/rules.mjs +186 -0
- package/ztheme.mjs +236 -5
package/color.mjs
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 颜色解析(零依赖)。
|
|
3
|
+
*
|
|
4
|
+
* 只做 audit 建议需要的事:把 hex / rgb / hsl / oklch 转成 OKLab,再比较距离。
|
|
5
|
+
* 判定原则与 utils/contrast-check.ts 保持一致:无法解析、半透明、transparent、
|
|
6
|
+
* color-mix 一律返回 null —— 不猜、不静默当黑色。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @typedef {{ l: number, a: number, b: number }} Oklab */
|
|
10
|
+
|
|
11
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
12
|
+
|
|
13
|
+
const NAMED = {
|
|
14
|
+
white: [1, 1, 1],
|
|
15
|
+
black: [0, 0, 0],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const srgbToLinear = (channel) =>
|
|
19
|
+
channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* sRGB(0..1)→ OKLab。
|
|
23
|
+
* @param {number} r
|
|
24
|
+
* @param {number} g
|
|
25
|
+
* @param {number} b
|
|
26
|
+
* @returns {Oklab}
|
|
27
|
+
*/
|
|
28
|
+
function srgbToOklab(r, g, b) {
|
|
29
|
+
const lr = srgbToLinear(clamp01(r));
|
|
30
|
+
const lg = srgbToLinear(clamp01(g));
|
|
31
|
+
const lb = srgbToLinear(clamp01(b));
|
|
32
|
+
|
|
33
|
+
const l = 0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb;
|
|
34
|
+
const m = 0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb;
|
|
35
|
+
const s = 0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb;
|
|
36
|
+
|
|
37
|
+
const l_ = Math.cbrt(l);
|
|
38
|
+
const m_ = Math.cbrt(m);
|
|
39
|
+
const s_ = Math.cbrt(s);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
l: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
|
|
43
|
+
a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
|
|
44
|
+
b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
49
|
+
const h = ((hue % 360) + 360) % 360;
|
|
50
|
+
const s = clamp01(saturation);
|
|
51
|
+
const l = clamp01(lightness);
|
|
52
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
53
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
54
|
+
const m = l - c / 2;
|
|
55
|
+
|
|
56
|
+
let r = 0;
|
|
57
|
+
let g = 0;
|
|
58
|
+
let b = 0;
|
|
59
|
+
if (h < 60) [r, g, b] = [c, x, 0];
|
|
60
|
+
else if (h < 120) [r, g, b] = [x, c, 0];
|
|
61
|
+
else if (h < 180) [r, g, b] = [0, c, x];
|
|
62
|
+
else if (h < 240) [r, g, b] = [0, x, c];
|
|
63
|
+
else if (h < 300) [r, g, b] = [x, 0, c];
|
|
64
|
+
else [r, g, b] = [c, 0, x];
|
|
65
|
+
|
|
66
|
+
return [r + m, g + m, b + m];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parseNumber(value) {
|
|
70
|
+
if (typeof value !== "string") return null;
|
|
71
|
+
const raw = value.trim();
|
|
72
|
+
if (!raw) return null;
|
|
73
|
+
if (raw.endsWith("%")) {
|
|
74
|
+
const n = Number(raw.slice(0, -1));
|
|
75
|
+
return Number.isFinite(n) ? n / 100 : null;
|
|
76
|
+
}
|
|
77
|
+
const n = Number(raw);
|
|
78
|
+
return Number.isFinite(n) ? n : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function parseAlpha(parts) {
|
|
82
|
+
// parts 里最后一个可能是 alpha(用 / 分隔);无 alpha 视为 1
|
|
83
|
+
if (!parts.length) return 1;
|
|
84
|
+
const alpha = parseNumber(parts[parts.length - 1]);
|
|
85
|
+
if (alpha === null) return null;
|
|
86
|
+
return alpha <= 1 ? alpha : alpha / 100;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @returns {Oklab | null} */
|
|
90
|
+
function parseHex(raw) {
|
|
91
|
+
const match = /^#([0-9a-f]{3,8})$/i.exec(raw);
|
|
92
|
+
if (!match) return null;
|
|
93
|
+
let hex = match[1].toLowerCase();
|
|
94
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
95
|
+
hex = hex
|
|
96
|
+
.split("")
|
|
97
|
+
.map((char) => char + char)
|
|
98
|
+
.join("");
|
|
99
|
+
}
|
|
100
|
+
if (hex.length !== 6 && hex.length !== 8) return null;
|
|
101
|
+
|
|
102
|
+
const alpha = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
|
|
103
|
+
if (alpha < 1) return null;
|
|
104
|
+
|
|
105
|
+
const r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
106
|
+
const g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
107
|
+
const b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
108
|
+
return srgbToOklab(r, g, b);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @returns {Oklab | null} */
|
|
112
|
+
function parseRgb(raw) {
|
|
113
|
+
const match = /^rgba?\(([\s\S]+)\)$/i.exec(raw);
|
|
114
|
+
if (!match) return null;
|
|
115
|
+
|
|
116
|
+
const [body, ...alphaParts] = match[1].split("/");
|
|
117
|
+
const tokens = body
|
|
118
|
+
.trim()
|
|
119
|
+
.split(/[\s,]+/)
|
|
120
|
+
.map((token) => token.trim())
|
|
121
|
+
.filter(Boolean);
|
|
122
|
+
if (tokens.length !== 3) return null;
|
|
123
|
+
|
|
124
|
+
const alpha = parseAlpha(alphaParts.length ? alphaParts : []);
|
|
125
|
+
if (alpha === null || alpha < 1) return null;
|
|
126
|
+
|
|
127
|
+
const channels = tokens.map((token) => {
|
|
128
|
+
if (token.endsWith("%")) {
|
|
129
|
+
const n = Number(token.slice(0, -1));
|
|
130
|
+
return Number.isFinite(n) ? (n / 100) * 255 : null;
|
|
131
|
+
}
|
|
132
|
+
const n = Number(token);
|
|
133
|
+
return Number.isFinite(n) ? n : null;
|
|
134
|
+
});
|
|
135
|
+
if (channels.some((value) => value === null)) return null;
|
|
136
|
+
|
|
137
|
+
const [r, g, b] = channels;
|
|
138
|
+
return srgbToOklab(r / 255, g / 255, b / 255);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @returns {Oklab | null} */
|
|
142
|
+
function parseHsl(raw) {
|
|
143
|
+
const match = /^hsla?\(([\s\S]+)\)$/i.exec(raw);
|
|
144
|
+
if (!match) return null;
|
|
145
|
+
|
|
146
|
+
const [body, ...alphaParts] = match[1].split("/");
|
|
147
|
+
const tokens = body
|
|
148
|
+
.trim()
|
|
149
|
+
.split(/[\s,]+/)
|
|
150
|
+
.map((token) => token.trim())
|
|
151
|
+
.filter(Boolean);
|
|
152
|
+
if (tokens.length !== 3) return null;
|
|
153
|
+
|
|
154
|
+
const alpha = parseAlpha(alphaParts.length ? alphaParts : []);
|
|
155
|
+
if (alpha === null || alpha < 1) return null;
|
|
156
|
+
|
|
157
|
+
const hue = Number(tokens[0].replace(/deg$/i, ""));
|
|
158
|
+
const saturation = parseNumber(tokens[1]);
|
|
159
|
+
const lightness = parseNumber(tokens[2]);
|
|
160
|
+
if (!Number.isFinite(hue) || saturation === null || lightness === null) return null;
|
|
161
|
+
|
|
162
|
+
const [r, g, b] = hslToRgb(hue, saturation, lightness);
|
|
163
|
+
return srgbToOklab(r, g, b);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @returns {Oklab | null} */
|
|
167
|
+
function parseOklch(raw) {
|
|
168
|
+
const match = /^oklch\(([\s\S]+)\)$/i.exec(raw);
|
|
169
|
+
if (!match) return null;
|
|
170
|
+
|
|
171
|
+
const [body, ...alphaParts] = match[1].split("/");
|
|
172
|
+
const tokens = body
|
|
173
|
+
.trim()
|
|
174
|
+
.split(/[\s,]+/)
|
|
175
|
+
.map((token) => token.trim())
|
|
176
|
+
.filter(Boolean);
|
|
177
|
+
if (tokens.length !== 3) return null;
|
|
178
|
+
|
|
179
|
+
const alpha = parseAlpha(alphaParts.length ? alphaParts : []);
|
|
180
|
+
if (alpha === null || alpha < 1) return null;
|
|
181
|
+
|
|
182
|
+
const lightness = parseNumber(tokens[0]);
|
|
183
|
+
const chroma = parseNumber(tokens[1]);
|
|
184
|
+
const hue = Number(tokens[2].replace(/deg$/i, ""));
|
|
185
|
+
if (lightness === null || chroma === null || !Number.isFinite(hue)) return null;
|
|
186
|
+
if (lightness < 0 || lightness > 1 || chroma < 0) return null;
|
|
187
|
+
|
|
188
|
+
const radians = (hue * Math.PI) / 180;
|
|
189
|
+
return {
|
|
190
|
+
l: lightness,
|
|
191
|
+
a: chroma * Math.cos(radians),
|
|
192
|
+
b: chroma * Math.sin(radians),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 解析任意 CSS 颜色为 OKLab;无法判定时返回 null。
|
|
198
|
+
* @param {unknown} input
|
|
199
|
+
* @returns {Oklab | null}
|
|
200
|
+
*/
|
|
201
|
+
export function parseColor(input) {
|
|
202
|
+
if (typeof input !== "string") return null;
|
|
203
|
+
const raw = input.trim().toLowerCase();
|
|
204
|
+
if (!raw) return null;
|
|
205
|
+
if (raw === "transparent" || raw === "currentcolor" || raw === "none") return null;
|
|
206
|
+
if (raw.startsWith("color-mix(")) return null;
|
|
207
|
+
|
|
208
|
+
const named = NAMED[raw];
|
|
209
|
+
if (named) return srgbToOklab(named[0], named[1], named[2]);
|
|
210
|
+
|
|
211
|
+
if (raw.startsWith("#")) return parseHex(raw);
|
|
212
|
+
if (raw.startsWith("rgb")) return parseRgb(raw);
|
|
213
|
+
if (raw.startsWith("hsl")) return parseHsl(raw);
|
|
214
|
+
if (raw.startsWith("oklch")) return parseOklch(raw);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* OKLab 距离(×100,便于用 2/10 这类阈值表达)。
|
|
220
|
+
* @param {Oklab} left
|
|
221
|
+
* @param {Oklab} right
|
|
222
|
+
*/
|
|
223
|
+
export function deltaE(left, right) {
|
|
224
|
+
const dl = left.l - right.l;
|
|
225
|
+
const da = left.a - right.a;
|
|
226
|
+
const db = left.b - right.b;
|
|
227
|
+
return Math.sqrt(dl * dl + da * da + db * db) * 100;
|
|
228
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ztheme-cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Ztheme 主题 CLI
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Ztheme 主题 CLI:从站点拉取主题 CSS 变量,并在仓库里扫设计漂移",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ztheme": "ztheme.mjs"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"ztheme.mjs",
|
|
11
|
+
"audit.mjs",
|
|
12
|
+
"color.mjs",
|
|
13
|
+
"rules.mjs",
|
|
11
14
|
"README.md",
|
|
12
15
|
"LICENSE"
|
|
13
16
|
],
|
|
14
17
|
"engines": {
|
|
15
18
|
"node": ">=18"
|
|
16
19
|
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"registry": "https://registry.npmjs.org"
|
|
22
|
+
},
|
|
17
23
|
"license": "MIT",
|
|
18
24
|
"repository": {
|
|
19
25
|
"type": "git",
|
package/rules.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目规则(.ztheme/rules.json):校验与判定。
|
|
3
|
+
*
|
|
4
|
+
* 规则只表达阈值(圆角上限、间距基准),不表达严重级别——severity 只放在
|
|
5
|
+
* .ztheme/audit.json 一处,避免两个文件都能改级别时出现「谁生效」的争论。
|
|
6
|
+
*
|
|
7
|
+
* 零依赖、纯函数、无 IO:CLI 负责读文件,这里只负责判断。
|
|
8
|
+
*/
|
|
9
|
+
export const RULES_FILE = ".ztheme/rules.json";
|
|
10
|
+
export const RULES_SCHEMA_VERSION = 1;
|
|
11
|
+
|
|
12
|
+
export const RULE_RADIUS = "no-excessive-radius";
|
|
13
|
+
export const RULE_SPACING = "no-off-grid-spacing";
|
|
14
|
+
|
|
15
|
+
const KNOWN_KEYS = ["schemaVersion", "radius", "spacing"];
|
|
16
|
+
|
|
17
|
+
/** Tailwind 默认圆角刻度(rem)。用于在越界时给出「最近的合法档」。 */
|
|
18
|
+
const RADIUS_TIERS = [
|
|
19
|
+
["sm", 0.125],
|
|
20
|
+
["md", 0.375],
|
|
21
|
+
["lg", 0.5],
|
|
22
|
+
["xl", 0.75],
|
|
23
|
+
["2xl", 1],
|
|
24
|
+
["3xl", 1.5],
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/** 受间距政策约束的 Tailwind 前缀。布局尺寸(w/h/size)与字号刻意不在内。 */
|
|
28
|
+
const SPACING_PREFIX =
|
|
29
|
+
/^(?:p|px|py|pt|pr|pb|pl|m|mx|my|mt|mr|mb|ml|gap|gap-x|gap-y|space-x|space-y)$/;
|
|
30
|
+
|
|
31
|
+
const fmtRem = (value) => String(Number(value.toFixed(4))) + "rem";
|
|
32
|
+
|
|
33
|
+
/** 单个值 → rem。只认 px/rem/0;负值、百分比、calc/var/em 一律 null(不猜)。 */
|
|
34
|
+
function remOf(value) {
|
|
35
|
+
const raw = value.trim();
|
|
36
|
+
if (raw === "0") return 0;
|
|
37
|
+
let match = raw.match(/^(\d*\.?\d+)rem$/i);
|
|
38
|
+
if (match) return parseFloat(match[1]);
|
|
39
|
+
match = raw.match(/^(\d*\.?\d+)px$/i);
|
|
40
|
+
if (match) return parseFloat(match[1]) / 16;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 单个值 → px(16px = 1rem)。规则同 remOf。 */
|
|
45
|
+
function pxOf(value) {
|
|
46
|
+
const rem = remOf(value);
|
|
47
|
+
return rem === null ? null : Math.round(rem * 16 * 1e6) / 1e6;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const splitValues = (value) =>
|
|
51
|
+
String(value)
|
|
52
|
+
.split("_")
|
|
53
|
+
.map((part) => part.trim())
|
|
54
|
+
.filter(Boolean);
|
|
55
|
+
|
|
56
|
+
/** 多值(如 `7px_8px`)取最大;任一值判不了就整体判不了。 */
|
|
57
|
+
export function radiusRemOf(value) {
|
|
58
|
+
let max = null;
|
|
59
|
+
for (const part of splitValues(value)) {
|
|
60
|
+
const rem = remOf(part);
|
|
61
|
+
if (rem === null) return null;
|
|
62
|
+
if (max === null || rem > max) max = rem;
|
|
63
|
+
}
|
|
64
|
+
return max;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function spacingPxOf(value) {
|
|
68
|
+
let max = null;
|
|
69
|
+
for (const part of splitValues(value)) {
|
|
70
|
+
const px = pxOf(part);
|
|
71
|
+
if (px === null) return null;
|
|
72
|
+
if (max === null || px > max) max = px;
|
|
73
|
+
}
|
|
74
|
+
return max;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 越界时建议「允许范围内最大的那一档」,拼回原前缀(rounded-t → rounded-t-lg)。 */
|
|
78
|
+
export function nearestRadiusClass(prefix, maxRem) {
|
|
79
|
+
const allowed = RADIUS_TIERS.filter(([, rem]) => rem <= maxRem + 1e-9);
|
|
80
|
+
if (!allowed.length) return prefix + "-none";
|
|
81
|
+
return prefix + "-" + allowed[allowed.length - 1][0];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 间距按基准单位就近取整,拼回原前缀(px → px-3)。 */
|
|
85
|
+
export function nearestSpacingClass(prefix, px, baseUnit) {
|
|
86
|
+
return prefix + "-" + Math.max(0, Math.round(px / baseUnit));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 政策判定。
|
|
91
|
+
* - `{ applies: false }`:这条值不归政策管(或判不了),调用方继续走通用规则。
|
|
92
|
+
* - `{ applies: true, ok: true }`:合规,调用方应静默(规则的价值就是降噪)。
|
|
93
|
+
* - `{ applies: true, ok: false, ... }`:越界,调用方按 `rule` 报。
|
|
94
|
+
*/
|
|
95
|
+
export function classifySize(prefix, value, policy) {
|
|
96
|
+
if (!policy) return { applies: false };
|
|
97
|
+
|
|
98
|
+
if (policy.radius && /^rounded(?:-|$)/.test(prefix)) {
|
|
99
|
+
const rem = radiusRemOf(value);
|
|
100
|
+
if (rem === null) return { applies: false };
|
|
101
|
+
if (rem <= policy.radius.maxRem + 1e-9) return { applies: true, ok: true };
|
|
102
|
+
return {
|
|
103
|
+
applies: true,
|
|
104
|
+
ok: false,
|
|
105
|
+
rule: RULE_RADIUS,
|
|
106
|
+
expected: "≤" + fmtRem(policy.radius.maxRem),
|
|
107
|
+
actual: fmtRem(rem),
|
|
108
|
+
suggestion: nearestRadiusClass(prefix, policy.radius.maxRem),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (policy.spacing && SPACING_PREFIX.test(prefix)) {
|
|
113
|
+
const px = spacingPxOf(value);
|
|
114
|
+
if (px === null) return { applies: false };
|
|
115
|
+
const quotient = px / policy.spacing.baseUnit;
|
|
116
|
+
if (Math.abs(quotient - Math.round(quotient)) < 1e-9) return { applies: true, ok: true };
|
|
117
|
+
return {
|
|
118
|
+
applies: true,
|
|
119
|
+
ok: false,
|
|
120
|
+
rule: RULE_SPACING,
|
|
121
|
+
expected: policy.spacing.baseUnit + " 的倍数",
|
|
122
|
+
actual: px + "px",
|
|
123
|
+
suggestion: nearestSpacingClass(prefix, px, policy.spacing.baseUnit),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { applies: false };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function validateRules(parsed) {
|
|
131
|
+
const warnings = [];
|
|
132
|
+
const errors = [];
|
|
133
|
+
const policy = { radius: null, spacing: null };
|
|
134
|
+
|
|
135
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
136
|
+
return { policy, warnings, errors: ["rules 必须是对象"] };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (const key of Object.keys(parsed)) {
|
|
140
|
+
if (!KNOWN_KEYS.includes(key)) warnings.push("未知配置项 " + key + "(已忽略)");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (parsed.schemaVersion !== undefined && parsed.schemaVersion !== RULES_SCHEMA_VERSION) {
|
|
144
|
+
warnings.push(
|
|
145
|
+
"schemaVersion 是 " + parsed.schemaVersion + ",本工具只认识 " + RULES_SCHEMA_VERSION
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (parsed.radius !== undefined) {
|
|
150
|
+
if (!parsed.radius || typeof parsed.radius !== "object" || Array.isArray(parsed.radius)) {
|
|
151
|
+
errors.push("radius 必须是对象");
|
|
152
|
+
} else {
|
|
153
|
+
const maxRem = parsed.radius.maxRem;
|
|
154
|
+
if (maxRem !== undefined) {
|
|
155
|
+
if (typeof maxRem !== "number" || !Number.isFinite(maxRem) || maxRem <= 0) {
|
|
156
|
+
errors.push("radius.maxRem 必须是大于 0 的数字");
|
|
157
|
+
} else {
|
|
158
|
+
policy.radius = { maxRem };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const key of Object.keys(parsed.radius)) {
|
|
162
|
+
if (key !== "maxRem") warnings.push("未知配置项 radius." + key + "(已忽略)");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (parsed.spacing !== undefined) {
|
|
168
|
+
if (!parsed.spacing || typeof parsed.spacing !== "object" || Array.isArray(parsed.spacing)) {
|
|
169
|
+
errors.push("spacing 必须是对象");
|
|
170
|
+
} else {
|
|
171
|
+
const baseUnit = parsed.spacing.baseUnit;
|
|
172
|
+
if (baseUnit !== undefined) {
|
|
173
|
+
if (!Number.isInteger(baseUnit) || baseUnit <= 0) {
|
|
174
|
+
errors.push("spacing.baseUnit 必须是大于 0 的整数");
|
|
175
|
+
} else {
|
|
176
|
+
policy.spacing = { baseUnit };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
for (const key of Object.keys(parsed.spacing)) {
|
|
180
|
+
if (key !== "baseUnit") warnings.push("未知配置项 spacing." + key + "(已忽略)");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return { policy, warnings, errors };
|
|
186
|
+
}
|