@stacksjs/components 0.2.867 → 0.2.869

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 (109) hide show
  1. package/dist/AppearancePicker-61r20jpp.stx +351 -0
  2. package/dist/{Button-sebyqeva.stx → Button-pg8mzsq3.stx} +249 -0
  3. package/dist/Checkbox-52mhrzkz.stx +417 -0
  4. package/dist/ColorSwatches-ecfxphjy.stx +287 -0
  5. package/dist/{NumberInput-axcfj9y8.stx → NumberInput-e2afxyh3.stx} +303 -0
  6. package/dist/{PasswordInput-8m3109tp.stx → PasswordInput-n2ven456.stx} +315 -0
  7. package/dist/RadioGroup-ps9kn22f.stx +329 -0
  8. package/dist/RadioGroupOption-6hyy1bvb.stx +246 -0
  9. package/dist/{SegmentedControl-fr69q4gb.stx → SegmentedControl-7q0t8c9s.stx} +170 -1
  10. package/dist/{Select-1cnqbcmg.stx → Select-ygzchedx.stx} +266 -0
  11. package/dist/SettingsGroup-dkae46k5.stx +200 -0
  12. package/dist/SettingsPane-jbd1gbdt.stx +50 -0
  13. package/dist/SettingsPaneHeader-f0cvkqs7.stx +188 -0
  14. package/dist/SettingsRow-4cxbsf1q.stx +424 -0
  15. package/dist/SettingsSidebarGroup-p2ygv5yy.stx +108 -0
  16. package/dist/SettingsSidebarItem-x8fsn3w5.stx +228 -0
  17. package/dist/SettingsWindow-mm490ymt.stx +537 -0
  18. package/dist/Slider-j59dgw1c.stx +377 -0
  19. package/dist/Switch-ga9ap8n8.stx +374 -0
  20. package/dist/{TextInput-tsvfwxmg.stx → TextInput-tyqzz3jy.stx} +325 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +35 -24
  23. package/dist/settings/settings.js +757 -0
  24. package/dist/ui/appearance-picker/AppearancePicker.d.ts +12 -0
  25. package/dist/ui/appearance-picker/index.d.ts +16 -0
  26. package/dist/ui/button/Button.d.ts +24 -1
  27. package/dist/ui/button/index.d.ts +1 -0
  28. package/dist/ui/checkbox/Checkbox.d.ts +9 -1
  29. package/dist/ui/checkbox/index.d.ts +1 -0
  30. package/dist/ui/color-swatches/ColorSwatches.d.ts +26 -0
  31. package/dist/ui/color-swatches/index.d.ts +18 -0
  32. package/dist/ui/input/NumberInput.d.ts +11 -1
  33. package/dist/ui/input/PasswordInput.d.ts +9 -1
  34. package/dist/ui/input/TextInput.d.ts +12 -1
  35. package/dist/ui/input/index.d.ts +7 -3
  36. package/dist/ui/radio-group/RadioGroup.d.ts +14 -2
  37. package/dist/ui/radio-group/RadioGroupOption.d.ts +6 -1
  38. package/dist/ui/radio-group/index.d.ts +2 -0
  39. package/dist/ui/segmented-control/SegmentedControl.d.ts +9 -1
  40. package/dist/ui/segmented-control/index.d.ts +1 -0
  41. package/dist/ui/select/Select.d.ts +10 -1
  42. package/dist/ui/select/index.d.ts +1 -0
  43. package/dist/ui/settings/SettingsGroup.d.ts +30 -0
  44. package/dist/ui/settings/SettingsPane.d.ts +19 -0
  45. package/dist/ui/settings/SettingsPaneHeader.d.ts +20 -0
  46. package/dist/ui/settings/SettingsRow.d.ts +53 -0
  47. package/dist/ui/settings/SettingsSidebarGroup.d.ts +11 -0
  48. package/dist/ui/settings/SettingsSidebarItem.d.ts +22 -0
  49. package/dist/ui/settings/SettingsWindow.d.ts +22 -0
  50. package/dist/ui/settings/core.d.ts +146 -0
  51. package/dist/ui/settings/index.d.ts +73 -0
  52. package/dist/ui/settings/settings.d.ts +8 -0
  53. package/dist/ui/settings/view.d.ts +36 -0
  54. package/dist/ui/slider/Slider.d.ts +24 -0
  55. package/dist/ui/slider/core.d.ts +33 -0
  56. package/dist/ui/slider/index.d.ts +20 -0
  57. package/dist/ui/switch/Switch.d.ts +10 -1
  58. package/dist/ui/switch/index.d.ts +2 -1
  59. package/dist/utils/mac-theme.d.ts +24 -0
  60. package/package.json +8 -3
  61. package/src/index.ts +6 -0
  62. package/src/ui/appearance-picker/AppearancePicker.stx +351 -0
  63. package/src/ui/appearance-picker/README.md +61 -0
  64. package/src/ui/appearance-picker/index.ts +22 -0
  65. package/src/ui/button/Button.stx +249 -0
  66. package/src/ui/button/README.md +21 -0
  67. package/src/ui/button/index.ts +8 -0
  68. package/src/ui/checkbox/Checkbox.stx +275 -0
  69. package/src/ui/checkbox/index.ts +2 -0
  70. package/src/ui/color-swatches/ColorSwatches.stx +287 -0
  71. package/src/ui/color-swatches/README.md +66 -0
  72. package/src/ui/color-swatches/index.ts +25 -0
  73. package/src/ui/input/NumberInput.stx +303 -0
  74. package/src/ui/input/PasswordInput.stx +315 -0
  75. package/src/ui/input/TextInput.stx +325 -0
  76. package/src/ui/input/index.ts +9 -3
  77. package/src/ui/radio-group/README.md +17 -0
  78. package/src/ui/radio-group/RadioGroup.stx +184 -6
  79. package/src/ui/radio-group/RadioGroupOption.stx +178 -2
  80. package/src/ui/radio-group/index.ts +4 -0
  81. package/src/ui/segmented-control/SegmentedControl.stx +170 -1
  82. package/src/ui/segmented-control/index.ts +2 -0
  83. package/src/ui/select/README.md +12 -0
  84. package/src/ui/select/Select.stx +266 -0
  85. package/src/ui/select/index.ts +2 -0
  86. package/src/ui/settings/README.md +221 -0
  87. package/src/ui/settings/SettingsGroup.stx +200 -0
  88. package/src/ui/settings/SettingsPane.stx +50 -0
  89. package/src/ui/settings/SettingsPaneHeader.stx +188 -0
  90. package/src/ui/settings/SettingsRow.stx +424 -0
  91. package/src/ui/settings/SettingsSidebarGroup.stx +108 -0
  92. package/src/ui/settings/SettingsSidebarItem.stx +228 -0
  93. package/src/ui/settings/SettingsWindow.stx +537 -0
  94. package/src/ui/settings/core.ts +359 -0
  95. package/src/ui/settings/index.ts +111 -0
  96. package/src/ui/settings/settings.ts +8 -0
  97. package/src/ui/settings/view.ts +740 -0
  98. package/src/ui/slider/README.md +91 -0
  99. package/src/ui/slider/Slider.stx +377 -0
  100. package/src/ui/slider/core.ts +120 -0
  101. package/src/ui/slider/index.ts +34 -0
  102. package/src/ui/switch/README.md +11 -0
  103. package/src/ui/switch/Switch.stx +217 -0
  104. package/src/ui/switch/index.ts +4 -1
  105. package/src/utils/mac-theme.ts +95 -0
  106. package/dist/Checkbox-80myyzzm.stx +0 -142
  107. package/dist/RadioGroup-smqcqgds.stx +0 -151
  108. package/dist/RadioGroupOption-twcw1b2a.stx +0 -70
  109. package/dist/Switch-s8yf2rvm.stx +0 -157
