@reticular/speakable 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4199 @@
1
+ import {
2
+ EVENT_RESULT,
3
+ EVENT_TIMELINE
4
+ } from "./chunk-QVJRQZT5.js";
5
+ import {
6
+ awaitCustomElementsReady
7
+ } from "./chunk-3SVI6IQE.js";
8
+ import {
9
+ __commonJS,
10
+ __toESM
11
+ } from "./chunk-JSBRDJBE.js";
12
+
13
+ // ../node_modules/picocolors/picocolors.browser.js
14
+ var require_picocolors_browser = __commonJS({
15
+ "../node_modules/picocolors/picocolors.browser.js"(exports, module) {
16
+ "use strict";
17
+ var x = String;
18
+ var create = function() {
19
+ return { isColorSupported: false, reset: x, bold: x, dim: x, italic: x, underline: x, inverse: x, hidden: x, strikethrough: x, black: x, red: x, green: x, yellow: x, blue: x, magenta: x, cyan: x, white: x, gray: x, bgBlack: x, bgRed: x, bgGreen: x, bgYellow: x, bgBlue: x, bgMagenta: x, bgCyan: x, bgWhite: x, blackBright: x, redBright: x, greenBright: x, yellowBright: x, blueBright: x, magentaBright: x, cyanBright: x, whiteBright: x, bgBlackBright: x, bgRedBright: x, bgGreenBright: x, bgYellowBright: x, bgBlueBright: x, bgMagentaBright: x, bgCyanBright: x, bgWhiteBright: x };
20
+ };
21
+ module.exports = create();
22
+ module.exports.createColors = create;
23
+ }
24
+ });
25
+
26
+ // ../src/model/types.ts
27
+ var SUPPORTED_ROLES = [
28
+ // Original roles (22)
29
+ "button",
30
+ "link",
31
+ "heading",
32
+ "textbox",
33
+ "checkbox",
34
+ "radio",
35
+ "combobox",
36
+ "listbox",
37
+ "option",
38
+ "list",
39
+ "listitem",
40
+ "navigation",
41
+ "main",
42
+ "banner",
43
+ "contentinfo",
44
+ "region",
45
+ "img",
46
+ "article",
47
+ "complementary",
48
+ "form",
49
+ "search",
50
+ "generic",
51
+ // New roles (21)
52
+ "paragraph",
53
+ "blockquote",
54
+ "code",
55
+ "staticText",
56
+ "table",
57
+ "row",
58
+ "cell",
59
+ "columnheader",
60
+ "rowheader",
61
+ "term",
62
+ "definition",
63
+ "figure",
64
+ "caption",
65
+ "group",
66
+ "dialog",
67
+ "meter",
68
+ "progressbar",
69
+ "status",
70
+ "document",
71
+ "application",
72
+ "separator"
73
+ ];
74
+ var CURRENT_MODEL_VERSION = {
75
+ major: 1,
76
+ minor: 0
77
+ };
78
+
79
+ // ../src/extractor/aria-name.ts
80
+ function computeAccessibleName(element, visited = /* @__PURE__ */ new Set()) {
81
+ const warnings = [];
82
+ if (visited.has(element)) {
83
+ warnings.push({
84
+ message: "Circular reference detected in aria-labelledby chain",
85
+ element
86
+ });
87
+ return { name: "", warnings };
88
+ }
89
+ visited.add(element);
90
+ const labelledBy = element.getAttribute("aria-labelledby");
91
+ if (labelledBy) {
92
+ const name = computeNameFromLabelledBy(element, labelledBy, visited, warnings);
93
+ return { name, warnings };
94
+ }
95
+ const ariaLabel = element.getAttribute("aria-label");
96
+ if (ariaLabel && ariaLabel.trim()) {
97
+ return { name: ariaLabel.trim(), warnings };
98
+ }
99
+ if (isFormControl(element)) {
100
+ const labelName = computeNameFromLabel(element);
101
+ if (labelName) {
102
+ return { name: labelName, warnings };
103
+ }
104
+ }
105
+ if (element.tagName.toLowerCase() === "img") {
106
+ const alt = element.getAttribute("alt");
107
+ if (alt !== null) {
108
+ return { name: alt.trim(), warnings };
109
+ }
110
+ }
111
+ if (supportsNameFromContent(element)) {
112
+ const textName = computeNameFromContent(element, visited);
113
+ if (textName) {
114
+ return { name: textName, warnings };
115
+ }
116
+ }
117
+ const title = element.getAttribute("title");
118
+ if (title && title.trim()) {
119
+ return { name: title.trim(), warnings };
120
+ }
121
+ return { name: "", warnings };
122
+ }
123
+ function computeNameFromLabelledBy(element, labelledBy, visited, warnings) {
124
+ const document2 = element.ownerDocument;
125
+ if (!document2) {
126
+ return "";
127
+ }
128
+ const ids = labelledBy.trim().split(/\s+/);
129
+ const names = [];
130
+ for (const id of ids) {
131
+ if (!id) continue;
132
+ const referencedElement = document2.getElementById(id);
133
+ if (!referencedElement) {
134
+ warnings.push({
135
+ message: `aria-labelledby references non-existent ID: ${id}`,
136
+ element
137
+ });
138
+ continue;
139
+ }
140
+ const result = computeAccessibleName(referencedElement, new Set(visited));
141
+ warnings.push(...result.warnings);
142
+ const name = result.name || getTextContent(referencedElement);
143
+ if (name) {
144
+ names.push(name);
145
+ }
146
+ }
147
+ return names.join(" ").trim();
148
+ }
149
+ function computeNameFromLabel(element) {
150
+ const document2 = element.ownerDocument;
151
+ if (!document2) {
152
+ return "";
153
+ }
154
+ const id = element.getAttribute("id");
155
+ if (id) {
156
+ const label = document2.querySelector(`label[for="${id}"]`);
157
+ if (label) {
158
+ return getTextContent(label);
159
+ }
160
+ }
161
+ const parentLabel = element.closest("label");
162
+ if (parentLabel) {
163
+ return getTextContent(parentLabel);
164
+ }
165
+ return "";
166
+ }
167
+ function computeNameFromContent(element, _visited) {
168
+ return getTextContent(element);
169
+ }
170
+ function getTextContent(element) {
171
+ if (element.getAttribute("aria-hidden") === "true") {
172
+ return "";
173
+ }
174
+ let text = "";
175
+ for (const node of Array.from(element.childNodes)) {
176
+ if (node.nodeType === 3) {
177
+ text += node.textContent || "";
178
+ } else if (node.nodeType === 1) {
179
+ const childElement = node;
180
+ if (childElement.getAttribute("aria-hidden") === "true") {
181
+ continue;
182
+ }
183
+ text += getTextContent(childElement);
184
+ }
185
+ }
186
+ return text.trim();
187
+ }
188
+ function isFormControl(element) {
189
+ const tagName = element.tagName.toLowerCase();
190
+ return tagName === "input" || tagName === "textarea" || tagName === "select" || tagName === "button";
191
+ }
192
+ function supportsNameFromContent(element) {
193
+ const tagName = element.tagName.toLowerCase();
194
+ const role = element.getAttribute("role");
195
+ const contentElements = [
196
+ "button",
197
+ "a",
198
+ "h1",
199
+ "h2",
200
+ "h3",
201
+ "h4",
202
+ "h5",
203
+ "h6",
204
+ "summary",
205
+ "figcaption",
206
+ "legend",
207
+ "caption",
208
+ "th",
209
+ "td",
210
+ "li",
211
+ "dt",
212
+ "dd"
213
+ ];
214
+ if (contentElements.includes(tagName)) {
215
+ return true;
216
+ }
217
+ const contentRoles = [
218
+ "button",
219
+ "link",
220
+ "heading",
221
+ "tab",
222
+ "treeitem",
223
+ "option",
224
+ "row",
225
+ "cell",
226
+ "columnheader",
227
+ "rowheader",
228
+ "tooltip",
229
+ "menuitem",
230
+ "menuitemcheckbox",
231
+ "menuitemradio"
232
+ ];
233
+ if (role && contentRoles.includes(role)) {
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+ function computeAccessibleDescription(element) {
239
+ const warnings = [];
240
+ const describedBy = element.getAttribute("aria-describedby");
241
+ if (describedBy) {
242
+ const description = computeDescriptionFromDescribedBy(
243
+ element,
244
+ describedBy,
245
+ warnings
246
+ );
247
+ if (description) {
248
+ return { description, warnings };
249
+ }
250
+ }
251
+ const title = element.getAttribute("title");
252
+ if (title && title.trim()) {
253
+ return { description: title.trim(), warnings };
254
+ }
255
+ return { description: "", warnings };
256
+ }
257
+ function computeDescriptionFromDescribedBy(element, describedBy, warnings) {
258
+ const document2 = element.ownerDocument;
259
+ if (!document2) {
260
+ return "";
261
+ }
262
+ const ids = describedBy.trim().split(/\s+/);
263
+ const descriptions = [];
264
+ for (const id of ids) {
265
+ if (!id) continue;
266
+ const referencedElement = document2.getElementById(id);
267
+ if (!referencedElement) {
268
+ warnings.push({
269
+ message: `aria-describedby references non-existent ID: ${id}`,
270
+ element
271
+ });
272
+ continue;
273
+ }
274
+ const text = getTextContent(referencedElement);
275
+ if (text) {
276
+ descriptions.push(text);
277
+ }
278
+ }
279
+ return descriptions.join(" ").trim();
280
+ }
281
+
282
+ // ../src/extractor/role-mapper.ts
283
+ var IMPLICIT_ROLE_MAP = {
284
+ // Interactive elements
285
+ "button": "button",
286
+ "a": "link",
287
+ // Only if href attribute present
288
+ // Form controls
289
+ "input": "textbox",
290
+ // Default, varies by type
291
+ "textarea": "textbox",
292
+ "select": "listbox",
293
+ // Headings
294
+ "h1": "heading",
295
+ "h2": "heading",
296
+ "h3": "heading",
297
+ "h4": "heading",
298
+ "h5": "heading",
299
+ "h6": "heading",
300
+ // Landmarks
301
+ "nav": "navigation",
302
+ "main": "main",
303
+ "header": "banner",
304
+ // Only if not nested in article/section
305
+ "footer": "contentinfo",
306
+ // Only if not nested in article/section
307
+ "aside": "complementary",
308
+ "form": "form",
309
+ "section": "region",
310
+ // Only if has accessible name
311
+ // Lists
312
+ "ul": "list",
313
+ "ol": "list",
314
+ "li": "listitem",
315
+ // Images
316
+ "img": "img",
317
+ // Articles
318
+ "article": "article",
319
+ // Static content (new)
320
+ "p": "paragraph",
321
+ "blockquote": "blockquote",
322
+ "code": "code",
323
+ "pre": "code",
324
+ // Tables (new)
325
+ "table": "table",
326
+ "tr": "row",
327
+ "td": "cell",
328
+ "th": "columnheader",
329
+ // Default; scope="row" handled in computeImplicitRole
330
+ // Definition lists (new)
331
+ "dl": "list",
332
+ "dt": "term",
333
+ "dd": "definition",
334
+ // Figures (new)
335
+ "figure": "figure",
336
+ "figcaption": "caption",
337
+ // Disclosure (new)
338
+ "details": "group",
339
+ "summary": "button",
340
+ // Dialogs and widgets (new)
341
+ "dialog": "dialog",
342
+ "meter": "meter",
343
+ "progress": "progressbar",
344
+ "output": "status",
345
+ // Forms (new)
346
+ "fieldset": "group",
347
+ "legend": "caption",
348
+ // Embedded content (new)
349
+ "iframe": "document",
350
+ "video": "application",
351
+ "audio": "application",
352
+ // Separators (new)
353
+ "hr": "separator",
354
+ // Table caption (new)
355
+ "caption": "caption"
356
+ };
357
+ var INPUT_TYPE_ROLE_MAP = {
358
+ "button": "button",
359
+ "submit": "button",
360
+ "reset": "button",
361
+ "checkbox": "checkbox",
362
+ "radio": "radio",
363
+ "text": "textbox",
364
+ "email": "textbox",
365
+ "password": "textbox",
366
+ "search": "textbox",
367
+ "tel": "textbox",
368
+ "url": "textbox",
369
+ "number": "textbox"
370
+ };
371
+ function computeRole(element) {
372
+ const warnings = [];
373
+ const explicitRole = element.getAttribute("role");
374
+ if (explicitRole) {
375
+ const role = validateAndNormalizeRole(explicitRole, element, warnings);
376
+ if (role) {
377
+ return { role, warnings };
378
+ }
379
+ }
380
+ const implicitRole = computeImplicitRole(element, warnings);
381
+ return { role: implicitRole, warnings };
382
+ }
383
+ function validateAndNormalizeRole(roleAttr, element, warnings) {
384
+ const role = roleAttr.trim().toLowerCase();
385
+ if (role === "presentation" || role === "none") {
386
+ return null;
387
+ }
388
+ if (SUPPORTED_ROLES.includes(role)) {
389
+ return role;
390
+ }
391
+ warnings.push({
392
+ message: `Invalid or unsupported role: "${roleAttr}". Falling back to implicit role.`,
393
+ element
394
+ });
395
+ return null;
396
+ }
397
+ function computeImplicitRole(element, _warnings) {
398
+ const tagName = element.tagName.toLowerCase();
399
+ if (tagName === "input") {
400
+ return computeInputRole(element);
401
+ }
402
+ if (tagName === "a") {
403
+ return element.hasAttribute("href") ? "link" : null;
404
+ }
405
+ if (tagName === "header") {
406
+ return isTopLevelLandmark(element) ? "banner" : null;
407
+ }
408
+ if (tagName === "footer") {
409
+ return isTopLevelLandmark(element) ? "contentinfo" : null;
410
+ }
411
+ if (tagName === "th") {
412
+ const scope = element.getAttribute("scope");
413
+ return scope === "row" ? "rowheader" : "columnheader";
414
+ }
415
+ if (tagName === "section") {
416
+ return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : null;
417
+ }
418
+ const implicitRole = IMPLICIT_ROLE_MAP[tagName];
419
+ return implicitRole || null;
420
+ }
421
+ function computeInputRole(input) {
422
+ const type = (input.getAttribute("type") || "text").toLowerCase();
423
+ return INPUT_TYPE_ROLE_MAP[type] || "textbox";
424
+ }
425
+ function isTopLevelLandmark(element) {
426
+ let parent = element.parentElement;
427
+ while (parent) {
428
+ const tagName = parent.tagName.toLowerCase();
429
+ if (tagName === "article" || tagName === "section") {
430
+ return false;
431
+ }
432
+ parent = parent.parentElement;
433
+ }
434
+ return true;
435
+ }
436
+ function isAccessible(element) {
437
+ if (element.getAttribute("aria-hidden") === "true") {
438
+ return false;
439
+ }
440
+ const role = element.getAttribute("role");
441
+ if (role === "presentation" || role === "none") {
442
+ return false;
443
+ }
444
+ const roleResult = computeRole(element);
445
+ return roleResult.role !== null;
446
+ }
447
+
448
+ // ../src/extractor/state-extractor.ts
449
+ function extractState(element) {
450
+ const warnings = [];
451
+ const state = {};
452
+ const expanded = extractBooleanAttribute(element, "aria-expanded", warnings);
453
+ if (expanded !== void 0) {
454
+ state.expanded = expanded;
455
+ }
456
+ const checked = extractTriStateAttribute(element, "aria-checked", warnings);
457
+ if (checked !== void 0) {
458
+ state.checked = checked;
459
+ }
460
+ const pressed = extractTriStateAttribute(element, "aria-pressed", warnings);
461
+ if (pressed !== void 0) {
462
+ state.pressed = pressed;
463
+ }
464
+ const selected = extractBooleanAttribute(element, "aria-selected", warnings);
465
+ if (selected !== void 0) {
466
+ state.selected = selected;
467
+ }
468
+ const disabled = extractBooleanAttribute(element, "aria-disabled", warnings);
469
+ if (disabled !== void 0) {
470
+ state.disabled = disabled;
471
+ }
472
+ const invalid = extractBooleanAttribute(element, "aria-invalid", warnings);
473
+ if (invalid !== void 0) {
474
+ state.invalid = invalid;
475
+ }
476
+ const required = extractBooleanAttribute(element, "aria-required", warnings);
477
+ if (required !== void 0) {
478
+ state.required = required;
479
+ }
480
+ const readonly = extractBooleanAttribute(element, "aria-readonly", warnings);
481
+ if (readonly !== void 0) {
482
+ state.readonly = readonly;
483
+ }
484
+ const busy = extractBooleanAttribute(element, "aria-busy", warnings);
485
+ if (busy !== void 0) {
486
+ state.busy = busy;
487
+ }
488
+ const current = extractCurrentAttribute(element, warnings);
489
+ if (current !== void 0) {
490
+ state.current = current;
491
+ }
492
+ const grabbed = extractBooleanAttribute(element, "aria-grabbed", warnings);
493
+ if (grabbed !== void 0) {
494
+ state.grabbed = grabbed;
495
+ }
496
+ const hidden = extractBooleanAttribute(element, "aria-hidden", warnings);
497
+ if (hidden !== void 0) {
498
+ state.hidden = hidden;
499
+ }
500
+ const level = extractLevelAttribute(element, warnings);
501
+ if (level !== void 0) {
502
+ state.level = level;
503
+ }
504
+ const posinset = extractNumberAttribute(element, "aria-posinset", warnings);
505
+ if (posinset !== void 0) {
506
+ state.posinset = posinset;
507
+ }
508
+ const setsize = extractNumberAttribute(element, "aria-setsize", warnings);
509
+ if (setsize !== void 0) {
510
+ state.setsize = setsize;
511
+ }
512
+ extractNativeStates(element, state, warnings);
513
+ return { state, warnings };
514
+ }
515
+ function extractValue(element) {
516
+ const warnings = [];
517
+ const tagName = element.tagName.toLowerCase();
518
+ if (tagName === "input") {
519
+ return extractInputValue(element, warnings);
520
+ }
521
+ if (tagName === "textarea") {
522
+ return extractTextareaValue(element, warnings);
523
+ }
524
+ if (tagName === "select") {
525
+ return extractSelectValue(element, warnings);
526
+ }
527
+ const valueNow = element.getAttribute("aria-valuenow");
528
+ if (valueNow !== null) {
529
+ const current = parseFloat(valueNow);
530
+ if (!isNaN(current)) {
531
+ const valueMin = element.getAttribute("aria-valuemin");
532
+ const valueMax = element.getAttribute("aria-valuemax");
533
+ const valueText = element.getAttribute("aria-valuetext");
534
+ return {
535
+ value: {
536
+ current,
537
+ min: valueMin !== null ? parseFloat(valueMin) : void 0,
538
+ max: valueMax !== null ? parseFloat(valueMax) : void 0,
539
+ text: valueText || void 0
540
+ },
541
+ warnings
542
+ };
543
+ }
544
+ }
545
+ return { value: void 0, warnings };
546
+ }
547
+ function extractBooleanAttribute(element, attrName, warnings) {
548
+ const value = element.getAttribute(attrName);
549
+ if (value === null) {
550
+ return void 0;
551
+ }
552
+ const normalized = value.toLowerCase().trim();
553
+ if (normalized === "true") {
554
+ return true;
555
+ }
556
+ if (normalized === "false") {
557
+ return false;
558
+ }
559
+ warnings.push({
560
+ message: `Invalid ${attrName} value: "${value}". Expected "true" or "false".`,
561
+ element
562
+ });
563
+ return void 0;
564
+ }
565
+ function extractTriStateAttribute(element, attrName, warnings) {
566
+ const value = element.getAttribute(attrName);
567
+ if (value === null) {
568
+ return void 0;
569
+ }
570
+ const normalized = value.toLowerCase().trim();
571
+ if (normalized === "true") {
572
+ return true;
573
+ }
574
+ if (normalized === "false") {
575
+ return false;
576
+ }
577
+ if (normalized === "mixed") {
578
+ return "mixed";
579
+ }
580
+ warnings.push({
581
+ message: `Invalid ${attrName} value: "${value}". Expected "true", "false", or "mixed".`,
582
+ element
583
+ });
584
+ return void 0;
585
+ }
586
+ function extractCurrentAttribute(element, warnings) {
587
+ const value = element.getAttribute("aria-current");
588
+ if (value === null) {
589
+ return void 0;
590
+ }
591
+ const normalized = value.toLowerCase().trim();
592
+ const validValues = ["page", "step", "location", "date", "time", "true", "false"];
593
+ if (validValues.includes(normalized)) {
594
+ return normalized === "false" ? false : normalized;
595
+ }
596
+ warnings.push({
597
+ message: `Invalid aria-current value: "${value}". Expected one of: ${validValues.join(", ")}.`,
598
+ element
599
+ });
600
+ return void 0;
601
+ }
602
+ function extractLevelAttribute(element, warnings) {
603
+ const ariaLevel = element.getAttribute("aria-level");
604
+ if (ariaLevel !== null) {
605
+ const level = parseInt(ariaLevel, 10);
606
+ if (!isNaN(level) && level >= 1 && level <= 6) {
607
+ return level;
608
+ }
609
+ warnings.push({
610
+ message: `Invalid aria-level value: "${ariaLevel}". Expected integer 1-6.`,
611
+ element
612
+ });
613
+ return void 0;
614
+ }
615
+ const tagName = element.tagName.toLowerCase();
616
+ const match = tagName.match(/^h([1-6])$/);
617
+ if (match) {
618
+ return parseInt(match[1], 10);
619
+ }
620
+ return void 0;
621
+ }
622
+ function extractNumberAttribute(element, attrName, warnings) {
623
+ const value = element.getAttribute(attrName);
624
+ if (value === null) {
625
+ return void 0;
626
+ }
627
+ const num = parseInt(value, 10);
628
+ if (isNaN(num) || num < 1) {
629
+ warnings.push({
630
+ message: `Invalid ${attrName} value: "${value}". Expected positive integer.`,
631
+ element
632
+ });
633
+ return void 0;
634
+ }
635
+ return num;
636
+ }
637
+ function extractNativeStates(element, state, _warnings) {
638
+ const tagName = element.tagName.toLowerCase();
639
+ if (tagName === "input") {
640
+ const input = element;
641
+ const type = input.type.toLowerCase();
642
+ if (type === "checkbox" || type === "radio") {
643
+ if (state.checked === void 0) {
644
+ state.checked = input.checked;
645
+ }
646
+ }
647
+ }
648
+ if ("disabled" in element) {
649
+ const htmlElement = element;
650
+ if (state.disabled === void 0 && htmlElement.disabled) {
651
+ state.disabled = true;
652
+ }
653
+ }
654
+ if ("required" in element) {
655
+ const htmlElement = element;
656
+ if (state.required === void 0 && htmlElement.required) {
657
+ state.required = true;
658
+ }
659
+ }
660
+ if ("readOnly" in element) {
661
+ const htmlElement = element;
662
+ if (state.readonly === void 0 && htmlElement.readOnly) {
663
+ state.readonly = true;
664
+ }
665
+ }
666
+ }
667
+ function extractInputValue(input, warnings) {
668
+ const type = input.type.toLowerCase();
669
+ if (type === "checkbox" || type === "radio") {
670
+ return { value: void 0, warnings };
671
+ }
672
+ if (type === "button" || type === "submit" || type === "reset") {
673
+ return { value: void 0, warnings };
674
+ }
675
+ const value = input.value;
676
+ if (value) {
677
+ return {
678
+ value: {
679
+ current: value,
680
+ text: value
681
+ },
682
+ warnings
683
+ };
684
+ }
685
+ return { value: void 0, warnings };
686
+ }
687
+ function extractTextareaValue(textarea, warnings) {
688
+ const value = textarea.value;
689
+ if (value) {
690
+ return {
691
+ value: {
692
+ current: value,
693
+ text: value
694
+ },
695
+ warnings
696
+ };
697
+ }
698
+ return { value: void 0, warnings };
699
+ }
700
+ function extractSelectValue(select, warnings) {
701
+ const value = select.value;
702
+ const selectedOption = select.options[select.selectedIndex];
703
+ const text = selectedOption?.textContent || value;
704
+ if (value) {
705
+ return {
706
+ value: {
707
+ current: value,
708
+ text
709
+ },
710
+ warnings
711
+ };
712
+ }
713
+ return { value: void 0, warnings };
714
+ }
715
+
716
+ // ../src/extractor/focus-extractor.ts
717
+ var NATIVELY_FOCUSABLE_ELEMENTS = [
718
+ "a",
719
+ "button",
720
+ "input",
721
+ "select",
722
+ "textarea",
723
+ "area",
724
+ "iframe",
725
+ "object",
726
+ "embed",
727
+ "audio",
728
+ "video"
729
+ ];
730
+ function extractFocusInfo(element) {
731
+ const tabindexAttr = element.getAttribute("tabindex");
732
+ const tabindex = tabindexAttr !== null ? parseInt(tabindexAttr, 10) : void 0;
733
+ const focusable = isFocusable(element, tabindex);
734
+ return {
735
+ focusable,
736
+ ...tabindexAttr !== null && !isNaN(tabindex) && { tabindex }
737
+ };
738
+ }
739
+ function isFocusable(element, tabindex) {
740
+ const tagName = element.tagName.toLowerCase();
741
+ if (isDisabled(element)) {
742
+ return false;
743
+ }
744
+ if (tabindex !== void 0 && !isNaN(tabindex)) {
745
+ return true;
746
+ }
747
+ if (isNativelyFocusable(element, tagName)) {
748
+ return true;
749
+ }
750
+ return false;
751
+ }
752
+ function isNativelyFocusable(element, tagName) {
753
+ if (tagName === "a" || tagName === "area") {
754
+ return element.hasAttribute("href");
755
+ }
756
+ if (NATIVELY_FOCUSABLE_ELEMENTS.includes(tagName)) {
757
+ return true;
758
+ }
759
+ return false;
760
+ }
761
+ function isDisabled(element) {
762
+ if ("disabled" in element) {
763
+ const htmlElement = element;
764
+ if (htmlElement.disabled) {
765
+ return true;
766
+ }
767
+ }
768
+ const ariaDisabled = element.getAttribute("aria-disabled");
769
+ if (ariaDisabled === "true") {
770
+ return true;
771
+ }
772
+ return false;
773
+ }
774
+
775
+ // ../src/extractor/tree-builder.ts
776
+ function isHidden(element) {
777
+ if (element.getAttribute("aria-hidden") === "true") return true;
778
+ if (typeof getComputedStyle === "function") {
779
+ try {
780
+ const style = getComputedStyle(element);
781
+ if (style.display === "none") return true;
782
+ if (style.visibility === "hidden") return true;
783
+ } catch {
784
+ }
785
+ }
786
+ return false;
787
+ }
788
+ function processChildNode(node, children, warnings) {
789
+ if (node.nodeType === 3) {
790
+ const text = (node.textContent || "").trim();
791
+ if (text.length > 0) {
792
+ children.push({
793
+ role: "staticText",
794
+ name: text,
795
+ state: {},
796
+ focus: { focusable: false },
797
+ children: []
798
+ });
799
+ }
800
+ return;
801
+ }
802
+ if (node.nodeType === 1) {
803
+ const element = node;
804
+ if (isHidden(element)) return;
805
+ if (!isAccessible(element)) {
806
+ const grandchildren = collectChildrenFromRolelessElement(element, warnings);
807
+ children.push(...grandchildren);
808
+ return;
809
+ }
810
+ const childNode = buildNodeRecursive(element, warnings);
811
+ if (childNode) children.push(childNode);
812
+ }
813
+ }
814
+ function collectChildrenFromRolelessElement(element, warnings) {
815
+ return collectAccessibleChildren(element, warnings);
816
+ }
817
+ function collectAccessibleChildren(element, warnings) {
818
+ const children = [];
819
+ if (element.shadowRoot) {
820
+ for (const child of Array.from(element.shadowRoot.childNodes)) {
821
+ processShadowNode(child, children, warnings);
822
+ }
823
+ return children;
824
+ }
825
+ if (element.localName && element.localName.includes("-") && element.childNodes.length === 0) {
826
+ warnings.push({
827
+ message: `Custom element <${element.localName}> has no accessible children and may have a closed shadow root; its content could not be analyzed.`,
828
+ element
829
+ });
830
+ }
831
+ for (const child of Array.from(element.childNodes)) {
832
+ processChildNode(child, children, warnings);
833
+ }
834
+ return children;
835
+ }
836
+ function processShadowNode(node, children, warnings) {
837
+ if (node.nodeType === 1) {
838
+ const element = node;
839
+ if (element.localName === "slot") {
840
+ const slot = element;
841
+ let assigned = [];
842
+ if (typeof slot.assignedNodes === "function") {
843
+ try {
844
+ assigned = Array.from(slot.assignedNodes({ flatten: true }));
845
+ } catch {
846
+ assigned = [];
847
+ }
848
+ }
849
+ if (assigned.length > 0) {
850
+ for (const assignedNode of assigned) {
851
+ processChildNode(assignedNode, children, warnings);
852
+ }
853
+ } else {
854
+ for (const child of Array.from(slot.childNodes)) {
855
+ processShadowNode(child, children, warnings);
856
+ }
857
+ }
858
+ return;
859
+ }
860
+ }
861
+ processChildNode(node, children, warnings);
862
+ }
863
+ function buildAccessibilityTree(rootElement, sourceHash) {
864
+ const warnings = [];
865
+ if (isHidden(rootElement)) {
866
+ const model2 = {
867
+ version: CURRENT_MODEL_VERSION,
868
+ root: {
869
+ role: "generic",
870
+ name: "",
871
+ state: {},
872
+ focus: { focusable: false },
873
+ children: []
874
+ },
875
+ metadata: {
876
+ extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
877
+ ...sourceHash && { sourceHash }
878
+ }
879
+ };
880
+ return { model: model2, warnings };
881
+ }
882
+ const rootNode = buildNodeRecursive(rootElement, warnings);
883
+ const accessibleRoot = rootNode || createGenericContainer(rootElement, warnings);
884
+ const model = {
885
+ version: CURRENT_MODEL_VERSION,
886
+ root: accessibleRoot,
887
+ metadata: {
888
+ extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
889
+ ...sourceHash && { sourceHash }
890
+ }
891
+ };
892
+ return { model, warnings };
893
+ }
894
+ function buildNodeRecursive(element, warnings) {
895
+ if (isHidden(element)) {
896
+ return null;
897
+ }
898
+ if (!isAccessible(element)) {
899
+ return null;
900
+ }
901
+ const roleResult = computeRole(element);
902
+ warnings.push(...roleResult.warnings.map((w) => ({
903
+ message: w.message,
904
+ element: w.element
905
+ })));
906
+ if (!roleResult.role) {
907
+ return null;
908
+ }
909
+ const nameResult = computeAccessibleName(element);
910
+ warnings.push(...nameResult.warnings.map((w) => ({
911
+ message: w.message,
912
+ element: w.element
913
+ })));
914
+ const descResult = computeAccessibleDescription(element);
915
+ warnings.push(...descResult.warnings.map((w) => ({
916
+ message: w.message,
917
+ element: w.element
918
+ })));
919
+ const stateResult = extractState(element);
920
+ warnings.push(...stateResult.warnings.map((w) => ({
921
+ message: w.message,
922
+ element: w.element
923
+ })));
924
+ const valueResult = extractValue(element);
925
+ warnings.push(...valueResult.warnings.map((w) => ({
926
+ message: w.message,
927
+ element: w.element
928
+ })));
929
+ const focusInfo = extractFocusInfo(element);
930
+ const children = collectAccessibleChildren(element, warnings);
931
+ const node = {
932
+ role: roleResult.role,
933
+ name: nameResult.name,
934
+ ...descResult.description && { description: descResult.description },
935
+ ...valueResult.value && { value: valueResult.value },
936
+ state: stateResult.state,
937
+ focus: focusInfo,
938
+ children
939
+ };
940
+ return node;
941
+ }
942
+ function createGenericContainer(rootElement, warnings) {
943
+ const children = collectAccessibleChildren(rootElement, warnings);
944
+ return {
945
+ role: "generic",
946
+ name: "",
947
+ state: {},
948
+ focus: {
949
+ focusable: false
950
+ },
951
+ children
952
+ };
953
+ }
954
+
955
+ // ../src/cli/colors.ts
956
+ var import_picocolors = __toESM(require_picocolors_browser(), 1);
957
+ var identity = (s) => s;
958
+ function createColors(enabled) {
959
+ if (!enabled) {
960
+ return {
961
+ error: identity,
962
+ warning: identity,
963
+ info: identity,
964
+ success: identity,
965
+ heading: identity,
966
+ title: identity,
967
+ dim: identity,
968
+ roleName: identity,
969
+ stateName: identity,
970
+ elementName: identity,
971
+ sectionHeader: identity,
972
+ description: identity,
973
+ bold: identity,
974
+ enabled: false
975
+ };
976
+ }
977
+ return {
978
+ error: import_picocolors.default.red,
979
+ warning: import_picocolors.default.yellow,
980
+ info: import_picocolors.default.blue,
981
+ success: import_picocolors.default.green,
982
+ heading: (s) => import_picocolors.default.bold(import_picocolors.default.cyan(s)),
983
+ title: (s) => import_picocolors.default.bold(import_picocolors.default.cyan(s)),
984
+ dim: import_picocolors.default.dim,
985
+ roleName: import_picocolors.default.cyan,
986
+ stateName: import_picocolors.default.yellow,
987
+ elementName: (s) => import_picocolors.default.bold(import_picocolors.default.white(s)),
988
+ sectionHeader: (s) => import_picocolors.default.bold(import_picocolors.default.white(s)),
989
+ description: import_picocolors.default.dim,
990
+ bold: import_picocolors.default.bold,
991
+ enabled: true
992
+ };
993
+ }
994
+
995
+ // ../src/renderer/nvda-renderer.ts
996
+ function renderNVDA(model, colorize) {
997
+ const c = createColors(colorize ?? false);
998
+ const announcements = [];
999
+ renderNodeNVDA(model.root, announcements, c);
1000
+ return announcements.join("\n");
1001
+ }
1002
+ function renderNodeNVDA(node, announcements, c) {
1003
+ const announcement = formatNodeNVDA(node, c);
1004
+ if (announcement) {
1005
+ announcements.push(announcement);
1006
+ }
1007
+ for (const child of node.children) {
1008
+ if (child.name && child.name === node.name && node.children.length === 1) {
1009
+ for (const grandchild of child.children) {
1010
+ renderNodeNVDA(grandchild, announcements, c);
1011
+ }
1012
+ continue;
1013
+ }
1014
+ renderNodeNVDA(child, announcements, c);
1015
+ }
1016
+ }
1017
+ function formatNodeNVDA(node, c) {
1018
+ const parts = [];
1019
+ if (node.name) {
1020
+ parts.push(c.elementName(node.name));
1021
+ }
1022
+ const roleText = formatRoleNVDA(node);
1023
+ if (roleText) {
1024
+ parts.push(c.roleName(roleText));
1025
+ }
1026
+ const stateText = formatStatesNVDA(node);
1027
+ if (stateText) {
1028
+ parts.push(c.stateName(stateText));
1029
+ }
1030
+ if (node.value) {
1031
+ const valueText = node.value.text || String(node.value.current);
1032
+ if (valueText) {
1033
+ parts.push(valueText);
1034
+ }
1035
+ }
1036
+ if (node.description) {
1037
+ parts.push(c.description(node.description));
1038
+ }
1039
+ return parts.join(", ");
1040
+ }
1041
+ function formatRoleNVDA(node) {
1042
+ const role = node.role;
1043
+ switch (role) {
1044
+ case "button":
1045
+ return "button";
1046
+ case "link":
1047
+ return "link";
1048
+ case "heading":
1049
+ if (node.state.level) {
1050
+ return `heading level ${node.state.level}`;
1051
+ }
1052
+ return "heading";
1053
+ case "textbox":
1054
+ return "edit";
1055
+ case "checkbox":
1056
+ return "checkbox";
1057
+ case "radio":
1058
+ return "radio button";
1059
+ case "combobox":
1060
+ return "combo box";
1061
+ case "listbox":
1062
+ return "list box";
1063
+ case "option":
1064
+ return "option";
1065
+ case "list":
1066
+ return "list";
1067
+ case "listitem":
1068
+ return "list item";
1069
+ case "navigation":
1070
+ return "navigation landmark";
1071
+ case "main":
1072
+ return "main landmark";
1073
+ case "banner":
1074
+ return "banner landmark";
1075
+ case "contentinfo":
1076
+ return "content information landmark";
1077
+ case "region":
1078
+ return "region landmark";
1079
+ case "complementary":
1080
+ return "complementary landmark";
1081
+ case "form":
1082
+ return "form landmark";
1083
+ case "search":
1084
+ return "search landmark";
1085
+ case "img":
1086
+ return "graphic";
1087
+ case "article":
1088
+ return "article";
1089
+ case "generic":
1090
+ return "";
1091
+ case "staticText":
1092
+ case "paragraph":
1093
+ case "cell":
1094
+ case "term":
1095
+ case "definition":
1096
+ case "caption":
1097
+ return "";
1098
+ case "blockquote":
1099
+ return "block quote";
1100
+ case "code":
1101
+ return "code";
1102
+ case "table":
1103
+ return "table";
1104
+ case "row":
1105
+ return "row";
1106
+ case "columnheader":
1107
+ return "column header";
1108
+ case "rowheader":
1109
+ return "row header";
1110
+ case "figure":
1111
+ return "figure";
1112
+ case "dialog":
1113
+ return "dialog";
1114
+ case "meter":
1115
+ return "meter";
1116
+ case "progressbar":
1117
+ return "progress bar";
1118
+ case "status":
1119
+ return "status";
1120
+ case "group":
1121
+ return node.name ? "grouping" : "";
1122
+ case "document":
1123
+ return "document";
1124
+ case "application":
1125
+ return "embedded object";
1126
+ case "separator":
1127
+ return "separator";
1128
+ default:
1129
+ return role;
1130
+ }
1131
+ }
1132
+ function formatStatesNVDA(node) {
1133
+ const states = [];
1134
+ if (node.state.expanded !== void 0) {
1135
+ states.push(node.state.expanded ? "expanded" : "collapsed");
1136
+ }
1137
+ if (node.state.checked !== void 0) {
1138
+ if (node.state.checked === "mixed") {
1139
+ states.push("half checked");
1140
+ } else {
1141
+ states.push(node.state.checked ? "checked" : "not checked");
1142
+ }
1143
+ }
1144
+ if (node.state.pressed !== void 0) {
1145
+ if (node.state.pressed === "mixed") {
1146
+ states.push("half pressed");
1147
+ } else {
1148
+ states.push(node.state.pressed ? "pressed" : "not pressed");
1149
+ }
1150
+ }
1151
+ if (node.state.selected !== void 0) {
1152
+ states.push(node.state.selected ? "selected" : "not selected");
1153
+ }
1154
+ if (node.state.disabled) {
1155
+ states.push("unavailable");
1156
+ }
1157
+ if (node.state.invalid) {
1158
+ states.push("invalid entry");
1159
+ }
1160
+ if (node.state.required) {
1161
+ states.push("required");
1162
+ }
1163
+ if (node.state.readonly) {
1164
+ states.push("read only");
1165
+ }
1166
+ if (node.state.busy) {
1167
+ states.push("busy");
1168
+ }
1169
+ if (node.state.current) {
1170
+ if (node.state.current === "page") {
1171
+ states.push("current page");
1172
+ } else if (node.state.current === "step") {
1173
+ states.push("current step");
1174
+ } else if (node.state.current === "location") {
1175
+ states.push("current location");
1176
+ } else if (node.state.current === "date") {
1177
+ states.push("current date");
1178
+ } else if (node.state.current === "time") {
1179
+ states.push("current time");
1180
+ } else if (node.state.current === "true") {
1181
+ states.push("current");
1182
+ }
1183
+ }
1184
+ if (node.state.grabbed !== void 0) {
1185
+ states.push(node.state.grabbed ? "grabbed" : "not grabbed");
1186
+ }
1187
+ return states.join(", ");
1188
+ }
1189
+
1190
+ // ../src/renderer/jaws-renderer.ts
1191
+ function renderJAWS(model, colorize) {
1192
+ const c = createColors(colorize ?? false);
1193
+ const announcements = [];
1194
+ renderNodeJAWS(model.root, announcements, c);
1195
+ return announcements.join("\n");
1196
+ }
1197
+ function renderNodeJAWS(node, announcements, c) {
1198
+ const announcement = formatNodeJAWS(node, c);
1199
+ if (announcement) {
1200
+ announcements.push(announcement);
1201
+ }
1202
+ for (const child of node.children) {
1203
+ if (child.name && child.name === node.name && node.children.length === 1) {
1204
+ for (const grandchild of child.children) {
1205
+ renderNodeJAWS(grandchild, announcements, c);
1206
+ }
1207
+ continue;
1208
+ }
1209
+ renderNodeJAWS(child, announcements, c);
1210
+ }
1211
+ }
1212
+ function formatNodeJAWS(node, c) {
1213
+ const parts = [];
1214
+ if (node.name) {
1215
+ parts.push(c.elementName(node.name));
1216
+ }
1217
+ const roleText = formatRoleJAWS(node);
1218
+ if (roleText) {
1219
+ parts.push(c.roleName(roleText));
1220
+ }
1221
+ const stateText = formatStatesJAWS(node);
1222
+ if (stateText) {
1223
+ parts.push(c.stateName(stateText));
1224
+ }
1225
+ if (node.value) {
1226
+ const valueText = node.value.text || String(node.value.current);
1227
+ if (valueText) {
1228
+ parts.push(valueText);
1229
+ }
1230
+ }
1231
+ if (node.description) {
1232
+ parts.push(c.description(node.description));
1233
+ }
1234
+ return parts.join(", ");
1235
+ }
1236
+ function formatRoleJAWS(node) {
1237
+ const role = node.role;
1238
+ switch (role) {
1239
+ case "button":
1240
+ return "button";
1241
+ case "link":
1242
+ return "clickable";
1243
+ case "heading":
1244
+ if (node.state.level) {
1245
+ return `heading ${node.state.level}`;
1246
+ }
1247
+ return "heading";
1248
+ case "textbox":
1249
+ return "edit";
1250
+ case "checkbox":
1251
+ return "check box";
1252
+ case "radio":
1253
+ return "radio button";
1254
+ case "combobox":
1255
+ return "combo box";
1256
+ case "listbox":
1257
+ return "list box";
1258
+ case "option":
1259
+ return "option";
1260
+ case "list":
1261
+ return "list";
1262
+ case "listitem":
1263
+ return "list item";
1264
+ case "navigation":
1265
+ return "navigation region";
1266
+ case "main":
1267
+ return "main region";
1268
+ case "banner":
1269
+ return "banner region";
1270
+ case "contentinfo":
1271
+ return "content information region";
1272
+ case "region":
1273
+ return "region";
1274
+ case "img":
1275
+ return "graphic";
1276
+ case "article":
1277
+ return "article";
1278
+ case "complementary":
1279
+ return "complementary region";
1280
+ case "form":
1281
+ return "form";
1282
+ case "search":
1283
+ return "search region";
1284
+ case "generic":
1285
+ return "";
1286
+ case "staticText":
1287
+ case "paragraph":
1288
+ case "term":
1289
+ case "definition":
1290
+ case "caption":
1291
+ return "";
1292
+ case "blockquote":
1293
+ return "block quote";
1294
+ case "code":
1295
+ return "code";
1296
+ case "table": {
1297
+ const rows = node.children.filter((c) => c.role === "row");
1298
+ const rowCount = rows.length;
1299
+ const colCount = rows.length > 0 ? rows[0].children.length : 0;
1300
+ return `table with ${rowCount} rows and ${colCount} columns`;
1301
+ }
1302
+ case "row": {
1303
+ const pos = node.state.posinset ?? 0;
1304
+ return `row ${pos}`;
1305
+ }
1306
+ case "cell": {
1307
+ const pos = node.state.posinset ?? 0;
1308
+ return `column ${pos}`;
1309
+ }
1310
+ case "columnheader":
1311
+ return "column header";
1312
+ case "rowheader":
1313
+ return "row header";
1314
+ case "figure":
1315
+ return "figure";
1316
+ case "dialog":
1317
+ return "dialog";
1318
+ case "meter":
1319
+ return "meter";
1320
+ case "progressbar":
1321
+ return "progress bar";
1322
+ case "status":
1323
+ return "status";
1324
+ case "group":
1325
+ return node.name ? "group" : "";
1326
+ case "document":
1327
+ return "frame";
1328
+ case "application":
1329
+ return "embedded object";
1330
+ case "separator":
1331
+ return "separator";
1332
+ default:
1333
+ return role;
1334
+ }
1335
+ }
1336
+ function formatStatesJAWS(node) {
1337
+ const states = [];
1338
+ if (node.state.expanded !== void 0) {
1339
+ states.push(node.state.expanded ? "expanded" : "collapsed");
1340
+ }
1341
+ if (node.state.checked !== void 0) {
1342
+ if (node.state.checked === "mixed") {
1343
+ states.push("partially checked");
1344
+ } else if (node.state.checked) {
1345
+ states.push("checked");
1346
+ } else {
1347
+ states.push("not checked");
1348
+ }
1349
+ }
1350
+ if (node.state.pressed !== void 0) {
1351
+ if (node.state.pressed === "mixed") {
1352
+ states.push("partially pressed");
1353
+ } else if (node.state.pressed) {
1354
+ states.push("pressed");
1355
+ } else {
1356
+ states.push("not pressed");
1357
+ }
1358
+ }
1359
+ if (node.state.selected !== void 0) {
1360
+ states.push(node.state.selected ? "selected" : "not selected");
1361
+ }
1362
+ if (node.state.disabled) {
1363
+ states.push("unavailable");
1364
+ }
1365
+ if (node.state.invalid) {
1366
+ states.push("invalid entry");
1367
+ }
1368
+ if (node.state.required) {
1369
+ states.push("required");
1370
+ }
1371
+ if (node.state.readonly) {
1372
+ states.push("read only");
1373
+ }
1374
+ if (node.state.busy) {
1375
+ states.push("busy");
1376
+ }
1377
+ if (node.state.current) {
1378
+ switch (node.state.current) {
1379
+ case "page":
1380
+ states.push("current page");
1381
+ break;
1382
+ case "step":
1383
+ states.push("current step");
1384
+ break;
1385
+ case "location":
1386
+ states.push("current location");
1387
+ break;
1388
+ case "date":
1389
+ states.push("current date");
1390
+ break;
1391
+ case "time":
1392
+ states.push("current time");
1393
+ break;
1394
+ case "true":
1395
+ states.push("current");
1396
+ break;
1397
+ }
1398
+ }
1399
+ if (node.state.grabbed !== void 0) {
1400
+ states.push(node.state.grabbed ? "grabbed" : "not grabbed");
1401
+ }
1402
+ return states.join(", ");
1403
+ }
1404
+
1405
+ // ../src/renderer/voiceover-renderer.ts
1406
+ function renderVoiceOver(model, colorize) {
1407
+ const c = createColors(colorize ?? false);
1408
+ const announcements = [];
1409
+ renderNodeVoiceOver(model.root, announcements, c);
1410
+ return announcements.join("\n");
1411
+ }
1412
+ function renderNodeVoiceOver(node, announcements, c) {
1413
+ const announcement = formatNodeVoiceOver(node, c);
1414
+ if (announcement) {
1415
+ announcements.push(announcement);
1416
+ }
1417
+ for (const child of node.children) {
1418
+ if (child.name && child.name === node.name && node.children.length === 1) {
1419
+ for (const grandchild of child.children) {
1420
+ renderNodeVoiceOver(grandchild, announcements, c);
1421
+ }
1422
+ continue;
1423
+ }
1424
+ renderNodeVoiceOver(child, announcements, c);
1425
+ }
1426
+ }
1427
+ function formatNodeVoiceOver(node, c) {
1428
+ const parts = [];
1429
+ const roleFirst = shouldAnnounceRoleFirst(node.role);
1430
+ if (roleFirst) {
1431
+ const roleText = formatRoleVoiceOver(node);
1432
+ if (roleText) {
1433
+ parts.push(c.roleName(roleText));
1434
+ }
1435
+ if (node.name) {
1436
+ parts.push(c.elementName(node.name));
1437
+ }
1438
+ } else {
1439
+ if (node.name) {
1440
+ parts.push(c.elementName(node.name));
1441
+ }
1442
+ const roleText = formatRoleVoiceOver(node);
1443
+ if (roleText) {
1444
+ parts.push(c.roleName(roleText));
1445
+ }
1446
+ }
1447
+ const stateText = formatStatesVoiceOver(node);
1448
+ if (stateText) {
1449
+ parts.push(c.stateName(stateText));
1450
+ }
1451
+ if (node.value) {
1452
+ const valueText = node.value.text || String(node.value.current);
1453
+ if (valueText) {
1454
+ parts.push(valueText);
1455
+ }
1456
+ }
1457
+ if (node.description) {
1458
+ parts.push(c.description(node.description));
1459
+ }
1460
+ return parts.join(", ");
1461
+ }
1462
+ function shouldAnnounceRoleFirst(role) {
1463
+ return role === "heading" || role === "navigation" || role === "main" || role === "banner" || role === "contentinfo" || role === "complementary" || role === "region" || role === "form" || role === "search" || role === "blockquote" || role === "figure" || role === "dialog" || role === "group" || role === "document";
1464
+ }
1465
+ function formatRoleVoiceOver(node) {
1466
+ const role = node.role;
1467
+ switch (role) {
1468
+ case "button":
1469
+ return "button";
1470
+ case "link":
1471
+ return "link";
1472
+ case "heading":
1473
+ if (node.state.level) {
1474
+ return `heading level ${node.state.level}`;
1475
+ }
1476
+ return "heading";
1477
+ case "textbox":
1478
+ return "edit text";
1479
+ case "checkbox":
1480
+ return "checkbox";
1481
+ case "radio":
1482
+ return "radio button";
1483
+ case "combobox":
1484
+ return "combo box";
1485
+ case "listbox":
1486
+ return "list box";
1487
+ case "option":
1488
+ return "option";
1489
+ case "list":
1490
+ return "list";
1491
+ case "listitem":
1492
+ return "item";
1493
+ case "navigation":
1494
+ return "navigation";
1495
+ case "main":
1496
+ return "main";
1497
+ case "banner":
1498
+ return "banner";
1499
+ case "contentinfo":
1500
+ return "content information";
1501
+ case "region":
1502
+ return "region";
1503
+ case "complementary":
1504
+ return "complementary";
1505
+ case "form":
1506
+ return "form";
1507
+ case "search":
1508
+ return "search";
1509
+ case "img":
1510
+ return "image";
1511
+ case "article":
1512
+ return "article";
1513
+ case "generic":
1514
+ return "";
1515
+ case "staticText":
1516
+ case "paragraph":
1517
+ case "cell":
1518
+ case "term":
1519
+ case "definition":
1520
+ case "caption":
1521
+ return "";
1522
+ case "blockquote":
1523
+ return "blockquote";
1524
+ case "code":
1525
+ return "code";
1526
+ case "table": {
1527
+ const rows = node.children.filter((c) => c.role === "row");
1528
+ const rowCount = rows.length;
1529
+ const colCount = rows.length > 0 ? rows[0].children.length : 0;
1530
+ return `table, ${rowCount} rows, ${colCount} columns`;
1531
+ }
1532
+ case "row":
1533
+ return "row";
1534
+ case "columnheader":
1535
+ return "column header";
1536
+ case "rowheader":
1537
+ return "row header";
1538
+ case "figure":
1539
+ return "figure";
1540
+ case "dialog":
1541
+ return "web dialog";
1542
+ case "meter":
1543
+ return "level indicator";
1544
+ case "progressbar":
1545
+ return "progress indicator";
1546
+ case "status":
1547
+ return "status";
1548
+ case "group":
1549
+ return node.name ? "group" : "";
1550
+ case "document":
1551
+ return "frame";
1552
+ case "application":
1553
+ return "embedded object";
1554
+ case "separator":
1555
+ return "separator";
1556
+ default:
1557
+ return role;
1558
+ }
1559
+ }
1560
+ function formatStatesVoiceOver(node) {
1561
+ const states = [];
1562
+ if (node.state.expanded !== void 0) {
1563
+ states.push(node.state.expanded ? "expanded" : "collapsed");
1564
+ }
1565
+ if (node.state.checked !== void 0) {
1566
+ if (node.state.checked === "mixed") {
1567
+ states.push("mixed");
1568
+ } else {
1569
+ states.push(node.state.checked ? "checked" : "unchecked");
1570
+ }
1571
+ }
1572
+ if (node.state.pressed !== void 0) {
1573
+ if (node.state.pressed === "mixed") {
1574
+ states.push("mixed");
1575
+ } else {
1576
+ states.push(node.state.pressed ? "pressed" : "not pressed");
1577
+ }
1578
+ }
1579
+ if (node.state.selected !== void 0) {
1580
+ states.push(node.state.selected ? "selected" : "unselected");
1581
+ }
1582
+ if (node.state.disabled) {
1583
+ states.push("dimmed");
1584
+ }
1585
+ if (node.state.invalid) {
1586
+ states.push("invalid data");
1587
+ }
1588
+ if (node.state.required) {
1589
+ states.push("required");
1590
+ }
1591
+ if (node.state.readonly) {
1592
+ states.push("read only");
1593
+ }
1594
+ if (node.state.busy) {
1595
+ states.push("busy");
1596
+ }
1597
+ if (node.state.current) {
1598
+ if (node.state.current === "page") {
1599
+ states.push("current page");
1600
+ } else if (node.state.current === "step") {
1601
+ states.push("current step");
1602
+ } else if (node.state.current === "location") {
1603
+ states.push("current location");
1604
+ } else if (node.state.current === "date") {
1605
+ states.push("current date");
1606
+ } else if (node.state.current === "time") {
1607
+ states.push("current time");
1608
+ } else if (node.state.current === "true") {
1609
+ states.push("current");
1610
+ }
1611
+ }
1612
+ if (node.state.grabbed !== void 0) {
1613
+ states.push(node.state.grabbed ? "grabbed" : "not grabbed");
1614
+ }
1615
+ return states.join(", ");
1616
+ }
1617
+
1618
+ // ../src/renderer/narrator-renderer.ts
1619
+ function renderNarrator(model, colorize) {
1620
+ const c = createColors(colorize ?? false);
1621
+ const announcements = [];
1622
+ renderNodeNarrator(model.root, announcements, c);
1623
+ return announcements.join("\n");
1624
+ }
1625
+ function renderNodeNarrator(node, announcements, c) {
1626
+ const announcement = formatNodeNarrator(node, c);
1627
+ if (announcement) {
1628
+ announcements.push(announcement);
1629
+ }
1630
+ for (const child of node.children) {
1631
+ if (child.name && child.name === node.name && node.children.length === 1) {
1632
+ for (const grandchild of child.children) {
1633
+ renderNodeNarrator(grandchild, announcements, c);
1634
+ }
1635
+ continue;
1636
+ }
1637
+ renderNodeNarrator(child, announcements, c);
1638
+ }
1639
+ }
1640
+ function formatNodeNarrator(node, c) {
1641
+ const parts = [];
1642
+ const roleFirst = shouldAnnounceRoleFirst2(node.role);
1643
+ if (roleFirst) {
1644
+ const roleText = formatRoleNarrator(node);
1645
+ if (roleText) {
1646
+ parts.push(c.roleName(roleText));
1647
+ }
1648
+ if (node.name) {
1649
+ parts.push(c.elementName(node.name));
1650
+ }
1651
+ } else {
1652
+ if (node.name) {
1653
+ parts.push(c.elementName(node.name));
1654
+ }
1655
+ const roleText = formatRoleNarrator(node);
1656
+ if (roleText) {
1657
+ parts.push(c.roleName(roleText));
1658
+ }
1659
+ }
1660
+ const stateText = formatStatesNarrator(node);
1661
+ if (stateText) {
1662
+ parts.push(c.stateName(stateText));
1663
+ }
1664
+ if (node.value) {
1665
+ const valueText = node.value.text || String(node.value.current);
1666
+ if (valueText) {
1667
+ parts.push(valueText);
1668
+ }
1669
+ }
1670
+ if (node.description) {
1671
+ parts.push(c.description(node.description));
1672
+ }
1673
+ return parts.join(", ");
1674
+ }
1675
+ function shouldAnnounceRoleFirst2(role) {
1676
+ const roleFirstRoles = [
1677
+ "link",
1678
+ "heading",
1679
+ "navigation",
1680
+ "main",
1681
+ "banner",
1682
+ "contentinfo",
1683
+ "complementary",
1684
+ "region",
1685
+ "form",
1686
+ "search",
1687
+ "blockquote",
1688
+ "figure",
1689
+ "dialog",
1690
+ "group",
1691
+ "document"
1692
+ ];
1693
+ return roleFirstRoles.includes(role);
1694
+ }
1695
+ function formatRoleNarrator(node) {
1696
+ const role = node.role;
1697
+ switch (role) {
1698
+ case "button":
1699
+ return "button";
1700
+ case "link":
1701
+ return "link";
1702
+ case "heading":
1703
+ if (node.state.level) {
1704
+ return `Heading level ${node.state.level}`;
1705
+ }
1706
+ return "Heading";
1707
+ case "textbox":
1708
+ return "edit";
1709
+ case "checkbox":
1710
+ return "check box";
1711
+ case "radio":
1712
+ return "radio button";
1713
+ case "combobox":
1714
+ return "combo box";
1715
+ case "listbox":
1716
+ return "list box";
1717
+ case "option":
1718
+ return "option";
1719
+ case "list":
1720
+ return "list";
1721
+ case "listitem":
1722
+ return "list item";
1723
+ case "navigation":
1724
+ return "navigation";
1725
+ case "main":
1726
+ return "main";
1727
+ case "banner":
1728
+ return "banner";
1729
+ case "contentinfo":
1730
+ return "content info";
1731
+ case "complementary":
1732
+ return "complementary";
1733
+ case "form":
1734
+ return "form";
1735
+ case "search":
1736
+ return "search";
1737
+ case "region":
1738
+ return "region";
1739
+ case "img":
1740
+ return "image";
1741
+ case "article":
1742
+ return "article";
1743
+ case "generic":
1744
+ return "";
1745
+ case "staticText":
1746
+ case "paragraph":
1747
+ case "cell":
1748
+ case "term":
1749
+ case "definition":
1750
+ case "caption":
1751
+ return "";
1752
+ case "blockquote":
1753
+ return "block quote";
1754
+ case "code":
1755
+ return "code";
1756
+ case "table": {
1757
+ const rows = node.children.filter((c) => c.role === "row");
1758
+ const rowCount = rows.length;
1759
+ const colCount = rows.length > 0 ? rows[0].children.length : 0;
1760
+ return `table, ${rowCount} rows, ${colCount} columns`;
1761
+ }
1762
+ case "row":
1763
+ return "row";
1764
+ case "columnheader":
1765
+ return "column header";
1766
+ case "rowheader":
1767
+ return "row header";
1768
+ case "figure":
1769
+ return "figure";
1770
+ case "dialog":
1771
+ return "dialog";
1772
+ case "meter":
1773
+ return "meter";
1774
+ case "progressbar":
1775
+ return "progress bar";
1776
+ case "status":
1777
+ return "status";
1778
+ case "group":
1779
+ return node.name ? "group" : "";
1780
+ case "document":
1781
+ return "document";
1782
+ case "application":
1783
+ return "application";
1784
+ case "separator":
1785
+ return "separator";
1786
+ default:
1787
+ return role;
1788
+ }
1789
+ }
1790
+ function formatStatesNarrator(node) {
1791
+ const states = [];
1792
+ if (node.state.expanded !== void 0) {
1793
+ states.push(node.state.expanded ? "expanded" : "collapsed");
1794
+ }
1795
+ if (node.state.checked !== void 0) {
1796
+ if (node.state.checked === "mixed") {
1797
+ states.push("partially selected");
1798
+ } else {
1799
+ states.push(node.state.checked ? "checked" : "unchecked");
1800
+ }
1801
+ }
1802
+ if (node.state.pressed !== void 0) {
1803
+ if (node.state.pressed === "mixed") {
1804
+ states.push("partially pressed");
1805
+ } else {
1806
+ states.push(node.state.pressed ? "pressed" : "not pressed");
1807
+ }
1808
+ }
1809
+ if (node.state.selected !== void 0) {
1810
+ states.push(node.state.selected ? "selected" : "not selected");
1811
+ }
1812
+ if (node.state.disabled) {
1813
+ states.push("disabled");
1814
+ }
1815
+ if (node.state.invalid) {
1816
+ states.push("invalid");
1817
+ }
1818
+ if (node.state.required) {
1819
+ states.push("required");
1820
+ }
1821
+ if (node.state.readonly) {
1822
+ states.push("read only");
1823
+ }
1824
+ if (node.state.busy) {
1825
+ states.push("busy");
1826
+ }
1827
+ if (node.state.current) {
1828
+ if (node.state.current === "page") {
1829
+ states.push("current page");
1830
+ } else if (node.state.current === "step") {
1831
+ states.push("current step");
1832
+ } else if (node.state.current === "location") {
1833
+ states.push("current location");
1834
+ } else if (node.state.current === "date") {
1835
+ states.push("current date");
1836
+ } else if (node.state.current === "time") {
1837
+ states.push("current time");
1838
+ } else if (node.state.current === "true") {
1839
+ states.push("current");
1840
+ }
1841
+ }
1842
+ if (node.state.grabbed !== void 0) {
1843
+ states.push(node.state.grabbed ? "grabbed" : "not grabbed");
1844
+ }
1845
+ return states.join(", ");
1846
+ }
1847
+
1848
+ // ../src/renderer/audit-renderer.ts
1849
+ function generateAuditReport(model) {
1850
+ const statistics = {
1851
+ totalElements: 0,
1852
+ roleDistribution: {},
1853
+ landmarkCount: 0,
1854
+ headingCount: 0,
1855
+ interactiveCount: 0,
1856
+ focusableCount: 0,
1857
+ statesUsed: /* @__PURE__ */ new Set()
1858
+ };
1859
+ const landmarks = [];
1860
+ const headings = [];
1861
+ const interactiveElements = [];
1862
+ const issues = [];
1863
+ collectAuditData(model.root, statistics, landmarks, headings, interactiveElements);
1864
+ detectLandmarkIssues(landmarks, issues);
1865
+ detectHeadingIssues(headings, issues);
1866
+ detectInteractiveIssues(interactiveElements, issues);
1867
+ return {
1868
+ statistics,
1869
+ landmarks,
1870
+ headings,
1871
+ interactiveElements,
1872
+ issues
1873
+ };
1874
+ }
1875
+ function collectAuditData(node, statistics, landmarks, headings, interactiveElements) {
1876
+ if (node.role !== "generic") {
1877
+ statistics.totalElements++;
1878
+ statistics.roleDistribution[node.role] = (statistics.roleDistribution[node.role] || 0) + 1;
1879
+ if (isLandmark(node.role)) {
1880
+ statistics.landmarkCount++;
1881
+ landmarks.push(node);
1882
+ }
1883
+ if (node.role === "heading") {
1884
+ statistics.headingCount++;
1885
+ headings.push(node);
1886
+ }
1887
+ if (isInteractive(node.role)) {
1888
+ statistics.interactiveCount++;
1889
+ interactiveElements.push(node);
1890
+ }
1891
+ if (node.focus.focusable) {
1892
+ statistics.focusableCount++;
1893
+ }
1894
+ Object.keys(node.state).forEach((state) => {
1895
+ if (node.state[state] !== void 0) {
1896
+ statistics.statesUsed.add(state);
1897
+ }
1898
+ });
1899
+ }
1900
+ for (const child of node.children) {
1901
+ collectAuditData(child, statistics, landmarks, headings, interactiveElements);
1902
+ }
1903
+ }
1904
+ function isLandmark(role) {
1905
+ return [
1906
+ "navigation",
1907
+ "main",
1908
+ "banner",
1909
+ "contentinfo",
1910
+ "region",
1911
+ "complementary",
1912
+ "form",
1913
+ "search"
1914
+ ].includes(role);
1915
+ }
1916
+ function isInteractive(role) {
1917
+ return [
1918
+ "button",
1919
+ "link",
1920
+ "textbox",
1921
+ "checkbox",
1922
+ "radio",
1923
+ "combobox",
1924
+ "listbox",
1925
+ "option"
1926
+ ].includes(role);
1927
+ }
1928
+ function detectLandmarkIssues(landmarks, issues) {
1929
+ if (landmarks.length === 0) {
1930
+ issues.push({
1931
+ severity: "info",
1932
+ message: "No landmarks found",
1933
+ suggestion: "Consider adding semantic landmarks (main, nav, aside, etc.)"
1934
+ });
1935
+ }
1936
+ landmarks.forEach((landmark) => {
1937
+ if (!landmark.name && ["navigation", "region", "complementary", "form"].includes(landmark.role)) {
1938
+ issues.push({
1939
+ severity: "warning",
1940
+ message: `${landmark.role} landmark has no accessible name`,
1941
+ suggestion: `Add aria-label="${landmark.role === "navigation" ? "Main navigation" : "Descriptive name"}" to the ${landmark.role} element`,
1942
+ element: {
1943
+ role: landmark.role,
1944
+ name: landmark.name
1945
+ }
1946
+ });
1947
+ }
1948
+ });
1949
+ const landmarksByRole = /* @__PURE__ */ new Map();
1950
+ landmarks.forEach((landmark) => {
1951
+ if (!landmarksByRole.has(landmark.role)) {
1952
+ landmarksByRole.set(landmark.role, []);
1953
+ }
1954
+ landmarksByRole.get(landmark.role).push(landmark);
1955
+ });
1956
+ landmarksByRole.forEach((nodes, role) => {
1957
+ if (nodes.length > 1) {
1958
+ const allUnnamed = nodes.every((n) => !n.name);
1959
+ const allSameName = nodes.every((n) => n.name === nodes[0].name);
1960
+ if (allUnnamed || allSameName) {
1961
+ issues.push({
1962
+ severity: "warning",
1963
+ message: `Multiple ${role} landmarks without distinguishing names`,
1964
+ suggestion: `Add unique aria-label attributes to distinguish between ${role} landmarks`
1965
+ });
1966
+ }
1967
+ }
1968
+ });
1969
+ }
1970
+ function detectHeadingIssues(headings, issues) {
1971
+ if (headings.length === 0) {
1972
+ return;
1973
+ }
1974
+ const firstHeading = headings[0];
1975
+ if (firstHeading.state.level && firstHeading.state.level !== 1) {
1976
+ issues.push({
1977
+ severity: "error",
1978
+ message: `First heading is h${firstHeading.state.level} (should be h1)`,
1979
+ suggestion: `Change <h${firstHeading.state.level}> to <h1> or add h1 before it`,
1980
+ element: {
1981
+ role: firstHeading.role,
1982
+ name: firstHeading.name
1983
+ }
1984
+ });
1985
+ }
1986
+ for (let i = 1; i < headings.length; i++) {
1987
+ const prevLevel = headings[i - 1].state.level || 1;
1988
+ const currLevel = headings[i].state.level || 1;
1989
+ if (currLevel > prevLevel + 1) {
1990
+ issues.push({
1991
+ severity: "error",
1992
+ message: `Heading hierarchy violation: h${prevLevel} followed by h${currLevel} (skipped h${prevLevel + 1})`,
1993
+ suggestion: `Change h${currLevel} to h${prevLevel + 1} or add intermediate heading levels`,
1994
+ element: {
1995
+ role: headings[i].role,
1996
+ name: headings[i].name
1997
+ }
1998
+ });
1999
+ }
2000
+ }
2001
+ }
2002
+ function detectInteractiveIssues(elements, issues) {
2003
+ elements.forEach((element) => {
2004
+ if (!element.name) {
2005
+ issues.push({
2006
+ severity: "error",
2007
+ message: `${element.role} has no accessible name`,
2008
+ suggestion: element.role === "button" ? "Add text content or aria-label to button" : element.role === "link" ? "Add text content or aria-label to link" : `Add aria-label to ${element.role}`,
2009
+ element: {
2010
+ role: element.role,
2011
+ name: element.name
2012
+ }
2013
+ });
2014
+ }
2015
+ if (element.role === "textbox" && !element.name) {
2016
+ issues.push({
2017
+ severity: "error",
2018
+ message: "Input has no associated label",
2019
+ suggestion: "Add <label> element or aria-label attribute",
2020
+ element: {
2021
+ role: element.role,
2022
+ name: element.name
2023
+ }
2024
+ });
2025
+ }
2026
+ });
2027
+ }
2028
+
2029
+ // ../src/browser/analyze.ts
2030
+ var LANDMARK_ROLES = /* @__PURE__ */ new Set([
2031
+ "navigation",
2032
+ "main",
2033
+ "banner",
2034
+ "contentinfo",
2035
+ "complementary",
2036
+ "region",
2037
+ "form",
2038
+ "search"
2039
+ ]);
2040
+ var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
2041
+ "button",
2042
+ "link",
2043
+ "textbox",
2044
+ "checkbox",
2045
+ "radio",
2046
+ "combobox",
2047
+ "listbox",
2048
+ "option"
2049
+ ]);
2050
+ function countStats(node) {
2051
+ const stats = { totalElements: 0, interactiveElements: 0, landmarks: 0, headings: 0 };
2052
+ function walk(n) {
2053
+ if (n.role !== "generic" && n.role !== "staticText") {
2054
+ stats.totalElements++;
2055
+ }
2056
+ if (INTERACTIVE_ROLES.has(n.role)) stats.interactiveElements++;
2057
+ if (LANDMARK_ROLES.has(n.role)) stats.landmarks++;
2058
+ if (n.role === "heading") stats.headings++;
2059
+ for (const child of n.children) walk(child);
2060
+ }
2061
+ walk(node);
2062
+ return stats;
2063
+ }
2064
+ function convertAuditFindings(model) {
2065
+ const report = generateAuditReport(model);
2066
+ return report.issues.map((issue) => ({
2067
+ severity: issue.severity,
2068
+ message: issue.message,
2069
+ selector: issue.element ? `${issue.element.role}${issue.element.name ? ` "${issue.element.name}"` : ""}` : issue.suggestion || ""
2070
+ }));
2071
+ }
2072
+ function emptyResult(extraWarnings = []) {
2073
+ return {
2074
+ nvda: [],
2075
+ jaws: [],
2076
+ voiceover: [],
2077
+ narrator: [],
2078
+ audit: [],
2079
+ stats: { totalElements: 0, interactiveElements: 0, landmarks: 0, headings: 0 },
2080
+ warnings: [...extraWarnings]
2081
+ };
2082
+ }
2083
+ function analyzeElement(root, extraWarnings = []) {
2084
+ if (!root) {
2085
+ return emptyResult(extraWarnings);
2086
+ }
2087
+ let built;
2088
+ try {
2089
+ built = buildAccessibilityTree(root);
2090
+ } catch (err) {
2091
+ return emptyResult([
2092
+ ...extraWarnings,
2093
+ `Analysis failed: ${err instanceof Error ? err.message : String(err)}`
2094
+ ]);
2095
+ }
2096
+ const { model, warnings: treeWarnings } = built;
2097
+ const nvda = renderNVDA(model, false).split("\n").filter(Boolean);
2098
+ const jaws = renderJAWS(model, false).split("\n").filter(Boolean);
2099
+ const voiceover = renderVoiceOver(model, false).split("\n").filter(Boolean);
2100
+ const narrator = renderNarrator(model, false).split("\n").filter(Boolean);
2101
+ const audit = convertAuditFindings(model);
2102
+ const stats = countStats(model.root);
2103
+ const warnings = [
2104
+ ...extraWarnings,
2105
+ ...treeWarnings.map((w) => w.message)
2106
+ ];
2107
+ return { nvda, jaws, voiceover, narrator, audit, stats, warnings };
2108
+ }
2109
+
2110
+ // src/analyzer.ts
2111
+ function analyzeDOM(root) {
2112
+ return analyzeElement(root);
2113
+ }
2114
+
2115
+ // ../src/runtime/selector.ts
2116
+ function generateSelector(element) {
2117
+ if (element.id) {
2118
+ return `#${escapeCSSIdentifier(element.id)}`;
2119
+ }
2120
+ const document2 = element.ownerDocument;
2121
+ if (!document2) {
2122
+ return getTagName(element);
2123
+ }
2124
+ const segments = [];
2125
+ let current = element;
2126
+ while (current && current !== document2.documentElement) {
2127
+ const segment = buildSegment(current, document2);
2128
+ segments.unshift(segment);
2129
+ const partialSelector = segments.join(" > ");
2130
+ try {
2131
+ const matches = document2.querySelectorAll(partialSelector);
2132
+ if (matches.length === 1 && matches[0] === element) {
2133
+ return partialSelector;
2134
+ }
2135
+ } catch {
2136
+ }
2137
+ current = current.parentElement;
2138
+ }
2139
+ if (segments.length === 0) {
2140
+ return getTagName(element);
2141
+ }
2142
+ const fullSelector = segments.join(" > ");
2143
+ return fullSelector;
2144
+ }
2145
+ function buildSegment(element, _document) {
2146
+ const tag = getTagName(element);
2147
+ const parent = element.parentElement;
2148
+ if (parent) {
2149
+ const siblingsWithSameTag = Array.from(parent.children).filter(
2150
+ (child) => getTagName(child) === tag
2151
+ );
2152
+ if (siblingsWithSameTag.length === 1) {
2153
+ return tag;
2154
+ }
2155
+ } else {
2156
+ return tag;
2157
+ }
2158
+ const classes = getStableClasses(element);
2159
+ if (classes.length > 0) {
2160
+ const tagWithClasses = `${tag}.${classes.join(".")}`;
2161
+ if (parent) {
2162
+ const siblingsMatchingClasses = Array.from(parent.children).filter(
2163
+ (child) => {
2164
+ if (getTagName(child) !== tag) return false;
2165
+ return classes.every((cls) => child.classList.contains(cls));
2166
+ }
2167
+ );
2168
+ if (siblingsMatchingClasses.length === 1) {
2169
+ return tagWithClasses;
2170
+ }
2171
+ }
2172
+ }
2173
+ const index = getNthChildIndex(element);
2174
+ return `${tag}:nth-child(${index})`;
2175
+ }
2176
+ function getTagName(element) {
2177
+ return element.tagName.toLowerCase();
2178
+ }
2179
+ function getStableClasses(element) {
2180
+ const classes = Array.from(element.classList);
2181
+ if (classes.length === 0) return [];
2182
+ const stableClasses = classes.filter((cls) => !looksLikeDynamicClass(cls));
2183
+ return stableClasses.sort().map(escapeCSSIdentifier);
2184
+ }
2185
+ function looksLikeDynamicClass(className) {
2186
+ if (/^[a-f0-9]{5,}$/i.test(className)) return true;
2187
+ if (/[_-][a-f0-9]{5,}$/i.test(className)) return true;
2188
+ if (/_{2,}[A-Za-z0-9]{4,}$/.test(className)) return true;
2189
+ return false;
2190
+ }
2191
+ function getNthChildIndex(element) {
2192
+ const parent = element.parentElement;
2193
+ if (!parent) return 1;
2194
+ const children = Array.from(parent.children);
2195
+ const index = children.indexOf(element);
2196
+ return index + 1;
2197
+ }
2198
+ function escapeCSSIdentifier(value) {
2199
+ if (!value) return value;
2200
+ let result = "";
2201
+ for (let i = 0; i < value.length; i++) {
2202
+ const char = value[i];
2203
+ const code = char.charCodeAt(0);
2204
+ if (i === 0 && code >= 48 && code <= 57) {
2205
+ result += `\\3${char} `;
2206
+ continue;
2207
+ }
2208
+ if (char === "!" || char === '"' || char === "#" || char === "$" || char === "%" || char === "&" || char === "'" || char === "(" || char === ")" || char === "*" || char === "+" || char === "," || char === "." || char === "/" || char === ":" || char === ";" || char === "<" || char === "=" || char === ">" || char === "?" || char === "@" || char === "[" || char === "\\" || char === "]" || char === "^" || char === "`" || char === "{" || char === "|" || char === "}" || char === "~" || char === " ") {
2209
+ result += `\\${char}`;
2210
+ continue;
2211
+ }
2212
+ result += char;
2213
+ }
2214
+ return result;
2215
+ }
2216
+
2217
+ // ../src/runtime/observers/focus-observer.ts
2218
+ function computeAccessibleName2(element, document2) {
2219
+ const ariaLabel = element.getAttribute("aria-label");
2220
+ if (ariaLabel && ariaLabel.trim()) {
2221
+ return ariaLabel.trim();
2222
+ }
2223
+ const labelledBy = element.getAttribute("aria-labelledby");
2224
+ if (labelledBy && labelledBy.trim()) {
2225
+ const ids = labelledBy.trim().split(/\s+/);
2226
+ const parts = [];
2227
+ for (const id of ids) {
2228
+ const referenced = document2.getElementById(id);
2229
+ if (referenced && referenced.textContent) {
2230
+ parts.push(referenced.textContent.trim());
2231
+ }
2232
+ }
2233
+ const combined = parts.join(" ");
2234
+ if (combined) {
2235
+ return combined;
2236
+ }
2237
+ }
2238
+ const textContent = element.textContent;
2239
+ if (textContent && textContent.trim()) {
2240
+ return textContent.trim();
2241
+ }
2242
+ return "";
2243
+ }
2244
+ function getElementRole(element) {
2245
+ const explicitRole = element.getAttribute("role");
2246
+ if (explicitRole && explicitRole.trim()) {
2247
+ return explicitRole.trim();
2248
+ }
2249
+ const tagName = element.tagName.toLowerCase();
2250
+ switch (tagName) {
2251
+ case "button":
2252
+ return "button";
2253
+ case "a":
2254
+ return element.hasAttribute("href") ? "link" : "generic";
2255
+ case "input": {
2256
+ const type = (element.getAttribute("type") || "text").toLowerCase();
2257
+ switch (type) {
2258
+ case "button":
2259
+ case "submit":
2260
+ case "reset":
2261
+ case "image":
2262
+ return "button";
2263
+ case "checkbox":
2264
+ return "checkbox";
2265
+ case "radio":
2266
+ return "radio";
2267
+ case "range":
2268
+ return "slider";
2269
+ case "search":
2270
+ return "searchbox";
2271
+ default:
2272
+ return "textbox";
2273
+ }
2274
+ }
2275
+ case "textarea":
2276
+ return "textbox";
2277
+ case "select":
2278
+ return element.hasAttribute("multiple") ? "listbox" : "combobox";
2279
+ case "nav":
2280
+ return "navigation";
2281
+ case "main":
2282
+ return "main";
2283
+ case "header":
2284
+ return "banner";
2285
+ case "footer":
2286
+ return "contentinfo";
2287
+ case "aside":
2288
+ return "complementary";
2289
+ case "form":
2290
+ return "form";
2291
+ case "section":
2292
+ return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : "generic";
2293
+ case "article":
2294
+ return "article";
2295
+ case "dialog":
2296
+ return "dialog";
2297
+ case "table":
2298
+ return "table";
2299
+ case "ul":
2300
+ case "ol":
2301
+ return "list";
2302
+ case "li":
2303
+ return "listitem";
2304
+ case "img":
2305
+ return element.getAttribute("alt") === "" ? "presentation" : "img";
2306
+ case "h1":
2307
+ case "h2":
2308
+ case "h3":
2309
+ case "h4":
2310
+ case "h5":
2311
+ case "h6":
2312
+ return "heading";
2313
+ case "option":
2314
+ return "option";
2315
+ case "progress":
2316
+ return "progressbar";
2317
+ case "output":
2318
+ return "status";
2319
+ case "menu":
2320
+ return "menu";
2321
+ default:
2322
+ return "generic";
2323
+ }
2324
+ }
2325
+ function createFocusObserver(options) {
2326
+ const { document: doc, onEvent, getTimestamp } = options;
2327
+ let active = false;
2328
+ let previousTarget = null;
2329
+ function buildEventTarget2(element) {
2330
+ return {
2331
+ role: getElementRole(element),
2332
+ accessibleName: computeAccessibleName2(element, doc),
2333
+ selector: generateSelector(element)
2334
+ };
2335
+ }
2336
+ function handleFocusIn(event) {
2337
+ if (!active) return;
2338
+ const target = event.target;
2339
+ if (!target || !(target instanceof doc.defaultView.Element)) {
2340
+ return;
2341
+ }
2342
+ const currentTarget = buildEventTarget2(target);
2343
+ const a11yEvent = {
2344
+ type: "FOCUS_CHANGED",
2345
+ timestamp: getTimestamp(),
2346
+ target: currentTarget,
2347
+ payload: {
2348
+ kind: "focus_changed",
2349
+ previousTarget
2350
+ }
2351
+ };
2352
+ onEvent(a11yEvent);
2353
+ previousTarget = currentTarget;
2354
+ }
2355
+ return {
2356
+ start() {
2357
+ if (active) return;
2358
+ active = true;
2359
+ previousTarget = null;
2360
+ doc.addEventListener("focusin", handleFocusIn);
2361
+ },
2362
+ stop() {
2363
+ if (!active) return;
2364
+ active = false;
2365
+ doc.removeEventListener("focusin", handleFocusIn);
2366
+ },
2367
+ get isActive() {
2368
+ return active;
2369
+ }
2370
+ };
2371
+ }
2372
+
2373
+ // ../src/runtime/observers/mutation-observer.ts
2374
+ var ROLE_ATTRIBUTE = "role";
2375
+ var NAME_ATTRIBUTES = /* @__PURE__ */ new Set(["aria-label", "aria-labelledby"]);
2376
+ var STATE_ATTRIBUTES = /* @__PURE__ */ new Set([
2377
+ "aria-expanded",
2378
+ "aria-selected",
2379
+ "aria-checked",
2380
+ "aria-disabled",
2381
+ "aria-hidden"
2382
+ ]);
2383
+ var OBSERVED_ATTRIBUTES = [
2384
+ ROLE_ATTRIBUTE,
2385
+ "aria-label",
2386
+ "aria-labelledby",
2387
+ "aria-expanded",
2388
+ "aria-selected",
2389
+ "aria-checked",
2390
+ "aria-disabled",
2391
+ "aria-hidden"
2392
+ ];
2393
+ function computeAccessibleName3(element, document2) {
2394
+ const ariaLabel = element.getAttribute("aria-label");
2395
+ if (ariaLabel && ariaLabel.trim()) {
2396
+ return ariaLabel.trim();
2397
+ }
2398
+ const labelledBy = element.getAttribute("aria-labelledby");
2399
+ if (labelledBy && labelledBy.trim()) {
2400
+ const ids = labelledBy.trim().split(/\s+/);
2401
+ const parts = [];
2402
+ for (const id of ids) {
2403
+ const referenced = document2.getElementById(id);
2404
+ if (referenced && referenced.textContent) {
2405
+ parts.push(referenced.textContent.trim());
2406
+ }
2407
+ }
2408
+ const combined = parts.join(" ");
2409
+ if (combined) {
2410
+ return combined;
2411
+ }
2412
+ }
2413
+ const textContent = element.textContent;
2414
+ if (textContent && textContent.trim()) {
2415
+ return textContent.trim();
2416
+ }
2417
+ return "";
2418
+ }
2419
+ function getElementRole2(element) {
2420
+ const explicitRole = element.getAttribute("role");
2421
+ if (explicitRole && explicitRole.trim()) {
2422
+ return explicitRole.trim();
2423
+ }
2424
+ const tagName = element.tagName.toLowerCase();
2425
+ switch (tagName) {
2426
+ case "button":
2427
+ return "button";
2428
+ case "a":
2429
+ return element.hasAttribute("href") ? "link" : "generic";
2430
+ case "input": {
2431
+ const type = (element.getAttribute("type") || "text").toLowerCase();
2432
+ switch (type) {
2433
+ case "button":
2434
+ case "submit":
2435
+ case "reset":
2436
+ case "image":
2437
+ return "button";
2438
+ case "checkbox":
2439
+ return "checkbox";
2440
+ case "radio":
2441
+ return "radio";
2442
+ case "range":
2443
+ return "slider";
2444
+ case "search":
2445
+ return "searchbox";
2446
+ default:
2447
+ return "textbox";
2448
+ }
2449
+ }
2450
+ case "textarea":
2451
+ return "textbox";
2452
+ case "select":
2453
+ return element.hasAttribute("multiple") ? "listbox" : "combobox";
2454
+ case "nav":
2455
+ return "navigation";
2456
+ case "main":
2457
+ return "main";
2458
+ case "header":
2459
+ return "banner";
2460
+ case "footer":
2461
+ return "contentinfo";
2462
+ case "aside":
2463
+ return "complementary";
2464
+ case "form":
2465
+ return "form";
2466
+ case "section":
2467
+ return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : "generic";
2468
+ case "article":
2469
+ return "article";
2470
+ case "dialog":
2471
+ return "dialog";
2472
+ case "table":
2473
+ return "table";
2474
+ case "ul":
2475
+ case "ol":
2476
+ return "list";
2477
+ case "li":
2478
+ return "listitem";
2479
+ case "img":
2480
+ return element.getAttribute("alt") === "" ? "presentation" : "img";
2481
+ case "h1":
2482
+ case "h2":
2483
+ case "h3":
2484
+ case "h4":
2485
+ case "h5":
2486
+ case "h6":
2487
+ return "heading";
2488
+ case "option":
2489
+ return "option";
2490
+ case "progress":
2491
+ return "progressbar";
2492
+ case "output":
2493
+ return "status";
2494
+ case "menu":
2495
+ return "menu";
2496
+ default:
2497
+ return "generic";
2498
+ }
2499
+ }
2500
+ function createMutationObserver(options) {
2501
+ const { document: doc, onEvent, getTimestamp } = options;
2502
+ let observer = null;
2503
+ let active = false;
2504
+ function handleMutations(mutations) {
2505
+ if (!active) return;
2506
+ for (const mutation of mutations) {
2507
+ if (mutation.type !== "attributes") {
2508
+ continue;
2509
+ }
2510
+ const attributeName = mutation.attributeName;
2511
+ if (!attributeName) {
2512
+ continue;
2513
+ }
2514
+ const target = mutation.target;
2515
+ if (!(target instanceof Element)) {
2516
+ continue;
2517
+ }
2518
+ if (attributeName === ROLE_ATTRIBUTE) {
2519
+ handleRoleChange(target, mutation.oldValue);
2520
+ } else if (NAME_ATTRIBUTES.has(attributeName)) {
2521
+ handleNameChange(target, attributeName, mutation.oldValue);
2522
+ } else if (STATE_ATTRIBUTES.has(attributeName)) {
2523
+ handleStateChange(target, attributeName, mutation.oldValue);
2524
+ }
2525
+ }
2526
+ }
2527
+ function handleRoleChange(element, oldValue) {
2528
+ const previousRole = oldValue?.trim() || getImplicitRole(element);
2529
+ const newRole = element.getAttribute("role")?.trim() || getImplicitRole(element);
2530
+ if (previousRole === newRole) {
2531
+ return;
2532
+ }
2533
+ const eventTarget = buildEventTarget2(element);
2534
+ const payload = {
2535
+ kind: "role_changed",
2536
+ previousRole,
2537
+ newRole
2538
+ };
2539
+ onEvent({
2540
+ type: "ROLE_CHANGED",
2541
+ timestamp: getTimestamp(),
2542
+ target: eventTarget,
2543
+ payload
2544
+ });
2545
+ }
2546
+ function handleNameChange(element, attributeName, oldValue) {
2547
+ let previousName;
2548
+ let newName;
2549
+ if (attributeName === "aria-label") {
2550
+ previousName = oldValue?.trim() || "";
2551
+ newName = computeAccessibleName3(element, doc);
2552
+ if (!previousName && oldValue === null) {
2553
+ const labelledBy = element.getAttribute("aria-labelledby");
2554
+ if (labelledBy) {
2555
+ previousName = resolveAriaLabelledBy(element, labelledBy);
2556
+ } else {
2557
+ previousName = element.textContent?.trim() || "";
2558
+ }
2559
+ }
2560
+ } else {
2561
+ previousName = oldValue ? resolveAriaLabelledBy(element, oldValue) : "";
2562
+ if (!previousName && oldValue === null) {
2563
+ const ariaLabel = element.getAttribute("aria-label");
2564
+ if (ariaLabel) {
2565
+ previousName = ariaLabel.trim();
2566
+ } else {
2567
+ previousName = element.textContent?.trim() || "";
2568
+ }
2569
+ }
2570
+ newName = computeAccessibleName3(element, doc);
2571
+ }
2572
+ if (previousName === newName) {
2573
+ return;
2574
+ }
2575
+ const eventTarget = buildEventTarget2(element);
2576
+ const payload = {
2577
+ kind: "accessible_name_changed",
2578
+ previousName,
2579
+ newName
2580
+ };
2581
+ onEvent({
2582
+ type: "ACCESSIBLE_NAME_CHANGED",
2583
+ timestamp: getTimestamp(),
2584
+ target: eventTarget,
2585
+ payload
2586
+ });
2587
+ }
2588
+ function handleStateChange(element, attributeName, oldValue) {
2589
+ const currentValue = element.getAttribute(attributeName);
2590
+ const normalizedOld = normalizeStateValue(oldValue);
2591
+ const normalizedNew = normalizeStateValue(currentValue);
2592
+ if (normalizedOld === normalizedNew) {
2593
+ return;
2594
+ }
2595
+ const eventTarget = buildEventTarget2(element);
2596
+ const payload = {
2597
+ kind: "state_changed",
2598
+ attribute: attributeName,
2599
+ previousValue: normalizedOld,
2600
+ newValue: normalizedNew
2601
+ };
2602
+ onEvent({
2603
+ type: "STATE_CHANGED",
2604
+ timestamp: getTimestamp(),
2605
+ target: eventTarget,
2606
+ payload
2607
+ });
2608
+ }
2609
+ function buildEventTarget2(element) {
2610
+ return {
2611
+ role: getElementRole2(element),
2612
+ accessibleName: computeAccessibleName3(element, doc),
2613
+ selector: generateSelector(element)
2614
+ };
2615
+ }
2616
+ function getImplicitRole(element) {
2617
+ const tagName = element.tagName.toLowerCase();
2618
+ switch (tagName) {
2619
+ case "button":
2620
+ return "button";
2621
+ case "a":
2622
+ return element.hasAttribute("href") ? "link" : "generic";
2623
+ case "input": {
2624
+ const type = (element.getAttribute("type") || "text").toLowerCase();
2625
+ switch (type) {
2626
+ case "button":
2627
+ case "submit":
2628
+ case "reset":
2629
+ case "image":
2630
+ return "button";
2631
+ case "checkbox":
2632
+ return "checkbox";
2633
+ case "radio":
2634
+ return "radio";
2635
+ default:
2636
+ return "textbox";
2637
+ }
2638
+ }
2639
+ default:
2640
+ return "generic";
2641
+ }
2642
+ }
2643
+ function resolveAriaLabelledBy(element, idRefs) {
2644
+ const ownerDoc = element.ownerDocument;
2645
+ if (!ownerDoc) {
2646
+ return "";
2647
+ }
2648
+ const ids = idRefs.trim().split(/\s+/).filter(Boolean);
2649
+ const parts = [];
2650
+ for (const id of ids) {
2651
+ const referenced = ownerDoc.getElementById(id);
2652
+ if (referenced && referenced.textContent) {
2653
+ parts.push(referenced.textContent.trim());
2654
+ }
2655
+ }
2656
+ return parts.join(" ");
2657
+ }
2658
+ function normalizeStateValue(value) {
2659
+ if (value === null) {
2660
+ return null;
2661
+ }
2662
+ if (value === "true") {
2663
+ return true;
2664
+ }
2665
+ if (value === "false") {
2666
+ return false;
2667
+ }
2668
+ return value;
2669
+ }
2670
+ return {
2671
+ start() {
2672
+ if (active) return;
2673
+ active = true;
2674
+ observer = new MutationObserver(handleMutations);
2675
+ observer.observe(doc.body ?? doc.documentElement, {
2676
+ attributes: true,
2677
+ attributeOldValue: true,
2678
+ attributeFilter: OBSERVED_ATTRIBUTES,
2679
+ subtree: true
2680
+ });
2681
+ },
2682
+ stop() {
2683
+ if (!active) return;
2684
+ active = false;
2685
+ if (observer) {
2686
+ observer.disconnect();
2687
+ observer = null;
2688
+ }
2689
+ },
2690
+ get isActive() {
2691
+ return active;
2692
+ }
2693
+ };
2694
+ }
2695
+
2696
+ // ../src/runtime/observers/live-region-observer.ts
2697
+ var IMPLICIT_LIVE_ROLES = /* @__PURE__ */ new Set(["alert", "status", "log", "marquee", "timer"]);
2698
+ var ROLE_POLITENESS_MAP = {
2699
+ alert: "assertive",
2700
+ status: "polite",
2701
+ log: "polite",
2702
+ marquee: "polite",
2703
+ timer: "polite"
2704
+ };
2705
+ function createLiveRegionObserver(document2, callback) {
2706
+ let contentObserver = null;
2707
+ let documentObserver = null;
2708
+ const trackedRegions = /* @__PURE__ */ new Set();
2709
+ function getLiveRegionPoliteness(element) {
2710
+ const ariaLive = element.getAttribute("aria-live");
2711
+ if (ariaLive === "assertive") return "assertive";
2712
+ if (ariaLive === "polite") return "polite";
2713
+ if (ariaLive === "off") return null;
2714
+ const role = element.getAttribute("role");
2715
+ if (role && IMPLICIT_LIVE_ROLES.has(role)) {
2716
+ return ROLE_POLITENESS_MAP[role] || "polite";
2717
+ }
2718
+ if (ariaLive && ariaLive !== "off") return "polite";
2719
+ return null;
2720
+ }
2721
+ function isAtomic(element) {
2722
+ return element.getAttribute("aria-atomic") === "true";
2723
+ }
2724
+ function buildEventTarget2(element) {
2725
+ const role = element.getAttribute("role") || "region";
2726
+ const accessibleName = element.getAttribute("aria-label") || element.getAttribute("aria-labelledby") || "";
2727
+ const selector = generateSelector(element);
2728
+ return { role, accessibleName, selector };
2729
+ }
2730
+ function getTextFromNodes(nodes) {
2731
+ const parts = [];
2732
+ nodes.forEach((node) => {
2733
+ if (node.nodeType === Node.TEXT_NODE) {
2734
+ const text = node.textContent?.trim();
2735
+ if (text) parts.push(text);
2736
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
2737
+ const text = node.textContent?.trim();
2738
+ if (text) parts.push(text);
2739
+ }
2740
+ });
2741
+ return parts.join(" ").trim();
2742
+ }
2743
+ function emitAnnouncement(liveRegion, text, politeness) {
2744
+ if (!text) return;
2745
+ const target = buildEventTarget2(liveRegion);
2746
+ callback({
2747
+ type: "ANNOUNCEMENT",
2748
+ target,
2749
+ payload: {
2750
+ kind: "announcement",
2751
+ politeness,
2752
+ text
2753
+ }
2754
+ });
2755
+ }
2756
+ function findLiveRegionAncestor(node) {
2757
+ let current = node;
2758
+ while (current) {
2759
+ if (current.nodeType === Node.ELEMENT_NODE && trackedRegions.has(current)) {
2760
+ return current;
2761
+ }
2762
+ current = current.parentNode;
2763
+ }
2764
+ return null;
2765
+ }
2766
+ function handleContentMutations(mutations) {
2767
+ const regionChanges = /* @__PURE__ */ new Map();
2768
+ for (const mutation of mutations) {
2769
+ const liveRegion = findLiveRegionAncestor(mutation.target);
2770
+ if (!liveRegion) continue;
2771
+ if (!regionChanges.has(liveRegion)) {
2772
+ regionChanges.set(liveRegion, { addedText: [], charDataChanged: false });
2773
+ }
2774
+ const changes = regionChanges.get(liveRegion);
2775
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
2776
+ const text = getTextFromNodes(mutation.addedNodes);
2777
+ if (text) {
2778
+ changes.addedText.push(text);
2779
+ }
2780
+ } else if (mutation.type === "characterData") {
2781
+ changes.charDataChanged = true;
2782
+ }
2783
+ }
2784
+ for (const [region, changes] of regionChanges) {
2785
+ const politeness = getLiveRegionPoliteness(region);
2786
+ if (!politeness) continue;
2787
+ let text;
2788
+ if (isAtomic(region)) {
2789
+ text = region.textContent?.trim() || "";
2790
+ } else {
2791
+ if (changes.addedText.length > 0) {
2792
+ text = changes.addedText.join(" ").trim();
2793
+ } else if (changes.charDataChanged) {
2794
+ text = region.textContent?.trim() || "";
2795
+ } else {
2796
+ text = "";
2797
+ }
2798
+ }
2799
+ emitAnnouncement(region, text, politeness);
2800
+ }
2801
+ }
2802
+ function handleDocumentMutations(mutations) {
2803
+ for (const mutation of mutations) {
2804
+ if (mutation.type !== "childList") continue;
2805
+ mutation.addedNodes.forEach((node) => {
2806
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
2807
+ const element = node;
2808
+ if (getLiveRegionPoliteness(element) !== null && !trackedRegions.has(element)) {
2809
+ trackRegion(element);
2810
+ }
2811
+ const descendants = element.querySelectorAll("[aria-live], [role]");
2812
+ descendants.forEach((desc) => {
2813
+ if (getLiveRegionPoliteness(desc) !== null && !trackedRegions.has(desc)) {
2814
+ trackRegion(desc);
2815
+ }
2816
+ });
2817
+ });
2818
+ mutation.removedNodes.forEach((node) => {
2819
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
2820
+ const element = node;
2821
+ if (trackedRegions.has(element)) {
2822
+ trackedRegions.delete(element);
2823
+ }
2824
+ const descendants = element.querySelectorAll("[aria-live], [role]");
2825
+ descendants.forEach((desc) => {
2826
+ trackedRegions.delete(desc);
2827
+ });
2828
+ });
2829
+ }
2830
+ }
2831
+ function trackRegion(element) {
2832
+ trackedRegions.add(element);
2833
+ }
2834
+ function discoverExistingRegions() {
2835
+ const ariaLiveElements = document2.querySelectorAll("[aria-live]");
2836
+ ariaLiveElements.forEach((el) => {
2837
+ if (getLiveRegionPoliteness(el) !== null) {
2838
+ trackRegion(el);
2839
+ }
2840
+ });
2841
+ IMPLICIT_LIVE_ROLES.forEach((role) => {
2842
+ const roleElements = document2.querySelectorAll(`[role="${role}"]`);
2843
+ roleElements.forEach((el) => {
2844
+ if (!trackedRegions.has(el)) {
2845
+ trackRegion(el);
2846
+ }
2847
+ });
2848
+ });
2849
+ }
2850
+ function start() {
2851
+ discoverExistingRegions();
2852
+ contentObserver = new MutationObserver(handleContentMutations);
2853
+ const body = document2.body;
2854
+ if (body) {
2855
+ contentObserver.observe(body, {
2856
+ childList: true,
2857
+ characterData: true,
2858
+ subtree: true,
2859
+ characterDataOldValue: true
2860
+ });
2861
+ }
2862
+ documentObserver = new MutationObserver(handleDocumentMutations);
2863
+ if (body) {
2864
+ documentObserver.observe(body, {
2865
+ childList: true,
2866
+ subtree: true
2867
+ });
2868
+ }
2869
+ }
2870
+ function stop() {
2871
+ if (contentObserver) {
2872
+ contentObserver.disconnect();
2873
+ contentObserver = null;
2874
+ }
2875
+ if (documentObserver) {
2876
+ documentObserver.disconnect();
2877
+ documentObserver = null;
2878
+ }
2879
+ trackedRegions.clear();
2880
+ }
2881
+ return { start, stop };
2882
+ }
2883
+
2884
+ // ../src/runtime/observers/dialog-observer.ts
2885
+ function computeDialogAccessibleName(element, document2) {
2886
+ const ariaLabel = element.getAttribute("aria-label");
2887
+ if (ariaLabel && ariaLabel.trim()) {
2888
+ return ariaLabel.trim();
2889
+ }
2890
+ const labelledBy = element.getAttribute("aria-labelledby");
2891
+ if (labelledBy && labelledBy.trim()) {
2892
+ const ids = labelledBy.trim().split(/\s+/);
2893
+ const parts = [];
2894
+ for (const id of ids) {
2895
+ const referenced = document2.getElementById(id);
2896
+ if (referenced && referenced.textContent) {
2897
+ parts.push(referenced.textContent.trim());
2898
+ }
2899
+ }
2900
+ const combined = parts.join(" ");
2901
+ if (combined) {
2902
+ return combined;
2903
+ }
2904
+ }
2905
+ const title = element.getAttribute("title");
2906
+ if (title && title.trim()) {
2907
+ return title.trim();
2908
+ }
2909
+ const heading = element.querySelector("h1, h2, h3, h4, h5, h6");
2910
+ if (heading && heading.textContent && heading.textContent.trim()) {
2911
+ return heading.textContent.trim();
2912
+ }
2913
+ return "";
2914
+ }
2915
+ function getDialogRole(element) {
2916
+ const explicitRole = element.getAttribute("role");
2917
+ if (explicitRole && explicitRole.trim()) {
2918
+ return explicitRole.trim();
2919
+ }
2920
+ if (element.tagName.toLowerCase() === "dialog") {
2921
+ return "dialog";
2922
+ }
2923
+ return "generic";
2924
+ }
2925
+ function isDialogElement(element) {
2926
+ if (element.tagName.toLowerCase() === "dialog") {
2927
+ return true;
2928
+ }
2929
+ const role = element.getAttribute("role");
2930
+ return role === "dialog" || role === "alertdialog";
2931
+ }
2932
+ function isDialogModal(element) {
2933
+ const ariaModal = element.getAttribute("aria-modal");
2934
+ if (ariaModal === "true") {
2935
+ return true;
2936
+ }
2937
+ return false;
2938
+ }
2939
+ function createDialogObserver(options) {
2940
+ const { document: doc, onEvent, getTimestamp } = options;
2941
+ let active = false;
2942
+ let mutationObserver = null;
2943
+ const openDialogStack = [];
2944
+ function buildEventTarget2(element) {
2945
+ return {
2946
+ role: getDialogRole(element),
2947
+ accessibleName: computeDialogAccessibleName(element, doc),
2948
+ selector: generateSelector(element)
2949
+ };
2950
+ }
2951
+ function emitDialogOpened(element) {
2952
+ const name = computeDialogAccessibleName(element, doc);
2953
+ const isModal = isDialogModal(element);
2954
+ const target = buildEventTarget2(element);
2955
+ openDialogStack.push({
2956
+ element,
2957
+ name,
2958
+ selector: target.selector
2959
+ });
2960
+ const a11yEvent = {
2961
+ type: "DIALOG_OPENED",
2962
+ timestamp: getTimestamp(),
2963
+ target,
2964
+ payload: {
2965
+ kind: "dialog_opened",
2966
+ dialogName: name,
2967
+ isModal
2968
+ }
2969
+ };
2970
+ onEvent(a11yEvent);
2971
+ }
2972
+ function emitDialogClosed(element) {
2973
+ const name = computeDialogAccessibleName(element, doc);
2974
+ const target = buildEventTarget2(element);
2975
+ const index = openDialogStack.findIndex((d) => d.element === element);
2976
+ if (index !== -1) {
2977
+ openDialogStack.splice(index, 1);
2978
+ }
2979
+ const a11yEvent = {
2980
+ type: "DIALOG_CLOSED",
2981
+ timestamp: getTimestamp(),
2982
+ target,
2983
+ payload: {
2984
+ kind: "dialog_closed",
2985
+ dialogName: name
2986
+ }
2987
+ };
2988
+ onEvent(a11yEvent);
2989
+ }
2990
+ function isTrackedAsOpen(element) {
2991
+ return openDialogStack.some((d) => d.element === element);
2992
+ }
2993
+ function handleMutations(mutations) {
2994
+ if (!active) return;
2995
+ for (const mutation of mutations) {
2996
+ if (mutation.type === "attributes") {
2997
+ const target = mutation.target;
2998
+ if (!(target instanceof doc.defaultView.Element)) continue;
2999
+ if (mutation.attributeName === "open" && target.tagName.toLowerCase() === "dialog") {
3000
+ if (target.hasAttribute("open")) {
3001
+ if (!isTrackedAsOpen(target)) {
3002
+ emitDialogOpened(target);
3003
+ }
3004
+ } else {
3005
+ if (isTrackedAsOpen(target)) {
3006
+ emitDialogClosed(target);
3007
+ }
3008
+ }
3009
+ }
3010
+ if (mutation.attributeName === "aria-modal" && isDialogElement(target)) {
3011
+ if (!isTrackedAsOpen(target) && isVisibleDialog(target)) {
3012
+ emitDialogOpened(target);
3013
+ }
3014
+ }
3015
+ if (mutation.attributeName === "role") {
3016
+ const oldRole = mutation.oldValue;
3017
+ const newRole = target.getAttribute("role");
3018
+ const wasDialog = oldRole === "dialog" || oldRole === "alertdialog";
3019
+ const isNowDialog = newRole === "dialog" || newRole === "alertdialog";
3020
+ if (!wasDialog && isNowDialog && isVisibleDialog(target)) {
3021
+ emitDialogOpened(target);
3022
+ } else if (wasDialog && !isNowDialog && isTrackedAsOpen(target)) {
3023
+ emitDialogClosed(target);
3024
+ }
3025
+ }
3026
+ }
3027
+ if (mutation.type === "childList") {
3028
+ for (let i = 0; i < mutation.addedNodes.length; i++) {
3029
+ const node = mutation.addedNodes[i];
3030
+ if (!(node instanceof doc.defaultView.Element)) continue;
3031
+ if (isDialogElement(node) && isVisibleDialog(node)) {
3032
+ if (!isTrackedAsOpen(node)) {
3033
+ emitDialogOpened(node);
3034
+ }
3035
+ }
3036
+ const dialogDescendants = node.querySelectorAll(
3037
+ 'dialog[open], [role="dialog"], [role="alertdialog"]'
3038
+ );
3039
+ for (let j = 0; j < dialogDescendants.length; j++) {
3040
+ const dialog = dialogDescendants[j];
3041
+ if (isVisibleDialog(dialog) && !isTrackedAsOpen(dialog)) {
3042
+ emitDialogOpened(dialog);
3043
+ }
3044
+ }
3045
+ }
3046
+ for (let i = 0; i < mutation.removedNodes.length; i++) {
3047
+ const node = mutation.removedNodes[i];
3048
+ if (!(node instanceof doc.defaultView.Element)) continue;
3049
+ if (isTrackedAsOpen(node)) {
3050
+ emitDialogClosed(node);
3051
+ }
3052
+ const trackedInRemoved = openDialogStack.filter(
3053
+ (d) => node.contains(d.element)
3054
+ );
3055
+ for (const tracked of trackedInRemoved) {
3056
+ emitDialogClosed(tracked.element);
3057
+ }
3058
+ }
3059
+ }
3060
+ }
3061
+ }
3062
+ function isVisibleDialog(element) {
3063
+ if (element.tagName.toLowerCase() === "dialog") {
3064
+ return element.hasAttribute("open");
3065
+ }
3066
+ return true;
3067
+ }
3068
+ return {
3069
+ start() {
3070
+ if (active) return;
3071
+ active = true;
3072
+ openDialogStack.length = 0;
3073
+ const existingDialogs = doc.querySelectorAll(
3074
+ 'dialog[open], [role="dialog"], [role="alertdialog"]'
3075
+ );
3076
+ for (let i = 0; i < existingDialogs.length; i++) {
3077
+ const dialog = existingDialogs[i];
3078
+ if (isVisibleDialog(dialog)) {
3079
+ openDialogStack.push({
3080
+ element: dialog,
3081
+ name: computeDialogAccessibleName(dialog, doc),
3082
+ selector: generateSelector(dialog)
3083
+ });
3084
+ }
3085
+ }
3086
+ mutationObserver = new MutationObserver(handleMutations);
3087
+ mutationObserver.observe(doc.body || doc.documentElement, {
3088
+ attributes: true,
3089
+ attributeFilter: ["open", "role", "aria-modal"],
3090
+ attributeOldValue: true,
3091
+ childList: true,
3092
+ subtree: true
3093
+ });
3094
+ },
3095
+ stop() {
3096
+ if (!active) return;
3097
+ active = false;
3098
+ if (mutationObserver) {
3099
+ mutationObserver.disconnect();
3100
+ mutationObserver = null;
3101
+ }
3102
+ openDialogStack.length = 0;
3103
+ },
3104
+ get isActive() {
3105
+ return active;
3106
+ },
3107
+ getOpenDialogs() {
3108
+ return openDialogStack.map((d) => d.name);
3109
+ }
3110
+ };
3111
+ }
3112
+
3113
+ // ../src/runtime/engine.ts
3114
+ function createEngine(options) {
3115
+ const { document: doc } = options;
3116
+ let attached = false;
3117
+ let sessionStart = 0;
3118
+ let events = [];
3119
+ function getTimestamp() {
3120
+ return Date.now() - sessionStart;
3121
+ }
3122
+ function collectEvent(event) {
3123
+ events.push(event);
3124
+ }
3125
+ function collectLiveRegionEvent(event) {
3126
+ const fullEvent = {
3127
+ ...event,
3128
+ timestamp: getTimestamp()
3129
+ };
3130
+ events.push(fullEvent);
3131
+ }
3132
+ const focusObs = createFocusObserver({
3133
+ document: doc,
3134
+ onEvent: collectEvent,
3135
+ getTimestamp
3136
+ });
3137
+ const mutationObs = createMutationObserver({
3138
+ document: doc,
3139
+ onEvent: collectEvent,
3140
+ getTimestamp
3141
+ });
3142
+ const liveRegionObs = createLiveRegionObserver(
3143
+ doc,
3144
+ collectLiveRegionEvent
3145
+ );
3146
+ const dialogObs = createDialogObserver({
3147
+ document: doc,
3148
+ onEvent: collectEvent,
3149
+ getTimestamp
3150
+ });
3151
+ return {
3152
+ attach() {
3153
+ if (attached) return;
3154
+ attached = true;
3155
+ sessionStart = Date.now();
3156
+ events = [];
3157
+ focusObs.start();
3158
+ mutationObs.start();
3159
+ liveRegionObs.start();
3160
+ dialogObs.start();
3161
+ },
3162
+ detach() {
3163
+ if (!attached) return;
3164
+ attached = false;
3165
+ focusObs.stop();
3166
+ mutationObs.stop();
3167
+ liveRegionObs.stop();
3168
+ dialogObs.stop();
3169
+ },
3170
+ getEvents() {
3171
+ return [...events];
3172
+ },
3173
+ reset() {
3174
+ events = [];
3175
+ },
3176
+ get isAttached() {
3177
+ return attached;
3178
+ },
3179
+ get dialogObserver() {
3180
+ return {
3181
+ getOpenDialogs() {
3182
+ return dialogObs.getOpenDialogs();
3183
+ }
3184
+ };
3185
+ }
3186
+ };
3187
+ }
3188
+
3189
+ // ../src/runtime/interactions.ts
3190
+ var KEY_MAP = {
3191
+ Tab: { key: "Tab", code: "Tab", keyCode: 9 },
3192
+ Escape: { key: "Escape", code: "Escape", keyCode: 27 },
3193
+ Enter: { key: "Enter", code: "Enter", keyCode: 13 },
3194
+ " ": { key: " ", code: "Space", keyCode: 32 },
3195
+ ArrowUp: { key: "ArrowUp", code: "ArrowUp", keyCode: 38 },
3196
+ ArrowDown: { key: "ArrowDown", code: "ArrowDown", keyCode: 40 },
3197
+ ArrowLeft: { key: "ArrowLeft", code: "ArrowLeft", keyCode: 37 },
3198
+ ArrowRight: { key: "ArrowRight", code: "ArrowRight", keyCode: 39 }
3199
+ };
3200
+ var FOCUSABLE_SELECTOR = [
3201
+ "button:not([disabled])",
3202
+ "a[href]",
3203
+ "input:not([disabled])",
3204
+ "select:not([disabled])",
3205
+ "textarea:not([disabled])",
3206
+ '[tabindex]:not([tabindex="-1"])'
3207
+ ].join(", ");
3208
+ function getFocusableElements(document2) {
3209
+ return Array.from(document2.querySelectorAll(FOCUSABLE_SELECTOR));
3210
+ }
3211
+ function computeAccessibleName4(element, document2) {
3212
+ const ariaLabel = element.getAttribute("aria-label");
3213
+ if (ariaLabel && ariaLabel.trim()) {
3214
+ return ariaLabel.trim();
3215
+ }
3216
+ const labelledBy = element.getAttribute("aria-labelledby");
3217
+ if (labelledBy && labelledBy.trim()) {
3218
+ const ids = labelledBy.trim().split(/\s+/);
3219
+ const parts = [];
3220
+ for (const id of ids) {
3221
+ const referenced = document2.getElementById(id);
3222
+ if (referenced && referenced.textContent) {
3223
+ parts.push(referenced.textContent.trim());
3224
+ }
3225
+ }
3226
+ const combined = parts.join(" ");
3227
+ if (combined) return combined;
3228
+ }
3229
+ const textContent = element.textContent;
3230
+ if (textContent && textContent.trim()) {
3231
+ return textContent.trim();
3232
+ }
3233
+ return "";
3234
+ }
3235
+ function getElementRole3(element) {
3236
+ const explicitRole = element.getAttribute("role");
3237
+ if (explicitRole && explicitRole.trim()) {
3238
+ return explicitRole.trim();
3239
+ }
3240
+ const tagName = element.tagName.toLowerCase();
3241
+ switch (tagName) {
3242
+ case "button":
3243
+ return "button";
3244
+ case "a":
3245
+ return element.hasAttribute("href") ? "link" : "generic";
3246
+ case "input": {
3247
+ const type = (element.getAttribute("type") || "text").toLowerCase();
3248
+ switch (type) {
3249
+ case "button":
3250
+ case "submit":
3251
+ case "reset":
3252
+ case "image":
3253
+ return "button";
3254
+ case "checkbox":
3255
+ return "checkbox";
3256
+ case "radio":
3257
+ return "radio";
3258
+ case "range":
3259
+ return "slider";
3260
+ case "search":
3261
+ return "searchbox";
3262
+ default:
3263
+ return "textbox";
3264
+ }
3265
+ }
3266
+ case "textarea":
3267
+ return "textbox";
3268
+ case "select":
3269
+ return element.hasAttribute("multiple") ? "listbox" : "combobox";
3270
+ case "dialog":
3271
+ return "dialog";
3272
+ default:
3273
+ return "generic";
3274
+ }
3275
+ }
3276
+ function buildEventTarget(element, document2) {
3277
+ return {
3278
+ role: getElementRole3(element),
3279
+ accessibleName: computeAccessibleName4(element, document2),
3280
+ selector: generateSelector(element)
3281
+ };
3282
+ }
3283
+ function dispatchKeyboardEvent(document2, options) {
3284
+ const target = document2.activeElement || document2.body;
3285
+ const commonProps = {
3286
+ key: options.key,
3287
+ code: options.code,
3288
+ keyCode: options.keyCode,
3289
+ which: options.keyCode,
3290
+ shiftKey: options.shiftKey || false,
3291
+ ctrlKey: options.ctrlKey || false,
3292
+ altKey: options.altKey || false,
3293
+ metaKey: options.metaKey || false,
3294
+ bubbles: true,
3295
+ cancelable: true
3296
+ };
3297
+ target.dispatchEvent(new KeyboardEvent("keydown", commonProps));
3298
+ if (options.key.length === 1) {
3299
+ target.dispatchEvent(new KeyboardEvent("keypress", commonProps));
3300
+ }
3301
+ target.dispatchEvent(new KeyboardEvent("keyup", commonProps));
3302
+ }
3303
+ function parseKeyCombo(combo) {
3304
+ const parts = combo.split("+");
3305
+ const modifiers = [];
3306
+ let shiftKey = false;
3307
+ let ctrlKey = false;
3308
+ let altKey = false;
3309
+ let metaKey = false;
3310
+ const key = parts[parts.length - 1];
3311
+ for (let i = 0; i < parts.length - 1; i++) {
3312
+ const mod = parts[i].toLowerCase();
3313
+ switch (mod) {
3314
+ case "shift":
3315
+ shiftKey = true;
3316
+ modifiers.push("Shift");
3317
+ break;
3318
+ case "control":
3319
+ case "ctrl":
3320
+ ctrlKey = true;
3321
+ modifiers.push("Control");
3322
+ break;
3323
+ case "alt":
3324
+ altKey = true;
3325
+ modifiers.push("Alt");
3326
+ break;
3327
+ case "meta":
3328
+ case "cmd":
3329
+ case "command":
3330
+ metaKey = true;
3331
+ modifiers.push("Meta");
3332
+ break;
3333
+ }
3334
+ }
3335
+ return { key, modifiers, shiftKey, ctrlKey, altKey, metaKey };
3336
+ }
3337
+ function getKeyInfo(key) {
3338
+ if (KEY_MAP[key]) {
3339
+ return KEY_MAP[key];
3340
+ }
3341
+ if (key.length === 1) {
3342
+ return {
3343
+ key,
3344
+ code: `Key${key.toUpperCase()}`,
3345
+ keyCode: key.toUpperCase().charCodeAt(0)
3346
+ };
3347
+ }
3348
+ return {
3349
+ key,
3350
+ code: key,
3351
+ keyCode: 0
3352
+ };
3353
+ }
3354
+ function executeClick(selector, document2, onEvent, getTimestamp) {
3355
+ const element = document2.querySelector(selector);
3356
+ if (!element) {
3357
+ const warningEvent = {
3358
+ type: "WARNING",
3359
+ timestamp: getTimestamp(),
3360
+ target: {
3361
+ role: "generic",
3362
+ accessibleName: "",
3363
+ selector
3364
+ },
3365
+ payload: {
3366
+ kind: "warning",
3367
+ message: `Element not found: ${selector}`
3368
+ }
3369
+ };
3370
+ onEvent(warningEvent);
3371
+ return;
3372
+ }
3373
+ const eventProps = { bubbles: true, cancelable: true };
3374
+ element.dispatchEvent(new MouseEvent("mousedown", eventProps));
3375
+ element.dispatchEvent(new MouseEvent("mouseup", eventProps));
3376
+ element.dispatchEvent(new MouseEvent("click", eventProps));
3377
+ if ("focus" in element && typeof element.focus === "function") {
3378
+ element.focus();
3379
+ }
3380
+ }
3381
+ function executeTab(document2, onEvent, getTimestamp) {
3382
+ const focusableElements = getFocusableElements(document2);
3383
+ if (focusableElements.length === 0) return;
3384
+ const activeElement = document2.activeElement;
3385
+ let currentIndex = -1;
3386
+ if (activeElement) {
3387
+ currentIndex = focusableElements.indexOf(activeElement);
3388
+ }
3389
+ const nextIndex = (currentIndex + 1) % focusableElements.length;
3390
+ const nextElement = focusableElements[nextIndex];
3391
+ dispatchKeyboardEvent(document2, {
3392
+ ...KEY_MAP["Tab"],
3393
+ shiftKey: false
3394
+ });
3395
+ if (nextElement && typeof nextElement.focus === "function") {
3396
+ nextElement.focus();
3397
+ }
3398
+ const target = document2.activeElement || document2.body;
3399
+ const keyboardEvent = {
3400
+ type: "KEYBOARD_ACTION",
3401
+ timestamp: getTimestamp(),
3402
+ target: buildEventTarget(target, document2),
3403
+ payload: {
3404
+ kind: "keyboard_action",
3405
+ key: "Tab",
3406
+ modifiers: []
3407
+ }
3408
+ };
3409
+ onEvent(keyboardEvent);
3410
+ }
3411
+ function executeShiftTab(document2, onEvent, getTimestamp) {
3412
+ const focusableElements = getFocusableElements(document2);
3413
+ if (focusableElements.length === 0) return;
3414
+ const activeElement = document2.activeElement;
3415
+ let currentIndex = -1;
3416
+ if (activeElement) {
3417
+ currentIndex = focusableElements.indexOf(activeElement);
3418
+ }
3419
+ const prevIndex = currentIndex <= 0 ? focusableElements.length - 1 : currentIndex - 1;
3420
+ const prevElement = focusableElements[prevIndex];
3421
+ dispatchKeyboardEvent(document2, {
3422
+ ...KEY_MAP["Tab"],
3423
+ shiftKey: true
3424
+ });
3425
+ if (prevElement && typeof prevElement.focus === "function") {
3426
+ prevElement.focus();
3427
+ }
3428
+ const target = document2.activeElement || document2.body;
3429
+ const keyboardEvent = {
3430
+ type: "KEYBOARD_ACTION",
3431
+ timestamp: getTimestamp(),
3432
+ target: buildEventTarget(target, document2),
3433
+ payload: {
3434
+ kind: "keyboard_action",
3435
+ key: "Tab",
3436
+ modifiers: ["Shift"]
3437
+ }
3438
+ };
3439
+ onEvent(keyboardEvent);
3440
+ }
3441
+ function executeKeyAction(keyName, document2, onEvent, getTimestamp) {
3442
+ const keyInfo = KEY_MAP[keyName];
3443
+ if (!keyInfo) return;
3444
+ dispatchKeyboardEvent(document2, {
3445
+ ...keyInfo
3446
+ });
3447
+ const target = document2.activeElement || document2.body;
3448
+ const keyboardEvent = {
3449
+ type: "KEYBOARD_ACTION",
3450
+ timestamp: getTimestamp(),
3451
+ target: buildEventTarget(target, document2),
3452
+ payload: {
3453
+ kind: "keyboard_action",
3454
+ key: keyName,
3455
+ modifiers: []
3456
+ }
3457
+ };
3458
+ onEvent(keyboardEvent);
3459
+ }
3460
+ function executeKeyCombo(combo, document2, onEvent, getTimestamp) {
3461
+ const parsed = parseKeyCombo(combo);
3462
+ const keyInfo = getKeyInfo(parsed.key);
3463
+ dispatchKeyboardEvent(document2, {
3464
+ ...keyInfo,
3465
+ shiftKey: parsed.shiftKey,
3466
+ ctrlKey: parsed.ctrlKey,
3467
+ altKey: parsed.altKey,
3468
+ metaKey: parsed.metaKey
3469
+ });
3470
+ const target = document2.activeElement || document2.body;
3471
+ const keyboardEvent = {
3472
+ type: "KEYBOARD_ACTION",
3473
+ timestamp: getTimestamp(),
3474
+ target: buildEventTarget(target, document2),
3475
+ payload: {
3476
+ kind: "keyboard_action",
3477
+ key: parsed.key,
3478
+ modifiers: parsed.modifiers
3479
+ }
3480
+ };
3481
+ onEvent(keyboardEvent);
3482
+ }
3483
+ async function executeAction(action, document2, onEvent, getTimestamp) {
3484
+ switch (action.type) {
3485
+ case "click":
3486
+ executeClick(action.selector, document2, onEvent, getTimestamp);
3487
+ break;
3488
+ case "tab":
3489
+ executeTab(document2, onEvent, getTimestamp);
3490
+ break;
3491
+ case "shiftTab":
3492
+ executeShiftTab(document2, onEvent, getTimestamp);
3493
+ break;
3494
+ case "escape":
3495
+ executeKeyAction("Escape", document2, onEvent, getTimestamp);
3496
+ break;
3497
+ case "enter":
3498
+ executeKeyAction("Enter", document2, onEvent, getTimestamp);
3499
+ break;
3500
+ case "space":
3501
+ executeKeyAction(" ", document2, onEvent, getTimestamp);
3502
+ break;
3503
+ case "arrowUp":
3504
+ executeKeyAction("ArrowUp", document2, onEvent, getTimestamp);
3505
+ break;
3506
+ case "arrowDown":
3507
+ executeKeyAction("ArrowDown", document2, onEvent, getTimestamp);
3508
+ break;
3509
+ case "arrowLeft":
3510
+ executeKeyAction("ArrowLeft", document2, onEvent, getTimestamp);
3511
+ break;
3512
+ case "arrowRight":
3513
+ executeKeyAction("ArrowRight", document2, onEvent, getTimestamp);
3514
+ break;
3515
+ case "key":
3516
+ executeKeyCombo(action.combo, document2, onEvent, getTimestamp);
3517
+ break;
3518
+ case "wait":
3519
+ await new Promise((resolve) => setTimeout(resolve, action.ms));
3520
+ break;
3521
+ }
3522
+ }
3523
+ async function executeSequence(sequence, document2, onEvent, getTimestamp, settleTime = 100) {
3524
+ for (let i = 0; i < sequence.actions.length; i++) {
3525
+ const action = sequence.actions[i];
3526
+ await executeAction(action, document2, onEvent, getTimestamp);
3527
+ if (i < sequence.actions.length - 1) {
3528
+ await new Promise((resolve) => setTimeout(resolve, settleTime));
3529
+ }
3530
+ }
3531
+ }
3532
+
3533
+ // ../src/runtime/heuristics.ts
3534
+ var DEFAULT_CONFIG = {
3535
+ dialogFocusTimeout: 100,
3536
+ rapidAnnouncementWindow: 500,
3537
+ rapidAnnouncementThreshold: 3,
3538
+ keyboardResponseTimeout: 200
3539
+ };
3540
+ function createHeuristicAnalyzer(config) {
3541
+ const cfg = { ...DEFAULT_CONFIG, ...config };
3542
+ const trackedDialogs = [];
3543
+ const pendingDialogFocusChecks = [];
3544
+ const pendingKeyboardResponses = [];
3545
+ const announcementTimestamps = [];
3546
+ let lastFocusedSelector = null;
3547
+ function createWarning(timestamp, message, target, relatedEvent) {
3548
+ const payload = {
3549
+ kind: "warning",
3550
+ message,
3551
+ relatedEvent
3552
+ };
3553
+ return {
3554
+ type: "WARNING",
3555
+ timestamp,
3556
+ target,
3557
+ payload
3558
+ };
3559
+ }
3560
+ function checkExpiredDialogFocusTimeouts(currentTimestamp) {
3561
+ const warnings = [];
3562
+ for (let i = pendingDialogFocusChecks.length - 1; i >= 0; i--) {
3563
+ const pending = pendingDialogFocusChecks[i];
3564
+ if (pending.resolved) continue;
3565
+ const elapsed = currentTimestamp - pending.openedAt;
3566
+ if (elapsed > cfg.dialogFocusTimeout) {
3567
+ if (pending.isModal) {
3568
+ warnings.push(
3569
+ createWarning(
3570
+ currentTimestamp,
3571
+ "Focus was not moved into modal dialog",
3572
+ {
3573
+ role: "dialog",
3574
+ accessibleName: pending.dialogName,
3575
+ selector: pending.dialogSelector
3576
+ }
3577
+ )
3578
+ );
3579
+ }
3580
+ pending.resolved = true;
3581
+ }
3582
+ }
3583
+ return warnings;
3584
+ }
3585
+ function checkExpiredKeyboardResponses(currentTimestamp) {
3586
+ const warnings = [];
3587
+ for (let i = pendingKeyboardResponses.length - 1; i >= 0; i--) {
3588
+ const pending = pendingKeyboardResponses[i];
3589
+ if (pending.resolved) continue;
3590
+ const elapsed = currentTimestamp - pending.timestamp;
3591
+ if (elapsed > cfg.keyboardResponseTimeout) {
3592
+ warnings.push(
3593
+ createWarning(
3594
+ currentTimestamp,
3595
+ "Keyboard action produced no accessibility response",
3596
+ pending.event.target,
3597
+ pending.event
3598
+ )
3599
+ );
3600
+ pending.resolved = true;
3601
+ }
3602
+ }
3603
+ return warnings;
3604
+ }
3605
+ function checkRapidAnnouncements(currentTimestamp) {
3606
+ const warnings = [];
3607
+ const windowStart = currentTimestamp - cfg.rapidAnnouncementWindow;
3608
+ while (announcementTimestamps.length > 0 && announcementTimestamps[0] < windowStart) {
3609
+ announcementTimestamps.shift();
3610
+ }
3611
+ if (announcementTimestamps.length > cfg.rapidAnnouncementThreshold) {
3612
+ warnings.push(
3613
+ createWarning(
3614
+ currentTimestamp,
3615
+ "Rapid announcements detected: assistive technology users may miss content",
3616
+ {
3617
+ role: "region",
3618
+ accessibleName: "",
3619
+ selector: "body"
3620
+ }
3621
+ )
3622
+ );
3623
+ announcementTimestamps.length = 0;
3624
+ }
3625
+ return warnings;
3626
+ }
3627
+ function checkFocusEscape(event) {
3628
+ const warnings = [];
3629
+ if (event.type !== "FOCUS_CHANGED") return warnings;
3630
+ const modalDialogs = trackedDialogs.filter((d) => d.isModal);
3631
+ if (modalDialogs.length === 0) return warnings;
3632
+ const focusedSelector = event.target.selector;
3633
+ for (const dialog of modalDialogs) {
3634
+ if (!isSelectorInside(focusedSelector, dialog.selector)) {
3635
+ warnings.push(
3636
+ createWarning(
3637
+ event.timestamp,
3638
+ "Focus escaped modal dialog",
3639
+ event.target,
3640
+ event
3641
+ )
3642
+ );
3643
+ break;
3644
+ }
3645
+ }
3646
+ return warnings;
3647
+ }
3648
+ function checkFocusedElementRemoved(event) {
3649
+ const warnings = [];
3650
+ if (event.type === "DOM_MUTATION" && lastFocusedSelector !== null) {
3651
+ if (event.target.selector === lastFocusedSelector) {
3652
+ warnings.push(
3653
+ createWarning(
3654
+ event.timestamp,
3655
+ "Focused element removed without focus management",
3656
+ event.target,
3657
+ event
3658
+ )
3659
+ );
3660
+ }
3661
+ }
3662
+ return warnings;
3663
+ }
3664
+ function isSelectorInside(childSelector, containerSelector) {
3665
+ if (childSelector === containerSelector) return true;
3666
+ if (childSelector.startsWith(containerSelector + " ")) return true;
3667
+ if (childSelector.startsWith(containerSelector + " > ")) return true;
3668
+ if (childSelector.startsWith(containerSelector + ">")) return true;
3669
+ return false;
3670
+ }
3671
+ function processEvent(event) {
3672
+ const warnings = [];
3673
+ warnings.push(...checkExpiredDialogFocusTimeouts(event.timestamp));
3674
+ warnings.push(...checkExpiredKeyboardResponses(event.timestamp));
3675
+ switch (event.type) {
3676
+ case "DIALOG_OPENED": {
3677
+ const payload = event.payload;
3678
+ const dialog = {
3679
+ selector: event.target.selector,
3680
+ name: payload.dialogName,
3681
+ isModal: payload.isModal
3682
+ };
3683
+ trackedDialogs.push(dialog);
3684
+ if (payload.isModal) {
3685
+ pendingDialogFocusChecks.push({
3686
+ dialogSelector: event.target.selector,
3687
+ dialogName: payload.dialogName,
3688
+ openedAt: event.timestamp,
3689
+ isModal: true,
3690
+ resolved: false
3691
+ });
3692
+ }
3693
+ break;
3694
+ }
3695
+ case "DIALOG_CLOSED": {
3696
+ const closedSelector = event.target.selector;
3697
+ const idx = trackedDialogs.findIndex(
3698
+ (d) => d.selector === closedSelector
3699
+ );
3700
+ if (idx !== -1) {
3701
+ trackedDialogs.splice(idx, 1);
3702
+ }
3703
+ for (const pending of pendingDialogFocusChecks) {
3704
+ if (pending.dialogSelector === closedSelector && !pending.resolved) {
3705
+ pending.resolved = true;
3706
+ }
3707
+ }
3708
+ break;
3709
+ }
3710
+ case "FOCUS_CHANGED": {
3711
+ for (const pending of pendingDialogFocusChecks) {
3712
+ if (pending.resolved) continue;
3713
+ if (isSelectorInside(event.target.selector, pending.dialogSelector)) {
3714
+ pending.resolved = true;
3715
+ }
3716
+ }
3717
+ for (const pending of pendingKeyboardResponses) {
3718
+ if (!pending.resolved) {
3719
+ pending.resolved = true;
3720
+ }
3721
+ }
3722
+ warnings.push(...checkFocusEscape(event));
3723
+ lastFocusedSelector = event.target.selector;
3724
+ break;
3725
+ }
3726
+ case "ANNOUNCEMENT": {
3727
+ announcementTimestamps.push(event.timestamp);
3728
+ for (const pending of pendingKeyboardResponses) {
3729
+ if (!pending.resolved) {
3730
+ pending.resolved = true;
3731
+ }
3732
+ }
3733
+ warnings.push(...checkRapidAnnouncements(event.timestamp));
3734
+ break;
3735
+ }
3736
+ case "KEYBOARD_ACTION": {
3737
+ pendingKeyboardResponses.push({
3738
+ event,
3739
+ timestamp: event.timestamp,
3740
+ resolved: false
3741
+ });
3742
+ break;
3743
+ }
3744
+ case "DOM_MUTATION": {
3745
+ warnings.push(...checkFocusedElementRemoved(event));
3746
+ for (const pending of pendingKeyboardResponses) {
3747
+ if (!pending.resolved) {
3748
+ pending.resolved = true;
3749
+ }
3750
+ }
3751
+ break;
3752
+ }
3753
+ case "STATE_CHANGED":
3754
+ case "ROLE_CHANGED":
3755
+ case "ACCESSIBLE_NAME_CHANGED": {
3756
+ for (const pending of pendingKeyboardResponses) {
3757
+ if (!pending.resolved) {
3758
+ pending.resolved = true;
3759
+ }
3760
+ }
3761
+ break;
3762
+ }
3763
+ default:
3764
+ break;
3765
+ }
3766
+ cleanupResolvedChecks();
3767
+ return warnings;
3768
+ }
3769
+ function cleanupResolvedChecks() {
3770
+ for (let i = pendingDialogFocusChecks.length - 1; i >= 0; i--) {
3771
+ if (pendingDialogFocusChecks[i].resolved) {
3772
+ pendingDialogFocusChecks.splice(i, 1);
3773
+ }
3774
+ }
3775
+ for (let i = pendingKeyboardResponses.length - 1; i >= 0; i--) {
3776
+ if (pendingKeyboardResponses[i].resolved) {
3777
+ pendingKeyboardResponses.splice(i, 1);
3778
+ }
3779
+ }
3780
+ }
3781
+ return {
3782
+ process(event) {
3783
+ return processEvent(event);
3784
+ },
3785
+ get openDialogs() {
3786
+ return trackedDialogs.map((d) => d.selector);
3787
+ }
3788
+ };
3789
+ }
3790
+
3791
+ // ../src/version.ts
3792
+ var SPEAKABLE_VERSION = typeof __SPEAKABLE_VERSION__ !== "undefined" && __SPEAKABLE_VERSION__ ? __SPEAKABLE_VERSION__ : "dev";
3793
+
3794
+ // ../src/runtime/timeline-generator.ts
3795
+ var TIMELINE_FORMAT_VERSION = "1.0";
3796
+ var DEFAULT_SETTLE_PERIOD = 500;
3797
+ var DEFAULT_LOAD_TIMEOUT = 1e4;
3798
+ var DOM_STABILITY_WAIT = 100;
3799
+ function createTimelineGenerator(options) {
3800
+ const {
3801
+ document: doc,
3802
+ componentName,
3803
+ storyName,
3804
+ settlePeriod = DEFAULT_SETTLE_PERIOD,
3805
+ loadTimeout = DEFAULT_LOAD_TIMEOUT,
3806
+ heuristics: enableHeuristics = true
3807
+ } = options;
3808
+ let aborted = false;
3809
+ let currentEngine = null;
3810
+ return {
3811
+ async capture(sequence) {
3812
+ aborted = false;
3813
+ await waitForDocumentReady(doc, loadTimeout);
3814
+ if (aborted) {
3815
+ return buildAbortedTimeline(componentName, storyName, sequence);
3816
+ }
3817
+ const engine = createEngine({ document: doc });
3818
+ currentEngine = engine;
3819
+ const heuristicAnalyzer = enableHeuristics ? createHeuristicAnalyzer() : null;
3820
+ const interactionEvents = [];
3821
+ const sessionStart = Date.now();
3822
+ engine.attach();
3823
+ if (aborted) {
3824
+ engine.detach();
3825
+ currentEngine = null;
3826
+ return buildAbortedTimeline(componentName, storyName, sequence);
3827
+ }
3828
+ function getTimestamp() {
3829
+ return Date.now() - sessionStart;
3830
+ }
3831
+ await executeSequence(
3832
+ sequence,
3833
+ doc,
3834
+ (event) => {
3835
+ interactionEvents.push(event);
3836
+ },
3837
+ getTimestamp,
3838
+ DOM_STABILITY_WAIT
3839
+ );
3840
+ if (aborted) {
3841
+ engine.detach();
3842
+ currentEngine = null;
3843
+ return buildAbortedTimeline(componentName, storyName, sequence);
3844
+ }
3845
+ await delay(settlePeriod);
3846
+ engine.detach();
3847
+ currentEngine = null;
3848
+ const duration = Date.now() - sessionStart;
3849
+ const engineEvents = engine.getEvents();
3850
+ const allEvents = mergeEvents(engineEvents, interactionEvents);
3851
+ if (heuristicAnalyzer) {
3852
+ const heuristicWarnings = [];
3853
+ for (const event of allEvents) {
3854
+ const warnings = heuristicAnalyzer.process(event);
3855
+ heuristicWarnings.push(...warnings);
3856
+ }
3857
+ for (const warning of heuristicWarnings) {
3858
+ allEvents.push(warning);
3859
+ }
3860
+ allEvents.sort((a, b) => a.timestamp - b.timestamp);
3861
+ }
3862
+ const allWarnings = allEvents.filter((e) => e.type === "WARNING");
3863
+ const metadata = {
3864
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
3865
+ speakableVersion: SPEAKABLE_VERSION,
3866
+ sourceUrl: getSourceUrl(doc),
3867
+ userAgent: getUserAgent()
3868
+ };
3869
+ const timeline = {
3870
+ version: TIMELINE_FORMAT_VERSION,
3871
+ component: componentName,
3872
+ story: storyName || null,
3873
+ interactionSequence: sequence.description,
3874
+ duration,
3875
+ events: allEvents,
3876
+ warnings: allWarnings,
3877
+ metadata
3878
+ };
3879
+ return timeline;
3880
+ },
3881
+ abort() {
3882
+ aborted = true;
3883
+ if (currentEngine && currentEngine.isAttached) {
3884
+ currentEngine.detach();
3885
+ currentEngine = null;
3886
+ }
3887
+ }
3888
+ };
3889
+ }
3890
+ async function waitForDocumentReady(doc, timeout) {
3891
+ if (doc.body) return;
3892
+ return new Promise((resolve, reject) => {
3893
+ const timeoutId = setTimeout(() => {
3894
+ reject(
3895
+ new Error(
3896
+ `Document load timeout (${timeout}ms): ${getSourceUrl(doc)}`
3897
+ )
3898
+ );
3899
+ }, timeout);
3900
+ const interval = setInterval(() => {
3901
+ if (doc.body) {
3902
+ clearTimeout(timeoutId);
3903
+ clearInterval(interval);
3904
+ resolve();
3905
+ }
3906
+ }, 50);
3907
+ });
3908
+ }
3909
+ function mergeEvents(engineEvents, interactionEvents) {
3910
+ const all = [...engineEvents, ...interactionEvents];
3911
+ all.sort((a, b) => a.timestamp - b.timestamp);
3912
+ return all;
3913
+ }
3914
+ function getSourceUrl(doc) {
3915
+ try {
3916
+ const url = doc.URL;
3917
+ if (url && url !== "about:blank" && url !== "") {
3918
+ return url;
3919
+ }
3920
+ } catch {
3921
+ }
3922
+ return "local";
3923
+ }
3924
+ function getUserAgent() {
3925
+ try {
3926
+ if (typeof navigator !== "undefined" && navigator.userAgent) {
3927
+ return navigator.userAgent;
3928
+ }
3929
+ } catch {
3930
+ }
3931
+ return "jsdom";
3932
+ }
3933
+ function delay(ms) {
3934
+ return new Promise((resolve) => setTimeout(resolve, ms));
3935
+ }
3936
+ function buildAbortedTimeline(componentName, storyName, sequence) {
3937
+ return {
3938
+ version: TIMELINE_FORMAT_VERSION,
3939
+ component: componentName,
3940
+ story: storyName || null,
3941
+ interactionSequence: sequence.description,
3942
+ duration: 0,
3943
+ events: [],
3944
+ warnings: [],
3945
+ metadata: {
3946
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
3947
+ speakableVersion: SPEAKABLE_VERSION,
3948
+ sourceUrl: "local",
3949
+ userAgent: getUserAgent()
3950
+ }
3951
+ };
3952
+ }
3953
+
3954
+ // ../src/browser/capture.ts
3955
+ async function captureTimeline(document2, options) {
3956
+ const {
3957
+ componentName,
3958
+ storyName,
3959
+ sequence,
3960
+ settlePeriod,
3961
+ awaitUpgrade = true,
3962
+ upgradeTimeoutMs
3963
+ } = options;
3964
+ let upgradeWarnings = [];
3965
+ if (awaitUpgrade) {
3966
+ const warnings = await awaitCustomElementsReady(document2, upgradeTimeoutMs);
3967
+ upgradeWarnings = warnings.map((w) => w.message);
3968
+ }
3969
+ const generator = createTimelineGenerator({
3970
+ document: document2,
3971
+ componentName,
3972
+ storyName,
3973
+ ...settlePeriod !== void 0 && { settlePeriod }
3974
+ });
3975
+ const timeline = await generator.capture(sequence);
3976
+ if (upgradeWarnings.length > 0) {
3977
+ const upgradeEvents = upgradeWarnings.map((message) => ({
3978
+ type: "WARNING",
3979
+ timestamp: 0,
3980
+ target: { role: "generic", accessibleName: "", selector: ":root" },
3981
+ payload: { kind: "warning", message }
3982
+ }));
3983
+ return {
3984
+ ...timeline,
3985
+ events: [...upgradeEvents, ...timeline.events],
3986
+ warnings: [...upgradeEvents, ...timeline.warnings]
3987
+ };
3988
+ }
3989
+ return timeline;
3990
+ }
3991
+
3992
+ // ../src/runtime/patterns.ts
3993
+ var MODAL_DIALOG_DEFAULTS = {
3994
+ trigger: "button",
3995
+ container: '[role="dialog"], dialog'
3996
+ };
3997
+ var COMBOBOX_DEFAULTS = {
3998
+ input: '[role="combobox"], input[type="text"]',
3999
+ items: '[role="option"]'
4000
+ };
4001
+ var TABS_DEFAULTS = {
4002
+ container: '[role="tablist"]',
4003
+ items: '[role="tab"]'
4004
+ };
4005
+ var ACCORDION_DEFAULTS = {
4006
+ trigger: "button[aria-expanded]"
4007
+ };
4008
+ function buildModalDialogPattern(selectors) {
4009
+ const trigger = selectors?.trigger ?? MODAL_DIALOG_DEFAULTS.trigger;
4010
+ const actions = [
4011
+ { type: "click", selector: trigger },
4012
+ { type: "tab" },
4013
+ { type: "tab" },
4014
+ { type: "tab" },
4015
+ { type: "escape" }
4016
+ ];
4017
+ return {
4018
+ description: "Modal dialog: click trigger to open, tab through dialog content, press Escape to close, verify focus returns to trigger",
4019
+ actions
4020
+ };
4021
+ }
4022
+ function buildComboboxPattern(selectors) {
4023
+ const input = selectors?.input ?? COMBOBOX_DEFAULTS.input;
4024
+ const actions = [
4025
+ { type: "click", selector: input },
4026
+ { type: "key", combo: "a" },
4027
+ { type: "arrowDown" },
4028
+ { type: "arrowDown" },
4029
+ { type: "enter" }
4030
+ ];
4031
+ return {
4032
+ description: "Combobox: focus input, type to filter, navigate options with arrow keys, select with Enter",
4033
+ actions
4034
+ };
4035
+ }
4036
+ function buildTabsPattern(selectors) {
4037
+ const container = selectors?.container ?? TABS_DEFAULTS.container;
4038
+ const actions = [
4039
+ { type: "click", selector: container },
4040
+ { type: "arrowRight" },
4041
+ { type: "arrowRight" },
4042
+ { type: "enter" },
4043
+ { type: "arrowLeft" },
4044
+ { type: "space" }
4045
+ ];
4046
+ return {
4047
+ description: "Tabs: focus tablist, navigate between tabs with arrow keys, activate with Enter/Space",
4048
+ actions
4049
+ };
4050
+ }
4051
+ function buildAccordionPattern(selectors) {
4052
+ const trigger = selectors?.trigger ?? ACCORDION_DEFAULTS.trigger;
4053
+ const actions = [
4054
+ { type: "click", selector: trigger },
4055
+ { type: "enter" },
4056
+ { type: "arrowDown" },
4057
+ { type: "space" },
4058
+ { type: "arrowDown" },
4059
+ { type: "enter" }
4060
+ ];
4061
+ return {
4062
+ description: "Accordion: focus header, toggle with Enter/Space, navigate between headers with arrow keys",
4063
+ actions
4064
+ };
4065
+ }
4066
+ function getBuiltinPattern(name, selectors) {
4067
+ switch (name) {
4068
+ case "modal-dialog":
4069
+ return buildModalDialogPattern(selectors);
4070
+ case "combobox":
4071
+ return buildComboboxPattern(selectors);
4072
+ case "tabs":
4073
+ return buildTabsPattern(selectors);
4074
+ case "accordion":
4075
+ return buildAccordionPattern(selectors);
4076
+ }
4077
+ }
4078
+
4079
+ // src/sequence.ts
4080
+ var PLAY_PROBE_SEQUENCE = {
4081
+ description: "Keyboard walk: tab through focusable elements",
4082
+ actions: [{ type: "tab" }, { type: "tab" }, { type: "tab" }]
4083
+ };
4084
+ function resolveSequence(context) {
4085
+ const params = context?.parameters?.speakable;
4086
+ if (params && params.timeline === false) {
4087
+ return null;
4088
+ }
4089
+ if (params?.sequence && Array.isArray(params.sequence.actions)) {
4090
+ return params.sequence;
4091
+ }
4092
+ if (params?.pattern) {
4093
+ try {
4094
+ return getBuiltinPattern(params.pattern, params.selectors);
4095
+ } catch {
4096
+ return null;
4097
+ }
4098
+ }
4099
+ if (typeof context?.playFunction === "function" || typeof context?.play === "function") {
4100
+ return PLAY_PROBE_SEQUENCE;
4101
+ }
4102
+ return null;
4103
+ }
4104
+
4105
+ // src/preview.ts
4106
+ var currentObserver = null;
4107
+ var debounceTimer = null;
4108
+ var captureToken = 0;
4109
+ function getChannel() {
4110
+ return window.__STORYBOOK_ADDONS_CHANNEL__;
4111
+ }
4112
+ function findStoryRoot() {
4113
+ return document.getElementById("storybook-root") || document.getElementById("root") || document.body;
4114
+ }
4115
+ function runAnalysis() {
4116
+ const root = findStoryRoot();
4117
+ if (!root) return;
4118
+ const analysis = analyzeDOM(root);
4119
+ const channel = getChannel();
4120
+ if (channel) {
4121
+ channel.emit(EVENT_RESULT, analysis);
4122
+ }
4123
+ }
4124
+ async function runTimelineCapture(context) {
4125
+ const sequence = resolveSequence(context || {});
4126
+ if (!sequence) return;
4127
+ const token = ++captureToken;
4128
+ const componentName = context?.title || context?.kind || context?.componentId || "Component";
4129
+ const storyName = context?.name || context?.story || "Story";
4130
+ let timeline;
4131
+ try {
4132
+ timeline = await captureTimeline(document, {
4133
+ componentName,
4134
+ storyName,
4135
+ sequence
4136
+ });
4137
+ } catch {
4138
+ return;
4139
+ }
4140
+ if (token !== captureToken) return;
4141
+ const channel = getChannel();
4142
+ if (channel) {
4143
+ channel.emit(EVENT_TIMELINE, timeline);
4144
+ }
4145
+ }
4146
+ function debouncedAnalysis() {
4147
+ if (debounceTimer) clearTimeout(debounceTimer);
4148
+ debounceTimer = setTimeout(() => {
4149
+ runAnalysis();
4150
+ debounceTimer = null;
4151
+ }, 150);
4152
+ }
4153
+ function startObserving() {
4154
+ if (currentObserver) {
4155
+ currentObserver.disconnect();
4156
+ currentObserver = null;
4157
+ }
4158
+ const root = findStoryRoot();
4159
+ if (!root) return;
4160
+ currentObserver = new MutationObserver(() => {
4161
+ debouncedAnalysis();
4162
+ });
4163
+ currentObserver.observe(root, {
4164
+ childList: true,
4165
+ subtree: true,
4166
+ attributes: true,
4167
+ attributeFilter: [
4168
+ "aria-expanded",
4169
+ "aria-selected",
4170
+ "aria-checked",
4171
+ "aria-disabled",
4172
+ "aria-hidden",
4173
+ "aria-pressed",
4174
+ "aria-label",
4175
+ "aria-labelledby",
4176
+ "role",
4177
+ "disabled",
4178
+ "hidden"
4179
+ ]
4180
+ });
4181
+ }
4182
+ var withSpeakable = (storyFn, context) => {
4183
+ const result = storyFn();
4184
+ captureToken++;
4185
+ if (typeof window !== "undefined") {
4186
+ requestAnimationFrame(() => {
4187
+ setTimeout(() => {
4188
+ runAnalysis();
4189
+ startObserving();
4190
+ void runTimelineCapture(context);
4191
+ }, 100);
4192
+ });
4193
+ }
4194
+ return result;
4195
+ };
4196
+ var decorators = [withSpeakable];
4197
+ export {
4198
+ decorators
4199
+ };