@swisspost/design-system-components 1.3.4 → 1.3.6

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.
Files changed (66) hide show
  1. package/dist/cjs/{index-126f28cf.js → index-f95ab17b.js} +62 -20
  2. package/dist/cjs/index-f95ab17b.js.map +1 -0
  3. package/dist/cjs/loader.cjs.js +3 -3
  4. package/dist/cjs/loader.cjs.js.map +1 -1
  5. package/dist/cjs/{package-3838cb5b.js → package-79d607b8.js} +2 -2
  6. package/dist/cjs/{package-3838cb5b.js.map → package-79d607b8.js.map} +1 -1
  7. package/dist/cjs/post-collapsible.cjs.entry.js +3 -3
  8. package/dist/cjs/post-collapsible.cjs.entry.js.map +1 -1
  9. package/dist/cjs/post-components.cjs.js +3 -3
  10. package/dist/cjs/post-components.cjs.js.map +1 -1
  11. package/dist/cjs/post-icon.cjs.entry.js +17 -84
  12. package/dist/cjs/post-icon.cjs.entry.js.map +1 -1
  13. package/dist/collection/collection-manifest.json +2 -2
  14. package/dist/collection/components/post-collapsible/post-collapsible.css +1187 -48
  15. package/dist/collection/components/post-icon/post-icon.css +11 -3
  16. package/dist/collection/components/post-icon/post-icon.js +14 -82
  17. package/dist/collection/components/post-icon/post-icon.js.map +1 -1
  18. package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js +36 -0
  19. package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js.map +1 -0
  20. package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js +13 -0
  21. package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js.map +1 -0
  22. package/dist/collection/utils/property-checkers/tests/check-type.spec.js +103 -0
  23. package/dist/collection/utils/property-checkers/tests/check-type.spec.js.map +1 -0
  24. package/dist/collection/utils/property-checkers/tests/empty-or.spec.js +23 -0
  25. package/dist/collection/utils/property-checkers/tests/empty-or.spec.js.map +1 -0
  26. package/dist/collection/utils/tests/should-reduce-motion.spec.js +16 -0
  27. package/dist/collection/utils/tests/should-reduce-motion.spec.js.map +1 -0
  28. package/dist/components/package.js +1 -1
  29. package/dist/components/post-collapsible.js +2 -2
  30. package/dist/components/post-collapsible.js.map +1 -1
  31. package/dist/components/post-icon.js +16 -84
  32. package/dist/components/post-icon.js.map +1 -1
  33. package/dist/docs.json +3 -3
  34. package/dist/esm/{index-286143e7.js → index-0cfe0348.js} +62 -20
  35. package/dist/esm/index-0cfe0348.js.map +1 -0
  36. package/dist/esm/loader.js +4 -4
  37. package/dist/esm/loader.js.map +1 -1
  38. package/dist/esm/{package-fb4a74d0.js → package-ba1192d8.js} +2 -2
  39. package/dist/esm/{package-fb4a74d0.js.map → package-ba1192d8.js.map} +1 -1
  40. package/dist/esm/post-collapsible.entry.js +3 -3
  41. package/dist/esm/post-collapsible.entry.js.map +1 -1
  42. package/dist/esm/post-components.js +4 -4
  43. package/dist/esm/post-components.js.map +1 -1
  44. package/dist/esm/post-icon.entry.js +17 -84
  45. package/dist/esm/post-icon.entry.js.map +1 -1
  46. package/dist/post-components/p-2f408d84.entry.js +2 -0
  47. package/dist/post-components/{p-7dd960f1.entry.js.map → p-2f408d84.entry.js.map} +1 -1
  48. package/dist/post-components/p-75734ad5.entry.js +2 -0
  49. package/dist/post-components/p-75734ad5.entry.js.map +1 -0
  50. package/dist/post-components/p-8f4d1bc9.js +3 -0
  51. package/dist/post-components/p-8f4d1bc9.js.map +1 -0
  52. package/dist/post-components/{p-87bf3416.js → p-a6796794.js} +2 -2
  53. package/dist/post-components/post-components.esm.js +1 -1
  54. package/dist/post-components/post-components.esm.js.map +1 -1
  55. package/dist/types/components/post-icon/post-icon.d.ts +0 -8
  56. package/dist/types/stencil-public-runtime.d.ts +1 -0
  57. package/loader/index.d.ts +1 -1
  58. package/package.json +13 -14
  59. package/dist/cjs/index-126f28cf.js.map +0 -1
  60. package/dist/esm/index-286143e7.js.map +0 -1
  61. package/dist/post-components/p-0c286590.js +0 -3
  62. package/dist/post-components/p-0c286590.js.map +0 -1
  63. package/dist/post-components/p-6e225c16.entry.js +0 -2
  64. package/dist/post-components/p-6e225c16.entry.js.map +0 -1
  65. package/dist/post-components/p-7dd960f1.entry.js +0 -2
  66. /package/dist/post-components/{p-87bf3416.js.map → p-a6796794.js.map} +0 -0
