@swisspost/design-system-components 1.0.0-beta.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +15 -23
  2. package/dist/cjs/{index-5c30acf6.js → index-8880977f.js} +588 -154
  3. package/dist/cjs/index-8880977f.js.map +1 -0
  4. package/dist/cjs/index.cjs.js +2 -0
  5. package/dist/cjs/index.cjs.js.map +1 -0
  6. package/dist/cjs/loader.cjs.js +6 -3
  7. package/dist/cjs/loader.cjs.js.map +1 -0
  8. package/dist/cjs/post-collapsible.cjs.entry.js +134 -0
  9. package/dist/cjs/post-collapsible.cjs.entry.js.map +1 -0
  10. package/dist/cjs/post-components.cjs.js +12 -3
  11. package/dist/cjs/post-components.cjs.js.map +1 -0
  12. package/dist/cjs/post-icon.cjs.entry.js +142 -0
  13. package/dist/cjs/post-icon.cjs.entry.js.map +1 -0
  14. package/dist/cjs/property-checkers-586ad9d4.js +40 -0
  15. package/dist/cjs/property-checkers-586ad9d4.js.map +1 -0
  16. package/dist/collection/collection-manifest.json +4 -3
  17. package/dist/collection/components/post-collapsible/post-collapsible.css +17297 -0
  18. package/dist/collection/components/post-collapsible/post-collapsible.js +173 -0
  19. package/dist/collection/components/post-collapsible/post-collapsible.js.map +1 -0
  20. package/dist/collection/components/post-icon/post-icon.css +94 -0
  21. package/dist/collection/components/post-icon/post-icon.js +291 -0
  22. package/dist/collection/components/post-icon/post-icon.js.map +1 -0
  23. package/dist/collection/index.js +1 -0
  24. package/dist/collection/index.js.map +1 -0
  25. package/dist/collection/utils/get-element-height.js +15 -0
  26. package/dist/collection/utils/get-element-height.js.map +1 -0
  27. package/dist/collection/utils/index.js +8 -0
  28. package/dist/collection/utils/index.js.map +1 -0
  29. package/dist/collection/utils/on-transition-end.js +18 -0
  30. package/dist/collection/utils/on-transition-end.js.map +1 -0
  31. package/dist/collection/utils/property-checkers.js +31 -0
  32. package/dist/collection/utils/property-checkers.js.map +1 -0
  33. package/dist/collection/utils/should-reduce-motion.js +7 -0
  34. package/dist/collection/utils/should-reduce-motion.js.map +1 -0
  35. package/dist/components/index.d.ts +9 -4
  36. package/dist/components/index.js +3 -2
  37. package/dist/components/index.js.map +1 -0
  38. package/dist/components/post-collapsible.d.ts +11 -0
  39. package/dist/components/post-collapsible.js +158 -0
  40. package/dist/components/post-collapsible.js.map +1 -0
  41. package/dist/components/{my-component.d.ts → post-icon.d.ts} +4 -4
  42. package/dist/components/post-icon.js +168 -0
  43. package/dist/components/post-icon.js.map +1 -0
  44. package/dist/components/property-checkers.js +34 -0
  45. package/dist/components/property-checkers.js.map +1 -0
  46. package/dist/docs.d.ts +24 -0
  47. package/dist/docs.json +153 -41
  48. package/dist/esm/{index-865c32d6.js → index-6d5a72fa.js} +586 -154
  49. package/dist/esm/index-6d5a72fa.js.map +1 -0
  50. package/dist/esm/index.js +2 -0
  51. package/dist/esm/index.js.map +1 -0
  52. package/dist/esm/loader.js +6 -3
  53. package/dist/esm/loader.js.map +1 -0
  54. package/dist/esm/polyfills/css-shim.js +1 -1
  55. package/dist/esm/post-collapsible.entry.js +130 -0
  56. package/dist/esm/post-collapsible.entry.js.map +1 -0
  57. package/dist/esm/post-components.js +9 -3
  58. package/dist/esm/post-components.js.map +1 -0
  59. package/dist/esm/post-icon.entry.js +138 -0
  60. package/dist/esm/post-icon.entry.js.map +1 -0
  61. package/dist/esm/property-checkers-484ca671.js +34 -0
  62. package/dist/esm/property-checkers-484ca671.js.map +1 -0
  63. package/dist/post-components/index.esm.js +2 -0
  64. package/dist/post-components/index.esm.js.map +1 -0
  65. package/dist/post-components/p-7cd9c1ad.js +2 -0
  66. package/dist/post-components/p-7cd9c1ad.js.map +1 -0
  67. package/dist/post-components/p-a93114b9.js +3 -0
  68. package/dist/post-components/p-a93114b9.js.map +1 -0
  69. package/dist/post-components/p-b07185a3.entry.js +2 -0
  70. package/dist/post-components/p-b07185a3.entry.js.map +1 -0
  71. package/dist/post-components/p-c4af958b.entry.js +2 -0
  72. package/dist/post-components/p-c4af958b.entry.js.map +1 -0
  73. package/dist/post-components/post-components.esm.js +2 -1
  74. package/dist/post-components/post-components.esm.js.map +1 -0
  75. package/dist/types/components/post-collapsible/post-collapsible.d.ts +30 -0
  76. package/dist/types/components/post-icon/post-icon.d.ts +50 -0
  77. package/dist/types/components.d.ts +96 -28
  78. package/dist/types/stencil-public-runtime.d.ts +91 -19
  79. package/dist/types/utils/get-element-height.d.ts +3 -0
  80. package/dist/types/utils/index.d.ts +4 -0
  81. package/dist/types/utils/on-transition-end.d.ts +1 -0
  82. package/dist/types/utils/property-checkers.d.ts +5 -0
  83. package/dist/types/utils/should-reduce-motion.d.ts +1 -0
  84. package/loader/index.d.ts +9 -0
  85. package/package.json +25 -36
  86. package/dist/cjs/my-component.cjs.entry.js +0 -35
  87. package/dist/collection/components/my-component/my-component.css +0 -3
  88. package/dist/collection/components/my-component/my-component.js +0 -129
  89. package/dist/collection/components/my-component/my-component.stories.js +0 -19
  90. package/dist/collection/stories/Button.js +0 -21
  91. package/dist/collection/stories/Button.stories.js +0 -48
  92. package/dist/collection/stories/Header.js +0 -45
  93. package/dist/collection/stories/Header.stories.js +0 -20
  94. package/dist/collection/stories/Page.js +0 -67
  95. package/dist/collection/stories/Page.stories.js +0 -24
  96. package/dist/collection/stories/assets/code-brackets.svg +0 -1
  97. package/dist/collection/stories/assets/colors.svg +0 -1
  98. package/dist/collection/stories/assets/comments.svg +0 -1
  99. package/dist/collection/stories/assets/direction.svg +0 -1
  100. package/dist/collection/stories/assets/flow.svg +0 -1
  101. package/dist/collection/stories/assets/plugin.svg +0 -1
  102. package/dist/collection/stories/assets/repo.svg +0 -1
  103. package/dist/collection/stories/assets/stackalt.svg +0 -1
  104. package/dist/collection/utils/utils.js +0 -3
  105. package/dist/components/my-component.js +0 -54
  106. package/dist/esm/my-component.entry.js +0 -31
  107. package/dist/post-components/p-89fc10d3.js +0 -2
  108. package/dist/post-components/p-e4e802f7.entry.js +0 -1
  109. package/dist/types/components/my-component/my-component.d.ts +0 -22
  110. package/dist/types/components/my-component/my-component.stories.d.ts +0 -12
  111. package/dist/types/utils/utils.d.ts +0 -1
