@swisspost/design-system-components 1.3.1 → 1.3.3
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-8880977f.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/package-f1eacd4f.js +27 -0
- package/dist/cjs/package-f1eacd4f.js.map +1 -0
- package/dist/cjs/post-collapsible.cjs.entry.js +11 -19
- 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 +107 -72
- 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 +1420 -3930
- package/dist/collection/components/post-collapsible/post-collapsible.js +14 -11
- package/dist/collection/components/post-collapsible/post-collapsible.js.map +1 -1
- package/dist/collection/components/post-icon/post-icon.js +105 -90
- 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 +0 -3
- package/dist/collection/utils/get-element-height.js.map +1 -1
- package/dist/collection/utils/index.js +0 -3
- package/dist/collection/utils/index.js.map +1 -1
- package/dist/collection/utils/on-transition-end.js +0 -3
- 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 +5 -0
- package/dist/collection/utils/property-checkers/check-one-of.js.map +1 -0
- package/dist/collection/utils/property-checkers/check-type.js +13 -0
- package/dist/collection/utils/property-checkers/check-type.js.map +1 -0
- 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 +9 -0
- package/dist/collection/utils/property-checkers/empty-or.js.map +1 -0
- package/dist/collection/utils/property-checkers/index.js +9 -0
- package/dist/collection/utils/property-checkers/index.js.map +1 -0
- package/dist/collection/utils/should-reduce-motion.js +0 -3
- package/dist/collection/utils/should-reduce-motion.js.map +1 -1
- package/dist/components/package.js +23 -0
- package/dist/components/package.js.map +1 -0
- package/dist/components/post-collapsible.js +13 -20
- package/dist/components/post-collapsible.js.map +1 -1
- package/dist/components/post-icon.js +106 -73
- package/dist/components/post-icon.js.map +1 -1
- package/dist/docs.json +2 -2
- package/dist/esm/{index-6d5a72fa.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/package-144d0036.js +23 -0
- package/dist/esm/package-144d0036.js.map +1 -0
- package/dist/esm/post-collapsible.entry.js +10 -18
- 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 +103 -68
- package/dist/esm/post-icon.entry.js.map +1 -1
- package/dist/post-components/{p-a93114b9.js → p-0c286590.js} +3 -3
- package/dist/post-components/p-0c286590.js.map +1 -0
- package/dist/post-components/p-20d342a4.entry.js +2 -0
- package/dist/post-components/p-20d342a4.entry.js.map +1 -0
- package/dist/post-components/p-72fc6cda.entry.js +2 -0
- package/dist/post-components/p-72fc6cda.entry.js.map +1 -0
- package/dist/post-components/p-d2e9b37c.js +2 -0
- package/dist/post-components/p-d2e9b37c.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-collapsible/post-collapsible.d.ts +14 -13
- package/dist/types/components/post-icon/post-icon.d.ts +25 -23
- package/dist/types/utils/property-checkers/check-non-empty.d.ts +1 -0
- package/dist/types/utils/property-checkers/check-one-of.d.ts +1 -0
- package/dist/types/utils/property-checkers/check-type.d.ts +2 -0
- package/dist/types/utils/property-checkers/constants.d.ts +1 -0
- package/dist/types/utils/property-checkers/empty-or.d.ts +1 -0
- package/dist/types/utils/property-checkers/index.d.ts +5 -0
- package/package.json +19 -14
- package/dist/cjs/index-8880977f.js.map +0 -1
- package/dist/cjs/property-checkers-586ad9d4.js +0 -40
- package/dist/cjs/property-checkers-586ad9d4.js.map +0 -1
- package/dist/collection/utils/property-checkers.js +0 -31
- package/dist/collection/utils/property-checkers.js.map +0 -1
- package/dist/components/property-checkers.js +0 -34
- package/dist/components/property-checkers.js.map +0 -1
- package/dist/esm/index-6d5a72fa.js.map +0 -1
- package/dist/esm/property-checkers-484ca671.js +0 -34
- package/dist/esm/property-checkers-484ca671.js.map +0 -1
- package/dist/post-components/p-7cd9c1ad.js +0 -2
- package/dist/post-components/p-7cd9c1ad.js.map +0 -1
- package/dist/post-components/p-a93114b9.js.map +0 -1
- package/dist/post-components/p-b07185a3.entry.js +0 -2
- package/dist/post-components/p-b07185a3.entry.js.map +0 -1
- package/dist/post-components/p-d1bc7b0b.entry.js +0 -2
- package/dist/post-components/p-d1bc7b0b.entry.js.map +0 -1
- package/dist/types/utils/property-checkers.d.ts +0 -5
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { h } from '@stencil/core';
|
|
2
|
-
import {
|
|
1
|
+
import { h, Host } from '@stencil/core';
|
|
2
|
+
import { checkOneOf, checkType, getElementHeight, onTransitionEnd } from '../../utils';
|
|
3
|
+
import { version } from '../../../package.json';
|
|
3
4
|
let nextId = 0;
|
|
4
5
|
export class PostCollapsible {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.isLoaded = false;
|
|
7
|
-
this.collapsed = false;
|
|
8
|
-
this.headingLevel = 2;
|
|
9
|
-
this.isOpen = true;
|
|
10
8
|
this.collapseClasses = undefined;
|
|
11
9
|
this.collapseHeight = null;
|
|
12
|
-
this.headingTag = undefined;
|
|
13
10
|
this.collapsibleId = undefined;
|
|
14
11
|
this.hasHeader = undefined;
|
|
12
|
+
this.headingTag = undefined;
|
|
13
|
+
this.isOpen = true;
|
|
14
|
+
this.onAccordionButtonClick = () => this.toggle();
|
|
15
|
+
this.collapsed = false;
|
|
16
|
+
this.headingLevel = 2;
|
|
15
17
|
}
|
|
16
18
|
validateCollapsed(newValue = this.collapsed) {
|
|
17
|
-
|
|
19
|
+
checkType(newValue, 'boolean', 'The post-collapsible "collapsed" prop should be a boolean.');
|
|
18
20
|
if (!this.isLoaded) {
|
|
19
21
|
this.isOpen = !newValue;
|
|
20
22
|
this.collapseClasses = this.getCollapseClasses();
|
|
@@ -72,7 +74,7 @@ export class PostCollapsible {
|
|
|
72
74
|
if (!this.hasHeader) {
|
|
73
75
|
return (h("div", { id: `${this.collapsibleId}--collapse`, class: this.collapseClasses, style: { height: this.collapseHeight } }, h("slot", null)));
|
|
74
76
|
}
|
|
75
|
-
return (h("div", { class: "accordion-item" }, h(this.headingTag, { class: "accordion-header", id: `${this.collapsibleId}--header` }, h("button", { class: `accordion-button ${this.isOpen ? '' : 'collapsed'}`, type: "button", "aria-expanded": `${this.isOpen}`, "aria-controls": `${this.collapsibleId}--collapse`, onClick:
|
|
77
|
+
return (h(Host, { "data-version": version }, h("div", { class: "accordion-item" }, h(this.headingTag, { class: "accordion-header", id: `${this.collapsibleId}--header` }, h("button", { class: `accordion-button ${this.isOpen ? '' : 'collapsed'}`, type: "button", "aria-expanded": `${this.isOpen}`, "aria-controls": `${this.collapsibleId}--collapse`, onClick: this.onAccordionButtonClick }, h("slot", { name: "header" }))), h("div", { id: `${this.collapsibleId}--collapse`, class: `accordion-collapse ${this.collapseClasses}`, style: { height: this.collapseHeight }, "aria-labelledby": `${this.collapsibleId}--header` }, h("div", { class: "accordion-body" }, h("slot", null))))));
|
|
76
78
|
}
|
|
77
79
|
static get is() { return "post-collapsible"; }
|
|
78
80
|
static get encapsulation() { return "shadow"; }
|
|
@@ -128,12 +130,13 @@ export class PostCollapsible {
|
|
|
128
130
|
}
|
|
129
131
|
static get states() {
|
|
130
132
|
return {
|
|
131
|
-
"isOpen": {},
|
|
132
133
|
"collapseClasses": {},
|
|
133
134
|
"collapseHeight": {},
|
|
134
|
-
"headingTag": {},
|
|
135
135
|
"collapsibleId": {},
|
|
136
|
-
"hasHeader": {}
|
|
136
|
+
"hasHeader": {},
|
|
137
|
+
"headingTag": {},
|
|
138
|
+
"isOpen": {},
|
|
139
|
+
"onAccordionButtonClick": {}
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
142
|
static get methods() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-collapsible.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"post-collapsible.js","sourceRoot":"","sources":["../../../../src/components/post-collapsible/post-collapsible.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,IAAI,MAAM,GAAG,CAAC,CAAC;AAOf,MAAM,OAAO,eAAe;;IAElB,aAAQ,GAAG,KAAK,CAAC;;0BAKgB,IAAI;;;;kBAI3B,IAAI;kCACY,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;qBAKd,KAAK;wBAmBH,CAAC;;EAhB1C,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;IACzC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,4DAA4D,CAAC,CAAC;IAE7F,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAClB,IAAI,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC;MACxB,IAAI,CA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BAAgB;QACzB,EAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAC,kBAAkB,EAAC,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa,UAAU;UAC3E,cACE,KAAK,EAAE,oBAAoB,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,EAC3D,IAAI,EAAC,QAAQ,mBACE,GAAG,IAAI,CAAC,MAAM,EAAE,mBAChB,GAAG,IAAI,CAAC,aAAa,YAAY,EAChD,OAAO,EAAE,IAAI,CAAC,sBAAsB;YAEpC,YAAM,IAAI,EAAC,QAAQ,GAAG,CACf,CACO;QAClB,WACE,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa,YAAY,EACrC,KAAK,EAAE,sBAAsB,IAAI,CAAC,eAAe,EAAE,EACnD,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,qBACrB,GAAG,IAAI,CAAC,aAAa,UAAU;UAEhD,WAAK,KAAK,EAAC,gBAAgB;YACzB,eAAQ,CACJ,CACF,CACF,CACD,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, h, Host, Method, Prop, State, Watch } from '@stencil/core';\nimport { checkOneOf, checkType, getElementHeight, onTransitionEnd } from '../../utils';\nimport { version } from '../../../package.json';\n\nlet nextId = 0;\n\n@Component({\n tag: 'post-collapsible',\n styleUrl: 'post-collapsible.scss',\n shadow: true,\n})\nexport class PostCollapsible {\n private collapsibleElement: HTMLElement;\n private isLoaded = false;\n\n @Element() host: HTMLPostCollapsibleElement;\n\n @State() collapseClasses: string;\n @State() collapseHeight: string | null = null;\n @State() collapsibleId: string;\n @State() hasHeader: boolean;\n @State() headingTag: string | undefined;\n @State() isOpen = true;\n @State() onAccordionButtonClick = () => this.toggle();\n\n /**\n * If `true`, the element is initially collapsed otherwise it is displayed.\n */\n @Prop() readonly collapsed?: boolean = false;\n\n @Watch('collapsed')\n validateCollapsed(newValue = this.collapsed) {\n checkType(newValue, 'boolean', 'The post-collapsible \"collapsed\" prop should be a boolean.');\n\n if (!this.isLoaded) {\n this.isOpen = !newValue;\n this.collapseClasses = this.getCollapseClasses();\n } else {\n setTimeout(() => {\n this.toggle(!newValue);\n });\n }\n }\n\n /**\n * Defines the hierarchical level of the collapsible header within the headings structure.\n */\n @Prop() readonly headingLevel?: number = 2;\n\n @Watch('headingLevel')\n validateHeadingLevel(newValue = this.headingLevel) {\n checkOneOf(\n newValue,\n [1, 2, 3, 4, 5, 6],\n 'The post-collapsible element requires a heading level between 1 and 6.',\n );\n\n this.headingTag = `h${newValue}`;\n }\n\n componentWillLoad() {\n this.validateCollapsed();\n this.validateHeadingLevel();\n\n this.hasHeader = this.host.querySelectorAll('[slot=\"header\"]').length > 0;\n if (!this.hasHeader) {\n console.warn(\n 'Be sure to bind the post-collapsible to its control using aria-controls and aria-expanded attributes. More information here: https://getbootstrap.com/docs/5.2/components/collapse/#accessibility',\n );\n }\n\n this.collapsibleId = this.host.id || `post-collapsible-${nextId++}`;\n this.collapseClasses = this.getCollapseClasses();\n }\n\n componentDidLoad() {\n this.isLoaded = true;\n this.collapsibleElement = this.host.shadowRoot.querySelector(\n `#${this.collapsibleId}--collapse`,\n );\n }\n\n /**\n * Triggers the collapse programmatically.\n */\n @Method()\n async toggle(open = !this.isOpen): Promise<boolean> {\n if (open !== this.isOpen) {\n this.isOpen = !this.isOpen;\n\n this.startTransition();\n\n await onTransitionEnd(this.collapsibleElement).then(() => {\n this.collapseHeight = null;\n this.collapseClasses = this.getCollapseClasses();\n });\n\n return this.isOpen;\n }\n }\n\n private startTransition() {\n const expandedHeight = getElementHeight(this.collapsibleElement, 'show');\n\n this.collapseHeight = `${this.isOpen ? 0 : expandedHeight}px`;\n this.collapseClasses = 'collapsing';\n\n setTimeout(() => {\n this.collapseHeight = `${this.isOpen ? expandedHeight : 0}px`;\n }, 50);\n }\n\n private getCollapseClasses() {\n return this.isOpen ? 'collapse show' : 'collapse';\n }\n\n render() {\n if (!this.hasHeader) {\n return (\n <div\n id={`${this.collapsibleId}--collapse`}\n class={this.collapseClasses}\n style={{ height: this.collapseHeight }}\n >\n <slot />\n </div>\n );\n }\n\n return (\n <Host data-version={version}>\n <div class=\"accordion-item\">\n <this.headingTag class=\"accordion-header\" id={`${this.collapsibleId}--header`}>\n <button\n class={`accordion-button ${this.isOpen ? '' : 'collapsed'}`}\n type=\"button\"\n aria-expanded={`${this.isOpen}`}\n aria-controls={`${this.collapsibleId}--collapse`}\n onClick={this.onAccordionButtonClick}\n >\n <slot name=\"header\" />\n </button>\n </this.headingTag>\n <div\n id={`${this.collapsibleId}--collapse`}\n class={`accordion-collapse ${this.collapseClasses}`}\n style={{ height: this.collapseHeight }}\n aria-labelledby={`${this.collapsibleId}--header`}\n >\n <div class=\"accordion-body\">\n <slot />\n </div>\n </div>\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -1,33 +1,27 @@
|
|
|
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 ANIMATION_KEYS = [
|
|
5
|
-
'cylon',
|
|
6
|
-
'cylon-vertical',
|
|
7
|
-
'spin',
|
|
8
|
-
'spin-reverse',
|
|
9
|
-
'fade',
|
|
10
|
-
'throb'
|
|
11
|
-
];
|
|
5
|
+
const ANIMATION_KEYS = ['cylon', 'cylon-vertical', 'spin', 'spin-reverse', 'fade', 'throb'];
|
|
12
6
|
/**
|
|
13
7
|
* @class PostIcon - representing a stencil component
|
|
14
8
|
*/
|
|
15
9
|
export class PostIcon {
|
|
16
10
|
constructor() {
|
|
17
|
-
this.
|
|
11
|
+
this.svgSource = '<svg viewBox="0 0 16 16"></svg>';
|
|
12
|
+
this.pathForceCDN = false;
|
|
13
|
+
this.svgOutput = undefined;
|
|
14
|
+
this.animation = undefined;
|
|
18
15
|
this.base = undefined;
|
|
19
16
|
this.flipH = undefined;
|
|
20
17
|
this.flipV = undefined;
|
|
21
|
-
this.
|
|
18
|
+
this.name = undefined;
|
|
22
19
|
this.rotate = undefined;
|
|
23
|
-
this.
|
|
24
|
-
this.initialPath = undefined;
|
|
25
|
-
this.path = undefined;
|
|
26
|
-
this.svgSource = '<svg viewBox="0 0 16 16"></svg>';
|
|
27
|
-
this.svgOutput = undefined;
|
|
20
|
+
this.scale = undefined;
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
validateAnimation(newValue = this.animation) {
|
|
23
|
+
if (newValue !== undefined)
|
|
24
|
+
checkEmptyOrOneOf(newValue, ANIMATION_KEYS, `The post-icon "animation" prop requires one of the following values: ${ANIMATION_KEYS.join(', ')}.`);
|
|
31
25
|
}
|
|
32
26
|
validateBase(newValue = this.base) {
|
|
33
27
|
checkEmptyOrType(newValue, 'string', 'The post-icon "base" prop should be a string.');
|
|
@@ -38,17 +32,44 @@ export class PostIcon {
|
|
|
38
32
|
validateFlipV(newValue = this.flipV) {
|
|
39
33
|
checkEmptyOrType(newValue, 'boolean', 'The post-icon "flipV" prop should be a boolean.');
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
validateName(newValue = this.name) {
|
|
36
|
+
checkNonEmpty(newValue, 'The post-icon "name" prop is required!.');
|
|
37
|
+
checkType(newValue, 'string', 'The post-icon "name" prop should be a string.');
|
|
43
38
|
}
|
|
44
39
|
validateRotate(newValue = this.rotate) {
|
|
45
40
|
checkEmptyOrType(newValue, 'number', 'The post-icon "rotate" prop should be a number.');
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
validateScale(newValue = this.scale) {
|
|
43
|
+
checkEmptyOrType(newValue, 'number', 'The post-icon "scale" prop should be a number.');
|
|
44
|
+
}
|
|
45
|
+
componentWillLoad() {
|
|
46
|
+
this.validateBase();
|
|
47
|
+
this.validateName();
|
|
48
|
+
this.validateFlipH();
|
|
49
|
+
this.validateFlipV();
|
|
50
|
+
this.validateScale();
|
|
51
|
+
this.validateRotate();
|
|
52
|
+
this.validateAnimation();
|
|
53
|
+
}
|
|
54
|
+
componentWillRender() {
|
|
55
|
+
// create path dependant on the props
|
|
56
|
+
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
|
+
}
|
|
50
71
|
}
|
|
51
|
-
|
|
72
|
+
setPath() {
|
|
52
73
|
var _a;
|
|
53
74
|
// Construct icon path from different possible sources
|
|
54
75
|
let basePath;
|
|
@@ -62,20 +83,43 @@ export class PostIcon {
|
|
|
62
83
|
else {
|
|
63
84
|
basePath = CDN_URL;
|
|
64
85
|
}
|
|
65
|
-
|
|
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
|
|
66
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;
|
|
67
92
|
}
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
this.validateBase();
|
|
71
|
-
this.validateFlipH();
|
|
72
|
-
this.validateFlipV();
|
|
73
|
-
this.validateScale();
|
|
74
|
-
this.validateRotate();
|
|
75
|
-
this.validateAnimation();
|
|
76
|
-
this.fetchSVG();
|
|
93
|
+
getPath(basePath) {
|
|
94
|
+
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
77
95
|
}
|
|
78
|
-
|
|
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
|
|
79
123
|
const svgStyles = Object.entries({
|
|
80
124
|
scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
|
|
81
125
|
rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
|
|
@@ -83,42 +127,15 @@ export class PostIcon {
|
|
|
83
127
|
.filter(([_key, value]) => value !== null)
|
|
84
128
|
.map(([key, value]) => `${key}: ${value}`)
|
|
85
129
|
.join(';');
|
|
130
|
+
// create svg in RAM and append the above styles, before defining the "svgOutput"
|
|
86
131
|
const helperElement = document.createElement('div');
|
|
87
132
|
helperElement.innerHTML = this.svgSource;
|
|
88
133
|
const svgElement = helperElement.querySelector('svg');
|
|
89
134
|
svgElement.setAttribute('style', svgStyles);
|
|
90
135
|
this.svgOutput = helperElement.innerHTML;
|
|
91
136
|
}
|
|
92
|
-
getPath(basePath) {
|
|
93
|
-
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
94
|
-
}
|
|
95
|
-
fetchSVG() {
|
|
96
|
-
fetch(this.path)
|
|
97
|
-
.then(response => response.text())
|
|
98
|
-
.then(textResponse => {
|
|
99
|
-
const match = textResponse.match(/^<svg\b([\s\S]*)><\/svg>/);
|
|
100
|
-
if (match !== null) {
|
|
101
|
-
this.svgSource = match[0];
|
|
102
|
-
window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.initialPath = this.path;
|
|
106
|
-
this.path = this.getPath(CDN_URL);
|
|
107
|
-
if (this.initialPath !== this.path) {
|
|
108
|
-
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.`);
|
|
109
|
-
this.fetchSVG();
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.error(`Error in <post-icon/>: Could not load the svg on the path "${this.initialPath}"!`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
.catch(error => {
|
|
117
|
-
console.log(error);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
137
|
render() {
|
|
121
|
-
return (h(Host,
|
|
138
|
+
return (h(Host, { "data-version": version }, h("div", { innerHTML: this.svgOutput })));
|
|
122
139
|
}
|
|
123
140
|
static get is() { return "post-icon"; }
|
|
124
141
|
static get encapsulation() { return "shadow"; }
|
|
@@ -134,7 +151,7 @@ export class PostIcon {
|
|
|
134
151
|
}
|
|
135
152
|
static get properties() {
|
|
136
153
|
return {
|
|
137
|
-
"
|
|
154
|
+
"animation": {
|
|
138
155
|
"type": "string",
|
|
139
156
|
"mutable": false,
|
|
140
157
|
"complexType": {
|
|
@@ -143,12 +160,12 @@ export class PostIcon {
|
|
|
143
160
|
"references": {}
|
|
144
161
|
},
|
|
145
162
|
"required": false,
|
|
146
|
-
"optional":
|
|
163
|
+
"optional": true,
|
|
147
164
|
"docs": {
|
|
148
165
|
"tags": [],
|
|
149
|
-
"text": "The name
|
|
166
|
+
"text": "The name of the animation (`cylon`, `cylon-vertical`, `spin`, `spin-reverse`, `fade`, `throb`)."
|
|
150
167
|
},
|
|
151
|
-
"attribute": "
|
|
168
|
+
"attribute": "animation",
|
|
152
169
|
"reflect": false
|
|
153
170
|
},
|
|
154
171
|
"base": {
|
|
@@ -202,21 +219,21 @@ export class PostIcon {
|
|
|
202
219
|
"attribute": "flip-v",
|
|
203
220
|
"reflect": false
|
|
204
221
|
},
|
|
205
|
-
"
|
|
206
|
-
"type": "
|
|
222
|
+
"name": {
|
|
223
|
+
"type": "string",
|
|
207
224
|
"mutable": false,
|
|
208
225
|
"complexType": {
|
|
209
|
-
"original": "
|
|
210
|
-
"resolved": "
|
|
226
|
+
"original": "string",
|
|
227
|
+
"resolved": "string",
|
|
211
228
|
"references": {}
|
|
212
229
|
},
|
|
213
230
|
"required": false,
|
|
214
|
-
"optional":
|
|
231
|
+
"optional": false,
|
|
215
232
|
"docs": {
|
|
216
233
|
"tags": [],
|
|
217
|
-
"text": "The
|
|
234
|
+
"text": "The name/id of the icon (e.g. 1000, 1001, ...)."
|
|
218
235
|
},
|
|
219
|
-
"attribute": "
|
|
236
|
+
"attribute": "name",
|
|
220
237
|
"reflect": false
|
|
221
238
|
},
|
|
222
239
|
"rotate": {
|
|
@@ -236,37 +253,35 @@ export class PostIcon {
|
|
|
236
253
|
"attribute": "rotate",
|
|
237
254
|
"reflect": false
|
|
238
255
|
},
|
|
239
|
-
"
|
|
240
|
-
"type": "
|
|
256
|
+
"scale": {
|
|
257
|
+
"type": "number",
|
|
241
258
|
"mutable": false,
|
|
242
259
|
"complexType": {
|
|
243
|
-
"original": "
|
|
244
|
-
"resolved": "
|
|
260
|
+
"original": "number",
|
|
261
|
+
"resolved": "number",
|
|
245
262
|
"references": {}
|
|
246
263
|
},
|
|
247
264
|
"required": false,
|
|
248
265
|
"optional": true,
|
|
249
266
|
"docs": {
|
|
250
267
|
"tags": [],
|
|
251
|
-
"text": "The
|
|
268
|
+
"text": "The `number` for the css `scale` transformation."
|
|
252
269
|
},
|
|
253
|
-
"attribute": "
|
|
270
|
+
"attribute": "scale",
|
|
254
271
|
"reflect": false
|
|
255
272
|
}
|
|
256
273
|
};
|
|
257
274
|
}
|
|
258
275
|
static get states() {
|
|
259
276
|
return {
|
|
260
|
-
"
|
|
261
|
-
"path": {},
|
|
262
|
-
"svgSource": {},
|
|
277
|
+
"pathForceCDN": {},
|
|
263
278
|
"svgOutput": {}
|
|
264
279
|
};
|
|
265
280
|
}
|
|
266
281
|
static get watchers() {
|
|
267
282
|
return [{
|
|
268
|
-
"propName": "
|
|
269
|
-
"methodName": "
|
|
283
|
+
"propName": "animation",
|
|
284
|
+
"methodName": "validateAnimation"
|
|
270
285
|
}, {
|
|
271
286
|
"propName": "base",
|
|
272
287
|
"methodName": "validateBase"
|
|
@@ -277,14 +292,14 @@ export class PostIcon {
|
|
|
277
292
|
"propName": "flipV",
|
|
278
293
|
"methodName": "validateFlipV"
|
|
279
294
|
}, {
|
|
280
|
-
"propName": "
|
|
281
|
-
"methodName": "
|
|
295
|
+
"propName": "name",
|
|
296
|
+
"methodName": "validateName"
|
|
282
297
|
}, {
|
|
283
298
|
"propName": "rotate",
|
|
284
299
|
"methodName": "validateRotate"
|
|
285
300
|
}, {
|
|
286
|
-
"propName": "
|
|
287
|
-
"methodName": "
|
|
301
|
+
"propName": "scale",
|
|
302
|
+
"methodName": "validateScale"
|
|
288
303
|
}];
|
|
289
304
|
}
|
|
290
305
|
}
|
|
@@ -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;;;;;;;;;;;qBAqCU,iCAAiC;;;EAI9D,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI;IAC/B,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,+CAA+C,CAAC,CAAC;EACjF,CAAC;EAGD,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI;IAC/B,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,+CAA+C,CAAC,CAAC;EACxF,CAAC;EAGD,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK;IACjC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,iDAAiD,CAAC,CAAC;EAC3F,CAAC;EAGD,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK;IACjC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,iDAAiD,CAAC,CAAC;EAC3F,CAAC;EAGD,aAAa,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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 /**\n * The name/id of the icon (e.g. 1000, 1001, ...).\n */\n @Prop() name: string;\n\n /**\n * The base path, where the icons are located (must be a public url).\n */\n @Prop() base?: string;\n\n /**\n * When set to `true`, the icon will be flipped horizontally.\n */\n @Prop() flipH?: boolean;\n\n /**\n * When set to `true`, the icon will be flipped vertically.\n */\n @Prop() flipV?: boolean;\n\n /**\n * The `number` for the css `scale` transformation.\n */\n @Prop() scale?: number;\n\n /**\n * The `number` of degree for the css `rotate` transformation.\n */\n @Prop() rotate?: number;\n\n /**\n * The name of the animation (`cylon`, `cylon-vertical`, `spin`, `spin-reverse`, `fade`, `throb`).\n */\n @Prop() animation?: string;\n @State() initialPath: string;\n @State() path: string;\n @State() svgSource: string = '<svg viewBox=\"0 0 16 16\"></svg>';\n @State() svgOutput: 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 @Watch('base')\n validateBase(newValue = this.base) {\n checkEmptyOrType(newValue, 'string', 'The post-icon \"base\" prop should be a string.');\n }\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 @Watch('flipV')\n validateFlipV(newValue = this.flipV) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipV\" prop should be a boolean.');\n }\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 @Watch('rotate')\n validateRotate(newValue = this.rotate) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"rotate\" prop should be a number.');\n }\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 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.validateName();\n this.validateBase();\n this.validateFlipH();\n this.validateFlipV();\n this.validateScale();\n this.validateRotate();\n this.validateAnimation();\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 getPath(basePath: string) {\n return new URL(\n [...basePath.split('/'), `${this.name}.svg#icon`].join('/'),\n window.location.origin,\n ).toString();\n }\n\n 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 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,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,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,cAAc,GAAG,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5F;;GAEG;AAMH,MAAM,OAAO,QAAQ;;IAGX,cAAS,GAAG,iCAAiC,CAAC;wBAE9B,KAAK;;;;;;;;;;EAS7B,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;IACzC,IAAI,QAAQ,KAAK,SAAS;MACxB,iBAAiB,CACf,QAAQ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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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 +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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function checkType(value, type, error) {
|
|
2
|
+
const typeIsArray = type === 'array';
|
|
3
|
+
const valueIsArray = Array.isArray(value);
|
|
4
|
+
if (typeIsArray || valueIsArray) {
|
|
5
|
+
if (valueIsArray !== typeIsArray)
|
|
6
|
+
throw new Error(error);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
if (typeof value !== type)
|
|
10
|
+
throw new Error(error);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=check-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { emptyOr } from './empty-or';
|
|
2
|
+
import { checkOneOf } from './check-one-of';
|
|
3
|
+
import { checkType } from './check-type';
|
|
4
|
+
export const checkEmptyOrOneOf = emptyOr(checkOneOf);
|
|
5
|
+
export const checkEmptyOrType = emptyOr(checkType);
|
|
6
|
+
export * from './check-non-empty';
|
|
7
|
+
export * from './check-one-of';
|
|
8
|
+
export * from './check-type';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|