import { getAssetPath, proxyCustomElement, HTMLElement, Build, h, Host } from '@stencil/core/internal/client'; let CACHED_MAP; const getIconMap = () => { if (typeof window === 'undefined') { return new Map(); } else { if (!CACHED_MAP) { const win = window; win.Ionicons = win.Ionicons || {}; CACHED_MAP = win.Ionicons.map = win.Ionicons.map || new Map(); } return CACHED_MAP; } }; const addIcons = (icons) => { const map = getIconMap(); Object.keys(icons).forEach(name => map.set(name, icons[name])); }; const getUrl = (i) => { let url = getSrc(i.src); if (url) { return url; } url = getName(i.name, i.icon, i.mode, i.ios, i.md); if (url) { return getNamedUrl(url); } if (i.icon) { url = getSrc(i.icon); if (url) { return url; } url = getSrc(i.icon[i.mode]); if (url) { return url; } } return null; }; const getNamedUrl = (iconName) => { const url = getIconMap().get(iconName); if (url) { return url; } return getAssetPath(`svg/${iconName}.svg`); }; const getName = (iconName, icon, mode, ios, md) => { // default to "md" if somehow the mode wasn't set mode = (mode && toLower(mode)) === 'ios' ? 'ios' : 'md'; // if an icon was passed in using the ios or md attributes // set the iconName to whatever was passed in if (ios && mode === 'ios') { iconName = toLower(ios); } else if (md && mode === 'md') { iconName = toLower(md); } else { if (!iconName && icon && !isSrc(icon)) { iconName = icon; } if (isStr(iconName)) { iconName = toLower(iconName); } } if (!isStr(iconName) || iconName.trim() === '') { return null; } // only allow alpha characters and dash const invalidChars = iconName.replace(/[a-z]|-|\d/gi, ''); if (invalidChars !== '') { return null; } return iconName; }; const getSrc = (src) => { if (isStr(src)) { src = src.trim(); if (isSrc(src)) { return src; } } return null; }; const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str); const isStr = (val) => typeof val === 'string'; const toLower = (val) => val.toLowerCase(); /** * Elements inside of web components sometimes need to inherit global attributes * set on the host. For example, the inner input in `ion-input` should inherit * the `title` attribute that developers set directly on `ion-input`. This * helper function should be called in componentWillLoad and assigned to a variable * that is later used in the render function. * * This does not need to be reactive as changing attributes on the host element * does not trigger a re-render. */ const inheritAttributes = (el, attributes = []) => { const attributeObject = {}; attributes.forEach(attr => { if (el.hasAttribute(attr)) { const value = el.getAttribute(attr); if (value !== null) { attributeObject[attr] = el.getAttribute(attr); } el.removeAttribute(attr); } }); return attributeObject; }; /** * Returns `true` if the document or host element * has a `dir` set to `rtl`. The host value will always * take priority over the root document value. */ const isRTL = (hostEl) => { if (hostEl) { if (hostEl.dir !== '') { return hostEl.dir.toLowerCase() === 'rtl'; } } return (document === null || document === void 0 ? void 0 : document.dir.toLowerCase()) === 'rtl'; }; 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; const getSvgContent = (url, sanitize) => { // see if we already have a request for this url let req = requests.get(url); if (!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)) { 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 Promise.resolve(); } else { // we don't already have a request req = fetch(url).then((rsp) => { if (rsp.ok) { return rsp.text().then((svgContent) => { if (svgContent && sanitize !== false) { svgContent = validateContent(svgContent); } ioniconContent.set(url, svgContent || ''); }); } ioniconContent.set(url, ''); }); // cache for the same requests requests.set(url, req); } } else { // set to empty for ssr scenarios and resolve promise ioniconContent.set(url, ''); return Promise.resolve(); } } return req; }; const iconCss = ":host{display:inline-block;width:1em;height:1em;contain:strict;fill:currentColor;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host .ionicon{stroke:currentColor}.ionicon-fill-none{fill:none}.ionicon-stroke-width{stroke-width:32px;stroke-width:var(--ionicon-stroke-width, 32px)}.icon-inner,.ionicon,svg{display:block;height:100%;width:100%}:host(.flip-rtl) .icon-inner{-webkit-transform:scaleX(-1);transform:scaleX(-1)}:host(.icon-small){font-size:18px !important}:host(.icon-large){font-size:32px !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 extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.iconName = null; this.inheritedAttributes = {}; 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 `