soma-kit 0.1.15 → 0.1.16
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 +934 -92
- 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 +186 -57
- 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 +130 -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 +1015 -53
- 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 +424 -103
- 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
package/src/base/price-text.ts
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { kitLocaleAt } from '../i18n/kit-text';
|
|
10
10
|
import { createFormatter } from 'soma-foundation/values';
|
|
11
|
+
import { KIT_ATTR_ORIGINAL } from '../shared/dom-attrs';
|
|
11
12
|
import {
|
|
12
13
|
CLASS_PROP, ID_PROPS,
|
|
13
14
|
applyCommon, classCandidates, createKitController, joinClass, num, str,
|
|
15
|
+
kitInlineRootAlign, kitMarkDataState, kitOuterRoot, kitReadProps,
|
|
14
16
|
type KitSize,
|
|
15
17
|
} from './shared';
|
|
16
18
|
|
|
@@ -18,21 +20,24 @@ const CURRENCY_CODE = /^[A-Za-z]{3}$/;
|
|
|
18
20
|
const LOCALE_FALLBACK = 'zh-CN';
|
|
19
21
|
|
|
20
22
|
const ROOT: Record<KitSize, string> = {
|
|
21
|
-
sm: 'inline-flex items-baseline gap-1.5 text-sm',
|
|
22
|
-
md: 'inline-flex items-baseline gap-2 text-base',
|
|
23
|
-
lg: 'inline-flex items-baseline gap-2 text-xl',
|
|
23
|
+
sm: 'inline-flex items-baseline gap-1.5 text-sm tabular-nums',
|
|
24
|
+
md: 'inline-flex items-baseline gap-2 text-base tabular-nums',
|
|
25
|
+
lg: 'inline-flex items-baseline gap-2 text-xl tabular-nums',
|
|
24
26
|
};
|
|
25
|
-
const NOW: Record<'normal' | 'negative' | 'muted', string> = {
|
|
27
|
+
const NOW: Record<'normal' | 'negative' | 'muted' | 'empty', string> = {
|
|
26
28
|
normal: 'font-semibold text-fg',
|
|
27
29
|
negative: 'font-semibold text-danger-on-soft',
|
|
28
30
|
muted: 'font-semibold text-fg-muted',
|
|
31
|
+
empty: 'font-normal text-fg-subtle',
|
|
29
32
|
};
|
|
30
33
|
const ORIGINAL = 'text-xs text-fg-subtle line-through';
|
|
31
34
|
const HIDDEN = 'hidden';
|
|
35
|
+
const DEFAULT_PLACEHOLDER = '—';
|
|
32
36
|
|
|
33
37
|
export const KIT_PRICE_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
34
38
|
Object.values(ROOT), Object.values(NOW), ORIGINAL, HIDDEN,
|
|
35
39
|
);
|
|
40
|
+
// 页面线对齐换上的块级根与自动外边距(kitInlineRootAlign)只在新模式下用到,由 data/kit-contract.ts#KIT_CONTRACT_CLASS_CANDIDATES 统一并入,不进本组件候选
|
|
36
41
|
|
|
37
42
|
export interface PriceSpec {
|
|
38
43
|
currency: string;
|
|
@@ -42,6 +47,27 @@ export interface PriceSpec {
|
|
|
42
47
|
locale: string;
|
|
43
48
|
}
|
|
44
49
|
|
|
50
|
+
type PriceFormatter = ReturnType<typeof createFormatter>;
|
|
51
|
+
const FORMATTER_CACHE = new Map<string, PriceFormatter>();
|
|
52
|
+
const FORMATTER_CACHE_MAX = 64;
|
|
53
|
+
|
|
54
|
+
function cachedPriceFormatter(spec: PriceSpec): PriceFormatter {
|
|
55
|
+
const digitsKey = spec.minFraction !== undefined || spec.maxFraction !== undefined
|
|
56
|
+
? `${spec.minFraction ?? ''}:${spec.maxFraction ?? ''}`
|
|
57
|
+
: '';
|
|
58
|
+
const key = `${spec.locale}|${spec.currency}|${digitsKey}`;
|
|
59
|
+
let fmt = FORMATTER_CACHE.get(key);
|
|
60
|
+
if (!fmt) {
|
|
61
|
+
if (FORMATTER_CACHE.size >= FORMATTER_CACHE_MAX) {
|
|
62
|
+
const oldest = FORMATTER_CACHE.keys().next().value;
|
|
63
|
+
if (oldest !== undefined) FORMATTER_CACHE.delete(oldest);
|
|
64
|
+
}
|
|
65
|
+
fmt = createFormatter({ locale: spec.locale, fallbackLocale: LOCALE_FALLBACK, placeholder: DEFAULT_PLACEHOLDER, now: () => Date.now() });
|
|
66
|
+
FORMATTER_CACHE.set(key, fmt);
|
|
67
|
+
}
|
|
68
|
+
return fmt;
|
|
69
|
+
}
|
|
70
|
+
|
|
45
71
|
function digitsOf(raw: unknown): number | undefined {
|
|
46
72
|
const n = num(raw);
|
|
47
73
|
return n !== null && n >= 0 && n <= 6 ? Math.floor(n) : undefined;
|
|
@@ -57,13 +83,14 @@ export function priceSpecOf(p: Record<string, unknown>): PriceSpec {
|
|
|
57
83
|
};
|
|
58
84
|
}
|
|
59
85
|
|
|
60
|
-
/** 金额文字;值不是有限数字 -> placeholder(缺省 '
|
|
61
|
-
export function formatPrice(value: unknown, spec: PriceSpec, placeholder =
|
|
62
|
-
if (value === null || value === undefined
|
|
86
|
+
/** 金额文字;值不是有限数字 -> placeholder(缺省 '—') */
|
|
87
|
+
export function formatPrice(value: unknown, spec: PriceSpec, placeholder = DEFAULT_PLACEHOLDER): string {
|
|
88
|
+
if (value === null || value === undefined) return placeholder;
|
|
89
|
+
if (typeof value === 'string' && value.trim() === '') return placeholder;
|
|
63
90
|
const n = typeof value === 'number' ? value : Number(value);
|
|
64
91
|
if (!Number.isFinite(n)) return placeholder;
|
|
65
92
|
try {
|
|
66
|
-
const fmt =
|
|
93
|
+
const fmt = cachedPriceFormatter(spec);
|
|
67
94
|
return fmt.currency(typeof value === 'string' ? value : n, {
|
|
68
95
|
currency: spec.currency,
|
|
69
96
|
...(spec.minFraction !== undefined ? { minFraction: spec.minFraction } : {}),
|
|
@@ -86,7 +113,7 @@ export function createPriceText(): SomaComponentDefinition {
|
|
|
86
113
|
digits: { type: 'string', default: '', desc: '固定小数位数 0..6;空为按币种默认' },
|
|
87
114
|
locale: { type: 'string', default: '', desc: '格式化语言环境;缺省取页面语言(page.locale),都没声明为 zh-CN' },
|
|
88
115
|
negative: { type: 'enum', values: ['danger', 'plain'], default: 'danger', desc: '负数:danger 着色 / plain 不着色' },
|
|
89
|
-
placeholder: { type: 'string', default:
|
|
116
|
+
placeholder: { type: 'string', default: DEFAULT_PLACEHOLDER, desc: '金额不可用时的占位' },
|
|
90
117
|
muted: { type: 'boolean', default: false, desc: '次要色(如已失效的价格)' },
|
|
91
118
|
...ID_PROPS,
|
|
92
119
|
size: { type: 'enum', values: ['sm', 'md', 'lg'], default: 'md', desc: '字号档' },
|
|
@@ -97,30 +124,37 @@ export function createPriceText(): SomaComponentDefinition {
|
|
|
97
124
|
templateHtml:
|
|
98
125
|
`<span data-soma-id="root" class="${ROOT.md}">` +
|
|
99
126
|
`<span data-soma-id="now" class="${NOW.normal}"></span><del data-soma-id="was" class="${HIDDEN}"></del></span>`,
|
|
127
|
+
// 金额是值:根只报元素部件,不报层级角色
|
|
100
128
|
controllerFactory: createKitController(() => ({
|
|
101
|
-
render(root, p) {
|
|
129
|
+
render(root, p, api) {
|
|
102
130
|
const spec = priceSpecOf({ ...p, locale: str(p.locale, kitLocaleAt(root)) });
|
|
103
|
-
const placeholder = str(p.placeholder,
|
|
131
|
+
const placeholder = str(p.placeholder, DEFAULT_PLACEHOLDER);
|
|
104
132
|
const now = root.querySelector<HTMLElement>('[data-soma-id="now"], [data-soma-scoped-id="now"]');
|
|
105
133
|
const was = root.querySelector<HTMLElement>('[data-soma-id="was"], [data-soma-scoped-id="was"]');
|
|
106
134
|
const n = num(p.value);
|
|
107
135
|
if (now) {
|
|
108
136
|
now.textContent = formatPrice(p.value, spec, placeholder);
|
|
109
|
-
now.className = n
|
|
110
|
-
? NOW.
|
|
111
|
-
:
|
|
137
|
+
now.className = n === null
|
|
138
|
+
? NOW.empty
|
|
139
|
+
: n < 0 && str(p.negative, 'danger') !== 'plain'
|
|
140
|
+
? NOW.negative
|
|
141
|
+
: p.muted === true || p.muted === 'true' ? NOW.muted : NOW.normal;
|
|
112
142
|
}
|
|
113
143
|
if (was) {
|
|
114
144
|
const hasOriginal = num(p.original) !== null;
|
|
115
145
|
was.textContent = hasOriginal ? formatPrice(p.original, spec, placeholder) : '';
|
|
116
146
|
was.className = hasOriginal ? ORIGINAL : HIDDEN;
|
|
117
147
|
// 划线靠 <del> 语义之外的类实现;文字本身保持金额,读屏按顺序读出现价、原价
|
|
118
|
-
was.setAttribute(
|
|
148
|
+
was.setAttribute(KIT_ATTR_ORIGINAL, hasOriginal ? 'true' : 'false');
|
|
119
149
|
}
|
|
120
150
|
applyCommon(root, { id: p.id, aria_label: p.aria_label });
|
|
121
151
|
const sz = p.size === 'sm' || p.size === 'lg' ? p.size : 'md';
|
|
122
|
-
|
|
152
|
+
// 逻辑对齐(页面线判定,如表格金额列靠止端):根是 inline-flex,文本对齐类对它自身无效,所以换成块级根 + 自动外边距真正移动位置
|
|
153
|
+
// (kitInlineRootAlign);p.class 已有对齐类时以自有类为准;没有判定时类串与原来一致
|
|
154
|
+
const align = kitReadProps(p).align;
|
|
155
|
+
root.className = joinClass(kitInlineRootAlign(ROOT[sz], align, p.class), p.class);
|
|
156
|
+
kitMarkDataState(kitOuterRoot(api.host, root), n === null ? 'empty' : 'normal');
|
|
123
157
|
},
|
|
124
|
-
})),
|
|
158
|
+
}), { self: { part: 'value' } }),
|
|
125
159
|
};
|
|
126
160
|
}
|
package/src/base/progress.ts
CHANGED
|
@@ -5,39 +5,56 @@
|
|
|
5
5
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
7
|
import { kitText } from '../i18n/kit-text';
|
|
8
|
+
import { kitIcon } from '../shared/icons';
|
|
9
|
+
import { mergeClass } from '../shared/merge-class';
|
|
10
|
+
import { KIT_ATTR_MINI_BAR } from '../shared/dom-attrs';
|
|
11
|
+
import { KIT_CONTROL_TRACK_CLASS, kitToneFillClass, type KitSemanticOrCategoryTone } from '../recipes/color-role';
|
|
8
12
|
import {
|
|
9
13
|
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
10
14
|
classCandidates, createKitController, joinClass, num, setAttr, sizeOf, str,
|
|
15
|
+
kitReadProps, kitToneOfPipeline,
|
|
11
16
|
type KitSize,
|
|
12
17
|
} from './shared';
|
|
13
18
|
|
|
14
19
|
export type ProgressShape = 'ring' | 'bar' | 'dots';
|
|
15
20
|
export type ProgressTone = 'primary' | 'info' | 'success' | 'warning' | 'danger';
|
|
21
|
+
export type ProgressStatus = '' | 'complete' | 'exception';
|
|
16
22
|
|
|
17
23
|
const RING_ROOT: Record<KitSize, string> = {
|
|
18
24
|
sm: 'relative inline-flex h-10 w-10 shrink-0 items-center justify-center',
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
// 取值表 02 §6(Ant progress/utils):环直径 小 60 / 大 120(随 density 比例);环内文字 20 / 500
|
|
26
|
+
md: 'relative inline-flex h-15 w-15 shrink-0 items-center justify-center',
|
|
27
|
+
lg: 'relative inline-flex h-30 w-30 shrink-0 items-center justify-center',
|
|
21
28
|
};
|
|
22
29
|
const RING_TEXT: Record<KitSize, string> = {
|
|
23
|
-
sm: 'absolute text-xs font-medium text-fg',
|
|
24
|
-
md: 'absolute text-sm font-medium text-fg',
|
|
25
|
-
lg: 'absolute text-
|
|
30
|
+
sm: 'absolute text-xs font-medium tabular-nums text-fg',
|
|
31
|
+
md: 'absolute text-sm font-medium tabular-nums text-fg',
|
|
32
|
+
lg: 'absolute text-xl font-medium tabular-nums text-fg',
|
|
26
33
|
};
|
|
27
34
|
const BAR_ROOT = 'flex w-full items-center gap-2';
|
|
35
|
+
// 条文字 12 / 次要色(取值表 02 §6:Arco 12 / Ant 14);条高 小 4 / 缺省 6 / 大 8(Ant 8 / TDesign 6)
|
|
28
36
|
const BAR_TEXT: Record<KitSize, string> = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// 等宽数字 + 最小宽 + 右对齐:百分比跳动时条不抖(组件卡 Progress §6)
|
|
38
|
+
sm: 'min-w-10 shrink-0 text-end text-xs font-medium tabular-nums text-fg-muted',
|
|
39
|
+
md: 'min-w-10 shrink-0 text-end text-xs font-medium tabular-nums text-fg-muted',
|
|
40
|
+
lg: 'min-w-12 shrink-0 text-end text-sm font-medium tabular-nums text-fg-muted',
|
|
32
41
|
};
|
|
42
|
+
// 末端状态图标(成功 / 异常):条文字位换成语气色图标,环中心文字位换成图标;与文字同占一格
|
|
43
|
+
const STATUS_ICON: Record<'success' | 'danger', string> = {
|
|
44
|
+
success: 'shrink-0 text-success',
|
|
45
|
+
danger: 'shrink-0 text-danger',
|
|
46
|
+
};
|
|
47
|
+
const BAR_STATUS_ICON_WRAP = 'inline-flex min-w-10 shrink-0 items-center justify-end';
|
|
48
|
+
const RING_STATUS_ICON_WRAP = 'absolute inline-flex items-center justify-center';
|
|
33
49
|
const RING_SVG = 'h-full w-full';
|
|
34
50
|
const BAR_SVG: Record<KitSize, string> = {
|
|
35
51
|
sm: 'block h-1 w-full overflow-hidden rounded-full',
|
|
36
52
|
md: 'block h-1.5 w-full overflow-hidden rounded-full',
|
|
37
|
-
lg: 'block h-2
|
|
53
|
+
lg: 'block h-2 w-full overflow-hidden rounded-full',
|
|
38
54
|
};
|
|
39
|
-
|
|
40
|
-
const
|
|
55
|
+
// 轨 = 宿主自适应控件滑轨色(放在凹槽井或子块内仍具清晰层次),不用边线令牌
|
|
56
|
+
const TRACK_RING = 'fill-none stroke-control-track';
|
|
57
|
+
const TRACK_BAR = mergeClass('fill-control-track', KIT_CONTROL_TRACK_CLASS);
|
|
41
58
|
const ARC: Record<ProgressTone, string> = {
|
|
42
59
|
primary: 'fill-none stroke-primary',
|
|
43
60
|
info: 'fill-none stroke-info',
|
|
@@ -86,12 +103,37 @@ const DOT_GAP: Record<KitSize, number> = { sm: 12, md: 16, lg: 20 };
|
|
|
86
103
|
const DOT_RADIUS: Record<KitSize, number> = { sm: 3, md: 4, lg: 5 };
|
|
87
104
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
88
105
|
|
|
106
|
+
const MINI_BAR_TONES: readonly KitSemanticOrCategoryTone[] = Object.freeze([
|
|
107
|
+
'primary', 'info', 'success', 'warning', 'danger', 'neutral', 'tertiary', 'second',
|
|
108
|
+
'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8',
|
|
109
|
+
]);
|
|
110
|
+
|
|
89
111
|
export const KIT_PROGRESS_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
90
112
|
Object.values(RING_ROOT), Object.values(RING_TEXT), BAR_ROOT, Object.values(BAR_TEXT), RING_SVG,
|
|
91
|
-
Object.values(BAR_SVG), TRACK_RING, TRACK_BAR, Object.values(ARC), Object.values(FILL),
|
|
113
|
+
Object.values(BAR_SVG), TRACK_RING, TRACK_BAR, Object.values(ARC), Object.values(FILL),
|
|
114
|
+
MINI_BAR_TONES.map((t) => kitToneFillClass(t)), HIDDEN,
|
|
92
115
|
Object.values(BUFFER), Object.values(FILL_INDET), Object.values(ARC_INDET), DOTS_SVG, DOTS_SVG_INDET,
|
|
116
|
+
Object.values(STATUS_ICON), BAR_STATUS_ICON_WRAP, RING_STATUS_ICON_WRAP,
|
|
93
117
|
);
|
|
94
118
|
|
|
119
|
+
/**
|
|
120
|
+
* 迷你条(指标配套元素,DC2 一层缺省:单位为 % 的比率在数值下出一根细条,自然上限 100):与条形进度同一组形体类(sm 轨道 + 填充),
|
|
121
|
+
* 只画图形、不带文字与 role(数值已在旁边读出,条是 aria-hidden 的冗余编码)。tone 支持语义色与分类色 c1..c8,缺省主色。
|
|
122
|
+
*/
|
|
123
|
+
export function kitMiniBarNode(doc: Document, percent: number, tone: ProgressTone | KitSemanticOrCategoryTone = 'primary'): SVGSVGElement {
|
|
124
|
+
const svg = doc.createElementNS(SVG_NS, 'svg');
|
|
125
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
126
|
+
svg.setAttribute('class', BAR_SVG.sm);
|
|
127
|
+
svg.setAttribute(KIT_ATTR_MINI_BAR, '');
|
|
128
|
+
const rect = (width: string, cls: string): SVGRectElement => {
|
|
129
|
+
const r = doc.createElementNS(SVG_NS, 'rect');
|
|
130
|
+
for (const [k, v] of [['x', '0'], ['y', '0'], ['width', width], ['height', '100%'], ['ry', '50%'], ['class', cls]] as const) r.setAttribute(k, v);
|
|
131
|
+
return r;
|
|
132
|
+
};
|
|
133
|
+
svg.append(rect('100%', TRACK_BAR), rect(`${clampPercent(percent)}%`, kitToneFillClass(tone)));
|
|
134
|
+
return svg;
|
|
135
|
+
}
|
|
136
|
+
|
|
95
137
|
export function clampPercent(raw: unknown): number {
|
|
96
138
|
const n = num(raw);
|
|
97
139
|
if (n === null) return 0;
|
|
@@ -115,6 +157,10 @@ function indeterminateOf(raw: unknown): boolean {
|
|
|
115
157
|
return raw === true || raw === 'true';
|
|
116
158
|
}
|
|
117
159
|
|
|
160
|
+
function statusOf(raw: unknown): ProgressStatus {
|
|
161
|
+
return raw === 'complete' || raw === 'exception' ? raw : '';
|
|
162
|
+
}
|
|
163
|
+
|
|
118
164
|
export function createKitProgress(): SomaComponentDefinition {
|
|
119
165
|
return {
|
|
120
166
|
contract: {
|
|
@@ -126,7 +172,8 @@ export function createKitProgress(): SomaComponentDefinition {
|
|
|
126
172
|
indeterminate: { type: 'boolean', default: false, desc: '不确定态(不知道进度多少):条形一段色块来回扫、环形一段弧呼吸、点阵整体呼吸;减少动效下静止;不带 aria-valuenow,文字只显示 label' },
|
|
127
173
|
buffer: { type: 'string', default: '', desc: '缓冲进度 0~100(条形:画在进度段之下的淡色段,如视频已缓冲);空 = 不画' },
|
|
128
174
|
tone: { type: 'enum', values: ['primary', 'info', 'success', 'warning', 'danger'], default: 'primary', desc: '进度色' },
|
|
129
|
-
|
|
175
|
+
status: { type: 'enum', values: ['', 'complete', 'exception'], default: '', desc: '末端状态:显式指定 complete / exception(或满 100 且 tone=success)时将右侧百分比换成完成/异常图标' },
|
|
176
|
+
show_text: { type: 'boolean', default: true, desc: '显示百分比文字或末端状态图标' },
|
|
130
177
|
label: { type: 'string', default: '', desc: '自定义文字,非空时替代百分比' },
|
|
131
178
|
id: ID_PROPS.id,
|
|
132
179
|
aria_label: ID_PROPS.aria_label,
|
|
@@ -141,7 +188,9 @@ export function createKitProgress(): SomaComponentDefinition {
|
|
|
141
188
|
const value = clampPercent(p.value);
|
|
142
189
|
const shape = shapeOf(p.shape);
|
|
143
190
|
const size = sizeOf(p.size);
|
|
144
|
-
|
|
191
|
+
// 进度色:组件自己写了非缺省(primary 是契约缺省)的 tone 优先,否则取页面线的语义色调(中性 / 无不改色)
|
|
192
|
+
const kitTone = kitToneOfPipeline(kitReadProps(p).tone);
|
|
193
|
+
const tone = toneOf(p.tone !== 'primary' && str(p.tone) !== '' ? p.tone : kitTone ?? p.tone);
|
|
145
194
|
const [ring, bar, dots, text] = Array.from(root.children) as [SVGElement, SVGElement, SVGElement, HTMLElement];
|
|
146
195
|
const isRing = shape === 'ring';
|
|
147
196
|
const isBar = shape === 'bar';
|
|
@@ -196,9 +245,41 @@ export function createKitProgress(): SomaComponentDefinition {
|
|
|
196
245
|
dots.textContent = '';
|
|
197
246
|
}
|
|
198
247
|
const custom = str(p.label);
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
248
|
+
const allowRightSlot = p.show_text !== false && p.show_text !== 'false';
|
|
249
|
+
const explicitStatus = statusOf(p.status);
|
|
250
|
+
const statusIconTone: 'success' | 'danger' | null = !indeterminate && shape !== 'dots' && custom === ''
|
|
251
|
+
? (explicitStatus === 'complete'
|
|
252
|
+
? 'success'
|
|
253
|
+
: explicitStatus === 'exception'
|
|
254
|
+
? 'danger'
|
|
255
|
+
: value >= 100 && tone === 'success'
|
|
256
|
+
? 'success'
|
|
257
|
+
: null)
|
|
258
|
+
: null;
|
|
259
|
+
const dataState = !indeterminate
|
|
260
|
+
? (explicitStatus === 'exception' || tone === 'danger'
|
|
261
|
+
? 'exception'
|
|
262
|
+
: explicitStatus === 'complete' || value >= 100
|
|
263
|
+
? 'complete'
|
|
264
|
+
: null)
|
|
265
|
+
: null;
|
|
266
|
+
if (!allowRightSlot) {
|
|
267
|
+
text.replaceChildren();
|
|
268
|
+
text.className = HIDDEN;
|
|
269
|
+
root.removeAttribute('aria-valuetext');
|
|
270
|
+
} else if (statusIconTone !== null) {
|
|
271
|
+
text.replaceChildren(kitIcon(statusIconTone === 'success' ? 'check' : 'close', isRing ? (size === 'sm' ? 'sm' : 'lg') : 'sm', STATUS_ICON[statusIconTone]));
|
|
272
|
+
text.className = isRing ? RING_STATUS_ICON_WRAP : BAR_STATUS_ICON_WRAP;
|
|
273
|
+
// 图标不进读屏文字,状态由 aria-valuetext 给
|
|
274
|
+
root.setAttribute('aria-valuetext', `${Math.round(value)}%`);
|
|
275
|
+
} else {
|
|
276
|
+
const showText = custom !== '' || !indeterminate;
|
|
277
|
+
text.textContent = custom !== '' ? custom : `${Math.round(value)}%`;
|
|
278
|
+
text.className = !showText ? HIDDEN : isRing ? RING_TEXT[size] : BAR_TEXT[size];
|
|
279
|
+
root.removeAttribute('aria-valuetext');
|
|
280
|
+
}
|
|
281
|
+
if (dataState !== null) root.setAttribute('data-state', dataState);
|
|
282
|
+
else root.removeAttribute('data-state');
|
|
202
283
|
root.setAttribute('role', 'progressbar');
|
|
203
284
|
root.setAttribute('aria-valuemin', '0');
|
|
204
285
|
root.setAttribute('aria-valuemax', '100');
|
|
@@ -211,6 +292,7 @@ export function createKitProgress(): SomaComponentDefinition {
|
|
|
211
292
|
if (indeterminate) root.setAttribute('aria-busy', 'true'); else root.removeAttribute('aria-busy');
|
|
212
293
|
root.className = joinClass(isRing ? RING_ROOT[size] : BAR_ROOT, p.class);
|
|
213
294
|
},
|
|
214
|
-
|
|
295
|
+
// 进度是指标:根只报元素部件
|
|
296
|
+
}), { self: { part: 'metric' } }),
|
|
215
297
|
};
|
|
216
298
|
}
|
package/src/base/qr-code.ts
CHANGED
|
@@ -3,32 +3,53 @@
|
|
|
3
3
|
// 归类(2.1a 四问):单值展示(文本 -> 图形),没有对象形状 -> 基础组件。不引入第三方库:最小的 QR Code Model 2 编码器在本文件
|
|
4
4
|
// (字节模式、UTF-8、版本 1–10、纠错 L / M / Q / H、8 种掩码按罚分自动择优),做法与公开的 QR 规范(ISO/IEC 18004)一致;
|
|
5
5
|
// 不支持数字 / 字母数字 / 汉字模式与版本 11 以上(容量:纠错 M 约 213 字节,L 约 271 字节),超出时不画并抛 `error { reason: 'too-long' }`。
|
|
6
|
-
// 输出是 SVG:背景一个 rect,暗模块按行合并成横向长条 rect,颜色走 `fill-
|
|
7
|
-
//
|
|
6
|
+
// 输出是 SVG:背景一个 rect,暗模块按行合并成横向长条 rect,颜色走 `fill-static-black` / `fill-static-white` 物理恒量类(暗色模式下绝不翻转,
|
|
7
|
+
// 保障光学扫码器在亮/暗任意宿主下 100% 可靠识别)。四周静区 `quiet` 默认 4 个模块(规范值)。读屏读 `label`(缺省「二维码」),不朗读矩阵。
|
|
8
8
|
// 值是纯字符串,不进样式;组件不联网、不做 URL 校验。
|
|
9
9
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
|
-
import { kitText } from '../i18n/kit-text';
|
|
11
|
+
import { kitLocaleAt, kitText, kitTextLocaleOf } from '../i18n/kit-text';
|
|
12
|
+
import { KIT_STATIC_QR_INK_CLASS, KIT_STATIC_QR_SURFACE_CLASS } from '../recipes/color-role';
|
|
13
|
+
import { kitWellRecipe } from '../recipes/surface';
|
|
14
|
+
import { kitTypographyRecipe, KIT_TYPOGRAPHY_RECIPE_CLASS_CANDIDATES } from '../recipes/typography';
|
|
15
|
+
import { KIT_ICON_CLASS_CANDIDATES, kitIcon } from '../shared/icons';
|
|
16
|
+
import { mergeClass } from '../shared/merge-class';
|
|
17
|
+
import { KIT_ATTR_STATE } from '../shared/dom-attrs';
|
|
12
18
|
import {
|
|
13
19
|
CLASS_PROP, ID_PROPS, classCandidates,
|
|
14
20
|
createKitController, joinClass, num, setAttr, str,
|
|
21
|
+
kitMarkDataState, kitOuterRoot,
|
|
15
22
|
} from './shared';
|
|
16
23
|
|
|
17
24
|
// ---- Tailwind 类常量与候选类清单 ----
|
|
18
25
|
|
|
26
|
+
const SIZE_BOX = {
|
|
27
|
+
sm: 'h-28 w-28 shrink-0',
|
|
28
|
+
md: 'h-40 w-40 shrink-0',
|
|
29
|
+
lg: 'h-56 w-56 shrink-0',
|
|
30
|
+
} as const;
|
|
31
|
+
// 高对比静态白底静区:暗色主题下二维码外缘与静区恒保持白底黑码,防止反色或贴暗边扫不出
|
|
19
32
|
const SIZE_CLASS = {
|
|
20
|
-
sm:
|
|
21
|
-
md:
|
|
22
|
-
lg:
|
|
33
|
+
sm: `block ${SIZE_BOX.sm} rounded-item bg-static-white p-1`,
|
|
34
|
+
md: `block ${SIZE_BOX.md} rounded-item bg-static-white p-1.5`,
|
|
35
|
+
lg: `block ${SIZE_BOX.lg} rounded-item bg-static-white p-2`,
|
|
36
|
+
} as const;
|
|
37
|
+
const TOO_LONG_BASE = mergeClass(mergeClass('inline-flex flex-col items-center justify-center gap-1 overflow-hidden rounded-control p-2 text-center', kitWellRecipe()), kitTypographyRecipe('caption'));
|
|
38
|
+
const TOO_LONG_ICON_CLASS = 'shrink-0 text-warning-on-soft';
|
|
39
|
+
const TOO_LONG_TEXT_CLASS = 'max-w-full break-words';
|
|
40
|
+
const QR_TOO_LONG_TEXT = {
|
|
41
|
+
'zh-CN': '内容超出二维码容量上限',
|
|
42
|
+
en: 'Content exceeds QR capacity',
|
|
23
43
|
} as const;
|
|
24
|
-
const BG_CLASS =
|
|
25
|
-
const DARK_CLASS =
|
|
44
|
+
const BG_CLASS = KIT_STATIC_QR_SURFACE_CLASS;
|
|
45
|
+
const DARK_CLASS = KIT_STATIC_QR_INK_CLASS;
|
|
26
46
|
const SVG_CLASS = 'block h-full w-full';
|
|
27
47
|
const HIDDEN = 'hidden';
|
|
28
48
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
29
49
|
|
|
30
50
|
export const KIT_QR_CODE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
31
|
-
Object.values(
|
|
51
|
+
Object.values(SIZE_BOX), Object.values(SIZE_CLASS), TOO_LONG_BASE, TOO_LONG_ICON_CLASS, TOO_LONG_TEXT_CLASS,
|
|
52
|
+
BG_CLASS, DARK_CLASS, SVG_CLASS, HIDDEN, KIT_TYPOGRAPHY_RECIPE_CLASS_CANDIDATES, KIT_ICON_CLASS_CANDIDATES,
|
|
32
53
|
);
|
|
33
54
|
|
|
34
55
|
// ---- 纯 TS 编码器(QR Code Model 2,字节模式、UTF-8、版本 1–10、纠错 L / M / Q / H、8 种掩码按罚分择优)与矩阵合并 ----
|
|
@@ -395,24 +416,49 @@ export function createQrCode(): SomaComponentDefinition {
|
|
|
395
416
|
const quiet = rawQuiet !== null && rawQuiet >= 0 && rawQuiet <= 8 ? Math.floor(rawQuiet) : 4;
|
|
396
417
|
const size = p.size === 'sm' || p.size === 'lg' ? p.size : 'md';
|
|
397
418
|
const matrix = qrMatrix(text, ecc);
|
|
419
|
+
const ariaLabel = str(p.aria_label) !== ''
|
|
420
|
+
? str(p.aria_label)
|
|
421
|
+
: str(p.label) !== ''
|
|
422
|
+
? str(p.label)
|
|
423
|
+
: kitText('soma.kit.qr_label', undefined, root);
|
|
398
424
|
const key = `${text}\u0000${ecc}\u0000${quiet}`;
|
|
399
425
|
setAttr(root, 'id', str(p.id));
|
|
400
426
|
if (matrix === null) {
|
|
401
|
-
root.textContent = '';
|
|
402
427
|
lastKey = '';
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
428
|
+
if (text === '') {
|
|
429
|
+
root.textContent = '';
|
|
430
|
+
root.removeAttribute('role');
|
|
431
|
+
root.removeAttribute('aria-label');
|
|
432
|
+
root.className = HIDDEN;
|
|
433
|
+
root.setAttribute(KIT_ATTR_STATE, 'empty');
|
|
434
|
+
kitMarkDataState(kitOuterRoot(api.host, root), 'empty');
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
root.setAttribute(KIT_ATTR_STATE, 'too-long');
|
|
438
|
+
// 文本装不下 = 生成失败:组件根报「加载出错」(data-kit-state 是本组件原有的细分标记,保留)
|
|
439
|
+
kitMarkDataState(kitOuterRoot(api.host, root), 'error');
|
|
440
|
+
root.setAttribute('role', 'status');
|
|
441
|
+
root.className = joinClass(mergeClass(TOO_LONG_BASE, SIZE_BOX[size]), p.class);
|
|
442
|
+
const declared = kitLocaleAt(root);
|
|
443
|
+
const col = kitTextLocaleOf(declared) ?? (declared.trim() === '' ? 'zh-CN' : 'en');
|
|
444
|
+
const notice = document.createElement('span');
|
|
445
|
+
notice.className = TOO_LONG_TEXT_CLASS;
|
|
446
|
+
notice.textContent = QR_TOO_LONG_TEXT[col];
|
|
447
|
+
root.replaceChildren(kitIcon('warning', 'sm', TOO_LONG_ICON_CLASS), notice);
|
|
448
|
+
if (lastError !== text) {
|
|
406
449
|
lastError = text;
|
|
407
450
|
api.emit('error', { reason: 'too-long' });
|
|
408
451
|
}
|
|
409
452
|
return;
|
|
410
453
|
}
|
|
411
454
|
lastError = '';
|
|
412
|
-
root.removeAttribute(
|
|
455
|
+
root.removeAttribute(KIT_ATTR_STATE);
|
|
456
|
+
kitMarkDataState(kitOuterRoot(api.host, root), 'normal');
|
|
457
|
+
root.removeAttribute('role');
|
|
458
|
+
root.removeAttribute('aria-label');
|
|
413
459
|
root.className = joinClass(SIZE_CLASS[size], p.class);
|
|
414
460
|
if (key === lastKey && root.firstElementChild) {
|
|
415
|
-
root.firstElementChild.setAttribute('aria-label',
|
|
461
|
+
root.firstElementChild.setAttribute('aria-label', ariaLabel);
|
|
416
462
|
return;
|
|
417
463
|
}
|
|
418
464
|
lastKey = key;
|
|
@@ -421,7 +467,7 @@ export function createQrCode(): SomaComponentDefinition {
|
|
|
421
467
|
svg.setAttribute('viewBox', `0 0 ${n} ${n}`);
|
|
422
468
|
svg.setAttribute('class', SVG_CLASS);
|
|
423
469
|
svg.setAttribute('role', 'img');
|
|
424
|
-
svg.setAttribute('aria-label',
|
|
470
|
+
svg.setAttribute('aria-label', ariaLabel);
|
|
425
471
|
svg.setAttribute('shape-rendering', 'crispEdges');
|
|
426
472
|
const bg = document.createElementNS(SVG_NS, 'rect');
|
|
427
473
|
bg.setAttribute('width', String(n));
|
|
@@ -441,6 +487,7 @@ export function createQrCode(): SomaComponentDefinition {
|
|
|
441
487
|
root.appendChild(svg);
|
|
442
488
|
},
|
|
443
489
|
};
|
|
444
|
-
|
|
490
|
+
// 二维码是值(链接 / 编码的图形呈现):根只报元素部件
|
|
491
|
+
}, { self: { part: 'value' } }),
|
|
445
492
|
};
|
|
446
493
|
}
|