@fragiola/primitives 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +21 -0
  3. package/README.md +50 -2
  4. package/dist/async-list-Bv6ff5Oj.js +81 -0
  5. package/dist/async-list-Bv6ff5Oj.js.map +1 -0
  6. package/dist/async-list.d.ts +2 -0
  7. package/dist/async-list.js +1 -0
  8. package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
  9. package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
  10. package/dist/calendar-systems-Daa6Q_ca.js +659 -0
  11. package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
  12. package/dist/calendar-systems.d.ts +3 -0
  13. package/dist/calendar-systems.js +1 -0
  14. package/dist/carousel-LRbWqbAx.js +375 -0
  15. package/dist/carousel-LRbWqbAx.js.map +1 -0
  16. package/dist/carousel.d.ts +2 -0
  17. package/dist/carousel.js +1 -0
  18. package/dist/cascade-B155Xvvv.js +64 -0
  19. package/dist/cascade-B155Xvvv.js.map +1 -0
  20. package/dist/cascade.d.ts +2 -0
  21. package/dist/cascade.js +1 -0
  22. package/dist/clipboard-Cy2cbGEW.js +33 -0
  23. package/dist/clipboard-Cy2cbGEW.js.map +1 -0
  24. package/dist/clipboard.d.ts +2 -0
  25. package/dist/clipboard.js +1 -0
  26. package/dist/collection-Dbk-PB5S.js +609 -0
  27. package/dist/collection-Dbk-PB5S.js.map +1 -0
  28. package/dist/collection.d.ts +2 -0
  29. package/dist/collection.js +3 -0
  30. package/dist/color-sURV5Irg.js +699 -0
  31. package/dist/color-sURV5Irg.js.map +1 -0
  32. package/dist/color.d.ts +2 -0
  33. package/dist/color.js +1 -0
  34. package/dist/command-DueCXi65.js +104 -0
  35. package/dist/command-DueCXi65.js.map +1 -0
  36. package/dist/command.d.ts +2 -0
  37. package/dist/command.js +1 -0
  38. package/dist/date-CrbFSJKQ.js +215 -0
  39. package/dist/date-CrbFSJKQ.js.map +1 -0
  40. package/dist/date.d.ts +4 -0
  41. package/dist/date.js +1 -0
  42. package/dist/direction-CTnVLpmd.d.ts +8 -0
  43. package/dist/direction-DJDPvnxJ.js +13 -0
  44. package/dist/direction-DJDPvnxJ.js.map +1 -0
  45. package/dist/direction.d.ts +2 -0
  46. package/dist/direction.js +1 -0
  47. package/dist/drag-session-CSr06B5v.js +41 -0
  48. package/dist/drag-session-CSr06B5v.js.map +1 -0
  49. package/dist/file-DSLtfzbi.js +263 -0
  50. package/dist/file-DSLtfzbi.js.map +1 -0
  51. package/dist/file.d.ts +2 -0
  52. package/dist/file.js +1 -0
  53. package/dist/focus-BI-VvM0f.js +75 -0
  54. package/dist/focus-BI-VvM0f.js.map +1 -0
  55. package/dist/focus.d.ts +2 -0
  56. package/dist/focus.js +3 -0
  57. package/dist/form-DovwKtqz.js +501 -0
  58. package/dist/form-DovwKtqz.js.map +1 -0
  59. package/dist/form.d.ts +2 -0
  60. package/dist/form.js +1 -0
  61. package/dist/hover-BakyPYnC.js +62 -0
  62. package/dist/hover-BakyPYnC.js.map +1 -0
  63. package/dist/hover.d.ts +2 -0
  64. package/dist/hover.js +1 -0
  65. package/dist/id-B0Y8iZrc.js +13 -0
  66. package/dist/id-B0Y8iZrc.js.map +1 -0
  67. package/dist/id.d.ts +2 -0
  68. package/dist/id.js +1 -0
  69. package/dist/image-D4X_yRYw.js +44 -0
  70. package/dist/image-D4X_yRYw.js.map +1 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +1 -0
  73. package/dist/index-B0rwIZw9.d.ts +51 -0
  74. package/dist/index-B4wF1isn.d.ts +128 -0
  75. package/dist/index-BHiBRE01.d.ts +20 -0
  76. package/dist/index-BNlMm-0u.d.ts +17 -0
  77. package/dist/index-BapNrjY9.d.ts +48 -0
  78. package/dist/index-Bd-tVb7C.d.ts +6 -0
  79. package/dist/index-BjE8nDiX.d.ts +125 -0
  80. package/dist/index-BpbT-FsX.d.ts +117 -0
  81. package/dist/index-CBgGcTeX.d.ts +37 -0
  82. package/dist/index-CGThV_Md.d.ts +100 -0
  83. package/dist/index-CMig3TXL.d.ts +28 -0
  84. package/dist/index-CWFRduRd.d.ts +212 -0
  85. package/dist/index-CkrHWyU_.d.ts +33 -0
  86. package/dist/index-Cwu6f7y1.d.ts +18 -0
  87. package/dist/index-D10LDdR6.d.ts +139 -0
  88. package/dist/index-D146vm21.d.ts +104 -0
  89. package/dist/index-DGKhEvNr.d.ts +107 -0
  90. package/dist/index-DbAu4s16.d.ts +48 -0
  91. package/dist/index-DdaCj6IO.d.ts +54 -0
  92. package/dist/index-DeHcNdjC.d.ts +68 -0
  93. package/dist/index-DeR4ncrW.d.ts +93 -0
  94. package/dist/index-HIksgK0e.d.ts +70 -0
  95. package/dist/index-IZB0mlZl.d.ts +71 -0
  96. package/dist/index-IfDZj87U.d.ts +28 -0
  97. package/dist/index-SrTuVBms.d.ts +75 -0
  98. package/dist/index-T9UcYvkf.d.ts +339 -0
  99. package/dist/index-fRTojAoR.d.ts +31 -0
  100. package/dist/index-fuLUke9n.d.ts +6 -0
  101. package/dist/index-l63esAck.d.ts +104 -0
  102. package/dist/index-raSUg9U7.d.ts +38 -0
  103. package/dist/index-twgzPKvZ.d.ts +278 -0
  104. package/dist/index-wBpjRykh.d.ts +125 -0
  105. package/dist/index.d.ts +39 -0
  106. package/dist/index.js +42 -0
  107. package/dist/inert-DlGToy3q.js +80 -0
  108. package/dist/inert-DlGToy3q.js.map +1 -0
  109. package/dist/inert.d.ts +2 -0
  110. package/dist/inert.js +1 -0
  111. package/dist/layer-stack-BEtzaFC1.js +118 -0
  112. package/dist/layer-stack-BEtzaFC1.js.map +1 -0
  113. package/dist/layers-C-N4rrZX.js +24 -0
  114. package/dist/layers-C-N4rrZX.js.map +1 -0
  115. package/dist/layers.d.ts +2 -0
  116. package/dist/layers.js +3 -0
  117. package/dist/list-navigation-CbWv4DK5.js +40 -0
  118. package/dist/list-navigation-CbWv4DK5.js.map +1 -0
  119. package/dist/month-year-BG5imFUq.js +108 -0
  120. package/dist/month-year-BG5imFUq.js.map +1 -0
  121. package/dist/month-year.d.ts +3 -0
  122. package/dist/month-year.js +1 -0
  123. package/dist/number-BFUio97d.js +316 -0
  124. package/dist/number-BFUio97d.js.map +1 -0
  125. package/dist/number.d.ts +2 -0
  126. package/dist/number.js +1 -0
  127. package/dist/overlay-BwPyiM3T.js +78 -0
  128. package/dist/overlay-BwPyiM3T.js.map +1 -0
  129. package/dist/overlay.d.ts +2 -0
  130. package/dist/overlay.js +1 -0
  131. package/dist/pagination-BkVzaIGP.js +51 -0
  132. package/dist/pagination-BkVzaIGP.js.map +1 -0
  133. package/dist/pagination.d.ts +2 -0
  134. package/dist/pagination.js +1 -0
  135. package/dist/plain-date-idQH1P6X.d.ts +29 -0
  136. package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
  137. package/dist/pointer-CuDtD9XA.js +189 -0
  138. package/dist/pointer-CuDtD9XA.js.map +1 -0
  139. package/dist/pointer.d.ts +2 -0
  140. package/dist/pointer.js +3 -0
  141. package/dist/positioning-DDUQ75mB.js +148 -0
  142. package/dist/positioning-DDUQ75mB.js.map +1 -0
  143. package/dist/positioning.d.ts +2 -0
  144. package/dist/positioning.js +1 -0
  145. package/dist/presence-BhKDOmII.js +86 -0
  146. package/dist/presence-BhKDOmII.js.map +1 -0
  147. package/dist/presence.d.ts +2 -0
  148. package/dist/presence.js +1 -0
  149. package/dist/range-o0_GBhyY.js +158 -0
  150. package/dist/range-o0_GBhyY.js.map +1 -0
  151. package/dist/range.d.ts +2 -0
  152. package/dist/range.js +1 -0
  153. package/dist/scroll-area-BYNhv36t.js +447 -0
  154. package/dist/scroll-area-BYNhv36t.js.map +1 -0
  155. package/dist/scroll-area.d.ts +2 -0
  156. package/dist/scroll-area.js +1 -0
  157. package/dist/scroll-lock-JzRNOA1O.js +42 -0
  158. package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
  159. package/dist/scroll-lock.d.ts +2 -0
  160. package/dist/scroll-lock.js +1 -0
  161. package/dist/segments-eRu5G_Bd.js +587 -0
  162. package/dist/segments-eRu5G_Bd.js.map +1 -0
  163. package/dist/segments.d.ts +3 -0
  164. package/dist/segments.js +1 -0
  165. package/dist/selection-Cor67w_V.js +287 -0
  166. package/dist/selection-Cor67w_V.js.map +1 -0
  167. package/dist/selection.d.ts +2 -0
  168. package/dist/selection.js +1 -0
  169. package/dist/swipe.d.ts +2 -0
  170. package/dist/swipe.js +1 -0
  171. package/dist/tabbable-BPiLssIv.js +35 -0
  172. package/dist/tabbable-BPiLssIv.js.map +1 -0
  173. package/dist/time-Ct6oq9kt.js +208 -0
  174. package/dist/time-Ct6oq9kt.js.map +1 -0
  175. package/dist/time-zone-DegkzwST.js +305 -0
  176. package/dist/time-zone-DegkzwST.js.map +1 -0
  177. package/dist/time-zone.d.ts +2 -0
  178. package/dist/time-zone.js +1 -0
  179. package/dist/time.d.ts +2 -0
  180. package/dist/time.js +1 -0
  181. package/dist/toast-BjRpJalM.js +400 -0
  182. package/dist/toast-BjRpJalM.js.map +1 -0
  183. package/dist/toast.d.ts +2 -0
  184. package/dist/toast.js +1 -0
  185. package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
  186. package/dist/virtual-BlX1RuHD.js +306 -0
  187. package/dist/virtual-BlX1RuHD.js.map +1 -0
  188. package/dist/virtual.d.ts +2 -0
  189. package/dist/virtual.js +1 -0
  190. package/dist/watch-swipe-BIucfr9O.js +301 -0
  191. package/dist/watch-swipe-BIucfr9O.js.map +1 -0
  192. package/package.json +234 -3
