@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.
Files changed (47) hide show
  1. package/README.md +4 -3
  2. package/dist/composites.css +1 -1
  3. package/dist/composites.js +501 -158
  4. package/dist/composites.js.map +1 -1
  5. package/dist/graph.js +94 -79
  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/shell.css +1 -0
  11. package/dist/shell.js +177 -0
  12. package/dist/shell.js.map +1 -0
  13. package/dist/testing.js +207 -0
  14. package/dist/testing.js.map +1 -0
  15. package/dist/types/composites/banner/Banner.d.ts +9 -3
  16. package/dist/types/composites/banner/index.d.ts +2 -2
  17. package/dist/types/composites/code-editor/CodeEditor.d.ts +45 -0
  18. package/dist/types/composites/code-editor/CodeRuns.d.ts +5 -0
  19. package/dist/types/composites/code-editor/CodeText.d.ts +12 -0
  20. package/dist/types/composites/code-editor/highlight.d.ts +83 -0
  21. package/dist/types/composites/code-editor/index.d.ts +6 -0
  22. package/dist/types/composites/command-palette/CommandPalette.d.ts +16 -10
  23. package/dist/types/composites/command-palette/index.d.ts +2 -2
  24. package/dist/types/composites/index.d.ts +1 -0
  25. package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +17 -11
  26. package/dist/types/composites/shortcut-sheet/index.d.ts +2 -2
  27. package/dist/types/composites/toaster/Toaster.d.ts +15 -9
  28. package/dist/types/composites/toaster/index.d.ts +2 -2
  29. package/dist/types/graph/follow-fit/useFollowFit.d.ts +3 -0
  30. package/dist/types/graph/meter/Meter.d.ts +9 -3
  31. package/dist/types/graph/meter/index.d.ts +2 -2
  32. package/dist/types/graph/node-box/NodeBox.d.ts +7 -8
  33. package/dist/types/graph/node-box/index.d.ts +2 -2
  34. package/dist/types/primitives/dialog/Dialog.d.ts +8 -2
  35. package/dist/types/primitives/dialog/index.d.ts +2 -2
  36. package/dist/types/primitives/sheet/Sheet.d.ts +8 -2
  37. package/dist/types/primitives/sheet/index.d.ts +2 -2
  38. package/dist/types/primitives/splitter/Splitter.d.ts +8 -2
  39. package/dist/types/primitives/splitter/splitter-math.d.ts +12 -4
  40. package/dist/types/shell/app-shell/AppShell.d.ts +76 -0
  41. package/dist/types/shell/app-shell/bounds.d.ts +16 -0
  42. package/dist/types/shell/app-shell/index.d.ts +3 -0
  43. package/dist/types/shell/index.d.ts +1 -1
  44. package/dist/types/testing/brand-css.d.ts +41 -0
  45. package/dist/types/testing/contrast.d.ts +36 -0
  46. package/dist/types/testing/index.d.ts +2 -0
  47. package/package.json +5 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","names":["inspectorBounds","drawerBounds","clamp","px","max","min","clampInspectorWidth","drawerMaxHeight","share","windowHeight","clampDrawerHeight","defaultAppShellLabels","subscribeToResize","onChange","useWindowHeight","useSyncExternalStore","DrawerGlyph","open","TopBar","brand","status","start","end","Drawer","bodyId","useId","height","drawer","words","Splitter","IconButton","AppShell","labels","layout","useMediaBreakpoint","width","inspector","wide","className","topBar","children","Sheet"],"sources":["../src/shell/app-shell/bounds.ts","../src/shell/app-shell/AppShell.tsx"],"sourcesContent":["// The sizes the shell holds its panes to (docs/components.md#appshell): an inspector 280–560 px wide, and a drawer\n// from 120 px to 70 % of the window's height. Pure, so an app can check a kept size with the same rules before it\n// draws (as usePersistentState's check).\n\n/** The inspector's width in px. */\nexport const inspectorBounds = { min: 280, max: 560 } as const;\n\n/** The drawer's height: at least `min` px, at most `maxShare` of the window's height. */\nexport const drawerBounds = { min: 120, maxShare: 0.7 } as const;\n\n/** `px` as whole px within `min` and `max`; a value that is not a finite number is `min`. */\nfunction clamp(px: number, min: number, max: number): number {\n if (!Number.isFinite(px)) return min;\n return Math.min(max, Math.max(min, Math.round(px)));\n}\n\n/** The inspector's width as drawn for an asked `px`: whole px within 280–560. */\nexport function clampInspectorWidth(px: number): number {\n return clamp(px, inspectorBounds.min, inspectorBounds.max);\n}\n\n/** The tallest the drawer may be in a window `windowHeight` px high: 70 % of it, and never below the least. */\nexport function drawerMaxHeight(windowHeight: number): number {\n const share = Number.isFinite(windowHeight) ? Math.floor(windowHeight * drawerBounds.maxShare) : 0;\n return Math.max(drawerBounds.min, share);\n}\n\n/** The drawer's height as drawn for an asked `px` in a window `windowHeight` px high. */\nexport function clampDrawerHeight(px: number, windowHeight: number): number {\n return clamp(px, drawerBounds.min, drawerMaxHeight(windowHeight));\n}\n","// The layout of a graph-editing app (docs/components.md#appshell): a top bar of slots, the canvas, an inspector on the\n// right and a drawer along the bottom, filling the screen (100dvh) inside the safe-area insets. It keeps no data: the\n// inspector's width, the drawer's height and whether each is open are the app's props, drawn within the shell's bounds\n// (bounds.ts) and changed through callbacks. Below 760 px the inspector is a Sheet over the canvas's right edge, below\n// 600 px one rising from the bottom (useMediaBreakpoint's widths). The drawer's body stays mounted while it is closed,\n// so what it holds (a draft, a caret, a scroll position) is still there when it opens.\nimport { type ReactNode, useId, useSyncExternalStore } from \"react\";\nimport { useMediaBreakpoint } from \"../../hooks\";\nimport { IconButton, Sheet, Splitter } from \"../../primitives\";\nimport { clampDrawerHeight, clampInspectorWidth, drawerBounds, drawerMaxHeight, inspectorBounds } from \"./bounds\";\nimport \"./AppShell.css\";\n\n/**\n * The top bar's slots, drawn in reading order (left to right in left-to-right text): the brand, a status, the app's\n * controls, and controls at the far end.\n */\nexport type AppShellTopBar = {\n /** The app's mark or name, first. */\n brand?: ReactNode;\n /** A short state after the brand (a connection's Pill). */\n status?: ReactNode;\n /** The app's controls, taking the free width. */\n start?: ReactNode;\n /** Controls at the far end (a theme switch, a menu). */\n end?: ReactNode;\n};\n\nexport type AppShellInspector = {\n /** What the inspector shows: usually a Panel, which scrolls on its own. */\n content: ReactNode;\n /** Whether it is shown; the app holds it. */\n open: boolean;\n /** Asked for with false when the person closes the narrow window's sheet (its close button, or Escape inside it). */\n onOpen: (open: boolean) => void;\n /** Its width in px, drawn within 280–560 px (`inspectorBounds`); a narrow window's sheet takes it too. */\n width: number;\n /** A new width from its splitter, in whole px within the bounds. */\n onWidth: (px: number) => void;\n};\n\nexport type AppShellDrawer = {\n /** The drawer's header, beside its show and hide button; shown while it is closed too. */\n header: ReactNode;\n /** The drawer's body, mounted while it is closed. */\n content: ReactNode;\n /** Whether its body is shown; the app holds it. */\n open: boolean;\n /** Asked for by its show and hide button. */\n onOpen: (open: boolean) => void;\n /** Its height in px while open, header included, drawn within 120 px and 70 % of the window (`drawerBounds`). */\n height: number;\n /** A new height from its splitter, in whole px within the bounds. */\n onHeight: (px: number) => void;\n};\n\n/** The shell's own words, each replaceable. */\nexport interface AppShellLabels {\n /** The inspector's name, as a region and as a sheet: \"Inspector\". */\n inspector: string;\n /** The drawer's name as a region: \"Drawer\". */\n drawer: string;\n /** The inspector's splitter: \"Resize the inspector\". */\n resizeInspector: string;\n /** The drawer's splitter: \"Resize the drawer\". */\n resizeDrawer: string;\n /** The drawer's button while it is closed: \"Show the drawer\". */\n showDrawer: string;\n /** The drawer's button while it is open: \"Hide the drawer\". */\n hideDrawer: string;\n /** The inspector sheet's close button: \"Close\". */\n close: string;\n}\n\nexport const defaultAppShellLabels: AppShellLabels = {\n inspector: \"Inspector\",\n drawer: \"Drawer\",\n resizeInspector: \"Resize the inspector\",\n resizeDrawer: \"Resize the drawer\",\n showDrawer: \"Show the drawer\",\n hideDrawer: \"Hide the drawer\",\n close: \"Close\",\n};\n\nexport type AppShellProps = {\n /** The top bar's slots; without them there is no bar. */\n topBar?: AppShellTopBar;\n /** The inspector; without it there is none. */\n inspector?: AppShellInspector;\n /** The drawer; without it there is none. */\n drawer?: AppShellDrawer;\n /** The canvas, filling the workspace. */\n children: ReactNode;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<AppShellLabels>;\n /** A class added to the shell. */\n className?: string;\n};\n\nfunction subscribeToResize(onChange: () => void): () => void {\n window.addEventListener(\"resize\", onChange);\n return () => {\n window.removeEventListener(\"resize\", onChange);\n };\n}\n\n/** The window's height in px, kept current as it resizes; 0 with no window (the drawer then holds to its least). */\nfunction useWindowHeight(): number {\n return useSyncExternalStore(\n subscribeToResize,\n () => window.innerHeight,\n () => 0,\n );\n}\n\n/** A chevron pointing up (show) or down (hide), in the current text colour. */\nfunction DrawerGlyph({ open }: { open: boolean }) {\n return (\n <svg viewBox=\"0 0 16 16\" width=\"12\" height=\"12\" aria-hidden=\"true\">\n <path d={open ? \"M3 6l5 5 5-5\" : \"M3 10l5-5 5 5\"} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" />\n </svg>\n );\n}\n\nfunction TopBar({ brand, status, start, end }: AppShellTopBar) {\n return (\n <header className=\"pb-shell-bar\">\n {brand !== undefined && <div className=\"pb-shell-brand\">{brand}</div>}\n {status !== undefined && <div className=\"pb-shell-status\">{status}</div>}\n <div className=\"pb-shell-start\">{start}</div>\n {end !== undefined && <div className=\"pb-shell-end\">{end}</div>}\n </header>\n );\n}\n\nfunction Drawer({ drawer, words }: { drawer: AppShellDrawer; words: AppShellLabels }) {\n const bodyId = useId();\n const windowHeight = useWindowHeight();\n const height = clampDrawerHeight(drawer.height, windowHeight);\n return (\n <section\n className=\"pb-shell-drawer\"\n aria-label={words.drawer}\n data-open={drawer.open ? \"\" : undefined}\n style={drawer.open ? { height: `${height}px` } : undefined}\n >\n {drawer.open && (\n <Splitter\n orientation=\"horizontal\"\n edge=\"start\"\n value={height}\n min={drawerBounds.min}\n max={drawerMaxHeight(windowHeight)}\n onChange={drawer.onHeight}\n label={words.resizeDrawer}\n />\n )}\n <div className=\"pb-shell-drawer-head\">\n <div className=\"pb-shell-drawer-header\">{drawer.header}</div>\n <IconButton\n className=\"pb-shell-drawer-toggle\"\n label={drawer.open ? words.hideDrawer : words.showDrawer}\n aria-expanded={drawer.open}\n aria-controls={bodyId}\n onClick={() => {\n drawer.onOpen(!drawer.open);\n }}\n >\n <DrawerGlyph open={drawer.open} />\n </IconButton>\n </div>\n <div className=\"pb-shell-drawer-body\" id={bodyId} hidden={!drawer.open}>\n {drawer.content}\n </div>\n </section>\n );\n}\n\n/** Lays out a graph editor: top bar, canvas, inspector and drawer, with a sheet for the inspector on narrow windows. */\nexport function AppShell({ topBar, inspector, drawer, children, labels, className }: AppShellProps) {\n const words = { ...defaultAppShellLabels, ...labels };\n const { width: layout } = useMediaBreakpoint();\n const width = inspector === undefined ? 0 : clampInspectorWidth(inspector.width);\n const wide = layout === \"wide\";\n return (\n <div\n className={className === undefined ? \"pb-shell\" : `pb-shell ${className}`}\n data-layout={layout}\n data-bar={topBar === undefined ? undefined : \"\"}\n data-drawer={drawer === undefined ? undefined : \"\"}\n >\n {topBar !== undefined && <TopBar {...topBar} />}\n <div className=\"pb-shell-main\">\n <main className=\"pb-shell-workspace\">\n {children}\n {inspector !== undefined && !wide && (\n <Sheet\n open={inspector.open}\n onClose={() => {\n inspector.onOpen(false);\n }}\n side={layout === \"phone\" ? \"bottom\" : \"right\"}\n label={words.inspector}\n width={width}\n labels={{ close: words.close }}\n >\n {inspector.content}\n </Sheet>\n )}\n </main>\n {inspector !== undefined && wide && inspector.open && (\n <aside className=\"pb-shell-inspector\" aria-label={words.inspector} style={{ width: `${width}px` }}>\n <Splitter\n orientation=\"vertical\"\n edge=\"start\"\n value={width}\n min={inspectorBounds.min}\n max={inspectorBounds.max}\n onChange={inspector.onWidth}\n label={words.resizeInspector}\n />\n <div className=\"pb-shell-inspector-body\">{inspector.content}</div>\n </aside>\n )}\n </div>\n {drawer !== undefined && <Drawer drawer={drawer} words={words} />}\n </div>\n );\n}\n"],"mappings":";;;;;AAKA,IAAaA,IAAkB;CAAE,KAAK;CAAK,KAAK;AAAI,GAGvCC,IAAe;CAAE,KAAK;CAAK,UAAU;AAAI;AAGtD,SAASC,EAAM,GAAY,GAAa,GAAqB;CAE3D,OADK,OAAO,SAASC,CAAE,IAChB,KAAK,IAAIC,GAAK,KAAK,IAAIC,GAAK,KAAK,MAAMF,CAAE,C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n(t) {
