/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { ɵgetDOM as getDOM } from '@angular/common'; import { NgZone } from '@angular/core'; export function dispatchEvent(element, eventType) { const evt = getDOM().getDefaultDocument().createEvent('Event'); evt.initEvent(eventType, true, true); getDOM().dispatchEvent(element, evt); return evt; } export function createMouseEvent(eventType) { const evt = getDOM().getDefaultDocument().createEvent('MouseEvent'); evt.initEvent(eventType, true, true); return evt; } export function el(html) { return getContent(createTemplate(html)).firstChild; } function getAttributeMap(element) { const res = new Map(); const elAttrs = element.attributes; for (let i = 0; i < elAttrs.length; i++) { const attrib = elAttrs.item(i); res.set(attrib.name, attrib.value); } return res; } const _selfClosingTags = ['br', 'hr', 'input']; export function stringifyElement(el) { let result = ''; if (getDOM().isElementNode(el)) { const tagName = el.tagName.toLowerCase(); // Opening tag result += `<${tagName}`; // Attributes in an ordered way const attributeMap = getAttributeMap(el); const sortedKeys = Array.from(attributeMap.keys()).sort(); for (const key of sortedKeys) { const lowerCaseKey = key.toLowerCase(); let attValue = attributeMap.get(key); if (typeof attValue !== 'string') { result += ` ${lowerCaseKey}`; } else { // Browsers order style rules differently. Order them alphabetically for consistency. if (lowerCaseKey === 'style') { attValue = attValue.split(/; ?/).filter(s => !!s).sort().map(s => `${s};`).join(' '); } result += ` ${lowerCaseKey}="${attValue}"`; } } result += '>'; // Children const childrenRoot = templateAwareRoot(el); const children = childrenRoot ? childrenRoot.childNodes : []; for (let j = 0; j < children.length; j++) { result += stringifyElement(children[j]); } // Closing tag if (_selfClosingTags.indexOf(tagName) == -1) { result += ``; } } else if (isCommentNode(el)) { result += ``; } else { result += el.textContent; } return result; } export function createNgZone() { return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false }); } export function isCommentNode(node) { return node.nodeType === Node.COMMENT_NODE; } export function isTextNode(node) { return node.nodeType === Node.TEXT_NODE; } export function getContent(node) { if ('content' in node) { return node.content; } else { return node; } } export function templateAwareRoot(el) { return getDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el; } export function setCookie(name, value) { // document.cookie is magical, assigning into it assigns/overrides one cookie value, but does // not clear other cookies. document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value); } export function hasStyle(element, styleName, styleValue) { const value = element.style[styleName] || ''; return styleValue ? value == styleValue : value.length > 0; } export function hasClass(element, className) { return element.classList.contains(className); } export function sortedClassList(element) { return Array.prototype.slice.call(element.classList, 0).sort(); } export function createTemplate(html) { const t = getDOM().getDefaultDocument().createElement('template'); t.innerHTML = html; return t; } export function childNodesAsList(el) { const childNodes = el.childNodes; const res = []; for (let i = 0; i < childNodes.length; i++) { res[i] = childNodes[i]; } return res; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlcl91dGlsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvcGxhdGZvcm0tYnJvd3Nlci90ZXN0aW5nL3NyYy9icm93c2VyX3V0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLE9BQU8sSUFBSSxNQUFNLEVBQUMsTUFBTSxpQkFBaUIsQ0FBQztBQUNsRCxPQUFPLEVBQUMsTUFBTSxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBRXJDLE1BQU0sVUFBVSxhQUFhLENBQUMsT0FBWSxFQUFFLFNBQWM7SUFDeEQsTUFBTSxHQUFHLEdBQVUsTUFBTSxFQUFFLENBQUMsa0JBQWtCLEVBQUUsQ0FBQyxXQUFXLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEUsR0FBRyxDQUFDLFNBQVMsQ0FBQyxTQUFTLEVBQUUsSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFDO0lBQ3JDLE1BQU0sRUFBRSxDQUFD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