@mcurcio/patchbay 0.5.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.
Files changed (52) hide show
  1. package/README.md +9 -7
  2. package/dist/composites.js +190 -158
  3. package/dist/composites.js.map +1 -1
  4. package/dist/graph.css +1 -1
  5. package/dist/graph.js +639 -63
  6. package/dist/graph.js.map +1 -1
  7. package/dist/primitives.css +1 -1
  8. package/dist/primitives.js +108 -93
  9. package/dist/primitives.js.map +1 -1
  10. package/dist/testing.js +207 -0
  11. package/dist/testing.js.map +1 -0
  12. package/dist/tokens.css +22 -2
  13. package/dist/types/composites/banner/Banner.d.ts +9 -3
  14. package/dist/types/composites/banner/index.d.ts +2 -2
  15. package/dist/types/composites/command-palette/CommandPalette.d.ts +16 -10
  16. package/dist/types/composites/command-palette/index.d.ts +2 -2
  17. package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +17 -11
  18. package/dist/types/composites/shortcut-sheet/index.d.ts +2 -2
  19. package/dist/types/composites/toaster/Toaster.d.ts +15 -9
  20. package/dist/types/composites/toaster/index.d.ts +2 -2
  21. package/dist/types/graph/add-at/index.d.ts +2 -0
  22. package/dist/types/graph/add-at/useAddAt.d.ts +32 -0
  23. package/dist/types/graph/canvas-tools/CanvasTools.d.ts +40 -0
  24. package/dist/types/graph/canvas-tools/index.d.ts +2 -0
  25. package/dist/types/graph/canvas-tools/motion.d.ts +2 -0
  26. package/dist/types/graph/connect-hints/index.d.ts +4 -0
  27. package/dist/types/graph/connect-hints/mergeFlowProps.d.ts +10 -0
  28. package/dist/types/graph/connect-hints/useConnectHints.d.ts +48 -0
  29. package/dist/types/graph/follow-fit/index.d.ts +2 -0
  30. package/dist/types/graph/follow-fit/useFollowFit.d.ts +21 -0
  31. package/dist/types/graph/ghost-wire/GhostWire.d.ts +16 -0
  32. package/dist/types/graph/ghost-wire/index.d.ts +2 -0
  33. package/dist/types/graph/index.d.ts +8 -0
  34. package/dist/types/graph/meter/Meter.d.ts +9 -3
  35. package/dist/types/graph/meter/index.d.ts +2 -2
  36. package/dist/types/graph/node-box/NodeBox.d.ts +52 -0
  37. package/dist/types/graph/node-box/geometry.d.ts +47 -0
  38. package/dist/types/graph/node-box/index.d.ts +4 -0
  39. package/dist/types/graph/port-row/PortRow.d.ts +31 -0
  40. package/dist/types/graph/port-row/index.d.ts +2 -0
  41. package/dist/types/graph/wire/Wire.d.ts +27 -0
  42. package/dist/types/graph/wire/index.d.ts +2 -0
  43. package/dist/types/primitives/dialog/Dialog.d.ts +8 -2
  44. package/dist/types/primitives/dialog/index.d.ts +2 -2
  45. package/dist/types/primitives/sheet/Sheet.d.ts +8 -2
  46. package/dist/types/primitives/sheet/index.d.ts +2 -2
  47. package/dist/types/primitives/splitter/Splitter.d.ts +8 -2
  48. package/dist/types/primitives/splitter/splitter-math.d.ts +12 -4
  49. package/dist/types/testing/brand-css.d.ts +41 -0
  50. package/dist/types/testing/contrast.d.ts +36 -0
  51. package/dist/types/testing/index.d.ts +2 -0
  52. package/package.json +6 -2
