import * as namespaces from '../../utils/namespaces.js';
import validateElement from './validateElement.js';
import validateWindow from './validateWindow.js';

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|title|tref|tspan|unknown|use|view|vkern)$/;

const meta = {
	':Window': validateWindow
};

export default function validateHtml ( validator, html ) {
	let elementDepth = 0;

	function visit ( node ) {
		if ( node.type === 'Element' ) {
			if ( elementDepth === 0 && validator.namespace !== namespaces.svg && svg.test( node.name ) ) {
				validator.warn( `<${node.name}> is an SVG element – did you forget to add { namespace: 'svg' } ?`, node.start );
			}

			if ( node.name in meta ) {
				return meta[ node.name ]( validator, node );
			}

			elementDepth += 1;

			validateElement( validator, node );
		}

		if ( node.children ) {
			node.children.forEach( visit );
		}

		if ( node.else ) {
			visit( node.else );
		}

		if ( node.type === 'Element' ) {
			elementDepth -= 1;
		}
	}

	html.children.forEach( visit );
}

@@ -1017,19 +1017,29 @@
  meta = 
-%7B%0A%09
+new Map(%5B%0A%09%5B 
 ':Window
@@ -1039,17 +1039,17 @@
 :Window'
-:
+,
  validat
@@ -1055,18 +1055,21 @@
 teWindow
-%0A%7D
+ %5D%0A%5D)
 ;%0A%0Aexpor
@@ -1432,24 +1432,34 @@
 %09%09%7D%0A%0A%09%09%09if (
+ meta.has(
  node.name i
@@ -1461,15 +1461,9 @@
 ame 
-in meta
+)
  ) %7B
@@ -1478,17 +1478,21 @@
 urn meta
-%5B
+.get(
  node.na
@@ -1494,17 +1494,17 @@
 de.name 
-%5D
+)
 ( valida

use map rather than object