@swisspost/design-system-components 1.3.2 → 1.3.4
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/dist/cjs/{index-a8b23f1b.js → index-126f28cf.js} +1 -11
- package/dist/cjs/index-126f28cf.js.map +1 -0
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/{check-type-f24cf91d.js → package-3838cb5b.js} +4 -1
- package/dist/cjs/{check-type-f24cf91d.js.map → package-3838cb5b.js.map} +1 -1
- package/dist/cjs/post-collapsible.cjs.entry.js +6 -6
- package/dist/cjs/post-collapsible.cjs.entry.js.map +1 -1
- package/dist/cjs/post-components.cjs.js +3 -3
- package/dist/cjs/post-components.cjs.js.map +1 -1
- package/dist/cjs/post-icon.cjs.entry.js +101 -62
- package/dist/cjs/post-icon.cjs.entry.js.map +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/post-collapsible/post-collapsible.css +184 -82
- package/dist/collection/components/post-collapsible/post-collapsible.js +3 -2
- package/dist/collection/components/post-collapsible/post-collapsible.js.map +1 -1
- package/dist/collection/components/post-icon/post-icon.css +10 -10
- package/dist/collection/components/post-icon/post-icon.js +119 -74
- package/dist/collection/components/post-icon/post-icon.js.map +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/utils/get-element-height.js.map +1 -1
- package/dist/collection/utils/index.js.map +1 -1
- package/dist/collection/utils/on-transition-end.js.map +1 -1
- package/dist/collection/utils/property-checkers/check-non-empty.js +7 -0
- package/dist/collection/utils/property-checkers/check-non-empty.js.map +1 -0
- package/dist/collection/utils/property-checkers/check-one-of.js.map +1 -1
- package/dist/collection/utils/property-checkers/check-type.js.map +1 -1
- package/dist/collection/utils/property-checkers/constants.js +2 -0
- package/dist/collection/utils/property-checkers/constants.js.map +1 -0
- package/dist/collection/utils/property-checkers/empty-or.js +1 -1
- package/dist/collection/utils/property-checkers/empty-or.js.map +1 -1
- package/dist/collection/utils/property-checkers/index.js +1 -0
- package/dist/collection/utils/property-checkers/index.js.map +1 -1
- package/dist/collection/utils/should-reduce-motion.js.map +1 -1
- package/dist/components/{check-type.js → package.js} +4 -2
- package/dist/components/package.js.map +1 -0
- package/dist/components/post-collapsible.js +4 -4
- package/dist/components/post-collapsible.js.map +1 -1
- package/dist/components/post-icon.js +99 -58
- package/dist/components/post-icon.js.map +1 -1
- package/dist/docs.json +35 -8
- package/dist/esm/{index-401f2d6a.js → index-286143e7.js} +1 -11
- package/dist/esm/index-286143e7.js.map +1 -0
- package/dist/esm/loader.js +4 -4
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/{check-type-67411ed3.js → package-fb4a74d0.js} +4 -2
- package/dist/esm/package-fb4a74d0.js.map +1 -0
- package/dist/esm/post-collapsible.entry.js +4 -4
- package/dist/esm/post-collapsible.entry.js.map +1 -1
- package/dist/esm/post-components.js +4 -4
- package/dist/esm/post-components.js.map +1 -1
- package/dist/esm/post-icon.entry.js +98 -59
- package/dist/esm/post-icon.entry.js.map +1 -1
- package/dist/post-components/{p-f214c52a.js → p-0c286590.js} +3 -3
- package/dist/post-components/p-0c286590.js.map +1 -0
- package/dist/post-components/p-6e225c16.entry.js +2 -0
- package/dist/post-components/p-6e225c16.entry.js.map +1 -0
- package/dist/post-components/p-7dd960f1.entry.js +2 -0
- package/dist/post-components/p-7dd960f1.entry.js.map +1 -0
- package/dist/post-components/p-87bf3416.js +2 -0
- package/dist/post-components/{p-f549b3fc.js.map → p-87bf3416.js.map} +1 -1
- package/dist/post-components/post-components.esm.js +1 -1
- package/dist/post-components/post-components.esm.js.map +1 -1
- package/dist/types/components/post-icon/post-icon.d.ts +21 -12
- package/dist/types/components.d.ts +17 -17
- package/dist/types/utils/property-checkers/check-non-empty.d.ts +1 -0
- package/dist/types/utils/property-checkers/constants.d.ts +1 -0
- package/dist/types/utils/property-checkers/index.d.ts +1 -0
- package/package.json +16 -17
- package/dist/cjs/index-a8b23f1b.js.map +0 -1
- package/dist/components/check-type.js.map +0 -1
- package/dist/esm/check-type-67411ed3.js.map +0 -1
- package/dist/esm/index-401f2d6a.js.map +0 -1
- package/dist/post-components/p-07a51673.entry.js +0 -2
- package/dist/post-components/p-07a51673.entry.js.map +0 -1
- package/dist/post-components/p-416f1e74.entry.js +0 -2
- package/dist/post-components/p-416f1e74.entry.js.map +0 -1
- package/dist/post-components/p-f214c52a.js.map +0 -1
- package/dist/post-components/p-f549b3fc.js +0 -2
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { Host, h } from '@stencil/core';
|
|
2
|
-
import { checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';
|
|
2
|
+
import { checkNonEmpty, checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';
|
|
3
|
+
import { version } from '../../../package.json';
|
|
3
4
|
const CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';
|
|
4
|
-
const
|
|
5
|
+
const ANIMATION_NAMES = [
|
|
5
6
|
'cylon',
|
|
6
7
|
'cylon-vertical',
|
|
7
8
|
'spin',
|
|
8
9
|
'spin-reverse',
|
|
9
10
|
'fade',
|
|
10
|
-
'throb'
|
|
11
|
+
'throb',
|
|
11
12
|
];
|
|
13
|
+
const ANIMATION_KEYS = [...ANIMATION_NAMES];
|
|
12
14
|
/**
|
|
13
15
|
* @class PostIcon - representing a stencil component
|
|
14
16
|
*/
|
|
15
17
|
export class PostIcon {
|
|
16
18
|
constructor() {
|
|
17
19
|
this.svgSource = '<svg viewBox="0 0 16 16"></svg>';
|
|
20
|
+
this.pathForceCDN = false;
|
|
21
|
+
this.svgStyles = undefined;
|
|
18
22
|
this.svgOutput = undefined;
|
|
19
|
-
this.animation =
|
|
20
|
-
this.base =
|
|
21
|
-
this.flipH =
|
|
22
|
-
this.flipV =
|
|
23
|
+
this.animation = null;
|
|
24
|
+
this.base = null;
|
|
25
|
+
this.flipH = false;
|
|
26
|
+
this.flipV = false;
|
|
23
27
|
this.name = undefined;
|
|
24
|
-
this.rotate =
|
|
25
|
-
this.scale =
|
|
28
|
+
this.rotate = null;
|
|
29
|
+
this.scale = null;
|
|
26
30
|
}
|
|
27
31
|
validateAnimation(newValue = this.animation) {
|
|
28
32
|
if (newValue !== undefined)
|
|
@@ -38,6 +42,7 @@ export class PostIcon {
|
|
|
38
42
|
checkEmptyOrType(newValue, 'boolean', 'The post-icon "flipV" prop should be a boolean.');
|
|
39
43
|
}
|
|
40
44
|
validateName(newValue = this.name) {
|
|
45
|
+
checkNonEmpty(newValue, 'The post-icon "name" prop is required!.');
|
|
41
46
|
checkType(newValue, 'string', 'The post-icon "name" prop should be a string.');
|
|
42
47
|
}
|
|
43
48
|
validateRotate(newValue = this.rotate) {
|
|
@@ -46,8 +51,35 @@ export class PostIcon {
|
|
|
46
51
|
validateScale(newValue = this.scale) {
|
|
47
52
|
checkEmptyOrType(newValue, 'number', 'The post-icon "scale" prop should be a number.');
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
componentWillLoad() {
|
|
55
|
+
this.validateBase();
|
|
56
|
+
this.validateName();
|
|
57
|
+
this.validateFlipH();
|
|
58
|
+
this.validateFlipV();
|
|
59
|
+
this.validateScale();
|
|
60
|
+
this.validateRotate();
|
|
61
|
+
this.validateAnimation();
|
|
62
|
+
}
|
|
63
|
+
componentWillRender() {
|
|
64
|
+
this.createIconFromStorage();
|
|
65
|
+
// create path dependant on the props
|
|
66
|
+
this.setPath();
|
|
67
|
+
// fetch icon if the prop "name" is defined and
|
|
68
|
+
// the path has not allready been loaded
|
|
69
|
+
if (this.name && this.path !== this.loadedPath) {
|
|
70
|
+
this.loadedPath = this.path;
|
|
71
|
+
this.fetchIcon()
|
|
72
|
+
.then(successfullyLoaded => {
|
|
73
|
+
// create icon only if an svg has been loaded successfully
|
|
74
|
+
if (successfullyLoaded)
|
|
75
|
+
this.createIcon();
|
|
76
|
+
})
|
|
77
|
+
.catch(error => {
|
|
78
|
+
console.error(error);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
setPath() {
|
|
51
83
|
// Construct icon path from different possible sources
|
|
52
84
|
let basePath;
|
|
53
85
|
const metaBase = document.head.querySelector('meta[name="design-system-settings"][data-post-icon-base]');
|
|
@@ -60,20 +92,51 @@ export class PostIcon {
|
|
|
60
92
|
else {
|
|
61
93
|
basePath = CDN_URL;
|
|
62
94
|
}
|
|
63
|
-
|
|
64
|
-
this.
|
|
95
|
+
// use "basePath" only if "pathForceCDN" state is "false"
|
|
96
|
+
this.path = this.getPath(this.pathForceCDN ? CDN_URL : basePath);
|
|
97
|
+
// reset "pathForceCDN" after every try
|
|
98
|
+
this.pathForceCDN = false;
|
|
65
99
|
}
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
this.validateBase();
|
|
69
|
-
this.validateFlipH();
|
|
70
|
-
this.validateFlipV();
|
|
71
|
-
this.validateName();
|
|
72
|
-
this.validateRotate();
|
|
73
|
-
this.validateScale();
|
|
74
|
-
this.fetchSVG();
|
|
100
|
+
getPath(basePath) {
|
|
101
|
+
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
75
102
|
}
|
|
76
|
-
|
|
103
|
+
fetchIcon() {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
fetch(this.path)
|
|
106
|
+
.then(response => response.text())
|
|
107
|
+
.then(textResponse => {
|
|
108
|
+
// match "svg" out of "textResponse"
|
|
109
|
+
const match = textResponse.match(/^<svg\b([\s\S]*)><\/svg>/);
|
|
110
|
+
if (match !== null) {
|
|
111
|
+
// set "svgSource" and return "successfullyLoaded" with true
|
|
112
|
+
this.svgSource = match[0];
|
|
113
|
+
window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);
|
|
114
|
+
resolve(true);
|
|
115
|
+
}
|
|
116
|
+
else if (this.path !== this.getPath(CDN_URL)) {
|
|
117
|
+
// if used "path" is not CDN path, and fetch has loaded something else than a "svg", try to reload it from the CDN
|
|
118
|
+
console.warn(`Warning in <post-icon/>: The path "${this.path}" seems to be no svg-only content. We'll gonna try to load the icon from the cdn.`);
|
|
119
|
+
// trigger a component update, which will result in a refetch of the icon with the "CDN_URL"
|
|
120
|
+
this.pathForceCDN = true;
|
|
121
|
+
// return "successfullyLoaded" with false
|
|
122
|
+
resolve(false);
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch(reject);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
createIconFromStorage() {
|
|
129
|
+
const storedIcon = window.localStorage.getItem(`post-icon-${this.name}`);
|
|
130
|
+
if (storedIcon) {
|
|
131
|
+
this.svgSource = storedIcon !== null && storedIcon !== void 0 ? storedIcon : this.svgSource;
|
|
132
|
+
this.createIcon();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
createIcon() {
|
|
136
|
+
// create svg element from svgSource string
|
|
137
|
+
const domParser = new DOMParser();
|
|
138
|
+
this.svgElement = domParser.parseFromString(this.svgSource, 'text/html').querySelector('svg');
|
|
139
|
+
// create inline styles for some properties
|
|
77
140
|
const svgStyles = Object.entries({
|
|
78
141
|
scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
|
|
79
142
|
rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
|
|
@@ -81,42 +144,11 @@ export class PostIcon {
|
|
|
81
144
|
.filter(([_key, value]) => value !== null)
|
|
82
145
|
.map(([key, value]) => `${key}: ${value}`)
|
|
83
146
|
.join(';');
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const svgElement = helperElement.querySelector('svg');
|
|
87
|
-
svgElement.setAttribute('style', svgStyles);
|
|
88
|
-
this.svgOutput = helperElement.innerHTML;
|
|
89
|
-
}
|
|
90
|
-
fetchSVG() {
|
|
91
|
-
fetch(this.path)
|
|
92
|
-
.then(response => response.text())
|
|
93
|
-
.then(textResponse => {
|
|
94
|
-
const match = textResponse.match(/^<svg\b([\s\S]*)><\/svg>/);
|
|
95
|
-
if (match !== null) {
|
|
96
|
-
this.svgSource = match[0];
|
|
97
|
-
window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.initialPath = this.path;
|
|
101
|
-
this.path = this.getPath(CDN_URL);
|
|
102
|
-
if (this.initialPath !== this.path) {
|
|
103
|
-
console.warn(`Warning in <post-icon/>: The content on the path "${this.path}" seems to be no svg-only content. We'll gonna try to load the icon from the cdn.`);
|
|
104
|
-
this.fetchSVG();
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
console.error(`Error in <post-icon/>: Could not load the svg on the path "${this.initialPath}"!`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
.catch(error => {
|
|
112
|
-
console.log(error);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
getPath(basePath) {
|
|
116
|
-
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
147
|
+
this.svgElement.setAttribute('style', svgStyles);
|
|
148
|
+
this.host.shadowRoot.innerHTML = this.svgElement.outerHTML;
|
|
117
149
|
}
|
|
118
150
|
render() {
|
|
119
|
-
return
|
|
151
|
+
return h(Host, { "data-version": version });
|
|
120
152
|
}
|
|
121
153
|
static get is() { return "post-icon"; }
|
|
122
154
|
static get encapsulation() { return "shadow"; }
|
|
@@ -136,24 +168,29 @@ export class PostIcon {
|
|
|
136
168
|
"type": "string",
|
|
137
169
|
"mutable": false,
|
|
138
170
|
"complexType": {
|
|
139
|
-
"original": "
|
|
140
|
-
"resolved": "
|
|
141
|
-
"references": {
|
|
171
|
+
"original": "Animation | null",
|
|
172
|
+
"resolved": "\"cylon\" | \"cylon-vertical\" | \"fade\" | \"spin\" | \"spin-reverse\" | \"throb\"",
|
|
173
|
+
"references": {
|
|
174
|
+
"Animation": {
|
|
175
|
+
"location": "global"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
142
178
|
},
|
|
143
179
|
"required": false,
|
|
144
180
|
"optional": true,
|
|
145
181
|
"docs": {
|
|
146
182
|
"tags": [],
|
|
147
|
-
"text": "The name of the animation
|
|
183
|
+
"text": "The name of the animation."
|
|
148
184
|
},
|
|
149
185
|
"attribute": "animation",
|
|
150
|
-
"reflect": false
|
|
186
|
+
"reflect": false,
|
|
187
|
+
"defaultValue": "null"
|
|
151
188
|
},
|
|
152
189
|
"base": {
|
|
153
190
|
"type": "string",
|
|
154
191
|
"mutable": false,
|
|
155
192
|
"complexType": {
|
|
156
|
-
"original": "string",
|
|
193
|
+
"original": "string | null",
|
|
157
194
|
"resolved": "string",
|
|
158
195
|
"references": {}
|
|
159
196
|
},
|
|
@@ -161,10 +198,11 @@ export class PostIcon {
|
|
|
161
198
|
"optional": true,
|
|
162
199
|
"docs": {
|
|
163
200
|
"tags": [],
|
|
164
|
-
"text": "The base path, where the icons are located (must be a public url)."
|
|
201
|
+
"text": "The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url."
|
|
165
202
|
},
|
|
166
203
|
"attribute": "base",
|
|
167
|
-
"reflect": false
|
|
204
|
+
"reflect": false,
|
|
205
|
+
"defaultValue": "null"
|
|
168
206
|
},
|
|
169
207
|
"flipH": {
|
|
170
208
|
"type": "boolean",
|
|
@@ -181,7 +219,8 @@ export class PostIcon {
|
|
|
181
219
|
"text": "When set to `true`, the icon will be flipped horizontally."
|
|
182
220
|
},
|
|
183
221
|
"attribute": "flip-h",
|
|
184
|
-
"reflect": false
|
|
222
|
+
"reflect": false,
|
|
223
|
+
"defaultValue": "false"
|
|
185
224
|
},
|
|
186
225
|
"flipV": {
|
|
187
226
|
"type": "boolean",
|
|
@@ -198,7 +237,8 @@ export class PostIcon {
|
|
|
198
237
|
"text": "When set to `true`, the icon will be flipped vertically."
|
|
199
238
|
},
|
|
200
239
|
"attribute": "flip-v",
|
|
201
|
-
"reflect": false
|
|
240
|
+
"reflect": false,
|
|
241
|
+
"defaultValue": "false"
|
|
202
242
|
},
|
|
203
243
|
"name": {
|
|
204
244
|
"type": "string",
|
|
@@ -208,7 +248,7 @@ export class PostIcon {
|
|
|
208
248
|
"resolved": "string",
|
|
209
249
|
"references": {}
|
|
210
250
|
},
|
|
211
|
-
"required":
|
|
251
|
+
"required": true,
|
|
212
252
|
"optional": false,
|
|
213
253
|
"docs": {
|
|
214
254
|
"tags": [],
|
|
@@ -221,7 +261,7 @@ export class PostIcon {
|
|
|
221
261
|
"type": "number",
|
|
222
262
|
"mutable": false,
|
|
223
263
|
"complexType": {
|
|
224
|
-
"original": "number",
|
|
264
|
+
"original": "number | null",
|
|
225
265
|
"resolved": "number",
|
|
226
266
|
"references": {}
|
|
227
267
|
},
|
|
@@ -229,16 +269,17 @@ export class PostIcon {
|
|
|
229
269
|
"optional": true,
|
|
230
270
|
"docs": {
|
|
231
271
|
"tags": [],
|
|
232
|
-
"text": "The
|
|
272
|
+
"text": "The number of degree for the css rotate transformation."
|
|
233
273
|
},
|
|
234
274
|
"attribute": "rotate",
|
|
235
|
-
"reflect": false
|
|
275
|
+
"reflect": false,
|
|
276
|
+
"defaultValue": "null"
|
|
236
277
|
},
|
|
237
278
|
"scale": {
|
|
238
279
|
"type": "number",
|
|
239
280
|
"mutable": false,
|
|
240
281
|
"complexType": {
|
|
241
|
-
"original": "number",
|
|
282
|
+
"original": "number | null",
|
|
242
283
|
"resolved": "number",
|
|
243
284
|
"references": {}
|
|
244
285
|
},
|
|
@@ -246,18 +287,22 @@ export class PostIcon {
|
|
|
246
287
|
"optional": true,
|
|
247
288
|
"docs": {
|
|
248
289
|
"tags": [],
|
|
249
|
-
"text": "The
|
|
290
|
+
"text": "The number for the css scale transformation."
|
|
250
291
|
},
|
|
251
292
|
"attribute": "scale",
|
|
252
|
-
"reflect": false
|
|
293
|
+
"reflect": false,
|
|
294
|
+
"defaultValue": "null"
|
|
253
295
|
}
|
|
254
296
|
};
|
|
255
297
|
}
|
|
256
298
|
static get states() {
|
|
257
299
|
return {
|
|
300
|
+
"pathForceCDN": {},
|
|
301
|
+
"svgStyles": {},
|
|
258
302
|
"svgOutput": {}
|
|
259
303
|
};
|
|
260
304
|
}
|
|
305
|
+
static get elementRef() { return "host"; }
|
|
261
306
|
static get watchers() {
|
|
262
307
|
return [{
|
|
263
308
|
"propName": "animation",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-icon.js","sourceRoot":"","sources":["../../../src/components/post-icon/post-icon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,OAAO,GAAG,oEAAoE,CAAC;AACrF,MAAM,cAAc,GAAG;EACrB,OAAO;EACP,gBAAgB;EAChB,MAAM;EACN,cAAc;EACd,MAAM;EACN,OAAO;CACR,CAAC;AAEF;;GAEG;AAMH,MAAM,OAAO,QAAQ;;IAGX,cAAS,GAAG,iCAAiC,CAAC;;;;;;;;;;EAUtD,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;IACzC,IAAI,QAAQ,KAAK,SAAS;MAAE,iBAAiB,CAAC,QAAQ,EAAE,cAAc,EAAE,wEAAwE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;EAChL,CAAC;EAQD,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI;IAC/B,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,+CAA+C,CAAC,CAAC;EACxF,CAAC;EAQD,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK;IACjC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,iDAAiD,CAAC,CAAC;EAC3F,CAAC;EAQD,aAAa,CAAC,QAAQ,GAAG,IAAI,CA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AC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Host, h, Prop, State, Watch } from '@stencil/core';\nimport { checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';\n\nconst CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';\nconst ANIMATION_KEYS = [\n 'cylon',\n 'cylon-vertical',\n 'spin',\n 'spin-reverse',\n 'fade',\n 'throb'\n];\n\n/**\n * @class PostIcon - representing a stencil component\n */\n@Component({\n tag: 'post-icon',\n styleUrl: 'post-icon.scss',\n shadow: true,\n})\nexport class PostIcon {\n private initialPath: string;\n private path: string;\n private svgSource = '<svg viewBox=\"0 0 16 16\"></svg>';\n\n @State() svgOutput: string;\n\n /**\n * The name of the animation (`cylon`, `cylon-vertical`, `spin`, `spin-reverse`, `fade`, `throb`).\n */\n @Prop() readonly animation?: string;\n\n @Watch('animation')\n validateAnimation(newValue = this.animation) {\n if (newValue !== undefined) checkEmptyOrOneOf(newValue, ANIMATION_KEYS, `The post-icon \"animation\" prop requires one of the following values: ${ANIMATION_KEYS.join(', ')}.`);\n }\n\n /**\n * The base path, where the icons are located (must be a public url).\n */\n @Prop() readonly base?: string;\n\n @Watch('base')\n validateBase(newValue = this.base) {\n checkEmptyOrType(newValue, 'string', 'The post-icon \"base\" prop should be a string.');\n }\n\n /**\n * When set to `true`, the icon will be flipped horizontally.\n */\n @Prop() readonly flipH?: boolean;\n\n @Watch('flipH')\n validateFlipH(newValue = this.flipH) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipH\" prop should be a boolean.');\n }\n\n /**\n * When set to `true`, the icon will be flipped vertically.\n */\n @Prop() readonly flipV?: boolean;\n\n @Watch('flipV')\n validateFlipV(newValue = this.flipV) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipV\" prop should be a boolean.');\n }\n\n /**\n * The name/id of the icon (e.g. 1000, 1001, ...).\n */\n @Prop() readonly name: string;\n\n @Watch('name')\n validateName(newValue = this.name) {\n checkType(newValue, 'string', 'The post-icon \"name\" prop should be a string.');\n }\n\n /**\n * The `number` of degree for the css `rotate` transformation.\n */\n @Prop() readonly rotate?: number;\n\n @Watch('rotate')\n validateRotate(newValue = this.rotate) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"rotate\" prop should be a number.');\n }\n\n /**\n * The `number` for the css `scale` transformation.\n */\n @Prop() readonly scale?: number;\n\n @Watch('scale')\n validateScale(newValue = this.scale) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"scale\" prop should be a number.');\n }\n\n connectedCallback() {\n // Construct icon path from different possible sources\n let basePath: string;\n const metaBase = document.head.querySelector(\n 'meta[name=\"design-system-settings\"][data-post-icon-base]',\n );\n\n if (this.base) {\n basePath = this.base;\n } else if (metaBase) {\n basePath = metaBase.getAttribute('data-post-icon-base');\n } else {\n basePath = CDN_URL;\n }\n\n this.path = this.getPath(basePath);\n this.svgSource = window.localStorage.getItem(`post-icon-${this.name}`) ?? this.svgSource;\n }\n\n componentWillLoad() {\n this.validateAnimation();\n this.validateBase();\n this.validateFlipH();\n this.validateFlipV();\n this.validateName();\n this.validateRotate();\n this.validateScale();\n\n this.fetchSVG();\n }\n\n componentWillRender() {\n const svgStyles = Object.entries({\n scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,\n rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,\n })\n .filter(([_key, value]) => value !== null)\n .map(([key, value]) => `${key}: ${value}`)\n .join(';');\n\n const helperElement = document.createElement('div');\n helperElement.innerHTML = this.svgSource;\n\n const svgElement = helperElement.querySelector('svg');\n svgElement.setAttribute('style', svgStyles);\n\n this.svgOutput = helperElement.innerHTML;\n }\n\n private fetchSVG() {\n fetch(this.path)\n .then(response => response.text())\n .then(textResponse => {\n const match = textResponse.match(/^<svg\\b([\\s\\S]*)><\\/svg>/);\n\n if (match !== null) {\n this.svgSource = match[0];\n window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);\n } else {\n this.initialPath = this.path;\n this.path = this.getPath(CDN_URL);\n\n if (this.initialPath !== this.path) {\n console.warn(\n `Warning in <post-icon/>: The content on the path \"${this.path}\" seems to be no svg-only content. We'll gonna try to load the icon from the cdn.`,\n );\n this.fetchSVG();\n } else {\n console.error(\n `Error in <post-icon/>: Could not load the svg on the path \"${this.initialPath}\"!`,\n );\n }\n }\n })\n .catch(error => {\n console.log(error);\n });\n }\n\n private getPath(basePath: string) {\n return new URL(\n [...basePath.split('/'), `${this.name}.svg#icon`].join('/'),\n window.location.origin,\n ).toString();\n }\n\n render() {\n return (\n <Host>\n <div innerHTML={this.svgOutput} />\n </Host>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"post-icon.js","sourceRoot":"","sources":["../../../../src/components/post-icon/post-icon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,OAAO,GAAG,oEAAoE,CAAC;AACrF,MAAM,eAAe,GAAG;EACtB,OAAO;EACP,gBAAgB;EAChB,MAAM;EACN,cAAc;EACd,MAAM;EACN,OAAO;CACC,CAAC;AACX,MAAM,cAAc,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC;AAI5C;;GAEG;AAMH,MAAM,OAAO,QAAQ;;IAGX,cAAS,GAAG,iCAAiC,CAAC;wBAK9B,KAAK;;;qBAOmB,I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,CAAC,CAAC;IACjD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;EAC7D,CAAC;EAED,MAAM;IACJ,OAAO,EAAC,IAAI,oBAAe,OAAO,GAAI,CAAC;EACzC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Host, h, Prop, State, Watch } from '@stencil/core';\nimport { checkNonEmpty, checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';\nimport { version } from '../../../package.json';\n\nconst CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';\nconst ANIMATION_NAMES = [\n 'cylon',\n 'cylon-vertical',\n 'spin',\n 'spin-reverse',\n 'fade',\n 'throb',\n] as const;\nconst ANIMATION_KEYS = [...ANIMATION_NAMES];\n\ntype Animation = (typeof ANIMATION_NAMES)[number];\n\n/**\n * @class PostIcon - representing a stencil component\n */\n@Component({\n tag: 'post-icon',\n styleUrl: 'post-icon.scss',\n shadow: true,\n})\nexport class PostIcon {\n private path: string;\n private loadedPath: string;\n private svgSource = '<svg viewBox=\"0 0 16 16\"></svg>';\n private svgElement: SVGElement;\n\n @Element() host: HTMLPostIconElement;\n\n @State() pathForceCDN = false;\n @State() svgStyles: string;\n @State() svgOutput: string;\n\n /**\n * The name of the animation.\n */\n @Prop() readonly animation?: Animation | null = null;\n\n @Watch('animation')\n validateAnimation(newValue = this.animation) {\n if (newValue !== undefined)\n checkEmptyOrOneOf(\n newValue,\n ANIMATION_KEYS,\n `The post-icon \"animation\" prop requires one of the following values: ${ANIMATION_KEYS.join(\n ', ',\n )}.`,\n );\n }\n\n /**\n * The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url.\n */\n @Prop() readonly base?: string | null = null;\n\n @Watch('base')\n validateBase(newValue = this.base) {\n checkEmptyOrType(newValue, 'string', 'The post-icon \"base\" prop should be a string.');\n }\n\n /**\n * When set to `true`, the icon will be flipped horizontally.\n */\n @Prop() readonly flipH?: boolean = false;\n\n @Watch('flipH')\n validateFlipH(newValue = this.flipH) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipH\" prop should be a boolean.');\n }\n\n /**\n * When set to `true`, the icon will be flipped vertically.\n */\n @Prop() readonly flipV?: boolean = false;\n\n @Watch('flipV')\n validateFlipV(newValue = this.flipV) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipV\" prop should be a boolean.');\n }\n\n /**\n * The name/id of the icon (e.g. 1000, 1001, ...).\n */\n @Prop() readonly name!: string;\n\n @Watch('name')\n validateName(newValue = this.name) {\n checkNonEmpty(newValue, 'The post-icon \"name\" prop is required!.');\n checkType(newValue, 'string', 'The post-icon \"name\" prop should be a string.');\n }\n\n /**\n * The number of degree for the css rotate transformation.\n */\n @Prop() readonly rotate?: number | null = null;\n\n @Watch('rotate')\n validateRotate(newValue = this.rotate) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"rotate\" prop should be a number.');\n }\n\n /**\n * The number for the css scale transformation.\n */\n @Prop() readonly scale?: number | null = null;\n\n @Watch('scale')\n validateScale(newValue = this.scale) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"scale\" prop should be a number.');\n }\n\n componentWillLoad() {\n this.validateBase();\n this.validateName();\n this.validateFlipH();\n this.validateFlipV();\n this.validateScale();\n this.validateRotate();\n this.validateAnimation();\n }\n\n componentWillRender() {\n this.createIconFromStorage();\n\n // create path dependant on the props\n this.setPath();\n\n // fetch icon if the prop \"name\" is defined and\n // the path has not allready been loaded\n if (this.name && this.path !== this.loadedPath) {\n this.loadedPath = this.path;\n\n this.fetchIcon()\n .then(successfullyLoaded => {\n // create icon only if an svg has been loaded successfully\n if (successfullyLoaded) this.createIcon();\n })\n .catch(error => {\n console.error(error);\n });\n }\n }\n\n private setPath() {\n // Construct icon path from different possible sources\n let basePath: string;\n const metaBase = document.head.querySelector(\n 'meta[name=\"design-system-settings\"][data-post-icon-base]',\n );\n\n if (this.base) {\n basePath = this.base;\n } else if (metaBase) {\n basePath = metaBase.getAttribute('data-post-icon-base');\n } else {\n basePath = CDN_URL;\n }\n\n // use \"basePath\" only if \"pathForceCDN\" state is \"false\"\n this.path = this.getPath(this.pathForceCDN ? CDN_URL : basePath);\n // reset \"pathForceCDN\" after every try\n this.pathForceCDN = false;\n }\n\n private getPath(basePath: string) {\n return new URL(\n [...basePath.split('/'), `${this.name}.svg#icon`].join('/'),\n window.location.origin,\n ).toString();\n }\n\n private fetchIcon() {\n return new Promise((resolve, reject) => {\n fetch(this.path)\n .then(response => response.text())\n .then(textResponse => {\n // match \"svg\" out of \"textResponse\"\n const match = textResponse.match(/^<svg\\b([\\s\\S]*)><\\/svg>/);\n\n if (match !== null) {\n // set \"svgSource\" and return \"successfullyLoaded\" with true\n this.svgSource = match[0];\n window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);\n resolve(true);\n } else if (this.path !== this.getPath(CDN_URL)) {\n // if used \"path\" is not CDN path, and fetch has loaded something else than a \"svg\", try to reload it from the CDN\n console.warn(\n `Warning in <post-icon/>: The path \"${this.path}\" seems to be no svg-only content. We'll gonna try to load the icon from the cdn.`,\n );\n // trigger a component update, which will result in a refetch of the icon with the \"CDN_URL\"\n this.pathForceCDN = true;\n // return \"successfullyLoaded\" with false\n resolve(false);\n }\n })\n .catch(reject);\n });\n }\n\n private createIconFromStorage() {\n const storedIcon = window.localStorage.getItem(`post-icon-${this.name}`);\n\n if (storedIcon) {\n this.svgSource = storedIcon ?? this.svgSource;\n this.createIcon();\n }\n }\n\n private createIcon() {\n // create svg element from svgSource string\n const domParser = new DOMParser();\n this.svgElement = domParser.parseFromString(this.svgSource, 'text/html').querySelector('svg');\n\n // create inline styles for some properties\n const svgStyles = Object.entries({\n scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,\n rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,\n })\n .filter(([_key, value]) => value !== null)\n .map(([key, value]) => `${key}: ${value}`)\n .join(';');\n\n this.svgElement.setAttribute('style', svgStyles);\n this.host.shadowRoot.innerHTML = this.svgElement.outerHTML;\n }\n\n render() {\n return <Host data-version={version} />;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"","sourcesContent":["export { Components, JSX } from './components';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-element-height.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"get-element-height.js","sourceRoot":"","sources":["../../../src/utils/get-element-height.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,gBAAgB,CAAC,EAAe,EAAE,mBAAsC,EAAE;EACxF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;IAAE,gBAAgB,GAAG,CAAC,gBAAgB,CAAC,CAAC;EAE5E,MAAM,YAAY,GAAG,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;EACrF,IAAI,YAAY,CAAC,MAAM;IAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;EAE3D,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC;EAErC,IAAI,YAAY,CAAC,MAAM;IAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC;EAE9D,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["export function getElementHeight(el: HTMLElement): number;\nexport function getElementHeight(el: HTMLElement, classWhenShown: string): number;\nexport function getElementHeight(el: HTMLElement, classesWhenShown: string[]): number;\nexport function getElementHeight(el: HTMLElement, classesWhenShown: string | string[] = []): number {\n if (!Array.isArray(classesWhenShown)) classesWhenShown = [classesWhenShown];\n\n const classesToAdd = classesWhenShown.filter(klass => !el.classList.contains(klass));\n if (classesToAdd.length) el.classList.add(...classesToAdd);\n\n const scrollHeight = el.scrollHeight;\n\n if (classesToAdd.length) el.classList.remove(...classesToAdd);\n\n return scrollHeight;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './get-element-height';\nexport * from './on-transition-end';\nexport * from './property-checkers';\nexport * from './should-reduce-motion';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-transition-end.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"on-transition-end.js","sourceRoot":"","sources":["../../../src/utils/on-transition-end.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAe;EACnD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;IAC3B,IAAI,kBAAkB,EAAE,EAAE;MACxB,OAAO,EAAE,CAAC;KACX;SAAM;MACL,EAAE,CAAC,eAAe,GAAG,GAAG,EAAE;QACxB,OAAO,EAAE,CAAC;QACV,EAAE,CAAC,eAAe,GAAG,IAAI,CAAC;MAC5B,CAAC,CAAC;KACH;EACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { shouldReduceMotion } from './should-reduce-motion';\n\nexport async function onTransitionEnd(el: HTMLElement): Promise<void> {\n return new Promise(resolve => {\n if (shouldReduceMotion()) {\n resolve();\n } else {\n el.ontransitionend = () => {\n resolve();\n el.ontransitionend = null;\n };\n }\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-non-empty.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/check-non-empty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,KAAa;EACzD,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE;IACvC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GACxB;AACH,CAAC","sourcesContent":["import { EMPTY_VALUES } from './constants';\n\nexport function checkNonEmpty(value: unknown, error: string) {\n if (EMPTY_VALUES.some(v => v === value)) {\n throw new Error(error);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-one-of.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"check-one-of.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/check-one-of.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAI,KAAQ,EAAE,cAAmB,EAAE,KAAa;EACxE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC;IAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["export function checkOneOf<T>(value: T, possibleValues: T[], error: string) {\n if (!possibleValues.includes(value)) throw new Error(error);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-type.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"check-type.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/check-type.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,IAAkB,EAAE,KAAa;EACzE,MAAM,WAAW,GAAG,IAAI,KAAK,OAAO,CAAC;EACrC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;EAE1C,IAAI,WAAW,IAAI,YAAY,EAAE;IAC/B,IAAI,YAAY,KAAK,WAAW;MAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GAC1D;OAAM;IACL,IAAI,OAAO,KAAK,KAAK,IAAI;MAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GACnD;AACH,CAAC","sourcesContent":["export type PropertyType =\n | 'boolean'\n | 'number'\n | 'string'\n | 'array'\n | 'object'\n | 'function';\n\nexport function checkType(value: unknown, type: PropertyType, error: string) {\n const typeIsArray = type === 'array';\n const valueIsArray = Array.isArray(value);\n\n if (typeIsArray || valueIsArray) {\n if (valueIsArray !== typeIsArray) throw new Error(error);\n } else {\n if (typeof value !== type) throw new Error(error);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC","sourcesContent":["export const EMPTY_VALUES = [undefined, null, ''];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-or.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"empty-or.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/empty-or.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,UAAU,OAAO,CAAsB,KAA2B;EACtE,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE;IACpB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC;MAAE,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;EAC3D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { EMPTY_VALUES } from './constants';\n\nexport function emptyOr<T extends unknown[]>(check: (...args: T) => void) {\n return (...args: T) => {\n const value = args[0];\n if (!EMPTY_VALUES.some(v => v === value)) check(...args);\n };\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { checkOneOf } from './check-one-of';
|
|
|
3
3
|
import { checkType } from './check-type';
|
|
4
4
|
export const checkEmptyOrOneOf = emptyOr(checkOneOf);
|
|
5
5
|
export const checkEmptyOrType = emptyOr(checkType);
|
|
6
|
+
export * from './check-non-empty';
|
|
6
7
|
export * from './check-one-of';
|
|
7
8
|
export * from './check-type';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/property-checkers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC","sourcesContent":["import { emptyOr } from './empty-or';\nimport { checkOneOf } from './check-one-of';\nimport { checkType } from './check-type';\n\nexport const checkEmptyOrOneOf = emptyOr(checkOneOf);\nexport const checkEmptyOrType = emptyOr(checkType);\n\nexport * from './check-non-empty';\nexport * from './check-one-of';\nexport * from './check-type';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-reduce-motion.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"should-reduce-motion.js","sourceRoot":"","sources":["../../../src/utils/should-reduce-motion.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB;EAChC,OAAO,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC","sourcesContent":["export function shouldReduceMotion(): boolean {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n"]}
|
|
@@ -16,6 +16,8 @@ function checkType(value, type, error) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const version = "1.3.4";
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export { checkOneOf as a, checkType as c, version as v };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"package.js","mappings":"SAAgB,UAAU,CAAI,KAAQ,EAAE,cAAmB,EAAE,KAAa;EACxE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC;IAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC9D;;SCMgB,SAAS,CAAC,KAAc,EAAE,IAAkB,EAAE,KAAa;EACzE,MAAM,WAAW,GAAG,IAAI,KAAK,OAAO,CAAC;EACrC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;EAE1C,IAAI,WAAW,IAAI,YAAY,EAAE;IAC/B,IAAI,YAAY,KAAK,WAAW;MAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GAC1D;OAAM;IACL,IAAI,OAAO,KAAK,KAAK,IAAI;MAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GACnD;AACH;;;;;;","names":[],"sources":["./src/utils/property-checkers/check-one-of.ts","./src/utils/property-checkers/check-type.ts"],"sourcesContent":["export function checkOneOf<T>(value: T, possibleValues: T[], error: string) {\n if (!possibleValues.includes(value)) throw new Error(error);\n}\n","export type PropertyType =\n | 'boolean'\n | 'number'\n | 'string'\n | 'array'\n | 'object'\n | 'function';\n\nexport function checkType(value: unknown, type: PropertyType, error: string) {\n const typeIsArray = type === 'array';\n const valueIsArray = Array.isArray(value);\n\n if (typeIsArray || valueIsArray) {\n if (valueIsArray !== typeIsArray) throw new Error(error);\n } else {\n if (typeof value !== type) throw new Error(error);\n }\n}\n"],"version":3}
|