@pine-ds/icons 3.1.0 → 3.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/pds-icon.d.ts +2 -2
- package/components/pds-icon.js +175 -171
- package/components/pds-icon.js.map +1 -1
- package/components/utils.js +65 -45
- package/components/utils.js.map +1 -1
- package/dist/cheatsheet.html +7 -5
- package/dist/cjs/{index-b35d5b0f.js → index-17212f65.js} +81 -21
- package/dist/cjs/index-17212f65.js.map +1 -0
- package/dist/cjs/index.cjs.js +2 -2
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/pds-icon.cjs.entry.js +152 -150
- package/dist/cjs/pds-icon.cjs.entry.js.map +1 -1
- package/dist/cjs/pds-icons.cjs.js +3 -3
- package/dist/cjs/pds-icons.cjs.js.map +1 -1
- package/dist/cjs/utils-8c57ce6a.js +101 -0
- package/dist/cjs/utils-8c57ce6a.js.map +1 -0
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/pds-icon/pds-icon.js +189 -168
- package/dist/collection/components/pds-icon/pds-icon.js.map +1 -1
- package/dist/collection/components/pds-icon/request.js +21 -21
- package/dist/collection/components/pds-icon/request.js.map +1 -1
- package/dist/collection/components/pds-icon/svg/premium.svg +1 -0
- package/dist/collection/components/pds-icon/svg/theme-store.svg +1 -1
- package/dist/collection/components/pds-icon/test/pds-icon.e2e.js +6 -6
- package/dist/collection/components/pds-icon/test/pds-icon.e2e.js.map +1 -1
- package/dist/collection/components/pds-icon/test/pds-icon.spec.js +69 -31
- package/dist/collection/components/pds-icon/test/pds-icon.spec.js.map +1 -1
- package/dist/collection/components/pds-icon/utils.js +61 -51
- package/dist/collection/components/pds-icon/utils.js.map +1 -1
- package/dist/collection/components/pds-icon/validate.js +35 -35
- package/dist/collection/components/pds-icon/validate.js.map +1 -1
- package/dist/docs.json +23 -2
- package/dist/esm/{index-8effeb27.js → index-d1a605fc.js} +81 -21
- package/dist/esm/index-d1a605fc.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/loader.js +3 -3
- package/dist/esm/pds-icon.entry.js +152 -150
- package/dist/esm/pds-icon.entry.js.map +1 -1
- package/dist/esm/pds-icons.js +4 -4
- package/dist/esm/pds-icons.js.map +1 -1
- package/dist/esm/utils-15462a67.js +95 -0
- package/dist/esm/utils-15462a67.js.map +1 -0
- package/dist/pds-icons/index.esm.js +1 -1
- package/dist/pds-icons/p-19d7058a.js +3 -0
- package/dist/pds-icons/p-19d7058a.js.map +1 -0
- package/dist/pds-icons/p-229b8f4e.entry.js +2 -0
- package/dist/pds-icons/p-229b8f4e.entry.js.map +1 -0
- package/dist/pds-icons/p-f0b1dbd6.js +2 -0
- package/dist/pds-icons/p-f0b1dbd6.js.map +1 -0
- package/dist/pds-icons/pds-icons.esm.js +1 -1
- package/dist/pds-icons/pds-icons.esm.js.map +1 -1
- package/dist/pds-icons.json +8 -1
- package/dist/pds-icons.symbols.svg +3 -2
- package/dist/svg/premium.svg +1 -0
- package/dist/svg/theme-store.svg +1 -1
- package/dist/types/components/pds-icon/pds-icon.d.ts +41 -35
- package/dist/types/components/pds-icon/utils.d.ts +4 -4
- package/dist/types/components.d.ts +8 -0
- package/dist/types/stencil-public-runtime.d.ts +29 -0
- package/icons/index.d.ts +2 -1
- package/icons/index.js +3 -2
- package/icons/index.mjs +3 -2
- package/icons/package.json +1 -1
- package/package.json +6 -6
- package/dist/cjs/index-b35d5b0f.js.map +0 -1
- package/dist/cjs/utils-395a38b7.js +0 -81
- package/dist/cjs/utils-395a38b7.js.map +0 -1
- package/dist/esm/index-8effeb27.js.map +0 -1
- package/dist/esm/utils-a0ad61d0.js +0 -75
- package/dist/esm/utils-a0ad61d0.js.map +0 -1
- package/dist/pds-icons/p-91678731.entry.js +0 -2
- package/dist/pds-icons/p-91678731.entry.js.map +0 -1
- package/dist/pds-icons/p-a3383818.js +0 -3
- package/dist/pds-icons/p-a3383818.js.map +0 -1
- package/dist/pds-icons/p-dc5765cb.js +0 -2
- package/dist/pds-icons/p-dc5765cb.js.map +0 -1
package/components/pds-icon.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { Components, JSX } from "../dist/types/components";
|
|
|
2
2
|
|
|
3
3
|
interface PdsIcon extends Components.PdsIcon, HTMLElement {}
|
|
4
4
|
export const PdsIcon: {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
prototype: PdsIcon;
|
|
6
|
+
new (): PdsIcon;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Used to define this component and all nested components recursively.
|
package/components/pds-icon.js
CHANGED
|
@@ -2,207 +2,211 @@ import { proxyCustomElement, HTMLElement, Build, h, Host } from '@stencil/core/i
|
|
|
2
2
|
import { i as isStr, b as inheritAttributes, g as getUrl, c as getName } from './utils.js';
|
|
3
3
|
|
|
4
4
|
const validateContent = (svgContent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const div = document.createElement('div');
|
|
6
|
+
div.innerHTML = svgContent;
|
|
7
|
+
// setup this way to ensure it works on our buddy IE
|
|
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
|
+
}
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
// must only have 1 root element
|
|
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
|
+
// root element must be an svg
|
|
19
|
+
// lets double check we've got valid elements
|
|
20
|
+
// do not allow scripts
|
|
21
|
+
if (isValid(svgElm)) {
|
|
22
|
+
return div.innerHTML;
|
|
23
|
+
}
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
return '';
|
|
25
|
+
return '';
|
|
26
26
|
};
|
|
27
27
|
const isValid = (elm) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 name = elm.attributes[i].name;
|
|
34
|
+
if (isStr(name) && name.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
|
+
}
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
return true;
|
|
44
|
+
return true;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const pdsIconContent = new Map();
|
|
48
48
|
const requests = new Map(); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
49
49
|
const getSvgContent = (url, sanitize = false) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
let req = requests.get(url);
|
|
51
|
+
if (!req) {
|
|
52
|
+
if (typeof fetch != 'undefined' && typeof document !== 'undefined') {
|
|
53
|
+
// we don't have a request
|
|
54
|
+
req = fetch(url).then((rsp) => {
|
|
55
|
+
if (rsp.ok) {
|
|
56
|
+
return rsp.text().then((svgContent) => {
|
|
57
|
+
if (svgContent && sanitize !== false) {
|
|
58
|
+
svgContent = validateContent(svgContent);
|
|
59
|
+
}
|
|
60
|
+
pdsIconContent.set(url, svgContent || '');
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
pdsIconContent.set(url, '');
|
|
64
|
+
});
|
|
65
|
+
requests.set(url, req);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
pdsIconContent.set(url, '');
|
|
69
|
+
return Promise.resolve();
|
|
62
70
|
}
|
|
63
|
-
pdsIconContent.set(url, '');
|
|
64
|
-
});
|
|
65
|
-
requests.set(url, req);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
pdsIconContent.set(url, '');
|
|
69
|
-
return Promise.resolve();
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
return req;
|
|
72
|
+
return req;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
const pdsIconCss = ":host{contain:strict;display:inline-block;fill:currentColor;height:1em;width:1em}:host .pdsicon{fill:currentColor}.pds-icon-fill-none{fill:none}.icon-inner,.pds-icon,svg{display:block;height:100%;width:100%}";
|
|
76
76
|
|
|
77
77
|
const PdsIcon$1 = /*@__PURE__*/ proxyCustomElement(class PdsIcon extends HTMLElement {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
iconSize() {
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
-
const sizes = {
|
|
97
|
-
small: '12px',
|
|
98
|
-
regular: '16px',
|
|
99
|
-
medium: '20px',
|
|
100
|
-
large: '24px',
|
|
101
|
-
};
|
|
102
|
-
if (sizes[this.size]) {
|
|
103
|
-
return sizes[this.size];
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return this.size;
|
|
78
|
+
constructor() {
|
|
79
|
+
super();
|
|
80
|
+
this.__registerHost();
|
|
81
|
+
this.__attachShadow();
|
|
82
|
+
this.inheritedAttributes = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
83
|
+
this.hasAriaHidden = () => {
|
|
84
|
+
const { el } = this;
|
|
85
|
+
return el.hasAttribute('aria-hidden') && el.getAttribute('aria-hidden') === 'true';
|
|
86
|
+
};
|
|
87
|
+
this.ariaLabel = undefined;
|
|
88
|
+
this.isVisible = false;
|
|
89
|
+
this.svgContent = undefined;
|
|
90
|
+
this.color = undefined;
|
|
91
|
+
this.icon = undefined;
|
|
92
|
+
this.name = undefined;
|
|
93
|
+
this.size = 'regular';
|
|
107
94
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
disconnectedCallback() {
|
|
119
|
-
if (this.io) {
|
|
120
|
-
this.io.disconnect();
|
|
121
|
-
this.io = undefined;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
loadIcon() {
|
|
125
|
-
if (Build.isBrowser && this.isVisible) {
|
|
126
|
-
const url = getUrl(this);
|
|
127
|
-
if (url) {
|
|
128
|
-
if (pdsIconContent.has(url)) {
|
|
129
|
-
this.svgContent = pdsIconContent.get(url);
|
|
95
|
+
iconSize() {
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
const sizes = {
|
|
98
|
+
small: '12px',
|
|
99
|
+
regular: '16px',
|
|
100
|
+
medium: '20px',
|
|
101
|
+
large: '24px',
|
|
102
|
+
};
|
|
103
|
+
if (sizes[this.size]) {
|
|
104
|
+
return sizes[this.size];
|
|
130
105
|
}
|
|
131
106
|
else {
|
|
132
|
-
|
|
107
|
+
return this.size;
|
|
133
108
|
}
|
|
134
|
-
}
|
|
135
109
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
110
|
+
componentWillLoad() {
|
|
111
|
+
this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
|
|
112
|
+
}
|
|
113
|
+
connectedCallback() {
|
|
114
|
+
this.waitUntilVisible(this.el, '50px', () => {
|
|
115
|
+
this.isVisible = true;
|
|
116
|
+
this.loadIcon();
|
|
117
|
+
});
|
|
139
118
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
height: this.iconSize(),
|
|
145
|
-
width: this.iconSize(),
|
|
146
|
-
color: this.color,
|
|
147
|
-
};
|
|
148
|
-
return (h(Host, Object.assign({ "aria-label": ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null, role: "img", style: style, class: Object.assign({}, createColorClasses(this.color)) }, inheritedAttributes), Build.isBrowser && this.svgContent ? (h("div", { class: "icon-inner", innerHTML: this.svgContent })) : (h("div", { class: "icon-inner" }))));
|
|
149
|
-
}
|
|
150
|
-
/*****
|
|
151
|
-
* Private Methods
|
|
152
|
-
****/
|
|
153
|
-
waitUntilVisible(el, rootMargin, cb) {
|
|
154
|
-
if (Build.isBrowser && typeof window !== 'undefined' && (window).IntersectionObserver) {
|
|
155
|
-
const io = (this.io = new (window).IntersectionObserver((data) => {
|
|
156
|
-
if (data[0].isIntersecting) {
|
|
157
|
-
io.disconnect();
|
|
158
|
-
this.io = undefined;
|
|
159
|
-
cb();
|
|
119
|
+
disconnectedCallback() {
|
|
120
|
+
if (this.io) {
|
|
121
|
+
this.io.disconnect();
|
|
122
|
+
this.io = undefined;
|
|
160
123
|
}
|
|
161
|
-
}, { rootMargin }));
|
|
162
|
-
io.observe(el);
|
|
163
124
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
125
|
+
loadIcon() {
|
|
126
|
+
if (Build.isBrowser && this.isVisible) {
|
|
127
|
+
const url = getUrl(this);
|
|
128
|
+
if (url) {
|
|
129
|
+
if (pdsIconContent.has(url)) {
|
|
130
|
+
this.svgContent = pdsIconContent.get(url);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
getSvgContent(url).then(() => (this.svgContent = pdsIconContent.get(url)));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const label = getName(this.name, this.icon);
|
|
138
|
+
if (label) {
|
|
139
|
+
this.ariaLabel = label.replace(/\-/g, ' ');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
render() {
|
|
143
|
+
const { ariaLabel, inheritedAttributes } = this;
|
|
144
|
+
const style = {
|
|
145
|
+
height: this.iconSize(),
|
|
146
|
+
width: this.iconSize(),
|
|
147
|
+
color: this.color,
|
|
148
|
+
};
|
|
149
|
+
return (h(Host, Object.assign({ "aria-label": ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null, role: "img", style: style, class: Object.assign({}, createColorClasses(this.color)) }, inheritedAttributes), Build.isBrowser && this.svgContent ? (h("div", { class: "icon-inner", innerHTML: this.svgContent })) : (h("div", { class: "icon-inner" }))));
|
|
150
|
+
}
|
|
151
|
+
/*****
|
|
152
|
+
* Private Methods
|
|
153
|
+
****/
|
|
154
|
+
waitUntilVisible(el, rootMargin, cb) {
|
|
155
|
+
if (Build.isBrowser && typeof window !== 'undefined' && (window).IntersectionObserver) {
|
|
156
|
+
const io = (this.io = new (window).IntersectionObserver((data) => {
|
|
157
|
+
if (data[0].isIntersecting) {
|
|
158
|
+
io.disconnect();
|
|
159
|
+
this.io = undefined;
|
|
160
|
+
cb();
|
|
161
|
+
}
|
|
162
|
+
}, { rootMargin }));
|
|
163
|
+
io.observe(el);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// browser doesn't support IntersectionObserver
|
|
167
|
+
// so just fallback to always show it
|
|
168
|
+
cb();
|
|
169
|
+
}
|
|
168
170
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
static get assetsDirs() { return ["svg"]; }
|
|
172
|
+
get el() { return this; }
|
|
173
|
+
static get watchers() { return {
|
|
174
|
+
"name": ["loadIcon"],
|
|
175
|
+
"icon": ["loadIcon"]
|
|
176
|
+
}; }
|
|
177
|
+
static get style() { return pdsIconCss; }
|
|
176
178
|
}, [1, "pds-icon", {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
"color": [1],
|
|
180
|
+
"icon": [8],
|
|
181
|
+
"name": [513],
|
|
182
|
+
"size": [513],
|
|
183
|
+
"ariaLabel": [32],
|
|
184
|
+
"isVisible": [32],
|
|
185
|
+
"svgContent": [32]
|
|
186
|
+
}, undefined, {
|
|
187
|
+
"name": ["loadIcon"],
|
|
188
|
+
"icon": ["loadIcon"]
|
|
189
|
+
}]);
|
|
186
190
|
const createColorClasses = (color) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
return color
|
|
192
|
+
? {
|
|
193
|
+
'pds-color': true,
|
|
194
|
+
[`pds-color-${color}`]: true,
|
|
195
|
+
}
|
|
196
|
+
: null;
|
|
193
197
|
};
|
|
194
198
|
function defineCustomElement$1() {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
if (typeof customElements === "undefined") {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const components = ["pds-icon"];
|
|
203
|
+
components.forEach(tagName => { switch (tagName) {
|
|
204
|
+
case "pds-icon":
|
|
205
|
+
if (!customElements.get(tagName)) {
|
|
206
|
+
customElements.define(tagName, PdsIcon$1);
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
} });
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
const PdsIcon = PdsIcon$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"pds-icon.js","mappings":";;;AAEO,MAAM,eAAe,GAAG,CAAC,UAAkB;EAChD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;EAC1C,GAAG,CAAC,SAAS,GAAG,UAAU,CAAC;;EAG3B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;IACnD,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE;MACtD,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KACpC;GACF;;EAGD,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,CAAC;EACrC,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE;IACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACpD,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,QAAQ,GAAG,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;;;;IAKhE,IAAI,OAAO,CAAC,MAAqB,CAAC,EAAE;MAClC,OAAO,GAAG,CAAC,SAAS,CAAC;KACtB;GACF;EACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEK,MAAM,OAAO,GAAG,CAAC,GAAgB;EACtC,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE;IACtB,IAAI,GA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AAa,EAAE,GAAG,SAAS,GAAG,IAAI,EAC/E,IAAI,EAAC,KAAK,EACV,KAAK,EAAE,KAAK,EACZ,KAAK,oBACA,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,KAE/B,mBAAmB,GAEtB,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,IACjC,WAAK,KAAK,EAAC,YAAY,EAAC,SAAS,EAAE,IAAI,CAAC,UAAU,GAAQ,KAE1D,WAAK,KAAK,EAAC,YAAY,GAAO,CAC/B,CACI,EACR;GACF;;;;EAMO,gBAAgB,CAAC,EAAe,EAAE,UAAkB,EAAE,EAAc;IAC1E,IAAI,KAAK,CAAC,SAAS,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE;MACrF,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,oBAAoB,CACrD,CAAC,IAAiC;QAChC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE;UAC1B,EAAE,CAAC,UAAU,EAAE,CAAC;UAChB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;UACpB,EAAE,EAAE,CAAC;SACN;OACF,EACD,EAAE,UAAU,EAAE,CACf,CAAC,CAAC;MAEH,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;KAChB;SAAM;;;MAGL,EAAE,EAAE,CAAC;KACN;GACF;;;;;;;;;;;;;;;;;AASH,MAAM,kBAAkB,GAAG,CAAC,KAAyB;EACnD,OAAO,KAAK;MACT;MACE,WAAW,EAAE,IAAI;MACjB,CAAC,aAAa,KAAK,EAAE,GAAG,IAAI;KAC7B;MACD,IAAI,CAAC;AACT,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;","names":["PdsIcon"],"sources":["src/components/pds-icon/validate.ts","src/components/pds-icon/request.ts","src/components/pds-icon/pds-icon.scss?tag=pds-icon&encapsulation=shadow","src/components/pds-icon/pds-icon.tsx"],"sourcesContent":["import { isStr } from './utils';\n\nexport const validateContent = (svgContent: string) => {\n const div = document.createElement('div');\n div.innerHTML = svgContent;\n\n // setup this way to ensure it works on our buddy IE\n for (let i = div.childNodes.length - 1; i >= 0; i--) {\n if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {\n div.removeChild(div.childNodes[i]);\n }\n }\n\n // must only have 1 root element\n const svgElm = div.firstElementChild;\n if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {\n const svgClass = svgElm.getAttribute('class') || '';\n svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());\n\n // root element must be an svg\n // lets double check we've got valid elements\n // do not allow scripts\n if (isValid(svgElm as HTMLElement)) {\n return div.innerHTML;\n }\n }\n return '';\n};\n\nexport const isValid = (elm: HTMLElement) => {\n if (elm.nodeType === 1) {\n if (elm.nodeName.toLowerCase() === 'script') {\n return false;\n }\n\n for (let i = 0; i < elm.attributes.length; i++) {\n const name = elm.attributes[i].name;\n if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {\n return false;\n }\n }\n\n for (let i = 0; i < elm.childNodes.length; i++) {\n if (!isValid(elm.childNodes[i] as HTMLElement)) {\n return false;\n }\n }\n }\n return true;\n};\n","import { validateContent } from './validate';\n\nexport const pdsIconContent = new Map<string, string>();\nconst requests = new Map<string, Promise<any>>(); // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport const getSvgContent = (url: string, sanitize = false) => {\n let req = requests.get(url);\n\n if(!req) {\n if (typeof fetch != 'undefined' && typeof document !== 'undefined') {\n // we don't have a request\n req = fetch(url).then((rsp) => {\n if (rsp.ok) {\n return rsp.text().then((svgContent) => {\n if (svgContent && sanitize !== false) {\n svgContent = validateContent(svgContent);\n }\n pdsIconContent.set(url, svgContent || '');\n });\n }\n pdsIconContent.set(url, '');\n });\n\n requests.set(url, req);\n } else {\n pdsIconContent.set(url, '');\n return Promise.resolve();\n }\n }\n return req;\n}\n",":host {\n contain: strict;\n display: inline-block;\n fill: currentColor;\n height: 1em;\n width: 1em;\n\n .pdsicon {\n fill: currentColor;\n }\n}\n\n.pds-icon-fill-none {\n fill: none;\n}\n\n.icon-inner,\n.pds-icon,\nsvg {\n display: block;\n height: 100%;\n width: 100%;\n}\n","import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';\nimport { getSvgContent, pdsIconContent } from './request';\nimport { getName, getUrl, inheritAttributes } from './utils';\n\n@Component({\n tag: 'pds-icon',\n assetsDirs: ['svg'],\n styleUrl: 'pds-icon.scss',\n shadow: true,\n})\nexport class PdsIcon {\n private io?: IntersectionObserver;\n private inheritedAttributes: { [k: string]: any } = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n @Element() el!: HTMLPdsIconElement;\n\n @State() private ariaLabel?: string;\n @State() private isVisible = false;\n @State() private svgContent?: string;\n\n /**\n *\n * The color of the icon\n *\n */\n @Prop() color?: string;\n\n /**\n * The name of the icon to use from\n * the built-in set.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * The size of the icon. This can be\n * 'small', 'regular', 'medium', large, or a\n * custom value (40px, 1rem, etc)\n *\n */\n @Prop({ reflect: true }) size?:\n | 'small' // 12px\n | 'regular' // 16px\n | 'medium' // 20px\n | 'large' // 24px\n | 'auto'\n | string = 'regular'\n\n private iconSize() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const sizes: { [key: string]: any } = {\n small: '12px',\n regular: '16px',\n medium: '20px',\n large: '24px',\n }\n\n if (sizes[this.size]) {\n return sizes[this.size];\n } else {\n return this.size;\n }\n }\n componentWillLoad() {\n this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);\n }\n\n connectedCallback() {\n this.waitUntilVisible(this.el, '50px', () => {\n this.isVisible = true;\n this.loadIcon();\n })\n }\n\n disconnectedCallback() {\n if (this.io) {\n this.io.disconnect();\n this.io = undefined;\n }\n }\n\n @Watch('name')\n loadIcon() {\n if (Build.isBrowser && this.isVisible) {\n const url = getUrl(this);\n if (url) {\n if (pdsIconContent.has(url)) {\n this.svgContent = pdsIconContent.get(url);\n } else {\n getSvgContent(url).then(() => (this.svgContent = pdsIconContent.get(url)));\n }\n }\n }\n\n const label = getName(this.name);\n\n if (label) {\n this.ariaLabel = label.replace(/\\-/g, ' ');\n }\n }\n\n render() {\n const { ariaLabel, inheritedAttributes } = this;\n\n const style = {\n height: this.iconSize(),\n width: this.iconSize(),\n color: this.color,\n }\n\n return (\n\n <Host\n aria-label={ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null }\n role=\"img\"\n style={style}\n class={{\n ...createColorClasses(this.color),\n }}\n {...inheritedAttributes}\n >\n {Build.isBrowser && this.svgContent ? (\n <div class=\"icon-inner\" innerHTML={this.svgContent}></div>\n ) : (\n <div class=\"icon-inner\"></div>\n )}\n </Host>\n )\n }\n\n /*****\n * Private Methods\n ****/\n\n private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {\n if (Build.isBrowser && typeof window !== 'undefined' && (window).IntersectionObserver) {\n const io = (this.io = new (window).IntersectionObserver(\n (data: IntersectionObserverEntry[]) => {\n if (data[0].isIntersecting) {\n io.disconnect();\n this.io = undefined;\n cb();\n }\n },\n { rootMargin },\n ));\n\n io.observe(el);\n } else {\n // browser doesn't support IntersectionObserver\n // so just fallback to always show it\n cb();\n }\n }\n\n private hasAriaHidden = () => {\n const { el } = this;\n\n return el.hasAttribute('aria-hidden') && el.getAttribute('aria-hidden') === 'true';\n }\n}\n\nconst createColorClasses = (color: string | undefined) => {\n return color\n ? {\n 'pds-color': true,\n [`pds-color-${color}`]: true,\n }\n : null;\n };\n"],"version":3}
|
|
1
|
+
{"file":"pds-icon.js","mappings":";;;AAEO,MAAM,eAAe,GAAG,CAAC,UAAkB;IAChD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,GAAG,CAAC,SAAS,GAAG,UAAU,CAAC;;IAG3B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,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C1E,IAAI,KAAK,CAAC,SAAS,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE;YACrF,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,oBAAoB,CACrD,CAAC,IAAiC;gBAChC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE;oBAC1B,EAAE,CAAC,UAAU,EAAE,CAAC;oBAChB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;oBACpB,EAAE,EAAE,CAAC;iBACN;aACF,EACD,EAAE,UAAU,EAAE,CACf,CAAC,CAAC;YAEH,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;SAChB;aAAM;;;YAGL,EAAE,EAAE,CAAC;SACN;KACF;;;;;;;;;;;;;;;;;;;;AASH,MAAM,kBAAkB,GAAG,CAAC,KAAyB;IACnD,OAAO,KAAK;UACT;YACE,WAAW,EAAE,IAAI;YACjB,CAAC,aAAa,KAAK,EAAE,GAAG,IAAI;SAC7B;UACD,IAAI,CAAC;AACT,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;","names":["PdsIcon"],"sources":["src/components/pds-icon/validate.ts","src/components/pds-icon/request.ts","src/components/pds-icon/pds-icon.scss?tag=pds-icon&encapsulation=shadow","src/components/pds-icon/pds-icon.tsx"],"sourcesContent":["import { isStr } from './utils';\n\nexport const validateContent = (svgContent: string) => {\n const div = document.createElement('div');\n div.innerHTML = svgContent;\n\n // setup this way to ensure it works on our buddy IE\n for (let i = div.childNodes.length - 1; i >= 0; i--) {\n if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {\n div.removeChild(div.childNodes[i]);\n }\n }\n\n // must only have 1 root element\n const svgElm = div.firstElementChild;\n if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {\n const svgClass = svgElm.getAttribute('class') || '';\n svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());\n\n // root element must be an svg\n // lets double check we've got valid elements\n // do not allow scripts\n if (isValid(svgElm as HTMLElement)) {\n return div.innerHTML;\n }\n }\n return '';\n};\n\nexport const isValid = (elm: HTMLElement) => {\n if (elm.nodeType === 1) {\n if (elm.nodeName.toLowerCase() === 'script') {\n return false;\n }\n\n for (let i = 0; i < elm.attributes.length; i++) {\n const name = elm.attributes[i].name;\n if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {\n return false;\n }\n }\n\n for (let i = 0; i < elm.childNodes.length; i++) {\n if (!isValid(elm.childNodes[i] as HTMLElement)) {\n return false;\n }\n }\n }\n return true;\n};\n","import { validateContent } from './validate';\n\nexport const pdsIconContent = new Map<string, string>();\nconst requests = new Map<string, Promise<any>>(); // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport const getSvgContent = (url: string, sanitize = false) => {\n let req = requests.get(url);\n\n if(!req) {\n if (typeof fetch != 'undefined' && typeof document !== 'undefined') {\n // we don't have a request\n req = fetch(url).then((rsp) => {\n if (rsp.ok) {\n return rsp.text().then((svgContent) => {\n if (svgContent && sanitize !== false) {\n svgContent = validateContent(svgContent);\n }\n pdsIconContent.set(url, svgContent || '');\n });\n }\n pdsIconContent.set(url, '');\n });\n\n requests.set(url, req);\n } else {\n pdsIconContent.set(url, '');\n return Promise.resolve();\n }\n }\n return req;\n}\n",":host {\n contain: strict;\n display: inline-block;\n fill: currentColor;\n height: 1em;\n width: 1em;\n\n .pdsicon {\n fill: currentColor;\n }\n}\n\n.pds-icon-fill-none {\n fill: none;\n}\n\n.icon-inner,\n.pds-icon,\nsvg {\n display: block;\n height: 100%;\n width: 100%;\n}\n","import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';\nimport { getSvgContent, pdsIconContent } from './request';\nimport { getName, getUrl, inheritAttributes } from './utils';\n\n@Component({\n tag: 'pds-icon',\n assetsDirs: ['svg'],\n styleUrl: 'pds-icon.scss',\n shadow: true,\n})\nexport class PdsIcon {\n private io?: IntersectionObserver;\n private inheritedAttributes: { [k: string]: any } = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n @Element() el!: HTMLPdsIconElement;\n\n @State() private ariaLabel?: string;\n @State() private isVisible = false;\n @State() private svgContent?: string;\n\n /**\n *\n * The color of the icon\n *\n */\n @Prop() color?: string;\n\n /**\n * This a combination of both `name` and `src`. If a `src` url is detected\n * it will set the `src` property. Otherwise it assumes it's a built-in named\n * SVG and set the `name` property.\n */\n @Prop() icon?: any;\n\n /**\n * The name of the icon to use from\n * the built-in set.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * The size of the icon. This can be\n * 'small', 'regular', 'medium', large, or a\n * custom value (40px, 1rem, etc)\n *\n */\n @Prop({ reflect: true }) size?:\n | 'small' // 12px\n | 'regular' // 16px\n | 'medium' // 20px\n | 'large' // 24px\n | 'auto'\n | string = 'regular'\n\n private iconSize() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const sizes: { [key: string]: any } = {\n small: '12px',\n regular: '16px',\n medium: '20px',\n large: '24px',\n }\n\n if (sizes[this.size]) {\n return sizes[this.size];\n } else {\n return this.size;\n }\n }\n componentWillLoad() {\n this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);\n }\n\n connectedCallback() {\n this.waitUntilVisible(this.el, '50px', () => {\n this.isVisible = true;\n this.loadIcon();\n })\n }\n\n disconnectedCallback() {\n if (this.io) {\n this.io.disconnect();\n this.io = undefined;\n }\n }\n\n @Watch('name')\n @Watch('icon')\n loadIcon() {\n if (Build.isBrowser && this.isVisible) {\n const url = getUrl(this);\n if (url) {\n if (pdsIconContent.has(url)) {\n this.svgContent = pdsIconContent.get(url);\n } else {\n getSvgContent(url).then(() => (this.svgContent = pdsIconContent.get(url)));\n }\n }\n }\n\n const label = getName(this.name, this.icon);\n\n if (label) {\n this.ariaLabel = label.replace(/\\-/g, ' ');\n }\n }\n\n render() {\n const { ariaLabel, inheritedAttributes } = this;\n\n const style = {\n height: this.iconSize(),\n width: this.iconSize(),\n color: this.color,\n }\n\n return (\n\n <Host\n aria-label={ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null }\n role=\"img\"\n style={style}\n class={{\n ...createColorClasses(this.color),\n }}\n {...inheritedAttributes}\n >\n {Build.isBrowser && this.svgContent ? (\n <div class=\"icon-inner\" innerHTML={this.svgContent}></div>\n ) : (\n <div class=\"icon-inner\"></div>\n )}\n </Host>\n )\n }\n\n /*****\n * Private Methods\n ****/\n\n private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {\n if (Build.isBrowser && typeof window !== 'undefined' && (window).IntersectionObserver) {\n const io = (this.io = new (window).IntersectionObserver(\n (data: IntersectionObserverEntry[]) => {\n if (data[0].isIntersecting) {\n io.disconnect();\n this.io = undefined;\n cb();\n }\n },\n { rootMargin },\n ));\n\n io.observe(el);\n } else {\n // browser doesn't support IntersectionObserver\n // so just fallback to always show it\n cb();\n }\n }\n\n private hasAriaHidden = () => {\n const { el } = this;\n\n return el.hasAttribute('aria-hidden') && el.getAttribute('aria-hidden') === 'true';\n }\n}\n\nconst createColorClasses = (color: string | undefined) => {\n return color\n ? {\n 'pds-color': true,\n [`pds-color-${color}`]: true,\n }\n : null;\n };\n"],"version":3}
|
package/components/utils.js
CHANGED
|
@@ -2,48 +2,68 @@ import { getAssetPath } from '@stencil/core/internal/client';
|
|
|
2
2
|
|
|
3
3
|
let CACHED_MAP;
|
|
4
4
|
const addIcons = (icons) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const map = getIconMap();
|
|
6
|
+
Object.keys(icons).forEach(name => map.set(name, icons[name]));
|
|
7
7
|
};
|
|
8
8
|
const getIconMap = () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
if (typeof window === 'undefined') {
|
|
10
|
+
return new Map();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (!CACHED_MAP) {
|
|
14
|
+
const win = window; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
15
|
+
win.PdsIcons = win.PdsIcons || {};
|
|
16
|
+
CACHED_MAP = win.PdsIcons.map = win.PdsIcons.map || new Map();
|
|
17
|
+
}
|
|
18
|
+
return CACHED_MAP;
|
|
17
19
|
}
|
|
18
|
-
return CACHED_MAP;
|
|
19
|
-
}
|
|
20
20
|
};
|
|
21
|
-
const getName = (iconName) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const getName = (iconName, icon) => {
|
|
22
|
+
if (!iconName && icon && !isSrc(icon)) {
|
|
23
|
+
iconName = icon;
|
|
24
|
+
}
|
|
25
|
+
if (isStr(iconName)) {
|
|
26
|
+
iconName = toLower(iconName);
|
|
27
|
+
}
|
|
28
|
+
if (!isStr(iconName) || iconName.trim() === '') {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const invalidChars = iconName.replace(/[a-z]|-|\d/gi, '');
|
|
32
|
+
if (invalidChars != '') {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return iconName;
|
|
33
36
|
};
|
|
34
37
|
const getNamedUrl = (iconName) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const url = getIconMap().get(iconName);
|
|
39
|
+
if (url) {
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
return getAssetPath(`svg/${iconName}.svg`);
|
|
40
43
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const getSrc = (src) => {
|
|
45
|
+
if (isStr(src)) {
|
|
46
|
+
src = src.trim();
|
|
47
|
+
if (isSrc(src)) {
|
|
48
|
+
return src;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
46
52
|
};
|
|
53
|
+
const getUrl = (pdsIcon) => {
|
|
54
|
+
let url = getName(pdsIcon.name, pdsIcon.icon);
|
|
55
|
+
if (url) {
|
|
56
|
+
return getNamedUrl(url);
|
|
57
|
+
}
|
|
58
|
+
if (pdsIcon.icon) {
|
|
59
|
+
url = getSrc(pdsIcon.icon);
|
|
60
|
+
if (url) {
|
|
61
|
+
return url;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str);
|
|
47
67
|
const isStr = (val) => typeof val === 'string'; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
48
68
|
const toLower = (val) => val.toLowerCase();
|
|
49
69
|
/**
|
|
@@ -57,17 +77,17 @@ const toLower = (val) => val.toLowerCase();
|
|
|
57
77
|
* does not trigger a re-render.
|
|
58
78
|
*/
|
|
59
79
|
const inheritAttributes = (el, attributes = []) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
const attributeObject = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
|
+
attributes.forEach(attr => {
|
|
82
|
+
if (el.hasAttribute(attr)) {
|
|
83
|
+
const value = el.getAttribute(attr);
|
|
84
|
+
if (value !== null) {
|
|
85
|
+
attributeObject[attr] = el.getAttribute(attr);
|
|
86
|
+
}
|
|
87
|
+
el.removeAttribute(attr);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return attributeObject;
|
|
71
91
|
};
|
|
72
92
|
|
|
73
93
|
export { addIcons as a, inheritAttributes as b, getName as c, getUrl as g, isStr as i };
|
package/components/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"utils.js","mappings":";;AAGA,IAAI,UAA+B,CAAC;MAEvB,QAAQ,GAAG,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AE,aAAuB,EAAE;IAC3E,MAAM,eAAe,GAAyB,EAAE,CAAC;IAEjD,UAAU,CAAC,OAAO,CAAC,IAAI;QACrB,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YACzB,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,KAAK,KAAK,IAAI,EAAE;gBAClB,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;aAC/C;YACD,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC1B;KACF,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACzB;;;;","names":[],"sources":["src/components/pds-icon/utils.ts"],"sourcesContent":["import { getAssetPath } from '@stencil/core';\nimport { PdsIcon } from './pds-icon';\n\nlet CACHED_MAP: Map<string, string>;\n\nexport const addIcons = (icons: { [name: string]: string; }) => {\n const map = getIconMap();\n Object.keys(icons).forEach(name => map.set(name, icons[name]));\n}\n\nexport const getIconMap = (): Map<string, string> => {\n if (typeof window === 'undefined') {\n return new Map();\n } else {\n if (!CACHED_MAP) {\n const win = window as any; // eslint-disable-line @typescript-eslint/no-explicit-any\n win.PdsIcons = win.PdsIcons || {};\n CACHED_MAP = win.PdsIcons.map = win.PdsIcons.map || new Map();\n }\n\n return CACHED_MAP;\n }\n}\n\nexport const getName = (\n iconName: string | undefined,\n icon: string | undefined\n ) => {\n\n if(!iconName && icon && !isSrc(icon)) {\n iconName = icon;\n }\n\n if (isStr(iconName)) {\n iconName = toLower(iconName);\n }\n\n if (!isStr(iconName) || iconName.trim() === '') {\n return null;\n }\n\n const invalidChars = iconName.replace(/[a-z]|-|\\d/gi,'');\n if (invalidChars != '') { return null; }\n\n return iconName;\n}\n\nconst getNamedUrl = (iconName: string) => {\n const url = getIconMap().get(iconName);\n if (url) {\n return url;\n }\n\n return getAssetPath(`svg/${iconName}.svg`);\n};\n\nexport const getSrc = (src: string | undefined) => {\n if (isStr(src)) {\n src = src.trim();\n\n if (isSrc(src)) {\n return src;\n }\n }\n\n return null;\n}\n\nexport const getUrl = (pdsIcon: PdsIcon) => {\n let url = getName(pdsIcon.name, pdsIcon.icon);\n if (url) {\n return getNamedUrl(url);\n }\n\n if (pdsIcon.icon) {\n url = getSrc(pdsIcon.icon);\n\n if(url) {\n return url;\n }\n }\n\n return null;\n};\n\n\nexport const isSrc = (str: string) => str.length > 0 && /(\\/|\\.)/.test(str);\nexport const isStr = (val: any): val is string => typeof val === 'string'; // eslint-disable-line @typescript-eslint/no-explicit-any\nexport const toLower = (val: string) => val.toLowerCase();\n\n/**\n * Elements inside of web components sometimes need to inherit global attributes\n * set on the host. For example, the inner input in `ion-input` should inherit\n * the `title` attribute that developers set directly on `ion-input`. This\n * helper function should be called in componentWillLoad and assigned to a variable\n * that is later used in the render function.\n *\n * This does not need to be reactive as changing attributes on the host element\n * does not trigger a re-render.\n */\n export const inheritAttributes = (el: HTMLElement, attributes: string[] = []) => {\n const attributeObject: { [k: string]: any } = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n attributes.forEach(attr => {\n if (el.hasAttribute(attr)) {\n const value = el.getAttribute(attr);\n if (value !== null) {\n attributeObject[attr] = el.getAttribute(attr);\n }\n el.removeAttribute(attr);\n }\n });\n\n return attributeObject;\n}\n"],"version":3}
|