@reticular/speakable 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -9
- package/dist/cli.js +240 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1058 -1
- package/dist/index.js +4715 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +258 -19
- package/dist/mcp.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
1
7
|
// src/model/types.ts
|
|
2
8
|
var SUPPORTED_ROLES = [
|
|
3
9
|
// Original roles (22)
|
|
@@ -329,10 +335,10 @@ function describeChange(change) {
|
|
|
329
335
|
case "removed":
|
|
330
336
|
return `Removed ${change.node?.role} "${change.node?.name}" from ${change.path}`;
|
|
331
337
|
case "changed": {
|
|
332
|
-
const descriptions = change.changes?.map((
|
|
333
|
-
const oldVal = formatValue(
|
|
334
|
-
const newVal = formatValue(
|
|
335
|
-
return `${
|
|
338
|
+
const descriptions = change.changes?.map((pc2) => {
|
|
339
|
+
const oldVal = formatValue(pc2.oldValue);
|
|
340
|
+
const newVal = formatValue(pc2.newValue);
|
|
341
|
+
return `${pc2.property}: ${oldVal} \u2192 ${newVal}`;
|
|
336
342
|
}) || [];
|
|
337
343
|
return `Changed at ${change.path}: ${descriptions.join(", ")}`;
|
|
338
344
|
}
|
|
@@ -438,7 +444,7 @@ function formatDiffForCI(diff) {
|
|
|
438
444
|
break;
|
|
439
445
|
case "changed":
|
|
440
446
|
const props = change.changes?.map(
|
|
441
|
-
(
|
|
447
|
+
(pc2) => `${pc2.property}:${formatValue2(pc2.oldValue)}->${formatValue2(pc2.newValue)}`
|
|
442
448
|
).join(" | ") || "";
|
|
443
449
|
lines.push(`CHANGED: ${change.path} | ${props}`);
|
|
444
450
|
break;
|
|
@@ -489,21 +495,4725 @@ function hasAccessibilityRegression(diff) {
|
|
|
489
495
|
}
|
|
490
496
|
return false;
|
|
491
497
|
}
|
|
498
|
+
|
|
499
|
+
// src/cli/colors.ts
|
|
500
|
+
import pc from "picocolors";
|
|
501
|
+
var identity = (s) => s;
|
|
502
|
+
function createColors(enabled) {
|
|
503
|
+
if (!enabled) {
|
|
504
|
+
return {
|
|
505
|
+
error: identity,
|
|
506
|
+
warning: identity,
|
|
507
|
+
info: identity,
|
|
508
|
+
success: identity,
|
|
509
|
+
heading: identity,
|
|
510
|
+
title: identity,
|
|
511
|
+
dim: identity,
|
|
512
|
+
roleName: identity,
|
|
513
|
+
stateName: identity,
|
|
514
|
+
elementName: identity,
|
|
515
|
+
sectionHeader: identity,
|
|
516
|
+
description: identity,
|
|
517
|
+
bold: identity,
|
|
518
|
+
enabled: false
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
error: pc.red,
|
|
523
|
+
warning: pc.yellow,
|
|
524
|
+
info: pc.blue,
|
|
525
|
+
success: pc.green,
|
|
526
|
+
heading: (s) => pc.bold(pc.cyan(s)),
|
|
527
|
+
title: (s) => pc.bold(pc.cyan(s)),
|
|
528
|
+
dim: pc.dim,
|
|
529
|
+
roleName: pc.cyan,
|
|
530
|
+
stateName: pc.yellow,
|
|
531
|
+
elementName: (s) => pc.bold(pc.white(s)),
|
|
532
|
+
sectionHeader: (s) => pc.bold(pc.white(s)),
|
|
533
|
+
description: pc.dim,
|
|
534
|
+
bold: pc.bold,
|
|
535
|
+
enabled: true
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/renderer/nvda-renderer.ts
|
|
540
|
+
function renderNVDA(model, colorize) {
|
|
541
|
+
const c = createColors(colorize ?? false);
|
|
542
|
+
const announcements = [];
|
|
543
|
+
renderNodeNVDA(model.root, announcements, c);
|
|
544
|
+
return announcements.join("\n");
|
|
545
|
+
}
|
|
546
|
+
function renderNodeNVDA(node, announcements, c) {
|
|
547
|
+
const announcement = formatNodeNVDA(node, c);
|
|
548
|
+
if (announcement) {
|
|
549
|
+
announcements.push(announcement);
|
|
550
|
+
}
|
|
551
|
+
for (const child of node.children) {
|
|
552
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
553
|
+
for (const grandchild of child.children) {
|
|
554
|
+
renderNodeNVDA(grandchild, announcements, c);
|
|
555
|
+
}
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
renderNodeNVDA(child, announcements, c);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function formatNodeNVDA(node, c) {
|
|
562
|
+
const parts = [];
|
|
563
|
+
if (node.name) {
|
|
564
|
+
parts.push(c.elementName(node.name));
|
|
565
|
+
}
|
|
566
|
+
const roleText = formatRoleNVDA(node);
|
|
567
|
+
if (roleText) {
|
|
568
|
+
parts.push(c.roleName(roleText));
|
|
569
|
+
}
|
|
570
|
+
const stateText = formatStatesNVDA(node);
|
|
571
|
+
if (stateText) {
|
|
572
|
+
parts.push(c.stateName(stateText));
|
|
573
|
+
}
|
|
574
|
+
if (node.value) {
|
|
575
|
+
const valueText = node.value.text || String(node.value.current);
|
|
576
|
+
if (valueText) {
|
|
577
|
+
parts.push(valueText);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (node.description) {
|
|
581
|
+
parts.push(c.description(node.description));
|
|
582
|
+
}
|
|
583
|
+
return parts.join(", ");
|
|
584
|
+
}
|
|
585
|
+
function formatRoleNVDA(node) {
|
|
586
|
+
const role = node.role;
|
|
587
|
+
switch (role) {
|
|
588
|
+
case "button":
|
|
589
|
+
return "button";
|
|
590
|
+
case "link":
|
|
591
|
+
return "link";
|
|
592
|
+
case "heading":
|
|
593
|
+
if (node.state.level) {
|
|
594
|
+
return `heading level ${node.state.level}`;
|
|
595
|
+
}
|
|
596
|
+
return "heading";
|
|
597
|
+
case "textbox":
|
|
598
|
+
return "edit";
|
|
599
|
+
case "checkbox":
|
|
600
|
+
return "checkbox";
|
|
601
|
+
case "radio":
|
|
602
|
+
return "radio button";
|
|
603
|
+
case "combobox":
|
|
604
|
+
return "combo box";
|
|
605
|
+
case "listbox":
|
|
606
|
+
return "list box";
|
|
607
|
+
case "option":
|
|
608
|
+
return "option";
|
|
609
|
+
case "list":
|
|
610
|
+
return "list";
|
|
611
|
+
case "listitem":
|
|
612
|
+
return "list item";
|
|
613
|
+
case "navigation":
|
|
614
|
+
return "navigation landmark";
|
|
615
|
+
case "main":
|
|
616
|
+
return "main landmark";
|
|
617
|
+
case "banner":
|
|
618
|
+
return "banner landmark";
|
|
619
|
+
case "contentinfo":
|
|
620
|
+
return "content information landmark";
|
|
621
|
+
case "region":
|
|
622
|
+
return "region landmark";
|
|
623
|
+
case "complementary":
|
|
624
|
+
return "complementary landmark";
|
|
625
|
+
case "form":
|
|
626
|
+
return "form landmark";
|
|
627
|
+
case "search":
|
|
628
|
+
return "search landmark";
|
|
629
|
+
case "img":
|
|
630
|
+
return "graphic";
|
|
631
|
+
case "article":
|
|
632
|
+
return "article";
|
|
633
|
+
case "generic":
|
|
634
|
+
return "";
|
|
635
|
+
case "staticText":
|
|
636
|
+
case "paragraph":
|
|
637
|
+
case "cell":
|
|
638
|
+
case "term":
|
|
639
|
+
case "definition":
|
|
640
|
+
case "caption":
|
|
641
|
+
return "";
|
|
642
|
+
case "blockquote":
|
|
643
|
+
return "block quote";
|
|
644
|
+
case "code":
|
|
645
|
+
return "code";
|
|
646
|
+
case "table":
|
|
647
|
+
return "table";
|
|
648
|
+
case "row":
|
|
649
|
+
return "row";
|
|
650
|
+
case "columnheader":
|
|
651
|
+
return "column header";
|
|
652
|
+
case "rowheader":
|
|
653
|
+
return "row header";
|
|
654
|
+
case "figure":
|
|
655
|
+
return "figure";
|
|
656
|
+
case "dialog":
|
|
657
|
+
return "dialog";
|
|
658
|
+
case "meter":
|
|
659
|
+
return "meter";
|
|
660
|
+
case "progressbar":
|
|
661
|
+
return "progress bar";
|
|
662
|
+
case "status":
|
|
663
|
+
return "status";
|
|
664
|
+
case "group":
|
|
665
|
+
return node.name ? "grouping" : "";
|
|
666
|
+
case "document":
|
|
667
|
+
return "document";
|
|
668
|
+
case "application":
|
|
669
|
+
return "embedded object";
|
|
670
|
+
case "separator":
|
|
671
|
+
return "separator";
|
|
672
|
+
default:
|
|
673
|
+
return role;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function formatStatesNVDA(node) {
|
|
677
|
+
const states = [];
|
|
678
|
+
if (node.state.expanded !== void 0) {
|
|
679
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
680
|
+
}
|
|
681
|
+
if (node.state.checked !== void 0) {
|
|
682
|
+
if (node.state.checked === "mixed") {
|
|
683
|
+
states.push("half checked");
|
|
684
|
+
} else {
|
|
685
|
+
states.push(node.state.checked ? "checked" : "not checked");
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (node.state.pressed !== void 0) {
|
|
689
|
+
if (node.state.pressed === "mixed") {
|
|
690
|
+
states.push("half pressed");
|
|
691
|
+
} else {
|
|
692
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (node.state.selected !== void 0) {
|
|
696
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
697
|
+
}
|
|
698
|
+
if (node.state.disabled) {
|
|
699
|
+
states.push("unavailable");
|
|
700
|
+
}
|
|
701
|
+
if (node.state.invalid) {
|
|
702
|
+
states.push("invalid entry");
|
|
703
|
+
}
|
|
704
|
+
if (node.state.required) {
|
|
705
|
+
states.push("required");
|
|
706
|
+
}
|
|
707
|
+
if (node.state.readonly) {
|
|
708
|
+
states.push("read only");
|
|
709
|
+
}
|
|
710
|
+
if (node.state.busy) {
|
|
711
|
+
states.push("busy");
|
|
712
|
+
}
|
|
713
|
+
if (node.state.current) {
|
|
714
|
+
if (node.state.current === "page") {
|
|
715
|
+
states.push("current page");
|
|
716
|
+
} else if (node.state.current === "step") {
|
|
717
|
+
states.push("current step");
|
|
718
|
+
} else if (node.state.current === "location") {
|
|
719
|
+
states.push("current location");
|
|
720
|
+
} else if (node.state.current === "date") {
|
|
721
|
+
states.push("current date");
|
|
722
|
+
} else if (node.state.current === "time") {
|
|
723
|
+
states.push("current time");
|
|
724
|
+
} else if (node.state.current === "true") {
|
|
725
|
+
states.push("current");
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (node.state.grabbed !== void 0) {
|
|
729
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
730
|
+
}
|
|
731
|
+
return states.join(", ");
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// src/renderer/jaws-renderer.ts
|
|
735
|
+
function renderJAWS(model, colorize) {
|
|
736
|
+
const c = createColors(colorize ?? false);
|
|
737
|
+
const announcements = [];
|
|
738
|
+
renderNodeJAWS(model.root, announcements, c);
|
|
739
|
+
return announcements.join("\n");
|
|
740
|
+
}
|
|
741
|
+
function renderNodeJAWS(node, announcements, c) {
|
|
742
|
+
const announcement = formatNodeJAWS(node, c);
|
|
743
|
+
if (announcement) {
|
|
744
|
+
announcements.push(announcement);
|
|
745
|
+
}
|
|
746
|
+
for (const child of node.children) {
|
|
747
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
748
|
+
for (const grandchild of child.children) {
|
|
749
|
+
renderNodeJAWS(grandchild, announcements, c);
|
|
750
|
+
}
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
renderNodeJAWS(child, announcements, c);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function formatNodeJAWS(node, c) {
|
|
757
|
+
const parts = [];
|
|
758
|
+
if (node.name) {
|
|
759
|
+
parts.push(c.elementName(node.name));
|
|
760
|
+
}
|
|
761
|
+
const roleText = formatRoleJAWS(node);
|
|
762
|
+
if (roleText) {
|
|
763
|
+
parts.push(c.roleName(roleText));
|
|
764
|
+
}
|
|
765
|
+
const stateText = formatStatesJAWS(node);
|
|
766
|
+
if (stateText) {
|
|
767
|
+
parts.push(c.stateName(stateText));
|
|
768
|
+
}
|
|
769
|
+
if (node.value) {
|
|
770
|
+
const valueText = node.value.text || String(node.value.current);
|
|
771
|
+
if (valueText) {
|
|
772
|
+
parts.push(valueText);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (node.description) {
|
|
776
|
+
parts.push(c.description(node.description));
|
|
777
|
+
}
|
|
778
|
+
return parts.join(", ");
|
|
779
|
+
}
|
|
780
|
+
function formatRoleJAWS(node) {
|
|
781
|
+
const role = node.role;
|
|
782
|
+
switch (role) {
|
|
783
|
+
case "button":
|
|
784
|
+
return "button";
|
|
785
|
+
case "link":
|
|
786
|
+
return "clickable";
|
|
787
|
+
case "heading":
|
|
788
|
+
if (node.state.level) {
|
|
789
|
+
return `heading ${node.state.level}`;
|
|
790
|
+
}
|
|
791
|
+
return "heading";
|
|
792
|
+
case "textbox":
|
|
793
|
+
return "edit";
|
|
794
|
+
case "checkbox":
|
|
795
|
+
return "check box";
|
|
796
|
+
case "radio":
|
|
797
|
+
return "radio button";
|
|
798
|
+
case "combobox":
|
|
799
|
+
return "combo box";
|
|
800
|
+
case "listbox":
|
|
801
|
+
return "list box";
|
|
802
|
+
case "option":
|
|
803
|
+
return "option";
|
|
804
|
+
case "list":
|
|
805
|
+
return "list";
|
|
806
|
+
case "listitem":
|
|
807
|
+
return "list item";
|
|
808
|
+
case "navigation":
|
|
809
|
+
return "navigation region";
|
|
810
|
+
case "main":
|
|
811
|
+
return "main region";
|
|
812
|
+
case "banner":
|
|
813
|
+
return "banner region";
|
|
814
|
+
case "contentinfo":
|
|
815
|
+
return "content information region";
|
|
816
|
+
case "region":
|
|
817
|
+
return "region";
|
|
818
|
+
case "img":
|
|
819
|
+
return "graphic";
|
|
820
|
+
case "article":
|
|
821
|
+
return "article";
|
|
822
|
+
case "complementary":
|
|
823
|
+
return "complementary region";
|
|
824
|
+
case "form":
|
|
825
|
+
return "form";
|
|
826
|
+
case "search":
|
|
827
|
+
return "search region";
|
|
828
|
+
case "generic":
|
|
829
|
+
return "";
|
|
830
|
+
case "staticText":
|
|
831
|
+
case "paragraph":
|
|
832
|
+
case "term":
|
|
833
|
+
case "definition":
|
|
834
|
+
case "caption":
|
|
835
|
+
return "";
|
|
836
|
+
case "blockquote":
|
|
837
|
+
return "block quote";
|
|
838
|
+
case "code":
|
|
839
|
+
return "code";
|
|
840
|
+
case "table": {
|
|
841
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
842
|
+
const rowCount = rows.length;
|
|
843
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
844
|
+
return `table with ${rowCount} rows and ${colCount} columns`;
|
|
845
|
+
}
|
|
846
|
+
case "row": {
|
|
847
|
+
const pos = node.state.posinset ?? 0;
|
|
848
|
+
return `row ${pos}`;
|
|
849
|
+
}
|
|
850
|
+
case "cell": {
|
|
851
|
+
const pos = node.state.posinset ?? 0;
|
|
852
|
+
return `column ${pos}`;
|
|
853
|
+
}
|
|
854
|
+
case "columnheader":
|
|
855
|
+
return "column header";
|
|
856
|
+
case "rowheader":
|
|
857
|
+
return "row header";
|
|
858
|
+
case "figure":
|
|
859
|
+
return "figure";
|
|
860
|
+
case "dialog":
|
|
861
|
+
return "dialog";
|
|
862
|
+
case "meter":
|
|
863
|
+
return "meter";
|
|
864
|
+
case "progressbar":
|
|
865
|
+
return "progress bar";
|
|
866
|
+
case "status":
|
|
867
|
+
return "status";
|
|
868
|
+
case "group":
|
|
869
|
+
return node.name ? "group" : "";
|
|
870
|
+
case "document":
|
|
871
|
+
return "frame";
|
|
872
|
+
case "application":
|
|
873
|
+
return "embedded object";
|
|
874
|
+
case "separator":
|
|
875
|
+
return "separator";
|
|
876
|
+
default:
|
|
877
|
+
return role;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
function formatStatesJAWS(node) {
|
|
881
|
+
const states = [];
|
|
882
|
+
if (node.state.expanded !== void 0) {
|
|
883
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
884
|
+
}
|
|
885
|
+
if (node.state.checked !== void 0) {
|
|
886
|
+
if (node.state.checked === "mixed") {
|
|
887
|
+
states.push("partially checked");
|
|
888
|
+
} else if (node.state.checked) {
|
|
889
|
+
states.push("checked");
|
|
890
|
+
} else {
|
|
891
|
+
states.push("not checked");
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (node.state.pressed !== void 0) {
|
|
895
|
+
if (node.state.pressed === "mixed") {
|
|
896
|
+
states.push("partially pressed");
|
|
897
|
+
} else if (node.state.pressed) {
|
|
898
|
+
states.push("pressed");
|
|
899
|
+
} else {
|
|
900
|
+
states.push("not pressed");
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (node.state.selected !== void 0) {
|
|
904
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
905
|
+
}
|
|
906
|
+
if (node.state.disabled) {
|
|
907
|
+
states.push("unavailable");
|
|
908
|
+
}
|
|
909
|
+
if (node.state.invalid) {
|
|
910
|
+
states.push("invalid entry");
|
|
911
|
+
}
|
|
912
|
+
if (node.state.required) {
|
|
913
|
+
states.push("required");
|
|
914
|
+
}
|
|
915
|
+
if (node.state.readonly) {
|
|
916
|
+
states.push("read only");
|
|
917
|
+
}
|
|
918
|
+
if (node.state.busy) {
|
|
919
|
+
states.push("busy");
|
|
920
|
+
}
|
|
921
|
+
if (node.state.current) {
|
|
922
|
+
switch (node.state.current) {
|
|
923
|
+
case "page":
|
|
924
|
+
states.push("current page");
|
|
925
|
+
break;
|
|
926
|
+
case "step":
|
|
927
|
+
states.push("current step");
|
|
928
|
+
break;
|
|
929
|
+
case "location":
|
|
930
|
+
states.push("current location");
|
|
931
|
+
break;
|
|
932
|
+
case "date":
|
|
933
|
+
states.push("current date");
|
|
934
|
+
break;
|
|
935
|
+
case "time":
|
|
936
|
+
states.push("current time");
|
|
937
|
+
break;
|
|
938
|
+
case "true":
|
|
939
|
+
states.push("current");
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
if (node.state.grabbed !== void 0) {
|
|
944
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
945
|
+
}
|
|
946
|
+
return states.join(", ");
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// src/renderer/voiceover-renderer.ts
|
|
950
|
+
function renderVoiceOver(model, colorize) {
|
|
951
|
+
const c = createColors(colorize ?? false);
|
|
952
|
+
const announcements = [];
|
|
953
|
+
renderNodeVoiceOver(model.root, announcements, c);
|
|
954
|
+
return announcements.join("\n");
|
|
955
|
+
}
|
|
956
|
+
function renderNodeVoiceOver(node, announcements, c) {
|
|
957
|
+
const announcement = formatNodeVoiceOver(node, c);
|
|
958
|
+
if (announcement) {
|
|
959
|
+
announcements.push(announcement);
|
|
960
|
+
}
|
|
961
|
+
for (const child of node.children) {
|
|
962
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
963
|
+
for (const grandchild of child.children) {
|
|
964
|
+
renderNodeVoiceOver(grandchild, announcements, c);
|
|
965
|
+
}
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
renderNodeVoiceOver(child, announcements, c);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function formatNodeVoiceOver(node, c) {
|
|
972
|
+
const parts = [];
|
|
973
|
+
const roleFirst = shouldAnnounceRoleFirst(node.role);
|
|
974
|
+
if (roleFirst) {
|
|
975
|
+
const roleText = formatRoleVoiceOver(node);
|
|
976
|
+
if (roleText) {
|
|
977
|
+
parts.push(c.roleName(roleText));
|
|
978
|
+
}
|
|
979
|
+
if (node.name) {
|
|
980
|
+
parts.push(c.elementName(node.name));
|
|
981
|
+
}
|
|
982
|
+
} else {
|
|
983
|
+
if (node.name) {
|
|
984
|
+
parts.push(c.elementName(node.name));
|
|
985
|
+
}
|
|
986
|
+
const roleText = formatRoleVoiceOver(node);
|
|
987
|
+
if (roleText) {
|
|
988
|
+
parts.push(c.roleName(roleText));
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const stateText = formatStatesVoiceOver(node);
|
|
992
|
+
if (stateText) {
|
|
993
|
+
parts.push(c.stateName(stateText));
|
|
994
|
+
}
|
|
995
|
+
if (node.value) {
|
|
996
|
+
const valueText = node.value.text || String(node.value.current);
|
|
997
|
+
if (valueText) {
|
|
998
|
+
parts.push(valueText);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
if (node.description) {
|
|
1002
|
+
parts.push(c.description(node.description));
|
|
1003
|
+
}
|
|
1004
|
+
return parts.join(", ");
|
|
1005
|
+
}
|
|
1006
|
+
function shouldAnnounceRoleFirst(role) {
|
|
1007
|
+
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";
|
|
1008
|
+
}
|
|
1009
|
+
function formatRoleVoiceOver(node) {
|
|
1010
|
+
const role = node.role;
|
|
1011
|
+
switch (role) {
|
|
1012
|
+
case "button":
|
|
1013
|
+
return "button";
|
|
1014
|
+
case "link":
|
|
1015
|
+
return "link";
|
|
1016
|
+
case "heading":
|
|
1017
|
+
if (node.state.level) {
|
|
1018
|
+
return `heading level ${node.state.level}`;
|
|
1019
|
+
}
|
|
1020
|
+
return "heading";
|
|
1021
|
+
case "textbox":
|
|
1022
|
+
return "edit text";
|
|
1023
|
+
case "checkbox":
|
|
1024
|
+
return "checkbox";
|
|
1025
|
+
case "radio":
|
|
1026
|
+
return "radio button";
|
|
1027
|
+
case "combobox":
|
|
1028
|
+
return "combo box";
|
|
1029
|
+
case "listbox":
|
|
1030
|
+
return "list box";
|
|
1031
|
+
case "option":
|
|
1032
|
+
return "option";
|
|
1033
|
+
case "list":
|
|
1034
|
+
return "list";
|
|
1035
|
+
case "listitem":
|
|
1036
|
+
return "item";
|
|
1037
|
+
case "navigation":
|
|
1038
|
+
return "navigation";
|
|
1039
|
+
case "main":
|
|
1040
|
+
return "main";
|
|
1041
|
+
case "banner":
|
|
1042
|
+
return "banner";
|
|
1043
|
+
case "contentinfo":
|
|
1044
|
+
return "content information";
|
|
1045
|
+
case "region":
|
|
1046
|
+
return "region";
|
|
1047
|
+
case "complementary":
|
|
1048
|
+
return "complementary";
|
|
1049
|
+
case "form":
|
|
1050
|
+
return "form";
|
|
1051
|
+
case "search":
|
|
1052
|
+
return "search";
|
|
1053
|
+
case "img":
|
|
1054
|
+
return "image";
|
|
1055
|
+
case "article":
|
|
1056
|
+
return "article";
|
|
1057
|
+
case "generic":
|
|
1058
|
+
return "";
|
|
1059
|
+
case "staticText":
|
|
1060
|
+
case "paragraph":
|
|
1061
|
+
case "cell":
|
|
1062
|
+
case "term":
|
|
1063
|
+
case "definition":
|
|
1064
|
+
case "caption":
|
|
1065
|
+
return "";
|
|
1066
|
+
case "blockquote":
|
|
1067
|
+
return "blockquote";
|
|
1068
|
+
case "code":
|
|
1069
|
+
return "code";
|
|
1070
|
+
case "table": {
|
|
1071
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
1072
|
+
const rowCount = rows.length;
|
|
1073
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
1074
|
+
return `table, ${rowCount} rows, ${colCount} columns`;
|
|
1075
|
+
}
|
|
1076
|
+
case "row":
|
|
1077
|
+
return "row";
|
|
1078
|
+
case "columnheader":
|
|
1079
|
+
return "column header";
|
|
1080
|
+
case "rowheader":
|
|
1081
|
+
return "row header";
|
|
1082
|
+
case "figure":
|
|
1083
|
+
return "figure";
|
|
1084
|
+
case "dialog":
|
|
1085
|
+
return "web dialog";
|
|
1086
|
+
case "meter":
|
|
1087
|
+
return "level indicator";
|
|
1088
|
+
case "progressbar":
|
|
1089
|
+
return "progress indicator";
|
|
1090
|
+
case "status":
|
|
1091
|
+
return "status";
|
|
1092
|
+
case "group":
|
|
1093
|
+
return node.name ? "group" : "";
|
|
1094
|
+
case "document":
|
|
1095
|
+
return "frame";
|
|
1096
|
+
case "application":
|
|
1097
|
+
return "embedded object";
|
|
1098
|
+
case "separator":
|
|
1099
|
+
return "separator";
|
|
1100
|
+
default:
|
|
1101
|
+
return role;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
function formatStatesVoiceOver(node) {
|
|
1105
|
+
const states = [];
|
|
1106
|
+
if (node.state.expanded !== void 0) {
|
|
1107
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1108
|
+
}
|
|
1109
|
+
if (node.state.checked !== void 0) {
|
|
1110
|
+
if (node.state.checked === "mixed") {
|
|
1111
|
+
states.push("mixed");
|
|
1112
|
+
} else {
|
|
1113
|
+
states.push(node.state.checked ? "checked" : "unchecked");
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
if (node.state.pressed !== void 0) {
|
|
1117
|
+
if (node.state.pressed === "mixed") {
|
|
1118
|
+
states.push("mixed");
|
|
1119
|
+
} else {
|
|
1120
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
if (node.state.selected !== void 0) {
|
|
1124
|
+
states.push(node.state.selected ? "selected" : "unselected");
|
|
1125
|
+
}
|
|
1126
|
+
if (node.state.disabled) {
|
|
1127
|
+
states.push("dimmed");
|
|
1128
|
+
}
|
|
1129
|
+
if (node.state.invalid) {
|
|
1130
|
+
states.push("invalid data");
|
|
1131
|
+
}
|
|
1132
|
+
if (node.state.required) {
|
|
1133
|
+
states.push("required");
|
|
1134
|
+
}
|
|
1135
|
+
if (node.state.readonly) {
|
|
1136
|
+
states.push("read only");
|
|
1137
|
+
}
|
|
1138
|
+
if (node.state.busy) {
|
|
1139
|
+
states.push("busy");
|
|
1140
|
+
}
|
|
1141
|
+
if (node.state.current) {
|
|
1142
|
+
if (node.state.current === "page") {
|
|
1143
|
+
states.push("current page");
|
|
1144
|
+
} else if (node.state.current === "step") {
|
|
1145
|
+
states.push("current step");
|
|
1146
|
+
} else if (node.state.current === "location") {
|
|
1147
|
+
states.push("current location");
|
|
1148
|
+
} else if (node.state.current === "date") {
|
|
1149
|
+
states.push("current date");
|
|
1150
|
+
} else if (node.state.current === "time") {
|
|
1151
|
+
states.push("current time");
|
|
1152
|
+
} else if (node.state.current === "true") {
|
|
1153
|
+
states.push("current");
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (node.state.grabbed !== void 0) {
|
|
1157
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1158
|
+
}
|
|
1159
|
+
return states.join(", ");
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// src/renderer/narrator-renderer.ts
|
|
1163
|
+
function renderNarrator(model, colorize) {
|
|
1164
|
+
const c = createColors(colorize ?? false);
|
|
1165
|
+
const announcements = [];
|
|
1166
|
+
renderNodeNarrator(model.root, announcements, c);
|
|
1167
|
+
return announcements.join("\n");
|
|
1168
|
+
}
|
|
1169
|
+
function renderNodeNarrator(node, announcements, c) {
|
|
1170
|
+
const announcement = formatNodeNarrator(node, c);
|
|
1171
|
+
if (announcement) {
|
|
1172
|
+
announcements.push(announcement);
|
|
1173
|
+
}
|
|
1174
|
+
for (const child of node.children) {
|
|
1175
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
1176
|
+
for (const grandchild of child.children) {
|
|
1177
|
+
renderNodeNarrator(grandchild, announcements, c);
|
|
1178
|
+
}
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
renderNodeNarrator(child, announcements, c);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
function formatNodeNarrator(node, c) {
|
|
1185
|
+
const parts = [];
|
|
1186
|
+
const roleFirst = shouldAnnounceRoleFirst2(node.role);
|
|
1187
|
+
if (roleFirst) {
|
|
1188
|
+
const roleText = formatRoleNarrator(node);
|
|
1189
|
+
if (roleText) {
|
|
1190
|
+
parts.push(c.roleName(roleText));
|
|
1191
|
+
}
|
|
1192
|
+
if (node.name) {
|
|
1193
|
+
parts.push(c.elementName(node.name));
|
|
1194
|
+
}
|
|
1195
|
+
} else {
|
|
1196
|
+
if (node.name) {
|
|
1197
|
+
parts.push(c.elementName(node.name));
|
|
1198
|
+
}
|
|
1199
|
+
const roleText = formatRoleNarrator(node);
|
|
1200
|
+
if (roleText) {
|
|
1201
|
+
parts.push(c.roleName(roleText));
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const stateText = formatStatesNarrator(node);
|
|
1205
|
+
if (stateText) {
|
|
1206
|
+
parts.push(c.stateName(stateText));
|
|
1207
|
+
}
|
|
1208
|
+
if (node.value) {
|
|
1209
|
+
const valueText = node.value.text || String(node.value.current);
|
|
1210
|
+
if (valueText) {
|
|
1211
|
+
parts.push(valueText);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (node.description) {
|
|
1215
|
+
parts.push(c.description(node.description));
|
|
1216
|
+
}
|
|
1217
|
+
return parts.join(", ");
|
|
1218
|
+
}
|
|
1219
|
+
function shouldAnnounceRoleFirst2(role) {
|
|
1220
|
+
const roleFirstRoles = [
|
|
1221
|
+
"link",
|
|
1222
|
+
"heading",
|
|
1223
|
+
"navigation",
|
|
1224
|
+
"main",
|
|
1225
|
+
"banner",
|
|
1226
|
+
"contentinfo",
|
|
1227
|
+
"complementary",
|
|
1228
|
+
"region",
|
|
1229
|
+
"form",
|
|
1230
|
+
"search",
|
|
1231
|
+
"blockquote",
|
|
1232
|
+
"figure",
|
|
1233
|
+
"dialog",
|
|
1234
|
+
"group",
|
|
1235
|
+
"document"
|
|
1236
|
+
];
|
|
1237
|
+
return roleFirstRoles.includes(role);
|
|
1238
|
+
}
|
|
1239
|
+
function formatRoleNarrator(node) {
|
|
1240
|
+
const role = node.role;
|
|
1241
|
+
switch (role) {
|
|
1242
|
+
case "button":
|
|
1243
|
+
return "button";
|
|
1244
|
+
case "link":
|
|
1245
|
+
return "link";
|
|
1246
|
+
case "heading":
|
|
1247
|
+
if (node.state.level) {
|
|
1248
|
+
return `Heading level ${node.state.level}`;
|
|
1249
|
+
}
|
|
1250
|
+
return "Heading";
|
|
1251
|
+
case "textbox":
|
|
1252
|
+
return "edit";
|
|
1253
|
+
case "checkbox":
|
|
1254
|
+
return "check box";
|
|
1255
|
+
case "radio":
|
|
1256
|
+
return "radio button";
|
|
1257
|
+
case "combobox":
|
|
1258
|
+
return "combo box";
|
|
1259
|
+
case "listbox":
|
|
1260
|
+
return "list box";
|
|
1261
|
+
case "option":
|
|
1262
|
+
return "option";
|
|
1263
|
+
case "list":
|
|
1264
|
+
return "list";
|
|
1265
|
+
case "listitem":
|
|
1266
|
+
return "list item";
|
|
1267
|
+
case "navigation":
|
|
1268
|
+
return "navigation";
|
|
1269
|
+
case "main":
|
|
1270
|
+
return "main";
|
|
1271
|
+
case "banner":
|
|
1272
|
+
return "banner";
|
|
1273
|
+
case "contentinfo":
|
|
1274
|
+
return "content info";
|
|
1275
|
+
case "complementary":
|
|
1276
|
+
return "complementary";
|
|
1277
|
+
case "form":
|
|
1278
|
+
return "form";
|
|
1279
|
+
case "search":
|
|
1280
|
+
return "search";
|
|
1281
|
+
case "region":
|
|
1282
|
+
return "region";
|
|
1283
|
+
case "img":
|
|
1284
|
+
return "image";
|
|
1285
|
+
case "article":
|
|
1286
|
+
return "article";
|
|
1287
|
+
case "generic":
|
|
1288
|
+
return "";
|
|
1289
|
+
case "staticText":
|
|
1290
|
+
case "paragraph":
|
|
1291
|
+
case "cell":
|
|
1292
|
+
case "term":
|
|
1293
|
+
case "definition":
|
|
1294
|
+
case "caption":
|
|
1295
|
+
return "";
|
|
1296
|
+
case "blockquote":
|
|
1297
|
+
return "block quote";
|
|
1298
|
+
case "code":
|
|
1299
|
+
return "code";
|
|
1300
|
+
case "table": {
|
|
1301
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
1302
|
+
const rowCount = rows.length;
|
|
1303
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
1304
|
+
return `table, ${rowCount} rows, ${colCount} columns`;
|
|
1305
|
+
}
|
|
1306
|
+
case "row":
|
|
1307
|
+
return "row";
|
|
1308
|
+
case "columnheader":
|
|
1309
|
+
return "column header";
|
|
1310
|
+
case "rowheader":
|
|
1311
|
+
return "row header";
|
|
1312
|
+
case "figure":
|
|
1313
|
+
return "figure";
|
|
1314
|
+
case "dialog":
|
|
1315
|
+
return "dialog";
|
|
1316
|
+
case "meter":
|
|
1317
|
+
return "meter";
|
|
1318
|
+
case "progressbar":
|
|
1319
|
+
return "progress bar";
|
|
1320
|
+
case "status":
|
|
1321
|
+
return "status";
|
|
1322
|
+
case "group":
|
|
1323
|
+
return node.name ? "group" : "";
|
|
1324
|
+
case "document":
|
|
1325
|
+
return "document";
|
|
1326
|
+
case "application":
|
|
1327
|
+
return "application";
|
|
1328
|
+
case "separator":
|
|
1329
|
+
return "separator";
|
|
1330
|
+
default:
|
|
1331
|
+
return role;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
function formatStatesNarrator(node) {
|
|
1335
|
+
const states = [];
|
|
1336
|
+
if (node.state.expanded !== void 0) {
|
|
1337
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1338
|
+
}
|
|
1339
|
+
if (node.state.checked !== void 0) {
|
|
1340
|
+
if (node.state.checked === "mixed") {
|
|
1341
|
+
states.push("partially selected");
|
|
1342
|
+
} else {
|
|
1343
|
+
states.push(node.state.checked ? "checked" : "unchecked");
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (node.state.pressed !== void 0) {
|
|
1347
|
+
if (node.state.pressed === "mixed") {
|
|
1348
|
+
states.push("partially pressed");
|
|
1349
|
+
} else {
|
|
1350
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
if (node.state.selected !== void 0) {
|
|
1354
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
1355
|
+
}
|
|
1356
|
+
if (node.state.disabled) {
|
|
1357
|
+
states.push("disabled");
|
|
1358
|
+
}
|
|
1359
|
+
if (node.state.invalid) {
|
|
1360
|
+
states.push("invalid");
|
|
1361
|
+
}
|
|
1362
|
+
if (node.state.required) {
|
|
1363
|
+
states.push("required");
|
|
1364
|
+
}
|
|
1365
|
+
if (node.state.readonly) {
|
|
1366
|
+
states.push("read only");
|
|
1367
|
+
}
|
|
1368
|
+
if (node.state.busy) {
|
|
1369
|
+
states.push("busy");
|
|
1370
|
+
}
|
|
1371
|
+
if (node.state.current) {
|
|
1372
|
+
if (node.state.current === "page") {
|
|
1373
|
+
states.push("current page");
|
|
1374
|
+
} else if (node.state.current === "step") {
|
|
1375
|
+
states.push("current step");
|
|
1376
|
+
} else if (node.state.current === "location") {
|
|
1377
|
+
states.push("current location");
|
|
1378
|
+
} else if (node.state.current === "date") {
|
|
1379
|
+
states.push("current date");
|
|
1380
|
+
} else if (node.state.current === "time") {
|
|
1381
|
+
states.push("current time");
|
|
1382
|
+
} else if (node.state.current === "true") {
|
|
1383
|
+
states.push("current");
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if (node.state.grabbed !== void 0) {
|
|
1387
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1388
|
+
}
|
|
1389
|
+
return states.join(", ");
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/renderer/audit-renderer.ts
|
|
1393
|
+
function renderAuditReport(model, colorize) {
|
|
1394
|
+
const report = generateAuditReport(model);
|
|
1395
|
+
return formatAuditReport(report, model, colorize);
|
|
1396
|
+
}
|
|
1397
|
+
function generateAuditReport(model) {
|
|
1398
|
+
const statistics = {
|
|
1399
|
+
totalElements: 0,
|
|
1400
|
+
roleDistribution: {},
|
|
1401
|
+
landmarkCount: 0,
|
|
1402
|
+
headingCount: 0,
|
|
1403
|
+
interactiveCount: 0,
|
|
1404
|
+
focusableCount: 0,
|
|
1405
|
+
statesUsed: /* @__PURE__ */ new Set()
|
|
1406
|
+
};
|
|
1407
|
+
const landmarks = [];
|
|
1408
|
+
const headings = [];
|
|
1409
|
+
const interactiveElements = [];
|
|
1410
|
+
const issues = [];
|
|
1411
|
+
collectAuditData(model.root, statistics, landmarks, headings, interactiveElements);
|
|
1412
|
+
detectLandmarkIssues(landmarks, issues);
|
|
1413
|
+
detectHeadingIssues(headings, issues);
|
|
1414
|
+
detectInteractiveIssues(interactiveElements, issues);
|
|
1415
|
+
return {
|
|
1416
|
+
statistics,
|
|
1417
|
+
landmarks,
|
|
1418
|
+
headings,
|
|
1419
|
+
interactiveElements,
|
|
1420
|
+
issues
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
function collectAuditData(node, statistics, landmarks, headings, interactiveElements) {
|
|
1424
|
+
if (node.role !== "generic") {
|
|
1425
|
+
statistics.totalElements++;
|
|
1426
|
+
statistics.roleDistribution[node.role] = (statistics.roleDistribution[node.role] || 0) + 1;
|
|
1427
|
+
if (isLandmark(node.role)) {
|
|
1428
|
+
statistics.landmarkCount++;
|
|
1429
|
+
landmarks.push(node);
|
|
1430
|
+
}
|
|
1431
|
+
if (node.role === "heading") {
|
|
1432
|
+
statistics.headingCount++;
|
|
1433
|
+
headings.push(node);
|
|
1434
|
+
}
|
|
1435
|
+
if (isInteractive(node.role)) {
|
|
1436
|
+
statistics.interactiveCount++;
|
|
1437
|
+
interactiveElements.push(node);
|
|
1438
|
+
}
|
|
1439
|
+
if (node.focus.focusable) {
|
|
1440
|
+
statistics.focusableCount++;
|
|
1441
|
+
}
|
|
1442
|
+
Object.keys(node.state).forEach((state) => {
|
|
1443
|
+
if (node.state[state] !== void 0) {
|
|
1444
|
+
statistics.statesUsed.add(state);
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
for (const child of node.children) {
|
|
1449
|
+
collectAuditData(child, statistics, landmarks, headings, interactiveElements);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function isLandmark(role) {
|
|
1453
|
+
return [
|
|
1454
|
+
"navigation",
|
|
1455
|
+
"main",
|
|
1456
|
+
"banner",
|
|
1457
|
+
"contentinfo",
|
|
1458
|
+
"region",
|
|
1459
|
+
"complementary",
|
|
1460
|
+
"form",
|
|
1461
|
+
"search"
|
|
1462
|
+
].includes(role);
|
|
1463
|
+
}
|
|
1464
|
+
function isInteractive(role) {
|
|
1465
|
+
return [
|
|
1466
|
+
"button",
|
|
1467
|
+
"link",
|
|
1468
|
+
"textbox",
|
|
1469
|
+
"checkbox",
|
|
1470
|
+
"radio",
|
|
1471
|
+
"combobox",
|
|
1472
|
+
"listbox",
|
|
1473
|
+
"option"
|
|
1474
|
+
].includes(role);
|
|
1475
|
+
}
|
|
1476
|
+
function detectLandmarkIssues(landmarks, issues) {
|
|
1477
|
+
if (landmarks.length === 0) {
|
|
1478
|
+
issues.push({
|
|
1479
|
+
severity: "info",
|
|
1480
|
+
message: "No landmarks found",
|
|
1481
|
+
suggestion: "Consider adding semantic landmarks (main, nav, aside, etc.)"
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
landmarks.forEach((landmark) => {
|
|
1485
|
+
if (!landmark.name && ["navigation", "region", "complementary", "form"].includes(landmark.role)) {
|
|
1486
|
+
issues.push({
|
|
1487
|
+
severity: "warning",
|
|
1488
|
+
message: `${landmark.role} landmark has no accessible name`,
|
|
1489
|
+
suggestion: `Add aria-label="${landmark.role === "navigation" ? "Main navigation" : "Descriptive name"}" to the ${landmark.role} element`,
|
|
1490
|
+
element: {
|
|
1491
|
+
role: landmark.role,
|
|
1492
|
+
name: landmark.name
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
const landmarksByRole = /* @__PURE__ */ new Map();
|
|
1498
|
+
landmarks.forEach((landmark) => {
|
|
1499
|
+
if (!landmarksByRole.has(landmark.role)) {
|
|
1500
|
+
landmarksByRole.set(landmark.role, []);
|
|
1501
|
+
}
|
|
1502
|
+
landmarksByRole.get(landmark.role).push(landmark);
|
|
1503
|
+
});
|
|
1504
|
+
landmarksByRole.forEach((nodes, role) => {
|
|
1505
|
+
if (nodes.length > 1) {
|
|
1506
|
+
const allUnnamed = nodes.every((n) => !n.name);
|
|
1507
|
+
const allSameName = nodes.every((n) => n.name === nodes[0].name);
|
|
1508
|
+
if (allUnnamed || allSameName) {
|
|
1509
|
+
issues.push({
|
|
1510
|
+
severity: "warning",
|
|
1511
|
+
message: `Multiple ${role} landmarks without distinguishing names`,
|
|
1512
|
+
suggestion: `Add unique aria-label attributes to distinguish between ${role} landmarks`
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
function detectHeadingIssues(headings, issues) {
|
|
1519
|
+
if (headings.length === 0) {
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
const firstHeading = headings[0];
|
|
1523
|
+
if (firstHeading.state.level && firstHeading.state.level !== 1) {
|
|
1524
|
+
issues.push({
|
|
1525
|
+
severity: "error",
|
|
1526
|
+
message: `First heading is h${firstHeading.state.level} (should be h1)`,
|
|
1527
|
+
suggestion: `Change <h${firstHeading.state.level}> to <h1> or add h1 before it`,
|
|
1528
|
+
element: {
|
|
1529
|
+
role: firstHeading.role,
|
|
1530
|
+
name: firstHeading.name
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
for (let i = 1; i < headings.length; i++) {
|
|
1535
|
+
const prevLevel = headings[i - 1].state.level || 1;
|
|
1536
|
+
const currLevel = headings[i].state.level || 1;
|
|
1537
|
+
if (currLevel > prevLevel + 1) {
|
|
1538
|
+
issues.push({
|
|
1539
|
+
severity: "error",
|
|
1540
|
+
message: `Heading hierarchy violation: h${prevLevel} followed by h${currLevel} (skipped h${prevLevel + 1})`,
|
|
1541
|
+
suggestion: `Change h${currLevel} to h${prevLevel + 1} or add intermediate heading levels`,
|
|
1542
|
+
element: {
|
|
1543
|
+
role: headings[i].role,
|
|
1544
|
+
name: headings[i].name
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
function detectInteractiveIssues(elements, issues) {
|
|
1551
|
+
elements.forEach((element) => {
|
|
1552
|
+
if (!element.name) {
|
|
1553
|
+
issues.push({
|
|
1554
|
+
severity: "error",
|
|
1555
|
+
message: `${element.role} has no accessible name`,
|
|
1556
|
+
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}`,
|
|
1557
|
+
element: {
|
|
1558
|
+
role: element.role,
|
|
1559
|
+
name: element.name
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
if (element.role === "textbox" && !element.name) {
|
|
1564
|
+
issues.push({
|
|
1565
|
+
severity: "error",
|
|
1566
|
+
message: "Input has no associated label",
|
|
1567
|
+
suggestion: "Add <label> element or aria-label attribute",
|
|
1568
|
+
element: {
|
|
1569
|
+
role: element.role,
|
|
1570
|
+
name: element.name
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
function formatAuditReport(report, model, colorize) {
|
|
1577
|
+
const c = createColors(colorize ?? false);
|
|
1578
|
+
const lines = [];
|
|
1579
|
+
lines.push(c.title("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
|
|
1580
|
+
lines.push(c.title("\u2551 ACCESSIBILITY AUDIT REPORT \u2551"));
|
|
1581
|
+
lines.push(c.title("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
|
|
1582
|
+
lines.push("");
|
|
1583
|
+
lines.push(c.dim(`Analyzed: ${model.metadata.extractedAt}`));
|
|
1584
|
+
lines.push("");
|
|
1585
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1586
|
+
lines.push(c.heading("\u{1F4CD} LANDMARK STRUCTURE"));
|
|
1587
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1588
|
+
lines.push("");
|
|
1589
|
+
if (report.landmarks.length === 0) {
|
|
1590
|
+
lines.push(c.error("\u2717 No landmarks found"));
|
|
1591
|
+
} else {
|
|
1592
|
+
lines.push(c.success(`\u2713 ${report.landmarks.length} landmark(s) found`));
|
|
1593
|
+
lines.push("");
|
|
1594
|
+
report.landmarks.forEach((landmark) => {
|
|
1595
|
+
const name = landmark.name ? `"${landmark.name}"` : "(unnamed)";
|
|
1596
|
+
lines.push(`${landmark.role} ${name}`);
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
lines.push("");
|
|
1600
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1601
|
+
lines.push(c.heading("\u{1F4D1} HEADING HIERARCHY"));
|
|
1602
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1603
|
+
lines.push("");
|
|
1604
|
+
if (report.headings.length === 0) {
|
|
1605
|
+
lines.push(c.info("\u2139 No headings found"));
|
|
1606
|
+
} else {
|
|
1607
|
+
const hasHierarchyIssues = report.issues.some(
|
|
1608
|
+
(i) => i.message.includes("heading") || i.message.includes("h1") || i.message.includes("h2")
|
|
1609
|
+
);
|
|
1610
|
+
lines.push(`${hasHierarchyIssues ? c.error("\u2717") : c.success("\u2713")} ${report.headings.length} heading(s) found ${hasHierarchyIssues ? "(HIERARCHY VIOLATION)" : "(proper hierarchy)"}`);
|
|
1611
|
+
lines.push("");
|
|
1612
|
+
report.headings.forEach((heading) => {
|
|
1613
|
+
const level = heading.state.level || 1;
|
|
1614
|
+
const indent = " ".repeat(level - 1);
|
|
1615
|
+
lines.push(`${indent}h${level} "${heading.name}"`);
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
lines.push("");
|
|
1619
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1620
|
+
lines.push(c.heading("\u{1F3AF} INTERACTIVE ELEMENTS"));
|
|
1621
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1622
|
+
lines.push("");
|
|
1623
|
+
if (report.interactiveElements.length === 0) {
|
|
1624
|
+
lines.push(c.info("\u2139 No interactive elements found"));
|
|
1625
|
+
} else {
|
|
1626
|
+
lines.push(c.success(`\u2713 ${report.interactiveElements.length} interactive element(s) found`));
|
|
1627
|
+
lines.push("");
|
|
1628
|
+
const byRole = /* @__PURE__ */ new Map();
|
|
1629
|
+
report.interactiveElements.forEach((el) => {
|
|
1630
|
+
if (!byRole.has(el.role)) {
|
|
1631
|
+
byRole.set(el.role, []);
|
|
1632
|
+
}
|
|
1633
|
+
byRole.get(el.role).push(el);
|
|
1634
|
+
});
|
|
1635
|
+
byRole.forEach((elements, role) => {
|
|
1636
|
+
lines.push(`${role}s (${elements.length}):`);
|
|
1637
|
+
elements.forEach((el) => {
|
|
1638
|
+
const name = el.name ? `"${el.name}"` : "(unnamed)";
|
|
1639
|
+
const states = Object.keys(el.state).filter((k) => el.state[k] !== void 0);
|
|
1640
|
+
const stateStr = states.length > 0 ? ` [${states.join(", ")}]` : "";
|
|
1641
|
+
lines.push(` \u2022 ${name}${stateStr}`);
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
lines.push("");
|
|
1646
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1647
|
+
lines.push(c.heading("\u{1F4CA} SUMMARY STATISTICS"));
|
|
1648
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1649
|
+
lines.push("");
|
|
1650
|
+
lines.push(`Total accessible elements: ${report.statistics.totalElements}`);
|
|
1651
|
+
lines.push("");
|
|
1652
|
+
lines.push("Role distribution:");
|
|
1653
|
+
Object.entries(report.statistics.roleDistribution).sort((a, b) => b[1] - a[1]).forEach(([role, count]) => {
|
|
1654
|
+
lines.push(c.dim(` \u2022 ${role}: ${count}`));
|
|
1655
|
+
});
|
|
1656
|
+
lines.push("");
|
|
1657
|
+
lines.push(c.dim(`Focusable elements: ${report.statistics.focusableCount}`));
|
|
1658
|
+
lines.push("");
|
|
1659
|
+
if (report.issues.length > 0) {
|
|
1660
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1661
|
+
lines.push(c.heading("\u26A0\uFE0F ACCESSIBILITY ISSUES"));
|
|
1662
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1663
|
+
lines.push("");
|
|
1664
|
+
const errors = report.issues.filter((i) => i.severity === "error");
|
|
1665
|
+
const warnings = report.issues.filter((i) => i.severity === "warning");
|
|
1666
|
+
const infos = report.issues.filter((i) => i.severity === "info");
|
|
1667
|
+
if (errors.length > 0) {
|
|
1668
|
+
lines.push(c.error(`\u2717 Error (${errors.length}):`));
|
|
1669
|
+
errors.forEach((issue) => {
|
|
1670
|
+
lines.push(c.error(` \u2022 ${issue.message}`));
|
|
1671
|
+
if (issue.suggestion) {
|
|
1672
|
+
lines.push(` \u2192 ${issue.suggestion}`);
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
lines.push("");
|
|
1676
|
+
}
|
|
1677
|
+
if (warnings.length > 0) {
|
|
1678
|
+
lines.push(c.warning(`\u26A0 Warning (${warnings.length}):`));
|
|
1679
|
+
warnings.forEach((issue) => {
|
|
1680
|
+
lines.push(c.warning(` \u2022 ${issue.message}`));
|
|
1681
|
+
if (issue.suggestion) {
|
|
1682
|
+
lines.push(` \u2192 ${issue.suggestion}`);
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
lines.push("");
|
|
1686
|
+
}
|
|
1687
|
+
if (infos.length > 0) {
|
|
1688
|
+
lines.push(c.info(`\u2139 Info (${infos.length}):`));
|
|
1689
|
+
infos.forEach((issue) => {
|
|
1690
|
+
lines.push(c.info(` \u2022 ${issue.message}`));
|
|
1691
|
+
if (issue.suggestion) {
|
|
1692
|
+
lines.push(` \u2192 ${issue.suggestion}`);
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
lines.push("");
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1699
|
+
lines.push(c.success("\u2705 OVERALL ASSESSMENT"));
|
|
1700
|
+
lines.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
1701
|
+
lines.push("");
|
|
1702
|
+
const errorCount = report.issues.filter((i) => i.severity === "error").length;
|
|
1703
|
+
const warningCount = report.issues.filter((i) => i.severity === "warning").length;
|
|
1704
|
+
if (errorCount === 0 && warningCount === 0) {
|
|
1705
|
+
lines.push(c.success("Excellent! No critical issues found."));
|
|
1706
|
+
} else if (errorCount > 0) {
|
|
1707
|
+
lines.push(`Critical accessibility issues found:`);
|
|
1708
|
+
lines.push(c.error(` \u2717 ${errorCount} error(s)`));
|
|
1709
|
+
if (warningCount > 0) {
|
|
1710
|
+
lines.push(c.warning(` \u26A0 ${warningCount} warning(s)`));
|
|
1711
|
+
}
|
|
1712
|
+
lines.push("");
|
|
1713
|
+
lines.push("Recommendation: Address errors before deployment");
|
|
1714
|
+
} else {
|
|
1715
|
+
lines.push(`Good structure with minor improvements needed:`);
|
|
1716
|
+
lines.push(c.warning(` \u26A0 ${warningCount} warning(s)`));
|
|
1717
|
+
}
|
|
1718
|
+
return lines.join("\n");
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
// src/parser/html-parser.ts
|
|
1722
|
+
import { JSDOM } from "jsdom";
|
|
1723
|
+
var ParsingError = class extends Error {
|
|
1724
|
+
constructor(message, cause) {
|
|
1725
|
+
super(message);
|
|
1726
|
+
this.cause = cause;
|
|
1727
|
+
this.name = "ParsingError";
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
var MAX_INPUT_SIZE = 10 * 1024 * 1024;
|
|
1731
|
+
function parseHTML(html) {
|
|
1732
|
+
const warnings = [];
|
|
1733
|
+
const inputSize = Buffer.byteLength(html, "utf-8");
|
|
1734
|
+
if (inputSize > MAX_INPUT_SIZE) {
|
|
1735
|
+
throw new ParsingError(
|
|
1736
|
+
`Input exceeds maximum size of ${MAX_INPUT_SIZE / (1024 * 1024)} MB (received ${(inputSize / (1024 * 1024)).toFixed(1)} MB). Use CSS selectors to analyze specific sections of large documents.`
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
try {
|
|
1740
|
+
const dom = new JSDOM(html, {
|
|
1741
|
+
contentType: "text/html",
|
|
1742
|
+
// Include useful defaults for accessibility tree extraction
|
|
1743
|
+
includeNodeLocations: false,
|
|
1744
|
+
storageQuota: 0
|
|
1745
|
+
});
|
|
1746
|
+
const document = dom.window.document;
|
|
1747
|
+
if (!document.documentElement) {
|
|
1748
|
+
warnings.push({
|
|
1749
|
+
message: "Document has no root element. HTML may be severely malformed."
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
if (!document.body) {
|
|
1753
|
+
warnings.push({
|
|
1754
|
+
message: "Document has no body element. HTML may be malformed."
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
return {
|
|
1758
|
+
document,
|
|
1759
|
+
warnings
|
|
1760
|
+
};
|
|
1761
|
+
} catch (error) {
|
|
1762
|
+
throw new ParsingError(
|
|
1763
|
+
`Failed to parse HTML: ${error instanceof Error ? error.message : String(error)}`,
|
|
1764
|
+
error instanceof Error ? error : void 0
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
function parseHTMLStrict(html) {
|
|
1769
|
+
const result = parseHTML(html);
|
|
1770
|
+
if (result.warnings.length > 0) {
|
|
1771
|
+
const warningMessages = result.warnings.map((w) => w.message).join("; ");
|
|
1772
|
+
throw new ParsingError(`HTML parsing warnings: ${warningMessages}`);
|
|
1773
|
+
}
|
|
1774
|
+
return result.document;
|
|
1775
|
+
}
|
|
1776
|
+
function validateHTMLNotEmpty(html) {
|
|
1777
|
+
if (!html || html.trim().length === 0) {
|
|
1778
|
+
throw new ParsingError("HTML input is empty or contains only whitespace");
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
// src/extractor/aria-name.ts
|
|
1783
|
+
function computeAccessibleName(element, visited = /* @__PURE__ */ new Set()) {
|
|
1784
|
+
const warnings = [];
|
|
1785
|
+
if (visited.has(element)) {
|
|
1786
|
+
warnings.push({
|
|
1787
|
+
message: "Circular reference detected in aria-labelledby chain",
|
|
1788
|
+
element
|
|
1789
|
+
});
|
|
1790
|
+
return { name: "", warnings };
|
|
1791
|
+
}
|
|
1792
|
+
visited.add(element);
|
|
1793
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
1794
|
+
if (labelledBy) {
|
|
1795
|
+
const name = computeNameFromLabelledBy(element, labelledBy, visited, warnings);
|
|
1796
|
+
return { name, warnings };
|
|
1797
|
+
}
|
|
1798
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
1799
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
1800
|
+
return { name: ariaLabel.trim(), warnings };
|
|
1801
|
+
}
|
|
1802
|
+
if (isFormControl(element)) {
|
|
1803
|
+
const labelName = computeNameFromLabel(element);
|
|
1804
|
+
if (labelName) {
|
|
1805
|
+
return { name: labelName, warnings };
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
if (element.tagName.toLowerCase() === "img") {
|
|
1809
|
+
const alt = element.getAttribute("alt");
|
|
1810
|
+
if (alt !== null) {
|
|
1811
|
+
return { name: alt.trim(), warnings };
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
if (supportsNameFromContent(element)) {
|
|
1815
|
+
const textName = computeNameFromContent(element, visited);
|
|
1816
|
+
if (textName) {
|
|
1817
|
+
return { name: textName, warnings };
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
const title = element.getAttribute("title");
|
|
1821
|
+
if (title && title.trim()) {
|
|
1822
|
+
return { name: title.trim(), warnings };
|
|
1823
|
+
}
|
|
1824
|
+
return { name: "", warnings };
|
|
1825
|
+
}
|
|
1826
|
+
function computeNameFromLabelledBy(element, labelledBy, visited, warnings) {
|
|
1827
|
+
const document = element.ownerDocument;
|
|
1828
|
+
if (!document) {
|
|
1829
|
+
return "";
|
|
1830
|
+
}
|
|
1831
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
1832
|
+
const names = [];
|
|
1833
|
+
for (const id of ids) {
|
|
1834
|
+
if (!id) continue;
|
|
1835
|
+
const referencedElement = document.getElementById(id);
|
|
1836
|
+
if (!referencedElement) {
|
|
1837
|
+
warnings.push({
|
|
1838
|
+
message: `aria-labelledby references non-existent ID: ${id}`,
|
|
1839
|
+
element
|
|
1840
|
+
});
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
const result = computeAccessibleName(referencedElement, new Set(visited));
|
|
1844
|
+
warnings.push(...result.warnings);
|
|
1845
|
+
const name = result.name || getTextContent(referencedElement);
|
|
1846
|
+
if (name) {
|
|
1847
|
+
names.push(name);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return names.join(" ").trim();
|
|
1851
|
+
}
|
|
1852
|
+
function computeNameFromLabel(element) {
|
|
1853
|
+
const document = element.ownerDocument;
|
|
1854
|
+
if (!document) {
|
|
1855
|
+
return "";
|
|
1856
|
+
}
|
|
1857
|
+
const id = element.getAttribute("id");
|
|
1858
|
+
if (id) {
|
|
1859
|
+
const label = document.querySelector(`label[for="${id}"]`);
|
|
1860
|
+
if (label) {
|
|
1861
|
+
return getTextContent(label);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
const parentLabel = element.closest("label");
|
|
1865
|
+
if (parentLabel) {
|
|
1866
|
+
return getTextContent(parentLabel);
|
|
1867
|
+
}
|
|
1868
|
+
return "";
|
|
1869
|
+
}
|
|
1870
|
+
function computeNameFromContent(element, _visited) {
|
|
1871
|
+
return getTextContent(element);
|
|
1872
|
+
}
|
|
1873
|
+
function getTextContent(element) {
|
|
1874
|
+
if (element.getAttribute("aria-hidden") === "true") {
|
|
1875
|
+
return "";
|
|
1876
|
+
}
|
|
1877
|
+
let text = "";
|
|
1878
|
+
for (const node of Array.from(element.childNodes)) {
|
|
1879
|
+
if (node.nodeType === 3) {
|
|
1880
|
+
text += node.textContent || "";
|
|
1881
|
+
} else if (node.nodeType === 1) {
|
|
1882
|
+
const childElement = node;
|
|
1883
|
+
if (childElement.getAttribute("aria-hidden") === "true") {
|
|
1884
|
+
continue;
|
|
1885
|
+
}
|
|
1886
|
+
text += getTextContent(childElement);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
return text.trim();
|
|
1890
|
+
}
|
|
1891
|
+
function isFormControl(element) {
|
|
1892
|
+
const tagName = element.tagName.toLowerCase();
|
|
1893
|
+
return tagName === "input" || tagName === "textarea" || tagName === "select" || tagName === "button";
|
|
1894
|
+
}
|
|
1895
|
+
function supportsNameFromContent(element) {
|
|
1896
|
+
const tagName = element.tagName.toLowerCase();
|
|
1897
|
+
const role = element.getAttribute("role");
|
|
1898
|
+
const contentElements = [
|
|
1899
|
+
"button",
|
|
1900
|
+
"a",
|
|
1901
|
+
"h1",
|
|
1902
|
+
"h2",
|
|
1903
|
+
"h3",
|
|
1904
|
+
"h4",
|
|
1905
|
+
"h5",
|
|
1906
|
+
"h6",
|
|
1907
|
+
"summary",
|
|
1908
|
+
"figcaption",
|
|
1909
|
+
"legend",
|
|
1910
|
+
"caption",
|
|
1911
|
+
"th",
|
|
1912
|
+
"td",
|
|
1913
|
+
"li",
|
|
1914
|
+
"dt",
|
|
1915
|
+
"dd"
|
|
1916
|
+
];
|
|
1917
|
+
if (contentElements.includes(tagName)) {
|
|
1918
|
+
return true;
|
|
1919
|
+
}
|
|
1920
|
+
const contentRoles = [
|
|
1921
|
+
"button",
|
|
1922
|
+
"link",
|
|
1923
|
+
"heading",
|
|
1924
|
+
"tab",
|
|
1925
|
+
"treeitem",
|
|
1926
|
+
"option",
|
|
1927
|
+
"row",
|
|
1928
|
+
"cell",
|
|
1929
|
+
"columnheader",
|
|
1930
|
+
"rowheader",
|
|
1931
|
+
"tooltip",
|
|
1932
|
+
"menuitem",
|
|
1933
|
+
"menuitemcheckbox",
|
|
1934
|
+
"menuitemradio"
|
|
1935
|
+
];
|
|
1936
|
+
if (role && contentRoles.includes(role)) {
|
|
1937
|
+
return true;
|
|
1938
|
+
}
|
|
1939
|
+
return false;
|
|
1940
|
+
}
|
|
1941
|
+
function computeAccessibleDescription(element) {
|
|
1942
|
+
const warnings = [];
|
|
1943
|
+
const describedBy = element.getAttribute("aria-describedby");
|
|
1944
|
+
if (describedBy) {
|
|
1945
|
+
const description = computeDescriptionFromDescribedBy(
|
|
1946
|
+
element,
|
|
1947
|
+
describedBy,
|
|
1948
|
+
warnings
|
|
1949
|
+
);
|
|
1950
|
+
if (description) {
|
|
1951
|
+
return { description, warnings };
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
const title = element.getAttribute("title");
|
|
1955
|
+
if (title && title.trim()) {
|
|
1956
|
+
return { description: title.trim(), warnings };
|
|
1957
|
+
}
|
|
1958
|
+
return { description: "", warnings };
|
|
1959
|
+
}
|
|
1960
|
+
function computeDescriptionFromDescribedBy(element, describedBy, warnings) {
|
|
1961
|
+
const document = element.ownerDocument;
|
|
1962
|
+
if (!document) {
|
|
1963
|
+
return "";
|
|
1964
|
+
}
|
|
1965
|
+
const ids = describedBy.trim().split(/\s+/);
|
|
1966
|
+
const descriptions = [];
|
|
1967
|
+
for (const id of ids) {
|
|
1968
|
+
if (!id) continue;
|
|
1969
|
+
const referencedElement = document.getElementById(id);
|
|
1970
|
+
if (!referencedElement) {
|
|
1971
|
+
warnings.push({
|
|
1972
|
+
message: `aria-describedby references non-existent ID: ${id}`,
|
|
1973
|
+
element
|
|
1974
|
+
});
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
const text = getTextContent(referencedElement);
|
|
1978
|
+
if (text) {
|
|
1979
|
+
descriptions.push(text);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
return descriptions.join(" ").trim();
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
// src/extractor/role-mapper.ts
|
|
1986
|
+
var IMPLICIT_ROLE_MAP = {
|
|
1987
|
+
// Interactive elements
|
|
1988
|
+
"button": "button",
|
|
1989
|
+
"a": "link",
|
|
1990
|
+
// Only if href attribute present
|
|
1991
|
+
// Form controls
|
|
1992
|
+
"input": "textbox",
|
|
1993
|
+
// Default, varies by type
|
|
1994
|
+
"textarea": "textbox",
|
|
1995
|
+
"select": "listbox",
|
|
1996
|
+
// Headings
|
|
1997
|
+
"h1": "heading",
|
|
1998
|
+
"h2": "heading",
|
|
1999
|
+
"h3": "heading",
|
|
2000
|
+
"h4": "heading",
|
|
2001
|
+
"h5": "heading",
|
|
2002
|
+
"h6": "heading",
|
|
2003
|
+
// Landmarks
|
|
2004
|
+
"nav": "navigation",
|
|
2005
|
+
"main": "main",
|
|
2006
|
+
"header": "banner",
|
|
2007
|
+
// Only if not nested in article/section
|
|
2008
|
+
"footer": "contentinfo",
|
|
2009
|
+
// Only if not nested in article/section
|
|
2010
|
+
"aside": "complementary",
|
|
2011
|
+
"form": "form",
|
|
2012
|
+
"section": "region",
|
|
2013
|
+
// Only if has accessible name
|
|
2014
|
+
// Lists
|
|
2015
|
+
"ul": "list",
|
|
2016
|
+
"ol": "list",
|
|
2017
|
+
"li": "listitem",
|
|
2018
|
+
// Images
|
|
2019
|
+
"img": "img",
|
|
2020
|
+
// Articles
|
|
2021
|
+
"article": "article",
|
|
2022
|
+
// Static content (new)
|
|
2023
|
+
"p": "paragraph",
|
|
2024
|
+
"blockquote": "blockquote",
|
|
2025
|
+
"code": "code",
|
|
2026
|
+
"pre": "code",
|
|
2027
|
+
// Tables (new)
|
|
2028
|
+
"table": "table",
|
|
2029
|
+
"tr": "row",
|
|
2030
|
+
"td": "cell",
|
|
2031
|
+
"th": "columnheader",
|
|
2032
|
+
// Default; scope="row" handled in computeImplicitRole
|
|
2033
|
+
// Definition lists (new)
|
|
2034
|
+
"dl": "list",
|
|
2035
|
+
"dt": "term",
|
|
2036
|
+
"dd": "definition",
|
|
2037
|
+
// Figures (new)
|
|
2038
|
+
"figure": "figure",
|
|
2039
|
+
"figcaption": "caption",
|
|
2040
|
+
// Disclosure (new)
|
|
2041
|
+
"details": "group",
|
|
2042
|
+
"summary": "button",
|
|
2043
|
+
// Dialogs and widgets (new)
|
|
2044
|
+
"dialog": "dialog",
|
|
2045
|
+
"meter": "meter",
|
|
2046
|
+
"progress": "progressbar",
|
|
2047
|
+
"output": "status",
|
|
2048
|
+
// Forms (new)
|
|
2049
|
+
"fieldset": "group",
|
|
2050
|
+
"legend": "caption",
|
|
2051
|
+
// Embedded content (new)
|
|
2052
|
+
"iframe": "document",
|
|
2053
|
+
"video": "application",
|
|
2054
|
+
"audio": "application",
|
|
2055
|
+
// Separators (new)
|
|
2056
|
+
"hr": "separator",
|
|
2057
|
+
// Table caption (new)
|
|
2058
|
+
"caption": "caption"
|
|
2059
|
+
};
|
|
2060
|
+
var INPUT_TYPE_ROLE_MAP = {
|
|
2061
|
+
"button": "button",
|
|
2062
|
+
"submit": "button",
|
|
2063
|
+
"reset": "button",
|
|
2064
|
+
"checkbox": "checkbox",
|
|
2065
|
+
"radio": "radio",
|
|
2066
|
+
"text": "textbox",
|
|
2067
|
+
"email": "textbox",
|
|
2068
|
+
"password": "textbox",
|
|
2069
|
+
"search": "textbox",
|
|
2070
|
+
"tel": "textbox",
|
|
2071
|
+
"url": "textbox",
|
|
2072
|
+
"number": "textbox"
|
|
2073
|
+
};
|
|
2074
|
+
function computeRole(element) {
|
|
2075
|
+
const warnings = [];
|
|
2076
|
+
const explicitRole = element.getAttribute("role");
|
|
2077
|
+
if (explicitRole) {
|
|
2078
|
+
const role = validateAndNormalizeRole(explicitRole, element, warnings);
|
|
2079
|
+
if (role) {
|
|
2080
|
+
return { role, warnings };
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
const implicitRole = computeImplicitRole(element, warnings);
|
|
2084
|
+
return { role: implicitRole, warnings };
|
|
2085
|
+
}
|
|
2086
|
+
function validateAndNormalizeRole(roleAttr, element, warnings) {
|
|
2087
|
+
const role = roleAttr.trim().toLowerCase();
|
|
2088
|
+
if (role === "presentation" || role === "none") {
|
|
2089
|
+
return null;
|
|
2090
|
+
}
|
|
2091
|
+
if (SUPPORTED_ROLES.includes(role)) {
|
|
2092
|
+
return role;
|
|
2093
|
+
}
|
|
2094
|
+
warnings.push({
|
|
2095
|
+
message: `Invalid or unsupported role: "${roleAttr}". Falling back to implicit role.`,
|
|
2096
|
+
element
|
|
2097
|
+
});
|
|
2098
|
+
return null;
|
|
2099
|
+
}
|
|
2100
|
+
function computeImplicitRole(element, _warnings) {
|
|
2101
|
+
const tagName = element.tagName.toLowerCase();
|
|
2102
|
+
if (tagName === "input") {
|
|
2103
|
+
return computeInputRole(element);
|
|
2104
|
+
}
|
|
2105
|
+
if (tagName === "a") {
|
|
2106
|
+
return element.hasAttribute("href") ? "link" : null;
|
|
2107
|
+
}
|
|
2108
|
+
if (tagName === "header") {
|
|
2109
|
+
return isTopLevelLandmark(element) ? "banner" : null;
|
|
2110
|
+
}
|
|
2111
|
+
if (tagName === "footer") {
|
|
2112
|
+
return isTopLevelLandmark(element) ? "contentinfo" : null;
|
|
2113
|
+
}
|
|
2114
|
+
if (tagName === "th") {
|
|
2115
|
+
const scope = element.getAttribute("scope");
|
|
2116
|
+
return scope === "row" ? "rowheader" : "columnheader";
|
|
2117
|
+
}
|
|
2118
|
+
if (tagName === "section") {
|
|
2119
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : null;
|
|
2120
|
+
}
|
|
2121
|
+
const implicitRole = IMPLICIT_ROLE_MAP[tagName];
|
|
2122
|
+
return implicitRole || null;
|
|
2123
|
+
}
|
|
2124
|
+
function computeInputRole(input) {
|
|
2125
|
+
const type = (input.getAttribute("type") || "text").toLowerCase();
|
|
2126
|
+
return INPUT_TYPE_ROLE_MAP[type] || "textbox";
|
|
2127
|
+
}
|
|
2128
|
+
function isTopLevelLandmark(element) {
|
|
2129
|
+
let parent = element.parentElement;
|
|
2130
|
+
while (parent) {
|
|
2131
|
+
const tagName = parent.tagName.toLowerCase();
|
|
2132
|
+
if (tagName === "article" || tagName === "section") {
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
parent = parent.parentElement;
|
|
2136
|
+
}
|
|
2137
|
+
return true;
|
|
2138
|
+
}
|
|
2139
|
+
function isAccessible(element) {
|
|
2140
|
+
if (element.getAttribute("aria-hidden") === "true") {
|
|
2141
|
+
return false;
|
|
2142
|
+
}
|
|
2143
|
+
const role = element.getAttribute("role");
|
|
2144
|
+
if (role === "presentation" || role === "none") {
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
const roleResult = computeRole(element);
|
|
2148
|
+
return roleResult.role !== null;
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
// src/extractor/state-extractor.ts
|
|
2152
|
+
function extractState(element) {
|
|
2153
|
+
const warnings = [];
|
|
2154
|
+
const state = {};
|
|
2155
|
+
const expanded = extractBooleanAttribute(element, "aria-expanded", warnings);
|
|
2156
|
+
if (expanded !== void 0) {
|
|
2157
|
+
state.expanded = expanded;
|
|
2158
|
+
}
|
|
2159
|
+
const checked = extractTriStateAttribute(element, "aria-checked", warnings);
|
|
2160
|
+
if (checked !== void 0) {
|
|
2161
|
+
state.checked = checked;
|
|
2162
|
+
}
|
|
2163
|
+
const pressed = extractTriStateAttribute(element, "aria-pressed", warnings);
|
|
2164
|
+
if (pressed !== void 0) {
|
|
2165
|
+
state.pressed = pressed;
|
|
2166
|
+
}
|
|
2167
|
+
const selected = extractBooleanAttribute(element, "aria-selected", warnings);
|
|
2168
|
+
if (selected !== void 0) {
|
|
2169
|
+
state.selected = selected;
|
|
2170
|
+
}
|
|
2171
|
+
const disabled = extractBooleanAttribute(element, "aria-disabled", warnings);
|
|
2172
|
+
if (disabled !== void 0) {
|
|
2173
|
+
state.disabled = disabled;
|
|
2174
|
+
}
|
|
2175
|
+
const invalid = extractBooleanAttribute(element, "aria-invalid", warnings);
|
|
2176
|
+
if (invalid !== void 0) {
|
|
2177
|
+
state.invalid = invalid;
|
|
2178
|
+
}
|
|
2179
|
+
const required = extractBooleanAttribute(element, "aria-required", warnings);
|
|
2180
|
+
if (required !== void 0) {
|
|
2181
|
+
state.required = required;
|
|
2182
|
+
}
|
|
2183
|
+
const readonly = extractBooleanAttribute(element, "aria-readonly", warnings);
|
|
2184
|
+
if (readonly !== void 0) {
|
|
2185
|
+
state.readonly = readonly;
|
|
2186
|
+
}
|
|
2187
|
+
const busy = extractBooleanAttribute(element, "aria-busy", warnings);
|
|
2188
|
+
if (busy !== void 0) {
|
|
2189
|
+
state.busy = busy;
|
|
2190
|
+
}
|
|
2191
|
+
const current = extractCurrentAttribute(element, warnings);
|
|
2192
|
+
if (current !== void 0) {
|
|
2193
|
+
state.current = current;
|
|
2194
|
+
}
|
|
2195
|
+
const grabbed = extractBooleanAttribute(element, "aria-grabbed", warnings);
|
|
2196
|
+
if (grabbed !== void 0) {
|
|
2197
|
+
state.grabbed = grabbed;
|
|
2198
|
+
}
|
|
2199
|
+
const hidden = extractBooleanAttribute(element, "aria-hidden", warnings);
|
|
2200
|
+
if (hidden !== void 0) {
|
|
2201
|
+
state.hidden = hidden;
|
|
2202
|
+
}
|
|
2203
|
+
const level = extractLevelAttribute(element, warnings);
|
|
2204
|
+
if (level !== void 0) {
|
|
2205
|
+
state.level = level;
|
|
2206
|
+
}
|
|
2207
|
+
const posinset = extractNumberAttribute(element, "aria-posinset", warnings);
|
|
2208
|
+
if (posinset !== void 0) {
|
|
2209
|
+
state.posinset = posinset;
|
|
2210
|
+
}
|
|
2211
|
+
const setsize = extractNumberAttribute(element, "aria-setsize", warnings);
|
|
2212
|
+
if (setsize !== void 0) {
|
|
2213
|
+
state.setsize = setsize;
|
|
2214
|
+
}
|
|
2215
|
+
extractNativeStates(element, state, warnings);
|
|
2216
|
+
return { state, warnings };
|
|
2217
|
+
}
|
|
2218
|
+
function extractValue(element) {
|
|
2219
|
+
const warnings = [];
|
|
2220
|
+
const tagName = element.tagName.toLowerCase();
|
|
2221
|
+
if (tagName === "input") {
|
|
2222
|
+
return extractInputValue(element, warnings);
|
|
2223
|
+
}
|
|
2224
|
+
if (tagName === "textarea") {
|
|
2225
|
+
return extractTextareaValue(element, warnings);
|
|
2226
|
+
}
|
|
2227
|
+
if (tagName === "select") {
|
|
2228
|
+
return extractSelectValue(element, warnings);
|
|
2229
|
+
}
|
|
2230
|
+
const valueNow = element.getAttribute("aria-valuenow");
|
|
2231
|
+
if (valueNow !== null) {
|
|
2232
|
+
const current = parseFloat(valueNow);
|
|
2233
|
+
if (!isNaN(current)) {
|
|
2234
|
+
const valueMin = element.getAttribute("aria-valuemin");
|
|
2235
|
+
const valueMax = element.getAttribute("aria-valuemax");
|
|
2236
|
+
const valueText = element.getAttribute("aria-valuetext");
|
|
2237
|
+
return {
|
|
2238
|
+
value: {
|
|
2239
|
+
current,
|
|
2240
|
+
min: valueMin !== null ? parseFloat(valueMin) : void 0,
|
|
2241
|
+
max: valueMax !== null ? parseFloat(valueMax) : void 0,
|
|
2242
|
+
text: valueText || void 0
|
|
2243
|
+
},
|
|
2244
|
+
warnings
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
return { value: void 0, warnings };
|
|
2249
|
+
}
|
|
2250
|
+
function extractBooleanAttribute(element, attrName, warnings) {
|
|
2251
|
+
const value = element.getAttribute(attrName);
|
|
2252
|
+
if (value === null) {
|
|
2253
|
+
return void 0;
|
|
2254
|
+
}
|
|
2255
|
+
const normalized = value.toLowerCase().trim();
|
|
2256
|
+
if (normalized === "true") {
|
|
2257
|
+
return true;
|
|
2258
|
+
}
|
|
2259
|
+
if (normalized === "false") {
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2262
|
+
warnings.push({
|
|
2263
|
+
message: `Invalid ${attrName} value: "${value}". Expected "true" or "false".`,
|
|
2264
|
+
element
|
|
2265
|
+
});
|
|
2266
|
+
return void 0;
|
|
2267
|
+
}
|
|
2268
|
+
function extractTriStateAttribute(element, attrName, warnings) {
|
|
2269
|
+
const value = element.getAttribute(attrName);
|
|
2270
|
+
if (value === null) {
|
|
2271
|
+
return void 0;
|
|
2272
|
+
}
|
|
2273
|
+
const normalized = value.toLowerCase().trim();
|
|
2274
|
+
if (normalized === "true") {
|
|
2275
|
+
return true;
|
|
2276
|
+
}
|
|
2277
|
+
if (normalized === "false") {
|
|
2278
|
+
return false;
|
|
2279
|
+
}
|
|
2280
|
+
if (normalized === "mixed") {
|
|
2281
|
+
return "mixed";
|
|
2282
|
+
}
|
|
2283
|
+
warnings.push({
|
|
2284
|
+
message: `Invalid ${attrName} value: "${value}". Expected "true", "false", or "mixed".`,
|
|
2285
|
+
element
|
|
2286
|
+
});
|
|
2287
|
+
return void 0;
|
|
2288
|
+
}
|
|
2289
|
+
function extractCurrentAttribute(element, warnings) {
|
|
2290
|
+
const value = element.getAttribute("aria-current");
|
|
2291
|
+
if (value === null) {
|
|
2292
|
+
return void 0;
|
|
2293
|
+
}
|
|
2294
|
+
const normalized = value.toLowerCase().trim();
|
|
2295
|
+
const validValues = ["page", "step", "location", "date", "time", "true", "false"];
|
|
2296
|
+
if (validValues.includes(normalized)) {
|
|
2297
|
+
return normalized === "false" ? false : normalized;
|
|
2298
|
+
}
|
|
2299
|
+
warnings.push({
|
|
2300
|
+
message: `Invalid aria-current value: "${value}". Expected one of: ${validValues.join(", ")}.`,
|
|
2301
|
+
element
|
|
2302
|
+
});
|
|
2303
|
+
return void 0;
|
|
2304
|
+
}
|
|
2305
|
+
function extractLevelAttribute(element, warnings) {
|
|
2306
|
+
const ariaLevel = element.getAttribute("aria-level");
|
|
2307
|
+
if (ariaLevel !== null) {
|
|
2308
|
+
const level = parseInt(ariaLevel, 10);
|
|
2309
|
+
if (!isNaN(level) && level >= 1 && level <= 6) {
|
|
2310
|
+
return level;
|
|
2311
|
+
}
|
|
2312
|
+
warnings.push({
|
|
2313
|
+
message: `Invalid aria-level value: "${ariaLevel}". Expected integer 1-6.`,
|
|
2314
|
+
element
|
|
2315
|
+
});
|
|
2316
|
+
return void 0;
|
|
2317
|
+
}
|
|
2318
|
+
const tagName = element.tagName.toLowerCase();
|
|
2319
|
+
const match = tagName.match(/^h([1-6])$/);
|
|
2320
|
+
if (match) {
|
|
2321
|
+
return parseInt(match[1], 10);
|
|
2322
|
+
}
|
|
2323
|
+
return void 0;
|
|
2324
|
+
}
|
|
2325
|
+
function extractNumberAttribute(element, attrName, warnings) {
|
|
2326
|
+
const value = element.getAttribute(attrName);
|
|
2327
|
+
if (value === null) {
|
|
2328
|
+
return void 0;
|
|
2329
|
+
}
|
|
2330
|
+
const num = parseInt(value, 10);
|
|
2331
|
+
if (isNaN(num) || num < 1) {
|
|
2332
|
+
warnings.push({
|
|
2333
|
+
message: `Invalid ${attrName} value: "${value}". Expected positive integer.`,
|
|
2334
|
+
element
|
|
2335
|
+
});
|
|
2336
|
+
return void 0;
|
|
2337
|
+
}
|
|
2338
|
+
return num;
|
|
2339
|
+
}
|
|
2340
|
+
function extractNativeStates(element, state, _warnings) {
|
|
2341
|
+
const tagName = element.tagName.toLowerCase();
|
|
2342
|
+
if (tagName === "input") {
|
|
2343
|
+
const input = element;
|
|
2344
|
+
const type = input.type.toLowerCase();
|
|
2345
|
+
if (type === "checkbox" || type === "radio") {
|
|
2346
|
+
if (state.checked === void 0) {
|
|
2347
|
+
state.checked = input.checked;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
if ("disabled" in element) {
|
|
2352
|
+
const htmlElement = element;
|
|
2353
|
+
if (state.disabled === void 0 && htmlElement.disabled) {
|
|
2354
|
+
state.disabled = true;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
if ("required" in element) {
|
|
2358
|
+
const htmlElement = element;
|
|
2359
|
+
if (state.required === void 0 && htmlElement.required) {
|
|
2360
|
+
state.required = true;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
if ("readOnly" in element) {
|
|
2364
|
+
const htmlElement = element;
|
|
2365
|
+
if (state.readonly === void 0 && htmlElement.readOnly) {
|
|
2366
|
+
state.readonly = true;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
function extractInputValue(input, warnings) {
|
|
2371
|
+
const type = input.type.toLowerCase();
|
|
2372
|
+
if (type === "checkbox" || type === "radio") {
|
|
2373
|
+
return { value: void 0, warnings };
|
|
2374
|
+
}
|
|
2375
|
+
if (type === "button" || type === "submit" || type === "reset") {
|
|
2376
|
+
return { value: void 0, warnings };
|
|
2377
|
+
}
|
|
2378
|
+
const value = input.value;
|
|
2379
|
+
if (value) {
|
|
2380
|
+
return {
|
|
2381
|
+
value: {
|
|
2382
|
+
current: value,
|
|
2383
|
+
text: value
|
|
2384
|
+
},
|
|
2385
|
+
warnings
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
return { value: void 0, warnings };
|
|
2389
|
+
}
|
|
2390
|
+
function extractTextareaValue(textarea, warnings) {
|
|
2391
|
+
const value = textarea.value;
|
|
2392
|
+
if (value) {
|
|
2393
|
+
return {
|
|
2394
|
+
value: {
|
|
2395
|
+
current: value,
|
|
2396
|
+
text: value
|
|
2397
|
+
},
|
|
2398
|
+
warnings
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
return { value: void 0, warnings };
|
|
2402
|
+
}
|
|
2403
|
+
function extractSelectValue(select, warnings) {
|
|
2404
|
+
const value = select.value;
|
|
2405
|
+
const selectedOption = select.options[select.selectedIndex];
|
|
2406
|
+
const text = selectedOption?.textContent || value;
|
|
2407
|
+
if (value) {
|
|
2408
|
+
return {
|
|
2409
|
+
value: {
|
|
2410
|
+
current: value,
|
|
2411
|
+
text
|
|
2412
|
+
},
|
|
2413
|
+
warnings
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
return { value: void 0, warnings };
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// src/extractor/focus-extractor.ts
|
|
2420
|
+
var NATIVELY_FOCUSABLE_ELEMENTS = [
|
|
2421
|
+
"a",
|
|
2422
|
+
"button",
|
|
2423
|
+
"input",
|
|
2424
|
+
"select",
|
|
2425
|
+
"textarea",
|
|
2426
|
+
"area",
|
|
2427
|
+
"iframe",
|
|
2428
|
+
"object",
|
|
2429
|
+
"embed",
|
|
2430
|
+
"audio",
|
|
2431
|
+
"video"
|
|
2432
|
+
];
|
|
2433
|
+
function extractFocusInfo(element) {
|
|
2434
|
+
const tabindexAttr = element.getAttribute("tabindex");
|
|
2435
|
+
const tabindex = tabindexAttr !== null ? parseInt(tabindexAttr, 10) : void 0;
|
|
2436
|
+
const focusable = isFocusable(element, tabindex);
|
|
2437
|
+
return {
|
|
2438
|
+
focusable,
|
|
2439
|
+
...tabindexAttr !== null && !isNaN(tabindex) && { tabindex }
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
function isFocusable(element, tabindex) {
|
|
2443
|
+
const tagName = element.tagName.toLowerCase();
|
|
2444
|
+
if (isDisabled(element)) {
|
|
2445
|
+
return false;
|
|
2446
|
+
}
|
|
2447
|
+
if (tabindex !== void 0 && !isNaN(tabindex)) {
|
|
2448
|
+
return true;
|
|
2449
|
+
}
|
|
2450
|
+
if (isNativelyFocusable(element, tagName)) {
|
|
2451
|
+
return true;
|
|
2452
|
+
}
|
|
2453
|
+
return false;
|
|
2454
|
+
}
|
|
2455
|
+
function isNativelyFocusable(element, tagName) {
|
|
2456
|
+
if (tagName === "a" || tagName === "area") {
|
|
2457
|
+
return element.hasAttribute("href");
|
|
2458
|
+
}
|
|
2459
|
+
if (NATIVELY_FOCUSABLE_ELEMENTS.includes(tagName)) {
|
|
2460
|
+
return true;
|
|
2461
|
+
}
|
|
2462
|
+
return false;
|
|
2463
|
+
}
|
|
2464
|
+
function isDisabled(element) {
|
|
2465
|
+
if ("disabled" in element) {
|
|
2466
|
+
const htmlElement = element;
|
|
2467
|
+
if (htmlElement.disabled) {
|
|
2468
|
+
return true;
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
const ariaDisabled = element.getAttribute("aria-disabled");
|
|
2472
|
+
if (ariaDisabled === "true") {
|
|
2473
|
+
return true;
|
|
2474
|
+
}
|
|
2475
|
+
return false;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
// src/extractor/tree-builder.ts
|
|
2479
|
+
var SelectorError = class extends Error {
|
|
2480
|
+
constructor(message) {
|
|
2481
|
+
super(message);
|
|
2482
|
+
this.name = "SelectorError";
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
function isHidden(element) {
|
|
2486
|
+
if (element.getAttribute("aria-hidden") === "true") return true;
|
|
2487
|
+
if (typeof getComputedStyle === "function") {
|
|
2488
|
+
try {
|
|
2489
|
+
const style = getComputedStyle(element);
|
|
2490
|
+
if (style.display === "none") return true;
|
|
2491
|
+
if (style.visibility === "hidden") return true;
|
|
2492
|
+
} catch {
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
return false;
|
|
2496
|
+
}
|
|
2497
|
+
function processChildNode(node, children, warnings) {
|
|
2498
|
+
if (node.nodeType === 3) {
|
|
2499
|
+
const text = (node.textContent || "").trim();
|
|
2500
|
+
if (text.length > 0) {
|
|
2501
|
+
children.push({
|
|
2502
|
+
role: "staticText",
|
|
2503
|
+
name: text,
|
|
2504
|
+
state: {},
|
|
2505
|
+
focus: { focusable: false },
|
|
2506
|
+
children: []
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
if (node.nodeType === 1) {
|
|
2512
|
+
const element = node;
|
|
2513
|
+
if (isHidden(element)) return;
|
|
2514
|
+
if (!isAccessible(element)) {
|
|
2515
|
+
const grandchildren = collectChildrenFromRolelessElement(element, warnings);
|
|
2516
|
+
children.push(...grandchildren);
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
const childNode = buildNodeRecursive(element, warnings);
|
|
2520
|
+
if (childNode) children.push(childNode);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
function collectChildrenFromRolelessElement(element, warnings) {
|
|
2524
|
+
const children = [];
|
|
2525
|
+
if (element.shadowRoot) {
|
|
2526
|
+
for (const child of Array.from(element.shadowRoot.childNodes)) {
|
|
2527
|
+
processChildNode(child, children, warnings);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
for (const child of Array.from(element.childNodes)) {
|
|
2531
|
+
processChildNode(child, children, warnings);
|
|
2532
|
+
}
|
|
2533
|
+
return children;
|
|
2534
|
+
}
|
|
2535
|
+
function buildAccessibilityTree(rootElement, sourceHash) {
|
|
2536
|
+
const warnings = [];
|
|
2537
|
+
if (isHidden(rootElement)) {
|
|
2538
|
+
const model2 = {
|
|
2539
|
+
version: CURRENT_MODEL_VERSION,
|
|
2540
|
+
root: {
|
|
2541
|
+
role: "generic",
|
|
2542
|
+
name: "",
|
|
2543
|
+
state: {},
|
|
2544
|
+
focus: { focusable: false },
|
|
2545
|
+
children: []
|
|
2546
|
+
},
|
|
2547
|
+
metadata: {
|
|
2548
|
+
extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2549
|
+
...sourceHash && { sourceHash }
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
return { model: model2, warnings };
|
|
2553
|
+
}
|
|
2554
|
+
const rootNode = buildNodeRecursive(rootElement, warnings);
|
|
2555
|
+
const accessibleRoot = rootNode || createGenericContainer(rootElement, warnings);
|
|
2556
|
+
const model = {
|
|
2557
|
+
version: CURRENT_MODEL_VERSION,
|
|
2558
|
+
root: accessibleRoot,
|
|
2559
|
+
metadata: {
|
|
2560
|
+
extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2561
|
+
...sourceHash && { sourceHash }
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
return { model, warnings };
|
|
2565
|
+
}
|
|
2566
|
+
function buildAccessibilityTreeWithSelector(rootElement, selector, sourceHash) {
|
|
2567
|
+
const document = rootElement.ownerDocument;
|
|
2568
|
+
if (!document) {
|
|
2569
|
+
throw new SelectorError("Element has no owner document");
|
|
2570
|
+
}
|
|
2571
|
+
let matchingElements;
|
|
2572
|
+
try {
|
|
2573
|
+
if (rootElement.matches(selector)) {
|
|
2574
|
+
matchingElements = [rootElement];
|
|
2575
|
+
} else {
|
|
2576
|
+
matchingElements = Array.from(rootElement.querySelectorAll(selector));
|
|
2577
|
+
}
|
|
2578
|
+
} catch (error) {
|
|
2579
|
+
throw new SelectorError(`Invalid CSS selector: "${selector}". ${error instanceof Error ? error.message : String(error)}`);
|
|
2580
|
+
}
|
|
2581
|
+
if (matchingElements.length === 0) {
|
|
2582
|
+
throw new SelectorError(`No elements match selector: "${selector}"`);
|
|
2583
|
+
}
|
|
2584
|
+
const results = [];
|
|
2585
|
+
for (const element of matchingElements) {
|
|
2586
|
+
const result = buildAccessibilityTree(element, sourceHash);
|
|
2587
|
+
results.push(result);
|
|
2588
|
+
}
|
|
2589
|
+
return results;
|
|
2590
|
+
}
|
|
2591
|
+
function buildNodeRecursive(element, warnings) {
|
|
2592
|
+
if (isHidden(element)) {
|
|
2593
|
+
return null;
|
|
2594
|
+
}
|
|
2595
|
+
if (!isAccessible(element)) {
|
|
2596
|
+
return null;
|
|
2597
|
+
}
|
|
2598
|
+
const roleResult = computeRole(element);
|
|
2599
|
+
warnings.push(...roleResult.warnings.map((w) => ({
|
|
2600
|
+
message: w.message,
|
|
2601
|
+
element: w.element
|
|
2602
|
+
})));
|
|
2603
|
+
if (!roleResult.role) {
|
|
2604
|
+
return null;
|
|
2605
|
+
}
|
|
2606
|
+
const nameResult = computeAccessibleName(element);
|
|
2607
|
+
warnings.push(...nameResult.warnings.map((w) => ({
|
|
2608
|
+
message: w.message,
|
|
2609
|
+
element: w.element
|
|
2610
|
+
})));
|
|
2611
|
+
const descResult = computeAccessibleDescription(element);
|
|
2612
|
+
warnings.push(...descResult.warnings.map((w) => ({
|
|
2613
|
+
message: w.message,
|
|
2614
|
+
element: w.element
|
|
2615
|
+
})));
|
|
2616
|
+
const stateResult = extractState(element);
|
|
2617
|
+
warnings.push(...stateResult.warnings.map((w) => ({
|
|
2618
|
+
message: w.message,
|
|
2619
|
+
element: w.element
|
|
2620
|
+
})));
|
|
2621
|
+
const valueResult = extractValue(element);
|
|
2622
|
+
warnings.push(...valueResult.warnings.map((w) => ({
|
|
2623
|
+
message: w.message,
|
|
2624
|
+
element: w.element
|
|
2625
|
+
})));
|
|
2626
|
+
const focusInfo = extractFocusInfo(element);
|
|
2627
|
+
const children = [];
|
|
2628
|
+
if (element.shadowRoot) {
|
|
2629
|
+
for (const child of Array.from(element.shadowRoot.childNodes)) {
|
|
2630
|
+
processChildNode(child, children, warnings);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
for (const child of Array.from(element.childNodes)) {
|
|
2634
|
+
processChildNode(child, children, warnings);
|
|
2635
|
+
}
|
|
2636
|
+
const node = {
|
|
2637
|
+
role: roleResult.role,
|
|
2638
|
+
name: nameResult.name,
|
|
2639
|
+
...descResult.description && { description: descResult.description },
|
|
2640
|
+
...valueResult.value && { value: valueResult.value },
|
|
2641
|
+
state: stateResult.state,
|
|
2642
|
+
focus: focusInfo,
|
|
2643
|
+
children
|
|
2644
|
+
};
|
|
2645
|
+
return node;
|
|
2646
|
+
}
|
|
2647
|
+
function createGenericContainer(rootElement, warnings) {
|
|
2648
|
+
const children = [];
|
|
2649
|
+
if (rootElement.shadowRoot) {
|
|
2650
|
+
for (const child of Array.from(rootElement.shadowRoot.childNodes)) {
|
|
2651
|
+
processChildNode(child, children, warnings);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
for (const child of Array.from(rootElement.childNodes)) {
|
|
2655
|
+
processChildNode(child, children, warnings);
|
|
2656
|
+
}
|
|
2657
|
+
return {
|
|
2658
|
+
role: "generic",
|
|
2659
|
+
name: "",
|
|
2660
|
+
state: {},
|
|
2661
|
+
focus: {
|
|
2662
|
+
focusable: false
|
|
2663
|
+
},
|
|
2664
|
+
children
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
// src/runtime/index.ts
|
|
2669
|
+
var runtime_exports = {};
|
|
2670
|
+
__export(runtime_exports, {
|
|
2671
|
+
classifyDiff: () => classifyDiff,
|
|
2672
|
+
createBaselineStorage: () => createBaselineStorage,
|
|
2673
|
+
createEngine: () => createEngine,
|
|
2674
|
+
createHeuristicAnalyzer: () => createHeuristicAnalyzer,
|
|
2675
|
+
createTimelineGenerator: () => createTimelineGenerator,
|
|
2676
|
+
deserializeEvent: () => deserializeEvent,
|
|
2677
|
+
deserializeInteractionSequence: () => deserializeInteractionSequence,
|
|
2678
|
+
deserializeTimeline: () => deserializeTimeline,
|
|
2679
|
+
diffTimelines: () => diffTimelines,
|
|
2680
|
+
executeAction: () => executeAction,
|
|
2681
|
+
executeSequence: () => executeSequence,
|
|
2682
|
+
generateSelector: () => generateSelector,
|
|
2683
|
+
getBuiltinPattern: () => getBuiltinPattern,
|
|
2684
|
+
serializeEvent: () => serializeEvent,
|
|
2685
|
+
serializeInteractionSequence: () => serializeInteractionSequence,
|
|
2686
|
+
serializeTimeline: () => serializeTimeline,
|
|
2687
|
+
timelinesEqual: () => timelinesEqual
|
|
2688
|
+
});
|
|
2689
|
+
|
|
2690
|
+
// src/runtime/selector.ts
|
|
2691
|
+
function generateSelector(element) {
|
|
2692
|
+
if (element.id) {
|
|
2693
|
+
return `#${escapeCSSIdentifier(element.id)}`;
|
|
2694
|
+
}
|
|
2695
|
+
const document = element.ownerDocument;
|
|
2696
|
+
if (!document) {
|
|
2697
|
+
return getTagName(element);
|
|
2698
|
+
}
|
|
2699
|
+
const segments = [];
|
|
2700
|
+
let current = element;
|
|
2701
|
+
while (current && current !== document.documentElement) {
|
|
2702
|
+
const segment = buildSegment(current, document);
|
|
2703
|
+
segments.unshift(segment);
|
|
2704
|
+
const partialSelector = segments.join(" > ");
|
|
2705
|
+
try {
|
|
2706
|
+
const matches = document.querySelectorAll(partialSelector);
|
|
2707
|
+
if (matches.length === 1 && matches[0] === element) {
|
|
2708
|
+
return partialSelector;
|
|
2709
|
+
}
|
|
2710
|
+
} catch {
|
|
2711
|
+
}
|
|
2712
|
+
current = current.parentElement;
|
|
2713
|
+
}
|
|
2714
|
+
if (segments.length === 0) {
|
|
2715
|
+
return getTagName(element);
|
|
2716
|
+
}
|
|
2717
|
+
const fullSelector = segments.join(" > ");
|
|
2718
|
+
return fullSelector;
|
|
2719
|
+
}
|
|
2720
|
+
function buildSegment(element, _document) {
|
|
2721
|
+
const tag = getTagName(element);
|
|
2722
|
+
const parent = element.parentElement;
|
|
2723
|
+
if (parent) {
|
|
2724
|
+
const siblingsWithSameTag = Array.from(parent.children).filter(
|
|
2725
|
+
(child) => getTagName(child) === tag
|
|
2726
|
+
);
|
|
2727
|
+
if (siblingsWithSameTag.length === 1) {
|
|
2728
|
+
return tag;
|
|
2729
|
+
}
|
|
2730
|
+
} else {
|
|
2731
|
+
return tag;
|
|
2732
|
+
}
|
|
2733
|
+
const classes = getStableClasses(element);
|
|
2734
|
+
if (classes.length > 0) {
|
|
2735
|
+
const tagWithClasses = `${tag}.${classes.join(".")}`;
|
|
2736
|
+
if (parent) {
|
|
2737
|
+
const siblingsMatchingClasses = Array.from(parent.children).filter(
|
|
2738
|
+
(child) => {
|
|
2739
|
+
if (getTagName(child) !== tag) return false;
|
|
2740
|
+
return classes.every((cls) => child.classList.contains(cls));
|
|
2741
|
+
}
|
|
2742
|
+
);
|
|
2743
|
+
if (siblingsMatchingClasses.length === 1) {
|
|
2744
|
+
return tagWithClasses;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
const index = getNthChildIndex(element);
|
|
2749
|
+
return `${tag}:nth-child(${index})`;
|
|
2750
|
+
}
|
|
2751
|
+
function getTagName(element) {
|
|
2752
|
+
return element.tagName.toLowerCase();
|
|
2753
|
+
}
|
|
2754
|
+
function getStableClasses(element) {
|
|
2755
|
+
const classes = Array.from(element.classList);
|
|
2756
|
+
if (classes.length === 0) return [];
|
|
2757
|
+
const stableClasses = classes.filter((cls) => !looksLikeDynamicClass(cls));
|
|
2758
|
+
return stableClasses.sort().map(escapeCSSIdentifier);
|
|
2759
|
+
}
|
|
2760
|
+
function looksLikeDynamicClass(className) {
|
|
2761
|
+
if (/^[a-f0-9]{5,}$/i.test(className)) return true;
|
|
2762
|
+
if (/[_-][a-f0-9]{5,}$/i.test(className)) return true;
|
|
2763
|
+
if (/_{2,}[A-Za-z0-9]{4,}$/.test(className)) return true;
|
|
2764
|
+
return false;
|
|
2765
|
+
}
|
|
2766
|
+
function getNthChildIndex(element) {
|
|
2767
|
+
const parent = element.parentElement;
|
|
2768
|
+
if (!parent) return 1;
|
|
2769
|
+
const children = Array.from(parent.children);
|
|
2770
|
+
const index = children.indexOf(element);
|
|
2771
|
+
return index + 1;
|
|
2772
|
+
}
|
|
2773
|
+
function escapeCSSIdentifier(value) {
|
|
2774
|
+
if (!value) return value;
|
|
2775
|
+
let result = "";
|
|
2776
|
+
for (let i = 0; i < value.length; i++) {
|
|
2777
|
+
const char = value[i];
|
|
2778
|
+
const code = char.charCodeAt(0);
|
|
2779
|
+
if (i === 0 && code >= 48 && code <= 57) {
|
|
2780
|
+
result += `\\3${char} `;
|
|
2781
|
+
continue;
|
|
2782
|
+
}
|
|
2783
|
+
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 === " ") {
|
|
2784
|
+
result += `\\${char}`;
|
|
2785
|
+
continue;
|
|
2786
|
+
}
|
|
2787
|
+
result += char;
|
|
2788
|
+
}
|
|
2789
|
+
return result;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
// src/runtime/observers/focus-observer.ts
|
|
2793
|
+
function computeAccessibleName2(element, document) {
|
|
2794
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
2795
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
2796
|
+
return ariaLabel.trim();
|
|
2797
|
+
}
|
|
2798
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
2799
|
+
if (labelledBy && labelledBy.trim()) {
|
|
2800
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
2801
|
+
const parts = [];
|
|
2802
|
+
for (const id of ids) {
|
|
2803
|
+
const referenced = document.getElementById(id);
|
|
2804
|
+
if (referenced && referenced.textContent) {
|
|
2805
|
+
parts.push(referenced.textContent.trim());
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
const combined = parts.join(" ");
|
|
2809
|
+
if (combined) {
|
|
2810
|
+
return combined;
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
const textContent = element.textContent;
|
|
2814
|
+
if (textContent && textContent.trim()) {
|
|
2815
|
+
return textContent.trim();
|
|
2816
|
+
}
|
|
2817
|
+
return "";
|
|
2818
|
+
}
|
|
2819
|
+
function getElementRole(element) {
|
|
2820
|
+
const explicitRole = element.getAttribute("role");
|
|
2821
|
+
if (explicitRole && explicitRole.trim()) {
|
|
2822
|
+
return explicitRole.trim();
|
|
2823
|
+
}
|
|
2824
|
+
const tagName = element.tagName.toLowerCase();
|
|
2825
|
+
switch (tagName) {
|
|
2826
|
+
case "button":
|
|
2827
|
+
return "button";
|
|
2828
|
+
case "a":
|
|
2829
|
+
return element.hasAttribute("href") ? "link" : "generic";
|
|
2830
|
+
case "input": {
|
|
2831
|
+
const type = (element.getAttribute("type") || "text").toLowerCase();
|
|
2832
|
+
switch (type) {
|
|
2833
|
+
case "button":
|
|
2834
|
+
case "submit":
|
|
2835
|
+
case "reset":
|
|
2836
|
+
case "image":
|
|
2837
|
+
return "button";
|
|
2838
|
+
case "checkbox":
|
|
2839
|
+
return "checkbox";
|
|
2840
|
+
case "radio":
|
|
2841
|
+
return "radio";
|
|
2842
|
+
case "range":
|
|
2843
|
+
return "slider";
|
|
2844
|
+
case "search":
|
|
2845
|
+
return "searchbox";
|
|
2846
|
+
default:
|
|
2847
|
+
return "textbox";
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
case "textarea":
|
|
2851
|
+
return "textbox";
|
|
2852
|
+
case "select":
|
|
2853
|
+
return element.hasAttribute("multiple") ? "listbox" : "combobox";
|
|
2854
|
+
case "nav":
|
|
2855
|
+
return "navigation";
|
|
2856
|
+
case "main":
|
|
2857
|
+
return "main";
|
|
2858
|
+
case "header":
|
|
2859
|
+
return "banner";
|
|
2860
|
+
case "footer":
|
|
2861
|
+
return "contentinfo";
|
|
2862
|
+
case "aside":
|
|
2863
|
+
return "complementary";
|
|
2864
|
+
case "form":
|
|
2865
|
+
return "form";
|
|
2866
|
+
case "section":
|
|
2867
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : "generic";
|
|
2868
|
+
case "article":
|
|
2869
|
+
return "article";
|
|
2870
|
+
case "dialog":
|
|
2871
|
+
return "dialog";
|
|
2872
|
+
case "table":
|
|
2873
|
+
return "table";
|
|
2874
|
+
case "ul":
|
|
2875
|
+
case "ol":
|
|
2876
|
+
return "list";
|
|
2877
|
+
case "li":
|
|
2878
|
+
return "listitem";
|
|
2879
|
+
case "img":
|
|
2880
|
+
return element.getAttribute("alt") === "" ? "presentation" : "img";
|
|
2881
|
+
case "h1":
|
|
2882
|
+
case "h2":
|
|
2883
|
+
case "h3":
|
|
2884
|
+
case "h4":
|
|
2885
|
+
case "h5":
|
|
2886
|
+
case "h6":
|
|
2887
|
+
return "heading";
|
|
2888
|
+
case "option":
|
|
2889
|
+
return "option";
|
|
2890
|
+
case "progress":
|
|
2891
|
+
return "progressbar";
|
|
2892
|
+
case "output":
|
|
2893
|
+
return "status";
|
|
2894
|
+
case "menu":
|
|
2895
|
+
return "menu";
|
|
2896
|
+
default:
|
|
2897
|
+
return "generic";
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
function createFocusObserver(options) {
|
|
2901
|
+
const { document: doc, onEvent, getTimestamp } = options;
|
|
2902
|
+
let active = false;
|
|
2903
|
+
let previousTarget = null;
|
|
2904
|
+
function buildEventTarget2(element) {
|
|
2905
|
+
return {
|
|
2906
|
+
role: getElementRole(element),
|
|
2907
|
+
accessibleName: computeAccessibleName2(element, doc),
|
|
2908
|
+
selector: generateSelector(element)
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
function handleFocusIn(event) {
|
|
2912
|
+
if (!active) return;
|
|
2913
|
+
const target = event.target;
|
|
2914
|
+
if (!target || !(target instanceof doc.defaultView.Element)) {
|
|
2915
|
+
return;
|
|
2916
|
+
}
|
|
2917
|
+
const currentTarget = buildEventTarget2(target);
|
|
2918
|
+
const a11yEvent = {
|
|
2919
|
+
type: "FOCUS_CHANGED",
|
|
2920
|
+
timestamp: getTimestamp(),
|
|
2921
|
+
target: currentTarget,
|
|
2922
|
+
payload: {
|
|
2923
|
+
kind: "focus_changed",
|
|
2924
|
+
previousTarget
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
onEvent(a11yEvent);
|
|
2928
|
+
previousTarget = currentTarget;
|
|
2929
|
+
}
|
|
2930
|
+
return {
|
|
2931
|
+
start() {
|
|
2932
|
+
if (active) return;
|
|
2933
|
+
active = true;
|
|
2934
|
+
previousTarget = null;
|
|
2935
|
+
doc.addEventListener("focusin", handleFocusIn);
|
|
2936
|
+
},
|
|
2937
|
+
stop() {
|
|
2938
|
+
if (!active) return;
|
|
2939
|
+
active = false;
|
|
2940
|
+
doc.removeEventListener("focusin", handleFocusIn);
|
|
2941
|
+
},
|
|
2942
|
+
get isActive() {
|
|
2943
|
+
return active;
|
|
2944
|
+
}
|
|
2945
|
+
};
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
// src/runtime/observers/mutation-observer.ts
|
|
2949
|
+
var ROLE_ATTRIBUTE = "role";
|
|
2950
|
+
var NAME_ATTRIBUTES = /* @__PURE__ */ new Set(["aria-label", "aria-labelledby"]);
|
|
2951
|
+
var STATE_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
2952
|
+
"aria-expanded",
|
|
2953
|
+
"aria-selected",
|
|
2954
|
+
"aria-checked",
|
|
2955
|
+
"aria-disabled",
|
|
2956
|
+
"aria-hidden"
|
|
2957
|
+
]);
|
|
2958
|
+
var OBSERVED_ATTRIBUTES = [
|
|
2959
|
+
ROLE_ATTRIBUTE,
|
|
2960
|
+
"aria-label",
|
|
2961
|
+
"aria-labelledby",
|
|
2962
|
+
"aria-expanded",
|
|
2963
|
+
"aria-selected",
|
|
2964
|
+
"aria-checked",
|
|
2965
|
+
"aria-disabled",
|
|
2966
|
+
"aria-hidden"
|
|
2967
|
+
];
|
|
2968
|
+
function computeAccessibleName3(element, document) {
|
|
2969
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
2970
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
2971
|
+
return ariaLabel.trim();
|
|
2972
|
+
}
|
|
2973
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
2974
|
+
if (labelledBy && labelledBy.trim()) {
|
|
2975
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
2976
|
+
const parts = [];
|
|
2977
|
+
for (const id of ids) {
|
|
2978
|
+
const referenced = document.getElementById(id);
|
|
2979
|
+
if (referenced && referenced.textContent) {
|
|
2980
|
+
parts.push(referenced.textContent.trim());
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
const combined = parts.join(" ");
|
|
2984
|
+
if (combined) {
|
|
2985
|
+
return combined;
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
const textContent = element.textContent;
|
|
2989
|
+
if (textContent && textContent.trim()) {
|
|
2990
|
+
return textContent.trim();
|
|
2991
|
+
}
|
|
2992
|
+
return "";
|
|
2993
|
+
}
|
|
2994
|
+
function getElementRole2(element) {
|
|
2995
|
+
const explicitRole = element.getAttribute("role");
|
|
2996
|
+
if (explicitRole && explicitRole.trim()) {
|
|
2997
|
+
return explicitRole.trim();
|
|
2998
|
+
}
|
|
2999
|
+
const tagName = element.tagName.toLowerCase();
|
|
3000
|
+
switch (tagName) {
|
|
3001
|
+
case "button":
|
|
3002
|
+
return "button";
|
|
3003
|
+
case "a":
|
|
3004
|
+
return element.hasAttribute("href") ? "link" : "generic";
|
|
3005
|
+
case "input": {
|
|
3006
|
+
const type = (element.getAttribute("type") || "text").toLowerCase();
|
|
3007
|
+
switch (type) {
|
|
3008
|
+
case "button":
|
|
3009
|
+
case "submit":
|
|
3010
|
+
case "reset":
|
|
3011
|
+
case "image":
|
|
3012
|
+
return "button";
|
|
3013
|
+
case "checkbox":
|
|
3014
|
+
return "checkbox";
|
|
3015
|
+
case "radio":
|
|
3016
|
+
return "radio";
|
|
3017
|
+
case "range":
|
|
3018
|
+
return "slider";
|
|
3019
|
+
case "search":
|
|
3020
|
+
return "searchbox";
|
|
3021
|
+
default:
|
|
3022
|
+
return "textbox";
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
case "textarea":
|
|
3026
|
+
return "textbox";
|
|
3027
|
+
case "select":
|
|
3028
|
+
return element.hasAttribute("multiple") ? "listbox" : "combobox";
|
|
3029
|
+
case "nav":
|
|
3030
|
+
return "navigation";
|
|
3031
|
+
case "main":
|
|
3032
|
+
return "main";
|
|
3033
|
+
case "header":
|
|
3034
|
+
return "banner";
|
|
3035
|
+
case "footer":
|
|
3036
|
+
return "contentinfo";
|
|
3037
|
+
case "aside":
|
|
3038
|
+
return "complementary";
|
|
3039
|
+
case "form":
|
|
3040
|
+
return "form";
|
|
3041
|
+
case "section":
|
|
3042
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : "generic";
|
|
3043
|
+
case "article":
|
|
3044
|
+
return "article";
|
|
3045
|
+
case "dialog":
|
|
3046
|
+
return "dialog";
|
|
3047
|
+
case "table":
|
|
3048
|
+
return "table";
|
|
3049
|
+
case "ul":
|
|
3050
|
+
case "ol":
|
|
3051
|
+
return "list";
|
|
3052
|
+
case "li":
|
|
3053
|
+
return "listitem";
|
|
3054
|
+
case "img":
|
|
3055
|
+
return element.getAttribute("alt") === "" ? "presentation" : "img";
|
|
3056
|
+
case "h1":
|
|
3057
|
+
case "h2":
|
|
3058
|
+
case "h3":
|
|
3059
|
+
case "h4":
|
|
3060
|
+
case "h5":
|
|
3061
|
+
case "h6":
|
|
3062
|
+
return "heading";
|
|
3063
|
+
case "option":
|
|
3064
|
+
return "option";
|
|
3065
|
+
case "progress":
|
|
3066
|
+
return "progressbar";
|
|
3067
|
+
case "output":
|
|
3068
|
+
return "status";
|
|
3069
|
+
case "menu":
|
|
3070
|
+
return "menu";
|
|
3071
|
+
default:
|
|
3072
|
+
return "generic";
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
function createMutationObserver(options) {
|
|
3076
|
+
const { document: doc, onEvent, getTimestamp } = options;
|
|
3077
|
+
let observer = null;
|
|
3078
|
+
let active = false;
|
|
3079
|
+
function handleMutations(mutations) {
|
|
3080
|
+
if (!active) return;
|
|
3081
|
+
for (const mutation of mutations) {
|
|
3082
|
+
if (mutation.type !== "attributes") {
|
|
3083
|
+
continue;
|
|
3084
|
+
}
|
|
3085
|
+
const attributeName = mutation.attributeName;
|
|
3086
|
+
if (!attributeName) {
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
const target = mutation.target;
|
|
3090
|
+
if (!(target instanceof Element)) {
|
|
3091
|
+
continue;
|
|
3092
|
+
}
|
|
3093
|
+
if (attributeName === ROLE_ATTRIBUTE) {
|
|
3094
|
+
handleRoleChange(target, mutation.oldValue);
|
|
3095
|
+
} else if (NAME_ATTRIBUTES.has(attributeName)) {
|
|
3096
|
+
handleNameChange(target, attributeName, mutation.oldValue);
|
|
3097
|
+
} else if (STATE_ATTRIBUTES.has(attributeName)) {
|
|
3098
|
+
handleStateChange(target, attributeName, mutation.oldValue);
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
function handleRoleChange(element, oldValue) {
|
|
3103
|
+
const previousRole = oldValue?.trim() || getImplicitRole(element);
|
|
3104
|
+
const newRole = element.getAttribute("role")?.trim() || getImplicitRole(element);
|
|
3105
|
+
if (previousRole === newRole) {
|
|
3106
|
+
return;
|
|
3107
|
+
}
|
|
3108
|
+
const eventTarget = buildEventTarget2(element);
|
|
3109
|
+
const payload = {
|
|
3110
|
+
kind: "role_changed",
|
|
3111
|
+
previousRole,
|
|
3112
|
+
newRole
|
|
3113
|
+
};
|
|
3114
|
+
onEvent({
|
|
3115
|
+
type: "ROLE_CHANGED",
|
|
3116
|
+
timestamp: getTimestamp(),
|
|
3117
|
+
target: eventTarget,
|
|
3118
|
+
payload
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3121
|
+
function handleNameChange(element, attributeName, oldValue) {
|
|
3122
|
+
let previousName;
|
|
3123
|
+
let newName;
|
|
3124
|
+
if (attributeName === "aria-label") {
|
|
3125
|
+
previousName = oldValue?.trim() || "";
|
|
3126
|
+
newName = computeAccessibleName3(element, doc);
|
|
3127
|
+
if (!previousName && oldValue === null) {
|
|
3128
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
3129
|
+
if (labelledBy) {
|
|
3130
|
+
previousName = resolveAriaLabelledBy(element, labelledBy);
|
|
3131
|
+
} else {
|
|
3132
|
+
previousName = element.textContent?.trim() || "";
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
} else {
|
|
3136
|
+
previousName = oldValue ? resolveAriaLabelledBy(element, oldValue) : "";
|
|
3137
|
+
if (!previousName && oldValue === null) {
|
|
3138
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
3139
|
+
if (ariaLabel) {
|
|
3140
|
+
previousName = ariaLabel.trim();
|
|
3141
|
+
} else {
|
|
3142
|
+
previousName = element.textContent?.trim() || "";
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
newName = computeAccessibleName3(element, doc);
|
|
3146
|
+
}
|
|
3147
|
+
if (previousName === newName) {
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
const eventTarget = buildEventTarget2(element);
|
|
3151
|
+
const payload = {
|
|
3152
|
+
kind: "accessible_name_changed",
|
|
3153
|
+
previousName,
|
|
3154
|
+
newName
|
|
3155
|
+
};
|
|
3156
|
+
onEvent({
|
|
3157
|
+
type: "ACCESSIBLE_NAME_CHANGED",
|
|
3158
|
+
timestamp: getTimestamp(),
|
|
3159
|
+
target: eventTarget,
|
|
3160
|
+
payload
|
|
3161
|
+
});
|
|
3162
|
+
}
|
|
3163
|
+
function handleStateChange(element, attributeName, oldValue) {
|
|
3164
|
+
const currentValue = element.getAttribute(attributeName);
|
|
3165
|
+
const normalizedOld = normalizeStateValue(oldValue);
|
|
3166
|
+
const normalizedNew = normalizeStateValue(currentValue);
|
|
3167
|
+
if (normalizedOld === normalizedNew) {
|
|
3168
|
+
return;
|
|
3169
|
+
}
|
|
3170
|
+
const eventTarget = buildEventTarget2(element);
|
|
3171
|
+
const payload = {
|
|
3172
|
+
kind: "state_changed",
|
|
3173
|
+
attribute: attributeName,
|
|
3174
|
+
previousValue: normalizedOld,
|
|
3175
|
+
newValue: normalizedNew
|
|
3176
|
+
};
|
|
3177
|
+
onEvent({
|
|
3178
|
+
type: "STATE_CHANGED",
|
|
3179
|
+
timestamp: getTimestamp(),
|
|
3180
|
+
target: eventTarget,
|
|
3181
|
+
payload
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
function buildEventTarget2(element) {
|
|
3185
|
+
return {
|
|
3186
|
+
role: getElementRole2(element),
|
|
3187
|
+
accessibleName: computeAccessibleName3(element, doc),
|
|
3188
|
+
selector: generateSelector(element)
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
function getImplicitRole(element) {
|
|
3192
|
+
const tagName = element.tagName.toLowerCase();
|
|
3193
|
+
switch (tagName) {
|
|
3194
|
+
case "button":
|
|
3195
|
+
return "button";
|
|
3196
|
+
case "a":
|
|
3197
|
+
return element.hasAttribute("href") ? "link" : "generic";
|
|
3198
|
+
case "input": {
|
|
3199
|
+
const type = (element.getAttribute("type") || "text").toLowerCase();
|
|
3200
|
+
switch (type) {
|
|
3201
|
+
case "button":
|
|
3202
|
+
case "submit":
|
|
3203
|
+
case "reset":
|
|
3204
|
+
case "image":
|
|
3205
|
+
return "button";
|
|
3206
|
+
case "checkbox":
|
|
3207
|
+
return "checkbox";
|
|
3208
|
+
case "radio":
|
|
3209
|
+
return "radio";
|
|
3210
|
+
default:
|
|
3211
|
+
return "textbox";
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
default:
|
|
3215
|
+
return "generic";
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
function resolveAriaLabelledBy(element, idRefs) {
|
|
3219
|
+
const ownerDoc = element.ownerDocument;
|
|
3220
|
+
if (!ownerDoc) {
|
|
3221
|
+
return "";
|
|
3222
|
+
}
|
|
3223
|
+
const ids = idRefs.trim().split(/\s+/).filter(Boolean);
|
|
3224
|
+
const parts = [];
|
|
3225
|
+
for (const id of ids) {
|
|
3226
|
+
const referenced = ownerDoc.getElementById(id);
|
|
3227
|
+
if (referenced && referenced.textContent) {
|
|
3228
|
+
parts.push(referenced.textContent.trim());
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return parts.join(" ");
|
|
3232
|
+
}
|
|
3233
|
+
function normalizeStateValue(value) {
|
|
3234
|
+
if (value === null) {
|
|
3235
|
+
return null;
|
|
3236
|
+
}
|
|
3237
|
+
if (value === "true") {
|
|
3238
|
+
return true;
|
|
3239
|
+
}
|
|
3240
|
+
if (value === "false") {
|
|
3241
|
+
return false;
|
|
3242
|
+
}
|
|
3243
|
+
return value;
|
|
3244
|
+
}
|
|
3245
|
+
return {
|
|
3246
|
+
start() {
|
|
3247
|
+
if (active) return;
|
|
3248
|
+
active = true;
|
|
3249
|
+
observer = new MutationObserver(handleMutations);
|
|
3250
|
+
observer.observe(doc.body ?? doc.documentElement, {
|
|
3251
|
+
attributes: true,
|
|
3252
|
+
attributeOldValue: true,
|
|
3253
|
+
attributeFilter: OBSERVED_ATTRIBUTES,
|
|
3254
|
+
subtree: true
|
|
3255
|
+
});
|
|
3256
|
+
},
|
|
3257
|
+
stop() {
|
|
3258
|
+
if (!active) return;
|
|
3259
|
+
active = false;
|
|
3260
|
+
if (observer) {
|
|
3261
|
+
observer.disconnect();
|
|
3262
|
+
observer = null;
|
|
3263
|
+
}
|
|
3264
|
+
},
|
|
3265
|
+
get isActive() {
|
|
3266
|
+
return active;
|
|
3267
|
+
}
|
|
3268
|
+
};
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// src/runtime/observers/live-region-observer.ts
|
|
3272
|
+
var IMPLICIT_LIVE_ROLES = /* @__PURE__ */ new Set(["alert", "status", "log", "marquee", "timer"]);
|
|
3273
|
+
var ROLE_POLITENESS_MAP = {
|
|
3274
|
+
alert: "assertive",
|
|
3275
|
+
status: "polite",
|
|
3276
|
+
log: "polite",
|
|
3277
|
+
marquee: "polite",
|
|
3278
|
+
timer: "polite"
|
|
3279
|
+
};
|
|
3280
|
+
function createLiveRegionObserver(document, callback) {
|
|
3281
|
+
let contentObserver = null;
|
|
3282
|
+
let documentObserver = null;
|
|
3283
|
+
const trackedRegions = /* @__PURE__ */ new Set();
|
|
3284
|
+
function getLiveRegionPoliteness(element) {
|
|
3285
|
+
const ariaLive = element.getAttribute("aria-live");
|
|
3286
|
+
if (ariaLive === "assertive") return "assertive";
|
|
3287
|
+
if (ariaLive === "polite") return "polite";
|
|
3288
|
+
if (ariaLive === "off") return null;
|
|
3289
|
+
const role = element.getAttribute("role");
|
|
3290
|
+
if (role && IMPLICIT_LIVE_ROLES.has(role)) {
|
|
3291
|
+
return ROLE_POLITENESS_MAP[role] || "polite";
|
|
3292
|
+
}
|
|
3293
|
+
if (ariaLive && ariaLive !== "off") return "polite";
|
|
3294
|
+
return null;
|
|
3295
|
+
}
|
|
3296
|
+
function isAtomic(element) {
|
|
3297
|
+
return element.getAttribute("aria-atomic") === "true";
|
|
3298
|
+
}
|
|
3299
|
+
function buildEventTarget2(element) {
|
|
3300
|
+
const role = element.getAttribute("role") || "region";
|
|
3301
|
+
const accessibleName = element.getAttribute("aria-label") || element.getAttribute("aria-labelledby") || "";
|
|
3302
|
+
const selector = generateSelector(element);
|
|
3303
|
+
return { role, accessibleName, selector };
|
|
3304
|
+
}
|
|
3305
|
+
function getTextFromNodes(nodes) {
|
|
3306
|
+
const parts = [];
|
|
3307
|
+
nodes.forEach((node) => {
|
|
3308
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
3309
|
+
const text = node.textContent?.trim();
|
|
3310
|
+
if (text) parts.push(text);
|
|
3311
|
+
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
3312
|
+
const text = node.textContent?.trim();
|
|
3313
|
+
if (text) parts.push(text);
|
|
3314
|
+
}
|
|
3315
|
+
});
|
|
3316
|
+
return parts.join(" ").trim();
|
|
3317
|
+
}
|
|
3318
|
+
function emitAnnouncement(liveRegion, text, politeness) {
|
|
3319
|
+
if (!text) return;
|
|
3320
|
+
const target = buildEventTarget2(liveRegion);
|
|
3321
|
+
callback({
|
|
3322
|
+
type: "ANNOUNCEMENT",
|
|
3323
|
+
target,
|
|
3324
|
+
payload: {
|
|
3325
|
+
kind: "announcement",
|
|
3326
|
+
politeness,
|
|
3327
|
+
text
|
|
3328
|
+
}
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
function findLiveRegionAncestor(node) {
|
|
3332
|
+
let current = node;
|
|
3333
|
+
while (current) {
|
|
3334
|
+
if (current.nodeType === Node.ELEMENT_NODE && trackedRegions.has(current)) {
|
|
3335
|
+
return current;
|
|
3336
|
+
}
|
|
3337
|
+
current = current.parentNode;
|
|
3338
|
+
}
|
|
3339
|
+
return null;
|
|
3340
|
+
}
|
|
3341
|
+
function handleContentMutations(mutations) {
|
|
3342
|
+
const regionChanges = /* @__PURE__ */ new Map();
|
|
3343
|
+
for (const mutation of mutations) {
|
|
3344
|
+
const liveRegion = findLiveRegionAncestor(mutation.target);
|
|
3345
|
+
if (!liveRegion) continue;
|
|
3346
|
+
if (!regionChanges.has(liveRegion)) {
|
|
3347
|
+
regionChanges.set(liveRegion, { addedText: [], charDataChanged: false });
|
|
3348
|
+
}
|
|
3349
|
+
const changes = regionChanges.get(liveRegion);
|
|
3350
|
+
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
|
|
3351
|
+
const text = getTextFromNodes(mutation.addedNodes);
|
|
3352
|
+
if (text) {
|
|
3353
|
+
changes.addedText.push(text);
|
|
3354
|
+
}
|
|
3355
|
+
} else if (mutation.type === "characterData") {
|
|
3356
|
+
changes.charDataChanged = true;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
for (const [region, changes] of regionChanges) {
|
|
3360
|
+
const politeness = getLiveRegionPoliteness(region);
|
|
3361
|
+
if (!politeness) continue;
|
|
3362
|
+
let text;
|
|
3363
|
+
if (isAtomic(region)) {
|
|
3364
|
+
text = region.textContent?.trim() || "";
|
|
3365
|
+
} else {
|
|
3366
|
+
if (changes.addedText.length > 0) {
|
|
3367
|
+
text = changes.addedText.join(" ").trim();
|
|
3368
|
+
} else if (changes.charDataChanged) {
|
|
3369
|
+
text = region.textContent?.trim() || "";
|
|
3370
|
+
} else {
|
|
3371
|
+
text = "";
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
emitAnnouncement(region, text, politeness);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
function handleDocumentMutations(mutations) {
|
|
3378
|
+
for (const mutation of mutations) {
|
|
3379
|
+
if (mutation.type !== "childList") continue;
|
|
3380
|
+
mutation.addedNodes.forEach((node) => {
|
|
3381
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
3382
|
+
const element = node;
|
|
3383
|
+
if (getLiveRegionPoliteness(element) !== null && !trackedRegions.has(element)) {
|
|
3384
|
+
trackRegion(element);
|
|
3385
|
+
}
|
|
3386
|
+
const descendants = element.querySelectorAll("[aria-live], [role]");
|
|
3387
|
+
descendants.forEach((desc) => {
|
|
3388
|
+
if (getLiveRegionPoliteness(desc) !== null && !trackedRegions.has(desc)) {
|
|
3389
|
+
trackRegion(desc);
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3392
|
+
});
|
|
3393
|
+
mutation.removedNodes.forEach((node) => {
|
|
3394
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
3395
|
+
const element = node;
|
|
3396
|
+
if (trackedRegions.has(element)) {
|
|
3397
|
+
trackedRegions.delete(element);
|
|
3398
|
+
}
|
|
3399
|
+
const descendants = element.querySelectorAll("[aria-live], [role]");
|
|
3400
|
+
descendants.forEach((desc) => {
|
|
3401
|
+
trackedRegions.delete(desc);
|
|
3402
|
+
});
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
function trackRegion(element) {
|
|
3407
|
+
trackedRegions.add(element);
|
|
3408
|
+
}
|
|
3409
|
+
function discoverExistingRegions() {
|
|
3410
|
+
const ariaLiveElements = document.querySelectorAll("[aria-live]");
|
|
3411
|
+
ariaLiveElements.forEach((el) => {
|
|
3412
|
+
if (getLiveRegionPoliteness(el) !== null) {
|
|
3413
|
+
trackRegion(el);
|
|
3414
|
+
}
|
|
3415
|
+
});
|
|
3416
|
+
IMPLICIT_LIVE_ROLES.forEach((role) => {
|
|
3417
|
+
const roleElements = document.querySelectorAll(`[role="${role}"]`);
|
|
3418
|
+
roleElements.forEach((el) => {
|
|
3419
|
+
if (!trackedRegions.has(el)) {
|
|
3420
|
+
trackRegion(el);
|
|
3421
|
+
}
|
|
3422
|
+
});
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
function start() {
|
|
3426
|
+
discoverExistingRegions();
|
|
3427
|
+
contentObserver = new MutationObserver(handleContentMutations);
|
|
3428
|
+
const body = document.body;
|
|
3429
|
+
if (body) {
|
|
3430
|
+
contentObserver.observe(body, {
|
|
3431
|
+
childList: true,
|
|
3432
|
+
characterData: true,
|
|
3433
|
+
subtree: true,
|
|
3434
|
+
characterDataOldValue: true
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
documentObserver = new MutationObserver(handleDocumentMutations);
|
|
3438
|
+
if (body) {
|
|
3439
|
+
documentObserver.observe(body, {
|
|
3440
|
+
childList: true,
|
|
3441
|
+
subtree: true
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
function stop() {
|
|
3446
|
+
if (contentObserver) {
|
|
3447
|
+
contentObserver.disconnect();
|
|
3448
|
+
contentObserver = null;
|
|
3449
|
+
}
|
|
3450
|
+
if (documentObserver) {
|
|
3451
|
+
documentObserver.disconnect();
|
|
3452
|
+
documentObserver = null;
|
|
3453
|
+
}
|
|
3454
|
+
trackedRegions.clear();
|
|
3455
|
+
}
|
|
3456
|
+
return { start, stop };
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// src/runtime/observers/dialog-observer.ts
|
|
3460
|
+
function computeDialogAccessibleName(element, document) {
|
|
3461
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
3462
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
3463
|
+
return ariaLabel.trim();
|
|
3464
|
+
}
|
|
3465
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
3466
|
+
if (labelledBy && labelledBy.trim()) {
|
|
3467
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
3468
|
+
const parts = [];
|
|
3469
|
+
for (const id of ids) {
|
|
3470
|
+
const referenced = document.getElementById(id);
|
|
3471
|
+
if (referenced && referenced.textContent) {
|
|
3472
|
+
parts.push(referenced.textContent.trim());
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
const combined = parts.join(" ");
|
|
3476
|
+
if (combined) {
|
|
3477
|
+
return combined;
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
const title = element.getAttribute("title");
|
|
3481
|
+
if (title && title.trim()) {
|
|
3482
|
+
return title.trim();
|
|
3483
|
+
}
|
|
3484
|
+
const heading = element.querySelector("h1, h2, h3, h4, h5, h6");
|
|
3485
|
+
if (heading && heading.textContent && heading.textContent.trim()) {
|
|
3486
|
+
return heading.textContent.trim();
|
|
3487
|
+
}
|
|
3488
|
+
return "";
|
|
3489
|
+
}
|
|
3490
|
+
function getDialogRole(element) {
|
|
3491
|
+
const explicitRole = element.getAttribute("role");
|
|
3492
|
+
if (explicitRole && explicitRole.trim()) {
|
|
3493
|
+
return explicitRole.trim();
|
|
3494
|
+
}
|
|
3495
|
+
if (element.tagName.toLowerCase() === "dialog") {
|
|
3496
|
+
return "dialog";
|
|
3497
|
+
}
|
|
3498
|
+
return "generic";
|
|
3499
|
+
}
|
|
3500
|
+
function isDialogElement(element) {
|
|
3501
|
+
if (element.tagName.toLowerCase() === "dialog") {
|
|
3502
|
+
return true;
|
|
3503
|
+
}
|
|
3504
|
+
const role = element.getAttribute("role");
|
|
3505
|
+
return role === "dialog" || role === "alertdialog";
|
|
3506
|
+
}
|
|
3507
|
+
function isDialogModal(element) {
|
|
3508
|
+
const ariaModal = element.getAttribute("aria-modal");
|
|
3509
|
+
if (ariaModal === "true") {
|
|
3510
|
+
return true;
|
|
3511
|
+
}
|
|
3512
|
+
return false;
|
|
3513
|
+
}
|
|
3514
|
+
function createDialogObserver(options) {
|
|
3515
|
+
const { document: doc, onEvent, getTimestamp } = options;
|
|
3516
|
+
let active = false;
|
|
3517
|
+
let mutationObserver = null;
|
|
3518
|
+
const openDialogStack = [];
|
|
3519
|
+
function buildEventTarget2(element) {
|
|
3520
|
+
return {
|
|
3521
|
+
role: getDialogRole(element),
|
|
3522
|
+
accessibleName: computeDialogAccessibleName(element, doc),
|
|
3523
|
+
selector: generateSelector(element)
|
|
3524
|
+
};
|
|
3525
|
+
}
|
|
3526
|
+
function emitDialogOpened(element) {
|
|
3527
|
+
const name = computeDialogAccessibleName(element, doc);
|
|
3528
|
+
const isModal = isDialogModal(element);
|
|
3529
|
+
const target = buildEventTarget2(element);
|
|
3530
|
+
openDialogStack.push({
|
|
3531
|
+
element,
|
|
3532
|
+
name,
|
|
3533
|
+
selector: target.selector
|
|
3534
|
+
});
|
|
3535
|
+
const a11yEvent = {
|
|
3536
|
+
type: "DIALOG_OPENED",
|
|
3537
|
+
timestamp: getTimestamp(),
|
|
3538
|
+
target,
|
|
3539
|
+
payload: {
|
|
3540
|
+
kind: "dialog_opened",
|
|
3541
|
+
dialogName: name,
|
|
3542
|
+
isModal
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3545
|
+
onEvent(a11yEvent);
|
|
3546
|
+
}
|
|
3547
|
+
function emitDialogClosed(element) {
|
|
3548
|
+
const name = computeDialogAccessibleName(element, doc);
|
|
3549
|
+
const target = buildEventTarget2(element);
|
|
3550
|
+
const index = openDialogStack.findIndex((d) => d.element === element);
|
|
3551
|
+
if (index !== -1) {
|
|
3552
|
+
openDialogStack.splice(index, 1);
|
|
3553
|
+
}
|
|
3554
|
+
const a11yEvent = {
|
|
3555
|
+
type: "DIALOG_CLOSED",
|
|
3556
|
+
timestamp: getTimestamp(),
|
|
3557
|
+
target,
|
|
3558
|
+
payload: {
|
|
3559
|
+
kind: "dialog_closed",
|
|
3560
|
+
dialogName: name
|
|
3561
|
+
}
|
|
3562
|
+
};
|
|
3563
|
+
onEvent(a11yEvent);
|
|
3564
|
+
}
|
|
3565
|
+
function isTrackedAsOpen(element) {
|
|
3566
|
+
return openDialogStack.some((d) => d.element === element);
|
|
3567
|
+
}
|
|
3568
|
+
function handleMutations(mutations) {
|
|
3569
|
+
if (!active) return;
|
|
3570
|
+
for (const mutation of mutations) {
|
|
3571
|
+
if (mutation.type === "attributes") {
|
|
3572
|
+
const target = mutation.target;
|
|
3573
|
+
if (!(target instanceof doc.defaultView.Element)) continue;
|
|
3574
|
+
if (mutation.attributeName === "open" && target.tagName.toLowerCase() === "dialog") {
|
|
3575
|
+
if (target.hasAttribute("open")) {
|
|
3576
|
+
if (!isTrackedAsOpen(target)) {
|
|
3577
|
+
emitDialogOpened(target);
|
|
3578
|
+
}
|
|
3579
|
+
} else {
|
|
3580
|
+
if (isTrackedAsOpen(target)) {
|
|
3581
|
+
emitDialogClosed(target);
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
if (mutation.attributeName === "aria-modal" && isDialogElement(target)) {
|
|
3586
|
+
if (!isTrackedAsOpen(target) && isVisibleDialog(target)) {
|
|
3587
|
+
emitDialogOpened(target);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
if (mutation.attributeName === "role") {
|
|
3591
|
+
const oldRole = mutation.oldValue;
|
|
3592
|
+
const newRole = target.getAttribute("role");
|
|
3593
|
+
const wasDialog = oldRole === "dialog" || oldRole === "alertdialog";
|
|
3594
|
+
const isNowDialog = newRole === "dialog" || newRole === "alertdialog";
|
|
3595
|
+
if (!wasDialog && isNowDialog && isVisibleDialog(target)) {
|
|
3596
|
+
emitDialogOpened(target);
|
|
3597
|
+
} else if (wasDialog && !isNowDialog && isTrackedAsOpen(target)) {
|
|
3598
|
+
emitDialogClosed(target);
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
if (mutation.type === "childList") {
|
|
3603
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
3604
|
+
const node = mutation.addedNodes[i];
|
|
3605
|
+
if (!(node instanceof doc.defaultView.Element)) continue;
|
|
3606
|
+
if (isDialogElement(node) && isVisibleDialog(node)) {
|
|
3607
|
+
if (!isTrackedAsOpen(node)) {
|
|
3608
|
+
emitDialogOpened(node);
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
const dialogDescendants = node.querySelectorAll(
|
|
3612
|
+
'dialog[open], [role="dialog"], [role="alertdialog"]'
|
|
3613
|
+
);
|
|
3614
|
+
for (let j = 0; j < dialogDescendants.length; j++) {
|
|
3615
|
+
const dialog = dialogDescendants[j];
|
|
3616
|
+
if (isVisibleDialog(dialog) && !isTrackedAsOpen(dialog)) {
|
|
3617
|
+
emitDialogOpened(dialog);
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
3622
|
+
const node = mutation.removedNodes[i];
|
|
3623
|
+
if (!(node instanceof doc.defaultView.Element)) continue;
|
|
3624
|
+
if (isTrackedAsOpen(node)) {
|
|
3625
|
+
emitDialogClosed(node);
|
|
3626
|
+
}
|
|
3627
|
+
const trackedInRemoved = openDialogStack.filter(
|
|
3628
|
+
(d) => node.contains(d.element)
|
|
3629
|
+
);
|
|
3630
|
+
for (const tracked of trackedInRemoved) {
|
|
3631
|
+
emitDialogClosed(tracked.element);
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
function isVisibleDialog(element) {
|
|
3638
|
+
if (element.tagName.toLowerCase() === "dialog") {
|
|
3639
|
+
return element.hasAttribute("open");
|
|
3640
|
+
}
|
|
3641
|
+
return true;
|
|
3642
|
+
}
|
|
3643
|
+
return {
|
|
3644
|
+
start() {
|
|
3645
|
+
if (active) return;
|
|
3646
|
+
active = true;
|
|
3647
|
+
openDialogStack.length = 0;
|
|
3648
|
+
const existingDialogs = doc.querySelectorAll(
|
|
3649
|
+
'dialog[open], [role="dialog"], [role="alertdialog"]'
|
|
3650
|
+
);
|
|
3651
|
+
for (let i = 0; i < existingDialogs.length; i++) {
|
|
3652
|
+
const dialog = existingDialogs[i];
|
|
3653
|
+
if (isVisibleDialog(dialog)) {
|
|
3654
|
+
openDialogStack.push({
|
|
3655
|
+
element: dialog,
|
|
3656
|
+
name: computeDialogAccessibleName(dialog, doc),
|
|
3657
|
+
selector: generateSelector(dialog)
|
|
3658
|
+
});
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
mutationObserver = new MutationObserver(handleMutations);
|
|
3662
|
+
mutationObserver.observe(doc.body || doc.documentElement, {
|
|
3663
|
+
attributes: true,
|
|
3664
|
+
attributeFilter: ["open", "role", "aria-modal"],
|
|
3665
|
+
attributeOldValue: true,
|
|
3666
|
+
childList: true,
|
|
3667
|
+
subtree: true
|
|
3668
|
+
});
|
|
3669
|
+
},
|
|
3670
|
+
stop() {
|
|
3671
|
+
if (!active) return;
|
|
3672
|
+
active = false;
|
|
3673
|
+
if (mutationObserver) {
|
|
3674
|
+
mutationObserver.disconnect();
|
|
3675
|
+
mutationObserver = null;
|
|
3676
|
+
}
|
|
3677
|
+
openDialogStack.length = 0;
|
|
3678
|
+
},
|
|
3679
|
+
get isActive() {
|
|
3680
|
+
return active;
|
|
3681
|
+
},
|
|
3682
|
+
getOpenDialogs() {
|
|
3683
|
+
return openDialogStack.map((d) => d.name);
|
|
3684
|
+
}
|
|
3685
|
+
};
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
// src/runtime/engine.ts
|
|
3689
|
+
function createEngine(options) {
|
|
3690
|
+
const { document: doc } = options;
|
|
3691
|
+
let attached = false;
|
|
3692
|
+
let sessionStart = 0;
|
|
3693
|
+
let events = [];
|
|
3694
|
+
function getTimestamp() {
|
|
3695
|
+
return Date.now() - sessionStart;
|
|
3696
|
+
}
|
|
3697
|
+
function collectEvent(event) {
|
|
3698
|
+
events.push(event);
|
|
3699
|
+
}
|
|
3700
|
+
function collectLiveRegionEvent(event) {
|
|
3701
|
+
const fullEvent = {
|
|
3702
|
+
...event,
|
|
3703
|
+
timestamp: getTimestamp()
|
|
3704
|
+
};
|
|
3705
|
+
events.push(fullEvent);
|
|
3706
|
+
}
|
|
3707
|
+
const focusObs = createFocusObserver({
|
|
3708
|
+
document: doc,
|
|
3709
|
+
onEvent: collectEvent,
|
|
3710
|
+
getTimestamp
|
|
3711
|
+
});
|
|
3712
|
+
const mutationObs = createMutationObserver({
|
|
3713
|
+
document: doc,
|
|
3714
|
+
onEvent: collectEvent,
|
|
3715
|
+
getTimestamp
|
|
3716
|
+
});
|
|
3717
|
+
const liveRegionObs = createLiveRegionObserver(
|
|
3718
|
+
doc,
|
|
3719
|
+
collectLiveRegionEvent
|
|
3720
|
+
);
|
|
3721
|
+
const dialogObs = createDialogObserver({
|
|
3722
|
+
document: doc,
|
|
3723
|
+
onEvent: collectEvent,
|
|
3724
|
+
getTimestamp
|
|
3725
|
+
});
|
|
3726
|
+
return {
|
|
3727
|
+
attach() {
|
|
3728
|
+
if (attached) return;
|
|
3729
|
+
attached = true;
|
|
3730
|
+
sessionStart = Date.now();
|
|
3731
|
+
events = [];
|
|
3732
|
+
focusObs.start();
|
|
3733
|
+
mutationObs.start();
|
|
3734
|
+
liveRegionObs.start();
|
|
3735
|
+
dialogObs.start();
|
|
3736
|
+
},
|
|
3737
|
+
detach() {
|
|
3738
|
+
if (!attached) return;
|
|
3739
|
+
attached = false;
|
|
3740
|
+
focusObs.stop();
|
|
3741
|
+
mutationObs.stop();
|
|
3742
|
+
liveRegionObs.stop();
|
|
3743
|
+
dialogObs.stop();
|
|
3744
|
+
},
|
|
3745
|
+
getEvents() {
|
|
3746
|
+
return [...events];
|
|
3747
|
+
},
|
|
3748
|
+
reset() {
|
|
3749
|
+
events = [];
|
|
3750
|
+
},
|
|
3751
|
+
get isAttached() {
|
|
3752
|
+
return attached;
|
|
3753
|
+
},
|
|
3754
|
+
get dialogObserver() {
|
|
3755
|
+
return {
|
|
3756
|
+
getOpenDialogs() {
|
|
3757
|
+
return dialogObs.getOpenDialogs();
|
|
3758
|
+
}
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
// src/runtime/interactions.ts
|
|
3765
|
+
var KEY_MAP = {
|
|
3766
|
+
Tab: { key: "Tab", code: "Tab", keyCode: 9 },
|
|
3767
|
+
Escape: { key: "Escape", code: "Escape", keyCode: 27 },
|
|
3768
|
+
Enter: { key: "Enter", code: "Enter", keyCode: 13 },
|
|
3769
|
+
" ": { key: " ", code: "Space", keyCode: 32 },
|
|
3770
|
+
ArrowUp: { key: "ArrowUp", code: "ArrowUp", keyCode: 38 },
|
|
3771
|
+
ArrowDown: { key: "ArrowDown", code: "ArrowDown", keyCode: 40 },
|
|
3772
|
+
ArrowLeft: { key: "ArrowLeft", code: "ArrowLeft", keyCode: 37 },
|
|
3773
|
+
ArrowRight: { key: "ArrowRight", code: "ArrowRight", keyCode: 39 }
|
|
3774
|
+
};
|
|
3775
|
+
var FOCUSABLE_SELECTOR = [
|
|
3776
|
+
"button:not([disabled])",
|
|
3777
|
+
"a[href]",
|
|
3778
|
+
"input:not([disabled])",
|
|
3779
|
+
"select:not([disabled])",
|
|
3780
|
+
"textarea:not([disabled])",
|
|
3781
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
3782
|
+
].join(", ");
|
|
3783
|
+
function getFocusableElements(document) {
|
|
3784
|
+
return Array.from(document.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
3785
|
+
}
|
|
3786
|
+
function computeAccessibleName4(element, document) {
|
|
3787
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
3788
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
3789
|
+
return ariaLabel.trim();
|
|
3790
|
+
}
|
|
3791
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
3792
|
+
if (labelledBy && labelledBy.trim()) {
|
|
3793
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
3794
|
+
const parts = [];
|
|
3795
|
+
for (const id of ids) {
|
|
3796
|
+
const referenced = document.getElementById(id);
|
|
3797
|
+
if (referenced && referenced.textContent) {
|
|
3798
|
+
parts.push(referenced.textContent.trim());
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
const combined = parts.join(" ");
|
|
3802
|
+
if (combined) return combined;
|
|
3803
|
+
}
|
|
3804
|
+
const textContent = element.textContent;
|
|
3805
|
+
if (textContent && textContent.trim()) {
|
|
3806
|
+
return textContent.trim();
|
|
3807
|
+
}
|
|
3808
|
+
return "";
|
|
3809
|
+
}
|
|
3810
|
+
function getElementRole3(element) {
|
|
3811
|
+
const explicitRole = element.getAttribute("role");
|
|
3812
|
+
if (explicitRole && explicitRole.trim()) {
|
|
3813
|
+
return explicitRole.trim();
|
|
3814
|
+
}
|
|
3815
|
+
const tagName = element.tagName.toLowerCase();
|
|
3816
|
+
switch (tagName) {
|
|
3817
|
+
case "button":
|
|
3818
|
+
return "button";
|
|
3819
|
+
case "a":
|
|
3820
|
+
return element.hasAttribute("href") ? "link" : "generic";
|
|
3821
|
+
case "input": {
|
|
3822
|
+
const type = (element.getAttribute("type") || "text").toLowerCase();
|
|
3823
|
+
switch (type) {
|
|
3824
|
+
case "button":
|
|
3825
|
+
case "submit":
|
|
3826
|
+
case "reset":
|
|
3827
|
+
case "image":
|
|
3828
|
+
return "button";
|
|
3829
|
+
case "checkbox":
|
|
3830
|
+
return "checkbox";
|
|
3831
|
+
case "radio":
|
|
3832
|
+
return "radio";
|
|
3833
|
+
case "range":
|
|
3834
|
+
return "slider";
|
|
3835
|
+
case "search":
|
|
3836
|
+
return "searchbox";
|
|
3837
|
+
default:
|
|
3838
|
+
return "textbox";
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
case "textarea":
|
|
3842
|
+
return "textbox";
|
|
3843
|
+
case "select":
|
|
3844
|
+
return element.hasAttribute("multiple") ? "listbox" : "combobox";
|
|
3845
|
+
case "dialog":
|
|
3846
|
+
return "dialog";
|
|
3847
|
+
default:
|
|
3848
|
+
return "generic";
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
function buildEventTarget(element, document) {
|
|
3852
|
+
return {
|
|
3853
|
+
role: getElementRole3(element),
|
|
3854
|
+
accessibleName: computeAccessibleName4(element, document),
|
|
3855
|
+
selector: generateSelector(element)
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
function dispatchKeyboardEvent(document, options) {
|
|
3859
|
+
const target = document.activeElement || document.body;
|
|
3860
|
+
const commonProps = {
|
|
3861
|
+
key: options.key,
|
|
3862
|
+
code: options.code,
|
|
3863
|
+
keyCode: options.keyCode,
|
|
3864
|
+
which: options.keyCode,
|
|
3865
|
+
shiftKey: options.shiftKey || false,
|
|
3866
|
+
ctrlKey: options.ctrlKey || false,
|
|
3867
|
+
altKey: options.altKey || false,
|
|
3868
|
+
metaKey: options.metaKey || false,
|
|
3869
|
+
bubbles: true,
|
|
3870
|
+
cancelable: true
|
|
3871
|
+
};
|
|
3872
|
+
target.dispatchEvent(new KeyboardEvent("keydown", commonProps));
|
|
3873
|
+
if (options.key.length === 1) {
|
|
3874
|
+
target.dispatchEvent(new KeyboardEvent("keypress", commonProps));
|
|
3875
|
+
}
|
|
3876
|
+
target.dispatchEvent(new KeyboardEvent("keyup", commonProps));
|
|
3877
|
+
}
|
|
3878
|
+
function parseKeyCombo(combo) {
|
|
3879
|
+
const parts = combo.split("+");
|
|
3880
|
+
const modifiers = [];
|
|
3881
|
+
let shiftKey = false;
|
|
3882
|
+
let ctrlKey = false;
|
|
3883
|
+
let altKey = false;
|
|
3884
|
+
let metaKey = false;
|
|
3885
|
+
const key = parts[parts.length - 1];
|
|
3886
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
3887
|
+
const mod = parts[i].toLowerCase();
|
|
3888
|
+
switch (mod) {
|
|
3889
|
+
case "shift":
|
|
3890
|
+
shiftKey = true;
|
|
3891
|
+
modifiers.push("Shift");
|
|
3892
|
+
break;
|
|
3893
|
+
case "control":
|
|
3894
|
+
case "ctrl":
|
|
3895
|
+
ctrlKey = true;
|
|
3896
|
+
modifiers.push("Control");
|
|
3897
|
+
break;
|
|
3898
|
+
case "alt":
|
|
3899
|
+
altKey = true;
|
|
3900
|
+
modifiers.push("Alt");
|
|
3901
|
+
break;
|
|
3902
|
+
case "meta":
|
|
3903
|
+
case "cmd":
|
|
3904
|
+
case "command":
|
|
3905
|
+
metaKey = true;
|
|
3906
|
+
modifiers.push("Meta");
|
|
3907
|
+
break;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
return { key, modifiers, shiftKey, ctrlKey, altKey, metaKey };
|
|
3911
|
+
}
|
|
3912
|
+
function getKeyInfo(key) {
|
|
3913
|
+
if (KEY_MAP[key]) {
|
|
3914
|
+
return KEY_MAP[key];
|
|
3915
|
+
}
|
|
3916
|
+
if (key.length === 1) {
|
|
3917
|
+
return {
|
|
3918
|
+
key,
|
|
3919
|
+
code: `Key${key.toUpperCase()}`,
|
|
3920
|
+
keyCode: key.toUpperCase().charCodeAt(0)
|
|
3921
|
+
};
|
|
3922
|
+
}
|
|
3923
|
+
return {
|
|
3924
|
+
key,
|
|
3925
|
+
code: key,
|
|
3926
|
+
keyCode: 0
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
function executeClick(selector, document, onEvent, getTimestamp) {
|
|
3930
|
+
const element = document.querySelector(selector);
|
|
3931
|
+
if (!element) {
|
|
3932
|
+
const warningEvent = {
|
|
3933
|
+
type: "WARNING",
|
|
3934
|
+
timestamp: getTimestamp(),
|
|
3935
|
+
target: {
|
|
3936
|
+
role: "generic",
|
|
3937
|
+
accessibleName: "",
|
|
3938
|
+
selector
|
|
3939
|
+
},
|
|
3940
|
+
payload: {
|
|
3941
|
+
kind: "warning",
|
|
3942
|
+
message: `Element not found: ${selector}`
|
|
3943
|
+
}
|
|
3944
|
+
};
|
|
3945
|
+
onEvent(warningEvent);
|
|
3946
|
+
return;
|
|
3947
|
+
}
|
|
3948
|
+
const eventProps = { bubbles: true, cancelable: true };
|
|
3949
|
+
element.dispatchEvent(new MouseEvent("mousedown", eventProps));
|
|
3950
|
+
element.dispatchEvent(new MouseEvent("mouseup", eventProps));
|
|
3951
|
+
element.dispatchEvent(new MouseEvent("click", eventProps));
|
|
3952
|
+
if ("focus" in element && typeof element.focus === "function") {
|
|
3953
|
+
element.focus();
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
function executeTab(document, onEvent, getTimestamp) {
|
|
3957
|
+
const focusableElements = getFocusableElements(document);
|
|
3958
|
+
if (focusableElements.length === 0) return;
|
|
3959
|
+
const activeElement = document.activeElement;
|
|
3960
|
+
let currentIndex = -1;
|
|
3961
|
+
if (activeElement) {
|
|
3962
|
+
currentIndex = focusableElements.indexOf(activeElement);
|
|
3963
|
+
}
|
|
3964
|
+
const nextIndex = (currentIndex + 1) % focusableElements.length;
|
|
3965
|
+
const nextElement = focusableElements[nextIndex];
|
|
3966
|
+
dispatchKeyboardEvent(document, {
|
|
3967
|
+
...KEY_MAP["Tab"],
|
|
3968
|
+
shiftKey: false
|
|
3969
|
+
});
|
|
3970
|
+
if (nextElement && typeof nextElement.focus === "function") {
|
|
3971
|
+
nextElement.focus();
|
|
3972
|
+
}
|
|
3973
|
+
const target = document.activeElement || document.body;
|
|
3974
|
+
const keyboardEvent = {
|
|
3975
|
+
type: "KEYBOARD_ACTION",
|
|
3976
|
+
timestamp: getTimestamp(),
|
|
3977
|
+
target: buildEventTarget(target, document),
|
|
3978
|
+
payload: {
|
|
3979
|
+
kind: "keyboard_action",
|
|
3980
|
+
key: "Tab",
|
|
3981
|
+
modifiers: []
|
|
3982
|
+
}
|
|
3983
|
+
};
|
|
3984
|
+
onEvent(keyboardEvent);
|
|
3985
|
+
}
|
|
3986
|
+
function executeShiftTab(document, onEvent, getTimestamp) {
|
|
3987
|
+
const focusableElements = getFocusableElements(document);
|
|
3988
|
+
if (focusableElements.length === 0) return;
|
|
3989
|
+
const activeElement = document.activeElement;
|
|
3990
|
+
let currentIndex = -1;
|
|
3991
|
+
if (activeElement) {
|
|
3992
|
+
currentIndex = focusableElements.indexOf(activeElement);
|
|
3993
|
+
}
|
|
3994
|
+
const prevIndex = currentIndex <= 0 ? focusableElements.length - 1 : currentIndex - 1;
|
|
3995
|
+
const prevElement = focusableElements[prevIndex];
|
|
3996
|
+
dispatchKeyboardEvent(document, {
|
|
3997
|
+
...KEY_MAP["Tab"],
|
|
3998
|
+
shiftKey: true
|
|
3999
|
+
});
|
|
4000
|
+
if (prevElement && typeof prevElement.focus === "function") {
|
|
4001
|
+
prevElement.focus();
|
|
4002
|
+
}
|
|
4003
|
+
const target = document.activeElement || document.body;
|
|
4004
|
+
const keyboardEvent = {
|
|
4005
|
+
type: "KEYBOARD_ACTION",
|
|
4006
|
+
timestamp: getTimestamp(),
|
|
4007
|
+
target: buildEventTarget(target, document),
|
|
4008
|
+
payload: {
|
|
4009
|
+
kind: "keyboard_action",
|
|
4010
|
+
key: "Tab",
|
|
4011
|
+
modifiers: ["Shift"]
|
|
4012
|
+
}
|
|
4013
|
+
};
|
|
4014
|
+
onEvent(keyboardEvent);
|
|
4015
|
+
}
|
|
4016
|
+
function executeKeyAction(keyName, document, onEvent, getTimestamp) {
|
|
4017
|
+
const keyInfo = KEY_MAP[keyName];
|
|
4018
|
+
if (!keyInfo) return;
|
|
4019
|
+
dispatchKeyboardEvent(document, {
|
|
4020
|
+
...keyInfo
|
|
4021
|
+
});
|
|
4022
|
+
const target = document.activeElement || document.body;
|
|
4023
|
+
const keyboardEvent = {
|
|
4024
|
+
type: "KEYBOARD_ACTION",
|
|
4025
|
+
timestamp: getTimestamp(),
|
|
4026
|
+
target: buildEventTarget(target, document),
|
|
4027
|
+
payload: {
|
|
4028
|
+
kind: "keyboard_action",
|
|
4029
|
+
key: keyName,
|
|
4030
|
+
modifiers: []
|
|
4031
|
+
}
|
|
4032
|
+
};
|
|
4033
|
+
onEvent(keyboardEvent);
|
|
4034
|
+
}
|
|
4035
|
+
function executeKeyCombo(combo, document, onEvent, getTimestamp) {
|
|
4036
|
+
const parsed = parseKeyCombo(combo);
|
|
4037
|
+
const keyInfo = getKeyInfo(parsed.key);
|
|
4038
|
+
dispatchKeyboardEvent(document, {
|
|
4039
|
+
...keyInfo,
|
|
4040
|
+
shiftKey: parsed.shiftKey,
|
|
4041
|
+
ctrlKey: parsed.ctrlKey,
|
|
4042
|
+
altKey: parsed.altKey,
|
|
4043
|
+
metaKey: parsed.metaKey
|
|
4044
|
+
});
|
|
4045
|
+
const target = document.activeElement || document.body;
|
|
4046
|
+
const keyboardEvent = {
|
|
4047
|
+
type: "KEYBOARD_ACTION",
|
|
4048
|
+
timestamp: getTimestamp(),
|
|
4049
|
+
target: buildEventTarget(target, document),
|
|
4050
|
+
payload: {
|
|
4051
|
+
kind: "keyboard_action",
|
|
4052
|
+
key: parsed.key,
|
|
4053
|
+
modifiers: parsed.modifiers
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
onEvent(keyboardEvent);
|
|
4057
|
+
}
|
|
4058
|
+
async function executeAction(action, document, onEvent, getTimestamp) {
|
|
4059
|
+
switch (action.type) {
|
|
4060
|
+
case "click":
|
|
4061
|
+
executeClick(action.selector, document, onEvent, getTimestamp);
|
|
4062
|
+
break;
|
|
4063
|
+
case "tab":
|
|
4064
|
+
executeTab(document, onEvent, getTimestamp);
|
|
4065
|
+
break;
|
|
4066
|
+
case "shiftTab":
|
|
4067
|
+
executeShiftTab(document, onEvent, getTimestamp);
|
|
4068
|
+
break;
|
|
4069
|
+
case "escape":
|
|
4070
|
+
executeKeyAction("Escape", document, onEvent, getTimestamp);
|
|
4071
|
+
break;
|
|
4072
|
+
case "enter":
|
|
4073
|
+
executeKeyAction("Enter", document, onEvent, getTimestamp);
|
|
4074
|
+
break;
|
|
4075
|
+
case "space":
|
|
4076
|
+
executeKeyAction(" ", document, onEvent, getTimestamp);
|
|
4077
|
+
break;
|
|
4078
|
+
case "arrowUp":
|
|
4079
|
+
executeKeyAction("ArrowUp", document, onEvent, getTimestamp);
|
|
4080
|
+
break;
|
|
4081
|
+
case "arrowDown":
|
|
4082
|
+
executeKeyAction("ArrowDown", document, onEvent, getTimestamp);
|
|
4083
|
+
break;
|
|
4084
|
+
case "arrowLeft":
|
|
4085
|
+
executeKeyAction("ArrowLeft", document, onEvent, getTimestamp);
|
|
4086
|
+
break;
|
|
4087
|
+
case "arrowRight":
|
|
4088
|
+
executeKeyAction("ArrowRight", document, onEvent, getTimestamp);
|
|
4089
|
+
break;
|
|
4090
|
+
case "key":
|
|
4091
|
+
executeKeyCombo(action.combo, document, onEvent, getTimestamp);
|
|
4092
|
+
break;
|
|
4093
|
+
case "wait":
|
|
4094
|
+
await new Promise((resolve) => setTimeout(resolve, action.ms));
|
|
4095
|
+
break;
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
async function executeSequence(sequence, document, onEvent, getTimestamp, settleTime = 100) {
|
|
4099
|
+
for (let i = 0; i < sequence.actions.length; i++) {
|
|
4100
|
+
const action = sequence.actions[i];
|
|
4101
|
+
await executeAction(action, document, onEvent, getTimestamp);
|
|
4102
|
+
if (i < sequence.actions.length - 1) {
|
|
4103
|
+
await new Promise((resolve) => setTimeout(resolve, settleTime));
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
|
|
4108
|
+
// src/runtime/heuristics.ts
|
|
4109
|
+
var DEFAULT_CONFIG = {
|
|
4110
|
+
dialogFocusTimeout: 100,
|
|
4111
|
+
rapidAnnouncementWindow: 500,
|
|
4112
|
+
rapidAnnouncementThreshold: 3,
|
|
4113
|
+
keyboardResponseTimeout: 200
|
|
4114
|
+
};
|
|
4115
|
+
function createHeuristicAnalyzer(config) {
|
|
4116
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
4117
|
+
const trackedDialogs = [];
|
|
4118
|
+
const pendingDialogFocusChecks = [];
|
|
4119
|
+
const pendingKeyboardResponses = [];
|
|
4120
|
+
const announcementTimestamps = [];
|
|
4121
|
+
let lastFocusedSelector = null;
|
|
4122
|
+
function createWarning(timestamp, message, target, relatedEvent) {
|
|
4123
|
+
const payload = {
|
|
4124
|
+
kind: "warning",
|
|
4125
|
+
message,
|
|
4126
|
+
relatedEvent
|
|
4127
|
+
};
|
|
4128
|
+
return {
|
|
4129
|
+
type: "WARNING",
|
|
4130
|
+
timestamp,
|
|
4131
|
+
target,
|
|
4132
|
+
payload
|
|
4133
|
+
};
|
|
4134
|
+
}
|
|
4135
|
+
function checkExpiredDialogFocusTimeouts(currentTimestamp) {
|
|
4136
|
+
const warnings = [];
|
|
4137
|
+
for (let i = pendingDialogFocusChecks.length - 1; i >= 0; i--) {
|
|
4138
|
+
const pending = pendingDialogFocusChecks[i];
|
|
4139
|
+
if (pending.resolved) continue;
|
|
4140
|
+
const elapsed = currentTimestamp - pending.openedAt;
|
|
4141
|
+
if (elapsed > cfg.dialogFocusTimeout) {
|
|
4142
|
+
if (pending.isModal) {
|
|
4143
|
+
warnings.push(
|
|
4144
|
+
createWarning(
|
|
4145
|
+
currentTimestamp,
|
|
4146
|
+
"Focus was not moved into modal dialog",
|
|
4147
|
+
{
|
|
4148
|
+
role: "dialog",
|
|
4149
|
+
accessibleName: pending.dialogName,
|
|
4150
|
+
selector: pending.dialogSelector
|
|
4151
|
+
}
|
|
4152
|
+
)
|
|
4153
|
+
);
|
|
4154
|
+
}
|
|
4155
|
+
pending.resolved = true;
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
return warnings;
|
|
4159
|
+
}
|
|
4160
|
+
function checkExpiredKeyboardResponses(currentTimestamp) {
|
|
4161
|
+
const warnings = [];
|
|
4162
|
+
for (let i = pendingKeyboardResponses.length - 1; i >= 0; i--) {
|
|
4163
|
+
const pending = pendingKeyboardResponses[i];
|
|
4164
|
+
if (pending.resolved) continue;
|
|
4165
|
+
const elapsed = currentTimestamp - pending.timestamp;
|
|
4166
|
+
if (elapsed > cfg.keyboardResponseTimeout) {
|
|
4167
|
+
warnings.push(
|
|
4168
|
+
createWarning(
|
|
4169
|
+
currentTimestamp,
|
|
4170
|
+
"Keyboard action produced no accessibility response",
|
|
4171
|
+
pending.event.target,
|
|
4172
|
+
pending.event
|
|
4173
|
+
)
|
|
4174
|
+
);
|
|
4175
|
+
pending.resolved = true;
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
return warnings;
|
|
4179
|
+
}
|
|
4180
|
+
function checkRapidAnnouncements(currentTimestamp) {
|
|
4181
|
+
const warnings = [];
|
|
4182
|
+
const windowStart = currentTimestamp - cfg.rapidAnnouncementWindow;
|
|
4183
|
+
while (announcementTimestamps.length > 0 && announcementTimestamps[0] < windowStart) {
|
|
4184
|
+
announcementTimestamps.shift();
|
|
4185
|
+
}
|
|
4186
|
+
if (announcementTimestamps.length > cfg.rapidAnnouncementThreshold) {
|
|
4187
|
+
warnings.push(
|
|
4188
|
+
createWarning(
|
|
4189
|
+
currentTimestamp,
|
|
4190
|
+
"Rapid announcements detected: assistive technology users may miss content",
|
|
4191
|
+
{
|
|
4192
|
+
role: "region",
|
|
4193
|
+
accessibleName: "",
|
|
4194
|
+
selector: "body"
|
|
4195
|
+
}
|
|
4196
|
+
)
|
|
4197
|
+
);
|
|
4198
|
+
announcementTimestamps.length = 0;
|
|
4199
|
+
}
|
|
4200
|
+
return warnings;
|
|
4201
|
+
}
|
|
4202
|
+
function checkFocusEscape(event) {
|
|
4203
|
+
const warnings = [];
|
|
4204
|
+
if (event.type !== "FOCUS_CHANGED") return warnings;
|
|
4205
|
+
const modalDialogs = trackedDialogs.filter((d) => d.isModal);
|
|
4206
|
+
if (modalDialogs.length === 0) return warnings;
|
|
4207
|
+
const focusedSelector = event.target.selector;
|
|
4208
|
+
for (const dialog of modalDialogs) {
|
|
4209
|
+
if (!isSelectorInside(focusedSelector, dialog.selector)) {
|
|
4210
|
+
warnings.push(
|
|
4211
|
+
createWarning(
|
|
4212
|
+
event.timestamp,
|
|
4213
|
+
"Focus escaped modal dialog",
|
|
4214
|
+
event.target,
|
|
4215
|
+
event
|
|
4216
|
+
)
|
|
4217
|
+
);
|
|
4218
|
+
break;
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
return warnings;
|
|
4222
|
+
}
|
|
4223
|
+
function checkFocusedElementRemoved(event) {
|
|
4224
|
+
const warnings = [];
|
|
4225
|
+
if (event.type === "DOM_MUTATION" && lastFocusedSelector !== null) {
|
|
4226
|
+
if (event.target.selector === lastFocusedSelector) {
|
|
4227
|
+
warnings.push(
|
|
4228
|
+
createWarning(
|
|
4229
|
+
event.timestamp,
|
|
4230
|
+
"Focused element removed without focus management",
|
|
4231
|
+
event.target,
|
|
4232
|
+
event
|
|
4233
|
+
)
|
|
4234
|
+
);
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
return warnings;
|
|
4238
|
+
}
|
|
4239
|
+
function isSelectorInside(childSelector, containerSelector) {
|
|
4240
|
+
if (childSelector === containerSelector) return true;
|
|
4241
|
+
if (childSelector.startsWith(containerSelector + " ")) return true;
|
|
4242
|
+
if (childSelector.startsWith(containerSelector + " > ")) return true;
|
|
4243
|
+
if (childSelector.startsWith(containerSelector + ">")) return true;
|
|
4244
|
+
return false;
|
|
4245
|
+
}
|
|
4246
|
+
function processEvent(event) {
|
|
4247
|
+
const warnings = [];
|
|
4248
|
+
warnings.push(...checkExpiredDialogFocusTimeouts(event.timestamp));
|
|
4249
|
+
warnings.push(...checkExpiredKeyboardResponses(event.timestamp));
|
|
4250
|
+
switch (event.type) {
|
|
4251
|
+
case "DIALOG_OPENED": {
|
|
4252
|
+
const payload = event.payload;
|
|
4253
|
+
const dialog = {
|
|
4254
|
+
selector: event.target.selector,
|
|
4255
|
+
name: payload.dialogName,
|
|
4256
|
+
isModal: payload.isModal
|
|
4257
|
+
};
|
|
4258
|
+
trackedDialogs.push(dialog);
|
|
4259
|
+
if (payload.isModal) {
|
|
4260
|
+
pendingDialogFocusChecks.push({
|
|
4261
|
+
dialogSelector: event.target.selector,
|
|
4262
|
+
dialogName: payload.dialogName,
|
|
4263
|
+
openedAt: event.timestamp,
|
|
4264
|
+
isModal: true,
|
|
4265
|
+
resolved: false
|
|
4266
|
+
});
|
|
4267
|
+
}
|
|
4268
|
+
break;
|
|
4269
|
+
}
|
|
4270
|
+
case "DIALOG_CLOSED": {
|
|
4271
|
+
const closedSelector = event.target.selector;
|
|
4272
|
+
const idx = trackedDialogs.findIndex(
|
|
4273
|
+
(d) => d.selector === closedSelector
|
|
4274
|
+
);
|
|
4275
|
+
if (idx !== -1) {
|
|
4276
|
+
trackedDialogs.splice(idx, 1);
|
|
4277
|
+
}
|
|
4278
|
+
for (const pending of pendingDialogFocusChecks) {
|
|
4279
|
+
if (pending.dialogSelector === closedSelector && !pending.resolved) {
|
|
4280
|
+
pending.resolved = true;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
break;
|
|
4284
|
+
}
|
|
4285
|
+
case "FOCUS_CHANGED": {
|
|
4286
|
+
for (const pending of pendingDialogFocusChecks) {
|
|
4287
|
+
if (pending.resolved) continue;
|
|
4288
|
+
if (isSelectorInside(event.target.selector, pending.dialogSelector)) {
|
|
4289
|
+
pending.resolved = true;
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
for (const pending of pendingKeyboardResponses) {
|
|
4293
|
+
if (!pending.resolved) {
|
|
4294
|
+
pending.resolved = true;
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
warnings.push(...checkFocusEscape(event));
|
|
4298
|
+
lastFocusedSelector = event.target.selector;
|
|
4299
|
+
break;
|
|
4300
|
+
}
|
|
4301
|
+
case "ANNOUNCEMENT": {
|
|
4302
|
+
announcementTimestamps.push(event.timestamp);
|
|
4303
|
+
for (const pending of pendingKeyboardResponses) {
|
|
4304
|
+
if (!pending.resolved) {
|
|
4305
|
+
pending.resolved = true;
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
warnings.push(...checkRapidAnnouncements(event.timestamp));
|
|
4309
|
+
break;
|
|
4310
|
+
}
|
|
4311
|
+
case "KEYBOARD_ACTION": {
|
|
4312
|
+
pendingKeyboardResponses.push({
|
|
4313
|
+
event,
|
|
4314
|
+
timestamp: event.timestamp,
|
|
4315
|
+
resolved: false
|
|
4316
|
+
});
|
|
4317
|
+
break;
|
|
4318
|
+
}
|
|
4319
|
+
case "DOM_MUTATION": {
|
|
4320
|
+
warnings.push(...checkFocusedElementRemoved(event));
|
|
4321
|
+
for (const pending of pendingKeyboardResponses) {
|
|
4322
|
+
if (!pending.resolved) {
|
|
4323
|
+
pending.resolved = true;
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
break;
|
|
4327
|
+
}
|
|
4328
|
+
case "STATE_CHANGED":
|
|
4329
|
+
case "ROLE_CHANGED":
|
|
4330
|
+
case "ACCESSIBLE_NAME_CHANGED": {
|
|
4331
|
+
for (const pending of pendingKeyboardResponses) {
|
|
4332
|
+
if (!pending.resolved) {
|
|
4333
|
+
pending.resolved = true;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
break;
|
|
4337
|
+
}
|
|
4338
|
+
default:
|
|
4339
|
+
break;
|
|
4340
|
+
}
|
|
4341
|
+
cleanupResolvedChecks();
|
|
4342
|
+
return warnings;
|
|
4343
|
+
}
|
|
4344
|
+
function cleanupResolvedChecks() {
|
|
4345
|
+
for (let i = pendingDialogFocusChecks.length - 1; i >= 0; i--) {
|
|
4346
|
+
if (pendingDialogFocusChecks[i].resolved) {
|
|
4347
|
+
pendingDialogFocusChecks.splice(i, 1);
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
for (let i = pendingKeyboardResponses.length - 1; i >= 0; i--) {
|
|
4351
|
+
if (pendingKeyboardResponses[i].resolved) {
|
|
4352
|
+
pendingKeyboardResponses.splice(i, 1);
|
|
4353
|
+
}
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
return {
|
|
4357
|
+
process(event) {
|
|
4358
|
+
return processEvent(event);
|
|
4359
|
+
},
|
|
4360
|
+
get openDialogs() {
|
|
4361
|
+
return trackedDialogs.map((d) => d.selector);
|
|
4362
|
+
}
|
|
4363
|
+
};
|
|
4364
|
+
}
|
|
4365
|
+
|
|
4366
|
+
// src/runtime/timeline-generator.ts
|
|
4367
|
+
var SPEAKABLE_VERSION = "1.3.0";
|
|
4368
|
+
var TIMELINE_FORMAT_VERSION = "1.0";
|
|
4369
|
+
var DEFAULT_SETTLE_PERIOD = 500;
|
|
4370
|
+
var DEFAULT_LOAD_TIMEOUT = 1e4;
|
|
4371
|
+
var DOM_STABILITY_WAIT = 100;
|
|
4372
|
+
function createTimelineGenerator(options) {
|
|
4373
|
+
const {
|
|
4374
|
+
document: doc,
|
|
4375
|
+
componentName,
|
|
4376
|
+
storyName,
|
|
4377
|
+
settlePeriod = DEFAULT_SETTLE_PERIOD,
|
|
4378
|
+
loadTimeout = DEFAULT_LOAD_TIMEOUT,
|
|
4379
|
+
heuristics: enableHeuristics = true
|
|
4380
|
+
} = options;
|
|
4381
|
+
let aborted = false;
|
|
4382
|
+
let currentEngine = null;
|
|
4383
|
+
return {
|
|
4384
|
+
async capture(sequence) {
|
|
4385
|
+
aborted = false;
|
|
4386
|
+
await waitForDocumentReady(doc, loadTimeout);
|
|
4387
|
+
if (aborted) {
|
|
4388
|
+
return buildAbortedTimeline(componentName, storyName, sequence);
|
|
4389
|
+
}
|
|
4390
|
+
const engine = createEngine({ document: doc });
|
|
4391
|
+
currentEngine = engine;
|
|
4392
|
+
const heuristicAnalyzer = enableHeuristics ? createHeuristicAnalyzer() : null;
|
|
4393
|
+
const interactionEvents = [];
|
|
4394
|
+
const sessionStart = Date.now();
|
|
4395
|
+
engine.attach();
|
|
4396
|
+
if (aborted) {
|
|
4397
|
+
engine.detach();
|
|
4398
|
+
currentEngine = null;
|
|
4399
|
+
return buildAbortedTimeline(componentName, storyName, sequence);
|
|
4400
|
+
}
|
|
4401
|
+
function getTimestamp() {
|
|
4402
|
+
return Date.now() - sessionStart;
|
|
4403
|
+
}
|
|
4404
|
+
await executeSequence(
|
|
4405
|
+
sequence,
|
|
4406
|
+
doc,
|
|
4407
|
+
(event) => {
|
|
4408
|
+
interactionEvents.push(event);
|
|
4409
|
+
},
|
|
4410
|
+
getTimestamp,
|
|
4411
|
+
DOM_STABILITY_WAIT
|
|
4412
|
+
);
|
|
4413
|
+
if (aborted) {
|
|
4414
|
+
engine.detach();
|
|
4415
|
+
currentEngine = null;
|
|
4416
|
+
return buildAbortedTimeline(componentName, storyName, sequence);
|
|
4417
|
+
}
|
|
4418
|
+
await delay(settlePeriod);
|
|
4419
|
+
engine.detach();
|
|
4420
|
+
currentEngine = null;
|
|
4421
|
+
const duration = Date.now() - sessionStart;
|
|
4422
|
+
const engineEvents = engine.getEvents();
|
|
4423
|
+
const allEvents = mergeEvents(engineEvents, interactionEvents);
|
|
4424
|
+
if (heuristicAnalyzer) {
|
|
4425
|
+
const heuristicWarnings = [];
|
|
4426
|
+
for (const event of allEvents) {
|
|
4427
|
+
const warnings = heuristicAnalyzer.process(event);
|
|
4428
|
+
heuristicWarnings.push(...warnings);
|
|
4429
|
+
}
|
|
4430
|
+
for (const warning of heuristicWarnings) {
|
|
4431
|
+
allEvents.push(warning);
|
|
4432
|
+
}
|
|
4433
|
+
allEvents.sort((a, b) => a.timestamp - b.timestamp);
|
|
4434
|
+
}
|
|
4435
|
+
const allWarnings = allEvents.filter((e) => e.type === "WARNING");
|
|
4436
|
+
const metadata = {
|
|
4437
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4438
|
+
speakableVersion: SPEAKABLE_VERSION,
|
|
4439
|
+
sourceUrl: getSourceUrl(doc),
|
|
4440
|
+
userAgent: getUserAgent()
|
|
4441
|
+
};
|
|
4442
|
+
const timeline = {
|
|
4443
|
+
version: TIMELINE_FORMAT_VERSION,
|
|
4444
|
+
component: componentName,
|
|
4445
|
+
story: storyName || null,
|
|
4446
|
+
interactionSequence: sequence.description,
|
|
4447
|
+
duration,
|
|
4448
|
+
events: allEvents,
|
|
4449
|
+
warnings: allWarnings,
|
|
4450
|
+
metadata
|
|
4451
|
+
};
|
|
4452
|
+
return timeline;
|
|
4453
|
+
},
|
|
4454
|
+
abort() {
|
|
4455
|
+
aborted = true;
|
|
4456
|
+
if (currentEngine && currentEngine.isAttached) {
|
|
4457
|
+
currentEngine.detach();
|
|
4458
|
+
currentEngine = null;
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
};
|
|
4462
|
+
}
|
|
4463
|
+
async function waitForDocumentReady(doc, timeout) {
|
|
4464
|
+
if (doc.body) return;
|
|
4465
|
+
return new Promise((resolve, reject) => {
|
|
4466
|
+
const timeoutId = setTimeout(() => {
|
|
4467
|
+
reject(
|
|
4468
|
+
new Error(
|
|
4469
|
+
`Document load timeout (${timeout}ms): ${getSourceUrl(doc)}`
|
|
4470
|
+
)
|
|
4471
|
+
);
|
|
4472
|
+
}, timeout);
|
|
4473
|
+
const interval = setInterval(() => {
|
|
4474
|
+
if (doc.body) {
|
|
4475
|
+
clearTimeout(timeoutId);
|
|
4476
|
+
clearInterval(interval);
|
|
4477
|
+
resolve();
|
|
4478
|
+
}
|
|
4479
|
+
}, 50);
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4482
|
+
function mergeEvents(engineEvents, interactionEvents) {
|
|
4483
|
+
const all = [...engineEvents, ...interactionEvents];
|
|
4484
|
+
all.sort((a, b) => a.timestamp - b.timestamp);
|
|
4485
|
+
return all;
|
|
4486
|
+
}
|
|
4487
|
+
function getSourceUrl(doc) {
|
|
4488
|
+
try {
|
|
4489
|
+
const url = doc.URL;
|
|
4490
|
+
if (url && url !== "about:blank" && url !== "") {
|
|
4491
|
+
return url;
|
|
4492
|
+
}
|
|
4493
|
+
} catch {
|
|
4494
|
+
}
|
|
4495
|
+
return "local";
|
|
4496
|
+
}
|
|
4497
|
+
function getUserAgent() {
|
|
4498
|
+
try {
|
|
4499
|
+
if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
4500
|
+
return navigator.userAgent;
|
|
4501
|
+
}
|
|
4502
|
+
} catch {
|
|
4503
|
+
}
|
|
4504
|
+
return "jsdom";
|
|
4505
|
+
}
|
|
4506
|
+
function delay(ms) {
|
|
4507
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4508
|
+
}
|
|
4509
|
+
function buildAbortedTimeline(componentName, storyName, sequence) {
|
|
4510
|
+
return {
|
|
4511
|
+
version: TIMELINE_FORMAT_VERSION,
|
|
4512
|
+
component: componentName,
|
|
4513
|
+
story: storyName || null,
|
|
4514
|
+
interactionSequence: sequence.description,
|
|
4515
|
+
duration: 0,
|
|
4516
|
+
events: [],
|
|
4517
|
+
warnings: [],
|
|
4518
|
+
metadata: {
|
|
4519
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4520
|
+
speakableVersion: SPEAKABLE_VERSION,
|
|
4521
|
+
sourceUrl: "local",
|
|
4522
|
+
userAgent: getUserAgent()
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
// src/runtime/patterns.ts
|
|
4528
|
+
var MODAL_DIALOG_DEFAULTS = {
|
|
4529
|
+
trigger: "button",
|
|
4530
|
+
container: '[role="dialog"], dialog'
|
|
4531
|
+
};
|
|
4532
|
+
var COMBOBOX_DEFAULTS = {
|
|
4533
|
+
input: '[role="combobox"], input[type="text"]',
|
|
4534
|
+
items: '[role="option"]'
|
|
4535
|
+
};
|
|
4536
|
+
var TABS_DEFAULTS = {
|
|
4537
|
+
container: '[role="tablist"]',
|
|
4538
|
+
items: '[role="tab"]'
|
|
4539
|
+
};
|
|
4540
|
+
var ACCORDION_DEFAULTS = {
|
|
4541
|
+
trigger: "button[aria-expanded]"
|
|
4542
|
+
};
|
|
4543
|
+
function buildModalDialogPattern(selectors) {
|
|
4544
|
+
const trigger = selectors?.trigger ?? MODAL_DIALOG_DEFAULTS.trigger;
|
|
4545
|
+
const actions = [
|
|
4546
|
+
{ type: "click", selector: trigger },
|
|
4547
|
+
{ type: "tab" },
|
|
4548
|
+
{ type: "tab" },
|
|
4549
|
+
{ type: "tab" },
|
|
4550
|
+
{ type: "escape" }
|
|
4551
|
+
];
|
|
4552
|
+
return {
|
|
4553
|
+
description: "Modal dialog: click trigger to open, tab through dialog content, press Escape to close, verify focus returns to trigger",
|
|
4554
|
+
actions
|
|
4555
|
+
};
|
|
4556
|
+
}
|
|
4557
|
+
function buildComboboxPattern(selectors) {
|
|
4558
|
+
const input = selectors?.input ?? COMBOBOX_DEFAULTS.input;
|
|
4559
|
+
const actions = [
|
|
4560
|
+
{ type: "click", selector: input },
|
|
4561
|
+
{ type: "key", combo: "a" },
|
|
4562
|
+
{ type: "arrowDown" },
|
|
4563
|
+
{ type: "arrowDown" },
|
|
4564
|
+
{ type: "enter" }
|
|
4565
|
+
];
|
|
4566
|
+
return {
|
|
4567
|
+
description: "Combobox: focus input, type to filter, navigate options with arrow keys, select with Enter",
|
|
4568
|
+
actions
|
|
4569
|
+
};
|
|
4570
|
+
}
|
|
4571
|
+
function buildTabsPattern(selectors) {
|
|
4572
|
+
const container = selectors?.container ?? TABS_DEFAULTS.container;
|
|
4573
|
+
const actions = [
|
|
4574
|
+
{ type: "click", selector: container },
|
|
4575
|
+
{ type: "arrowRight" },
|
|
4576
|
+
{ type: "arrowRight" },
|
|
4577
|
+
{ type: "enter" },
|
|
4578
|
+
{ type: "arrowLeft" },
|
|
4579
|
+
{ type: "space" }
|
|
4580
|
+
];
|
|
4581
|
+
return {
|
|
4582
|
+
description: "Tabs: focus tablist, navigate between tabs with arrow keys, activate with Enter/Space",
|
|
4583
|
+
actions
|
|
4584
|
+
};
|
|
4585
|
+
}
|
|
4586
|
+
function buildAccordionPattern(selectors) {
|
|
4587
|
+
const trigger = selectors?.trigger ?? ACCORDION_DEFAULTS.trigger;
|
|
4588
|
+
const actions = [
|
|
4589
|
+
{ type: "click", selector: trigger },
|
|
4590
|
+
{ type: "enter" },
|
|
4591
|
+
{ type: "arrowDown" },
|
|
4592
|
+
{ type: "space" },
|
|
4593
|
+
{ type: "arrowDown" },
|
|
4594
|
+
{ type: "enter" }
|
|
4595
|
+
];
|
|
4596
|
+
return {
|
|
4597
|
+
description: "Accordion: focus header, toggle with Enter/Space, navigate between headers with arrow keys",
|
|
4598
|
+
actions
|
|
4599
|
+
};
|
|
4600
|
+
}
|
|
4601
|
+
function getBuiltinPattern(name, selectors) {
|
|
4602
|
+
switch (name) {
|
|
4603
|
+
case "modal-dialog":
|
|
4604
|
+
return buildModalDialogPattern(selectors);
|
|
4605
|
+
case "combobox":
|
|
4606
|
+
return buildComboboxPattern(selectors);
|
|
4607
|
+
case "tabs":
|
|
4608
|
+
return buildTabsPattern(selectors);
|
|
4609
|
+
case "accordion":
|
|
4610
|
+
return buildAccordionPattern(selectors);
|
|
4611
|
+
}
|
|
4612
|
+
}
|
|
4613
|
+
|
|
4614
|
+
// src/runtime/serialization.ts
|
|
4615
|
+
var VALID_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
4616
|
+
"FOCUS_CHANGED",
|
|
4617
|
+
"ANNOUNCEMENT",
|
|
4618
|
+
"DOM_MUTATION",
|
|
4619
|
+
"ROLE_CHANGED",
|
|
4620
|
+
"ACCESSIBLE_NAME_CHANGED",
|
|
4621
|
+
"STATE_CHANGED",
|
|
4622
|
+
"KEYBOARD_ACTION",
|
|
4623
|
+
"DIALOG_OPENED",
|
|
4624
|
+
"DIALOG_CLOSED",
|
|
4625
|
+
"WARNING",
|
|
4626
|
+
"REGRESSION"
|
|
4627
|
+
]);
|
|
4628
|
+
var VALID_PAYLOAD_KINDS = /* @__PURE__ */ new Set([
|
|
4629
|
+
"focus_changed",
|
|
4630
|
+
"announcement",
|
|
4631
|
+
"role_changed",
|
|
4632
|
+
"accessible_name_changed",
|
|
4633
|
+
"state_changed",
|
|
4634
|
+
"dialog_opened",
|
|
4635
|
+
"dialog_closed",
|
|
4636
|
+
"keyboard_action",
|
|
4637
|
+
"warning"
|
|
4638
|
+
]);
|
|
4639
|
+
var VALID_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
4640
|
+
"click",
|
|
4641
|
+
"tab",
|
|
4642
|
+
"shiftTab",
|
|
4643
|
+
"escape",
|
|
4644
|
+
"enter",
|
|
4645
|
+
"space",
|
|
4646
|
+
"arrowUp",
|
|
4647
|
+
"arrowDown",
|
|
4648
|
+
"arrowLeft",
|
|
4649
|
+
"arrowRight",
|
|
4650
|
+
"key",
|
|
4651
|
+
"wait"
|
|
4652
|
+
]);
|
|
4653
|
+
function sortKeysDeep(value) {
|
|
4654
|
+
if (value === null || value === void 0) {
|
|
4655
|
+
return value;
|
|
4656
|
+
}
|
|
4657
|
+
if (Array.isArray(value)) {
|
|
4658
|
+
return value.map(sortKeysDeep);
|
|
4659
|
+
}
|
|
4660
|
+
if (typeof value === "object") {
|
|
4661
|
+
const sorted = {};
|
|
4662
|
+
const keys = Object.keys(value).sort();
|
|
4663
|
+
for (const key of keys) {
|
|
4664
|
+
sorted[key] = sortKeysDeep(value[key]);
|
|
4665
|
+
}
|
|
4666
|
+
return sorted;
|
|
4667
|
+
}
|
|
4668
|
+
return value;
|
|
4669
|
+
}
|
|
4670
|
+
function serializeEvent(event) {
|
|
4671
|
+
const sorted = sortKeysDeep(event);
|
|
4672
|
+
return JSON.stringify(sorted, null, 2);
|
|
4673
|
+
}
|
|
4674
|
+
function deserializeEvent(json) {
|
|
4675
|
+
const parsed = JSON.parse(json);
|
|
4676
|
+
validateEvent(parsed);
|
|
4677
|
+
return parsed;
|
|
4678
|
+
}
|
|
4679
|
+
function serializeTimeline(timeline) {
|
|
4680
|
+
const sorted = sortKeysDeep(timeline);
|
|
4681
|
+
return JSON.stringify(sorted, null, 2);
|
|
4682
|
+
}
|
|
4683
|
+
function deserializeTimeline(json) {
|
|
4684
|
+
const parsed = JSON.parse(json);
|
|
4685
|
+
validateTimeline(parsed);
|
|
4686
|
+
return parsed;
|
|
4687
|
+
}
|
|
4688
|
+
function serializeInteractionSequence(seq) {
|
|
4689
|
+
const sorted = sortKeysDeep(seq);
|
|
4690
|
+
return JSON.stringify(sorted, null, 2);
|
|
4691
|
+
}
|
|
4692
|
+
function deserializeInteractionSequence(json) {
|
|
4693
|
+
const parsed = JSON.parse(json);
|
|
4694
|
+
validateInteractionSequence(parsed);
|
|
4695
|
+
return parsed;
|
|
4696
|
+
}
|
|
4697
|
+
function timelinesEqual(a, b) {
|
|
4698
|
+
return serializeTimeline(a) === serializeTimeline(b);
|
|
4699
|
+
}
|
|
4700
|
+
function validateEvent(obj) {
|
|
4701
|
+
if (obj === null || typeof obj !== "object") {
|
|
4702
|
+
throw new Error("Event must be a non-null object");
|
|
4703
|
+
}
|
|
4704
|
+
const event = obj;
|
|
4705
|
+
if (typeof event.type !== "string" || !VALID_EVENT_TYPES.has(event.type)) {
|
|
4706
|
+
throw new Error(
|
|
4707
|
+
`Event "type" must be one of: ${[...VALID_EVENT_TYPES].join(", ")}. Got: ${String(event.type)}`
|
|
4708
|
+
);
|
|
4709
|
+
}
|
|
4710
|
+
if (typeof event.timestamp !== "number" || !Number.isFinite(event.timestamp)) {
|
|
4711
|
+
throw new Error('Event "timestamp" must be a finite number');
|
|
4712
|
+
}
|
|
4713
|
+
validateEventTarget(event.target, 'Event "target"');
|
|
4714
|
+
validatePayload(event.payload);
|
|
4715
|
+
}
|
|
4716
|
+
function validateEventTarget(obj, label) {
|
|
4717
|
+
if (obj === null || typeof obj !== "object") {
|
|
4718
|
+
throw new Error(`${label} must be a non-null object`);
|
|
4719
|
+
}
|
|
4720
|
+
const target = obj;
|
|
4721
|
+
if (typeof target.role !== "string") {
|
|
4722
|
+
throw new Error(`${label}.role must be a string`);
|
|
4723
|
+
}
|
|
4724
|
+
if (typeof target.accessibleName !== "string") {
|
|
4725
|
+
throw new Error(`${label}.accessibleName must be a string`);
|
|
4726
|
+
}
|
|
4727
|
+
if (typeof target.selector !== "string") {
|
|
4728
|
+
throw new Error(`${label}.selector must be a string`);
|
|
4729
|
+
}
|
|
4730
|
+
}
|
|
4731
|
+
function validatePayload(obj) {
|
|
4732
|
+
if (obj === null || typeof obj !== "object") {
|
|
4733
|
+
throw new Error('Event "payload" must be a non-null object');
|
|
4734
|
+
}
|
|
4735
|
+
const payload = obj;
|
|
4736
|
+
if (typeof payload.kind !== "string" || !VALID_PAYLOAD_KINDS.has(payload.kind)) {
|
|
4737
|
+
throw new Error(
|
|
4738
|
+
`Payload "kind" must be one of: ${[...VALID_PAYLOAD_KINDS].join(", ")}. Got: ${String(payload.kind)}`
|
|
4739
|
+
);
|
|
4740
|
+
}
|
|
4741
|
+
switch (payload.kind) {
|
|
4742
|
+
case "focus_changed":
|
|
4743
|
+
if (payload.previousTarget !== null) {
|
|
4744
|
+
validateEventTarget(payload.previousTarget, "FocusChangedPayload.previousTarget");
|
|
4745
|
+
}
|
|
4746
|
+
break;
|
|
4747
|
+
case "announcement":
|
|
4748
|
+
if (payload.politeness !== "polite" && payload.politeness !== "assertive") {
|
|
4749
|
+
throw new Error('AnnouncementPayload.politeness must be "polite" or "assertive"');
|
|
4750
|
+
}
|
|
4751
|
+
if (typeof payload.text !== "string") {
|
|
4752
|
+
throw new Error("AnnouncementPayload.text must be a string");
|
|
4753
|
+
}
|
|
4754
|
+
break;
|
|
4755
|
+
case "role_changed":
|
|
4756
|
+
if (typeof payload.previousRole !== "string") {
|
|
4757
|
+
throw new Error("RoleChangedPayload.previousRole must be a string");
|
|
4758
|
+
}
|
|
4759
|
+
if (typeof payload.newRole !== "string") {
|
|
4760
|
+
throw new Error("RoleChangedPayload.newRole must be a string");
|
|
4761
|
+
}
|
|
4762
|
+
break;
|
|
4763
|
+
case "accessible_name_changed":
|
|
4764
|
+
if (typeof payload.previousName !== "string") {
|
|
4765
|
+
throw new Error("AccessibleNameChangedPayload.previousName must be a string");
|
|
4766
|
+
}
|
|
4767
|
+
if (typeof payload.newName !== "string") {
|
|
4768
|
+
throw new Error("AccessibleNameChangedPayload.newName must be a string");
|
|
4769
|
+
}
|
|
4770
|
+
break;
|
|
4771
|
+
case "state_changed":
|
|
4772
|
+
if (typeof payload.attribute !== "string") {
|
|
4773
|
+
throw new Error("StateChangedPayload.attribute must be a string");
|
|
4774
|
+
}
|
|
4775
|
+
validateStateValue(payload.previousValue, "StateChangedPayload.previousValue");
|
|
4776
|
+
validateStateValue(payload.newValue, "StateChangedPayload.newValue");
|
|
4777
|
+
break;
|
|
4778
|
+
case "dialog_opened":
|
|
4779
|
+
if (typeof payload.dialogName !== "string") {
|
|
4780
|
+
throw new Error("DialogOpenedPayload.dialogName must be a string");
|
|
4781
|
+
}
|
|
4782
|
+
if (typeof payload.isModal !== "boolean") {
|
|
4783
|
+
throw new Error("DialogOpenedPayload.isModal must be a boolean");
|
|
4784
|
+
}
|
|
4785
|
+
break;
|
|
4786
|
+
case "dialog_closed":
|
|
4787
|
+
if (typeof payload.dialogName !== "string") {
|
|
4788
|
+
throw new Error("DialogClosedPayload.dialogName must be a string");
|
|
4789
|
+
}
|
|
4790
|
+
break;
|
|
4791
|
+
case "keyboard_action":
|
|
4792
|
+
if (typeof payload.key !== "string") {
|
|
4793
|
+
throw new Error("KeyboardActionPayload.key must be a string");
|
|
4794
|
+
}
|
|
4795
|
+
if (!Array.isArray(payload.modifiers)) {
|
|
4796
|
+
throw new Error("KeyboardActionPayload.modifiers must be an array");
|
|
4797
|
+
}
|
|
4798
|
+
for (const mod of payload.modifiers) {
|
|
4799
|
+
if (typeof mod !== "string") {
|
|
4800
|
+
throw new Error("KeyboardActionPayload.modifiers must contain only strings");
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
break;
|
|
4804
|
+
case "warning":
|
|
4805
|
+
if (typeof payload.message !== "string") {
|
|
4806
|
+
throw new Error("WarningPayload.message must be a string");
|
|
4807
|
+
}
|
|
4808
|
+
if (payload.relatedEvent !== void 0 && payload.relatedEvent !== null) {
|
|
4809
|
+
validateEvent(payload.relatedEvent);
|
|
4810
|
+
}
|
|
4811
|
+
break;
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4814
|
+
function validateStateValue(value, label) {
|
|
4815
|
+
if (value !== null && typeof value !== "string" && typeof value !== "boolean") {
|
|
4816
|
+
throw new Error(`${label} must be a string, boolean, or null`);
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
function validateTimeline(obj) {
|
|
4820
|
+
if (obj === null || typeof obj !== "object") {
|
|
4821
|
+
throw new Error("Timeline must be a non-null object");
|
|
4822
|
+
}
|
|
4823
|
+
const timeline = obj;
|
|
4824
|
+
if (typeof timeline.version !== "string") {
|
|
4825
|
+
throw new Error('Timeline "version" must be a string');
|
|
4826
|
+
}
|
|
4827
|
+
if (typeof timeline.component !== "string") {
|
|
4828
|
+
throw new Error('Timeline "component" must be a string');
|
|
4829
|
+
}
|
|
4830
|
+
if (timeline.story !== null && typeof timeline.story !== "string") {
|
|
4831
|
+
throw new Error('Timeline "story" must be a string or null');
|
|
4832
|
+
}
|
|
4833
|
+
if (typeof timeline.interactionSequence !== "string") {
|
|
4834
|
+
throw new Error('Timeline "interactionSequence" must be a string');
|
|
4835
|
+
}
|
|
4836
|
+
if (typeof timeline.duration !== "number" || !Number.isFinite(timeline.duration)) {
|
|
4837
|
+
throw new Error('Timeline "duration" must be a finite number');
|
|
4838
|
+
}
|
|
4839
|
+
if (!Array.isArray(timeline.events)) {
|
|
4840
|
+
throw new Error('Timeline "events" must be an array');
|
|
4841
|
+
}
|
|
4842
|
+
for (let i = 0; i < timeline.events.length; i++) {
|
|
4843
|
+
try {
|
|
4844
|
+
validateEvent(timeline.events[i]);
|
|
4845
|
+
} catch (err) {
|
|
4846
|
+
throw new Error(
|
|
4847
|
+
`Timeline events[${i}]: ${err instanceof Error ? err.message : String(err)}`
|
|
4848
|
+
);
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
if (!Array.isArray(timeline.warnings)) {
|
|
4852
|
+
throw new Error('Timeline "warnings" must be an array');
|
|
4853
|
+
}
|
|
4854
|
+
for (let i = 0; i < timeline.warnings.length; i++) {
|
|
4855
|
+
try {
|
|
4856
|
+
validateEvent(timeline.warnings[i]);
|
|
4857
|
+
} catch (err) {
|
|
4858
|
+
throw new Error(
|
|
4859
|
+
`Timeline warnings[${i}]: ${err instanceof Error ? err.message : String(err)}`
|
|
4860
|
+
);
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
validateTimelineMetadata(timeline.metadata);
|
|
4864
|
+
}
|
|
4865
|
+
function validateTimelineMetadata(obj) {
|
|
4866
|
+
if (obj === null || typeof obj !== "object") {
|
|
4867
|
+
throw new Error('Timeline "metadata" must be a non-null object');
|
|
4868
|
+
}
|
|
4869
|
+
const meta = obj;
|
|
4870
|
+
if (typeof meta.capturedAt !== "string") {
|
|
4871
|
+
throw new Error("Timeline metadata.capturedAt must be a string");
|
|
4872
|
+
}
|
|
4873
|
+
if (typeof meta.speakableVersion !== "string") {
|
|
4874
|
+
throw new Error("Timeline metadata.speakableVersion must be a string");
|
|
4875
|
+
}
|
|
4876
|
+
if (typeof meta.sourceUrl !== "string") {
|
|
4877
|
+
throw new Error("Timeline metadata.sourceUrl must be a string");
|
|
4878
|
+
}
|
|
4879
|
+
if (typeof meta.userAgent !== "string") {
|
|
4880
|
+
throw new Error("Timeline metadata.userAgent must be a string");
|
|
4881
|
+
}
|
|
4882
|
+
}
|
|
4883
|
+
function validateInteractionSequence(obj) {
|
|
4884
|
+
if (obj === null || typeof obj !== "object") {
|
|
4885
|
+
throw new Error("InteractionSequence must be a non-null object");
|
|
4886
|
+
}
|
|
4887
|
+
const seq = obj;
|
|
4888
|
+
if (typeof seq.description !== "string") {
|
|
4889
|
+
throw new Error('InteractionSequence "description" must be a string');
|
|
4890
|
+
}
|
|
4891
|
+
if (!Array.isArray(seq.actions)) {
|
|
4892
|
+
throw new Error('InteractionSequence "actions" must be an array');
|
|
4893
|
+
}
|
|
4894
|
+
for (let i = 0; i < seq.actions.length; i++) {
|
|
4895
|
+
validateAction(seq.actions[i], i);
|
|
4896
|
+
}
|
|
4897
|
+
}
|
|
4898
|
+
function validateAction(obj, index) {
|
|
4899
|
+
if (obj === null || typeof obj !== "object") {
|
|
4900
|
+
throw new Error(`InteractionSequence actions[${index}] must be a non-null object`);
|
|
4901
|
+
}
|
|
4902
|
+
const action = obj;
|
|
4903
|
+
if (typeof action.type !== "string" || !VALID_ACTION_TYPES.has(action.type)) {
|
|
4904
|
+
throw new Error(
|
|
4905
|
+
`InteractionSequence actions[${index}].type must be one of: ${[...VALID_ACTION_TYPES].join(", ")}. Got: ${String(action.type)}`
|
|
4906
|
+
);
|
|
4907
|
+
}
|
|
4908
|
+
switch (action.type) {
|
|
4909
|
+
case "click":
|
|
4910
|
+
if (typeof action.selector !== "string") {
|
|
4911
|
+
throw new Error(
|
|
4912
|
+
`InteractionSequence actions[${index}].selector must be a string for click actions`
|
|
4913
|
+
);
|
|
4914
|
+
}
|
|
4915
|
+
break;
|
|
4916
|
+
case "key":
|
|
4917
|
+
if (typeof action.combo !== "string") {
|
|
4918
|
+
throw new Error(
|
|
4919
|
+
`InteractionSequence actions[${index}].combo must be a string for key actions`
|
|
4920
|
+
);
|
|
4921
|
+
}
|
|
4922
|
+
break;
|
|
4923
|
+
case "wait":
|
|
4924
|
+
if (typeof action.ms !== "number" || !Number.isFinite(action.ms)) {
|
|
4925
|
+
throw new Error(
|
|
4926
|
+
`InteractionSequence actions[${index}].ms must be a finite number for wait actions`
|
|
4927
|
+
);
|
|
4928
|
+
}
|
|
4929
|
+
break;
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
|
|
4933
|
+
// src/runtime/diff-engine.ts
|
|
4934
|
+
function matchingKey(event) {
|
|
4935
|
+
return `${event.type}::${event.target.selector}`;
|
|
4936
|
+
}
|
|
4937
|
+
function payloadsEqual(a, b) {
|
|
4938
|
+
if (a.type !== b.type) return false;
|
|
4939
|
+
if (!targetsEqual(a.target, b.target)) return false;
|
|
4940
|
+
return deepEqual(a.payload, b.payload);
|
|
4941
|
+
}
|
|
4942
|
+
function targetsEqual(a, b) {
|
|
4943
|
+
return a.role === b.role && a.accessibleName === b.accessibleName && a.selector === b.selector;
|
|
4944
|
+
}
|
|
4945
|
+
function deepEqual(a, b) {
|
|
4946
|
+
if (a === b) return true;
|
|
4947
|
+
if (a === null || b === null) return a === b;
|
|
4948
|
+
if (typeof a !== typeof b) return false;
|
|
4949
|
+
if (typeof a !== "object") return a === b;
|
|
4950
|
+
const aObj = a;
|
|
4951
|
+
const bObj = b;
|
|
4952
|
+
const aKeys = Object.keys(aObj).sort();
|
|
4953
|
+
const bKeys = Object.keys(bObj).sort();
|
|
4954
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
4955
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
4956
|
+
if (aKeys[i] !== bKeys[i]) return false;
|
|
4957
|
+
if (!deepEqual(aObj[aKeys[i]], bObj[bKeys[i]])) return false;
|
|
4958
|
+
}
|
|
4959
|
+
return true;
|
|
4960
|
+
}
|
|
4961
|
+
function buildModifiedMessage(baseline, current) {
|
|
4962
|
+
const type = current.type;
|
|
4963
|
+
const selector = current.target.selector;
|
|
4964
|
+
if (baseline.target.accessibleName !== current.target.accessibleName) {
|
|
4965
|
+
return `${type} on "${selector}": accessible name changed from "${baseline.target.accessibleName}" to "${current.target.accessibleName}"`;
|
|
4966
|
+
}
|
|
4967
|
+
if (baseline.target.role !== current.target.role) {
|
|
4968
|
+
return `${type} on "${selector}": role changed from "${baseline.target.role}" to "${current.target.role}"`;
|
|
4969
|
+
}
|
|
4970
|
+
return `${type} on "${selector}": payload values differ`;
|
|
4971
|
+
}
|
|
4972
|
+
function diffTimelines(baseline, current) {
|
|
4973
|
+
const added = [];
|
|
4974
|
+
const removed = [];
|
|
4975
|
+
const modified = [];
|
|
4976
|
+
const currentByKey = /* @__PURE__ */ new Map();
|
|
4977
|
+
for (const event of current.events) {
|
|
4978
|
+
const key = matchingKey(event);
|
|
4979
|
+
const existing = currentByKey.get(key);
|
|
4980
|
+
if (existing) {
|
|
4981
|
+
existing.push(event);
|
|
4982
|
+
} else {
|
|
4983
|
+
currentByKey.set(key, [event]);
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
const matchedCurrentIndices = /* @__PURE__ */ new Set();
|
|
4987
|
+
for (const baselineEvent of baseline.events) {
|
|
4988
|
+
const key = matchingKey(baselineEvent);
|
|
4989
|
+
const candidates = currentByKey.get(key);
|
|
4990
|
+
if (!candidates || candidates.length === 0) {
|
|
4991
|
+
removed.push({
|
|
4992
|
+
event: baselineEvent,
|
|
4993
|
+
message: `${baselineEvent.type} on "${baselineEvent.target.selector}" was removed`
|
|
4994
|
+
});
|
|
4995
|
+
continue;
|
|
4996
|
+
}
|
|
4997
|
+
let matched = false;
|
|
4998
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
4999
|
+
const candidateId = `${key}::${i}`;
|
|
5000
|
+
if (matchedCurrentIndices.has(candidateId)) continue;
|
|
5001
|
+
const currentEvent = candidates[i];
|
|
5002
|
+
matchedCurrentIndices.add(candidateId);
|
|
5003
|
+
if (!payloadsEqual(baselineEvent, currentEvent)) {
|
|
5004
|
+
modified.push({
|
|
5005
|
+
event: currentEvent,
|
|
5006
|
+
previousEvent: baselineEvent,
|
|
5007
|
+
message: buildModifiedMessage(baselineEvent, currentEvent)
|
|
5008
|
+
});
|
|
5009
|
+
}
|
|
5010
|
+
matched = true;
|
|
5011
|
+
break;
|
|
5012
|
+
}
|
|
5013
|
+
if (!matched) {
|
|
5014
|
+
removed.push({
|
|
5015
|
+
event: baselineEvent,
|
|
5016
|
+
message: `${baselineEvent.type} on "${baselineEvent.target.selector}" was removed`
|
|
5017
|
+
});
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
for (const [key, candidates] of currentByKey.entries()) {
|
|
5021
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
5022
|
+
const candidateId = `${key}::${i}`;
|
|
5023
|
+
if (!matchedCurrentIndices.has(candidateId)) {
|
|
5024
|
+
const event = candidates[i];
|
|
5025
|
+
added.push({
|
|
5026
|
+
event,
|
|
5027
|
+
message: `${event.type} on "${event.target.selector}" was added`
|
|
5028
|
+
});
|
|
5029
|
+
}
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
return {
|
|
5033
|
+
baseline: { totalEvents: baseline.events.length },
|
|
5034
|
+
current: { totalEvents: current.events.length },
|
|
5035
|
+
added,
|
|
5036
|
+
removed,
|
|
5037
|
+
modified,
|
|
5038
|
+
summary: {
|
|
5039
|
+
totalBaseline: baseline.events.length,
|
|
5040
|
+
totalCurrent: current.events.length,
|
|
5041
|
+
added: added.length,
|
|
5042
|
+
removed: removed.length,
|
|
5043
|
+
modified: modified.length
|
|
5044
|
+
}
|
|
5045
|
+
};
|
|
5046
|
+
}
|
|
5047
|
+
|
|
5048
|
+
// src/runtime/severity.ts
|
|
5049
|
+
function classifyDiff(report) {
|
|
5050
|
+
const entries = [];
|
|
5051
|
+
for (const entry of report.removed) {
|
|
5052
|
+
const severity = classifyRemoved(entry);
|
|
5053
|
+
entries.push({ ...entry, severity });
|
|
5054
|
+
}
|
|
5055
|
+
for (const entry of report.added) {
|
|
5056
|
+
const severity = classifyAdded(entry);
|
|
5057
|
+
entries.push({ ...entry, severity });
|
|
5058
|
+
}
|
|
5059
|
+
for (const entry of report.modified) {
|
|
5060
|
+
const severity = classifyModified(entry);
|
|
5061
|
+
entries.push({ ...entry, severity });
|
|
5062
|
+
}
|
|
5063
|
+
const criticalCount = entries.filter((e) => e.severity === "critical").length;
|
|
5064
|
+
const highCount = entries.filter((e) => e.severity === "high").length;
|
|
5065
|
+
const mediumCount = entries.filter((e) => e.severity === "medium").length;
|
|
5066
|
+
const lowCount = entries.filter((e) => e.severity === "low").length;
|
|
5067
|
+
let highestSeverity = null;
|
|
5068
|
+
if (criticalCount > 0) highestSeverity = "critical";
|
|
5069
|
+
else if (highCount > 0) highestSeverity = "high";
|
|
5070
|
+
else if (mediumCount > 0) highestSeverity = "medium";
|
|
5071
|
+
else if (lowCount > 0) highestSeverity = "low";
|
|
5072
|
+
return { entries, highestSeverity, criticalCount, highCount, mediumCount, lowCount };
|
|
5073
|
+
}
|
|
5074
|
+
function classifyRemoved(entry) {
|
|
5075
|
+
switch (entry.event.type) {
|
|
5076
|
+
case "FOCUS_CHANGED":
|
|
5077
|
+
return "critical";
|
|
5078
|
+
case "ANNOUNCEMENT":
|
|
5079
|
+
return "critical";
|
|
5080
|
+
case "DIALOG_OPENED":
|
|
5081
|
+
return "high";
|
|
5082
|
+
case "DIALOG_CLOSED":
|
|
5083
|
+
return "high";
|
|
5084
|
+
case "STATE_CHANGED":
|
|
5085
|
+
return "high";
|
|
5086
|
+
case "KEYBOARD_ACTION":
|
|
5087
|
+
return "medium";
|
|
5088
|
+
default:
|
|
5089
|
+
return "medium";
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
function classifyAdded(entry) {
|
|
5093
|
+
switch (entry.event.type) {
|
|
5094
|
+
case "WARNING":
|
|
5095
|
+
return "high";
|
|
5096
|
+
case "REGRESSION":
|
|
5097
|
+
return "critical";
|
|
5098
|
+
case "ANNOUNCEMENT":
|
|
5099
|
+
return "medium";
|
|
5100
|
+
case "FOCUS_CHANGED":
|
|
5101
|
+
return "medium";
|
|
5102
|
+
default:
|
|
5103
|
+
return "low";
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
function classifyModified(entry) {
|
|
5107
|
+
switch (entry.event.type) {
|
|
5108
|
+
case "FOCUS_CHANGED":
|
|
5109
|
+
return "high";
|
|
5110
|
+
case "STATE_CHANGED":
|
|
5111
|
+
return "high";
|
|
5112
|
+
case "ACCESSIBLE_NAME_CHANGED":
|
|
5113
|
+
return "medium";
|
|
5114
|
+
case "ANNOUNCEMENT":
|
|
5115
|
+
return "medium";
|
|
5116
|
+
default:
|
|
5117
|
+
return "medium";
|
|
5118
|
+
}
|
|
5119
|
+
}
|
|
5120
|
+
|
|
5121
|
+
// src/runtime/baseline-storage.ts
|
|
5122
|
+
import { readFile, writeFile, mkdir, access } from "fs/promises";
|
|
5123
|
+
import { join, dirname } from "path";
|
|
5124
|
+
var SPEAKABLE_VERSION2 = "1.3.0";
|
|
5125
|
+
function createBaselineStorage(baseDir) {
|
|
5126
|
+
function sanitize(name) {
|
|
5127
|
+
return name.toLowerCase().replace(/[/\\]/g, "-").replace(/[^a-z0-9._-]/g, "-");
|
|
5128
|
+
}
|
|
5129
|
+
function getPath(componentName, storyName) {
|
|
5130
|
+
return join(baseDir, sanitize(componentName), `${sanitize(storyName)}.timeline.json`);
|
|
5131
|
+
}
|
|
5132
|
+
return {
|
|
5133
|
+
async save(componentName, storyName, timeline, meta) {
|
|
5134
|
+
const filePath = getPath(componentName, storyName);
|
|
5135
|
+
const dir = dirname(filePath);
|
|
5136
|
+
try {
|
|
5137
|
+
await mkdir(dir, { recursive: true });
|
|
5138
|
+
} catch (err) {
|
|
5139
|
+
throw new Error(`Cannot create baseline directory "${dir}": ${err.message}`);
|
|
5140
|
+
}
|
|
5141
|
+
const baselineFile = {
|
|
5142
|
+
baseline: {
|
|
5143
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5144
|
+
speakableVersion: SPEAKABLE_VERSION2,
|
|
5145
|
+
storybookUrl: meta?.storybookUrl,
|
|
5146
|
+
interactionSequence: timeline.interactionSequence
|
|
5147
|
+
},
|
|
5148
|
+
timeline
|
|
5149
|
+
};
|
|
5150
|
+
const json = JSON.stringify(baselineFile, null, 2);
|
|
5151
|
+
try {
|
|
5152
|
+
await writeFile(filePath, json, "utf-8");
|
|
5153
|
+
} catch (err) {
|
|
5154
|
+
throw new Error(`Cannot write baseline file "${filePath}": ${err.message}`);
|
|
5155
|
+
}
|
|
5156
|
+
},
|
|
5157
|
+
async load(componentName, storyName) {
|
|
5158
|
+
const filePath = getPath(componentName, storyName);
|
|
5159
|
+
try {
|
|
5160
|
+
const content = await readFile(filePath, "utf-8");
|
|
5161
|
+
const parsed = JSON.parse(content);
|
|
5162
|
+
return parsed;
|
|
5163
|
+
} catch {
|
|
5164
|
+
return null;
|
|
5165
|
+
}
|
|
5166
|
+
},
|
|
5167
|
+
async exists(componentName, storyName) {
|
|
5168
|
+
const filePath = getPath(componentName, storyName);
|
|
5169
|
+
try {
|
|
5170
|
+
await access(filePath);
|
|
5171
|
+
return true;
|
|
5172
|
+
} catch {
|
|
5173
|
+
return false;
|
|
5174
|
+
}
|
|
5175
|
+
},
|
|
5176
|
+
getBaselinePath(componentName, storyName) {
|
|
5177
|
+
return getPath(componentName, storyName);
|
|
5178
|
+
}
|
|
5179
|
+
};
|
|
5180
|
+
}
|
|
492
5181
|
export {
|
|
493
5182
|
CURRENT_MODEL_VERSION,
|
|
5183
|
+
ParsingError,
|
|
494
5184
|
SUPPORTED_ROLES,
|
|
5185
|
+
SelectorError,
|
|
495
5186
|
ValidationError,
|
|
5187
|
+
buildAccessibilityTree,
|
|
5188
|
+
buildAccessibilityTreeWithSelector,
|
|
496
5189
|
cloneModel,
|
|
5190
|
+
computeAccessibleDescription,
|
|
5191
|
+
computeAccessibleName,
|
|
5192
|
+
computeRole,
|
|
497
5193
|
createModel,
|
|
498
5194
|
describeChange,
|
|
499
5195
|
deserializeModel,
|
|
500
5196
|
diffAccessibilityTrees,
|
|
5197
|
+
extractFocusInfo,
|
|
5198
|
+
extractState,
|
|
5199
|
+
extractValue,
|
|
501
5200
|
formatDiffAsJSON,
|
|
502
5201
|
formatDiffAsText,
|
|
503
5202
|
formatDiffForCI,
|
|
5203
|
+
generateAuditReport,
|
|
504
5204
|
hasAccessibilityRegression,
|
|
5205
|
+
isAccessible,
|
|
505
5206
|
modelsEqual,
|
|
5207
|
+
parseHTML,
|
|
5208
|
+
parseHTMLStrict,
|
|
5209
|
+
renderAuditReport,
|
|
5210
|
+
renderJAWS,
|
|
5211
|
+
renderNVDA,
|
|
5212
|
+
renderNarrator,
|
|
5213
|
+
renderVoiceOver,
|
|
5214
|
+
runtime_exports as runtime,
|
|
506
5215
|
serializeModel,
|
|
5216
|
+
validateHTMLNotEmpty,
|
|
507
5217
|
validateModel,
|
|
508
5218
|
validateRole,
|
|
509
5219
|
validateState,
|