@mcurcio/patchbay 0.6.0 → 0.8.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 +4 -3
- package/dist/composites.css +1 -1
- package/dist/composites.js +501 -158
- package/dist/composites.js.map +1 -1
- package/dist/graph.js +94 -79
- 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/shell.css +1 -0
- package/dist/shell.js +177 -0
- package/dist/shell.js.map +1 -0
- 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/code-editor/CodeEditor.d.ts +45 -0
- package/dist/types/composites/code-editor/CodeRuns.d.ts +5 -0
- package/dist/types/composites/code-editor/CodeText.d.ts +12 -0
- package/dist/types/composites/code-editor/highlight.d.ts +83 -0
- package/dist/types/composites/code-editor/index.d.ts +6 -0
- 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/index.d.ts +1 -0
- 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/follow-fit/useFollowFit.d.ts +3 -0
- 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/shell/app-shell/AppShell.d.ts +76 -0
- package/dist/types/shell/app-shell/bounds.d.ts +16 -0
- package/dist/types/shell/app-shell/index.d.ts +3 -0
- package/dist/types/shell/index.d.ts +1 -1
- 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
|
@@ -10,12 +10,15 @@ export type FollowFitOptions<NodeType extends Node = Node> = {
|
|
|
10
10
|
/** The props `useFollowFit` gives `<ReactFlow>`. */
|
|
11
11
|
export type FollowFitFlowProps = {
|
|
12
12
|
onMoveStart: OnMove;
|
|
13
|
+
onMoveEnd: OnMove;
|
|
13
14
|
};
|
|
14
15
|
export type FollowFit = {
|
|
15
16
|
/** Whether the view fits again on its own: true from the start, false once the person moves the view. */
|
|
16
17
|
following: boolean;
|
|
17
18
|
/** Fits now, moving as the fit tool does, and follows again. */
|
|
18
19
|
fit: () => void;
|
|
20
|
+
/** Stops following, as the person's own move does: for an app that moves the view itself (going to a node). */
|
|
21
|
+
stop: () => void;
|
|
19
22
|
flowProps: FollowFitFlowProps;
|
|
20
23
|
};
|
|
21
24
|
export declare function useFollowFit<NodeType extends Node = Node>({ key, fitOptions, onFitted, }: FollowFitOptions<NodeType>): FollowFit;
|
|
@@ -31,8 +31,8 @@ export type MeterProps = Omit<ComponentPropsWithoutRef<"div">, "children" | "tit
|
|
|
31
31
|
clipHoldMs?: number;
|
|
32
32
|
/** The accessible name ("Level" by default); the numbers are never announced. */
|
|
33
33
|
label?: string;
|
|
34
|
-
/**
|
|
35
|
-
|
|
34
|
+
/** Words to replace; the rest keep their defaults. */
|
|
35
|
+
labels?: Partial<MeterLabels>;
|
|
36
36
|
/** `reset()`, for when the source closes. */
|
|
37
37
|
ref?: Ref<MeterHandle>;
|
|
38
38
|
};
|
|
@@ -53,4 +53,10 @@ export declare function toDb(linear: number): number;
|
|
|
53
53
|
export declare function meterFraction(db: number, floor: number): number;
|
|
54
54
|
/** The English tooltip: "peak -12.0 dB, rms -18.3 dB", with −∞ for silence. */
|
|
55
55
|
export declare const defaultMeterTitle: MeterTitle;
|
|
56
|
-
|
|
56
|
+
/** The meter's own words, each replaceable. */
|
|
57
|
+
export interface MeterLabels {
|
|
58
|
+
/** Writes the tooltip from the level: `defaultMeterTitle`, "peak -12.0 dB, rms -18.3 dB". */
|
|
59
|
+
title: MeterTitle;
|
|
60
|
+
}
|
|
61
|
+
export declare const defaultMeterLabels: MeterLabels;
|
|
62
|
+
export declare function Meter({ subscribe, read, orientation, floor, zones, holdMs, fallDbPerS, clipAt, clipHoldMs, label, labels, ref, className, style, onPointerEnter, onPointerLeave, ...rest }: MeterProps): import("react").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { defaultMeterScale, defaultMeterTitle, Meter, meterFraction, meterTitleEveryMs, toDb } from "./Meter";
|
|
2
|
-
export type { MeterHandle, MeterOrientation, MeterProps, MeterTitle } from "./Meter";
|
|
1
|
+
export { defaultMeterLabels, defaultMeterScale, defaultMeterTitle, Meter, meterFraction, meterTitleEveryMs, toDb, } from "./Meter";
|
|
2
|
+
export type { MeterHandle, MeterLabels, MeterOrientation, MeterProps, MeterTitle } from "./Meter";
|
|
@@ -6,15 +6,14 @@ import "./NodeBox.css";
|
|
|
6
6
|
export type NodeBoxTone = "ok" | "warn" | "err" | "quiet" | "off" | "accent" | "muted" | (string & {});
|
|
7
7
|
/** An edit not yet applied: an open enum, and one it does not know is a plain border with its own string as the word. */
|
|
8
8
|
export type NodeBoxChange = "added" | "removed" | "renamed" | "changed" | (string & {});
|
|
9
|
-
/** The words
|
|
10
|
-
export
|
|
9
|
+
/** The box's own words, each replaceable: the change badge's word for each known change. */
|
|
10
|
+
export interface NodeBoxLabels {
|
|
11
11
|
added: string;
|
|
12
12
|
removed: string;
|
|
13
13
|
renamed: string;
|
|
14
14
|
changed: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export declare const defaultChangeLabels: NodeBoxChangeLabels;
|
|
15
|
+
}
|
|
16
|
+
export declare const defaultNodeBoxLabels: NodeBoxLabels;
|
|
18
17
|
/** One port of a box: a `PortRow`'s props without `side`, which `NodeBox` sets. */
|
|
19
18
|
export type PortSpec = Omit<PortRowProps, "side">;
|
|
20
19
|
export type NodeBoxProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "children" | "role"> & {
|
|
@@ -30,8 +29,8 @@ export type NodeBoxProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "chil
|
|
|
30
29
|
failed?: boolean;
|
|
31
30
|
/** An edit not yet applied: a 2 px border in its tone and a badge with its word; `removed` strikes the title. */
|
|
32
31
|
change?: NodeBoxChange;
|
|
33
|
-
/**
|
|
34
|
-
|
|
32
|
+
/** Words to replace; the rest keep their defaults. */
|
|
33
|
+
labels?: Partial<NodeBoxLabels>;
|
|
35
34
|
/** A slot at the header's end (a `Pill`). */
|
|
36
35
|
status?: ReactNode;
|
|
37
36
|
/** One row under the header saying why the node is silent; a string is also its tooltip. */
|
|
@@ -50,4 +49,4 @@ export type NodeBoxProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "chil
|
|
|
50
49
|
width?: number;
|
|
51
50
|
};
|
|
52
51
|
/** Draws a node's box; render it inside a React Flow node. */
|
|
53
|
-
export declare function NodeBox({ title, subtitle, tone, disabled, failed, change,
|
|
52
|
+
export declare function NodeBox({ title, subtitle, tone, disabled, failed, change, labels, status, line, inputs, outputs, ports, footer, selected, width, className, style, ...rest }: NodeBoxProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { NodeBoxChange,
|
|
1
|
+
export { defaultNodeBoxLabels, NodeBox } from "./NodeBox";
|
|
2
|
+
export type { NodeBoxChange, NodeBoxLabels, NodeBoxProps, NodeBoxTone, PortSpec } from "./NodeBox";
|
|
3
3
|
export { HANDLE_HIT, HANDLE_SIZE, NODE_FOOTER, NODE_HEADER, NODE_LINE, NODE_PAD, NODE_ROW, NODE_WIDTH, nodeBoxSize, } from "./geometry";
|
|
4
4
|
export type { NodeBoxShape, NodePorts } from "./geometry";
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import "./Dialog.css";
|
|
3
|
+
/** The dialog's own words, each replaceable. */
|
|
4
|
+
export interface DialogLabels {
|
|
5
|
+
/** The close button's name: "Close". */
|
|
6
|
+
close: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultDialogLabels: DialogLabels;
|
|
3
9
|
export type DialogProps = {
|
|
4
10
|
/** Whether the dialog is shown; the app holds it. */
|
|
5
11
|
open: boolean;
|
|
@@ -10,8 +16,8 @@ export type DialogProps = {
|
|
|
10
16
|
children: ReactNode;
|
|
11
17
|
/** A row at the foot of the dialog, for its buttons. */
|
|
12
18
|
actions?: ReactNode;
|
|
13
|
-
/**
|
|
14
|
-
|
|
19
|
+
/** Words to replace; the rest keep their defaults. */
|
|
20
|
+
labels?: Partial<DialogLabels>;
|
|
15
21
|
/** A class added to the dialog's box. */
|
|
16
22
|
className?: string;
|
|
17
23
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Dialog } from "./Dialog";
|
|
2
|
-
export type { DialogProps } from "./Dialog";
|
|
1
|
+
export { defaultDialogLabels, Dialog } from "./Dialog";
|
|
2
|
+
export type { DialogLabels, DialogProps } from "./Dialog";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import "./Sheet.css";
|
|
3
3
|
export type SheetSide = "right" | "bottom";
|
|
4
|
+
/** The sheet's own words, each replaceable. */
|
|
5
|
+
export interface SheetLabels {
|
|
6
|
+
/** The close button's name: "Close". */
|
|
7
|
+
close: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const defaultSheetLabels: SheetLabels;
|
|
4
10
|
export type SheetProps = {
|
|
5
11
|
/** Whether the sheet is shown; the app holds it. */
|
|
6
12
|
open: boolean;
|
|
@@ -15,8 +21,8 @@ export type SheetProps = {
|
|
|
15
21
|
children: ReactNode;
|
|
16
22
|
/** A right sheet's width in px, held to 280–560 px and to 48 px short of its container. */
|
|
17
23
|
width?: number;
|
|
18
|
-
/**
|
|
19
|
-
|
|
24
|
+
/** Words to replace; the rest keep their defaults. */
|
|
25
|
+
labels?: Partial<SheetLabels>;
|
|
20
26
|
/** A class added to the sheet. */
|
|
21
27
|
className?: string;
|
|
22
28
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Sheet } from "./Sheet";
|
|
2
|
-
export type { SheetProps, SheetSide } from "./Sheet";
|
|
1
|
+
export { defaultSheetLabels, Sheet } from "./Sheet";
|
|
2
|
+
export type { SheetLabels, SheetProps, SheetSide } from "./Sheet";
|
|
@@ -2,7 +2,10 @@ import { type ComponentPropsWithRef } from "react";
|
|
|
2
2
|
import "./Splitter.css";
|
|
3
3
|
/** vertical: a vertical bar that resizes a width; horizontal: a horizontal bar that resizes a height. */
|
|
4
4
|
export type SplitterOrientation = "vertical" | "horizontal";
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The edge of the resized pane the splitter sits on, in the text's direction: start is its inline start (the left, or
|
|
7
|
+
* the right in right-to-left text) or its top, end the inline end or its bottom.
|
|
8
|
+
*/
|
|
6
9
|
export type SplitterEdge = "start" | "end";
|
|
7
10
|
export type SplitterProps = Omit<ComponentPropsWithRef<"div">, "onChange" | "children" | "role" | "aria-orientation" | "aria-valuenow" | "aria-valuemin" | "aria-valuemax"> & {
|
|
8
11
|
orientation: SplitterOrientation;
|
|
@@ -16,7 +19,10 @@ export type SplitterProps = Omit<ComponentPropsWithRef<"div">, "onChange" | "chi
|
|
|
16
19
|
onChange: (px: number) => void;
|
|
17
20
|
/** The separator's accessible name, such as "Resize the inspector". */
|
|
18
21
|
label: string;
|
|
19
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Which edge of the pane it sits on: start (its inline start, or its top) by default, end the other. Moving outward,
|
|
24
|
+
* away from the pane, grows it; in right-to-left text a vertical splitter's start is on the right.
|
|
25
|
+
*/
|
|
20
26
|
edge?: SplitterEdge;
|
|
21
27
|
/** How far one arrow key moves it, in px; 16 by default. */
|
|
22
28
|
step?: number;
|
|
@@ -5,13 +5,21 @@ export interface Bounds {
|
|
|
5
5
|
}
|
|
6
6
|
/** `value` within `bounds`, in whole px. A max below the min is read as the min. */
|
|
7
7
|
export declare function clamp(value: number, bounds: Bounds): number;
|
|
8
|
+
/** The text's direction where the splitter is: it decides which side a vertical splitter's start and end are on. */
|
|
9
|
+
export type Direction = "ltr" | "rtl";
|
|
8
10
|
/**
|
|
9
|
-
* A drag: the size at the drag's start plus the pointer's travel times `sign`, clamped.
|
|
10
|
-
*
|
|
11
|
+
* A drag: the size at the drag's start plus the pointer's travel times `sign`, clamped. `sign` is `dragSign`'s: -1
|
|
12
|
+
* where moving left or up grows what the splitter resizes, 1 where moving right or down does.
|
|
11
13
|
*/
|
|
12
14
|
export declare function dragged(start: number, travel: number, sign: 1 | -1, bounds: Bounds): number;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Whether the pointer's travel (clientX for a vertical splitter, clientY for a horizontal one) grows the pane (1) or
|
|
17
|
+
* shrinks it (-1). The start edge is the pane's inline start for a vertical splitter (the left, or the right in
|
|
18
|
+
* right-to-left text) and its top for a horizontal one; moving outward, away from the pane, grows it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function dragSign(orientation: "vertical" | "horizontal", edge: "start" | "end", direction: Direction): 1 | -1;
|
|
21
|
+
/** Which arrow grows what the splitter resizes: the one pointing outward from the edge it sits on. */
|
|
22
|
+
export declare function growKey(orientation: "vertical" | "horizontal", edge: "start" | "end", direction: Direction): string;
|
|
15
23
|
/**
|
|
16
24
|
* A key on a focused splitter: `grow` adds `step` and its opposite arrow takes it away, clamped; Home goes to the min
|
|
17
25
|
* and End to the max; any other key gives undefined (the key is not the splitter's).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import "./AppShell.css";
|
|
3
|
+
/**
|
|
4
|
+
* The top bar's slots, drawn in reading order (left to right in left-to-right text): the brand, a status, the app's
|
|
5
|
+
* controls, and controls at the far end.
|
|
6
|
+
*/
|
|
7
|
+
export type AppShellTopBar = {
|
|
8
|
+
/** The app's mark or name, first. */
|
|
9
|
+
brand?: ReactNode;
|
|
10
|
+
/** A short state after the brand (a connection's Pill). */
|
|
11
|
+
status?: ReactNode;
|
|
12
|
+
/** The app's controls, taking the free width. */
|
|
13
|
+
start?: ReactNode;
|
|
14
|
+
/** Controls at the far end (a theme switch, a menu). */
|
|
15
|
+
end?: ReactNode;
|
|
16
|
+
};
|
|
17
|
+
export type AppShellInspector = {
|
|
18
|
+
/** What the inspector shows: usually a Panel, which scrolls on its own. */
|
|
19
|
+
content: ReactNode;
|
|
20
|
+
/** Whether it is shown; the app holds it. */
|
|
21
|
+
open: boolean;
|
|
22
|
+
/** Asked for with false when the person closes the narrow window's sheet (its close button, or Escape inside it). */
|
|
23
|
+
onOpen: (open: boolean) => void;
|
|
24
|
+
/** Its width in px, drawn within 280–560 px (`inspectorBounds`); a narrow window's sheet takes it too. */
|
|
25
|
+
width: number;
|
|
26
|
+
/** A new width from its splitter, in whole px within the bounds. */
|
|
27
|
+
onWidth: (px: number) => void;
|
|
28
|
+
};
|
|
29
|
+
export type AppShellDrawer = {
|
|
30
|
+
/** The drawer's header, beside its show and hide button; shown while it is closed too. */
|
|
31
|
+
header: ReactNode;
|
|
32
|
+
/** The drawer's body, mounted while it is closed. */
|
|
33
|
+
content: ReactNode;
|
|
34
|
+
/** Whether its body is shown; the app holds it. */
|
|
35
|
+
open: boolean;
|
|
36
|
+
/** Asked for by its show and hide button. */
|
|
37
|
+
onOpen: (open: boolean) => void;
|
|
38
|
+
/** Its height in px while open, header included, drawn within 120 px and 70 % of the window (`drawerBounds`). */
|
|
39
|
+
height: number;
|
|
40
|
+
/** A new height from its splitter, in whole px within the bounds. */
|
|
41
|
+
onHeight: (px: number) => void;
|
|
42
|
+
};
|
|
43
|
+
/** The shell's own words, each replaceable. */
|
|
44
|
+
export interface AppShellLabels {
|
|
45
|
+
/** The inspector's name, as a region and as a sheet: "Inspector". */
|
|
46
|
+
inspector: string;
|
|
47
|
+
/** The drawer's name as a region: "Drawer". */
|
|
48
|
+
drawer: string;
|
|
49
|
+
/** The inspector's splitter: "Resize the inspector". */
|
|
50
|
+
resizeInspector: string;
|
|
51
|
+
/** The drawer's splitter: "Resize the drawer". */
|
|
52
|
+
resizeDrawer: string;
|
|
53
|
+
/** The drawer's button while it is closed: "Show the drawer". */
|
|
54
|
+
showDrawer: string;
|
|
55
|
+
/** The drawer's button while it is open: "Hide the drawer". */
|
|
56
|
+
hideDrawer: string;
|
|
57
|
+
/** The inspector sheet's close button: "Close". */
|
|
58
|
+
close: string;
|
|
59
|
+
}
|
|
60
|
+
export declare const defaultAppShellLabels: AppShellLabels;
|
|
61
|
+
export type AppShellProps = {
|
|
62
|
+
/** The top bar's slots; without them there is no bar. */
|
|
63
|
+
topBar?: AppShellTopBar;
|
|
64
|
+
/** The inspector; without it there is none. */
|
|
65
|
+
inspector?: AppShellInspector;
|
|
66
|
+
/** The drawer; without it there is none. */
|
|
67
|
+
drawer?: AppShellDrawer;
|
|
68
|
+
/** The canvas, filling the workspace. */
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
/** Words to replace; the rest keep their defaults. */
|
|
71
|
+
labels?: Partial<AppShellLabels>;
|
|
72
|
+
/** A class added to the shell. */
|
|
73
|
+
className?: string;
|
|
74
|
+
};
|
|
75
|
+
/** Lays out a graph editor: top bar, canvas, inspector and drawer, with a sheet for the inspector on narrow windows. */
|
|
76
|
+
export declare function AppShell({ topBar, inspector, drawer, children, labels, className }: AppShellProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The inspector's width in px. */
|
|
2
|
+
export declare const inspectorBounds: {
|
|
3
|
+
readonly min: 280;
|
|
4
|
+
readonly max: 560;
|
|
5
|
+
};
|
|
6
|
+
/** The drawer's height: at least `min` px, at most `maxShare` of the window's height. */
|
|
7
|
+
export declare const drawerBounds: {
|
|
8
|
+
readonly min: 120;
|
|
9
|
+
readonly maxShare: 0.7;
|
|
10
|
+
};
|
|
11
|
+
/** The inspector's width as drawn for an asked `px`: whole px within 280–560. */
|
|
12
|
+
export declare function clampInspectorWidth(px: number): number;
|
|
13
|
+
/** The tallest the drawer may be in a window `windowHeight` px high: 70 % of it, and never below the least. */
|
|
14
|
+
export declare function drawerMaxHeight(windowHeight: number): number;
|
|
15
|
+
/** The drawer's height as drawn for an asked `px` in a window `windowHeight` px high. */
|
|
16
|
+
export declare function clampDrawerHeight(px: number, windowHeight: number): number;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AppShell, defaultAppShellLabels } from "./AppShell";
|
|
2
|
+
export type { AppShellDrawer, AppShellInspector, AppShellLabels, AppShellProps, AppShellTopBar } from "./AppShell";
|
|
3
|
+
export { clampDrawerHeight, clampInspectorWidth, drawerBounds, drawerMaxHeight, inspectorBounds } from "./bounds";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./app-shell";
|
|
@@ -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.8.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": {
|