Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1905x 1905x 1905x 1905x 1905x 1905x 1905x 1905x 1845x 1905x 2x 2x 2x 2x 2x 2x 2x 2x 1905x 555x 555x 2x 2x 2x 2x 2x 10359x 10359x 10359x 2x 2x 2x 2x 14270x 14270x 14270x 2x 2x 2x 2x 3814x 3814x 3814x 2x 2x 2x 2x 2x 2x 19726x 19726x 19726x 2x 2x 2x 2x 2x 21316x 21316x 1166x 1166x 9x 9x 1166x 21307x 21307x 21316x 57x 3052x 21316x 21316x 2x 2x 2x 2x 581x 581x 581x 1x 1x 580x 580x 581x 4x 4x 4x 4x 4x 576x 576x 2x 2x 2x 2x 2x 2x 1680x 855x 855x 2x 2x 2x 2x 2x 2x 2x 1680x 540x 540x 2x 2x 2x 2x 2x 1860x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1050x 390x 390x 1050x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1050x 615x 615x 1050x 2x 2x 2x 2x 2x 2x 2x 4583845x 4583845x 4583845x 41824x 42395x 42395x 42395x 8099x 8099x 2062x 41824x 41824x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 47484x 47484x 47484x 47484x 10421x 10421x 37063x 42101x 37011x 1821675x 37011x 47484x 15143x 15143x 21920x 21920x 541808x 21920x 47484x 1991x 1991x 19929x 19929x 796147x 19929x 47484x 1291x 1291x 18638x 18638x 2x 2x 2x 2x 2x 2x 30712x 30712x 30712x 2x 2x 2x 2x 2x 2x 16525x 16525x 16525x 2x 2x 2x 2x 2x 2x 247x 247x 247x 2x 2x 2x 2x 2x 2x 580x 580x 39842x 39842x 635x 103x 103x 103x 103x 11x 635x 39842x 533x 553x 553x 112x 113x 22x 22x 113x 90x 553x 511x 39842x 558x 558x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 19x 19x 1x 19x 3x 3x 15x 19x 5x 5x 19x 6x 6x 19x 10x 19x 5x 3x 3x 5x 3x 5x 2x 2x 5x 19x 2x 2x 13x 13x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 574x 574x 574x 315x 568x 307x 574x 10x 10x 297x 297x 2x 2x 7x 7x 7x 6x 7x 6x 6x 2x 2x 2x 2x 2x 9602x 9602x 7x 9602x 574x 9595x 9021x 9021x 9602x 2x 2x 2x 2x 2x 2x 2x 588x 588x 589x 589x 8x 8x 581x 581x 580x 580x 2x 2x 2x 2x 2x 2x 2x 507x 507x 507x 507x 507x 447x 507x 2x 507x 4x 445x 3x 441x 438x 438x 36x 36x 4x 4x 4x 4x 4x 4x 438x 22x 22x 22x 22x 22x 22x 22x 5x 5x 5x 5x 5x 5x 402x 2x 2x 507x 2x 2x 2x 2x 2x 2x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 2x 2x 2x 2x 30914x 30914x 30786x 28296x 477x 477x 2x 2x 2x 2x 26170x 26170x 26170x 26119x 26119x 2x 2x 2x 2x 2x 2x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 7075x 234x 7075x 1097x 6841x 4461x 679x 4461x 3782x 3782x 3782x 23x 23x 3782x 5744x 22x 22x 7075x 9603x 9603x 7075x 4461x 4461x 4461x 7075x 508x 1x 1x 1x 508x 508x 508x 1x 1x 1x 508x 508x 1x 1x 508x 508x 508x 508x 508x 508x 507x 507x 508x 508x 508x 508x 508x 508x 8x 508x 1x 1x 508x 4461x 4461x 7075x 582x 1x 1x 1x 582x 582x 582x 579x 581x 581x 581x 24x 581x 2x 2x 2x 581x 581x 581x 581x 39x 581x 39x 39x 581x 38x 38x 581x 581x 581x 581x 581x 581x 581x 2x 2x 581x 581x 581x 581x 581x 580x 581x 558x 558x 556x 556x 556x 556x 556x 4x 4x 4x 4x 4x 4x 4x 4x 4x 556x 558x 581x 581x 581x 581x 581x 581x 581x 581x 169x 581x 160x 22x 160x 160x 22x 22x 160x 581x 581x 581x 581x 60x 581x 46x 46x 581x 581x 581x 581x 581x 64x 64x 64x 581x 48x 48x 581x 579x 582x 4461x 4461x 7075x 1x 1x 4461x 4461x 7075x 10x 10x 4461x 4461x 7075x 8x 8x 4461x 4461x 7075x 33x 33x 33x 1x 1x 33x 7075x 9603x 9603x 9603x 9603x 9603x 9603x 1567x 1567x 1567x 1567x 1567x 1567x 1567x 77x 1567x 72x 72x 72x 55x 55x 72x 1567x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 6741x 9603x 6506x 6506x 6506x 4x 4x 6506x 9603x 9603x 9603x 3589x 3589x 3589x 3589x 2087x 179x 59x 179x 120x 120x 179x 2087x 3589x 9603x 9603x 9603x 9603x 9603x 9603x 9549x 9549x 9549x 9603x 3401x 28x 3401x 3401x 10x 10x 3401x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 9603x 3233x 9603x 3209x 126x 3209x 3209x 87x 87x 3209x 9603x 9603x 3x 3x 9603x 9603x 3x 3x 9603x 9603x 9603x 9603x 9603x 1697x 1697x 1697x 75x 75x 1697x 9603x 9603x 94x 94x 83x 83x 64x 5x 5x 64x 94x 11x 11x 11x 11x 8x 8x 11x 9603x 9277x 9277x 60x 60x 23x 23x 60x 9277x 9603x 9603x 574x 574x 574x 5x 5x 5x 2x 2x 5x 574x 574x 574x 19x 19x 3x 3x 3x 3x 3x 3x 19x 574x 9603x 9603x 50x 50x 50x 20x 3x 3x 20x 50x 9603x 9603x 75x 75x 70x 70x 70x 70x 70x 70x 533x 533x 533x 533x 533x 530x 530x 533x 67x 533x 466x 466x 533x 70x 70x 70x 75x 75x 3x 3x 75x 9603x 9603x 10x 10x 10x 5x 5x 5x 5x 5x 5x 6x 2x 2x 1x 1x 2x 2x 6x 4x 4x 10x 9598x 9603x 7x 3x 3x 7x 9598x 9603x 9x 35x 35x 14x 9x 9x 9x 9x 9x 1x 1x 9x 9598x 9603x 10x 10x 10x 9598x 9598x 9598x 9599x 9603x 9603x 296x 9603x 5x 5x 9603x 2x 2x 2x 2x 2003x 2003x 2002x 1541x 79x 79x 1541x 1923x 2002x 17x 17x 1x 17x 1x 1x 16x 17x 1x 1x 17x 1921x 1921x 1921x 1921x 1921x 81x | /** @import { AnalysisState } from '../../types.js' */ /** @import { AST, SvelteNode, TemplateNode } from '#compiler' */ /** @import { ARIARoleDefinitionKey, ARIARoleRelationConcept, ARIAProperty, ARIAPropertyDefinition, ARIARoleDefinition } from 'aria-query' */ import { roles as roles_map, aria, elementRoles } from 'aria-query'; // @ts-expect-error package doesn't provide typings import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query'; import { regex_heading_tags, regex_not_whitespace, regex_starts_with_vowel, regex_whitespaces } from '../../../patterns.js'; import * as w from '../../../../warnings.js'; import fuzzymatch from '../../../1-parse/utils/fuzzymatch.js'; import { is_event_attribute, is_text_attribute } from '../../../../utils/ast.js'; import { walk } from 'zimmerframe'; import { list } from '../../../../utils/string.js'; import { is_content_editable_binding } from '../../../../../utils.js'; const aria_roles = roles_map.keys(); const abstract_roles = aria_roles.filter((role) => roles_map.get(role)?.abstract); const non_abstract_roles = aria_roles.filter((name) => !abstract_roles.includes(name)); const non_interactive_roles = non_abstract_roles .filter((name) => { const role = roles_map.get(name); return ( // 'toolbar' does not descend from widget, but it does support // aria-activedescendant, thus in practice we treat it as a widget. // focusable tabpanel elements are recommended if any panels in a set contain content where the first element in the panel is not focusable. // 'generic' is meant to have no semantic meaning. // 'cell' is treated as CellRole by the AXObject which is interactive, so we treat 'cell' it as interactive as well. !['toolbar', 'tabpanel', 'generic', 'cell'].includes(name) && !role?.superClass.some((classes) => classes.includes('widget')) ); }) .concat( // The `progressbar` is descended from `widget`, but in practice, its // value is always `readonly`, so we treat it as a non-interactive role. 'progressbar' ); const interactive_roles = non_abstract_roles.filter( (name) => !non_interactive_roles.includes(name) && // 'generic' is meant to have no semantic meaning. name !== 'generic' ); /** * @param {ARIARoleDefinitionKey} role */ function is_non_interactive_roles(role) { return non_interactive_roles.includes(role); } /** * @param {ARIARoleDefinitionKey} role */ function is_interactive_roles(role) { return interactive_roles.includes(role); } /** * @param {ARIARoleDefinitionKey} role */ function is_abstract_role(role) { return abstract_roles.includes(role); } const presentation_roles = ['presentation', 'none']; /** * @param {ARIARoleDefinitionKey} role */ function is_presentation_role(role) { return presentation_roles.includes(role); } /** * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map */ function is_hidden_from_screen_reader(tag_name, attribute_map) { if (tag_name === 'input') { const type = get_static_value(attribute_map.get('type')); if (type === 'hidden') { return true; } } const aria_hidden = attribute_map.get('aria-hidden'); if (!aria_hidden) return false; const aria_hidden_value = get_static_value(aria_hidden); if (aria_hidden_value === null) return true; return aria_hidden_value === true || aria_hidden_value === 'true'; } /** * @param {Map<string, AST.Attribute>} attribute_map */ function has_disabled_attribute(attribute_map) { const disabled_attr_value = get_static_value(attribute_map.get('disabled')); if (disabled_attr_value) { return true; } const aria_disabled_attr = attribute_map.get('aria-disabled'); if (aria_disabled_attr) { const aria_disabled_attr_value = get_static_value(aria_disabled_attr); if (aria_disabled_attr_value === 'true') { return true; } } return false; } /** * @type {ARIARoleRelationConcept[]} */ const non_interactive_element_role_schemas = []; elementRoles.entries().forEach(([schema, roles]) => { if ([...roles].every((role) => role !== 'generic' && non_interactive_roles.includes(role))) { non_interactive_element_role_schemas.push(schema); } }); /** * @type {ARIARoleRelationConcept[]} */ const interactive_element_role_schemas = []; elementRoles.entries().forEach(([schema, roles]) => { if ([...roles].every((role) => interactive_roles.includes(role))) { interactive_element_role_schemas.push(schema); } }); const interactive_ax_objects = [...AXObjects.keys()].filter( (name) => AXObjects.get(name).type === 'widget' ); const non_interactive_ax_objects = [...AXObjects.keys()].filter((name) => ['windows', 'structure'].includes(AXObjects.get(name).type) ); /** * @type {ARIARoleRelationConcept[]} */ const interactive_element_ax_object_schemas = []; elementAXObjects.entries().forEach( /** * @param {any} _ */ ([schema, ax_object]) => { if ([...ax_object].every((role) => interactive_ax_objects.includes(role))) { interactive_element_ax_object_schemas.push(schema); } } ); /** * @type {ARIARoleRelationConcept[]} */ const non_interactive_element_ax_object_schemas = []; elementAXObjects.entries().forEach( /** * @param {any} _ */ ([schema, ax_object]) => { if ([...ax_object].every((role) => non_interactive_ax_objects.includes(role))) { non_interactive_element_ax_object_schemas.push(schema); } } ); /** * @param {ARIARoleRelationConcept} schema * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map */ function match_schema(schema, tag_name, attribute_map) { if (schema.name !== tag_name) return false; if (!schema.attributes) return true; return schema.attributes.every((schema_attribute) => { const attribute = attribute_map.get(schema_attribute.name); if (!attribute) return false; if (schema_attribute.value && schema_attribute.value !== get_static_text_value(attribute)) { return false; } return true; }); } const ElementInteractivity = /** @type {const} */ ({ Interactive: 'interactive', NonInteractive: 'non-interactive', Static: 'static' }); /** * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map * @returns {ElementInteractivity[keyof ElementInteractivity]} */ function element_interactivity(tag_name, attribute_map) { if ( interactive_element_role_schemas.some((schema) => match_schema(schema, tag_name, attribute_map)) ) { return ElementInteractivity.Interactive; } if ( tag_name !== 'header' && non_interactive_element_role_schemas.some((schema) => match_schema(schema, tag_name, attribute_map) ) ) { return ElementInteractivity.NonInteractive; } if ( interactive_element_ax_object_schemas.some((schema) => match_schema(schema, tag_name, attribute_map) ) ) { return ElementInteractivity.Interactive; } if ( non_interactive_element_ax_object_schemas.some((schema) => match_schema(schema, tag_name, attribute_map) ) ) { return ElementInteractivity.NonInteractive; } return ElementInteractivity.Static; } /** * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map * @returns {boolean} */ function is_interactive_element(tag_name, attribute_map) { return element_interactivity(tag_name, attribute_map) === ElementInteractivity.Interactive; } /** * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map * @returns {boolean} */ function is_non_interactive_element(tag_name, attribute_map) { return element_interactivity(tag_name, attribute_map) === ElementInteractivity.NonInteractive; } /** * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map * @returns {boolean} */ function is_static_element(tag_name, attribute_map) { return element_interactivity(tag_name, attribute_map) === ElementInteractivity.Static; } /** * @param {ARIARoleDefinitionKey} role * @param {string} tag_name * @param {Map<string, AST.Attribute>} attribute_map */ function is_semantic_role_element(role, tag_name, attribute_map) { for (const [schema, ax_object] of elementAXObjects.entries()) { if ( schema.name === tag_name && (!schema.attributes || schema.attributes.every( /** @param {any} attr */ (attr) => attribute_map.has(attr.name) && get_static_value(attribute_map.get(attr.name)) === attr.value )) ) { for (const name of ax_object) { const roles = AXObjectRoles.get(name); if (roles) { for (const { name } of roles) { if (name === role) { return true; } } } } } } return false; } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute const address_type_tokens = ['shipping', 'billing']; const autofill_field_name_tokens = [ '', 'on', 'off', 'name', 'honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix', 'nickname', 'username', 'new-password', 'current-password', 'one-time-code', 'organization-title', 'organization', 'street-address', 'address-line1', 'address-line2', 'address-line3', 'address-level4', 'address-level3', 'address-level2', 'address-level1', 'country', 'country-name', 'postal-code', 'cc-name', 'cc-given-name', 'cc-additional-name', 'cc-family-name', 'cc-number', 'cc-exp', 'cc-exp-month', 'cc-exp-year', 'cc-csc', 'cc-type', 'transaction-currency', 'transaction-amount', 'language', 'bday', 'bday-day', 'bday-month', 'bday-year', 'sex', 'url', 'photo' ]; const contact_type_tokens = ['home', 'work', 'mobile', 'fax', 'pager']; const autofill_contact_field_name_tokens = [ 'tel', 'tel-country-code', 'tel-national', 'tel-area-code', 'tel-local', 'tel-local-prefix', 'tel-local-suffix', 'tel-extension', 'email', 'impp' ]; /** * @param {null | true | string} autocomplete */ function is_valid_autocomplete(autocomplete) { if (autocomplete === true) { return false; } else if (!autocomplete) { return true; // dynamic value } const tokens = autocomplete.trim().toLowerCase().split(regex_whitespaces); if (typeof tokens[0] === 'string' && tokens[0].startsWith('section-')) { tokens.shift(); } if (address_type_tokens.includes(tokens[0])) { tokens.shift(); } if (autofill_field_name_tokens.includes(tokens[0])) { tokens.shift(); } else { if (contact_type_tokens.includes(tokens[0])) { tokens.shift(); } if (autofill_contact_field_name_tokens.includes(tokens[0])) { tokens.shift(); } else { return false; } } if (tokens[0] === 'webauthn') { tokens.shift(); } return tokens.length === 0; } const aria_attributes = 'activedescendant atomic autocomplete busy checked colcount colindex colspan controls current describedby description details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription rowcount rowindex rowspan selected setsize sort valuemax valuemin valuenow valuetext'.split( ' ' ); /** @type {Record<string, string[]>} */ const a11y_required_attributes = { a: ['href'], area: ['alt', 'aria-label', 'aria-labelledby'], // html-has-lang html: ['lang'], // iframe-has-title iframe: ['title'], img: ['alt'], object: ['title', 'aria-label', 'aria-labelledby'] }; const a11y_distracting_elements = ['blink', 'marquee']; // this excludes `<a>` and `<button>` because they are handled separately const a11y_required_content = [ // heading-has-content 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]; const a11y_labelable = [ 'button', 'input', 'keygen', 'meter', 'output', 'progress', 'select', 'textarea' ]; const a11y_interactive_handlers = [ // Keyboard events 'keypress', 'keydown', 'keyup', // Click events 'click', 'contextmenu', 'dblclick', 'drag', 'dragend', 'dragenter', 'dragexit', 'dragleave', 'dragover', 'dragstart', 'drop', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseout', 'mouseover', 'mouseup' ]; const a11y_recommended_interactive_handlers = [ 'click', 'mousedown', 'mouseup', 'keypress', 'keydown', 'keyup' ]; const a11y_nested_implicit_semantics = new Map([ ['header', 'banner'], ['footer', 'contentinfo'] ]); const a11y_implicit_semantics = new Map([ ['a', 'link'], ['area', 'link'], ['article', 'article'], ['aside', 'complementary'], ['body', 'document'], ['button', 'button'], ['datalist', 'listbox'], ['dd', 'definition'], ['dfn', 'term'], ['dialog', 'dialog'], ['details', 'group'], ['dt', 'term'], ['fieldset', 'group'], ['figure', 'figure'], ['form', 'form'], ['h1', 'heading'], ['h2', 'heading'], ['h3', 'heading'], ['h4', 'heading'], ['h5', 'heading'], ['h6', 'heading'], ['hr', 'separator'], ['img', 'img'], ['li', 'listitem'], ['link', 'link'], ['main', 'main'], ['menu', 'list'], ['meter', 'progressbar'], ['nav', 'navigation'], ['ol', 'list'], ['option', 'option'], ['optgroup', 'group'], ['output', 'status'], ['progress', 'progressbar'], ['section', 'region'], ['summary', 'button'], ['table', 'table'], ['tbody', 'rowgroup'], ['textarea', 'textbox'], ['tfoot', 'rowgroup'], ['thead', 'rowgroup'], ['tr', 'row'], ['ul', 'list'] ]); const menuitem_type_to_implicit_role = new Map([ ['command', 'menuitem'], ['checkbox', 'menuitemcheckbox'], ['radio', 'menuitemradio'] ]); const input_type_to_implicit_role = new Map([ ['button', 'button'], ['image', 'button'], ['reset', 'button'], ['submit', 'button'], ['checkbox', 'checkbox'], ['radio', 'radio'], ['range', 'slider'], ['number', 'spinbutton'], ['email', 'textbox'], ['search', 'searchbox'], ['tel', 'textbox'], ['text', 'textbox'], ['url', 'textbox'] ]); /** * Exceptions to the rule which follows common A11y conventions * TODO make this configurable by the user * @type {Record<string, string[]>} */ const a11y_non_interactive_element_to_interactive_role_exceptions = { ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'], ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'], li: ['menuitem', 'option', 'row', 'tab', 'treeitem'], table: ['grid'], td: ['gridcell'], fieldset: ['radiogroup', 'presentation'] }; const combobox_if_list = ['email', 'search', 'tel', 'text', 'url']; /** @param {Map<string, AST.Attribute>} attribute_map */ function input_implicit_role(attribute_map) { const type_attribute = attribute_map.get('type'); if (!type_attribute) return; const type = get_static_text_value(type_attribute); if (!type) return; const list_attribute_exists = attribute_map.has('list'); if (list_attribute_exists && combobox_if_list.includes(type)) { return 'combobox'; } return input_type_to_implicit_role.get(type); } /** @param {Map<string, AST.Attribute>} attribute_map */ function menuitem_implicit_role(attribute_map) { const type_attribute = attribute_map.get('type'); if (!type_attribute) return; const type = get_static_text_value(type_attribute); if (!type) return; return menuitem_type_to_implicit_role.get(type); } /** * @param {string} name * @param {Map<string, AST.Attribute>} attribute_map */ function get_implicit_role(name, attribute_map) { if (name === 'menuitem') { return menuitem_implicit_role(attribute_map); } else if (name === 'input') { return input_implicit_role(attribute_map); } else { return a11y_implicit_semantics.get(name); } } const invisible_elements = ['meta', 'html', 'script', 'style']; /** * @param {SvelteNode | null} parent * @param {string[]} elements */ function is_parent(parent, elements) { while (parent) { if (parent.type === 'SvelteElement') return true; // unknown, play it safe, so we don't warn if (parent.type === 'RegularElement') { return elements.includes(parent.name); } parent = /** @type {TemplateNode} */ (parent).parent; } return false; } /** * @param {AST.Attribute} attribute * @param {ARIAProperty} name * @param {ARIAPropertyDefinition} schema * @param {string | true | null} value */ function validate_aria_attribute_value(attribute, name, schema, value) { const type = schema.type; if (value === null) return; if (value === true) value = ''; if (type === 'boolean' && value !== 'true' && value !== 'false') { w.a11y_incorrect_aria_attribute_type_boolean(attribute, name); } else if (type === 'integer' && (value === '' || !Number.isInteger(+value))) { w.a11y_incorrect_aria_attribute_type_integer(attribute, name); } else if (type === 'number' && (value === '' || isNaN(+value))) { w.a11y_incorrect_aria_attribute_type(attribute, name, 'number'); } else if ((type === 'string' || type === 'id') && value === '') { w.a11y_incorrect_aria_attribute_type(attribute, name, 'non-empty string'); } else if (type === 'idlist' && value === '') { w.a11y_incorrect_aria_attribute_type_idlist(attribute, name); } else if (type === 'token') { const values = (schema.values ?? []).map((value) => value.toString()); if (!values.includes(value.toLowerCase())) { w.a11y_incorrect_aria_attribute_type_token( attribute, name, list(values.map((v) => `"${v}"`)) ); } } else if (type === 'tokenlist') { const values = (schema.values ?? []).map((value) => value.toString()); if ( value .toLowerCase() .split(regex_whitespaces) .some((value) => !values.includes(value)) ) { w.a11y_incorrect_aria_attribute_type_tokenlist( attribute, name, list(values.map((v) => `"${v}"`)) ); } } else if (type === 'tristate' && value !== 'true' && value !== 'false' && value !== 'mixed') { w.a11y_incorrect_aria_attribute_type_tristate(attribute, name); } } /** * @param {AST.RegularElement |AST.SvelteElement} node * @param {string[]} attributes * @param {string} name */ function warn_missing_attribute(node, attributes, name = node.name) { const article = regex_starts_with_vowel.test(attributes[0]) || attributes[0] === 'href' ? 'an' : 'a'; const sequence = attributes.length > 1 ? attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` : attributes[0]; w.a11y_missing_attribute(node, name, article, sequence); } /** * @param {AST.Attribute | undefined} attribute */ function get_static_value(attribute) { if (!attribute) return null; if (attribute.value === true) return true; if (is_text_attribute(attribute)) return attribute.value[0].data; return null; } /** * @param {AST.Attribute | undefined} attribute */ function get_static_text_value(attribute) { const value = get_static_value(attribute); if (value === true) return null; return value; } /** * @param {AST.RegularElement | AST.SvelteElement} node * @param {AnalysisState} state */ export function check_element(node, state) { /** @type {Map<string, AST.Attribute>} */ const attribute_map = new Map(); /** @type {Set<string>} */ const handlers = new Set(); /** @type {AST.Attribute[]} */ const attributes = []; const is_dynamic_element = node.type === 'SvelteElement'; let has_spread = false; let has_contenteditable_attr = false; let has_contenteditable_binding = false; for (const attribute of node.attributes) { if (attribute.type === 'SpreadAttribute') { has_spread = true; } else if (attribute.type === 'OnDirective') { handlers.add(attribute.name); } else if (attribute.type === 'Attribute') { if (is_event_attribute(attribute)) { handlers.add(attribute.name.slice(2)); } else { attributes.push(attribute); attribute_map.set(attribute.name, attribute); if (attribute.name === 'contenteditable') { has_contenteditable_attr = true; } } } else if (attribute.type === 'BindDirective' && is_content_editable_binding(attribute.name)) { has_contenteditable_binding = true; } } for (const attribute of node.attributes) { if (attribute.type !== 'Attribute') continue; const name = attribute.name.toLowerCase(); // aria-props if (name.startsWith('aria-')) { if (invisible_elements.includes(node.name)) { // aria-unsupported-elements w.a11y_aria_attributes(attribute, node.name); } const type = name.slice(5); if (!aria_attributes.includes(type)) { const match = fuzzymatch(type, aria_attributes); w.a11y_unknown_aria_attribute(attribute, type, match); } if (name === 'aria-hidden' && regex_heading_tags.test(node.name)) { w.a11y_hidden(attribute, node.name); } // aria-proptypes let value = get_static_value(attribute); const schema = aria.get(/** @type {ARIAProperty} */ (name)); if (schema !== undefined) { validate_aria_attribute_value(attribute, /** @type {ARIAProperty} */ (name), schema, value); } // aria-activedescendant-has-tabindex if ( name === 'aria-activedescendant' && !is_dynamic_element && !is_interactive_element(node.name, attribute_map) && !attribute_map.has('tabindex') ) { w.a11y_aria_activedescendant_has_tabindex(attribute); } } // aria-role if (name === 'role') { if (invisible_elements.includes(node.name)) { // aria-unsupported-elements w.a11y_misplaced_role(attribute, node.name); } const value = get_static_value(attribute); if (typeof value === 'string') { for (const c_r of value.split(regex_whitespaces)) { const current_role = /** @type {ARIARoleDefinitionKey} current_role */ (c_r); if (current_role && is_abstract_role(current_role)) { w.a11y_no_abstract_role(attribute, current_role); } else if (current_role && !aria_roles.includes(current_role)) { const match = fuzzymatch(current_role, aria_roles); w.a11y_unknown_role(attribute, current_role, match); } // no-redundant-roles if ( current_role === get_implicit_role(node.name, attribute_map) && // <ul role="list"> is ok because CSS list-style:none removes the semantics and this is a way to bring them back !['ul', 'ol', 'li'].includes(node.name) && // <a role="link" /> is ok because without href the a tag doesn't have a role of link !(node.name === 'a' && !attribute_map.has('href')) ) { w.a11y_no_redundant_roles(attribute, current_role); } // Footers and headers are special cases, and should not have redundant roles unless they are the children of sections or articles. const is_parent_section_or_article = is_parent(node.parent, ['section', 'article']); if (!is_parent_section_or_article) { const has_nested_redundant_role = current_role === a11y_nested_implicit_semantics.get(node.name); if (has_nested_redundant_role) { w.a11y_no_redundant_roles(attribute, current_role); } } // role-has-required-aria-props if ( !is_dynamic_element && !is_semantic_role_element(current_role, node.name, attribute_map) ) { const role = roles_map.get(current_role); if (role) { const required_role_props = Object.keys(role.requiredProps); const has_missing_props = required_role_props.some( (prop) => !attributes.find((a) => a.name === prop) ); if (has_missing_props) { w.a11y_role_has_required_aria_props( attribute, current_role, list( required_role_props.map((v) => `"${v}"`), 'and' ) ); } } } // interactive-supports-focus if ( !has_disabled_attribute(attribute_map) && !is_hidden_from_screen_reader(node.name, attribute_map) && !is_presentation_role(current_role) && is_interactive_roles(current_role) && is_static_element(node.name, attribute_map) && !attribute_map.get('tabindex') ) { const has_interactive_handlers = [...handlers].some((handler) => a11y_interactive_handlers.includes(handler) ); if (has_interactive_handlers) { w.a11y_interactive_supports_focus(node, current_role); } } // no-interactive-element-to-noninteractive-role if ( is_interactive_element(node.name, attribute_map) && (is_non_interactive_roles(current_role) || is_presentation_role(current_role)) ) { w.a11y_no_interactive_element_to_noninteractive_role(node, node.name, current_role); } // no-noninteractive-element-to-interactive-role if ( is_non_interactive_element(node.name, attribute_map) && is_interactive_roles(current_role) && !a11y_non_interactive_element_to_interactive_role_exceptions[node.name]?.includes( current_role ) ) { w.a11y_no_noninteractive_element_to_interactive_role(node, node.name, current_role); } } } } // no-access-key if (name === 'accesskey') { w.a11y_accesskey(attribute); } // no-autofocus if (name === 'autofocus') { w.a11y_autofocus(attribute); } // scope if (name === 'scope' && !is_dynamic_element && node.name !== 'th') { w.a11y_misplaced_scope(attribute); } // tabindex-no-positive if (name === 'tabindex') { const value = get_static_value(attribute); // @ts-ignore todo is tabindex=true correct case? if (!isNaN(value) && +value > 0) { w.a11y_positive_tabindex(attribute); } } } const role = attribute_map.get('role'); const role_static_value = /** @type {ARIARoleDefinitionKey} */ (get_static_text_value(role)); // click-events-have-key-events if (handlers.has('click')) { const is_non_presentation_role = role_static_value !== null && !is_presentation_role(role_static_value); if ( !is_dynamic_element && !is_hidden_from_screen_reader(node.name, attribute_map) && (!role || is_non_presentation_role) && !is_interactive_element(node.name, attribute_map) && !has_spread ) { const has_key_event = handlers.has('keydown') || handlers.has('keyup') || handlers.has('keypress'); if (!has_key_event) { w.a11y_click_events_have_key_events(node); } } } const role_value = /** @type {ARIARoleDefinitionKey} */ ( role ? role_static_value : get_implicit_role(node.name, attribute_map) ); // no-noninteractive-tabindex if ( !is_dynamic_element && !is_interactive_element(node.name, attribute_map) && !is_interactive_roles(role_static_value) ) { const tab_index = attribute_map.get('tabindex'); const tab_index_value = get_static_text_value(tab_index); if (tab_index && (tab_index_value === null || Number(tab_index_value) >= 0)) { w.a11y_no_noninteractive_tabindex(node); } } // role-supports-aria-props if (typeof role_value === 'string' && roles_map.has(role_value)) { const { props } = /** @type {ARIARoleDefinition} */ (roles_map.get(role_value)); const invalid_aria_props = aria.keys().filter((attribute) => !(attribute in props)); const is_implicit = role_value && role === undefined; for (const attr of attributes) { if (invalid_aria_props.includes(/** @type {ARIAProperty} */ (attr.name))) { if (is_implicit) { w.a11y_role_supports_aria_props_implicit(attr, attr.name, role_value, node.name); } else { w.a11y_role_supports_aria_props(attr, attr.name, role_value); } } } } // no-noninteractive-element-interactions if ( !has_contenteditable_attr && !is_hidden_from_screen_reader(node.name, attribute_map) && !is_presentation_role(role_static_value) && ((!is_interactive_element(node.name, attribute_map) && is_non_interactive_roles(role_static_value)) || (is_non_interactive_element(node.name, attribute_map) && !role)) ) { const has_interactive_handlers = [...handlers].some((handler) => a11y_recommended_interactive_handlers.includes(handler) ); if (has_interactive_handlers) { w.a11y_no_noninteractive_element_interactions(node, node.name); } } // no-static-element-interactions if ( (!role || role_static_value !== null) && !is_hidden_from_screen_reader(node.name, attribute_map) && !is_presentation_role(role_static_value) && !is_interactive_element(node.name, attribute_map) && !is_interactive_roles(role_static_value) && !is_non_interactive_element(node.name, attribute_map) && !is_non_interactive_roles(role_static_value) && !is_abstract_role(role_static_value) ) { const interactive_handlers = [...handlers].filter((handler) => a11y_interactive_handlers.includes(handler) ); if (interactive_handlers.length > 0) { w.a11y_no_static_element_interactions(node, node.name, list(interactive_handlers)); } } if (handlers.has('mouseover') && !handlers.has('focus')) { w.a11y_mouse_events_have_key_events(node, 'mouseover', 'focus'); } if (handlers.has('mouseout') && !handlers.has('blur')) { w.a11y_mouse_events_have_key_events(node, 'mouseout', 'blur'); } // element-specific checks const is_labelled = attribute_map.has('aria-label') || attribute_map.has('aria-labelledby'); if (node.name === 'a' || node.name === 'button') { const is_hidden = get_static_value(attribute_map.get('aria-hidden')) === 'true'; if (!is_hidden && !is_labelled && !has_content(node)) { w.a11y_consider_explicit_label(node); } } if (node.name === 'a') { const href = attribute_map.get('href') || attribute_map.get('xlink:href'); if (href) { const href_value = get_static_text_value(href); if (href_value !== null) { if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) { w.a11y_invalid_attribute(href, href_value, href.name); } } } else if (!has_spread) { const id_attribute = get_static_value(attribute_map.get('id')); const name_attribute = get_static_value(attribute_map.get('name')); const aria_disabled_attribute = get_static_value(attribute_map.get('aria-disabled')); if (!id_attribute && !name_attribute && aria_disabled_attribute !== 'true') { warn_missing_attribute(node, ['href']); } } } else if (!has_spread) { const required_attributes = a11y_required_attributes[node.name]; if (required_attributes) { const has_attribute = required_attributes.some((name) => attribute_map.has(name)); if (!has_attribute) { warn_missing_attribute(node, required_attributes); } } } if (node.name === 'input') { const type = attribute_map.get('type'); const type_value = get_static_text_value(type); if (type_value === 'image' && !has_spread) { const required_attributes = ['alt', 'aria-label', 'aria-labelledby']; const has_attribute = required_attributes.some((name) => attribute_map.has(name)); if (!has_attribute) { warn_missing_attribute(node, required_attributes, 'input type="image"'); } } // autocomplete-valid const autocomplete = attribute_map.get('autocomplete'); if (type && autocomplete) { const autocomplete_value = get_static_value(autocomplete); if (!is_valid_autocomplete(autocomplete_value)) { w.a11y_autocomplete_valid( autocomplete, /** @type {string} */ (autocomplete_value), type_value ?? '...' ); } } } if (node.name === 'img') { const alt_attribute = get_static_text_value(attribute_map.get('alt')); const aria_hidden = get_static_value(attribute_map.get('aria-hidden')); if (alt_attribute && !aria_hidden) { if (/\b(image|picture|photo)\b/i.test(alt_attribute)) { w.a11y_img_redundant_alt(node); } } } if (node.name === 'label') { /** @param {TemplateNode} node */ const has_input_child = (node) => { let has = false; walk( node, {}, { _(node, { next }) { if ( node.type === 'SvelteElement' || node.type === 'SlotElement' || node.type === 'Component' || node.type === 'RenderTag' || (node.type === 'RegularElement' && (a11y_labelable.includes(node.name) || node.name === 'slot')) ) { has = true; } else { next(); } } } ); return has; }; if (!attribute_map.has('for') && !has_input_child(node)) { w.a11y_label_has_associated_control(node); } } if (node.name === 'video') { const aria_hidden_attribute = attribute_map.get('aria-hidden'); const aria_hidden_exist = aria_hidden_attribute && get_static_value(aria_hidden_attribute); if (attribute_map.has('muted') || aria_hidden_exist === 'true') { return; } let has_caption = false; const track = /** @type {AST.RegularElement | undefined} */ ( node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track') ); if (track) { has_caption = track.attributes.some( (a) => a.type === 'SpreadAttribute' || (a.type === 'Attribute' && a.name === 'kind' && get_static_value(a) === 'captions') ); } if (!has_caption) { w.a11y_media_has_caption(node); } } if (node.name === 'figcaption') { if (!is_parent(node.parent, ['figure'])) { w.a11y_figcaption_parent(node); } } if (node.name === 'figure') { const children = node.fragment.nodes.filter((node) => { if (node.type === 'Comment') return false; if (node.type === 'Text') return regex_not_whitespace.test(node.data); return true; }); const index = children.findIndex( (child) => child.type === 'RegularElement' && child.name === 'figcaption' ); if (index !== -1 && index !== 0 && index !== children.length - 1) { w.a11y_figcaption_index(children[index]); } } if (a11y_distracting_elements.includes(node.name)) { // no-distracting-elements w.a11y_distracting_elements(node, node.name); } // Check content if ( !is_labelled && !has_contenteditable_binding && a11y_required_content.includes(node.name) && !has_content(node) ) { w.a11y_missing_content(node, node.name); } } /** * @param {AST.RegularElement | AST.SvelteElement} element */ function has_content(element) { for (const node of element.fragment.nodes) { if (node.type === 'Text') { if (node.data.trim() === '') { continue; } } if (node.type === 'RegularElement' || node.type === 'SvelteElement') { if ( node.name === 'img' && node.attributes.some((node) => node.type === 'Attribute' && node.name === 'alt') ) { return true; } if (!has_content(node)) { continue; } } // assume everything else has content — this will result in false positives // (e.g. an empty `{#if ...}{/if}`) but that's probably fine return true; } } |