@openartifactsai/ui 0.0.0-stage → 0.23.0-rc.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +82 -4
- package/src/button.d.ts +30 -0
- package/src/button.js +29 -0
- package/src/clicks.d.ts +63 -0
- package/src/clicks.js +75 -0
- package/src/cn.d.ts +3 -0
- package/src/cn.js +5 -0
- package/src/color-picker.d.ts +98 -0
- package/src/color-picker.js +395 -0
- package/src/color.d.ts +150 -0
- package/src/color.js +543 -0
- package/src/crash-boundary.d.ts +29 -0
- package/src/crash-boundary.js +32 -0
- package/src/data/google-fonts.json +1775 -0
- package/src/drag-cover.d.ts +48 -0
- package/src/drag-cover.js +41 -0
- package/src/effect-editors.d.ts +48 -0
- package/src/effect-editors.js +230 -0
- package/src/effects.d.ts +118 -0
- package/src/effects.js +425 -0
- package/src/escape-to-popup.d.ts +53 -0
- package/src/escape-to-popup.js +78 -0
- package/src/field-announce.d.ts +28 -0
- package/src/field-announce.js +43 -0
- package/src/fields.d.ts +176 -0
- package/src/fields.js +377 -0
- package/src/focusables.d.ts +50 -0
- package/src/focusables.js +61 -0
- package/src/font-picker.d.ts +62 -0
- package/src/font-picker.js +242 -0
- package/src/fonts.d.ts +121 -0
- package/src/fonts.js +273 -0
- package/src/history-diff.d.ts +64 -0
- package/src/history-diff.js +151 -0
- package/src/history.d.ts +95 -0
- package/src/history.js +160 -0
- package/src/index.d.ts +38 -0
- package/src/index.js +38 -0
- package/src/key-chord.d.ts +74 -0
- package/src/key-chord.js +228 -0
- package/src/keys.d.ts +142 -0
- package/src/keys.js +172 -0
- package/src/layout.d.ts +74 -0
- package/src/layout.js +173 -0
- package/src/link-card-view.d.ts +97 -0
- package/src/link-card-view.js +175 -0
- package/src/link-card.d.ts +136 -0
- package/src/link-card.js +158 -0
- package/src/menu-shortcuts.d.ts +31 -0
- package/src/menu-shortcuts.js +91 -0
- package/src/menu.d.ts +120 -0
- package/src/menu.js +100 -0
- package/src/number-entry.d.ts +140 -0
- package/src/number-entry.js +202 -0
- package/src/number-limits.d.ts +2 -0
- package/src/number-limits.js +2 -0
- package/src/number-wheel.d.ts +29 -0
- package/src/number-wheel.js +27 -0
- package/src/numbers.d.ts +28 -0
- package/src/numbers.js +124 -0
- package/src/overlays.d.ts +71 -0
- package/src/overlays.js +131 -0
- package/src/pressed.d.ts +5 -0
- package/src/pressed.js +10 -0
- package/src/scroll.d.ts +24 -0
- package/src/scroll.js +111 -0
- package/src/scrub-number-field.d.ts +79 -0
- package/src/scrub-number-field.js +254 -0
- package/src/select-announce.d.ts +50 -0
- package/src/select-announce.js +71 -0
- package/src/slider-session.d.ts +43 -0
- package/src/slider-session.js +39 -0
- package/src/styles.css +96 -0
- package/src/tab-strip-layout.d.ts +76 -0
- package/src/tab-strip-layout.js +111 -0
- package/src/tab-strip.d.ts +73 -0
- package/src/tab-strip.js +498 -0
- package/src/text-area-view.d.ts +35 -0
- package/src/text-area-view.js +142 -0
- package/src/text-area.d.ts +38 -0
- package/src/text-area.js +51 -0
- package/src/theme.css +34 -0
- package/src/toast-fit.d.ts +21 -0
- package/src/toast-fit.js +30 -0
- package/src/toast-tone.d.ts +27 -0
- package/src/toast-tone.js +22 -0
- package/src/tooltip.d.ts +23 -0
- package/src/tooltip.js +18 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* {@link ScrubNumberField}: a number field whose label is dragged sideways
|
|
4
|
+
* to change the value, the way design tools do it.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
7
|
+
import { cn } from "./cn.js";
|
|
8
|
+
import { isComposingKey, shortcutLetter } from "./keys.js";
|
|
9
|
+
import { announceFromField, prepareFieldAnnounce } from "./field-announce.js";
|
|
10
|
+
import { isMinusSign, leadsNumber, limitsKept, notANumberMessage, numberLimitMessage, refusesMinus, settleNumber, startsWithMinus } from "./number-entry.js";
|
|
11
|
+
import { clampNumber, evaluateNumberInput, formatNumber, roundTo, snapToStep, stepDecimals, stepStart } from "./numbers.js";
|
|
12
|
+
/**
|
|
13
|
+
* A number field with a drag-to-scrub label.
|
|
14
|
+
*
|
|
15
|
+
* - Drag the label sideways to scrub (Shift: large steps, Alt: small
|
|
16
|
+
* steps); values land on multiples of `step` unless Alt is held. Escape
|
|
17
|
+
* during a drag puts the value back; the end of a drag leaves the field
|
|
18
|
+
* focused with its text selected. Pressing the label commits any other
|
|
19
|
+
* field being typed in first.
|
|
20
|
+
* - Arrow Up/Down step (Shift ×10, Alt ÷10), Page Up/Down take large
|
|
21
|
+
* steps, Home/End go to `min`/`max`. An empty or mixed field steps
|
|
22
|
+
* from 0 (kept within `min`/`max`).
|
|
23
|
+
* - Typing accepts arithmetic (`12*2`, `100/3`) and a unit; Enter or blur
|
|
24
|
+
* commits, Escape reverts. ⌘S / Ctrl+S commits before the page saves.
|
|
25
|
+
* - When `min` is zero or more, a minus sign can't start the number: the
|
|
26
|
+
* key does nothing there, and typed text that starts with one keeps its
|
|
27
|
+
* number without it. The field says that, and typed values held at
|
|
28
|
+
* `min` or `max`, to screen readers, unless `onLimit` takes them over.
|
|
29
|
+
* - `mixed` shows "Mixed" until something is entered.
|
|
30
|
+
*/
|
|
31
|
+
export function ScrubNumberField({ value, mixed = false, onChange, onCommit, label, unit, units, min, max, step = 1, largeStep, smallStep, precision, pixelsPerStep = 2, placeholder, disabled, className, title, onLimit, strict = false, ...aria }) {
|
|
32
|
+
const big = largeStep ?? step * 10;
|
|
33
|
+
const small = smallStep ?? step / 10;
|
|
34
|
+
const decimals = precision ?? Math.max(stepDecimals(step), stepDecimals(small));
|
|
35
|
+
const shown = (v) => (v === null || mixed ? '' : formatNumber(v, decimals));
|
|
36
|
+
const [draft, setDraft] = useState(() => shown(value));
|
|
37
|
+
const [scrubbing, setScrubbing] = useState(false);
|
|
38
|
+
const editing = useRef(false);
|
|
39
|
+
const inputRef = useRef(null);
|
|
40
|
+
const inputId = useId();
|
|
41
|
+
/** The value at the start of a scrub, and the drag so far. */
|
|
42
|
+
const scrub = useRef(null);
|
|
43
|
+
// Follow outside changes unless the user is typing.
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!editing.current)
|
|
46
|
+
setDraft(shown(value));
|
|
47
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
+
}, [value, mixed, decimals]);
|
|
49
|
+
const fit = (v) => roundTo(clampNumber(v, min, max), decimals);
|
|
50
|
+
const bounds = { min, max };
|
|
51
|
+
const tell = (limits) => {
|
|
52
|
+
if (limits.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
if (onLimit)
|
|
55
|
+
return onLimit(limits);
|
|
56
|
+
if (inputRef.current)
|
|
57
|
+
announceFromField(inputRef.current, numberLimitMessage(limits, { name: aria['aria-label'], unit, format: (v) => formatNumber(v, decimals) }));
|
|
58
|
+
};
|
|
59
|
+
const commitText = () => {
|
|
60
|
+
const typedByUser = editing.current;
|
|
61
|
+
editing.current = false;
|
|
62
|
+
const text = draft.trim();
|
|
63
|
+
if (!text) {
|
|
64
|
+
setDraft(shown(value));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const typed = evaluateNumberInput(text);
|
|
68
|
+
const typedUnit = typed?.unit;
|
|
69
|
+
const allowed = typedUnit === undefined || typedUnit === unit?.toLowerCase() || units?.some((u) => u.toLowerCase() === typedUnit);
|
|
70
|
+
if (!typed || !allowed) {
|
|
71
|
+
setDraft(shown(value));
|
|
72
|
+
if (strict && typedByUser && inputRef.current)
|
|
73
|
+
announceFromField(inputRef.current, notANumberMessage(aria['aria-label'], unit ?? units?.[0]));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const settled = settleNumber(typed.value, typedByUser && startsWithMinus(text), bounds);
|
|
77
|
+
const next = fit(settled.value);
|
|
78
|
+
const otherUnit = typedUnit !== undefined && typedUnit !== unit?.toLowerCase() ? typedUnit : undefined;
|
|
79
|
+
setDraft(formatNumber(next, decimals));
|
|
80
|
+
if (next !== value || mixed || otherUnit)
|
|
81
|
+
onCommit(next, otherUnit);
|
|
82
|
+
if (typedByUser)
|
|
83
|
+
tell(limitsKept(settled.limits, next));
|
|
84
|
+
};
|
|
85
|
+
/** Puts `target` (fitted) in the field and commits it. */
|
|
86
|
+
const settleAt = (target) => {
|
|
87
|
+
const next = fit(target);
|
|
88
|
+
editing.current = false;
|
|
89
|
+
setDraft(formatNumber(next, decimals));
|
|
90
|
+
onChange?.(next);
|
|
91
|
+
onCommit(next);
|
|
92
|
+
};
|
|
93
|
+
/** Steps from the text being typed, else the value, else {@link stepStart}. */
|
|
94
|
+
const stepBy = (delta) => {
|
|
95
|
+
const typed = editing.current ? evaluateNumberInput(draft) : null;
|
|
96
|
+
if (typed === null) {
|
|
97
|
+
settleAt((mixed || value === null ? stepStart(min, max) : value) + delta);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// A step from typed text starts at its number, without a minus sign the field refuses.
|
|
101
|
+
const minusDropped = refusesMinus(bounds) && startsWithMinus(draft);
|
|
102
|
+
const from = minusDropped ? Math.abs(typed.value) : typed.value;
|
|
103
|
+
const next = fit(from + delta);
|
|
104
|
+
settleAt(next);
|
|
105
|
+
const held = settleNumber(from, false, bounds).limits;
|
|
106
|
+
tell([...(minusDropped ? [{ reason: 'no-minus', limit: min ?? 0 }] : []), ...limitsKept(held, next)]);
|
|
107
|
+
};
|
|
108
|
+
const onKeyDown = (event) => {
|
|
109
|
+
if (isComposingKey(event.nativeEvent))
|
|
110
|
+
return;
|
|
111
|
+
if ((event.metaKey || event.ctrlKey) && !event.altKey && shortcutLetter(event) === 's') {
|
|
112
|
+
// Commit what is typed, then let the key go on to the page's save.
|
|
113
|
+
const field = event.currentTarget;
|
|
114
|
+
field.blur();
|
|
115
|
+
field.focus({ preventScroll: true });
|
|
116
|
+
field.select();
|
|
117
|
+
queueMicrotask(() => field.select());
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (refusesMinus(bounds) && isMinusSign(event.key) && !event.ctrlKey && !event.metaKey && leadsNumber(event.currentTarget.value, event.currentTarget.selectionStart ?? 0)) {
|
|
121
|
+
// Only a leading minus is refused: "10-4" still subtracts.
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
if (!event.repeat)
|
|
124
|
+
tell([{ reason: 'no-minus', limit: min ?? 0 }]);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const unitStep = event.shiftKey ? big : event.altKey ? small : step;
|
|
128
|
+
switch (event.key) {
|
|
129
|
+
case 'ArrowUp':
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
stepBy(unitStep);
|
|
132
|
+
break;
|
|
133
|
+
case 'ArrowDown':
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
stepBy(-unitStep);
|
|
136
|
+
break;
|
|
137
|
+
case 'PageUp':
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
stepBy(big);
|
|
140
|
+
break;
|
|
141
|
+
case 'PageDown':
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
stepBy(-big);
|
|
144
|
+
break;
|
|
145
|
+
case 'Home':
|
|
146
|
+
if (min !== undefined && !event.shiftKey) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
settleAt(min);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case 'End':
|
|
152
|
+
if (max !== undefined && !event.shiftKey) {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
settleAt(max);
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case 'Enter':
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
commitText();
|
|
160
|
+
event.currentTarget.select();
|
|
161
|
+
break;
|
|
162
|
+
case 'Escape':
|
|
163
|
+
if (editing.current) {
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
event.stopPropagation();
|
|
166
|
+
editing.current = false;
|
|
167
|
+
setDraft(shown(value));
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/* --------------------------------- scrub -------------------------------- */
|
|
173
|
+
const endScrub = (target, commit) => {
|
|
174
|
+
const state = scrub.current;
|
|
175
|
+
if (!state)
|
|
176
|
+
return;
|
|
177
|
+
scrub.current = null;
|
|
178
|
+
setScrubbing(false);
|
|
179
|
+
if (target.hasPointerCapture(state.pointerId))
|
|
180
|
+
target.releasePointerCapture(state.pointerId);
|
|
181
|
+
if (!commit) {
|
|
182
|
+
setDraft(shown(value));
|
|
183
|
+
if (state.current !== state.start)
|
|
184
|
+
onChange?.(state.start);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// A click on the label, or the end of a drag, leaves the field focused and selected.
|
|
188
|
+
inputRef.current?.focus();
|
|
189
|
+
inputRef.current?.select();
|
|
190
|
+
if (state.travel < pixelsPerStep)
|
|
191
|
+
return;
|
|
192
|
+
if (state.current !== state.start || mixed)
|
|
193
|
+
onCommit(state.current);
|
|
194
|
+
};
|
|
195
|
+
const onPointerDown = (event) => {
|
|
196
|
+
if (disabled || event.button !== 0)
|
|
197
|
+
return;
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
// A field typed into elsewhere commits before the scrub writes its own value.
|
|
200
|
+
const typing = document.activeElement;
|
|
201
|
+
if (typing instanceof HTMLElement && typing !== inputRef.current && (typing.matches('input, textarea') || typing.isContentEditable))
|
|
202
|
+
typing.blur();
|
|
203
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
204
|
+
const start = mixed || value === null ? stepStart(min, max) : value;
|
|
205
|
+
scrub.current = { start, current: start, travel: 0, carry: 0, pointerId: event.pointerId };
|
|
206
|
+
};
|
|
207
|
+
const onPointerMove = (event) => {
|
|
208
|
+
const state = scrub.current;
|
|
209
|
+
if (!state || event.pointerId !== state.pointerId)
|
|
210
|
+
return;
|
|
211
|
+
state.travel += Math.abs(event.movementX);
|
|
212
|
+
// Movement below a step carries over, so slow drags still move.
|
|
213
|
+
state.carry += event.movementX;
|
|
214
|
+
if (state.travel < pixelsPerStep)
|
|
215
|
+
return;
|
|
216
|
+
if (!scrubbing)
|
|
217
|
+
setScrubbing(true);
|
|
218
|
+
const steps = Math.trunc(state.carry / pixelsPerStep);
|
|
219
|
+
if (steps === 0)
|
|
220
|
+
return;
|
|
221
|
+
state.carry -= steps * pixelsPerStep;
|
|
222
|
+
const unitStep = event.shiftKey ? big : event.altKey ? small : step;
|
|
223
|
+
const moved = state.current + steps * unitStep;
|
|
224
|
+
const next = fit(event.altKey ? moved : snapToStep(moved, step));
|
|
225
|
+
if (next === state.current)
|
|
226
|
+
return;
|
|
227
|
+
state.current = next;
|
|
228
|
+
setDraft(formatNumber(next, decimals));
|
|
229
|
+
onChange?.(next);
|
|
230
|
+
};
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (!scrubbing)
|
|
233
|
+
return;
|
|
234
|
+
const onKey = (event) => {
|
|
235
|
+
if (event.key !== 'Escape' || !scrub.current)
|
|
236
|
+
return;
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
const handle = document.querySelector(`[data-scrub-for="${CSS.escape(inputId)}"]`);
|
|
239
|
+
if (handle)
|
|
240
|
+
endScrub(handle, false);
|
|
241
|
+
};
|
|
242
|
+
window.addEventListener('keydown', onKey, true);
|
|
243
|
+
return () => window.removeEventListener('keydown', onKey, true);
|
|
244
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
245
|
+
}, [scrubbing]);
|
|
246
|
+
const numeric = value !== null && !mixed ? roundTo(value, decimals) : undefined;
|
|
247
|
+
return (_jsxs("div", { "data-ui-field": "", className: cn('flex h-7 min-w-0 items-center rounded-control border border-line bg-surface-2 text-[13px] text-fg focus-within:border-accent focus-within:bg-surface', disabled && 'opacity-50', scrubbing && 'border-accent', className), children: [label !== undefined ? (_jsx("span", { "aria-hidden": "true", "data-scrub-for": inputId, title: title ?? 'Drag to change', onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: (event) => endScrub(event.currentTarget, true), onPointerCancel: (event) => endScrub(event.currentTarget, false), onLostPointerCapture: (event) => scrub.current && endScrub(event.currentTarget, true), className: cn('flex h-full min-w-6 shrink-0 select-none items-center justify-center px-1 text-[11px] text-fg-subtle touch-none', disabled ? 'cursor-default' : 'cursor-ew-resize hover:text-fg'), children: label })) : null, _jsx("input", { ref: inputRef, id: inputId, role: "spinbutton", inputMode: "decimal", autoComplete: "off", spellCheck: false, "aria-label": aria['aria-label'], "aria-valuenow": numeric, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext": mixed ? 'Mixed' : numeric !== undefined ? `${formatNumber(numeric, decimals)}${unit ?? ''}` : undefined, disabled: disabled, value: draft, placeholder: mixed ? 'Mixed' : placeholder, onFocus: (event) => {
|
|
248
|
+
event.currentTarget.select();
|
|
249
|
+
prepareFieldAnnounce(event.currentTarget);
|
|
250
|
+
}, onChange: (event) => {
|
|
251
|
+
editing.current = true;
|
|
252
|
+
setDraft(event.target.value);
|
|
253
|
+
}, onBlur: commitText, onKeyDown: onKeyDown, className: cn('h-full w-full min-w-0 bg-transparent tabular-nums outline-none placeholder:text-fg-subtle', label === undefined && 'pl-2', !unit && 'pr-2') }), unit ? _jsx("span", { className: "shrink-0 pr-2 text-[11px] text-fg-subtle", children: unit }) : null] }));
|
|
254
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Says a select's new value while its trigger has the focus: a quiet
|
|
3
|
+
* (`polite`) live region made when the trigger is focused, in the nearest
|
|
4
|
+
* dialog or else the page body, in the page's language. A new value is
|
|
5
|
+
* written into it when it changes under the focus, or when the focus comes
|
|
6
|
+
* back to the trigger after a pick from the list. It goes when the trigger
|
|
7
|
+
* loses the focus; when the trigger is disabled as it loses it, at the next
|
|
8
|
+
* focus anywhere, so the last word is still read.
|
|
9
|
+
*/
|
|
10
|
+
/** The parts of the live region the announcer makes and fills. */
|
|
11
|
+
export interface AnnounceRegion {
|
|
12
|
+
setAttribute(name: string, value: string): void;
|
|
13
|
+
remove(): void;
|
|
14
|
+
textContent: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** Where the region goes: a dialog or the page body. */
|
|
17
|
+
export interface AnnounceHost<R extends AnnounceRegion> {
|
|
18
|
+
appendChild(node: R): unknown;
|
|
19
|
+
}
|
|
20
|
+
/** The parts of a document the announcer uses; it makes regions of type `R`. */
|
|
21
|
+
export interface AnnounceDocument<R extends AnnounceRegion> {
|
|
22
|
+
createElement(tag: 'span'): R;
|
|
23
|
+
body: AnnounceHost<R> | null;
|
|
24
|
+
documentElement: {
|
|
25
|
+
lang: string;
|
|
26
|
+
};
|
|
27
|
+
addEventListener(type: 'focusin', listener: () => void, options: {
|
|
28
|
+
once: true;
|
|
29
|
+
capture: true;
|
|
30
|
+
}): void;
|
|
31
|
+
}
|
|
32
|
+
/** The parts of a select trigger the announcer uses (an `HTMLElement` has them, with `HTMLSpanElement` regions). */
|
|
33
|
+
export interface AnnounceTrigger<R extends AnnounceRegion> {
|
|
34
|
+
ownerDocument: AnnounceDocument<R>;
|
|
35
|
+
closest(selector: string): AnnounceHost<R> | null;
|
|
36
|
+
matches(selector: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Visually hidden, still read (inline, so no style sheet has to carry it). */
|
|
39
|
+
export declare const VISUALLY_HIDDEN = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap";
|
|
40
|
+
export interface SelectAnnouncer<R extends AnnounceRegion> {
|
|
41
|
+
/** The trigger got the focus, showing `label`. */
|
|
42
|
+
focus(trigger: AnnounceTrigger<R>, label: string): void;
|
|
43
|
+
/** The value now shows `label`; said when the trigger has the focus. */
|
|
44
|
+
change(label: string): void;
|
|
45
|
+
/** The trigger lost the focus. */
|
|
46
|
+
blur(trigger: AnnounceTrigger<R>): void;
|
|
47
|
+
/** The select went away. */
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
export declare function createSelectAnnouncer<R extends AnnounceRegion>(): SelectAnnouncer<R>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Says a select's new value while its trigger has the focus: a quiet
|
|
3
|
+
* (`polite`) live region made when the trigger is focused, in the nearest
|
|
4
|
+
* dialog or else the page body, in the page's language. A new value is
|
|
5
|
+
* written into it when it changes under the focus, or when the focus comes
|
|
6
|
+
* back to the trigger after a pick from the list. It goes when the trigger
|
|
7
|
+
* loses the focus; when the trigger is disabled as it loses it, at the next
|
|
8
|
+
* focus anywhere, so the last word is still read.
|
|
9
|
+
*/
|
|
10
|
+
/** Visually hidden, still read (inline, so no style sheet has to carry it). */
|
|
11
|
+
export const VISUALLY_HIDDEN = 'position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap';
|
|
12
|
+
export function createSelectAnnouncer() {
|
|
13
|
+
let region = null;
|
|
14
|
+
let focused = false;
|
|
15
|
+
/** The label shown when the trigger last lost the focus. */
|
|
16
|
+
let left = null;
|
|
17
|
+
let shown = null;
|
|
18
|
+
const say = (label) => {
|
|
19
|
+
if (region)
|
|
20
|
+
region.textContent = label;
|
|
21
|
+
};
|
|
22
|
+
const drop = () => {
|
|
23
|
+
region?.remove();
|
|
24
|
+
region = null;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
focus(trigger, label) {
|
|
28
|
+
focused = true;
|
|
29
|
+
shown = label;
|
|
30
|
+
if (!region) {
|
|
31
|
+
const doc = trigger.ownerDocument;
|
|
32
|
+
region = doc.createElement('span');
|
|
33
|
+
region.setAttribute('aria-live', 'polite');
|
|
34
|
+
region.setAttribute('aria-atomic', 'true');
|
|
35
|
+
region.setAttribute('style', VISUALLY_HIDDEN);
|
|
36
|
+
if (doc.documentElement.lang)
|
|
37
|
+
region.setAttribute('lang', doc.documentElement.lang);
|
|
38
|
+
const host = trigger.closest('[role="dialog"], [role="alertdialog"]') ?? doc.body;
|
|
39
|
+
host?.appendChild(region);
|
|
40
|
+
}
|
|
41
|
+
// Back from a pick in the list: say what was picked.
|
|
42
|
+
if (left !== null && left !== label)
|
|
43
|
+
say(label);
|
|
44
|
+
left = null;
|
|
45
|
+
},
|
|
46
|
+
change(label) {
|
|
47
|
+
if (label === shown)
|
|
48
|
+
return;
|
|
49
|
+
shown = label;
|
|
50
|
+
if (focused)
|
|
51
|
+
say(label);
|
|
52
|
+
},
|
|
53
|
+
blur(trigger) {
|
|
54
|
+
focused = false;
|
|
55
|
+
left = shown;
|
|
56
|
+
if (trigger.matches('[disabled], [data-disabled]')) {
|
|
57
|
+
const current = region;
|
|
58
|
+
trigger.ownerDocument.addEventListener('focusin', () => {
|
|
59
|
+
if (region === current && !focused)
|
|
60
|
+
drop();
|
|
61
|
+
}, { once: true, capture: true });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
drop();
|
|
65
|
+
},
|
|
66
|
+
dispose() {
|
|
67
|
+
focused = false;
|
|
68
|
+
drop();
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of {@link SliderInput}'s drag and reading that need no DOM:
|
|
3
|
+
* which event ends a drag, which press is a context click, the PageUp /
|
|
4
|
+
* PageDown step, and the text a screen reader hears for the value.
|
|
5
|
+
*/
|
|
6
|
+
/** PageUp / PageDown (and Shift with an arrow) move ten steps. */
|
|
7
|
+
export declare function largeStepOf(step: number): number;
|
|
8
|
+
/** The events that can end a drag; the window hears them all. */
|
|
9
|
+
export declare const DRAG_ENDS: readonly ["pointerup", "pointercancel", "touchend", "touchcancel", "blur"];
|
|
10
|
+
/** What {@link endsDrag} reads of an event. */
|
|
11
|
+
export interface DragEndEvent {
|
|
12
|
+
type: string;
|
|
13
|
+
pointerId?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether `event` ends the drag the pointer `pointerId` started: a pointer
|
|
17
|
+
* release or cancel only of that pointer, a touch end or cancel and the
|
|
18
|
+
* window losing focus always.
|
|
19
|
+
*/
|
|
20
|
+
export declare function endsDrag(event: DragEndEvent, pointerId: number | null): boolean;
|
|
21
|
+
/** What {@link isContextClick} reads of a press. */
|
|
22
|
+
export interface SliderPress {
|
|
23
|
+
button: number;
|
|
24
|
+
ctrlKey: boolean;
|
|
25
|
+
pointerType: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether a press asks for the context menu instead of moving the slider:
|
|
29
|
+
* on an Apple platform, the main button with Control held, from a mouse, or
|
|
30
|
+
* from a pen on a screen without touch (where the pen works as a mouse).
|
|
31
|
+
*/
|
|
32
|
+
export declare function isContextClick(press: SliderPress, apple: boolean, maxTouchPoints: number): boolean;
|
|
33
|
+
/** How the slider's value reads out. */
|
|
34
|
+
export interface SliderReading {
|
|
35
|
+
/** The selection holds different values: it reads "Mixed". */
|
|
36
|
+
mixed?: boolean;
|
|
37
|
+
/** "%": the value is a percentage, read in the language's percent format. */
|
|
38
|
+
unit?: string;
|
|
39
|
+
/** The language to read numbers in; the page's when not given. */
|
|
40
|
+
locale?: string;
|
|
41
|
+
}
|
|
42
|
+
/** The text a screen reader hears for `value`, or null to let the slider read the number itself. */
|
|
43
|
+
export declare function sliderValueText(value: number, { mixed, unit, locale }?: SliderReading): string | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of {@link SliderInput}'s drag and reading that need no DOM:
|
|
3
|
+
* which event ends a drag, which press is a context click, the PageUp /
|
|
4
|
+
* PageDown step, and the text a screen reader hears for the value.
|
|
5
|
+
*/
|
|
6
|
+
/** PageUp / PageDown (and Shift with an arrow) move ten steps. */
|
|
7
|
+
export function largeStepOf(step) {
|
|
8
|
+
return step * 10;
|
|
9
|
+
}
|
|
10
|
+
/** The events that can end a drag; the window hears them all. */
|
|
11
|
+
export const DRAG_ENDS = ['pointerup', 'pointercancel', 'touchend', 'touchcancel', 'blur'];
|
|
12
|
+
/**
|
|
13
|
+
* Whether `event` ends the drag the pointer `pointerId` started: a pointer
|
|
14
|
+
* release or cancel only of that pointer, a touch end or cancel and the
|
|
15
|
+
* window losing focus always.
|
|
16
|
+
*/
|
|
17
|
+
export function endsDrag(event, pointerId) {
|
|
18
|
+
if (event.type === 'pointerup' || event.type === 'pointercancel')
|
|
19
|
+
return pointerId === null || event.pointerId === undefined || event.pointerId === pointerId;
|
|
20
|
+
return DRAG_ENDS.includes(event.type);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a press asks for the context menu instead of moving the slider:
|
|
24
|
+
* on an Apple platform, the main button with Control held, from a mouse, or
|
|
25
|
+
* from a pen on a screen without touch (where the pen works as a mouse).
|
|
26
|
+
*/
|
|
27
|
+
export function isContextClick(press, apple, maxTouchPoints) {
|
|
28
|
+
if (!apple || press.button !== 0 || !press.ctrlKey)
|
|
29
|
+
return false;
|
|
30
|
+
return press.pointerType === 'mouse' || (press.pointerType === 'pen' && maxTouchPoints === 0);
|
|
31
|
+
}
|
|
32
|
+
/** The text a screen reader hears for `value`, or null to let the slider read the number itself. */
|
|
33
|
+
export function sliderValueText(value, { mixed, unit, locale } = {}) {
|
|
34
|
+
if (mixed)
|
|
35
|
+
return 'Mixed';
|
|
36
|
+
if (unit === '%')
|
|
37
|
+
return new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 2 }).format(value / 100);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Open Artifacts UI theme.
|
|
3
|
+
*
|
|
4
|
+
* Tailwind CSS v4 with a small set of semantic color tokens. Components use
|
|
5
|
+
* the semantic names (`bg-surface`, `text-fg-muted`, `border-line`…) only,
|
|
6
|
+
* so light and dark themes are just two sets of variable values.
|
|
7
|
+
*
|
|
8
|
+
* Apps import this file once: `@import "@openartifactsai/ui/styles.css";`.
|
|
9
|
+
*/
|
|
10
|
+
@import "tailwindcss";
|
|
11
|
+
@import "./theme.css";
|
|
12
|
+
|
|
13
|
+
/* Scan the UI kit's own components for class names. */
|
|
14
|
+
@source "./";
|
|
15
|
+
|
|
16
|
+
/* Light theme (default). */
|
|
17
|
+
:root {
|
|
18
|
+
color-scheme: light;
|
|
19
|
+
--open-artifacts-canvas: #f2f2f0;
|
|
20
|
+
--open-artifacts-surface: #ffffff;
|
|
21
|
+
--open-artifacts-surface-2: #f7f7f5;
|
|
22
|
+
--open-artifacts-hover: rgb(0 0 0 / 0.05);
|
|
23
|
+
--open-artifacts-line: rgb(0 0 0 / 0.1);
|
|
24
|
+
--open-artifacts-line-strong: rgb(0 0 0 / 0.2);
|
|
25
|
+
--open-artifacts-fg: #1c1c1a;
|
|
26
|
+
--open-artifacts-fg-muted: #5c5c57;
|
|
27
|
+
--open-artifacts-fg-subtle: #8a8a84;
|
|
28
|
+
--open-artifacts-accent: #2563eb;
|
|
29
|
+
--open-artifacts-accent-fg: #ffffff;
|
|
30
|
+
--open-artifacts-accent-soft: rgb(37 99 235 / 0.12);
|
|
31
|
+
--open-artifacts-danger: #c2410c;
|
|
32
|
+
--open-artifacts-warning: #b45309;
|
|
33
|
+
--open-artifacts-success: #15803d;
|
|
34
|
+
--open-artifacts-select: #2563eb;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Dark theme: follows the system unless a page pins `data-theme`. */
|
|
38
|
+
@media (prefers-color-scheme: dark) {
|
|
39
|
+
:root:not([data-theme="light"]) {
|
|
40
|
+
color-scheme: dark;
|
|
41
|
+
--open-artifacts-canvas: #1a1a19;
|
|
42
|
+
--open-artifacts-surface: #242423;
|
|
43
|
+
--open-artifacts-surface-2: #2c2c2a;
|
|
44
|
+
--open-artifacts-hover: rgb(255 255 255 / 0.07);
|
|
45
|
+
--open-artifacts-line: rgb(255 255 255 / 0.1);
|
|
46
|
+
--open-artifacts-line-strong: rgb(255 255 255 / 0.2);
|
|
47
|
+
--open-artifacts-fg: #ededeb;
|
|
48
|
+
--open-artifacts-fg-muted: #a8a8a3;
|
|
49
|
+
--open-artifacts-fg-subtle: #7c7c77;
|
|
50
|
+
--open-artifacts-accent: #60a5fa;
|
|
51
|
+
--open-artifacts-accent-fg: #0b1220;
|
|
52
|
+
--open-artifacts-accent-soft: rgb(96 165 250 / 0.16);
|
|
53
|
+
--open-artifacts-danger: #fb923c;
|
|
54
|
+
--open-artifacts-warning: #fbbf24;
|
|
55
|
+
--open-artifacts-success: #4ade80;
|
|
56
|
+
--open-artifacts-select: #60a5fa;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
:root[data-theme="dark"] {
|
|
60
|
+
color-scheme: dark;
|
|
61
|
+
--open-artifacts-canvas: #1a1a19;
|
|
62
|
+
--open-artifacts-surface: #242423;
|
|
63
|
+
--open-artifacts-surface-2: #2c2c2a;
|
|
64
|
+
--open-artifacts-hover: rgb(255 255 255 / 0.07);
|
|
65
|
+
--open-artifacts-line: rgb(255 255 255 / 0.1);
|
|
66
|
+
--open-artifacts-line-strong: rgb(255 255 255 / 0.2);
|
|
67
|
+
--open-artifacts-fg: #ededeb;
|
|
68
|
+
--open-artifacts-fg-muted: #a8a8a3;
|
|
69
|
+
--open-artifacts-fg-subtle: #7c7c77;
|
|
70
|
+
--open-artifacts-accent: #60a5fa;
|
|
71
|
+
--open-artifacts-accent-fg: #0b1220;
|
|
72
|
+
--open-artifacts-accent-soft: rgb(96 165 250 / 0.16);
|
|
73
|
+
--open-artifacts-danger: #fb923c;
|
|
74
|
+
--open-artifacts-warning: #fbbf24;
|
|
75
|
+
--open-artifacts-success: #4ade80;
|
|
76
|
+
--open-artifacts-select: #60a5fa;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@layer base {
|
|
80
|
+
html,
|
|
81
|
+
body,
|
|
82
|
+
#root {
|
|
83
|
+
height: 100%;
|
|
84
|
+
}
|
|
85
|
+
body {
|
|
86
|
+
margin: 0;
|
|
87
|
+
background: var(--open-artifacts-canvas);
|
|
88
|
+
color: var(--open-artifacts-fg);
|
|
89
|
+
font-family: var(--font-sans);
|
|
90
|
+
font-size: 13px;
|
|
91
|
+
-webkit-font-smoothing: antialiased;
|
|
92
|
+
}
|
|
93
|
+
button {
|
|
94
|
+
cursor: default;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of {@link TabStrip} (`tab-strip.tsx`), apart from the page so it can be tested on its own: which tabs
|
|
3
|
+
* fit in the row and what room the ones whose title is cut are given, where a dragged tab is drawn and lands, where a tab picked from
|
|
4
|
+
* the list of those that do not fit goes, and what each Close item of a tab's menu closes.
|
|
5
|
+
*/
|
|
6
|
+
/** What {@link fitTabs} measures, one entry per tab in the order shown. */
|
|
7
|
+
export interface FitInput {
|
|
8
|
+
ids: readonly string[];
|
|
9
|
+
/** Stays first and is never put in the list. */
|
|
10
|
+
fixed: readonly boolean[];
|
|
11
|
+
/** Each tab's width on its own (the room it was given taken off). */
|
|
12
|
+
widths: readonly number[];
|
|
13
|
+
/** What each tab's title needs on top of that to be whole. */
|
|
14
|
+
needs: readonly number[];
|
|
15
|
+
/** The space between two tabs. */
|
|
16
|
+
gap: number;
|
|
17
|
+
/** The room for the tabs (the row's width less + and the space before it). */
|
|
18
|
+
avail: number;
|
|
19
|
+
/** ▾'s width with the space before it: taken off the room once some tabs do not fit. */
|
|
20
|
+
more: number;
|
|
21
|
+
/** The tab in front: kept in sight. */
|
|
22
|
+
activeId: string;
|
|
23
|
+
/** The first tab shown (of those not fixed) the last time: kept while the tab in front stays in sight. */
|
|
24
|
+
start: number;
|
|
25
|
+
}
|
|
26
|
+
export interface Fit {
|
|
27
|
+
/** Tabs that do not fit: out of the row, in the list. */
|
|
28
|
+
hidden: Set<string>;
|
|
29
|
+
/** Room given to a tab whose title is cut, out of what the row has left over. */
|
|
30
|
+
stretch: Map<string, number>;
|
|
31
|
+
/** Tabs whose title is still cut: it fades out at its end. */
|
|
32
|
+
clipped: Set<string>;
|
|
33
|
+
/** The first tab shown, of those not fixed. */
|
|
34
|
+
start: number;
|
|
35
|
+
}
|
|
36
|
+
/** Which tabs fit in the row. */
|
|
37
|
+
export declare function fitTabs(input: FitInput): Fit;
|
|
38
|
+
/** Whether two fits show the same thing. */
|
|
39
|
+
export declare const sameFit: (a: Fit, b: Fit) => boolean;
|
|
40
|
+
/** The order with `id` moved to `to`. */
|
|
41
|
+
export declare function moveTo(order: readonly string[], id: string, to: number): string[];
|
|
42
|
+
/** Where the dragged tab is, for {@link dragLeft} and {@link dragOrder}; all in the row's own coordinates. */
|
|
43
|
+
export interface DragBox {
|
|
44
|
+
/** Its left edge where the pointer puts it, before the row holds it. */
|
|
45
|
+
left: number;
|
|
46
|
+
width: number;
|
|
47
|
+
/** The left edge of the place it is laid out in. */
|
|
48
|
+
slot: number;
|
|
49
|
+
/** The row's edges. */
|
|
50
|
+
rowLeft: number;
|
|
51
|
+
rowRight: number;
|
|
52
|
+
/** Where the fixed tabs end (-Infinity when there are none): the dragged tab goes no further left. */
|
|
53
|
+
fixedEnd: number;
|
|
54
|
+
}
|
|
55
|
+
/** Room left between the dragged tab and the row's ends. */
|
|
56
|
+
export declare const DRAG_EDGE_PX = 4;
|
|
57
|
+
/** Where the dragged tab is drawn: under the pointer, held inside the row and right of the fixed tabs. */
|
|
58
|
+
export declare function dragLeft(drag: DragBox): number;
|
|
59
|
+
/**
|
|
60
|
+
* The order while a tab is dragged. It goes after every other tab of the row it has passed: one whose middle its own
|
|
61
|
+
* middle (held inside the row) has passed, or, when it covers the other tab whole, one laid out after its place. Held
|
|
62
|
+
* against the fixed tabs, it goes first. `row` is the tabs shown that can move, in order; `boxOf` says where another
|
|
63
|
+
* tab is laid out.
|
|
64
|
+
*/
|
|
65
|
+
export declare function dragOrder(order: readonly string[], row: readonly string[], id: string, drag: DragBox, boxOf: (id: string) => {
|
|
66
|
+
left: number;
|
|
67
|
+
width: number;
|
|
68
|
+
} | undefined): string[];
|
|
69
|
+
/** Where a tab picked from the list goes: next to the last tab shown. Null when it stays where it is. */
|
|
70
|
+
export declare function pickedPlace(order: readonly string[], id: string, lastShown: string | undefined): number | null;
|
|
71
|
+
/** What the Close items of a tab's menu close: the others, the ones to its right, all (closable ones only). */
|
|
72
|
+
export declare function closeGroups(order: readonly string[], closable: (id: string) => boolean, id: string): {
|
|
73
|
+
others: string[];
|
|
74
|
+
right: string[];
|
|
75
|
+
all: string[];
|
|
76
|
+
};
|