@swisspost/design-system-components 1.3.3 → 1.3.5
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-126f28cf.js → index-f95ab17b.js} +62 -20
- package/dist/cjs/index-f95ab17b.js.map +1 -0
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/{package-f1eacd4f.js → package-5e7ba83a.js} +2 -2
- package/dist/cjs/{package-f1eacd4f.js.map → package-5e7ba83a.js.map} +1 -1
- package/dist/cjs/post-collapsible.cjs.entry.js +3 -3
- 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 +28 -90
- package/dist/cjs/post-icon.cjs.entry.js.map +1 -1
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/post-collapsible/post-collapsible.css +1166 -48
- package/dist/collection/components/post-icon/post-icon.css +10 -10
- package/dist/collection/components/post-icon/post-icon.js +53 -105
- package/dist/collection/components/post-icon/post-icon.js.map +1 -1
- package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js +36 -0
- package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js +13 -0
- package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/check-type.spec.js +103 -0
- package/dist/collection/utils/property-checkers/tests/check-type.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/empty-or.spec.js +23 -0
- package/dist/collection/utils/property-checkers/tests/empty-or.spec.js.map +1 -0
- package/dist/collection/utils/tests/should-reduce-motion.spec.js +16 -0
- package/dist/collection/utils/tests/should-reduce-motion.spec.js.map +1 -0
- package/dist/components/package.js +1 -1
- package/dist/components/post-collapsible.js +2 -2
- package/dist/components/post-collapsible.js.map +1 -1
- package/dist/components/post-icon.js +28 -90
- package/dist/components/post-icon.js.map +1 -1
- package/dist/docs.json +36 -9
- package/dist/esm/{index-286143e7.js → index-0cfe0348.js} +62 -20
- package/dist/esm/index-0cfe0348.js.map +1 -0
- package/dist/esm/loader.js +4 -4
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/{package-144d0036.js → package-1c534bc2.js} +2 -2
- package/dist/esm/{package-144d0036.js.map → package-1c534bc2.js.map} +1 -1
- package/dist/esm/post-collapsible.entry.js +3 -3
- 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 +28 -90
- package/dist/esm/post-icon.entry.js.map +1 -1
- package/dist/post-components/{p-d2e9b37c.js → p-0049f179.js} +2 -2
- package/dist/post-components/p-50562794.entry.js +2 -0
- package/dist/post-components/{p-72fc6cda.entry.js.map → p-50562794.entry.js.map} +1 -1
- package/dist/post-components/p-8f4d1bc9.js +3 -0
- package/dist/post-components/p-8f4d1bc9.js.map +1 -0
- package/dist/post-components/p-fd9201c2.entry.js +2 -0
- package/dist/post-components/p-fd9201c2.entry.js.map +1 -0
- 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 +14 -15
- package/dist/types/components.d.ts +17 -17
- package/dist/types/stencil-public-runtime.d.ts +1 -0
- package/loader/index.d.ts +1 -1
- package/package.json +13 -14
- package/dist/cjs/index-126f28cf.js.map +0 -1
- package/dist/esm/index-286143e7.js.map +0 -1
- package/dist/post-components/p-0c286590.js +0 -3
- package/dist/post-components/p-0c286590.js.map +0 -1
- package/dist/post-components/p-20d342a4.entry.js +0 -2
- package/dist/post-components/p-20d342a4.entry.js.map +0 -1
- package/dist/post-components/p-72fc6cda.entry.js +0 -2
- /package/dist/post-components/{p-d2e9b37c.js.map → p-0049f179.js.map} +0 -0
|
@@ -10,43 +10,43 @@ svg {
|
|
|
10
10
|
fill: currentColor;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
:host([flip-h]) svg {
|
|
13
|
+
:host([flip-h]:not([flip-h=false])) svg {
|
|
14
14
|
scale: -1 1;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
:host([flip-v]) svg {
|
|
17
|
+
:host([flip-v]:not([flip-v=false])) svg {
|
|
18
18
|
scale: 1 -1;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
:host([flip-h][flip-v]) svg {
|
|
21
|
+
:host([flip-h][flip-v]:not([flip-h=false], [flip-v=false])) svg {
|
|
22
22
|
scale: -1;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
:host([animation])
|
|
25
|
+
:host([animation]) {
|
|
26
26
|
transform-origin: center;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
:host([animation=cylon])
|
|
29
|
+
:host([animation=cylon]) {
|
|
30
30
|
animation: icon-animation-cylon 0.75s ease-in-out infinite alternate;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
:host([animation=cylon-vertical])
|
|
33
|
+
:host([animation=cylon-vertical]) {
|
|
34
34
|
animation: icon-animation-cylon-vertical 0.75s ease-in-out infinite alternate;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
:host([animation=spin])
|
|
37
|
+
:host([animation=spin]) {
|
|
38
38
|
animation: icon-animation-spin 2s linear infinite normal;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
:host([animation=spin-reverse])
|
|
41
|
+
:host([animation=spin-reverse]) {
|
|
42
42
|
animation: icon-animation-spin 2s linear infinite reverse;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
:host([animation=fade])
|
|
45
|
+
:host([animation=fade]) {
|
|
46
46
|
animation: icon-animation-fade 0.75s ease-in-out infinite alternate;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
:host([animation=throb])
|
|
49
|
+
:host([animation=throb]) {
|
|
50
50
|
animation: icon-animation-throb 0.75s ease-in-out infinite alternate;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -2,22 +2,29 @@ import { Host, h } from '@stencil/core';
|
|
|
2
2
|
import { checkNonEmpty, checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';
|
|
3
3
|
import { version } from '../../../package.json';
|
|
4
4
|
const CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';
|
|
5
|
-
const
|
|
5
|
+
const ANIMATION_NAMES = [
|
|
6
|
+
'cylon',
|
|
7
|
+
'cylon-vertical',
|
|
8
|
+
'spin',
|
|
9
|
+
'spin-reverse',
|
|
10
|
+
'fade',
|
|
11
|
+
'throb',
|
|
12
|
+
];
|
|
13
|
+
const ANIMATION_KEYS = [...ANIMATION_NAMES];
|
|
6
14
|
/**
|
|
7
15
|
* @class PostIcon - representing a stencil component
|
|
8
16
|
*/
|
|
9
17
|
export class PostIcon {
|
|
10
18
|
constructor() {
|
|
11
|
-
this.
|
|
12
|
-
this.pathForceCDN = false;
|
|
19
|
+
this.svgStyles = undefined;
|
|
13
20
|
this.svgOutput = undefined;
|
|
14
|
-
this.animation =
|
|
15
|
-
this.base =
|
|
16
|
-
this.flipH =
|
|
17
|
-
this.flipV =
|
|
21
|
+
this.animation = null;
|
|
22
|
+
this.base = null;
|
|
23
|
+
this.flipH = false;
|
|
24
|
+
this.flipV = false;
|
|
18
25
|
this.name = undefined;
|
|
19
|
-
this.rotate =
|
|
20
|
-
this.scale =
|
|
26
|
+
this.rotate = null;
|
|
27
|
+
this.scale = null;
|
|
21
28
|
}
|
|
22
29
|
validateAnimation(newValue = this.animation) {
|
|
23
30
|
if (newValue !== undefined)
|
|
@@ -52,90 +59,20 @@ export class PostIcon {
|
|
|
52
59
|
this.validateAnimation();
|
|
53
60
|
}
|
|
54
61
|
componentWillRender() {
|
|
55
|
-
// create path dependant on the props
|
|
56
62
|
this.setPath();
|
|
57
|
-
// fetch icon if the prop "name" is defined and
|
|
58
|
-
// the path has not allready been loaded
|
|
59
|
-
if (this.name && this.path !== this.loadedPath) {
|
|
60
|
-
this.loadedPath = this.path;
|
|
61
|
-
this.fetchIcon()
|
|
62
|
-
.then(successfullyLoaded => {
|
|
63
|
-
// create icon only if an svg has been loaded successfully
|
|
64
|
-
if (successfullyLoaded)
|
|
65
|
-
this.createIcon();
|
|
66
|
-
})
|
|
67
|
-
.catch(error => {
|
|
68
|
-
console.error(error);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
63
|
}
|
|
72
64
|
setPath() {
|
|
73
|
-
var _a;
|
|
65
|
+
var _a, _b, _c, _d;
|
|
74
66
|
// Construct icon path from different possible sources
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
basePath = metaBase.getAttribute('data-post-icon-base');
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
basePath = CDN_URL;
|
|
85
|
-
}
|
|
86
|
-
// use "basePath" only if "pathForceCDN" state is "false"
|
|
87
|
-
this.path = this.getPath(this.pathForceCDN ? CDN_URL : basePath);
|
|
88
|
-
// try to get the "svgSource" from localStorage
|
|
89
|
-
this.svgSource = (_a = window.localStorage.getItem(`post-icon-${this.name}`)) !== null && _a !== void 0 ? _a : this.svgSource;
|
|
90
|
-
// reset "pathForceCDN" after every try
|
|
91
|
-
this.pathForceCDN = false;
|
|
92
|
-
}
|
|
93
|
-
getPath(basePath) {
|
|
94
|
-
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
95
|
-
}
|
|
96
|
-
fetchIcon() {
|
|
97
|
-
return new Promise((resolve, reject) => {
|
|
98
|
-
fetch(this.path)
|
|
99
|
-
.then(response => response.text())
|
|
100
|
-
.then(textResponse => {
|
|
101
|
-
// match "svg" out of "textResponse"
|
|
102
|
-
const match = textResponse.match(/^<svg\b([\s\S]*)><\/svg>/);
|
|
103
|
-
if (match !== null) {
|
|
104
|
-
// set "svgSource" and return "successfullyLoaded" with true
|
|
105
|
-
this.svgSource = match[0];
|
|
106
|
-
window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);
|
|
107
|
-
resolve(true);
|
|
108
|
-
}
|
|
109
|
-
else if (this.path !== this.getPath(CDN_URL)) {
|
|
110
|
-
// if used "path" is not CDN path, and fetch has loaded something else than a "svg", try to reload it from the CDN
|
|
111
|
-
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.`);
|
|
112
|
-
// trigger a component update, which will result in a refetch of the icon with the "CDN_URL"
|
|
113
|
-
this.pathForceCDN = true;
|
|
114
|
-
// return "successfullyLoaded" with false
|
|
115
|
-
resolve(false);
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
.catch(reject);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
createIcon() {
|
|
122
|
-
// create inline styles for some properties
|
|
123
|
-
const svgStyles = Object.entries({
|
|
124
|
-
scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
|
|
125
|
-
rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
|
|
126
|
-
})
|
|
127
|
-
.filter(([_key, value]) => value !== null)
|
|
128
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
129
|
-
.join(';');
|
|
130
|
-
// create svg in RAM and append the above styles, before defining the "svgOutput"
|
|
131
|
-
const helperElement = document.createElement('div');
|
|
132
|
-
helperElement.innerHTML = this.svgSource;
|
|
133
|
-
const svgElement = helperElement.querySelector('svg');
|
|
134
|
-
svgElement.setAttribute('style', svgStyles);
|
|
135
|
-
this.svgOutput = helperElement.innerHTML;
|
|
67
|
+
const metaBase = (_b = (_a = document.head
|
|
68
|
+
.querySelector('meta[name="design-system-settings"][data-post-icon-base]')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-post-icon-base')) !== null && _b !== void 0 ? _b : null;
|
|
69
|
+
const fileBase = `${(_d = (_c = this.base) !== null && _c !== void 0 ? _c : metaBase) !== null && _d !== void 0 ? _d : CDN_URL}/`.replace(/\/\/$/, '/');
|
|
70
|
+
const fileName = `${this.name}.svg#icon`;
|
|
71
|
+
const filePath = `${fileBase}${fileName}`;
|
|
72
|
+
this.path = new URL(filePath, window.location.origin).toString();
|
|
136
73
|
}
|
|
137
74
|
render() {
|
|
138
|
-
return (h(Host, { "data-version": version }, h("
|
|
75
|
+
return (h(Host, { "data-version": version }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32" }, h("use", { href: this.path }))));
|
|
139
76
|
}
|
|
140
77
|
static get is() { return "post-icon"; }
|
|
141
78
|
static get encapsulation() { return "shadow"; }
|
|
@@ -155,24 +92,29 @@ export class PostIcon {
|
|
|
155
92
|
"type": "string",
|
|
156
93
|
"mutable": false,
|
|
157
94
|
"complexType": {
|
|
158
|
-
"original": "
|
|
159
|
-
"resolved": "
|
|
160
|
-
"references": {
|
|
95
|
+
"original": "Animation | null",
|
|
96
|
+
"resolved": "\"cylon\" | \"cylon-vertical\" | \"fade\" | \"spin\" | \"spin-reverse\" | \"throb\"",
|
|
97
|
+
"references": {
|
|
98
|
+
"Animation": {
|
|
99
|
+
"location": "global"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
161
102
|
},
|
|
162
103
|
"required": false,
|
|
163
104
|
"optional": true,
|
|
164
105
|
"docs": {
|
|
165
106
|
"tags": [],
|
|
166
|
-
"text": "The name of the animation
|
|
107
|
+
"text": "The name of the animation."
|
|
167
108
|
},
|
|
168
109
|
"attribute": "animation",
|
|
169
|
-
"reflect": false
|
|
110
|
+
"reflect": false,
|
|
111
|
+
"defaultValue": "null"
|
|
170
112
|
},
|
|
171
113
|
"base": {
|
|
172
114
|
"type": "string",
|
|
173
115
|
"mutable": false,
|
|
174
116
|
"complexType": {
|
|
175
|
-
"original": "string",
|
|
117
|
+
"original": "string | null",
|
|
176
118
|
"resolved": "string",
|
|
177
119
|
"references": {}
|
|
178
120
|
},
|
|
@@ -180,10 +122,11 @@ export class PostIcon {
|
|
|
180
122
|
"optional": true,
|
|
181
123
|
"docs": {
|
|
182
124
|
"tags": [],
|
|
183
|
-
"text": "The base path, where the icons are located (must be a public url)."
|
|
125
|
+
"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."
|
|
184
126
|
},
|
|
185
127
|
"attribute": "base",
|
|
186
|
-
"reflect": false
|
|
128
|
+
"reflect": false,
|
|
129
|
+
"defaultValue": "null"
|
|
187
130
|
},
|
|
188
131
|
"flipH": {
|
|
189
132
|
"type": "boolean",
|
|
@@ -200,7 +143,8 @@ export class PostIcon {
|
|
|
200
143
|
"text": "When set to `true`, the icon will be flipped horizontally."
|
|
201
144
|
},
|
|
202
145
|
"attribute": "flip-h",
|
|
203
|
-
"reflect": false
|
|
146
|
+
"reflect": false,
|
|
147
|
+
"defaultValue": "false"
|
|
204
148
|
},
|
|
205
149
|
"flipV": {
|
|
206
150
|
"type": "boolean",
|
|
@@ -217,7 +161,8 @@ export class PostIcon {
|
|
|
217
161
|
"text": "When set to `true`, the icon will be flipped vertically."
|
|
218
162
|
},
|
|
219
163
|
"attribute": "flip-v",
|
|
220
|
-
"reflect": false
|
|
164
|
+
"reflect": false,
|
|
165
|
+
"defaultValue": "false"
|
|
221
166
|
},
|
|
222
167
|
"name": {
|
|
223
168
|
"type": "string",
|
|
@@ -227,7 +172,7 @@ export class PostIcon {
|
|
|
227
172
|
"resolved": "string",
|
|
228
173
|
"references": {}
|
|
229
174
|
},
|
|
230
|
-
"required":
|
|
175
|
+
"required": true,
|
|
231
176
|
"optional": false,
|
|
232
177
|
"docs": {
|
|
233
178
|
"tags": [],
|
|
@@ -240,7 +185,7 @@ export class PostIcon {
|
|
|
240
185
|
"type": "number",
|
|
241
186
|
"mutable": false,
|
|
242
187
|
"complexType": {
|
|
243
|
-
"original": "number",
|
|
188
|
+
"original": "number | null",
|
|
244
189
|
"resolved": "number",
|
|
245
190
|
"references": {}
|
|
246
191
|
},
|
|
@@ -248,16 +193,17 @@ export class PostIcon {
|
|
|
248
193
|
"optional": true,
|
|
249
194
|
"docs": {
|
|
250
195
|
"tags": [],
|
|
251
|
-
"text": "The
|
|
196
|
+
"text": "The number of degree for the css rotate transformation."
|
|
252
197
|
},
|
|
253
198
|
"attribute": "rotate",
|
|
254
|
-
"reflect": false
|
|
199
|
+
"reflect": false,
|
|
200
|
+
"defaultValue": "null"
|
|
255
201
|
},
|
|
256
202
|
"scale": {
|
|
257
203
|
"type": "number",
|
|
258
204
|
"mutable": false,
|
|
259
205
|
"complexType": {
|
|
260
|
-
"original": "number",
|
|
206
|
+
"original": "number | null",
|
|
261
207
|
"resolved": "number",
|
|
262
208
|
"references": {}
|
|
263
209
|
},
|
|
@@ -265,19 +211,21 @@ export class PostIcon {
|
|
|
265
211
|
"optional": true,
|
|
266
212
|
"docs": {
|
|
267
213
|
"tags": [],
|
|
268
|
-
"text": "The
|
|
214
|
+
"text": "The number for the css scale transformation."
|
|
269
215
|
},
|
|
270
216
|
"attribute": "scale",
|
|
271
|
-
"reflect": false
|
|
217
|
+
"reflect": false,
|
|
218
|
+
"defaultValue": "null"
|
|
272
219
|
}
|
|
273
220
|
};
|
|
274
221
|
}
|
|
275
222
|
static get states() {
|
|
276
223
|
return {
|
|
277
|
-
"
|
|
224
|
+
"svgStyles": {},
|
|
278
225
|
"svgOutput": {}
|
|
279
226
|
};
|
|
280
227
|
}
|
|
228
|
+
static get elementRef() { return "host"; }
|
|
281
229
|
static get watchers() {
|
|
282
230
|
return [{
|
|
283
231
|
"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,aAAa,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AC;IACzC,MAAM,UAAU,GAAG,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACtD,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAE5C,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;EAC3C,CAAC;EAED,MAAM;IACJ,OAAO,CACL,EAAC,IAAI,oBAAe,OAAO;MACzB,WAAK,SAAS,EAAE,IAAI,CAAC,SAAS,GAAI,CAC7B,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, 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_KEYS = ['cylon', 'cylon-vertical', 'spin', 'spin-reverse', 'fade', 'throb'];\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\n @State() pathForceCDN = false;\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)\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).\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 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;\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 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 // 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 // try to get the \"svgSource\" from localStorage\n this.svgSource = window.localStorage.getItem(`post-icon-${this.name}`) ?? this.svgSource;\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 createIcon() {\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 // create svg in RAM and append the above styles, before defining the \"svgOutput\"\n const helperElement = document.createElement('div');\n helperElement.innerHTML = this.svgSource;\n const svgElement = helperElement.querySelector('svg');\n svgElement.setAttribute('style', svgStyles);\n\n this.svgOutput = helperElement.innerHTML;\n }\n\n render() {\n return (\n <Host data-version={version}>\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;;;;qBAW6B,IAAI;gBAiBZ,IAAI;iBAUT,KAAK;iBAUL,KAAK;;kBAqBE,IAAI;iBAUL,IAAI;;EAjE7C,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;IACzC,IAAI,QAAQ,KAAK,SAAS;MACxB,iBAAiB,CACf,QAAQ,EACR,cAAc,EACd,wEAAwE,cAAc,CAAC,IAAI,CACzF,IAAI,CACL,GAAG,CACL,CAAC;EACN,CAAC;EAQD,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI;IAC/B,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE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CAAC;IAElD,MAAM,QAAQ,GAAG,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,mCAAI,QAAQ,mCAAI,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,IAAI,WAAW,CAAC;IACzC,MAAM,QAAQ,GAAG,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE1C,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;EACnE,CAAC;EAED,MAAM;IACJ,OAAO,CACL,EAAC,IAAI,oBAAe,OAAO;MACzB,WAAK,KAAK,EAAC,4BAA4B,EAAC,OAAO,EAAC,WAAW;QACzD,WAAK,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI,CACpB,CACD,CACR,CAAC;EACJ,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\n @Element() host: HTMLPostIconElement;\n\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.setPath();\n }\n\n private setPath() {\n // Construct icon path from different possible sources\n const metaBase =\n document.head\n .querySelector('meta[name=\"design-system-settings\"][data-post-icon-base]')\n ?.getAttribute('data-post-icon-base') ?? null;\n\n const fileBase = `${this.base ?? metaBase ?? CDN_URL}/`.replace(/\\/\\/$/, '/');\n const fileName = `${this.name}.svg#icon`;\n const filePath = `${fileBase}${fileName}`;\n\n this.path = new URL(filePath, window.location.origin).toString();\n }\n\n render() {\n return (\n <Host data-version={version}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\">\n <use href={this.path} />\n </svg>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EMPTY_VALUES } from '../constants';
|
|
2
|
+
import { checkNonEmpty } from '../check-non-empty';
|
|
3
|
+
const TEST_VALUES = [
|
|
4
|
+
undefined,
|
|
5
|
+
null,
|
|
6
|
+
'',
|
|
7
|
+
'string',
|
|
8
|
+
NaN,
|
|
9
|
+
-1000,
|
|
10
|
+
0,
|
|
11
|
+
1000,
|
|
12
|
+
false,
|
|
13
|
+
true,
|
|
14
|
+
{},
|
|
15
|
+
[],
|
|
16
|
+
() => {
|
|
17
|
+
/* empty */
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
const NON_EMPTY_VALUES = TEST_VALUES.filter(tValue => !EMPTY_VALUES.some(eValue => eValue === tValue));
|
|
21
|
+
describe('notEmpty', () => {
|
|
22
|
+
const error = 'Is empty!';
|
|
23
|
+
describe('empty value', () => {
|
|
24
|
+
it('should not throw an error if the value is an non-empty value', () => {
|
|
25
|
+
NON_EMPTY_VALUES.forEach(value => {
|
|
26
|
+
expect(() => checkNonEmpty(value, error)).not.toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('should throw an error if the value is an empty value', () => {
|
|
30
|
+
EMPTY_VALUES.forEach(value => {
|
|
31
|
+
expect(() => checkNonEmpty(value, error)).toThrow(error);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=check-non-empty.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-non-empty.spec.js","sourceRoot":"","sources":["../../../../../src/utils/property-checkers/tests/check-non-empty.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,GAAG;EAClB,SAAS;EACT,IAAI;EACJ,EAAE;EACF,QAAQ;EACR,GAAG;EACH,CAAC,IAAI;EACL,CAAC;EACD,IAAI;EACJ,KAAK;EACL,IAAI;EACJ,EAAE;EACF,EAAE;EACF,GAAG,EAAE;IACH,WAAW;EACb,CAAC;CACF,CAAC;AACF,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,CACzC,MAAM,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC,CAC1D,CAAC;AAEF,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;EACxB,MAAM,KAAK,GAAG,WAAW,CAAC;EAE1B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;MACtE,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC/B,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;MAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;MAC9D,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;MAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { EMPTY_VALUES } from '../constants';\nimport { checkNonEmpty } from '../check-non-empty';\n\nconst TEST_VALUES = [\n undefined,\n null,\n '',\n 'string',\n NaN,\n -1000,\n 0,\n 1000,\n false,\n true,\n {},\n [],\n () => {\n /* empty */\n },\n];\nconst NON_EMPTY_VALUES = TEST_VALUES.filter(\n tValue => !EMPTY_VALUES.some(eValue => eValue === tValue),\n);\n\ndescribe('notEmpty', () => {\n const error = 'Is empty!';\n\n describe('empty value', () => {\n it('should not throw an error if the value is an non-empty value', () => {\n NON_EMPTY_VALUES.forEach(value => {\n expect(() => checkNonEmpty(value, error)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is an empty value', () => {\n EMPTY_VALUES.forEach(value => {\n expect(() => checkNonEmpty(value, error)).toThrow(error);\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { checkOneOf } from '../check-one-of';
|
|
2
|
+
describe('checkOneOf', () => {
|
|
3
|
+
const possibleValues = ['A', 'B', 'C', 'D'];
|
|
4
|
+
const error = 'Is not one of.';
|
|
5
|
+
const runCheckForValue = value => () => checkOneOf(value, possibleValues, error);
|
|
6
|
+
it('should not throw an error if the value is one of the possible values', () => {
|
|
7
|
+
expect(runCheckForValue('A')).not.toThrow();
|
|
8
|
+
});
|
|
9
|
+
it('should throw the provided error if the value is not one of the possible values', () => {
|
|
10
|
+
expect(runCheckForValue('E')).toThrow(error);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=check-one-of.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-one-of.spec.js","sourceRoot":"","sources":["../../../../../src/utils/property-checkers/tests/check-one-of.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;EAC1B,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;EAC5C,MAAM,KAAK,GAAG,gBAAgB,CAAC;EAC/B,MAAM,gBAAgB,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;EAEjF,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;IAC9E,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;EAC9C,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,gFAAgF,EAAE,GAAG,EAAE;IACxF,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;EAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { checkOneOf } from '../check-one-of';\n\ndescribe('checkOneOf', () => {\n const possibleValues = ['A', 'B', 'C', 'D'];\n const error = 'Is not one of.';\n const runCheckForValue = value => () => checkOneOf(value, possibleValues, error);\n\n it('should not throw an error if the value is one of the possible values', () => {\n expect(runCheckForValue('A')).not.toThrow();\n });\n\n it('should throw the provided error if the value is not one of the possible values', () => {\n expect(runCheckForValue('E')).toThrow(error);\n });\n});\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { checkType } from '../check-type';
|
|
2
|
+
describe('checkType', () => {
|
|
3
|
+
let type;
|
|
4
|
+
let error;
|
|
5
|
+
const runCheckForValue = value => () => checkType(value, type, error);
|
|
6
|
+
describe('boolean', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
type = 'boolean';
|
|
9
|
+
error = 'Not a boolean.';
|
|
10
|
+
});
|
|
11
|
+
it('should not throw an error if the value is a boolean', () => {
|
|
12
|
+
[true, false].forEach(boolean => {
|
|
13
|
+
expect(runCheckForValue(boolean)).not.toThrow();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it('should throw an error if the value is not a boolean', () => {
|
|
17
|
+
[undefined, null, 42, NaN, 'string', [], {}, () => { }].forEach(nonBoolean => {
|
|
18
|
+
expect(runCheckForValue(nonBoolean)).toThrow(error);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('number', () => {
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
type = 'number';
|
|
25
|
+
error = 'Not a number.';
|
|
26
|
+
});
|
|
27
|
+
it('should not throw an error if the value is a number', () => {
|
|
28
|
+
[42, 4.2, 4200, 2.4434634e9, NaN].forEach(number => {
|
|
29
|
+
expect(runCheckForValue(number)).not.toThrow();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
it('should throw an error if the value is not a number', () => {
|
|
33
|
+
[undefined, null, true, 'string', [], {}, () => { }].forEach(nonNumber => {
|
|
34
|
+
expect(runCheckForValue(nonNumber)).toThrow(error);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('string', () => {
|
|
39
|
+
beforeAll(() => {
|
|
40
|
+
type = 'string';
|
|
41
|
+
error = 'Not a string.';
|
|
42
|
+
});
|
|
43
|
+
it('should not throw an error if the value is a string', () => {
|
|
44
|
+
['', 'string', '42', '¡¡Olé 🙌!!'].forEach(string => {
|
|
45
|
+
expect(runCheckForValue(string)).not.toThrow();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it('should throw an error if the value is not string', () => {
|
|
49
|
+
[undefined, null, true, 42, NaN, [], {}, () => { }].forEach(nonString => {
|
|
50
|
+
expect(runCheckForValue(nonString)).toThrow(error);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('array', () => {
|
|
55
|
+
beforeAll(() => {
|
|
56
|
+
type = 'array';
|
|
57
|
+
error = 'Not an array.';
|
|
58
|
+
});
|
|
59
|
+
it('should not throw an error if the value is an array', () => {
|
|
60
|
+
[[], [1, 'a']].forEach(array => {
|
|
61
|
+
expect(runCheckForValue(array)).not.toThrow();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('should throw an error if the value is not an array', () => {
|
|
65
|
+
[undefined, null, true, 42, NaN, 'string', {}, () => { }].forEach(nonArray => {
|
|
66
|
+
expect(runCheckForValue(nonArray)).toThrow(error);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('object', () => {
|
|
71
|
+
beforeAll(() => {
|
|
72
|
+
type = 'object';
|
|
73
|
+
error = 'Not an object.';
|
|
74
|
+
});
|
|
75
|
+
it('should not throw an error if the value is an object', () => {
|
|
76
|
+
[null, {}].forEach(object => {
|
|
77
|
+
expect(runCheckForValue(object)).not.toThrow();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it('should throw an error if the value is not an object', () => {
|
|
81
|
+
[undefined, true, 42, NaN, 'string', () => { }].forEach(nonObject => {
|
|
82
|
+
expect(runCheckForValue(nonObject)).toThrow(error);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('function', () => {
|
|
87
|
+
beforeAll(() => {
|
|
88
|
+
type = 'function';
|
|
89
|
+
error = 'Not a function.';
|
|
90
|
+
});
|
|
91
|
+
it('should not throw an error if the value is a function', () => {
|
|
92
|
+
[function () { }, () => { }].forEach(fn => {
|
|
93
|
+
expect(runCheckForValue(fn)).not.toThrow();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('should throw an error if the value is not a function', () => {
|
|
97
|
+
[undefined, null, true, 42, NaN, 'string', [], {}].forEach(nonFn => {
|
|
98
|
+
expect(runCheckForValue(nonFn)).toThrow(error);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=check-type.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-type.spec.js","sourceRoot":"","sources":["../../../../../src/utils/property-checkers/tests/check-type.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,eAAe,CAAC;AAExD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;EACzB,IAAI,IAAkB,CAAC;EACvB,IAAI,KAAa,CAAC;EAClB,MAAM,gBAAgB,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;EAEtE,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,SAAS,CAAC,GAAG,EAAE;MACb,IAAI,GAAG,SAAS,CAAC;MACjB,KAAK,GAAG,gBAAgB,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;MAC7D,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;MAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;MAC7D,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAa,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QACrF,MAAM,CAAC,gBA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AAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;MAC9D,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACjE,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;MACjD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { checkType, PropertyType } from '../check-type';\n\ndescribe('checkType', () => {\n let type: PropertyType;\n let error: string;\n const runCheckForValue = value => () => checkType(value, type, error);\n\n describe('boolean', () => {\n beforeAll(() => {\n type = 'boolean';\n error = 'Not a boolean.';\n });\n\n it('should not throw an error if the value is a boolean', () => {\n [true, false].forEach(boolean => {\n expect(runCheckForValue(boolean)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not a boolean', () => {\n [undefined, null, 42, NaN, 'string', [], {}, () => {/* empty */}].forEach(nonBoolean => {\n expect(runCheckForValue(nonBoolean)).toThrow(error);\n });\n });\n });\n\n describe('number', () => {\n beforeAll(() => {\n type = 'number';\n error = 'Not a number.';\n });\n\n it('should not throw an error if the value is a number', () => {\n [ 42, 4.2, 4_200, 2.4434634e9, NaN ].forEach(number => {\n expect(runCheckForValue(number)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not a number', () => {\n [undefined, null, true, 'string', [], {}, () => {/* empty */}].forEach(nonNumber => {\n expect(runCheckForValue(nonNumber)).toThrow(error);\n });\n });\n });\n\n describe('string', () => {\n beforeAll(() => {\n type = 'string';\n error = 'Not a string.';\n });\n\n it('should not throw an error if the value is a string', () => {\n ['', 'string', '42', '¡¡Olé 🙌!!'].forEach(string => {\n expect(runCheckForValue(string)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not string', () => {\n [undefined, null, true, 42, NaN, [], {}, () => {/* empty */}].forEach(nonString => {\n expect(runCheckForValue(nonString)).toThrow(error);\n });\n });\n });\n\n describe('array', () => {\n beforeAll(() => {\n type = 'array';\n error = 'Not an array.';\n });\n\n it('should not throw an error if the value is an array', () => {\n [[], [1, 'a']].forEach(array => {\n expect(runCheckForValue(array)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not an array', () => {\n [undefined, null, true, 42, NaN, 'string', {}, () => {/* empty */}].forEach(nonArray => {\n expect(runCheckForValue(nonArray)).toThrow(error);\n });\n });\n });\n\n describe('object', () => {\n beforeAll(() => {\n type = 'object';\n error = 'Not an object.';\n });\n\n it('should not throw an error if the value is an object', () => {\n [null, {}].forEach(object => {\n expect(runCheckForValue(object)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not an object', () => {\n [undefined, true, 42, NaN, 'string', () => {/* empty */}].forEach(nonObject => {\n expect(runCheckForValue(nonObject)).toThrow(error);\n });\n });\n });\n\n describe('function', () => {\n beforeAll(() => {\n type = 'function';\n error = 'Not a function.';\n });\n\n it('should not throw an error if the value is a function', () => {\n [function () {/* empty */}, () => {/* empty */}].forEach(fn => {\n expect(runCheckForValue(fn)).not.toThrow();\n });\n });\n\n it('should throw an error if the value is not a function', () => {\n [undefined, null, true, 42, NaN, 'string', [], {}].forEach(nonFn => {\n expect(runCheckForValue(nonFn)).toThrow(error);\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { emptyOr } from '../empty-or';
|
|
2
|
+
describe('emptyOr', () => {
|
|
3
|
+
const mockCheck = jest.fn();
|
|
4
|
+
const mockEmptyOrCheck = emptyOr(mockCheck);
|
|
5
|
+
it('should not run the check if the provided value is empty', () => {
|
|
6
|
+
[undefined, null, ''].forEach(emptyValue => {
|
|
7
|
+
mockEmptyOrCheck(emptyValue);
|
|
8
|
+
expect(mockCheck).not.toHaveBeenCalled();
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
it('should run the check if the provided value is not empty', () => {
|
|
12
|
+
[0, NaN, ' ', false, [], {}, () => { }].forEach((nonEmptyValue, index) => {
|
|
13
|
+
mockEmptyOrCheck(nonEmptyValue);
|
|
14
|
+
expect(mockCheck).toHaveBeenCalledTimes(index + 1);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('should pass all provided arguments to the nested check function', () => {
|
|
18
|
+
const args = ['non empty value', true, false, ['arg in an array'], { arg: 'in an object' }];
|
|
19
|
+
mockEmptyOrCheck(...args);
|
|
20
|
+
expect(mockCheck).toHaveBeenCalledWith(...args);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=empty-or.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-or.spec.js","sourceRoot":"","sources":["../../../../../src/utils/property-checkers/tests/empty-or.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;EACvB,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;EAC5B,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;EAE5C,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;IACjE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;MACzC,gBAAgB,CAAC,UAAU,CAAC,CAAC;MAC7B,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;IACjE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,EAAE,EAAE;MACjF,gBAAgB,CAAC,aAAa,CAAC,CAAC;MAChC,MAAM,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;IACzE,MAAM,IAAI,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAC,GAAG,EAAE,cAAc,EAAC,CAAC,CAAC;IAC1F,gBAAgB,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;EAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { emptyOr } from '../empty-or';\n\ndescribe('emptyOr', () => {\n const mockCheck = jest.fn();\n const mockEmptyOrCheck = emptyOr(mockCheck);\n\n it('should not run the check if the provided value is empty', () => {\n [undefined, null, ''].forEach(emptyValue => {\n mockEmptyOrCheck(emptyValue);\n expect(mockCheck).not.toHaveBeenCalled();\n });\n });\n\n it('should run the check if the provided value is not empty', () => {\n [0, NaN, ' ', false, [], {}, () => {/* empty */}].forEach((nonEmptyValue, index) => {\n mockEmptyOrCheck(nonEmptyValue);\n expect(mockCheck).toHaveBeenCalledTimes(index + 1);\n });\n });\n\n it('should pass all provided arguments to the nested check function', () => {\n const args = ['non empty value', true, false, ['arg in an array'], {arg: 'in an object'}];\n mockEmptyOrCheck(...args);\n expect(mockCheck).toHaveBeenCalledWith(...args);\n });\n});\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { shouldReduceMotion } from '../should-reduce-motion';
|
|
2
|
+
describe('shouldReduceMotion', () => {
|
|
3
|
+
let matchMedia;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
matchMedia = window.matchMedia = jest.fn();
|
|
6
|
+
});
|
|
7
|
+
it('should return true if reduced motion is requested', () => {
|
|
8
|
+
matchMedia.mockReturnValue({ matches: true });
|
|
9
|
+
expect(shouldReduceMotion()).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
it('should return false if reduced motion is not requested', () => {
|
|
12
|
+
matchMedia.mockReturnValue({ matches: false });
|
|
13
|
+
expect(shouldReduceMotion()).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=should-reduce-motion.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"should-reduce-motion.spec.js","sourceRoot":"","sources":["../../../../src/utils/tests/should-reduce-motion.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;EAClC,IAAI,UAAU,CAAC;EAEf,UAAU,CAAC,GAAG,EAAE;IACd,UAAU,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;EAC7C,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;IAC3D,UAAU,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EAC1C,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;IAChE,UAAU,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;EAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { shouldReduceMotion } from '../should-reduce-motion';\n\ndescribe('shouldReduceMotion', () => {\n let matchMedia;\n\n beforeEach(() => {\n matchMedia = window.matchMedia = jest.fn();\n });\n\n it('should return true if reduced motion is requested', () => {\n matchMedia.mockReturnValue({ matches: true });\n expect(shouldReduceMotion()).toBe(true);\n });\n\n it('should return false if reduced motion is not requested', () => {\n matchMedia.mockReturnValue({ matches: false });\n expect(shouldReduceMotion()).toBe(false);\n });\n});\n"]}
|