@@ -0,0 +1,21 @@
1
+ import { type FitViewOptions, type Node, type OnMove, type Viewport } from "@xyflow/react";
2
+ export type FollowFitOptions<NodeType extends Node = Node> = {
3
+ /** The app's value that changes when nodes are added, removed or laid out; a change fits again while following. */
4
+ key: unknown;
5
+ /** React Flow's fit options, for every fit. */
6
+ fitOptions?: FitViewOptions<NodeType>;
7
+ /** Called with the viewport after each fit has landed, in the frame after the viewport is set. */
8
+ onFitted?: (viewport: Viewport) => void;
9
+ };
10
+ /** The props `useFollowFit` gives `<ReactFlow>`. */
11
+ export type FollowFitFlowProps = {
12
+ onMoveStart: OnMove;
13
+ };
14
+ export type FollowFit = {
15
+ /** Whether the view fits again on its own: true from the start, false once the person moves the view. */
16
+ following: boolean;
17
+ /** Fits now, moving as the fit tool does, and follows again. */
18
+ fit: () => void;
19
+ flowProps: FollowFitFlowProps;
20
+ };
21
+ export declare function useFollowFit<NodeType extends Node = Node>({ key, fitOptions, onFitted, }: FollowFitOptions<NodeType>): FollowFit;
@@ -0,0 +1,16 @@
1
+ import { type Edge, type EdgeProps } from "@xyflow/react";
2
+ import { type ReactNode } from "react";
3
+ import "./GhostWire.css";
4
+ /** `pending` (the default) or `refused`; any other string is drawn as `pending`. */
5
+ export type GhostWireTone = "pending" | "refused" | (string & {});
6
+ /** A ghost wire's look, as React Flow's edge `data`. */
7
+ export type GhostWireData = {
8
+ /** `pending` (dashed in the quiet tone, dimmed) or `refused` (the error tone). */
9
+ tone?: GhostWireTone;
10
+ /** At the midpoint, on the raised surface; it takes no pointer events. */
11
+ label?: ReactNode;
12
+ };
13
+ /** An edge drawn by `GhostWire`: register it as `edgeTypes={{ ghost: GhostWire }}`. */
14
+ export type GhostWireEdge = Edge<GhostWireData, "ghost">;
15
+ /** Draws a request's wire between two handles while it is on its way. */
16
+ export declare function GhostWire({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, }: EdgeProps<GhostWireEdge>): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { GhostWire } from "./GhostWire";
2
+ export type { GhostWireData, GhostWireEdge, GhostWireTone } from "./GhostWire";
@@ -1 +1,9 @@
1
+ export * from "./add-at";
2
+ export * from "./canvas-tools";
3
+ export * from "./connect-hints";
4
+ export * from "./follow-fit";
5
+ export * from "./ghost-wire";
1
6
  export * from "./meter";
