@bigpixelrocket/uiok 0.0.0-stage → 0.1.1
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 +42 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour tokens, derived from a theme of the catalog, and the stylesheet
|
|
3
|
+
* that delivers them (`themes.generated.css`, written by `themes.test.ts`).
|
|
4
|
+
*
|
|
5
|
+
* A token follows a rule wherever one gives the value: a palette role, a mix,
|
|
6
|
+
* a choice by the theme's appearance, or the quietest tone that keeps its
|
|
7
|
+
* contrast on what it sits on. A theme overrides a token only where it was
|
|
8
|
+
* hand-tuned past what a rule gives (`Theme.overrides`), and a token derived
|
|
9
|
+
* from an overridden one (`--on-primary` from `--primary`) is derived from
|
|
10
|
+
* the override. A token other tokens read straight from the palette (the
|
|
11
|
+
* panel, the text, the primary hue, the group hues) takes no override; a
|
|
12
|
+
* theme sets it through its palette, or a group hue through `Theme.groups`.
|
|
13
|
+
* Tokens that read the same in every theme (aliases, shadows, the disabled
|
|
14
|
+
* opacity, the chart series) are fixed.
|
|
15
|
+
*
|
|
16
|
+
* An app that needs tokens of its own derives them from the same theme and
|
|
17
|
+
* emits them through `themeStylesheet`'s options, so one stylesheet holds
|
|
18
|
+
* both sets under the same selectors.
|
|
19
|
+
*/
|
|
20
|
+
import { type GroupHue, type TerminalPalette, type Theme, type ThemePalette } from './catalog.js';
|
|
21
|
+
import { type Hex } from './color.js';
|
|
22
|
+
import { type ThemeAppearance } from './ids.js';
|
|
23
|
+
/**
|
|
24
|
+
* The value a theme may override a token with, by what the token holds: a
|
|
25
|
+
* hex colour for a colour, a number or a percentage for a factor. A token
|
|
26
|
+
* written as a compound value (a translucent colour, a mix, a `var()`, a
|
|
27
|
+
* shadow) follows its rule in every theme and takes no override.
|
|
28
|
+
*/
|
|
29
|
+
type OverrideValue<Value> = Value extends Hex ? Hex : Value extends `${number}%` ? `${number}%` : Value extends `${number}` ? `${number}` : never;
|
|
30
|
+
/**
|
|
31
|
+
* Every token a theme sets, as `themeTokens` gives it, before it is written
|
|
32
|
+
* into the stylesheet. `overrides` replaces a token where the theme was
|
|
33
|
+
* hand-tuned, and each token the rules derive from it is derived from the
|
|
34
|
+
* replacement.
|
|
35
|
+
*/
|
|
36
|
+
declare function derivedTokens(palette: ThemePalette, terminal: TerminalPalette, appearance: ThemeAppearance, overrides: Readonly<Record<string, string | undefined>>, hues: Readonly<Partial<Record<GroupHue, Hex>>>): {
|
|
37
|
+
'--syntax-rosewater': `#${string}`;
|
|
38
|
+
'--syntax-flamingo': `#${string}`;
|
|
39
|
+
'--syntax-pink': `#${string}`;
|
|
40
|
+
'--syntax-mauve': `#${string}`;
|
|
41
|
+
'--syntax-red': `#${string}`;
|
|
42
|
+
'--syntax-maroon': `#${string}`;
|
|
43
|
+
'--syntax-peach': `#${string}`;
|
|
44
|
+
'--syntax-yellow': `#${string}`;
|
|
45
|
+
'--syntax-green': `#${string}`;
|
|
46
|
+
'--syntax-teal': `#${string}`;
|
|
47
|
+
'--syntax-sky': `#${string}`;
|
|
48
|
+
'--syntax-sapphire': `#${string}`;
|
|
49
|
+
'--syntax-blue': `#${string}`;
|
|
50
|
+
'--syntax-lavender': `#${string}`;
|
|
51
|
+
'--syntax-subtext0': `#${string}`;
|
|
52
|
+
'--syntax-overlay2': `#${string}`;
|
|
53
|
+
'--file-list-bg': string;
|
|
54
|
+
'--bg': `#${string}`;
|
|
55
|
+
'--bg-panel': `#${string}`;
|
|
56
|
+
'--bg-header': `#${string}`;
|
|
57
|
+
'--border': `#${string}`;
|
|
58
|
+
'--border-strong': `#${string}`;
|
|
59
|
+
'--text': `#${string}`;
|
|
60
|
+
'--text-dim': `#${string}`;
|
|
61
|
+
'--text-on-surface': `#${string}`;
|
|
62
|
+
'--accent': `#${string}`;
|
|
63
|
+
'--on-accent': `#${string}`;
|
|
64
|
+
'--primary-hue': `#${string}`;
|
|
65
|
+
'--primary': `#${string}`;
|
|
66
|
+
'--on-primary': `#${string}`;
|
|
67
|
+
'--on-tonal': `#${string}`;
|
|
68
|
+
'--tonal-border': `#${string}`;
|
|
69
|
+
'--tonal-hover-brightness': `${number}`;
|
|
70
|
+
'--row-lift': string;
|
|
71
|
+
'--cursor-bg': `#${string}`;
|
|
72
|
+
'--cursor-row-bg': `#${string}`;
|
|
73
|
+
'--row-meta-text': `#${string}`;
|
|
74
|
+
'--glass-edge': string;
|
|
75
|
+
'--hover-wash': string;
|
|
76
|
+
'--warning': `#${string}`;
|
|
77
|
+
'--success': `#${string}`;
|
|
78
|
+
'--danger': `#${string}`;
|
|
79
|
+
'--group-blue': `#${string}`;
|
|
80
|
+
'--group-green': `#${string}`;
|
|
81
|
+
'--group-purple': `#${string}`;
|
|
82
|
+
'--group-orange': `#${string}`;
|
|
83
|
+
'--group-teal': `#${string}`;
|
|
84
|
+
'--group-pink': `#${string}`;
|
|
85
|
+
'--group-yellow': `#${string}`;
|
|
86
|
+
'--group-red': `#${string}`;
|
|
87
|
+
'--group-dot-ring': string;
|
|
88
|
+
'--terminal-bg': `#${string}`;
|
|
89
|
+
'--terminal-fg': `#${string}`;
|
|
90
|
+
'--terminal-cursor': `#${string}`;
|
|
91
|
+
'--terminal-selection': string;
|
|
92
|
+
};
|
|
93
|
+
/** A colour token a theme sets. */
|
|
94
|
+
export type ThemeTokenName = keyof ReturnType<typeof derivedTokens>;
|
|
95
|
+
/** Every colour token a theme sets, by name, as `themeTokens` gives them. */
|
|
96
|
+
export type ThemeTokens = Readonly<Record<ThemeTokenName, string>>;
|
|
97
|
+
/**
|
|
98
|
+
* Tokens that take no override: each is a palette role other tokens are
|
|
99
|
+
* derived from straight from the palette (the panel's colour under the
|
|
100
|
+
* terminal and the listings' lift, the text in the quieter-text ramp and the
|
|
101
|
+
* terminal, the primary hue in the primary and tonal text, the group hues in
|
|
102
|
+
* their marks' ring), so an override would leave those behind. A theme
|
|
103
|
+
* changes them through its palette, and a group hue through `Theme.groups`.
|
|
104
|
+
*/
|
|
105
|
+
type PaletteDrawnToken = '--bg-panel' | '--text' | '--primary-hue' | `--group-${GroupHue}`;
|
|
106
|
+
/**
|
|
107
|
+
* The tokens a theme may override, each with the kind of value it holds: a
|
|
108
|
+
* colour token takes a six-digit hex colour, a factor its number or
|
|
109
|
+
* percentage. A token drawn straight from the palette (the panel, the text,
|
|
110
|
+
* the primary hue, the group hues) and a compound token (a shadow, a
|
|
111
|
+
* translucent colour) take none.
|
|
112
|
+
*/
|
|
113
|
+
export type ThemeOverrides = {
|
|
114
|
+
readonly [Name in Exclude<ThemeTokenName, PaletteDrawnToken> as [
|
|
115
|
+
OverrideValue<ReturnType<typeof derivedTokens>[Name]>
|
|
116
|
+
] extends [never] ? never : Name]?: OverrideValue<ReturnType<typeof derivedTokens>[Name]>;
|
|
117
|
+
};
|
|
118
|
+
/** Every colour token `theme` sets, in the stylesheet's order, its overrides applied. */
|
|
119
|
+
export declare function themeTokens(theme: Theme): ThemeTokens;
|
|
120
|
+
/**
|
|
121
|
+
* The colour tokens every theme shares: names for the grounds by role, mixes
|
|
122
|
+
* of a theme's tokens, shadows, the chart series, and the colours that hold
|
|
123
|
+
* in every theme by what they sit on.
|
|
124
|
+
*/
|
|
125
|
+
export declare const FIXED_TOKENS: Readonly<Record<string, string>>;
|
|
126
|
+
/**
|
|
127
|
+
* The tokens a theme's preview paints with (a theme picker's miniature
|
|
128
|
+
* window per theme): its grounds, hairline, text and quieter text, accent,
|
|
129
|
+
* primary, and six of its terminal colours. Each holds a literal colour in
|
|
130
|
+
* every theme, so a preview scope that sets them shows that theme whatever
|
|
131
|
+
* the page wears. A token that names another (`--surface` is
|
|
132
|
+
* `var(--bg-panel)`) is resolved where it is declared, on the root, so a
|
|
133
|
+
* preview paints with these names alone.
|
|
134
|
+
*/
|
|
135
|
+
export declare const PREVIEW_TOKENS: readonly ["--bg", "--bg-panel", "--bg-header", "--border", "--text", "--text-dim", "--accent", "--primary", "--terminal-ansi-1", "--terminal-ansi-2", "--terminal-ansi-3", "--terminal-ansi-4", "--terminal-ansi-5", "--terminal-ansi-6"];
|
|
136
|
+
/** The tokens `theme`'s preview scope sets: `PREVIEW_TOKENS`, as the theme sets them. */
|
|
137
|
+
export declare function previewTokens(theme: Theme): Readonly<Record<string, string>>;
|
|
138
|
+
/**
|
|
139
|
+
* What an app adds to the theme stylesheet: tokens of its own, derived from
|
|
140
|
+
* the same themes and written under the same selectors, so it ships one
|
|
141
|
+
* stylesheet rather than a second copy of every theme block. Each extra
|
|
142
|
+
* token must be a custom property (`--name`) that uiok does not define. No
|
|
143
|
+
* value or selector may hold a semicolon, a brace, or a comment delimiter
|
|
144
|
+
* outside a string or url(), nor the banner a comment's end, since each would
|
|
145
|
+
* end its declaration, rule, or comment early.
|
|
146
|
+
*/
|
|
147
|
+
export interface ThemeStylesheetOptions {
|
|
148
|
+
/**
|
|
149
|
+
* The comment the stylesheet opens with, without its delimiters: what
|
|
150
|
+
* generated the file and how to regenerate it. Defaults to uiok's own.
|
|
151
|
+
*/
|
|
152
|
+
readonly banner?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Whether the stylesheet holds uiok's own tokens as well as the app's (the
|
|
155
|
+
* default). An app that imports `@bigpixelrocket/uiok/styles.css`, which already carries
|
|
156
|
+
* them, sets `false` to write its own tokens alone under the same
|
|
157
|
+
* selectors, so no token is declared twice; a block left with nothing to
|
|
158
|
+
* declare is dropped.
|
|
159
|
+
*/
|
|
160
|
+
readonly includeUiokTokens?: boolean;
|
|
161
|
+
/** Tokens that read the same in every theme, added to `:root` after `FIXED_TOKENS`. */
|
|
162
|
+
readonly extraFixed?: Readonly<Record<string, string>>;
|
|
163
|
+
/**
|
|
164
|
+
* Tokens derived from each theme, added after uiok's own wherever a theme's
|
|
165
|
+
* tokens are written: the defaults on `:root` and each theme's block.
|
|
166
|
+
* `tokens` are the theme's uiok tokens with its overrides applied; the
|
|
167
|
+
* theme's palette, appearance, and id are on `theme`, so an app can tune a
|
|
168
|
+
* token for one theme by its id.
|
|
169
|
+
*/
|
|
170
|
+
readonly extraTokens?: (theme: Theme, tokens: ThemeTokens) => Readonly<Record<string, string>>;
|
|
171
|
+
/**
|
|
172
|
+
* Rules of tokens by selector, written after the default `:root` block and
|
|
173
|
+
* outside any query, such as tokens an attribute switches on the element
|
|
174
|
+
* that carries it (`[data-variant='compact']`).
|
|
175
|
+
*/
|
|
176
|
+
readonly extraBlocks?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The stylesheet of every colour token: the default themes on `:root` (light
|
|
180
|
+
* outside any query, dark under `prefers-color-scheme: dark`), a block per
|
|
181
|
+
* theme that `data-light-theme` or `data-dark-theme` on the root element
|
|
182
|
+
* selects under its appearance, and a preview scope per theme
|
|
183
|
+
* (`PREVIEW_TOKENS` under `data-theme-preview`) outside any query. `:root`
|
|
184
|
+
* also declares `color-scheme: light dark`, so native controls and scrollbars
|
|
185
|
+
* follow the appearance the tokens follow. `options` adds an app's own
|
|
186
|
+
* tokens to the same blocks, or writes those alone.
|
|
187
|
+
*/
|
|
188
|
+
export declare function themeStylesheet(options?: ThemeStylesheetOptions): string;
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour tokens, derived from a theme of the catalog, and the stylesheet
|
|
3
|
+
* that delivers them (`themes.generated.css`, written by `themes.test.ts`).
|
|
4
|
+
*
|
|
5
|
+
* A token follows a rule wherever one gives the value: a palette role, a mix,
|
|
6
|
+
* a choice by the theme's appearance, or the quietest tone that keeps its
|
|
7
|
+
* contrast on what it sits on. A theme overrides a token only where it was
|
|
8
|
+
* hand-tuned past what a rule gives (`Theme.overrides`), and a token derived
|
|
9
|
+
* from an overridden one (`--on-primary` from `--primary`) is derived from
|
|
10
|
+
* the override. A token other tokens read straight from the palette (the
|
|
11
|
+
* panel, the text, the primary hue, the group hues) takes no override; a
|
|
12
|
+
* theme sets it through its palette, or a group hue through `Theme.groups`.
|
|
13
|
+
* Tokens that read the same in every theme (aliases, shadows, the disabled
|
|
14
|
+
* opacity, the chart series) are fixed.
|
|
15
|
+
*
|
|
16
|
+
* An app that needs tokens of its own derives them from the same theme and
|
|
17
|
+
* emits them through `themeStylesheet`'s options, so one stylesheet holds
|
|
18
|
+
* both sets under the same selectors.
|
|
19
|
+
*/
|
|
20
|
+
import { DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, THEMES } from './catalog.js';
|
|
21
|
+
import { contrast, luminance, mix, translucent } from './color.js';
|
|
22
|
+
import { THEME_ATTRIBUTES, THEME_PREVIEW_ATTRIBUTE } from './ids.js';
|
|
23
|
+
const WHITE = '#ffffff';
|
|
24
|
+
const BLACK = '#000000';
|
|
25
|
+
/** Body text and anything read as words. */
|
|
26
|
+
const TEXT_CONTRAST = 4.5;
|
|
27
|
+
/** Marks read by shape alone: a dot, a glyph. */
|
|
28
|
+
const MARK_CONTRAST = 3;
|
|
29
|
+
/**
|
|
30
|
+
* How opaque a control that cannot act right now is drawn (`--disabled-opacity`,
|
|
31
|
+
* which the base stylesheet applies to every disabled control): its words,
|
|
32
|
+
* icons, and fill fade together, far enough from enabled text to read as
|
|
33
|
+
* unavailable at a glance in every theme, and near enough to stay legible.
|
|
34
|
+
*/
|
|
35
|
+
const DISABLED_OPACITY = 0.4;
|
|
36
|
+
/**
|
|
37
|
+
* What a theme's appearance decides on its own, the same for every theme of
|
|
38
|
+
* that appearance: how much each wash and lift shows over the grounds.
|
|
39
|
+
*/
|
|
40
|
+
const BY_APPEARANCE = {
|
|
41
|
+
light: {
|
|
42
|
+
cursorRow: 10,
|
|
43
|
+
rowLift: () => translucent(WHITE, 35),
|
|
44
|
+
glassEdge: translucent(WHITE, 60),
|
|
45
|
+
hoverWash: translucent(WHITE, 50),
|
|
46
|
+
// A pale fill barely brightens, so its hover deepens a touch instead.
|
|
47
|
+
tonalHoverBrightness: '0.97',
|
|
48
|
+
fileListLift: 30,
|
|
49
|
+
terminalSelection: 22
|
|
50
|
+
},
|
|
51
|
+
dark: {
|
|
52
|
+
cursorRow: 14,
|
|
53
|
+
rowLift: (palette) => translucent(palette.base, 50),
|
|
54
|
+
glassEdge: translucent(WHITE, 10),
|
|
55
|
+
hoverWash: translucent(WHITE, 6),
|
|
56
|
+
tonalHoverBrightness: '1.12',
|
|
57
|
+
fileListLift: 0,
|
|
58
|
+
terminalSelection: 28
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/** Whether `tone` keeps `ratio` on every one of `grounds`. */
|
|
62
|
+
function legibleOnAll(tone, grounds, ratio) {
|
|
63
|
+
return grounds.every((ground) => contrast(tone, ground) >= ratio);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The first of `candidates` that keeps `ratio` on every one of `grounds`,
|
|
67
|
+
* else the last, the strongest.
|
|
68
|
+
*/
|
|
69
|
+
function firstLegible(candidates, grounds, ratio) {
|
|
70
|
+
return (candidates.find((tone) => legibleOnAll(tone, grounds, ratio)) ?? candidates.at(-1) ?? WHITE);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* `color` moved away from `grounds` (toward black over light grounds, white
|
|
74
|
+
* over dark ones, judged by the first) a percent at a time until it keeps
|
|
75
|
+
* `ratio` on every one of them.
|
|
76
|
+
*/
|
|
77
|
+
function legibleOn(color, grounds, ratio) {
|
|
78
|
+
const away = luminance(grounds[0] ?? WHITE) > 0.18 ? BLACK : WHITE;
|
|
79
|
+
for (let share = 100; share > 0; share -= 1) {
|
|
80
|
+
const tone = mix(color, away, share);
|
|
81
|
+
if (legibleOnAll(tone, grounds, ratio))
|
|
82
|
+
return tone;
|
|
83
|
+
}
|
|
84
|
+
return away;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The text colour for a fill: white or the palette's darkest neutral,
|
|
88
|
+
* whichever stands out more on it.
|
|
89
|
+
*/
|
|
90
|
+
function onFill(fill, palette) {
|
|
91
|
+
const ink = luminance(palette.text) < luminance(palette.crust) ? palette.text : palette.crust;
|
|
92
|
+
return contrast(WHITE, fill) >= contrast(ink, fill) ? WHITE : ink;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Every token a theme sets, as `themeTokens` gives it, before it is written
|
|
96
|
+
* into the stylesheet. `overrides` replaces a token where the theme was
|
|
97
|
+
* hand-tuned, and each token the rules derive from it is derived from the
|
|
98
|
+
* replacement.
|
|
99
|
+
*/
|
|
100
|
+
function derivedTokens(palette, terminal, appearance, overrides, hues) {
|
|
101
|
+
const look = BY_APPEARANCE[appearance];
|
|
102
|
+
/**
|
|
103
|
+
* `name`'s override where the theme has one, else what its rule gives.
|
|
104
|
+
* `ThemeOverrides` holds an override to the kind of value its rule gives.
|
|
105
|
+
*/
|
|
106
|
+
const tuned = (name, rule) => overrides[name] ?? rule;
|
|
107
|
+
// The grounds: the window (mantle), panels (base), and the header bar (crust).
|
|
108
|
+
const ground = tuned('--bg', palette.mantle);
|
|
109
|
+
const panel = palette.base;
|
|
110
|
+
const header = tuned('--bg-header', palette.crust);
|
|
111
|
+
const surfaceFill = tuned('--cursor-bg', palette.surface0);
|
|
112
|
+
// The accent: the blue, moved until the text on it keeps 4.5:1, as a
|
|
113
|
+
// selected row's name sits on it.
|
|
114
|
+
const accent = tuned('--accent', legibleOn(palette.blue, [onFill(palette.blue, palette)], TEXT_CONTRAST));
|
|
115
|
+
// The neutral ramp from the quietest tone a word may wear to the text itself.
|
|
116
|
+
const quiet = [palette.subtext0, palette.subtext1, palette.text];
|
|
117
|
+
// A recessed surface, such as a tab behind the selected one: the panel at
|
|
118
|
+
// 45% over the ground. The group marks keep their ring rule against it.
|
|
119
|
+
const recessed = mix(panel, ground, 45);
|
|
120
|
+
// A listing's lift over the panel surface.
|
|
121
|
+
const fileList = mix(WHITE, panel, look.fileListLift);
|
|
122
|
+
// --text-dim sits on the ground, a panel, and the header bar.
|
|
123
|
+
const textDim = tuned('--text-dim', firstLegible(quiet, [ground, panel, header], TEXT_CONTRAST));
|
|
124
|
+
const rowMeta = tuned('--row-meta-text', firstLegible([palette.overlay2, ...quiet], [fileList], TEXT_CONTRAST));
|
|
125
|
+
const cursorRow = tuned('--cursor-row-bg', mix(accent, panel, look.cursorRow));
|
|
126
|
+
const primary = tuned('--primary', legibleOn(palette.lavender, [onFill(palette.lavender, palette)], TEXT_CONTRAST));
|
|
127
|
+
// Each group hue's palette role, unless the theme draws it apart
|
|
128
|
+
// (`Theme.groups`).
|
|
129
|
+
const groups = {
|
|
130
|
+
blue: hues.blue ?? palette.blue,
|
|
131
|
+
green: hues.green ?? palette.green,
|
|
132
|
+
purple: hues.purple ?? palette.mauve,
|
|
133
|
+
orange: hues.orange ?? palette.peach,
|
|
134
|
+
teal: hues.teal ?? palette.teal,
|
|
135
|
+
pink: hues.pink ?? palette.pink,
|
|
136
|
+
yellow: hues.yellow ?? palette.yellow,
|
|
137
|
+
red: hues.red ?? palette.red
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
'--bg': ground,
|
|
141
|
+
'--bg-panel': panel,
|
|
142
|
+
'--bg-header': header,
|
|
143
|
+
'--border': palette.surface0,
|
|
144
|
+
// For outlines on surface0 fills, where --border vanishes.
|
|
145
|
+
'--border-strong': palette.surface1,
|
|
146
|
+
'--text': palette.text,
|
|
147
|
+
// The quietest subtext that keeps 4.5:1 on the ground, a panel, and the header bar
|
|
148
|
+
// (Latte's subtext0 misses it on mantle).
|
|
149
|
+
'--text-dim': textDim,
|
|
150
|
+
// The quietest subtext that keeps 4.5:1 on surface0 fills and on the
|
|
151
|
+
// cursor row (Latte needs the text itself).
|
|
152
|
+
'--text-on-surface': tuned('--text-on-surface', firstLegible(quiet, [surfaceFill, cursorRow], TEXT_CONTRAST)),
|
|
153
|
+
// Selection, focus, and links.
|
|
154
|
+
'--accent': accent,
|
|
155
|
+
'--on-accent': tuned('--on-accent', onFill(accent, palette)),
|
|
156
|
+
// The palette's lavender as is, for icons and marks drawn in the primary
|
|
157
|
+
// hue; the primary fill and the tonal text derive from the same role.
|
|
158
|
+
'--primary-hue': palette.lavender,
|
|
159
|
+
// Primary actions wear the primary hue, moved until its text keeps
|
|
160
|
+
// 4.5:1, so they stand apart from the accent that marks selection,
|
|
161
|
+
// focus, and links.
|
|
162
|
+
'--primary': primary,
|
|
163
|
+
'--on-primary': tuned('--on-primary', onFill(primary, palette)),
|
|
164
|
+
// The middle button tier (.button-tonal) for a row's routine positive
|
|
165
|
+
// action such as Install: the cursor row's tint (--tonal) with text in
|
|
166
|
+
// the primary hue and a hairline, a quiet step below the solid primary and
|
|
167
|
+
// above the neutral outline; the hairline keeps it reading as a button,
|
|
168
|
+
// not as a highlighted row, inside tables.
|
|
169
|
+
'--on-tonal': tuned('--on-tonal', legibleOn(palette.lavender, [cursorRow], TEXT_CONTRAST)),
|
|
170
|
+
'--tonal-border': tuned('--tonal-border', mix(accent, cursorRow, 25)),
|
|
171
|
+
'--tonal-hover-brightness': tuned('--tonal-hover-brightness', look.tonalHoverBrightness),
|
|
172
|
+
// Listings lift themselves off the ground, so rows read as a pane rather
|
|
173
|
+
// than as the ground.
|
|
174
|
+
'--row-lift': look.rowLift(palette),
|
|
175
|
+
'--cursor-bg': surfaceFill,
|
|
176
|
+
// The keyboard cursor row in listings: a whisper of the accent over the
|
|
177
|
+
// panel, so the cursor reads apart from the surface0 hover fills.
|
|
178
|
+
'--cursor-row-bg': cursorRow,
|
|
179
|
+
// A listing row's attributes one tone under its name, as Finder's are, so
|
|
180
|
+
// the names lead; a dialog's title strip names where it acts in the same
|
|
181
|
+
// tone. The quietest tone from overlay2 up that keeps 4.5:1 on the
|
|
182
|
+
// listing, which is lighter than the ground in a light theme.
|
|
183
|
+
'--row-meta-text': rowMeta,
|
|
184
|
+
// Glass: the specular hairline along a raised surface's top edge, and the
|
|
185
|
+
// frosted wash every outlined control takes on hover.
|
|
186
|
+
'--glass-edge': look.glassEdge,
|
|
187
|
+
'--hover-wash': look.hoverWash,
|
|
188
|
+
'--warning': tuned('--warning', palette.yellow),
|
|
189
|
+
'--success': tuned('--success', palette.green),
|
|
190
|
+
// Errors and destructive marks: the red, moved until it keeps 4.5:1 on a
|
|
191
|
+
// panel, where error text sits.
|
|
192
|
+
'--danger': tuned('--danger', legibleOn(palette.red, [panel], TEXT_CONTRAST)),
|
|
193
|
+
// Eight categorical hues by plain name, for marks that tell the items of
|
|
194
|
+
// a set apart (a group, a tag, a label). A group mark is never a status.
|
|
195
|
+
// Where any hue falls under 3:1 on a recessed surface (Latte's yellow,
|
|
196
|
+
// pink, orange, and green sit near 2:1), every mark wears a hairline of
|
|
197
|
+
// the text colour, --group-dot-ring.
|
|
198
|
+
'--group-blue': groups.blue,
|
|
199
|
+
'--group-green': groups.green,
|
|
200
|
+
'--group-purple': groups.purple,
|
|
201
|
+
'--group-orange': groups.orange,
|
|
202
|
+
'--group-teal': groups.teal,
|
|
203
|
+
'--group-pink': groups.pink,
|
|
204
|
+
'--group-yellow': groups.yellow,
|
|
205
|
+
'--group-red': groups.red,
|
|
206
|
+
'--group-dot-ring': Object.values(groups).some((hue) => contrast(hue, recessed) < MARK_CONTRAST)
|
|
207
|
+
? `inset 0 0 0 1px ${translucent(palette.text, 28)}`
|
|
208
|
+
: 'none',
|
|
209
|
+
// A terminal, which a terminal engine reads as literal colours, so each
|
|
210
|
+
// is hex or rgb(): the theme's own terminal palette over its base, and
|
|
211
|
+
// the accent under the selection, which is drawn over the cell colours.
|
|
212
|
+
// The 256-colour cube and grey ramp derive from the 16.
|
|
213
|
+
'--terminal-bg': palette.base,
|
|
214
|
+
'--terminal-fg': palette.text,
|
|
215
|
+
'--terminal-cursor': terminal.cursor,
|
|
216
|
+
'--terminal-selection': translucent(accent, look.terminalSelection),
|
|
217
|
+
...Object.fromEntries(terminal.ansi.map((color, index) => [`--terminal-ansi-${index}`, color])),
|
|
218
|
+
// Syntax highlighting: Shiki's Catppuccin theme maps each token colour to
|
|
219
|
+
// its palette role, so a highlighter can follow these by the same names.
|
|
220
|
+
'--syntax-rosewater': palette.rosewater,
|
|
221
|
+
'--syntax-flamingo': palette.flamingo,
|
|
222
|
+
'--syntax-pink': palette.pink,
|
|
223
|
+
'--syntax-mauve': palette.mauve,
|
|
224
|
+
'--syntax-red': palette.red,
|
|
225
|
+
'--syntax-maroon': palette.maroon,
|
|
226
|
+
'--syntax-peach': palette.peach,
|
|
227
|
+
'--syntax-yellow': palette.yellow,
|
|
228
|
+
'--syntax-green': palette.green,
|
|
229
|
+
'--syntax-teal': palette.teal,
|
|
230
|
+
'--syntax-sky': palette.sky,
|
|
231
|
+
'--syntax-sapphire': palette.sapphire,
|
|
232
|
+
'--syntax-blue': palette.blue,
|
|
233
|
+
'--syntax-lavender': palette.lavender,
|
|
234
|
+
'--syntax-subtext0': palette.subtext0,
|
|
235
|
+
'--syntax-overlay2': palette.overlay2,
|
|
236
|
+
// A listing's ground (.listing-root): a white lift over a light panel
|
|
237
|
+
// with no second tint over the ground; nothing in a dark theme.
|
|
238
|
+
'--file-list-bg': look.fileListLift > 0 ? translucent(WHITE, look.fileListLift) : 'transparent'
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** Every colour token `theme` sets, in the stylesheet's order, its overrides applied. */
|
|
242
|
+
export function themeTokens(theme) {
|
|
243
|
+
const tokens = derivedTokens(theme.palette, theme.terminal, theme.appearance, theme.overrides ?? {}, theme.groups ?? {});
|
|
244
|
+
return { ...tokens, ...theme.overrides };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The colour tokens every theme shares: names for the grounds by role, mixes
|
|
248
|
+
* of a theme's tokens, shadows, the chart series, and the colours that hold
|
|
249
|
+
* in every theme by what they sit on.
|
|
250
|
+
*/
|
|
251
|
+
export const FIXED_TOKENS = {
|
|
252
|
+
// Surfaces: the three grounds by role. The body paints the ground once, a
|
|
253
|
+
// panel paints --surface, and what sits inside a panel paints no ground of
|
|
254
|
+
// its own. Surfaces that float over other content add --frost (the base
|
|
255
|
+
// stylesheet) so what scrolls under them blurs.
|
|
256
|
+
'--ground': 'var(--bg)',
|
|
257
|
+
'--surface': 'var(--bg-panel)',
|
|
258
|
+
'--surface-header': 'var(--bg-header)',
|
|
259
|
+
'--tonal': 'var(--cursor-row-bg)',
|
|
260
|
+
// The glass-edge hover every button shares: a frosted ring for outlined
|
|
261
|
+
// controls and a lit top edge for filled ones.
|
|
262
|
+
'--hover-frost': 'inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--border-strong)',
|
|
263
|
+
'--hover-lit': `inset 0 1px 0 ${translucent(WHITE, 40)}, inset 0 -1px 0 ${translucent(BLACK, 12)}`,
|
|
264
|
+
// A fill a step darker or lighter for a state laid over it: the cursor on
|
|
265
|
+
// a selection and a fuzzy match's characters over it darken the accent,
|
|
266
|
+
// and a primary fill lifts on hover.
|
|
267
|
+
'--selection-cursor': 'color-mix(in srgb, var(--accent) 80%, black)',
|
|
268
|
+
'--selection-hit': 'color-mix(in srgb, var(--accent) 70%, black)',
|
|
269
|
+
'--primary-hover': 'color-mix(in srgb, var(--primary) 88%, white)',
|
|
270
|
+
// A disabled control's opacity (DISABLED_OPACITY), the same in every theme.
|
|
271
|
+
'--disabled-opacity': `${DISABLED_OPACITY}`,
|
|
272
|
+
// Shadows by what casts them. Black in every theme, since a shadow only
|
|
273
|
+
// darkens the ground it falls on.
|
|
274
|
+
'--shadow-menu': `0 10px 24px ${translucent(BLACK, 18)}`,
|
|
275
|
+
'--shadow-dialog': `0 24px 60px ${translucent(BLACK, 28)}, 0 2px 8px ${translucent(BLACK, 12)}`,
|
|
276
|
+
'--shadow-notice': `0 6px 20px ${translucent(BLACK, 14)}`,
|
|
277
|
+
'--shadow-card': `0 8px 24px ${translucent(BLACK, 25)}`,
|
|
278
|
+
'--shadow-card-hover': `0 10px 28px ${translucent(BLACK, 30)}`,
|
|
279
|
+
'--shadow-segment': `0 1px 2px ${translucent(BLACK, 12)}`,
|
|
280
|
+
'--shadow-pressed': `inset 0 1px 2px ${translucent(BLACK, 18)}`,
|
|
281
|
+
'--shadow-knob': `0 1px 1px ${translucent(BLACK, 25)}`,
|
|
282
|
+
// A colour that holds in every theme by what it sits on: a switch's knob
|
|
283
|
+
// is white on its track.
|
|
284
|
+
'--switch-knob': WHITE,
|
|
285
|
+
// The chart series colours, in the order a chart assigns them, from the
|
|
286
|
+
// syntax palette.
|
|
287
|
+
'--chart-1': 'var(--syntax-blue)',
|
|
288
|
+
'--chart-2': 'var(--syntax-peach)',
|
|
289
|
+
'--chart-3': 'var(--syntax-green)',
|
|
290
|
+
'--chart-4': 'var(--syntax-mauve)',
|
|
291
|
+
'--chart-5': 'var(--syntax-teal)',
|
|
292
|
+
'--chart-6': 'var(--syntax-red)',
|
|
293
|
+
'--chart-7': 'var(--syntax-yellow)',
|
|
294
|
+
'--chart-8': 'var(--syntax-pink)'
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* The tokens a theme's preview paints with (a theme picker's miniature
|
|
298
|
+
* window per theme): its grounds, hairline, text and quieter text, accent,
|
|
299
|
+
* primary, and six of its terminal colours. Each holds a literal colour in
|
|
300
|
+
* every theme, so a preview scope that sets them shows that theme whatever
|
|
301
|
+
* the page wears. A token that names another (`--surface` is
|
|
302
|
+
* `var(--bg-panel)`) is resolved where it is declared, on the root, so a
|
|
303
|
+
* preview paints with these names alone.
|
|
304
|
+
*/
|
|
305
|
+
export const PREVIEW_TOKENS = [
|
|
306
|
+
'--bg',
|
|
307
|
+
'--bg-panel',
|
|
308
|
+
'--bg-header',
|
|
309
|
+
'--border',
|
|
310
|
+
'--text',
|
|
311
|
+
'--text-dim',
|
|
312
|
+
'--accent',
|
|
313
|
+
'--primary',
|
|
314
|
+
'--terminal-ansi-1',
|
|
315
|
+
'--terminal-ansi-2',
|
|
316
|
+
'--terminal-ansi-3',
|
|
317
|
+
'--terminal-ansi-4',
|
|
318
|
+
'--terminal-ansi-5',
|
|
319
|
+
'--terminal-ansi-6'
|
|
320
|
+
];
|
|
321
|
+
/** The tokens `theme`'s preview scope sets: `PREVIEW_TOKENS`, as the theme sets them. */
|
|
322
|
+
export function previewTokens(theme) {
|
|
323
|
+
const tokens = themeTokens(theme);
|
|
324
|
+
return Object.fromEntries(PREVIEW_TOKENS.map((name) => [name, tokens[name] ?? '']));
|
|
325
|
+
}
|
|
326
|
+
/** uiok's own banner: what writes `themes.generated.css` and how the attributes select a theme. */
|
|
327
|
+
const BANNER = [
|
|
328
|
+
'Generated from the theme catalog (src/themes/) by src/themes/themes.test.ts;',
|
|
329
|
+
'do not edit. Regenerate with',
|
|
330
|
+
'UPDATE_THEMES=1 npx vitest run src/themes/themes.test.ts',
|
|
331
|
+
'',
|
|
332
|
+
':root wears the default themes, Catppuccin Latte while light and',
|
|
333
|
+
'Catppuccin Mocha while dark. A page wears other themes through the',
|
|
334
|
+
'data-light-theme and data-dark-theme attributes on its root element,',
|
|
335
|
+
"each selecting its theme's block below under its own appearance. An",
|
|
336
|
+
"element with data-theme-preview set to a theme's id paints that theme's",
|
|
337
|
+
'preview tokens whatever the page wears.'
|
|
338
|
+
].join('\n');
|
|
339
|
+
/** `tokens` as declarations, one a line at `indent`. */
|
|
340
|
+
function declarations(tokens, indent) {
|
|
341
|
+
return Object.entries(tokens)
|
|
342
|
+
.map(([name, value]) => `${indent}${name}: ${value};`)
|
|
343
|
+
.join('\n');
|
|
344
|
+
}
|
|
345
|
+
/** A rule of `tokens` under `selector`, nested `depth` levels deep. */
|
|
346
|
+
function rule(selector, tokens, depth = 0) {
|
|
347
|
+
const indent = ' '.repeat(depth);
|
|
348
|
+
return `${indent}${selector} {\n${declarations(tokens, `${indent} `)}\n${indent}}`;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The custom properties `@bigpixelrocket/uiok/styles.css` declares or reads beside the theme
|
|
352
|
+
* tokens: the base sheet's on `:root`, and the hooks a component stylesheet
|
|
353
|
+
* declares or reads (the activity stripes' colour, a dialog's tone and
|
|
354
|
+
* pinned top), which an app token on `:root` would otherwise reach.
|
|
355
|
+
*/
|
|
356
|
+
const BASE_TOKEN_NAMES = [
|
|
357
|
+
'--frost',
|
|
358
|
+
'--font-mono',
|
|
359
|
+
'--font-ui',
|
|
360
|
+
'--z-panel',
|
|
361
|
+
'--z-dialog',
|
|
362
|
+
'--z-tooltip',
|
|
363
|
+
'--stripe-ink',
|
|
364
|
+
'--stripe-ground',
|
|
365
|
+
'--dialog-tone',
|
|
366
|
+
'--dialog-icon',
|
|
367
|
+
'--dialog-top',
|
|
368
|
+
'--pane-columns-height',
|
|
369
|
+
'--pane-path-height',
|
|
370
|
+
'--pane-column-gap',
|
|
371
|
+
'--pane-row-inset',
|
|
372
|
+
'--pane-grid',
|
|
373
|
+
'--warning-text'
|
|
374
|
+
];
|
|
375
|
+
/** Every token name uiok defines: the fixed tokens, those a theme sets, and the stylesheet's own. */
|
|
376
|
+
const UIOK_TOKEN_NAMES = new Set([
|
|
377
|
+
...Object.keys(FIXED_TOKENS),
|
|
378
|
+
...Object.keys(themeTokens(DEFAULT_LIGHT_THEME)),
|
|
379
|
+
...BASE_TOKEN_NAMES
|
|
380
|
+
]);
|
|
381
|
+
/**
|
|
382
|
+
* Whether `text` holds a sequence that would end a declaration, rule, or
|
|
383
|
+
* comment early. It masks what CSS reads as one token: a quoted string,
|
|
384
|
+
* which honours backslash escapes and ends at a raw newline (so a quoted
|
|
385
|
+
* `url("…")` may hold a `)`), an unquoted `url(…)` (a data URI's
|
|
386
|
+
* `;base64`), and an escaped character outside a string (`\:` in a
|
|
387
|
+
* selector). A separator, quote, lone backslash, or comment delimiter left
|
|
388
|
+
* over is unsafe; a raw newline outside a string is not.
|
|
389
|
+
*/
|
|
390
|
+
function breaksOut(text) {
|
|
391
|
+
const bare = text.replace(/"(?:[^"\\\n\r\f]|\\[^\n\r\f])*"|'(?:[^'\\\n\r\f]|\\[^\n\r\f])*'|url\((?!\s*["'])[^)"'\\]*\)|\\[^\n\r\f]/g, '');
|
|
392
|
+
return /[;{}"'\\]|\/\*|\*\//.test(bare);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* `extra`, checked to add only custom properties uiok leaves undefined, each
|
|
396
|
+
* with a value confined to its declaration, so an app token can never
|
|
397
|
+
* silently replace a token uiok's components read.
|
|
398
|
+
*/
|
|
399
|
+
function extraTokens(extra, source) {
|
|
400
|
+
for (const [name, value] of Object.entries(extra)) {
|
|
401
|
+
if (!/^--[a-z0-9-]+$/.test(name)) {
|
|
402
|
+
throw new Error(`${source} names ${name}, which is not a kebab-case custom property.`);
|
|
403
|
+
}
|
|
404
|
+
if (UIOK_TOKEN_NAMES.has(name)) {
|
|
405
|
+
throw new Error(`${source} redefines ${name}, a token UIOK defines.`);
|
|
406
|
+
}
|
|
407
|
+
if (breaksOut(value)) {
|
|
408
|
+
throw new Error(`${source} gives ${name} a value that would end its declaration early.`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return extra;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* The stylesheet of every colour token: the default themes on `:root` (light
|
|
415
|
+
* outside any query, dark under `prefers-color-scheme: dark`), a block per
|
|
416
|
+
* theme that `data-light-theme` or `data-dark-theme` on the root element
|
|
417
|
+
* selects under its appearance, and a preview scope per theme
|
|
418
|
+
* (`PREVIEW_TOKENS` under `data-theme-preview`) outside any query. `:root`
|
|
419
|
+
* also declares `color-scheme: light dark`, so native controls and scrollbars
|
|
420
|
+
* follow the appearance the tokens follow. `options` adds an app's own
|
|
421
|
+
* tokens to the same blocks, or writes those alone.
|
|
422
|
+
*/
|
|
423
|
+
export function themeStylesheet(options = {}) {
|
|
424
|
+
const { banner = BANNER, includeUiokTokens = true, extraFixed = {}, extraBlocks = {} } = options;
|
|
425
|
+
if (banner.includes('*/')) {
|
|
426
|
+
throw new Error('banner holds */, which would end its comment early.');
|
|
427
|
+
}
|
|
428
|
+
const own = (tokens) => (includeUiokTokens ? tokens : {});
|
|
429
|
+
const tokensOf = (theme) => {
|
|
430
|
+
const tokens = themeTokens(theme);
|
|
431
|
+
const extra = options.extraTokens?.(theme, tokens) ?? {};
|
|
432
|
+
return { ...own(tokens), ...extraTokens(extra, `extraTokens(${theme.id})`) };
|
|
433
|
+
};
|
|
434
|
+
/** A rule, or none where it would declare nothing. */
|
|
435
|
+
const block = (selector, tokens, depth = 0) => Object.keys(tokens).length === 0 ? [] : [rule(selector, tokens, depth)];
|
|
436
|
+
/** `rules` under a media query, or nothing where there are none. */
|
|
437
|
+
const media = (condition, rules) => rules.length === 0 ? [] : [`@media ${condition} {\n${rules.join('\n\n')}\n}`];
|
|
438
|
+
const themed = (appearance) => THEMES.filter((theme) => theme.appearance === appearance).flatMap((theme) => block(`:root[${THEME_ATTRIBUTES[appearance]}='${theme.id}']`, tokensOf(theme), 1));
|
|
439
|
+
return [
|
|
440
|
+
`/* ${banner
|
|
441
|
+
.split('\n')
|
|
442
|
+
.map((line, index) => (index === 0 || line === '' ? line : ` ${line}`))
|
|
443
|
+
.join('\n')} */`,
|
|
444
|
+
...block(':root', {
|
|
445
|
+
...own({ 'color-scheme': 'light dark', ...FIXED_TOKENS }),
|
|
446
|
+
...extraTokens(extraFixed, 'extraFixed'),
|
|
447
|
+
...tokensOf(DEFAULT_LIGHT_THEME)
|
|
448
|
+
}),
|
|
449
|
+
...Object.entries(extraBlocks).flatMap(([selector, tokens]) => {
|
|
450
|
+
if (breaksOut(selector)) {
|
|
451
|
+
throw new Error(`extraBlocks['${selector}'] is a selector that would end its rule early.`);
|
|
452
|
+
}
|
|
453
|
+
return block(selector, extraTokens(tokens, `extraBlocks['${selector}']`));
|
|
454
|
+
}),
|
|
455
|
+
...media('(prefers-color-scheme: dark)', block(':root', tokensOf(DEFAULT_DARK_THEME), 1)),
|
|
456
|
+
...media('(prefers-color-scheme: light)', themed('light')),
|
|
457
|
+
...media('(prefers-color-scheme: dark)', themed('dark')),
|
|
458
|
+
...THEMES.flatMap((theme) => block(`[${THEME_PREVIEW_ATTRIBUTE}='${theme.id}']`, own(previewTokens(theme))))
|
|
459
|
+
]
|
|
460
|
+
.join('\n\n')
|
|
461
|
+
.concat('\n');
|
|
462
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The hover tooltip, drawn by the page instead of left to the system's
|
|
4
|
+
* `title` tooltip, so the page decides when it opens and what it looks like.
|
|
5
|
+
* Mount it once per window (near the root, beside `UiokProvider`); it serves
|
|
6
|
+
* every control that carries `tooltip()` or `describedTooltip()`
|
|
7
|
+
* attributes. The tooltip opens after the pointer rests on the control and
|
|
8
|
+
* closes when the pointer leaves, on a press, on a key, on a scroll, and
|
|
9
|
+
* when the window is resized. After a press or a key it stays away until the
|
|
10
|
+
* pointer has left the control and come back, and it never opens while a
|
|
11
|
+
* mouse button is held.
|
|
12
|
+
*
|
|
13
|
+
* The box hangs from the body, or from the element in full screen while
|
|
14
|
+
* there is one: nothing outside that element is drawn, so a tooltip left on
|
|
15
|
+
* the body would open behind a full-screen video.
|
|
16
|
+
*
|
|
17
|
+
* The pointer alone opens it. A control keeps its own accessible name, and a
|
|
18
|
+
* tooltip that says more than its element is also the element's description
|
|
19
|
+
* (`describedTooltip`), so a screen reader misses nothing.
|
|
20
|
+
*/
|
|
21
|
+
export declare function TooltipLayer(): ReactElement | null;
|