1 | import { r as registerInstance, h, H as Host, a as getElement } from './index-468d974f.js';
|
2 | import { i as isStr, g as getUrl, b as getName } from './utils-4f847845.js';
|
3 |
|
4 | const validateContent = (svgContent) => {
|
5 | const div = document.createElement('div');
|
6 | div.innerHTML = svgContent;
|
7 |
|
8 | for (let i = div.childNodes.length - 1; i >= 0; i--) {
|
9 | if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {
|
10 | div.removeChild(div.childNodes[i]);
|
11 | }
|
12 | }
|
13 |
|
14 | const svgElm = div.firstElementChild;
|
15 | if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {
|
16 | const svgClass = svgElm.getAttribute('class') || '';
|
17 | svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());
|
18 |
|
19 |
|
20 |
|
21 | if (isValid(svgElm)) {
|
22 | return div.innerHTML;
|
23 | }
|
24 | }
|
25 | return '';
|
26 | };
|
27 | const isValid = (elm) => {
|
28 | if (elm.nodeType === 1) {
|
29 | if (elm.nodeName.toLowerCase() === 'script') {
|
30 | return false;
|
31 | }
|
32 | for (let i = 0; i < elm.attributes.length; i++) {
|
33 | const val = elm.attributes[i].value;
|
34 | if (isStr(val) && val.toLowerCase().indexOf('on') === 0) {
|
35 | return false;
|
36 | }
|
37 | }
|
38 | for (let i = 0; i < elm.childNodes.length; i++) {
|
39 | if (!isValid(elm.childNodes[i])) {
|
40 | return false;
|
41 | }
|
42 | }
|
43 | }
|
44 | return true;
|
45 | };
|
46 |
|
47 | const ioniconContent = new Map();
|
48 | const requests = new Map();
|
49 | const getSvgContent = (url, sanitize) => {
|
50 |
|
51 | let req = requests.get(url);
|
52 | if (!req) {
|
53 | if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
|
54 |
|
55 | req = fetch(url).then((rsp) => {
|
56 | if (rsp.ok) {
|
57 | return rsp.text().then((svgContent) => {
|
58 | if (svgContent && sanitize !== false) {
|
59 | svgContent = validateContent(svgContent);
|
60 | }
|
61 | ioniconContent.set(url, svgContent || '');
|
62 | });
|
63 | }
|
64 | ioniconContent.set(url, '');
|
65 | });
|
66 |
|
67 | requests.set(url, req);
|
68 | }
|
69 | else {
|
70 |
|
71 | ioniconContent.set(url, '');
|
72 | return Promise.resolve();
|
73 | }
|
74 | }
|
75 | return req;
|
76 | };
|
77 |
|
78 | 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)}";
|
79 |
|
80 | const Icon = class {
|
81 | constructor(hostRef) {
|
82 | registerInstance(this, hostRef);
|
83 | this.iconName = null;
|
84 | this.isVisible = false;
|
85 | |
86 |
|
87 |
|
88 | this.mode = getIonMode();
|
89 | |
90 |
|
91 |
|
92 |
|
93 | this.lazy = false;
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | this.sanitize = true;
|
101 | }
|
102 | connectedCallback() {
|
103 |
|
104 |
|
105 |
|
106 | this.waitUntilVisible(this.el, '50px', () => {
|
107 | this.isVisible = true;
|
108 | this.loadIcon();
|
109 | });
|
110 | }
|
111 | disconnectedCallback() {
|
112 | if (this.io) {
|
113 | this.io.disconnect();
|
114 | this.io = undefined;
|
115 | }
|
116 | }
|
117 | waitUntilVisible(el, rootMargin, cb) {
|
118 | if (this.lazy && typeof window !== 'undefined' && window.IntersectionObserver) {
|
119 | const io = (this.io = new window.IntersectionObserver((data) => {
|
120 | if (data[0].isIntersecting) {
|
121 | io.disconnect();
|
122 | this.io = undefined;
|
123 | cb();
|
124 | }
|
125 | }, { rootMargin }));
|
126 | io.observe(el);
|
127 | }
|
128 | else {
|
129 |
|
130 |
|
131 | cb();
|
132 | }
|
133 | }
|
134 | loadIcon() {
|
135 | if (this.isVisible) {
|
136 | const url = getUrl(this);
|
137 | if (url) {
|
138 | if (ioniconContent.has(url)) {
|
139 |
|
140 | this.svgContent = ioniconContent.get(url);
|
141 | }
|
142 | else {
|
143 |
|
144 | getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
|
145 | }
|
146 | }
|
147 | }
|
148 | const label = this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
|
149 | if (!this.ariaLabel && this.ariaHidden !== 'true') {
|
150 |
|
151 |
|
152 | if (label) {
|
153 | this.ariaLabel = label.replace(/\-/g, ' ');
|
154 | }
|
155 | }
|
156 | }
|
157 | render() {
|
158 | const { iconName } = this;
|
159 | const mode = this.mode || 'md';
|
160 | const flipRtl = this.flipRtl ||
|
161 | (iconName &&
|
162 | (iconName.indexOf('arrow') > -1 || iconName.indexOf('chevron') > -1) &&
|
163 | this.flipRtl !== false);
|
164 | return (h(Host, { role: "img", class: Object.assign(Object.assign({ [mode]: true }, createColorClasses(this.color)), { [`icon-${this.size}`]: !!this.size, 'flip-rtl': !!flipRtl && this.el.ownerDocument.dir === 'rtl' }) }, this.svgContent ? (h("div", { class: "icon-inner", innerHTML: this.svgContent })) : (h("div", { class: "icon-inner" }))));
|
165 | }
|
166 | static get assetsDirs() { return ["svg"]; }
|
167 | get el() { return getElement(this); }
|
168 | static get watchers() { return {
|
169 | "name": ["loadIcon"],
|
170 | "src": ["loadIcon"],
|
171 | "icon": ["loadIcon"]
|
172 | }; }
|
173 | };
|
174 | const getIonMode = () => (typeof document !== 'undefined' && document.documentElement.getAttribute('mode')) || 'md';
|
175 | const createColorClasses = (color) => {
|
176 | return color
|
177 | ? {
|
178 | 'ion-color': true,
|
179 | [`ion-color-${color}`]: true,
|
180 | }
|
181 | : null;
|
182 | };
|
183 | Icon.style = iconCss;
|
184 |
|
185 | export { Icon as ion_icon };
|