@ac-kit/ui-common 0.2.0 → 0.3.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/CHANGELOG.md +55 -0
- package/README.md +59 -3
- package/dist/adapter/_anchor.d.ts.map +1 -0
- package/dist/adapter/_anchor.js.map +1 -0
- package/dist/adapter/_dom.d.ts.map +1 -0
- package/dist/adapter/_dom.js.map +1 -0
- package/dist/{preact → adapter}/_live-announcer.d.ts +1 -1
- package/dist/adapter/_live-announcer.d.ts.map +1 -0
- package/dist/{preact → adapter}/_live-announcer.js +1 -1
- package/dist/adapter/_live-announcer.js.map +1 -0
- package/dist/adapter/join-classes.d.ts.map +1 -0
- package/dist/adapter/join-classes.js.map +1 -0
- package/dist/bit-grid/bit-grid.d.ts +151 -0
- package/dist/bit-grid/bit-grid.d.ts.map +1 -0
- package/dist/bit-grid/bit-grid.js +201 -0
- package/dist/bit-grid/bit-grid.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/preact/bit-grid.d.ts +39 -0
- package/dist/preact/bit-grid.d.ts.map +1 -0
- package/dist/preact/bit-grid.js +72 -0
- package/dist/preact/bit-grid.js.map +1 -0
- package/dist/preact/button.d.ts.map +1 -1
- package/dist/preact/button.js +1 -1
- package/dist/preact/button.js.map +1 -1
- package/dist/preact/dialog.d.ts.map +1 -1
- package/dist/preact/dialog.js +1 -1
- package/dist/preact/dialog.js.map +1 -1
- package/dist/preact/index.d.ts +3 -1
- package/dist/preact/index.d.ts.map +1 -1
- package/dist/preact/index.js +3 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/knob.d.ts.map +1 -1
- package/dist/preact/knob.js +1 -1
- package/dist/preact/knob.js.map +1 -1
- package/dist/preact/menu-button.d.ts.map +1 -1
- package/dist/preact/menu-button.js +3 -3
- package/dist/preact/menu-button.js.map +1 -1
- package/dist/preact/meter.d.ts.map +1 -1
- package/dist/preact/meter.js +1 -1
- package/dist/preact/meter.js.map +1 -1
- package/dist/preact/progress-ring.d.ts.map +1 -1
- package/dist/preact/progress-ring.js +1 -1
- package/dist/preact/progress-ring.js.map +1 -1
- package/dist/preact/radio-group.d.ts.map +1 -1
- package/dist/preact/radio-group.js +1 -1
- package/dist/preact/radio-group.js.map +1 -1
- package/dist/preact/readout.d.ts.map +1 -1
- package/dist/preact/readout.js +1 -1
- package/dist/preact/readout.js.map +1 -1
- package/dist/preact/slider.d.ts.map +1 -1
- package/dist/preact/slider.js +1 -1
- package/dist/preact/slider.js.map +1 -1
- package/dist/preact/spin-button.d.ts.map +1 -1
- package/dist/preact/spin-button.js +2 -2
- package/dist/preact/spin-button.js.map +1 -1
- package/dist/preact/swatch-strip.d.ts +30 -0
- package/dist/preact/swatch-strip.d.ts.map +1 -0
- package/dist/preact/swatch-strip.js +17 -0
- package/dist/preact/swatch-strip.js.map +1 -0
- package/dist/preact/switch.js +1 -1
- package/dist/preact/switch.js.map +1 -1
- package/dist/preact/tabs.d.ts.map +1 -1
- package/dist/preact/tabs.js +2 -2
- package/dist/preact/tabs.js.map +1 -1
- package/dist/preact/toaster.d.ts.map +1 -1
- package/dist/preact/toaster.js +2 -2
- package/dist/preact/toaster.js.map +1 -1
- package/dist/preact/toggle-button.d.ts.map +1 -1
- package/dist/preact/toggle-button.js +1 -1
- package/dist/preact/toggle-button.js.map +1 -1
- package/dist/preact/toolbar.d.ts.map +1 -1
- package/dist/preact/toolbar.js +2 -2
- package/dist/preact/toolbar.js.map +1 -1
- package/dist/preact/tooltip.d.ts.map +1 -1
- package/dist/preact/tooltip.js +2 -2
- package/dist/preact/tooltip.js.map +1 -1
- package/dist/preact/tree.d.ts.map +1 -1
- package/dist/preact/tree.js +2 -2
- package/dist/preact/tree.js.map +1 -1
- package/dist/react/_props.d.ts +22 -0
- package/dist/react/_props.d.ts.map +1 -0
- package/dist/react/_props.js +14 -0
- package/dist/react/_props.js.map +1 -0
- package/dist/react/bit-grid.d.ts +40 -0
- package/dist/react/bit-grid.d.ts.map +1 -0
- package/dist/react/bit-grid.js +71 -0
- package/dist/react/bit-grid.js.map +1 -0
- package/dist/react/button.d.ts +60 -0
- package/dist/react/button.d.ts.map +1 -0
- package/dist/react/button.js +34 -0
- package/dist/react/button.js.map +1 -0
- package/dist/react/dialog.d.ts +44 -0
- package/dist/react/dialog.d.ts.map +1 -0
- package/dist/react/dialog.js +91 -0
- package/dist/react/dialog.js.map +1 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +22 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/knob.d.ts +55 -0
- package/dist/react/knob.d.ts.map +1 -0
- package/dist/react/knob.js +144 -0
- package/dist/react/knob.js.map +1 -0
- package/dist/react/menu-button.d.ts +147 -0
- package/dist/react/menu-button.d.ts.map +1 -0
- package/dist/react/menu-button.js +342 -0
- package/dist/react/menu-button.js.map +1 -0
- package/dist/react/meter.d.ts +34 -0
- package/dist/react/meter.d.ts.map +1 -0
- package/dist/react/meter.js +23 -0
- package/dist/react/meter.js.map +1 -0
- package/dist/react/progress-ring.d.ts +42 -0
- package/dist/react/progress-ring.d.ts.map +1 -0
- package/dist/react/progress-ring.js +28 -0
- package/dist/react/progress-ring.js.map +1 -0
- package/dist/react/radio-group.d.ts +52 -0
- package/dist/react/radio-group.d.ts.map +1 -0
- package/dist/react/radio-group.js +30 -0
- package/dist/react/radio-group.js.map +1 -0
- package/dist/react/readout.d.ts +23 -0
- package/dist/react/readout.d.ts.map +1 -0
- package/dist/react/readout.js +13 -0
- package/dist/react/readout.js.map +1 -0
- package/dist/react/slider.d.ts +44 -0
- package/dist/react/slider.d.ts.map +1 -0
- package/dist/react/slider.js +167 -0
- package/dist/react/slider.js.map +1 -0
- package/dist/react/spin-button.d.ts +71 -0
- package/dist/react/spin-button.d.ts.map +1 -0
- package/dist/react/spin-button.js +132 -0
- package/dist/react/spin-button.js.map +1 -0
- package/dist/react/swatch-strip.d.ts +31 -0
- package/dist/react/swatch-strip.d.ts.map +1 -0
- package/dist/react/swatch-strip.js +17 -0
- package/dist/react/swatch-strip.js.map +1 -0
- package/dist/react/switch.d.ts +26 -0
- package/dist/react/switch.d.ts.map +1 -0
- package/dist/react/switch.js +19 -0
- package/dist/react/switch.js.map +1 -0
- package/dist/react/tabs.d.ts +95 -0
- package/dist/react/tabs.d.ts.map +1 -0
- package/dist/react/tabs.js +274 -0
- package/dist/react/tabs.js.map +1 -0
- package/dist/react/toaster.d.ts +43 -0
- package/dist/react/toaster.d.ts.map +1 -0
- package/dist/react/toaster.js +368 -0
- package/dist/react/toaster.js.map +1 -0
- package/dist/react/toggle-button.d.ts +37 -0
- package/dist/react/toggle-button.d.ts.map +1 -0
- package/dist/react/toggle-button.js +22 -0
- package/dist/react/toggle-button.js.map +1 -0
- package/dist/react/toolbar.d.ts +25 -0
- package/dist/react/toolbar.d.ts.map +1 -0
- package/dist/react/toolbar.js +143 -0
- package/dist/react/toolbar.js.map +1 -0
- package/dist/react/tooltip.d.ts +68 -0
- package/dist/react/tooltip.d.ts.map +1 -0
- package/dist/react/tooltip.js +165 -0
- package/dist/react/tooltip.js.map +1 -0
- package/dist/react/tree.d.ts +94 -0
- package/dist/react/tree.d.ts.map +1 -0
- package/dist/react/tree.js +422 -0
- package/dist/react/tree.js.map +1 -0
- package/dist/react/use-element-binding.d.ts +35 -0
- package/dist/react/use-element-binding.d.ts.map +1 -0
- package/dist/react/use-element-binding.js +51 -0
- package/dist/react/use-element-binding.js.map +1 -0
- package/dist/swatch-strip/swatch-strip.d.ts +60 -0
- package/dist/swatch-strip/swatch-strip.d.ts.map +1 -0
- package/dist/swatch-strip/swatch-strip.js +60 -0
- package/dist/swatch-strip/swatch-strip.js.map +1 -0
- package/package.json +38 -15
- package/styles.css +191 -1
- package/dist/preact/_anchor.d.ts.map +0 -1
- package/dist/preact/_anchor.js.map +0 -1
- package/dist/preact/_dom.d.ts.map +0 -1
- package/dist/preact/_dom.js.map +0 -1
- package/dist/preact/_live-announcer.d.ts.map +0 -1
- package/dist/preact/_live-announcer.js.map +0 -1
- package/dist/preact/join-classes.d.ts.map +0 -1
- package/dist/preact/join-classes.js.map +0 -1
- /package/dist/{preact → adapter}/_anchor.d.ts +0 -0
- /package/dist/{preact → adapter}/_anchor.js +0 -0
- /package/dist/{preact → adapter}/_dom.d.ts +0 -0
- /package/dist/{preact → adapter}/_dom.js +0 -0
- /package/dist/{preact → adapter}/join-classes.d.ts +0 -0
- /package/dist/{preact → adapter}/join-classes.js +0 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Component, useCallback, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { directionOf_, localesOf_ } from "../adapter/_dom.js";
|
|
4
|
+
import { Typeahead } from "../focus/typeahead.js";
|
|
5
|
+
import { expandTreeSiblings, nextTreeSelection, treeAttributes, treeItemAttributes, treeKeyAction, treePath, treeTabStop, visibleTreeRows, } from "../tree/tree.js";
|
|
6
|
+
import { classOf_, reactAttributes_, } from "./_props.js";
|
|
7
|
+
import { useLatest } from "./use-element-binding.js";
|
|
8
|
+
const ITEM_SELECTOR_ = '[role="treeitem"]';
|
|
9
|
+
const NO_SELECTION_ = new Set();
|
|
10
|
+
/**
|
|
11
|
+
* A React key per node: React keys are strings, and nodes are any value, an
|
|
12
|
+
* object or a primitive. Each distinct node keeps its key while it lives.
|
|
13
|
+
*/
|
|
14
|
+
class NodeKeys_ {
|
|
15
|
+
objects_ = new WeakMap();
|
|
16
|
+
primitives_ = new Map();
|
|
17
|
+
count_ = 0;
|
|
18
|
+
keyOf(node) {
|
|
19
|
+
if ((typeof node === "object" && node !== null) ||
|
|
20
|
+
typeof node === "function") {
|
|
21
|
+
return this.objects_.get(node) ?? this.add_(this.objects_, node);
|
|
22
|
+
}
|
|
23
|
+
return this.primitives_.get(node) ?? this.add_(this.primitives_, node);
|
|
24
|
+
}
|
|
25
|
+
add_(map, node) {
|
|
26
|
+
this.count_ += 1;
|
|
27
|
+
const key = String(this.count_);
|
|
28
|
+
map.set(node, key);
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function chevron_() {
|
|
33
|
+
return (_jsx("svg", { viewBox: "0 0 16 16", focusable: "false", children: _jsx("path", { d: "M6 4l4 4-4 4" }) }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One row. A class for `shouldComponentUpdate`: a focus move draws again only
|
|
37
|
+
* the two rows whose tab stop or selection changed, not every row.
|
|
38
|
+
*/
|
|
39
|
+
class TreeItem_ extends Component {
|
|
40
|
+
shouldComponentUpdate(next) {
|
|
41
|
+
const current = this.props;
|
|
42
|
+
const { rows, index } = current;
|
|
43
|
+
return (next.node !== current.node ||
|
|
44
|
+
next.selectionMode !== current.selectionMode ||
|
|
45
|
+
next.isSelected !== current.isSelected ||
|
|
46
|
+
next.isTabStop !== current.isTabStop ||
|
|
47
|
+
next.isDisabled !== current.isDisabled ||
|
|
48
|
+
next.textValueOf !== current.textValueOf ||
|
|
49
|
+
next.renderItem !== current.renderItem ||
|
|
50
|
+
next.register !== current.register ||
|
|
51
|
+
next.rows.levelAt(next.index) !== rows.levelAt(index) ||
|
|
52
|
+
next.rows.positionAt(next.index) !== rows.positionAt(index) ||
|
|
53
|
+
next.rows.setSizeAt(next.index) !== rows.setSizeAt(index) ||
|
|
54
|
+
next.rows.isBranchAt(next.index) !== rows.isBranchAt(index) ||
|
|
55
|
+
next.rows.isExpandedAt(next.index) !== rows.isExpandedAt(index) ||
|
|
56
|
+
next.rows.isLoadingAt(next.index) !== rows.isLoadingAt(index));
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
const { rows, index, node, selectionMode, isSelected, isTabStop, isDisabled, textValueOf, renderItem, register, } = this.props;
|
|
60
|
+
const level = rows.levelAt(index);
|
|
61
|
+
const isBranch = rows.isBranchAt(index);
|
|
62
|
+
const state = {
|
|
63
|
+
level,
|
|
64
|
+
isBranch,
|
|
65
|
+
isExpanded: rows.isExpandedAt(index),
|
|
66
|
+
isSelected,
|
|
67
|
+
isDisabled,
|
|
68
|
+
isLoading: rows.isLoadingAt(index),
|
|
69
|
+
};
|
|
70
|
+
const style = { "--ack-tree-level": level };
|
|
71
|
+
return (_jsxs("li", { ...reactAttributes_(treeItemAttributes({
|
|
72
|
+
rows,
|
|
73
|
+
index,
|
|
74
|
+
selectionMode,
|
|
75
|
+
isSelected,
|
|
76
|
+
isTabStop,
|
|
77
|
+
isDisabled,
|
|
78
|
+
})), ref: (element) => {
|
|
79
|
+
register(element, node);
|
|
80
|
+
}, className: "ack-tree-item", "data-selected": isSelected ? "" : undefined, style: style, children: [_jsx("span", { className: "ack-tree-item-toggle", "aria-hidden": "true", "data-loading": state.isLoading ? "" : undefined, children: isBranch && chevron_() }), _jsx("span", { className: "ack-tree-item-content", children: renderItem === undefined
|
|
81
|
+
? textValueOf(node)
|
|
82
|
+
: renderItem(node, state) })] }));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A hierarchy of nodes to browse, expand and select (WAI-ARIA tree view
|
|
87
|
+
* pattern), such as a file tree or the elements of a document. One tab stop, on
|
|
88
|
+
* the focused node (at first the first selected node, else the first); Arrow
|
|
89
|
+
* Down and Up move through the shown rows, Home and End to the ends; Arrow
|
|
90
|
+
* Right expands a branch, then moves to its first child; Arrow Left collapses
|
|
91
|
+
* it, or moves to the parent; `*` expands every branch beside the focused one;
|
|
92
|
+
* typing a name moves to it; Enter activates a node, or expands or collapses a
|
|
93
|
+
* branch with no action. Right to left, Arrow Right and Left swap.
|
|
94
|
+
*
|
|
95
|
+
* In single selection, Space or a click selects a node; with
|
|
96
|
+
* `selectionFollowsFocus`, moving focus does. In multiple selection, Space or
|
|
97
|
+
* Ctrl (Cmd) click flips a node, Shift Arrow Down and Up move and flip, Shift
|
|
98
|
+
* Space and Shift click select from the last node selected, Ctrl (Cmd) Shift
|
|
99
|
+
* Home and End to the first and last row, Ctrl (Cmd) A selects every node or
|
|
100
|
+
* none. A click on the expand mark, or a double click on a branch, expands or
|
|
101
|
+
* collapses it. Disabled nodes take focus and expand, but are never selected or
|
|
102
|
+
* activated.
|
|
103
|
+
*
|
|
104
|
+
* The rows are one flat list stating each item's level, position and set size,
|
|
105
|
+
* so a branch's children load lazily: an expanded branch whose children are
|
|
106
|
+
* `undefined` shows as busy until they come. When the focused row goes away
|
|
107
|
+
* (its branch collapsed, its node removed), focus moves to the nearest row
|
|
108
|
+
* still shown. Expansion and selection are the caller's.
|
|
109
|
+
*/
|
|
110
|
+
export function Tree(props) {
|
|
111
|
+
const { roots, childrenOf, isBranch, textValueOf, renderItem, expanded, onExpandedChange, selectionMode = "single", selected = NO_SELECTION_, onSelectedChange, selectionFollowsFocus = false, onActivate, isDisabled, id, } = props;
|
|
112
|
+
const nameInput = props.label === undefined
|
|
113
|
+
? { labelledBy: props.labelledBy }
|
|
114
|
+
: { label: props.label };
|
|
115
|
+
const source = useMemo(() => ({ roots, childrenOf, isBranch }), [roots, childrenOf, isBranch]);
|
|
116
|
+
const rows = useMemo(() => visibleTreeRows(source, (node) => expanded.has(node)), [source, expanded]);
|
|
117
|
+
const [focusedPath, setFocusedPath] = useState([]);
|
|
118
|
+
const tabStop = treeTabStop(rows, focusedPath, selected);
|
|
119
|
+
const tree = useRef(null);
|
|
120
|
+
const nodes = useRef(new WeakMap());
|
|
121
|
+
const [nodeKeys] = useState(() => new NodeKeys_());
|
|
122
|
+
const typeahead = useRef(new Typeahead());
|
|
123
|
+
const anchor = useRef(undefined);
|
|
124
|
+
const labels = useRef(undefined);
|
|
125
|
+
// The row focus was last on, until focus leaves the tree for another place.
|
|
126
|
+
const focusedRow = useRef(null);
|
|
127
|
+
// What was last reported, until the next render brings the caller's answer:
|
|
128
|
+
// two changes in one event build on each other.
|
|
129
|
+
const reportedSelection = useRef(undefined);
|
|
130
|
+
reportedSelection.current = undefined;
|
|
131
|
+
const latest = useLatest({
|
|
132
|
+
rows,
|
|
133
|
+
source,
|
|
134
|
+
expanded,
|
|
135
|
+
selected,
|
|
136
|
+
selectionMode,
|
|
137
|
+
selectionFollowsFocus,
|
|
138
|
+
isDisabled,
|
|
139
|
+
onExpandedChange,
|
|
140
|
+
onSelectedChange,
|
|
141
|
+
onActivate,
|
|
142
|
+
focusedPath,
|
|
143
|
+
});
|
|
144
|
+
const register = useCallback((element, node) => {
|
|
145
|
+
if (element !== null) {
|
|
146
|
+
nodes.current.set(element, node);
|
|
147
|
+
}
|
|
148
|
+
}, []);
|
|
149
|
+
// Focus on a row that went away moves to the tab stop, the nearest row left.
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
const element = tree.current;
|
|
152
|
+
const row = focusedRow.current;
|
|
153
|
+
if (element === null || row === null || row.isConnected) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const active = document.activeElement;
|
|
157
|
+
if (active !== null && active !== document.body) {
|
|
158
|
+
focusedRow.current = null;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const stop = element.children[tabStop];
|
|
162
|
+
if (stop instanceof HTMLElement) {
|
|
163
|
+
stop.focus({ preventScroll: true });
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
focusedRow.current = null;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const rowElementAt = (index) => {
|
|
170
|
+
const row = tree.current?.children[index];
|
|
171
|
+
return row instanceof HTMLElement ? row : undefined;
|
|
172
|
+
};
|
|
173
|
+
const isNodeDisabled = (node) => latest.current.isDisabled?.(node) === true;
|
|
174
|
+
const changeSelection = (change) => {
|
|
175
|
+
const current = latest.current;
|
|
176
|
+
if (current.selectionMode === "none") {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const base = reportedSelection.current ?? current.selected;
|
|
180
|
+
const next = nextTreeSelection(base, change, {
|
|
181
|
+
source: current.source,
|
|
182
|
+
rows: current.rows,
|
|
183
|
+
isDisabled: current.isDisabled,
|
|
184
|
+
});
|
|
185
|
+
if (next !== base) {
|
|
186
|
+
reportedSelection.current = next;
|
|
187
|
+
current.onSelectedChange?.(next);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const setExpanded = (node, isExpanded) => {
|
|
191
|
+
const current = latest.current.expanded;
|
|
192
|
+
if (current.has(node) === isExpanded) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const next = new Set(current);
|
|
196
|
+
if (isExpanded) {
|
|
197
|
+
next.add(node);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
next.delete(node);
|
|
201
|
+
}
|
|
202
|
+
latest.current.onExpandedChange(next);
|
|
203
|
+
};
|
|
204
|
+
const rowOf = (target) => {
|
|
205
|
+
const row = target instanceof Element
|
|
206
|
+
? target.closest(ITEM_SELECTOR_)
|
|
207
|
+
: null;
|
|
208
|
+
return row !== null && row.parentElement === tree.current ? row : null;
|
|
209
|
+
};
|
|
210
|
+
const indexOfRow = (row) => {
|
|
211
|
+
const node = nodes.current.get(row);
|
|
212
|
+
return node === undefined ? -1 : latest.current.rows.indexOf(node);
|
|
213
|
+
};
|
|
214
|
+
const activate = (index) => {
|
|
215
|
+
const { rows: currentRows, onActivate: action } = latest.current;
|
|
216
|
+
const node = currentRows.nodeAt(index);
|
|
217
|
+
if (action !== undefined) {
|
|
218
|
+
if (!isNodeDisabled(node)) {
|
|
219
|
+
action(node);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if (currentRows.isBranchAt(index)) {
|
|
223
|
+
setExpanded(node, !currentRows.isExpandedAt(index));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
return (_jsx("ul", { ...treeAttributes({ ...nameInput, selectionMode }), id: id, ref: tree, className: classOf_("ack-control ack-tree", props), onFocus: (event) => {
|
|
227
|
+
const row = rowOf(event.target);
|
|
228
|
+
if (row === null) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
focusedRow.current = row;
|
|
232
|
+
const index = indexOfRow(row);
|
|
233
|
+
if (index === -1) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const current = latest.current;
|
|
237
|
+
const node = current.rows.nodeAt(index);
|
|
238
|
+
if (current.focusedPath.at(-1) !== node) {
|
|
239
|
+
setFocusedPath(treePath(current.rows, index));
|
|
240
|
+
}
|
|
241
|
+
if (current.selectionFollowsFocus &&
|
|
242
|
+
current.selectionMode === "single") {
|
|
243
|
+
changeSelection({ kind: "replace", index });
|
|
244
|
+
}
|
|
245
|
+
}, onBlur: (event) => {
|
|
246
|
+
const row = rowOf(event.target);
|
|
247
|
+
const next = event.relatedTarget;
|
|
248
|
+
if (row === null ||
|
|
249
|
+
(next instanceof Node && tree.current?.contains(next) === true)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
// A row removed while focused may report its blur before it is
|
|
253
|
+
// detached (Chromium): decide once the removal is done, keeping a
|
|
254
|
+
// removed row so its focus is restored.
|
|
255
|
+
queueMicrotask(() => {
|
|
256
|
+
if (focusedRow.current === row && row.isConnected) {
|
|
257
|
+
focusedRow.current = null;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}, onKeyDown: (event) => {
|
|
261
|
+
const row = rowOf(event.target);
|
|
262
|
+
if (row === null) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const current = indexOfRow(row);
|
|
266
|
+
if (current === -1) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const state = latest.current;
|
|
270
|
+
const action = treeKeyAction({
|
|
271
|
+
key: event.key,
|
|
272
|
+
shiftKey: event.shiftKey,
|
|
273
|
+
ctrlKey: event.ctrlKey,
|
|
274
|
+
altKey: event.altKey,
|
|
275
|
+
metaKey: event.metaKey,
|
|
276
|
+
current,
|
|
277
|
+
rows: state.rows,
|
|
278
|
+
direction: directionOf_(event.currentTarget),
|
|
279
|
+
selectionMode: state.selectionMode,
|
|
280
|
+
isTypingAhead: typeahead.current.isActive(event.timeStamp),
|
|
281
|
+
});
|
|
282
|
+
if (action === undefined) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
switch (action.kind) {
|
|
287
|
+
case "focus":
|
|
288
|
+
rowElementAt(action.index)?.focus();
|
|
289
|
+
if (action.toggles) {
|
|
290
|
+
anchor.current = state.rows.nodeAt(action.index);
|
|
291
|
+
changeSelection({ kind: "toggle", index: action.index });
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
case "expand":
|
|
295
|
+
setExpanded(state.rows.nodeAt(action.index), true);
|
|
296
|
+
break;
|
|
297
|
+
case "collapse":
|
|
298
|
+
setExpanded(state.rows.nodeAt(action.index), false);
|
|
299
|
+
break;
|
|
300
|
+
case "expandSiblings": {
|
|
301
|
+
const next = expandTreeSiblings(state.source, state.rows, action.index, state.expanded);
|
|
302
|
+
if (next !== state.expanded) {
|
|
303
|
+
state.onExpandedChange(next);
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case "activate":
|
|
308
|
+
activate(action.index);
|
|
309
|
+
break;
|
|
310
|
+
case "select":
|
|
311
|
+
anchor.current = state.rows.nodeAt(action.index);
|
|
312
|
+
changeSelection({
|
|
313
|
+
kind: state.selectionMode === "multiple" ? "toggle" : "replace",
|
|
314
|
+
index: action.index,
|
|
315
|
+
});
|
|
316
|
+
break;
|
|
317
|
+
case "selectRange": {
|
|
318
|
+
const anchorIndex = anchor.current === undefined
|
|
319
|
+
? -1
|
|
320
|
+
: state.rows.indexOf(anchor.current);
|
|
321
|
+
const from = action.from === "anchor"
|
|
322
|
+
? anchorIndex === -1
|
|
323
|
+
? current
|
|
324
|
+
: anchorIndex
|
|
325
|
+
: action.from;
|
|
326
|
+
changeSelection({
|
|
327
|
+
kind: "range",
|
|
328
|
+
from,
|
|
329
|
+
to: action.to,
|
|
330
|
+
isAdded: true,
|
|
331
|
+
});
|
|
332
|
+
rowElementAt(action.focus)?.focus();
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case "selectAll":
|
|
336
|
+
changeSelection({ kind: "all" });
|
|
337
|
+
break;
|
|
338
|
+
case "typeahead": {
|
|
339
|
+
let cached = labels.current;
|
|
340
|
+
if (cached?.rows !== state.rows ||
|
|
341
|
+
cached.textValueOf !== textValueOf) {
|
|
342
|
+
const all = [];
|
|
343
|
+
for (let index = 0; index < state.rows.count; index += 1) {
|
|
344
|
+
all.push(textValueOf(state.rows.nodeAt(index)));
|
|
345
|
+
}
|
|
346
|
+
cached = { rows: state.rows, textValueOf, labels: all };
|
|
347
|
+
labels.current = cached;
|
|
348
|
+
}
|
|
349
|
+
const next = typeahead.current.find(action.character, event.timeStamp, cached.labels, current, { locales: localesOf_(event.currentTarget) });
|
|
350
|
+
if (next !== undefined) {
|
|
351
|
+
rowElementAt(next)?.focus();
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}, onClick: (event) => {
|
|
357
|
+
const row = rowOf(event.target);
|
|
358
|
+
if (row === null) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const index = indexOfRow(row);
|
|
362
|
+
if (index === -1) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const state = latest.current;
|
|
366
|
+
if (document.activeElement !== row) {
|
|
367
|
+
row.focus({ preventScroll: true });
|
|
368
|
+
}
|
|
369
|
+
const isToggle = event.target instanceof Element &&
|
|
370
|
+
event.target.closest(".ack-tree-item-toggle") !== null;
|
|
371
|
+
if (isToggle) {
|
|
372
|
+
if (state.rows.isBranchAt(index)) {
|
|
373
|
+
setExpanded(state.rows.nodeAt(index), !state.rows.isExpandedAt(index));
|
|
374
|
+
}
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const node = state.rows.nodeAt(index);
|
|
378
|
+
const command = event.ctrlKey || event.metaKey;
|
|
379
|
+
if (state.selectionMode === "multiple" && (command || event.shiftKey)) {
|
|
380
|
+
if (event.shiftKey) {
|
|
381
|
+
const anchorIndex = anchor.current === undefined
|
|
382
|
+
? -1
|
|
383
|
+
: state.rows.indexOf(anchor.current);
|
|
384
|
+
changeSelection({
|
|
385
|
+
kind: "range",
|
|
386
|
+
from: anchorIndex === -1 ? index : anchorIndex,
|
|
387
|
+
to: index,
|
|
388
|
+
isAdded: command,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
anchor.current = node;
|
|
393
|
+
changeSelection({ kind: "toggle", index });
|
|
394
|
+
}
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
anchor.current = node;
|
|
398
|
+
changeSelection({ kind: "replace", index });
|
|
399
|
+
if (!event.altKey && !event.shiftKey && !command) {
|
|
400
|
+
const action = state.onActivate;
|
|
401
|
+
if (action !== undefined && !isNodeDisabled(node)) {
|
|
402
|
+
action(node);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}, onDoubleClick: (event) => {
|
|
406
|
+
const row = rowOf(event.target);
|
|
407
|
+
if (row === null ||
|
|
408
|
+
(event.target instanceof Element &&
|
|
409
|
+
event.target.closest(".ack-tree-item-toggle") !== null)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const index = indexOfRow(row);
|
|
413
|
+
const state = latest.current;
|
|
414
|
+
if (index !== -1 && state.rows.isBranchAt(index)) {
|
|
415
|
+
setExpanded(state.rows.nodeAt(index), !state.rows.isExpandedAt(index));
|
|
416
|
+
}
|
|
417
|
+
}, children: Array.from({ length: rows.count }, (_unused, index) => {
|
|
418
|
+
const node = rows.nodeAt(index);
|
|
419
|
+
return (_jsx(TreeItem_, { rows: rows, index: index, node: node, selectionMode: selectionMode, isSelected: selected.has(node), isTabStop: index === tabStop, isDisabled: isDisabled?.(node) === true, textValueOf: textValueOf, renderItem: renderItem, register: register }, nodeKeys.keyOf(node)));
|
|
420
|
+
}) }));
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/react/tree.tsx"],"names":[],"mappings":";AAEA,OAAO,EACN,SAAS,EAGT,WAAW,EACX,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GACR,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EAKjB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAe,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEN,QAAQ,EAER,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgErD,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,aAAa,GAAuB,IAAI,GAAG,EAAE,CAAC;AAEpD;;;GAGG;AACH,MAAM,SAAS;IACG,QAAQ,GAAG,IAAI,OAAO,EAAkB,CAAC;IACzC,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;IAClD,MAAM,GAAG,CAAC,CAAC;IAEnB,KAAK,CAAC,IAAa;QAClB,IACC,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC;YAC3C,OAAO,IAAI,KAAK,UAAU,EACzB,CAAC;YACF,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,I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5B,UAAU,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EACvC,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,IAVb,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAWxB,CACF,CAAC;QACH,CAAC,CAAC,GACE,CACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import { type RefCallback } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Runs `bind` on an element once it is mounted, and again when `deps` change or
|
|
5
|
+
* the element is replaced; before each re-run and at unmount it aborts the
|
|
6
|
+
* signal it passed and disposes what `bind` returned. For `ui-gesture/dom`
|
|
7
|
+
* bindings in this package's components, `ui-music`'s and the caller's.
|
|
8
|
+
*
|
|
9
|
+
* Returns the callback ref to put on the element, which is how the hook sees an
|
|
10
|
+
* element mounted late or swapped for another with the dependencies unchanged.
|
|
11
|
+
* The binding is made in the render that follows the element's mount, so a
|
|
12
|
+
* `touch-action` it sets comes right after the first paint; the stylesheet sets
|
|
13
|
+
* the same ones for the first press. Under `StrictMode`'s second mount the
|
|
14
|
+
* binding is disposed and made again, as for any effect.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const root = useElementBinding<HTMLDivElement>(
|
|
18
|
+
* (element, signal) => bindPointers(element, handlers, { signal }),
|
|
19
|
+
* [],
|
|
20
|
+
* );
|
|
21
|
+
* return <div ref={root} />;
|
|
22
|
+
*/
|
|
23
|
+
export declare function useElementBinding<Target extends Element>(bind: Callable<[
|
|
24
|
+
element: Target,
|
|
25
|
+
signal: AbortSignal
|
|
26
|
+
], Disposable | undefined>, deps: ReadonlyArray<unknown>): RefCallback<Target>;
|
|
27
|
+
/**
|
|
28
|
+
* A ref whose `current` is always the latest `value`, for handlers a binding
|
|
29
|
+
* reads at each call. It is written during render, so a handler that runs
|
|
30
|
+
* between a render and its commit sees the newer value.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useLatest<Value>(value: Value): {
|
|
33
|
+
readonly current: Value;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=use-element-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-element-binding.d.ts","sourceRoot":"","sources":["../../src/react/use-element-binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACN,KAAK,WAAW,EAKhB,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,OAAO,EACvD,IAAI,EAAE,QAAQ,CACb;IAAC,OAAO,EAAE,MAAM;IAAE,MAAM,EAAE,WAAW;CAAC,EACtC,UAAU,GAAG,SAAS,CACtB,EACD,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAC1B,WAAW,CAAC,MAAM,CAAC,CAoBrB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAK1E"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef, useState, } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `bind` on an element once it is mounted, and again when `deps` change or
|
|
4
|
+
* the element is replaced; before each re-run and at unmount it aborts the
|
|
5
|
+
* signal it passed and disposes what `bind` returned. For `ui-gesture/dom`
|
|
6
|
+
* bindings in this package's components, `ui-music`'s and the caller's.
|
|
7
|
+
*
|
|
8
|
+
* Returns the callback ref to put on the element, which is how the hook sees an
|
|
9
|
+
* element mounted late or swapped for another with the dependencies unchanged.
|
|
10
|
+
* The binding is made in the render that follows the element's mount, so a
|
|
11
|
+
* `touch-action` it sets comes right after the first paint; the stylesheet sets
|
|
12
|
+
* the same ones for the first press. Under `StrictMode`'s second mount the
|
|
13
|
+
* binding is disposed and made again, as for any effect.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const root = useElementBinding<HTMLDivElement>(
|
|
17
|
+
* (element, signal) => bindPointers(element, handlers, { signal }),
|
|
18
|
+
* [],
|
|
19
|
+
* );
|
|
20
|
+
* return <div ref={root} />;
|
|
21
|
+
*/
|
|
22
|
+
export function useElementBinding(bind, deps) {
|
|
23
|
+
const [element, setElement] = useState(null);
|
|
24
|
+
const attach = useCallback((node) => {
|
|
25
|
+
setElement(node);
|
|
26
|
+
}, []);
|
|
27
|
+
const latestBind = useLatest(bind);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (element === null) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const binding = latestBind.current(element, controller.signal);
|
|
34
|
+
return () => {
|
|
35
|
+
controller.abort();
|
|
36
|
+
binding?.[Symbol.dispose]();
|
|
37
|
+
};
|
|
38
|
+
}, [element, ...deps]);
|
|
39
|
+
return attach;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A ref whose `current` is always the latest `value`, for handlers a binding
|
|
43
|
+
* reads at each call. It is written during render, so a handler that runs
|
|
44
|
+
* between a render and its commit sees the newer value.
|
|
45
|
+
*/
|
|
46
|
+
export function useLatest(value) {
|
|
47
|
+
const ref = useRef(value);
|
|
48
|
+
ref.current = value;
|
|
49
|
+
return ref;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=use-element-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-element-binding.js","sourceRoot":"","sources":["../../src/react/use-element-binding.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,WAAW,EACX,eAAe,EACf,MAAM,EACN,QAAQ,GACR,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAGC,EACD,IAA4B;IAE5B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAmB,EAAE,EAAE;QAClD,UAAU,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACnC,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/D,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAEvB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAQ,KAAY;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** One colour of a swatch strip. */
|
|
2
|
+
export type SwatchStripItem = {
|
|
3
|
+
/** Any CSS colour: `#3b82f6`, `oklch(70% 0.1 200)`. */
|
|
4
|
+
readonly color: string;
|
|
5
|
+
/** Drawn under the swatch: a name, a step, a value. */
|
|
6
|
+
readonly label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* What a screen reader says for the swatch, when the label alone does not say
|
|
9
|
+
* it: `"step 3, OKLab lightness 0.62"`.
|
|
10
|
+
*/
|
|
11
|
+
readonly description?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Options of {@link swatchStripGradient}. */
|
|
14
|
+
export type SwatchStripGradientOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* The CSS colour space the browser blends adjacent colours in (`oklab`,
|
|
17
|
+
* `srgb`, `oklch longer hue`). Omitted, the strip has hard stops: every
|
|
18
|
+
* colour gets an equal band and the browser blends nothing, so what is drawn
|
|
19
|
+
* is exactly the colours given.
|
|
20
|
+
*/
|
|
21
|
+
interpolation?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The CSS `linear-gradient()` that draws `colors` left to right as one strip:
|
|
25
|
+
* equal bands with hard edges by default, or a smooth blend in the given colour
|
|
26
|
+
* space.
|
|
27
|
+
*
|
|
28
|
+
* Time complexity: O(n). Memory: O(n).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* swatchStripGradient(["red", "blue"]);
|
|
32
|
+
* // "linear-gradient(to right, red 0% 50%, blue 50% 100%)"
|
|
33
|
+
* swatchStripGradient(["red", "blue"], { interpolation: "oklab" });
|
|
34
|
+
* // "linear-gradient(in oklab to right, red 0%, blue 100%)"
|
|
35
|
+
*
|
|
36
|
+
* @throws {RangeError} When `colors` is empty.
|
|
37
|
+
*/
|
|
38
|
+
export declare function swatchStripGradient(colors: readonly string[], options?: SwatchStripGradientOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* What a screen reader says for one swatch: its description, else its label
|
|
41
|
+
* with its colour, else its colour.
|
|
42
|
+
*
|
|
43
|
+
* Time complexity: O(1). Memory: O(1).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* swatchStripItemLabel({ color: "#ff0000", label: "red" }); // "red, #ff0000"
|
|
47
|
+
*/
|
|
48
|
+
export declare function swatchStripItemLabel(item: SwatchStripItem): string;
|
|
49
|
+
/**
|
|
50
|
+
* What a screen reader says for a whole strip drawn as one gradient: its name
|
|
51
|
+
* and its colours in order, each with its label.
|
|
52
|
+
*
|
|
53
|
+
* Time complexity: O(n). Memory: O(n).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* swatchStripSummary("Red to blue", [{ color: "red" }, { color: "blue" }]);
|
|
57
|
+
* // "Red to blue: red; blue"
|
|
58
|
+
*/
|
|
59
|
+
export declare function swatchStripSummary(label: string, items: readonly SwatchStripItem[]): string;
|
|
60
|
+
//# sourceMappingURL=swatch-strip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swatch-strip.d.ts","sourceRoot":"","sources":["../../src/swatch-strip/swatch-strip.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,MAAM,eAAe,GAAG;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,0BAA0B,GAAG;IACxC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,GAAE,0BAA+B,GACtC,MAAM,CAsBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAKlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,eAAe,EAAE,GAC/B,MAAM,CAER"}
|