@@ -0,0 +1,173 @@
1
+ import { h } from '@stencil/core';
2
+ import { checkBoolean, checkOneOf, getElementHeight, onTransitionEnd } from '../../utils';
3
+ let nextId = 0;
4
+ export class PostCollapsible {
5
+ constructor() {
6
+ this.isLoaded = false;
7
+ this.collapsed = false;
8
+ this.headingLevel = 2;
9
+ this.isOpen = true;
10
+ this.collapseClasses = undefined;
11
+ this.collapseHeight = null;
12
+ this.headingTag = undefined;
13
+ this.collapsibleId = undefined;
14
+ this.hasHeader = undefined;
15
+ }
16
+ validateCollapsed(newValue = this.collapsed) {
17
+ checkBoolean(newValue, 'The post-collapsible "collapsed" prop should be a boolean.');
18
+ if (!this.isLoaded) {
19
+ this.isOpen = !newValue;
20
+ this.collapseClasses = this.getCollapseClasses();
21
+ }
22
+ else {
23
+ setTimeout(() => {
24
+ this.toggle(!newValue);
25
+ });
26
+ }
27
+ }
28
+ validateHeadingLevel(newValue = this.headingLevel) {
29
+ checkOneOf(newValue, [1, 2, 3, 4, 5, 6], 'The post-collapsible element requires a heading level between 1 and 6.');
30
+ this.headingTag = `h${newValue}`;
31
+ }
32
+ componentWillLoad() {
33
+ this.validateCollapsed();
34
+ this.validateHeadingLevel();
35
+ this.hasHeader = this.host.querySelectorAll('[slot="header"]').length > 0;
36
+ if (!this.hasHeader) {
37
+ console.warn('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');
38
+ }
39
+ this.collapsibleId = this.host.id || `post-collapsible-${nextId++}`;
40
+ this.collapseClasses = this.getCollapseClasses();
41
+ }
42
+ componentDidLoad() {
43
+ this.isLoaded = true;
44
+ this.collapsibleElement = this.host.shadowRoot.querySelector(`#${this.collapsibleId}--collapse`);
45
+ }
46
+ /**
47
+ * Triggers the collapse programmatically.
48
+ */
49
+ async toggle(open = !this.isOpen) {
50
+ if (open !== this.isOpen) {
51
+ this.isOpen = !this.isOpen;
52
+ this.startTransition();
53
+ await onTransitionEnd(this.collapsibleElement).then(() => {
54
+ this.collapseHeight = null;
55
+ this.collapseClasses = this.getCollapseClasses();
56
+ });
57
+ return this.isOpen;
58
+ }
59
+ }
60
+ startTransition() {
61
+ const expandedHeight = getElementHeight(this.collapsibleElement, 'show');
62
+ this.collapseHeight = `${this.isOpen ? 0 : expandedHeight}px`;
63
+ this.collapseClasses = 'collapsing';
64
+ setTimeout(() => {
65
+ this.collapseHeight = `${this.isOpen ? expandedHeight : 0}px`;
66
+ }, 50);
67
+ }
68
+ getCollapseClasses() {
69
+ return this.isOpen ? 'collapse show' : 'collapse';
70
+ }
71
+ render() {
72
+ if (!this.hasHeader) {
73
+ return (h("div", { id: `${this.collapsibleId}--collapse`, class: this.collapseClasses, style: { height: this.collapseHeight } }, h("slot", null)));
74
+ }
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: () => this.toggle() }, 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
+ }
77
+ static get is() { return "post-collapsible"; }
78
+ static get encapsulation() { return "shadow"; }
79
+ static get originalStyleUrls() {
80
+ return {
81
+ "$": ["post-collapsible.scss"]
82
+ };
83
+ }
84
+ static get styleUrls() {
85
+ return {
86
+ "$": ["post-collapsible.css"]
87
+ };
88
+ }
89
+ static get properties() {
90
+ return {
91
+ "collapsed": {
92
+ "type": "boolean",
93
+ "mutable": false,
94
+ "complexType": {
95
+ "original": "boolean",
96
+ "resolved": "boolean",
97
+ "references": {}
98
+ },
99
+ "required": false,
100
+ "optional": true,
101
+ "docs": {
102
+ "tags": [],
103
+ "text": "If `true`, the element is initially collapsed otherwise it is displayed."
104
+ },
105
+ "attribute": "collapsed",
106
+ "reflect": false,
107
+ "defaultValue": "false"
108
+ },
109
+ "headingLevel": {
110
+ "type": "number",
111
+ "mutable": false,
112
+ "complexType": {
113
+ "original": "number",
114
+ "resolved": "number",
115
+ "references": {}
116
+ },
117
+ "required": false,
118
+ "optional": true,
119
+ "docs": {
120
+ "tags": [],
121
+ "text": "Defines the hierarchical level of the collapsible header within the headings structure."
122
+ },
123
+ "attribute": "heading-level",
124
+ "reflect": false,
125
+ "defaultValue": "2"
126
+ }
127
+ };
128
+ }
129
+ static get states() {
130
+ return {
131
+ "isOpen": {},
132
+ "collapseClasses": {},
133
+ "collapseHeight": {},
134
+ "headingTag": {},
135
+ "collapsibleId": {},
136
+ "hasHeader": {}
137
+ };
138
+ }
139
+ static get methods() {
140
+ return {
141
+ "toggle": {
142
+ "complexType": {
143
+ "signature": "(open?: boolean) => Promise<boolean>",
144
+ "parameters": [{
145
+ "tags": [],
146
+ "text": ""
147
+ }],
148
+ "references": {
149
+ "Promise": {
150
+ "location": "global"
151
+ }
152
+ },
153
+ "return": "Promise<boolean>"
154
+ },
155
+ "docs": {
156
+ "text": "Triggers the collapse programmatically.",
157
+ "tags": []
158
+ }
159
+ }
160
+ };
161
+ }
162
+ static get elementRef() { return "host"; }
163
+ static get watchers() {
164
+ return [{
165
+ "propName": "collapsed",
166
+ "methodName": "validateCollapsed"
167
+ }, {
168
+ "propName": "headingLevel",
169
+ "methodName": "validateHeadingLevel"
170
+ }];
171
+ }
172
+ }
173
+ //# sourceMappingURL=post-collapsible.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-collapsible.js","sourceRoot":"","sources":["../../../src/components/post-collapsible/post-collapsible.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, h, Method, Prop, State, Watch } from '@stencil/core';\nimport { checkBoolean, checkOneOf, getElementHeight, onTransitionEnd } from '../../utils';\n\nlet nextId = 0;\n\n@Component({\n tag: 'post-collapsible',\n styleUrl: 'post-collapsible.scss',\n shadow: true,\n})\nexport class PostCollapsible {\n /**\n * If `true`, the element is initially collapsed otherwise it is displayed.\n */\n @Prop() collapsed?: boolean = false;\n\n /**\n * Defines the hierarchical level of the collapsible header within the headings structure.\n */\n @Prop() headingLevel?: number = 2;\n\n @State() isOpen = true;\n @State() collapseClasses: string;\n @State() collapseHeight: string | null = null;\n @State() headingTag: string | undefined;\n @State() collapsibleId: string;\n @State() hasHeader: boolean;\n\n @Element() host: HTMLElement;\n\n isLoaded = false;\n collapsibleElement: HTMLElement;\n\n @Watch('collapsed')\n validateCollapsed(newValue = this.collapsed) {\n checkBoolean(newValue, '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 @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('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 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(`#${this.collapsibleId}--collapse`);\n }\n\n /**\n * Triggers the collapse programmatically.\n */\n @Method()\n async toggle(open: boolean = !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 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 <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.toggle()}\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 );\n }\n}\n"]}
@@ -0,0 +1,94 @@
1
+ :host {
2
+ display: inline-block;
3
+ width: 1em;
4
+ vertical-align: -0.15em;
5
+ }
6
+
7
+ svg {
8
+ display: block;
9
+ width: 100%;
10
+ fill: currentColor;
11
+ }
12
+
13
+ :host([flip-h]) svg {
14
+ scale: -1 1;
15
+ }
16
+
17
+ :host([flip-v]) svg {
18
+ scale: 1 -1;
19
+ }
20
+
21
+ :host([flip-h][flip-v]) svg {
22
+ scale: -1;
23
+ }
24
+
25
+ :host([animation]) svg {
26
+ transform-origin: center;
27
+ }
28
+
29
+ :host([animation=cylon]) svg {
30
+ animation: icon-animation-cylon 0.75s ease-in-out infinite alternate;
31
+ }
32
+
33
+ :host([animation=cylon-vertical]) svg {
34
+ animation: icon-animation-cylon-vertical 0.75s ease-in-out infinite alternate;
35
+ }
36
+
37
+ :host([animation=spin]) svg {
38
+ animation: icon-animation-spin 2s linear infinite normal;
39
+ }
40
+
41
+ :host([animation=spin-reverse]) svg {
42
+ animation: icon-animation-spin 2s linear infinite reverse;
43
+ }
44
+
45
+ :host([animation=fade]) svg {
46
+ animation: icon-animation-fade 0.75s ease-in-out infinite alternate;
47
+ }
48
+
49
+ :host([animation=throb]) svg {
50
+ animation: icon-animation-throb 0.75s ease-in-out infinite alternate;
51
+ }
52
+
53
+ @keyframes icon-animation-cylon {
54
+ from {
55
+ transform: translateX(-25%);
56
+ }
57
+ to {
58
+ transform: translateX(25%);
59
+ }
60
+ }
61
+ @keyframes icon-animation-cylon-vertical {
62
+ from {
63
+ transform: translateY(25%);
64
+ }
65
+ to {
66
+ transform: translateY(-25%);
67
+ }
68
+ }
69
+ @keyframes icon-animation-fade {
70
+ from {
71
+ opacity: 0.1;
72
+ }
73
+ to {
74
+ opacity: 1;
75
+ }
76
+ }
77
+ @keyframes icon-animation-spin {
78
+ from {
79
+ transform: rotate(0deg);
80
+ }
81
+ to {
82
+ transform: rotate(359deg);
83
+ }
84
+ }
85
+ @keyframes icon-animation-throb {
86
+ from {
87
+ opacity: 0.5;
88
+ transform: scale(0.5);
89
+ }
90
+ to {
91
+ opacity: 1;
92
+ transform: scale(1);
93
+ }
94
+ }
@@ -0,0 +1,291 @@
1
+ import { Host, h } from '@stencil/core';
2
+ import { checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';
3
+ 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
+ ];
12
+ /**
13
+ * @class PostIcon - representing a stencil component
14
+ */
15
+ export class PostIcon {
16
+ constructor() {
17
+ this.name = undefined;
18
+ this.base = undefined;
19
+ this.flipH = undefined;
20
+ this.flipV = undefined;
21
+ this.scale = undefined;
22
+ this.rotate = undefined;
23
+ this.animation = undefined;
24
+ this.initialPath = undefined;
25
+ this.path = undefined;
26
+ this.svgSource = '<svg viewBox="0 0 16 16"></svg>';
27
+ this.svgOutput = undefined;
28
+ }
29
+ validateName(newValue = this.name) {
30
+ checkType(newValue, 'string', 'The post-icon "name" prop should be a string.');
31
+ }
32
+ validateBase(newValue = this.base) {
33
+ checkEmptyOrType(newValue, 'string', 'The post-icon "base" prop should be a string.');
34
+ }
35
+ validateFlipH(newValue = this.flipH) {
36
+ checkEmptyOrType(newValue, 'boolean', 'The post-icon "flipH" prop should be a boolean.');
37
+ }
38
+ validateFlipV(newValue = this.flipV) {
39
+ checkEmptyOrType(newValue, 'boolean', 'The post-icon "flipV" prop should be a boolean.');
40
+ }
41
+ validateScale(newValue = this.scale) {
42
+ checkEmptyOrType(newValue, 'number', 'The post-icon "scale" prop should be a number.');
43
+ }
44
+ validateRotate(newValue = this.rotate) {
45
+ checkEmptyOrType(newValue, 'number', 'The post-icon "rotate" prop should be a number.');
46
+ }
47
+ validateAnimation(newValue = this.animation) {
48
+ if (newValue !== undefined)
49
+ checkEmptyOrOneOf(newValue, ANIMATION_KEYS, `The post-icon "animation" prop requires one of the following values: ${ANIMATION_KEYS.join(', ')}.`);
50
+ }
51
+ connectedCallback() {
52
+ var _a;
53
+ // Construct icon path from different possible sources
54
+ let basePath;
55
+ const metaBase = document.head.querySelector('meta[name="design-system-settings"][data-post-icon-base]');
56
+ if (this.base) {
57
+ basePath = this.base;
58
+ }
59
+ else if (metaBase) {
60
+ basePath = metaBase.getAttribute('data-post-icon-base');
61
+ }
62
+ else {
63
+ basePath = CDN_URL;
64
+ }
65
+ this.path = this.getPath(basePath);
66
+ this.svgSource = (_a = window.localStorage.getItem(`post-icon-${this.name}`)) !== null && _a !== void 0 ? _a : this.svgSource;
67
+ }
68
+ componentWillLoad() {
69
+ this.validateName();
70
+ this.validateBase();
71
+ this.validateFlipH();
72
+ this.validateFlipV();
73
+ this.validateScale();
74
+ this.validateRotate();
75
+ this.validateAnimation();
76
+ this.fetchSVG();
77
+ }
78
+ componentWillRender() {
79
+ const svgStyles = Object.entries({
80
+ scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
81
+ rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
82
+ })
83
+ .filter(([_key, value]) => value !== null)
84
+ .map(([key, value]) => `${key}: ${value}`)
85
+ .join(';');
86
+ const helperElement = document.createElement('div');
87
+ helperElement.innerHTML = this.svgSource;
88
+ const svgElement = helperElement.querySelector('svg');
89
+ svgElement.setAttribute('style', svgStyles);
90
+ this.svgOutput = helperElement.innerHTML;
91
+ }
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
+ render() {
121
+ return (h(Host, null, h("div", { innerHTML: this.svgOutput })));
122
+ }
123
+ static get is() { return "post-icon"; }
124
+ static get encapsulation() { return "shadow"; }
125
+ static get originalStyleUrls() {
126
+ return {
127
+ "$": ["post-icon.scss"]
128
+ };
129
+ }
130
+ static get styleUrls() {
131
+ return {
132
+ "$": ["post-icon.css"]
133
+ };
134
+ }
135
+ static get properties() {
136
+ return {
137
+ "name": {
138
+ "type": "string",
139
+ "mutable": false,
140
+ "complexType": {
141
+ "original": "string",
142
+ "resolved": "string",
143
+ "references": {}
144
+ },
145
+ "required": false,
146
+ "optional": false,
147
+ "docs": {
148
+ "tags": [],
149
+ "text": "The name/id of the icon (e.g. 1000, 1001, ...)."
150
+ },
151
+ "attribute": "name",
152
+ "reflect": false
153
+ },
154
+ "base": {
155
+ "type": "string",
156
+ "mutable": false,
157
+ "complexType": {
158
+ "original": "string",
159
+ "resolved": "string",
160
+ "references": {}
161
+ },
162
+ "required": false,
163
+ "optional": true,
164
+ "docs": {
165
+ "tags": [],
166
+ "text": "The base path, where the icons are located (must be a public url)."
167
+ },
168
+ "attribute": "base",
169
+ "reflect": false
170
+ },
171
+ "flipH": {
172
+ "type": "boolean",
173
+ "mutable": false,
174
+ "complexType": {
175
+ "original": "boolean",
176
+ "resolved": "boolean",
177
+ "references": {}
178
+ },
179
+ "required": false,
180
+ "optional": true,
181
+ "docs": {
182
+ "tags": [],
183
+ "text": "When set to `true`, the icon will be flipped horizontally."
184
+ },
185
+ "attribute": "flip-h",
186
+ "reflect": false
187
+ },
188
+ "flipV": {
189
+ "type": "boolean",
190
+ "mutable": false,
191
+ "complexType": {
192
+ "original": "boolean",
193
+ "resolved": "boolean",
194
+ "references": {}
195
+ },
196
+ "required": false,
197
+ "optional": true,
198
+ "docs": {
199
+ "tags": [],
200
+ "text": "When set to `true`, the icon will be flipped vertically."
201
+ },
202
+ "attribute": "flip-v",
203
+ "reflect": false
204
+ },
205
+ "scale": {
206
+ "type": "number",
207
+ "mutable": false,
208
+ "complexType": {
209
+ "original": "number",
210
+ "resolved": "number",
211
+ "references": {}
212
+ },
213
+ "required": false,
214
+ "optional": true,
215
+ "docs": {
216
+ "tags": [],
217
+ "text": "The `number` for the css `scale` transformation."
218
+ },
219
+ "attribute": "scale",
220
+ "reflect": false
221
+ },
222
+ "rotate": {
223
+ "type": "number",
224
+ "mutable": false,
225
+ "complexType": {
226
+ "original": "number",
227
+ "resolved": "number",
228
+ "references": {}
229
+ },
230
+ "required": false,
231
+ "optional": true,
232
+ "docs": {
233
+ "tags": [],
234
+ "text": "The `number` of degree for the css `rotate` transformation."
235
+ },
236
+ "attribute": "rotate",
237
+ "reflect": false
238
+ },
239
+ "animation": {
240
+ "type": "string",
241
+ "mutable": false,
242
+ "complexType": {
243
+ "original": "string",
244
+ "resolved": "string",
245
+ "references": {}
246
+ },
247
+ "required": false,
248
+ "optional": true,
249
+ "docs": {
250
+ "tags": [],
251
+ "text": "The name of the animation (`cylon`, `cylon-vertical`, `spin`, `spin-reverse`, `fade`, `throb`)."
252
+ },
253
+ "attribute": "animation",
254
+ "reflect": false
255
+ }
256
+ };
257
+ }
258
+ static get states() {
259
+ return {
260
+ "initialPath": {},
261
+ "path": {},
262
+ "svgSource": {},
263
+ "svgOutput": {}
264
+ };
265
+ }
266
+ static get watchers() {
267
+ return [{
268
+ "propName": "name",
269
+ "methodName": "validateName"
270
+ }, {
271
+ "propName": "base",
272
+ "methodName": "validateBase"
273
+ }, {
274
+ "propName": "flipH",
275
+ "methodName": "validateFlipH"
276
+ }, {
277
+ "propName": "flipV",
278
+ "methodName": "validateFlipV"
279
+ }, {
280
+ "propName": "scale",
281
+ "methodName": "validateScale"
282
+ }, {
283
+ "propName": "rotate",
284
+ "methodName": "validateRotate"
285
+ }, {
286
+ "propName": "animation",
287
+ "methodName": "validateAnimation"
288
+ }];
289
+ }
290
+ }
291
+ //# sourceMappingURL=post-icon.js.map
@@ -0,0 +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,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK;IACjC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,gDAAgD,CAAC,CAAC;EACzF,CAAC;EAGD,cAAc,CAAC,QAAQ,GAAG,IAA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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 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"","sourcesContent":["export { Components, JSX } from './components';\n"]}
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright 2022 by Swiss Post, Information Technology
3
+ */
4
+ export function getElementHeight(el, classesWhenShown = []) {
5
+ if (!Array.isArray(classesWhenShown))
6
+ classesWhenShown = [classesWhenShown];
7
+ const classesToAdd = classesWhenShown.filter(klass => !el.classList.contains(klass));
8
+ if (classesToAdd.length)
9
+ el.classList.add(...classesToAdd);
10
+ const scrollHeight = el.scrollHeight;
11
+ if (classesToAdd.length)
12
+ el.classList.remove(...classesToAdd);
13
+ return scrollHeight;
14
+ }
15
+ //# sourceMappingURL=get-element-height.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-element-height.js","sourceRoot":"","sources":["../../src/utils/get-element-height.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,UAAU,gBAAgB,CAAC,EAAe,EAAE,mBAAwB,EAAE;EAC1E,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":["/*\n * Copyright 2022 by Swiss Post, Information Technology\n */\n\nexport 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: any = []): 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"]}
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright 2022 by Swiss Post, Information Technology
3
+ */
4
+ export * from './get-element-height';
5
+ export * from './on-transition-end';
6
+ export * from './property-checkers';
7
+ export * from './should-reduce-motion';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC","sourcesContent":["/*\n * Copyright 2022 by Swiss Post, Information Technology\n */\n\nexport * from './get-element-height';\nexport * from './on-transition-end';\nexport * from './property-checkers';\nexport * from './should-reduce-motion';\n"]}
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2022 by Swiss Post, Information Technology
3
+ */
4
+ import { shouldReduceMotion } from './should-reduce-motion';
5
+ export async function onTransitionEnd(el) {
6
+ return new Promise(resolve => {
7
+ if (shouldReduceMotion()) {
8
+ resolve();
9
+ }
10
+ else {
11
+ el.ontransitionend = () => {
12
+ resolve();
13
+ el.ontransitionend = null;
14
+ };
15
+ }
16
+ });
17
+ }
18
+ //# sourceMappingURL=on-transition-end.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-transition-end.js","sourceRoot":"","sources":["../../src/utils/on-transition-end.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,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":["/*\n * Copyright 2022 by Swiss Post, Information Technology\n */\n\nimport { 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"]}