@@ -0,0 +1,757 @@
1
+ // src/ui/settings/core.ts
2
+ var SETTINGS_RANK = { NONE: 0, KEYWORD: 1, SUBSTRING: 2, WORD_PREFIX: 3, PREFIX: 4 };
3
+ var SETTINGS_TYPE_AHEAD_MS = 700;
4
+ var SETTINGS_HIGHLIGHT_MS = 1600;
5
+ function settingsStorageName(key) {
6
+ return `stx:settings:${key}`;
7
+ }
8
+ function findSettingsPane(panes, id) {
9
+ if (!id)
10
+ return null;
11
+ return panes.find((pane) => pane.id === id) ?? null;
12
+ }
13
+ function firstSettingsPane(panes) {
14
+ const top = panes.find((pane) => !pane.parent);
15
+ return (top ?? panes[0])?.id ?? "";
16
+ }
17
+ function resolveSettingsPane(panes, ...wanted) {
18
+ for (const id of wanted) {
19
+ if (findSettingsPane(panes, id))
20
+ return id;
21
+ }
22
+ return firstSettingsPane(panes);
23
+ }
24
+ function settingsSidebarPane(panes, id) {
25
+ const seen = new Set;
26
+ let current = findSettingsPane(panes, id);
27
+ while (current && current.parent && !seen.has(current.id)) {
28
+ seen.add(current.id);
29
+ const parent = findSettingsPane(panes, current.parent);
30
+ if (!parent)
31
+ break;
32
+ current = parent;
33
+ }
34
+ return current?.id ?? "";
35
+ }
36
+ function settingsParentPane(panes, id) {
37
+ const pane = findSettingsPane(panes, id);
38
+ if (!pane?.parent || pane.parent === id)
39
+ return "";
40
+ return findSettingsPane(panes, pane.parent) ? pane.parent : "";
41
+ }
42
+ function emptySettingsHistory() {
43
+ return { trail: [], cursor: -1 };
44
+ }
45
+ function settingsHistoryCurrent(history) {
46
+ return history.trail[history.cursor] ?? "";
47
+ }
48
+ function settingsHistoryVisit(history, id) {
49
+ if (!id || settingsHistoryCurrent(history) === id)
50
+ return history;
51
+ const trail = [...history.trail.slice(0, history.cursor + 1), id];
52
+ return { trail, cursor: trail.length - 1 };
53
+ }
54
+ function settingsCanGoForward(history) {
55
+ return history.cursor < history.trail.length - 1;
56
+ }
57
+ function settingsCanGoBack(history, panes = []) {
58
+ if (history.cursor > 0)
59
+ return true;
60
+ return history.cursor === 0 && settingsParentPane(panes, settingsHistoryCurrent(history)) !== "";
61
+ }
62
+ function settingsHistoryBack(history, panes = []) {
63
+ if (history.cursor > 0)
64
+ return { trail: history.trail, cursor: history.cursor - 1 };
65
+ if (history.cursor === 0) {
66
+ const parent = settingsParentPane(panes, settingsHistoryCurrent(history));
67
+ if (parent)
68
+ return { trail: [parent, ...history.trail], cursor: 0 };
69
+ }
70
+ return history;
71
+ }
72
+ function settingsHistoryForward(history) {
73
+ return settingsCanGoForward(history) ? { trail: history.trail, cursor: history.cursor + 1 } : history;
74
+ }
75
+ function normalizeSettingsText(text) {
76
+ return String(text ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
77
+ }
78
+ function wordStarts(text, needle) {
79
+ let from = text.indexOf(needle);
80
+ while (from !== -1) {
81
+ if (from === 0 || !/[\p{L}\p{N}]/u.test(text.charAt(from - 1)))
82
+ return true;
83
+ from = text.indexOf(needle, from + 1);
84
+ }
85
+ return false;
86
+ }
87
+ function rankOne(needle, label, keywords) {
88
+ if (label.startsWith(needle))
89
+ return SETTINGS_RANK.PREFIX;
90
+ if (wordStarts(label, needle))
91
+ return SETTINGS_RANK.WORD_PREFIX;
92
+ if (label.includes(needle))
93
+ return SETTINGS_RANK.SUBSTRING;
94
+ if (wordStarts(keywords, needle))
95
+ return SETTINGS_RANK.KEYWORD;
96
+ return SETTINGS_RANK.NONE;
97
+ }
98
+ function settingsMatchRank(query, label, keywords = "") {
99
+ const needle = normalizeSettingsText(query);
100
+ if (needle === "")
101
+ return SETTINGS_RANK.NONE;
102
+ const text = normalizeSettingsText(label);
103
+ const extra = normalizeSettingsText(keywords);
104
+ const whole = rankOne(needle, text, extra);
105
+ const words = needle.split(" ");
106
+ if (whole !== SETTINGS_RANK.NONE || words.length === 1)
107
+ return whole;
108
+ let weakest = SETTINGS_RANK.PREFIX;
109
+ for (const word of words) {
110
+ const rank = rankOne(word, text, extra);
111
+ if (rank === SETTINGS_RANK.NONE)
112
+ return SETTINGS_RANK.NONE;
113
+ weakest = Math.min(weakest, rank === SETTINGS_RANK.PREFIX && word !== words[0] ? SETTINGS_RANK.WORD_PREFIX : rank);
114
+ }
115
+ return weakest;
116
+ }
117
+ function searchSettings(query, index) {
118
+ const text = normalizeSettingsText(query);
119
+ if (text === "")
120
+ return { query: "", panes: [], settings: [] };
121
+ const panes = [];
122
+ for (const item of index.items) {
123
+ const pane = findSettingsPane(index.panes, item.id);
124
+ const keywords = `${item.keywords ?? ""} ${pane?.keywords ?? ""} ${pane && pane.title !== item.label ? pane.title : ""}`;
125
+ if (settingsMatchRank(text, item.label, keywords) !== SETTINGS_RANK.NONE)
126
+ panes.push(item.id);
127
+ }
128
+ const settings = [];
129
+ index.rows.forEach((row, position) => {
130
+ if (!row.label)
131
+ return;
132
+ const pane = findSettingsPane(index.panes, row.pane);
133
+ const paneTitle = pane?.title ?? "";
134
+ const rank = settingsMatchRank(text, row.label, `${row.keywords ?? ""} ${paneTitle}`);
135
+ if (rank !== SETTINGS_RANK.NONE)
136
+ settings.push({ id: row.id, label: row.label, pane: row.pane, paneTitle, row: position, rank });
137
+ });
138
+ settings.sort((a, b) => b.rank - a.rank || a.row - b.row);
139
+ return { query: text, panes, settings };
140
+ }
141
+ function settingsResultsAnnouncement(count) {
142
+ if (count <= 0)
143
+ return "No results";
144
+ return count === 1 ? "1 result" : `${count} results`;
145
+ }
146
+ function settingsRovingIndex(key, index, count) {
147
+ if (count <= 0)
148
+ return -1;
149
+ if (key === "ArrowDown")
150
+ return Math.min(count - 1, index + 1);
151
+ if (key === "ArrowUp")
152
+ return index < 0 ? count - 1 : Math.max(0, index - 1);
153
+ if (key === "Home")
154
+ return 0;
155
+ if (key === "End")
156
+ return count - 1;
157
+ return -1;
158
+ }
159
+ function settingsTypeAheadAdd(state, character, now, timeout = SETTINGS_TYPE_AHEAD_MS) {
160
+ const fresh = !state || now - state.at > timeout;
161
+ return { buffer: (fresh ? "" : state.buffer) + normalizeSettingsText(character), at: now };
162
+ }
163
+ function settingsTypeAheadMatch(labels, buffer, current) {
164
+ const count = labels.length;
165
+ const typed = normalizeSettingsText(buffer);
166
+ if (count === 0 || typed === "")
167
+ return -1;
168
+ const repeated = typed.split("").every((letter) => letter === typed.charAt(0));
169
+ const needle = repeated ? typed.charAt(0) : typed;
170
+ const start = repeated ? current + 1 : Math.max(0, current);
171
+ for (let offset = 0;offset < count; offset++) {
172
+ const index = ((start + offset) % count + count) % count;
173
+ if (normalizeSettingsText(labels[index]).startsWith(needle))
174
+ return index;
175
+ }
176
+ return -1;
177
+ }
178
+ // src/ui/settings/view.ts
179
+ var ROOT = "[data-stx-settings]";
180
+ var ITEM = "[data-settings-item]";
181
+ var PANE = "[data-settings-pane]";
182
+ var ROW = "[data-settings-row]";
183
+ var RESULT = "[data-settings-result]";
184
+ var CONTROLS = 'button, a[href], input, select, textarea, label, [role="switch"], [role="checkbox"], [role="radio"], [role="slider"], [role="button"], [contenteditable]';
185
+ function domId(text) {
186
+ return text.replace(/[^\w-]+/g, "-");
187
+ }
188
+
189
+ class SettingsWindowView {
190
+ root;
191
+ callbacks;
192
+ history = emptySettingsHistory();
193
+ current = "";
194
+ query = "";
195
+ storageKey;
196
+ typed = null;
197
+ hits = [];
198
+ highlighted = null;
199
+ highlightTimer = null;
200
+ disposers = [];
201
+ list;
202
+ account;
203
+ input;
204
+ field;
205
+ results;
206
+ empty;
207
+ live;
208
+ backButton;
209
+ forwardButton;
210
+ title;
211
+ body;
212
+ constructor(root, options = {}, callbacks = {}) {
213
+ this.root = root;
214
+ this.callbacks = callbacks;
215
+ this.storageKey = options.storageKey || "";
216
+ if (!root.id)
217
+ root.id = `settings-${Math.random().toString(36).slice(2, 8)}`;
218
+ this.list = this.own("[data-settings-list]");
219
+ this.account = this.own("[data-settings-account]");
220
+ this.input = this.own("[data-settings-search-input]");
221
+ this.field = this.own("[data-settings-search]");
222
+ this.results = this.own("[data-settings-results]");
223
+ this.empty = this.own("[data-settings-empty]");
224
+ this.live = this.own("[data-settings-live]");
225
+ this.backButton = this.own("[data-settings-back]");
226
+ this.forwardButton = this.own("[data-settings-forward]");
227
+ this.title = this.own("[data-settings-title]");
228
+ this.body = this.own("[data-settings-body]");
229
+ for (const filled of [this.results, this.live, this.title]) {
230
+ if (filled)
231
+ filled.__stx_inert_content = true;
232
+ }
233
+ this.listen(root, "click", (event) => this.onClick(event));
234
+ this.listen(options.globalKeys ? document : root, "keydown", (event) => this.onKeyDown(event));
235
+ if (this.input)
236
+ this.listen(this.input, "input", () => this.search(this.input.value));
237
+ if (this.body)
238
+ this.listen(this.body, "scroll", () => this.syncScrolled(), { passive: true });
239
+ this.listen(window, "focus", () => root.setAttribute("data-stx-window-active", "true"));
240
+ this.listen(window, "blur", () => root.setAttribute("data-stx-window-active", "false"));
241
+ this.describe();
242
+ const panes = this.panes();
243
+ const shown = this.paneElements().find((pane) => !pane.hidden)?.getAttribute("data-settings-pane");
244
+ this.open(resolveSettingsPane(panes, this.stored(), options.pane, shown));
245
+ root.setAttribute("data-settings-ready", "");
246
+ }
247
+ getPane() {
248
+ return this.current;
249
+ }
250
+ showPane(id) {
251
+ if (!findSettingsPane(this.panes(), id))
252
+ return false;
253
+ this.open(id);
254
+ return true;
255
+ }
256
+ revealSetting(id) {
257
+ if (!id)
258
+ return false;
259
+ const row = this.rowElements().find((element) => element.getAttribute("data-setting") === id);
260
+ const pane = row ? this.paneOf(row) : "";
261
+ if (!row || !pane)
262
+ return false;
263
+ this.open(pane);
264
+ this.reveal(row);
265
+ return true;
266
+ }
267
+ back() {
268
+ this.travel(settingsHistoryBack(this.history, this.panes()));
269
+ }
270
+ forward() {
271
+ this.travel(settingsHistoryForward(this.history));
272
+ }
273
+ focusSearch() {
274
+ if (!this.input)
275
+ return;
276
+ this.input.focus();
277
+ this.input.select();
278
+ }
279
+ search(query) {
280
+ this.query = query;
281
+ if (this.input && this.input.value !== query)
282
+ this.input.value = query;
283
+ this.applySearch(true);
284
+ }
285
+ destroy() {
286
+ for (const dispose of this.disposers)
287
+ dispose();
288
+ this.disposers.length = 0;
289
+ this.clearHighlight();
290
+ this.root.removeAttribute("data-settings-ready");
291
+ }
292
+ own(selector) {
293
+ return this.all(selector)[0] ?? null;
294
+ }
295
+ all(selector, within = this.root) {
296
+ return Array.from(within.querySelectorAll(selector)).filter((element) => element.closest(ROOT) === this.root);
297
+ }
298
+ listen(target, type, handler, options) {
299
+ target.addEventListener(type, handler, options);
300
+ this.disposers.push(() => target.removeEventListener(type, handler, options));
301
+ }
302
+ paneElements() {
303
+ return this.all(PANE);
304
+ }
305
+ paneElement(id) {
306
+ return this.paneElements().find((pane) => pane.getAttribute("data-settings-pane") === id) ?? null;
307
+ }
308
+ panes() {
309
+ return this.paneElements().map((pane) => ({
310
+ id: pane.getAttribute("data-settings-pane") || "",
311
+ title: pane.getAttribute("data-title") || pane.getAttribute("data-settings-pane") || "",
312
+ keywords: pane.getAttribute("data-keywords") || "",
313
+ parent: pane.getAttribute("data-parent") || ""
314
+ })).filter((pane) => pane.id !== "");
315
+ }
316
+ itemElements() {
317
+ return this.list ? this.all(ITEM, this.list) : [];
318
+ }
319
+ visibleItems() {
320
+ return this.itemElements().filter((item) => !item.hidden && !item.disabled);
321
+ }
322
+ labelOf(item) {
323
+ return (item.querySelector(".stx-settings-item-label")?.textContent || item.getAttribute("aria-label") || item.textContent || "").trim();
324
+ }
325
+ items() {
326
+ return this.itemElements().map((item) => ({
327
+ id: item.getAttribute("data-settings-item") || "",
328
+ label: this.labelOf(item),
329
+ keywords: item.getAttribute("data-keywords") || ""
330
+ }));
331
+ }
332
+ rowElements() {
333
+ return this.all(ROW).filter((row) => this.paneOf(row) !== "");
334
+ }
335
+ paneOf(element) {
336
+ return element.closest(PANE)?.getAttribute("data-settings-pane") || "";
337
+ }
338
+ stored() {
339
+ if (!this.storageKey)
340
+ return "";
341
+ try {
342
+ return localStorage.getItem(settingsStorageName(this.storageKey)) || "";
343
+ } catch {
344
+ return "";
345
+ }
346
+ }
347
+ store() {
348
+ if (!this.storageKey || !this.current)
349
+ return;
350
+ try {
351
+ localStorage.setItem(settingsStorageName(this.storageKey), this.current);
352
+ } catch {}
353
+ }
354
+ describe() {
355
+ const prefix = this.root.id;
356
+ const items = new Map;
357
+ for (const item of this.itemElements()) {
358
+ const id = item.getAttribute("data-settings-item") || "";
359
+ if (!item.id)
360
+ item.id = `${prefix}-item-${domId(id)}`;
361
+ item.setAttribute("role", "tab");
362
+ items.set(id, item);
363
+ for (let wrapper = item.parentElement;wrapper && wrapper !== this.list; wrapper = wrapper.parentElement) {
364
+ if (!wrapper.hasAttribute("role"))
365
+ wrapper.setAttribute("role", "presentation");
366
+ }
367
+ }
368
+ for (const pane of this.paneElements()) {
369
+ const id = pane.getAttribute("data-settings-pane") || "";
370
+ if (!pane.id)
371
+ pane.id = `${prefix}-pane-${domId(id)}`;
372
+ const item = items.get(id);
373
+ if (item) {
374
+ item.setAttribute("aria-controls", pane.id);
375
+ pane.setAttribute("role", "tabpanel");
376
+ pane.setAttribute("aria-labelledby", item.id);
377
+ pane.removeAttribute("aria-label");
378
+ } else if (this.title?.id) {
379
+ pane.setAttribute("role", "region");
380
+ if (!pane.hasAttribute("aria-label"))
381
+ pane.setAttribute("aria-label", pane.getAttribute("data-title") || id);
382
+ }
383
+ }
384
+ }
385
+ open(id) {
386
+ if (!id)
387
+ return;
388
+ this.history = settingsHistoryVisit(this.history, id);
389
+ this.show();
390
+ }
391
+ travel(next) {
392
+ if (next === this.history)
393
+ return;
394
+ this.history = next;
395
+ this.show();
396
+ }
397
+ show() {
398
+ this.describe();
399
+ const panes = this.panes();
400
+ const id = settingsHistoryCurrent(this.history);
401
+ const info = findSettingsPane(panes, id);
402
+ const target = this.paneElement(id);
403
+ if (!info || !target)
404
+ return;
405
+ const active = document.activeElement;
406
+ const focusLeaves = active instanceof HTMLElement && this.paneElements().some((pane) => pane !== target && pane.contains(active));
407
+ for (const pane of this.paneElements()) {
408
+ pane.hidden = pane !== target;
409
+ pane.toggleAttribute("data-active", pane === target);
410
+ }
411
+ const selected = settingsSidebarPane(panes, id);
412
+ for (const item of this.itemElements()) {
413
+ const on = item.getAttribute("data-settings-item") === selected;
414
+ item.setAttribute("aria-selected", on ? "true" : "false");
415
+ item.toggleAttribute("data-active", on);
416
+ }
417
+ this.syncTabStops();
418
+ if (this.title)
419
+ this.title.textContent = info.title;
420
+ this.root.setAttribute("data-pane", id);
421
+ this.root.toggleAttribute("data-subpane", settingsParentPane(panes, id) !== "");
422
+ this.syncHistoryButtons(panes);
423
+ const changed = id !== this.current;
424
+ this.current = id;
425
+ if (changed) {
426
+ this.clearHighlight();
427
+ if (this.body)
428
+ this.body.scrollTop = 0;
429
+ this.syncScrolled();
430
+ if (focusLeaves) {
431
+ if (!target.hasAttribute("tabindex"))
432
+ target.setAttribute("tabindex", "-1");
433
+ target.focus({ preventScroll: true });
434
+ }
435
+ this.store();
436
+ this.callbacks.onPane?.({ id, title: info.title, parent: settingsParentPane(panes, id) });
437
+ }
438
+ }
439
+ syncTabStops() {
440
+ const visible = this.visibleItems();
441
+ const stop = visible.find((item) => item.getAttribute("aria-selected") === "true") ?? visible[0];
442
+ for (const item of this.itemElements())
443
+ item.setAttribute("tabindex", item === stop ? "0" : "-1");
444
+ }
445
+ syncHistoryButtons(panes) {
446
+ const set = (button, enabled, other) => {
447
+ if (!button)
448
+ return;
449
+ const focused = document.activeElement === button;
450
+ button.disabled = !enabled;
451
+ if (focused && !enabled && other && !other.disabled)
452
+ other.focus();
453
+ };
454
+ const back = settingsCanGoBack(this.history, panes);
455
+ const forward = settingsCanGoForward(this.history);
456
+ if (back) {
457
+ set(this.backButton, true, null);
458
+ set(this.forwardButton, forward, this.backButton);
459
+ } else {
460
+ set(this.forwardButton, forward, null);
461
+ set(this.backButton, false, this.forwardButton);
462
+ }
463
+ }
464
+ syncScrolled() {
465
+ this.root.toggleAttribute("data-scrolled", Boolean(this.body && this.body.scrollTop > 0));
466
+ }
467
+ applySearch(report) {
468
+ const rows = this.rowElements();
469
+ const index = rows.map((row) => ({
470
+ id: row.getAttribute("data-setting") || "",
471
+ label: (row.getAttribute("data-label") || "").trim(),
472
+ keywords: row.getAttribute("data-keywords") || "",
473
+ pane: this.paneOf(row)
474
+ }));
475
+ const found = searchSettings(this.query, { panes: this.panes(), items: this.items(), rows: index });
476
+ const searching = found.query !== "";
477
+ this.root.toggleAttribute("data-searching", searching);
478
+ this.field?.toggleAttribute("data-filled", this.query !== "");
479
+ for (const item of this.itemElements())
480
+ item.hidden = searching && !found.panes.includes(item.getAttribute("data-settings-item") || "");
481
+ if (this.list) {
482
+ for (const group of this.all("[data-settings-group]", this.list))
483
+ group.hidden = searching && this.all(ITEM, group).every((item) => item.hidden);
484
+ this.list.hidden = searching && found.panes.length === 0;
485
+ }
486
+ if (this.account)
487
+ this.account.hidden = searching;
488
+ this.hits = found.settings.map((hit) => ({ hit, row: rows[hit.row] }));
489
+ this.drawResults();
490
+ const total = found.panes.length + found.settings.length;
491
+ if (this.empty)
492
+ this.empty.hidden = !searching || total > 0;
493
+ if (this.live)
494
+ this.live.textContent = searching ? settingsResultsAnnouncement(total) : "";
495
+ this.syncTabStops();
496
+ if (report) {
497
+ this.callbacks.onSearch?.({
498
+ query: this.query.trim(),
499
+ panes: found.panes,
500
+ settings: found.settings.map((hit) => ({ id: hit.id, label: hit.label, pane: hit.pane }))
501
+ });
502
+ }
503
+ }
504
+ drawResults() {
505
+ const box = this.results;
506
+ if (!box)
507
+ return;
508
+ box.replaceChildren();
509
+ box.hidden = this.hits.length === 0;
510
+ this.hits.forEach(({ hit }, position) => {
511
+ const button = document.createElement("button");
512
+ button.type = "button";
513
+ button.className = "stx-settings-result";
514
+ button.setAttribute("data-settings-result", String(position));
515
+ button.setAttribute("tabindex", "-1");
516
+ const label = document.createElement("span");
517
+ label.className = "stx-settings-result-label";
518
+ label.textContent = hit.label;
519
+ const pane = document.createElement("span");
520
+ pane.className = "stx-settings-result-pane";
521
+ pane.textContent = hit.paneTitle;
522
+ button.append(label, pane);
523
+ box.append(button);
524
+ });
525
+ }
526
+ chooseResult(position) {
527
+ const found = this.hits[position];
528
+ if (!found || !found.row.isConnected)
529
+ return;
530
+ this.open(found.hit.pane);
531
+ this.reveal(found.row);
532
+ }
533
+ clearSearch() {
534
+ if (this.query === "" && (!this.input || this.input.value === ""))
535
+ return;
536
+ this.search("");
537
+ }
538
+ reveal(row) {
539
+ if (this.body) {
540
+ const frame = this.body.getBoundingClientRect();
541
+ const box = row.getBoundingClientRect();
542
+ this.body.scrollTop += box.top - frame.top - (frame.height - box.height) / 2;
543
+ this.syncScrolled();
544
+ }
545
+ this.clearHighlight();
546
+ row.setAttribute("data-highlight", "");
547
+ this.highlighted = row;
548
+ this.highlightTimer = setTimeout(() => this.clearHighlight(), SETTINGS_HIGHLIGHT_MS);
549
+ }
550
+ clearHighlight() {
551
+ if (this.highlightTimer)
552
+ clearTimeout(this.highlightTimer);
553
+ this.highlightTimer = null;
554
+ this.highlighted?.removeAttribute("data-highlight");
555
+ this.highlighted = null;
556
+ }
557
+ inside(target) {
558
+ return target instanceof Element && target.closest(ROOT) === this.root;
559
+ }
560
+ navigationRow(target) {
561
+ const row = target.closest("[data-navigate]");
562
+ if (!row || row.closest(ROOT) !== this.root || row.getAttribute("aria-disabled") === "true")
563
+ return null;
564
+ const control = target.closest(CONTROLS);
565
+ if (control && control !== row && row.contains(control))
566
+ return null;
567
+ return row;
568
+ }
569
+ navigate(row) {
570
+ const id = row.getAttribute("data-navigate") || "";
571
+ if (!findSettingsPane(this.panes(), id))
572
+ return;
573
+ const from = this.current;
574
+ this.open(id);
575
+ this.callbacks.onNavigate?.({ id, from, setting: row.getAttribute("data-setting") || "" });
576
+ }
577
+ onClick(event) {
578
+ const target = event.target;
579
+ if (!this.inside(target))
580
+ return;
581
+ const item = target.closest(ITEM);
582
+ if (item && this.list?.contains(item)) {
583
+ this.open(item.getAttribute("data-settings-item") || "");
584
+ return;
585
+ }
586
+ const result = target.closest(RESULT);
587
+ if (result) {
588
+ this.chooseResult(Number(result.getAttribute("data-settings-result")));
589
+ return;
590
+ }
591
+ if (target.closest("[data-settings-back]")) {
592
+ this.back();
593
+ return;
594
+ }
595
+ if (target.closest("[data-settings-forward]")) {
596
+ this.forward();
597
+ return;
598
+ }
599
+ if (target.closest("[data-settings-search-clear]")) {
600
+ this.clearSearch();
601
+ this.input?.focus();
602
+ return;
603
+ }
604
+ const row = this.navigationRow(target);
605
+ if (row)
606
+ this.navigate(row);
607
+ }
608
+ onKeyDown(event) {
609
+ if (event.defaultPrevented)
610
+ return;
611
+ const command = (event.metaKey || event.ctrlKey) && !event.altKey;
612
+ if (command && !event.shiftKey) {
613
+ const key = event.key.toLowerCase();
614
+ if (key === "f" && this.input) {
615
+ event.preventDefault();
616
+ this.focusSearch();
617
+ return;
618
+ }
619
+ if (key === "[") {
620
+ event.preventDefault();
621
+ this.back();
622
+ return;
623
+ }
624
+ if (key === "]") {
625
+ event.preventDefault();
626
+ this.forward();
627
+ return;
628
+ }
629
+ }
630
+ const target = event.target;
631
+ if (!this.inside(target))
632
+ return;
633
+ if (event.key === "Escape" && this.query !== "") {
634
+ event.preventDefault();
635
+ this.clearSearch();
636
+ this.visibleItems().find((item) => item.getAttribute("tabindex") === "0")?.focus();
637
+ return;
638
+ }
639
+ if (target === this.input) {
640
+ this.onSearchKey(event);
641
+ return;
642
+ }
643
+ const result = target.closest(RESULT);
644
+ if (result) {
645
+ this.onResultKey(event, result);
646
+ return;
647
+ }
648
+ const item = target.closest(ITEM);
649
+ if (item && this.list?.contains(item)) {
650
+ this.onItemKey(event, item);
651
+ return;
652
+ }
653
+ if ((event.key === "Enter" || event.key === " ") && !command && !event.altKey) {
654
+ const row = target.closest("[data-navigate]");
655
+ if (row && row === target && this.navigationRow(target)) {
656
+ event.preventDefault();
657
+ this.navigate(row);
658
+ }
659
+ }
660
+ }
661
+ resultButtons() {
662
+ return this.results ? Array.from(this.results.querySelectorAll(RESULT)) : [];
663
+ }
664
+ onSearchKey(event) {
665
+ if (event.key === "ArrowDown") {
666
+ const first = this.visibleItems()[0] ?? this.resultButtons()[0];
667
+ if (first) {
668
+ event.preventDefault();
669
+ first.focus();
670
+ }
671
+ } else if (event.key === "Enter" && this.query.trim() !== "") {
672
+ event.preventDefault();
673
+ const first = this.visibleItems()[0];
674
+ if (first)
675
+ this.open(first.getAttribute("data-settings-item") || "");
676
+ else
677
+ this.chooseResult(0);
678
+ }
679
+ }
680
+ onResultKey(event, result) {
681
+ const buttons = this.resultButtons();
682
+ const index = buttons.indexOf(result);
683
+ if (event.key === "ArrowUp" && index === 0) {
684
+ const items = this.visibleItems();
685
+ const last = items[items.length - 1] ?? this.input;
686
+ if (last) {
687
+ event.preventDefault();
688
+ last.focus();
689
+ }
690
+ return;
691
+ }
692
+ const next = settingsRovingIndex(event.key, index, buttons.length);
693
+ if (next === -1)
694
+ return;
695
+ event.preventDefault();
696
+ buttons[next].focus();
697
+ }
698
+ onItemKey(event, item) {
699
+ if (event.metaKey || event.ctrlKey || event.altKey)
700
+ return;
701
+ const items = this.visibleItems();
702
+ const index = items.indexOf(item);
703
+ if (event.key === "ArrowDown" && index === items.length - 1) {
704
+ const first = this.resultButtons()[0];
705
+ if (first) {
706
+ event.preventDefault();
707
+ first.focus();
708
+ return;
709
+ }
710
+ }
711
+ let next = settingsRovingIndex(event.key, index, items.length);
712
+ if (next === -1 && event.key.length === 1 && (event.key !== " " || this.typed !== null)) {
713
+ const typed = settingsTypeAheadAdd(this.typed, event.key, Date.now());
714
+ if (event.key === " " && typed.buffer.trim() === "") {
715
+ this.typed = null;
716
+ return;
717
+ }
718
+ this.typed = typed;
719
+ next = settingsTypeAheadMatch(items.map((entry) => this.labelOf(entry)), typed.buffer, index);
720
+ if (next === -1) {
721
+ event.preventDefault();
722
+ return;
723
+ }
724
+ }
725
+ if (next === -1)
726
+ return;
727
+ event.preventDefault();
728
+ items[next].focus();
729
+ this.open(items[next].getAttribute("data-settings-item") || "");
730
+ }
731
+ }
732
+ export {
733
+ SETTINGS_HIGHLIGHT_MS,
734
+ SETTINGS_RANK,
735
+ SETTINGS_TYPE_AHEAD_MS,
736
+ SettingsWindowView,
737
+ emptySettingsHistory,
738
+ findSettingsPane,
739
+ firstSettingsPane,
740
+ normalizeSettingsText,
741
+ resolveSettingsPane,
742
+ searchSettings,
743
+ settingsCanGoBack,
744
+ settingsCanGoForward,
745
+ settingsHistoryBack,
746
+ settingsHistoryCurrent,
747
+ settingsHistoryForward,
748
+ settingsHistoryVisit,
749
+ settingsMatchRank,
750
+ settingsParentPane,
751
+ settingsResultsAnnouncement,
752
+ settingsRovingIndex,
753
+ settingsSidebarPane,
754
+ settingsStorageName,
755
+ settingsTypeAheadAdd,
756
+ settingsTypeAheadMatch
757
+ };