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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
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
import { is_html, is_svg, is_void } from '../../../shared/utils/names.js';
import Node from './shared/Node.js';
import { walk } from 'estree-walker';
import Attribute from './Attribute.js';
import Binding from './Binding.js';
import EventHandler from './EventHandler.js';
import Transition from './Transition.js';
import Animation from './Animation.js';
import Action from './Action.js';
import Class from './Class.js';
import StyleDirective from './StyleDirective.js';
import Text from './Text.js';
import { namespaces } from '../../utils/namespaces.js';
import map_children from './shared/map_children.js';
import {
	is_name_contenteditable,
	get_contenteditable_attr,
	has_contenteditable_attr
} from '../utils/contenteditable.js';
import {
	regex_dimensions,
	regex_starts_with_newline,
	regex_non_whitespace_character,
	regex_box_size
} from '../../utils/patterns.js';
import fuzzymatch from '../../utils/fuzzymatch.js';
import list from '../../utils/list.js';
import hash from '../utils/hash.js';
import Let from './Let.js';
import Expression from './shared/Expression.js';
import { string_literal } from '../utils/stringify.js';
import compiler_warnings from '../compiler_warnings.js';
import compiler_errors from '../compiler_errors.js';
import { roles, aria } from 'aria-query';
import {
	is_interactive_element,
	is_non_interactive_element,
	is_non_interactive_roles,
	is_presentation_role,
	is_interactive_roles,
	is_hidden_from_screen_reader,
	is_semantic_role_element,
	is_abstract_role,
	is_static_element,
	has_disabled_attribute,
	is_valid_autocomplete
} from '../utils/a11y.js';

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(
		' '
	);