7
+ let n = /* @__PURE__ */ new Map();
8
+ for (let r of t.split(";")) {
9
+ let t = r.indexOf(":");
10
+ t < 0 || n.set(r.slice(0, t).trim(), e(r.slice(t + 1)));
11
+ }
12
+ return n;
13
+ }
14
+ function r(i, a = null) {
15
+ let o = t(i), s = [], c = 0;
16
+ for (; c < o.length;) {
17
+ let t = o.indexOf("{", c);
18
+ if (t < 0) break;
19
+ let i = 1, l = t + 1;
20
+ for (; l < o.length && i > 0; l += 1) o[l] === "{" ? i += 1 : o[l] === "}" && --i;
21
+ let u = o.slice(c, t), d = e(u.slice(u.lastIndexOf(";") + 1)), f = o.slice(t + 1, l - 1);
22
+ d.startsWith("@") ? s.push(...r(f, d)) : s.push({
23
+ media: a,
24
+ selector: d,
25
+ declarations: n(f)
26
+ }), c = l;
27
+ }
28
+ return s;
29
+ }
30
+ function i(e) {
31
+ return e === void 0 ? /* @__PURE__ */ new Map() : new Map([...e.declarations].filter(([e]) => e.startsWith("--")));
32
+ }
33
+ var a = /^@media \(prefers-color-scheme:\s*dark\)$/;
34
+ function o(e, t, n) {
35
+ return e.find((e) => e.selector === n && (t === null ? e.media === null : e.media !== null && t.test(e.media)));
36
+ }
37
+ function s(e, t) {
38
+ let n = r(e);
39
+ return {
40
+ blocks: n,
41
+ light: o(n, null, t),
42
+ systemDark: o(n, a, `${t}:not([data-theme])`),
43
+ chosenDark: o(n, null, `${t}[data-theme="dark"]`)
44
+ };
45
+ }
46
+ function c(e, t, n) {
47
+ let r = (e) => n === "dark" ? e.chosenDark : n === "system dark" ? e.systemDark : void 0, a = [i(e.light), i(r(e))];
48
+ return t !== null && a.push(i(t.light), i(r(t))), new Map(a.flatMap((e) => [...e]));
49
+ }
50
+ function l(e, t) {
51
+ let n = /* @__PURE__ */ new Set(), r = t;
52
+ for (let t = /^var\((--[\w-]+)\)$/.exec(r); t !== null;) {
53
+ let i = t[1] ?? "";
54
+ if (n.has(i)) throw Error(`a var() cycle through ${i}`);
55
+ n.add(i);
56
+ let a = e.get(i);
57
+ if (a === void 0) throw Error(`${i} is not defined`);
58
+ r = a, t = /^var\((--[\w-]+)\)$/.exec(r);
59
+ }
60
+ return r;
61
+ }
62
+ function u(e) {
63
+ let t = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e);
64
+ if (t !== null) return [
65
+ 1,
66
+ 2,
67
+ 3
68
+ ].map((e) => parseInt((t[e] ?? "") + (t[e] ?? ""), 16));
69
+ let n = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);
70
+ return n === null ? null : [
71
+ 1,
72
+ 2,
73
+ 3
74
+ ].map((e) => parseInt(n[e] ?? "", 16));
75
+ }
76
+ // src/testing/contrast.ts
77
+ var d = 4.5, f = [
78
+ {
79
+ fg: ["--pb-text", "--pb-muted"],
80
+ on: [
81
+ "--pb-surface",
82
+ "--pb-raised",
83
+ "--pb-sunken"
84
+ ]
85
+ },
86
+ {
87
+ fg: ["--pb-text"],
88
+ on: ["--pb-warn-soft", "--pb-err-soft"]
89
+ },
90
+ {
91
+ fg: ["--pb-accent"],
92
+ on: [
93
+ "--pb-surface",
94
+ "--pb-raised",
95
+ "--pb-sunken"
96
+ ]
97
+ },
98
+ {
99
+ fg: [
100
+ "--pb-ok",
101
+ "--pb-warn",
102
+ "--pb-err",
103
+ "--pb-quiet",
104
+ "--pb-off",
105
+ "--pb-added",
106
+ "--pb-removed",
107
+ "--pb-renamed"
108
+ ],
109
+ on: [
110
+ "--pb-surface",
111
+ "--pb-raised",
112
+ "--pb-sunken"
113
+ ]
114
+ },
115
+ {
116
+ fg: ["--pb-warn"],
117
+ on: ["--pb-warn-soft"]
118
+ },
119
+ {
120
+ fg: ["--pb-err"],
121
+ on: ["--pb-err-soft"]
122
+ },
123
+ {
124
+ fg: ["--pb-on-strong"],
125
+ on: [
126
+ "--pb-accent",
127
+ "--pb-err",
128
+ "--pb-warn",
129
+ "--pb-ok",
130
+ "--pb-quiet",
131
+ "--pb-off",
132
+ "--pb-muted",
133
+ "--pb-added",
134
+ "--pb-removed",
135
+ "--pb-renamed"
136
+ ]
137
+ },
138
+ {
139
+ fg: [
140
+ "--pb-code-text",
141
+ "--pb-code-directive",
142
+ "--pb-code-keyword",
143
+ "--pb-code-variable",
144
+ "--pb-code-number",
145
+ "--pb-code-string",
146
+ "--pb-code-comment",
147
+ "--pb-code-punctuation",
148
+ "--pb-code-error"
149
+ ],
150
+ on: ["--pb-code-surface", "--pb-code-surface-readonly"]
151
+ },
152
+ {
153
+ fg: ["--pb-code-error"],
154
+ on: ["--pb-code-error-surface"]
155
+ }
156
+ ];
157
+ function p([e, t, n]) {
158
+ let r = (e) => {
159
+ let t = e / 255;
160
+ return t <= .04045 ? t / 12.92 : ((t + .055) / 1.055) ** 2.4;
161
+ };
162
+ return .2126 * r(e) + .7152 * r(t) + .0722 * r(n);
163
+ }
164
+ function m(e, t) {
165
+ let n = u(e), r = u(t);
166
+ if (n === null || r === null) return NaN;
167
+ let [i = 0, a = 0] = [p(n), p(r)].sort((e, t) => t - e);
168
+ return (i + .05) / (a + .05);
169
+ }
170
+ function h(e, t) {
171
+ let n = e.get(t);
172
+ if (n === void 0) return `undefined (${t} is not set)`;
173
+ try {
174
+ return l(e, n);
175
+ } catch (e) {
176
+ return `unresolved (${e instanceof Error ? e.message : String(e)})`;
177
+ }
178
+ }
179
+ function g(e, t) {
180
+ let n = s("/* patchbay's design tokens (@mcurcio/patchbay/tokens.css): every colour, radius, shadow, duration, space and type\n size a component draws with, as --pb-* custom properties on :root, in a light and a dark theme (docs/tokens.md).\n Component stylesheets use only these, and tokens.test.ts checks it.\n\n The theme follows the system until data-theme on <html> chooses one: no attribute is the system's choice,\n data-theme=\"light\" or \"dark\" overrides it. The dark set is therefore written twice, once for a dark system with no\n choice made and once for a chosen dark, and tokens.test.ts holds the two equal. CSS's light-dark() is not used\n because a CSS minifier may rewrite it for older browsers. */\n:root {\n color-scheme: light;\n\n /* Surfaces: the canvas, boxes and controls, tracks and read-only text. */\n --pb-surface: #f6f7f9;\n --pb-raised: #ffffff;\n --pb-sunken: #eef0f3;\n\n /* Lines: borders, the canvas's dot grid. */\n --pb-line: #d9dde3;\n --pb-line-strong: #aeb5bf;\n\n /* Text: body, secondary, selection and focus, text on a filled chip. */\n --pb-text: #16181d;\n --pb-muted: #5b6270;\n --pb-accent: #3b5bdb;\n --pb-on-strong: #ffffff;\n\n /* Tones: what a state is drawn in, and the soft surfaces under a warning or an error. */\n --pb-ok: #26773a;\n --pb-warn: #a35200;\n --pb-err: #c92a2a;\n --pb-quiet: #4058d6;\n --pb-off: #646b78;\n --pb-warn-soft: #fff4e6;\n --pb-err-soft: #ffe3e3;\n\n /* Changes: an edit not yet applied (added, removed, renamed). */\n --pb-added: #157a3a;\n --pb-removed: #c42020;\n --pb-renamed: #7c3aed;\n\n /* Meters: the bar's three zones and the peak tick. */\n --pb-meter-low: #40c057;\n --pb-meter-mid: #fab005;\n --pb-meter-hot: #fa5252;\n --pb-meter-peak: #2b8a3e;\n\n /* Code: a code box and its highlighter's token colours. */\n --pb-code-surface: var(--pb-raised);\n --pb-code-surface-readonly: var(--pb-sunken);\n --pb-code-border: var(--pb-line-strong);\n --pb-code-text: var(--pb-text);\n --pb-code-directive: #1864ab;\n --pb-code-keyword: #a35200;\n --pb-code-variable: #8a6100;\n --pb-code-number: #2b7a3a;\n --pb-code-string: #a61e1e;\n --pb-code-comment: #666666;\n --pb-code-punctuation: #495057;\n --pb-code-error: #c92a2a;\n --pb-code-error-surface: var(--pb-err-soft);\n\n /* Shape. */\n --pb-radius-box: 8px;\n --pb-radius-control: 6px;\n --pb-radius-pill: 999px;\n --pb-shadow: 0 1px 2px rgb(16 24 40 / 0.08);\n --pb-shadow-lifted: 0 4px 12px rgb(16 24 40 / 0.14);\n\n /* Motion: hover and selection, what slides, a pulsing dot, a wire's flow, the busy spinner's turn. The last three\n drive infinite animations, which a component stops under reduced motion rather than running at 0 s. */\n --pb-motion-fast: 120ms;\n --pb-motion-slow: 180ms;\n --pb-motion-pulse: 2s;\n --pb-motion-flow: 1s;\n --pb-motion-spin: 0.8s;\n\n /* Density: the spacing steps, a compact control's height, the top bar's height. */\n --pb-space-1: 2px;\n --pb-space-2: 4px;\n --pb-space-3: 8px;\n --pb-space-4: 12px;\n --pb-space-5: 16px;\n --pb-row: 22px;\n --pb-bar: 44px;\n\n /* Node geometry: a node box's fixed sizes, the same values as the constants /graph exports (NODE_WIDTH and the\n rest), since an app lays its nodes out from those before they render. A brand may not set these; the tests hold\n each equal to its constant and fail on a brand that sets one. */\n --pb-node-width: 240px;\n --pb-node-header: 46px;\n --pb-node-line: 22px;\n --pb-node-row: 22px;\n --pb-node-pad: 8px;\n --pb-node-footer: 28px;\n --pb-node-handle: 10px;\n --pb-node-handle-hit: 20px;\n\n /* Type: the faces, the two text sizes, and the code boxes' size (shared by a textarea, its highlighted copy and a\n gutter, so their glyphs line up). */\n --pb-font-ui: system-ui, sans-serif;\n --pb-font-code: ui-monospace, monospace;\n --pb-text-sm: 12px;\n --pb-text-md: 13px;\n --pb-code-size: 12px;\n}\n\n/* The system's dark, while no theme is chosen. */\n@media (prefers-color-scheme: dark) {\n :root:not([data-theme]) {\n color-scheme: dark;\n --pb-surface: #0f1115;\n --pb-raised: #181b21;\n --pb-sunken: #12151a;\n --pb-line: #2a2f38;\n --pb-line-strong: #3d4450;\n --pb-text: #e6e8ec;\n --pb-muted: #9aa2b1;\n --pb-accent: #7c94ff;\n --pb-on-strong: #0f1115;\n --pb-ok: #51cf66;\n --pb-warn: #ffa94d;\n --pb-err: #ff6b6b;\n --pb-quiet: #91a7ff;\n --pb-off: #808999;\n --pb-warn-soft: #2e2414;\n --pb-err-soft: #361b1d;\n --pb-added: #4ade80;\n --pb-removed: #f87171;\n --pb-renamed: #c084fc;\n --pb-meter-low: #51cf66;\n --pb-meter-mid: #ffd43b;\n --pb-meter-hot: #ff8787;\n --pb-meter-peak: #b2f2bb;\n --pb-shadow: 0 1px 2px rgb(0 0 0 / 0.5);\n --pb-shadow-lifted: 0 4px 12px rgb(0 0 0 / 0.6);\n --pb-code-directive: #74c0fc;\n --pb-code-keyword: #ffa94d;\n --pb-code-variable: #ffd43b;\n --pb-code-number: #69db7c;\n --pb-code-string: #ff8787;\n --pb-code-comment: #8c929c;\n --pb-code-punctuation: #adb5bd;\n --pb-code-error: #ff6b6b;\n }\n}\n\n/* Dark chosen over any system: the same set, line for line. */\n:root[data-theme=\"dark\"] {\n color-scheme: dark;\n --pb-surface: #0f1115;\n --pb-raised: #181b21;\n --pb-sunken: #12151a;\n --pb-line: #2a2f38;\n --pb-line-strong: #3d4450;\n --pb-text: #e6e8ec;\n --pb-muted: #9aa2b1;\n --pb-accent: #7c94ff;\n --pb-on-strong: #0f1115;\n --pb-ok: #51cf66;\n --pb-warn: #ffa94d;\n --pb-err: #ff6b6b;\n --pb-quiet: #91a7ff;\n --pb-off: #808999;\n --pb-warn-soft: #2e2414;\n --pb-err-soft: #361b1d;\n --pb-added: #4ade80;\n --pb-removed: #f87171;\n --pb-renamed: #c084fc;\n --pb-meter-low: #51cf66;\n --pb-meter-mid: #ffd43b;\n --pb-meter-hot: #ff8787;\n --pb-meter-peak: #b2f2bb;\n --pb-shadow: 0 1px 2px rgb(0 0 0 / 0.5);\n --pb-shadow-lifted: 0 4px 12px rgb(0 0 0 / 0.6);\n --pb-code-directive: #74c0fc;\n --pb-code-keyword: #ffa94d;\n --pb-code-variable: #ffd43b;\n --pb-code-number: #69db7c;\n --pb-code-string: #ff8787;\n --pb-code-comment: #8c929c;\n --pb-code-punctuation: #adb5bd;\n --pb-code-error: #ff6b6b;\n}\n\n/* A finger: every text field is 16 px, code boxes included, as iOS Safari zooms the page when a smaller field takes\n the focus; a handle's hit area grows to 32 px (handles sit 22 px apart, too close for 36 px targets). */\n@media (hover: none) and (pointer: coarse) {\n :root {\n --pb-code-size: 16px;\n --pb-node-handle-hit: 32px;\n }\n}\n\n/* No motion for those who ask for none. The pulse, the flow and the spin keep their durations: a component stops those\n infinite animations instead, since one at 0 s would churn rather than stop. */\n@media (prefers-reduced-motion: reduce) {\n :root {\n --pb-motion-fast: 0ms;\n --pb-motion-slow: 0ms;\n }\n}\n\n/* Derived colours: mixed from the theme's tokens, so they follow the theme and a brand without a dark value of their\n own (var() resolves on :root, after the theme and the brand). A brand may still override them. */\n:root {\n /* Behind a modal dialog: the canvas, mostly opaque. */\n --pb-scrim: color-mix(in srgb, var(--pb-surface) 72%, transparent);\n /* A filled accent control under the pointer: the accent pulled toward the text colour. */\n --pb-accent-hover: color-mix(in srgb, var(--pb-accent) 85%, var(--pb-text));\n}\n\n/* React Flow's own variables point at the tokens, so its canvas, dot grid, wires, handles and minimap follow the\n theme and the brand. Its colorMode prop is not used: it would fight data-theme. Set on .react-flow, so each var()\n resolves where React Flow reads it. */\n.react-flow {\n --xy-background-color: var(--pb-surface);\n --xy-background-pattern-color: var(--pb-line);\n --xy-node-color: var(--pb-text);\n --xy-edge-stroke: var(--pb-muted);\n --xy-edge-stroke-selected: var(--pb-accent);\n --xy-connectionline-stroke: var(--pb-muted);\n --xy-handle-background-color: var(--pb-text);\n --xy-handle-border-color: var(--pb-raised);\n --xy-selection-background-color: color-mix(in srgb, var(--pb-accent) 8%, transparent);\n --xy-selection-border: 1px dotted var(--pb-accent);\n --xy-attribution-background-color: color-mix(in srgb, var(--pb-raised) 60%, transparent);\n --xy-controls-button-background-color: var(--pb-raised);\n --xy-controls-button-color: var(--pb-text);\n --xy-minimap-background-color: var(--pb-raised);\n --xy-minimap-mask-background-color: color-mix(in srgb, var(--pb-surface) 65%, transparent);\n --xy-minimap-mask-stroke-color: var(--pb-accent);\n --xy-minimap-node-background-color: var(--pb-sunken);\n --xy-minimap-node-stroke-color: var(--pb-line-strong);\n}\n\n/* React Flow's attribution link is drawn in a fixed grey of its own, below 4.5:1 on its panel, with no variable to\n point at a token; the muted text colour keeps it legible in both themes and under a brand. Written under .react-flow,\n so it wins whichever of the two stylesheets an app loads first. */\n.react-flow .react-flow__attribution a {\n color: var(--pb-muted);\n}\n", ":root"), r = s(e, `:root[data-brand="${t}"]`), i = [];
181
+ for (let e of [
182
+ "light",
183
+ "dark",
184
+ "system dark"
185
+ ]) {
186
+ let a = c(n, r, e);
187
+ for (let n of f) for (let r of n.fg) for (let o of n.on) {
188
+ let n = h(a, r), s = h(a, o), c = m(n, s);
189
+ if (c >= 4.5) continue;
190
+ let l = `${t} ${e}: ${r} (${n}) on ${o} (${s}) ${Number.isNaN(c) ? "is not two hex colours" : `is ${c.toFixed(2)}:1`}`;
191
+ i.push({
192
+ brand: t,
193
+ theme: e,
194
+ fg: r,
195
+ on: o,
196
+ fgValue: n,
197
+ onValue: s,
198
+ ratio: c,
199
+ message: l
200
+ });
201
+ }
202
+ }
203
+ return i;
204
+ }
205
+ export { g as checkBrandContrast, f as contrastPairs, m as contrastRatio, d as minimumContrast };
206
+
207
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","names":["tokensCss","squash","text","stripComments","declarations","found","declaration","body","colon","cssBlocks","css","at","open","depth","close","before","prelude","customProperties","block","name","systemDark","findBlock","blocks","candidate","selector","media","tokenSets","root","tokensInForce","dark","theme","sets","layers","base","brand","layer","resolveToken","seen","current","value","reference","next","tokens","hexColour","short","i","long","minimumContrast","contrastPairs","luminance","r","g","b","channel","s","c","contrastRatio","first","a","second","high","low","y","x","valueOf","error","checkBrandContrast","own","failures","pair","fg","on","fgValue","onValue","ratio","message"],"sources":["../src/testing/brand-css.ts","../src/testing/contrast.ts"],"sourcesContent":["// Reading the token and brand stylesheets as text (docs/tokens.md#writing-a-brand): their rule sets, the three sets of\n// tokens a :root selector holds (light, the system's dark, the chosen dark), and the tokens in force in a theme, as\n// the cascade resolves them. Pure: no DOM, no test runner. The contrast check and the token tests read through it.\n\n/** One rule set: its selector, the at-rule it sits in (`@media (…)`, or null at the top), and its declarations. */\nexport type CssBlock = { media: string | null; selector: string; declarations: Map<string, string> };\n\nconst squash = (text: string) => text.trim().replace(/\\s+/g, \" \");\n\nexport function stripComments(text: string): string {\n return text.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n}\n\nfunction declarations(body: string): Map<string, string> {\n const found = new Map<string, string>();\n for (const declaration of body.split(\";\")) {\n const colon = declaration.indexOf(\":\");\n if (colon < 0) continue;\n found.set(declaration.slice(0, colon).trim(), squash(declaration.slice(colon + 1)));\n }\n return found;\n}\n\n/**\n * A stylesheet's rule sets, in order: each plain rule, and each rule inside an at-rule (`@media`) with that at-rule's\n * prelude as its `media`. Statement at-rules (`@import …;`) are skipped. It reads stylesheets as the token files and\n * brands are written, not every CSS there is: braces inside strings are not understood.\n */\nexport function cssBlocks(css: string, media: string | null = null): CssBlock[] {\n const text = stripComments(css);\n const found: CssBlock[] = [];\n let at = 0;\n while (at < text.length) {\n const open = text.indexOf(\"{\", at);\n if (open < 0) break;\n let depth = 1;\n let close = open + 1;\n for (; close < text.length && depth > 0; close += 1) {\n if (text[close] === \"{\") depth += 1;\n else if (text[close] === \"}\") depth -= 1;\n }\n const before = text.slice(at, open);\n const prelude = squash(before.slice(before.lastIndexOf(\";\") + 1));\n const body = text.slice(open + 1, close - 1);\n if (prelude.startsWith(\"@\")) found.push(...cssBlocks(body, prelude));\n else found.push({ media, selector: prelude, declarations: declarations(body) });\n at = close;\n }\n return found;\n}\n\n/** A block's custom properties (`--name: value`), or none for a missing block. */\nexport function customProperties(block: CssBlock | undefined): Map<string, string> {\n if (block === undefined) return new Map();\n return new Map([...block.declarations].filter(([name]) => name.startsWith(\"--\")));\n}\n\nconst systemDark = /^@media \\(prefers-color-scheme:\\s*dark\\)$/;\n\n/** The block with this selector, at the top (`media` null) or inside an at-rule whose prelude `media` matches. */\nexport function findBlock(blocks: readonly CssBlock[], media: RegExp | null, selector: string): CssBlock | undefined {\n return blocks.find(\n (candidate) =>\n candidate.selector === selector &&\n (media === null ? candidate.media === null : candidate.media !== null && media.test(candidate.media)),\n );\n}\n\n/** A stylesheet's three sets under a :root selector, as tokens.css and a brand write them, and all its blocks. */\nexport type TokenSets = {\n blocks: CssBlock[];\n /** `root` itself: the light set. */\n light: CssBlock | undefined;\n /** `root:not([data-theme])` inside `@media (prefers-color-scheme: dark)`: the dark set when no choice is made. */\n systemDark: CssBlock | undefined;\n /** `root[data-theme=\"dark\"]`: the dark set when dark is chosen. */\n chosenDark: CssBlock | undefined;\n};\n\n/** The light, system dark and chosen dark sets of a stylesheet under `root` (`:root`, or `:root[data-brand=\"x\"]`). */\nexport function tokenSets(css: string, root: string): TokenSets {\n const blocks = cssBlocks(css);\n return {\n blocks,\n light: findBlock(blocks, null, root),\n systemDark: findBlock(blocks, systemDark, `${root}:not([data-theme])`),\n chosenDark: findBlock(blocks, null, `${root}[data-theme=\"dark\"]`),\n };\n}\n\n/** How a page is themed: light, dark chosen with `data-theme=\"dark\"`, or dark by the system with no choice made. */\nexport type ContrastTheme = \"light\" | \"dark\" | \"system dark\";\n\n/** The tokens in force in a theme, in the cascade's order: the base's set for it, then the brand's (if any). */\nexport function tokensInForce(base: TokenSets, brand: TokenSets | null, theme: ContrastTheme): Map<string, string> {\n const dark = (sets: TokenSets) =>\n theme === \"dark\" ? sets.chosenDark : theme === \"system dark\" ? sets.systemDark : undefined;\n const layers = [customProperties(base.light), customProperties(dark(base))];\n if (brand !== null) layers.push(customProperties(brand.light), customProperties(dark(brand)));\n return new Map(layers.flatMap((layer) => [...layer]));\n}\n\n/** A value with every `var(--name)` it is followed through resolved from `tokens`; throws on a cycle or a gap. */\nexport function resolveToken(tokens: Map<string, string>, value: string): string {\n const seen = new Set<string>();\n let current = value;\n for (let reference = /^var\\((--[\\w-]+)\\)$/.exec(current); reference !== null;) {\n const name = reference[1] ?? \"\";\n if (seen.has(name)) throw new Error(`a var() cycle through ${name}`);\n seen.add(name);\n const next = tokens.get(name);\n if (next === undefined) throw new Error(`${name} is not defined`);\n current = next;\n reference = /^var\\((--[\\w-]+)\\)$/.exec(current);\n }\n return current;\n}\n\n/** An sRGB colour, 0 to 255 a channel. */\nexport type Rgb = readonly [number, number, number];\n\n/** A `#rgb` or `#rrggbb` colour, or null for anything else. */\nexport function hexColour(value: string): Rgb | null {\n const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(value);\n if (short !== null) return [1, 2, 3].map((i) => parseInt((short[i] ?? \"\") + (short[i] ?? \"\"), 16)) as unknown as Rgb;\n const long = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(value);\n if (long !== null) return [1, 2, 3].map((i) => parseInt(long[i] ?? \"\", 16)) as unknown as Rgb;\n return null;\n}\n\n/** Whether a value is a colour written as hex or `rgb()`/`rgba()`. */\nexport function isColour(value: string): boolean {\n return hexColour(value) !== null || /\\brgba?\\(/.test(value);\n}\n","// The contrast rule (docs/tokens.md#writing-a-brand): every text, tone, change, on-strong and code token at 4.5:1 on\n// each surface it is drawn on, in light and in dark, with a brand's values in force over tokens.css's. Pure: it reads\n// stylesheets as text and returns what fails, so an app's own tests (any runner) can hold its brand to the rule.\nimport tokensCss from \"../tokens/tokens.css?raw\";\nimport { hexColour, resolveToken, type Rgb, type ContrastTheme, tokenSets, tokensInForce } from \"./brand-css\";\n\n/** Tokens drawn as text (`fg`), each checked on every surface it is drawn on (`on`). */\nexport type ContrastPair = { readonly fg: readonly string[]; readonly on: readonly string[] };\n\n/** The least contrast a text token keeps on its surfaces: WCAG's 4.5:1 for normal text. */\nexport const minimumContrast = 4.5;\n\n/** Every text token and the surfaces it is drawn on: text, the accent, tones, changes, on-strong and code. */\nexport const contrastPairs: readonly ContrastPair[] = [\n { fg: [\"--pb-text\", \"--pb-muted\"], on: [\"--pb-surface\", \"--pb-raised\", \"--pb-sunken\"] },\n { fg: [\"--pb-text\"], on: [\"--pb-warn-soft\", \"--pb-err-soft\"] },\n // The sunken surface is under an accent pill or badge.\n { fg: [\"--pb-accent\"], on: [\"--pb-surface\", \"--pb-raised\", \"--pb-sunken\"] },\n {\n fg: [\"--pb-ok\", \"--pb-warn\", \"--pb-err\", \"--pb-quiet\", \"--pb-off\", \"--pb-added\", \"--pb-removed\", \"--pb-renamed\"],\n on: [\"--pb-surface\", \"--pb-raised\", \"--pb-sunken\"],\n },\n { fg: [\"--pb-warn\"], on: [\"--pb-warn-soft\"] },\n { fg: [\"--pb-err\"], on: [\"--pb-err-soft\"] },\n // On-strong is the words on a filled button, mark or badge, so it is checked on every tone a badge fills with.\n {\n fg: [\"--pb-on-strong\"],\n on: [\n \"--pb-accent\",\n \"--pb-err\",\n \"--pb-warn\",\n \"--pb-ok\",\n \"--pb-quiet\",\n \"--pb-off\",\n \"--pb-muted\",\n \"--pb-added\",\n \"--pb-removed\",\n \"--pb-renamed\",\n ],\n },\n {\n fg: [\n \"--pb-code-text\",\n \"--pb-code-directive\",\n \"--pb-code-keyword\",\n \"--pb-code-variable\",\n \"--pb-code-number\",\n \"--pb-code-string\",\n \"--pb-code-comment\",\n \"--pb-code-punctuation\",\n \"--pb-code-error\",\n ],\n on: [\"--pb-code-surface\", \"--pb-code-surface-readonly\"],\n },\n { fg: [\"--pb-code-error\"], on: [\"--pb-code-error-surface\"] },\n];\n\n/** WCAG 2's relative luminance of an sRGB colour. */\nfunction luminance([r, g, b]: Rgb): number {\n const channel = (c: number) => {\n const s = c / 255;\n return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);\n}\n\n/** WCAG 2's contrast ratio of two hex colours (`#rgb` or `#rrggbb`), 1 to 21; NaN when either is not one. */\nexport function contrastRatio(a: string, b: string): number {\n const first = hexColour(a);\n const second = hexColour(b);\n if (first === null || second === null) return Number.NaN;\n const [high = 0, low = 0] = [luminance(first), luminance(second)].sort((x, y) => y - x);\n return (high + 0.05) / (low + 0.05);\n}\n\n/** One text token below the rule on one surface, in one theme. */\nexport type ContrastFailure = {\n /** The brand's name, or \"base\" for tokens.css alone. */\n brand: string;\n theme: ContrastTheme;\n fg: string;\n on: string;\n /** The values the two resolve to in that theme (or why one does not resolve). */\n fgValue: string;\n onValue: string;\n /** The contrast, or NaN when a value is not a hex colour. */\n ratio: number;\n /** All of it in a line: \"harbor dark: --pb-muted (#64748b) on --pb-raised (#1e293b) is 3.07:1\". */\n message: string;\n};\n\nexport type { ContrastTheme } from \"./brand-css\";\n\nfunction valueOf(tokens: Map<string, string>, name: string): string {\n const value = tokens.get(name);\n if (value === undefined) return `undefined (${name} is not set)`;\n try {\n return resolveToken(tokens, value);\n } catch (error) {\n return `unresolved (${error instanceof Error ? error.message : String(error)})`;\n }\n}\n\n/**\n * Checks a brand against the contrast rule: for each theme (light, dark chosen, dark by the system), the tokens in\n * force are tokens.css's set for it with the brand's blocks for `brand` (its `:root[data-brand=\"…\"]` rules) over\n * them, and every pair in `contrastPairs` must reach `minimumContrast`. Returns the failures; none means the brand\n * keeps the rule. `css` is the brand's stylesheet as text; an empty one (or a `brand` it has no blocks for) checks\n * the base theme alone. Colours must be written as hex, or the pair fails saying so.\n */\nexport function checkBrandContrast(css: string, brand: string): ContrastFailure[] {\n const base = tokenSets(tokensCss, \":root\");\n const own = tokenSets(css, `:root[data-brand=\"${brand}\"]`);\n const failures: ContrastFailure[] = [];\n for (const theme of [\"light\", \"dark\", \"system dark\"] as const) {\n const tokens = tokensInForce(base, own, theme);\n for (const pair of contrastPairs) {\n for (const fg of pair.fg) {\n for (const on of pair.on) {\n const fgValue = valueOf(tokens, fg);\n const onValue = valueOf(tokens, on);\n const ratio = contrastRatio(fgValue, onValue);\n if (ratio >= minimumContrast) continue;\n const said = Number.isNaN(ratio) ? \"is not two hex colours\" : `is ${ratio.toFixed(2)}:1`;\n const message = `${brand} ${theme}: ${fg} (${fgValue}) on ${on} (${onValue}) ${said}`;\n failures.push({ brand, theme, fg, on, fgValue, onValue, ratio, message });\n }\n }\n }\n }\n return failures;\n}\n"],"mappings":";A,IAOMC,KAAU,MAAiBC,EAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG;AAEhE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AK,IACpB,KAAK,IAAME,KAAMF,EAAK,IAAI;GACxB,IAAMG,IAAUR,EAAQtB,GAAQ4B,CAAE,GAC5BG,IAAUT,EAAQtB,GAAQ6B,CAAE,GAC5BG,IAAQlB,EAAcgB,GAASC,CAAO;GAC5C,IAAIC,KAAA,KAA0B;GAE9B,IAAMC,IAAU,GAAGzC,EAAM,GAAGJ,EAAM,IAAIwC,EAAG,IAAIE,EAAQ,OAAOD,EAAG,IAAIE,EAAQ,IAD9D,OAAO,MAAMC,CAAK,IAAI,2BAA2B,MAAMA,EAAM,QAAQ,CAAC,EAAE;GAErF,EAAS,KAAK;IAAE;IAAO;IAAO;IAAI;IAAI;IAAS;IAAS;IAAO;GAAQ,CAAC;EAC1E;CAGN;CACA,OAAON;AACT"}
@@ -2,6 +2,12 @@ import type { ComponentPropsWithRef, ReactNode } from "react";
2
2
  import "./Banner.css";
