All files / src/compiler/phases/2-analyze a11y.js

99.91% Statements 1180/1181
98.42% Branches 375/381
100% Functions 27/27
99.91% Lines 1172/1173

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 11742x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1750x 1750x 1750x 1750x 1750x 1750x 1750x 1750x 1694x 1750x 2x 2x 2x 2x 2x 2x 2x 2x 1750x 518x 518x 2x 2x 2x 2x 2x 9325x 9325x 9325x 2x 2x 2x 2x 12930x 12930x 12930x 2x 2x 2x 2x 3461x 3461x 3461x 2x 2x 2x 2x 2x 2x 17124x 17124x 17124x 2x 2x 2x 2x 2x 18271x 18271x 1028x 1028x 9x 9x 1028x 18262x 18262x 18271x 55x 2846x 18271x 18271x 2x 2x 2x 2x 580x 580x 580x 1x 1x 579x 579x 580x 3x 3x 3x 3x 3x 576x 576x 2x 2x 2x 2x 2x 2x 1582x 798x 798x 2x 2x 2x 2x 2x 2x 2x 1582x 518x 518x 2x 2x 2x 2x 2x 1736x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 980x 364x 364x 980x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 980x 574x 574x 980x 2x 2x 2x 2x 2x 2x 2x 4162897x 4162897x 4162897x 37558x 38073x 38073x 38073x 7019x 7019x 1828x 37558x 37558x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 41181x 41181x 41181x 41181x 7768x 7768x 33413x 38025x 33381x 1642310x 33381x 41181x 13663x 13663x 19750x 19750x 489068x 19750x 41181x 1732x 1732x 18018x 18018x 721226x 18018x 41181x 1116x 1116x 16902x 16902x 2x 2x 2x 2x 2x 2x 26393x 26393x 26393x 2x 2x 2x 2x 2x 2x 14541x 14541x 14541x 2x 2x 2x 2x 2x 2x 247x 247x 247x 2x 2x 2x 2x 2x 2x 579x 579x 39772x 39772x 634x 102x 102x 102x 102x 11x 634x 39772x 533x 553x 553x 112x 113x 22x 22x 113x 90x 553x 511x 39772x 557x 557x 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 505x 505x 505x 281x 499x 273x 505x 10x 10x 263x 263x 2x 2x 7x 7x 7x 6x 7x 6x 6x 2x 2x 2x 2x 2x 8299x 8299x 7x 8299x 505x 8292x 7787x 7787x 8299x 2x 2x 2x 2x 2x 2x 2x 587x 587x 588x 588x 8x 8x 580x 580x 579x 579x 2x 2x 2x 2x 2x 2x 443x 443x 443x 127x 443x 443x 78x 443x 40x 443x 443x 106x 443x 36x 36x 36x 443x 34x 34x 34x 34x 443x 22x 22x 21x 21x 21x 22x 443x   443x 443x 2x 2x 2x 2x 2x 2x 27x 27x 27x 27x 27x 27x 27x 27x 27x 2x 2x 2x 2x 25799x 25799x 25799x 23787x 476x 476x 2x 2x 2x 2x 22924x 22924x 22924x 22873x 22873x 2x 2x 2x 2x 2x 2x 8306x 8306x 8306x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8306x 6042x 191x 6042x 934x 5851x 3800x 343x 3800x 3457x 3457x 3457x 21x 21x 3457x 4917x 1117x 621x 1117x 20x 20x 6042x 8300x 8306x 6042x 3800x 3800x 3800x 6042x 505x 1x 1x 1x 505x 505x 505x 1x 1x 1x 505x 505x 1x 1x 505x 505x 505x 505x 505x 505x 444x 444x 20x 20x 444x 505x 505x 505x 505x 505x 505x 8x 505x 1x 1x 505x 3800x 3800x 6042x 581x 1x 1x 1x 581x 581x 581x 578x 580x 580x 580x 580x 24x 580x 2x 2x 2x 580x 580x 580x 580x 38x 38x 580x 38x 38x 580x 580x 580x 580x 580x 580x 580x 2x 2x 580x 580x 580x 580x 580x 579x 580x 557x 557x 555x 555x 555x 555x 555x 4x 4x 4x 4x 4x 4x 4x 555x 557x 580x 580x 580x 580x 580x 580x 580x 580x 169x 580x 160x 22x 160x 160x 22x 22x 160x 580x 580x 580x 580x 60x 580x 46x 46x 46x 46x 46x 46x 46x 580x 580x 580x 580x 580x 64x 64x 64x 580x 48x 48x 48x 48x 48x 48x 48x 580x 578x 581x 3800x 3800x 6042x 1x 1x 3800x 3800x 6042x 10x 10x 3800x 3800x 6042x 1x 1x 3800x 3800x 6042x 33x 33x 33x 1x 1x 33x 6042x 8300x 8300x 8300x 8300x 8300x 8300x 8300x 8306x 1126x 1126x 1126x 1126x 1126x 1126x 1126x 75x 1126x 74x 74x 74x 57x 57x 74x 1126x 8300x 8300x 8306x 8306x 8306x 8306x 8306x 8306x 8306x 6085x 8306x 5851x 5851x 5851x 4x 4x 5851x 8300x 8300x 8306x 2879x 2879x 2879x 2879x 2879x 2879x 1948x 1948x 1948x 179x 179x 179x 179x 179x 179x 179x 179x 179x 1948x 2879x 8300x 8300x 8300x 8306x 8306x 8306x 8249x 8249x 8249x 8306x 3070x 28x 3070x 3070x 10x 10x 3070x 8300x 8300x 8300x 8306x 8306x 8306x 8306x 8306x 8306x 8306x 2881x 8306x 2857x 114x 2857x 2857x 81x 81x 2857x 8300x 8306x 3x 3x 8300x 8306x 3x 3x 8300x 8300x 8300x 8300x 8306x 79x 79x 1x 1x 1x 1x 79x 79x 79x 69x 69x 52x 5x 5x 52x 79x 10x 10x 10x 8x 8x 10x 8306x 8032x 8032x 44x 44x 17x 17x 44x 8032x 8300x 8306x 505x 505x 505x 5x 5x 5x 2x 2x 5x 505x 505x 505x 19x 19x 3x 3x 19x 505x 8300x 8306x 35x 35x 35x 15x 3x 3x 15x 35x 8300x 8306x 69x 69x 68x 68x 68x 68x 68x 68x 523x 523x 523x 522x 522x 523x 65x 523x 458x 458x 523x 68x 68x 68x 69x 69x 3x 3x 69x 8300x 8306x 11x 11x 11x 5x 5x 6x 6x 6x 6x 7x 2x 2x 1x 1x 2x 2x 7x 5x 5x 11x 8295x 8306x 7x 3x 3x 7x 8295x 8306x 9x 35x 35x 14x 9x 9x 9x 9x 9x 1x 1x 9x 8295x 8306x 9x 9x 9x 8295x 8295x 8295x 8302x 8306x 8306x 359x 8306x 7x 7x 8306x 2x 2x 2x 2x 2x 2x 8178x 2x 2x 128x 128x 2x  
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 { warn } from '../../warnings.js';
import fuzzymatch from '../1-parse/utils/fuzzymatch.js';
import { is_event_attribute, is_text_attribute } from '../../utils/ast.js';
import { ContentEditableBindings } from '../constants.js';
import { walk } from 'zimmerframe';
 
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 {import('aria-query').ARIARoleDefinitionKey} role
 */
