1 | 'use strict';
|
2 |
|
3 | const index = require('./index-b34d10f5.js');
|
4 |
|
5 | let CACHED_MAP;
|
6 | const getIconMap = () => {
|
7 | if (typeof window === 'undefined') {
|
8 | return new Map();
|
9 | }
|
10 | else {
|
11 | if (!CACHED_MAP) {
|
12 | const win = window;
|
13 | win.Ionicons = win.Ionicons || {};
|
14 | CACHED_MAP = win.Ionicons.map = win.Ionicons.map || new Map();
|
15 | }
|
16 | return CACHED_MAP;
|
17 | }
|
18 | };
|
19 | const addIcons = (icons) => {
|
20 | Object.keys(icons).forEach(name => {
|
21 | addToIconMap(name, icons[name]);
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | const toKebabCase = name.replace(/([a-z0-9]|(?=[A-Z]))([A-Z0-9])/g, "$1-$2").toLowerCase();
|
33 | if (name !== toKebabCase) {
|
34 | addToIconMap(toKebabCase, icons[name]);
|
35 | }
|
36 | });
|
37 | };
|
38 | const addToIconMap = (name, data) => {
|
39 | const map = getIconMap();
|
40 | const existingIcon = map.get(name);
|
41 | if (existingIcon === undefined) {
|
42 | map.set(name, data);
|
43 | |
44 |
|
45 |
|
46 |
|
47 | }
|
48 | else if (existingIcon !== data) {
|
49 | console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`);
|
50 | }
|
51 | };
|
52 | const getUrl = (i) => {
|
53 | let url = getSrc(i.src);
|
54 | if (url) {
|
55 | return url;
|
56 | }
|
57 | url = getName(i.name, i.icon, i.mode, i.ios, i.md);
|
58 | if (url) {
|
59 | return getNamedUrl(url, i);
|
60 | }
|
61 | if (i.icon) {
|
62 | url = getSrc(i.icon);
|
63 | if (url) {
|
64 | return url;
|
65 | }
|
66 | url = getSrc(i.icon[i.mode]);
|
67 | if (url) {
|
68 | return url;
|
69 | }
|
70 | }
|
71 | return null;
|
72 | };
|
73 | const getNamedUrl = (iconName, iconEl) => {
|
74 | const url = getIconMap().get(iconName);
|
75 | if (url) {
|
76 | return url;
|
77 | }
|
78 | try {
|
79 | return index.getAssetPath(`svg/${iconName}.svg`);
|
80 | }
|
81 | catch (e) {
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | console.warn(`[Ionicons Warning]: Could not load icon with name "${iconName}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the icon component.`, iconEl);
|
90 | }
|
91 | };
|
92 | const getName = (iconName, icon, mode, ios, md) => {
|
93 |
|
94 | mode = (mode && toLower(mode)) === 'ios' ? 'ios' : 'md';
|
95 |
|
96 |
|
97 | if (ios && mode === 'ios') {
|
98 | iconName = toLower(ios);
|
99 | }
|
100 | else if (md && mode === 'md') {
|
101 | iconName = toLower(md);
|
102 | }
|
103 | else {
|
104 | if (!iconName && icon && !isSrc(icon)) {
|
105 | iconName = icon;
|
106 | }
|
107 | if (isStr(iconName)) {
|
108 | iconName = toLower(iconName);
|
109 | }
|
110 | }
|
111 | if (!isStr(iconName) || iconName.trim() === '') {
|
112 | return null;
|
113 | }
|
114 |
|
115 | const invalidChars = iconName.replace(/[a-z]|-|\d/gi, '');
|
116 | if (invalidChars !== '') {
|
117 | return null;
|
118 | }
|
119 | return iconName;
|
120 | };
|
121 | const getSrc = (src) => {
|
122 | if (isStr(src)) {
|
123 | src = src.trim();
|
124 | if (isSrc(src)) {
|
125 | return src;
|
126 | }
|
127 | }
|
128 | return null;
|
129 | };
|
130 | const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str);
|
131 | const isStr = (val) => typeof val === 'string';
|
132 | const toLower = (val) => val.toLowerCase();
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | const inheritAttributes = (el, attributes = []) => {
|
144 | const attributeObject = {};
|
145 | attributes.forEach(attr => {
|
146 | if (el.hasAttribute(attr)) {
|
147 | const value = el.getAttribute(attr);
|
148 | if (value !== null) {
|
149 | attributeObject[attr] = el.getAttribute(attr);
|
150 | }
|
151 | el.removeAttribute(attr);
|
152 | }
|
153 | });
|
154 | return attributeObject;
|
155 | };
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | const isRTL = (hostEl) => {
|
162 | if (hostEl) {
|
163 | if (hostEl.dir !== '') {
|
164 | return hostEl.dir.toLowerCase() === 'rtl';
|
165 | }
|
166 | }
|
167 | return (document === null || document === void 0 ? void 0 : document.dir.toLowerCase()) === 'rtl';
|
168 | };
|
169 |
|
170 | exports.addIcons = addIcons;
|
171 | exports.getName = getName;
|
172 | exports.getUrl = getUrl;
|
173 | exports.inheritAttributes = inheritAttributes;
|
174 | exports.isRTL = isRTL;
|
175 | exports.isStr = isStr;
|