3
3
  /** The tones a banner draws; any other string is drawn neutrally. */
4
4
  export type BannerTone = "ok" | "warn" | "err" | "quiet" | "off" | (string & {});
5
+ /** The banner's own words, each replaceable. */
6
+ export interface BannerLabels {
7
+ /** The close button's name: "Dismiss". */
8
+ dismiss: string;
9
+ }
10
+ export declare const defaultBannerLabels: BannerLabels;
5
11
  export type BannerProps = Omit<ComponentPropsWithRef<"div">, "role"> & {
6
12
  /** What the news is, by colour: the stripe's, and the surface's for warn and err. */
7
13
  tone: BannerTone;
@@ -11,7 +17,7 @@ export type BannerProps = Omit<ComponentPropsWithRef<"div">, "role"> & {
11
17
  actions?: ReactNode;
12
18
  /** Shows a close button, which asks the app to take the banner away. */
13
19
  onDismiss?: () => void;
14
- /** The close button's name, "Dismiss" by default. */
15
- dismissLabel?: string;
20
+ /** Words to replace; the rest keep their defaults. */
21
+ labels?: Partial<BannerLabels>;
16
22
  };
17
- export declare function Banner({ tone, children, actions, onDismiss, dismissLabel, className, ...rest }: BannerProps): import("react").JSX.Element;
23
+ export declare function Banner({ tone, children, actions, onDismiss, labels, className, ...rest }: BannerProps): import("react").JSX.Element;
@@ -1,2 +1,2 @@
1
- export { Banner } from "./Banner";
2
- export type { BannerProps, BannerTone } from "./Banner";
1
+ export { Banner, defaultBannerLabels } from "./Banner";
2
+ export type { BannerLabels, BannerProps, BannerTone } from "./Banner";
@@ -0,0 +1,45 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ import { type CodeCaret, type CodeDiagnostic, type CodeLanguage, type Highlighter } from "./highlight";
3
+ import "./CodeEditor.css";
4
+ /** The editor's own words, each replaceable. */
5
+ export interface CodeEditorLabels {
6
+ /** How a diagnostic is read, and shown over its gutter mark: "Line 3, column 5: error E1: message". */
7
+ diagnostic: (diagnostic: CodeDiagnostic) => string;
8
+ /** Read after the editor's name while it can be edited: how Tab works and how to leave. */
9
+ tabKey: string;
10
+ }
11
+ export declare const defaultCodeEditorLabels: CodeEditorLabels;
12
+ export type CodeEditorProps = Omit<ComponentPropsWithRef<"textarea">, "value" | "defaultValue" | "onChange"> & {
13
+ /** The text. CRLF and a lone CR are shown as LF, and an edit gives the text back with LF. */
14
+ value: string;
15
+ /** The person changed the text: the textarea's whole new value. */
16
+ onChange?: (value: string) => void;
17
+ /** A language built in ("knobly"); any other draws plain text. `highlight` wins over it. */
18
+ language?: CodeLanguage;
19
+ /** The app's highlighter, from the shown text to its spans. */
20
+ highlight?: Highlighter;
21
+ /** What the app found in the text, marked in the gutter and under the text, and read with the editor. */
22
+ diagnostics?: readonly CodeDiagnostic[];
23
+ /** The caret moved (by a key, a press, an edit or a gutter mark): its line, column and offset. */
24
+ onCaret?: (caret: CodeCaret) => void;
25
+ /** Show the line-number gutter (true by default). */
26
+ lineNumbers?: boolean;
27
+ /** What Tab inserts, and Shift+Tab takes away from a line's start: a tab by default. */
28
+ indent?: string;
29
+ /** Words to replace; the rest keep their defaults. */
30
+ labels?: Partial<CodeEditorLabels>;
31
+ };
32
+ /**
33
+ * What Tab (or Shift+Tab, `out`) does to a text and its selection: the range it replaces, with what, and the
34
+ * selection after. Tab in one line replaces the selection with the indent; across lines, and Shift+Tab always, it
35
+ * indents or outdents each line the selection touches (empty lines are left alone when indenting). Undefined when
36
+ * nothing would change.
37
+ */
38
+ export declare function tabEdit(text: string, start: number, end: number, indent: string, out: boolean): {
39
+ from: number;
40
+ to: number;
41
+ insert: string;
42
+ start: number;
43
+ end: number;
44
+ } | undefined;
45
+ export declare function CodeEditor({ value, onChange, language, highlight, diagnostics, onCaret, lineNumbers, indent, labels, readOnly, className, style, ref, onKeyDown, onBlur, onScroll, onSelect, "aria-describedby": describedBy, ...rest }: CodeEditorProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import type { CodeRun } from "./highlight";
2
+ import "./CodeRuns.css";
3
+ export declare function CodeRuns({ runs }: {
4
+ runs: readonly CodeRun[];
5
+ }): (string | import("react").JSX.Element)[];
@@ -0,0 +1,12 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ import { type CodeLanguage, type Highlighter } from "./highlight";
3
+ import "./CodeText.css";
4
+ export type CodeTextProps = Omit<ComponentPropsWithRef<"pre">, "children"> & {
5
+ /** The text; CRLF and a lone CR are drawn as LF. */
6
+ value: string;
7
+ /** A language built in ("knobly"); any other draws plain text. `highlight` wins over it. */
8
+ language?: CodeLanguage;
9
+ /** The app's highlighter, from the shown text to its spans. */
10
+ highlight?: Highlighter;
11
+ };
12
+ export declare function CodeText({ value, language, highlight, className, ...rest }: CodeTextProps): import("react").JSX.Element;
@@ -0,0 +1,83 @@
1
+ /** A highlighter's span: offsets into the shown text (`end` exclusive) and its class. */
2
+ export type CodeSpan = {
3
+ readonly start: number;
4
+ readonly end: number;
5
+ /**
6
+ * How it is drawn: "directive", "keyword", "word", "variable", "number", "string", "comment", "punctuation" or
7
+ * "error" have a colour each; "space", "" and any other class are drawn as plain text.
8
+ */
9
+ readonly class: string;
10
+ };
11
+ /** A highlighter: the text, as shown (LF line breaks), to its spans. Pure and total. */
12
+ export type Highlighter = (text: string) => readonly CodeSpan[];
13
+ /** A language built in: "knobly"; any other is drawn as plain text unless a highlighter is given. */
14
+ export type CodeLanguage = "knobly" | (string & {});
15
+ /** How bad a diagnostic is: "error" and "warning" have their own mark; any other is drawn neutrally. */
16
+ export type CodeSeverity = "error" | "warning" | (string & {});
17
+ /** Something the app found in the text: a line (from 1) and an optional column (from 1, in UTF-16 code units). */
18
+ export type CodeDiagnostic = {
19
+ line: number;
20
+ column?: number;
21
+ severity: CodeSeverity;
22
+ message: string;
23
+ /** The app's own code for it, read with the message. */
24
+ code?: string;
25
+ };
26
+ /** Where the caret is: a line and a column, both from 1, and its offset into the shown text. */
27
+ export type CodeCaret = {
28
+ line: number;
29
+ column: number;
30
+ offset: number;
31
+ };
32
+ /** The mark a severity draws. */
33
+ export type CodeMarkLevel = "error" | "warning" | "other";
34
+ /** One run of shown text, drawn in one class with at most one mark. */
35
+ export type CodeRun = {
36
+ text: string;
37
+ class: string;
38
+ mark?: CodeMarkLevel;
39
+ };
40
+ /** One gutter row per shown line, with its diagnostics in the order given. */
41
+ export type CodeGutterRow = {
42
+ line: number;
43
+ mark?: CodeMarkLevel;
44
+ /** Where a press on its mark puts the caret: the first diagnostic's column, else 1. */
45
+ column: number;
46
+ diagnostics: CodeDiagnostic[];
47
+ };
48
+ /**
49
+ * The text as a textarea shows it: a textarea holds LF line breaks only, so CRLF and a lone CR are drawn as LF. The
50
+ * value itself is never changed.
51
+ */
52
+ export declare function shownText(text: string): string;
53
+ /** Where each line of shown text starts. "" is one line, and a last newline starts an empty one after it. */
54
+ export declare function lineStarts(shown: string): number[];
55
+ /** The caret at an offset into the shown text, clamped to the text. */
56
+ export declare function caretAt(shown: string, offset: number): CodeCaret;
57
+ /** The offset of a line and column (both from 1) into the shown text, each clamped to the text. */
58
+ export declare function offsetAt(shown: string, line: number, column?: number): number;
59
+ /** The mark a severity draws: error, warning, or a neutral one for any other. */
60
+ export declare function markLevel(severity: string): CodeMarkLevel;
61
+ /** A diagnostic's mark in the shown text: from its column to the word's end, or the line's text without a column. */
62
+ export declare function markRange(shown: string, diagnostic: CodeDiagnostic): {
63
+ start: number;
64
+ end: number;
65
+ };
66
+ /**
67
+ * The shown text cut into runs by the spans (clipped to the text, empty ones ignored; where two overlap, the later
68
+ * one wins) and the diagnostics' marks (where two overlap, error over warning over any other). Joined, the runs are
69
+ * the shown text exactly.
70
+ */
71
+ export declare function codeRuns(shown: string, spans?: readonly CodeSpan[], diagnostics?: readonly CodeDiagnostic[]): CodeRun[];
72
+ /** One row per shown line; a diagnostic's line is clamped to the text, so one past the end marks the last line. */
73
+ export declare function gutterRows(shown: string, diagnostics?: readonly CodeDiagnostic[]): CodeGutterRow[];
74
+ /**
75
+ * Loads knobly's highlighter from the optional knobly peer, once for the page; null when knobly is not installed (the
76
+ * view then draws plain text, and says so once on the console).
77
+ */
78
+ export declare function loadKnobly(): Promise<Highlighter | null>;
79
+ /**
80
+ * The highlighter a view draws with: the app's `highlight` when given, else knobly's for language "knobly" (once
81
+ * loaded; plain text until then), else none.
82
+ */
83
+ export declare function useHighlighter(language: CodeLanguage | undefined, highlight: Highlighter | undefined): Highlighter | undefined;
@@ -0,0 +1,6 @@
1
+ export { CodeEditor, defaultCodeEditorLabels, tabEdit } from "./CodeEditor";
2
+ export type { CodeEditorLabels, CodeEditorProps } from "./CodeEditor";
3
+ export { CodeText } from "./CodeText";
4
+ export type { CodeTextProps } from "./CodeText";
5
+ export { caretAt, codeRuns, gutterRows, loadKnobly, markLevel, offsetAt, shownText } from "./highlight";
6
+ export type { CodeCaret, CodeDiagnostic, CodeGutterRow, CodeLanguage, CodeMarkLevel, CodeRun, CodeSeverity, CodeSpan, Highlighter, } from "./highlight";
@@ -31,21 +31,27 @@ export type CommandPaletteProps = {
31
31
  commands: readonly Command[];
32
32
  /** Anchors the palette's top-left corner at this point, kept inside the window; centred near the top without it. */
33
33
  at?: PalettePoint;
34
- /** The field's placeholder, "Type a command" by default. */
35
- placeholder?: string;
36
- /** The palette's name for screen readers, "Commands" by default. */
37
- label?: string;
38
- /** Shown when there are no commands at all, "No commands" by default. */
39
- emptyLabel?: ReactNode;
40
- /** Shown when the query matches none, "No command matches “query”" by default. */
41
- noMatchLabel?: (query: string) => ReactNode;
42
34
  /** The platform keys are drawn for; the browser's by default. */
43
35
  platform?: Platform;
44
- /** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"). */
45
- keyNames?: Readonly<Record<string, string>>;
36
+ /** Words to replace; the rest keep their defaults. */
37
+ labels?: Partial<CommandPaletteLabels>;
46
38
  /** A class added to the palette's box. */
47
39
  className?: string;
48
40
  };
41
+ /** The palette's own words, each replaceable. */
42
+ export interface CommandPaletteLabels {
43
+ /** The palette's name for screen readers: "Commands". */
44
+ palette: string;
45
+ /** The field's placeholder: "Type a command". */
46
+ placeholder: string;
47
+ /** Shown when there are no commands at all: "No commands". */
48
+ empty: ReactNode;
49
+ /** Shown when the query matches none: "No command matches “query”". */
50
+ noMatch: (query: string) => ReactNode;
51
+ /** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"); none by default, keyLabel's own. */
52
+ keyNames: Readonly<Record<string, string>>;
53
+ }
54
+ export declare const defaultCommandPaletteLabels: CommandPaletteLabels;
49
55
  /** The anchored palette's size, held inside the window less the gutter. */
50
56
  export declare const PALETTE_WIDTH = 320;
51
57
  export declare const PALETTE_HEIGHT = 360;
@@ -1,4 +1,4 @@
1
- export { CommandPalette, PALETTE_GUTTER, PALETTE_HEIGHT, PALETTE_WIDTH, placePalette } from "./CommandPalette";
2
- export type { Command, CommandPaletteProps, PalettePoint } from "./CommandPalette";
1
+ export { CommandPalette, defaultCommandPaletteLabels, PALETTE_GUTTER, PALETTE_HEIGHT, PALETTE_WIDTH, placePalette, } from "./CommandPalette";
2
+ export type { Command, CommandPaletteLabels, CommandPaletteProps, PalettePoint } from "./CommandPalette";
3
3
  export { markRuns, matchSubsequence, rankCommands } from "./rank";
4
4
  export type { Rankable, RankedCommand, RankedGroup, SubsequenceMatch } from "./rank";
@@ -1,4 +1,5 @@
1
1
  export * from "./banner";
2
+ export * from "./code-editor";
2
3
  export * from "./command-palette";
3
4
  export * from "./diff-view";
4
5
  export * from "./shortcut-sheet";
@@ -16,26 +16,32 @@ export type ShortcutSheetProps = {
16
16
  /** Asked for on Escape, the close button and a press on the scrim. */
17
17
  onClose: () => void;
18
18
  shortcuts: readonly ShortcutLine[];
19
- /** The dialog's title, "Keyboard shortcuts" by default. */
20
- title?: ReactNode;
21
19
  /** A note under the lists (where the keys do not act, say). */
22
20
  children?: ReactNode;
23
- /** Between two keys that do the same, "or" by default. */
24
- orLabel?: string;
25
- /** Shown when there are no shortcuts, "No shortcuts" by default. */
26
- emptyLabel?: ReactNode;
27
- /** The close button's name, "Close" by default. */
28
- closeLabel?: string;
29
21
  /** The platform keys are drawn for; the browser's by default. */
30
22
  platform?: Platform;
31
- /** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"). */
32
- keyNames?: Readonly<Record<string, string>>;
23
+ /** Words to replace; the rest keep their defaults. */
24
+ labels?: Partial<ShortcutSheetLabels>;
33
25
  /** A class added to the dialog's box. */
34
26
  className?: string;
35
27
  };
28
+ /** The sheet's own words, each replaceable. */
29
+ export interface ShortcutSheetLabels {
30
+ /** The dialog's title, which also names it: "Keyboard shortcuts". */
31
+ title: ReactNode;
32
+ /** Between two keys that do the same: "or". */
33
+ or: string;
34
+ /** Shown when there are no shortcuts: "No shortcuts". */
35
+ empty: ReactNode;
36
+ /** The close button's name: "Close". */
37
+ close: string;
38
+ /** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"); none by default, keyLabel's own. */
39
+ keyNames: Readonly<Record<string, string>>;
40
+ }
41
+ export declare const defaultShortcutSheetLabels: ShortcutSheetLabels;
36
42
  /** The lines in groups, the groups in the order they first appear and each group's lines in the order given. */
37
43
  export declare function groupShortcuts(shortcuts: readonly ShortcutLine[]): {
38
44
  group: string;
39
45
  lines: ShortcutLine[];
40
46
  }[];
41
- export declare function ShortcutSheet({ open, onClose, shortcuts, title, children, orLabel, emptyLabel, closeLabel, platform, keyNames, className, }: ShortcutSheetProps): import("react").JSX.Element;
47
+ export declare function ShortcutSheet({ open, onClose, shortcuts, children, platform, labels, className }: ShortcutSheetProps): import("react").JSX.Element;
@@ -1,2 +1,2 @@
1
- export { ShortcutSheet, groupShortcuts } from "./ShortcutSheet";
2
- export type { ShortcutLine, ShortcutSheetProps } from "./ShortcutSheet";
1
+ export { defaultShortcutSheetLabels, groupShortcuts, ShortcutSheet } from "./ShortcutSheet";
2
+ export type { ShortcutLine, ShortcutSheetLabels, ShortcutSheetProps } from "./ShortcutSheet";
@@ -26,13 +26,19 @@ export type ToasterProps = Omit<ComponentPropsWithRef<"section">, "children"> &
26
26
  * direction), or "inline": in the flow, where the app put it (in a canvas's own panel).
27
27
  */
28
28
  placement?: ToasterPlacement;
29
- /** The region's name, "Notifications" by default. */
30
- label?: string;
31
- /** The words on each Dismiss button, "Dismiss" by default. */
32
- dismissLabel?: string;
33
- /** The words for the folded toasts, "and n more" by default. */
34
- moreLabel?: (more: number) => ReactNode;
35
- /** What a screen reader reads for a count in place of "×n", "n times" by default. */
36
- countLabel?: (count: number) => string;
29
+ /** Words to replace; the rest keep their defaults. */
30
+ labels?: Partial<ToasterLabels>;
37
31
  };
38
- export declare function Toaster({ toasts, more, onDismiss, onHold, placement, label, dismissLabel, moreLabel, countLabel, className, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }: ToasterProps): import("react").JSX.Element;
32
+ /** The toaster's own words, each replaceable. */
33
+ export interface ToasterLabels {
34
+ /** The stack's region name: "Notifications". An `aria-label` the app gives wins. */
35
+ region: string;
36
+ /** The words on each Dismiss button: "Dismiss". */
37
+ dismiss: string;
38
+ /** The words for the folded toasts: "and n more". */
39
+ more: (more: number) => ReactNode;
40
+ /** What a screen reader reads for a count in place of "×n": "n times". */
41
+ count: (count: number) => string;
42
+ }
43
+ export declare const defaultToasterLabels: ToasterLabels;
44
+ export declare function Toaster({ toasts, more, onDismiss, onHold, placement, labels, className, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }: ToasterProps): import("react").JSX.Element;
@@ -1,2 +1,2 @@
1
- export { Toaster } from "./Toaster";
2
- export type { ToasterPlacement, ToasterProps, ToasterToast } from "./Toaster";
1
+ export { defaultToasterLabels, Toaster } from "./Toaster";
2
+ export type { ToasterLabels, ToasterPlacement, ToasterProps, ToasterToast } from "./Toaster";