function is_non_interactive_roles(role) {
	return non_interactive_roles.includes(role);
}
 
/**
 * @param {import('aria-query').ARIARoleDefinitionKey} role
 */
function is_interactive_roles(role) {
	return interactive_roles.includes(role);
}
 
/**
 * @param {import('aria-query').ARIARoleDefinitionKey} role
 */
function is_abstract_role(role) {
	return abstract_roles.includes(role);
}
 
const presentation_roles = ['presentation', 'none'];
 
/**
 * @param {import('aria-query').ARIARoleDefinitionKey} role
 */
function is_presentation_role(role) {
	return presentation_roles.includes(role);
}
 
/**
 * @param {string} tag_name
 * @param {Map<string, import('#compiler').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, import('#compiler').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 {import('aria-query').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 {import('aria-query').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 {import('aria-query').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 {import('aria-query').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 {import('aria-query').ARIARoleRelationConcept} schema
 * @param {string} tag_name
 * @param {Map<string, import('#compiler').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, import('#compiler').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, import('#compiler').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, import('#compiler').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, import('#compiler').Attribute>} attribute_map
 * @returns {boolean}
 */
function is_static_element(tag_name, attribute_map) {
	return element_interactivity(tag_name, attribute_map) === ElementInteractivity.Static;
}
 
/**
 * @param {import('aria-query').ARIARoleDefinitionKey} role
 * @param {string} tag_name
 * @param {Map<string, import('#compiler').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'];
const a11y_required_content = [
	// anchor-has-content
	'a',
	// 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, import('#compiler').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, import('#compiler').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, import('#compiler').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 {import('#compiler').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 {import('#compiler').TemplateNode} */ (parent).parent;
	}
	return false;
}
 