const aria_attribute_set = new Set(aria_attributes);
const aria_roles = roles.keys();
const aria_role_set = new Set(aria_roles);
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 = new Set(['blink', 'marquee']);
const a11y_required_content = new Set([
	// anchor-has-content
	'a',
	// heading-has-content
	'h1',
	'h2',
	'h3',
	'h4',
	'h5',
	'h6'
]);
const a11y_labelable = new Set([
	'button',
	'input',
	'keygen',
	'meter',
	'output',
	'progress',
	'select',
	'textarea'
]);
const a11y_interactive_handlers = new Set([
	// 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 = new Set([
	'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
 */
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 = new Set(['email', 'search', 'tel', 'text', 'url']);

/** @param {Map<string, import('./Attribute.js').default>} attribute_map */
function input_implicit_role(attribute_map) {
	const type_attribute = attribute_map.get('type');
	if (!type_attribute || !type_attribute.is_static) return;
	const type = /** @type {string} */ (type_attribute.get_static_value());
	const list_attribute_exists = attribute_map.has('list');
	if (list_attribute_exists && combobox_if_list.has(type)) {
		return 'combobox';
	}
	return input_type_to_implicit_role.get(type);
}

/** @param {Map<string, import('./Attribute.js').default>} attribute_map */
function menuitem_implicit_role(attribute_map) {
	const type_attribute = attribute_map.get('type');
	if (!type_attribute || !type_attribute.is_static) return;
	const type = /** @type {string} */ (type_attribute.get_static_value());
	return menuitem_type_to_implicit_role.get(type);
}

/**
 * @param {string} name
 * @param {Map<string, import('./Attribute.js').default>} attribute_map
 * @returns {string}
 */
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 = new Set(['meta', 'html', 'script', 'style']);
const valid_modifiers = new Set([
	'preventDefault',
	'stopPropagation',
	'stopImmediatePropagation',
	'capture',
	'once',
	'passive',
	'nonpassive',
	'self',
	'trusted'
]);
const passive_events = new Set(['wheel', 'touchstart', 'touchmove', 'touchend', 'touchcancel']);
const react_attributes = new Map([
	['className', 'class'],
	['htmlFor', 'for']
]);
const attributes_to_compact_whitespace = ['class', 'style'];

/**
 * @param {import('./interfaces.js').INode} parent
 * @param {string[]} elements
 */
function is_parent(parent, elements) {
	let check = false;
	while (parent) {
		const parent_name = /** @type {Element} */ (parent).name;
		if (elements.includes(parent_name)) {
			check = true;
			break;
		}
		if (parent.type === 'Element') {
			break;
		}
		parent = parent.parent;
	}
	return check;
}

/**
 * @param {Element} parent
 * @param {Element} element
 * @param {string} explicit_namespace
 */
function get_namespace(parent, element, explicit_namespace) {
	const parent_element = parent.find_nearest(/^Element/);
	if (!parent_element) {
		return explicit_namespace || (is_svg(element.name) ? namespaces.svg : null);
	}
	if (parent_element.namespace !== namespaces.foreign) {
		if (is_svg(element.name.toLowerCase())) return namespaces.svg;
		if (parent_element.name.toLowerCase() === 'foreignobject') return null;
	}
	return parent_element.namespace;
}

/**
 * @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_any_repeated_whitespaces).every((id) => typeof id === 'string')
			);
		case 'tokenlist': // if list of tokens, split each
			return (
				typeof value === 'string' &&
				value
					.split(regex_any_repeated_whitespaces)
					.every((token) => (schema.values || []).indexOf(token.toLowerCase()) > -1)
			);
		default:
			return false;
	}
}
const regex_any_repeated_whitespaces = /[\s]+/g;
const regex_heading_tags = /^h[1-6]$/;
const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/;

/** @extends Node<'Element'> */
export default class Element extends Node {
	/** @type {string} */
	name;

	/** @type {import('./shared/TemplateScope.js').default} */
	scope;

	/** @type {import('./Action.js').default[]} */
	actions = [];

	/** @type {import('./Binding.js').default[]} */
	bindings = [];

	/** @type {import('./Class.js').default[]} */
	classes = [];

	/** @type {import('./StyleDirective.js').default[]} */
	styles = [];

	/** @type {import('./EventHandler.js').default[]} */
	handlers = [];

	/** @type {import('./Let.js').default[]} */
	lets = [];

	/** @type {import('./Transition.js').default} */
	intro = null;

	/** @type {import('./Transition.js').default} */
	outro = null;

	/** @type {import('./Animation.js').default} */
	animation = null;

	/** @type {import('./interfaces.js').INode[]} */
	children;

	/** @type {string} */
	namespace;

	/** @type {boolean} */
	needs_manual_style_scoping;

	/** @type {import('./shared/Expression.js').default} */
	tag_expr;

	/** @type {boolean} */
	contains_a11y_label;
	get is_dynamic_element() {
		return this.name === 'svelte:element';
	}

	/**
	 * @param {import('../Component.js').default} component
	 * @param {import('./shared/Node.js').default} parent
	 * @param {import('./shared/TemplateScope.js').default} scope
	 * @param {any} info
	 */
	constructor(component, parent, scope, info) {
		super(component, parent, scope, info);
		this.name = info.name;
		if (info.name === 'svelte:element') {
			if (typeof info.tag !== 'string') {
				this.tag_expr = new Expression(component, this, scope, info.tag);
			} else {
				this.tag_expr = new Expression(
					component,
					this,
					scope,
					/** @type {import('estree').Literal} */ (string_literal(info.tag))
				);
				this.name = info.tag;
			}
		} else {
			this.tag_expr = new Expression(
				component,
				this,
				scope,
				/** @type {import('estree').Literal} */ (string_literal(this.name))
			);
		}
		this.namespace = get_namespace(/** @type {Element} */ (parent), this, component.namespace);
		if (this.namespace !== namespaces.foreign) {
			if (this.name === 'pre' || this.name === 'textarea') {
				const first = info.children[0];
				if (first && first.type === 'Text') {
					// The leading newline character needs to be stripped because of a quirk,
					// it is ignored by browsers if the tag and its contents are set through
					// innerHTML (NOT if set through the innerHTML of the tag or dynamically).
					// Therefore strip it here but add it back in the appropriate
					// places if there's another newline afterwards.
					// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
					// see https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
					first.data = first.data.replace(regex_starts_with_newline, '');
				}
			}
			if (this.name === 'textarea') {
				if (info.children.length > 0) {
					const value_attribute = get_value_attribute(info.attributes);
					if (value_attribute) {
						component.error(value_attribute, compiler_errors.textarea_duplicate_value);
						return;
					}
					// this is an egregious hack, but it's the easiest way to get <textarea>
					// children treated the same way as a value attribute
					info.attributes.push({
						type: 'Attribute',
						name: 'value',
						value: info.children
					});
					info.children = [];
				}
			}
			if (this.name === 'option') {
				// Special case — treat these the same way:
				//   <option>{foo}</option>
				//   <option value={foo}>{foo}</option>
				const value_attribute = get_value_attribute(info.attributes);
				if (!value_attribute) {
					info.attributes.push({
						type: 'Attribute',
						name: 'value',
						value: info.children,
						synthetic: true
					});
				}
			}
		}
		const has_let = info.attributes.some((node) => node.type === 'Let');
		if (has_let) {
			scope = scope.child();
		}
		// Binding relies on Attribute, defer its evaluation
		const order = ['Binding']; // everything else is -1
		info.attributes.sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type));
		info.attributes.forEach((node) => {
			switch (node.type) {
				case 'Action':
					this.actions.push(new Action(component, this, scope, node));
					break;
				case 'Attribute':
				case 'Spread':
					// special case
					if (node.name === 'xmlns') this.namespace = node.value[0].data;
					this.attributes.push(new Attribute(component, this, scope, node));
					break;
				case 'Binding':
					this.bindings.push(new Binding(component, this, scope, node));
					break;
				case 'Class':
					this.classes.push(new Class(component, this, scope, node));
					break;
				case 'StyleDirective':
					this.styles.push(new StyleDirective(component, this, scope, node));
					break;
				case 'EventHandler':
					this.handlers.push(new EventHandler(component, this, scope, node));
					break;
				case 'Let': {
					const l = new Let(component, this, scope, node);
					this.lets.push(l);
					const dependencies = new Set([l.name.name]);
					l.names.forEach((name) => {
						scope.add(name, dependencies, this);
					});
					break;
				}
				case 'Transition': {
					const transition = new Transition(component, this, scope, node);
					if (node.intro) this.intro = transition;
					if (node.outro) this.outro = transition;
					break;
				}
				case 'Animation':
					this.animation = new Animation(component, this, scope, node);
					break;
				default:
					throw new Error(`Not implemented: ${node.type}`);
			}
		});
		this.scope = scope;
		this.children = map_children(component, this, this.scope, info.children);
		this.validate();
		this.optimise();
		component.apply_stylesheet(this);
		if (this.parent) {
			if (
				this.actions.length > 0 ||
				this.animation ||
				this.bindings.length > 0 ||
				this.classes.length > 0 ||
				this.intro ||
				this.outro ||
				this.handlers.length > 0 ||
				this.styles.length > 0 ||
				this.name === 'option' ||
				this.is_dynamic_element ||
				this.tag_expr.dynamic_dependencies().length ||
				component.compile_options.dev
			) {
				this.parent.cannot_use_innerhtml(); // need to use add_location
				this.parent.not_static_content();
			}
		}
	}
	validate() {
		if (
			this.component.var_lookup.has(this.name) &&
			this.component.var_lookup.get(this.name).imported &&
			!is_svg(this.name) &&
			!is_html(this.name)
		) {
			this.component.warn(this, compiler_warnings.component_name_lowercase(this.name));
		}
		this.validate_attributes();
		this.validate_event_handlers();
		if (this.namespace === namespaces.foreign) {
			this.validate_bindings_foreign();
		} else {
			this.validate_attributes_a11y();
			this.validate_special_cases();
			this.validate_bindings();
			this.validate_content();
		}
	}
	validate_attributes() {
		const { component, parent } = this;
		this.attributes.forEach((attribute) => {
			if (attribute.is_spread) return;
			const name = attribute.name.toLowerCase();
			// Errors
			if (regex_illegal_attribute_character.test(name)) {
				return component.error(attribute, compiler_errors.illegal_attribute(name));
			}
			if (name === 'slot') {
				if (!attribute.is_static) {
					return component.error(attribute, compiler_errors.invalid_slot_attribute);
				}
				if (component.slot_outlets.has(name)) {
					return component.error(attribute, compiler_errors.duplicate_slot_attribute(name));
					// this code was unreachable. Still needed?
					// component.slot_outlets.add(name);
				}
				if (!(parent.type === 'SlotTemplate' || within_custom_element(parent))) {
					return component.error(attribute, compiler_errors.invalid_slotted_content);
				}
			}
			// Warnings
			if (this.namespace !== namespaces.foreign) {
				if (name === 'is') {
					component.warn(attribute, compiler_warnings.avoid_is);
				}
				if (react_attributes.has(attribute.name)) {
					component.warn(
						attribute,
						compiler_warnings.invalid_html_attribute(
							attribute.name,
							react_attributes.get(attribute.name)
						)
					);
				}
			}
		});
	}
	validate_attributes_a11y() {
		const { component, attributes, handlers } = this;
		const attribute_map = new Map();
		const handlers_map = new Map();
		attributes.forEach((attribute) => attribute_map.set(attribute.name, attribute));
		handlers.forEach((handler) => handlers_map.set(handler.name, handler));
		attributes.forEach((attribute) => {
			if (attribute.is_spread) return;
			const name = attribute.name.toLowerCase();
			// aria-props
			if (name.startsWith('aria-')) {
				if (invisible_elements.has(this.name)) {
					// aria-unsupported-elements
					component.warn(attribute, compiler_warnings.a11y_aria_attributes(this.name));
				}
				const type = name.slice(5);
				if (!aria_attribute_set.has(type)) {
					const match = fuzzymatch(type, aria_attributes);
					component.warn(attribute, compiler_warnings.a11y_unknown_aria_attribute(type, match));
				}
				if (name === 'aria-hidden' && regex_heading_tags.test(this.name)) {
					component.warn(attribute, compiler_warnings.a11y_hidden(this.name));
				}
				// aria-proptypes
				let value = attribute.get_static_value();
				if (value === 'true') value = true;
				if (value === 'false') value = false;
				if (
					value !== null &&
					value !== undefined &&
					aria.has(/** @type {import('aria-query').ARIAProperty} */ (name))
				) {
					const schema = aria.get(/** @type {import('aria-query').ARIAProperty} */ (name));
					if (!is_valid_aria_attribute_value(schema, value)) {
						component.warn(
							attribute,
							compiler_warnings.a11y_incorrect_attribute_type(schema, name)
						);
					}
				}
				// aria-activedescendant-has-tabindex
				if (
					name === 'aria-activedescendant' &&
					!this.is_dynamic_element &&
					!is_interactive_element(this.name, attribute_map) &&
					!attribute_map.has('tabindex')
				) {
					component.warn(attribute, compiler_warnings.a11y_aria_activedescendant_has_tabindex);
				}
			}
			// aria-role
			if (name === 'role') {
				if (invisible_elements.has(this.name)) {
					// aria-unsupported-elements
					component.warn(attribute, compiler_warnings.a11y_misplaced_role(this.name));
				}
				const value = attribute.get_static_value();
				if (typeof value === 'string') {
					value.split(regex_any_repeated_whitespaces).forEach(
						/** @param {import('aria-query').ARIARoleDefinitionKey} current_role */ (
							current_role
						) => {
							if (current_role && is_abstract_role(current_role)) {
								component.warn(attribute, compiler_warnings.a11y_no_abstract_role(current_role));
							} else if (current_role && !aria_role_set.has(current_role)) {
								const match = fuzzymatch(current_role, aria_roles);
								component.warn(attribute, compiler_warnings.a11y_unknown_role(current_role, match));
							}
							// no-redundant-roles
							if (
								current_role === get_implicit_role(this.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(this.name)
							) {
								component.warn(attribute, compiler_warnings.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(this.parent, ['section', 'article']);
							if (!is_parent_section_or_article) {
								const has_nested_redundant_role =
									current_role === a11y_nested_implicit_semantics.get(this.name);
								if (has_nested_redundant_role) {
									component.warn(
										attribute,
										compiler_warnings.a11y_no_redundant_roles(current_role)
									);
								}
							}
							// role-has-required-aria-props
							if (
								!this.is_dynamic_element &&
								!is_semantic_role_element(current_role, this.name, attribute_map)
							) {
								const role = roles.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) {
										component.warn(
											attribute,
											compiler_warnings.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(this.name, attribute_map) &&
								!is_presentation_role(current_role) &&
								is_interactive_roles(current_role) &&
								is_static_element(this.name, attribute_map) &&
								!attribute_map.get('tabindex')
							) {
								const has_interactive_handlers = handlers.some((handler) =>
									a11y_interactive_handlers.has(handler.name)
								);
								if (has_interactive_handlers) {
									component.warn(
										this,
										compiler_warnings.a11y_interactive_supports_focus(current_role)
									);
								}
							}
							// no-interactive-element-to-noninteractive-role
							if (
								is_interactive_element(this.name, attribute_map) &&
								(is_non_interactive_roles(current_role) || is_presentation_role(current_role))
							) {
								component.warn(
									this,
									compiler_warnings.a11y_no_interactive_element_to_noninteractive_role(
										current_role,
										this.name
									)
								);
							}
							// no-noninteractive-element-to-interactive-role
							if (
								is_non_interactive_element(this.name, attribute_map) &&
								is_interactive_roles(current_role) &&
								!a11y_non_interactive_element_to_interactive_role_exceptions[this.name]?.includes(
									current_role
								)
							) {
								component.warn(
									this,
									compiler_warnings.a11y_no_noninteractive_element_to_interactive_role(
										current_role,
										this.name
									)
								);
							}
						}
					);
				}
			}
			// no-access-key
			if (name === 'accesskey') {
				component.warn(attribute, compiler_warnings.a11y_accesskey);
			}
			// no-autofocus
			if (name === 'autofocus') {
				component.warn(attribute, compiler_warnings.a11y_autofocus);
			}
			// scope
			if (name === 'scope' && !this.is_dynamic_element && this.name !== 'th') {
				component.warn(attribute, compiler_warnings.a11y_misplaced_scope);
			}
			// tabindex-no-positive
			if (name === 'tabindex') {
				const value = attribute.get_static_value();
				// @ts-ignore todo is tabindex=true correct case?
				if (!isNaN(value) && +value > 0) {
					component.warn(attribute, compiler_warnings.a11y_positive_tabindex);
				}
			}
		});
		// click-events-have-key-events
		if (handlers_map.has('click')) {
			const role = attribute_map.get('role');
			const is_non_presentation_role =
				role?.is_static &&
				!is_presentation_role(
					/** @type {import('aria-query').ARIARoleDefinitionKey} */ (role.get_static_value())
				);
			if (
				!this.is_dynamic_element &&
				!is_hidden_from_screen_reader(this.name, attribute_map) &&
				(!role || is_non_presentation_role) &&
				!is_interactive_element(this.name, attribute_map) &&
				!this.attributes.find((attr) => attr.is_spread)
			) {
				const has_key_event =
					handlers_map.has('keydown') || handlers_map.has('keyup') || handlers_map.has('keypress');
				if (!has_key_event) {
					component.warn(this, compiler_warnings.a11y_click_events_have_key_events);
				}
			}
		}
		const role = attribute_map.get('role');
		const role_static_value = /** @type {import('aria-query').ARIARoleDefinitionKey} */ (
			role?.get_static_value()
		);
		const role_value = /** @type {import('aria-query').ARIARoleDefinitionKey} */ (
			role ? role_static_value : get_implicit_role(this.name, attribute_map)
		);
		// no-noninteractive-tabindex
		if (
			!this.is_dynamic_element &&
			!is_interactive_element(this.name, attribute_map) &&
			!is_interactive_roles(role_static_value)
		) {
			const tab_index = attribute_map.get('tabindex');
			if (tab_index && (!tab_index.is_static || Number(tab_index.get_static_value()) >= 0)) {
				component.warn(this, compiler_warnings.a11y_no_noninteractive_tabindex);
			}
		}
		// role-supports-aria-props
		if (typeof role_value === 'string' && roles.has(role_value)) {
			const { props } = roles.get(role_value);
			const invalid_aria_props = new Set(aria.keys().filter((attribute) => !(attribute in props)));
			const is_implicit = role_value && role === undefined;
			attributes
				.filter((prop) => prop.type !== 'Spread')
				.forEach((prop) => {
					if (
						invalid_aria_props.has(/** @type {import('aria-query').ARIAProperty} */ (prop.name))
					) {
						component.warn(
							prop,
							compiler_warnings.a11y_role_supports_aria_props(
								prop.name,
								role_value,
								is_implicit,
								this.name
							)
						);
					}
				});
		}
		// no-noninteractive-element-interactions
		if (
			!has_contenteditable_attr(this) &&
			!is_hidden_from_screen_reader(this.name, attribute_map) &&
			!is_presentation_role(role_static_value) &&
			((!is_interactive_element(this.name, attribute_map) &&
				is_non_interactive_roles(role_static_value)) ||
				(is_non_interactive_element(this.name, attribute_map) && !role))
		) {
			const has_interactive_handlers = handlers.some((handler) =>
				a11y_recommended_interactive_handlers.has(handler.name)
			);
			if (has_interactive_handlers) {
				component.warn(
					this,
					compiler_warnings.a11y_no_noninteractive_element_interactions(this.name)
				);
			}
		}
		const has_dynamic_role = attribute_map.get('role') && !attribute_map.get('role').is_static;
		// no-static-element-interactions
		if (
			!has_dynamic_role &&
			!is_hidden_from_screen_reader(this.name, attribute_map) &&
			!is_presentation_role(role_static_value) &&
			!is_interactive_element(this.name, attribute_map) &&
			!is_interactive_roles(role_static_value) &&
			!is_non_interactive_element(this.name, attribute_map) &&
			!is_non_interactive_roles(role_static_value) &&
			!is_abstract_role(role_static_value)
		) {
			const interactive_handlers = handlers
				.map((handler) => handler.name)
				.filter((handler_name) => a11y_interactive_handlers.has(handler_name));
			if (interactive_handlers.length > 0) {
				component.warn(
					this,
					compiler_warnings.a11y_no_static_element_interactions(this.name, interactive_handlers)
				);
			}
		}
	}
	validate_special_cases() {
		const { component, attributes, handlers } = this;
		const attribute_map = new Map();
		const handlers_map = new Map();
		attributes.forEach((attribute) => attribute_map.set(attribute.name, attribute));
		handlers.forEach((handler) => handlers_map.set(handler.name, handler));
		if (this.name === 'a') {
			const href_attribute = attribute_map.get('href') || attribute_map.get('xlink:href');
			const id_attribute = attribute_map.get('id');
			const name_attribute = attribute_map.get('name');
			const target_attribute = attribute_map.get('target');
			const aria_label_attribute = attribute_map.get('aria-label');
			// links with target="_blank" should have noopener or noreferrer: https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener/
			// modern browsers add noopener by default, so we only need to check legacy browsers
			// legacy browsers don't support noopener so we only check for noreferrer there
			if (
				component.compile_options.legacy &&
				target_attribute &&
				target_attribute.get_static_value() === '_blank' &&
				href_attribute
			) {
				const href_static_value = href_attribute.get_static_value()
					? href_attribute.get_static_value().toLowerCase()
					: null;
				if (href_static_value === null || href_static_value.match(/^(https?:)?\/\//i)) {
					const rel = attribute_map.get('rel');
					if (rel == null || rel.is_static) {
						const rel_values = rel
							? rel.get_static_value().split(regex_any_repeated_whitespaces)
							: [];
						if (!rel || !rel_values.includes('noreferrer')) {
							component.warn(this, {
								code: 'security-anchor-rel-noreferrer',
								message:
									'Security: Anchor with "target=_blank" should have rel attribute containing the value "noreferrer"'
							});
						}
					}
				}
			}
			if (aria_label_attribute) {
				const aria_value = aria_label_attribute.get_static_value();
				if (aria_value != '') {
					this.contains_a11y_label = true;
				}
			}
			if (href_attribute) {
				const href_value = href_attribute.get_static_value();
				if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
					component.warn(
						href_attribute,
						compiler_warnings.a11y_invalid_attribute(href_attribute.name, href_value)
					);
				}
			} else {
				const id_attribute_valid = id_attribute && id_attribute.get_static_value() !== '';
				const name_attribute_valid = name_attribute && name_attribute.get_static_value() !== '';
				if (!id_attribute_valid && !name_attribute_valid) {
					component.warn(this, compiler_warnings.a11y_missing_attribute('a', 'an', 'href'));
				}
			}
		} else {
			const required_attributes = a11y_required_attributes[this.name];
			if (required_attributes) {
				const has_attribute = required_attributes.some((name) => attribute_map.has(name));
				if (!has_attribute) {
					should_have_attribute(this, required_attributes);
				}
			}
		}
		if (this.name === 'input') {
			const type = attribute_map.get('type');
			if (type && type.get_static_value() === 'image') {
				const required_attributes = ['alt', 'aria-label', 'aria-labelledby'];
				const has_attribute = required_attributes.some((name) => attribute_map.has(name));
				if (!has_attribute) {
					should_have_attribute(this, required_attributes, 'input type="image"');
				}
			}
			// autocomplete-valid
			const autocomplete = attribute_map.get('autocomplete');
			if (type && autocomplete) {
				const type_value = type.get_static_value();
				const autocomplete_value = autocomplete.get_static_value();
				if (!is_valid_autocomplete(autocomplete_value)) {
					component.warn(
						autocomplete,
						compiler_warnings.a11y_autocomplete_valid(type_value, autocomplete_value)
					);
				}
			}
		}
		if (this.name === 'img') {
			const alt_attribute = attribute_map.get('alt');
			const aria_hidden_attribute = attribute_map.get('aria-hidden');
			const aria_hidden_exist = aria_hidden_attribute && aria_hidden_attribute.get_static_value();
			if (alt_attribute && !aria_hidden_exist) {
				const alt_value = alt_attribute.get_static_value();
				if (/\b(image|picture|photo)\b/i.test(alt_value)) {
					component.warn(this, compiler_warnings.a11y_img_redundant_alt);
				}
			}
		}
		if (this.name === 'label') {
			/** @param {import('./interfaces.js').INode[]} children */
			const has_input_child = (children) => {
				if (
					children.some(
						(child) =>
							child instanceof Element && (a11y_labelable.has(child.name) || child.name === 'slot')
					)
				) {
					return true;
				}
				for (const child of children) {
					if (!('children' in child) || child.children.length === 0) {
						continue;
					}
					if (has_input_child(child.children)) {
						return true;
					}
				}
				return false;
			};
			if (!attribute_map.has('for') && !has_input_child(this.children)) {
				component.warn(this, compiler_warnings.a11y_label_has_associated_control);
			}
		}
		if (this.name === 'video') {
			const aria_hidden_attribute = attribute_map.get('aria-hidden');
			const aria_hidden_exist = aria_hidden_attribute && aria_hidden_attribute.get_static_value();
			if (attribute_map.has('muted') || aria_hidden_exist === 'true') {
				return;
			}
			let has_caption;
			const track = this.children.find(/** @param {Element} i */ (i) => i.name === 'track');
			if (track) {
				has_caption = track.attributes.find(
					(a) => a.name === 'kind' && a.get_static_value() === 'captions'
				);
			}
			if (!has_caption) {
				component.warn(this, compiler_warnings.a11y_media_has_caption);
			}
		}
		if (a11y_distracting_elements.has(this.name)) {
			// no-distracting-elements
			component.warn(this, compiler_warnings.a11y_distracting_elements(this.name));
		}
		if (this.name === 'figcaption') {
			let { parent } = this;
			let is_figure_parent = false;
			while (parent) {
				if (/** @type {Element} */ (parent).name === 'figure') {
					is_figure_parent = true;
					break;
				}
				if (parent.type === 'Element') {
					break;
				}
				parent = parent.parent;
			}
			if (!is_figure_parent) {
				component.warn(this, compiler_warnings.a11y_structure_immediate);
			}
		}
		if (this.name === 'figure') {
			const children = this.children.filter((node) => {
				if (node.type === 'Comment') return false;
				if (node.type === 'Text') return regex_non_whitespace_character.test(node.data);
				return true;
			});
			const index = children.findIndex(
				(child) => /** @type {Element} */ (child).name === 'figcaption'
			);
			if (index !== -1 && index !== 0 && index !== children.length - 1) {
				component.warn(children[index], compiler_warnings.a11y_structure_first_or_last);
			}
		}
		if (handlers_map.has('mouseover') && !handlers_map.has('focus')) {
			component.warn(
				this,
				compiler_warnings.a11y_mouse_events_have_key_events('mouseover', 'focus')
			);
		}
		if (handlers_map.has('mouseout') && !handlers_map.has('blur')) {
			component.warn(this, compiler_warnings.a11y_mouse_events_have_key_events('mouseout', 'blur'));
		}
	}
	validate_bindings_foreign() {
		this.bindings.forEach((binding) => {
			if (binding.name !== 'this') {
				return this.component.error(binding, compiler_errors.invalid_binding_foreign(binding.name));
			}
		});
	}
	validate_bindings() {
		const { component } = this;
		const check_type_attribute = () => {
			const attribute = this.attributes.find(
				/** @param {import('./Attribute.js').default} attribute */ (attribute) =>
					attribute.name === 'type'
			);
			if (!attribute) return null;
			if (!attribute.is_static) {
				return component.error(attribute, compiler_errors.invalid_type);
			}
			const value = attribute.get_static_value();
			if (value === true) {
				return component.error(attribute, compiler_errors.missing_type);
			}
			return value;
		};
		this.bindings.forEach((binding) => {
			const { name } = binding;
			if (name === 'value') {
				if (this.name !== 'input' && this.name !== 'textarea' && this.name !== 'select') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_elements(this.name, 'value')
					);
				}
				if (this.name === 'select') {
					const attribute = this.attributes.find(
						/** @param {import('./Attribute.js').default} attribute */
						(attribute) => attribute.name === 'multiple'
					);
					if (attribute && !attribute.is_static) {
						return component.error(attribute, compiler_errors.dynamic_multiple_attribute);
					}
				} else {
					check_type_attribute();
				}
			} else if (name === 'checked' || name === 'indeterminate') {
				if (this.name !== 'input') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_elements(this.name, name)
					);
				}
				const type = check_type_attribute();
				if (type !== 'checkbox') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_no_checkbox(name, type === 'radio')
					);
				}
			} else if (name === 'group') {
				if (this.name !== 'input') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_elements(this.name, 'group')
					);
				}
				const type = check_type_attribute();
				if (type !== 'checkbox' && type !== 'radio') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with(
							'<input type="checkbox"> or <input type="radio">',
							'group'
						)
					);
				}
			} else if (name === 'files') {
				if (this.name !== 'input') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_elements(this.name, 'files')
					);
				}
				const type = check_type_attribute();
				if (type !== 'file') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with('<input type="file">', 'files')
					);
				}
			} else if (name === 'open') {
				if (this.name !== 'details') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with('<details>', name)
					);
				}
			} else if (
				name === 'currentTime' ||
				name === 'duration' ||
				name === 'paused' ||
				name === 'buffered' ||
				name === 'seekable' ||
				name === 'played' ||
				name === 'volume' ||
				name === 'muted' ||
				name === 'playbackRate' ||
				name === 'seeking' ||
				name === 'ended' ||
				name === 'readyState'
			) {
				if (this.name !== 'audio' && this.name !== 'video') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with('audio> or <video>', name)
					);
				}
			} else if (name === 'videoHeight' || name === 'videoWidth') {
				if (this.name !== 'video') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with('<video>', name)
					);
				}
			} else if (regex_dimensions.test(name)) {
				if (this.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
					return component.error(
						binding,
						compiler_errors.invalid_binding_on(
							binding.name,
							`<svg>. Use '${name.replace('offset', 'client')}' instead`
						)
					);
				} else if (is_svg(this.name)) {
					return component.error(
						binding,
						compiler_errors.invalid_binding_on(binding.name, 'SVG elements')
					);
				} else if (is_void(this.name)) {
					return component.error(
						binding,
						compiler_errors.invalid_binding_on(
							binding.name,
							`void elements like <${this.name}>. Use a wrapper element instead`
						)
					);
				}
			} else if (name === 'naturalWidth' || name === 'naturalHeight') {
				if (this.name !== 'img') {
					return component.error(
						binding,
						compiler_errors.invalid_binding_element_with('<img>', name)
					);
				}
			} else if (is_name_contenteditable(name)) {
				const contenteditable = get_contenteditable_attr(this);
				if (!contenteditable) {
					return component.error(binding, compiler_errors.missing_contenteditable_attribute);
				} else if (contenteditable && !contenteditable.is_static) {
					return component.error(
						contenteditable,
						compiler_errors.dynamic_contenteditable_attribute
					);
				}
			} else if (name !== 'this' && !regex_box_size.test(name)) {
				return component.error(binding, compiler_errors.invalid_binding(binding.name));
			}
		});
	}
	validate_content() {
		if (!a11y_required_content.has(this.name)) return;
		if (this.contains_a11y_label) return;
		if (this.bindings.some((binding) => ['textContent', 'innerHTML'].includes(binding.name)))
			return;
		if (this.children.length === 0) {
			this.component.warn(this, compiler_warnings.a11y_missing_content(this.name));
		}
	}
	validate_event_handlers() {
		const { component } = this;
		this.handlers.forEach((handler) => {
			if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) {
				return component.error(
					handler,
					compiler_errors.invalid_event_modifier_combination('passive', 'preventDefault')
				);
			}
			if (handler.modifiers.has('passive') && handler.modifiers.has('nonpassive')) {
				return component.error(
					handler,
					compiler_errors.invalid_event_modifier_combination('passive', 'nonpassive')
				);
			}
			handler.modifiers.forEach((modifier) => {
				if (!valid_modifiers.has(modifier)) {
					return component.error(
						handler,
						compiler_errors.invalid_event_modifier(list(Array.from(valid_modifiers)))
					);
				}
				if (modifier === 'passive') {
					if (passive_events.has(handler.name)) {
						if (handler.can_make_passive) {
							component.warn(handler, compiler_warnings.redundant_event_modifier_for_touch);
						}
					} else {
						component.warn(handler, compiler_warnings.redundant_event_modifier_passive);
					}
				}
				if (component.compile_options.legacy && (modifier === 'once' || modifier === 'passive')) {
					// TODO this could be supported, but it would need a few changes to
					// how event listeners work
					return component.error(handler, compiler_errors.invalid_event_modifier_legacy(modifier));
				}
			});
			if (
				passive_events.has(handler.name) &&
				handler.can_make_passive &&
				!handler.modifiers.has('preventDefault') &&
				!handler.modifiers.has('nonpassive')
			) {
				// touch/wheel events should be passive by default
				handler.modifiers.add('passive');
			}
		});
	}
	is_media_node() {
		return this.name === 'audio' || this.name === 'video';
	}
	add_css_class() {
		if (this.attributes.some((attr) => attr.is_spread)) {
			this.needs_manual_style_scoping = true;
			return;
		}
		const { id } = this.component.stylesheet;
		const class_attribute = this.attributes.find((a) => a.name === 'class');
		if (class_attribute && !class_attribute.is_true) {
			if (class_attribute.chunks.length === 1 && class_attribute.chunks[0].type === 'Text') {
				/** @type {import('./Text.js').default} */ (class_attribute.chunks[0]).data += ` ${id}`;
			} else {
				/** @type {import('./shared/Node.js').default[]} */ (class_attribute.chunks).push(
					new Text(
						this.component,
						this,
						this.scope,
						/** @type {any} */ ({
							type: 'Text',
							data: ` ${id}`,
							synthetic: true
						})
					)
				);
			}
		} else {
			this.attributes.push(
				new Attribute(
					this.component,
					this,
					this.scope,
					/** @type {any} */ ({
						type: 'Attribute',
						name: 'class',
						value: [{ type: 'Text', data: id, synthetic: true }]
					})
				)
			);
		}
	}
	get slot_template_name() {
		return /** @type {string} */ (
			this.attributes.find((attribute) => attribute.name === 'slot').get_static_value()
		);
	}
	optimise() {
		attributes_to_compact_whitespace.forEach((attribute_name) => {
			const attribute = this.attributes.find((a) => a.name === attribute_name);
			if (attribute && !attribute.is_true) {
				attribute.chunks.forEach((chunk, index) => {
					if (chunk.type === 'Text') {
						let data = chunk.data.replace(regex_any_repeated_whitespaces, ' ');
						if (index === 0) {
							data = data.trimLeft();
						} else if (index === attribute.chunks.length - 1) {
							data = data.trimRight();
						}
						chunk.data = data;
					}
				});
			}
		});
	}
	get can_use_textcontent() {
		return (
			this.is_static_content &&
			this.children.every((node) => node.type === 'Text' || node.type === 'MustacheTag')
		);
	}
	get can_optimise_to_html_string() {
		const can_use_textcontent = this.can_use_textcontent;
		const is_template_with_text_content = this.name === 'template' && can_use_textcontent;
		return (
			!is_template_with_text_content &&
			!this.namespace &&
			(this.can_use_innerhtml || can_use_textcontent) &&
			this.children.length > 0
		);
	}
	get can_optimise_hydration() {
		// In contrast to normal html string optimization, we also bail in case of mustache tags even
		// if they seem to contain static content. This is because we cannot know whether that static
		// value is different between client and server builds, e.g. {browser ? 'hi' : 'bye'} which
		// becomes {'hi'} and {'bye'} respectively.
		const is_static_text_content =
			this.is_static_content && this.children.every((node) => node.type === 'Text');
		return this.can_optimise_to_html_string && (this.can_use_innerhtml || is_static_text_content);
	}
	hash() {
		return `svelte-${hash(this.component.source.slice(this.start, this.end))}`;
	}
}
const regex_starts_with_vowel = /^[aeiou]/;

