cardbuddy 0.15.0 → 0.16.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/dist/preview-editor/assets/index-BkbBxDTT.css +1 -0
- package/dist/preview-editor/assets/{index-CIIfMlwI.js → index-Bro07DTa.js} +91 -88
- package/dist/preview-editor/index.html +2 -2
- package/dist/vendored/card-editor/runtime/adapter.js +2 -2
- package/dist/vendored/mcp/client.mjs +1 -1
- package/dist/vendored/server/core/ai-chat.js +251 -80
- package/dist/vendored/server/core/cardValidate.js +16 -5
- package/dist/vendored/skills/card-skill-trainer/SKILL.md +61 -6
- package/dist/vendored/skills/card-skill-trainer/scripts/diagnose_case.mjs +14 -82
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/diagnosis.mjs +207 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/layout-correction-sim.mjs +62 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/paradigm-router.mjs +76 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/pixel-worker-runner.mjs +31 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/pixel-worker.mjs +138 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/scoring.mjs +24 -20
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/telemetry.mjs +46 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/plan_next_round.mjs +4 -1
- package/dist/vendored/skills/card-skill-trainer/scripts/run_round.mjs +279 -90
- package/dist/vendored/skills/card-skill-trainer/scripts/score_round.mjs +74 -2
- package/dist/vendored/skills/card-skill-trainer/scripts/sink_rules.mjs +127 -0
- package/dist/vendored/skills/dsl-card-generator/SKILL.md +93 -27
- package/dist/vendored/skills/dsl-card-generator/references/dsl_structure.md +1 -15
- package/dist/vendored/skills/dsl-card-generator/references/expression_engine.md +11 -20
- package/dist/vendored/skills/dsl-card-generator/references/generation_pitfalls.md +169 -44
- package/dist/vendored/skills/dsl-card-generator/references/ir-format.md +87 -3
- package/dist/vendored/skills/dsl-card-generator/references/iteration_protocol.md +35 -6
- package/dist/vendored/skills/dsl-card-generator/references/quickref.md +28 -27
- package/dist/vendored/skills/dsl-card-generator/references/recipes.md +30 -8
- package/dist/vendored/skills/dsl-card-generator/references/rules.md +3 -2
- package/dist/vendored/skills/dsl-card-generator/references/scripts_reference.md +5 -2
- package/dist/vendored/skills/dsl-card-generator/references/slices_convention.md +2 -3
- package/dist/vendored/skills/dsl-card-generator/references/spec_to_schema_patterns.md +1 -4
- package/dist/vendored/skills/dsl-card-generator/scripts/add_component.mjs +5 -14
- package/dist/vendored/skills/dsl-card-generator/scripts/autofix_schema.py +88 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/check_fidelity.mjs +143 -42
- package/dist/vendored/skills/dsl-card-generator/scripts/check_topology.py +0 -35
- package/dist/vendored/skills/dsl-card-generator/scripts/expand_ir.mjs +99 -53
- package/dist/vendored/skills/dsl-card-generator/scripts/gate.mjs +5 -2
- package/dist/vendored/skills/dsl-card-generator/scripts/iterate.mjs +388 -29
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/component_contract.mjs +315 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/layout-tokens.mjs +1 -1
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/paths.mjs +23 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/paths.py +0 -37
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/python.mjs +99 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/adaptive-width.mjs +105 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/bindings.mjs +260 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/expr.mjs +52 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/image.mjs +96 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/registry.mjs +166 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/structure.mjs +127 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/walk.mjs +61 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/scope_alias.mjs +125 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_assemble.mjs +325 -41
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_extract.mjs +112 -6
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_shared.mjs +0 -6
- package/dist/vendored/skills/dsl-card-generator/scripts/lint_card.mjs +119 -78
- package/dist/vendored/skills/dsl-card-generator/scripts/preflight.mjs +48 -50
- package/dist/vendored/skills/dsl-card-generator/scripts/readiness.mjs +634 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/register_card_template.mjs +5 -8
- package/dist/vendored/skills/dsl-card-generator/scripts/route_input.mjs +5 -10
- package/dist/vendored/skills/dsl-card-generator/scripts/spec_audit.mjs +122 -8
- package/dist/vendored/skills/dsl-card-generator/scripts/v3_regression.mjs +3 -1
- package/dist/vendored/skills/dsl-card-generator/scripts/validate_schema.py +23 -15
- package/dist/vendored/skills/shared/exit-codes.md +79 -0
- package/dist/vendored/skills/shared/spec-contract.md +118 -0
- package/dist/vendored/skills/sketch-spec-to-card/SKILL.md +26 -9
- package/dist/vendored/skills/sketch-spec-to-card/references/spec-schema.md +3 -3
- package/dist/vendored/skills/sketch-spec-to-card/scripts/build_prompt.py +0 -8
- package/dist/vendored/skills/sketch-spec-to-card/scripts/cluster_states.py +14 -25
- package/dist/vendored/skills/sketch-spec-to-card/scripts/parse_meaxure.py +91 -47
- package/dist/vendored/skills/sketch-spec-to-card/scripts/png_utils.py +0 -5
- package/dist/vendored/skills/sketch-spec-to-card/scripts/test_text_only_artboard.py +75 -15
- package/dist/vendored/skills/sketch-spec-to-card/scripts/vision.py +40 -34
- package/package.json +1 -1
- package/dist/preview-editor/assets/index-DQn0zQBP.css +0 -1
- package/dist/vendored/skills/card-skill-trainer/scripts/test_missing_slice.py +0 -122
- package/dist/vendored/skills/dsl-card-generator/scripts/analyze_component_usage.mjs +0 -153
|
@@ -324,7 +324,21 @@ export function extractSemantics(spec, cardIndex = 0, opts = {}) {
|
|
|
324
324
|
&& (tr.x || 0) >= left - 24 && (tr.x || 0) <= left + 24
|
|
325
325
|
&& (ts(text).fontSize || 0) >= 14
|
|
326
326
|
}).sort((a, b) => (rect(b).y || 0) - (rect(a).y || 0))
|
|
327
|
-
|
|
327
|
+
let labelEl = labelCands[0] || null
|
|
328
|
+
let _sideLabel = false
|
|
329
|
+
if (!labelEl) {
|
|
330
|
+
// Side label: text at same y (vertically overlapping), to the LEFT of the group
|
|
331
|
+
const _grpCY = top + (bottom - top) / 2
|
|
332
|
+
const _sideCands = texts.filter((text) => {
|
|
333
|
+
const tr = rect(text)
|
|
334
|
+
const tcY = (tr.y || 0) + (tr.height || 0) / 2
|
|
335
|
+
return !memberTexts.has(text)
|
|
336
|
+
&& Math.abs(tcY - _grpCY) <= Math.max(15, (bottom - top) * 0.6)
|
|
337
|
+
&& (tr.x || 0) + (tr.width || 0) <= left + 4
|
|
338
|
+
&& (ts(text).fontSize || 0) >= 13
|
|
339
|
+
}).sort((a, b) => (rect(a).x || 0) - (rect(b).x || 0))
|
|
340
|
+
if (_sideCands[0]) { labelEl = _sideCands[0]; _sideLabel = true }
|
|
341
|
+
}
|
|
328
342
|
const labelStyle = labelEl ? ts(labelEl) : null
|
|
329
343
|
groups.push({
|
|
330
344
|
x: left,
|
|
@@ -338,9 +352,12 @@ export function extractSemantics(spec, cardIndex = 0, opts = {}) {
|
|
|
338
352
|
fontSize: labelStyle.fontSize || 16,
|
|
339
353
|
fontWeight: labelStyle.fontWeight || '500',
|
|
340
354
|
height: rect(labelEl).height || (labelStyle.fontSize || 16) * 1.4,
|
|
355
|
+
x: rect(labelEl).x || 0,
|
|
356
|
+
y: rect(labelEl).y || 0,
|
|
357
|
+
width: rect(labelEl).width || 0,
|
|
341
358
|
} : null,
|
|
342
359
|
members,
|
|
343
|
-
sourceLabelEl: labelEl,
|
|
360
|
+
sourceLabelEl: labelEl, sideLabel: _sideLabel,
|
|
344
361
|
sourceTextEls: members.map((m) => m.sourceTextEl).filter(Boolean),
|
|
345
362
|
})
|
|
346
363
|
segment = []
|
|
@@ -589,7 +606,64 @@ export function extractSemantics(spec, cardIndex = 0, opts = {}) {
|
|
|
589
606
|
})
|
|
590
607
|
}
|
|
591
608
|
|
|
592
|
-
//
|
|
609
|
+
// 空间散布的图表顶点标签(如雷达图五边形周围的类别 pill):
|
|
610
|
+
// 动作按钮必然横向成排(y-span ≤ 30px),若 ≥3 个候选按钮的 y 跨度 > 40px
|
|
611
|
+
// 且分布在 ≥3 个 y 带,判为空间散布的图表顶点标签而非按钮排。
|
|
612
|
+
// 检出后:收集这些 pill + 其周围的文本/形状为一个 vertexRegion(AbsoluteLayout 整块渲染),
|
|
613
|
+
// 从 buttons / auxTexts / postAmountTexts / isolatedBlocks 等路径排除以防重影。
|
|
614
|
+
let vertexClusters = null
|
|
615
|
+
const _vertexConsumedEls = new Set()
|
|
616
|
+
if (buttons.length >= 3) {
|
|
617
|
+
const ys = buttons.map((b) => b.y || 0)
|
|
618
|
+
const xs = buttons.map((b) => b.x || 0)
|
|
619
|
+
const ySpan = Math.max(...ys) - Math.min(...ys)
|
|
620
|
+
const xSpan = Math.max(...xs) - Math.min(...xs)
|
|
621
|
+
if (ySpan > 40 && xSpan > 80) {
|
|
622
|
+
const yBands = new Set(ys.map((y) => Math.floor(y / 20)))
|
|
623
|
+
if (yBands.size >= 3) {
|
|
624
|
+
vertexClusters = buttons.map((btn, bi) => {
|
|
625
|
+
const bx = btn.x || 0, by = btn.y || 0
|
|
626
|
+
const bw = btn.width || 0, bh = btn.height || 0
|
|
627
|
+
const pillShape = buttonShapeSorted[bi]
|
|
628
|
+
if (pillShape) _vertexConsumedEls.add(pillShape)
|
|
629
|
+
if (btn.sourceEl) _vertexConsumedEls.add(btn.sourceEl)
|
|
630
|
+
const clusterEls = content.filter((e) => {
|
|
631
|
+
if (e === btn.sourceEl || (pillShape && e === pillShape)) return false
|
|
632
|
+
if (_vertexConsumedEls.has(e)) return false
|
|
633
|
+
const r = rect(e)
|
|
634
|
+
const ex = (r.x || 0) + (r.width || 0) / 2
|
|
635
|
+
const ey = (r.y || 0) + (r.height || 0) / 2
|
|
636
|
+
return ex >= bx - 15 && ex <= bx + bw + 15
|
|
637
|
+
&& ey >= by - 8 && ey <= by + bh + 35
|
|
638
|
+
})
|
|
639
|
+
clusterEls.forEach((e) => _vertexConsumedEls.add(e))
|
|
640
|
+
return {
|
|
641
|
+
pill: {
|
|
642
|
+
text: btn.text, color: btn.color, fontSize: btn.fontSize,
|
|
643
|
+
fontWeight: btn.fontWeight || '400',
|
|
644
|
+
fillColor: btn.fillColor, radius: btn.radius,
|
|
645
|
+
shape: pillShape, sourceEl: btn.sourceEl,
|
|
646
|
+
},
|
|
647
|
+
texts: clusterEls.filter((e) => textOf(e)),
|
|
648
|
+
shapes: clusterEls.filter((e) => !textOf(e)),
|
|
649
|
+
x: bx, y: by, width: bw, height: bh,
|
|
650
|
+
}
|
|
651
|
+
})
|
|
652
|
+
buttons.length = 0
|
|
653
|
+
for (let ti = texts.length - 1; ti >= 0; ti--)
|
|
654
|
+
if (_vertexConsumedEls.has(texts[ti])) texts.splice(ti, 1)
|
|
655
|
+
for (let si = shapes.length - 1; si >= 0; si--)
|
|
656
|
+
if (_vertexConsumedEls.has(shapes[si])) shapes.splice(si, 1)
|
|
657
|
+
for (let ci2 = content.length - 1; ci2 >= 0; ci2--)
|
|
658
|
+
if (_vertexConsumedEls.has(content[ci2])) content.splice(ci2, 1)
|
|
659
|
+
for (let bs2 = buttonShapes.length - 1; bs2 >= 0; bs2--)
|
|
660
|
+
if (_vertexConsumedEls.has(buttonShapes[bs2])) buttonShapes.splice(bs2, 1)
|
|
661
|
+
}
|
|
662
|
+
for (let si3 = slices.length - 1; si3 >= 0; si3--)
|
|
663
|
+
if (_vertexConsumedEls.has(slices[si3])) slices.splice(si3, 1)
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
// 重复面板组(同尺寸壳纵向等距重复、壳内结构同构)→ 面板列表 ——
|
|
593
667
|
// 纯几何识别,无任何业务词:
|
|
594
668
|
// ① ≥2 个同尺寸(±4px)带填充/渐变的壳(非按钮、非全卡背景)
|
|
595
669
|
// ② 纵向 pitch 一致(±8px)
|
|
@@ -2365,6 +2439,31 @@ export function extractSemantics(spec, cardIndex = 0, opts = {}) {
|
|
|
2365
2439
|
.sort((a, b) => a.y - b.y || a.x - b.x)
|
|
2366
2440
|
// 浮动装饰切片回收:isolatedBlocks 先于 orphanSlices 消费切片(卡头月亮等贴缘叠装饰),
|
|
2367
2441
|
// 命中「与文本带竖直重叠 + 贴卡缘」者改走绝对定位叠层,不占流式行高。
|
|
2442
|
+
// Chart center media (radar/ring vector group): when vertexClusters exist,
|
|
2443
|
+
// pull it from isolatedBlocks into vertexClusters.chartMedia so assemble can
|
|
2444
|
+
// render both in the SAME AbsoluteLayout (shared coordinate system).
|
|
2445
|
+
if (vertexClusters && vertexClusters.length >= 3) {
|
|
2446
|
+
const vcXs = vertexClusters.map((vc) => vc.x || 0)
|
|
2447
|
+
const vcXRights = vertexClusters.map((vc, i) => (vc.x || 0) + (vc.width || 88))
|
|
2448
|
+
const vcYs = vertexClusters.map((vc) => vc.y || 0)
|
|
2449
|
+
const vcYBottoms = vertexClusters.map((vc, i) => (vc.y || 0) + (vc.height || 30))
|
|
2450
|
+
const vcCx = (Math.min(...vcXs) + Math.max(...vcXRights)) / 2
|
|
2451
|
+
const vcCy = (Math.min(...vcYs) + Math.max(...vcYBottoms)) / 2
|
|
2452
|
+
for (let ib = isolatedBlocks.length - 1; ib >= 0; ib--) {
|
|
2453
|
+
const blk = isolatedBlocks[ib]
|
|
2454
|
+
const bw = blk.width || 0, bh = blk.height || 0
|
|
2455
|
+
if (bw < 50 || bh < 50 || bw > 200 || bh > 200) continue
|
|
2456
|
+
if (Math.abs(bw - bh) > 30) continue
|
|
2457
|
+
const bcx = (blk.x || 0) + bw / 2
|
|
2458
|
+
const bcy = (blk.y || 0) + bh / 2
|
|
2459
|
+
if (Math.hypot(bcx - vcCx, bcy - vcCy) > 80) continue
|
|
2460
|
+
vertexClusters.chartMedia = blk
|
|
2461
|
+
isolatedBlocks.splice(ib, 1)
|
|
2462
|
+
_vertexConsumedEls.add(blk.element)
|
|
2463
|
+
break
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2368
2467
|
const floatDecos = []
|
|
2369
2468
|
{
|
|
2370
2469
|
const cRd = rect(card)
|
|
@@ -3991,7 +4090,12 @@ const optionTextStrings = new Set([...optionTextSet].map((t) => textOf(t)))
|
|
|
3991
4090
|
artboardType: spec.artboardType || 'card',
|
|
3992
4091
|
cardRect: rect(card), // 卡片容器几何(用于底部留白/顶部留白几何推导)
|
|
3993
4092
|
cardFill: card.cardFill || null,
|
|
3994
|
-
|
|
4093
|
+
// 契约 skills/shared/spec-contract.md §cards[].mask.radius:
|
|
4094
|
+
// null = 上游没找到带圆角的卡壳(_card_mask_info 返回 (None, fill)),
|
|
4095
|
+
// 下游兜底点在 v3_assemble.mjs 的 `sem.cardRadius || T.radius('card')`(契约规定的默认圆角)。
|
|
4096
|
+
// 取用必须用 ?? 而非 ||:`radius[0] === 0` 是合法值(真·直角卡),用 || 会被吞成 null
|
|
4097
|
+
// 从而错误地套上默认圆角。(存量数据无此值,属防御性修正。)
|
|
4098
|
+
cardRadius: card.mask?.radius?.[0] ?? null,
|
|
3995
4099
|
tabs, buttons, optionGroups, primaryAmount, subAmounts, auxTexts, postAmountTexts, tabY, badgeRows,
|
|
3996
4100
|
topTintBlobs,
|
|
3997
4101
|
listTitle, sampleItems, allItems, viewMore, collapseBtn, countdown, topDecoration, formRows, midCluster: midCluster && (midCluster.items || []).length >= 2 && !(midCluster.items || []).every((it) => optionTextStrings.has(it.text)) ? midCluster : null, bindings,
|
|
@@ -4004,11 +4108,13 @@ const optionTextStrings = new Set([...optionTextSet].map((t) => textOf(t)))
|
|
|
4004
4108
|
panelRows,
|
|
4005
4109
|
titleUnderlines,
|
|
4006
4110
|
subAmountPanel,
|
|
4007
|
-
orphanSlices
|
|
4111
|
+
orphanSlices: (orphanSlices || []).filter((s) => !_vertexConsumedEls.has(s)),
|
|
4112
|
+
floatDecos: (floatDecos || []).filter((fd) => !_vertexConsumedEls.has(fd)),
|
|
4008
4113
|
thinShellRows, thinShellStrips, shellRightColumns,
|
|
4009
4114
|
gradientPanels, panelGroup,
|
|
4010
4115
|
richBlocks,
|
|
4011
4116
|
chartClusters,
|
|
4117
|
+
vertexClusters,
|
|
4012
4118
|
shellLayers,
|
|
4013
4119
|
contentBounds: (() => {
|
|
4014
4120
|
const cardWidth = rect(card).width || 0
|
|
@@ -4044,7 +4150,7 @@ const optionTextStrings = new Set([...optionTextSet].map((t) => textOf(t)))
|
|
|
4044
4150
|
(rect(card).x || 0) + (rect(card).width || 0),
|
|
4045
4151
|
}
|
|
4046
4152
|
})(),
|
|
4047
|
-
slices: slices.map((s) => s),
|
|
4153
|
+
slices: slices.filter((s) => !_vertexConsumedEls.has(s)).map((s) => s),
|
|
4048
4154
|
slicesExports: spec.slices || [],
|
|
4049
4155
|
allTexts: texts.map((t) => ({ text: textOf(t), ...ts(t), sourceEl: t })),
|
|
4050
4156
|
}
|
|
@@ -422,12 +422,6 @@ export function imageOrPlaceholder(sliceEl, specSlices) {
|
|
|
422
422
|
return img || placeholderImage(sliceEl)
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
/** 在 sem.slices(切片元素数组)中按导出相对路径反查切片元素(用于取 rect 尺寸) */
|
|
426
|
-
export function findSliceElByExport(sem, exportRel) {
|
|
427
|
-
if (!exportRel) return null
|
|
428
|
-
const base = stripScale(String(exportRel).split('/').pop())
|
|
429
|
-
return (sem.slices || []).find((s) => stripScale(String(s.name || '').split('/').pop()) === base) || null
|
|
430
|
-
}
|
|
431
425
|
/** 把金额字符串(如 "¥5,638.00" / "-¥23.50")解析为数字 */
|
|
432
426
|
export function parseAmount(text) {
|
|
433
427
|
if (!text) return null
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* 15. 切图引用含 URL 保留字符(r31b):`# ? % & +` 会被浏览器当 fragment/query 截掉 → 图片静默不显示(R31 的补充,R31 只拦空格)。
|
|
26
26
|
* 16. 横向流父容器里的容器子节点未写 rect.width + flexShrink:0(r22b):渲染器按 component-meta 默认「100%」出 → 吃掉整行,同排兄弟被压成 0 宽或被顶出卡外。
|
|
27
27
|
* 17. 切图引用在 src/slices 里没有对应文件(r31c):渲染时 404,图片位置空白且控制台零报错 —— R31(空格)/R31b(保留字符)之外的第三种「引用与磁盘名不同源」。
|
|
28
|
+
* 18. 组件契约(r28 / r28b-*):属性键 / 样式组 / 样式子键必须在 component-meta.json + style-meta.json 白名单内 —— 不存在的键被运行时**整条静默丢弃**(Image 的键写成 image 而非 value ⇒ 图片变破图,而四道闸全绿)。
|
|
28
29
|
*
|
|
29
30
|
* 用法:
|
|
30
31
|
* node lint_card.mjs --id <cardId> # 体检单张卡
|
|
@@ -44,6 +45,12 @@ import { fileURLToPath } from 'node:url'
|
|
|
44
45
|
import { cardsDir, cardSchemaPath, cardDataPath, readJson, metaDir, slicesDir } from './lib/paths.mjs'
|
|
45
46
|
import { buildContentIndex, buildSliceFileIndex, checkSliceName, collectSliceRefStrings, duplicatePeers, findUrlReservedChars, isRemoteSliceRef, resolveSliceRefOnDisk, sliceNameFromRef } from './lib/slice_dedupe.mjs'
|
|
46
47
|
import { collectRowChildNoWidth } from './lib/layout_rules.mjs'
|
|
48
|
+
import { collectFullwidthFixedPx } from './lib/rules/adaptive-width.mjs'
|
|
49
|
+
import { loadContract, collectContractViolations, describeViolation } from './lib/component_contract.mjs'
|
|
50
|
+
import { collectImageValueFrom, collectImageNoHeight } from './lib/rules/image.mjs'
|
|
51
|
+
import { collectExprNoMathRound, numericHint } from './lib/rules/expr.mjs'
|
|
52
|
+
import { collectRepeaterDefects, collectStaticTileExpansion, collectArrayConsumption } from './lib/rules/bindings.mjs'
|
|
53
|
+
import { collectSlotMultiChildren, collectNullChildren, collectDuplicateStyleChildren, collectAlertDataWholeState, collectIconNoRect, collectRootFixedHeight } from './lib/rules/structure.mjs'
|
|
47
54
|
|
|
48
55
|
// src/slices 内容索引(sha256 → 文件名)进程内只建一次,--all 体检全量卡时复用
|
|
49
56
|
let SLICE_CONTENT_INDEX = null
|
|
@@ -252,6 +259,25 @@ export function lint(schema, data) {
|
|
|
252
259
|
const view = schema.view
|
|
253
260
|
if (!view) return [{ severity: 'error', code: 'no-view', message: 'schema 没有 view 字段' }]
|
|
254
261
|
|
|
262
|
+
// 0. 组件契约:属性键 / 样式组 / 样式子键必须落在白名单内(唯一来源 component-meta.json + style-meta.json)。
|
|
263
|
+
//
|
|
264
|
+
// 2026-09-24 事故:模型给 Image 写 itemKey:"image",而该组件元数据里图片地址的键**只有 value**。
|
|
265
|
+
// 运行时按 itemKey 绑定组件 props,不存在的键被**整条静默丢弃** ⇒ value 为空 ⇒ 图片渲染成破图。
|
|
266
|
+
// 而 validate / lint / preflight / elements.missing 当时**全部放行**(preflight 的 Check 3/5 都用
|
|
267
|
+
// getProp(n,'value'),取不到就 continue —— 键写错反而把检查链短路了)。
|
|
268
|
+
// 全仓 82 处 Image 里 81 处写 value,唯一写 image 的就是这张卡 ⇒ 模型会偶发编造键名,必须机械兜底。
|
|
269
|
+
{
|
|
270
|
+
const contract = loadContract({ metaDir })
|
|
271
|
+
for (const v of collectContractViolations(schema, contract)) {
|
|
272
|
+
out.push({
|
|
273
|
+
severity: v.severity,
|
|
274
|
+
code: v.code === 'unknown-class' ? 'r28-unknown-class' : `r28b-${v.code}`,
|
|
275
|
+
componentId: v.componentId,
|
|
276
|
+
message: describeViolation(v),
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
255
281
|
// 1. 脚手架前缀残留("示例"是 scaffold_card.mjs 默认占位文本)
|
|
256
282
|
if (data && typeof data === 'object') {
|
|
257
283
|
for (const [k, v] of Object.entries(data)) {
|
|
@@ -615,16 +641,9 @@ export function lint(schema, data) {
|
|
|
615
641
|
}
|
|
616
642
|
|
|
617
643
|
// ── R61: 静态文案 / 字典默认值含疑似运行期数字(rules.md §十四,提醒级 WARN)──
|
|
618
|
-
//
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
{ re: /[¥¥]\s*\d+(\.\d+)?/, label: '货币符+数字' },
|
|
622
|
-
{ re: /\d+(\.\d+)?\s*(元|笔|次|个|条)/, label: '数字+单位词' },
|
|
623
|
-
]
|
|
624
|
-
const numericHit = (str) => {
|
|
625
|
-
for (const { re, label } of NUMERIC_LITERAL_PATTERNS) if (re.test(str)) return label
|
|
626
|
-
return null
|
|
627
|
-
}
|
|
644
|
+
// 形态表共享 lib/rules/expr.mjs(NUMERIC_HINT_PATTERNS + numericHint,测试直测):
|
|
645
|
+
// 只作「提醒 AI 语义复核」的启发式:命中 ≠ 违规(版本号 / 固定营销话术会误报),故 WARN 不阻塞。
|
|
646
|
+
const numericHit = numericHint
|
|
628
647
|
walk(view, (n) => {
|
|
629
648
|
if (n.className !== 'Text') return
|
|
630
649
|
for (const p of n.properties || []) {
|
|
@@ -654,79 +673,65 @@ export function lint(schema, data) {
|
|
|
654
673
|
})
|
|
655
674
|
}
|
|
656
675
|
|
|
657
|
-
// ── R32: Image
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
676
|
+
// ── R32 / R25: Image 硬契约(缺 rect.height、itemValueFrom 三态)──
|
|
677
|
+
// 判定与文案共享 lib/rules/image.mjs(与 preflight 同一实现,避免「同一张卡两处措辞/结论不同」)。
|
|
678
|
+
// 这里显式挑选字段构造 finding,保持 lint 输出形状与重构前逐字一致。
|
|
679
|
+
for (const f of collectImageNoHeight(view)) {
|
|
680
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
681
|
+
}
|
|
682
|
+
for (const f of collectImageValueFrom(view)) {
|
|
683
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// ── R23: 百分比表达式缺 Math.round → JS 浮点精度 ──(共享 lib/rules/expr.mjs)
|
|
687
|
+
for (const f of collectExprNoMathRound(view)) {
|
|
688
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// ── 数据绑定完备:列表数组化三件套 ──(共享 lib/rules/bindings.mjs,2026-09-25)
|
|
692
|
+
// 复现器硬伤是 error(渲染 0 项 / 空壳,必然错);未消费数组与静态 tile 是 warn
|
|
693
|
+
// (像素可以很高但数据维度缺失;硬拦在 readiness 的 bindings/lists 门——有视觉提名背书才拦)。
|
|
694
|
+
for (const f of collectRepeaterDefects(view)) {
|
|
695
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
696
|
+
}
|
|
697
|
+
for (const f of collectStaticTileExpansion(view)) {
|
|
698
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
699
|
+
}
|
|
700
|
+
{
|
|
701
|
+
const { unconsumed } = collectArrayConsumption(schema, data || {})
|
|
702
|
+
for (const u of unconsumed) {
|
|
665
703
|
out.push({
|
|
666
|
-
severity: '
|
|
667
|
-
code: '
|
|
668
|
-
componentId:
|
|
669
|
-
message: `
|
|
704
|
+
severity: 'warn',
|
|
705
|
+
code: 'binding-array-unconsumed',
|
|
706
|
+
componentId: '',
|
|
707
|
+
message: `data["${u.name}"](${u.len} 项)没有任何列表消费(复现器 value / slotScope 模板 / 事件代码 / 表达式都找不到引用)→ ` +
|
|
708
|
+
(u.semantic
|
|
709
|
+
? '名字带列表语义却没被任何列表使用:设计稿若有重复数据行,应 ListLayout/GridLayout + $' + u.name + ' + slotScope 模板(ir-format.md §2e);若该数组确无视图用途应从 data.json 删除'
|
|
710
|
+
: '若为 Canvas 图表 / 运行时配置数据可忽略本预警'),
|
|
670
711
|
})
|
|
671
712
|
}
|
|
672
|
-
}
|
|
713
|
+
}
|
|
673
714
|
|
|
674
|
-
// ──
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const val = String(p.itemValue || '')
|
|
681
|
-
if (from === '0' && !val.startsWith('$')) {
|
|
682
|
-
out.push({
|
|
683
|
-
severity: 'error',
|
|
684
|
-
code: 'r25-image-from-0',
|
|
685
|
-
componentId: n.componentId || '',
|
|
686
|
-
message: `Image "${n.componentId}" itemValueFrom="0"(常量) → 渲染器不走图片逻辑,空白(R25)。静态路径用 "2"`,
|
|
687
|
-
})
|
|
688
|
-
}
|
|
689
|
-
if (from === '1' && !val.startsWith('$')) {
|
|
690
|
-
out.push({
|
|
691
|
-
severity: 'error',
|
|
692
|
-
code: 'r25-image-from-1',
|
|
693
|
-
componentId: n.componentId || '',
|
|
694
|
-
message: `Image "${n.componentId}" itemValueFrom="1"(变量) 但值不以 $ 开头 → 表达式求值失败,空白(R25)`,
|
|
695
|
-
})
|
|
696
|
-
}
|
|
697
|
-
if (from === '2' && val.startsWith('$')) {
|
|
698
|
-
out.push({
|
|
699
|
-
severity: 'error',
|
|
700
|
-
code: 'r25-image-from-2',
|
|
701
|
-
componentId: n.componentId || '',
|
|
702
|
-
message:
|
|
703
|
-
`Image "${n.componentId}" itemValueFrom="2"(图片/文件值) 但值是表达式 "${val}" → ` +
|
|
704
|
-
`运行时对 "2" 是原样透传(property.js onPreview),该字符串直接进 background-image:url(${val}),` +
|
|
705
|
-
`画布必然空白(R25)。变量绑定必须改 "1"`,
|
|
706
|
-
})
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
})
|
|
715
|
+
// ── 宽度自适应契约(ir-format.md §2f;判定共享 lib/rules/adaptive-width.mjs,2026-09-25)──
|
|
716
|
+
// 容器类在纵向流父级里把占满语义写死成 px(98%~103% 占满父内容盒)→ error。
|
|
717
|
+
// meta 默认 rect.width 就是 100%,覆盖成 px = 显式锁死;改 100% 与设计宽逐像素等价且自适应。
|
|
718
|
+
for (const f of collectFullwidthFixedPx(view)) {
|
|
719
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
720
|
+
}
|
|
710
721
|
|
|
711
|
-
// ──
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
message: `"${n.componentId}" 表达式含 *100 但无 Math.round → JS 浮点精度溢出(R23): ${p.itemValue.slice(0, 50)}`,
|
|
725
|
-
})
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
})
|
|
722
|
+
// ── 结构与事件代码:pitfalls 教训 → 机器 gate ──(共享 lib/rules/structure.mjs,2026-09-25)
|
|
723
|
+
// §27 slot 平铺 / R34 null 子节点 / §20.4 style 重复子项是 error(必然错、存量零命中);
|
|
724
|
+
// §10 整体回传 / R20 Icon 缺 rect / R38 Root 定高是 warn(存量有命中或语义复核兜底)。
|
|
725
|
+
for (const f of [
|
|
726
|
+
...collectSlotMultiChildren(view),
|
|
727
|
+
...collectNullChildren(view),
|
|
728
|
+
...collectDuplicateStyleChildren(view),
|
|
729
|
+
...collectAlertDataWholeState(view),
|
|
730
|
+
...collectIconNoRect(view),
|
|
731
|
+
...collectRootFixedHeight(view),
|
|
732
|
+
]) {
|
|
733
|
+
out.push({ severity: f.severity, code: f.code, componentId: f.componentId, message: f.message })
|
|
734
|
+
}
|
|
730
735
|
|
|
731
736
|
// R17/R22: flexShrink 铁律
|
|
732
737
|
// R17: 关键 Text(金额/数字/标签/标题/占比/单位)必须 flexShrink:0(防换行)
|
|
@@ -1200,6 +1205,42 @@ export function lint(schema, data) {
|
|
|
1200
1205
|
}
|
|
1201
1206
|
})
|
|
1202
1207
|
|
|
1208
|
+
// R50b: 未归一化的列表作用域别名(哨兵,**不是**「禁止 $item」的规则)。
|
|
1209
|
+
//
|
|
1210
|
+
// 2026-09-24 定论:`$item.xxx` 不是模型的问题 —— 我们自己把它手写进了系统提示词
|
|
1211
|
+
// (提交 56e9894)与 ir-format.md,模型只是照做。所以处理方式是**编译器归一化**:
|
|
1212
|
+
// · IR → schema:expand_ir.mjs 的 expandIR() 开头调用 lib/scope_alias.mjs 改写;
|
|
1213
|
+
// · schema 级:autofix_schema.py 规则 5 改写(gate 第 1 步 / iterate 内建 autofix 都会跑到)。
|
|
1214
|
+
// 规范形只有三种:`$<字段名>` / `$$` / `$_index`(运行时 makeSlotScope 的作用域没有 `item` 键)。
|
|
1215
|
+
//
|
|
1216
|
+
// 那这条规则还拦什么:**未走过归一化管线的 schema**(外部手改、老产物、绕过 expand/autofix
|
|
1217
|
+
// 直接写盘)。此时 lint 是最后一道可机械判定的闸 —— 命中说明该 schema 该跑一次
|
|
1218
|
+
// `autofix_schema.py`,而不是说作者写错了字。CI 对已提交 schema 跑 lint 时它是唯一防线。
|
|
1219
|
+
walk(view, (n) => {
|
|
1220
|
+
const cid = n.componentId || '(root)'
|
|
1221
|
+
const hit = []
|
|
1222
|
+
const scan = (where, val) => {
|
|
1223
|
+
const s = String(val || '')
|
|
1224
|
+
if (!/\$item(?![A-Za-z0-9_$])/.test(s)) return
|
|
1225
|
+
hit.push(`${where}: ${s.length > 90 ? s.slice(0, 90) + '…' : s}`)
|
|
1226
|
+
}
|
|
1227
|
+
for (const p of (n.properties || [])) if (String(p.itemValueFrom) === '1') scan(p.itemKey || '?', p.itemValue)
|
|
1228
|
+
for (const g of (n.style?.properties || [])) {
|
|
1229
|
+
for (const c of (g.itemChildren?.properties || [])) if (String(c.itemValueFrom) === '1') scan(`style.${g.itemKey}.${c.itemKey}`, c.itemValue)
|
|
1230
|
+
}
|
|
1231
|
+
for (const d of (n.directives || [])) if (String(d.itemValueFrom) === '1') scan(`directive.${d.itemKey}`, d.itemValue)
|
|
1232
|
+
for (const ea of (n.eventactions || [])) {
|
|
1233
|
+
for (const p of (ea?.action?.properties || [])) if (p?.itemValue?.code) scan(`action.${p.itemKey}.code`, p.itemValue.code)
|
|
1234
|
+
}
|
|
1235
|
+
if (!hit.length) return
|
|
1236
|
+
out.push({
|
|
1237
|
+
severity: 'error',
|
|
1238
|
+
code: 'r50b-unnormalized-scope-alias',
|
|
1239
|
+
componentId: cid,
|
|
1240
|
+
message: `${n.className} "${cid}" 的绑定里含未归一化的列表作用域别名 $item —— 运行时 makeSlotScope 的作用域里**没有 item 这个键**(它是「item 字段逐个展开 ∪ {$$: 整项, _index: 索引}」),求值恒为 undefined 且不抛错(validate/preflight/render 全绿,只在 /__render-status 的 bindingErrors 留痕)。规范形:字段写 \`$<字段名>\`、整项写 \`$$\`、索引写 \`$_index\`。**这不是要你手改**:跑一次 \`autofix_schema.py <schema>\`(或 \`expand_ir.mjs\` 重新展开 IR)即自动归一化;命中说明该 schema 绕过了归一化管线。命中:${hit.join(' | ')}`,
|
|
1241
|
+
})
|
|
1242
|
+
})
|
|
1243
|
+
|
|
1203
1244
|
// R51: customAction 里 this.data 只允许读 Input 绑定键的实时输入值;运行态变量一律 this.state
|
|
1204
1245
|
const inputBoundKeys = new Set()
|
|
1205
1246
|
walk(view, (n) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* preflight.mjs —
|
|
3
|
+
* preflight.mjs — 生成前/后一键机械检查(把 AI 需手动过的机械项一次性跑完)。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 检查项(共 14 项;语义清单见 SKILL.md §8 Workflow A 步骤 4):
|
|
6
6
|
* 1. 元素清单:spec text/slice/shape 数 vs schema 节点数(R29)
|
|
7
7
|
* 2. 组件白名单:className ∈ component-meta.json(R28)
|
|
8
8
|
* 3. Image itemValueFrom:静态路径必须 "2",变量 "1"(双向都拦:`"0"` 常量放路径、
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* 11. 切图引用含 URL 保留字符(`# ? % & +`)→ 浏览器截断请求、图片静默不显示(R31b)
|
|
18
18
|
* 12. 横向流父容器里的容器子节点未写 rect.width + flexShrink:0 → 默认 100% 吃掉整行(R22b)
|
|
19
19
|
* 13. 切图引用在 src/slices 里没有对应文件 → 渲染 404、图空白零报错(R31c)
|
|
20
|
-
*
|
|
20
|
+
* 14. 组件契约:属性键 / 样式组 / 样式子键必须在 component-meta.json + style-meta.json 白名单内(R28b)
|
|
21
|
+
* —— 不存在的键被运行时**整条静默丢弃**(Image 键写错 ⇒ 破图),历史四道闸全放行。
|
|
22
|
+
* —— 11/12/13 与 lint_card.mjs 共用 lib/layout_rules.mjs 与 lib/slice_dedupe.mjs;14 共用 lib/component_contract.mjs,避免双写漂移。
|
|
21
23
|
*
|
|
22
24
|
* 用法:
|
|
23
25
|
* node preflight.mjs --spec UI/<画板>/spec.json --id <卡id>
|
|
@@ -31,6 +33,9 @@ import path from 'node:path'
|
|
|
31
33
|
import { metaDir, cardsDir, slicesDir } from './lib/paths.mjs'
|
|
32
34
|
import { buildSliceFileIndex, collectSliceRefStrings, findUrlReservedChars, isRemoteSliceRef, resolveSliceRefOnDisk, sliceNameFromRef } from './lib/slice_dedupe.mjs'
|
|
33
35
|
import { collectRowChildNoWidth } from './lib/layout_rules.mjs'
|
|
36
|
+
import { loadContract, collectContractViolations, describeViolation } from './lib/component_contract.mjs'
|
|
37
|
+
import { collectImageValueFrom, collectImageNoHeight } from './lib/rules/image.mjs'
|
|
38
|
+
import { collectExprNoMathRound } from './lib/rules/expr.mjs'
|
|
34
39
|
|
|
35
40
|
/* ── args ── */
|
|
36
41
|
const args = {}
|
|
@@ -60,10 +65,12 @@ if (!schema) {
|
|
|
60
65
|
const spec = args.spec ? loadJSONSafe(args.spec) : null
|
|
61
66
|
const specCards = spec?.cards || []
|
|
62
67
|
|
|
63
|
-
/* ── Load meta ──
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
/* ── Load meta ──
|
|
69
|
+
* 组件/样式白名单唯一来源:lib/component_contract.mjs(内部编译 component-meta.json + style-meta.json)。
|
|
70
|
+
* 原先这里自建 `new Set(Object.keys(CM.components))`,与 lint 侧经 loadContract 得到的
|
|
71
|
+
* `contract.classes` **并不相等**——后者含内置类 `Root`(CM 里没有),且元数据读不到时
|
|
72
|
+
* 前者会把全部组件报成「不在白名单」。统一到一处,消除这条口径差。 */
|
|
73
|
+
const contract = loadContract({ metaDir })
|
|
67
74
|
|
|
68
75
|
/* ── helpers ── */
|
|
69
76
|
function getStyleChild(node, groupKey, childKey) {
|
|
@@ -113,40 +120,28 @@ if (specCards.length > 0) {
|
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
|
|
116
|
-
/* ══ Check 2: Component whitelist (R28) ══
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
/* ══ Check 2: Component whitelist (R28) ══
|
|
124
|
+
* 白名单 = contract.classes(component-meta.json 的 components 键 ∪ 内置类 Root)。
|
|
125
|
+
* 元数据读不到时**不报**——满屏「不在白名单」只会淹没真正的问题(与 lint 同口径)。 */
|
|
126
|
+
if (contract.loaded.components) {
|
|
127
|
+
for (const n of allNodes) {
|
|
128
|
+
if (n.className && !contract.classes.has(n.className)) {
|
|
129
|
+
check('r28-unknown-class', 'error', `${n.className} "${n.componentId}" 不在 component-meta.json 中 → 渲染空白(R28)`)
|
|
130
|
+
}
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
|
|
123
|
-
/* ══ Check 3: Image itemValueFrom (R25) ══
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (from === '0' && !val.startsWith('$')) {
|
|
130
|
-
check('r25-image-from-0', 'error', `Image "${n.componentId}" itemValueFrom="0"(常量) 但值是路径 → 渲染器不走图片逻辑,空白(R25)。静态路径用 "2"`)
|
|
131
|
-
}
|
|
132
|
-
if (from === '1' && !val.startsWith('$')) {
|
|
133
|
-
check('r25-image-from-1', 'error', `Image "${n.componentId}" itemValueFrom="1"(变量) 但值不以 $ 开头 → 表达式求值失败,空白(R25)`)
|
|
134
|
-
}
|
|
135
|
-
if (from === '2' && val.startsWith('$')) {
|
|
136
|
-
check(
|
|
137
|
-
'r25-image-from-2',
|
|
138
|
-
'error',
|
|
139
|
-
`Image "${n.componentId}" itemValueFrom="2"(图片/文件值) 但值是表达式 "${val}" → 运行时对 "2" 是**原样透传**(property.js onPreview),该字符串会直接进 background-image:url(${val}),画布必然空白(R25)。变量绑定必须改 "1"`,
|
|
140
|
-
)
|
|
141
|
-
}
|
|
134
|
+
/* ══ Check 3: Image itemValueFrom (R25) ══
|
|
135
|
+
* 判定与文案共享 lib/rules/image.mjs(与 lint_card.mjs 同一实现)。
|
|
136
|
+
* reportMissingProp=true —— 键名写错(如 itemKey:"image")会让本项与 Check 5 **双双短路跳过**,
|
|
137
|
+
* 四道闸全绿而图片死掉,故缺失 value 本身必须是 ERROR。 */
|
|
138
|
+
for (const f of collectImageValueFrom(schema.view, { reportMissingProp: true })) {
|
|
139
|
+
check(f.code, f.severity, f.message, f.detail)
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
/* ══ Check 4: Image rect.height (R32)
|
|
145
|
-
for (const
|
|
146
|
-
|
|
147
|
-
if (!h || !String(h.itemValue).trim()) {
|
|
148
|
-
check('r32-image-no-height', 'error', `Image "${n.componentId}" 缺 rect.height → CSS aspect-ratio:16/9 会压缩图片高度(R32)。设显式高度`)
|
|
149
|
-
}
|
|
142
|
+
/* ══ Check 4: Image rect.height (R32) ══(共享 lib/rules/image.mjs) */
|
|
143
|
+
for (const f of collectImageNoHeight(schema.view)) {
|
|
144
|
+
check(f.code, f.severity, f.message, f.detail)
|
|
150
145
|
}
|
|
151
146
|
|
|
152
147
|
/* ══ Check 5: Slice filename spaces (R31) ══ */
|
|
@@ -169,21 +164,10 @@ for (const n of allNodes.filter(n => n.className === 'Icon')) {
|
|
|
169
164
|
}
|
|
170
165
|
}
|
|
171
166
|
|
|
172
|
-
/* ══ Check 7: Percentage expression Math.round (R23)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
for (const sp of node.style?.properties || []) {
|
|
176
|
-
for (const c of sp.itemChildren?.properties || []) props.push(c)
|
|
177
|
-
}
|
|
178
|
-
for (const p of props) {
|
|
179
|
-
if (String(p.itemValueFrom) === '1' && typeof p.itemValue === 'string') {
|
|
180
|
-
if (/\*\s*100/.test(p.itemValue) && !/Math\.round/.test(p.itemValue)) {
|
|
181
|
-
check('r23-no-math-round', 'error', `"${node.componentId}" 表达式含 *100 但无 Math.round → JS 浮点精度问题(R23): ${p.itemValue.slice(0, 50)}`)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
167
|
+
/* ══ Check 7: Percentage expression Math.round (R23) ══(共享 lib/rules/expr.mjs) */
|
|
168
|
+
for (const f of collectExprNoMathRound(schema.view)) {
|
|
169
|
+
check(f.code, f.severity, f.message, f.detail)
|
|
185
170
|
}
|
|
186
|
-
for (const n of allNodes) walkExprs(n)
|
|
187
171
|
|
|
188
172
|
/* ══ Check 8: Divider for separators (R28) ══ */
|
|
189
173
|
// Heuristic: Row with height ≤2 and background color but no children = likely a divider
|
|
@@ -273,6 +257,20 @@ for (const hit of collectRowChildNoWidth(schema.view)) {
|
|
|
273
257
|
}
|
|
274
258
|
}
|
|
275
259
|
|
|
260
|
+
/* ══ Check 14: Component contract — 属性键 / 样式组 / 样式子键白名单 ══
|
|
261
|
+
* 2026-09-24 事故:模型给 Image 写 itemKey:"image"(合法键只有 "value"),
|
|
262
|
+
* 运行时按 itemKey 绑定、不存在的键被整条静默丢弃 ⇒ value 为空、图片渲染成破图;
|
|
263
|
+
* 而 validate / lint / preflight / elements.missing **全部放行**。
|
|
264
|
+
* 全仓 82 处 Image 有 81 处写 value,唯一写 image 的正是这张卡 ⇒ 必须机械兜底。
|
|
265
|
+
* 白名单唯一来源 card-editor/meta/component-meta.json(经 lib/component_contract.mjs 编译)。 */
|
|
266
|
+
{
|
|
267
|
+
for (const v of collectContractViolations(schema, contract)) {
|
|
268
|
+
// unknown-class 由 Check 2 报(r28-unknown-class),此处只报属性键 / 样式组 / 样式子键
|
|
269
|
+
if (v.code === 'unknown-class') continue
|
|
270
|
+
check(`r28b-${v.code}`, v.severity, describeViolation(v), v.where ? `节点路径 ${v.where}` : '')
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
276
274
|
/* ── Output ── */
|
|
277
275
|
const errors = results.filter(r => r.severity === 'error')
|
|
278
276
|
const warns = results.filter(r => r.severity === 'warn')
|