/**
 * @param {import('aria-query').ARIAPropertyDefinition} schema
 * @param {string | boolean} value
 * @returns {boolean}
 */
function is_valid_aria_attribute_value(schema, value) {
	switch (schema.type) {
		case 'boolean':
			return typeof value === 'boolean';
		case 'string':
		case 'id':
			return typeof value === 'string';
		case 'tristate':
			return typeof value === 'boolean' || value === 'mixed';
		case 'integer':
		case 'number':
			return typeof value !== 'boolean' && isNaN(Number(value)) === false;
		case 'token': // single token
			return (
				(schema.values || []).indexOf(typeof value === 'string' ? value.toLowerCase() : value) > -1
			);
		case 'idlist': // if list of ids, split each
			return (
				typeof value === 'string' &&
				value.split(regex_whitespaces).every((id) => typeof id === 'string')
			);
		case 'tokenlist': // if list of tokens, split each
			return (
				typeof value === 'string' &&
				value
					.split(regex_whitespaces)
					.every((token) => (schema.values || []).indexOf(token.toLowerCase()) > -1)
			);
		default:
			return false;
	}
}
 
/**
 * @param {import('#compiler').RegularElement |import('#compiler').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];
	return /** @type {const} */ ([node, 'a11y-missing-attribute', name, article, sequence]);
}
 
/**
 * @param {import('#compiler').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 {import('#compiler').Attribute | undefined} attribute
 */
function get_static_text_value(attribute) {
	const value = get_static_value(attribute);
	if (value === true) return null;
	return value;
}
 
/**
 * @param {import('#compiler').RegularElement | import('#compiler').SvelteElement} node
 * @param {import('./types.js').AnalysisState} state
 * @param {import('#compiler').SvelteNode[]} path
 */
