soma-kit 0.1.15 → 0.1.17
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 +1 -1
- package/package.json +8 -5
- package/packs/ai/model-card.ts +3 -3
- package/packs/ops/error-budget-card.ts +3 -3
- package/packs/ops/release-readiness-card.ts +3 -3
- package/packs/security/control-evidence-card.ts +3 -3
- package/packs/security/finding-card.ts +3 -2
- package/packs/shared/card-util.ts +17 -0
- package/spec/generated/kit-app.schema.json +2148 -340
- package/spec/generated/kit-page.schema.json +1134 -139
- package/spec/kit-grammar.json +935 -93
- package/spec/kit-grammar.schema.json +167 -2
- package/src/app/app-config.ts +219 -186
- package/src/app/define-kit-actions.ts +126 -20
- package/src/app/define-kit-app.ts +49 -4
- package/src/app/index.ts +5 -0
- package/src/app/kit-view-context.ts +39 -1
- package/src/app/list-page-defaults.ts +14 -0
- package/src/app/server-pages.ts +239 -7
- package/src/app/server.ts +466 -25
- package/src/app/theme-endpoint.ts +67 -23
- package/src/app/theme-runtime.ts +414 -85
- package/src/app/theme-shards.ts +69 -0
- package/src/app/tier-compat.ts +107 -0
- package/src/base/action-busy.ts +215 -38
- package/src/base/affix.ts +137 -0
- package/src/base/alert.ts +104 -59
- package/src/base/anchored-layer.ts +7 -6
- package/src/base/avatar.ts +147 -61
- package/src/base/badge.ts +186 -0
- package/src/base/button-group.ts +227 -0
- package/src/base/button.ts +347 -50
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +143 -32
- package/src/base/check-core.ts +193 -33
- package/src/base/checkbox.ts +67 -2
- package/src/base/choice.ts +132 -31
- package/src/base/collapse.ts +249 -0
- package/src/base/color-picker.ts +399 -27
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +148 -36
- package/src/base/context-menu.ts +23 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +114 -96
- package/src/base/date.ts +481 -74
- package/src/base/delta.ts +16 -9
- package/src/base/divider.ts +51 -33
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +57 -21
- package/src/base/gap-value.ts +34 -15
- package/src/base/hint-tips.ts +99 -29
- package/src/base/identity-cells.ts +839 -0
- package/src/base/illustrations.ts +6 -4
- package/src/base/image.ts +40 -19
- package/src/base/index.ts +79 -22
- package/src/base/inline-error.ts +13 -7
- package/src/base/input.ts +135 -35
- package/src/base/kbd.ts +30 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +282 -101
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +55 -22
- package/src/base/menu-button.ts +73 -22
- package/src/base/menu-core.ts +201 -24
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +7 -5
- package/src/base/motion/hover-gallery.ts +16 -12
- package/src/base/motion/limits.ts +10 -0
- package/src/base/motion/marquee.ts +18 -11
- package/src/base/motion/text-rotate.ts +34 -16
- package/src/base/notification.ts +292 -0
- package/src/base/number.ts +93 -12
- package/src/base/otp.ts +139 -27
- package/src/base/overlay-runtime.ts +30 -23
- package/src/base/overlay-shell.ts +59 -14
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +624 -73
- package/src/base/popup.ts +187 -52
- package/src/base/portal-core.ts +99 -2
- package/src/base/price-text.ts +51 -17
- package/src/base/progress.ts +100 -18
- package/src/base/qr-code.ts +64 -17
- package/src/base/qty-stepper.ts +141 -22
- package/src/base/radio.ts +43 -2
- package/src/base/range.ts +194 -39
- package/src/base/rating.ts +117 -31
- package/src/base/reason-tip.ts +58 -16
- package/src/base/relation-cells.ts +541 -0
- package/src/base/resize-handle.ts +5 -3
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +70 -26
- package/src/base/select.ts +8 -3
- package/src/base/shared.ts +482 -71
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/sticky-edge.ts +96 -29
- package/src/base/swap.ts +39 -21
- package/src/base/switch.ts +158 -38
- package/src/base/tabs.ts +292 -0
- package/src/base/tag-input.ts +123 -54
- package/src/base/tag.ts +184 -66
- package/src/base/text.ts +461 -71
- package/src/base/textarea.ts +88 -39
- package/src/base/time-picker.ts +335 -55
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +342 -88
- package/src/base/upload.ts +604 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +70 -5
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +52 -12
- package/src/biz/auth-panel/compile.ts +13 -3
- package/src/biz/auth-panel/shell.ts +27 -7
- package/src/biz/category-crud/compile.ts +51 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +29 -9
- package/src/biz/checkout-page/compile.ts +37 -3
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +26 -9
- package/src/biz/compose.ts +6 -1
- package/src/biz/data-components.ts +2 -0
- package/src/biz/import-wizard/compile.ts +4 -1
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +32 -18
- package/src/biz/index.ts +1 -1
- package/src/biz/landing-page/compile.ts +3 -2
- package/src/biz/landing-page/shell.ts +22 -3
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +54 -15
- package/src/biz/master-sub/compile.ts +194 -57
- package/src/biz/master-sub/detail-head.ts +141 -18
- package/src/biz/master-sub/index.ts +3 -0
- package/src/biz/master-sub/shell.ts +188 -62
- package/src/biz/multi-board/compile.ts +87 -36
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +3 -2
- package/src/biz/multi-board/prose-fold.ts +15 -11
- package/src/biz/multi-board/shell.ts +148 -37
- package/src/biz/notification-center/compile.ts +20 -6
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +43 -10
- package/src/biz/page-templates/domain-templates.ts +145 -22
- package/src/biz/page-templates/result-page/compile.ts +4 -1
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +17 -4
- package/src/biz/page-templates/sign-in-page/compile.ts +19 -8
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +28 -12
- package/src/biz/record-detail/compile.ts +39 -11
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +41 -10
- package/src/biz/settings-center/compile.ts +4 -1
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +30 -9
- package/src/biz/shared/action-host.ts +137 -46
- package/src/biz/shared/compile-helpers.ts +152 -28
- package/src/biz/shared/coordinator.ts +628 -147
- package/src/biz/shared/focus-return.ts +180 -0
- package/src/biz/shared/object-aliases.ts +7 -1
- package/src/biz/shared/overlay-compile.ts +58 -10
- package/src/biz/shared/overlay-shell.ts +40 -10
- package/src/biz/shared/page-form-actions.ts +151 -0
- package/src/biz/shared/page-form.ts +255 -0
- package/src/biz/shared/pipeline.ts +74 -0
- package/src/biz/shared/runtime-hub.ts +101 -8
- package/src/biz/shared/verbs.ts +129 -0
- package/src/biz/single-form/compile.ts +4 -2
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +21 -11
- package/src/biz/standard-crud/compile.ts +206 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +82 -22
- package/src/biz/standard-crud/summary.ts +2 -37
- package/src/biz/step-form/compile.ts +12 -3
- package/src/biz/step-form/hub.ts +165 -50
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +31 -15
- package/src/biz/types.ts +40 -4
- package/src/cli/kit-cli.ts +145 -26
- package/src/cli/kit-init.ts +3 -3
- package/src/cli/migrate/theme-map.ts +35 -28
- package/src/cli/migrate/ts-rules.ts +2 -2
- package/src/cli/migrate/types.ts +3 -3
- package/src/cli/migrate/yaml-rules.ts +11 -9
- package/src/cli/view-writes.ts +13 -0
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +446 -53
- package/src/compile/component-candidates.ts +56 -4
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +1 -1
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/rules-composition.ts +2 -1
- package/src/compile/layout-lint/rules-table.ts +4 -19
- package/src/compile/look-page.ts +551 -0
- package/src/compile/look.ts +376 -0
- package/src/compile/page-composition.ts +382 -46
- package/src/compile/page-hierarchy.ts +131 -0
- package/src/compile/page-pipeline-look.ts +156 -0
- package/src/compile/page-pipeline.ts +200 -0
- package/src/compile/parse.ts +12 -11
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +645 -28
- package/src/compile/styles.ts +226 -26
- package/src/compile/types.ts +62 -5
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +49 -22
- package/src/data/anchor-nav.ts +73 -15
- package/src/data/approval-flow.ts +210 -124
- package/src/data/assignment-picker.ts +163 -85
- package/src/data/async-result-panel.ts +110 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +141 -19
- package/src/data/calendar.ts +434 -96
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +72 -38
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +904 -77
- package/src/data/checklist.ts +78 -35
- package/src/data/code-view.ts +106 -48
- package/src/data/comment-thread.ts +607 -87
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +198 -30
- package/src/data/context-menu.ts +95 -21
- package/src/data/d9-limits.ts +2 -0
- package/src/data/d9-util.ts +13 -5
- package/src/data/diff.ts +107 -50
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +33 -17
- package/src/data/embed.ts +142 -7
- package/src/data/engine-ports.ts +13 -4
- package/src/data/field-mapper.ts +104 -48
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +603 -142
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +85 -27
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +637 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +38 -15
- package/src/data/image-viewer.ts +261 -62
- package/src/data/index.ts +63 -1
- package/src/data/item-list.ts +217 -57
- package/src/data/json-view.ts +165 -100
- package/src/data/kanban.ts +339 -87
- package/src/data/kit-contract.ts +230 -0
- package/src/data/leaderboard.ts +343 -0
- package/src/data/level-class.ts +21 -0
- package/src/data/log-stream.ts +347 -0
- package/src/data/markdown-view.ts +155 -45
- package/src/data/matrix.ts +217 -112
- package/src/data/media-grid.ts +162 -38
- package/src/data/mega-menu.ts +39 -23
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +50 -15
- package/src/data/menu.ts +131 -47
- package/src/data/mockup.ts +30 -22
- package/src/data/modal-dialog.ts +90 -13
- package/src/data/navbar.ts +143 -61
- package/src/data/notice-list.ts +100 -48
- package/src/data/notify-renderer.ts +61 -7
- package/src/data/object-form.ts +1389 -130
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +122 -42
- package/src/data/panel-head.ts +237 -75
- package/src/data/permission-matrix.ts +371 -119
- package/src/data/permission-tree.ts +135 -80
- package/src/data/pricing-table.ts +106 -42
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +63 -31
- package/src/data/record-card.ts +239 -70
- package/src/data/record-picker.ts +56 -27
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +131 -41
- package/src/data/resident.ts +11 -1
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +206 -35
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +376 -102
- package/src/data/rule-builder.ts +129 -80
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +86 -43
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +438 -86
- package/src/data/static-lazy.ts +18 -0
- package/src/data/static-registry.ts +38 -2
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +63 -34
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +128 -47
- package/src/data/system-switcher.ts +40 -20
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +99 -31
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +110 -47
- package/src/data/transfer.ts +195 -47
- package/src/data/tree-table.ts +194 -112
- package/src/data/tree.ts +191 -70
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +242 -102
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +26 -4
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +1 -2
- package/src/frames/inherited-shell.ts +54 -13
- package/src/frames/page-bar.ts +205 -27
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +0 -2
- package/src/frames/shared.ts +64 -21
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +11 -7
- package/src/frames/split-frame/wiring.ts +14 -10
- package/src/frames/tabs-frame/shell.ts +3 -2
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +2 -0
- package/src/frames/workspace-frame/extras.ts +5 -3
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/pipeline-key.ts +6 -0
- package/src/frames/workspace-frame/shell.ts +22 -2
- package/src/frames/workspace-frame/state.ts +42 -14
- package/src/frames/workspace-frame/view.ts +697 -167
- package/src/generated/kit-grammar-runtime.ts +1016 -54
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +96 -3
- package/src/object-renderer/action-group.ts +175 -23
- package/src/object-renderer/action-more.ts +48 -17
- package/src/object-renderer/arrange.ts +241 -29
- package/src/object-renderer/category-tone.ts +96 -0
- package/src/object-renderer/collapse-wiring.ts +19 -9
- package/src/object-renderer/collection-expand.ts +3 -3
- package/src/object-renderer/collection-parts.ts +432 -107
- package/src/object-renderer/collection-table.ts +347 -45
- package/src/object-renderer/collection.ts +291 -62
- package/src/object-renderer/compile-data.ts +12 -2
- package/src/object-renderer/defaults.ts +6 -5
- package/src/object-renderer/emit-events.ts +45 -19
- package/src/object-renderer/emit-object.ts +35 -9
- package/src/object-renderer/emit-static.ts +734 -159
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +105 -18
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +18 -2
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +44 -2
- package/src/object-renderer/pick-component.ts +8 -2
- package/src/object-renderer/pipeline-mode.ts +6 -0
- package/src/object-renderer/relation-field.ts +79 -0
- package/src/object-renderer/render-object.ts +71 -26
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +423 -104
- package/src/object-renderer/table-gap.ts +2 -1
- package/src/object-renderer/table-reorder.ts +237 -0
- package/src/object-renderer/table-summary.ts +26 -12
- package/src/object-renderer/table-tools.ts +428 -128
- package/src/object-renderer/types.ts +91 -2
- package/src/object-renderer/value-present.ts +49 -0
- package/src/page-target/ai-surface.ts +15 -22
- package/src/page-target/compile.ts +5 -6
- package/src/page-target/drift.ts +0 -7
- package/src/page-target/intent-schema.ts +46 -43
- package/src/page-target/target.ts +4 -5
- package/src/page-target/writer-policy.ts +4 -5
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +15 -14
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +3 -2
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +76 -19
- package/src/recipes/control.ts +64 -5
- package/src/recipes/desc-list.ts +101 -7
- package/src/recipes/divider.ts +30 -9
- package/src/recipes/emphasis.ts +90 -5
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +3 -2
- package/src/recipes/index.ts +28 -4
- package/src/recipes/inherited-shell.ts +21 -15
- package/src/recipes/json-view.ts +6 -5
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +16 -6
- package/src/recipes/overlay.ts +47 -19
- package/src/recipes/page-width.ts +31 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +37 -19
- package/src/recipes/rail-grid.ts +6 -3
- package/src/recipes/self-owned.ts +59 -0
- package/src/recipes/slot-align.ts +5 -3
- package/src/recipes/stat-state.ts +5 -5
- package/src/recipes/state.ts +54 -3
- package/src/recipes/status.ts +14 -14
- package/src/recipes/strip.ts +47 -5
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +33 -4
- package/src/recipes/table-gap.ts +3 -2
- package/src/recipes/table-native-edit.ts +22 -9
- package/src/recipes/table-row.ts +45 -12
- package/src/recipes/tabs.ts +54 -22
- package/src/recipes/text-diff.ts +15 -8
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +68 -3
- package/src/shared/action-func.ts +106 -0
- package/src/shared/color-scheme.ts +127 -0
- package/src/shared/confirm-decl.ts +5 -2
- package/src/shared/danger-facts.ts +55 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +58 -12
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/icons.ts +28 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/shared/order-value.ts +15 -0
- package/src/shared/page-attrs-runtime.ts +327 -0
- package/src/shared/page-attrs.ts +262 -0
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +165 -24
- package/src/shared/theme-usage.ts +16 -0
- package/src/shared/value-table-contract.ts +68 -0
- package/src/spatial/action-func.ts +4 -0
- package/src/spatial/declared-actions.ts +116 -0
- package/src/spatial/emit.ts +660 -0
- package/src/spatial/expand.ts +1482 -0
- package/src/spatial/field-types.ts +48 -0
- package/src/spatial/index.ts +82 -0
- package/src/spatial/layout.ts +697 -0
- package/src/spatial/look-apply.ts +206 -0
- package/src/spatial/page-decl.ts +44 -0
- package/src/spatial/page-object.ts +349 -0
- package/src/spatial/recognize.ts +491 -0
- package/src/spatial/self-report.ts +571 -0
- package/src/spatial/shape.ts +205 -0
- package/src/spatial/spatial-map.ts +136 -0
- package/src/spatial/tone.ts +145 -0
- package/src/theme/index.ts +11 -2
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +527 -16
- package/src/theme/kit-theme.tpl +491 -16
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +522 -185
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +3 -2
- package/src/theme/theme-tokens.ts +1601 -93
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/frames/list-summary.ts +0 -123
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
// 界面规则(look,KT-LK)引擎:选择器解析 → 语义节点树上匹配(从右往左、至多三段、::部件)→ 固定四层层叠 → 每个节点的「部件外观表」+ 诊断。
|
|
2
|
+
// 文法、节点种类、角色、属性与取值闭集全部读语法真源 kit-grammar.json#look / #toneNames(本文件不持有词表);纯函数,不碰 DOM、不碰类名。
|
|
3
|
+
// 层:0 主题缺省 < 1 应用(kit.app.yaml#look)< 2 页面(page.look)< 3 就地(节点自身的 look:,只写本节点部件);同层后写胜,不比较选择器具体程度。
|
|
4
|
+
|
|
5
|
+
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
6
|
+
import type { KitDiagnostic } from './types';
|
|
7
|
+
|
|
8
|
+
import { KIT_LOOK_LIMITS } from 'soma-foundation/kit-limits';
|
|
9
|
+
|
|
10
|
+
interface LookGrammar {
|
|
11
|
+
readonly selector: { readonly partSeparator: string; readonly idPrefix: string };
|
|
12
|
+
readonly nodes: Readonly<Record<string, { readonly named: boolean; readonly filters: readonly string[] }>>;
|
|
13
|
+
readonly roles: Readonly<Record<string, readonly string[]>>;
|
|
14
|
+
/** 色调适用部件(裁决二·3):承载数据的角色收全部;装饰性角色只收 decorativeTones;说明文字角色不收 */
|
|
15
|
+
readonly toneGroups: { readonly data: readonly string[]; readonly decorative: readonly string[]; readonly none: readonly string[]; readonly decorativeTones: readonly string[] };
|
|
16
|
+
readonly properties: Readonly<Record<string, KitLookPropertySpec>>;
|
|
17
|
+
readonly bindPrefixes: Readonly<Record<string, string>>;
|
|
18
|
+
}
|
|
19
|
+
/** 一个属性的真源登记:stage = 工序('3'…'6' / 'removed'),恰好一道 */
|
|
20
|
+
export interface KitLookPropertySpec {
|
|
21
|
+
readonly stage: string;
|
|
22
|
+
readonly values: unknown;
|
|
23
|
+
readonly bindable: boolean;
|
|
24
|
+
/** 已登记、出口未接(写了报 KIT-LOOK-003「本期未开放」) */
|
|
25
|
+
readonly b2?: boolean;
|
|
26
|
+
/** 布局类属性的去处:声明里已有求解器读的那个键('fieldRef.align' 等;编译期写回声明,不出类) */
|
|
27
|
+
readonly input?: string;
|
|
28
|
+
/** 取值按角色再分(width) */
|
|
29
|
+
readonly byRole?: Readonly<Record<string, readonly unknown[]>>;
|
|
30
|
+
/** 已进闭集、该取值出口未接 */
|
|
31
|
+
readonly unwiredValues?: readonly unknown[];
|
|
32
|
+
/** 过渡期旧写法:旧值 → 改写成的 { 属性: 取值 }(KIT-LOOK-012 告警) */
|
|
33
|
+
readonly deprecatedValues?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
34
|
+
}
|
|
35
|
+
interface ToneNames { readonly semantic: readonly string[]; readonly categorical: readonly string[]; readonly identity: readonly string[]; readonly aliases: Readonly<Record<string, string>> }
|
|
36
|
+
|
|
37
|
+
const G = (grammarJson as unknown as { look: LookGrammar }).look;
|
|
38
|
+
const TONES = (grammarJson as unknown as { toneNames: ToneNames }).toneNames;
|
|
39
|
+
/** 选择器至多段数(数字真源 kit-limits#look.maxCompounds) */
|
|
40
|
+
export const KIT_LOOK_MAX_COMPOUNDS: number = KIT_LOOK_LIMITS.maxCompounds;
|
|
41
|
+
const ICONS = (grammarJson as unknown as { icons?: { names?: readonly string[] } }).icons?.names ?? [];
|
|
42
|
+
|
|
43
|
+
/** 层号(固定四层) */
|
|
44
|
+
export const KIT_LOOK_LAYERS = Object.freeze({ theme: 0, app: 1, page: 2, inPlace: 3 } as const);
|
|
45
|
+
export type KitLookLayer = (typeof KIT_LOOK_LAYERS)[keyof typeof KIT_LOOK_LAYERS];
|
|
46
|
+
|
|
47
|
+
/** 全部色名(语义 + 分类;identity 为 B2) */
|
|
48
|
+
export function kitToneNames(): readonly string[] {
|
|
49
|
+
return [...TONES.semantic, ...TONES.categorical];
|
|
50
|
+
}
|
|
51
|
+
/** 语义色名 */
|
|
52
|
+
export function kitSemanticToneNames(): readonly string[] {
|
|
53
|
+
return TONES.semantic;
|
|
54
|
+
}
|
|
55
|
+
/** 工序闭集(界面规则属性的工序,按真源书写序去重;'removed' 不算工序) */
|
|
56
|
+
export function kitLookStages(): readonly string[] {
|
|
57
|
+
return [...new Set(Object.values(G.properties).map((p) => p.stage))].filter((s) => s !== 'removed').sort();
|
|
58
|
+
}
|
|
59
|
+
/** 属性 → 它交给求解器的输入键(真源 look.properties.*.input;不是布局类属性返回 undefined) */
|
|
60
|
+
export function kitLookInputOf(prop: string): string | undefined {
|
|
61
|
+
return G.properties[prop]?.input;
|
|
62
|
+
}
|
|
63
|
+
/** 属性 → 工序(未知属性返回 undefined) */
|
|
64
|
+
export function kitLookStageOf(prop: string): string | undefined {
|
|
65
|
+
return G.properties[prop]?.stage;
|
|
66
|
+
}
|
|
67
|
+
/** 诊断文字的工序前缀(「(工序 ⑤)」):序号字形由工序号顺推,不另设表 */
|
|
68
|
+
const STAGE_GLYPHS = '⓪①②③④⑤⑥';
|
|
69
|
+
export function kitStageGlyph(stage: string): string {
|
|
70
|
+
return STAGE_GLYPHS[Number(stage)] ?? stage;
|
|
71
|
+
}
|
|
72
|
+
const stageTag = (prop: string): string => {
|
|
73
|
+
const s = G.properties[prop]?.stage;
|
|
74
|
+
return s === undefined || s === 'removed' ? '' : `(工序 ${kitStageGlyph(s)})`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export interface KitLookCompound {
|
|
78
|
+
readonly type: string;
|
|
79
|
+
readonly name?: string;
|
|
80
|
+
readonly filters: Readonly<Record<string, readonly string[]>>;
|
|
81
|
+
}
|
|
82
|
+
export interface KitLookSelector {
|
|
83
|
+
readonly compounds: readonly KitLookCompound[];
|
|
84
|
+
readonly part?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 语义节点:种类、名字、筛选键取值、组件名、部件 → 角色表、父节点 */
|
|
88
|
+
export interface KitLookNode {
|
|
89
|
+
readonly kind: string;
|
|
90
|
+
readonly name?: string;
|
|
91
|
+
readonly attrs?: Readonly<Record<string, string>>;
|
|
92
|
+
readonly component?: string;
|
|
93
|
+
/** 本节点自己的部件(来自组件契约 look.parts / 内置渲染器):部件名 → 角色 */
|
|
94
|
+
readonly parts?: Readonly<Record<string, string>>;
|
|
95
|
+
/** 部件只接受的属性(契约 accept 收窄) */
|
|
96
|
+
readonly accept?: Readonly<Record<string, readonly string[]>>;
|
|
97
|
+
/** 是否处在集合行里(row. 绑定可用) */
|
|
98
|
+
readonly inRow?: boolean;
|
|
99
|
+
readonly parent?: KitLookNode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 规则取值:静态值或纯绑定(row. / item. / view.) */
|
|
103
|
+
export type KitLookValue = string | boolean | { readonly bind: string };
|
|
104
|
+
/** 一个部件上生效的属性表 */
|
|
105
|
+
export type KitLookParts = Record<string, Record<string, KitLookValue>>;
|
|
106
|
+
|
|
107
|
+
export interface KitLookRule {
|
|
108
|
+
readonly selector: string;
|
|
109
|
+
readonly decls: Readonly<Record<string, unknown>>;
|
|
110
|
+
readonly layer: KitLookLayer;
|
|
111
|
+
/** 诊断路径(文件内位置) */
|
|
112
|
+
readonly path: string;
|
|
113
|
+
/** 就地规则:直接挂在这个节点上(selector 只写 ::部件 或空) */
|
|
114
|
+
readonly host?: KitLookNode;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface KitLookResolved {
|
|
118
|
+
/** 每个被规则改到的节点的部件外观表(只含规则写了的项;未命中的节点不出现) */
|
|
119
|
+
readonly table: Map<KitLookNode, KitLookParts>;
|
|
120
|
+
/** 来源记录:每个(节点, 部件, 属性)最终生效的那条规则的诊断路径(soma kit explain look 读它) */
|
|
121
|
+
readonly sources: Map<KitLookNode, Record<string, Record<string, string>>>;
|
|
122
|
+
readonly diagnostics: KitDiagnostic[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const IDENT = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
126
|
+
const RAW_VALUE = /^(#|rgba?\(|hsla?\(|oklch\(|oklab\(|color-mix\(|var\()|^-?\d+(\.\d+)?(px|rem|em|%)?$|^(text|bg|border|ring|fill|stroke)-/;
|
|
127
|
+
/** 选择器不碰 DOM:常见标签名直接按「不支持的写法」报(KIT-LOOK-002),不当未知节点种类 */
|
|
128
|
+
const HTML_TAGS = new Set(['div', 'span', 'section', 'article', 'aside', 'main', 'header', 'footer', 'nav', 'button', 'a', 'p', 'input', 'select', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'ul', 'ol', 'li', 'svg', 'img', 'label', 'h1', 'h2', 'h3', 'h4']);
|
|
129
|
+
const UNSUPPORTED =/[:>+~!]|\[[^\]]*(\^=|\$=|\*=|~=|\|=|<|>)/;
|
|
130
|
+
|
|
131
|
+
function diag(code: string, path: string, message: string): KitDiagnostic {
|
|
132
|
+
return { code, path, message };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 解析一个选择器;失败返回诊断(KIT-LOOK-001 / 002) */
|
|
136
|
+
export function parseLookSelector(text: string, path = 'look'): { selector?: KitLookSelector; diagnostics: KitDiagnostic[] } {
|
|
137
|
+
const out: KitDiagnostic[] = [];
|
|
138
|
+
const src = text.trim();
|
|
139
|
+
const sep = G.selector.partSeparator;
|
|
140
|
+
const at = src.indexOf(sep);
|
|
141
|
+
const head = at < 0 ? src : src.slice(0, at);
|
|
142
|
+
const part = at < 0 ? undefined : src.slice(at + sep.length);
|
|
143
|
+
if (part !== undefined && !IDENT.test(part)) {
|
|
144
|
+
out.push(diag('KIT-LOOK-002', path, `「${text}」:部件名「${part}」写法不支持(部件是叶子,后面不能再接后代或第二个部件)`));
|
|
145
|
+
return { diagnostics: out };
|
|
146
|
+
}
|
|
147
|
+
if (UNSUPPORTED.test(head.replace(/\[[^\]=]+=[^\]]*\]/g, (m) => (/(\^=|\$=|\*=|~=|<|>)/.test(m) ? m : '')))) {
|
|
148
|
+
out.push(diag('KIT-LOOK-002', path, `「${text}」用了不支持的选择器写法(交互状态、比较、:not / :has、> + ~、位置选择、前后缀匹配、!important):改用 #名 或 [键=值] 按声明事实寻址`));
|
|
149
|
+
return { diagnostics: out };
|
|
150
|
+
}
|
|
151
|
+
const parts = head.trim() === '' ? [] : head.trim().split(/\s+/);
|
|
152
|
+
if (parts.length > KIT_LOOK_MAX_COMPOUNDS) {
|
|
153
|
+
out.push(diag('KIT-LOOK-002', path, `「${text}」有 ${parts.length} 段,至多 ${KIT_LOOK_MAX_COMPOUNDS} 段:拆成两条`));
|
|
154
|
+
return { diagnostics: out };
|
|
155
|
+
}
|
|
156
|
+
const compounds: KitLookCompound[] = [];
|
|
157
|
+
for (const p of parts) {
|
|
158
|
+
const m = /^([A-Za-z_*][A-Za-z0-9_-]*)?(#[^\s#[\]:.>+~]+)?((?:\[[^\]]+\])*)$/u.exec(p);
|
|
159
|
+
if (m === null || (m[1] === undefined && m[2] === undefined && m[3] === '') || HTML_TAGS.has(m[1] ?? '')) {
|
|
160
|
+
out.push(diag('KIT-LOOK-002', path, `「${text}」里的「${p}」不是合法的一段(节点种类或组件名 + 可选 #名 + 可选 [键=值|值]);不支持 DOM 标签、类名(.x)与 data-*`));
|
|
161
|
+
return { diagnostics: out };
|
|
162
|
+
}
|
|
163
|
+
const type = m[1] ?? '*';
|
|
164
|
+
const isComponent = /^[A-Z]/.test(type);
|
|
165
|
+
const spec = G.nodes[type];
|
|
166
|
+
if (!isComponent && spec === undefined) {
|
|
167
|
+
out.push(diag('KIT-LOOK-001', path, `「${text}」:未知节点种类「${type}」(可用 ${Object.keys(G.nodes).join(' / ')},或声明了 look 段的组件名)`));
|
|
168
|
+
return { diagnostics: out };
|
|
169
|
+
}
|
|
170
|
+
const filters: Record<string, string[]> = {};
|
|
171
|
+
for (const f of m[3].match(/\[[^\]]+\]/g) ?? []) {
|
|
172
|
+
const fm = /^\[([A-Za-z_][A-Za-z0-9_-]*)=([^\]]+)\]$/.exec(f);
|
|
173
|
+
if (fm === null) {
|
|
174
|
+
out.push(diag('KIT-LOOK-002', path, `「${text}」:筛选「${f}」只支持 [键=值] 或 [键=值1|值2]`));
|
|
175
|
+
return { diagnostics: out };
|
|
176
|
+
}
|
|
177
|
+
if (!isComponent && !spec!.filters.includes(fm[1])) {
|
|
178
|
+
out.push(diag('KIT-LOOK-001', path, `「${text}」:${type} 没有筛选键「${fm[1]}」(可用 ${spec!.filters.join(' / ') || '无'})`));
|
|
179
|
+
return { diagnostics: out };
|
|
180
|
+
}
|
|
181
|
+
filters[fm[1]] = fm[2].split('|').map((v) => v.trim().replace(/^["']|["']$/g, ''));
|
|
182
|
+
}
|
|
183
|
+
const name = m[2]?.slice(1);
|
|
184
|
+
if (name !== undefined && !isComponent && spec!.named !== true) {
|
|
185
|
+
out.push(diag('KIT-LOOK-001', path, `「${text}」:${type} 没有名字,不能写 #${name}(改用 [键=值])`));
|
|
186
|
+
return { diagnostics: out };
|
|
187
|
+
}
|
|
188
|
+
compounds.push({ type, ...(name !== undefined ? { name } : {}), filters });
|
|
189
|
+
}
|
|
190
|
+
return { selector: { compounds, ...(part !== undefined ? { part } : {}) }, diagnostics: out };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function compoundMatches(c: KitLookCompound, n: KitLookNode): boolean {
|
|
194
|
+
if (c.type !== '*' && c.type !== n.kind && c.type !== n.component) return false;
|
|
195
|
+
if (c.name !== undefined && n.name !== c.name) return false;
|
|
196
|
+
for (const [k, vs] of Object.entries(c.filters)) {
|
|
197
|
+
const v = k === 'name' ? n.name : n.attrs?.[k];
|
|
198
|
+
if (v === undefined || !vs.includes(v)) return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** 从右往左:最右段匹配节点本身,其余段依次匹配祖先链(最近祖先优先) */
|
|
204
|
+
export function lookSelectorMatches(sel: KitLookSelector, n: KitLookNode): boolean {
|
|
205
|
+
const cs = sel.compounds;
|
|
206
|
+
if (cs.length === 0) return false;
|
|
207
|
+
if (!compoundMatches(cs[cs.length - 1]!, n)) return false;
|
|
208
|
+
let cur = n.parent;
|
|
209
|
+
for (let i = cs.length - 2; i >= 0; i -= 1) {
|
|
210
|
+
while (cur !== undefined && !compoundMatches(cs[i]!, cur)) cur = cur.parent;
|
|
211
|
+
if (cur === undefined) return false;
|
|
212
|
+
cur = cur.parent;
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** 部件角色:未写 ::部件 时取节点的「本体」部件(与节点同名的部件,或唯一部件) */
|
|
218
|
+
function partOf(n: KitLookNode, part: string | undefined): string | undefined {
|
|
219
|
+
const ps = n.parts ?? {};
|
|
220
|
+
if (part !== undefined) return part in ps ? part : undefined;
|
|
221
|
+
if (n.kind in ps) return n.kind;
|
|
222
|
+
const keys = Object.keys(ps);
|
|
223
|
+
return keys.length === 1 ? keys[0] : undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** 校验一条声明(属性 × 取值 × 角色 × 绑定);合法返回规范化取值 */
|
|
227
|
+
function checkDecl(prop: string, raw: unknown, role: string, n: KitLookNode, accept: readonly string[] | undefined, path: string, out: KitDiagnostic[]): ReadonlyArray<readonly [string, KitLookValue]> | undefined {
|
|
228
|
+
const spec = G.properties[prop];
|
|
229
|
+
if (spec === undefined) { out.push(diag('KIT-LOOK-003', path, `未知属性「${prop}」(可用 ${Object.keys(G.properties).filter((k) => G.properties[k]!.b2 !== true).join(' / ')})`)); return undefined; }
|
|
230
|
+
if (spec.b2 === true) { out.push(diag('KIT-LOOK-003', path, `${stageTag(prop)}属性「${prop}」本期未开放(已登记,出口未接)`)); return undefined; }
|
|
231
|
+
const roleProps = G.roles[role] ?? [];
|
|
232
|
+
if (!roleProps.includes(prop) || (accept !== undefined && !accept.includes(prop))) {
|
|
233
|
+
out.push(diag('KIT-LOOK-004', path, `部件角色 ${role} 不接受属性「${prop}」(接受 ${(accept ?? roleProps).join(' / ') || '无'})`));
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
if (typeof raw === 'string' && /^(row|item|view)\./.test(raw)) {
|
|
237
|
+
if (!spec.bindable) { out.push(diag('KIT-LOOK-005', path, `「${prop}」不能绑定数据(只有 tone 能随数据变化)`)); return undefined; }
|
|
238
|
+
const prefix = `${raw.split('.')[0]}.`;
|
|
239
|
+
if (!/^(row|item|view)\.[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(raw)) { out.push(diag('KIT-LOOK-005', path, `绑定「${raw}」不是纯路径`)); return undefined; }
|
|
240
|
+
if (prefix === 'row.' && n.inRow !== true) { out.push(diag('KIT-LOOK-005', path, `row. 绑定只能用在集合行里(「${raw}」的宿主不在集合行内)`)); return undefined; }
|
|
241
|
+
if (prefix === 'item.' && n.kind !== 'item') { out.push(diag('KIT-LOOK-005', path, `item. 绑定只能用在条目型组件的项上(「${raw}」)`)); return undefined; }
|
|
242
|
+
// 说明文字部件不收任何 tone(绑定也不收);绑定到装饰性部件的取值运行期才知道,由 applyLook 按 neutral 画并告警
|
|
243
|
+
if (prop === 'tone' && G.toneGroups.none.includes(role)) { out.push(diag('KIT-LOOK-504', path, `${stageTag(prop)}说明文字部件(角色 ${role}:标签、单位)不收 tone,只用墨级 ink`)); return undefined; }
|
|
244
|
+
return [[prop, { bind: raw }]];
|
|
245
|
+
}
|
|
246
|
+
const all: readonly unknown[] = spec.values === 'toneNames' ? kitToneNames() : spec.values === 'icons.names' ? ICONS : spec.values === 'limits.columns' ? KIT_LOOK_LIMITS.columns : Array.isArray(spec.values) ? spec.values : [];
|
|
247
|
+
const values = spec.byRole?.[role] ?? all;
|
|
248
|
+
const v = typeof raw === 'string' && prop === 'tone' ? (TONES.aliases[raw] ?? raw) : raw;
|
|
249
|
+
if (!values.includes(v)) {
|
|
250
|
+
const rawHint = typeof raw === 'string' && RAW_VALUE.test(raw) ? '(不收原始值:色值、带单位的数字、类名)' : '';
|
|
251
|
+
out.push(diag('KIT-LOOK-003', path, `${stageTag(prop)}「${prop}: ${String(raw)}」取值不在闭集${rawHint}:可用 ${values.slice(0, 16).map(String).join(' / ')}`));
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
if (spec.unwiredValues?.includes(v) === true) {
|
|
255
|
+
out.push(diag('KIT-LOOK-003', path, `${stageTag(prop)}「${prop}: ${String(raw)}」本期未开放(取值已登记,出口未接)`));
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
if (prop === 'tone') {
|
|
259
|
+
if (G.toneGroups.none.includes(role)) {
|
|
260
|
+
out.push(diag('KIT-LOOK-504', path, `${stageTag(prop)}说明文字部件(角色 ${role}:标签、单位)不收 tone,只用墨级 ink`));
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
if (G.toneGroups.decorative.includes(role) && !G.toneGroups.decorativeTones.includes(v as string)) {
|
|
264
|
+
out.push(diag('KIT-LOOK-504', path, `${stageTag(prop)}语义色不作装饰:装饰性部件(角色 ${role})只收 ${G.toneGroups.decorativeTones.join(' / ')},「${String(v)}」写到承载数据的部件上(值、标记、指标数值、填充、行)`));
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// 过渡期旧写法:照收并改写成新写法(角色不收的那一半丢掉,如 row 没有 text),告警给出新写法
|
|
269
|
+
const dep = typeof v === 'string' ? spec.deprecatedValues?.[v] : undefined;
|
|
270
|
+
if (dep !== undefined) {
|
|
271
|
+
out.push(diag('KIT-LOOK-012', path, `${stageTag(prop)}「${prop}: ${v as string}」是过渡期旧写法,已按 ${Object.entries(dep).map(([k, x]) => `${k}: ${x}`).join(' + ')} 渲染:改成新写法`));
|
|
272
|
+
return Object.entries(dep).filter(([k]) => roleProps.includes(k) && (accept === undefined || accept.includes(k))).map(([k, x]) => [k, x] as const);
|
|
273
|
+
}
|
|
274
|
+
return [[prop, v as KitLookValue]];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface Hit { node: KitLookNode; part: string; prop: string }
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 求值:rules 按层、层内按书写序给出(调用方保证同层书写序);nodes = 语义节点树的全部节点(先序)。
|
|
281
|
+
* 没有规则时直接返回空表——没写规则的页面不经过任何改写(产物逐字节不变)。
|
|
282
|
+
*/
|
|
283
|
+
export function resolveLook(rules: readonly KitLookRule[], nodes: readonly KitLookNode[], scope: 'page' | 'app' = 'page'): KitLookResolved {
|
|
284
|
+
const table = new Map<KitLookNode, KitLookParts>();
|
|
285
|
+
const sources = new Map<KitLookNode, Record<string, Record<string, string>>>();
|
|
286
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
287
|
+
if (rules.length === 0) return { table, sources, diagnostics };
|
|
288
|
+
const ordered = rules.map((r, i) => ({ r, i })).sort((a, b) => a.r.layer - b.r.layer || a.i - b.i).map((x) => x.r);
|
|
289
|
+
const owner = new Map<string, number>(); // (节点, 部件, 属性) → 最后写它的规则序号
|
|
290
|
+
const keyOf = (h: Hit, nodeIx: number): string => `${nodeIx}\u0000${h.part}\u0000${h.prop}`;
|
|
291
|
+
const nodeIx = new Map<KitLookNode, number>();
|
|
292
|
+
nodes.forEach((n, i) => nodeIx.set(n, i));
|
|
293
|
+
const hits: Hit[][] = [];
|
|
294
|
+
ordered.forEach((rule, ri) => {
|
|
295
|
+
const mine: Hit[] = [];
|
|
296
|
+
hits.push(mine);
|
|
297
|
+
let targets: { node: KitLookNode; part?: string }[];
|
|
298
|
+
if (rule.host !== undefined) {
|
|
299
|
+
const sel = rule.selector.trim();
|
|
300
|
+
const part = sel.startsWith(G.selector.partSeparator) ? sel.slice(G.selector.partSeparator.length) : sel === '' ? undefined : null;
|
|
301
|
+
if (part === null || (part !== undefined && !IDENT.test(part))) { diagnostics.push(diag('KIT-LOOK-002', rule.path, `就地 look 只写本节点的部件("::部件"),不能写选择器「${sel}」`)); return; }
|
|
302
|
+
targets = [{ node: rule.host, ...(part !== undefined ? { part } : {}) }];
|
|
303
|
+
} else {
|
|
304
|
+
const parsed = parseLookSelector(rule.selector, rule.path);
|
|
305
|
+
diagnostics.push(...parsed.diagnostics);
|
|
306
|
+
if (parsed.selector === undefined) return;
|
|
307
|
+
const sel = parsed.selector;
|
|
308
|
+
targets = nodes.filter((n) => lookSelectorMatches(sel, n)).map((node) => ({ node, ...(sel.part !== undefined ? { part: sel.part } : {}) }));
|
|
309
|
+
}
|
|
310
|
+
const declEntries = Object.entries(rule.decls ?? {});
|
|
311
|
+
let validated = false;
|
|
312
|
+
for (const t of targets) {
|
|
313
|
+
const part = partOf(t.node, t.part);
|
|
314
|
+
if (part === undefined) {
|
|
315
|
+
// 节点没有这个部件:不计命中(如无标题面板的 ::icon);就地写的节点自身属性没有去处要说出来
|
|
316
|
+
if (rule.host !== undefined && t.part === undefined) diagnostics.push(diag('KIT-LOOK-004', rule.path, `就地 look 写了本节点自身的属性(${declEntries.map(([k]) => k).join(' / ')}),但这个节点没有可写的本体部件:改写到它的部件上("::部件")`));
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const role = t.node.parts![part]!;
|
|
320
|
+
for (const [prop, raw] of declEntries) {
|
|
321
|
+
const before = diagnostics.length;
|
|
322
|
+
const pairs = checkDecl(prop, raw, role, t.node, t.node.accept?.[part], `${rule.path}.${prop}`, diagnostics);
|
|
323
|
+
// 同一条规则同一个错只报一次(命中多个节点时)
|
|
324
|
+
if (validated && diagnostics.length > before) diagnostics.splice(before);
|
|
325
|
+
if (pairs === undefined) continue;
|
|
326
|
+
for (const [outProp, v] of pairs) {
|
|
327
|
+
const parts = table.get(t.node) ?? {};
|
|
328
|
+
(parts[part] ??= {})[outProp] = v;
|
|
329
|
+
table.set(t.node, parts);
|
|
330
|
+
const src = sources.get(t.node) ?? {};
|
|
331
|
+
(src[part] ??= {})[outProp] = rule.path;
|
|
332
|
+
sources.set(t.node, src);
|
|
333
|
+
const h = { node: t.node, part, prop: outProp };
|
|
334
|
+
mine.push(h);
|
|
335
|
+
owner.set(keyOf(h, nodeIx.get(t.node) ?? -1), ri);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
validated = true;
|
|
339
|
+
}
|
|
340
|
+
if (rule.host === undefined && mine.length === 0 && !diagnostics.some((d) => d.path.startsWith(rule.path))) {
|
|
341
|
+
diagnostics.push(diag('KIT-LOOK-006', rule.path, `规则「${rule.selector}」${scope === 'app' ? '在全应用' : '在本页'}零命中:删掉它,或改选择器`));
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
hits.forEach((mine, ri) => {
|
|
345
|
+
if (mine.length === 0) return;
|
|
346
|
+
const live = mine.some((h) => owner.get(keyOf(h, nodeIx.get(h.node) ?? -1)) === ri);
|
|
347
|
+
if (!live) {
|
|
348
|
+
const rule = ordered[ri]!;
|
|
349
|
+
diagnostics.push(diag('KIT-LOOK-007', rule.path, `规则「${rule.selector}」被完全遮蔽:它改到的每一项都被同层后写或更高层的规则覆盖(同层后写胜;宽规则写在前、窄规则写在后)`));
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
return { table, sources, diagnostics };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** 从 YAML 映射读规则(有序映射:选择器 → 声明);不是映射 → KIT-LOOK-003 */
|
|
356
|
+
export function lookRulesOf(raw: unknown, layer: KitLookLayer, path: string, host?: KitLookNode): { rules: KitLookRule[]; diagnostics: KitDiagnostic[] } {
|
|
357
|
+
const rules: KitLookRule[] = [];
|
|
358
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
359
|
+
if (raw === undefined || raw === null) return { rules, diagnostics };
|
|
360
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
361
|
+
diagnostics.push(diag('KIT-LOOK-003', path, 'look 写成有序映射:「选择器: { 属性: 取值 }」'));
|
|
362
|
+
return { rules, diagnostics };
|
|
363
|
+
}
|
|
364
|
+
// 就地(L3):以 :: 开头的键是本节点的部件,其余取值是标量的键是本节点自身的属性(look: { span: half }),合成一条空选择器规则
|
|
365
|
+
const own: Record<string, unknown> = {};
|
|
366
|
+
for (const [selector, decls] of Object.entries(raw as Record<string, unknown>)) {
|
|
367
|
+
if (host !== undefined && (decls === null || typeof decls !== 'object')) { own[selector] = decls; continue; }
|
|
368
|
+
if (decls === null || typeof decls !== 'object' || Array.isArray(decls)) {
|
|
369
|
+
diagnostics.push(diag('KIT-LOOK-003', `${path}.${selector}`, `「${selector}」的值写成 { 属性: 取值 }`));
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
rules.push({ selector, decls: decls as Record<string, unknown>, layer, path: `${path}.${selector}`, ...(host !== undefined ? { host } : {}) });
|
|
373
|
+
}
|
|
374
|
+
if (host !== undefined && Object.keys(own).length > 0) rules.push({ selector: '', decls: own, layer, path, host });
|
|
375
|
+
return { rules, diagnostics };
|
|
376
|
+
}
|