/** * @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 { ɵparseCookieValue as parseCookieValue, ɵsetRootDomAdapter as setRootDomAdapter } from '@angular/common'; import { GenericBrowserDomAdapter } from './generic_browser_adapter'; /** * A `DomAdapter` powered by full browser DOM APIs. * * @security Tread carefully! Interacting with the DOM directly is dangerous and * can introduce XSS risks. */ /* tslint:disable:requireParameterType no-console */ export class BrowserDomAdapter extends GenericBrowserDomAdapter { static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); } onAndCancel(el, evt, listener) { el.addEventListener(evt, listener); return () => { el.removeEventListener(evt, listener); }; } dispatchEvent(el, evt) { el.dispatchEvent(evt); } remove(node) { if (node.parentNode) { node.parentNode.removeChild(node); } } createElement(tagName, doc) { doc = doc || this.getDefaultDocument(); return doc.createElement(tagName); } createHtmlDocument() { return document.implementation.createHTMLDocument('fakeTitle'); } getDefaultDocument() { return document; } isElementNode(node) { return node.nodeType === Node.ELEMENT_NODE; } isShadowRoot(node) { return node instanceof DocumentFragment; } /** @deprecated No longer being used in Ivy code. To be removed in version 14. */ getGlobalEventTarget(doc, target) { if (target === 'window') { return window; } if (target === 'document') { return doc; } if (target === 'body') { return doc.body; } return null; } getBaseHref(doc) { const href = getBaseElementHref(); return href == null ? null : relativePath(href); } resetBaseElement() { baseElement = null; } getUserAgent() { return window.navigator.userAgent; } getCookie(name) { return parseCookieValue(document.cookie, name); } } let baseElement = null; function getBaseElementHref() { baseElement = baseElement || document.querySelector('base'); return baseElement ? baseElement.getAttribute('href') : null; } // based on urlUtils.js in AngularJS 1 let urlParsingNode; function relativePath(url) { urlParsingNode = urlParsingNode || document.createElement('a'); urlParsingNode.setAttribute('href', url); const pathName = urlParsingNode.pathname; return pathName.charAt(0) === '/' ? pathName : `/${pathName}`; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlcl9hZGFwdGVyLmpzI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