@datalayer/primer-addons 1.0.45 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/lib/components/closeable-flash/CloseableFlash.js +1 -1
- package/lib/components/hover-card/HoverCardDetails.js +1 -1
- package/lib/components/toolbar/FloatingToolbar.js +4 -19
- package/lib/theme/colors/hueColors.d.ts +29 -0
- package/lib/theme/colors/hueColors.js +77 -0
- package/lib/theme/colors/index.d.ts +1 -0
- package/lib/theme/colors/index.js +1 -0
- package/lib/theme/palettes/ColorPalette.d.ts +43 -1
- package/lib/theme/palettes/ColorPalette.js +77 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,42 @@ const config = getThemeConfig(app.interface.theme.variant);
|
|
|
116
116
|
|
|
117
117
|
The source: `src/theme/colors/themeAccents.ts`.
|
|
118
118
|
|
|
119
|
+
## The color palette
|
|
120
|
+
|
|
121
|
+
`useColorPalette()` returns one `ColorPalette` object, resolved for the current theme and color mode (a new one when either changes); `getColorPalette(theme, mode)` gives the same without a hook. It holds two categories of colors, and `isLight`, whether the mode is light. The [gallery](examples/gallery)'s *Color Palette* page shows both in whatever theme and mode the gallery wears.
|
|
122
|
+
|
|
123
|
+
- **Roles**, what each theme's own design uses, by role (`paletteRoleNames`, type `PaletteRoleName`): `bg`, `bgPanel`, `bgAlt`, `primary`, `secondary`, `accent`, `glow`, `pop`, `spark`, `blaze`, `surge`, `flame`, `gold`, `textLight`, `textMuted`. What a role is changes with the theme (`surge` is blue in one theme and sage in another). Use them for a page's own design.
|
|
124
|
+
- **Hues**, named colors a spec or a person picks, the same names in every theme (`hueNames`, type `HueName`): `red`, `orange`, `amber`, `yellow`, `lime`, `green`, `emerald`, `teal`, `cyan`, `sky`, `blue`, `indigo`, `violet`, `purple`, `fuchsia`, `pink`, `rose`, `slate`, `gray`, `stone`. A hue keeps its hue in every theme: deep on a light background, bright on a dark one. Use them for a color a spec or a person picks, such as an agent's color.
|
|
125
|
+
|
|
126
|
+
`paletteColorNames` lists both, roles first (type `PaletteColorName`).
|
|
127
|
+
|
|
128
|
+
Roles, for a page's own design:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { useColorPalette } from '@datalayer/primer-addons';
|
|
132
|
+
|
|
133
|
+
const palette = useColorPalette();
|
|
134
|
+
<Box style={{ background: palette.bgPanel, color: palette.textLight }}>
|
|
135
|
+
<Text style={{ color: palette.primary }}>Title</Text>
|
|
136
|
+
</Box>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Hues, for a color that is picked: a spec gives a palette name (an agent's `color: indigo`), or a hex where no name fits. `usePaletteColor()` returns a function that resolves it in the current theme and mode; `resolvePaletteColor(value, palette)` does the same with a palette in hand. A palette name gives its value, a hex is returned as is, and nothing or anything else is `undefined`, so the caller draws its own default. `isPaletteColorName` and `isHexColor` (`#RGB` or `#RRGGBB`) check a value first.
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { isHexColor, isPaletteColorName, resolvePaletteColor, usePaletteColor } from '@datalayer/primer-addons';
|
|
143
|
+
|
|
144
|
+
const colorOf = usePaletteColor();
|
|
145
|
+
const agentColor = colorOf(agent.color) ?? 'var(--fgColor-accent)';
|
|
146
|
+
// 'indigo' -> the theme's indigo, '#0969da' -> '#0969da', 'nope' -> undefined
|
|
147
|
+
|
|
148
|
+
resolvePaletteColor('teal', palette);
|
|
149
|
+
isPaletteColorName('rose'); // true
|
|
150
|
+
isHexColor('#abc'); // true
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The source: `src/theme/palettes/ColorPalette.tsx` and `src/theme/colors/hueColors.ts`.
|
|
154
|
+
|
|
119
155
|
## The `loop` theme
|
|
120
156
|
|
|
121
157
|
`loop` is one of the variants of the theme registry (`ThemeVariant`, `themeConfigs`), beside `datalayer`, `spatial`, `lovely`, `matrix`, `earth`, `sand`, `ivory` and `sun`: the look of an application built in LOOP — **one accent, neutral everything else**. A white (near-black in dark mode) canvas, a deep-grey ink, hairlines, soft shadows, round corners and one filled button in the accent. Success, attention and danger are kept for verdicts and rules only. The [gallery](examples/gallery) shows it on the *Theme Accents* page when the gallery wears it. Its accent is mint, `green` of the [theme accents](#theme-accents).
|
|
@@ -89,7 +89,7 @@ export const CloseableFlash = (props) => {
|
|
|
89
89
|
? { borderColor: 'danger.emphasis', borderWidth: 2, borderStyle: 'solid' }
|
|
90
90
|
: {}),
|
|
91
91
|
...sx,
|
|
92
|
-
}, ...otherProps, children: _jsxs(Box, { display:
|
|
92
|
+
}, ...otherProps, children: _jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsxs(Box, { sx: { flexGrow: 1 }, children: [leadingVisual && _jsx(CircleOcticon, { icon: leadingVisual }), _jsx(Text, { color: textColorForVariant(resolvedVariant), sx: isCritical ? { fontWeight: 'bold' } : undefined, children: props.children })] }), dismissible && (_jsx(Box, { as: "button", type: "button", "aria-label": "Close", onClick: handleClose, sx: {
|
|
93
93
|
flex: '0 0 auto',
|
|
94
94
|
p: 0,
|
|
95
95
|
m: 0,
|
|
@@ -39,7 +39,7 @@ export function HoverCardDetails({ label, onClose, width = 880, closeLabel = 'Cl
|
|
|
39
39
|
: `${leaving ? 'dlaHoverCardVeilOut' : 'dlaHoverCardVeilIn'} ${HOVER_CARD_MOTION_MS}ms ease-out both`, sx: {
|
|
40
40
|
'@keyframes dlaHoverCardVeilIn': { from: { opacity: 0 }, to: { opacity: 1 } },
|
|
41
41
|
'@keyframes dlaHoverCardVeilOut': { from: { opacity: 1 }, to: { opacity: 0 } },
|
|
42
|
-
}, children: _jsxs(Card, { role: "dialog", "aria-modal": "true", "aria-label": label, onClick: (event) => event.stopPropagation(), shadow: "extraLarge", width: width, maxWidth: "100%", borderRadius: [0, '
|
|
42
|
+
}, children: _jsxs(Card, { role: "dialog", "aria-modal": "true", "aria-label": label, onClick: (event) => event.stopPropagation(), shadow: "extraLarge", width: width, maxWidth: "100%", borderRadius: [0, 'overlay'], overflow: "hidden", position: "relative", display: "block",
|
|
43
43
|
// Rises into place and sinks back out, at the hover card's speed: the
|
|
44
44
|
// third size arrives the way the second one did.
|
|
45
45
|
animation: reduced
|
|
@@ -108,25 +108,10 @@ export function FloatingToolbar({ items, extraItems, anchorElement, isVisible, c
|
|
|
108
108
|
return null;
|
|
109
109
|
}
|
|
110
110
|
const container = portalContainer || anchorElement || document.body;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
px: 1,
|
|
116
|
-
py: '4px',
|
|
117
|
-
bg: 'var(--overlay-bgColor, var(--bgColor-default))',
|
|
118
|
-
border: '1px solid',
|
|
119
|
-
borderColor: 'var(--borderColor-muted, transparent)',
|
|
120
|
-
borderRadius: 2,
|
|
121
|
-
boxShadow: 'shadow.large',
|
|
122
|
-
position: 'absolute',
|
|
123
|
-
zIndex: 10,
|
|
124
|
-
top: '-10000px',
|
|
125
|
-
left: '-10000px',
|
|
126
|
-
opacity: 0,
|
|
127
|
-
transition: 'opacity 0.15s ease, transform 0.15s ease',
|
|
128
|
-
transform: 'translateY(-4px)',
|
|
129
|
-
}, children: _jsx(ToolbarRenderer, { items: allItems, disabled: disabled, size: "small" }) }));
|
|
111
|
+
// Drawn as this package's `Card` draws itself, from the theme's tokens
|
|
112
|
+
// only: the theme's card corner, Primer's overlay ground and hairline, and
|
|
113
|
+
// the floating shadow each colour mode sets for itself.
|
|
114
|
+
const toolbar = (_jsx(Box, { ref: floatingRef, className: className, role: "toolbar", "aria-label": ariaLabel, display: "flex", alignItems: "center", gap: "2px", px: 1, py: "4px", bg: "canvas.overlay", color: "fg.default", border: "1px solid", borderColor: "border.default", borderRadius: "overlay", boxShadow: "shadow.large", position: "absolute", zIndex: 10, top: "-10000px", left: "-10000px", opacity: 0, transition: "opacity 0.15s ease, transform 0.15s ease", transform: "translateY(-4px)", children: _jsx(ToolbarRenderer, { items: allItems, disabled: disabled, size: "small" }) }));
|
|
130
115
|
return createPortal(toolbar, container);
|
|
131
116
|
}
|
|
132
117
|
export default FloatingToolbar;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hue colours – a colour named by its hue, in every theme and both modes.
|
|
3
|
+
*
|
|
4
|
+
* The palette's other names are roles (`primary`, `glow`, `surge`…): what
|
|
5
|
+
* they are changes with the theme, so `surge` is blue in one theme and sage
|
|
6
|
+
* in another. A hue name keeps its hue: `teal` is a teal in every theme, a
|
|
7
|
+
* deep one that reads on a light background and a bright one that reads on
|
|
8
|
+
* a dark background. A spec names its colour by hue (an agent's `color:
|
|
9
|
+
* indigo`), and the drawing follows the theme and its mode.
|
|
10
|
+
*
|
|
11
|
+
* Every theme takes the base values; a theme with hues of its own (`loop`'s
|
|
12
|
+
* pastels, `vscode`'s terminal colours) gives them for the hues it has.
|
|
13
|
+
*/
|
|
14
|
+
import type { ThemeVariant } from '../themeTokens';
|
|
15
|
+
/** The hue names, in the order of the colour wheel, then the neutrals: slate (cool), gray, stone (warm). */
|
|
16
|
+
export declare const hueNames: readonly ["red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose", "slate", "gray", "stone"];
|
|
17
|
+
/** A hue name. */
|
|
18
|
+
export type HueName = (typeof hueNames)[number];
|
|
19
|
+
/** A hue's value on a light background and on a dark one. */
|
|
20
|
+
export interface HueColor {
|
|
21
|
+
/** Deep enough to read on a light background. */
|
|
22
|
+
light: string;
|
|
23
|
+
/** Bright enough to read on a dark background. */
|
|
24
|
+
dark: string;
|
|
25
|
+
}
|
|
26
|
+
/** The hues every theme takes, unless it gives its own. */
|
|
27
|
+
export declare const baseHueColors: Record<HueName, HueColor>;
|
|
28
|
+
/** Every hue of a theme, in a mode. */
|
|
29
|
+
export declare function hueColorsOf(variant: ThemeVariant, mode: 'light' | 'dark'): Record<HueName, string>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/** The hue names, in the order of the colour wheel, then the neutrals: slate (cool), gray, stone (warm). */
|
|
6
|
+
export const hueNames = [
|
|
7
|
+
'red',
|
|
8
|
+
'orange',
|
|
9
|
+
'amber',
|
|
10
|
+
'yellow',
|
|
11
|
+
'lime',
|
|
12
|
+
'green',
|
|
13
|
+
'emerald',
|
|
14
|
+
'teal',
|
|
15
|
+
'cyan',
|
|
16
|
+
'sky',
|
|
17
|
+
'blue',
|
|
18
|
+
'indigo',
|
|
19
|
+
'violet',
|
|
20
|
+
'purple',
|
|
21
|
+
'fuchsia',
|
|
22
|
+
'pink',
|
|
23
|
+
'rose',
|
|
24
|
+
'slate',
|
|
25
|
+
'gray',
|
|
26
|
+
'stone',
|
|
27
|
+
];
|
|
28
|
+
/** The hues every theme takes, unless it gives its own. */
|
|
29
|
+
export const baseHueColors = {
|
|
30
|
+
red: { light: '#B91C1C', dark: '#F87171' },
|
|
31
|
+
orange: { light: '#C2410C', dark: '#FB923C' },
|
|
32
|
+
amber: { light: '#B45309', dark: '#FBBF24' },
|
|
33
|
+
yellow: { light: '#A16207', dark: '#FACC15' },
|
|
34
|
+
lime: { light: '#4D7C0F', dark: '#A3E635' },
|
|
35
|
+
green: { light: '#15803D', dark: '#4ADE80' },
|
|
36
|
+
emerald: { light: '#047857', dark: '#34D399' },
|
|
37
|
+
teal: { light: '#0F766E', dark: '#2DD4BF' },
|
|
38
|
+
cyan: { light: '#0E7490', dark: '#22D3EE' },
|
|
39
|
+
sky: { light: '#0369A1', dark: '#38BDF8' },
|
|
40
|
+
blue: { light: '#1D4ED8', dark: '#60A5FA' },
|
|
41
|
+
indigo: { light: '#4338CA', dark: '#818CF8' },
|
|
42
|
+
violet: { light: '#6D28D9', dark: '#A78BFA' },
|
|
43
|
+
purple: { light: '#7E22CE', dark: '#C084FC' },
|
|
44
|
+
fuchsia: { light: '#A21CAF', dark: '#E879F9' },
|
|
45
|
+
pink: { light: '#BE185D', dark: '#F472B6' },
|
|
46
|
+
rose: { light: '#BE123C', dark: '#FB7185' },
|
|
47
|
+
slate: { light: '#475569', dark: '#94A3B8' },
|
|
48
|
+
gray: { light: '#4B5563', dark: '#9CA3AF' },
|
|
49
|
+
stone: { light: '#57534E', dark: '#A8A29E' },
|
|
50
|
+
};
|
|
51
|
+
/** The hues a theme gives of its own. */
|
|
52
|
+
const themeHueColors = {
|
|
53
|
+
// Loop's soft accents, deep on light, the pastels on dark (`themeAccents`).
|
|
54
|
+
loop: {
|
|
55
|
+
green: { light: '#248462', dark: '#8FE5C6' },
|
|
56
|
+
rose: { light: '#B83A6B', dark: '#F6A5C1' },
|
|
57
|
+
sky: { light: '#1F6FB0', dark: '#8CCBF9' },
|
|
58
|
+
lime: { light: '#5F7A00', dark: '#BEDC55' },
|
|
59
|
+
yellow: { light: '#8A6A00', dark: '#F8D469' },
|
|
60
|
+
violet: { light: '#6B53C9', dark: '#C0AEF6' },
|
|
61
|
+
orange: { light: '#B4571A', dark: '#F4A261' },
|
|
62
|
+
},
|
|
63
|
+
// The terminal's ANSI colours.
|
|
64
|
+
vscode: {
|
|
65
|
+
red: { light: '#CD3131', dark: '#F14C4C' },
|
|
66
|
+
green: { light: '#107C10', dark: '#0DBC79' },
|
|
67
|
+
yellow: { light: '#858800', dark: '#E5E510' }, // the ANSI yellow, a shade deeper to read on white
|
|
68
|
+
blue: { light: '#0451A5', dark: '#2472C8' },
|
|
69
|
+
cyan: { light: '#0598BC', dark: '#11A8CD' },
|
|
70
|
+
purple: { light: '#BC05BC', dark: '#BC3FBC' },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
/** Every hue of a theme, in a mode. */
|
|
74
|
+
export function hueColorsOf(variant, mode) {
|
|
75
|
+
const own = themeHueColors[variant] ?? {};
|
|
76
|
+
return Object.fromEntries(hueNames.map(name => [name, (own[name] ?? baseHueColors[name])[mode]]));
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ export { sunColors } from './sunColors';
|
|
|
9
9
|
export { loopColors } from './loopColors';
|
|
10
10
|
export { vscodeColors, vscodeVars, vscodeVar, vscodeTint, vscodeFontFamily, vscodeMonoFontFamily, vscodeFontSize, type VSCodeColor, type VSCodeVarName, } from './vscodeColors';
|
|
11
11
|
export { themeAccents, themeAccentNames, themeAccentVars, themeAccentTints, themeStageGradient, themeTintVars, type ThemeAccent, type ThemeAccentName, } from './themeAccents';
|
|
12
|
+
export { hueNames, baseHueColors, hueColorsOf, type HueName, type HueColor, } from './hueColors';
|
|
12
13
|
import type { ThemeVariant } from '../themeRegistry';
|
|
13
14
|
/**
|
|
14
15
|
* Themed color palettes — maps each `ThemeVariant` to its corresponding
|
|
@@ -13,6 +13,7 @@ export { sunColors } from './sunColors';
|
|
|
13
13
|
export { loopColors } from './loopColors';
|
|
14
14
|
export { vscodeColors, vscodeVars, vscodeVar, vscodeTint, vscodeFontFamily, vscodeMonoFontFamily, vscodeFontSize, } from './vscodeColors';
|
|
15
15
|
export { themeAccents, themeAccentNames, themeAccentVars, themeAccentTints, themeStageGradient, themeTintVars, } from './themeAccents';
|
|
16
|
+
export { hueNames, baseHueColors, hueColorsOf, } from './hueColors';
|
|
16
17
|
import { datalayerColors } from './datalayerColors';
|
|
17
18
|
import { spatialColors } from './spatialColors';
|
|
18
19
|
import { lovelyColors } from './lovelyColors';
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared palette types, theme-aware colour resolution, and reusable
|
|
3
|
+
* gradient / grid definitions.
|
|
4
|
+
*/
|
|
5
|
+
import { type HueName } from '../colors';
|
|
1
6
|
import { type ThemeVariant } from '../themeRegistry';
|
|
2
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The palette's role names: what each is changes with the theme (`surge` is
|
|
9
|
+
* blue in one theme and sage in another).
|
|
10
|
+
*/
|
|
11
|
+
export declare const paletteRoleNames: readonly ["bg", "bgPanel", "bgAlt", "primary", "secondary", "accent", "glow", "pop", "spark", "blaze", "surge", "flame", "gold", "textLight", "textMuted"];
|
|
12
|
+
/** A role name of the palette. */
|
|
13
|
+
export type PaletteRoleName = (typeof paletteRoleNames)[number];
|
|
14
|
+
/**
|
|
15
|
+
* Every name of the palette: its roles, then its hues (`hueNames`: `red`
|
|
16
|
+
* … `rose`, then `slate`, `gray`, `stone`, each in every theme). A spec's colour names one of
|
|
17
|
+
* these, and is drawn in the value the current theme and mode give it.
|
|
18
|
+
*
|
|
19
|
+
* This list is the one source of the names: agentspecs keeps a copy
|
|
20
|
+
* (`agentspecs/colors.py`), and its tests check the copy against this file.
|
|
21
|
+
*/
|
|
22
|
+
export declare const paletteColorNames: readonly ["bg", "bgPanel", "bgAlt", "primary", "secondary", "accent", "glow", "pop", "spark", "blaze", "surge", "flame", "gold", "textLight", "textMuted", "red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose", "slate", "gray", "stone"];
|
|
23
|
+
/** A name of the palette. */
|
|
24
|
+
export type PaletteColorName = PaletteRoleName | HueName;
|
|
25
|
+
export interface ColorPalette extends Record<HueName, string> {
|
|
3
26
|
bg: string;
|
|
4
27
|
bgPanel: string;
|
|
5
28
|
bgAlt: string;
|
|
@@ -18,6 +41,25 @@ export interface ColorPalette {
|
|
|
18
41
|
isLight: boolean;
|
|
19
42
|
}
|
|
20
43
|
export declare function getColorPalette(theme?: ThemeVariant, colorMode?: 'light' | 'dark' | 'auto'): ColorPalette;
|
|
44
|
+
/** A hex colour, `#RGB` or `#RRGGBB`: what a spec may give where no name fits. */
|
|
45
|
+
export declare const HEX_COLOR_PATTERN: RegExp;
|
|
46
|
+
/** Whether a value is a name of the palette. */
|
|
47
|
+
export declare const isPaletteColorName: (value: string) => value is PaletteColorName;
|
|
48
|
+
/** Whether a value is a hex colour, `#RGB` or `#RRGGBB`. */
|
|
49
|
+
export declare const isHexColor: (value: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* A spec's colour as a CSS colour in a palette: a name of the palette is
|
|
52
|
+
* the value the palette's theme and mode give it, a hex colour is itself.
|
|
53
|
+
* Nothing, an empty string or anything else is `undefined`: the caller
|
|
54
|
+
* draws its own default.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolvePaletteColor(value: string | null | undefined, palette: ColorPalette): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* `resolvePaletteColor` in the current theme and mode: a function that
|
|
59
|
+
* turns a spec's colour (a palette name, or a hex) into the CSS colour to
|
|
60
|
+
* draw, and is a new function when the theme or the mode changes.
|
|
61
|
+
*/
|
|
62
|
+
export declare function usePaletteColor(): (value: string | null | undefined) => string | undefined;
|
|
21
63
|
export declare function useColorPalette(): ColorPalette;
|
|
22
64
|
/** @deprecated Use `useColorPalette` instead. */
|
|
23
65
|
export declare const useBlogColorPalette: typeof useColorPalette;
|
|
@@ -7,9 +7,44 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* Shared palette types, theme-aware colour resolution, and reusable
|
|
8
8
|
* gradient / grid definitions.
|
|
9
9
|
*/
|
|
10
|
-
import { datalayerColors, spatialColors, lovelyColors, matrixColors, earthColors, sandColors, ivoryColors, sunColors, loopColors, vscodeColors, } from '../colors';
|
|
10
|
+
import { datalayerColors, spatialColors, lovelyColors, matrixColors, earthColors, sandColors, ivoryColors, sunColors, loopColors, vscodeColors, hueColorsOf, hueNames, } from '../colors';
|
|
11
11
|
import { getBrightPalette, } from '../themeRegistry';
|
|
12
|
+
import { useCallback } from 'react';
|
|
12
13
|
import { useThemeStore } from '../useThemeStore';
|
|
14
|
+
/**
|
|
15
|
+
* The palette's role names: what each is changes with the theme (`surge` is
|
|
16
|
+
* blue in one theme and sage in another).
|
|
17
|
+
*/
|
|
18
|
+
export const paletteRoleNames = [
|
|
19
|
+
'bg',
|
|
20
|
+
'bgPanel',
|
|
21
|
+
'bgAlt',
|
|
22
|
+
'primary',
|
|
23
|
+
'secondary',
|
|
24
|
+
'accent',
|
|
25
|
+
'glow',
|
|
26
|
+
'pop',
|
|
27
|
+
'spark',
|
|
28
|
+
'blaze',
|
|
29
|
+
'surge',
|
|
30
|
+
'flame',
|
|
31
|
+
'gold',
|
|
32
|
+
'textLight',
|
|
33
|
+
'textMuted',
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Every name of the palette: its roles, then its hues (`hueNames`: `red`
|
|
37
|
+
* … `rose`, then `slate`, `gray`, `stone`, each in every theme). A spec's colour names one of
|
|
38
|
+
* these, and is drawn in the value the current theme and mode give it.
|
|
39
|
+
*
|
|
40
|
+
* This list is the one source of the names: agentspecs keeps a copy
|
|
41
|
+
* (`agentspecs/colors.py`), and its tests check the copy against this file.
|
|
42
|
+
*/
|
|
43
|
+
// palette-color-names:start
|
|
44
|
+
export const paletteColorNames = [
|
|
45
|
+
...paletteRoleNames,
|
|
46
|
+
...hueNames,
|
|
47
|
+
];
|
|
13
48
|
const dlBrightDark = getBrightPalette('datalayer');
|
|
14
49
|
const dlBrightLight = getBrightPalette('datalayer', 'light');
|
|
15
50
|
const spBrightDark = getBrightPalette('spatial');
|
|
@@ -30,7 +65,7 @@ const loBrightDark = getBrightPalette('loop');
|
|
|
30
65
|
const loBrightLight = getBrightPalette('loop', 'light');
|
|
31
66
|
const vsBrightDark = getBrightPalette('vscode');
|
|
32
67
|
const vsBrightLight = getBrightPalette('vscode', 'light');
|
|
33
|
-
const
|
|
68
|
+
const rolePalettes = {
|
|
34
69
|
datalayer: {
|
|
35
70
|
light: {
|
|
36
71
|
bg: '#f6f8fa',
|
|
@@ -412,15 +447,55 @@ const palettes = {
|
|
|
412
447
|
},
|
|
413
448
|
},
|
|
414
449
|
};
|
|
450
|
+
/** Each theme's roles with its hues, light and dark. */
|
|
451
|
+
const palettes = Object.fromEntries(Object.keys(rolePalettes).map(variant => [
|
|
452
|
+
variant,
|
|
453
|
+
{
|
|
454
|
+
light: { ...rolePalettes[variant].light, ...hueColorsOf(variant, 'light') },
|
|
455
|
+
dark: { ...rolePalettes[variant].dark, ...hueColorsOf(variant, 'dark') },
|
|
456
|
+
},
|
|
457
|
+
]));
|
|
415
458
|
export function getColorPalette(theme = 'datalayer', colorMode = 'auto') {
|
|
416
459
|
const mode = colorMode === 'auto'
|
|
417
460
|
? typeof window !== 'undefined' &&
|
|
461
|
+
typeof window.matchMedia === 'function' &&
|
|
418
462
|
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
419
463
|
? 'dark'
|
|
420
464
|
: 'light'
|
|
421
465
|
: colorMode;
|
|
422
466
|
return palettes[theme]?.[mode] ?? palettes.datalayer.dark;
|
|
423
467
|
}
|
|
468
|
+
const PALETTE_NAMES = new Set(paletteColorNames);
|
|
469
|
+
/** A hex colour, `#RGB` or `#RRGGBB`: what a spec may give where no name fits. */
|
|
470
|
+
export const HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
471
|
+
/** Whether a value is a name of the palette. */
|
|
472
|
+
export const isPaletteColorName = (value) => PALETTE_NAMES.has(value);
|
|
473
|
+
/** Whether a value is a hex colour, `#RGB` or `#RRGGBB`. */
|
|
474
|
+
export const isHexColor = (value) => HEX_COLOR_PATTERN.test(value);
|
|
475
|
+
/**
|
|
476
|
+
* A spec's colour as a CSS colour in a palette: a name of the palette is
|
|
477
|
+
* the value the palette's theme and mode give it, a hex colour is itself.
|
|
478
|
+
* Nothing, an empty string or anything else is `undefined`: the caller
|
|
479
|
+
* draws its own default.
|
|
480
|
+
*/
|
|
481
|
+
export function resolvePaletteColor(value, palette) {
|
|
482
|
+
if (!value) {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
if (isPaletteColorName(value)) {
|
|
486
|
+
return palette[value];
|
|
487
|
+
}
|
|
488
|
+
return isHexColor(value) ? value : undefined;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* `resolvePaletteColor` in the current theme and mode: a function that
|
|
492
|
+
* turns a spec's colour (a palette name, or a hex) into the CSS colour to
|
|
493
|
+
* draw, and is a new function when the theme or the mode changes.
|
|
494
|
+
*/
|
|
495
|
+
export function usePaletteColor() {
|
|
496
|
+
const palette = useColorPalette();
|
|
497
|
+
return useCallback(value => resolvePaletteColor(value, palette), [palette]);
|
|
498
|
+
}
|
|
424
499
|
export function useColorPalette() {
|
|
425
500
|
const { colorMode, theme } = useThemeStore();
|
|
426
501
|
return getColorPalette(theme, colorMode);
|