@@ -0,0 +1,609 @@
1
+ import { n as stepIndex, t as edgeIndex } from "./list-navigation-CbWv4DK5.js";
2
+ // src/collection/activation-direction.ts
3
+ /**
4
+ * The physical direction from the previously selected tab to the new one, measured on the page
5
+ * (Base UI): `left` / `right` along a horizontal list, `up` / `down` along a vertical one, `none`
6
+ * when either tab is missing or both sit at the same place. In RTL the next tab sits on the left,
7
+ * so it gives `left`.
8
+ */
9
+ function activationDirection(previous, next, orientation) {
10
+ if (!previous || !next || previous === next) return "none";
11
+ const from = previous.getBoundingClientRect();
12
+ const to = next.getBoundingClientRect();
13
+ const [before, after] = orientation === "horizontal" ? [from.left, to.left] : [from.top, to.top];
14
+ if (after < before) return orientation === "horizontal" ? "left" : "up";
15
+ if (after > before) return orientation === "horizontal" ? "right" : "down";
16
+ return "none";
17
+ }
18
+ // src/collection/chip-keys.ts
19
+ /** The arrow that goes back (toward the first chip) and forward, for the direction. */
20
+ function chipArrows(rtl) {
21
+ return rtl ? {
22
+ previous: "ArrowRight",
23
+ next: "ArrowLeft"
24
+ } : {
25
+ previous: "ArrowLeft",
26
+ next: "ArrowRight"
27
+ };
28
+ }
29
+ /**
30
+ * The action of `key` on the chip at `index` of `count` chips, or `null` for a key it leaves
31
+ * alone. A printable character moves focus to the input, which receives it.
32
+ */
33
+ function chipKeyTarget(key, index, count, rtl) {
34
+ const arrows = chipArrows(rtl);
35
+ if (key === arrows.previous) return { focus: index > 0 ? index - 1 : "input" };
36
+ if (key === arrows.next) return { focus: index < count - 1 ? index + 1 : "input" };
37
+ if (key === "Backspace" || key === "Delete") {
38
+ const next = index >= count - 1 ? count - 2 : index;
39
+ return {
40
+ focus: next >= 0 ? next : "input",
41
+ remove: true
42
+ };
43
+ }
44
+ if (key === "Enter" || key === " ") return { focus: "input" };
45
+ if (key === "ArrowDown" || key === "ArrowUp") return {
46
+ focus: "input",
47
+ open: true
48
+ };
49
+ if (key.length === 1) return { focus: "input" };
50
+ return null;
51
+ }
52
+ // src/collection/combobox-items.ts
53
+ /** Whether an entry of `items` is a group (it carries an `items` array). */
54
+ function isItemGroup(entry) {
55
+ return typeof entry === "object" && entry !== null && Array.isArray(entry.items);
56
+ }
57
+ /** Every item of `items`, groups flattened, in order. */
58
+ function flattenItems(items) {
59
+ return items.flatMap((entry) => isItemGroup(entry) ? [...entry.items] : [entry]);
60
+ }
61
+ function serialize(item) {
62
+ if (item === null || item === void 0) return "";
63
+ return typeof item === "string" ? item : JSON.stringify(item) ?? "";
64
+ }
65
+ /**
66
+ * An item's text (`itemToStringLabel`): the consumer's function, else an object's `label`, else
67
+ * its `value`, else the item itself.
68
+ */
69
+ function itemLabel(item, itemToStringLabel) {
70
+ if (item === null || item === void 0) return "";
71
+ if (itemToStringLabel !== void 0) return itemToStringLabel(item) ?? "";
72
+ if (typeof item === "object") {
73
+ const record = item;
74
+ if (record.label !== null && record.label !== void 0) return String(record.label);
75
+ if ("value" in record) return String(record.value);
76
+ }
77
+ return typeof item === "string" ? item : serialize(item);
78
+ }
79
+ /**
80
+ * An item's form value (`itemToStringValue`): the consumer's function, else the `value` of an
81
+ * object with `value` and `label`, else the item as a string.
82
+ */
83
+ function itemFormValue(item, itemToStringValue) {
84
+ if (item === null || item === void 0) return "";
85
+ if (itemToStringValue !== void 0) return itemToStringValue(item) ?? "";
86
+ if (typeof item === "object" && "value" in item && "label" in item) return serialize(item.value);
87
+ return serialize(item);
88
+ }
89
+ const collators = /* @__PURE__ */ new Map();
90
+ function collator(locale) {
91
+ const key = locale ?? "";
92
+ let found = collators.get(key);
93
+ if (found === void 0) {
94
+ found = new Intl.Collator(locale, {
95
+ usage: "search",
96
+ sensitivity: "base",
97
+ ignorePunctuation: true
98
+ });
99
+ collators.set(key, found);
100
+ }
101
+ return found;
102
+ }
103
+ /** Whether `text` holds `query`, ignoring case, accents and punctuation (the locale's collator). */
104
+ function textContains(text, query, locale) {
105
+ if (query === "") return true;
106
+ const compare = collator(locale);
107
+ for (let start = 0; start <= text.length - query.length; start += 1) if (compare.compare(text.slice(start, start + query.length), query) === 0) return true;
108
+ return false;
109
+ }
110
+ /** The default `filter`: the item's label contains the query, for the locale. */
111
+ function containsFilter(locale) {
112
+ return (item, query, itemToString) => textContains(itemToString(item), query, locale);
113
+ }
114
+ /**
115
+ * Whether the query is the selected item's label: then a single combobox that just opened shows
116
+ * every item (spec/combobox.md, "The query").
117
+ */
118
+ function queryIsLabel(label, query, locale) {
119
+ return query !== "" && label.length === query.length && textContains(label, query, locale);
120
+ }
121
+ /**
122
+ * The entries a List renders for a query: the matching items, or the groups with their matching
123
+ * items (a group with none is left out), at most `limit` items in all.
124
+ */
125
+ function filterItems(items, query, options) {
126
+ const { filter, limit, itemToString } = options;
127
+ let left = limit < 0 ? Number.POSITIVE_INFINITY : limit;
128
+ const keep = (item) => query === "" || filter === null || filter(item, query, itemToString);
129
+ const take = (list) => {
130
+ const kept = [];
131
+ for (const item of list) {
132
+ if (left <= 0) break;
133
+ if (keep(item)) {
134
+ kept.push(item);
135
+ left -= 1;
136
+ }
137
+ }
138
+ return kept;
139
+ };
140
+ const entries = [];
141
+ for (const entry of items) {
142
+ if (left <= 0) break;
143
+ if (isItemGroup(entry)) {
144
+ const kept = take(entry.items);
145
+ if (kept.length > 0) entries.push({
146
+ ...entry,
147
+ items: kept
148
+ });
149
+ } else entries.push(...take([entry]));
150
+ }
151
+ return entries;
152
+ }
153
+ /** `isItemEqualToValue`, with `null` and `undefined` compared by identity. */
154
+ function itemsEqual(item, value, isEqual = Object.is) {
155
+ if (item === null || item === void 0 || value === null || value === void 0) return Object.is(item, value);
156
+ return isEqual(item, value);
157
+ }
158
+ /** Whether `item` is one of `values`. */
159
+ function includesItem(values, item, isEqual) {
160
+ return values.some((value) => itemsEqual(item, value, isEqual));
161
+ }
162
+ /** `values` with `item` added at the end, or removed when it is already one of them. */
163
+ function toggleItem(values, item, isEqual) {
164
+ return includesItem(values, item, isEqual) ? values.filter((value) => !itemsEqual(item, value, isEqual)) : [...values, item];
165
+ }
166
+ // src/collection/key-maps.ts
167
+ /**
168
+ * The tab a key moves focus to (spec/tabs.md, "Keyboard"): arrows along the orientation (mirrored
169
+ * in RTL), Home and End; `null` when the key does not move it. Disabled tabs are reachable.
170
+ */
171
+ function tabsKeyTarget(key, index, count, options) {
172
+ const next = options.orientation === "vertical" ? "ArrowDown" : options.rtl ? "ArrowLeft" : "ArrowRight";
173
+ const previous = options.orientation === "vertical" ? "ArrowUp" : options.rtl ? "ArrowRight" : "ArrowLeft";
174
+ if (key === next || key === previous) return stepIndex(count, index, key === next ? 1 : -1, { loop: options.loop });
175
+ if (key === "Home") return count > 0 ? 0 : null;
176
+ if (key === "End") return count > 0 ? count - 1 : null;
177
+ return null;
178
+ }
179
+ /**
180
+ * The Trigger a key moves focus to in an accordion (spec/accordion.md, "Keyboard"): the tabs' key
181
+ * map (arrows along the orientation, mirrored in RTL, Home and End) over the enabled Triggers the
182
+ * caller passes; `null` when the key does not move it.
183
+ */
184
+ function accordionKeyTarget(key, index, count, options) {
185
+ return tabsKeyTarget(key, index, count, options);
186
+ }
187
+ /**
188
+ * The item a key moves focus to in a menu (spec/menu.md, "Keyboard"): ArrowDown and ArrowUp (wrapping
189
+ * with `loop`), Home and End; `null` when the key does not move it. Disabled items are reachable.
190
+ */
191
+ function menuKeyTarget(key, index, count, options) {
192
+ if (key === "ArrowDown" || key === "ArrowUp") return stepIndex(count, index, key === "ArrowDown" ? 1 : -1, { loop: options.loop });
193
+ if (key === "Home") return count > 0 ? 0 : null;
194
+ if (key === "End") return count > 0 ? count - 1 : null;
195
+ return null;
196
+ }
197
+ /** The keys that open and close a submenu: the arrows toward and away from it. */
198
+ function submenuKeys(rtl) {
199
+ return rtl ? {
200
+ open: "ArrowLeft",
201
+ close: "ArrowRight"
202
+ } : {
203
+ open: "ArrowRight",
204
+ close: "ArrowLeft"
205
+ };
206
+ }
207
+ /**
208
+ * The radio an arrow key moves focus (and the check) to in a radio group (spec/radio-group.md,
209
+ * "Keyboard"): ArrowDown and ArrowRight the next, ArrowUp and ArrowLeft the previous, whatever the
210
+ * orientation (APG); in RTL, ArrowLeft is the next and ArrowRight the previous. Skipped radios are
211
+ * passed over. `null` when the key does not move it: another key, or an end without `loop`.
212
+ */
213
+ function radioKeyTarget(key, index, count, options) {
214
+ const forward = options.rtl ? key === "ArrowDown" || key === "ArrowLeft" : key === "ArrowDown" || key === "ArrowRight";
215
+ const backward = options.rtl ? key === "ArrowUp" || key === "ArrowRight" : key === "ArrowUp" || key === "ArrowLeft";
216
+ if (!forward && !backward) return null;
217
+ const target = stepIndex(count, index, forward ? 1 : -1, {
218
+ loop: options.loop,
219
+ skip: options.skip
220
+ });
221
+ return target === index || target === -1 ? null : target;
222
+ }
223
+ // src/collection/roving-focus.ts
224
+ /**
225
+ * The arrows of a roving composite (a toolbar, a toggle group, a menu bar; spec/toolbar.md,
226
+ * "Keyboard"): ArrowRight and ArrowLeft when horizontal (mirrored in RTL), ArrowDown and ArrowUp
227
+ * when vertical. A menu bar reads them to tell an arrow that moves to the neighbouring item.
228
+ */
229
+ function rovingKeys(orientation, rtl) {
230
+ if (orientation === "vertical") return {
231
+ next: "ArrowDown",
232
+ previous: "ArrowUp"
233
+ };
234
+ return rtl ? {
235
+ next: "ArrowLeft",
236
+ previous: "ArrowRight"
237
+ } : {
238
+ next: "ArrowRight",
239
+ previous: "ArrowLeft"
240
+ };
241
+ }
242
+ /**
243
+ * The item a key moves focus to in a roving composite of `count` items (spec/toolbar.md,
244
+ * spec/toggle-group.md, "Keyboard"): the next and previous arrows of the orientation (mirrored in
245
+ * RTL), passing over skipped items and wrapping with `loop` (without it, an arrow at an end gives
246
+ * `index` back); Home and End the first and last item not skipped. From no item (`index` -1), the
247
+ * next arrow gives the first item and the previous one the last. `null` when the key is none of
248
+ * these (the other orientation's arrows included), or when every item is skipped.
249
+ */
250
+ function rovingKeyTarget(key, index, count, options) {
251
+ const { next, previous } = rovingKeys(options.orientation, options.rtl);
252
+ const skip = options.skip ?? (() => false);
253
+ let target;
254
+ if (key === next || key === previous) {
255
+ target = stepIndex(count, index, key === next ? 1 : -1, {
256
+ loop: options.loop,
257
+ skip
258
+ });
259
+ if (target !== -1 && skip(target)) return null;
260
+ } else if (key === "Home" || key === "End") target = edgeIndex(count, key === "Home" ? "first" : "last", skip);
261
+ else return null;
262
+ return target === -1 ? null : target;
263
+ }
264
+ /**
265
+ * The item that holds a roving composite's tab stop (`tabindex="0"`, spec/toolbar.md, "Focus"):
266
+ * `preferred` (the item that last had focus) while it is in range and not skipped, else the first
267
+ * item not skipped; -1 when every item is skipped (the composite is then no tab stop).
268
+ */
269
+ function rovingTabStop(count, preferred, skip = () => false) {
270
+ if (preferred >= 0 && preferred < count && !skip(preferred)) return preferred;
271
+ return edgeIndex(count, "first", skip);
272
+ }
273
+ /** The `<input>` types whose caret the arrow keys move (they have a text selection). */
274
+ const TEXT_TYPES = [
275
+ "",
276
+ "text",
277
+ "search",
278
+ "url",
279
+ "tel",
280
+ "password"
281
+ ];
282
+ /** An enabled text field: a `<textarea>`, or an `<input>` of a text type, not `aria-disabled`. */
283
+ function textField(element) {
284
+ const tag = element.tagName;
285
+ if (tag !== "INPUT" && tag !== "TEXTAREA") return null;
286
+ const field = element;
287
+ if (field.disabled || element.getAttribute("aria-disabled") === "true" || tag === "INPUT" && !TEXT_TYPES.includes(field.type)) return null;
288
+ return field;
289
+ }
290
+ /**
291
+ * Whether a text field keeps a key a roving composite would act on (spec/toolbar.md, "A
292
+ * Toolbar.Input keeps its text keys", Base UI): while text is selected, every key; with a
293
+ * collapsed caret, the next arrow unless the caret is at the end, the previous arrow unless it is
294
+ * at the start, Home and End unless the text is empty. `false` for an element that is no enabled
295
+ * text field, and for any other key (the composite does not act on it anyway).
296
+ */
297
+ function textFieldKeepsKey(element, key, keys) {
298
+ const field = textField(element);
299
+ if (field === null) return false;
300
+ if (!(key === keys.next || key === keys.previous || key === "Home" || key === "End")) return false;
301
+ const start = field.selectionStart;
302
+ const end = field.selectionEnd;
303
+ if (start === null || end === null || start !== end) return true;
304
+ const length = field.value.length;
305
+ if (key === keys.next) return start < length;
306
+ if (key === keys.previous) return start > 0;
307
+ return length > 0;
308
+ }
309
+ /**
310
+ * The entries in their elements' document order (a roving composite's items registered in any
311
+ * order: spec/toolbar.md, "Nested composites"). The order is taken in one tree: the document's
312
+ * when an element is connected, else the first element's; the entries whose element is in another
313
+ * tree (disconnected) come last, in their relative order.
314
+ */
315
+ function inDocumentOrder(entries, element) {
316
+ const first = entries.find((entry) => element(entry).isConnected) ?? entries[0];
317
+ if (first === void 0) return [];
318
+ const tree = element(first).getRootNode();
319
+ const inTree = [];
320
+ const elsewhere = [];
321
+ for (const entry of entries) (element(entry).getRootNode() === tree ? inTree : elsewhere).push(entry);
322
+ inTree.sort((a, b) => {
323
+ const left = element(a);
324
+ const right = element(b);
325
+ if (left === right) return 0;
326
+ return left.compareDocumentPosition(right) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
327
+ });
328
+ return [...inTree, ...elsewhere];
329
+ }
330
+ // src/collection/scroll-into-view.ts
331
+ /**
332
+ * Scrolls the scrollable ancestors of `item`, up to `boundary` (included), so the item is in view
333
+ * at the nearest edge: a highlighted option inside its popup (spec/select.md, spec/combobox.md).
334
+ * Unlike `Element.scrollIntoView`, it never scrolls past `boundary`: a list that mounts before it
335
+ * is positioned (at the end of a tall page) does not scroll the page.
336
+ */
337
+ function scrollIntoViewWithin(item, boundary) {
338
+ if (boundary === null || !boundary.contains(item)) return;
339
+ const view = item.ownerDocument.defaultView;
340
+ for (let element = item.parentElement; element !== null; element = element.parentElement) {
341
+ const overflow = view?.getComputedStyle(element).overflowY ?? "";
342
+ if (element.scrollHeight > element.clientHeight && (overflow === "auto" || overflow === "scroll")) {
343
+ const top = element.getBoundingClientRect().top + element.clientTop;
344
+ const bottom = top + element.clientHeight;
345
+ const rect = item.getBoundingClientRect();
346
+ if (rect.top < top) element.scrollTop -= top - rect.top;
347
+ else if (rect.bottom > bottom) element.scrollTop += rect.bottom - bottom;
348
+ }
349
+ if (element === boundary) return;
350
+ }
351
+ }
352
+ // src/collection/segment-indicator.ts
353
+ /**
354
+ * The checked Item's box relative to the Root's padding box (where an absolute Indicator is placed
355
+ * from), as the Indicator's variables (spec/segmented-control.md, "API"): the logical ones
356
+ * (inline-start measured from the Root's right padding edge when `rtl`, the layout's direction)
357
+ * and the physical ones, every value in pixels.
358
+ */
359
+ function segmentIndicatorBox(root, item, rtl) {
360
+ const rootRect = root.getBoundingClientRect();
361
+ const itemRect = item.getBoundingClientRect();
362
+ const left = itemRect.left - rootRect.left - root.clientLeft;
363
+ const top = itemRect.top - rootRect.top - root.clientTop;
364
+ const right = root.clientWidth - left - itemRect.width;
365
+ const bottom = root.clientHeight - top - itemRect.height;
366
+ return {
367
+ "--segment-indicator-inset-inline-start": `${rtl ? right : left}px`,
368
+ "--segment-indicator-inset-block-start": `${top}px`,
369
+ "--segment-indicator-inline-size": `${itemRect.width}px`,
370
+ "--segment-indicator-block-size": `${itemRect.height}px`,
371
+ "--segment-indicator-left": `${left}px`,
372
+ "--segment-indicator-right": `${right}px`,
373
+ "--segment-indicator-top": `${top}px`,
374
+ "--segment-indicator-bottom": `${bottom}px`,
375
+ "--segment-indicator-width": `${itemRect.width}px`,
376
+ "--segment-indicator-height": `${itemRect.height}px`
377
+ };
378
+ }
379
+ /**
380
+ * Places a server-rendered SegmentedControl Indicator before hydration
381
+ * (spec/segmented-control.md, "Server rendering"; Base UI's `renderBeforeHydration`, as
382
+ * {@link placeTabsIndicator}). It runs as an inline script inside the Indicator, as the page
383
+ * parses: `script` is that script, which it removes. The Root and its checked Item are found by
384
+ * their part attributes. Self-contained (no import, no closure): a framework writes its source
385
+ * into the page, `` `(${placeSegmentIndicator})(document.currentScript)` ``. It sets the variables
386
+ * of {@link segmentIndicatorBox}, computed the same way.
387
+ */
388
+ function placeSegmentIndicator(script) {
389
+ const indicator = script?.parentElement;
390
+ script?.remove();
391
+ const root = indicator?.closest("[data-primitives-part=\"segmented-control-root\"]");
392
+ const item = root?.querySelector("[data-primitives-part=\"segmented-control-item\"][aria-checked=\"true\"]");
393
+ const view = indicator?.ownerDocument.defaultView;
394
+ if (!indicator || !root || !item || !view) return;
395
+ const rootRect = root.getBoundingClientRect();
396
+ const itemRect = item.getBoundingClientRect();
397
+ const rtl = view.getComputedStyle(root).direction === "rtl";
398
+ const left = itemRect.left - rootRect.left - root.clientLeft;
399
+ const top = itemRect.top - rootRect.top - root.clientTop;
400
+ const right = root.clientWidth - left - itemRect.width;
401
+ [
402
+ ["inset-inline-start", rtl ? right : left],
403
+ ["inset-block-start", top],
404
+ ["inline-size", itemRect.width],
405
+ ["block-size", itemRect.height],
406
+ ["left", left],
407
+ ["right", right],
408
+ ["top", top],
409
+ ["bottom", root.clientHeight - top - itemRect.height],
410
+ ["width", itemRect.width],
411
+ ["height", itemRect.height]
412
+ ].forEach(([name, value]) => {
413
+ indicator.style.setProperty(`--segment-indicator-${name}`, `${value}px`);
414
+ });
415
+ }
416
+ // src/collection/tabs-indicator.ts
417
+ /**
418
+ * The selected tab's box relative to its list, as the Indicator's variables (spec/tabs.md, "API"):
419
+ * the logical ones (inline-start measured from the list's right edge when `rtl`, the layout's
420
+ * direction) and Base UI's physical ones, every value in pixels.
421
+ */
422
+ function tabsIndicatorBox(list, tab, rtl) {
423
+ const listRect = list.getBoundingClientRect();
424
+ const tabRect = tab.getBoundingClientRect();
425
+ const left = tabRect.left - listRect.left;
426
+ const right = listRect.right - tabRect.right;
427
+ const top = tabRect.top - listRect.top;
428
+ const bottom = listRect.bottom - tabRect.bottom;
429
+ return {
430
+ "--tabs-indicator-inset-inline-start": `${rtl ? right : left}px`,
431
+ "--tabs-indicator-inset-block-start": `${top}px`,
432
+ "--tabs-indicator-inline-size": `${tabRect.width}px`,
433
+ "--tabs-indicator-block-size": `${tabRect.height}px`,
434
+ "--active-tab-left": `${left}px`,
435
+ "--active-tab-right": `${right}px`,
436
+ "--active-tab-top": `${top}px`,
437
+ "--active-tab-bottom": `${bottom}px`,
438
+ "--active-tab-width": `${tabRect.width}px`,
439
+ "--active-tab-height": `${tabRect.height}px`
440
+ };
441
+ }
442
+ /**
443
+ * Places a server-rendered Tabs Indicator before hydration (spec/tabs.md, "Server rendering"; Base
444
+ * UI's `renderBeforeHydration`). It runs as an inline script inside the Indicator, as the page
445
+ * parses: `script` is that script, which it removes, so the hydration finds the Indicator as the
446
+ * client renders it. The selected tab is the list's `aria-selected="true"` tab. Self-contained (no
447
+ * import, no closure): a framework writes its source into the page,
448
+ * `` `(${placeTabsIndicator})(document.currentScript)` ``. It sets the variables of
449
+ * {@link tabsIndicatorBox}, computed the same way.
450
+ */
451
+ function placeTabsIndicator(script) {
452
+ const indicator = script?.parentElement;
453
+ script?.remove();
454
+ const list = indicator?.closest("[role=\"tablist\"]");
455
+ const tab = list?.querySelector("[role=\"tab\"][aria-selected=\"true\"]");
456
+ const view = indicator?.ownerDocument.defaultView;
457
+ if (!indicator || !list || !tab || !view) return;
458
+ const listRect = list.getBoundingClientRect();
459
+ const tabRect = tab.getBoundingClientRect();
460
+ const rtl = view.getComputedStyle(list).direction === "rtl";
461
+ const left = tabRect.left - listRect.left;
462
+ const right = listRect.right - tabRect.right;
463
+ const top = tabRect.top - listRect.top;
464
+ [
465
+ ["--tabs-indicator-inset-inline-start", rtl ? right : left],
466
+ ["--tabs-indicator-inset-block-start", top],
467
+ ["--tabs-indicator-inline-size", tabRect.width],
468
+ ["--tabs-indicator-block-size", tabRect.height],
469
+ ["--active-tab-left", left],
470
+ ["--active-tab-right", right],
471
+ ["--active-tab-top", top],
472
+ ["--active-tab-bottom", listRect.bottom - tabRect.bottom],
473
+ ["--active-tab-width", tabRect.width],
474
+ ["--active-tab-height", tabRect.height]
475
+ ].forEach(([name, value]) => {
476
+ indicator.style.setProperty(name, `${value}px`);
477
+ });
478
+ }
479
+ // src/collection/tag-keys.ts
480
+ /**
481
+ * The action of a key on the tag at `index` of a TagGroup's `count` tags (spec/tag-group.md,
482
+ * "Keyboard"), or `null` for a key it leaves alone: the next tag is ArrowRight (ArrowLeft in RTL)
483
+ * and ArrowDown, the previous one ArrowLeft (ArrowRight in RTL) and ArrowUp, passing over the
484
+ * skipped tags and wrapping with `loop`; Home and End the first and last tag not skipped; Space
485
+ * and Enter select; Delete and Backspace remove. A key with a modifier does nothing.
486
+ */
487
+ function tagGroupKeyTarget(event, index, count, options) {
488
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return null;
489
+ const { key } = event;
490
+ if (key === " " || key === "Enter") return options.selectable ? { type: "select" } : null;
491
+ if (key === "Delete" || key === "Backspace") return options.removable ? { type: "remove" } : null;
492
+ const roving = {
493
+ orientation: "horizontal",
494
+ rtl: options.rtl,
495
+ loop: options.loop,
496
+ ...options.skip === void 0 ? {} : { skip: options.skip }
497
+ };
498
+ const moved = key === "ArrowDown" ? rovingKeyTarget(options.rtl ? "ArrowLeft" : "ArrowRight", index, count, roving) : key === "ArrowUp" ? rovingKeyTarget(options.rtl ? "ArrowRight" : "ArrowLeft", index, count, roving) : rovingKeyTarget(key, index, count, roving);
499
+ return moved === null ? null : {
500
+ type: "focus",
501
+ index: moved
502
+ };
503
+ }
504
+ /**
505
+ * Where the focus goes once the item at `removed` of `count` items is gone (spec/tag-group.md,
506
+ * "Focus"): the first item after it not skipped, else the last one before it not skipped, else -1
507
+ * (the container). The index is the item's in the list before the removal.
508
+ */
509
+ function removalFocusIndex(count, removed, skip = () => false) {
510
+ for (let index = removed + 1; index < count; index++) if (!skip(index)) return index;
511
+ for (let index = Math.min(removed, count) - 1; index >= 0; index--) if (!skip(index)) return index;
512
+ return -1;
513
+ }
514
+ /** The arrows that move toward the first tag and toward the Input, for the direction. */
515
+ function tagArrows(rtl) {
516
+ return rtl ? {
517
+ previous: "ArrowRight",
518
+ next: "ArrowLeft"
519
+ } : {
520
+ previous: "ArrowLeft",
521
+ next: "ArrowRight"
522
+ };
523
+ }
524
+ /**
525
+ * The action of a key in a TagsInput's Input of `count` tags, or `null` for a key it leaves to the
526
+ * input: Enter adds (the caller checks the text is not blank); Backspace and the previous arrow,
527
+ * with the caret at the start and no text selected, focus the last tag. A key with Ctrl, Meta or
528
+ * Alt does nothing.
529
+ */
530
+ function tagsInputInputKeyTarget(event, caret, count, rtl) {
531
+ if (event.altKey || event.ctrlKey || event.metaKey) return null;
532
+ if (event.key === "Enter") return { type: "add" };
533
+ if (caret.selectionStart === 0 && caret.selectionEnd === 0 && count > 0 && !event.shiftKey && (event.key === "Backspace" || event.key === tagArrows(rtl).previous)) return {
534
+ type: "focus-tag",
535
+ index: count - 1
536
+ };
537
+ return null;
538
+ }
539
+ /**
540
+ * The action of a key on the tag at `index` of a TagsInput's `count` tags (spec/tags-input.md,
541
+ * "Keyboard"), or `null` for a key it leaves alone: the previous arrow focuses the previous tag
542
+ * (none on the first), the next arrow the next tag or, past the last, the Input; Backspace removes
543
+ * it and focuses the previous tag, else the one now at its place, else the Input; Delete removes it
544
+ * and focuses the one now at its place, else the previous tag, else the Input; Enter edits it when
545
+ * `editable`; Escape focuses the Input; a printable character goes to the Input. A key with Ctrl,
546
+ * Meta or Alt does nothing.
547
+ */
548
+ function tagsInputTagKeyTarget(event, index, count, options) {
549
+ if (event.altKey || event.ctrlKey || event.metaKey) return null;
550
+ const { key } = event;
551
+ const arrows = tagArrows(options.rtl);
552
+ if (key === arrows.previous) return index > 0 ? {
553
+ type: "focus",
554
+ target: index - 1
555
+ } : null;
556
+ if (key === arrows.next) return {
557
+ type: "focus",
558
+ target: index < count - 1 ? index + 1 : "input"
559
+ };
560
+ const left = count - 1;
561
+ if (key === "Backspace") return {
562
+ type: "remove",
563
+ focus: index > 0 ? index - 1 : left > 0 ? 0 : "input"
564
+ };
565
+ if (key === "Delete") return {
566
+ type: "remove",
567
+ focus: index < left ? index : left > 0 ? left - 1 : "input"
568
+ };
569
+ if (key === "Enter") return options.editable ? { type: "edit" } : null;
570
+ if (key === "Escape") return {
571
+ type: "focus",
572
+ target: "input"
573
+ };
574
+ if (key.length === 1) return { type: "type" };
575
+ return null;
576
+ }
577
+ // src/collection/typeahead.ts
578
+ /**
579
+ * Typeahead for lists (spec/menu.md): characters typed within `timeout` ms accumulate; repeating
580
+ * one character cycles through the items starting with it.
581
+ */
582
+ function createTypeahead(timeout = 500) {
583
+ let buffer = "";
584
+ let last = 0;
585
+ return {
586
+ /** The index of the item to move to for `key`, or -1. `labels[i]` is item i's text. */
587
+ match(key, labels, current, now = Date.now()) {
588
+ if (key.length !== 1 || labels.length === 0) return -1;
589
+ buffer = now - last > timeout ? key : buffer + key;
590
+ last = now;
591
+ const lower = buffer.toLowerCase();
592
+ const repeated = [...lower].every((character) => character === lower[0]);
593
+ const query = repeated ? lower[0] ?? "" : lower;
594
+ const start = repeated || buffer.length === 1 ? current + 1 : Math.max(current, 0);
595
+ for (let offset = 0; offset < labels.length; offset++) {
596
+ const index = (start + offset) % labels.length;
597
+ if ((labels[index] ?? "").trim().toLowerCase().startsWith(query)) return index;
598
+ }
599
+ return -1;
600
+ },
601
+ reset() {
602
+ buffer = "";
603
+ last = 0;
604
+ }
605
+ };
606
+ }
607
+ export { textContains as A, flattenItems as C, itemLabel as D, itemFormValue as E, chipArrows as M, chipKeyTarget as N, itemsEqual as O, activationDirection as P, filterItems as S, isItemGroup as T, menuKeyTarget as _, tagsInputTagKeyTarget as a, tabsKeyTarget as b, placeSegmentIndicator as c, inDocumentOrder as d, rovingKeyTarget as f, accordionKeyTarget as g, textFieldKeepsKey as h, tagsInputInputKeyTarget as i, toggleItem as j, queryIsLabel as k, segmentIndicatorBox as l, rovingTabStop as m, removalFocusIndex as n, placeTabsIndicator as o, rovingKeys as p, tagGroupKeyTarget as r, tabsIndicatorBox as s, createTypeahead as t, scrollIntoViewWithin as u, radioKeyTarget as v, includesItem as w, containsFilter as x, submenuKeys as y };
608
+
609
+ //# sourceMappingURL=collection-Dbk-PB5S.js.map