function check_element(node, state, path) {
	// foreign namespace means elements can have completely different meanings, therefore we don't check them
	if (state.options.namespace === 'foreign') return;
 
	/**
	 * @template {keyof import('../../warnings.js').AllWarnings} T
	 * @param {{ start?: number, end?: number }} node
	 * @param {T} code
	 * @param  {Parameters<import('../../warnings.js').AllWarnings[T]>} args
	 * @returns {void}
	 */
	const push_warning = (node, code, ...args) =>
		warn(state.analysis.warnings, node, path, code, ...args);
 
	/** @type {Map<string, import('#compiler').Attribute>} */
	const attribute_map = new Map();
 
	/** @type {Set<string>} */
	const handlers = new Set();
 
	/** @type {import('#compiler').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' &&
			ContentEditableBindings.includes(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
				push_warning(attribute, 'a11y-aria-attributes', node.name);
			}
 
			const type = name.slice(5);
			if (!aria_attributes.includes(type)) {
				const match = fuzzymatch(type, aria_attributes);
				push_warning(attribute, 'a11y-unknown-aria-attribute', type, match);
			}
 
			if (name === 'aria-hidden' && regex_heading_tags.test(node.name)) {
				push_warning(attribute, 'a11y-hidden', node.name);
			}
 
			// aria-proptypes
			let value = get_static_value(attribute);
			if (value === 'true') value = true;
			if (value === 'false') value = false;
			if (value !== null && value !== undefined) {
				const schema = aria.get(/** @type {import('aria-query').ARIAProperty} */ (name));
				if (schema !== undefined && !is_valid_aria_attribute_value(schema, value)) {
					push_warning(attribute, 'a11y-incorrect-aria-attribute-type', schema, name);
				}
			}
 
			// aria-activedescendant-has-tabindex
			if (
				name === 'aria-activedescendant' &&
				!is_dynamic_element &&
				!is_interactive_element(node.name, attribute_map) &&
				!attribute_map.has('tabindex')
			) {
				push_warning(attribute, 'a11y-aria-activedescendant-has-tabindex');
			}
		}
 
		// aria-role
		if (name === 'role') {
			if (invisible_elements.includes(node.name)) {
				// aria-unsupported-elements
				push_warning(attribute, 'a11y-misplaced-role', 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 {import('aria-query').ARIARoleDefinitionKey} current_role */ (c_r);
 
					if (current_role && is_abstract_role(current_role)) {
						push_warning(attribute, 'a11y-no-abstract-role', current_role);
					} else if (current_role && !aria_roles.includes(current_role)) {
						const match = fuzzymatch(current_role, aria_roles);
						push_warning(attribute, 'a11y-unknown-role', 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)
					) {
						push_warning(attribute, 'a11y-no-redundant-roles', 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) {
							push_warning(attribute, 'a11y-no-redundant-roles', 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) {
								push_warning(
									attribute,
									'a11y-role-has-required-aria-props',
									current_role,
									required_role_props
								);
							}
						}
					}
 
					// 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) {
							push_warning(node, 'a11y-interactive-supports-focus', 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))
					) {
						push_warning(
							node,
							'a11y-no-interactive-element-to-noninteractive-role',
							current_role,
							node.name
						);
					}
 
					// 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
						)
					) {
						push_warning(
							node,
							'a11y-no-noninteractive-element-to-interactive-role',
							current_role,
							node.name
						);
					}
				}
			}
		}
 
		// no-access-key
		if (name === 'accesskey') {
			push_warning(attribute, 'a11y-accesskey');
		}
 
		// no-autofocus
		if (name === 'autofocus') {
			push_warning(attribute, 'a11y-autofocus');
		}
 
		// scope
		if (name === 'scope' && !is_dynamic_element && node.name !== 'th') {
			push_warning(attribute, 'a11y-misplaced-scope');
		}
 
		// 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) {
				push_warning(attribute, 'a11y-positive-tabindex');
			}
		}
	}
 
	const role = attribute_map.get('role');
	const role_static_value = /** @type {import('aria-query').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) {
				push_warning(node, 'a11y-click-events-have-key-events');
			}
		}
	}
 
	const role_value = /** @type {import('aria-query').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)) {
			push_warning(node, 'a11y-no-noninteractive-tabindex');
		}
	}
 
	// role-supports-aria-props
	if (typeof role_value === 'string' && roles_map.has(role_value)) {
		const { props } = /** @type {import('aria-query').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 {import('aria-query').ARIAProperty} */ (attr.name))
			) {
				push_warning(
					attr,
					'a11y-role-supports-aria-props',
					attr.name,
					role_value,
					is_implicit,
					node.name
				);
			}
		}
	}
 
	// 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) {
			push_warning(node, 'a11y-no-noninteractive-element-interactions', 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) {
			push_warning(node, 'a11y-no-static-element-interactions', node.name, interactive_handlers);
		}
	}
 
	if (handlers.has('mouseover') && !handlers.has('focus')) {
		push_warning(node, 'a11y-mouse-events-have-key-events', 'mouseover', 'focus');
	}
 
	if (handlers.has('mouseout') && !handlers.has('blur')) {
		push_warning(node, 'a11y-mouse-events-have-key-events', 'mouseout', 'blur');
	}
 
	// element-specific checks
	let contains_a11y_label = false;
 
	if (node.name === 'a') {
		const aria_label_attribute = attribute_map.get('aria-label');
		if (aria_label_attribute) {
			if (get_static_value(aria_label_attribute) !== '') {
				contains_a11y_label = true;
			}
		}
 
		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)) {
					push_warning(href, 'a11y-invalid-attribute', href.name, href_value);
				}
			}
		} else if (!has_spread) {
			const id_attribute = get_static_value(attribute_map.get('id'));
			const name_attribute = get_static_value(attribute_map.get('name'));
			if (!id_attribute && !name_attribute) {
				push_warning(...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) {
				push_warning(...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) {
				push_warning(...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)) {
				push_warning(autocomplete, 'a11y-autocomplete-valid', type_value, autocomplete_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)) {
				push_warning(node, 'a11y-img-redundant-alt');
			}
		}
	}
 
	if (node.name === 'label') {
		/** @param {import('#compiler').TemplateNode} node */
		const has_input_child = (node) => {
			let has = false;
			walk(
				node,
				{},
				{
					_(node, { next }) {
						if (
							node.type === 'SvelteElement' ||
							node.type === 'SlotElement' ||
							(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)) {
			push_warning(node, 'a11y-label-has-associated-control');
		}
	}
 
	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 {import('#compiler').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) {
			push_warning(node, 'a11y-media-has-caption');
		}
	}
 
	if (node.name === 'figcaption') {
		if (!is_parent(node.parent, ['figure'])) {
			push_warning(node, 'a11y-structure', true);
		}
	}
 
	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) {
			push_warning(children[index], 'a11y-structure', false);
		}
	}
 
	if (a11y_distracting_elements.includes(node.name)) {
		// no-distracting-elements
		push_warning(node, 'a11y-distracting-elements', node.name);
	}
 
	// Check content
	if (
		!contains_a11y_label &&
		!has_contenteditable_binding &&
		a11y_required_content.includes(node.name) &&
		node.fragment.nodes.length === 0
	) {
		push_warning(node, 'a11y-missing-content', node.name);
	}
}
 
/**
 * @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState>}
 */
export const a11y_validators = {
	RegularElement(node, context) {
		check_element(node, context.state, context.path);
	},
	SvelteElement(node, context) {
		check_element(node, context.state, context.path);
	}
};