@mcurcio/patchbay 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/composites.js +190 -158
- package/dist/composites.js.map +1 -1
- package/dist/graph.js +70 -67
- package/dist/graph.js.map +1 -1
- package/dist/primitives.css +1 -1
- package/dist/primitives.js +108 -93
- package/dist/primitives.js.map +1 -1
- package/dist/testing.js +207 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/composites/banner/Banner.d.ts +9 -3
- package/dist/types/composites/banner/index.d.ts +2 -2
- package/dist/types/composites/command-palette/CommandPalette.d.ts +16 -10
- package/dist/types/composites/command-palette/index.d.ts +2 -2
- package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +17 -11
- package/dist/types/composites/shortcut-sheet/index.d.ts +2 -2
- package/dist/types/composites/toaster/Toaster.d.ts +15 -9
- package/dist/types/composites/toaster/index.d.ts +2 -2
- package/dist/types/graph/meter/Meter.d.ts +9 -3
- package/dist/types/graph/meter/index.d.ts +2 -2
- package/dist/types/graph/node-box/NodeBox.d.ts +7 -8
- package/dist/types/graph/node-box/index.d.ts +2 -2
- package/dist/types/primitives/dialog/Dialog.d.ts +8 -2
- package/dist/types/primitives/dialog/index.d.ts +2 -2
- package/dist/types/primitives/sheet/Sheet.d.ts +8 -2
- package/dist/types/primitives/sheet/index.d.ts +2 -2
- package/dist/types/primitives/splitter/Splitter.d.ts +8 -2
- package/dist/types/primitives/splitter/splitter-math.d.ts +12 -4
- package/dist/types/testing/brand-css.d.ts +41 -0
- package/dist/types/testing/contrast.d.ts +36 -0
- package/dist/types/testing/index.d.ts +2 -0
- package/package.json +5 -1
package/dist/testing.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// src/tokens/tokens.css?raw
|
|
2
|
+
var e = (e) => e.trim().replace(/\s+/g, " ");
|
|
3
|
+
function t(e) {
|
|
4
|
+
return e.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
5
|
+
}
|
|
6
|
+
function 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,SAAgBC,EAAc,GAAsB;CAClD,OAAOD,EAAK,QAAQ,qBAAqB,EAAE;AAC7C;AAEA,SAASE,EAAa,GAAmC;CACvD,IAAMC,oBAAQ,IAAI,IAAoB;CACtC,KAAK,IAAMC,KAAeC,EAAK,MAAM,GAAG,GAAG;EACzC,IAAMC,IAAQF,EAAY,QAAQ,GAAG;EACrC,AAAIE,IAAQ,KACZH,EAAM,IAAIC,EAAY,MAAM,GAAGE,CAAK,CAAC,CAAC,KAAK,GAAGP,EAAOK,EAAY,MAAME,IAAQ,CAAC,CAAC,CAAC;CACpF;CACA,OAAOH;AACT;AAOA,SAAgBI,EAAU,GAAa,IAAuB,MAAkB;CAC9E,IAAMP,IAAOC,EAAcO,CAAG,GACxBL,IAAoB,CAAC,GACvBM,IAAK;CACT,OAAOA,IAAKT,EAAK,SAAQ;EACvB,IAAMU,IAAOV,EAAK,QAAQ,KAAKS,CAAE;EACjC,IAAIC,IAAO,GAAG;EACd,IAAIC,IAAQ,GACRC,IAAQF,IAAO;EACnB,OAAOE,IAAQZ,EAAK,UAAUW,IAAQ,GAAG,KAAS,GAChD,AAAIX,EAAKY,OAAW,MAAK,KAAS,IACzBZ,EAAKY,OAAW,OAAK;EAEhC,IAAMC,IAASb,EAAK,MAAMS,GAAIC,CAAI,GAC5BI,IAAUf,EAAOc,EAAO,MAAMA,EAAO,YAAY,GAAG,IAAI,CAAC,CAAC,GAC1DR,IAAOL,EAAK,MAAMU,IAAO,GAAGE,IAAQ,CAAC;EAG3C,AAFIE,EAAQ,WAAW,GAAG,IAAGX,EAAM,KA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RAAW,OAAO,GACnCmE,IAAMzC,EAAUhB,GAAK,qBAAqBwB,EAAM,GAAG,GACnDkC,IAA8B,CAAC;CACrC,KAAK,IAAMtC,KAAS;EAAC;EAAS;EAAQ;CAAa,GAAY;EAC7D,IAAMY,IAASd,EAAcK,GAAMkC,GAAKrC,CAAK;EAC7C,KAAK,IAAMuC,KAAQrB,GACjB,KAAK,IAAMsB,KAAMD,EAAK,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
|
-
/**
|
|
15
|
-
|
|
20
|
+
/** Words to replace; the rest keep their defaults. */
|
|
21
|
+
labels?: Partial<BannerLabels>;
|
|
16
22
|
};
|
|
17
|
-
export declare function Banner({ tone, children, actions, onDismiss,
|
|
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";
|
|
@@ -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
|
-
/**
|
|
45
|
-
|
|
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";
|
|
@@ -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
|
-
/**
|
|
32
|
-
|
|
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,
|
|
47
|
+
export declare function ShortcutSheet({ open, onClose, shortcuts, children, platform, labels, className }: ShortcutSheetProps): import("react").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
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
|
-
/**
|
|
30
|
-
|
|
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
|
-
|
|
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";
|
|
@@ -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).
|