@zonsh/ui 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +639 -0
- package/README.md +49 -21
- package/dist/brand.d.ts +3 -0
- package/dist/brand.js +7 -0
- package/dist/components/_breadcrumb-more.d.ts +6 -0
- package/dist/components/_breadcrumb-more.js +5 -0
- package/dist/components/_drawing-svg.d.ts +11 -0
- package/dist/components/_drawing-svg.js +30 -0
- package/dist/components/_media.d.ts +159 -0
- package/dist/components/_media.js +266 -0
- package/dist/components/_overlay.d.ts +8 -5
- package/dist/components/_overlay.js +11 -6
- package/dist/components/_scheduler-calendar.d.ts +71 -0
- package/dist/components/_scheduler-calendar.js +940 -0
- package/dist/components/_scheduler-editor.d.ts +29 -0
- package/dist/components/_scheduler-editor.js +111 -0
- package/dist/components/_scheduler-menu.d.ts +16 -0
- package/dist/components/_scheduler-menu.js +18 -0
- package/dist/components/_scheduler-parts.d.ts +164 -0
- package/dist/components/_scheduler-parts.js +327 -0
- package/dist/components/_suggest-list.d.ts +142 -0
- package/dist/components/_suggest-list.js +159 -0
- package/dist/components/_toolbar-more.d.ts +24 -0
- package/dist/components/_toolbar-more.js +25 -0
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +6 -6
- package/dist/components/action-sheet.d.ts +88 -0
- package/dist/components/action-sheet.js +124 -0
- package/dist/components/alert-dialog.js +3 -1
- package/dist/components/alert.d.ts +11 -18
- package/dist/components/alert.js +9 -6
- package/dist/components/app-bar.d.ts +93 -0
- package/dist/components/app-bar.js +175 -0
- package/dist/components/audio-player.d.ts +134 -0
- package/dist/components/audio-player.js +618 -0
- package/dist/components/avatar.d.ts +6 -6
- package/dist/components/avatar.js +13 -11
- package/dist/components/badge.d.ts +12 -12
- package/dist/components/badge.js +7 -5
- package/dist/components/bottom-nav.d.ts +53 -11
- package/dist/components/bottom-nav.js +388 -23
- package/dist/components/breadcrumb.d.ts +11 -2
- package/dist/components/breadcrumb.js +60 -6
- package/dist/components/button-group.js +5 -1
- package/dist/components/button.d.ts +23 -6
- package/dist/components/button.js +63 -7
- package/dist/components/calendar.js +8 -6
- package/dist/components/card.d.ts +10 -8
- package/dist/components/card.js +15 -14
- package/dist/components/carousel.d.ts +2 -2
- package/dist/components/carousel.js +21 -8
- package/dist/components/chart.d.ts +27 -1
- package/dist/components/chart.js +15 -5
- package/dist/components/checkbox.js +2 -2
- package/dist/components/code-block.d.ts +9 -2
- package/dist/components/code-block.js +26 -7
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +2 -2
- package/dist/components/color-picker.js +5 -5
- package/dist/components/combobox.d.ts +26 -7
- package/dist/components/combobox.js +32 -13
- package/dist/components/command.d.ts +29 -5
- package/dist/components/command.js +35 -10
- package/dist/components/context-menu.d.ts +5 -2
- package/dist/components/context-menu.js +24 -3
- package/dist/components/conversation.d.ts +1 -1
- package/dist/components/conversation.js +67 -13
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/copy-button.js +1 -1
- package/dist/components/data-table.d.ts +6 -6
- package/dist/components/data-table.js +41 -15
- package/dist/components/date-picker.d.ts +31 -9
- package/dist/components/date-picker.js +100 -18
- package/dist/components/dialog.d.ts +17 -10
- package/dist/components/dialog.js +20 -13
- package/dist/components/drawer.d.ts +26 -8
- package/dist/components/drawer.js +75 -16
- package/dist/components/drawing.d.ts +25 -0
- package/dist/components/drawing.js +32 -0
- package/dist/components/empty.js +2 -2
- package/dist/components/feature-list.d.ts +65 -13
- package/dist/components/feature-list.js +116 -15
- package/dist/components/field.js +2 -2
- package/dist/components/file-drop.d.ts +9 -7
- package/dist/components/file-drop.js +8 -43
- package/dist/components/filter-bar.d.ts +10 -9
- package/dist/components/filter-bar.js +42 -25
- package/dist/components/graph.d.ts +19 -3
- package/dist/components/graph.js +170 -25
- package/dist/components/illustration.js +3 -28
- package/dist/components/input-group.d.ts +5 -10
- package/dist/components/input-group.js +16 -16
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/item.d.ts +9 -6
- package/dist/components/item.js +13 -8
- package/dist/components/kbd.d.ts +1 -1
- package/dist/components/kbd.js +1 -1
- package/dist/components/lightbox.d.ts +76 -9
- package/dist/components/lightbox.js +333 -45
- package/dist/components/locale.d.ts +6 -6
- package/dist/components/logo.d.ts +21 -1
- package/dist/components/logo.js +32 -2
- package/dist/components/markdown-editor.d.ts +275 -0
- package/dist/components/markdown-editor.js +831 -0
- package/dist/components/mentions.d.ts +153 -0
- package/dist/components/mentions.js +507 -0
- package/dist/components/menu.d.ts +2 -1
- package/dist/components/menu.js +5 -4
- package/dist/components/menubar.d.ts +23 -5
- package/dist/components/menubar.js +97 -22
- package/dist/components/message.d.ts +62 -11
- package/dist/components/message.js +49 -13
- package/dist/components/meter.js +1 -1
- package/dist/components/money-input.d.ts +1 -1
- package/dist/components/money-input.js +1 -1
- package/dist/components/native-select.d.ts +2 -2
- package/dist/components/native-select.js +4 -4
- package/dist/components/navigation-menu.d.ts +3 -1
- package/dist/components/navigation-menu.js +23 -12
- package/dist/components/number-field.d.ts +2 -9
- package/dist/components/number-field.js +86 -36
- package/dist/components/number-roll.d.ts +26 -0
- package/dist/components/number-roll.js +81 -0
- package/dist/components/otp-field.d.ts +1 -1
- package/dist/components/otp-field.js +24 -3
- package/dist/components/pagination.d.ts +11 -3
- package/dist/components/pagination.js +59 -13
- package/dist/components/pdf-viewer.d.ts +1 -1
- package/dist/components/pdf-viewer.js +8 -8
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +2 -2
- package/dist/components/popover.js +5 -3
- package/dist/components/preview-card.d.ts +37 -2
- package/dist/components/preview-card.js +226 -2
- package/dist/components/progress.js +1 -1
- package/dist/components/prompt-input.d.ts +1 -1
- package/dist/components/prompt-input.js +24 -14
- package/dist/components/pull-to-refresh.d.ts +50 -0
- package/dist/components/pull-to-refresh.js +189 -0
- package/dist/components/quote.d.ts +6 -1
- package/dist/components/quote.js +3 -2
- package/dist/components/radio-group.js +1 -1
- package/dist/components/rating.d.ts +4 -1
- package/dist/components/rating.js +131 -10
- package/dist/components/reasoning.d.ts +1 -1
- package/dist/components/reasoning.js +7 -3
- package/dist/components/resizable.d.ts +1 -1
- package/dist/components/resizable.js +2 -2
- package/dist/components/response.d.ts +1 -1
- package/dist/components/response.js +18 -6
- package/dist/components/scheduler.d.ts +352 -0
- package/dist/components/scheduler.js +1717 -0
- package/dist/components/scroll-area.js +1 -1
- package/dist/components/select.d.ts +17 -4
- package/dist/components/select.js +140 -9
- package/dist/components/separator.d.ts +1 -1
- package/dist/components/separator.js +3 -3
- package/dist/components/sidebar.d.ts +44 -3
- package/dist/components/sidebar.js +57 -17
- package/dist/components/site-header.d.ts +18 -13
- package/dist/components/site-header.js +23 -11
- package/dist/components/skeleton.d.ts +17 -7
- package/dist/components/skeleton.js +22 -7
- package/dist/components/slider.js +2 -2
- package/dist/components/sortable.d.ts +55 -4
- package/dist/components/sortable.js +172 -103
- package/dist/components/sources.d.ts +1 -1
- package/dist/components/sources.js +2 -2
- package/dist/components/spinner.d.ts +4 -4
- package/dist/components/spinner.js +4 -4
- package/dist/components/stat.d.ts +21 -4
- package/dist/components/stat.js +17 -8
- package/dist/components/stepper.d.ts +1 -1
- package/dist/components/stepper.js +8 -7
- package/dist/components/suggestions.d.ts +11 -3
- package/dist/components/suggestions.js +10 -4
- package/dist/components/swipe-actions.d.ts +66 -0
- package/dist/components/swipe-actions.js +292 -0
- package/dist/components/switch.js +1 -1
- package/dist/components/table.d.ts +12 -6
- package/dist/components/table.js +78 -30
- package/dist/components/tabs.js +7 -4
- package/dist/components/tag.d.ts +19 -20
- package/dist/components/tag.js +9 -5
- package/dist/components/tags-input.d.ts +2 -7
- package/dist/components/tags-input.js +11 -8
- package/dist/components/textarea.d.ts +3 -2
- package/dist/components/textarea.js +4 -3
- package/dist/components/theme.d.ts +49 -6
- package/dist/components/theme.js +147 -9
- package/dist/components/time-field.d.ts +4 -9
- package/dist/components/time-field.js +6 -6
- package/dist/components/timeline.d.ts +19 -3
- package/dist/components/timeline.js +21 -9
- package/dist/components/tippy.d.ts +17 -1
- package/dist/components/tippy.js +95 -15
- package/dist/components/toast.d.ts +2 -7
- package/dist/components/toast.js +12 -8
- package/dist/components/toggle-group.d.ts +7 -1
- package/dist/components/toggle-group.js +16 -5
- package/dist/components/toggle.d.ts +2 -2
- package/dist/components/toggle.js +3 -2
- package/dist/components/tool-call.d.ts +1 -1
- package/dist/components/tool-call.js +4 -4
- package/dist/components/toolbar.d.ts +57 -4
- package/dist/components/toolbar.js +216 -16
- package/dist/components/tooltip.d.ts +1 -1
- package/dist/components/tooltip.js +4 -2
- package/dist/components/tour.d.ts +1 -1
- package/dist/components/tour.js +36 -15
- package/dist/components/tree.js +5 -5
- package/dist/components/typography.d.ts +31 -8
- package/dist/components/typography.js +21 -10
- package/dist/components/video-player.d.ts +7 -2
- package/dist/components/video-player.js +121 -220
- package/dist/index.d.ts +99 -92
- package/dist/index.js +99 -92
- package/dist/lib/calendar.d.ts +153 -0
- package/dist/lib/calendar.js +312 -0
- package/dist/lib/cn.d.ts +3 -1
- package/dist/lib/cn.js +5 -0
- package/dist/lib/code-highlight.d.ts +14 -0
- package/dist/lib/code-highlight.js +81 -18
- package/dist/lib/drag.d.ts +39 -0
- package/dist/lib/drag.js +96 -0
- package/dist/lib/editorial-assets.js +16 -8
- package/dist/lib/figure/figures/automation.js +25 -6
- package/dist/lib/figure/figures/bar-chart.js +6 -1
- package/dist/lib/figure/figures/brackets-classic.js +4 -1
- package/dist/lib/figure/figures/city.js +12 -2
- package/dist/lib/figure/figures/conveyor.js +17 -4
- package/dist/lib/figure/figures/database.js +5 -2
- package/dist/lib/figure/figures/documents.js +11 -3
- package/dist/lib/figure/figures/inbox.js +5 -2
- package/dist/lib/figure/figures/laptop.js +3 -1
- package/dist/lib/figure/figures/pipeline.js +45 -10
- package/dist/lib/figure/figures/platform.js +62 -7
- package/dist/lib/figure/figures/server.js +21 -5
- package/dist/lib/figure/figures/spreadsheet.js +29 -5
- package/dist/lib/figure/kernel.d.ts +4 -2
- package/dist/lib/figure/kernel.js +10 -5
- package/dist/lib/figure/parts.js +6 -2
- package/dist/lib/files.d.ts +31 -0
- package/dist/lib/files.js +60 -0
- package/dist/lib/gesture.d.ts +70 -0
- package/dist/lib/gesture.js +141 -0
- package/dist/lib/glide.d.ts +5 -0
- package/dist/lib/glide.js +9 -1
- package/dist/lib/icons.d.ts +1 -0
- package/dist/lib/icons.js +6 -0
- package/dist/lib/illustration-library.js +1 -6
- package/dist/lib/markdown-edit.d.ts +112 -0
- package/dist/lib/markdown-edit.js +557 -0
- package/dist/lib/markdown-rich-editor.d.ts +188 -0
- package/dist/lib/markdown-rich-editor.js +1153 -0
- package/dist/lib/markdown-rich.d.ts +63 -0
- package/dist/lib/markdown-rich.js +534 -0
- package/dist/lib/mentions.d.ts +100 -0
- package/dist/lib/mentions.js +246 -0
- package/dist/lib/motion.d.ts +18 -0
- package/dist/lib/motion.js +43 -5
- package/dist/lib/number-roll.d.ts +89 -0
- package/dist/lib/number-roll.js +391 -0
- package/dist/lib/platform.d.ts +6 -0
- package/dist/lib/platform.js +14 -0
- package/dist/lib/portal-container.d.ts +9 -0
- package/dist/lib/portal-container.js +10 -0
- package/dist/lib/press.d.ts +5 -0
- package/dist/lib/press.js +186 -0
- package/dist/lib/scheduler.d.ts +128 -0
- package/dist/lib/scheduler.js +272 -0
- package/dist/lib/scroll-edges.d.ts +9 -0
- package/dist/lib/scroll-edges.js +50 -0
- package/dist/lib/table-fit.d.ts +1 -1
- package/dist/lib/table-fit.js +65 -8
- package/dist/lib/theme-preset.d.ts +267 -0
- package/dist/lib/theme-preset.js +1046 -0
- package/dist/lib/theme-script.d.ts +23 -3
- package/dist/lib/theme-script.js +17 -5
- package/dist/lib/tippy/sprite.d.ts +36 -4
- package/dist/lib/tippy/sprite.js +188 -15
- package/dist/lib/tone.d.ts +4 -0
- package/dist/lib/tone.js +1 -0
- package/dist/messages/de.d.ts +3 -3
- package/dist/messages/de.js +274 -3
- package/dist/skills/zon-ui/SKILL.md +279 -0
- package/dist/skills/zon-ui/references/authoring.md +265 -0
- package/dist/skills/zon-ui/references/brand.md +416 -0
- package/dist/skills/zon-ui/references/components/accordion.md +199 -0
- package/dist/skills/zon-ui/references/components/action-sheet.md +268 -0
- package/dist/skills/zon-ui/references/components/alert-dialog.md +276 -0
- package/dist/skills/zon-ui/references/components/alert.md +167 -0
- package/dist/skills/zon-ui/references/components/app-bar.md +307 -0
- package/dist/skills/zon-ui/references/components/ascii-field.md +121 -0
- package/dist/skills/zon-ui/references/components/aspect-ratio.md +112 -0
- package/dist/skills/zon-ui/references/components/audio-player.md +231 -0
- package/dist/skills/zon-ui/references/components/avatar.md +98 -0
- package/dist/skills/zon-ui/references/components/badge.md +227 -0
- package/dist/skills/zon-ui/references/components/bottom-nav.md +709 -0
- package/dist/skills/zon-ui/references/components/breadcrumb.md +143 -0
- package/dist/skills/zon-ui/references/components/button-group.md +216 -0
- package/dist/skills/zon-ui/references/components/button.md +309 -0
- package/dist/skills/zon-ui/references/components/calendar.md +296 -0
- package/dist/skills/zon-ui/references/components/card.md +158 -0
- package/dist/skills/zon-ui/references/components/carousel.md +297 -0
- package/dist/skills/zon-ui/references/components/chart.md +739 -0
- package/dist/skills/zon-ui/references/components/chat.md +417 -0
- package/dist/skills/zon-ui/references/components/checkbox.md +219 -0
- package/dist/skills/zon-ui/references/components/code-block.md +143 -0
- package/dist/skills/zon-ui/references/components/code-highlight.md +118 -0
- package/dist/skills/zon-ui/references/components/collapsible.md +146 -0
- package/dist/skills/zon-ui/references/components/color-picker.md +200 -0
- package/dist/skills/zon-ui/references/components/combobox.md +455 -0
- package/dist/skills/zon-ui/references/components/command.md +326 -0
- package/dist/skills/zon-ui/references/components/contact-form.md +562 -0
- package/dist/skills/zon-ui/references/components/context-menu.md +159 -0
- package/dist/skills/zon-ui/references/components/conversation.md +146 -0
- package/dist/skills/zon-ui/references/components/copy-button.md +162 -0
- package/dist/skills/zon-ui/references/components/crm.md +1022 -0
- package/dist/skills/zon-ui/references/components/dashboard.md +612 -0
- package/dist/skills/zon-ui/references/components/data-table.md +776 -0
- package/dist/skills/zon-ui/references/components/date-picker.md +444 -0
- package/dist/skills/zon-ui/references/components/dialog.md +335 -0
- package/dist/skills/zon-ui/references/components/direction.md +165 -0
- package/dist/skills/zon-ui/references/components/drawer.md +276 -0
- package/dist/skills/zon-ui/references/components/drawing.md +94 -0
- package/dist/skills/zon-ui/references/components/empty.md +225 -0
- package/dist/skills/zon-ui/references/components/feature-list.md +412 -0
- package/dist/skills/zon-ui/references/components/field.md +209 -0
- package/dist/skills/zon-ui/references/components/file-drop.md +234 -0
- package/dist/skills/zon-ui/references/components/filter-bar.md +485 -0
- package/dist/skills/zon-ui/references/components/form.md +970 -0
- package/dist/skills/zon-ui/references/components/graph.md +339 -0
- package/dist/skills/zon-ui/references/components/illustration.md +497 -0
- package/dist/skills/zon-ui/references/components/inbox.md +263 -0
- package/dist/skills/zon-ui/references/components/input-group.md +339 -0
- package/dist/skills/zon-ui/references/components/input.md +189 -0
- package/dist/skills/zon-ui/references/components/item.md +277 -0
- package/dist/skills/zon-ui/references/components/kanban.md +626 -0
- package/dist/skills/zon-ui/references/components/kbd.md +116 -0
- package/dist/skills/zon-ui/references/components/label.md +104 -0
- package/dist/skills/zon-ui/references/components/layout.md +291 -0
- package/dist/skills/zon-ui/references/components/lightbox.md +235 -0
- package/dist/skills/zon-ui/references/components/locale.md +279 -0
- package/dist/skills/zon-ui/references/components/logo.md +257 -0
- package/dist/skills/zon-ui/references/components/markdown-editor.md +558 -0
- package/dist/skills/zon-ui/references/components/mentions.md +512 -0
- package/dist/skills/zon-ui/references/components/menu.md +218 -0
- package/dist/skills/zon-ui/references/components/menubar.md +292 -0
- package/dist/skills/zon-ui/references/components/message.md +243 -0
- package/dist/skills/zon-ui/references/components/meter.md +105 -0
- package/dist/skills/zon-ui/references/components/money-input.md +333 -0
- package/dist/skills/zon-ui/references/components/native-select.md +197 -0
- package/dist/skills/zon-ui/references/components/navigation-menu.md +253 -0
- package/dist/skills/zon-ui/references/components/number-field.md +210 -0
- package/dist/skills/zon-ui/references/components/number-roll.md +175 -0
- package/dist/skills/zon-ui/references/components/onboarding.md +896 -0
- package/dist/skills/zon-ui/references/components/otp-field.md +166 -0
- package/dist/skills/zon-ui/references/components/pagination.md +109 -0
- package/dist/skills/zon-ui/references/components/pdf-viewer.md +177 -0
- package/dist/skills/zon-ui/references/components/phone-input.md +252 -0
- package/dist/skills/zon-ui/references/components/popover.md +176 -0
- package/dist/skills/zon-ui/references/components/preview-card.md +193 -0
- package/dist/skills/zon-ui/references/components/pricing.md +724 -0
- package/dist/skills/zon-ui/references/components/progress.md +92 -0
- package/dist/skills/zon-ui/references/components/prompt-input.md +307 -0
- package/dist/skills/zon-ui/references/components/pull-to-refresh.md +188 -0
- package/dist/skills/zon-ui/references/components/quote.md +115 -0
- package/dist/skills/zon-ui/references/components/radio-group.md +215 -0
- package/dist/skills/zon-ui/references/components/rating.md +260 -0
- package/dist/skills/zon-ui/references/components/reasoning.md +102 -0
- package/dist/skills/zon-ui/references/components/resizable.md +213 -0
- package/dist/skills/zon-ui/references/components/response.md +170 -0
- package/dist/skills/zon-ui/references/components/scheduler.md +732 -0
- package/dist/skills/zon-ui/references/components/scroll-area.md +122 -0
- package/dist/skills/zon-ui/references/components/select.md +351 -0
- package/dist/skills/zon-ui/references/components/separator.md +103 -0
- package/dist/skills/zon-ui/references/components/settings.md +793 -0
- package/dist/skills/zon-ui/references/components/shop.md +1715 -0
- package/dist/skills/zon-ui/references/components/sidebar.md +813 -0
- package/dist/skills/zon-ui/references/components/sign-in.md +1639 -0
- package/dist/skills/zon-ui/references/components/site-header.md +303 -0
- package/dist/skills/zon-ui/references/components/skeleton.md +256 -0
- package/dist/skills/zon-ui/references/components/slider.md +172 -0
- package/dist/skills/zon-ui/references/components/sortable.md +405 -0
- package/dist/skills/zon-ui/references/components/sources.md +106 -0
- package/dist/skills/zon-ui/references/components/spinner.md +222 -0
- package/dist/skills/zon-ui/references/components/stat.md +267 -0
- package/dist/skills/zon-ui/references/components/stepper.md +285 -0
- package/dist/skills/zon-ui/references/components/suggestions.md +146 -0
- package/dist/skills/zon-ui/references/components/swipe-actions.md +344 -0
- package/dist/skills/zon-ui/references/components/switch.md +160 -0
- package/dist/skills/zon-ui/references/components/table.md +999 -0
- package/dist/skills/zon-ui/references/components/tabs.md +258 -0
- package/dist/skills/zon-ui/references/components/tag.md +115 -0
- package/dist/skills/zon-ui/references/components/tags-input.md +216 -0
- package/dist/skills/zon-ui/references/components/textarea.md +95 -0
- package/dist/skills/zon-ui/references/components/theme-editor.md +3940 -0
- package/dist/skills/zon-ui/references/components/theme.md +362 -0
- package/dist/skills/zon-ui/references/components/time-field.md +222 -0
- package/dist/skills/zon-ui/references/components/timeline.md +285 -0
- package/dist/skills/zon-ui/references/components/tippy.md +243 -0
- package/dist/skills/zon-ui/references/components/toast.md +220 -0
- package/dist/skills/zon-ui/references/components/toggle-group.md +261 -0
- package/dist/skills/zon-ui/references/components/toggle.md +167 -0
- package/dist/skills/zon-ui/references/components/tool-call.md +146 -0
- package/dist/skills/zon-ui/references/components/toolbar.md +260 -0
- package/dist/skills/zon-ui/references/components/tooltip.md +172 -0
- package/dist/skills/zon-ui/references/components/tour.md +423 -0
- package/dist/skills/zon-ui/references/components/tree.md +481 -0
- package/dist/skills/zon-ui/references/components/typography.md +347 -0
- package/dist/skills/zon-ui/references/components/video-player.md +386 -0
- package/dist/skills/zon-ui/references/marketing.md +467 -0
- package/dist/skills/zon-ui/references/motion.md +455 -0
- package/dist/skills/zon-ui/references/recipes.md +1232 -0
- package/dist/skills/zon-ui/references/tokens.md +866 -0
- package/dist/sources/accordion.css +4 -0
- package/dist/sources/action-sheet.css +11 -0
- package/dist/sources/alert-dialog.css +6 -0
- package/dist/sources/alert.css +3 -0
- package/dist/sources/app-bar.css +14 -0
- package/dist/sources/ascii-field.css +3 -0
- package/dist/sources/aspect-ratio.css +3 -0
- package/dist/sources/audio-player.css +20 -0
- package/dist/sources/avatar.css +3 -0
- package/dist/sources/badge.css +3 -0
- package/dist/sources/bottom-nav.css +9 -0
- package/dist/sources/breadcrumb.css +14 -0
- package/dist/sources/button-group.css +3 -0
- package/dist/sources/button.css +9 -0
- package/dist/sources/calendar.css +13 -0
- package/dist/sources/card.css +3 -0
- package/dist/sources/carousel.css +11 -0
- package/dist/sources/chart.css +5 -0
- package/dist/sources/checkbox.css +6 -0
- package/dist/sources/code-block.css +13 -0
- package/dist/sources/collapsible.css +4 -0
- package/dist/sources/color-picker.css +13 -0
- package/dist/sources/combobox.css +13 -0
- package/dist/sources/command.css +13 -0
- package/dist/sources/context-menu.css +12 -0
- package/dist/sources/conversation.css +10 -0
- package/dist/sources/copy-button.css +10 -0
- package/dist/sources/data-table.css +27 -0
- package/dist/sources/date-picker.css +20 -0
- package/dist/sources/dialog.css +9 -0
- package/dist/sources/direction.css +2 -0
- package/dist/sources/drawer.css +9 -0
- package/dist/sources/drawing.css +5 -0
- package/dist/sources/empty.css +3 -0
- package/dist/sources/feature-list.css +4 -0
- package/dist/sources/field.css +4 -0
- package/dist/sources/file-drop.css +15 -0
- package/dist/sources/filter-bar.css +30 -0
- package/dist/sources/form.css +4 -0
- package/dist/sources/graph.css +19 -0
- package/dist/sources/illustration.css +28 -0
- package/dist/sources/input-group.css +7 -0
- package/dist/sources/input.css +3 -0
- package/dist/sources/item.css +4 -0
- package/dist/sources/kbd.css +5 -0
- package/dist/sources/label.css +3 -0
- package/dist/sources/layout.css +3 -0
- package/dist/sources/lightbox.css +33 -0
- package/dist/sources/locale.css +2 -0
- package/dist/sources/logo.css +4 -0
- package/dist/sources/markdown-editor.css +41 -0
- package/dist/sources/mentions.css +13 -0
- package/dist/sources/menu.css +11 -0
- package/dist/sources/menubar.css +14 -0
- package/dist/sources/message.css +16 -0
- package/dist/sources/meter.css +4 -0
- package/dist/sources/money-input.css +10 -0
- package/dist/sources/native-select.css +4 -0
- package/dist/sources/navigation-menu.css +8 -0
- package/dist/sources/number-field.css +8 -0
- package/dist/sources/number-roll.css +6 -0
- package/dist/sources/otp-field.css +5 -0
- package/dist/sources/pagination.css +11 -0
- package/dist/sources/pdf-viewer.css +30 -0
- package/dist/sources/phone-input.css +20 -0
- package/dist/sources/popover.css +7 -0
- package/dist/sources/preview-card.css +7 -0
- package/dist/sources/progress.css +4 -0
- package/dist/sources/prompt-input.css +15 -0
- package/dist/sources/pull-to-refresh.css +14 -0
- package/dist/sources/quote.css +3 -0
- package/dist/sources/radio-group.css +5 -0
- package/dist/sources/rating.css +6 -0
- package/dist/sources/reasoning.css +6 -0
- package/dist/sources/resizable.css +4 -0
- package/dist/sources/response.css +16 -0
- package/dist/sources/scheduler.css +44 -0
- package/dist/sources/scroll-area.css +3 -0
- package/dist/sources/select.css +12 -0
- package/dist/sources/separator.css +3 -0
- package/dist/sources/sidebar.css +19 -0
- package/dist/sources/site-header.css +15 -0
- package/dist/sources/skeleton.css +3 -0
- package/dist/sources/slider.css +6 -0
- package/dist/sources/sortable.css +12 -0
- package/dist/sources/sources.css +6 -0
- package/dist/sources/spinner.css +6 -0
- package/dist/sources/stat.css +9 -0
- package/dist/sources/stepper.css +6 -0
- package/dist/sources/suggestions.css +10 -0
- package/dist/sources/swipe-actions.css +20 -0
- package/dist/sources/switch.css +5 -0
- package/dist/sources/table.css +7 -0
- package/dist/sources/tabs.css +5 -0
- package/dist/sources/tag.css +3 -0
- package/dist/sources/tags-input.css +6 -0
- package/dist/sources/textarea.css +3 -0
- package/dist/sources/theme.css +13 -0
- package/dist/sources/time-field.css +7 -0
- package/dist/sources/timeline.css +7 -0
- package/dist/sources/tippy.css +6 -0
- package/dist/sources/toast.css +6 -0
- package/dist/sources/toggle-group.css +5 -0
- package/dist/sources/toggle.css +3 -0
- package/dist/sources/tool-call.css +16 -0
- package/dist/sources/toolbar.css +14 -0
- package/dist/sources/tooltip.css +6 -0
- package/dist/sources/tour.css +14 -0
- package/dist/sources/tree.css +6 -0
- package/dist/sources/typography.css +4 -0
- package/dist/sources/video-player.css +21 -0
- package/dist/styles/ai.css +3 -0
- package/dist/styles/brand.css +98 -0
- package/dist/styles/core.css +266 -0
- package/dist/styles/editor.css +3 -0
- package/dist/styles/expressive.css +35 -56
- package/dist/styles/fonts.css +61 -117
- package/dist/styles/graph.css +4 -0
- package/dist/styles/illustration.css +4 -0
- package/dist/styles/index.css +11 -201
- package/dist/styles/material.css +138 -12
- package/dist/styles/parts/ai.css +18 -13
- package/dist/styles/parts/brand.css +2 -2
- package/dist/styles/parts/controls.css +29 -20
- package/dist/styles/parts/data.css +13 -9
- package/dist/styles/parts/editor.css +372 -0
- package/dist/styles/parts/feedback.css +32 -2
- package/dist/styles/parts/foundations.css +12 -7
- package/dist/styles/parts/graph.css +25 -9
- package/dist/styles/parts/inputs.css +172 -9
- package/dist/styles/parts/isometric.css +6 -5
- package/dist/styles/parts/navigation.css +206 -27
- package/dist/styles/parts/overlays.css +19 -4
- package/dist/styles/parts/pdf.css +2 -2
- package/dist/styles/pdf.css +3 -0
- package/dist/styles/prose.css +3 -0
- package/dist/styles/tokens.css +89 -14
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +5 -0
- package/dist/vite.d.ts +48 -59
- package/dist/vite.js +54 -21
- package/package.json +69 -2
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Theme presets: a zon theme as a short code of letters and digits, and the generator that turns
|
|
3
|
+
* the code back into token values for light and dark and a shape for both.
|
|
4
|
+
*
|
|
5
|
+
* Plain code with no React and no DOM, so a server layout, a build script or a CLI can
|
|
6
|
+
* expand a code. The theme editor (docs/theme-editor.demo.tsx) builds its themes with the same
|
|
7
|
+
* functions, so a code it shows always expands to the theme it shows.
|
|
8
|
+
*
|
|
9
|
+
* Format, version 1 (`Z1…`), letters and digits, read without regard to case:
|
|
10
|
+
*
|
|
11
|
+
* Z 1 <13 body chars> <8 chars per pinned token …> <1 check char>
|
|
12
|
+
*
|
|
13
|
+
* - the body is one number in base 36 (0–9, A–Z), the generator's inputs in mixed radix (see
|
|
14
|
+
* BODY): which seed colours were picked, the greys' tint and hue, the primary's colour and hue,
|
|
15
|
+
* the vividness and turn of the tones and status colours, the ground, and the stepped control
|
|
16
|
+
* height and corners
|
|
17
|
+
* - each colour pinned by hand adds 8 characters: the theme it belongs to, the token (an index into
|
|
18
|
+
* PIN_TOKENS) and its OKLCH lightness, chroma, hue and alpha
|
|
19
|
+
* - the check character is a weighted sum of the others, so a mistyped character is caught
|
|
20
|
+
*
|
|
21
|
+
* Version 1 is frozen: its fields, its steps, PIN_TOKENS, zon's base values (ZON) and the
|
|
22
|
+
* generator below always expand a `Z1` code to the same tokens. A change to any of them is a new
|
|
23
|
+
* version, decoded next to this one. Colours pinned by hand never move.
|
|
24
|
+
*/
|
|
25
|
+
const toLinear = (v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
26
|
+
const toGamma = (v) => (v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055);
|
|
27
|
+
const clamp = (v, min = 0, max = 1) => Math.min(max, Math.max(min, v));
|
|
28
|
+
/* "+ 0" turns -0 into 0, so a value reads back equal to itself. */
|
|
29
|
+
const round = (v, digits) => Number(v.toFixed(digits)) + 0;
|
|
30
|
+
/** OKLCH to linear sRGB, unclamped: a channel outside 0–1 means the colour is outside sRGB. */
|
|
31
|
+
function linearRgb({ l, c, h }) {
|
|
32
|
+
const a = c * Math.cos((h * Math.PI) / 180);
|
|
33
|
+
const b = c * Math.sin((h * Math.PI) / 180);
|
|
34
|
+
const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
35
|
+
const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
36
|
+
const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
37
|
+
return [
|
|
38
|
+
4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
|
|
39
|
+
-1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
|
|
40
|
+
-0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_,
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
function fromLinearRgb([r, g, b], alpha = 1) {
|
|
44
|
+
const l_ = Math.cbrt(0.4122214708 * r + 0.5363015719 * g + 0.0514459929 * b);
|
|
45
|
+
const m_ = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
46
|
+
const s_ = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
47
|
+
const L = 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_;
|
|
48
|
+
const A = 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_;
|
|
49
|
+
const B = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_;
|
|
50
|
+
const c = Math.hypot(A, B);
|
|
51
|
+
const h = c < 1e-4 ? 0 : ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360;
|
|
52
|
+
return { l: L, c: c < 1e-4 ? 0 : c, h, a: alpha };
|
|
53
|
+
}
|
|
54
|
+
const inGamut = (rgb) => rgb.every((v) => v >= -1e-4 && v <= 1 + 1e-4);
|
|
55
|
+
/** Keeps lightness and hue and lowers chroma until the colour fits in sRGB. */
|
|
56
|
+
function toGamut(color) {
|
|
57
|
+
if (inGamut(linearRgb(color)))
|
|
58
|
+
return color;
|
|
59
|
+
let lo = 0;
|
|
60
|
+
let hi = color.c;
|
|
61
|
+
for (let i = 0; i < 24; i++) {
|
|
62
|
+
const mid = (lo + hi) / 2;
|
|
63
|
+
if (inGamut(linearRgb({ ...color, c: mid })))
|
|
64
|
+
lo = mid;
|
|
65
|
+
else
|
|
66
|
+
hi = mid;
|
|
67
|
+
}
|
|
68
|
+
return { ...color, c: lo };
|
|
69
|
+
}
|
|
70
|
+
function srgb(color) {
|
|
71
|
+
const [r, g, b] = linearRgb(toGamut(color));
|
|
72
|
+
return [toGamma(clamp(r)), toGamma(clamp(g)), toGamma(clamp(b))];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A colour as CSS: `oklch(0.52 0.15 250)` (lightness, chroma and hue to 3, 3 and 1 places, as
|
|
76
|
+
* tokens.css writes them), or `#rrggbb[aa]`, with chroma lowered until it fits in sRGB.
|
|
77
|
+
*/
|
|
78
|
+
export function formatThemeColor(color, format = "oklch") {
|
|
79
|
+
if (format === "hex") {
|
|
80
|
+
const channels = [...srgb(color), ...(color.a < 1 ? [color.a] : [])];
|
|
81
|
+
return `#${channels
|
|
82
|
+
.map((v) => Math.round(clamp(v) * 255)
|
|
83
|
+
.toString(16)
|
|
84
|
+
.padStart(2, "0"))
|
|
85
|
+
.join("")}`;
|
|
86
|
+
}
|
|
87
|
+
const { l, c, h, a } = color;
|
|
88
|
+
const body = `${round(l, 3)} ${round(c, 3)} ${c < 0.0005 ? 0 : round(h, 1)}`;
|
|
89
|
+
return a < 1 ? `oklch(${body} / ${Math.round(a * 100)}%)` : `oklch(${body})`;
|
|
90
|
+
}
|
|
91
|
+
function isColor(value) {
|
|
92
|
+
return (typeof value === "object" &&
|
|
93
|
+
value !== null &&
|
|
94
|
+
["l", "c", "h", "a"].every((key) => Number.isFinite(value[key])));
|
|
95
|
+
}
|
|
96
|
+
/** The CSS colour names, as `name:rrggbb`, for parseThemeColor. */
|
|
97
|
+
const CSS_NAMES = "aliceblue:f0f8ff antiquewhite:faebd7 aqua:00ffff aquamarine:7fffd4 azure:f0ffff beige:f5f5dc " +
|
|
98
|
+
"bisque:ffe4c4 black:000000 blanchedalmond:ffebcd blue:0000ff blueviolet:8a2be2 brown:a52a2a " +
|
|
99
|
+
"burlywood:deb887 cadetblue:5f9ea0 chartreuse:7fff00 chocolate:d2691e coral:ff7f50 " +
|
|
100
|
+
"cornflowerblue:6495ed cornsilk:fff8dc crimson:dc143c cyan:00ffff darkblue:00008b darkcyan:008b8b " +
|
|
101
|
+
"darkgoldenrod:b8860b darkgray:a9a9a9 darkgreen:006400 darkgrey:a9a9a9 darkkhaki:bdb76b " +
|
|
102
|
+
"darkmagenta:8b008b darkolivegreen:556b2f darkorange:ff8c00 darkorchid:9932cc darkred:8b0000 " +
|
|
103
|
+
"darksalmon:e9967a darkseagreen:8fbc8f darkslateblue:483d8b darkslategray:2f4f4f " +
|
|
104
|
+
"darkslategrey:2f4f4f darkturquoise:00ced1 darkviolet:9400d3 deeppink:ff1493 deepskyblue:00bfff " +
|
|
105
|
+
"dimgray:696969 dimgrey:696969 dodgerblue:1e90ff firebrick:b22222 floralwhite:fffaf0 " +
|
|
106
|
+
"forestgreen:228b22 fuchsia:ff00ff gainsboro:dcdcdc ghostwhite:f8f8ff gold:ffd700 " +
|
|
107
|
+
"goldenrod:daa520 gray:808080 green:008000 greenyellow:adff2f grey:808080 honeydew:f0fff0 " +
|
|
108
|
+
"hotpink:ff69b4 indianred:cd5c5c indigo:4b0082 ivory:fffff0 khaki:f0e68c lavender:e6e6fa " +
|
|
109
|
+
"lavenderblush:fff0f5 lawngreen:7cfc00 lemonchiffon:fffacd lightblue:add8e6 lightcoral:f08080 " +
|
|
110
|
+
"lightcyan:e0ffff lightgoldenrodyellow:fafad2 lightgray:d3d3d3 lightgreen:90ee90 lightgrey:d3d3d3 " +
|
|
111
|
+
"lightpink:ffb6c1 lightsalmon:ffa07a lightseagreen:20b2aa lightskyblue:87cefa " +
|
|
112
|
+
"lightslategray:778899 lightslategrey:778899 lightsteelblue:b0c4de lightyellow:ffffe0 lime:00ff00 " +
|
|
113
|
+
"limegreen:32cd32 linen:faf0e6 magenta:ff00ff maroon:800000 mediumaquamarine:66cdaa " +
|
|
114
|
+
"mediumblue:0000cd mediumorchid:ba55d3 mediumpurple:9370db mediumseagreen:3cb371 " +
|
|
115
|
+
"mediumslateblue:7b68ee mediumspringgreen:00fa9a mediumturquoise:48d1cc mediumvioletred:c71585 " +
|
|
116
|
+
"midnightblue:191970 mintcream:f5fffa mistyrose:ffe4e1 moccasin:ffe4b5 navajowhite:ffdead " +
|
|
117
|
+
"navy:000080 oldlace:fdf5e6 olive:808000 olivedrab:6b8e23 orange:ffa500 orangered:ff4500 " +
|
|
118
|
+
"orchid:da70d6 palegoldenrod:eee8aa palegreen:98fb98 paleturquoise:afeeee palevioletred:db7093 " +
|
|
119
|
+
"papayawhip:ffefd5 peachpuff:ffdab9 peru:cd853f pink:ffc0cb plum:dda0dd powderblue:b0e0e6 " +
|
|
120
|
+
"purple:800080 rebeccapurple:663399 red:ff0000 rosybrown:bc8f8f royalblue:4169e1 " +
|
|
121
|
+
"saddlebrown:8b4513 salmon:fa8072 sandybrown:f4a460 seagreen:2e8b57 seashell:fff5ee sienna:a0522d " +
|
|
122
|
+
"silver:c0c0c0 skyblue:87ceeb slateblue:6a5acd slategray:708090 slategrey:708090 snow:fffafa " +
|
|
123
|
+
"springgreen:00ff7f steelblue:4682b4 tan:d2b48c teal:008080 thistle:d8bfd8 tomato:ff6347 " +
|
|
124
|
+
"turquoise:40e0d0 violet:ee82ee wheat:f5deb3 white:ffffff whitesmoke:f5f5f5 yellow:ffff00 " +
|
|
125
|
+
"yellowgreen:9acd32";
|
|
126
|
+
let cssNames;
|
|
127
|
+
const namedHex = (name) => (cssNames ??= new Map(CSS_NAMES.split(" ").map((pair) => pair.split(":")))).get(name);
|
|
128
|
+
const fromSrgb = (r, g, b, alpha) => fromLinearRgb([toLinear(clamp(r)), toLinear(clamp(g)), toLinear(clamp(b))], clamp(alpha));
|
|
129
|
+
/** An alpha as CSS writes it: a number 0–1 or a percent; 1 when missing. */
|
|
130
|
+
const alphaOf = (value) => value === undefined ? 1 : value.endsWith("%") ? Number(value.slice(0, -1)) / 100 : Number(value);
|
|
131
|
+
/** The arguments of `name(…)`, split on commas, spaces and the slash before alpha. */
|
|
132
|
+
function cssArgs(value, names) {
|
|
133
|
+
const match = /^([a-z]+)\(\s*(.*?)\s*\)$/.exec(value);
|
|
134
|
+
if (!match || !names.includes(match[1]))
|
|
135
|
+
return null;
|
|
136
|
+
const args = match[2].split(/\s*[,/]\s*|\s+/).filter(Boolean);
|
|
137
|
+
return args.length === 3 || args.length === 4 ? args : null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Reads a CSS colour: `oklch(…)` (lightness as a number or a percent, optional `/ alpha`),
|
|
141
|
+
* `#rgb[a]`, `#rrggbb[aa]`, `rgb()`/`rgba()`, `hsl()`/`hsla()` (with commas or spaces) and the
|
|
142
|
+
* CSS colour names (`teal`, `rebeccapurple`). Null if it is none of them.
|
|
143
|
+
*/
|
|
144
|
+
export function parseThemeColor(input) {
|
|
145
|
+
const value = input.trim().toLowerCase();
|
|
146
|
+
const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(value)?.[1] ?? namedHex(value);
|
|
147
|
+
if (hex) {
|
|
148
|
+
const full = hex.length <= 4 ? [...hex].map((d) => d + d).join("") : hex;
|
|
149
|
+
const [r = 0, g = 0, b = 0, a = 255] = full.match(/../g).map((p) => parseInt(p, 16));
|
|
150
|
+
return fromLinearRgb([toLinear(r / 255), toLinear(g / 255), toLinear(b / 255)], a / 255);
|
|
151
|
+
}
|
|
152
|
+
const rgb = cssArgs(value, ["rgb", "rgba"]);
|
|
153
|
+
if (rgb) {
|
|
154
|
+
const [r, g, b] = rgb
|
|
155
|
+
.slice(0, 3)
|
|
156
|
+
.map((v) => (v.endsWith("%") ? Number(v.slice(0, -1)) / 100 : Number(v) / 255));
|
|
157
|
+
const color = fromSrgb(r, g, b, alphaOf(rgb[3]));
|
|
158
|
+
return [r, g, b].every(Number.isFinite) && isColor(color) ? color : null;
|
|
159
|
+
}
|
|
160
|
+
const hsl = cssArgs(value, ["hsl", "hsla"]);
|
|
161
|
+
if (hsl) {
|
|
162
|
+
const h = ((Number(hsl[0].replace(/deg$/, "")) % 360) + 360) % 360;
|
|
163
|
+
const [s, l] = hsl.slice(1, 3).map((v) => Number(v.replace(/%$/, "")) / 100);
|
|
164
|
+
const k = (n) => (n + h / 30) % 12;
|
|
165
|
+
const f = (n) => l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
|
|
166
|
+
if (![h, s, l].every(Number.isFinite))
|
|
167
|
+
return null;
|
|
168
|
+
const color = fromSrgb(f(0), f(8), f(4), alphaOf(hsl[3]));
|
|
169
|
+
return isColor(color) ? color : null;
|
|
170
|
+
}
|
|
171
|
+
const ok = /^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*(?:\/\s*([\d.]+)(%?))?\s*\)$/.exec(value);
|
|
172
|
+
if (!ok)
|
|
173
|
+
return null;
|
|
174
|
+
const [, l = "0", lp, c = "0", h = "0", a, ap] = ok;
|
|
175
|
+
const color = {
|
|
176
|
+
l: clamp(Number(l) / (lp ? 100 : 1)),
|
|
177
|
+
c: Number(c),
|
|
178
|
+
h: Number(h) % 360,
|
|
179
|
+
a: a === undefined ? 1 : clamp(Number(a) / (ap ? 100 : 1)),
|
|
180
|
+
};
|
|
181
|
+
return isColor(color) ? color : null;
|
|
182
|
+
}
|
|
183
|
+
/** A colour with alpha, laid over an opaque one, as the screen shows it. */
|
|
184
|
+
function over(top, bottom) {
|
|
185
|
+
const t = srgb(top);
|
|
186
|
+
const b = srgb(bottom);
|
|
187
|
+
return [0, 1, 2].map((i) => t[i] * top.a + b[i] * (1 - top.a));
|
|
188
|
+
}
|
|
189
|
+
const luminance = ([r, g, b]) => 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
190
|
+
/** The WCAG 2 contrast ratio of a colour (its alpha included) on an opaque ground: 1 to 21. */
|
|
191
|
+
export function themeContrast(fg, bg) {
|
|
192
|
+
const a = luminance(over(fg, bg));
|
|
193
|
+
const b = luminance(srgb(bg));
|
|
194
|
+
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
|
195
|
+
}
|
|
196
|
+
/** The nearest lightness, darker or lighter, at which `fg` reaches `min` on `bg`. Null if none does. */
|
|
197
|
+
export function fixThemeContrast(fg, bg, min) {
|
|
198
|
+
for (let step = 0; step <= 200; step++) {
|
|
199
|
+
for (const l of [fg.l - step * 0.005, fg.l + step * 0.005]) {
|
|
200
|
+
if (l < 0 || l > 1)
|
|
201
|
+
continue;
|
|
202
|
+
const next = { ...fg, l };
|
|
203
|
+
if (themeContrast(next, bg) >= min)
|
|
204
|
+
return next;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const TEXT = 4.5;
|
|
210
|
+
const onPage = { token: "--background", min: TEXT };
|
|
211
|
+
/* Status colours and tones mark rows and tags too, so they must read on the hovered and selected
|
|
212
|
+
fill: the darkest grey a light theme puts under text, and the lightest a dark one does. */
|
|
213
|
+
const onSelected = { token: "--control-hover", min: TEXT };
|
|
214
|
+
/* The grey grounds text sits on: the page, a raised surface, the hovered and selected fill, a menu
|
|
215
|
+
and the inside of a field (tokens.css). */
|
|
216
|
+
const GROUNDS = ["--background", "--control-surface", "--control-hover", "--control-menu", "--field-surface"];
|
|
217
|
+
/** The colour tokens a theme sets, grouped as in tokens.css. */
|
|
218
|
+
export const themeTokenGroups = [
|
|
219
|
+
{
|
|
220
|
+
title: "Canvas & ink",
|
|
221
|
+
tokens: [
|
|
222
|
+
{ name: "--background", label: "Page ground", kind: "neutral" },
|
|
223
|
+
{
|
|
224
|
+
name: "--foreground",
|
|
225
|
+
label: "Headlines and essential text",
|
|
226
|
+
kind: "neutral",
|
|
227
|
+
on: onPage,
|
|
228
|
+
alsoOn: GROUNDS,
|
|
229
|
+
},
|
|
230
|
+
{ name: "--foreground-soft", label: "Secondary text", kind: "neutral", on: onPage, alsoOn: GROUNDS },
|
|
231
|
+
{
|
|
232
|
+
name: "--muted-foreground",
|
|
233
|
+
label: "Captions and supporting copy",
|
|
234
|
+
kind: "neutral",
|
|
235
|
+
on: onPage,
|
|
236
|
+
// Captions sit on the page, in menus and in fields; zon's own grey is under 4.5:1 on a
|
|
237
|
+
// raised surface and the hovered fill in light, so those are not asked of it.
|
|
238
|
+
alsoOn: ["--control-menu", "--field-surface"],
|
|
239
|
+
},
|
|
240
|
+
{ name: "--border", label: "Hairlines and dividers", kind: "neutral" },
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
title: "Primary",
|
|
245
|
+
tokens: [
|
|
246
|
+
{ name: "--primary-fill", label: "The primary button", kind: "accent" },
|
|
247
|
+
{
|
|
248
|
+
name: "--primary-text",
|
|
249
|
+
label: "Label on the primary button",
|
|
250
|
+
kind: "neutral",
|
|
251
|
+
on: { token: "--primary-fill", min: TEXT },
|
|
252
|
+
},
|
|
253
|
+
{ name: "--primary", label: "Checked switches, boxes and radios", kind: "accent" },
|
|
254
|
+
{
|
|
255
|
+
name: "--primary-foreground",
|
|
256
|
+
label: "Tick and thumb on a checked control",
|
|
257
|
+
kind: "neutral",
|
|
258
|
+
on: { token: "--primary", min: 3 },
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "--control-focus",
|
|
262
|
+
label: "The 2px focus outline",
|
|
263
|
+
kind: "accent",
|
|
264
|
+
on: { token: "--background", min: 3 },
|
|
265
|
+
alsoOn: GROUNDS,
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
title: "Material",
|
|
271
|
+
tokens: [
|
|
272
|
+
{ name: "--control-surface", label: "Raised controls at rest", kind: "neutral" },
|
|
273
|
+
{ name: "--control-hover", label: "Hovered and current fill", kind: "neutral" },
|
|
274
|
+
{ name: "--control-menu", label: "Menus, popovers and toasts", kind: "neutral" },
|
|
275
|
+
{ name: "--field-surface", label: "Inside a field", kind: "neutral" },
|
|
276
|
+
{ name: "--field-edge", label: "Field outline and card edge", kind: "neutral" },
|
|
277
|
+
{
|
|
278
|
+
name: "--control-muted",
|
|
279
|
+
label: "Placeholders and quiet segments",
|
|
280
|
+
kind: "neutral",
|
|
281
|
+
on: { token: "--field-surface", min: TEXT },
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
title: "Data",
|
|
287
|
+
tokens: [1, 2, 3, 4, 5].map((n) => ({
|
|
288
|
+
name: `--chart-${n}`,
|
|
289
|
+
label: n === 1 ? "The first series, strongest" : `Series ${n}`,
|
|
290
|
+
kind: "neutral",
|
|
291
|
+
})),
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
title: "Status",
|
|
295
|
+
tokens: [
|
|
296
|
+
{ name: "--success", label: "Saved, sent, connected", kind: "status", on: onSelected, alsoOn: GROUNDS },
|
|
297
|
+
{ name: "--warning", label: "Needs attention soon", kind: "status", on: onSelected, alsoOn: GROUNDS },
|
|
298
|
+
{
|
|
299
|
+
name: "--info",
|
|
300
|
+
label: "Selected, new, in progress",
|
|
301
|
+
kind: "status",
|
|
302
|
+
on: onSelected,
|
|
303
|
+
alsoOn: GROUNDS,
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "--destructive",
|
|
307
|
+
label: "Errors and destructive actions",
|
|
308
|
+
kind: "status",
|
|
309
|
+
on: onSelected,
|
|
310
|
+
alsoOn: GROUNDS,
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
title: "Category tones",
|
|
316
|
+
tokens: ["blue", "aqua", "violet", "magenta", "orange", "lime"].map((tone) => ({
|
|
317
|
+
name: `--tone-${tone}`,
|
|
318
|
+
label: "A kind people tell apart",
|
|
319
|
+
kind: "tone",
|
|
320
|
+
on: onSelected,
|
|
321
|
+
alsoOn: GROUNDS,
|
|
322
|
+
})),
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
const specs = themeTokenGroups.flatMap((g) => g.tokens);
|
|
326
|
+
/** Tokens that follow another one: same chroma and hue, the same lightness step as in zon. */
|
|
327
|
+
const derived = [
|
|
328
|
+
{ name: "--primary-fill-hover", from: "--primary-fill" },
|
|
329
|
+
{ name: "--primary-fill-pressed", from: "--primary-fill" },
|
|
330
|
+
{ name: "--control-pressed", from: "--control-hover" },
|
|
331
|
+
{ name: "--card-foreground", from: "--foreground" },
|
|
332
|
+
{ name: "--popover-foreground", from: "--foreground" },
|
|
333
|
+
];
|
|
334
|
+
const allNames = [...specs.map((s) => s.name), ...derived.map((d) => d.name)];
|
|
335
|
+
/**
|
|
336
|
+
* zon's own values for the tokens a theme sets, as tokens.css writes them for `.theme-light` and
|
|
337
|
+
* `.theme-dark`. Frozen for version 1; a unit test checks them against tokens.css, so a change to
|
|
338
|
+
* zon's colours is a decision about the preset format too.
|
|
339
|
+
*/
|
|
340
|
+
const ZON = {
|
|
341
|
+
light: {
|
|
342
|
+
"--background": "oklch(0.99 0 0)",
|
|
343
|
+
"--foreground": "oklch(0.145 0 0)",
|
|
344
|
+
"--foreground-soft": "oklch(0.37 0 0)",
|
|
345
|
+
"--muted-foreground": "oklch(0.556 0 0)",
|
|
346
|
+
"--border": "oklch(0.922 0 0)",
|
|
347
|
+
"--primary-fill": "#292929",
|
|
348
|
+
"--primary-text": "#fafafa",
|
|
349
|
+
"--primary": "oklch(0.205 0 0)",
|
|
350
|
+
"--primary-foreground": "oklch(0.985 0 0)",
|
|
351
|
+
"--control-focus": "#737373",
|
|
352
|
+
"--control-surface": "#f5f5f5",
|
|
353
|
+
"--control-hover": "#ebebeb",
|
|
354
|
+
"--control-menu": "#fafafa",
|
|
355
|
+
"--field-surface": "#ffffff",
|
|
356
|
+
"--field-edge": "#d4d4d4",
|
|
357
|
+
"--control-muted": "#737373",
|
|
358
|
+
"--chart-1": "oklch(0.205 0 0)",
|
|
359
|
+
"--chart-2": "oklch(0.38 0 0)",
|
|
360
|
+
"--chart-3": "oklch(0.52 0 0)",
|
|
361
|
+
"--chart-4": "oklch(0.66 0 0)",
|
|
362
|
+
"--chart-5": "oklch(0.8 0 0)",
|
|
363
|
+
"--success": "oklch(0.505 0.133 152)",
|
|
364
|
+
"--warning": "oklch(0.53 0.12 65)",
|
|
365
|
+
"--info": "oklch(0.52 0.15 250)",
|
|
366
|
+
"--destructive": "oklch(0.55 0.224 27.325)",
|
|
367
|
+
"--tone-blue": "oklch(0.52 0.15 250)",
|
|
368
|
+
"--tone-aqua": "oklch(0.51 0.09 195)",
|
|
369
|
+
"--tone-violet": "oklch(0.53 0.17 300)",
|
|
370
|
+
"--tone-magenta": "oklch(0.54 0.2 340)",
|
|
371
|
+
"--tone-orange": "oklch(0.535 0.153 45)",
|
|
372
|
+
"--tone-lime": "oklch(0.51 0.13 130)",
|
|
373
|
+
"--primary-fill-hover": "#383838",
|
|
374
|
+
"--primary-fill-pressed": "#232323",
|
|
375
|
+
"--control-pressed": "#e4e4e4",
|
|
376
|
+
"--card-foreground": "oklch(0.145 0 0)",
|
|
377
|
+
"--popover-foreground": "oklch(0.145 0 0)",
|
|
378
|
+
},
|
|
379
|
+
dark: {
|
|
380
|
+
"--background": "oklch(0.07 0 0)",
|
|
381
|
+
"--foreground": "oklch(0.985 0 0)",
|
|
382
|
+
"--foreground-soft": "oklch(0.75 0 0)",
|
|
383
|
+
"--muted-foreground": "oklch(0.66 0 0)",
|
|
384
|
+
"--border": "oklch(1 0 0 / 10%)",
|
|
385
|
+
"--primary-fill": "#cbcbcb",
|
|
386
|
+
"--primary-text": "#171717",
|
|
387
|
+
"--primary": "oklch(0.985 0 0)",
|
|
388
|
+
"--primary-foreground": "oklch(0.145 0 0)",
|
|
389
|
+
"--control-focus": "#999999",
|
|
390
|
+
"--control-surface": "#1e1e1e",
|
|
391
|
+
"--control-hover": "#2a2a2a",
|
|
392
|
+
"--control-menu": "#1e1e1e",
|
|
393
|
+
"--field-surface": "#161616",
|
|
394
|
+
"--field-edge": "#393939",
|
|
395
|
+
"--control-muted": "#a3a3a3",
|
|
396
|
+
"--chart-1": "oklch(0.985 0 0)",
|
|
397
|
+
"--chart-2": "oklch(0.8 0 0)",
|
|
398
|
+
"--chart-3": "oklch(0.66 0 0)",
|
|
399
|
+
"--chart-4": "oklch(0.52 0 0)",
|
|
400
|
+
"--chart-5": "oklch(0.38 0 0)",
|
|
401
|
+
"--success": "oklch(0.76 0.16 152)",
|
|
402
|
+
"--warning": "oklch(0.78 0.15 75)",
|
|
403
|
+
"--info": "oklch(0.74 0.14 245)",
|
|
404
|
+
"--destructive": "oklch(0.704 0.191 22.216)",
|
|
405
|
+
"--tone-blue": "oklch(0.74 0.14 245)",
|
|
406
|
+
"--tone-aqua": "oklch(0.78 0.12 195)",
|
|
407
|
+
"--tone-violet": "oklch(0.75 0.15 300)",
|
|
408
|
+
"--tone-magenta": "oklch(0.74 0.18 340)",
|
|
409
|
+
"--tone-orange": "oklch(0.76 0.15 50)",
|
|
410
|
+
"--tone-lime": "oklch(0.8 0.16 130)",
|
|
411
|
+
"--primary-fill-hover": "#d5d5d5",
|
|
412
|
+
"--primary-fill-pressed": "#b9b9b9",
|
|
413
|
+
"--control-pressed": "#1e1e1e",
|
|
414
|
+
"--card-foreground": "oklch(0.985 0 0)",
|
|
415
|
+
"--popover-foreground": "oklch(0.985 0 0)",
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
/** zon's own colours as tokens.css writes them, by theme: the ground every preset is generated from. */
|
|
419
|
+
export const zonThemeTokens = ZON;
|
|
420
|
+
const parsePalette = (values) => Object.fromEntries(Object.entries(values).map(([name, value]) => [name, parseThemeColor(value)]));
|
|
421
|
+
let zonPalettes;
|
|
422
|
+
const zonPalette = (mode) => (zonPalettes ??= { light: parsePalette(ZON.light), dark: parsePalette(ZON.dark) })[mode];
|
|
423
|
+
/** The default control heights a theme can set, in px: zon's 38 in the middle, 4px apart. */
|
|
424
|
+
export const THEME_HEIGHTS = [30, 34, 38, 42, 46];
|
|
425
|
+
/** How round the corners can be, as a share of zon's button radius, in steps of 25%. */
|
|
426
|
+
export const THEME_CORNERS = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
|
427
|
+
const zonSettings = {
|
|
428
|
+
tint: 0,
|
|
429
|
+
tintHue: 250,
|
|
430
|
+
accent: 0,
|
|
431
|
+
accentHue: 250,
|
|
432
|
+
vivid: 1,
|
|
433
|
+
toneShift: 0,
|
|
434
|
+
statusShift: 0,
|
|
435
|
+
ground: 0,
|
|
436
|
+
};
|
|
437
|
+
/** zon's own theme as a preset: `encodeThemePreset(zonThemePreset)` is its code. */
|
|
438
|
+
export const zonThemePreset = {
|
|
439
|
+
settings: zonSettings,
|
|
440
|
+
shape: { controlHeight: 38, corners: 1 },
|
|
441
|
+
seeds: { base: false, theme: false, accent: false },
|
|
442
|
+
pinned: { light: {}, dark: {} },
|
|
443
|
+
};
|
|
444
|
+
/** How far the ground moves at 1: down in light, up in dark, where there is more room. */
|
|
445
|
+
const GROUND = { light: -0.045, dark: 0.12 };
|
|
446
|
+
/* ── Generation ─────────────────────────────────────────────────────────────── */
|
|
447
|
+
const mix = (a, b, t) => a + (b - a) * t;
|
|
448
|
+
/** One palette from zon's values and the settings; colours pinned by hand are laid on top later. */
|
|
449
|
+
function generate(base, s, mode) {
|
|
450
|
+
const out = {};
|
|
451
|
+
for (const spec of specs) {
|
|
452
|
+
const def = base[spec.name];
|
|
453
|
+
if (!def)
|
|
454
|
+
continue;
|
|
455
|
+
let next = def;
|
|
456
|
+
if (spec.kind === "neutral") {
|
|
457
|
+
// Surfaces, edges and charts move with the ground; text keeps zon's lightness, and the
|
|
458
|
+
// contrast pass moves it only if it has to.
|
|
459
|
+
const surface = !spec.on && def.a === 1;
|
|
460
|
+
const l = surface ? clamp(def.l + GROUND[mode] * s.ground) : def.l;
|
|
461
|
+
// The same chroma all but vanishes near black, so darker surfaces take more of it (within
|
|
462
|
+
// what sRGB can show): a dark ground reads as tinted, not as black.
|
|
463
|
+
const c = surface ? s.tint * (1 + 2 * (1 - l)) : s.tint;
|
|
464
|
+
next = surface ? toGamut({ ...def, l, c, h: s.tintHue }) : { ...def, l, c, h: s.tintHue };
|
|
465
|
+
}
|
|
466
|
+
if (spec.kind === "accent") {
|
|
467
|
+
// A coloured primary needs room to show its colour: near black or white there is none.
|
|
468
|
+
const l = mix(def.l, clamp(def.l, 0.45, 0.74), s.accent);
|
|
469
|
+
next = { ...def, l, c: Math.max(s.tint, s.accent * 0.19), h: s.accent > 0 ? s.accentHue : s.tintHue };
|
|
470
|
+
}
|
|
471
|
+
if (spec.kind === "status")
|
|
472
|
+
next = { ...def, c: def.c * s.vivid, h: (def.h + s.statusShift + 360) % 360 };
|
|
473
|
+
if (spec.kind === "tone")
|
|
474
|
+
next = { ...def, c: def.c * s.vivid, h: (def.h + s.toneShift + 360) % 360 };
|
|
475
|
+
out[spec.name] = next;
|
|
476
|
+
}
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
479
|
+
/** The lowest ratio `fg` reaches on any of `grounds`. */
|
|
480
|
+
const leastContrast = (fg, grounds) => Math.min(...grounds.map((ground) => themeContrast(fg, ground)));
|
|
481
|
+
/** As fixThemeContrast, on every ground at once: the nearest lightness that reads on all of them. */
|
|
482
|
+
function fixContrastOn(fg, grounds, min) {
|
|
483
|
+
for (let step = 0; step <= 200; step++) {
|
|
484
|
+
for (const l of [fg.l - step * 0.005, fg.l + step * 0.005]) {
|
|
485
|
+
if (l < 0 || l > 1)
|
|
486
|
+
continue;
|
|
487
|
+
const next = { ...fg, l };
|
|
488
|
+
if (leastContrast(next, grounds) >= min)
|
|
489
|
+
return next;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return null;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Generated text below its ratio, on its own ground or any other it sits on (`alsoOn`), moves
|
|
496
|
+
* lightness, darker or lighter, until it reads on all of them (or, if no lightness does, on its own). Colours set by hand stay exactly as
|
|
497
|
+
* set, and so does a colour zon ships unchanged on grounds zon ships unchanged.
|
|
498
|
+
*/
|
|
499
|
+
function keepContrast(palette, base, pinned) {
|
|
500
|
+
const out = { ...palette };
|
|
501
|
+
const same = (a, b) => !!a && !!b && formatThemeColor(a) === formatThemeColor(b);
|
|
502
|
+
for (const spec of specs) {
|
|
503
|
+
const color = out[spec.name];
|
|
504
|
+
if (!spec.on || spec.name in pinned || !color)
|
|
505
|
+
continue;
|
|
506
|
+
const names = [spec.on.token, ...(spec.alsoOn ?? []).filter((name) => name !== spec.on.token)];
|
|
507
|
+
const grounds = names.map((name) => out[name]).filter((g) => !!g);
|
|
508
|
+
if (grounds.length !== names.length)
|
|
509
|
+
continue;
|
|
510
|
+
const untouched = same(color, base[spec.name]) && names.every((name) => same(out[name], base[name]));
|
|
511
|
+
if (untouched || leastContrast(color, grounds) >= spec.on.min)
|
|
512
|
+
continue;
|
|
513
|
+
// Grounds pinned far apart (a dark page under light fields) may leave no lightness that reads
|
|
514
|
+
// on all of them: then it reads on its own ground at least.
|
|
515
|
+
out[spec.name] =
|
|
516
|
+
fixContrastOn(color, grounds, spec.on.min) ??
|
|
517
|
+
fixThemeContrast(color, grounds[0], spec.on.min) ??
|
|
518
|
+
color;
|
|
519
|
+
}
|
|
520
|
+
return out;
|
|
521
|
+
}
|
|
522
|
+
function withDerived(palette, base) {
|
|
523
|
+
const out = { ...palette };
|
|
524
|
+
for (const { name, from } of derived) {
|
|
525
|
+
const source = palette[from];
|
|
526
|
+
const def = base[name];
|
|
527
|
+
const defSource = base[from];
|
|
528
|
+
if (!source || !def || !defSource)
|
|
529
|
+
continue;
|
|
530
|
+
out[name] = { ...source, l: clamp(source.l + def.l - defSource.l), a: def.a };
|
|
531
|
+
}
|
|
532
|
+
return out;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Every colour token of one theme (light or dark) for a preset: generated from zon's values and
|
|
536
|
+
* the settings, text moved until it reaches its contrast, colours pinned by hand laid on top, and
|
|
537
|
+
* the hover, pressed and card inks following their token.
|
|
538
|
+
*/
|
|
539
|
+
export function themePalette(preset, mode) {
|
|
540
|
+
const base = zonPalette(mode);
|
|
541
|
+
const pinned = preset.pinned[mode] ?? {};
|
|
542
|
+
return withDerived(keepContrast({ ...generate(base, preset.settings, mode), ...pinned }, base, pinned), base);
|
|
543
|
+
}
|
|
544
|
+
/* ── Shape ──────────────────────────────────────────────────────────────────── */
|
|
545
|
+
/**
|
|
546
|
+
* zon's radii as offsets from the button's 12px: nested shapes keep the same gap between their
|
|
547
|
+
* edges at any size, so a card stays 8px rounder than the buttons in it and a checkbox 7px less.
|
|
548
|
+
*/
|
|
549
|
+
const RADIUS_OFFSETS = {
|
|
550
|
+
"--radius-button": 0,
|
|
551
|
+
"--radius-control": -2,
|
|
552
|
+
"--radius-item": -5,
|
|
553
|
+
"--radius-checkbox": -7,
|
|
554
|
+
"--radius-card": 8,
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* The radii for a corners step: the button's 12px scaled by it, the others at their fixed offsets
|
|
558
|
+
* from it (never below 0). At 0 every radius is 0, the card too: square buttons, square cards.
|
|
559
|
+
*/
|
|
560
|
+
function themeRadii(corners) {
|
|
561
|
+
const button = Math.round(12 * corners);
|
|
562
|
+
return Object.fromEntries(Object.entries(RADIUS_OFFSETS).map(([name, offset]) => [
|
|
563
|
+
name,
|
|
564
|
+
button === 0 ? 0 : Math.max(0, button + offset),
|
|
565
|
+
]));
|
|
566
|
+
}
|
|
567
|
+
/** An even number of px, the step every control height moves in. */
|
|
568
|
+
const even = (v) => Math.round(v / 2) * 2;
|
|
569
|
+
/** The dense, default and prominent heights for a default height: zon's 30 / 38 / 46, scaled. */
|
|
570
|
+
export function themeHeights(height) {
|
|
571
|
+
return { sm: even((height * 30) / 38), default: height, lg: even((height * 46) / 38) };
|
|
572
|
+
}
|
|
573
|
+
/** The density factor (`--density`) for a default control height in px: 1 at zon's 38px, 0.79 at 30, 1.21 at 46. */
|
|
574
|
+
export function themeDensity(height) {
|
|
575
|
+
return Math.round((height / 38) * 1000) / 1000;
|
|
576
|
+
}
|
|
577
|
+
/** A shape as zon's geometry tokens: the density, the three control heights, the round icon button 2px under the default, the inset controls and the radii. */
|
|
578
|
+
export function themeShapeTokens({ controlHeight, corners }) {
|
|
579
|
+
const height = controlHeight ?? 38;
|
|
580
|
+
const h = themeHeights(height);
|
|
581
|
+
return {
|
|
582
|
+
"--density": `${themeDensity(height)}`,
|
|
583
|
+
"--control-h-sm": `${h.sm}px`,
|
|
584
|
+
"--control-h": `${h.default}px`,
|
|
585
|
+
"--control-h-lg": `${h.lg}px`,
|
|
586
|
+
"--icon-button": `${height - 2}px`,
|
|
587
|
+
// Controls inside a field: written out, since the stylesheet derives them on :root only.
|
|
588
|
+
"--control-inset": `${h.default - 8}px`,
|
|
589
|
+
"--control-inset-sm": `${h.sm - 6}px`,
|
|
590
|
+
...Object.fromEntries(Object.entries(themeRadii(corners)).map(([name, r]) => [name, `${r}px`])),
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
/* ── The code ───────────────────────────────────────────────────────────────── */
|
|
594
|
+
/** The version this module writes. */
|
|
595
|
+
export const THEME_PRESET_VERSION = 1;
|
|
596
|
+
const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
597
|
+
const PREFIX = "Z1";
|
|
598
|
+
const BODY_LENGTH = 13;
|
|
599
|
+
const PIN_LENGTH = 8;
|
|
600
|
+
/** The tokens a code can pin, in a fixed order: a pin names one by its index here. Frozen for version 1. */
|
|
601
|
+
const PIN_TOKENS = specs.map((s) => s.name);
|
|
602
|
+
const nearest = (steps, v) => steps.reduce((best, s) => (Math.abs(s - v) < Math.abs(best - v) ? s : best), steps[0]);
|
|
603
|
+
const wrapHue = (h) => ((Math.round(h) % 360) + 360) % 360;
|
|
604
|
+
const num = (v, fallback) => (typeof v === "number" && Number.isFinite(v) ? v : fallback);
|
|
605
|
+
/** A pinned colour in the steps a code holds: lightness and chroma to 0.001, hue to 1°, alpha to 1%. */
|
|
606
|
+
function quantizeColor(color) {
|
|
607
|
+
return {
|
|
608
|
+
l: round(clamp(num(color.l, 0)), 3),
|
|
609
|
+
c: round(clamp(num(color.c, 0), 0, 0.4), 3),
|
|
610
|
+
h: wrapHue(num(color.h, 0)),
|
|
611
|
+
a: round(clamp(num(color.a, 1)), 2),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* A preset moved onto the steps a code holds, with anything out of range brought in and anything
|
|
616
|
+
* unknown dropped. Encoding a normalized preset and decoding it gives the same preset back.
|
|
617
|
+
*/
|
|
618
|
+
export function normalizeThemePreset(preset) {
|
|
619
|
+
const s = { ...zonSettings, ...preset.settings };
|
|
620
|
+
const settings = {
|
|
621
|
+
tint: round(clamp(num(s.tint, 0), 0, 0.04), 3),
|
|
622
|
+
tintHue: wrapHue(num(s.tintHue, 250)),
|
|
623
|
+
accent: round(clamp(num(s.accent, 0)), 2),
|
|
624
|
+
accentHue: wrapHue(num(s.accentHue, 250)),
|
|
625
|
+
vivid: round(clamp(num(s.vivid, 1), 0.3, 1.5), 2),
|
|
626
|
+
toneShift: round(clamp(num(s.toneShift, 0), -180, 180), 0),
|
|
627
|
+
statusShift: round(clamp(num(s.statusShift, 0), -12, 12), 0),
|
|
628
|
+
ground: round(clamp(num(s.ground, 0)), 2),
|
|
629
|
+
};
|
|
630
|
+
// A preset saved before `controlHeight` was named calls it `height`: data, so it is still read.
|
|
631
|
+
const saved = preset.shape;
|
|
632
|
+
const shape = {
|
|
633
|
+
controlHeight: nearest(THEME_HEIGHTS, num(saved?.controlHeight ?? saved?.height, 38)),
|
|
634
|
+
corners: nearest(THEME_CORNERS, num(preset.shape?.corners, 1)),
|
|
635
|
+
};
|
|
636
|
+
const pins = (mode) => Object.fromEntries(PIN_TOKENS.filter((name) => isColor(preset.pinned?.[mode]?.[name])).map((name) => [
|
|
637
|
+
name,
|
|
638
|
+
quantizeColor(preset.pinned[mode][name]),
|
|
639
|
+
]));
|
|
640
|
+
return {
|
|
641
|
+
settings,
|
|
642
|
+
shape,
|
|
643
|
+
seeds: {
|
|
644
|
+
base: !!preset.seeds?.base,
|
|
645
|
+
theme: !!preset.seeds?.theme,
|
|
646
|
+
accent: !!preset.seeds?.accent,
|
|
647
|
+
},
|
|
648
|
+
pinned: { light: pins("light"), dark: pins("dark") },
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
/** The body's fields, most significant first: each value runs from 0 to size − 1. */
|
|
652
|
+
const BODY = [
|
|
653
|
+
{
|
|
654
|
+
size: 8,
|
|
655
|
+
get: (p) => (p.seeds.base ? 4 : 0) + (p.seeds.theme ? 2 : 0) + (p.seeds.accent ? 1 : 0),
|
|
656
|
+
set: (p, v) => (p.seeds = { base: (v & 4) > 0, theme: (v & 2) > 0, accent: (v & 1) > 0 }),
|
|
657
|
+
},
|
|
658
|
+
{ size: 41, get: (p) => Math.round(p.settings.tint * 1000), set: (p, v) => (p.settings.tint = v / 1000) },
|
|
659
|
+
{ size: 360, get: (p) => p.settings.tintHue, set: (p, v) => (p.settings.tintHue = v) },
|
|
660
|
+
{
|
|
661
|
+
size: 101,
|
|
662
|
+
get: (p) => Math.round(p.settings.accent * 100),
|
|
663
|
+
set: (p, v) => (p.settings.accent = v / 100),
|
|
664
|
+
},
|
|
665
|
+
{ size: 360, get: (p) => p.settings.accentHue, set: (p, v) => (p.settings.accentHue = v) },
|
|
666
|
+
{
|
|
667
|
+
size: 121,
|
|
668
|
+
get: (p) => Math.round(p.settings.vivid * 100) - 30,
|
|
669
|
+
set: (p, v) => (p.settings.vivid = (v + 30) / 100),
|
|
670
|
+
},
|
|
671
|
+
{ size: 361, get: (p) => p.settings.toneShift + 180, set: (p, v) => (p.settings.toneShift = v - 180) },
|
|
672
|
+
{ size: 25, get: (p) => p.settings.statusShift + 12, set: (p, v) => (p.settings.statusShift = v - 12) },
|
|
673
|
+
{
|
|
674
|
+
size: 101,
|
|
675
|
+
get: (p) => Math.round(p.settings.ground * 100),
|
|
676
|
+
set: (p, v) => (p.settings.ground = v / 100),
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
size: THEME_HEIGHTS.length,
|
|
680
|
+
get: (p) => THEME_HEIGHTS.indexOf(p.shape.controlHeight),
|
|
681
|
+
set: (p, v) => (p.shape.controlHeight = THEME_HEIGHTS[v]),
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
size: THEME_CORNERS.length,
|
|
685
|
+
get: (p) => THEME_CORNERS.indexOf(p.shape.corners),
|
|
686
|
+
set: (p, v) => (p.shape.corners = THEME_CORNERS[v]),
|
|
687
|
+
},
|
|
688
|
+
];
|
|
689
|
+
/** A pin's fields: the theme, the token, then lightness, chroma, hue and alpha. */
|
|
690
|
+
const PIN = [2, PIN_TOKENS.length, 1001, 401, 360, 101];
|
|
691
|
+
function toBase36(values, sizes, length) {
|
|
692
|
+
let n = 0n;
|
|
693
|
+
values.forEach((v, i) => (n = n * BigInt(sizes[i]) + BigInt(v)));
|
|
694
|
+
let out = "";
|
|
695
|
+
for (let i = 0; i < length; i++) {
|
|
696
|
+
out = ALPHABET[Number(n % 36n)] + out;
|
|
697
|
+
n /= 36n;
|
|
698
|
+
}
|
|
699
|
+
return out;
|
|
700
|
+
}
|
|
701
|
+
function fromBase36(text, sizes) {
|
|
702
|
+
let n = 0n;
|
|
703
|
+
for (const ch of text)
|
|
704
|
+
n = n * 36n + BigInt(ALPHABET.indexOf(ch));
|
|
705
|
+
const values = [];
|
|
706
|
+
for (let i = sizes.length - 1; i >= 0; i--) {
|
|
707
|
+
const size = BigInt(sizes[i]);
|
|
708
|
+
values.unshift(Number(n % size));
|
|
709
|
+
n /= size;
|
|
710
|
+
}
|
|
711
|
+
// Left over past the last field: not a number this format writes.
|
|
712
|
+
return n === 0n ? values : null;
|
|
713
|
+
}
|
|
714
|
+
/* Weights prime to 36, so any one character changed changes the sum. */
|
|
715
|
+
const WEIGHTS = [1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35];
|
|
716
|
+
const check = (text) => ALPHABET[[...text].reduce((sum, ch, i) => sum + ALPHABET.indexOf(ch) * WEIGHTS[i % WEIGHTS.length], 0) % 36];
|
|
717
|
+
/**
|
|
718
|
+
* A preset as a code of letters and digits: 16 characters, and 8 more for each colour pinned by
|
|
719
|
+
* hand. The preset is normalized first, so the code holds what `decodeThemePreset` gives back.
|
|
720
|
+
*/
|
|
721
|
+
export function encodeThemePreset(preset) {
|
|
722
|
+
const p = normalizeThemePreset(preset);
|
|
723
|
+
const body = toBase36(BODY.map((f) => f.get(p)), BODY.map((f) => f.size), BODY_LENGTH);
|
|
724
|
+
const pins = ["light", "dark"].flatMap((mode, m) => PIN_TOKENS.filter((name) => p.pinned[mode][name]).map((name) => {
|
|
725
|
+
const c = p.pinned[mode][name];
|
|
726
|
+
return toBase36([
|
|
727
|
+
m,
|
|
728
|
+
PIN_TOKENS.indexOf(name),
|
|
729
|
+
Math.round(c.l * 1000),
|
|
730
|
+
Math.round(c.c * 1000),
|
|
731
|
+
c.h,
|
|
732
|
+
Math.round(c.a * 100),
|
|
733
|
+
], PIN, PIN_LENGTH);
|
|
734
|
+
}));
|
|
735
|
+
const text = PREFIX + body + pins.join("");
|
|
736
|
+
return text + check(text);
|
|
737
|
+
}
|
|
738
|
+
/** Why a code, or a colour or an option given to themePresetFromColor, could not be read. */
|
|
739
|
+
export class ThemePresetError extends Error {
|
|
740
|
+
constructor(message) {
|
|
741
|
+
super(message);
|
|
742
|
+
this.name = "ThemePresetError";
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Reads a code back into the preset it holds. Case, spaces and hyphens are ignored. Throws a
|
|
747
|
+
* ThemePresetError, with a sentence saying why, for anything that is not a code.
|
|
748
|
+
*/
|
|
749
|
+
export function decodeThemePreset(code) {
|
|
750
|
+
const text = code.replace(/[\s-]/g, "").toUpperCase();
|
|
751
|
+
if (!text.startsWith("Z"))
|
|
752
|
+
throw new ThemePresetError("A zon preset code starts with Z.");
|
|
753
|
+
if (text[1] !== "1")
|
|
754
|
+
throw new ThemePresetError(`This code is version ${text[1] ?? "?"}; this version of @zonsh/ui reads version ${THEME_PRESET_VERSION}.`);
|
|
755
|
+
if (/[^0-9A-Z]/.test(text))
|
|
756
|
+
throw new ThemePresetError("A preset code has only letters and digits.");
|
|
757
|
+
const pinChars = text.length - PREFIX.length - BODY_LENGTH - 1;
|
|
758
|
+
if (pinChars < 0 || pinChars % PIN_LENGTH !== 0)
|
|
759
|
+
throw new ThemePresetError(`A version 1 code is ${PREFIX.length + BODY_LENGTH + 1} characters, and ${PIN_LENGTH} more for each pinned colour.`);
|
|
760
|
+
if (check(text.slice(0, -1)) !== text.at(-1))
|
|
761
|
+
throw new ThemePresetError("This code doesn't add up: a character is missing or mistyped.");
|
|
762
|
+
const preset = {
|
|
763
|
+
settings: { ...zonSettings },
|
|
764
|
+
shape: { ...zonThemePreset.shape },
|
|
765
|
+
seeds: { ...zonThemePreset.seeds },
|
|
766
|
+
pinned: { light: {}, dark: {} },
|
|
767
|
+
};
|
|
768
|
+
const body = fromBase36(text.slice(PREFIX.length, PREFIX.length + BODY_LENGTH), BODY.map((f) => f.size));
|
|
769
|
+
if (!body)
|
|
770
|
+
throw new ThemePresetError("This code holds a value out of range.");
|
|
771
|
+
BODY.forEach((f, i) => f.set(preset, body[i]));
|
|
772
|
+
for (let at = PREFIX.length + BODY_LENGTH; at < text.length - 1; at += PIN_LENGTH) {
|
|
773
|
+
const pin = fromBase36(text.slice(at, at + PIN_LENGTH), PIN);
|
|
774
|
+
if (!pin)
|
|
775
|
+
throw new ThemePresetError("This code holds a pinned colour out of range.");
|
|
776
|
+
const [m, token, l, c, h, a] = pin;
|
|
777
|
+
const name = PIN_TOKENS[token];
|
|
778
|
+
if (!name || l > 1000 || c > 400 || a > 100)
|
|
779
|
+
throw new ThemePresetError("This code holds a pinned colour out of range.");
|
|
780
|
+
preset.pinned[m === 0 ? "light" : "dark"][name] = { l: l / 1000, c: c / 1000, h, a: a / 100 };
|
|
781
|
+
}
|
|
782
|
+
return normalizeThemePreset(preset);
|
|
783
|
+
}
|
|
784
|
+
/* ── Applying a preset ──────────────────────────────────────────────────────── */
|
|
785
|
+
/** Where each part of a theme goes, after `@import "@zonsh/ui/styles.css";`. */
|
|
786
|
+
export const THEME_SELECTORS = {
|
|
787
|
+
light: ":root, .theme-light",
|
|
788
|
+
dark: '.dark, [data-theme="dark"], .theme-dark',
|
|
789
|
+
shape: ":root",
|
|
790
|
+
};
|
|
791
|
+
/** The theme.json format this module writes and reads. */
|
|
792
|
+
export const THEME_FILE_VERSION = 1;
|
|
793
|
+
/** Whether a theme input is a theme.json file (it names its preset code) rather than a preset. */
|
|
794
|
+
export function isThemeFile(input) {
|
|
795
|
+
return typeof input === "object" && input !== null && typeof input.preset === "string";
|
|
796
|
+
}
|
|
797
|
+
const SHAPE_NAMES = Object.keys(themeShapeTokens(zonThemePreset.shape));
|
|
798
|
+
const SHAPE_VALUE = /^\d+(\.\d+)?(px)?$/;
|
|
799
|
+
/** Reads a theme.json file, or its text: its preset and the token values it sets. Throws a ThemePresetError for anything else. */
|
|
800
|
+
function readThemeFile(input) {
|
|
801
|
+
let file = input;
|
|
802
|
+
if (typeof input === "string") {
|
|
803
|
+
try {
|
|
804
|
+
file = JSON.parse(input);
|
|
805
|
+
}
|
|
806
|
+
catch {
|
|
807
|
+
throw new ThemePresetError("This theme file isn't JSON.");
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (!isThemeFile(file))
|
|
811
|
+
throw new ThemePresetError('A theme file names its preset code: "preset": "Z1…".');
|
|
812
|
+
const version = file.version ?? THEME_FILE_VERSION;
|
|
813
|
+
if (version !== THEME_FILE_VERSION)
|
|
814
|
+
throw new ThemePresetError(`This theme file is version ${version}; this version of @zonsh/ui reads version ${THEME_FILE_VERSION}.`);
|
|
815
|
+
const tokens = (part, names, valid) => {
|
|
816
|
+
const values = file[part] ?? {};
|
|
817
|
+
if (typeof values !== "object" || values === null)
|
|
818
|
+
throw new ThemePresetError(`"${part}" in a theme file is an object of tokens.`);
|
|
819
|
+
for (const [name, value] of Object.entries(values)) {
|
|
820
|
+
if (!names.includes(name))
|
|
821
|
+
throw new ThemePresetError(`"${name}" in "${part}" isn't a token a theme sets.`);
|
|
822
|
+
if (typeof value !== "string" || !valid(value))
|
|
823
|
+
throw new ThemePresetError(`"${name}" in "${part}" isn't a value it takes: ${JSON.stringify(value)}.`);
|
|
824
|
+
}
|
|
825
|
+
return values;
|
|
826
|
+
};
|
|
827
|
+
const color = (v) => parseThemeColor(v) !== null;
|
|
828
|
+
return {
|
|
829
|
+
preset: file.preset,
|
|
830
|
+
shape: tokens("shape", SHAPE_NAMES, (v) => SHAPE_VALUE.test(v.trim())),
|
|
831
|
+
light: tokens("light", allNames, color),
|
|
832
|
+
dark: tokens("dark", allNames, color),
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/** A token map in the order the theme writes it, with anything it doesn't set dropped. */
|
|
836
|
+
const ordered = (tokens, names) => Object.fromEntries(names.filter((name) => name in tokens).map((name) => [name, tokens[name]]));
|
|
837
|
+
/** A theme as theme.json text: the same theme always gives the same bytes. */
|
|
838
|
+
function themeJson(code, shape, light, dark) {
|
|
839
|
+
const file = {
|
|
840
|
+
name: "zon theme",
|
|
841
|
+
for: "@zonsh/ui",
|
|
842
|
+
version: THEME_FILE_VERSION,
|
|
843
|
+
preset: code,
|
|
844
|
+
shape: ordered(shape, SHAPE_NAMES),
|
|
845
|
+
light: ordered(light, allNames),
|
|
846
|
+
dark: ordered(dark, allNames),
|
|
847
|
+
};
|
|
848
|
+
return `${JSON.stringify(file, null, 2)}\n`;
|
|
849
|
+
}
|
|
850
|
+
/** The comment over each group of tokens in the stylesheet. */
|
|
851
|
+
const colorSections = [
|
|
852
|
+
...themeTokenGroups.map((g) => ({ title: g.title, names: g.tokens.map((t) => t.name) })),
|
|
853
|
+
{ title: "Following the tokens above", names: derived.map((d) => d.name) },
|
|
854
|
+
];
|
|
855
|
+
const shapeSections = [
|
|
856
|
+
{ title: "Density and control heights", names: SHAPE_NAMES.filter((n) => !n.startsWith("--radius-")) },
|
|
857
|
+
{ title: "Corners", names: SHAPE_NAMES.filter((n) => n.startsWith("--radius-")) },
|
|
858
|
+
];
|
|
859
|
+
/** One rule: the selectors one to a line, then each group of tokens under its comment, one to a line. */
|
|
860
|
+
function cssRule(selectors, tokens, sections) {
|
|
861
|
+
const body = sections
|
|
862
|
+
.map(({ title, names }) => {
|
|
863
|
+
const lines = names.filter((name) => name in tokens).map((name) => ` ${name}: ${tokens[name]};`);
|
|
864
|
+
return lines.length ? ` /* ${title} */\n${lines.join("\n")}` : "";
|
|
865
|
+
})
|
|
866
|
+
.filter(Boolean)
|
|
867
|
+
.join("\n\n");
|
|
868
|
+
return `${selectors.join(",\n")} {\n${body || " /* no changes */"}\n}`;
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* The selectors for one area of the page, `data-theme-scope="<key>"`. Written twice, so they
|
|
872
|
+
* outrank the library's own `.theme-light` and `.theme-dark` on the same element; dark when the
|
|
873
|
+
* page is dark, unless the area is forced light, or when the area is forced dark.
|
|
874
|
+
*/
|
|
875
|
+
function scopeSelectors(key) {
|
|
876
|
+
const at = `[data-theme-scope][data-theme-scope="${key}"]`;
|
|
877
|
+
return {
|
|
878
|
+
shape: [at],
|
|
879
|
+
light: [`${at}:not(.theme-dark)`],
|
|
880
|
+
dark: [
|
|
881
|
+
`:is(.dark, [data-theme="dark"], .theme-dark, .theme-night) ${at}:not(.theme-light)`,
|
|
882
|
+
`${at}.theme-dark`,
|
|
883
|
+
],
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Expands a preset code, a preset or a theme.json file into token values, the CSS that applies
|
|
888
|
+
* them and the theme.json text that records them:
|
|
889
|
+
*
|
|
890
|
+
* ```tsx
|
|
891
|
+
* <style>{themeFromPreset("Z1…").css}</style>
|
|
892
|
+
* ```
|
|
893
|
+
*
|
|
894
|
+
* Throws a ThemePresetError for a code or a file it can't read.
|
|
895
|
+
*/
|
|
896
|
+
export function themeFromPreset(preset, { format = "oklch", onlyChanges = false, scope } = {}) {
|
|
897
|
+
const file = isThemeFile(preset) ? readThemeFile(preset) : undefined;
|
|
898
|
+
const p = file
|
|
899
|
+
? decodeThemePreset(file.preset)
|
|
900
|
+
: typeof preset === "string"
|
|
901
|
+
? decodeThemePreset(preset)
|
|
902
|
+
: normalizeThemePreset(preset);
|
|
903
|
+
if (scope !== undefined && !/^[\w-]+$/.test(scope))
|
|
904
|
+
throw new ThemePresetError(`A scope is letters, digits, "-" and "_", not "${scope}".`);
|
|
905
|
+
const code = encodeThemePreset(p);
|
|
906
|
+
const colors = (mode) => {
|
|
907
|
+
const generated = themePalette(p, mode);
|
|
908
|
+
const base = zonPalette(mode);
|
|
909
|
+
// A value from a theme.json file that differs from what the code expands to, compared as it
|
|
910
|
+
// is written there (hex or oklch), was edited by hand. It counts as pinned, exactly as written:
|
|
911
|
+
// text that sits on it still moves until it reads, and the hover and pressed fills follow it.
|
|
912
|
+
const edits = {};
|
|
913
|
+
for (const [name, value] of Object.entries(file?.[mode] ?? {})) {
|
|
914
|
+
const color = generated[name];
|
|
915
|
+
const written = value.trim();
|
|
916
|
+
if (color && written !== formatThemeColor(color, written.startsWith("#") ? "hex" : "oklch"))
|
|
917
|
+
edits[name] = parseThemeColor(written);
|
|
918
|
+
}
|
|
919
|
+
const pins = Object.fromEntries(Object.entries(edits).filter(([name]) => PIN_TOKENS.includes(name)));
|
|
920
|
+
const palette = Object.keys(edits).length
|
|
921
|
+
? {
|
|
922
|
+
...themePalette({ ...p, pinned: { ...p.pinned, [mode]: { ...p.pinned[mode], ...pins } } }, mode),
|
|
923
|
+
...edits,
|
|
924
|
+
}
|
|
925
|
+
: generated;
|
|
926
|
+
const out = {};
|
|
927
|
+
for (const name of allNames) {
|
|
928
|
+
const color = palette[name];
|
|
929
|
+
if (!color)
|
|
930
|
+
continue;
|
|
931
|
+
const def = base[name];
|
|
932
|
+
if (onlyChanges && def && formatThemeColor(color) === formatThemeColor(def))
|
|
933
|
+
continue;
|
|
934
|
+
out[name] = formatThemeColor(color, format);
|
|
935
|
+
}
|
|
936
|
+
return out;
|
|
937
|
+
};
|
|
938
|
+
const zonShape = themeShapeTokens(zonThemePreset.shape);
|
|
939
|
+
const fullShape = { ...themeShapeTokens(p.shape), ...file?.shape };
|
|
940
|
+
const shape = Object.fromEntries(SHAPE_NAMES.filter((name) => !onlyChanges || zonShape[name] !== fullShape[name].trim()).map((name) => [
|
|
941
|
+
name,
|
|
942
|
+
fullShape[name].trim(),
|
|
943
|
+
]));
|
|
944
|
+
const light = colors("light");
|
|
945
|
+
const dark = colors("dark");
|
|
946
|
+
const selectors = scope
|
|
947
|
+
? scopeSelectors(scope)
|
|
948
|
+
: {
|
|
949
|
+
shape: [THEME_SELECTORS.shape],
|
|
950
|
+
light: THEME_SELECTORS.light.split(", "),
|
|
951
|
+
dark: THEME_SELECTORS.dark.split(", "),
|
|
952
|
+
};
|
|
953
|
+
const where = scope ? `the area with data-theme-scope="${scope}"` : "the page";
|
|
954
|
+
const shapeCss = Object.keys(shape).length
|
|
955
|
+
? `/* ── Shape: density and corners, for both themes ── */\n${cssRule(selectors.shape, shape, shapeSections)}\n\n`
|
|
956
|
+
: "";
|
|
957
|
+
const css = [
|
|
958
|
+
`/* zon theme ${code}, for ${where}: after @import "@zonsh/ui/styles.css"; */\n\n`,
|
|
959
|
+
shapeCss,
|
|
960
|
+
`/* ── Light ── */\n${cssRule(selectors.light, light, colorSections)}\n\n`,
|
|
961
|
+
`/* ── Dark ── */\n${cssRule(selectors.dark, dark, colorSections)}\n`,
|
|
962
|
+
].join("");
|
|
963
|
+
return { code, light, dark, shape, css, json: themeJson(code, shape, light, dark) };
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* One theme's tokens as an inline style, for an element that always shows that theme in light or
|
|
967
|
+
* dark: `<div className="theme-dark" style={themeScopeStyle(code, "dark")}>`. The colours, the
|
|
968
|
+
* density, the control heights and the radii, and `colorScheme`. To follow the page's light and
|
|
969
|
+
* dark, use `ThemeScope`, which writes the stylesheet for both.
|
|
970
|
+
*/
|
|
971
|
+
export function themeScopeStyle(preset, scheme, options = {}) {
|
|
972
|
+
const theme = themeFromPreset(preset, options);
|
|
973
|
+
return { colorScheme: scheme, ...theme.shape, ...theme[scheme] };
|
|
974
|
+
}
|
|
975
|
+
/** The greys' tint and hue for each neutral, within the theme editor's Stone and Slate families. */
|
|
976
|
+
const NEUTRALS = {
|
|
977
|
+
pure: { tint: 0 },
|
|
978
|
+
warm: { tint: 0.01, hue: 75 },
|
|
979
|
+
cool: { tint: 0.01, hue: 250 },
|
|
980
|
+
tinted: { tint: 0.008 },
|
|
981
|
+
};
|
|
982
|
+
const CORNER_NAMES = { square: 0, subtle: 0.5, default: 1, round: 1.5 };
|
|
983
|
+
const DENSITY_NAMES = {
|
|
984
|
+
dense: 30,
|
|
985
|
+
compact: 34,
|
|
986
|
+
default: 38,
|
|
987
|
+
comfortable: 42,
|
|
988
|
+
spacious: 46,
|
|
989
|
+
};
|
|
990
|
+
/** Below this chroma a colour reads as a grey (black, white, charcoal), and the primary stays zon's grey. */
|
|
991
|
+
const GREY_CHROMA = 0.03;
|
|
992
|
+
/** A named option or one of its steps, as a number; undefined when not given. */
|
|
993
|
+
function stepOption(name, value, names, steps) {
|
|
994
|
+
if (value === undefined)
|
|
995
|
+
return undefined;
|
|
996
|
+
if (typeof value === "number" && steps.includes(value))
|
|
997
|
+
return value;
|
|
998
|
+
if (typeof value === "string" && Object.hasOwn(names, value))
|
|
999
|
+
return names[value];
|
|
1000
|
+
throw new ThemePresetError(`${name} is ${Object.keys(names).length ? `${Object.keys(names).join(", ")} or ` : ""}one of ${steps.join(", ")}, not "${value}".`);
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* A theme from one colour, for when you know the brand colour but not the tokens. The primary
|
|
1004
|
+
* button, checked controls and the focus outline take the colour's hue and as much colour as it
|
|
1005
|
+
* has; the greys, corners and control height follow the plain options. It is built with the
|
|
1006
|
+
* theme editor's generator, so text and the primary's label move until they read (4.5:1, and 3:1
|
|
1007
|
+
* for the focus outline and the tick), in light and in dark.
|
|
1008
|
+
*
|
|
1009
|
+
* The colour is any CSS colour: `#c2410c`, `rgb(…)`, `hsl(…)`, `oklch(…)` or a name such as
|
|
1010
|
+
* `teal`. A grey, black or white keeps zon's grey primary. Throws a ThemePresetError, saying
|
|
1011
|
+
* why, for a colour or an option it can't read.
|
|
1012
|
+
*
|
|
1013
|
+
* ```tsx
|
|
1014
|
+
* <ThemeProvider preset={themePresetFromColor("#c2410c", { corners: "round" })}>
|
|
1015
|
+
* encodeThemePreset(themePresetFromColor("teal")) // its preset code, "Z1…"
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
export function themePresetFromColor(color, options = {}) {
|
|
1019
|
+
const parsed = typeof color === "string" ? parseThemeColor(color) : null;
|
|
1020
|
+
if (!parsed)
|
|
1021
|
+
throw new ThemePresetError(`"${color}" isn't a colour: give a hex code such as #c2410c, rgb(), hsl(), oklch() or a CSS colour name such as teal.`);
|
|
1022
|
+
const neutralName = options.neutral ?? "pure";
|
|
1023
|
+
if (!Object.hasOwn(NEUTRALS, neutralName))
|
|
1024
|
+
throw new ThemePresetError(`neutral is ${Object.keys(NEUTRALS).join(", ")}, not "${neutralName}".`);
|
|
1025
|
+
const neutral = NEUTRALS[neutralName];
|
|
1026
|
+
const coloured = parsed.c >= GREY_CHROMA;
|
|
1027
|
+
return normalizeThemePreset({
|
|
1028
|
+
settings: {
|
|
1029
|
+
...zonSettings,
|
|
1030
|
+
// A grey has no hue to tint with: `tinted` keeps the greys pure.
|
|
1031
|
+
tint: neutralName === "tinted" && !coloured ? 0 : neutral.tint,
|
|
1032
|
+
tintHue: neutral.hue ?? (coloured ? parsed.h : zonSettings.tintHue),
|
|
1033
|
+
// As the theme editor reads a picked theme colour: its hue, and its chroma against a full colour's 0.19.
|
|
1034
|
+
accent: coloured ? clamp(parsed.c / 0.19) : 0,
|
|
1035
|
+
accentHue: coloured ? parsed.h : zonSettings.accentHue,
|
|
1036
|
+
},
|
|
1037
|
+
shape: {
|
|
1038
|
+
controlHeight: stepOption("controlHeight", options.controlHeight, {}, THEME_HEIGHTS) ??
|
|
1039
|
+
stepOption("density", options.density, DENSITY_NAMES, THEME_HEIGHTS) ??
|
|
1040
|
+
38,
|
|
1041
|
+
corners: stepOption("corners", options.corners, CORNER_NAMES, THEME_CORNERS) ?? 1,
|
|
1042
|
+
},
|
|
1043
|
+
seeds: { base: neutralName !== "pure", theme: coloured, accent: false },
|
|
1044
|
+
pinned: { light: {}, dark: {} },
|
|
1045
|
+
});
|
|
1046
|
+
}
|