@@ -7,18 +7,26 @@
7
7
  svg {
8
8
  display: block;
9
9
  width: 100%;
10
+ height: 100%;
10
11
  fill: currentColor;
12
+ background-color: currentColor;
13
+ -webkit-mask-position: center center;
14
+ mask-position: center center;
15
+ -webkit-mask-repeat: no-repeat;
16
+ mask-repeat: no-repeat;
17
+ -webkit-mask-size: 100%;
18
+ mask-size: 100%;
11
19
  }
12
20
 
13
- :host([flip-h]:not([flip-h=false])) svg {
21
+ :host([flip-h]:not([flip-h=false])) {
14
22
  scale: -1 1;
15
23
  }
16
24
 
17
- :host([flip-v]:not([flip-v=false])) svg {
25
+ :host([flip-v]:not([flip-v=false])) {
18
26
  scale: 1 -1;
19
27
  }
20
28
 
21
- :host([flip-h][flip-v]:not([flip-h=false], [flip-v=false])) svg {
29
+ :host([flip-h][flip-v]:not([flip-h=false], [flip-v=false])) {
22
30
  scale: -1;
23
31
  }
24
32
 
@@ -16,8 +16,6 @@ const ANIMATION_KEYS = [...ANIMATION_NAMES];
16
16
  */
17
17
  export class PostIcon {
18
18
  constructor() {
19
- this.svgSource = '<svg viewBox="0 0 16 16"></svg>';
20
- this.pathForceCDN = false;
21
19
  this.svgStyles = undefined;
22
20
  this.svgOutput = undefined;
23
21
  this.animation = null;
@@ -61,94 +59,29 @@ export class PostIcon {
61
59
  this.validateAnimation();
62
60
  }
63
61
  componentWillRender() {
64
- this.createIconFromStorage();
65
- // create path dependant on the props
66
62
  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
63
  }
82
64
  setPath() {
65
+ var _a, _b, _c, _d;
83
66
  // Construct icon path from different possible sources
84
- let basePath;
85
- const metaBase = document.head.querySelector('meta[name="design-system-settings"][data-post-icon-base]');
86
- if (this.base) {
87
- basePath = this.base;
88
- }
89
- else if (metaBase) {
90
- basePath = metaBase.getAttribute('data-post-icon-base');
91
- }
92
- else {
93
- basePath = CDN_URL;
94
- }
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;
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();
99
73
  }
100
- getPath(basePath) {
101
- return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
102
- }
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');
74
+ render() {
139
75
  // create inline styles for some properties
140
76
  const svgStyles = Object.entries({
141
- scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
142
- rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
77
+ '-webkit-mask-image': `url('${this.path}')`,
78
+ 'mask-image': `url('${this.path}')`,
79
+ 'scale': this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
80
+ 'rotate': this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
143
81
  })
144
82
  .filter(([_key, value]) => value !== null)
145
- .map(([key, value]) => `${key}: ${value}`)
146
- .join(';');
147
- this.svgElement.setAttribute('style', svgStyles);
148
- this.host.shadowRoot.innerHTML = this.svgElement.outerHTML;
149
- }
150
- render() {
151
- return h(Host, { "data-version": version });
83
+ .reduce((styles, [key, value]) => Object.assign(styles, { [key]: value }), {});
84
+ return (h(Host, { "data-version": version }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32", style: svgStyles })));
152
85
  }
153
86
  static get is() { return "post-icon"; }
154
87
  static get encapsulation() { return "shadow"; }
@@ -297,7 +230,6 @@ export class PostIcon {
297
230
  }
298
231
  static get states() {
299
232
  return {
300
- "pathForceCDN": {},
301
233
  "svgStyles": {},
302
234
  "svgOutput": {}
303
235
  };
@@ -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,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI;MACxE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,IAAI;KAChF,CAAC;OACC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;OACzC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;OACzC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,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
+ {"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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Y,EAAE,QAAQ,IAAI,CAAC,IAAI,IAAI;MACnC,OAAO,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI;MAC1E,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,IAAI;KAClF,CAAC;OACC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;OACzC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEjF,OAAO,CACL,EAAC,IAAI,oBAAe,OAAO;MACzB,WAAK,KAAK,EAAC,4BAA4B,EAAC,OAAO,EAAC,WAAW,EAAC,KAAK,EAAE,SAAS,GACtE,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 // create inline styles for some properties\n const svgStyles = Object.entries({\n '-webkit-mask-image': `url('${this.path}')`,\n 'mask-image': `url('${this.path}')`,\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 .reduce((styles, [key, value]) => Object.assign(styles, { [key]: value }), {});\n\n return (\n <Host data-version={version}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" style={svgStyles}>\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,GAA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AC,SAAS,CAAC,EAAE;QAC5E,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;MACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;EAEH,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,SAAS,CAAC,GAAG,EAAE;MACb,IAAI,GAAG,UAAU,CAAC;MAClB,KAAK,GAAG,iBAAiB,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;MAC9D,CAAC,cAAwB,CAAC,EAAE,GAAG,EAAE,GAAa,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAC5D,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;MAC7C,CAAC,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"]}
@@ -16,7 +16,7 @@ function checkType(value, type, error) {
16
16
  }
17
17
  }
18
18
 
19
- const version = "1.3.4";
19
+ const version = "1.3.6";
20
20
 
21
21
  export { checkOneOf as a, checkType as c, version as v };
22
22