import isVoidElementName from '../../utils/isVoidElementName'; import Node from './shared/Node'; import Attribute from './Attribute'; import Binding from './Binding'; import EventHandler from './EventHandler'; import Transition from './Transition'; import Animation from './Animation'; import Action from './Action'; import Class from './Class'; import Text from './Text'; import { namespaces } from '../../utils/namespaces'; import mapChildren from './shared/mapChildren'; import { dimensions } from '../../utils/patterns'; import fuzzymatch from '../../utils/fuzzymatch'; import list from '../../utils/list'; import Let from './Let'; import TemplateScope from './shared/TemplateScope'; const svg = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/; const ariaAttributes = 'activedescendant atomic autocomplete busy checked controls current describedby 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 selected setsize sort valuemax valuemin valuenow valuetext'.split(' '); const ariaAttributeSet = new Set(ariaAttributes); const ariaRoles = 'alert alertdialog application article banner button cell checkbox columnheader combobox command complementary composite contentinfo definition dialog directory document feed figure form grid gridcell group heading img input landmark link list listbox listitem log main marquee math menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option presentation progressbar radio radiogroup range region roletype row rowgroup rowheader scrollbar search searchbox section sectionhead select separator slider spinbutton status structure switch tab table tablist tabpanel term textbox timer toolbar tooltip tree treegrid treeitem widget window'.split(' '); const ariaRoleSet = new Set(ariaRoles); const a11yRequiredAttributes = { 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 a11yDistractingElements = new Set([ 'blink', 'marquee' ]); const a11yRequiredContent = new Set([ // anchor-has-content 'a', // heading-has-content 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]) const invisibleElements = new Set(['meta', 'html', 'script', 'style']); const validModifiers = new Set([ 'preventDefault', 'stopPropagation', 'capture', 'once', 'passive' ]); const passiveEvents = new Set([ 'wheel', 'touchstart', 'touchmove', 'touchend', 'touchcancel' ]); export default class Element extends Node { type: 'Element'; name: string; scope: TemplateScope; attributes: Attribute[] = []; actions: Action[] = []; bindings: Binding[] = []; classes: Class[] = []; handlers: EventHandler[] = []; lets: Let[] = []; intro?: Transition = null; outro?: Transition = null; animation?: Animation = null; children: Node[]; namespace: string; constructor(component, parent, scope, info: any) { super(component, parent, scope, info); this.name = info.name; this.scope = scope; const parentElement = parent.findNearest(/^Element/); this.namespace = this.name === 'svg' ? namespaces.svg : parentElement ? parentElement.namespace : this.component.namespace; if (!this.namespace && svg.test(this.name)) { this.component.warn(this, { code: `missing-namespace`, message: `<${this.name}> is an SVG element – did you forget to add { namespace: 'svg' } ?` }); } if (this.name === 'textarea') { if (info.children.length > 0) { const valueAttribute = info.attributes.find(node => node.name === 'value'); if (valueAttribute) { component.error(valueAttribute, { code: `textarea-duplicate-value`, message: `A