/**
 * @param {any} node
 * @param {string[]} attributes
 * @param {any} name
 */
function should_have_attribute(node, attributes, name = node.name) {
	const article = regex_starts_with_vowel.test(attributes[0]) ? 'an' : 'a';
	const sequence =
		attributes.length > 1
			? attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}`
			: attributes[0];
	node.component.warn(node, compiler_warnings.a11y_missing_attribute(name, article, sequence));
}
const regex_minus_sign = /-/;

/** @param {import('./interfaces.js').INode} parent */
function within_custom_element(parent) {
	while (parent) {
		if (parent.type === 'InlineComponent') return false;
		if (parent.type === 'Element') {
			if (regex_minus_sign.test(parent.name) || parent.is_dynamic_element) return true;
		}
		parent = parent.parent;
	}
	return false;
}

/**
 * @param {any[]} attributes
 */
function get_value_attribute(attributes) {
	let node_value;
	attributes.forEach((node) => {
		if (node.type !== 'Spread' && node.name.toLowerCase() === 'value') {
			node_value = node;
		}
		if (node.type === 'Spread') {
			walk(/** @type {any} */ (node.expression), {
				enter(/** @type {import('estree').Node} */ node) {
					if (node_value) {
						this.skip();
					}
					if (node.type === 'Identifier') {
						if (/** @type {import('estree').Identifier} */ (node).name.toLowerCase() === 'value') {
							node_value = node;
						}
					}
				}
			});
		}
	});
	return node_value;
}