7
+ export * from "./node-box";
8
+ export * from "./port-row";
9
+ export * from "./wire";
@@ -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
- /** The tooltip's words; `defaultMeterTitle` by default. */
35
- title?: MeterTitle;
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
- export declare function Meter({ subscribe, read, orientation, floor, zones, holdMs, fallDbPerS, clipAt, clipHoldMs, label, title, ref, className, style, onPointerEnter, onPointerLeave, ...rest }: MeterProps): import("react").JSX.Element;
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";
@@ -0,0 +1,52 @@
1
+ import { type ComponentPropsWithoutRef, type ReactNode } from "react";
2
+ import { type PortRowProps } from "../port-row";
3
+ import type { NodePorts } from "./geometry";
4
+ import "./NodeBox.css";
5
+ /** A box's stripe down its start edge: an open enum, and one it does not know is drawn in `--pb-line-strong`. */
6
+ export type NodeBoxTone = "ok" | "warn" | "err" | "quiet" | "off" | "accent" | "muted" | (string & {});
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
+ export type NodeBoxChange = "added" | "removed" | "renamed" | "changed" | (string & {});
9
+ /** The box's own words, each replaceable: the change badge's word for each known change. */
10
+ export interface NodeBoxLabels {
11
+ added: string;
12
+ removed: string;
13
+ renamed: string;
14
+ changed: string;
15
+ }
16
+ export declare const defaultNodeBoxLabels: NodeBoxLabels;
17
+ /** One port of a box: a `PortRow`'s props without `side`, which `NodeBox` sets. */
18
+ export type PortSpec = Omit<PortRowProps, "side">;
19
+ export type NodeBoxProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "children" | "role"> & {
20
+ /** The node's name, one line cut with an ellipsis; a string is also the header's tooltip. Names the box's group. */
21
+ title: ReactNode;
22
+ /** The second header line, muted: the node's type. */
23
+ subtitle?: ReactNode;
24
+ /** The stripe down the box's start edge, in the tone's colour; none, or one it does not know, in `--pb-line-strong`. */
25
+ tone?: NodeBoxTone;
26
+ /** A dashed border, the stripe hatched and the words muted. Drawing only: whether its ports connect is the app's. */
27
+ disabled?: boolean;
28
+ /** The border in `--pb-err` and the header on `--pb-err-soft`; the reason goes in `line`. */
29
+ failed?: boolean;
30
+ /** An edit not yet applied: a 2 px border in its tone and a badge with its word; `removed` strikes the title. */
31
+ change?: NodeBoxChange;
32
+ /** Words to replace; the rest keep their defaults. */
33
+ labels?: Partial<NodeBoxLabels>;
34
+ /** A slot at the header's end (a `Pill`). */
35
+ status?: ReactNode;
36
+ /** One row under the header saying why the node is silent; a string is also its tooltip. */
37
+ line?: ReactNode;
38
+ /** The input ports, keyed by `id`. */
39
+ inputs?: readonly PortSpec[];
40
+ /** The output ports, keyed by `id`. */
41
+ outputs?: readonly PortSpec[];
42
+ /** `stacked` (the default: the inputs' rows, then the outputs') or `side-by-side` (two columns). */
43
+ ports?: NodePorts;
44
+ /** A slot: one row at the foot (badges). */
45
+ footer?: ReactNode;
46
+ /** Selected, from React Flow's `NodeProps`: a 2 px outline in the accent. */
47
+ selected?: boolean;
48
+ /** Its width in px; `NODE_WIDTH` by default. */
49
+ width?: number;
50
+ };
51
+ /** Draws a node's box; render it inside a React Flow node. */
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;
@@ -0,0 +1,47 @@
1
+ /** The default width of a node box, in px; `NodeBox`'s `width` overrides it per node (`--pb-node-width`). */
2
+ export declare const NODE_WIDTH = 240;
3
+ /** The header (title and subtitle), with or without a subtitle, in px (`--pb-node-header`). */
4
+ export declare const NODE_HEADER = 46;
5
+ /** The `line` row, when there is one, in px (`--pb-node-line`). */
6
+ export declare const NODE_LINE = 22;
7
+ /** One port row, in px (`--pb-node-row`). */
8
+ export declare const NODE_ROW = 22;
9
+ /** The space above the first port row and below the last, in px (`--pb-node-pad`). */
10
+ export declare const NODE_PAD = 8;
11
+ /** The footer, when there is one, in px (`--pb-node-footer`). */
12
+ export declare const NODE_FOOTER = 28;
13
+ /** A handle's dot, in px (`--pb-node-handle`). */
14
+ export declare const HANDLE_SIZE = 10;
15
+ /** A handle's hit area, centred on the dot, in px (`--pb-node-handle-hit`); 32 px on a touch screen. */
16
+ export declare const HANDLE_HIT = 20;
17
+ /**
18
+ * How a node box lays out its ports: `stacked` (the inputs' rows, then the outputs') or `side-by-side` (two columns,
19
+ * row n of each on one line). An open enum; one it does not know is stacked.
20
+ */
21
+ export type NodePorts = "stacked" | "side-by-side" | (string & {});
22
+ /** What decides a node box's size: its port counts, their layout, and whether it has a line and a footer. */
23
+ export type NodeBoxShape = {
24
+ /** How many input ports. */
25
+ inputs: number;
26
+ /** How many output ports. */
27
+ outputs: number;
28
+ /** How the ports are laid out. */
29
+ ports: NodePorts;
30
+ /** Whether it has a `line` row. */
31
+ line: boolean;
32
+ /** Whether it has a footer. */
33
+ footer: boolean;
34
+ /** Its width in px; `NODE_WIDTH` by default. */
35
+ width?: number;
36
+ };
37
+ /** How many port rows a box draws: inputs plus outputs stacked, the larger of the two side by side. */
38
+ export declare function nodePortRows(inputs: number, outputs: number, ports: NodePorts): number;
39
+ /**
40
+ * A node box's size in px, the one formula layout code sizes nodes with: the header, the line when there is one, the
41
+ * port rows and the padding above and below them when there are ports, and the footer when there is one. The box's
42
+ * 1 px border is inside it; the selection ring is outside.
43
+ */
44
+ export declare function nodeBoxSize({ inputs, outputs, ports, line, footer, width }: NodeBoxShape): {
45
+ width: number;
46
+ height: number;
47
+ };
@@ -0,0 +1,4 @@
1
+ export { defaultNodeBoxLabels, NodeBox } from "./NodeBox";
2
+ export type { NodeBoxChange, NodeBoxLabels, NodeBoxProps, NodeBoxTone, PortSpec } from "./NodeBox";
3
+ export { HANDLE_HIT, HANDLE_SIZE, NODE_FOOTER, NODE_HEADER, NODE_LINE, NODE_PAD, NODE_ROW, NODE_WIDTH, nodeBoxSize, } from "./geometry";
4
+ export type { NodeBoxShape, NodePorts } from "./geometry";
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from "react";
2
+ import "./PortRow.css";
3
+ /** Which side of the box a port is on: an input is a target handle on the left edge, an output a source on the right. */
4
+ export type PortSide = "input" | "output";
5
+ /**
6
+ * What a port shows while a wire is dragged: `origin` the handle the drag began at, `ok` a handle that accepts it,
7
+ * `no` one that refuses it, `null` no drag. An open enum; one it does not know is drawn as `null`.
8
+ */
9
+ export type PortHint = "ok" | "no" | "origin" | null | (string & {});
10
+ export type PortRowProps = {
11
+ /** The handle id, passed to React Flow's `<Handle id>` unchanged (the app's own scheme). */
12
+ id: string;
13
+ /** `input` (a target handle on the left edge) or `output` (a source handle on the right edge). */
14
+ side: PortSide;
15
+ /** The port's name; a string is also its tooltip. */
16
+ label: ReactNode;
17
+ /** After the label in the muted code face: the port's type. */
18
+ typeLabel?: ReactNode;
19
+ /** While a wire is dragged: `origin`, `ok`, `no`, or `null` for no drag. Given, it wins over `<ConnectHints>`'. */
20
+ hint?: PortHint;
21
+ /** Why the port refuses the wire: the handle's and the row's tooltip while `hint` is `no`. */
22
+ reason?: string;
23
+ /** A problem with the port: a warning mark beside the label, with these as its words. */
24
+ problem?: string;
25
+ /** A slot at the row's inner end, toward the box's centre (a `Meter`). */
26
+ trailing?: ReactNode;
27
+ /** Whether a wire may start or end here; true by default (`<Handle isConnectable>`). */
28
+ connectable?: boolean;
29
+ };
30
+ /** Draws one port: its handle at the edge, its label and type, a problem's mark and a trailing slot. */
31
+ export declare function PortRow({ id, side, label, typeLabel, hint: ownHint, reason: ownReason, problem, trailing, connectable, }: PortRowProps): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { PortRow } from "./PortRow";
2
+ export type { PortHint, PortRowProps, PortSide } from "./PortRow";
@@ -0,0 +1,27 @@
1
+ import { type Edge, type EdgeProps } from "@xyflow/react";
2
+ import { type ReactNode } from "react";
3
+ import type { PillTone } from "../../primitives";
4
+ import "./Wire.css";
5
+ /** Pill's tones, the changes, `pending` and `refused`; any other string is drawn in the edge stroke. */
6
+ export type WireTone = PillTone | "added" | "removed" | "changed" | "pending" | "refused" | (string & {});
7
+ /** A wire's look, as React Flow's edge `data`. */
8
+ export type WireData = {
9
+ /** The stroke's tone; none, or one it does not know, is React Flow's edge stroke. */
10
+ tone?: WireTone;
11
+ /** The signal's level, 0 to 1 (clamped; not a number is 0): thickness and brightness. None is the plain wire. */
12
+ emphasis?: number;
13
+ /** Dashes: an edit not yet saved. */
14
+ dashed?: boolean;
15
+ /** Dots moving along the wire toward the input; not drawn under reduced motion. */
16
+ flow?: boolean;
17
+ /** An arrowhead at the input end, facing the handle's side. */
18
+ arrow?: boolean;
19
+ /** At the midpoint, on the raised surface; it takes no pointer events. */
20
+ label?: ReactNode;
21
+ /** The wire's tooltip, on its hit path. */
22
+ title?: string;
23
+ };
24
+ /** An edge drawn by `Wire`: register it as `edgeTypes={{ wire: Wire }}`. */
25
+ export type WireEdge = Edge<WireData, "wire">;
26
+ /** Draws a wire between two handles: its tone, level, dashes, flow, arrow, label and tooltip from the edge's data. */
27
+ export declare function Wire({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, selected, interactionWidth, markerStart, markerEnd, style, }: EdgeProps<WireEdge>): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { Wire } from "./Wire";
2
+ export type { WireData, WireEdge, WireTone } from "./Wire";
@@ -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
- /** The close button's name: "Close". */
14
- closeLabel?: string;
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
- /** The close button's name: "Close". */
19
- closeLabel?: string;
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
- /** The edge of the resized pane the splitter sits on: start is its left or top, end its right or bottom. */
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
- /** Which edge of the pane it sits on; start (left or top) by default, where moving left or up grows the pane. */
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. The sign is -1 for a splitter on
10
- * the start edge (left or top) of what it resizes, where moving left or up grows it, and 1 on the end edge.
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
- /** Which arrow grows what the splitter resizes, from its orientation and the edge it sits on. */
14
- export declare function growKey(orientation: "vertical" | "horizontal", edge: "start" | "end"): string;
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,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[];
@@ -0,0 +1,2 @@
1
+ export { checkBrandContrast, contrastPairs, contrastRatio, minimumContrast } from "./contrast";
2
+ export type { ContrastFailure, ContrastPair, ContrastTheme } from "./contrast";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcurcio/patchbay",
3
- "version": "0.5.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": {
@@ -74,7 +78,7 @@
74
78
  "check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test && pnpm build"
75
79
  },
76
80
  "peerDependencies": {
77
- "@xyflow/react": "^12.0.0",
81
+ "@xyflow/react": "^12.1.0",
78
82
  "knobly": "^1.0.0",
79
83
  "react": "^19.0.0",
80
84
  "react-dom": "^19.0.0"