@mcurcio/patchbay 0.6.0 → 0.7.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/README.md +2 -1
- package/dist/composites.js +190 -158
- package/dist/composites.js.map +1 -1
- package/dist/graph.js +70 -67
- package/dist/graph.js.map +1 -1
- package/dist/primitives.css +1 -1
- package/dist/primitives.js +108 -93
- package/dist/primitives.js.map +1 -1
- package/dist/testing.js +207 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/composites/banner/Banner.d.ts +9 -3
- package/dist/types/composites/banner/index.d.ts +2 -2
- package/dist/types/composites/command-palette/CommandPalette.d.ts +16 -10
- package/dist/types/composites/command-palette/index.d.ts +2 -2
- package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +17 -11
- package/dist/types/composites/shortcut-sheet/index.d.ts +2 -2
- package/dist/types/composites/toaster/Toaster.d.ts +15 -9
- package/dist/types/composites/toaster/index.d.ts +2 -2
- package/dist/types/graph/meter/Meter.d.ts +9 -3
- package/dist/types/graph/meter/index.d.ts +2 -2
- package/dist/types/graph/node-box/NodeBox.d.ts +7 -8
- package/dist/types/graph/node-box/index.d.ts +2 -2
- package/dist/types/primitives/dialog/Dialog.d.ts +8 -2
- package/dist/types/primitives/dialog/index.d.ts +2 -2
- package/dist/types/primitives/sheet/Sheet.d.ts +8 -2
- package/dist/types/primitives/sheet/index.d.ts +2 -2
- package/dist/types/primitives/splitter/Splitter.d.ts +8 -2
- package/dist/types/primitives/splitter/splitter-math.d.ts +12 -4
- package/dist/types/testing/brand-css.d.ts +41 -0
- package/dist/types/testing/contrast.d.ts +36 -0
- package/dist/types/testing/index.d.ts +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** One rule set: its selector, the at-rule it sits in (`@media (…)`, or null at the top), and its declarations. */
|
|
2
|
+
export type CssBlock = {
|
|
3
|
+
media: string | null;
|
|
4
|
+
selector: string;
|
|
5
|
+
declarations: Map<string, string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function stripComments(text: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* A stylesheet's rule sets, in order: each plain rule, and each rule inside an at-rule (`@media`) with that at-rule's
|
|
10
|
+
* prelude as its `media`. Statement at-rules (`@import …;`) are skipped. It reads stylesheets as the token files and
|
|
11
|
+
* brands are written, not every CSS there is: braces inside strings are not understood.
|
|
12
|
+
*/
|
|
13
|
+
export declare function cssBlocks(css: string, media?: string | null): CssBlock[];
|
|
14
|
+
/** A block's custom properties (`--name: value`), or none for a missing block. */
|
|
15
|
+
export declare function customProperties(block: CssBlock | undefined): Map<string, string>;
|
|
16
|
+
/** The block with this selector, at the top (`media` null) or inside an at-rule whose prelude `media` matches. */
|
|
17
|
+
export declare function findBlock(blocks: readonly CssBlock[], media: RegExp | null, selector: string): CssBlock | undefined;
|
|
18
|
+
/** A stylesheet's three sets under a :root selector, as tokens.css and a brand write them, and all its blocks. */
|
|
19
|
+
export type TokenSets = {
|
|
20
|
+
blocks: CssBlock[];
|
|
21
|
+
/** `root` itself: the light set. */
|
|
22
|
+
light: CssBlock | undefined;
|
|
23
|
+
/** `root:not([data-theme])` inside `@media (prefers-color-scheme: dark)`: the dark set when no choice is made. */
|
|
24
|
+
systemDark: CssBlock | undefined;
|
|
25
|
+
/** `root[data-theme="dark"]`: the dark set when dark is chosen. */
|
|
26
|
+
chosenDark: CssBlock | undefined;
|
|
27
|
+
};
|
|
28
|
+
/** The light, system dark and chosen dark sets of a stylesheet under `root` (`:root`, or `:root[data-brand="x"]`). */
|
|
29
|
+
export declare function tokenSets(css: string, root: string): TokenSets;
|
|
30
|
+
/** How a page is themed: light, dark chosen with `data-theme="dark"`, or dark by the system with no choice made. */
|
|
31
|
+
export type ContrastTheme = "light" | "dark" | "system dark";
|
|
32
|
+
/** The tokens in force in a theme, in the cascade's order: the base's set for it, then the brand's (if any). */
|
|
33
|
+
export declare function tokensInForce(base: TokenSets, brand: TokenSets | null, theme: ContrastTheme): Map<string, string>;
|
|
34
|
+
/** A value with every `var(--name)` it is followed through resolved from `tokens`; throws on a cycle or a gap. */
|
|
35
|
+
export declare function resolveToken(tokens: Map<string, string>, value: string): string;
|
|
36
|
+
/** An sRGB colour, 0 to 255 a channel. */
|
|
37
|
+
export type Rgb = readonly [number, number, number];
|
|
38
|
+
/** A `#rgb` or `#rrggbb` colour, or null for anything else. */
|
|
39
|
+
export declare function hexColour(value: string): Rgb | null;
|
|
40
|
+
/** Whether a value is a colour written as hex or `rgb()`/`rgba()`. */
|
|
41
|
+
export declare function isColour(value: string): boolean;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ContrastTheme } from "./brand-css";
|
|
2
|
+
/** Tokens drawn as text (`fg`), each checked on every surface it is drawn on (`on`). */
|
|
3
|
+
export type ContrastPair = {
|
|
4
|
+
readonly fg: readonly string[];
|
|
5
|
+
readonly on: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
/** The least contrast a text token keeps on its surfaces: WCAG's 4.5:1 for normal text. */
|
|
8
|
+
export declare const minimumContrast = 4.5;
|
|
9
|
+
/** Every text token and the surfaces it is drawn on: text, the accent, tones, changes, on-strong and code. */
|
|
10
|
+
export declare const contrastPairs: readonly ContrastPair[];
|
|
11
|
+
/** WCAG 2's contrast ratio of two hex colours (`#rgb` or `#rrggbb`), 1 to 21; NaN when either is not one. */
|
|
12
|
+
export declare function contrastRatio(a: string, b: string): number;
|
|
13
|
+
/** One text token below the rule on one surface, in one theme. */
|
|
14
|
+
export type ContrastFailure = {
|
|
15
|
+
/** The brand's name, or "base" for tokens.css alone. */
|
|
16
|
+
brand: string;
|
|
17
|
+
theme: ContrastTheme;
|
|
18
|
+
fg: string;
|
|
19
|
+
on: string;
|
|
20
|
+
/** The values the two resolve to in that theme (or why one does not resolve). */
|
|
21
|
+
fgValue: string;
|
|
22
|
+
onValue: string;
|
|
23
|
+
/** The contrast, or NaN when a value is not a hex colour. */
|
|
24
|
+
ratio: number;
|
|
25
|
+
/** All of it in a line: "harbor dark: --pb-muted (#64748b) on --pb-raised (#1e293b) is 3.07:1". */
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
export type { ContrastTheme } from "./brand-css";
|
|
29
|
+
/**
|
|
30
|
+
* Checks a brand against the contrast rule: for each theme (light, dark chosen, dark by the system), the tokens in
|
|
31
|
+
* force are tokens.css's set for it with the brand's blocks for `brand` (its `:root[data-brand="…"]` rules) over
|
|
32
|
+
* them, and every pair in `contrastPairs` must reach `minimumContrast`. Returns the failures; none means the brand
|
|
33
|
+
* keeps the rule. `css` is the brand's stylesheet as text; an empty one (or a `brand` it has no blocks for) checks
|
|
34
|
+
* the base theme alone. Colours must be written as hex, or the pair fails saying so.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkBrandContrast(css: string, brand: string): ContrastFailure[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcurcio/patchbay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A React component library for graph-based editors and live dashboards: design tokens and themes, primitives, and React Flow graph components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -58,6 +58,10 @@
|
|
|
58
58
|
"types": "./dist/types/hooks/index.d.ts",
|
|
59
59
|
"default": "./dist/hooks.js"
|
|
60
60
|
},
|
|
61
|
+
"./testing": {
|
|
62
|
+
"types": "./dist/types/testing/index.d.ts",
|
|
63
|
+
"default": "./dist/testing.js"
|
|
64
|
+
},
|
|
61
65
|
"./package.json": "./package.json"
|
|
62
66
|
},
|
|
63
67
|
"scripts": {
|