@datalayer/primer-addons 1.0.45 → 1.0.46

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.
@@ -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: "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: {
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,
@@ -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
- export interface ColorPalette {
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 palettes = {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",