import { i as isStr, p as proxyCustomElement, H, a as inheritAttributes, g as getUrl, b as getName, h, c as isRTL, d as Host } from './index.js'; const validateContent = (svgContent) => { const div = document.createElement('div'); div.innerHTML = svgContent; // setup this way to ensure it works on our buddy IE for (let i = div.childNodes.length - 1; i >= 0; i--) { if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') { div.removeChild(div.childNodes[i]); } } // must only have 1 root element const svgElm = div.firstElementChild; if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') { const svgClass = svgElm.getAttribute('class') || ''; svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim()); // root element must be an svg // lets double check we've got valid elements // do not allow scripts if (isValid(svgElm)) { return div.innerHTML; } } return ''; }; const isValid = (elm) => { if (elm.nodeType === 1) { if (elm.nodeName.toLowerCase() === 'script') { return false; } for (let i = 0; i < elm.attributes.length; i++) { const name = elm.attributes[i].name; if (isStr(name) && name.toLowerCase().indexOf('on') === 0) { return false; } } for (let i = 0; i < elm.childNodes.length; i++) { if (!isValid(elm.childNodes[i])) { return false; } } } return true; }; const isSvgDataUrl = (url) => url.startsWith('data:image/svg+xml'); const isEncodedDataUrl = (url) => url.indexOf(';utf8,') !== -1; const ioniconContent = new Map(); const requests = new Map(); let parser; /** * Safely fallback to an empty svg */ function safeFallback(url) { const svg = ''; ioniconContent.set(url, svg); return svg; } const getSvgContent = (url, sanitize) => { /** * See if we already have a request for this url */ const req = requests.get(url); if (req) { return req; } if (typeof fetch !== 'undefined' && typeof document !== 'undefined') { /** * If the url is a data url of an svg, then try to parse it * with the DOMParser. This works with content security policies enabled. */ if (isSvgDataUrl(url) && isEncodedDataUrl(url)) { return Promise.resolve(getSvgByUrl(url)); } return fetchSvg(url, sanitize); } return Promise.resolve(safeFallback(url)); }; function getSvgByUrl(url) { if (!parser) { /** * Create an instance of the DOM parser. This creates a single * parser instance for the entire app, which is more efficient. */ parser = new DOMParser(); } const doc = parser.parseFromString(url, 'text/html'); const svg = doc.querySelector('svg'); if (svg) { ioniconContent.set(url, svg.outerHTML); return svg.outerHTML; } throw new Error(`Could not parse svg from ${url}`); } function fetchSvg(url, sanitize) { /** * We don't already have a request */ const req = fetch(url) .then((rsp) => { /** * When fetching from a file:// URL, some browsers return * a 0 status code even when the request succeeds so don't * rely on rsp.ok as the only signal of success. */ return rsp .text() .then((svgContent) => { if (svgContent && sanitize !== false) { svgContent = validateContent(svgContent); } const svg = svgContent || ''; ioniconContent.set(url, svg); return svg; }) .catch(() => safeFallback(url)); }) .catch(() => safeFallback(url)); /** * Cache for the same requests */ requests.set(url, req); return req; } const iconCss = ":host{display:inline-block;width:1em;height:1em;contain:strict;fill:currentColor;box-sizing:content-box !important}:host .ionicon{stroke:currentColor}.ionicon-fill-none{fill:none}.ionicon-stroke-width{stroke-width:var(--ionicon-stroke-width, 32px)}.icon-inner,.ionicon,svg{display:block;height:100%;width:100%}@supports (background: -webkit-named-image(i)){:host(.icon-rtl) .icon-inner{transform:scaleX(-1)}}@supports not selector(:dir(rtl)) and selector(:host-context([dir='rtl'])){:host(.icon-rtl) .icon-inner{transform:scaleX(-1)}}:host(.flip-rtl):host-context([dir='rtl']) .icon-inner{transform:scaleX(-1)}@supports selector(:dir(rtl)){:host(.flip-rtl:dir(rtl)) .icon-inner{transform:scaleX(-1)}:host(.flip-rtl:dir(ltr)) .icon-inner{transform:scaleX(1)}}:host(.icon-small){font-size:1.125rem !important}:host(.icon-large){font-size:2rem !important}:host(.ion-color){color:var(--ion-color-base) !important}:host(.ion-color-primary){--ion-color-base:var(--ion-color-primary, #3880ff)}:host(.ion-color-secondary){--ion-color-base:var(--ion-color-secondary, #0cd1e8)}:host(.ion-color-tertiary){--ion-color-base:var(--ion-color-tertiary, #f4a942)}:host(.ion-color-success){--ion-color-base:var(--ion-color-success, #10dc60)}:host(.ion-color-warning){--ion-color-base:var(--ion-color-warning, #ffce00)}:host(.ion-color-danger){--ion-color-base:var(--ion-color-danger, #f14141)}:host(.ion-color-light){--ion-color-base:var(--ion-color-light, #f4f5f8)}:host(.ion-color-medium){--ion-color-base:var(--ion-color-medium, #989aa2)}:host(.ion-color-dark){--ion-color-base:var(--ion-color-dark, #222428)}"; const Icon = /*@__PURE__*/ proxyCustomElement(class Icon extends H { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.iconName = null; this.inheritedAttributes = {}; this.didLoadIcon = false; this.isVisible = false; /** * The mode determines which platform styles to use. */ this.mode = getIonMode(); /** * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. * Default, `false`. */ this.lazy = false; /** * When set to `false`, SVG content that is HTTP fetched will not be checked * if the response SVG content has any `