@eifi1/ui-kit 0.51.4 → 0.51.6
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 +5 -5
- package/dist/account/account-settings-labels.js.map +1 -1
- package/dist/account/account-settings.js +11 -9
- package/dist/account/account-settings.js.map +1 -1
- package/dist/account/delete-account-setting.js +56 -65
- package/dist/account/delete-account-setting.js.map +1 -1
- package/dist/account/email-change-setting-labels.js.map +1 -1
- package/dist/account/email-change-setting.js.map +1 -1
- package/dist/account/passkeys-setting.js.map +1 -1
- package/dist/account/sessions-setting.js.map +1 -1
- package/dist/admin/admin-action-confirm.js +1 -3
- package/dist/admin/admin-action-confirm.js.map +1 -1
- package/dist/admin/admin-action-log.js.map +1 -1
- package/dist/admin/admin-area-labels.js +4 -1
- package/dist/admin/admin-area-labels.js.map +1 -1
- package/dist/admin/admin-overview.js +19 -11
- package/dist/admin/admin-overview.js.map +1 -1
- package/dist/admin/admin-sections.js.map +1 -1
- package/dist/admin/admin-tool-links.d.ts +1 -1
- package/dist/admin/admin-tool-links.js +7 -1
- package/dist/admin/admin-tool-links.js.map +1 -1
- package/dist/admin/invitations-panel.js +2 -13
- package/dist/admin/invitations-panel.js.map +1 -1
- package/dist/admin/mail-test-card.js.map +1 -1
- package/dist/admin/reviewer-scope-editor.js +4 -11
- package/dist/admin/reviewer-scope-editor.js.map +1 -1
- package/dist/admin/role-select.js.map +1 -1
- package/dist/admin/user-roster.js +1 -9
- package/dist/admin/user-roster.js.map +1 -1
- package/dist/auth/accept-invitation.js.map +1 -1
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/forgot-password-form.js +23 -31
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form.js.map +1 -1
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form.js +13 -5
- package/dist/auth/sign-in-form.js.map +1 -1
- package/dist/auth/verify-email.js +1 -8
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/billing/billing-banner.js.map +1 -1
- package/dist/billing/billing-labels.js.map +1 -1
- package/dist/billing/checkout-processing.js.map +1 -1
- package/dist/billing/plan-card.js +91 -85
- package/dist/billing/plan-card.js.map +1 -1
- package/dist/billing/plan-limit-toast.js.map +1 -1
- package/dist/billing/plan-limit.js.map +1 -1
- package/dist/billing/plan-price.js.map +1 -1
- package/dist/billing/plan-switch.js.map +1 -1
- package/dist/billing/subscription-actions.js.map +1 -1
- package/dist/bin/eifi1-pay-page.mjs +6 -1
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/alert-banner.js +1 -5
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.js +29 -12
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/authed-image.js.map +1 -1
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/bulk-action-bar.js +1 -4
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/button-look.js.map +1 -1
- package/dist/components/button.js +1 -7
- package/dist/components/button.js.map +1 -1
- package/dist/components/calculator.js +5 -5
- package/dist/components/calculator.js.map +1 -1
- package/dist/components/calendar-heatmap.js +4 -10
- package/dist/components/calendar-heatmap.js.map +1 -1
- package/dist/components/card.js +1 -8
- package/dist/components/card.js.map +1 -1
- package/dist/components/chart-zoom-core.js +3 -17
- package/dist/components/chart-zoom-core.js.map +1 -1
- package/dist/components/chart.d.ts +1 -1
- package/dist/components/chart.js +4 -22
- package/dist/components/chart.js.map +1 -1
- package/dist/components/checkbox-group.js +1 -4
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/chip-input.js +4 -1
- package/dist/components/chip-input.js.map +1 -1
- package/dist/components/chip.js +10 -5
- package/dist/components/chip.js.map +1 -1
- package/dist/components/choice-card.js +58 -74
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/column-mapper-labels.js.map +1 -1
- package/dist/components/column-mapper.js +167 -227
- package/dist/components/column-mapper.js.map +1 -1
- package/dist/components/combobox-core.js +1 -4
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.js +1 -4
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.js.map +1 -1
- package/dist/components/country-select.d.ts +5 -4
- package/dist/components/country-select.js +3 -19
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/currency-option-list.js +10 -8
- package/dist/components/currency-option-list.js.map +1 -1
- package/dist/components/currency-select.js +1 -6
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-cells.js.map +1 -1
- package/dist/components/data-table-column-settings.js.map +1 -1
- package/dist/components/data-table-filter-popover.js +2 -18
- package/dist/components/data-table-filter-popover.js.map +1 -1
- package/dist/components/data-table-filters.js.map +1 -1
- package/dist/components/data-table-fit.js.map +1 -1
- package/dist/components/data-table-groups.js +3 -1
- package/dist/components/data-table-groups.js.map +1 -1
- package/dist/components/data-table-head.js +44 -56
- package/dist/components/data-table-head.js.map +1 -1
- package/dist/components/data-table-mobile.js +31 -44
- package/dist/components/data-table-mobile.js.map +1 -1
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table-row-actions.js +19 -16
- package/dist/components/data-table-row-actions.js.map +1 -1
- package/dist/components/data-table-row.js.map +1 -1
- package/dist/components/data-table-shared.js.map +1 -1
- package/dist/components/data-table-sort.js.map +1 -1
- package/dist/components/data-table-virtual.js +4 -1
- package/dist/components/data-table-virtual.js.map +1 -1
- package/dist/components/data-table.js +30 -39
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +1 -6
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/date-range-picker.js.map +1 -1
- package/dist/components/description-list.js +10 -10
- package/dist/components/description-list.js.map +1 -1
- package/dist/components/dialog-frame.js +9 -2
- package/dist/components/dialog-frame.js.map +1 -1
- package/dist/components/disclosure.js +17 -27
- package/dist/components/disclosure.js.map +1 -1
- package/dist/components/dropdown.js +25 -35
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/empty-state.js.map +1 -1
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/error-boundary.js.map +1 -1
- package/dist/components/field-base.js +5 -5
- package/dist/components/field-base.js.map +1 -1
- package/dist/components/field-parts.d.ts +1 -1
- package/dist/components/field-parts.js +10 -14
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/field-sync.js +8 -10
- package/dist/components/field-sync.js.map +1 -1
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/floating-panel.js +4 -1
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/focus-ring.js.map +1 -1
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/grouped-picker.js +6 -8
- package/dist/components/grouped-picker.js.map +1 -1
- package/dist/components/hover-menu.js +1 -4
- package/dist/components/hover-menu.js.map +1 -1
- package/dist/components/iban-input-labels.js.map +1 -1
- package/dist/components/icon-button.js +4 -1
- package/dist/components/icon-button.js.map +1 -1
- package/dist/components/icon-picker.js +2 -7
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/image-grid.js +41 -50
- package/dist/components/image-grid.js.map +1 -1
- package/dist/components/inline-edit-field.js.map +1 -1
- package/dist/components/inline-entity-combobox.js +2 -8
- package/dist/components/inline-entity-combobox.js.map +1 -1
- package/dist/components/input.js +14 -2
- package/dist/components/input.js.map +1 -1
- package/dist/components/jump-calendar.js +1 -7
- package/dist/components/jump-calendar.js.map +1 -1
- package/dist/components/legal-labels.js.map +1 -1
- package/dist/components/legal-page.js +14 -2
- package/dist/components/legal-page.js.map +1 -1
- package/dist/components/legal.js +12 -2
- package/dist/components/legal.js.map +1 -1
- package/dist/components/lightbox.js.map +1 -1
- package/dist/components/line-items.js +26 -36
- package/dist/components/line-items.js.map +1 -1
- package/dist/components/list.js +22 -10
- package/dist/components/list.js.map +1 -1
- package/dist/components/measured-grid.js +29 -53
- package/dist/components/measured-grid.js.map +1 -1
- package/dist/components/menu-item.js.map +1 -1
- package/dist/components/mini-calendar.js +13 -31
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.js +10 -21
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.js +3 -16
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/nav-pills.js +10 -1
- package/dist/components/nav-pills.js.map +1 -1
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.js +1 -7
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.js +1 -4
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/one-time-code-input.js +1 -7
- package/dist/components/one-time-code-input.js.map +1 -1
- package/dist/components/page-contents.js +13 -22
- package/dist/components/page-contents.js.map +1 -1
- package/dist/components/page-header.js +1 -11
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/password-strength-labels.js.map +1 -1
- package/dist/components/password-strength.js +2 -8
- package/dist/components/password-strength.js.map +1 -1
- package/dist/components/phone-input.js +42 -57
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/pie-chart.js +1 -8
- package/dist/components/pie-chart.js.map +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/progress-bar.js +16 -9
- package/dist/components/progress-bar.js.map +1 -1
- package/dist/components/qr-code.js +1 -8
- package/dist/components/qr-code.js.map +1 -1
- package/dist/components/row-actions.js +5 -1
- package/dist/components/row-actions.js.map +1 -1
- package/dist/components/search-field.js.map +1 -1
- package/dist/components/select.js +28 -38
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.js +1 -5
- package/dist/components/separator.js.map +1 -1
- package/dist/components/series-chart-axes.js +4 -1
- package/dist/components/series-chart-axes.js.map +1 -1
- package/dist/components/series-chart-budget.js.map +1 -1
- package/dist/components/series-chart-ticks.js.map +1 -1
- package/dist/components/series-chart.js +29 -45
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.js +21 -17
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/share-card.js +4 -9
- package/dist/components/share-card.js.map +1 -1
- package/dist/components/sign-chip.js.map +1 -1
- package/dist/components/signature-pad.js +4 -13
- package/dist/components/signature-pad.js.map +1 -1
- package/dist/components/signed-amount.js +12 -5
- package/dist/components/signed-amount.js.map +1 -1
- package/dist/components/skeleton.js +2 -17
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/slider.js +13 -36
- package/dist/components/slider.js.map +1 -1
- package/dist/components/sparkline.js.map +1 -1
- package/dist/components/stat-tile.js +14 -10
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/swatch-picker.js +14 -4
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/swipeable-row.d.ts +1 -1
- package/dist/components/swipeable-row.js +1 -8
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/table-skeleton.js +4 -1
- package/dist/components/table-skeleton.js.map +1 -1
- package/dist/components/table.js +12 -9
- package/dist/components/table.js.map +1 -1
- package/dist/components/tabs.js +5 -24
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/text-link.js.map +1 -1
- package/dist/components/text.js.map +1 -1
- package/dist/components/tile-radio.js +1 -7
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.js.map +1 -1
- package/dist/components/toast.js.map +1 -1
- package/dist/components/toggle-group.js +6 -1
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle-legend.js +2 -11
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/tooltip.js +2 -22
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/translation-review-editor.js +1 -4
- package/dist/components/translation-review-editor.js.map +1 -1
- package/dist/components/translation-review-parts.d.ts +1 -1
- package/dist/components/translation-review-parts.js +7 -1
- package/dist/components/translation-review-parts.js.map +1 -1
- package/dist/components/translation-review.js +18 -7
- package/dist/components/translation-review.js.map +1 -1
- package/dist/components/tree-view.js +14 -10
- package/dist/components/tree-view.js.map +1 -1
- package/dist/components/treemap.d.ts +24 -2
- package/dist/components/treemap.js +28 -4
- package/dist/components/treemap.js.map +1 -1
- package/dist/components/trigger-aria.js.map +1 -1
- package/dist/components/use-table-state.js +14 -11
- package/dist/components/use-table-state.js.map +1 -1
- package/dist/components/user-avatar.js +3 -26
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/demo/demo-start.js +8 -4
- package/dist/demo/demo-start.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/feedback/feedback-attachment-labels.js.map +1 -1
- package/dist/feedback/feedback-attachment.js +1 -8
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-capture.d.ts +1 -1
- package/dist/feedback/feedback-capture.js +3 -1
- package/dist/feedback/feedback-capture.js.map +1 -1
- package/dist/feedback/feedback-comment-thread.js +27 -13
- package/dist/feedback/feedback-comment-thread.js.map +1 -1
- package/dist/feedback/feedback-context.js +1 -4
- package/dist/feedback/feedback-context.js.map +1 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-public-list.js +7 -1
- package/dist/feedback/feedback-public-list.js.map +1 -1
- package/dist/feedback/feedback-record.js +1 -5
- package/dist/feedback/feedback-record.js.map +1 -1
- package/dist/feedback/feedback-replies.js +25 -10
- package/dist/feedback/feedback-replies.js.map +1 -1
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.js.map +1 -1
- package/dist/feedback/feedback-submit-dialog.js.map +1 -1
- package/dist/feedback/feedback-table.js +4 -1
- package/dist/feedback/feedback-table.js.map +1 -1
- package/dist/feedback/feedback-thread.js +2 -13
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/feedback/feedback-vocabulary.js.map +1 -1
- package/dist/feedback/feedback-vote-button.js.map +1 -1
- package/dist/hooks/use-anchored-rect.js.map +1 -1
- package/dist/hooks/use-document-title.js.map +1 -1
- package/dist/hooks/use-file-drop.js.map +1 -1
- package/dist/hooks/use-file-picker-labels.js.map +1 -1
- package/dist/hooks/use-file-picker.js.map +1 -1
- package/dist/hooks/use-focus-trap.js.map +1 -1
- package/dist/hooks/use-overlay-history.js +10 -5
- package/dist/hooks/use-overlay-history.js.map +1 -1
- package/dist/hooks/use-row-swipe.d.ts +1 -1
- package/dist/hooks/use-row-swipe.js +1 -6
- package/dist/hooks/use-row-swipe.js.map +1 -1
- package/dist/i18n/defaults.js +1 -4
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +4 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.js +2 -8
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.js.map +1 -1
- package/dist/i18n/locales/en.js +4 -1
- package/dist/i18n/locales/en.js.map +2 -2
- package/dist/i18n/locales/es.js +4 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +4 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +4 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +4 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/plurals.js.map +1 -1
- package/dist/i18n/review.js +13 -7
- package/dist/i18n/review.js.map +1 -1
- package/dist/i18n/shared-labels.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +40 -23
- package/dist/index.js.map +1 -1
- package/dist/landing/access.js +1 -4
- package/dist/landing/access.js.map +1 -1
- package/dist/landing/landing-sections.js +35 -38
- package/dist/landing/landing-sections.js.map +1 -1
- package/dist/landing/page-seo.js.map +1 -1
- package/dist/lib/calc.js.map +1 -1
- package/dist/lib/clipboard-minus.js.map +1 -1
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/decimal-marks.js.map +1 -1
- package/dist/lib/device-settings.js +2 -1
- package/dist/lib/device-settings.js.map +1 -1
- package/dist/lib/direction.js.map +1 -1
- package/dist/lib/iban.js.map +1 -1
- package/dist/lib/logger.js +1 -5
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/person-name.js.map +1 -1
- package/dist/lib/phone.js.map +1 -1
- package/dist/lib/qr-encode.js +344 -8
- package/dist/lib/qr-encode.js.map +1 -1
- package/dist/lib/session-refresh.js.map +1 -1
- package/dist/lib/table-text.js +15 -3
- package/dist/lib/table-text.js.map +1 -1
- package/dist/lib/text-match.d.ts +4 -0
- package/dist/lib/text-match.js.map +1 -1
- package/dist/lib/translation-review.js.map +1 -1
- package/dist/notifications/notification-inbox.js +63 -44
- package/dist/notifications/notification-inbox.js.map +1 -1
- package/dist/notifications/notification-parts.js.map +1 -1
- package/dist/notifications/notification-types-setting.js.map +1 -1
- package/dist/notifications/notifications-labels.js.map +1 -1
- package/dist/notifications/push-device-setting.js +6 -1
- package/dist/notifications/push-device-setting.js.map +1 -1
- package/dist/notifications/push-devices-setting.js.map +1 -1
- package/dist/notifications/push-worker.js.map +1 -1
- package/dist/notifications/quiet-hours-setting.js.map +1 -1
- package/dist/notifications/use-push-device.js +4 -1
- package/dist/notifications/use-push-device.js.map +1 -1
- package/dist/offline/pwa-update-prompt.d.ts +1 -1
- package/dist/offline/pwa-update-prompt.js +7 -1
- package/dist/offline/pwa-update-prompt.js.map +1 -1
- package/dist/offline/query-persistence.js.map +1 -1
- package/dist/offline.d.ts +1 -1
- package/dist/offline.js +6 -1
- package/dist/offline.js.map +1 -1
- package/dist/pay/pay.css +8 -1
- package/dist/rhf/fields.d.ts +1 -2
- package/dist/rhf/fields.js +1 -10
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form-core.js +1 -4
- package/dist/rhf/form-core.js.map +1 -1
- package/dist/rhf/line-items.js.map +1 -1
- package/dist/rhf/use-rhf-wizard-step.js.map +1 -1
- package/dist/search/command-palette.js +71 -62
- package/dist/search/command-palette.js.map +1 -1
- package/dist/search/global-search.js +34 -5
- package/dist/search/global-search.js.map +1 -1
- package/dist/search/search-index.js.map +1 -1
- package/dist/settings/device-reset-setting.js +1 -6
- package/dist/settings/device-reset-setting.js.map +1 -1
- package/dist/settings/settings-heading.js.map +1 -1
- package/dist/settings/settings-layout.js +9 -20
- package/dist/settings/settings-layout.js.map +1 -1
- package/dist/settings/use-settings-route.js.map +1 -1
- package/dist/shell/app-shell.js +62 -31
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/auth-layout.js +1 -10
- package/dist/shell/auth-layout.js.map +1 -1
- package/dist/shell/dev-menu.js +12 -6
- package/dist/shell/dev-menu.js.map +1 -1
- package/dist/shell/option-switcher-menu.js.map +1 -1
- package/dist/shell/sync-status-indicator.js +7 -6
- package/dist/shell/sync-status-indicator.js.map +1 -1
- package/dist/shell/top-bar-parts-labels.js.map +1 -1
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell/topbar-controls.js +1 -10
- package/dist/shell/topbar-controls.js.map +1 -1
- package/dist/shell/tour-menu.js +9 -1
- package/dist/shell/tour-menu.js.map +1 -1
- package/dist/sync/db.js.map +1 -1
- package/dist/sync/engine.js +24 -6
- package/dist/sync/engine.js.map +1 -1
- package/dist/sync.d.ts +2 -2
- package/dist/sync.js +7 -1
- package/dist/sync.js.map +1 -1
- package/dist/testing/css-variables.js.map +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +1 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/viewport.js +7 -4
- package/dist/testing/viewport.js.map +1 -1
- package/dist/theme/contrast-tokens.js +13 -2
- package/dist/theme/contrast-tokens.js.map +1 -1
- package/dist/theme/contrast.d.ts +2 -2
- package/dist/theme/palette-derive.d.ts +1 -1
- package/dist/theme/palette-derive.js +18 -29
- package/dist/theme/palette-derive.js.map +1 -1
- package/dist/theme/palette-presets.js.map +1 -1
- package/dist/theme/palette-store.js.map +1 -1
- package/dist/theme/text-size.js.map +1 -1
- package/dist/theme/theme-store.js +1 -3
- package/dist/theme/theme-store.js.map +1 -1
- package/dist/tour/tour-catalogue.js.map +1 -1
- package/dist/tour/tour-dock.js +5 -1
- package/dist/tour/tour-dock.js.map +1 -1
- package/dist/tour/tour-engine.js +1 -4
- package/dist/tour/tour-engine.js.map +1 -1
- package/dist/tour/tour.js +21 -12
- package/dist/tour/tour.js.map +1 -1
- package/dist/tour/use-tour-progress.js.map +1 -1
- package/dist/tour/use-tour-url-sync.js.map +1 -1
- package/dist/wizard/stepper-nav.js +3 -24
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.js +24 -28
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/validation.js.map +1 -1
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard/wizard-step.d.ts +1 -1
- package/dist/wizard/wizard-step.js +1 -8
- package/dist/wizard/wizard-step.js.map +1 -1
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/package.json +5 -2
- package/src/account/account-settings-labels.ts +1 -2
- package/src/account/account-settings.tsx +11 -17
- package/src/account/delete-account-setting.tsx +1 -6
- package/src/account/email-change-setting-labels.ts +1 -2
- package/src/account/email-change-setting.tsx +3 -1
- package/src/account/passkeys-setting.tsx +1 -3
- package/src/account/sessions-setting.tsx +4 -2
- package/src/admin/admin-action-confirm.tsx +4 -7
- package/src/admin/admin-action-log.tsx +29 -29
- package/src/admin/admin-area-labels.ts +4 -1
- package/src/admin/admin-overview.tsx +8 -2
- package/src/admin/admin-sections.tsx +3 -1
- package/src/admin/admin-tool-links.tsx +7 -1
- package/src/admin/invitations-panel.tsx +5 -11
- package/src/admin/mail-test-card.tsx +1 -2
- package/src/admin/reviewer-scope-editor.tsx +4 -9
- package/src/admin/role-select.tsx +4 -2
- package/src/admin/user-roster.tsx +2 -11
- package/src/auth/accept-invitation.tsx +1 -7
- package/src/auth/auth-errors.ts +1 -6
- package/src/auth/forgot-password-form.tsx +2 -7
- package/src/auth/register-form.tsx +7 -8
- package/src/auth/reset-password-form.tsx +2 -5
- package/src/auth/sign-in-form.tsx +15 -14
- package/src/auth/verify-email.tsx +2 -7
- package/src/billing/billing-banner.tsx +3 -7
- package/src/billing/billing-labels.ts +6 -4
- package/src/billing/checkout-processing.ts +0 -1
- package/src/billing/plan-card.tsx +9 -8
- package/src/billing/plan-limit-toast.tsx +1 -2
- package/src/billing/plan-limit.ts +1 -2
- package/src/billing/plan-price.ts +1 -4
- package/src/billing/plan-switch.tsx +1 -2
- package/src/billing/subscription-actions.tsx +5 -2
- package/src/components/account-chips.tsx +1 -7
- package/src/components/alert-banner.tsx +2 -8
- package/src/components/amount-input.tsx +206 -178
- package/src/components/authed-image.tsx +7 -4
- package/src/components/autocomplete.tsx +7 -9
- package/src/components/bulk-action-bar.tsx +2 -7
- package/src/components/button-group.tsx +1 -2
- package/src/components/button-look.ts +6 -17
- package/src/components/button.tsx +1 -4
- package/src/components/calculator.tsx +6 -9
- package/src/components/calendar-heatmap.tsx +5 -10
- package/src/components/card.tsx +9 -13
- package/src/components/chart-zoom-core.tsx +6 -33
- package/src/components/chart.tsx +8 -31
- package/src/components/checkbox-group.tsx +1 -4
- package/src/components/chip-input.tsx +6 -6
- package/src/components/chip.tsx +14 -26
- package/src/components/choice-card.tsx +4 -18
- package/src/components/column-mapper-labels.ts +3 -10
- package/src/components/column-mapper.tsx +33 -122
- package/src/components/combobox-core.tsx +12 -42
- package/src/components/combobox.tsx +2 -6
- package/src/components/confirm-dialog.tsx +1 -3
- package/src/components/copy-button.tsx +2 -4
- package/src/components/country-select.tsx +9 -21
- package/src/components/currency-option-list.tsx +13 -14
- package/src/components/currency-select.tsx +2 -7
- package/src/components/danger-confirm.tsx +8 -9
- package/src/components/data-table-cells.tsx +1 -2
- package/src/components/data-table-column-settings.tsx +1 -3
- package/src/components/data-table-filter-popover.tsx +5 -19
- package/src/components/data-table-filters.ts +1 -6
- package/src/components/data-table-fit.ts +1 -3
- package/src/components/data-table-groups.tsx +3 -1
- package/src/components/data-table-head.tsx +27 -45
- package/src/components/data-table-mobile.tsx +99 -108
- package/src/components/data-table-pagination.tsx +2 -6
- package/src/components/data-table-row-actions.tsx +25 -24
- package/src/components/data-table-row.tsx +16 -17
- package/src/components/data-table-shared.tsx +10 -16
- package/src/components/data-table-sort.ts +1 -2
- package/src/components/data-table-virtual.ts +9 -4
- package/src/components/data-table.tsx +489 -501
- package/src/components/date-picker.tsx +1 -7
- package/src/components/date-range-picker.tsx +3 -13
- package/src/components/description-list.tsx +7 -13
- package/src/components/dialog-frame.tsx +12 -3
- package/src/components/disclosure.tsx +8 -12
- package/src/components/dropdown.tsx +3 -11
- package/src/components/empty-state.tsx +1 -3
- package/src/components/entity-combobox.tsx +2 -6
- package/src/components/error-boundary.tsx +7 -7
- package/src/components/field-base.tsx +8 -14
- package/src/components/field-parts.tsx +12 -23
- package/src/components/field-sync.tsx +7 -11
- package/src/components/file-button.tsx +7 -3
- package/src/components/file-dropzone.tsx +7 -12
- package/src/components/floating-panel.tsx +44 -51
- package/src/components/focus-ring.ts +1 -2
- package/src/components/form-actions.tsx +1 -4
- package/src/components/grouped-picker.tsx +6 -8
- package/src/components/hover-menu.tsx +1 -4
- package/src/components/iban-input-labels.ts +1 -2
- package/src/components/icon-button.tsx +46 -48
- package/src/components/icon-picker.tsx +4 -17
- package/src/components/image-grid.tsx +1 -6
- package/src/components/inline-edit-field.tsx +1 -5
- package/src/components/inline-entity-combobox.tsx +6 -21
- package/src/components/input.tsx +14 -2
- package/src/components/jump-calendar.tsx +2 -6
- package/src/components/legal-labels.ts +1 -2
- package/src/components/legal-page.tsx +18 -7
- package/src/components/legal.tsx +14 -5
- package/src/components/lightbox.tsx +1 -3
- package/src/components/line-items.tsx +7 -15
- package/src/components/list.tsx +29 -25
- package/src/components/measured-grid.tsx +8 -30
- package/src/components/menu-item.tsx +1 -3
- package/src/components/mini-calendar.tsx +129 -159
- package/src/components/money-field.tsx +4 -2
- package/src/components/month-picker.tsx +14 -21
- package/src/components/multi-entity-combobox.tsx +6 -26
- package/src/components/multi-select.tsx +5 -9
- package/src/components/nav-pills.tsx +10 -2
- package/src/components/number-field.tsx +18 -15
- package/src/components/number-input.tsx +3 -19
- package/src/components/numpad-sheet.tsx +9 -13
- package/src/components/one-time-code-input.tsx +6 -11
- package/src/components/page-contents.tsx +2 -9
- package/src/components/page-header.tsx +5 -10
- package/src/components/password-strength-labels.ts +1 -2
- package/src/components/password-strength.tsx +6 -9
- package/src/components/phone-input.tsx +2 -13
- package/src/components/picker-sheet.tsx +2 -5
- package/src/components/pie-chart.tsx +6 -12
- package/src/components/popover.tsx +2 -1
- package/src/components/progress-bar.tsx +16 -25
- package/src/components/qr-code.tsx +2 -9
- package/src/components/row-actions.tsx +9 -1
- package/src/components/search-field.tsx +4 -5
- package/src/components/select.tsx +2 -10
- package/src/components/separator.tsx +1 -5
- package/src/components/series-chart-axes.ts +5 -5
- package/src/components/series-chart-budget.ts +1 -4
- package/src/components/series-chart-ticks.ts +1 -4
- package/src/components/series-chart.tsx +43 -83
- package/src/components/settings-fields.tsx +20 -15
- package/src/components/share-card.tsx +6 -14
- package/src/components/sign-chip.tsx +16 -16
- package/src/components/signature-pad.tsx +21 -13
- package/src/components/signed-amount.tsx +6 -14
- package/src/components/skeleton.tsx +2 -13
- package/src/components/slider.tsx +9 -20
- package/src/components/sparkline.tsx +2 -13
- package/src/components/stat-tile.tsx +13 -24
- package/src/components/swatch-picker.tsx +8 -3
- package/src/components/swipeable-row.tsx +2 -11
- package/src/components/table-skeleton.tsx +4 -1
- package/src/components/table.tsx +12 -8
- package/src/components/tabs.tsx +24 -39
- package/src/components/text-link.tsx +6 -6
- package/src/components/text.tsx +1 -2
- package/src/components/tile-radio.tsx +6 -19
- package/src/components/time-input.tsx +4 -5
- package/src/components/toast.tsx +3 -12
- package/src/components/toggle-group.tsx +9 -9
- package/src/components/toggle-legend.tsx +4 -16
- package/src/components/tooltip.tsx +9 -48
- package/src/components/translation-review-editor.tsx +4 -4
- package/src/components/translation-review-parts.tsx +7 -1
- package/src/components/translation-review.tsx +15 -16
- package/src/components/tree-view.tsx +17 -20
- package/src/components/treemap.tsx +59 -9
- package/src/components/trigger-aria.ts +1 -4
- package/src/components/use-table-state.ts +16 -17
- package/src/components/user-avatar.tsx +4 -21
- package/src/demo/demo-start.tsx +8 -4
- package/src/feedback/feedback-attachment-labels.ts +2 -1
- package/src/feedback/feedback-attachment.tsx +16 -29
- package/src/feedback/feedback-capture.ts +3 -1
- package/src/feedback/feedback-comment-thread.tsx +9 -6
- package/src/feedback/feedback-context.tsx +1 -4
- package/src/feedback/feedback-dialog.tsx +3 -4
- package/src/feedback/feedback-inbox.tsx +3 -9
- package/src/feedback/feedback-public-list.tsx +7 -1
- package/src/feedback/feedback-record.ts +6 -14
- package/src/feedback/feedback-replies.tsx +10 -5
- package/src/feedback/feedback-row-detail.tsx +2 -5
- package/src/feedback/feedback-status-undo.ts +1 -4
- package/src/feedback/feedback-submit-dialog.tsx +4 -4
- package/src/feedback/feedback-table.tsx +12 -8
- package/src/feedback/feedback-thread.tsx +4 -16
- package/src/feedback/feedback-vocabulary.ts +72 -82
- package/src/feedback/feedback-vote-button.tsx +9 -8
- package/src/hooks/use-anchored-rect.ts +1 -4
- package/src/hooks/use-document-title.ts +3 -1
- package/src/hooks/use-file-drop.ts +1 -3
- package/src/hooks/use-file-picker-labels.ts +1 -2
- package/src/hooks/use-file-picker.tsx +1 -5
- package/src/hooks/use-focus-trap.ts +1 -2
- package/src/hooks/use-overlay-history.ts +10 -5
- package/src/hooks/use-row-swipe.ts +1 -6
- package/src/i18n/defaults.ts +1 -4
- package/src/i18n/german.ts +33 -49
- package/src/i18n/kit-labels.tsx +5 -20
- package/src/i18n/languages.ts +2 -8
- package/src/i18n/locales/en.ts +11 -31
- package/src/i18n/locales/es.ts +35 -49
- package/src/i18n/locales/fr.ts +34 -51
- package/src/i18n/locales/hu.ts +26 -37
- package/src/i18n/locales/it.ts +35 -52
- package/src/i18n/locales/zh.ts +14 -32
- package/src/i18n/plurals.ts +4 -1
- package/src/i18n/review.ts +18 -7
- package/src/i18n/shared-labels.ts +1 -2
- package/src/index.ts +106 -32
- package/src/landing/access.ts +2 -7
- package/src/landing/landing-sections.tsx +14 -15
- package/src/landing/page-seo.ts +1 -3
- package/src/lib/calc.ts +4 -1
- package/src/lib/clipboard-minus.ts +4 -1
- package/src/lib/dates.ts +2 -10
- package/src/lib/decimal-marks.ts +1 -3
- package/src/lib/device-settings.ts +2 -1
- package/src/lib/direction.ts +1 -3
- package/src/lib/iban.ts +89 -9
- package/src/lib/logger.ts +1 -5
- package/src/lib/person-name.ts +1 -3
- package/src/lib/phone.ts +5 -8
- package/src/lib/qr-encode.ts +32 -8
- package/src/lib/session-refresh.ts +5 -6
- package/src/lib/table-text.ts +24 -6
- package/src/lib/text-match.ts +15 -3
- package/src/lib/translation-review.ts +1 -3
- package/src/notifications/notification-inbox.tsx +17 -4
- package/src/notifications/notification-parts.tsx +1 -2
- package/src/notifications/notification-types-setting.tsx +19 -18
- package/src/notifications/notifications-labels.ts +1 -2
- package/src/notifications/push-device-setting.tsx +7 -1
- package/src/notifications/push-devices-setting.tsx +7 -3
- package/src/notifications/push-worker.ts +10 -2
- package/src/notifications/quiet-hours-setting.tsx +4 -1
- package/src/notifications/use-push-device.ts +4 -1
- package/src/offline/pwa-update-prompt.tsx +7 -1
- package/src/offline/query-persistence.ts +9 -6
- package/src/offline.ts +6 -1
- package/src/rhf/fields.tsx +50 -19
- package/src/rhf/form-core.tsx +2 -6
- package/src/rhf/line-items.tsx +5 -7
- package/src/rhf/use-rhf-wizard-step.ts +3 -12
- package/src/search/command-palette.tsx +15 -23
- package/src/search/global-search.tsx +38 -8
- package/src/search/search-index.ts +5 -1
- package/src/settings/device-reset-setting.tsx +5 -8
- package/src/settings/settings-heading.tsx +3 -1
- package/src/settings/settings-layout.tsx +6 -13
- package/src/settings/use-settings-route.ts +4 -3
- package/src/shell/app-shell.tsx +48 -24
- package/src/shell/auth-layout.tsx +1 -6
- package/src/shell/dev-menu.tsx +12 -6
- package/src/shell/option-switcher-menu.tsx +1 -3
- package/src/shell/sync-status-indicator.tsx +14 -12
- package/src/shell/top-bar-parts-labels.ts +1 -3
- package/src/shell/topbar-action-menu.tsx +9 -8
- package/src/shell/topbar-controls.tsx +5 -19
- package/src/shell/tour-menu.tsx +9 -1
- package/src/sync/db.ts +5 -1
- package/src/sync/engine.ts +44 -12
- package/src/sync.ts +16 -2
- package/src/testing/css-variables.ts +1 -2
- package/src/testing/index.ts +1 -6
- package/src/testing/react.ts +1 -2
- package/src/testing/viewport.ts +9 -9
- package/src/theme/contrast-tokens.ts +13 -2
- package/src/theme/palette-derive.ts +24 -50
- package/src/theme/palette-presets.ts +0 -1
- package/src/theme/palette-store.ts +1 -4
- package/src/theme/text-size.ts +1 -1
- package/src/theme/theme-store.ts +2 -6
- package/src/tour/tour-catalogue.tsx +4 -2
- package/src/tour/tour-dock.ts +5 -1
- package/src/tour/tour-engine.ts +2 -6
- package/src/tour/tour.tsx +28 -12
- package/src/tour/use-tour-progress.ts +8 -2
- package/src/tour/use-tour-url-sync.ts +3 -1
- package/src/vite-env.d.ts +1 -4
- package/src/wizard/stepper-nav.tsx +10 -35
- package/src/wizard/types.ts +1 -4
- package/src/wizard/use-wizard.ts +28 -43
- package/src/wizard/validation.ts +1 -5
- package/src/wizard/wizard-context.tsx +2 -6
- package/src/wizard/wizard-step.tsx +1 -8
- package/src/wizard/wizard-summary.tsx +2 -6
- package/tokens.css +393 -152
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/testing/viewport.ts"],"sourcesContent":["/**\n * Environment stubs for an app's own tests (0.34, refactor audit 2026-10, TST-10): the\n * two browser APIs jsdom does not have and the kit's layout reads — `matchMedia` and\n * `ResizeObserver`.\n *\n * Every suite rebuilt them by hand: the kit stubbed `matchMedia` in 25 files and defined\n * the same `stubPhone()` eight times, keksdose stubs it in 41, and most copies answer\n * one literal string. That breaks quietly at Large text, where `md` is 960 px and the\n * phone query the kit writes is `(width < 960px)`, not `(width < 768px)`. These answer\n * every width query from a WIDTH, as a browser does, so they stay right at every text\n * size (docs/text-size-harmonization.md §3.3). The reference is keksdose's\n * `frontend/src/test/viewport.ts`, which this generalises.\n *\n * Framework-free, like the rest of `@eifi1/ui-kit/testing`: nothing here imports vitest\n * or jest. Each stub returns its own undo, so it works under either runner, and a suite\n * that prefers `vi.stubGlobal` passes it {@link viewportMatchMedia} instead.\n */\n\n/** The media features a test may want besides the width. Each is off by default. */\nexport interface ViewportOptions {\n /** The primary pointer is a finger: `(pointer: coarse)`, `(any-pointer: coarse)` and\n * `(hover: none)` match; `(pointer: fine)` and `(hover: hover)` do not. */\n coarse?: boolean;\n /** The person asked for less motion: `(prefers-reduced-motion: reduce)` matches, and\n * the kit's overlays skip their exit animations. */\n reducedMotion?: boolean;\n /** `(prefers-color-scheme: dark)` matches (`light` does not). */\n dark?: boolean;\n /** `(prefers-contrast: more)` matches. */\n moreContrast?: boolean;\n}\n\n/** One length in CSS px. A media query's `rem`/`em` is the browser's default font size,\n * 16 px, never `<html>`'s — the kit's own `breakpointQuery` writes px. */\nfunction lengthPx(value: string, unit: string): number {\n return unit === \"px\" ? Number(value) : Number(value) * 16;\n}\n\nconst RANGE = /^\\(\\s*width\\s*(<=|>=|<|>)\\s*([\\d.]+)(px|r?em)\\s*\\)$/;\nconst MIN_MAX = /^\\(\\s*(min|max)-width\\s*:\\s*([\\d.]+)(px|r?em)\\s*\\)$/;\nconst FEATURE = /^\\(\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*\\)$/;\n\n/** One `(…)` condition, or a media type. */\nfunction condition(part: string, width: number, options: ViewportOptions): boolean {\n const q = part.trim();\n if (q === \"all\" || q === \"screen\") return true;\n const range = RANGE.exec(q);\n if (range) {\n const px = lengthPx(range[2], range[3]);\n switch (range[1]) {\n case \"<\":\n return width < px;\n case \"<=\":\n return width <= px;\n case \">\":\n return width > px;\n default:\n return width >= px;\n }\n }\n const minMax = MIN_MAX.exec(q);\n if (minMax) {\n const px = lengthPx(minMax[2], minMax[3]);\n return minMax[1] === \"min\" ? width >= px : width <= px;\n }\n const feature = FEATURE.exec(q);\n if (!feature) return false;\n const [, name, value] = feature;\n const coarse = Boolean(options.coarse);\n switch (name) {\n case \"pointer\":\n case \"any-pointer\":\n return value === (coarse ? \"coarse\" : \"fine\");\n case \"hover\":\n case \"any-hover\":\n return value === (coarse ? \"none\" : \"hover\");\n case \"prefers-reduced-motion\":\n return value === (options.reducedMotion ? \"reduce\" : \"no-preference\");\n case \"prefers-color-scheme\":\n return value === (options.dark ? \"dark\" : \"light\");\n case \"prefers-contrast\":\n return value === (options.moreContrast ? \"more\" : \"no-preference\");\n default:\n return false;\n }\n}\n\n/** A whole query: comma lists are alternatives, `and` joins conditions, as in CSS. */\nfunction answer(query: string, width: number, options: ViewportOptions): boolean {\n return query\n .split(\",\")\n .some((alternative) =>\n alternative.split(/\\s+and\\s+/).every((part) => condition(part, width, options)),\n );\n}\n\n/** A list {@link viewportMatchMedia} handed out: what {@link setViewportWidth} flips. */\ninterface StubMediaQueryList {\n matches: boolean;\n readonly media: string;\n onchange: ((this: MediaQueryList, event: MediaQueryListEvent) => unknown) | null;\n addEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;\n removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;\n addListener(listener: EventListenerOrEventListenerObject | null): void;\n removeListener(listener: EventListenerOrEventListenerObject | null): void;\n dispatchEvent(event: Event): boolean;\n}\n\n/** One stub's viewport: its width now, and every list it has handed out. */\ninterface StubViewport {\n width: number;\n readonly options: ViewportOptions;\n readonly lists: Set<StubMediaQueryList>;\n}\n\n/** Each `matchMedia` {@link viewportMatchMedia} made → its viewport. Keyed by the function,\n * so {@link setViewportWidth} finds whichever stub is in force however it was put in. */\nconst VIEWPORTS = new WeakMap<object, StubViewport>();\n\nfunction mediaQueryList(query: string, viewport: StubViewport): StubMediaQueryList {\n // One set for both APIs: in a browser `addListener(fn)` IS `addEventListener(\"change\",\n // fn)`, so adding the same function through both registers it once.\n const listeners = new Set<EventListenerOrEventListenerObject>();\n const list: StubMediaQueryList = {\n matches: answer(query, viewport.width, viewport.options),\n media: query,\n onchange: null,\n addEventListener(type, listener) {\n if (type === \"change\" && listener) listeners.add(listener);\n },\n removeEventListener(type, listener) {\n if (type === \"change\" && listener) listeners.delete(listener);\n },\n addListener(listener) {\n if (listener) listeners.add(listener);\n },\n removeListener(listener) {\n if (listener) listeners.delete(listener);\n },\n dispatchEvent(event) {\n if (event.type !== \"change\") return true;\n const self = list as unknown as MediaQueryList;\n list.onchange?.call(self, event as MediaQueryListEvent);\n for (const listener of [...listeners]) {\n if (typeof listener === \"function\") listener.call(self, event);\n else listener.handleEvent(event);\n }\n return !event.defaultPrevented;\n },\n };\n return list;\n}\n\n/** The `change` a browser fires at a list whose answer flipped: a `MediaQueryListEvent`'s\n * `matches` and `media`, on an `Event` (jsdom has no `MediaQueryListEvent`). */\nfunction changeEvent(list: StubMediaQueryList): Event {\n const event = new Event(\"change\");\n for (const [key, value] of Object.entries({ matches: list.matches, media: list.media, target: list, currentTarget: list })) {\n Object.defineProperty(event, key, { value, enumerable: true });\n }\n return event;\n}\n\n/**\n * A `window.matchMedia` for a viewport `width` CSS px wide.\n *\n * Width queries answer from `width`: the range syntax the kit writes for `max-*`\n * (`(width < 768px)`) and every other comparison, `(min-width: …)` and `(max-width: …)`,\n * in px or rem; `and` and comma lists combine as in CSS. The features in `options` answer\n * as set there; every other query is false. The lists keep their listeners, and\n * {@link setViewportWidth} resizes the viewport under them the way a browser window\n * does: each list whose answer flips fires `change`.\n *\n * Hand it to the runner's own global stub where the suite undoes stubs that way —\n * `vi.stubGlobal(\"matchMedia\", viewportMatchMedia(375))` — or use\n * {@link stubViewportWidth}.\n */\nexport function viewportMatchMedia(\n width: number,\n options: ViewportOptions = {},\n): (query: string) => MediaQueryList {\n const viewport: StubViewport = { width, options, lists: new Set() };\n const matchMedia = (query: string) => {\n const list = mediaQueryList(query, viewport);\n viewport.lists.add(list);\n return list as unknown as MediaQueryList;\n };\n VIEWPORTS.set(matchMedia, viewport);\n return matchMedia;\n}\n\n/**\n * Resize the stubbed viewport to `width` CSS px, live — the window being dragged narrower,\n * a phone turned (0.35, keksdose's 0.34 report). Every list the stub in force has handed\n * out answers from the new width, and each one whose answer flipped fires `change` to its\n * `addEventListener` listeners, its legacy `addListener` ones and its `onchange`, as in a\n * browser; a list whose answer stayed the same tells nobody. So a mounted component that\n * listens to a breakpoint (`usePhoneLayout()`, `useBreakpoint()`) switches without being\n * rendered again.\n *\n * The stub in force is whatever `window.matchMedia` is now — one {@link stubViewportWidth}\n * or `vi.stubGlobal(\"matchMedia\", viewportMatchMedia(…))` put in; its features\n * (`options`) stay as they were. Throws when `matchMedia` is not one of these stubs, rather\n * than resize nothing. Synchronous: wrap it in `act()` when a listener sets state.\n *\n * ```ts\n * undo = stubViewportWidth(1280);\n * render(<Page />);\n * act(() => setViewportWidth(375));\n * expect(screen.getByRole(\"list\")).toBeInTheDocument(); // the cards\n * ```\n */\nexport function setViewportWidth(width: number): void {\n const viewport = typeof window === \"undefined\" ? undefined : VIEWPORTS.get(window.matchMedia);\n if (!viewport) {\n throw new Error(\n \"setViewportWidth: no viewport stub is in force — put one in first with \" +\n \"stubViewportWidth(width), or vi.stubGlobal(\\\"matchMedia\\\", viewportMatchMedia(width)).\",\n );\n }\n viewport.width = width;\n for (const list of [...viewport.lists]) {\n const matches = answer(list.media, width, viewport.options);\n if (matches === list.matches) continue;\n list.matches = matches;\n list.dispatchEvent(changeEvent(list));\n }\n}\n\n/**\n * Make `window.matchMedia` answer as a viewport `width` CSS px wide (see\n * {@link viewportMatchMedia}), and return the undo: it puts back what was there, which\n * in jsdom is nothing — no `matchMedia` at all, the desktop fallback of every kit hook.\n *\n * ```ts\n * let undo = () => {};\n * afterEach(() => undo());\n * it(\"shows cards on a phone\", () => {\n * undo = stubViewportWidth(375);\n * …\n * });\n * ```\n *\n * Right at every text size: at Large the kit's phone query is `(width < 960px)`, which a\n * 375 px viewport matches and a 1280 px one does not, as in a browser.\n */\nexport function stubViewportWidth(width: number, options: ViewportOptions = {}): () => void {\n const before = Object.getOwnPropertyDescriptor(window, \"matchMedia\");\n Object.defineProperty(window, \"matchMedia\", {\n configurable: true,\n writable: true,\n value: viewportMatchMedia(width, options),\n });\n return () => {\n if (before) Object.defineProperty(window, \"matchMedia\", before);\n else Reflect.deleteProperty(window, \"matchMedia\");\n };\n}\n\n/** A box size for {@link ResizeObserverStub.resize}, in CSS px. */\nexport interface StubbedBoxSize {\n width: number;\n height: number;\n}\n\n/** What {@link stubResizeObserver} returns: the test drives the observers. */\nexport interface ResizeObserverStub {\n /**\n * Report `target` at `size` to every live observer watching it, as a browser does once\n * layout settles: one entry, with `contentRect` and the three box sizes all `size`.\n * Synchronous; wrap it in `act()` when the callback sets state.\n */\n resize(target: Element, size: StubbedBoxSize): void;\n /** The elements some live observer watches now, each once. */\n observed(): Element[];\n /** Put back the `ResizeObserver` that was there before — in jsdom, none. */\n restore(): void;\n}\n\n/**\n * Install a `ResizeObserver` the test drives. jsdom has none, and lays nothing out, so a\n * component that measures itself (a windowed list, a fitted chart, a measured grid)\n * either crashes on the missing global or never learns a size. Observers here record\n * what they watch and are called only by {@link ResizeObserverStub.resize}.\n *\n * ```ts\n * const ro = stubResizeObserver();\n * afterEach(() => ro.restore());\n * act(() => ro.resize(screen.getByRole(\"list\"), { width: 400, height: 320 }));\n * ```\n */\nexport function stubResizeObserver(): ResizeObserverStub {\n const live = new Set<StubResizeObserver>();\n\n class StubResizeObserver {\n readonly targets = new Set<Element>();\n constructor(readonly callback: ResizeObserverCallback) {\n live.add(this);\n }\n observe(target: Element) {\n this.targets.add(target);\n }\n unobserve(target: Element) {\n this.targets.delete(target);\n }\n disconnect() {\n this.targets.clear();\n live.delete(this);\n }\n }\n\n const before = Object.getOwnPropertyDescriptor(globalThis, \"ResizeObserver\");\n Object.defineProperty(globalThis, \"ResizeObserver\", {\n configurable: true,\n writable: true,\n value: StubResizeObserver,\n });\n\n return {\n resize(target, { width, height }) {\n const box = [{ inlineSize: width, blockSize: height }];\n const contentRect = {\n x: 0,\n y: 0,\n top: 0,\n left: 0,\n width,\n height,\n right: width,\n bottom: height,\n toJSON: () => ({ x: 0, y: 0, width, height }),\n };\n const entry = {\n target,\n contentRect,\n borderBoxSize: box,\n contentBoxSize: box,\n devicePixelContentBoxSize: box,\n } as unknown as ResizeObserverEntry;\n for (const observer of [...live]) {\n if (observer.targets.has(target)) {\n observer.callback([entry], observer as unknown as ResizeObserver);\n }\n }\n },\n observed() {\n const all: Element[] = [];\n for (const observer of live) for (const target of observer.targets) if (!all.includes(target)) all.push(target);\n return all;\n },\n restore() {\n live.clear();\n if (before) Object.defineProperty(globalThis, \"ResizeObserver\", before);\n else Reflect.deleteProperty(globalThis, \"ResizeObserver\");\n },\n };\n}\n"],"mappings":";AAkCA,SAAS,SAAS,OAAe,MAAsB;AACrD,SAAO,SAAS,OAAO,OAAO,KAAK,IAAI,OAAO,KAAK,IAAI;AACzD;AAEA,MAAM,QAAQ;AACd,MAAM,UAAU;AAChB,MAAM,UAAU;AAGhB,SAAS,UAAU,MAAc,OAAe,SAAmC;AACjF,QAAM,IAAI,KAAK,KAAK;AACpB,MAAI,MAAM,SAAS,MAAM,SAAU,QAAO;AAC1C,QAAM,QAAQ,MAAM,KAAK,CAAC;AAC1B,MAAI,OAAO;AACT,UAAM,KAAK,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;AACtC,YAAQ,MAAM,CAAC,GAAG;AAAA,MAChB,KAAK;AACH,eAAO,QAAQ;AAAA,MACjB,KAAK;AACH,eAAO,SAAS;AAAA,MAClB,KAAK;AACH,eAAO,QAAQ;AAAA,MACjB;AACE,eAAO,SAAS;AAAA,IACpB;AAAA,EACF;AACA,QAAM,SAAS,QAAQ,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M,cAAc;AAAA,QAClB,GAAG;AAAA,QACH,GAAG;AAAA,QACH,KAAK;AAAA,QACL,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,QAAQ,OAAO,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,OAAO;AAAA,MAC7C;AACA,YAAM,QAAQ;AAAA,QACZ;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf,gBAAgB;AAAA,QAChB,2BAA2B;AAAA,MAC7B;AACA,iBAAW,YAAY,CAAC,GAAG,IAAI,GAAG;AAChC,YAAI,SAAS,QAAQ,IAAI,MAAM,GAAG;AAChC,mBAAS,SAAS,CAAC,KAAK,GAAG,QAAqC;AAAA,QAClE;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW;AACT,YAAM,MAAiB,CAAC;AACxB,iBAAW,YAAY,KAAM,YAAW,UAAU,SAAS,QAAS,KAAI,CAAC,IAAI,SAAS,MAAM,EAAG,KAAI,KAAK,MAAM;AAC9G,aAAO;AAAA,IACT;AAAA,IACA,UAAU;AACR,WAAK,MAAM;AACX,UAAI,OAAQ,QAAO,eAAe,YAAY,kBAAkB,MAAM;AAAA,UACjE,SAAQ,eAAe,YAAY,gBAAgB;AAAA,IAC1D;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/testing/viewport.ts"],"sourcesContent":["/**\n * Environment stubs for an app's own tests (0.34, refactor audit 2026-10, TST-10): the\n * two browser APIs jsdom does not have and the kit's layout reads — `matchMedia` and\n * `ResizeObserver`.\n *\n * Every suite rebuilt them by hand: the kit stubbed `matchMedia` in 25 files and defined\n * the same `stubPhone()` eight times, keksdose stubs it in 41, and most copies answer\n * one literal string. That breaks quietly at Large text, where `md` is 960 px and the\n * phone query the kit writes is `(width < 960px)`, not `(width < 768px)`. These answer\n * every width query from a WIDTH, as a browser does, so they stay right at every text\n * size (docs/text-size-harmonization.md §3.3). The reference is keksdose's\n * `frontend/src/test/viewport.ts`, which this generalises.\n *\n * Framework-free, like the rest of `@eifi1/ui-kit/testing`: nothing here imports vitest\n * or jest. Each stub returns its own undo, so it works under either runner, and a suite\n * that prefers `vi.stubGlobal` passes it {@link viewportMatchMedia} instead.\n */\n\n/** The media features a test may want besides the width. Each is off by default. */\nexport interface ViewportOptions {\n /** The primary pointer is a finger: `(pointer: coarse)`, `(any-pointer: coarse)` and\n * `(hover: none)` match; `(pointer: fine)` and `(hover: hover)` do not. */\n coarse?: boolean;\n /** The person asked for less motion: `(prefers-reduced-motion: reduce)` matches, and\n * the kit's overlays skip their exit animations. */\n reducedMotion?: boolean;\n /** `(prefers-color-scheme: dark)` matches (`light` does not). */\n dark?: boolean;\n /** `(prefers-contrast: more)` matches. */\n moreContrast?: boolean;\n}\n\n/** One length in CSS px. A media query's `rem`/`em` is the browser's default font size,\n * 16 px, never `<html>`'s — the kit's own `breakpointQuery` writes px. */\nfunction lengthPx(value: string, unit: string): number {\n return unit === \"px\" ? Number(value) : Number(value) * 16;\n}\n\nconst RANGE = /^\\(\\s*width\\s*(<=|>=|<|>)\\s*([\\d.]+)(px|r?em)\\s*\\)$/;\nconst MIN_MAX = /^\\(\\s*(min|max)-width\\s*:\\s*([\\d.]+)(px|r?em)\\s*\\)$/;\nconst FEATURE = /^\\(\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*\\)$/;\n\n/** One `(…)` condition, or a media type. */\nfunction condition(part: string, width: number, options: ViewportOptions): boolean {\n const q = part.trim();\n if (q === \"all\" || q === \"screen\") return true;\n const range = RANGE.exec(q);\n if (range) {\n const px = lengthPx(range[2], range[3]);\n switch (range[1]) {\n case \"<\":\n return width < px;\n case \"<=\":\n return width <= px;\n case \">\":\n return width > px;\n default:\n return width >= px;\n }\n }\n const minMax = MIN_MAX.exec(q);\n if (minMax) {\n const px = lengthPx(minMax[2], minMax[3]);\n return minMax[1] === \"min\" ? width >= px : width <= px;\n }\n const feature = FEATURE.exec(q);\n if (!feature) return false;\n const [, name, value] = feature;\n const coarse = Boolean(options.coarse);\n switch (name) {\n case \"pointer\":\n case \"any-pointer\":\n return value === (coarse ? \"coarse\" : \"fine\");\n case \"hover\":\n case \"any-hover\":\n return value === (coarse ? \"none\" : \"hover\");\n case \"prefers-reduced-motion\":\n return value === (options.reducedMotion ? \"reduce\" : \"no-preference\");\n case \"prefers-color-scheme\":\n return value === (options.dark ? \"dark\" : \"light\");\n case \"prefers-contrast\":\n return value === (options.moreContrast ? \"more\" : \"no-preference\");\n default:\n return false;\n }\n}\n\n/** A whole query: comma lists are alternatives, `and` joins conditions, as in CSS. */\nfunction answer(query: string, width: number, options: ViewportOptions): boolean {\n return query\n .split(\",\")\n .some((alternative) => alternative.split(/\\s+and\\s+/).every((part) => condition(part, width, options)));\n}\n\n/** A list {@link viewportMatchMedia} handed out: what {@link setViewportWidth} flips. */\ninterface StubMediaQueryList {\n matches: boolean;\n readonly media: string;\n onchange: ((this: MediaQueryList, event: MediaQueryListEvent) => unknown) | null;\n addEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;\n removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;\n addListener(listener: EventListenerOrEventListenerObject | null): void;\n removeListener(listener: EventListenerOrEventListenerObject | null): void;\n dispatchEvent(event: Event): boolean;\n}\n\n/** One stub's viewport: its width now, and every list it has handed out. */\ninterface StubViewport {\n width: number;\n readonly options: ViewportOptions;\n readonly lists: Set<StubMediaQueryList>;\n}\n\n/** Each `matchMedia` {@link viewportMatchMedia} made → its viewport. Keyed by the function,\n * so {@link setViewportWidth} finds whichever stub is in force however it was put in. */\nconst VIEWPORTS = new WeakMap<object, StubViewport>();\n\nfunction mediaQueryList(query: string, viewport: StubViewport): StubMediaQueryList {\n // One set for both APIs: in a browser `addListener(fn)` IS `addEventListener(\"change\",\n // fn)`, so adding the same function through both registers it once.\n const listeners = new Set<EventListenerOrEventListenerObject>();\n const list: StubMediaQueryList = {\n matches: answer(query, viewport.width, viewport.options),\n media: query,\n onchange: null,\n addEventListener(type, listener) {\n if (type === \"change\" && listener) listeners.add(listener);\n },\n removeEventListener(type, listener) {\n if (type === \"change\" && listener) listeners.delete(listener);\n },\n addListener(listener) {\n if (listener) listeners.add(listener);\n },\n removeListener(listener) {\n if (listener) listeners.delete(listener);\n },\n dispatchEvent(event) {\n if (event.type !== \"change\") return true;\n const self = list as unknown as MediaQueryList;\n list.onchange?.call(self, event as MediaQueryListEvent);\n for (const listener of [...listeners]) {\n if (typeof listener === \"function\") listener.call(self, event);\n else listener.handleEvent(event);\n }\n return !event.defaultPrevented;\n },\n };\n return list;\n}\n\n/** The `change` a browser fires at a list whose answer flipped: a `MediaQueryListEvent`'s\n * `matches` and `media`, on an `Event` (jsdom has no `MediaQueryListEvent`). */\nfunction changeEvent(list: StubMediaQueryList): Event {\n const event = new Event(\"change\");\n for (const [key, value] of Object.entries({\n matches: list.matches,\n media: list.media,\n target: list,\n currentTarget: list,\n })) {\n Object.defineProperty(event, key, { value, enumerable: true });\n }\n return event;\n}\n\n/**\n * A `window.matchMedia` for a viewport `width` CSS px wide.\n *\n * Width queries answer from `width`: the range syntax the kit writes for `max-*`\n * (`(width < 768px)`) and every other comparison, `(min-width: …)` and `(max-width: …)`,\n * in px or rem; `and` and comma lists combine as in CSS. The features in `options` answer\n * as set there; every other query is false. The lists keep their listeners, and\n * {@link setViewportWidth} resizes the viewport under them the way a browser window\n * does: each list whose answer flips fires `change`.\n *\n * Hand it to the runner's own global stub where the suite undoes stubs that way —\n * `vi.stubGlobal(\"matchMedia\", viewportMatchMedia(375))` — or use\n * {@link stubViewportWidth}.\n */\nexport function viewportMatchMedia(width: number, options: ViewportOptions = {}): (query: string) => MediaQueryList {\n const viewport: StubViewport = { width, options, lists: new Set() };\n const matchMedia = (query: string) => {\n const list = mediaQueryList(query, viewport);\n viewport.lists.add(list);\n return list as unknown as MediaQueryList;\n };\n VIEWPORTS.set(matchMedia, viewport);\n return matchMedia;\n}\n\n/**\n * Resize the stubbed viewport to `width` CSS px, live — the window being dragged narrower,\n * a phone turned (0.35, keksdose's 0.34 report). Every list the stub in force has handed\n * out answers from the new width, and each one whose answer flipped fires `change` to its\n * `addEventListener` listeners, its legacy `addListener` ones and its `onchange`, as in a\n * browser; a list whose answer stayed the same tells nobody. So a mounted component that\n * listens to a breakpoint (`usePhoneLayout()`, `useBreakpoint()`) switches without being\n * rendered again.\n *\n * The stub in force is whatever `window.matchMedia` is now — one {@link stubViewportWidth}\n * or `vi.stubGlobal(\"matchMedia\", viewportMatchMedia(…))` put in; its features\n * (`options`) stay as they were. Throws when `matchMedia` is not one of these stubs, rather\n * than resize nothing. Synchronous: wrap it in `act()` when a listener sets state.\n *\n * ```ts\n * undo = stubViewportWidth(1280);\n * render(<Page />);\n * act(() => setViewportWidth(375));\n * expect(screen.getByRole(\"list\")).toBeInTheDocument(); // the cards\n * ```\n */\nexport function setViewportWidth(width: number): void {\n const viewport = typeof window === \"undefined\" ? undefined : VIEWPORTS.get(window.matchMedia);\n if (!viewport) {\n throw new Error(\n \"setViewportWidth: no viewport stub is in force — put one in first with \" +\n 'stubViewportWidth(width), or vi.stubGlobal(\"matchMedia\", viewportMatchMedia(width)).',\n );\n }\n viewport.width = width;\n for (const list of [...viewport.lists]) {\n const matches = answer(list.media, width, viewport.options);\n if (matches === list.matches) continue;\n list.matches = matches;\n list.dispatchEvent(changeEvent(list));\n }\n}\n\n/**\n * Make `window.matchMedia` answer as a viewport `width` CSS px wide (see\n * {@link viewportMatchMedia}), and return the undo: it puts back what was there, which\n * in jsdom is nothing — no `matchMedia` at all, the desktop fallback of every kit hook.\n *\n * ```ts\n * let undo = () => {};\n * afterEach(() => undo());\n * it(\"shows cards on a phone\", () => {\n * undo = stubViewportWidth(375);\n * …\n * });\n * ```\n *\n * Right at every text size: at Large the kit's phone query is `(width < 960px)`, which a\n * 375 px viewport matches and a 1280 px one does not, as in a browser.\n */\nexport function stubViewportWidth(width: number, options: ViewportOptions = {}): () => void {\n const before = Object.getOwnPropertyDescriptor(window, \"matchMedia\");\n Object.defineProperty(window, \"matchMedia\", {\n configurable: true,\n writable: true,\n value: viewportMatchMedia(width, options),\n });\n return () => {\n if (before) Object.defineProperty(window, \"matchMedia\", before);\n else Reflect.deleteProperty(window, \"matchMedia\");\n };\n}\n\n/** A box size for {@link ResizeObserverStub.resize}, in CSS px. */\nexport interface StubbedBoxSize {\n width: number;\n height: number;\n}\n\n/** What {@link stubResizeObserver} returns: the test drives the observers. */\nexport interface ResizeObserverStub {\n /**\n * Report `target` at `size` to every live observer watching it, as a browser does once\n * layout settles: one entry, with `contentRect` and the three box sizes all `size`.\n * Synchronous; wrap it in `act()` when the callback sets state.\n */\n resize(target: Element, size: StubbedBoxSize): void;\n /** The elements some live observer watches now, each once. */\n observed(): Element[];\n /** Put back the `ResizeObserver` that was there before — in jsdom, none. */\n restore(): void;\n}\n\n/**\n * Install a `ResizeObserver` the test drives. jsdom has none, and lays nothing out, so a\n * component that measures itself (a windowed list, a fitted chart, a measured grid)\n * either crashes on the missing global or never learns a size. Observers here record\n * what they watch and are called only by {@link ResizeObserverStub.resize}.\n *\n * ```ts\n * const ro = stubResizeObserver();\n * afterEach(() => ro.restore());\n * act(() => ro.resize(screen.getByRole(\"list\"), { width: 400, height: 320 }));\n * ```\n */\nexport function stubResizeObserver(): ResizeObserverStub {\n const live = new Set<StubResizeObserver>();\n\n class StubResizeObserver {\n readonly targets = new Set<Element>();\n constructor(readonly callback: ResizeObserverCallback) {\n live.add(this);\n }\n observe(target: Element) {\n this.targets.add(target);\n }\n unobserve(target: Element) {\n this.targets.delete(target);\n }\n disconnect() {\n this.targets.clear();\n live.delete(this);\n }\n }\n\n const before = Object.getOwnPropertyDescriptor(globalThis, \"ResizeObserver\");\n Object.defineProperty(globalThis, \"ResizeObserver\", {\n configurable: true,\n writable: true,\n value: StubResizeObserver,\n });\n\n return {\n resize(target, { width, height }) {\n const box = [{ inlineSize: width, blockSize: height }];\n const contentRect = {\n x: 0,\n y: 0,\n top: 0,\n left: 0,\n width,\n height,\n right: width,\n bottom: height,\n toJSON: () => ({ x: 0, y: 0, width, height }),\n };\n const entry = {\n target,\n contentRect,\n borderBoxSize: box,\n contentBoxSize: box,\n devicePixelContentBoxSize: box,\n } as unknown as ResizeObserverEntry;\n for (const observer of [...live]) {\n if (observer.targets.has(target)) {\n observer.callback([entry], observer as unknown as ResizeObserver);\n }\n }\n },\n observed() {\n const all: Element[] = [];\n for (const observer of live) for (const target of observer.targets) if (!all.includes(target)) all.push(target);\n return all;\n },\n restore() {\n live.clear();\n if (before) Object.defineProperty(globalThis, \"ResizeObserver\", before);\n else Reflect.deleteProperty(globalThis, \"ResizeObserver\");\n },\n };\n}\n"],"mappings":";AAkCA,SAAS,SAAS,OAAe,MAAsB;AACrD,SAAO,SAAS,OAAO,OAAO,KAAK,IAAI,OAAO,KAAK,IAAI;AACzD;AAEA,MAAM,QAAQ;AACd,MAAM,UAAU;AAChB,MAAM,UAAU;AAGhB,SAAS,UAAU,MAAc,OAAe,SAAmC;AACjF,QAAM,IAAI,KAAK,KAAK;AACpB,MAAI,MAAM,SAAS,MAAM,SAAU,QAAO;AAC1C,QAAM,QAAQ,MAAM,KAAK,CAAC;AAC1B,MAAI,OAAO;AACT,UAAM,KAAK,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;AACtC,YAAQ,MAAM,CAAC,GAAG;AAAA,MAChB,KAAK;AACH,eAAO,QAAQ;AAAA,MACjB,KAAK;AACH,eAAO,SAAS;AAAA,MAClB,KAAK;AACH,eAAO,QAAQ;AAAA,MACjB;AACE,eAAO,SAAS;AAAA,IACpB;AAAA,EACF;AACA,QAAM,SAAS,QAAQ,KAAK,CAAC;AAC7B,MAAI,QAAQ;AACV,UAAM,KAAK,SAAS,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AACxC,WAAO,OAAO,CAAC,MAAM,QAAQ,SAAS,KAAK,SAAS;AAAA,EACtD;AACA,QAAM,UAAU,QAAQ,KAAK,CAAC;AAC9B,MAAI,CAA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AAO,OAAO;AAAA,MAC7C;AACA,YAAM,QAAQ;AAAA,QACZ;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf,gBAAgB;AAAA,QAChB,2BAA2B;AAAA,MAC7B;AACA,iBAAW,YAAY,CAAC,GAAG,IAAI,GAAG;AAChC,YAAI,SAAS,QAAQ,IAAI,MAAM,GAAG;AAChC,mBAAS,SAAS,CAAC,KAAK,GAAG,QAAqC;AAAA,QAClE;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW;AACT,YAAM,MAAiB,CAAC;AACxB,iBAAW,YAAY,KAAM,YAAW,UAAU,SAAS,QAAS,KAAI,CAAC,IAAI,SAAS,MAAM,EAAG,KAAI,KAAK,MAAM;AAC9G,aAAO;AAAA,IACT;AAAA,IACA,UAAU;AACR,WAAK,MAAM;AACX,UAAI,OAAQ,QAAO,eAAe,YAAY,kBAAkB,MAAM;AAAA,UACjE,SAAQ,eAAe,YAAY,gBAAgB;AAAA,IAC1D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
contrast,
|
|
4
|
+
hexToOklch,
|
|
5
|
+
luminance,
|
|
6
|
+
oklchToHex,
|
|
7
|
+
oklchToRgb,
|
|
8
|
+
parseHex,
|
|
9
|
+
rgbToOklch,
|
|
10
|
+
solveLightness,
|
|
11
|
+
toHex
|
|
12
|
+
} from "./color.js";
|
|
3
13
|
const CONTRAST_STEPPED_VARS = [
|
|
4
14
|
"--text-secondary",
|
|
5
15
|
"--text-muted",
|
|
@@ -82,7 +92,8 @@ function worstContrast(color, t, well) {
|
|
|
82
92
|
function steppedBorder(t, well) {
|
|
83
93
|
const surface2 = well?.bgSurface2 ?? t.bgSurface2;
|
|
84
94
|
let lo = BORDER_STRONG_SHARE;
|
|
85
|
-
if (worstContrast(mix(t.border, t.textPrimary, 1 - lo), t, surface2) >= BORDER_TARGET)
|
|
95
|
+
if (worstContrast(mix(t.border, t.textPrimary, 1 - lo), t, surface2) >= BORDER_TARGET)
|
|
96
|
+
return mix(t.border, t.textPrimary, 1 - lo);
|
|
86
97
|
let hi = 1;
|
|
87
98
|
for (let i = 0; i < 16; i++) {
|
|
88
99
|
const mid = (lo + hi) / 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/contrast-tokens.ts"],"sourcesContent":["import { contrast, hexToOklch, luminance, oklchToHex, oklchToRgb, parseHex, rgbToOklch, solveLightness, toHex } from \"./color\";\nimport type { TokenSet } from \"./palette-presets\";\n\n/**\n * The \"More contrast\" step on a token set (docs/text-size-harmonization.md §5, §10.5).\n * INTERNAL — `applyTokenSet` and the contrast layer share it; it is not re-exported.\n *\n * The step happens HERE, in JS, because the tokens it changes are written inline on\n * `<html>` by `applyTokenSet`: an inline value beats any `[data-contrast=more]` rule and\n * any `@media (prefers-contrast: more)` block, so a stylesheet cannot do it (§10.5, the\n * keksdose review). `--text-placeholder` is a CSS-derived token, and it is written inline\n * here too rather than redefined per attribute in tokens.css.\n *\n * What moves (§5):\n * - `--text-muted` becomes the set's `--text-secondary`;\n * - `--text-secondary` moves halfway to `--text-primary`;\n * - `--text-placeholder` becomes the set's `--text-muted` (4.6–5.5:1 on every shipped\n * preset, where the CSS formula gives 2.4–2.8:1) — the order primary > secondary >\n * muted > placeholder survives the step;\n * - `--border` moves toward `--text-primary` until it clears 3:1 against the worst of the\n * three surfaces (WCAG 1.4.11, a field's boundary), and never less far than\n * `--border-strong`'s 45 % — so every border is at least as strong as a \"strong\" one was.\n * `--border-strong` stays derived in tokens.css and grows with it;\n * - in a LIGHT set only (0.36, docs/colour-roles-harmonization.md §13): the well\n * (`--bg-surface-2`) becomes {@link WELL_INK_MORE} of `--text-primary` mixed into the\n * card, and each of the four money colours that falls under 4.5:1 on that well is\n * solved darker at its own hue and chroma. The border above is solved against the\n * stepped well. A dark set's well stands 1.11–1.13:1 from its card already, and its\n * money has no room: nothing of it steps.\n *\n * What does NOT move here, because it is not inline: the light status, hue and field-sync\n * literals and `--bg-active` step in tokens.css's `:root[data-contrast=\"more\"]:not(.dark)`\n * block, solved over these stepped wells.\n */\n\n/** The custom properties a contrast step writes. The last five only for a light set. */\nexport const CONTRAST_STEPPED_VARS = [\n \"--text-secondary\",\n \"--text-muted\",\n \"--text-placeholder\",\n \"--border\",\n \"--bg-surface-2\",\n \"--money-income\",\n \"--money-expense\",\n \"--money-net\",\n \"--money-neutral\",\n] as const;\n\n/** The light well under More contrast and the money that reads on it (§13.4). */\nexport interface WellStep {\n bgSurface2: string;\n moneyIncome: string;\n moneyExpense: string;\n moneyNet: string;\n moneyNeutral: string;\n}\n\nexport interface ContrastStep {\n textSecondary: string;\n textMuted: string;\n textPlaceholder: string;\n border: string;\n /** The stepped well and money, or null for a dark set (which does not step them). */\n well: WellStep | null;\n}\n\ninterface Lab {\n l: number;\n a: number;\n b: number;\n}\n\nfunction toLab(hex: string): Lab | null {\n const rgb = parseHex(hex);\n if (!rgb) return null;\n const { l, c, h } = rgbToOklch(rgb);\n const rad = (h * Math.PI) / 180;\n return { l, a: c * Math.cos(rad), b: c * Math.sin(rad) };\n}\n\n/** `color-mix(in oklab, a p, b)` as a hex — the same formula tokens.css's derived roles\n * use, so a stepped value sits where the stylesheet would have put it. A colour that is\n * not hex (a consumer's own token set) comes back unmixed. The deriver mixes with it\n * too (`--bg-hover`, `--brand-muted`, `--brand-bg`, `--brand-bg-hover`). */\nexport function mix(a: string, b: string, p: number): string {\n const A = toLab(a);\n const B = toLab(b);\n if (!A || !B) return a;\n const l = A.l * p + B.l * (1 - p);\n const x = A.a * p + B.a * (1 - p);\n const y = A.b * p + B.b * (1 - p);\n const c = Math.hypot(x, y);\n const h = c < 1e-6 ? 0 : ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360;\n return toHex(oklchToRgb({ l, c, h }));\n}\n\n/**\n * `--bg-hover` in tokens.css: this share of `--text-primary` mixed into `--bg-surface`.\n *\n * 5.5 %, down from 7 % in 0.33 (docs/colour-roles-harmonization.md §12.10): a hovered row\n * on a card is the darkest fill (in dark, the lightest) that text sits on, and at 7 % the\n * light status colours, the money colours and Ink/Moss/Plum's muted text fell to\n * 4.25–4.49:1 on it. The status literals are fixed, the same in every preset, so the\n * hover moved instead: text wins over the hover's step. At 5.5 % the step from the card\n * is still 1.09–1.13:1, above the 1.08:1 the kit's hover rule asks (§12.2). The deriver\n * solves the money colours against this fill, and tokens-css-audit.test.ts measures\n * every text role on it in every shipped preset, so the two cannot part.\n */\nexport const HOVER_INK = 0.055;\n\n/** The card's hover fill (`--bg-hover`) for `t`, as tokens.css mixes it. */\nexport function hoverFill(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): string {\n return mix(t.textPrimary, t.bgSurface, HOVER_INK);\n}\n\n/**\n * The light well under More contrast: this share of `--text-primary` mixed into the card,\n * `--bg-hover`'s formula at a larger share (0.36, docs/colour-roles-harmonization.md §13).\n *\n * In light the well is the page (§5.3), 1.09–1.11:1 from the card. At 10 % it stands\n * 1.19–1.24:1 from it, about twice that. The rule it is held to: **the stepped well stands\n * at least 1.17:1 from the card**, two of the hover rule's 1.08 steps; 9 % is the least\n * that clears it in every shipped preset, with no room. The step cannot ship alone: on a\n * 10 % well money, status and two hues read 4.07–4.28:1, so the money is solved with it\n * here and the status and hue literals in tokens.css.\n */\nexport const WELL_INK_MORE = 0.1;\n\n/** The least the stepped light well stands from the card (§13.3, decision 2). */\nexport const WELL_STEP_MIN = 1.17;\n\n/** True when `t` is a light set: its body ink darker than its card. */\nfunction isLightSet(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): boolean | null {\n const ink = parseHex(t.textPrimary);\n const card = parseHex(t.bgSurface);\n if (!ink || !card) return null;\n return luminance(ink) < luminance(card);\n}\n\n/** Money as text: WCAG 1.4.3 AA. */\nconst MONEY_TARGET = 4.5;\n\n/** `color` as it is when it clears 4.5:1 on `well`, else solved darker at its own hue and\n * chroma until it does — measured on the hex (`solveLightness`). */\nfunction moneyOn(color: string, well: string): string {\n if (contrast(color, well) >= MONEY_TARGET) return color;\n const lch = hexToOklch(color);\n const bg = parseHex(well);\n if (!lch || !bg) return color;\n const l = solveLightness(MONEY_TARGET, bg, lch.h, lch.c, \"darker\");\n return oklchToHex({ l, c: lch.c, h: lch.h });\n}\n\n/** The light well under More contrast for `t`, or null for a dark set (or one whose ink or\n * card is not hex, which cannot be mixed). The deriver solves the brand against it. */\nexport function steppedWellFill(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): string | null {\n return isLightSet(t) ? mix(t.textPrimary, t.bgSurface, WELL_INK_MORE) : null;\n}\n\n/** The stepped well and money of a light set, or null (see {@link steppedWellFill}). */\nfunction wellStep(t: TokenSet): WellStep | null {\n const well = steppedWellFill(t);\n if (!well) return null;\n return {\n bgSurface2: well,\n moneyIncome: moneyOn(t.moneyIncome, well),\n moneyExpense: moneyOn(t.moneyExpense, well),\n moneyNet: moneyOn(t.moneyNet, well),\n moneyNeutral: moneyOn(t.moneyNeutral, well),\n };\n}\n\n/**\n * `--brand-muted` in tokens.css: this share of `--brand` mixed into `--text-primary`.\n *\n * 62 %, down from 70 % in 0.33 (docs/colour-roles-harmonization.md §12.11): the brand as\n * text sits on its soft chip HOVERED too (`--brand-bg-hover` — ButtonGroupLink's current\n * page, a selected day), and at 70 % it read 4.08–4.42:1 there in Default and Moss light\n * and in Ink, Moss, Plum and Contrast dark. The brand could not move instead: the dark\n * brands would have flipped their white label to the dark ink. Nor could the chip's hover\n * lighten: by the time the text cleared 4.5:1 the hover sat 1.00:1 from the chip it\n * hovers. So the text moves toward the ink, as `--bg-hover` moved for its text.\n */\nexport const BRAND_MUTED_SHARE = 0.62;\n/** `--brand-bg` and `--brand-bg-hover` in tokens.css: these shares of `--brand` mixed\n * into `--bg-surface`. */\nexport const BRAND_BG_SHARE = 0.14;\nexport const BRAND_BG_HOVER_SHARE = 0.24;\n\n/** `--brand-muted`, `--brand-bg` and `--brand-bg-hover` for `t`, as tokens.css mixes them.\n * tokens-css-audit.test.ts holds the three shares equal to the stylesheet's. */\nexport function brandSoft(t: Pick<TokenSet, \"brand\" | \"textPrimary\" | \"bgSurface\">): {\n brandMuted: string;\n brandBg: string;\n brandBgHover: string;\n} {\n return {\n brandMuted: mix(t.brand, t.textPrimary, BRAND_MUTED_SHARE),\n brandBg: mix(t.brand, t.bgSurface, BRAND_BG_SHARE),\n brandBgHover: mix(t.brand, t.bgSurface, BRAND_BG_HOVER_SHARE),\n };\n}\n\n/** WCAG 1.4.11 for a component's boundary. */\nconst BORDER_TARGET = 3;\n/** `--border-strong` in tokens.css: 55 % border, 45 % text. */\nconst BORDER_STRONG_SHARE = 0.45;\n\n/** The worst of the three surfaces; `well`, when the step has one, in place of the set's. */\nfunction worstContrast(color: string, t: TokenSet, well: string): number {\n return Math.min(contrast(color, t.bgPage), contrast(color, t.bgSurface), contrast(color, well));\n}\n\nfunction steppedBorder(t: TokenSet, well: WellStep | null): string {\n // The share of `--text-primary` in the border: at least --border-strong's, more until\n // 3:1. Monotonic in the share (the mix walks from the border to the text, away from\n // every surface), so a bisection finds the least that clears it. Against the stepped\n // light well (§13.4), which is the darkest surface under More contrast.\n const surface2 = well?.bgSurface2 ?? t.bgSurface2;\n let lo = BORDER_STRONG_SHARE;\n if (worstContrast(mix(t.border, t.textPrimary, 1 - lo), t, surface2) >= BORDER_TARGET) return mix(t.border, t.textPrimary, 1 - lo);\n let hi = 1;\n for (let i = 0; i < 16; i++) {\n const mid = (lo + hi) / 2;\n if (worstContrast(mix(t.border, t.textPrimary, 1 - mid), t, surface2) >= BORDER_TARGET) hi = mid;\n else lo = mid;\n }\n return mix(t.border, t.textPrimary, 1 - hi);\n}\n\n/** The stepped values for `t`: the four text and line tokens, and for a light set the\n * well and money (`well`, null in dark). Pure. */\nexport function contrastStep(t: TokenSet): ContrastStep {\n const well = wellStep(t);\n return {\n textSecondary: mix(t.textSecondary, t.textPrimary, 0.5),\n textMuted: t.textSecondary,\n textPlaceholder: t.textMuted,\n border: steppedBorder(t, well),\n well,\n };\n}\n\n/* ── The token set last written to an element ───────────────────────────── */\n\nconst lastWritten = new WeakMap<HTMLElement, TokenSet>();\n\n/** Remember the set `applyTokenSet` wrote, so a contrast change can re-apply it. */\nexport function rememberTokenSet(el: HTMLElement, t: TokenSet): void {\n lastWritten.set(el, t);\n}\n\n/** The set `applyTokenSet` last wrote to `el`, or undefined when nothing did — an app\n * without the palette layer, whose base tokens come from tokens.css. */\nexport function rememberedTokenSet(el: HTMLElement): TokenSet | undefined {\n return lastWritten.get(el);\n}\n"],"mappings":";AAAA,SAAS,UAAU,YAAY,WAAW,YAAY,YAAY,UAAU,YAAY,gBAAgB,aAAa;AAoC9G,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA0BA,SAAS,MAAM,KAAyB;AACtC,QAAM,MAAM,SAAS,GAAG;AACxB,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,WAAW,GAAG;AAClC,QAAM,MAAO,IAAI,KAAK,KAAM;AAC5B,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,IAAI,KAAK,IAAI,GAAG,EAAE;AACzD;AAMO,SAAS,IAAI,GAAW,GAAW,GAAmB;AAC3D,QAAM,IAAI,MAAM,CAAC;AACjB,QAAM,IAAI,MAAM,CAAC;AACjB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,KAAK,MAAM,GAAG,CAAC;AACzB,QAAM,IAAI,IAAI,OAAO,KAAM,KA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I,QAA+B;AAGhD,SAAS,iBAAiB,IAAiB,GAAmB;AACnE,cAAY,IAAI,IAAI,CAAC;AACvB;AAIO,SAAS,mBAAmB,IAAuC;AACxE,SAAO,YAAY,IAAI,EAAE;AAC3B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/contrast-tokens.ts"],"sourcesContent":["import {\n contrast,\n hexToOklch,\n luminance,\n oklchToHex,\n oklchToRgb,\n parseHex,\n rgbToOklch,\n solveLightness,\n toHex,\n} from \"./color\";\nimport type { TokenSet } from \"./palette-presets\";\n\n/**\n * The \"More contrast\" step on a token set (docs/text-size-harmonization.md §5, §10.5).\n * INTERNAL — `applyTokenSet` and the contrast layer share it; it is not re-exported.\n *\n * The step happens HERE, in JS, because the tokens it changes are written inline on\n * `<html>` by `applyTokenSet`: an inline value beats any `[data-contrast=more]` rule and\n * any `@media (prefers-contrast: more)` block, so a stylesheet cannot do it (§10.5, the\n * keksdose review). `--text-placeholder` is a CSS-derived token, and it is written inline\n * here too rather than redefined per attribute in tokens.css.\n *\n * What moves (§5):\n * - `--text-muted` becomes the set's `--text-secondary`;\n * - `--text-secondary` moves halfway to `--text-primary`;\n * - `--text-placeholder` becomes the set's `--text-muted` (4.6–5.5:1 on every shipped\n * preset, where the CSS formula gives 2.4–2.8:1) — the order primary > secondary >\n * muted > placeholder survives the step;\n * - `--border` moves toward `--text-primary` until it clears 3:1 against the worst of the\n * three surfaces (WCAG 1.4.11, a field's boundary), and never less far than\n * `--border-strong`'s 45 % — so every border is at least as strong as a \"strong\" one was.\n * `--border-strong` stays derived in tokens.css and grows with it;\n * - in a LIGHT set only (0.36, docs/colour-roles-harmonization.md §13): the well\n * (`--bg-surface-2`) becomes {@link WELL_INK_MORE} of `--text-primary` mixed into the\n * card, and each of the four money colours that falls under 4.5:1 on that well is\n * solved darker at its own hue and chroma. The border above is solved against the\n * stepped well. A dark set's well stands 1.11–1.13:1 from its card already, and its\n * money has no room: nothing of it steps.\n *\n * What does NOT move here, because it is not inline: the light status, hue and field-sync\n * literals and `--bg-active` step in tokens.css's `:root[data-contrast=\"more\"]:not(.dark)`\n * block, solved over these stepped wells.\n */\n\n/** The custom properties a contrast step writes. The last five only for a light set. */\nexport const CONTRAST_STEPPED_VARS = [\n \"--text-secondary\",\n \"--text-muted\",\n \"--text-placeholder\",\n \"--border\",\n \"--bg-surface-2\",\n \"--money-income\",\n \"--money-expense\",\n \"--money-net\",\n \"--money-neutral\",\n] as const;\n\n/** The light well under More contrast and the money that reads on it (§13.4). */\nexport interface WellStep {\n bgSurface2: string;\n moneyIncome: string;\n moneyExpense: string;\n moneyNet: string;\n moneyNeutral: string;\n}\n\nexport interface ContrastStep {\n textSecondary: string;\n textMuted: string;\n textPlaceholder: string;\n border: string;\n /** The stepped well and money, or null for a dark set (which does not step them). */\n well: WellStep | null;\n}\n\ninterface Lab {\n l: number;\n a: number;\n b: number;\n}\n\nfunction toLab(hex: string): Lab | null {\n const rgb = parseHex(hex);\n if (!rgb) return null;\n const { l, c, h } = rgbToOklch(rgb);\n const rad = (h * Math.PI) / 180;\n return { l, a: c * Math.cos(rad), b: c * Math.sin(rad) };\n}\n\n/** `color-mix(in oklab, a p, b)` as a hex — the same formula tokens.css's derived roles\n * use, so a stepped value sits where the stylesheet would have put it. A colour that is\n * not hex (a consumer's own token set) comes back unmixed. The deriver mixes with it\n * too (`--bg-hover`, `--brand-muted`, `--brand-bg`, `--brand-bg-hover`). */\nexport function mix(a: string, b: string, p: number): string {\n const A = toLab(a);\n const B = toLab(b);\n if (!A || !B) return a;\n const l = A.l * p + B.l * (1 - p);\n const x = A.a * p + B.a * (1 - p);\n const y = A.b * p + B.b * (1 - p);\n const c = Math.hypot(x, y);\n const h = c < 1e-6 ? 0 : ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360;\n return toHex(oklchToRgb({ l, c, h }));\n}\n\n/**\n * `--bg-hover` in tokens.css: this share of `--text-primary` mixed into `--bg-surface`.\n *\n * 5.5 %, down from 7 % in 0.33 (docs/colour-roles-harmonization.md §12.10): a hovered row\n * on a card is the darkest fill (in dark, the lightest) that text sits on, and at 7 % the\n * light status colours, the money colours and Ink/Moss/Plum's muted text fell to\n * 4.25–4.49:1 on it. The status literals are fixed, the same in every preset, so the\n * hover moved instead: text wins over the hover's step. At 5.5 % the step from the card\n * is still 1.09–1.13:1, above the 1.08:1 the kit's hover rule asks (§12.2). The deriver\n * solves the money colours against this fill, and tokens-css-audit.test.ts measures\n * every text role on it in every shipped preset, so the two cannot part.\n */\nexport const HOVER_INK = 0.055;\n\n/** The card's hover fill (`--bg-hover`) for `t`, as tokens.css mixes it. */\nexport function hoverFill(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): string {\n return mix(t.textPrimary, t.bgSurface, HOVER_INK);\n}\n\n/**\n * The light well under More contrast: this share of `--text-primary` mixed into the card,\n * `--bg-hover`'s formula at a larger share (0.36, docs/colour-roles-harmonization.md §13).\n *\n * In light the well is the page (§5.3), 1.09–1.11:1 from the card. At 10 % it stands\n * 1.19–1.24:1 from it, about twice that. The rule it is held to: **the stepped well stands\n * at least 1.17:1 from the card**, two of the hover rule's 1.08 steps; 9 % is the least\n * that clears it in every shipped preset, with no room. The step cannot ship alone: on a\n * 10 % well money, status and two hues read 4.07–4.28:1, so the money is solved with it\n * here and the status and hue literals in tokens.css.\n */\nexport const WELL_INK_MORE = 0.1;\n\n/** The least the stepped light well stands from the card (§13.3, decision 2). */\nexport const WELL_STEP_MIN = 1.17;\n\n/** True when `t` is a light set: its body ink darker than its card. */\nfunction isLightSet(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): boolean | null {\n const ink = parseHex(t.textPrimary);\n const card = parseHex(t.bgSurface);\n if (!ink || !card) return null;\n return luminance(ink) < luminance(card);\n}\n\n/** Money as text: WCAG 1.4.3 AA. */\nconst MONEY_TARGET = 4.5;\n\n/** `color` as it is when it clears 4.5:1 on `well`, else solved darker at its own hue and\n * chroma until it does — measured on the hex (`solveLightness`). */\nfunction moneyOn(color: string, well: string): string {\n if (contrast(color, well) >= MONEY_TARGET) return color;\n const lch = hexToOklch(color);\n const bg = parseHex(well);\n if (!lch || !bg) return color;\n const l = solveLightness(MONEY_TARGET, bg, lch.h, lch.c, \"darker\");\n return oklchToHex({ l, c: lch.c, h: lch.h });\n}\n\n/** The light well under More contrast for `t`, or null for a dark set (or one whose ink or\n * card is not hex, which cannot be mixed). The deriver solves the brand against it. */\nexport function steppedWellFill(t: Pick<TokenSet, \"textPrimary\" | \"bgSurface\">): string | null {\n return isLightSet(t) ? mix(t.textPrimary, t.bgSurface, WELL_INK_MORE) : null;\n}\n\n/** The stepped well and money of a light set, or null (see {@link steppedWellFill}). */\nfunction wellStep(t: TokenSet): WellStep | null {\n const well = steppedWellFill(t);\n if (!well) return null;\n return {\n bgSurface2: well,\n moneyIncome: moneyOn(t.moneyIncome, well),\n moneyExpense: moneyOn(t.moneyExpense, well),\n moneyNet: moneyOn(t.moneyNet, well),\n moneyNeutral: moneyOn(t.moneyNeutral, well),\n };\n}\n\n/**\n * `--brand-muted` in tokens.css: this share of `--brand` mixed into `--text-primary`.\n *\n * 62 %, down from 70 % in 0.33 (docs/colour-roles-harmonization.md §12.11): the brand as\n * text sits on its soft chip HOVERED too (`--brand-bg-hover` — ButtonGroupLink's current\n * page, a selected day), and at 70 % it read 4.08–4.42:1 there in Default and Moss light\n * and in Ink, Moss, Plum and Contrast dark. The brand could not move instead: the dark\n * brands would have flipped their white label to the dark ink. Nor could the chip's hover\n * lighten: by the time the text cleared 4.5:1 the hover sat 1.00:1 from the chip it\n * hovers. So the text moves toward the ink, as `--bg-hover` moved for its text.\n */\nexport const BRAND_MUTED_SHARE = 0.62;\n/** `--brand-bg` and `--brand-bg-hover` in tokens.css: these shares of `--brand` mixed\n * into `--bg-surface`. */\nexport const BRAND_BG_SHARE = 0.14;\nexport const BRAND_BG_HOVER_SHARE = 0.24;\n\n/** `--brand-muted`, `--brand-bg` and `--brand-bg-hover` for `t`, as tokens.css mixes them.\n * tokens-css-audit.test.ts holds the three shares equal to the stylesheet's. */\nexport function brandSoft(t: Pick<TokenSet, \"brand\" | \"textPrimary\" | \"bgSurface\">): {\n brandMuted: string;\n brandBg: string;\n brandBgHover: string;\n} {\n return {\n brandMuted: mix(t.brand, t.textPrimary, BRAND_MUTED_SHARE),\n brandBg: mix(t.brand, t.bgSurface, BRAND_BG_SHARE),\n brandBgHover: mix(t.brand, t.bgSurface, BRAND_BG_HOVER_SHARE),\n };\n}\n\n/** WCAG 1.4.11 for a component's boundary. */\nconst BORDER_TARGET = 3;\n/** `--border-strong` in tokens.css: 55 % border, 45 % text. */\nconst BORDER_STRONG_SHARE = 0.45;\n\n/** The worst of the three surfaces; `well`, when the step has one, in place of the set's. */\nfunction worstContrast(color: string, t: TokenSet, well: string): number {\n return Math.min(contrast(color, t.bgPage), contrast(color, t.bgSurface), contrast(color, well));\n}\n\nfunction steppedBorder(t: TokenSet, well: WellStep | null): string {\n // The share of `--text-primary` in the border: at least --border-strong's, more until\n // 3:1. Monotonic in the share (the mix walks from the border to the text, away from\n // every surface), so a bisection finds the least that clears it. Against the stepped\n // light well (§13.4), which is the darkest surface under More contrast.\n const surface2 = well?.bgSurface2 ?? t.bgSurface2;\n let lo = BORDER_STRONG_SHARE;\n if (worstContrast(mix(t.border, t.textPrimary, 1 - lo), t, surface2) >= BORDER_TARGET)\n return mix(t.border, t.textPrimary, 1 - lo);\n let hi = 1;\n for (let i = 0; i < 16; i++) {\n const mid = (lo + hi) / 2;\n if (worstContrast(mix(t.border, t.textPrimary, 1 - mid), t, surface2) >= BORDER_TARGET) hi = mid;\n else lo = mid;\n }\n return mix(t.border, t.textPrimary, 1 - hi);\n}\n\n/** The stepped values for `t`: the four text and line tokens, and for a light set the\n * well and money (`well`, null in dark). Pure. */\nexport function contrastStep(t: TokenSet): ContrastStep {\n const well = wellStep(t);\n return {\n textSecondary: mix(t.textSecondary, t.textPrimary, 0.5),\n textMuted: t.textSecondary,\n textPlaceholder: t.textMuted,\n border: steppedBorder(t, well),\n well,\n };\n}\n\n/* ── The token set last written to an element ───────────────────────────── */\n\nconst lastWritten = new WeakMap<HTMLElement, TokenSet>();\n\n/** Remember the set `applyTokenSet` wrote, so a contrast change can re-apply it. */\nexport function rememberTokenSet(el: HTMLElement, t: TokenSet): void {\n lastWritten.set(el, t);\n}\n\n/** The set `applyTokenSet` last wrote to `el`, or undefined when nothing did — an app\n * without the palette layer, whose base tokens come from tokens.css. */\nexport function rememberedTokenSet(el: HTMLElement): TokenSet | undefined {\n return lastWritten.get(el);\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAoCA,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA0BA,SAAS,MAAM,KAAyB;AACtC,QAAM,MAAM,SAAS,GAAG;AACxB,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,WAAW,GAAG;AAClC,QAAM,MAAO,IAAI,KAAK,KAAM;AAC5B,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,IAAI,KAAK,IAAI,GAAG,EAAE;AACzD;AAMO,SAAS,IAAI,GAAW,GAAW,GAAmB;AAC3D,QAAM,IAAI,MAAM,CAAC;AACjB,QAAM,IAAI,MAAM,CAAC;AACjB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,EAAE,IAAI,IAAI,EAAE,KAAK,IAAI;AAC/B,QAAM,IAAI,KAAK,MAAM,GAAG,CAAC;AACzB,QAAM,IAA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;AAIA,MAAM,cAAc,oBAAI,QAA+B;AAGhD,SAAS,iBAAiB,IAAiB,GAAmB;AACnE,cAAY,IAAI,IAAI,CAAC;AACvB;AAIO,SAAS,mBAAmB,IAAuC;AACxE,SAAO,YAAY,IAAI,EAAE;AAC3B;","names":[]}
|
package/dist/theme/contrast.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export declare function createContrastStore(storageKey: string): {
|
|
|
90
90
|
setState(state: ContrastState | ((state: ContrastState) => ContrastState), replace: true): unknown;
|
|
91
91
|
persist: {
|
|
92
92
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ContrastState, {
|
|
93
|
-
contrast: "
|
|
93
|
+
contrast: "more" | "system" | "standard" | null;
|
|
94
94
|
}, unknown>>) => void;
|
|
95
95
|
clearStorage: () => void;
|
|
96
96
|
rehydrate: () => Promise<void> | void;
|
|
@@ -98,7 +98,7 @@ export declare function createContrastStore(storageKey: string): {
|
|
|
98
98
|
onHydrate: (fn: (state: ContrastState) => void) => () => void;
|
|
99
99
|
onFinishHydration: (fn: (state: ContrastState) => void) => () => void;
|
|
100
100
|
getOptions: () => Partial<import("zustand/middleware").PersistOptions<ContrastState, {
|
|
101
|
-
contrast: "
|
|
101
|
+
contrast: "more" | "system" | "standard" | null;
|
|
102
102
|
}, unknown>>;
|
|
103
103
|
};
|
|
104
104
|
}>;
|
|
@@ -92,7 +92,7 @@ export interface DerivedPalette {
|
|
|
92
92
|
/** Compromises the deriver had to make, in plain words. Never silent. */
|
|
93
93
|
warnings: string[];
|
|
94
94
|
}
|
|
95
|
-
export declare function derivePalette({ anchors, mode, surfaceTint, textContrast
|
|
95
|
+
export declare function derivePalette({ anchors, mode, surfaceTint, textContrast }: DeriveOptions): DerivedPalette;
|
|
96
96
|
/**
|
|
97
97
|
* Measure every pair that has a requirement, and say which ones fail.
|
|
98
98
|
*
|
|
@@ -92,12 +92,7 @@ function tintOn(hue, chroma, surface, mode) {
|
|
|
92
92
|
const l = mode === "light" ? s.l - 0.055 : s.l + 0.055;
|
|
93
93
|
return oklchToHex({ l, c: Math.min(chroma * 0.45, 0.06), h: hue });
|
|
94
94
|
}
|
|
95
|
-
function derivePalette({
|
|
96
|
-
anchors,
|
|
97
|
-
mode,
|
|
98
|
-
surfaceTint = 0.55,
|
|
99
|
-
textContrast
|
|
100
|
-
}) {
|
|
95
|
+
function derivePalette({ anchors, mode, surfaceTint = 0.55, textContrast }) {
|
|
101
96
|
const warnings = [];
|
|
102
97
|
const brand = hexToOklch(anchors.brand);
|
|
103
98
|
if (!brand) {
|
|
@@ -194,20 +189,8 @@ function derivePalette({
|
|
|
194
189
|
const hue = semanticHue[role];
|
|
195
190
|
const chroma = semanticChroma[role];
|
|
196
191
|
const bg = tintOn(hue, chroma, surfaces.bgSurface, mode);
|
|
197
|
-
const onSurface = solveLightness(
|
|
198
|
-
|
|
199
|
-
parseHex(worstText),
|
|
200
|
-
hue,
|
|
201
|
-
chroma,
|
|
202
|
-
mode === "light" ? "darker" : "lighter"
|
|
203
|
-
);
|
|
204
|
-
const onTint = solveLightness(
|
|
205
|
-
4.5,
|
|
206
|
-
parseHex(bg),
|
|
207
|
-
hue,
|
|
208
|
-
chroma,
|
|
209
|
-
mode === "light" ? "darker" : "lighter"
|
|
210
|
-
);
|
|
192
|
+
const onSurface = solveLightness(4.5, parseHex(worstText), hue, chroma, mode === "light" ? "darker" : "lighter");
|
|
193
|
+
const onTint = solveLightness(4.5, parseHex(bg), hue, chroma, mode === "light" ? "darker" : "lighter");
|
|
211
194
|
const l = mode === "light" ? Math.min(onSurface, onTint) : Math.max(onSurface, onTint);
|
|
212
195
|
return oklchToHex({ l, c: chroma, h: hue });
|
|
213
196
|
};
|
|
@@ -266,7 +249,13 @@ function derivePalette({
|
|
|
266
249
|
const moneyExpense = money(70, 4.5);
|
|
267
250
|
const moneyNet = money(300, 4.5);
|
|
268
251
|
const neutralChroma = 0.012 * weight;
|
|
269
|
-
const neutralFloor = solveLightness(
|
|
252
|
+
const neutralFloor = solveLightness(
|
|
253
|
+
4.5,
|
|
254
|
+
parseHex(worstText),
|
|
255
|
+
brand.h,
|
|
256
|
+
neutralChroma,
|
|
257
|
+
mode === "light" ? "darker" : "lighter"
|
|
258
|
+
);
|
|
270
259
|
const moneyNeutral = oklchToHex({
|
|
271
260
|
l: mode === "light" ? Math.min(0.52, neutralFloor) : Math.max(0.72, neutralFloor),
|
|
272
261
|
c: neutralChroma,
|
|
@@ -350,7 +339,13 @@ function auditPalette(set, semantic, options = {}) {
|
|
|
350
339
|
else add(`border on ${name}`, t.border, bg, 1.1, "house rule: a hairline must be findable");
|
|
351
340
|
}
|
|
352
341
|
if (step?.well) {
|
|
353
|
-
add(
|
|
342
|
+
add(
|
|
343
|
+
"bgSurface2 on bgSurface",
|
|
344
|
+
t.bgSurface2,
|
|
345
|
+
t.bgSurface,
|
|
346
|
+
WELL_STEP_MIN,
|
|
347
|
+
"house rule: the well stands two hover steps from the card"
|
|
348
|
+
);
|
|
354
349
|
}
|
|
355
350
|
for (const [name, bg] of textGrounds) {
|
|
356
351
|
add(`textPrimary on ${name}`, t.textPrimary, bg, 7, "WCAG 1.4.6 AAA body text");
|
|
@@ -387,13 +382,7 @@ function auditPalette(set, semantic, options = {}) {
|
|
|
387
382
|
add("warning on warningBg", semantic.warning, semantic.warningBg, 4.5, "WCAG 1.4.3 \u2014 badge text");
|
|
388
383
|
add("info on infoBg", semantic.info, semantic.infoBg, 4.5, "WCAG 1.4.3 \u2014 badge text");
|
|
389
384
|
add("success on successBg", semantic.success, semantic.successBg, 4.5, "WCAG 1.4.3 \u2014 badge text");
|
|
390
|
-
add(
|
|
391
|
-
"dangerContrast on danger",
|
|
392
|
-
semantic.dangerContrast,
|
|
393
|
-
semantic.danger,
|
|
394
|
-
4.5,
|
|
395
|
-
"WCAG 1.4.3 AA body text"
|
|
396
|
-
);
|
|
385
|
+
add("dangerContrast on danger", semantic.dangerContrast, semantic.danger, 4.5, "WCAG 1.4.3 AA body text");
|
|
397
386
|
}
|
|
398
387
|
const failures = checks.filter((c) => !c.passes);
|
|
399
388
|
return { checks, failures, passes: failures.length === 0 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/palette-derive.ts"],"sourcesContent":["import type { ThemeMode } from \"./theme-store\";\nimport type { TokenSet } from \"./palette-presets\";\nimport type { HeatStops } from \"./chart-palette\";\nimport {\n contrast,\n deltaE,\n toHex,\n hexToOklch,\n oklchToHex,\n parseHex,\n rgbToOklch,\n simulateCvd,\n solveLightness,\n} from \"./color\";\nimport type { CvdType, Oklch } from \"./color\";\nimport type { ContrastLevel } from \"./contrast\";\nimport { brandSoft, contrastStep, hoverFill, steppedWellFill, WELL_STEP_MIN } from \"./contrast-tokens\";\n\n/**\n * Build a whole palette from one brand colour, plus any number of colours pinned by\n * hand, with every contrast ratio SOLVED rather than chosen and then hoped for.\n *\n * The presets this package shipped were assembled by eye and annotated with the ratios\n * they were believed to hold — `tokens.css` records \"7.0:1 and 4.8:1\", and\n * `palette-presets.ts` records \"2.67:1 … lifted they clear it at 3.30:1\". Nothing\n * computed any of them, and the audit found four of the nine default light chart hues\n * below the 3:1 that WCAG 1.4.11 requires of a graphical object. A comment is not a\n * test. Everything here is derived to a target and then measured, and\n * {@link auditPalette} returns the measurements so a caller can refuse a palette that\n * does not hold up.\n *\n * WHAT IS DERIVED AND WHAT IS NOT. The UI palette and the CATEGORICAL CHART RAMP solve\n * different problems and are deliberately kept apart. A UI colour needs contrast against\n * one known surface and carries a fixed meaning; a chart colour needs to stay separable\n * from eight unknown siblings, at roughly equal salience, with no implied order.\n * Optimising a set for one makes it worse at the other, which is why `deriveTokenSet`\n * leaves `chart` alone unless you explicitly ask for {@link deriveChartRamp}.\n */\n\n/* ── Inputs ───────────────────────────────────────────────────────────────── */\n\n/** A role whose hue may be pinned by the caller instead of chosen by the deriver. */\nexport type AnchorRole = \"brand\" | \"accent\" | \"danger\" | \"warning\" | \"success\" | \"info\";\n\nexport type PaletteAnchors = { brand: string } & Partial<Record<Exclude<AnchorRole, \"brand\">, string>>;\n\nexport interface DeriveOptions {\n anchors: PaletteAnchors;\n mode: ThemeMode;\n /**\n * How strongly the surfaces carry the brand's hue, 0–1 of the maximum useful tint.\n * 0 gives neutral greys; the shipped default is a visible warmth, because a page that\n * is very slightly the brand's hue reads as considered where a pure grey reads as\n * unstyled. Above ~0.5 the surfaces start competing with the content.\n */\n surfaceTint?: number;\n /** Contrast targets for the three text roles against the WORST surface. */\n textContrast?: { primary?: number; secondary?: number; muted?: number };\n}\n\n/* ── Outputs ──────────────────────────────────────────────────────────────── */\n\n/** The semantic layer, which lives in tokens.css rather than in `TokenSet`. */\nexport interface SemanticTokens {\n danger: string;\n dangerHover: string;\n dangerContrast: string;\n dangerBorder: string;\n /** The error line (invalid field, danger banner, destructive focus ring): as loud as\n * `dangerBorder` was before 0.15.5, so it keeps 3:1 against the surface. */\n dangerBorderStrong: string;\n dangerBg: string;\n warning: string;\n warningBorder: string;\n warningBg: string;\n info: string;\n infoBorder: string;\n infoBg: string;\n success: string;\n successBorder: string;\n successBg: string;\n /** Present only when a `accent` (secondary brand) anchor was supplied. */\n accent?: string;\n accentContrast?: string;\n accentBg?: string;\n}\n\nexport interface ContrastCheck {\n /** e.g. \"textMuted on bgPage\". */\n pair: string;\n ratio: number;\n /** What WCAG asks of this pair. */\n required: number;\n /** Which rule the requirement comes from, for a reader who wants to argue with it. */\n rule: string;\n passes: boolean;\n}\n\nexport interface ContrastReport {\n checks: ContrastCheck[];\n failures: ContrastCheck[];\n passes: boolean;\n}\n\nexport interface DerivedPalette {\n tokens: TokenSet;\n semantic: SemanticTokens;\n /** {@link auditPalette} at both contrast levels: the More-contrast checks carry a\n * \" (More contrast)\" suffix (0.36). */\n audit: ContrastReport;\n /** Compromises the deriver had to make, in plain words. Never silent. */\n warnings: string[];\n}\n\n/* ── The hue homes ────────────────────────────────────────────────────────── */\n\n/**\n * Where each semantic role wants to sit, and how far it may be pushed.\n *\n * A semantic colour is a convention before it is an aesthetic: danger is red because\n * every other interface the user has ever used made it red, and a \"danger\" button in\n * the brand's teal is a worse button however well it matches. So each role has a home\n * hue and a narrow licence to move — enough to get out of the brand's way when the\n * brand happens to live in the same neighbourhood, not enough to stop meaning what it\n * means. If it cannot get far enough, that is a warning, not a silent compromise.\n */\nconst HUE_HOME: Record<Exclude<AnchorRole, \"brand\" | \"accent\">, { hue: number; slack: number }> = {\n danger: { hue: 27, slack: 14 },\n warning: { hue: 75, slack: 16 },\n success: { hue: 150, slack: 20 },\n info: { hue: 240, slack: 22 },\n};\n\n/** Circular distance between two hue angles, 0–180. */\nfunction hueGap(a: number, b: number): number {\n const d = Math.abs(((a - b) % 360) + 360) % 360;\n return d > 180 ? 360 - d : d;\n}\n\n/**\n * Nudge `home` within `slack` to maximise the distance from every taken hue.\n *\n * Sampled rather than solved: the objective is a min-of-distances over a handful of\n * points on a short arc, which is piecewise-linear with kinks wherever the nearest\n * neighbour changes. Gradient methods stall on those kinks; 2° steps over a ±22° arc is\n * 23 evaluations of some trigonometry and cannot stall.\n */\nfunction placeHue(home: number, slack: number, taken: number[]): number {\n let best = home;\n let bestGap = Math.min(...taken.map((t) => hueGap(home, t)), 360);\n for (let d = -slack; d <= slack; d += 2) {\n const h = (home + d + 360) % 360;\n const gap = Math.min(...taken.map((t) => hueGap(h, t)), 360);\n // Ties go to the hue nearest home: a role should move only as far as it must.\n if (gap > bestGap + 1e-9) {\n best = h;\n bestGap = gap;\n }\n }\n return best;\n}\n\n/* ── Derivation ───────────────────────────────────────────────────────────── */\n\nconst SURFACE_L = {\n // Light: the PAGE is slightly darker than the cards on it, so a card reads as raised\n // without needing a shadow to say so. Matches the shipped presets' relationship.\n //\n // The light WELL is the page itself (0.33, docs/colour-roles-harmonization.md §5.3,\n // k26). Between the card and the page it sat 1.02–1.05:1 from the card it is inset\n // in, which is no well at all; at the page's lightness it stands out from the card\n // exactly as far as the card does from the page, and nothing re-solves, because the\n // page is already the surface every text role is solved against. Dark keeps its\n // well a step lighter than the card (1.11–1.13:1).\n light: { page: 0.912, surface: 0.945, surface2: 0.912 },\n dark: { page: 0.158, surface: 0.206, surface2: 0.249 },\n} as const;\n\n/**\n * What a hairline has to clear against the surface it divides.\n *\n * WCAG has nothing to say here — a decorative border is not a graphical object that\n * conveys information — so this is a house rule, and it is deliberately low. A border\n * that clears 3:1 is a RULE, not a hairline: it draws the eye to the box instead of to\n * what is in it. 1.5:1 is the point at which the edge is reliably findable without\n * becoming part of the composition.\n */\nconst BORDER_CONTRAST = 1.5;\n\n/** The most tint a surface can carry before it stops reading as a neutral ground. */\nconst MAX_SURFACE_CHROMA = 0.034;\n\n/**\n * The brand chroma from which the surfaces and the greys carry the brand's hue in full;\n * below it they carry it in proportion, down to none for a grey (round 0.34 BUG-8). A\n * grey has no hue — OKLCH reports 0, which is pink — and at full tint #808080 painted\n * every surface #eddde1.\n */\nconst FULL_HUE_CHROMA = 0.06;\n\n/** How much of the brand's hue the neutrals may carry: 0 for a grey, 1 from {@link FULL_HUE_CHROMA}. */\nfunction hueWeight(brand: Oklch): number {\n return Math.min(1, brand.c / FULL_HUE_CHROMA);\n}\n\nfunction surfaceSet(hue: number, mode: ThemeMode, tint: number, weight: number) {\n const c = MAX_SURFACE_CHROMA * Math.max(0, Math.min(1, tint)) * weight;\n const L = SURFACE_L[mode];\n const bgPage = oklchToHex({ l: L.page, c, h: hue });\n const bgSurface = oklchToHex({ l: L.surface, c, h: hue });\n const bgSurface2 = oklchToHex({ l: L.surface2, c, h: hue });\n // Solved, not guessed: a fixed lightness that looks right against a pale warm ground\n // disappears against a deep cold one, and both are reachable from the same `hue`\n // input. The border carries a little more chroma than the surfaces because at these\n // lightnesses a perfectly neutral hairline on a tinted ground reads as a wrong grey.\n const borderChroma = c * 1.6;\n // Solved against the surface the hairline is HARDEST to see on, not against one of\n // the three. Solving against `bgSurface` alone left it at 1.36:1 on `bgPage`, so the\n // target and the audit disagreed about the same border.\n const hardest = [bgPage, bgSurface, bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n const borderL = solveLightness(\n BORDER_CONTRAST,\n parseHex(hardest)!,\n hue,\n borderChroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n return {\n bgPage,\n bgSurface,\n bgSurface2,\n border: oklchToHex({ l: borderL, c: borderChroma, h: hue }),\n };\n}\n\n/** Solve a colour at this hue that clears `target` against `against`, keeping chroma. */\nfunction solveAgainst(hue: number, chroma: number, target: number, against: string, mode: ThemeMode): string {\n const bg = parseHex(against)!;\n const l = solveLightness(target, bg, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n return oklchToHex({ l, c: chroma, h: hue });\n}\n\n/** Whichever of near-white / near-black reads better ON `fill`. */\nfunction contrastOn(fill: string): string {\n const light = \"#ffffff\";\n const dark = \"#12100e\";\n return contrast(fill, light) >= contrast(fill, dark) ? light : dark;\n}\n\n/** A soft tint of `hue` sitting on the surface — a badge fill, not a button fill. */\nfunction tintOn(hue: number, chroma: number, surface: string, mode: ThemeMode): string {\n const s = hexToOklch(surface)!;\n // Toward the colour, but only far enough to be seen: these back TEXT of the same hue,\n // and a strong tint leaves the text nowhere to go.\n const l = mode === \"light\" ? s.l - 0.055 : s.l + 0.055;\n return oklchToHex({ l, c: Math.min(chroma * 0.45, 0.06), h: hue });\n}\n\nexport function derivePalette({\n anchors,\n mode,\n surfaceTint = 0.55,\n textContrast,\n}: DeriveOptions): DerivedPalette {\n const warnings: string[] = [];\n const brand = hexToOklch(anchors.brand);\n if (!brand) {\n throw new Error(\n `derivePalette: brand \"${anchors.brand}\" is not a #rgb or #rrggbb colour. ` +\n `Anchors must be hex — a named colour or an rgba() string cannot be converted.`,\n );\n }\n\n const targets = { primary: 10, secondary: 7, muted: 4.6, ...textContrast };\n\n // ── Surfaces, from the brand's hue.\n const weight = hueWeight(brand);\n const surfaces = surfaceSet(brand.h, mode, surfaceTint, weight);\n // Every text role is solved against the WORST of the three, so a token is legible\n // wherever it lands. Solving against `bgSurface` alone is the mistake that makes a\n // muted label fail on the page background it also sits on.\n const worstSurface = [surfaces.bgPage, surfaces.bgSurface, surfaces.bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Text. A trace of the brand hue keeps the greys from reading cold on a warm page.\n const textChroma = 0.014 * weight;\n const textPrimary = solveAgainst(brand.h, textChroma, targets.primary, worstSurface, mode);\n const textSecondary = solveAgainst(brand.h, textChroma, targets.secondary, worstSurface, mode);\n const textMuted = solveAgainst(brand.h, textChroma, targets.muted, worstSurface, mode);\n\n // The darkest fill text sits on (the lightest, in dark): the worst surface, or a\n // hovered row on the card (`--bg-hover`), which in light is a shade darker than the\n // page. The colours that are solved exactly to 4.5:1 — money, the semantic text — are\n // solved against this, so they hold on a hovered row too (0.33, §12.10). The text\n // roles above keep their margin (4.6:1 and up) and need no second solve.\n const hover = hoverFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const worstText = [worstSurface, hover].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Brand. Keep the hue the caller asked for; move only the lightness, and only as\n // far as 3:1 against the worst surface — WCAG 1.4.11, since a brand-filled control is\n // a graphical object whose boundary has to be perceivable.\n //\n // In light the worst surface includes More contrast's well (0.36, colour-roles §13.4):\n // 10 % ink into the card, darker than the page. The step is applied, not derived, but\n // the brand is not stepped, so both brand solves measure there too and a derived\n // palette holds at both levels.\n const moreWell = steppedWellFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const brandGround = moreWell\n ? [worstSurface, moreWell].reduce((a, b) => (contrast(a, \"#000000\") < contrast(b, \"#000000\") ? a : b))\n : worstSurface;\n const brandChroma = Math.max(brand.c, 0.06);\n const brandRatio = contrast(anchors.brand, brandGround);\n // NORMALISED, never the caller's raw string. `parseHex` accepts \"4f46e5\" and \"#abc\",\n // and passing either through unchanged put a value in the TokenSet that is not a CSS\n // colour — it then fails silently at paint time, three layers from here.\n let brandHex =\n brandRatio >= 3\n ? toHex(parseHex(anchors.brand)!)\n : solveAgainst(brand.h, brandChroma, 3, brandGround, mode);\n if (brandRatio < 3) {\n warnings.push(\n `brand ${anchors.brand} sits at ${brandRatio.toFixed(2)}:1 against the ${mode} surfaces, ` +\n `below the 3:1 WCAG 1.4.11 asks of a control boundary. Lightness was adjusted to ` +\n `${brandHex}; hue and chroma are unchanged.`,\n );\n }\n // `--brand-muted` is the brand AS TEXT — a soft brand chip's label, an outline chip, a\n // current link — and tokens.css derives it: 62 % brand into the ink. A brand solved\n // to 3:1 left it at 4.43–4.51:1 in three dark presets (0.33, §5.5), so it gets the\n // text floor here: the brand moves away from the surfaces, a step at a time, until its\n // muted form clears 4.5:1 on the worst fill and on its own soft chip, at rest\n // (`--brand-bg`) and hovered (`--brand-bg-hover`, the harder of the two: §12.11).\n const brandMutedWorst = (hex: string) => {\n const soft = brandSoft({ brand: hex, textPrimary, bgSurface: surfaces.bgSurface });\n return Math.min(\n contrast(soft.brandMuted, worstText),\n contrast(soft.brandMuted, soft.brandBg),\n contrast(soft.brandMuted, soft.brandBgHover),\n // …and on More contrast's light well, where a link button reads it (§13.3).\n moreWell ? contrast(soft.brandMuted, moreWell) : Infinity,\n );\n };\n for (let i = 0; i < 40 && brandMutedWorst(brandHex) < 4.5; i++) {\n const lch = hexToOklch(brandHex)!;\n brandHex = oklchToHex({ ...lch, l: mode === \"light\" ? lch.l - 0.005 : lch.l + 0.005 });\n }\n if (brandMutedWorst(brandHex) < 4.5) {\n warnings.push(\n `the brand as text (--brand-muted) reaches only ${brandMutedWorst(brandHex).toFixed(2)}:1 ` +\n `against the ${mode} surfaces (needs 4.5:1).`,\n );\n }\n const brandLch = hexToOklch(brandHex)!;\n const brandContrast = contrastOn(brandHex);\n const brandHover = oklchToHex({\n ...brandLch,\n // Hover moves AWAY from the colour of the text on it (0.33, §5.5): darker under\n // white, lighter under a dark ink. It used to move away from the page, which in dark\n // lightened a fill that carries WHITE text, toward its own label: 4.07:1.\n l: brandContrast === \"#ffffff\" ? brandLch.l - 0.06 : brandLch.l + 0.06,\n });\n const onBrand = contrast(brandHex, brandContrast);\n if (onBrand < 4.5) {\n warnings.push(\n `text on the brand fill reaches only ${onBrand.toFixed(2)}:1 (needs 4.5:1). ` +\n `A mid-lightness, high-chroma brand cannot carry legible text at any ink; ` +\n `use it as an accent and keep primary buttons on a darker or lighter variant.`,\n );\n }\n\n // ── Semantic roles. Anchors are honoured exactly; the rest are placed away from the\n // brand and from each other, within each role's licence to move.\n const taken: number[] = [brandLch.h];\n const accentLch = anchors.accent ? hexToOklch(anchors.accent) : null;\n if (anchors.accent && !accentLch) {\n warnings.push(`accent \"${anchors.accent}\" is not a hex colour and was ignored.`);\n }\n if (accentLch) taken.push(accentLch.h);\n\n const semanticHue = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n const semanticChroma = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n for (const role of [\"danger\", \"warning\", \"success\", \"info\"] as const) {\n const pinned = anchors[role] ? hexToOklch(anchors[role]!) : null;\n if (anchors[role] && !pinned) {\n warnings.push(`${role} \"${anchors[role]}\" is not a hex colour and was ignored.`);\n }\n const home = HUE_HOME[role];\n const hue = pinned ? pinned.h : placeHue(home.hue, home.slack, taken);\n if (!pinned) {\n const gap = Math.min(...taken.map((t) => hueGap(hue, t)));\n if (gap < 20) {\n warnings.push(\n `${role} could only reach ${gap.toFixed(0)}° from the nearest pinned hue, which is ` +\n `too close to tell apart at a glance. Pin ${role} explicitly, or move the brand.`,\n );\n }\n }\n semanticHue[role] = hue;\n semanticChroma[role] = pinned ? Math.max(pinned.c, 0.08) : 0.13;\n taken.push(hue);\n }\n\n /**\n * A semantic colour has two jobs and therefore two backgrounds: plain text on the\n * page, and the label inside its own tinted badge. The badge is the harder of the\n * two — it is a step toward the colour — so solving only against the surface produced\n * a badge at 4.1:1 while the loose text passed, which is the failure mode that is\n * hardest to notice because nine tenths of the uses look fine.\n */\n const sem = (role: Exclude<AnchorRole, \"brand\" | \"accent\">) => {\n const hue = semanticHue[role];\n const chroma = semanticChroma[role];\n const bg = tintOn(hue, chroma, surfaces.bgSurface, mode);\n const onSurface = solveLightness(\n 4.5,\n parseHex(worstText)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const onTint = solveLightness(\n 4.5,\n parseHex(bg)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const l = mode === \"light\" ? Math.min(onSurface, onTint) : Math.max(onSurface, onTint);\n return oklchToHex({ l, c: chroma, h: hue });\n };\n\n const danger = sem(\"danger\");\n const dangerLch = hexToOklch(danger)!;\n const semantic: SemanticTokens = {\n danger,\n dangerHover: oklchToHex({\n ...dangerLch,\n l: mode === \"light\" ? dangerLch.l - 0.06 : dangerLch.l + 0.06,\n }),\n dangerContrast: contrastOn(danger),\n // The tone border follows its siblings' lightness in dark mode (warning 0.44, info\n // and success 0.45) — a soft frame; the strong line keeps the old, louder recipe.\n dangerBorder: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : 0.45,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBorderStrong: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : dangerLch.l - 0.22,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBg: tintOn(semanticHue.danger, semanticChroma.danger, surfaces.bgSurface, mode),\n warning: sem(\"warning\"),\n warningBorder: oklchToHex({\n l: mode === \"light\" ? 0.82 : 0.44,\n c: semanticChroma.warning,\n h: semanticHue.warning,\n }),\n warningBg: tintOn(semanticHue.warning, semanticChroma.warning, surfaces.bgSurface, mode),\n info: sem(\"info\"),\n infoBorder: oklchToHex({\n l: mode === \"light\" ? 0.8 : 0.45,\n c: semanticChroma.info,\n h: semanticHue.info,\n }),\n infoBg: tintOn(semanticHue.info, semanticChroma.info, surfaces.bgSurface, mode),\n success: sem(\"success\"),\n successBorder: oklchToHex({\n l: mode === \"light\" ? 0.81 : 0.45,\n c: semanticChroma.success,\n h: semanticHue.success,\n }),\n successBg: tintOn(semanticHue.success, semanticChroma.success, surfaces.bgSurface, mode),\n };\n\n if (accentLch) {\n const accent = solveAgainst(accentLch.h, Math.max(accentLch.c, 0.06), 3, worstSurface, mode);\n semantic.accent = accent;\n semantic.accentContrast = contrastOn(accent);\n semantic.accentBg = tintOn(accentLch.h, Math.max(accentLch.c, 0.06), surfaces.bgSurface, mode);\n }\n\n // ── Money. A THIRD system again: these are data colours with fixed meanings, and the\n // one rule that outranks everything is that income and expense must never be the\n // red/green pair — which is why the shipped presets use teal/amber/violet. Derived\n // here at fixed hues rather than from the brand, for the same reason `--danger` is:\n // a consumer who rebrands does not thereby change what \"money out\" looks like.\n const money = (hue: number, target: number) => solveAgainst(hue, 0.12, target, worstText, mode);\n const moneyIncome = money(175, 4.5);\n const moneyExpense = money(70, 4.5);\n const moneyNet = money(300, 4.5);\n // \"No money has moved\": a quiet grey at a fixed lightness, but printed as TEXT (the\n // numpad's sign, a future row's figure), so it gets the text floor too (0.33). The\n // fixed lightness left it at 4.24:1 on four light pages.\n const neutralChroma = 0.012 * weight;\n const neutralFloor = solveLightness(4.5, parseHex(worstText)!, brand.h, neutralChroma, mode === \"light\" ? \"darker\" : \"lighter\");\n const moneyNeutral = oklchToHex({\n l: mode === \"light\" ? Math.min(0.52, neutralFloor) : Math.max(0.72, neutralFloor),\n c: neutralChroma,\n h: brand.h,\n });\n\n const tokens: TokenSet = {\n ...surfaces,\n textPrimary,\n textSecondary,\n textMuted,\n brand: brandHex,\n brandHover,\n brandContrast,\n moneyIncome,\n moneyExpense,\n moneyNet,\n moneyNeutral,\n // Left alone. See the note at the top of this file about why the categorical ramp is\n // not derived from the brand unless the caller asks.\n //\n // ⚠️ EMPTY, not absent: a caller who hands this straight to `applyTokenSet` keeps\n // whatever `--chart-1…9` were already on the element. That is deliberate — the ramp\n // is a separate decision and clearing it would leave charts unpainted — but it means\n // a derived palette applied over another preset is a MIX until you also supply a\n // ramp. `deriveChartRamp` is how you supply one.\n chart: [],\n heat: deriveHeat(moneyIncome, moneyExpense, surfaces, mode),\n };\n\n // Audited at both contrast levels (0.36, colour-roles §13.5): More contrast steps the\n // text, the border and, in light, the well and money of this set. The derived semantic\n // colours are audited at Standard only: they are solved for the standard grounds, and\n // only tokens.css's shipped literals step for the darker well.\n const standard = auditPalette(tokens, semantic);\n const more = auditPalette(tokens, undefined, { level: \"more\" });\n const checks = [...standard.checks, ...more.checks];\n const failures = checks.filter((c) => !c.passes);\n return { tokens, semantic, audit: { checks, failures, passes: failures.length === 0 }, warnings };\n}\n\n/**\n * Heatmap stops, reusing the money pair.\n *\n * `under` is the good direction and `over` the bad one, at the SAME hues as\n * `moneyIncome`/`moneyExpense` — so a heatmap cell and the figure printed beside it\n * agree about which way is which, rather than each inventing its own convention.\n */\nfunction deriveHeat(\n income: string,\n expense: string,\n surfaces: { bgSurface2: string },\n mode: ThemeMode,\n): HeatStops {\n const exp = hexToOklch(expense)!;\n return {\n neutral: surfaces.bgSurface2,\n under: income,\n over: expense,\n seqLow: oklchToHex({ l: mode === \"light\" ? 0.93 : 0.26, c: 0.05, h: exp.h }),\n seqHigh: expense,\n empty: mode === \"light\" ? \"rgba(120,110,95,0.14)\" : \"rgba(160,170,190,0.10)\",\n };\n}\n\n/* ── Audit ────────────────────────────────────────────────────────────────── */\n\n/**\n * Measure every pair that has a requirement, and say which ones fail.\n *\n * This is the part the shipped presets were missing. `derivePalette` runs it on the way\n * out, and the preset test runs it over everything the package ships, so a palette that\n * does not hold up cannot be merged with a comment claiming that it does.\n *\n * **`level: \"more\"`** (0.36, docs/colour-roles-harmonization.md §13.5) measures the set as\n * More contrast paints it: the stepped secondary, muted and border, and in a light set the\n * stepped well (as `bgSurface2`) and money — the same pairs, named with a \" (More\n * contrast)\" suffix. Two things change with the level: the border is a field's boundary\n * there, held to WCAG 1.4.11's 3:1 rather than the hairline's 1.1, and a light set's well\n * must stand {@link WELL_STEP_MIN}:1 from the card. Pass `semantic` with tokens.css's More\n * literals for a light set (the status colours step there); the status text is then\n * measured on the stepped well too.\n */\nexport function auditPalette(\n set: TokenSet,\n semantic?: SemanticTokens,\n options: { level?: ContrastLevel } = {},\n): ContrastReport {\n const more = options.level === \"more\";\n const step = more ? contrastStep(set) : null;\n // The set as it paints at this level: what `applyTokenSet` writes for it.\n const t: TokenSet = step\n ? {\n ...set,\n textSecondary: step.textSecondary,\n textMuted: step.textMuted,\n border: step.border,\n ...(step.well && {\n bgSurface2: step.well.bgSurface2,\n moneyIncome: step.well.moneyIncome,\n moneyExpense: step.well.moneyExpense,\n moneyNet: step.well.moneyNet,\n moneyNeutral: step.well.moneyNeutral,\n }),\n }\n : set;\n const suffix = more ? \" (More contrast)\" : \"\";\n const checks: ContrastCheck[] = [];\n const surfaces: Array<[string, string]> = [\n [\"bgPage\", t.bgPage],\n [\"bgSurface\", t.bgSurface],\n [\"bgSurface2\", t.bgSurface2],\n ];\n // A hovered row on the card (`--bg-hover`) carries the same text as the card, and in\n // light it is the darkest fill that text sits on (0.33, §12.10). Text is measured on\n // it; the brand fill and the hairline, which are not text, are not.\n const hover = hoverFill(t);\n const textGrounds: Array<[string, string]> = [...surfaces, [\"bgHover\", hover]];\n // `--brand-muted`, `--brand-bg` and `--brand-bg-hover`, mixed as tokens.css mixes them.\n const { brandMuted, brandBg, brandBgHover } = brandSoft(t);\n\n // The 0.05 of slack is for a pair with a color-mix on one side, and only for that: the\n // browser mixes in float and paints the result, where this mixes and rounds to hex, so\n // the two can differ by a hair. Hex against hex is what the page paints, measured\n // exactly — the slack used to cover those too, and passed the Contrast preset's dark\n // brand fill at 2.998:1 (round 0.34 BUG-8).\n const MIXED = /\\b(bgHover|brandMuted|brandBg|brandBgHover)\\b/;\n const add = (pair: string, fg: string, bg: string, required: number, rule: string) => {\n const ratio = contrast(fg, bg);\n const slack = MIXED.test(pair) ? 0.05 : 0;\n checks.push({ pair: pair + suffix, ratio, required, rule, passes: ratio >= required - slack });\n };\n\n for (const [name, bg] of surfaces) {\n add(`brand on ${name}`, t.brand, bg, 3, \"WCAG 1.4.11 graphical object\");\n if (more) add(`border on ${name}`, t.border, bg, 3, \"WCAG 1.4.11 — under More contrast a border bounds a field\");\n else add(`border on ${name}`, t.border, bg, 1.1, \"house rule: a hairline must be findable\");\n }\n // The stepped light well, a hex `applyTokenSet` writes (§13.3, decision 2).\n if (step?.well) {\n add(\"bgSurface2 on bgSurface\", t.bgSurface2, t.bgSurface, WELL_STEP_MIN, \"house rule: the well stands two hover steps from the card\");\n }\n for (const [name, bg] of textGrounds) {\n add(`textPrimary on ${name}`, t.textPrimary, bg, 7, \"WCAG 1.4.6 AAA body text\");\n add(`textSecondary on ${name}`, t.textSecondary, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`textMuted on ${name}`, t.textMuted, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`brandMuted on ${name}`, brandMuted, bg, 4.5, \"WCAG 1.4.3 — the brand as text\");\n for (const [key, hex] of [\n [\"moneyIncome\", t.moneyIncome],\n [\"moneyExpense\", t.moneyExpense],\n [\"moneyNet\", t.moneyNet],\n // Not a figure's colour but still printed as one (the numpad's sign, a future\n // row's amount) — measured since 0.33, when it was found at 4.24:1.\n [\"moneyNeutral\", t.moneyNeutral],\n ] as const) {\n add(`${key} on ${name}`, hex, bg, 4.5, \"WCAG 1.4.3 — these are rendered as TEXT\");\n }\n }\n\n add(\"brandContrast on brand\", t.brandContrast, t.brand, 4.5, \"WCAG 1.4.3 AA body text\");\n // A hovered brand button carries the same label (0.33): the derived dark presets\n // lightened the hover toward their white label and left it at 4.07:1.\n add(\"brandContrast on brandHover\", t.brandContrast, t.brandHover, 4.5, \"WCAG 1.4.3 AA body text\");\n add(\"brandMuted on brandBg\", brandMuted, brandBg, 4.5, \"WCAG 1.4.3 — a soft brand chip's label\");\n // The same label on the chip hovered (§12.11): a current link, a selected day. At 70 %\n // brand the muted text read 4.08–4.42:1 here (Default and Moss light; Ink, Moss, Plum\n // and Contrast dark).\n add(\"brandMuted on brandBgHover\", brandMuted, brandBgHover, 4.5, \"WCAG 1.4.3 — a hovered soft brand chip's label\");\n\n if (semantic) {\n for (const [name, fg] of [\n [\"danger\", semantic.danger],\n [\"warning\", semantic.warning],\n [\"info\", semantic.info],\n [\"success\", semantic.success],\n ] as const) {\n add(`${name} on bgSurface`, fg, t.bgSurface, 4.5, \"WCAG 1.4.3 — rendered as text\");\n add(`${name} on bgHover`, fg, hover, 4.5, \"WCAG 1.4.3 — rendered as text, on a hovered row\");\n // The darker light well the More literals were solved for (§13.3).\n if (step?.well) add(`${name} on bgSurface2`, fg, t.bgSurface2, 4.5, \"WCAG 1.4.3 — rendered as text, on the well\");\n }\n add(\"danger on dangerBg\", semantic.danger, semantic.dangerBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"warning on warningBg\", semantic.warning, semantic.warningBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"info on infoBg\", semantic.info, semantic.infoBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"success on successBg\", semantic.success, semantic.successBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\n \"dangerContrast on danger\",\n semantic.dangerContrast,\n semantic.danger,\n 4.5,\n \"WCAG 1.4.3 AA body text\",\n );\n }\n\n const failures = checks.filter((c) => !c.passes);\n return { checks, failures, passes: failures.length === 0 };\n}\n\n/* ── Categorical chart ramp ───────────────────────────────────────────────── */\n\nexport interface ChartRampReport {\n colors: string[];\n /** Series pairs that are too close under normal vision or any simulated CVD. */\n collisions: Array<{ a: number; b: number; under: \"normal\" | CvdType; distance: number }>;\n /** Series that do not clear 3:1 against a surface they may be drawn on. */\n lowContrast: Array<{ index: number; surface: string; ratio: number }>;\n /** The worst pairwise separation, across normal vision and all three dichromacies. */\n minSeparation: number;\n /** The worst contrast any series reaches against any surface it was measured on. */\n minContrast: number;\n passes: boolean;\n}\n\n/**\n * The floor for pairwise separation in OKLab, across normal vision and each dichromacy.\n *\n * CALIBRATED, not chosen. Paul Tol's \"Muted\" set — which this package ships and which is\n * a well-regarded CVD-safe palette — bottoms out at 0.059 in its light variant and 0.032\n * in the lightened dark one. A threshold above 0.059 would fail a palette that is known\n * to work, which is worse than having no check at all: an audit that cries wolf gets\n * switched off. 0.05 sits just under the known-good case.\n */\nconst MIN_SEPARATION = 0.05;\n\n/**\n * **The categorical trade-off, measured.** At a SINGLE lightness, the most series that\n * can satisfy both the 3:1 fill contrast of WCAG 1.4.11 and {@link MIN_SEPARATION} under\n * dichromacy is FOUR. Searched exhaustively over starting hue and lightness:\n *\n * n=4 best separation 0.065 — both satisfiable\n * n=5 best separation 0.041 — not satisfiable\n * n=9 best separation 0.015 — not satisfiable\n *\n * The reason is structural: dichromacy collapses the red-green axis, so hue alone stops\n * distinguishing colours once you need more than a handful, and the remaining channel is\n * LIGHTNESS — the very thing a uniform-contrast ramp holds constant. Paul Tol's set\n * varies lightness deliberately and pays for it in contrast; that is not an oversight in\n * their palette, it is the only currency left.\n *\n * So above four series this deriver varies lightness too, and reports what it gave up\n * rather than pretending both constraints were met.\n *\n * NOTE ON WHAT THIS BOUND IS. It describes the PROBLEM, not a guarantee about\n * {@link deriveChartRamp}. That function fixes lightness and starts the hue wheel at the\n * brand's own hue rather than searching for the best start, so it reaches the bound only\n * where the brand happens to sit well: sweeping 72 brand hues against the default light\n * surfaces, 7 of 72 produced a passing 4-series ramp (12 of 72 on dark), and none passed\n * at 5 or 9. Read the report it returns; do not assume a pass.\n */\nconst SINGLE_LIGHTNESS_MAX_SERIES = 4;\n\n/**\n * A categorical ramp of `count` hues, evenly spaced and equal in perceived lightness,\n * then MEASURED for separability — including under each dichromacy.\n *\n * Offered but not used by default, and the distinction matters. Evenly spaced hues at\n * one lightness are a reasonable generic answer; Paul Tol's \"Muted\" set, which this\n * package ships, is a better specific one, because it was optimised against real\n * confusion lines rather than derived from a formula. So this exists for a consumer who\n * wants their charts to follow their brand and is willing to read the report — not as\n * a silent upgrade to the default.\n */\nexport function deriveChartRamp(\n brandHex: string,\n mode: ThemeMode,\n surfaces: string[],\n count = 9,\n): ChartRampReport {\n const brand = hexToOklch(brandHex) ?? { l: 0.6, c: 0.12, h: 264 };\n const base = mode === \"light\" ? 0.58 : 0.74;\n const c = Math.max(0.09, Math.min(brand.c, 0.15));\n // Up to four series, one lightness: a scale that varies lightness implies rank, and a\n // categorical one must not. Beyond four, lightness is the only channel left that\n // survives dichromacy — see SINGLE_LIGHTNESS_MAX_SERIES — so it alternates in a\n // three-step cycle, which keeps ADJACENT series (the ones a legend puts side by side)\n // at different lightnesses as well as different hues.\n const vary = count > SINGLE_LIGHTNESS_MAX_SERIES;\n const offsets = [0, mode === \"light\" ? -0.1 : 0.1, mode === \"light\" ? 0.08 : -0.08];\n const colors = Array.from({ length: count }, (_, i) =>\n oklchToHex({\n l: vary ? base + offsets[i % offsets.length] : base,\n c,\n h: (brand.h + (360 / count) * i) % 360,\n }),\n );\n\n return measureRamp(colors, surfaces);\n}\n\n/** Audit a ramp somebody else chose — the shipped Paul Tol set, say. */\nexport function auditChartRamp(colors: string[], surfaces: string[]): ChartRampReport {\n return measureRamp(colors, surfaces);\n}\n\nfunction measureRamp(colors: string[], surfaces: string[]): ChartRampReport {\n const collisions: ChartRampReport[\"collisions\"] = [];\n const rgbs = colors.map((hex) => parseHex(hex)).filter((v): v is NonNullable<typeof v> => !!v);\n let minSeparation = Infinity;\n for (let i = 0; i < rgbs.length; i++) {\n for (let j = i + 1; j < rgbs.length; j++) {\n const normal = deltaE(rgbs[i], rgbs[j]);\n minSeparation = Math.min(minSeparation, normal);\n if (normal < MIN_SEPARATION) {\n collisions.push({ a: i, b: j, under: \"normal\", distance: normal });\n }\n for (const type of [\"protanopia\", \"deuteranopia\", \"tritanopia\"] as const) {\n const d = deltaE(simulateCvd(rgbs[i], type), simulateCvd(rgbs[j], type));\n minSeparation = Math.min(minSeparation, d);\n if (d < MIN_SEPARATION) collisions.push({ a: i, b: j, under: type, distance: d });\n }\n }\n }\n\n const lowContrast: ChartRampReport[\"lowContrast\"] = [];\n let minContrast = Infinity;\n colors.forEach((hex, index) => {\n for (const surface of surfaces) {\n const ratio = contrast(hex, surface);\n minContrast = Math.min(minContrast, ratio);\n // WCAG 1.4.11: a graphical object carrying meaning needs 3:1 against what is\n // adjacent to it. A bar the same value as the card behind it has no boundary.\n if (ratio < 3) lowContrast.push({ index, surface, ratio });\n }\n });\n\n return {\n colors,\n collisions,\n lowContrast,\n minSeparation: Number.isFinite(minSeparation) ? minSeparation : 0,\n minContrast: Number.isFinite(minContrast) ? minContrast : 0,\n passes: collisions.length === 0 && lowContrast.length === 0,\n };\n}\n\n/** Convenience: the OKLCH of a hex, for a caller inspecting an anchor. */\nexport function describe(hex: string): Oklch | null {\n const rgb = parseHex(hex);\n return rgb ? rgbToOklch(rgb) : null;\n}\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,WAAW,cAAc,WAAW,iBAAiB,qBAAqB;AA8GnF,MAAM,WAA4F;AAAA,EAChG,QAAQ,EAAE,KAAK,IAAI,OAAO,GAAG;AAAA,EAC7B,SAAS,EAAE,KAAK,IAAI,OAAO,GAAG;AAAA,EAC9B,SAAS,EAAE,KAAK,KAAK,OAAO,GAAG;AAAA,EAC/B,MAAM,EAAE,KAAK,KAAK,OAAO,GAAG;AAC9B;AAGA,SAAS,OAAO,GAAW,GAAmB;AAC5C,QAAM,IAAI,KAAK,KAAM,IAAI,KAAK,MAAO,GAAG,IAAI;AAC5C,SAAO,IAAI,MAAM,MAAM,IAAI;A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AAG,KAAK,CAAC,CAAC;AACtC,sBAAgB,KAAK,IAAI,eAAe,MAAM;AAC9C,UAAI,SAAS,gBAAgB;AAC3B,mBAAW,KAAK,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,UAAU,UAAU,OAAO,CAAC;AAAA,MACnE;AACA,iBAAW,QAAQ,CAAC,cAAc,gBAAgB,YAAY,GAAY;AACxE,cAAM,IAAI,OAAO,YAAY,KAAK,CAAC,GAAG,IAAI,GAAG,YAAY,KAAK,CAAC,GAAG,IAAI,CAAC;AACvE,wBAAgB,KAAK,IAAI,eAAe,CAAC;AACzC,YAAI,IAAI,eAAgB,YAAW,KAAK,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,MAAM,UAAU,EAAE,CAAC;AAAA,MAClF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,cAA8C,CAAC;AACrD,MAAI,cAAc;AAClB,SAAO,QAAQ,CAAC,KAAK,UAAU;AAC7B,eAAW,WAAW,UAAU;AAC9B,YAAM,QAAQ,SAAS,KAAK,OAAO;AACnC,oBAAc,KAAK,IAAI,aAAa,KAAK;AAGzC,UAAI,QAAQ,EAAG,aAAY,KAAK,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,IAC3D;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe,OAAO,SAAS,aAAa,IAAI,gBAAgB;AAAA,IAChE,aAAa,OAAO,SAAS,WAAW,IAAI,cAAc;AAAA,IAC1D,QAAQ,WAAW,WAAW,KAAK,YAAY,WAAW;AAAA,EAC5D;AACF;AAGO,SAAS,SAAS,KAA2B;AAClD,QAAM,MAAM,SAAS,GAAG;AACxB,SAAO,MAAM,WAAW,GAAG,IAAI;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/palette-derive.ts"],"sourcesContent":["import type { ThemeMode } from \"./theme-store\";\nimport type { TokenSet } from \"./palette-presets\";\nimport type { HeatStops } from \"./chart-palette\";\nimport {\n contrast,\n deltaE,\n toHex,\n hexToOklch,\n oklchToHex,\n parseHex,\n rgbToOklch,\n simulateCvd,\n solveLightness,\n} from \"./color\";\nimport type { CvdType, Oklch } from \"./color\";\nimport type { ContrastLevel } from \"./contrast\";\nimport { brandSoft, contrastStep, hoverFill, steppedWellFill, WELL_STEP_MIN } from \"./contrast-tokens\";\n\n/**\n * Build a whole palette from one brand colour, plus any number of colours pinned by\n * hand, with every contrast ratio SOLVED rather than chosen and then hoped for.\n *\n * The presets this package shipped were assembled by eye and annotated with the ratios\n * they were believed to hold — `tokens.css` records \"7.0:1 and 4.8:1\", and\n * `palette-presets.ts` records \"2.67:1 … lifted they clear it at 3.30:1\". Nothing\n * computed any of them, and the audit found four of the nine default light chart hues\n * below the 3:1 that WCAG 1.4.11 requires of a graphical object. A comment is not a\n * test. Everything here is derived to a target and then measured, and\n * {@link auditPalette} returns the measurements so a caller can refuse a palette that\n * does not hold up.\n *\n * WHAT IS DERIVED AND WHAT IS NOT. The UI palette and the CATEGORICAL CHART RAMP solve\n * different problems and are deliberately kept apart. A UI colour needs contrast against\n * one known surface and carries a fixed meaning; a chart colour needs to stay separable\n * from eight unknown siblings, at roughly equal salience, with no implied order.\n * Optimising a set for one makes it worse at the other, which is why `deriveTokenSet`\n * leaves `chart` alone unless you explicitly ask for {@link deriveChartRamp}.\n */\n\n/* ── Inputs ───────────────────────────────────────────────────────────────── */\n\n/** A role whose hue may be pinned by the caller instead of chosen by the deriver. */\nexport type AnchorRole = \"brand\" | \"accent\" | \"danger\" | \"warning\" | \"success\" | \"info\";\n\nexport type PaletteAnchors = { brand: string } & Partial<Record<Exclude<AnchorRole, \"brand\">, string>>;\n\nexport interface DeriveOptions {\n anchors: PaletteAnchors;\n mode: ThemeMode;\n /**\n * How strongly the surfaces carry the brand's hue, 0–1 of the maximum useful tint.\n * 0 gives neutral greys; the shipped default is a visible warmth, because a page that\n * is very slightly the brand's hue reads as considered where a pure grey reads as\n * unstyled. Above ~0.5 the surfaces start competing with the content.\n */\n surfaceTint?: number;\n /** Contrast targets for the three text roles against the WORST surface. */\n textContrast?: { primary?: number; secondary?: number; muted?: number };\n}\n\n/* ── Outputs ──────────────────────────────────────────────────────────────── */\n\n/** The semantic layer, which lives in tokens.css rather than in `TokenSet`. */\nexport interface SemanticTokens {\n danger: string;\n dangerHover: string;\n dangerContrast: string;\n dangerBorder: string;\n /** The error line (invalid field, danger banner, destructive focus ring): as loud as\n * `dangerBorder` was before 0.15.5, so it keeps 3:1 against the surface. */\n dangerBorderStrong: string;\n dangerBg: string;\n warning: string;\n warningBorder: string;\n warningBg: string;\n info: string;\n infoBorder: string;\n infoBg: string;\n success: string;\n successBorder: string;\n successBg: string;\n /** Present only when a `accent` (secondary brand) anchor was supplied. */\n accent?: string;\n accentContrast?: string;\n accentBg?: string;\n}\n\nexport interface ContrastCheck {\n /** e.g. \"textMuted on bgPage\". */\n pair: string;\n ratio: number;\n /** What WCAG asks of this pair. */\n required: number;\n /** Which rule the requirement comes from, for a reader who wants to argue with it. */\n rule: string;\n passes: boolean;\n}\n\nexport interface ContrastReport {\n checks: ContrastCheck[];\n failures: ContrastCheck[];\n passes: boolean;\n}\n\nexport interface DerivedPalette {\n tokens: TokenSet;\n semantic: SemanticTokens;\n /** {@link auditPalette} at both contrast levels: the More-contrast checks carry a\n * \" (More contrast)\" suffix (0.36). */\n audit: ContrastReport;\n /** Compromises the deriver had to make, in plain words. Never silent. */\n warnings: string[];\n}\n\n/* ── The hue homes ────────────────────────────────────────────────────────── */\n\n/**\n * Where each semantic role wants to sit, and how far it may be pushed.\n *\n * A semantic colour is a convention before it is an aesthetic: danger is red because\n * every other interface the user has ever used made it red, and a \"danger\" button in\n * the brand's teal is a worse button however well it matches. So each role has a home\n * hue and a narrow licence to move — enough to get out of the brand's way when the\n * brand happens to live in the same neighbourhood, not enough to stop meaning what it\n * means. If it cannot get far enough, that is a warning, not a silent compromise.\n */\nconst HUE_HOME: Record<Exclude<AnchorRole, \"brand\" | \"accent\">, { hue: number; slack: number }> = {\n danger: { hue: 27, slack: 14 },\n warning: { hue: 75, slack: 16 },\n success: { hue: 150, slack: 20 },\n info: { hue: 240, slack: 22 },\n};\n\n/** Circular distance between two hue angles, 0–180. */\nfunction hueGap(a: number, b: number): number {\n const d = Math.abs(((a - b) % 360) + 360) % 360;\n return d > 180 ? 360 - d : d;\n}\n\n/**\n * Nudge `home` within `slack` to maximise the distance from every taken hue.\n *\n * Sampled rather than solved: the objective is a min-of-distances over a handful of\n * points on a short arc, which is piecewise-linear with kinks wherever the nearest\n * neighbour changes. Gradient methods stall on those kinks; 2° steps over a ±22° arc is\n * 23 evaluations of some trigonometry and cannot stall.\n */\nfunction placeHue(home: number, slack: number, taken: number[]): number {\n let best = home;\n let bestGap = Math.min(...taken.map((t) => hueGap(home, t)), 360);\n for (let d = -slack; d <= slack; d += 2) {\n const h = (home + d + 360) % 360;\n const gap = Math.min(...taken.map((t) => hueGap(h, t)), 360);\n // Ties go to the hue nearest home: a role should move only as far as it must.\n if (gap > bestGap + 1e-9) {\n best = h;\n bestGap = gap;\n }\n }\n return best;\n}\n\n/* ── Derivation ───────────────────────────────────────────────────────────── */\n\nconst SURFACE_L = {\n // Light: the PAGE is slightly darker than the cards on it, so a card reads as raised\n // without needing a shadow to say so. Matches the shipped presets' relationship.\n //\n // The light WELL is the page itself (0.33, docs/colour-roles-harmonization.md §5.3,\n // k26). Between the card and the page it sat 1.02–1.05:1 from the card it is inset\n // in, which is no well at all; at the page's lightness it stands out from the card\n // exactly as far as the card does from the page, and nothing re-solves, because the\n // page is already the surface every text role is solved against. Dark keeps its\n // well a step lighter than the card (1.11–1.13:1).\n light: { page: 0.912, surface: 0.945, surface2: 0.912 },\n dark: { page: 0.158, surface: 0.206, surface2: 0.249 },\n} as const;\n\n/**\n * What a hairline has to clear against the surface it divides.\n *\n * WCAG has nothing to say here — a decorative border is not a graphical object that\n * conveys information — so this is a house rule, and it is deliberately low. A border\n * that clears 3:1 is a RULE, not a hairline: it draws the eye to the box instead of to\n * what is in it. 1.5:1 is the point at which the edge is reliably findable without\n * becoming part of the composition.\n */\nconst BORDER_CONTRAST = 1.5;\n\n/** The most tint a surface can carry before it stops reading as a neutral ground. */\nconst MAX_SURFACE_CHROMA = 0.034;\n\n/**\n * The brand chroma from which the surfaces and the greys carry the brand's hue in full;\n * below it they carry it in proportion, down to none for a grey (round 0.34 BUG-8). A\n * grey has no hue — OKLCH reports 0, which is pink — and at full tint #808080 painted\n * every surface #eddde1.\n */\nconst FULL_HUE_CHROMA = 0.06;\n\n/** How much of the brand's hue the neutrals may carry: 0 for a grey, 1 from {@link FULL_HUE_CHROMA}. */\nfunction hueWeight(brand: Oklch): number {\n return Math.min(1, brand.c / FULL_HUE_CHROMA);\n}\n\nfunction surfaceSet(hue: number, mode: ThemeMode, tint: number, weight: number) {\n const c = MAX_SURFACE_CHROMA * Math.max(0, Math.min(1, tint)) * weight;\n const L = SURFACE_L[mode];\n const bgPage = oklchToHex({ l: L.page, c, h: hue });\n const bgSurface = oklchToHex({ l: L.surface, c, h: hue });\n const bgSurface2 = oklchToHex({ l: L.surface2, c, h: hue });\n // Solved, not guessed: a fixed lightness that looks right against a pale warm ground\n // disappears against a deep cold one, and both are reachable from the same `hue`\n // input. The border carries a little more chroma than the surfaces because at these\n // lightnesses a perfectly neutral hairline on a tinted ground reads as a wrong grey.\n const borderChroma = c * 1.6;\n // Solved against the surface the hairline is HARDEST to see on, not against one of\n // the three. Solving against `bgSurface` alone left it at 1.36:1 on `bgPage`, so the\n // target and the audit disagreed about the same border.\n const hardest = [bgPage, bgSurface, bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") < contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n const borderL = solveLightness(\n BORDER_CONTRAST,\n parseHex(hardest)!,\n hue,\n borderChroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n return {\n bgPage,\n bgSurface,\n bgSurface2,\n border: oklchToHex({ l: borderL, c: borderChroma, h: hue }),\n };\n}\n\n/** Solve a colour at this hue that clears `target` against `against`, keeping chroma. */\nfunction solveAgainst(hue: number, chroma: number, target: number, against: string, mode: ThemeMode): string {\n const bg = parseHex(against)!;\n const l = solveLightness(target, bg, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n return oklchToHex({ l, c: chroma, h: hue });\n}\n\n/** Whichever of near-white / near-black reads better ON `fill`. */\nfunction contrastOn(fill: string): string {\n const light = \"#ffffff\";\n const dark = \"#12100e\";\n return contrast(fill, light) >= contrast(fill, dark) ? light : dark;\n}\n\n/** A soft tint of `hue` sitting on the surface — a badge fill, not a button fill. */\nfunction tintOn(hue: number, chroma: number, surface: string, mode: ThemeMode): string {\n const s = hexToOklch(surface)!;\n // Toward the colour, but only far enough to be seen: these back TEXT of the same hue,\n // and a strong tint leaves the text nowhere to go.\n const l = mode === \"light\" ? s.l - 0.055 : s.l + 0.055;\n return oklchToHex({ l, c: Math.min(chroma * 0.45, 0.06), h: hue });\n}\n\nexport function derivePalette({ anchors, mode, surfaceTint = 0.55, textContrast }: DeriveOptions): DerivedPalette {\n const warnings: string[] = [];\n const brand = hexToOklch(anchors.brand);\n if (!brand) {\n throw new Error(\n `derivePalette: brand \"${anchors.brand}\" is not a #rgb or #rrggbb colour. ` +\n `Anchors must be hex — a named colour or an rgba() string cannot be converted.`,\n );\n }\n\n const targets = { primary: 10, secondary: 7, muted: 4.6, ...textContrast };\n\n // ── Surfaces, from the brand's hue.\n const weight = hueWeight(brand);\n const surfaces = surfaceSet(brand.h, mode, surfaceTint, weight);\n // Every text role is solved against the WORST of the three, so a token is legible\n // wherever it lands. Solving against `bgSurface` alone is the mistake that makes a\n // muted label fail on the page background it also sits on.\n const worstSurface = [surfaces.bgPage, surfaces.bgSurface, surfaces.bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") < contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Text. A trace of the brand hue keeps the greys from reading cold on a warm page.\n const textChroma = 0.014 * weight;\n const textPrimary = solveAgainst(brand.h, textChroma, targets.primary, worstSurface, mode);\n const textSecondary = solveAgainst(brand.h, textChroma, targets.secondary, worstSurface, mode);\n const textMuted = solveAgainst(brand.h, textChroma, targets.muted, worstSurface, mode);\n\n // The darkest fill text sits on (the lightest, in dark): the worst surface, or a\n // hovered row on the card (`--bg-hover`), which in light is a shade darker than the\n // page. The colours that are solved exactly to 4.5:1 — money, the semantic text — are\n // solved against this, so they hold on a hovered row too (0.33, §12.10). The text\n // roles above keep their margin (4.6:1 and up) and need no second solve.\n const hover = hoverFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const worstText = [worstSurface, hover].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") < contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Brand. Keep the hue the caller asked for; move only the lightness, and only as\n // far as 3:1 against the worst surface — WCAG 1.4.11, since a brand-filled control is\n // a graphical object whose boundary has to be perceivable.\n //\n // In light the worst surface includes More contrast's well (0.36, colour-roles §13.4):\n // 10 % ink into the card, darker than the page. The step is applied, not derived, but\n // the brand is not stepped, so both brand solves measure there too and a derived\n // palette holds at both levels.\n const moreWell = steppedWellFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const brandGround = moreWell\n ? [worstSurface, moreWell].reduce((a, b) => (contrast(a, \"#000000\") < contrast(b, \"#000000\") ? a : b))\n : worstSurface;\n const brandChroma = Math.max(brand.c, 0.06);\n const brandRatio = contrast(anchors.brand, brandGround);\n // NORMALISED, never the caller's raw string. `parseHex` accepts \"4f46e5\" and \"#abc\",\n // and passing either through unchanged put a value in the TokenSet that is not a CSS\n // colour — it then fails silently at paint time, three layers from here.\n let brandHex =\n brandRatio >= 3 ? toHex(parseHex(anchors.brand)!) : solveAgainst(brand.h, brandChroma, 3, brandGround, mode);\n if (brandRatio < 3) {\n warnings.push(\n `brand ${anchors.brand} sits at ${brandRatio.toFixed(2)}:1 against the ${mode} surfaces, ` +\n `below the 3:1 WCAG 1.4.11 asks of a control boundary. Lightness was adjusted to ` +\n `${brandHex}; hue and chroma are unchanged.`,\n );\n }\n // `--brand-muted` is the brand AS TEXT — a soft brand chip's label, an outline chip, a\n // current link — and tokens.css derives it: 62 % brand into the ink. A brand solved\n // to 3:1 left it at 4.43–4.51:1 in three dark presets (0.33, §5.5), so it gets the\n // text floor here: the brand moves away from the surfaces, a step at a time, until its\n // muted form clears 4.5:1 on the worst fill and on its own soft chip, at rest\n // (`--brand-bg`) and hovered (`--brand-bg-hover`, the harder of the two: §12.11).\n const brandMutedWorst = (hex: string) => {\n const soft = brandSoft({ brand: hex, textPrimary, bgSurface: surfaces.bgSurface });\n return Math.min(\n contrast(soft.brandMuted, worstText),\n contrast(soft.brandMuted, soft.brandBg),\n contrast(soft.brandMuted, soft.brandBgHover),\n // …and on More contrast's light well, where a link button reads it (§13.3).\n moreWell ? contrast(soft.brandMuted, moreWell) : Infinity,\n );\n };\n for (let i = 0; i < 40 && brandMutedWorst(brandHex) < 4.5; i++) {\n const lch = hexToOklch(brandHex)!;\n brandHex = oklchToHex({ ...lch, l: mode === \"light\" ? lch.l - 0.005 : lch.l + 0.005 });\n }\n if (brandMutedWorst(brandHex) < 4.5) {\n warnings.push(\n `the brand as text (--brand-muted) reaches only ${brandMutedWorst(brandHex).toFixed(2)}:1 ` +\n `against the ${mode} surfaces (needs 4.5:1).`,\n );\n }\n const brandLch = hexToOklch(brandHex)!;\n const brandContrast = contrastOn(brandHex);\n const brandHover = oklchToHex({\n ...brandLch,\n // Hover moves AWAY from the colour of the text on it (0.33, §5.5): darker under\n // white, lighter under a dark ink. It used to move away from the page, which in dark\n // lightened a fill that carries WHITE text, toward its own label: 4.07:1.\n l: brandContrast === \"#ffffff\" ? brandLch.l - 0.06 : brandLch.l + 0.06,\n });\n const onBrand = contrast(brandHex, brandContrast);\n if (onBrand < 4.5) {\n warnings.push(\n `text on the brand fill reaches only ${onBrand.toFixed(2)}:1 (needs 4.5:1). ` +\n `A mid-lightness, high-chroma brand cannot carry legible text at any ink; ` +\n `use it as an accent and keep primary buttons on a darker or lighter variant.`,\n );\n }\n\n // ── Semantic roles. Anchors are honoured exactly; the rest are placed away from the\n // brand and from each other, within each role's licence to move.\n const taken: number[] = [brandLch.h];\n const accentLch = anchors.accent ? hexToOklch(anchors.accent) : null;\n if (anchors.accent && !accentLch) {\n warnings.push(`accent \"${anchors.accent}\" is not a hex colour and was ignored.`);\n }\n if (accentLch) taken.push(accentLch.h);\n\n const semanticHue = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n const semanticChroma = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n for (const role of [\"danger\", \"warning\", \"success\", \"info\"] as const) {\n const pinned = anchors[role] ? hexToOklch(anchors[role]!) : null;\n if (anchors[role] && !pinned) {\n warnings.push(`${role} \"${anchors[role]}\" is not a hex colour and was ignored.`);\n }\n const home = HUE_HOME[role];\n const hue = pinned ? pinned.h : placeHue(home.hue, home.slack, taken);\n if (!pinned) {\n const gap = Math.min(...taken.map((t) => hueGap(hue, t)));\n if (gap < 20) {\n warnings.push(\n `${role} could only reach ${gap.toFixed(0)}° from the nearest pinned hue, which is ` +\n `too close to tell apart at a glance. Pin ${role} explicitly, or move the brand.`,\n );\n }\n }\n semanticHue[role] = hue;\n semanticChroma[role] = pinned ? Math.max(pinned.c, 0.08) : 0.13;\n taken.push(hue);\n }\n\n /**\n * A semantic colour has two jobs and therefore two backgrounds: plain text on the\n * page, and the label inside its own tinted badge. The badge is the harder of the\n * two — it is a step toward the colour — so solving only against the surface produced\n * a badge at 4.1:1 while the loose text passed, which is the failure mode that is\n * hardest to notice because nine tenths of the uses look fine.\n */\n const sem = (role: Exclude<AnchorRole, \"brand\" | \"accent\">) => {\n const hue = semanticHue[role];\n const chroma = semanticChroma[role];\n const bg = tintOn(hue, chroma, surfaces.bgSurface, mode);\n const onSurface = solveLightness(4.5, parseHex(worstText)!, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n const onTint = solveLightness(4.5, parseHex(bg)!, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n const l = mode === \"light\" ? Math.min(onSurface, onTint) : Math.max(onSurface, onTint);\n return oklchToHex({ l, c: chroma, h: hue });\n };\n\n const danger = sem(\"danger\");\n const dangerLch = hexToOklch(danger)!;\n const semantic: SemanticTokens = {\n danger,\n dangerHover: oklchToHex({\n ...dangerLch,\n l: mode === \"light\" ? dangerLch.l - 0.06 : dangerLch.l + 0.06,\n }),\n dangerContrast: contrastOn(danger),\n // The tone border follows its siblings' lightness in dark mode (warning 0.44, info\n // and success 0.45) — a soft frame; the strong line keeps the old, louder recipe.\n dangerBorder: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : 0.45,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBorderStrong: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : dangerLch.l - 0.22,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBg: tintOn(semanticHue.danger, semanticChroma.danger, surfaces.bgSurface, mode),\n warning: sem(\"warning\"),\n warningBorder: oklchToHex({\n l: mode === \"light\" ? 0.82 : 0.44,\n c: semanticChroma.warning,\n h: semanticHue.warning,\n }),\n warningBg: tintOn(semanticHue.warning, semanticChroma.warning, surfaces.bgSurface, mode),\n info: sem(\"info\"),\n infoBorder: oklchToHex({\n l: mode === \"light\" ? 0.8 : 0.45,\n c: semanticChroma.info,\n h: semanticHue.info,\n }),\n infoBg: tintOn(semanticHue.info, semanticChroma.info, surfaces.bgSurface, mode),\n success: sem(\"success\"),\n successBorder: oklchToHex({\n l: mode === \"light\" ? 0.81 : 0.45,\n c: semanticChroma.success,\n h: semanticHue.success,\n }),\n successBg: tintOn(semanticHue.success, semanticChroma.success, surfaces.bgSurface, mode),\n };\n\n if (accentLch) {\n const accent = solveAgainst(accentLch.h, Math.max(accentLch.c, 0.06), 3, worstSurface, mode);\n semantic.accent = accent;\n semantic.accentContrast = contrastOn(accent);\n semantic.accentBg = tintOn(accentLch.h, Math.max(accentLch.c, 0.06), surfaces.bgSurface, mode);\n }\n\n // ── Money. A THIRD system again: these are data colours with fixed meanings, and the\n // one rule that outranks everything is that income and expense must never be the\n // red/green pair — which is why the shipped presets use teal/amber/violet. Derived\n // here at fixed hues rather than from the brand, for the same reason `--danger` is:\n // a consumer who rebrands does not thereby change what \"money out\" looks like.\n const money = (hue: number, target: number) => solveAgainst(hue, 0.12, target, worstText, mode);\n const moneyIncome = money(175, 4.5);\n const moneyExpense = money(70, 4.5);\n const moneyNet = money(300, 4.5);\n // \"No money has moved\": a quiet grey at a fixed lightness, but printed as TEXT (the\n // numpad's sign, a future row's figure), so it gets the text floor too (0.33). The\n // fixed lightness left it at 4.24:1 on four light pages.\n const neutralChroma = 0.012 * weight;\n const neutralFloor = solveLightness(\n 4.5,\n parseHex(worstText)!,\n brand.h,\n neutralChroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const moneyNeutral = oklchToHex({\n l: mode === \"light\" ? Math.min(0.52, neutralFloor) : Math.max(0.72, neutralFloor),\n c: neutralChroma,\n h: brand.h,\n });\n\n const tokens: TokenSet = {\n ...surfaces,\n textPrimary,\n textSecondary,\n textMuted,\n brand: brandHex,\n brandHover,\n brandContrast,\n moneyIncome,\n moneyExpense,\n moneyNet,\n moneyNeutral,\n // Left alone. See the note at the top of this file about why the categorical ramp is\n // not derived from the brand unless the caller asks.\n //\n // ⚠️ EMPTY, not absent: a caller who hands this straight to `applyTokenSet` keeps\n // whatever `--chart-1…9` were already on the element. That is deliberate — the ramp\n // is a separate decision and clearing it would leave charts unpainted — but it means\n // a derived palette applied over another preset is a MIX until you also supply a\n // ramp. `deriveChartRamp` is how you supply one.\n chart: [],\n heat: deriveHeat(moneyIncome, moneyExpense, surfaces, mode),\n };\n\n // Audited at both contrast levels (0.36, colour-roles §13.5): More contrast steps the\n // text, the border and, in light, the well and money of this set. The derived semantic\n // colours are audited at Standard only: they are solved for the standard grounds, and\n // only tokens.css's shipped literals step for the darker well.\n const standard = auditPalette(tokens, semantic);\n const more = auditPalette(tokens, undefined, { level: \"more\" });\n const checks = [...standard.checks, ...more.checks];\n const failures = checks.filter((c) => !c.passes);\n return { tokens, semantic, audit: { checks, failures, passes: failures.length === 0 }, warnings };\n}\n\n/**\n * Heatmap stops, reusing the money pair.\n *\n * `under` is the good direction and `over` the bad one, at the SAME hues as\n * `moneyIncome`/`moneyExpense` — so a heatmap cell and the figure printed beside it\n * agree about which way is which, rather than each inventing its own convention.\n */\nfunction deriveHeat(income: string, expense: string, surfaces: { bgSurface2: string }, mode: ThemeMode): HeatStops {\n const exp = hexToOklch(expense)!;\n return {\n neutral: surfaces.bgSurface2,\n under: income,\n over: expense,\n seqLow: oklchToHex({ l: mode === \"light\" ? 0.93 : 0.26, c: 0.05, h: exp.h }),\n seqHigh: expense,\n empty: mode === \"light\" ? \"rgba(120,110,95,0.14)\" : \"rgba(160,170,190,0.10)\",\n };\n}\n\n/* ── Audit ────────────────────────────────────────────────────────────────── */\n\n/**\n * Measure every pair that has a requirement, and say which ones fail.\n *\n * This is the part the shipped presets were missing. `derivePalette` runs it on the way\n * out, and the preset test runs it over everything the package ships, so a palette that\n * does not hold up cannot be merged with a comment claiming that it does.\n *\n * **`level: \"more\"`** (0.36, docs/colour-roles-harmonization.md §13.5) measures the set as\n * More contrast paints it: the stepped secondary, muted and border, and in a light set the\n * stepped well (as `bgSurface2`) and money — the same pairs, named with a \" (More\n * contrast)\" suffix. Two things change with the level: the border is a field's boundary\n * there, held to WCAG 1.4.11's 3:1 rather than the hairline's 1.1, and a light set's well\n * must stand {@link WELL_STEP_MIN}:1 from the card. Pass `semantic` with tokens.css's More\n * literals for a light set (the status colours step there); the status text is then\n * measured on the stepped well too.\n */\nexport function auditPalette(\n set: TokenSet,\n semantic?: SemanticTokens,\n options: { level?: ContrastLevel } = {},\n): ContrastReport {\n const more = options.level === \"more\";\n const step = more ? contrastStep(set) : null;\n // The set as it paints at this level: what `applyTokenSet` writes for it.\n const t: TokenSet = step\n ? {\n ...set,\n textSecondary: step.textSecondary,\n textMuted: step.textMuted,\n border: step.border,\n ...(step.well && {\n bgSurface2: step.well.bgSurface2,\n moneyIncome: step.well.moneyIncome,\n moneyExpense: step.well.moneyExpense,\n moneyNet: step.well.moneyNet,\n moneyNeutral: step.well.moneyNeutral,\n }),\n }\n : set;\n const suffix = more ? \" (More contrast)\" : \"\";\n const checks: ContrastCheck[] = [];\n const surfaces: Array<[string, string]> = [\n [\"bgPage\", t.bgPage],\n [\"bgSurface\", t.bgSurface],\n [\"bgSurface2\", t.bgSurface2],\n ];\n // A hovered row on the card (`--bg-hover`) carries the same text as the card, and in\n // light it is the darkest fill that text sits on (0.33, §12.10). Text is measured on\n // it; the brand fill and the hairline, which are not text, are not.\n const hover = hoverFill(t);\n const textGrounds: Array<[string, string]> = [...surfaces, [\"bgHover\", hover]];\n // `--brand-muted`, `--brand-bg` and `--brand-bg-hover`, mixed as tokens.css mixes them.\n const { brandMuted, brandBg, brandBgHover } = brandSoft(t);\n\n // The 0.05 of slack is for a pair with a color-mix on one side, and only for that: the\n // browser mixes in float and paints the result, where this mixes and rounds to hex, so\n // the two can differ by a hair. Hex against hex is what the page paints, measured\n // exactly — the slack used to cover those too, and passed the Contrast preset's dark\n // brand fill at 2.998:1 (round 0.34 BUG-8).\n const MIXED = /\\b(bgHover|brandMuted|brandBg|brandBgHover)\\b/;\n const add = (pair: string, fg: string, bg: string, required: number, rule: string) => {\n const ratio = contrast(fg, bg);\n const slack = MIXED.test(pair) ? 0.05 : 0;\n checks.push({ pair: pair + suffix, ratio, required, rule, passes: ratio >= required - slack });\n };\n\n for (const [name, bg] of surfaces) {\n add(`brand on ${name}`, t.brand, bg, 3, \"WCAG 1.4.11 graphical object\");\n if (more) add(`border on ${name}`, t.border, bg, 3, \"WCAG 1.4.11 — under More contrast a border bounds a field\");\n else add(`border on ${name}`, t.border, bg, 1.1, \"house rule: a hairline must be findable\");\n }\n // The stepped light well, a hex `applyTokenSet` writes (§13.3, decision 2).\n if (step?.well) {\n add(\n \"bgSurface2 on bgSurface\",\n t.bgSurface2,\n t.bgSurface,\n WELL_STEP_MIN,\n \"house rule: the well stands two hover steps from the card\",\n );\n }\n for (const [name, bg] of textGrounds) {\n add(`textPrimary on ${name}`, t.textPrimary, bg, 7, \"WCAG 1.4.6 AAA body text\");\n add(`textSecondary on ${name}`, t.textSecondary, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`textMuted on ${name}`, t.textMuted, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`brandMuted on ${name}`, brandMuted, bg, 4.5, \"WCAG 1.4.3 — the brand as text\");\n for (const [key, hex] of [\n [\"moneyIncome\", t.moneyIncome],\n [\"moneyExpense\", t.moneyExpense],\n [\"moneyNet\", t.moneyNet],\n // Not a figure's colour but still printed as one (the numpad's sign, a future\n // row's amount) — measured since 0.33, when it was found at 4.24:1.\n [\"moneyNeutral\", t.moneyNeutral],\n ] as const) {\n add(`${key} on ${name}`, hex, bg, 4.5, \"WCAG 1.4.3 — these are rendered as TEXT\");\n }\n }\n\n add(\"brandContrast on brand\", t.brandContrast, t.brand, 4.5, \"WCAG 1.4.3 AA body text\");\n // A hovered brand button carries the same label (0.33): the derived dark presets\n // lightened the hover toward their white label and left it at 4.07:1.\n add(\"brandContrast on brandHover\", t.brandContrast, t.brandHover, 4.5, \"WCAG 1.4.3 AA body text\");\n add(\"brandMuted on brandBg\", brandMuted, brandBg, 4.5, \"WCAG 1.4.3 — a soft brand chip's label\");\n // The same label on the chip hovered (§12.11): a current link, a selected day. At 70 %\n // brand the muted text read 4.08–4.42:1 here (Default and Moss light; Ink, Moss, Plum\n // and Contrast dark).\n add(\"brandMuted on brandBgHover\", brandMuted, brandBgHover, 4.5, \"WCAG 1.4.3 — a hovered soft brand chip's label\");\n\n if (semantic) {\n for (const [name, fg] of [\n [\"danger\", semantic.danger],\n [\"warning\", semantic.warning],\n [\"info\", semantic.info],\n [\"success\", semantic.success],\n ] as const) {\n add(`${name} on bgSurface`, fg, t.bgSurface, 4.5, \"WCAG 1.4.3 — rendered as text\");\n add(`${name} on bgHover`, fg, hover, 4.5, \"WCAG 1.4.3 — rendered as text, on a hovered row\");\n // The darker light well the More literals were solved for (§13.3).\n if (step?.well) add(`${name} on bgSurface2`, fg, t.bgSurface2, 4.5, \"WCAG 1.4.3 — rendered as text, on the well\");\n }\n add(\"danger on dangerBg\", semantic.danger, semantic.dangerBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"warning on warningBg\", semantic.warning, semantic.warningBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"info on infoBg\", semantic.info, semantic.infoBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"success on successBg\", semantic.success, semantic.successBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"dangerContrast on danger\", semantic.dangerContrast, semantic.danger, 4.5, \"WCAG 1.4.3 AA body text\");\n }\n\n const failures = checks.filter((c) => !c.passes);\n return { checks, failures, passes: failures.length === 0 };\n}\n\n/* ── Categorical chart ramp ───────────────────────────────────────────────── */\n\nexport interface ChartRampReport {\n colors: string[];\n /** Series pairs that are too close under normal vision or any simulated CVD. */\n collisions: Array<{ a: number; b: number; under: \"normal\" | CvdType; distance: number }>;\n /** Series that do not clear 3:1 against a surface they may be drawn on. */\n lowContrast: Array<{ index: number; surface: string; ratio: number }>;\n /** The worst pairwise separation, across normal vision and all three dichromacies. */\n minSeparation: number;\n /** The worst contrast any series reaches against any surface it was measured on. */\n minContrast: number;\n passes: boolean;\n}\n\n/**\n * The floor for pairwise separation in OKLab, across normal vision and each dichromacy.\n *\n * CALIBRATED, not chosen. Paul Tol's \"Muted\" set — which this package ships and which is\n * a well-regarded CVD-safe palette — bottoms out at 0.059 in its light variant and 0.032\n * in the lightened dark one. A threshold above 0.059 would fail a palette that is known\n * to work, which is worse than having no check at all: an audit that cries wolf gets\n * switched off. 0.05 sits just under the known-good case.\n */\nconst MIN_SEPARATION = 0.05;\n\n/**\n * **The categorical trade-off, measured.** At a SINGLE lightness, the most series that\n * can satisfy both the 3:1 fill contrast of WCAG 1.4.11 and {@link MIN_SEPARATION} under\n * dichromacy is FOUR. Searched exhaustively over starting hue and lightness:\n *\n * n=4 best separation 0.065 — both satisfiable\n * n=5 best separation 0.041 — not satisfiable\n * n=9 best separation 0.015 — not satisfiable\n *\n * The reason is structural: dichromacy collapses the red-green axis, so hue alone stops\n * distinguishing colours once you need more than a handful, and the remaining channel is\n * LIGHTNESS — the very thing a uniform-contrast ramp holds constant. Paul Tol's set\n * varies lightness deliberately and pays for it in contrast; that is not an oversight in\n * their palette, it is the only currency left.\n *\n * So above four series this deriver varies lightness too, and reports what it gave up\n * rather than pretending both constraints were met.\n *\n * NOTE ON WHAT THIS BOUND IS. It describes the PROBLEM, not a guarantee about\n * {@link deriveChartRamp}. That function fixes lightness and starts the hue wheel at the\n * brand's own hue rather than searching for the best start, so it reaches the bound only\n * where the brand happens to sit well: sweeping 72 brand hues against the default light\n * surfaces, 7 of 72 produced a passing 4-series ramp (12 of 72 on dark), and none passed\n * at 5 or 9. Read the report it returns; do not assume a pass.\n */\nconst SINGLE_LIGHTNESS_MAX_SERIES = 4;\n\n/**\n * A categorical ramp of `count` hues, evenly spaced and equal in perceived lightness,\n * then MEASURED for separability — including under each dichromacy.\n *\n * Offered but not used by default, and the distinction matters. Evenly spaced hues at\n * one lightness are a reasonable generic answer; Paul Tol's \"Muted\" set, which this\n * package ships, is a better specific one, because it was optimised against real\n * confusion lines rather than derived from a formula. So this exists for a consumer who\n * wants their charts to follow their brand and is willing to read the report — not as\n * a silent upgrade to the default.\n */\nexport function deriveChartRamp(brandHex: string, mode: ThemeMode, surfaces: string[], count = 9): ChartRampReport {\n const brand = hexToOklch(brandHex) ?? { l: 0.6, c: 0.12, h: 264 };\n const base = mode === \"light\" ? 0.58 : 0.74;\n const c = Math.max(0.09, Math.min(brand.c, 0.15));\n // Up to four series, one lightness: a scale that varies lightness implies rank, and a\n // categorical one must not. Beyond four, lightness is the only channel left that\n // survives dichromacy — see SINGLE_LIGHTNESS_MAX_SERIES — so it alternates in a\n // three-step cycle, which keeps ADJACENT series (the ones a legend puts side by side)\n // at different lightnesses as well as different hues.\n const vary = count > SINGLE_LIGHTNESS_MAX_SERIES;\n const offsets = [0, mode === \"light\" ? -0.1 : 0.1, mode === \"light\" ? 0.08 : -0.08];\n const colors = Array.from({ length: count }, (_, i) =>\n oklchToHex({\n l: vary ? base + offsets[i % offsets.length] : base,\n c,\n h: (brand.h + (360 / count) * i) % 360,\n }),\n );\n\n return measureRamp(colors, surfaces);\n}\n\n/** Audit a ramp somebody else chose — the shipped Paul Tol set, say. */\nexport function auditChartRamp(colors: string[], surfaces: string[]): ChartRampReport {\n return measureRamp(colors, surfaces);\n}\n\nfunction measureRamp(colors: string[], surfaces: string[]): ChartRampReport {\n const collisions: ChartRampReport[\"collisions\"] = [];\n const rgbs = colors.map((hex) => parseHex(hex)).filter((v): v is NonNullable<typeof v> => !!v);\n let minSeparation = Infinity;\n for (let i = 0; i < rgbs.length; i++) {\n for (let j = i + 1; j < rgbs.length; j++) {\n const normal = deltaE(rgbs[i], rgbs[j]);\n minSeparation = Math.min(minSeparation, normal);\n if (normal < MIN_SEPARATION) {\n collisions.push({ a: i, b: j, under: \"normal\", distance: normal });\n }\n for (const type of [\"protanopia\", \"deuteranopia\", \"tritanopia\"] as const) {\n const d = deltaE(simulateCvd(rgbs[i], type), simulateCvd(rgbs[j], type));\n minSeparation = Math.min(minSeparation, d);\n if (d < MIN_SEPARATION) collisions.push({ a: i, b: j, under: type, distance: d });\n }\n }\n }\n\n const lowContrast: ChartRampReport[\"lowContrast\"] = [];\n let minContrast = Infinity;\n colors.forEach((hex, index) => {\n for (const surface of surfaces) {\n const ratio = contrast(hex, surface);\n minContrast = Math.min(minContrast, ratio);\n // WCAG 1.4.11: a graphical object carrying meaning needs 3:1 against what is\n // adjacent to it. A bar the same value as the card behind it has no boundary.\n if (ratio < 3) lowContrast.push({ index, surface, ratio });\n }\n });\n\n return {\n colors,\n collisions,\n lowContrast,\n minSeparation: Number.isFinite(minSeparation) ? minSeparation : 0,\n minContrast: Number.isFinite(minContrast) ? minContrast : 0,\n passes: collisions.length === 0 && lowContrast.length === 0,\n };\n}\n\n/** Convenience: the OKLCH of a hex, for a caller inspecting an anchor. */\nexport function describe(hex: string): Oklch | null {\n const rgb = parseHex(hex);\n return rgb ? rgbToOklch(rgb) : null;\n}\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,WAAW,cAAc,WAAW,iBAAiB,qBAAqB;AA8GnF,MAAM,WAA4F;AAAA,EAChG,QAAQ,EAAE,KAAK,IAAI,OAAO,GAAG;AAAA,EAC7B,SAAS,EAAE,KAAK,IAAI,OAAO,GAAG;AAAA,EAC9B,SAAS,EAAE,KAAK,KAAK,OAAO,GAAG;AAAA,EAC/B,MAAM,EAAE,KAAK,KAAK,OAAO,GAAG;AAC9B;AAGA,SAAS,OAAO,GAAW,GAAmB;AAC5C,QAAM,IAAI,KAAK,KAAM,IAAI,KAAK,MAAO,GAAG,IAAI;AAC5C,SAAO,IAAI,MAAM,MAAM,IAAI;AAC7B;AAUA,SAAS,SAAS,MAAc,OAAe,OAAyB;AACtE,MAAI,OAAO;AACX,MAAI,UAAU,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC,GAAG,GAAG;AAChE,WAAS,IAAI,CAAC,OAAO,KAAK,OAAO,KAAK,GAAG;AACvC,UAAM,KAAK,OAAO,IAAI,OAAO;AAC7B,UAAM,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI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