@contui/ui 0.0.0-stage → 0.1.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/LICENSE +30 -0
- package/README.md +150 -2
- package/cli/contui.mjs +250 -0
- package/dist/charts/area-chart.d.ts +8 -0
- package/dist/charts/area-chart.js +9 -0
- package/dist/charts/bar-chart.d.ts +9 -0
- package/dist/charts/bar-chart.js +10 -0
- package/dist/charts/bubble-chart.d.ts +60 -0
- package/dist/charts/bubble-chart.js +392 -0
- package/dist/charts/bullet-chart.d.ts +53 -0
- package/dist/charts/bullet-chart.js +123 -0
- package/dist/charts/candlestick-chart.d.ts +77 -0
- package/dist/charts/candlestick-chart.js +558 -0
- package/dist/charts/cartesian.d.ts +121 -0
- package/dist/charts/cartesian.js +625 -0
- package/dist/charts/chart-card.d.ts +80 -0
- package/dist/charts/chart-card.js +114 -0
- package/dist/charts/donut-chart.d.ts +40 -0
- package/dist/charts/donut-chart.js +88 -0
- package/dist/charts/funnel-chart.d.ts +16 -0
- package/dist/charts/funnel-chart.js +164 -0
- package/dist/charts/horizontal-bar-chart.d.ts +67 -0
- package/dist/charts/horizontal-bar-chart.js +481 -0
- package/dist/charts/index.d.ts +21 -0
- package/dist/charts/index.js +32 -0
- package/dist/charts/legend.d.ts +23 -0
- package/dist/charts/legend.js +22 -0
- package/dist/charts/lib/candlestick-window.d.ts +15 -0
- package/dist/charts/lib/candlestick-window.js +23 -0
- package/dist/charts/lib/color.d.ts +39 -0
- package/dist/charts/lib/color.js +83 -0
- package/dist/charts/lib/format.d.ts +11 -0
- package/dist/charts/lib/format.js +33 -0
- package/dist/charts/lib/frame.d.ts +6 -0
- package/dist/charts/lib/frame.js +6 -0
- package/dist/charts/lib/layout.d.ts +11 -0
- package/dist/charts/lib/layout.js +71 -0
- package/dist/charts/lib/path.d.ts +35 -0
- package/dist/charts/lib/path.js +203 -0
- package/dist/charts/lib/scale.d.ts +41 -0
- package/dist/charts/lib/scale.js +80 -0
- package/dist/charts/lib/use-active.d.ts +18 -0
- package/dist/charts/lib/use-active.js +71 -0
- package/dist/charts/lib/use-size.d.ts +9 -0
- package/dist/charts/lib/use-size.js +40 -0
- package/dist/charts/line-chart.d.ts +7 -0
- package/dist/charts/line-chart.js +8 -0
- package/dist/charts/radar-chart.d.ts +27 -0
- package/dist/charts/radar-chart.js +165 -0
- package/dist/charts/rose-chart.d.ts +35 -0
- package/dist/charts/rose-chart.js +242 -0
- package/dist/charts/sparkline.d.ts +35 -0
- package/dist/charts/sparkline.js +110 -0
- package/dist/charts/tooltip.d.ts +35 -0
- package/dist/charts/tooltip.js +22 -0
- package/dist/charts/treemap.d.ts +28 -0
- package/dist/charts/treemap.js +103 -0
- package/dist/charts/uptime-strip.d.ts +40 -0
- package/dist/charts/uptime-strip.js +178 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +34 -0
- package/dist/components/activity-item.d.ts +12 -0
- package/dist/components/activity-item.js +6 -0
- package/dist/components/alert.d.ts +21 -0
- package/dist/components/alert.js +58 -0
- package/dist/components/assistant-answer.d.ts +52 -0
- package/dist/components/assistant-answer.js +40 -0
- package/dist/components/assistant-prompt.d.ts +63 -0
- package/dist/components/assistant-prompt.js +122 -0
- package/dist/components/avatar.d.ts +28 -0
- package/dist/components/avatar.js +75 -0
- package/dist/components/badge.d.ts +16 -0
- package/dist/components/badge.js +33 -0
- package/dist/components/bar-list.d.ts +65 -0
- package/dist/components/bar-list.js +119 -0
- package/dist/components/block-slider.d.ts +43 -0
- package/dist/components/block-slider.js +63 -0
- package/dist/components/branch-graph.d.ts +87 -0
- package/dist/components/branch-graph.js +231 -0
- package/dist/components/breadcrumb.d.ts +41 -0
- package/dist/components/breadcrumb.js +53 -0
- package/dist/components/button.d.ts +23 -0
- package/dist/components/button.js +108 -0
- package/dist/components/calendar.d.ts +5 -0
- package/dist/components/calendar.js +90 -0
- package/dist/components/card.d.ts +65 -0
- package/dist/components/card.js +104 -0
- package/dist/components/chat-attachment.d.ts +47 -0
- package/dist/components/chat-attachment.js +63 -0
- package/dist/components/chat-event.d.ts +7 -0
- package/dist/components/chat-event.js +7 -0
- package/dist/components/chat-message.d.ts +59 -0
- package/dist/components/chat-message.js +91 -0
- package/dist/components/chat-reference.d.ts +20 -0
- package/dist/components/chat-reference.js +41 -0
- package/dist/components/chat-shared.d.ts +21 -0
- package/dist/components/chat-shared.js +23 -0
- package/dist/components/chat-suggestions.d.ts +59 -0
- package/dist/components/chat-suggestions.js +88 -0
- package/dist/components/chat-thread.d.ts +39 -0
- package/dist/components/chat-thread.js +172 -0
- package/dist/components/chat-typing.d.ts +35 -0
- package/dist/components/chat-typing.js +66 -0
- package/dist/components/checkbox.d.ts +18 -0
- package/dist/components/checkbox.js +33 -0
- package/dist/components/checklist.d.ts +26 -0
- package/dist/components/checklist.js +18 -0
- package/dist/components/chip.d.ts +29 -0
- package/dist/components/chip.js +61 -0
- package/dist/components/code-input.d.ts +40 -0
- package/dist/components/code-input.js +285 -0
- package/dist/components/color-picker.d.ts +38 -0
- package/dist/components/color-picker.js +855 -0
- package/dist/components/combobox.d.ts +75 -0
- package/dist/components/combobox.js +112 -0
- package/dist/components/command-menu.d.ts +58 -0
- package/dist/components/command-menu.js +166 -0
- package/dist/components/copy-button.d.ts +16 -0
- package/dist/components/copy-button.js +31 -0
- package/dist/components/data-grid.d.ts +50 -0
- package/dist/components/data-grid.js +599 -0
- package/dist/components/date-picker.d.ts +109 -0
- package/dist/components/date-picker.js +268 -0
- package/dist/components/description-list.d.ts +12 -0
- package/dist/components/description-list.js +10 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +140 -0
- package/dist/components/dock.d.ts +45 -0
- package/dist/components/dock.js +79 -0
- package/dist/components/drop-zone.d.ts +46 -0
- package/dist/components/drop-zone.js +101 -0
- package/dist/components/dropdown-menu.d.ts +50 -0
- package/dist/components/dropdown-menu.js +78 -0
- package/dist/components/editable-cell.d.ts +34 -0
- package/dist/components/editable-cell.js +89 -0
- package/dist/components/empty-state.d.ts +17 -0
- package/dist/components/empty-state.js +9 -0
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +75 -0
- package/dist/components/filter-condition.d.ts +188 -0
- package/dist/components/filter-condition.js +113 -0
- package/dist/components/filter-menu.d.ts +57 -0
- package/dist/components/filter-menu.js +46 -0
- package/dist/components/header-bar.d.ts +84 -0
- package/dist/components/header-bar.js +94 -0
- package/dist/components/hold-button.d.ts +15 -0
- package/dist/components/hold-button.js +88 -0
- package/dist/components/icon-tile.d.ts +12 -0
- package/dist/components/icon-tile.js +29 -0
- package/dist/components/info-tip.d.ts +13 -0
- package/dist/components/info-tip.js +26 -0
- package/dist/components/input.d.ts +17 -0
- package/dist/components/input.js +83 -0
- package/dist/components/kbd.d.ts +6 -0
- package/dist/components/kbd.js +7 -0
- package/dist/components/menu-item.d.ts +56 -0
- package/dist/components/menu-item.js +94 -0
- package/dist/components/message-composer.d.ts +75 -0
- package/dist/components/message-composer.js +199 -0
- package/dist/components/nav-rail.d.ts +31 -0
- package/dist/components/nav-rail.js +85 -0
- package/dist/components/notice.d.ts +45 -0
- package/dist/components/notice.js +66 -0
- package/dist/components/optimistic-undo.d.ts +28 -0
- package/dist/components/optimistic-undo.js +43 -0
- package/dist/components/option-row.d.ts +15 -0
- package/dist/components/option-row.js +14 -0
- package/dist/components/page-content.d.ts +11 -0
- package/dist/components/page-content.js +31 -0
- package/dist/components/pagination.d.ts +34 -0
- package/dist/components/pagination.js +41 -0
- package/dist/components/popover.d.ts +27 -0
- package/dist/components/popover.js +25 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.js +75 -0
- package/dist/components/radio-group.d.ts +7 -0
- package/dist/components/radio-group.js +33 -0
- package/dist/components/readonly-field.d.ts +33 -0
- package/dist/components/readonly-field.js +80 -0
- package/dist/components/segmented-control.d.ts +21 -0
- package/dist/components/segmented-control.js +108 -0
- package/dist/components/select.d.ts +42 -0
- package/dist/components/select.js +86 -0
- package/dist/components/separator.d.ts +10 -0
- package/dist/components/separator.js +7 -0
- package/dist/components/setting-row.d.ts +53 -0
- package/dist/components/setting-row.js +93 -0
- package/dist/components/sidebar-switcher.d.ts +47 -0
- package/dist/components/sidebar-switcher.js +20 -0
- package/dist/components/sidebar.d.ts +220 -0
- package/dist/components/sidebar.js +327 -0
- package/dist/components/skeleton.d.ts +18 -0
- package/dist/components/skeleton.js +23 -0
- package/dist/components/slider.d.ts +15 -0
- package/dist/components/slider.js +28 -0
- package/dist/components/spinner.d.ts +14 -0
- package/dist/components/spinner.js +19 -0
- package/dist/components/status-dot.d.ts +24 -0
- package/dist/components/status-dot.js +35 -0
- package/dist/components/stepper.d.ts +60 -0
- package/dist/components/stepper.js +197 -0
- package/dist/components/switch.d.ts +9 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table-cell.d.ts +38 -0
- package/dist/components/table-cell.js +107 -0
- package/dist/components/table-context.d.ts +48 -0
- package/dist/components/table-context.js +69 -0
- package/dist/components/table-head.d.ts +42 -0
- package/dist/components/table-head.js +188 -0
- package/dist/components/table-tree.d.ts +96 -0
- package/dist/components/table-tree.js +137 -0
- package/dist/components/table.d.ts +78 -0
- package/dist/components/table.js +119 -0
- package/dist/components/tabs.d.ts +27 -0
- package/dist/components/tabs.js +79 -0
- package/dist/components/textarea.d.ts +3 -0
- package/dist/components/textarea.js +20 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +60 -0
- package/dist/components/thinking.d.ts +68 -0
- package/dist/components/thinking.js +94 -0
- package/dist/components/toast.d.ts +39 -0
- package/dist/components/toast.js +110 -0
- package/dist/components/toolbar.d.ts +25 -0
- package/dist/components/toolbar.js +92 -0
- package/dist/components/tooltip.d.ts +23 -0
- package/dist/components/tooltip.js +27 -0
- package/dist/components/top-nav.d.ts +129 -0
- package/dist/components/top-nav.js +211 -0
- package/dist/components/truncate.d.ts +29 -0
- package/dist/components/truncate.js +138 -0
- package/dist/deprecated.d.ts +43 -0
- package/dist/deprecated.js +47 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +93 -0
- package/dist/lib/cn.d.ts +5 -0
- package/dist/lib/cn.js +14 -0
- package/dist/lib/color.d.ts +136 -0
- package/dist/lib/color.js +307 -0
- package/dist/lib/contrast.d.ts +53 -0
- package/dist/lib/contrast.js +169 -0
- package/dist/lib/create-theme.d.ts +240 -0
- package/dist/lib/create-theme.js +461 -0
- package/dist/lib/harmony.d.ts +102 -0
- package/dist/lib/harmony.js +426 -0
- package/dist/lib/import-theme.d.ts +22 -0
- package/dist/lib/import-theme.js +221 -0
- package/dist/lib/overflow-scroll.d.ts +25 -0
- package/dist/lib/overflow-scroll.js +66 -0
- package/dist/lib/radio-toggle-render.d.ts +3 -0
- package/dist/lib/radio-toggle-render.js +9 -0
- package/dist/lib/reorder.d.ts +38 -0
- package/dist/lib/reorder.js +193 -0
- package/dist/lib/spacing.d.ts +101 -0
- package/dist/lib/spacing.js +118 -0
- package/dist/lib/tailwind-palette.d.ts +5 -0
- package/dist/lib/tailwind-palette.js +351 -0
- package/dist/lib/truncate.d.ts +18 -0
- package/dist/lib/truncate.js +69 -0
- package/dist/lib/use-single-value.d.ts +5 -0
- package/dist/lib/use-single-value.js +17 -0
- package/dist/styles.css +7988 -0
- package/mcp/server.mjs +87590 -0
- package/package.json +58 -5
- package/skills/continuum-fix-padding/SKILL.md +69 -0
- package/skills/continuum-fix-padding/scripts/compute.ts +155 -0
- package/skills/continuum-fix-padding/scripts/spacing.ts +189 -0
- package/skills/continuum-taste/SKILL.md +186 -0
- package/skills/continuum-taste/assets/tokens.css +647 -0
- package/skills/continuum-taste/references/charts.md +375 -0
- package/skills/continuum-taste/references/components.md +1369 -0
- package/skills/continuum-taste/references/foundations.md +539 -0
- package/skills/continuum-taste/references/media/canvas.md +75 -0
- package/skills/continuum-taste/references/media/css.md +61 -0
- package/skills/continuum-taste/references/media/react.md +161 -0
- package/skills/continuum-taste/references/method.md +87 -0
- package/skills/continuum-taste/references/pages.md +391 -0
- package/skills/continuum-taste/references/patterns.md +77 -0
- package/skills/continuum-taste/references/screens/agent.tsx +450 -0
- package/skills/continuum-taste/references/screens/analytics-overview.tsx +377 -0
- package/skills/continuum-taste/references/screens/checkout-funnel.tsx +193 -0
- package/skills/continuum-taste/references/screens/customer.tsx +475 -0
- package/skills/continuum-taste/references/screens/customers.tsx +608 -0
- package/skills/continuum-taste/references/screens/index.tsx +72 -0
- package/skills/continuum-taste/references/screens/invoice-editor.tsx +558 -0
- package/skills/continuum-taste/references/screens/new-customer.tsx +205 -0
- package/skills/continuum-taste/references/screens/overview.tsx +196 -0
- package/skills/continuum-taste/references/screens/report-generator.tsx +329 -0
- package/skills/continuum-taste/references/screens/risk-report.tsx +577 -0
- package/skills/continuum-taste/references/screens/sequence-editor.tsx +455 -0
- package/skills/continuum-taste/references/screens/settings.tsx +288 -0
- package/skills/continuum-taste/references/screens/shared.tsx +204 -0
- package/skills/continuum-taste/references/screens/sign-in.tsx +104 -0
- package/skills/continuum-taste/references/screens/workspace.tsx +596 -0
- package/skills/continuum-taste/references/theming.md +95 -0
- package/src/charts/area-chart.tsx +17 -0
- package/src/charts/bar-chart.tsx +15 -0
- package/src/charts/bubble-chart.tsx +913 -0
- package/src/charts/bullet-chart.tsx +419 -0
- package/src/charts/candlestick-chart.tsx +1242 -0
- package/src/charts/cartesian.tsx +1437 -0
- package/src/charts/chart-card.tsx +394 -0
- package/src/charts/donut-chart.tsx +299 -0
- package/src/charts/funnel-chart.tsx +373 -0
- package/src/charts/horizontal-bar-chart.tsx +991 -0
- package/src/charts/index.ts +76 -0
- package/src/charts/legend.tsx +59 -0
- package/src/charts/lib/candlestick-window.ts +42 -0
- package/src/charts/lib/color.ts +110 -0
- package/src/charts/lib/format.ts +42 -0
- package/src/charts/lib/frame.ts +6 -0
- package/src/charts/lib/layout.ts +78 -0
- package/src/charts/lib/path.ts +225 -0
- package/src/charts/lib/scale.ts +91 -0
- package/src/charts/lib/use-active.ts +87 -0
- package/src/charts/lib/use-size.ts +45 -0
- package/src/charts/line-chart.tsx +16 -0
- package/src/charts/radar-chart.tsx +485 -0
- package/src/charts/rose-chart.tsx +553 -0
- package/src/charts/sparkline.tsx +293 -0
- package/src/charts/tooltip.tsx +105 -0
- package/src/charts/treemap.tsx +271 -0
- package/src/charts/uptime-strip.tsx +469 -0
- package/src/components/accordion.tsx +136 -0
- package/src/components/activity-item.tsx +43 -0
- package/src/components/alert.tsx +135 -0
- package/src/components/assistant-answer.tsx +185 -0
- package/src/components/assistant-prompt.tsx +352 -0
- package/src/components/avatar.tsx +157 -0
- package/src/components/badge.tsx +55 -0
- package/src/components/bar-list.tsx +350 -0
- package/src/components/block-slider.tsx +189 -0
- package/src/components/branch-graph.tsx +580 -0
- package/src/components/breadcrumb.tsx +173 -0
- package/src/components/button.tsx +157 -0
- package/src/components/calendar.tsx +154 -0
- package/src/components/card.tsx +296 -0
- package/src/components/chat-attachment.tsx +255 -0
- package/src/components/chat-event.tsx +34 -0
- package/src/components/chat-message.tsx +332 -0
- package/src/components/chat-reference.tsx +100 -0
- package/src/components/chat-shared.ts +41 -0
- package/src/components/chat-suggestions.tsx +188 -0
- package/src/components/chat-thread.tsx +348 -0
- package/src/components/chat-typing.tsx +155 -0
- package/src/components/checkbox.tsx +83 -0
- package/src/components/checklist.tsx +146 -0
- package/src/components/chip.tsx +152 -0
- package/src/components/code-input.tsx +406 -0
- package/src/components/color-picker.tsx +1385 -0
- package/src/components/combobox.tsx +420 -0
- package/src/components/command-menu.tsx +405 -0
- package/src/components/copy-button.tsx +87 -0
- package/src/components/data-grid.tsx +965 -0
- package/src/components/date-picker.tsx +652 -0
- package/src/components/description-list.tsx +39 -0
- package/src/components/dialog.tsx +367 -0
- package/src/components/dock.tsx +192 -0
- package/src/components/drop-zone.tsx +283 -0
- package/src/components/dropdown-menu.tsx +323 -0
- package/src/components/editable-cell.tsx +219 -0
- package/src/components/empty-state.tsx +50 -0
- package/src/components/field.tsx +148 -0
- package/src/components/filter-condition.tsx +463 -0
- package/src/components/filter-menu.tsx +196 -0
- package/src/components/header-bar.tsx +220 -0
- package/src/components/hold-button.tsx +146 -0
- package/src/components/icon-tile.tsx +43 -0
- package/src/components/info-tip.tsx +87 -0
- package/src/components/input.tsx +136 -0
- package/src/components/kbd.tsx +17 -0
- package/src/components/menu-item.tsx +216 -0
- package/src/components/message-composer.tsx +458 -0
- package/src/components/nav-rail.tsx +235 -0
- package/src/components/notice.tsx +133 -0
- package/src/components/optimistic-undo.ts +68 -0
- package/src/components/option-row.tsx +54 -0
- package/src/components/page-content.tsx +44 -0
- package/src/components/pagination.tsx +182 -0
- package/src/components/popover.tsx +113 -0
- package/src/components/progress.tsx +222 -0
- package/src/components/radio-group.tsx +80 -0
- package/src/components/readonly-field.tsx +251 -0
- package/src/components/segmented-control.tsx +205 -0
- package/src/components/select.tsx +259 -0
- package/src/components/separator.tsx +30 -0
- package/src/components/setting-row.tsx +277 -0
- package/src/components/sidebar-switcher.tsx +134 -0
- package/src/components/sidebar.tsx +804 -0
- package/src/components/skeleton.tsx +57 -0
- package/src/components/slider.tsx +106 -0
- package/src/components/spinner.tsx +43 -0
- package/src/components/status-dot.tsx +100 -0
- package/src/components/stepper.tsx +459 -0
- package/src/components/switch.tsx +54 -0
- package/src/components/table-cell.tsx +239 -0
- package/src/components/table-context.ts +135 -0
- package/src/components/table-head.tsx +393 -0
- package/src/components/table-tree.tsx +357 -0
- package/src/components/table.tsx +295 -0
- package/src/components/tabs.tsx +191 -0
- package/src/components/textarea.tsx +44 -0
- package/src/components/theme.tsx +120 -0
- package/src/components/thinking.tsx +295 -0
- package/src/components/toast.tsx +308 -0
- package/src/components/toolbar.tsx +166 -0
- package/src/components/tooltip.tsx +84 -0
- package/src/components/top-nav.tsx +660 -0
- package/src/components/truncate.tsx +234 -0
- package/src/deprecated.ts +61 -0
- package/src/index.ts +184 -0
- package/src/lib/cn.ts +22 -0
- package/src/lib/color.ts +469 -0
- package/src/lib/contrast.ts +220 -0
- package/src/lib/create-theme.ts +659 -0
- package/src/lib/harmony.ts +609 -0
- package/src/lib/import-theme.ts +272 -0
- package/src/lib/overflow-scroll.tsx +108 -0
- package/src/lib/radio-toggle-render.tsx +15 -0
- package/src/lib/reorder.ts +222 -0
- package/src/lib/spacing.ts +189 -0
- package/src/lib/tailwind-palette.ts +355 -0
- package/src/lib/truncate.ts +79 -0
- package/src/lib/use-single-value.ts +23 -0
- package/src/styles/continuum.css +3 -0
- package/src/styles/theme.css +524 -0
- package/src/styles/tokens.css +647 -0
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGreyRamp,
|
|
3
|
+
buildRamp,
|
|
4
|
+
type Gamut,
|
|
5
|
+
hasRampSteps,
|
|
6
|
+
hexToOklch,
|
|
7
|
+
type Oklch,
|
|
8
|
+
type RampShape,
|
|
9
|
+
type RampStep,
|
|
10
|
+
type RampSteps,
|
|
11
|
+
rampLightness,
|
|
12
|
+
rampSteps,
|
|
13
|
+
rampToCss,
|
|
14
|
+
toCss,
|
|
15
|
+
} from './color';
|
|
16
|
+
import { wcagContrast } from './contrast';
|
|
17
|
+
import { buildChartSeries, type ChartHarmony, type ChartLead, type ChartSeries } from './harmony';
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* The theme builder. A theme is a handful of choices (an accent, how grey the
|
|
21
|
+
* greys are, a font, how the action and the selection draw) turned into a
|
|
22
|
+
* `.continuum[data-theme="name"]` block that overrides the default tokens.
|
|
23
|
+
* Components never change; only the values behind the tokens do.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The fonts a theme picks from by name: each read from `--font-<id>` (set it from `next/font`), then
|
|
28
|
+
* its Fontsource variable family, then the installed family. Any other value is used as a family.
|
|
29
|
+
*/
|
|
30
|
+
export const themeFontFamilies = {
|
|
31
|
+
geist: { family: 'Geist', package: '@fontsource-variable/geist' },
|
|
32
|
+
inter: { family: 'Inter', package: '@fontsource-variable/inter' },
|
|
33
|
+
'instrument-sans': {
|
|
34
|
+
family: 'Instrument Sans',
|
|
35
|
+
package: '@fontsource-variable/instrument-sans',
|
|
36
|
+
},
|
|
37
|
+
'ibm-plex-sans': {
|
|
38
|
+
family: 'IBM Plex Sans',
|
|
39
|
+
package: '@fontsource-variable/ibm-plex-sans',
|
|
40
|
+
},
|
|
41
|
+
figtree: { family: 'Figtree', package: '@fontsource-variable/figtree' },
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
export type ThemeFontId = keyof typeof themeFontFamilies;
|
|
45
|
+
|
|
46
|
+
export type ThemeFont = ThemeFontId | (string & {});
|
|
47
|
+
|
|
48
|
+
/** A theme's own data colours, in place of the set its accent leads. */
|
|
49
|
+
export type ThemeCharts = {
|
|
50
|
+
/** chart-1 to chart-5: steps in order, a funnel or shades of one measure. */
|
|
51
|
+
steps: readonly string[];
|
|
52
|
+
/** The steps dark mode changes, by position, so a deep one still reads on a dark surface. */
|
|
53
|
+
dark?: readonly (string | null)[];
|
|
54
|
+
/** series-2 to series-4, for independent series; without them the series take chart-2 to chart-4. */
|
|
55
|
+
series?: readonly string[];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type ThemeOptions = {
|
|
59
|
+
/** The `data-theme` value the block is written for. */
|
|
60
|
+
name?: string;
|
|
61
|
+
/** A hex colour; it becomes the primary ramp's `accentStep` and the rest is built around it. */
|
|
62
|
+
accent?: string;
|
|
63
|
+
/** Which step of the primary ramp the accent is; the 500 unless given. */
|
|
64
|
+
accentStep?: RampStep;
|
|
65
|
+
/** The greys: an oklch hue and the chroma at their peak (0 is pure grey; 0.012 is clearly tinted). */
|
|
66
|
+
neutral?: { hue: number; tint: number };
|
|
67
|
+
/** The colours the ramps may use: Display P3, as Tailwind's palette, or sRGB, which every screen shows. */
|
|
68
|
+
gamut?: Gamut;
|
|
69
|
+
/**
|
|
70
|
+
* How each ramp's curves are shaped; anything left out is Tailwind's. Dark mode reads the greys
|
|
71
|
+
* back to front, so one bend of their midtones moves the two modes opposite ways: `neutralDark`
|
|
72
|
+
* bends dark's own; the ends and the rest of the shape stay the two modes'. Left out, dark
|
|
73
|
+
* follows the greys' midtones.
|
|
74
|
+
*/
|
|
75
|
+
curves?: { primary?: RampShape; neutral?: RampShape; neutralDark?: { midtones?: number } };
|
|
76
|
+
/**
|
|
77
|
+
* The base type size in px, 13 as drawn. Every size on the scale follows it, rounded to a whole
|
|
78
|
+
* pixel, its line height 1.25 times that.
|
|
79
|
+
*/
|
|
80
|
+
type?: number;
|
|
81
|
+
/**
|
|
82
|
+
* The spacing unit in whole px, 4 as drawn: every padding, gap and margin is a multiple of it, the
|
|
83
|
+
* steps between whole units each rounded to a pixel. 3 is tight, 5 roomy.
|
|
84
|
+
*/
|
|
85
|
+
unit?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Every fixed height (controls, rows, bars) times this, each rounded to a whole pixel: 1 as drawn,
|
|
88
|
+
* 0.9 compact, 1.1 large.
|
|
89
|
+
*/
|
|
90
|
+
size?: number;
|
|
91
|
+
font?: ThemeFont;
|
|
92
|
+
/** What the primary button, checked controls and the active rail item are filled with. */
|
|
93
|
+
action?: 'neutral' | 'accent';
|
|
94
|
+
/** `lit` adds a top highlight and a ring; `glossy` adds a gradient as well. */
|
|
95
|
+
actionStyle?: 'flat' | 'lit' | 'glossy';
|
|
96
|
+
/**
|
|
97
|
+
* What a control holds inside its hairline: `outline` nothing, as drawn; `filled` a faint ink
|
|
98
|
+
* wash, so fields, selects, secondary buttons and the segmented control's track read as things
|
|
99
|
+
* to press rather than outlines on the panel. Ghost buttons, plain inputs and the primary button
|
|
100
|
+
* are the same in both.
|
|
101
|
+
*/
|
|
102
|
+
controls?: 'outline' | 'filled';
|
|
103
|
+
/**
|
|
104
|
+
* How a card with a head is drawn: `plain` one surface, as drawn; `framed` a frame a step off
|
|
105
|
+
* the page holding its head and foot, its content on a stage of its own inside it. Charts, stat
|
|
106
|
+
* cards, titled cards, checklists and settings cards; a card with no head, and a table,
|
|
107
|
+
* stay plain.
|
|
108
|
+
*/
|
|
109
|
+
cards?: 'plain' | 'framed';
|
|
110
|
+
/** The selected wash: a translucent neutral, or the accent's palest step. */
|
|
111
|
+
tint?: 'neutral' | 'accent';
|
|
112
|
+
/** The dock, rail and small chips: full pills, or a tighter 10px corner. */
|
|
113
|
+
dock?: 'pill' | 'rounded';
|
|
114
|
+
/**
|
|
115
|
+
* The page you are on in the sidebar: `quiet` the grey wash, `tinted` the primary's tint, `raised`
|
|
116
|
+
* a card on the canvas. The sections that hold it stay plain in every look; their darkened guide
|
|
117
|
+
* line leads to the page. A filled row would read as a button; a page that wants one adds one.
|
|
118
|
+
*/
|
|
119
|
+
nav?: 'quiet' | 'tinted' | 'raised';
|
|
120
|
+
/**
|
|
121
|
+
* What lifts off the page: `flat` only what floats (menus, popovers, sheets); `full` cards,
|
|
122
|
+
* panels and table frames as well, and the controls on them (fields, selects, secondary buttons,
|
|
123
|
+
* segmented controls, checkboxes). A theme saved with `soft`, since removed, reads as `full`.
|
|
124
|
+
*/
|
|
125
|
+
elevation?: 'flat' | 'full';
|
|
126
|
+
/** Letter spacing, in em of the type: 0.025 as drawn (0.32px at 13px), below 0 tighter. */
|
|
127
|
+
tracking?: number;
|
|
128
|
+
/** Line height as a share of the type size: 1.25 as drawn, every size on the scale with it. */
|
|
129
|
+
leading?: number;
|
|
130
|
+
/** How dark the shadows are: 1 as drawn, 0.25 barely there, 3 heavy. */
|
|
131
|
+
shadowStrength?: number;
|
|
132
|
+
/** How far the shadows reach: 1 as drawn, 0.5 tight, 3 wide and soft. */
|
|
133
|
+
shadowSize?: number;
|
|
134
|
+
/** Corner scale; 1 is as drawn, 0 squares everything off. */
|
|
135
|
+
radius?: number;
|
|
136
|
+
/**
|
|
137
|
+
* How series 2 to 4 are found from the primary: auto takes the hues that stay furthest apart for
|
|
138
|
+
* every reader, the others follow a harmony on the oklch wheel. Each series takes the step of its
|
|
139
|
+
* hue that tells it best from its neighbours. Auto unless given; set colours in `charts` win.
|
|
140
|
+
*/
|
|
141
|
+
chartHarmony?: ChartHarmony;
|
|
142
|
+
/**
|
|
143
|
+
* The harmony's one parameter, in degrees: how far analogous hues spread either side of the
|
|
144
|
+
* primary (30 as drawn, the outer one twice as far), how far split complementary ones sit either
|
|
145
|
+
* side of its opposite (30), how wide the tetradic rectangle is (60). Others have none.
|
|
146
|
+
*/
|
|
147
|
+
chartSpread?: number;
|
|
148
|
+
/** With the `custom` harmony: series 2 to 4, in order, as turns of the primary's hue. */
|
|
149
|
+
chartTurns?: readonly number[];
|
|
150
|
+
/**
|
|
151
|
+
* Steps held by hand: the light-mode step (3 to 8, the 300 to the 800) of each of the
|
|
152
|
+
* harmony's hues, in the order it lists its turns (custom: `chartTurns`); null leaves one to the
|
|
153
|
+
* search. Dark mode holds the same place in its band, a step lighter. Auto ignores it.
|
|
154
|
+
*/
|
|
155
|
+
chartSteps?: readonly (number | null)[];
|
|
156
|
+
/**
|
|
157
|
+
* Series 1 put by hand: `turn` is its hue as a turn of the primary's, `step` its light-mode
|
|
158
|
+
* step (3 to 8, the 300 to the 800). It is the primary's own 500 unless given, and the harmony's
|
|
159
|
+
* hues are turns of its hue, so the set follows it.
|
|
160
|
+
*/
|
|
161
|
+
chartLead?: ChartLead;
|
|
162
|
+
/** Data colours of the theme's own, in place of the set the harmony finds. */
|
|
163
|
+
charts?: ThemeCharts;
|
|
164
|
+
/**
|
|
165
|
+
* A texture in every tint a chart draws (an area's fill, a tinted bar): diagonal stripes or
|
|
166
|
+
* a field of dots. None unless given; a chart can still ask for one, or none, itself.
|
|
167
|
+
*/
|
|
168
|
+
chartTexture?: 'none' | 'stripes' | 'dots';
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const defaultThemeOptions = {
|
|
172
|
+
name: 'custom',
|
|
173
|
+
accentStep: '500' as RampStep,
|
|
174
|
+
gamut: 'p3' as Gamut,
|
|
175
|
+
// No theme leans nowhere: the baseline greys are achromatic.
|
|
176
|
+
neutral: { hue: 0, tint: 0 },
|
|
177
|
+
font: 'geist' as ThemeFont,
|
|
178
|
+
// A theme's own colour fills its main button unless it asks for near-black.
|
|
179
|
+
action: 'accent' as 'accent' | 'neutral',
|
|
180
|
+
actionStyle: 'flat' as const,
|
|
181
|
+
controls: 'outline' as const,
|
|
182
|
+
cards: 'plain' as const,
|
|
183
|
+
tint: 'neutral' as const,
|
|
184
|
+
nav: 'quiet' as const,
|
|
185
|
+
elevation: 'flat' as const,
|
|
186
|
+
dock: 'pill' as const,
|
|
187
|
+
radius: 1,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** The baseline greys, as the tokens write them: achromatic; new greys keep their lightness at every step. */
|
|
191
|
+
export const defaultNeutral: RampSteps = [
|
|
192
|
+
'#f8f8f8',
|
|
193
|
+
'#ededed',
|
|
194
|
+
'#d2d2d2',
|
|
195
|
+
'#b3b3b3',
|
|
196
|
+
'#9a9a9a',
|
|
197
|
+
'#818181',
|
|
198
|
+
'#676767',
|
|
199
|
+
'#484848',
|
|
200
|
+
'#2a2a2a',
|
|
201
|
+
'#181818',
|
|
202
|
+
'#0d0d0d',
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
/** The default accent, as the tokens write it: the indigo built from #3939e5 on the same curve. */
|
|
206
|
+
export const defaultAccent: RampSteps = [
|
|
207
|
+
'#f2f5ff',
|
|
208
|
+
'#dee6ff',
|
|
209
|
+
'#bdccfe',
|
|
210
|
+
'#91a7fe',
|
|
211
|
+
'#596ff4',
|
|
212
|
+
'#3939e5',
|
|
213
|
+
'#3218e0',
|
|
214
|
+
'#2a16c4',
|
|
215
|
+
'#23219f',
|
|
216
|
+
'#20267f',
|
|
217
|
+
'#171e52',
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const steps = rampSteps;
|
|
221
|
+
|
|
222
|
+
const neutralLightness = rampLightness(defaultNeutral);
|
|
223
|
+
|
|
224
|
+
/** The accent the default primary ramp was built from, at its 500. */
|
|
225
|
+
export const defaultAccentSeed = '#3939e5';
|
|
226
|
+
|
|
227
|
+
/** True when a shape sets any of its controls, or any step by hand. */
|
|
228
|
+
const touched = (shape?: RampShape) =>
|
|
229
|
+
Boolean(
|
|
230
|
+
shape &&
|
|
231
|
+
(Object.values(shape).some(
|
|
232
|
+
value => typeof value === 'number' && Number.isFinite(value),
|
|
233
|
+
) ||
|
|
234
|
+
hasRampSteps(shape)),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
/** The type scale as drawn, size and line height in px, by Tailwind's names. */
|
|
238
|
+
export const typeScale = {
|
|
239
|
+
xxs: [11, 13.75],
|
|
240
|
+
xs: [13, 16.25],
|
|
241
|
+
sm: [14, 17.5],
|
|
242
|
+
base: [16, 20],
|
|
243
|
+
lg: [18, 22.5],
|
|
244
|
+
xl: [20, 25],
|
|
245
|
+
'2xl': [24, 30],
|
|
246
|
+
'3xl': [31, 38.75],
|
|
247
|
+
'4xl': [39, 48.75],
|
|
248
|
+
'5xl': [48, 60],
|
|
249
|
+
'6xl': [61, 76.25],
|
|
250
|
+
} as const;
|
|
251
|
+
|
|
252
|
+
/** The base size the type scale is drawn at, and the spacing unit it is drawn on, in px. */
|
|
253
|
+
export const drawnType = 13;
|
|
254
|
+
export const drawnUnit = 4;
|
|
255
|
+
|
|
256
|
+
const px = (value: number) => `${Number(value.toFixed(2))}px`;
|
|
257
|
+
|
|
258
|
+
const gamutOf = (options: ThemeOptions) => options.gamut ?? defaultThemeOptions.gamut;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The primary ramp a set of options produces, as oklch colours: built around the accent at its step,
|
|
262
|
+
* with the steps set by hand. Null for the default ramp: no accent and nothing set by hand.
|
|
263
|
+
*/
|
|
264
|
+
export const themeAccentCurves = (options: ThemeOptions): Oklch[] | null => {
|
|
265
|
+
const shape = options.curves?.primary;
|
|
266
|
+
const seed =
|
|
267
|
+
hexToOklch(options.accent ?? '') ?? (touched(shape) ? hexToOklch(defaultAccentSeed) : null);
|
|
268
|
+
if (!seed) return null;
|
|
269
|
+
const step = steps.indexOf(options.accentStep ?? defaultThemeOptions.accentStep);
|
|
270
|
+
return buildRamp(seed, { step: step < 0 ? 5 : step, gamut: gamutOf(options), shape });
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** The greys' shape a mode is built from: dark takes its own midtones when it has them. */
|
|
274
|
+
export const greyShapeOf = (options: ThemeOptions, mode: 'light' | 'dark' = 'light') => {
|
|
275
|
+
const shape = options.curves?.neutral;
|
|
276
|
+
const own = options.curves?.neutralDark?.midtones;
|
|
277
|
+
// The same bend as light's is light's own shape, so the two modes build the one ramp.
|
|
278
|
+
return mode === 'dark' && own !== undefined && own !== (shape?.midtones ?? 0)
|
|
279
|
+
? { ...shape, midtones: own }
|
|
280
|
+
: shape;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The grey ramp a set of options produces for a mode, as oklch colours, in the ramp's own order
|
|
285
|
+
* (50 to 950; dark mode reads it back to front); null for the baseline greys.
|
|
286
|
+
*/
|
|
287
|
+
export const themeNeutralCurves = (
|
|
288
|
+
options: ThemeOptions,
|
|
289
|
+
mode: 'light' | 'dark' = 'light',
|
|
290
|
+
): Oklch[] | null => {
|
|
291
|
+
const neutral = options.neutral ?? defaultThemeOptions.neutral;
|
|
292
|
+
const shape = greyShapeOf(options, mode);
|
|
293
|
+
// No tint is the baseline whatever the hue says, unless the curves were shaped.
|
|
294
|
+
if (neutral.tint === 0 && !touched(shape)) return null;
|
|
295
|
+
return buildGreyRamp(neutral.hue, neutral.tint, neutralLightness, {
|
|
296
|
+
gamut: gamutOf(options),
|
|
297
|
+
shape,
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/** Each named font as a `font-family` stack; the platform font is only the last fallback. */
|
|
302
|
+
export const themeFonts = Object.fromEntries(
|
|
303
|
+
Object.entries(themeFontFamilies).map(([id, { family }]) => [
|
|
304
|
+
id,
|
|
305
|
+
`var(--font-${id}, "${family} Variable"), "${family}", ui-sans-serif, system-ui, sans-serif`,
|
|
306
|
+
]),
|
|
307
|
+
) as Record<ThemeFontId, string>;
|
|
308
|
+
|
|
309
|
+
const fontFamily = (font: ThemeFont) =>
|
|
310
|
+
font in themeFonts ? themeFonts[font as keyof typeof themeFonts] : font;
|
|
311
|
+
|
|
312
|
+
/** The neutral ramp a set of options produces for a mode, as stylesheet values, 50 to 950. */
|
|
313
|
+
export const themeNeutralRamp = (
|
|
314
|
+
options: ThemeOptions,
|
|
315
|
+
mode: 'light' | 'dark' = 'light',
|
|
316
|
+
): RampSteps => {
|
|
317
|
+
const curves = themeNeutralCurves(options, mode);
|
|
318
|
+
return curves ? rampToCss(curves, gamutOf(options)) : defaultNeutral;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/** The accent ramp a set of options produces, as stylesheet values; the default when there is none. */
|
|
322
|
+
export const themeAccentRamp = (options: ThemeOptions): RampSteps => {
|
|
323
|
+
const curves = themeAccentCurves(options);
|
|
324
|
+
return curves ? rampToCss(curves, gamutOf(options)) : defaultAccent;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export type ThemeVariables = {
|
|
328
|
+
/** Set on `.continuum[data-theme]`. */
|
|
329
|
+
light: Record<string, string>;
|
|
330
|
+
/** Set on `.continuum[data-theme][data-mode="dark"]`. */
|
|
331
|
+
dark: Record<string, string>;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const asOklch = (ramp: readonly string[]) =>
|
|
335
|
+
ramp.map(value => hexToOklch(value) ?? { l: 0.5, c: 0, h: 0 });
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Series 1 to 4 a set of options finds, for light and dark; null when the options leave the data
|
|
339
|
+
* colours to the tokens' own (no accent and no harmony) or set their own in `charts`.
|
|
340
|
+
*/
|
|
341
|
+
export const themeChartSeries = (options: ThemeOptions): ChartSeries | null => {
|
|
342
|
+
if (options.charts) return null;
|
|
343
|
+
const curves = themeAccentCurves(options);
|
|
344
|
+
if (!curves && !options.chartHarmony && !options.chartLead) return null;
|
|
345
|
+
const greys = themeNeutralCurves(options) ?? asOklch(defaultNeutral);
|
|
346
|
+
const surface = { light: greys[0], dark: greys[10] };
|
|
347
|
+
if (!surface.light || !surface.dark) return null;
|
|
348
|
+
return buildChartSeries(curves ?? asOklch(defaultAccent), options.chartHarmony ?? 'auto', {
|
|
349
|
+
gamut: gamutOf(options),
|
|
350
|
+
surface: { light: surface.light, dark: surface.dark },
|
|
351
|
+
spread: options.chartSpread,
|
|
352
|
+
turns: options.chartTurns,
|
|
353
|
+
steps: options.chartSteps,
|
|
354
|
+
lead: options.chartLead,
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/** Every token a set of options changes, as custom properties, for light and for dark. */
|
|
359
|
+
export const createThemeVariables = (options: ThemeOptions): ThemeVariables => {
|
|
360
|
+
const light: Record<string, string> = {};
|
|
361
|
+
const dark: Record<string, string> = {};
|
|
362
|
+
const hasAccent = themeAccentCurves(options) !== null;
|
|
363
|
+
|
|
364
|
+
const neutral = themeNeutralRamp(options);
|
|
365
|
+
if (neutral !== defaultNeutral) {
|
|
366
|
+
steps.forEach((step, i) => {
|
|
367
|
+
light[`--continuum-n-${step}`] = neutral[i] ?? '';
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
// Dark's own midtones: its greys between the shared ends, back to front, over the ramp's.
|
|
371
|
+
const darkGreys = themeNeutralRamp(options, 'dark');
|
|
372
|
+
if (darkGreys.some((value, i) => value !== neutral[i])) {
|
|
373
|
+
steps.forEach((_, i) => {
|
|
374
|
+
if (i === 0 || i === 10) return;
|
|
375
|
+
dark[`--color-neutral-${steps[10 - i]}`] = darkGreys[i] ?? '';
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const accent = themeAccentRamp(options);
|
|
380
|
+
if (hasAccent) {
|
|
381
|
+
steps.forEach((step, i) => {
|
|
382
|
+
light[`--continuum-p-${step}`] = accent[i] ?? '';
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (options.font && options.font !== defaultThemeOptions.font) {
|
|
387
|
+
light['--font-sans'] = fontFamily(options.font);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Type: every size on the scale from the base, rounded to a pixel, and its line height the
|
|
391
|
+
// theme's share of it (1.25 as drawn).
|
|
392
|
+
const type = options.type ?? drawnType;
|
|
393
|
+
const leading = options.leading;
|
|
394
|
+
if (type !== drawnType || leading !== undefined) {
|
|
395
|
+
const scale = type / drawnType;
|
|
396
|
+
for (const [name, [size, line]] of Object.entries(typeScale)) {
|
|
397
|
+
const rounded = Math.round(size * scale);
|
|
398
|
+
light[`--text-${name}`] = px(rounded);
|
|
399
|
+
light[`--text-${name}--line-height`] = px(rounded * (leading ?? line / size));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (leading !== undefined) light['--leading-normal'] = String(leading);
|
|
403
|
+
if (options.tracking !== undefined) {
|
|
404
|
+
light['--tracking-normal'] = `${Number(options.tracking.toFixed(4))}em`;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Spacing: a whole-pixel unit; the steps between units round themselves (tokens.css).
|
|
408
|
+
const unit = Math.round(options.unit ?? drawnUnit);
|
|
409
|
+
if (unit !== drawnUnit) {
|
|
410
|
+
light['--spacing'] = px(Math.max(1, unit));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Heights: every fixed height is drawn times this scale.
|
|
414
|
+
if (options.size !== undefined && options.size !== 1) {
|
|
415
|
+
light['--continuum-size-scale'] = String(options.size);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const action = options.action ?? defaultThemeOptions.action;
|
|
419
|
+
const style = options.actionStyle ?? defaultThemeOptions.actionStyle;
|
|
420
|
+
if (action === 'accent') {
|
|
421
|
+
const ramp = themeAccentCurves(options) ?? asOklch(defaultAccent);
|
|
422
|
+
const greys = themeNeutralCurves(options) ?? asOklch(defaultNeutral);
|
|
423
|
+
// The surface and the canvas each mode paints: dark reads the greys back to front.
|
|
424
|
+
const ground = {
|
|
425
|
+
light: [greys[0], greys[1]],
|
|
426
|
+
dark: [greys[10], greys[9]],
|
|
427
|
+
};
|
|
428
|
+
/** The first raw step from `from`, walking `by`, that keeps 3:1 on both grounds. */
|
|
429
|
+
const reach = (from: number, by: 1 | -1, on: (Oklch | undefined)[]) => {
|
|
430
|
+
for (let i = from; i >= 0 && i <= 10; i += by) {
|
|
431
|
+
const color = ramp[i];
|
|
432
|
+
if (color && on.every(bg => !bg || wcagContrast(color, bg) >= 3)) return i;
|
|
433
|
+
}
|
|
434
|
+
return by > 0 ? 10 : 0;
|
|
435
|
+
};
|
|
436
|
+
// What sits on the fill is neutral, never a step of the fill's own ramp: the palest grey
|
|
437
|
+
// wherever it keeps 3:1, the deepest only below that (an orange, a lime, a sky). WCAG's ratio
|
|
438
|
+
// under-rates white on saturated mid-tones, so the higher of the two ratios would put black
|
|
439
|
+
// on a blue, red or violet 500 that reads better in white. The raw greys, so it is the same
|
|
440
|
+
// in both modes, as the fill is.
|
|
441
|
+
const fill = ramp[5];
|
|
442
|
+
const paleGrey = greys[0];
|
|
443
|
+
const deepGrey = greys[10];
|
|
444
|
+
light['--color-action'] = 'var(--color-primary-500)';
|
|
445
|
+
light['--color-action-hover'] = 'var(--color-primary-600)';
|
|
446
|
+
light['--color-on-action'] =
|
|
447
|
+
fill && paleGrey && deepGrey && wcagContrast(paleGrey, fill) < 3
|
|
448
|
+
? 'var(--continuum-n-950)'
|
|
449
|
+
: 'var(--continuum-n-50)';
|
|
450
|
+
// The knob of a switch is a shape on the fill, not a label: the palest grey unless the fill
|
|
451
|
+
// is so pale itself that only the deepest shows on it.
|
|
452
|
+
light['--color-action-knob'] =
|
|
453
|
+
fill && paleGrey && wcagContrast(paleGrey, fill) < 1.6
|
|
454
|
+
? 'var(--continuum-n-950)'
|
|
455
|
+
: 'var(--continuum-n-50)';
|
|
456
|
+
|
|
457
|
+
// The ring is the accent's first step from its 300 that keeps 3:1 on the surface and the
|
|
458
|
+
// canvas, as the grey ring is: deeper in light, paler in dark.
|
|
459
|
+
const ringLight = `var(--continuum-p-${steps[reach(3, 1, ground.light)]})`;
|
|
460
|
+
const ringDark = `var(--continuum-p-${steps[reach(3, -1, ground.dark)]})`;
|
|
461
|
+
light['--color-focus'] = ringLight;
|
|
462
|
+
if (ringDark !== ringLight) dark['--color-focus'] = ringDark;
|
|
463
|
+
}
|
|
464
|
+
const lit = (step: number) => `var(--continuum-p-${steps[Math.max(0, step - 1)]})`;
|
|
465
|
+
if (style !== 'flat') {
|
|
466
|
+
light['--color-action-highlight'] =
|
|
467
|
+
action === 'accent'
|
|
468
|
+
? lit(5)
|
|
469
|
+
: 'color-mix(in oklab, var(--color-on-action) 20%, transparent)';
|
|
470
|
+
light['--color-action-ring'] = 'var(--color-action)';
|
|
471
|
+
}
|
|
472
|
+
if (style === 'glossy') {
|
|
473
|
+
light['--action-gradient'] =
|
|
474
|
+
action === 'accent'
|
|
475
|
+
? `linear-gradient(180deg, ${lit(5)}, var(--continuum-p-500))`
|
|
476
|
+
: 'linear-gradient(180deg, var(--color-neutral-800), var(--color-neutral-950))';
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if ((options.controls ?? defaultThemeOptions.controls) === 'filled') {
|
|
480
|
+
/*
|
|
481
|
+
* A wash of the text colour, never a fixed grey: a neutral-100 fill vanishes on a neutral-100
|
|
482
|
+
* panel, the wash shows on every surface. The ink reads back in dark, so the one mix is a dark
|
|
483
|
+
* wash in light and a light one in dark; light stays fainter, so a filled field never reads as
|
|
484
|
+
* a disabled one. Hover deepens it as the border deepens.
|
|
485
|
+
*/
|
|
486
|
+
const wash = (share: number) =>
|
|
487
|
+
`color-mix(in oklab, var(--color-neutral-950) ${share}%, transparent)`;
|
|
488
|
+
light['--color-control'] = wash(2.5);
|
|
489
|
+
light['--color-control-hover'] = wash(4.5);
|
|
490
|
+
dark['--color-control'] = wash(4);
|
|
491
|
+
dark['--color-control-hover'] = wash(6);
|
|
492
|
+
light['--color-segment-track'] = 'var(--color-control)';
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Empty turns the card-frame, card-head, card-stage and card-foot utilities to their framed values.
|
|
496
|
+
if ((options.cards ?? defaultThemeOptions.cards) === 'framed') light['--cards-framed'] = '';
|
|
497
|
+
|
|
498
|
+
if ((options.tint ?? defaultThemeOptions.tint) === 'accent') {
|
|
499
|
+
light['--color-tint'] = 'var(--color-primary-50)';
|
|
500
|
+
light['--color-tint-fg'] = 'var(--color-primary-700)';
|
|
501
|
+
// 700 reads back to a deep step on the dark wash; the raw 300 stays legible.
|
|
502
|
+
dark['--color-tint-fg'] = 'var(--continuum-p-300)';
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// The page you are on in the sidebar; the sections that hold it stay plain. A theme saved
|
|
506
|
+
// under an earlier name still reads; the filled looks, since removed, read as quiet.
|
|
507
|
+
const navNames: Record<string, ThemeOptions['nav']> = {
|
|
508
|
+
neutral: 'quiet',
|
|
509
|
+
tint: 'tinted',
|
|
510
|
+
fill: 'quiet',
|
|
511
|
+
bold: 'quiet',
|
|
512
|
+
};
|
|
513
|
+
const nav = navNames[String(options.nav)] ?? options.nav ?? defaultThemeOptions.nav;
|
|
514
|
+
const tintAt = (fill: string, text: string) => {
|
|
515
|
+
light[fill] = 'var(--color-primary-100)';
|
|
516
|
+
light[text] = 'var(--color-primary-700)';
|
|
517
|
+
// The 100 reads back to the 900 in dark, a muddy step darker than the canvas it should
|
|
518
|
+
// lift from: the accent's 500 shows through instead, at 30%, so the row lifts clearly off
|
|
519
|
+
// the dark canvas in the accent's own hue (the 600 at 20% read as a dull navy).
|
|
520
|
+
dark[fill] = 'color-mix(in oklab, var(--continuum-p-500) 30%, transparent)';
|
|
521
|
+
// The text takes the 100, near white in the accent's hue, so it reads clearly on that fill.
|
|
522
|
+
dark[text] = 'var(--continuum-p-100)';
|
|
523
|
+
};
|
|
524
|
+
if (nav === 'tinted') {
|
|
525
|
+
tintAt('--color-nav-active', '--color-nav-active-fg');
|
|
526
|
+
} else if (nav === 'raised') {
|
|
527
|
+
// A card on the canvas: the surface, a hairline and a short shadow. Dark reads the greys
|
|
528
|
+
// back to front, so there the surface would sink below the canvas: the item is the canvas
|
|
529
|
+
// lit a little instead, with a faint light edge.
|
|
530
|
+
light['--color-nav-active'] = 'var(--color-neutral-50)';
|
|
531
|
+
light['--color-nav-active-border'] = 'var(--color-neutral-200)';
|
|
532
|
+
light['--shadow-nav-active'] = '0 1px 2px 0 rgb(20 22 23 / 0.06)';
|
|
533
|
+
dark['--color-nav-active'] =
|
|
534
|
+
'color-mix(in oklab, var(--color-neutral-950) 7%, transparent)';
|
|
535
|
+
dark['--color-nav-active-border'] =
|
|
536
|
+
'color-mix(in oklab, var(--color-neutral-950) 10%, transparent)';
|
|
537
|
+
dark['--shadow-nav-active'] = '0 1px 2px 0 rgb(0 0 0 / 0.4)';
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// Cards and the controls on them lift together; the strength darkens them, the size spreads them.
|
|
541
|
+
const elevation = options.elevation ?? defaultThemeOptions.elevation;
|
|
542
|
+
if (elevation !== 'flat') {
|
|
543
|
+
const k = Math.max(0, options.shadowStrength ?? 1);
|
|
544
|
+
const z = Math.max(0.25, options.shadowSize ?? 1);
|
|
545
|
+
const n = (value: number) => Number(value.toFixed(2));
|
|
546
|
+
const shadow = (layers: [number, number, number, number][], tint: string, scale: number) =>
|
|
547
|
+
layers
|
|
548
|
+
.map(
|
|
549
|
+
([y, blur, spread, alpha]) =>
|
|
550
|
+
`0 ${n(y * z)}px ${n(blur * z)}px ${n(spread * z)}px rgb(${tint} / ${n(Math.min(1, alpha * k * scale))})`,
|
|
551
|
+
)
|
|
552
|
+
.join(', ');
|
|
553
|
+
// A card lifts a little more than a control, so the two read as layers.
|
|
554
|
+
const card: [number, number, number, number][] = [
|
|
555
|
+
[1, 2, 0, 0.06],
|
|
556
|
+
[4, 12, -2, 0.08],
|
|
557
|
+
];
|
|
558
|
+
const control: [number, number, number, number][] = [
|
|
559
|
+
[1, 2, 0, 0.07],
|
|
560
|
+
[2, 4, -1, 0.05],
|
|
561
|
+
];
|
|
562
|
+
// Dark: the canvas is near black, so a black shadow has little to darken. It is drawn
|
|
563
|
+
// deeper and wider there, and the lift is said mostly by a faint light top edge, as a
|
|
564
|
+
// surface catching light from above; the strength sets both.
|
|
565
|
+
const edge = (alpha: number) =>
|
|
566
|
+
`inset 0 1px 0 0 rgb(255 255 255 / ${n(Math.min(0.2, alpha * k))})`;
|
|
567
|
+
const deep = (layers: [number, number, number, number][]) =>
|
|
568
|
+
layers.map(([y, blur, spread, alpha]): [number, number, number, number] => [
|
|
569
|
+
y * 1.5,
|
|
570
|
+
blur * 1.5,
|
|
571
|
+
spread,
|
|
572
|
+
alpha,
|
|
573
|
+
]);
|
|
574
|
+
light['--shadow-card'] = shadow(card, '20 22 23', 1);
|
|
575
|
+
dark['--shadow-card'] = `${edge(0.06)}, ${shadow(deep(card), '0 0 0', 6)}`;
|
|
576
|
+
light['--shadow-control'] = shadow(control, '20 22 23', 1);
|
|
577
|
+
dark['--shadow-control'] = `${edge(0.05)}, ${shadow(deep(control), '0 0 0', 6)}`;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if ((options.dock ?? defaultThemeOptions.dock) === 'rounded') {
|
|
581
|
+
light['--continuum-r-dock'] = '10px';
|
|
582
|
+
light['--continuum-r-pill'] = '8px';
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (options.radius !== undefined && options.radius !== 1) {
|
|
586
|
+
light['--continuum-radius-scale'] = String(options.radius);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (options.chartTexture === 'stripes') light['--chart-texture-stripes'] = '1';
|
|
590
|
+
if (options.chartTexture === 'dots') light['--chart-texture-dots'] = '1';
|
|
591
|
+
|
|
592
|
+
if (options.charts) {
|
|
593
|
+
// The theme's own set, as given: the accent no longer leads it.
|
|
594
|
+
const { steps, dark: darkSteps = [], series = [] } = options.charts;
|
|
595
|
+
steps.forEach((hex, i) => {
|
|
596
|
+
light[`--color-chart-${i + 1}`] = hex;
|
|
597
|
+
});
|
|
598
|
+
series.forEach((hex, i) => {
|
|
599
|
+
light[`--color-chart-series-${i + 2}`] = hex;
|
|
600
|
+
});
|
|
601
|
+
darkSteps.forEach((hex, i) => {
|
|
602
|
+
if (hex) dark[`--color-chart-${i + 1}`] = hex;
|
|
603
|
+
});
|
|
604
|
+
} else {
|
|
605
|
+
// The primary leads the data colours; the harmony finds the three after it, per mode.
|
|
606
|
+
const series = themeChartSeries(options);
|
|
607
|
+
if (series) {
|
|
608
|
+
const gamut = gamutOf(options);
|
|
609
|
+
// Series 1 is a step of the primary while it keeps the primary's hue, and a colour of
|
|
610
|
+
// its own once it has been turned away from it.
|
|
611
|
+
const first = (mode: 'light' | 'dark') => {
|
|
612
|
+
const color = series[mode][0];
|
|
613
|
+
return series.leadTurn === 0 || !color
|
|
614
|
+
? `var(--continuum-p-${steps[series.primaryStep[mode]]})`
|
|
615
|
+
: toCss(color, gamut);
|
|
616
|
+
};
|
|
617
|
+
light['--color-chart-1'] = first('light');
|
|
618
|
+
light['--color-chart-5'] = 'var(--continuum-p-600)';
|
|
619
|
+
for (const i of [1, 2, 3]) {
|
|
620
|
+
const lit = series.light[i];
|
|
621
|
+
const deep = series.dark[i];
|
|
622
|
+
if (lit) light[`--color-chart-${i + 1}`] = toCss(lit, gamut);
|
|
623
|
+
if (deep) dark[`--color-chart-${i + 1}`] = toCss(deep, gamut);
|
|
624
|
+
light[`--color-chart-series-${i + 1}`] = `var(--color-chart-${i + 1})`;
|
|
625
|
+
}
|
|
626
|
+
// A 500 sinks into a dark surface, so the set starts a step lighter.
|
|
627
|
+
dark['--color-chart-1'] = first('dark');
|
|
628
|
+
dark['--color-chart-5'] = 'var(--continuum-p-300)';
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return { light, dark };
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
const block = (selector: string, variables: Record<string, string>) =>
|
|
636
|
+
`${selector} {\n${Object.entries(variables)
|
|
637
|
+
.map(([name, value]) => ` ${name}: ${value};`)
|
|
638
|
+
.join('\n')}\n}`;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* The CSS for a theme: paste it after tokens.css and open the scope with
|
|
642
|
+
* `<Theme theme="name">`. Empty when the options are the defaults.
|
|
643
|
+
*/
|
|
644
|
+
export const createThemeCss = (options: ThemeOptions) => {
|
|
645
|
+
const name = options.name ?? defaultThemeOptions.name;
|
|
646
|
+
const { light, dark } = createThemeVariables(options);
|
|
647
|
+
const blocks: string[] = [];
|
|
648
|
+
if (Object.keys(light).length) blocks.push(block(`.continuum[data-theme="${name}"]`, light));
|
|
649
|
+
if (Object.keys(dark).length) {
|
|
650
|
+
blocks.push(block(`.continuum[data-theme="${name}"][data-mode="dark"]`, dark));
|
|
651
|
+
}
|
|
652
|
+
return blocks.join('\n\n');
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
/** True when the options change nothing, so no theme block is needed. */
|
|
656
|
+
export const isDefaultTheme = (options: ThemeOptions) => {
|
|
657
|
+
const { light, dark } = createThemeVariables(options);
|
|
658
|
+
return Object.keys(light).length === 0 && Object.keys(dark).length === 0;
|
|
659
|
+
};
|