@swisspost/design-system-components 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-126f28cf.js → index-f95ab17b.js} +62 -20
- package/dist/cjs/index-f95ab17b.js.map +1 -0
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/{package-f1eacd4f.js → package-5e7ba83a.js} +2 -2
- package/dist/cjs/{package-f1eacd4f.js.map → package-5e7ba83a.js.map} +1 -1
- package/dist/cjs/post-collapsible.cjs.entry.js +3 -3
- package/dist/cjs/post-collapsible.cjs.entry.js.map +1 -1
- package/dist/cjs/post-components.cjs.js +3 -3
- package/dist/cjs/post-components.cjs.js.map +1 -1
- package/dist/cjs/post-icon.cjs.entry.js +28 -90
- package/dist/cjs/post-icon.cjs.entry.js.map +1 -1
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/post-collapsible/post-collapsible.css +1166 -48
- package/dist/collection/components/post-icon/post-icon.css +10 -10
- package/dist/collection/components/post-icon/post-icon.js +53 -105
- package/dist/collection/components/post-icon/post-icon.js.map +1 -1
- package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js +36 -0
- package/dist/collection/utils/property-checkers/tests/check-non-empty.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js +13 -0
- package/dist/collection/utils/property-checkers/tests/check-one-of.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/check-type.spec.js +103 -0
- package/dist/collection/utils/property-checkers/tests/check-type.spec.js.map +1 -0
- package/dist/collection/utils/property-checkers/tests/empty-or.spec.js +23 -0
- package/dist/collection/utils/property-checkers/tests/empty-or.spec.js.map +1 -0
- package/dist/collection/utils/tests/should-reduce-motion.spec.js +16 -0
- package/dist/collection/utils/tests/should-reduce-motion.spec.js.map +1 -0
- package/dist/components/package.js +1 -1
- package/dist/components/post-collapsible.js +2 -2
- package/dist/components/post-collapsible.js.map +1 -1
- package/dist/components/post-icon.js +28 -90
- package/dist/components/post-icon.js.map +1 -1
- package/dist/docs.json +36 -9
- package/dist/esm/{index-286143e7.js → index-0cfe0348.js} +62 -20
- package/dist/esm/index-0cfe0348.js.map +1 -0
- package/dist/esm/loader.js +4 -4
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/{package-144d0036.js → package-1c534bc2.js} +2 -2
- package/dist/esm/{package-144d0036.js.map → package-1c534bc2.js.map} +1 -1
- package/dist/esm/post-collapsible.entry.js +3 -3
- package/dist/esm/post-collapsible.entry.js.map +1 -1
- package/dist/esm/post-components.js +4 -4
- package/dist/esm/post-components.js.map +1 -1
- package/dist/esm/post-icon.entry.js +28 -90
- package/dist/esm/post-icon.entry.js.map +1 -1
- package/dist/post-components/{p-d2e9b37c.js → p-0049f179.js} +2 -2
- package/dist/post-components/p-50562794.entry.js +2 -0
- package/dist/post-components/{p-72fc6cda.entry.js.map → p-50562794.entry.js.map} +1 -1
- package/dist/post-components/p-8f4d1bc9.js +3 -0
- package/dist/post-components/p-8f4d1bc9.js.map +1 -0
- package/dist/post-components/p-fd9201c2.entry.js +2 -0
- package/dist/post-components/p-fd9201c2.entry.js.map +1 -0
- package/dist/post-components/post-components.esm.js +1 -1
- package/dist/post-components/post-components.esm.js.map +1 -1
- package/dist/types/components/post-icon/post-icon.d.ts +14 -15
- package/dist/types/components.d.ts +17 -17
- package/dist/types/stencil-public-runtime.d.ts +1 -0
- package/loader/index.d.ts +1 -1
- package/package.json +13 -14
- package/dist/cjs/index-126f28cf.js.map +0 -1
- package/dist/esm/index-286143e7.js.map +0 -1
- package/dist/post-components/p-0c286590.js +0 -3
- package/dist/post-components/p-0c286590.js.map +0 -1
- package/dist/post-components/p-20d342a4.entry.js +0 -2
- package/dist/post-components/p-20d342a4.entry.js.map +0 -1
- package/dist/post-components/p-72fc6cda.entry.js +0 -2
- /package/dist/post-components/{p-d2e9b37c.js.map → p-0049f179.js.map} +0 -0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B,IACzB,EAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAC,kBAAkB,EAAC,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa,UAAU,IAC3E,cACE,KAAK,EAAE,oBAAoB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,EAC3D,IAAI,EAAC,QAAQ,mBACE,GAAG,IAAI,CAAC,MAAM,EAAE,mBAChB,GAAG,IAAI,CAAC,aAAa,YAAY,EAChD,OAAO,EAAE,IAAI,CAAC,sBAAsB,IAEpC,YAAM,IAAI,EAAC,QAAQ,GAAG,CACf,CACO,EAClB,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,IAEhD,WAAK,KAAK,EAAC,gBAAgB,IACzB,eAAQ,CACJ,CACF,CACF,CACD,EACP;GACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["PostCollapsible"],"sources":["./src/utils/get-element-height.ts","./src/utils/should-reduce-motion.ts","./src/utils/on-transition-end.ts","./src/components/post-collapsible/post-collapsible.scss?tag=post-collapsible&encapsulation=shadow","./src/components/post-collapsible/post-collapsible.tsx"],"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","export function shouldReduceMotion(): boolean {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n","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","@use '@swisspost/design-system-styles/basics';\n@use '@swisspost/design-system-styles/components/accordion';\n@use '@swisspost/design-system-styles/components/transitions';\n\n:host {\n display: block;\n}\n","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"],"version":3}
|
|
1
|
+
{"file":"post-collapsible.js","mappings":";;;SAGgB,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,IAAI,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;;SCdgB,kBAAkB;EAChC,OAAO,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAC;AACvE;;ACAO,eAAe,eAAe,CAAC,EAAe;EACnD,OAAO,IAAI,OAAO,CAAC,OAAO;IACxB,IAAI,kBAAkB,EAAE,EAAE;MACxB,OAAO,EAAE,CAAC;KACX;SAAM;MACL,EAAE,CAAC,eAAe,GAAG;QACnB,OAAO,EAAE,CAAC;QACV,EAAE,CAAC,eAAe,GAAG,IAAI,CAAC;OAC3B,CAAC;KACH;GACF,CAAC,CAAC;AACL;;ACbA,MAAM,kBAAkB,GAAG,gvzNAAgvzN;;ACI3wzN,IAAI,MAAM,GAAG,CAAC,CAAC;MAOFA,iBAAe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AC,eAAe,EAC3B,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,IAEtC,eAAQ,CACJ,EACN;KACH;IAED,QACE,EAAC,IAAI,oBAAe,OAAO,IACzB,WAAK,KAAK,EAAC,gBAAgB,IACzB,EAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAC,kBAAkB,EAAC,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa,UAAU,IAC3E,cACE,KAAK,EAAE,oBAAoB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,EAC3D,IAAI,EAAC,QAAQ,mBACE,GAAG,IAAI,CAAC,MAAM,EAAE,mBAChB,GAAG,IAAI,CAAC,aAAa,YAAY,EAChD,OAAO,EAAE,IAAI,CAAC,sBAAsB,IAEpC,YAAM,IAAI,EAAC,QAAQ,GAAG,CACf,CACO,EAClB,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,IAEhD,WAAK,KAAK,EAAC,gBAAgB,IACzB,eAAQ,CACJ,CACF,CACF,CACD,EACP;GACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["PostCollapsible"],"sources":["./src/utils/get-element-height.ts","./src/utils/should-reduce-motion.ts","./src/utils/on-transition-end.ts","./src/components/post-collapsible/post-collapsible.scss?tag=post-collapsible&encapsulation=shadow","./src/components/post-collapsible/post-collapsible.tsx"],"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","export function shouldReduceMotion(): boolean {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n","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","@use '@swisspost/design-system-styles/basics';\n@use '@swisspost/design-system-styles/components/accordion';\n@use '@swisspost/design-system-styles/components/transitions';\n\n:host {\n display: block;\n}\n","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"],"version":3}
|
|
@@ -20,25 +20,32 @@ function checkNonEmpty(value, error) {
|
|
|
20
20
|
const checkEmptyOrOneOf = emptyOr(checkOneOf);
|
|
21
21
|
const checkEmptyOrType = emptyOr(checkType);
|
|
22
22
|
|
|
23
|
-
const postIconCss = ":host{display:inline-block;width:1em;vertical-align:-0.15em}svg{display:block;width:100%;fill:currentColor}:host([flip-h]) svg{scale:-1 1}:host([flip-v]) svg{scale:1 -1}:host([flip-h][flip-v]) svg{scale:-1}:host([animation])
|
|
23
|
+
const postIconCss = ":host{display:inline-block;width:1em;vertical-align:-0.15em}svg{display:block;width:100%;fill:currentColor}:host([flip-h]:not([flip-h=false])) svg{scale:-1 1}:host([flip-v]:not([flip-v=false])) svg{scale:1 -1}:host([flip-h][flip-v]:not([flip-h=false],[flip-v=false])) svg{scale:-1}:host([animation]){transform-origin:center}:host([animation=cylon]){animation:icon-animation-cylon 0.75s ease-in-out infinite alternate}:host([animation=cylon-vertical]){animation:icon-animation-cylon-vertical 0.75s ease-in-out infinite alternate}:host([animation=spin]){animation:icon-animation-spin 2s linear infinite normal}:host([animation=spin-reverse]){animation:icon-animation-spin 2s linear infinite reverse}:host([animation=fade]){animation:icon-animation-fade 0.75s ease-in-out infinite alternate}:host([animation=throb]){animation:icon-animation-throb 0.75s ease-in-out infinite alternate}@keyframes icon-animation-cylon{from{transform:translateX(-25%)}to{transform:translateX(25%)}}@keyframes icon-animation-cylon-vertical{from{transform:translateY(25%)}to{transform:translateY(-25%)}}@keyframes icon-animation-fade{from{opacity:0.1}to{opacity:1}}@keyframes icon-animation-spin{from{transform:rotate(0deg)}to{transform:rotate(359deg)}}@keyframes icon-animation-throb{from{opacity:0.5;transform:scale(0.5)}to{opacity:1;transform:scale(1)}}";
|
|
24
24
|
|
|
25
25
|
const CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const ANIMATION_NAMES = [
|
|
27
|
+
'cylon',
|
|
28
|
+
'cylon-vertical',
|
|
29
|
+
'spin',
|
|
30
|
+
'spin-reverse',
|
|
31
|
+
'fade',
|
|
32
|
+
'throb',
|
|
33
|
+
];
|
|
34
|
+
const ANIMATION_KEYS = [...ANIMATION_NAMES];
|
|
35
|
+
const PostIcon$1 = /*@__PURE__*/ proxyCustomElement(class PostIcon extends HTMLElement {
|
|
28
36
|
constructor() {
|
|
29
37
|
super();
|
|
30
38
|
this.__registerHost();
|
|
31
39
|
this.__attachShadow();
|
|
32
|
-
this.
|
|
33
|
-
this.pathForceCDN = false;
|
|
40
|
+
this.svgStyles = undefined;
|
|
34
41
|
this.svgOutput = undefined;
|
|
35
|
-
this.animation =
|
|
36
|
-
this.base =
|
|
37
|
-
this.flipH =
|
|
38
|
-
this.flipV =
|
|
42
|
+
this.animation = null;
|
|
43
|
+
this.base = null;
|
|
44
|
+
this.flipH = false;
|
|
45
|
+
this.flipV = false;
|
|
39
46
|
this.name = undefined;
|
|
40
|
-
this.rotate =
|
|
41
|
-
this.scale =
|
|
47
|
+
this.rotate = null;
|
|
48
|
+
this.scale = null;
|
|
42
49
|
}
|
|
43
50
|
validateAnimation(newValue = this.animation) {
|
|
44
51
|
if (newValue !== undefined)
|
|
@@ -73,91 +80,22 @@ const PostIcon$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
73
80
|
this.validateAnimation();
|
|
74
81
|
}
|
|
75
82
|
componentWillRender() {
|
|
76
|
-
// create path dependant on the props
|
|
77
83
|
this.setPath();
|
|
78
|
-
// fetch icon if the prop "name" is defined and
|
|
79
|
-
// the path has not allready been loaded
|
|
80
|
-
if (this.name && this.path !== this.loadedPath) {
|
|
81
|
-
this.loadedPath = this.path;
|
|
82
|
-
this.fetchIcon()
|
|
83
|
-
.then(successfullyLoaded => {
|
|
84
|
-
// create icon only if an svg has been loaded successfully
|
|
85
|
-
if (successfullyLoaded)
|
|
86
|
-
this.createIcon();
|
|
87
|
-
})
|
|
88
|
-
.catch(error => {
|
|
89
|
-
console.error(error);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
84
|
}
|
|
93
85
|
setPath() {
|
|
94
|
-
var _a;
|
|
86
|
+
var _a, _b, _c, _d;
|
|
95
87
|
// Construct icon path from different possible sources
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
basePath = metaBase.getAttribute('data-post-icon-base');
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
basePath = CDN_URL;
|
|
106
|
-
}
|
|
107
|
-
// use "basePath" only if "pathForceCDN" state is "false"
|
|
108
|
-
this.path = this.getPath(this.pathForceCDN ? CDN_URL : basePath);
|
|
109
|
-
// try to get the "svgSource" from localStorage
|
|
110
|
-
this.svgSource = (_a = window.localStorage.getItem(`post-icon-${this.name}`)) !== null && _a !== void 0 ? _a : this.svgSource;
|
|
111
|
-
// reset "pathForceCDN" after every try
|
|
112
|
-
this.pathForceCDN = false;
|
|
113
|
-
}
|
|
114
|
-
getPath(basePath) {
|
|
115
|
-
return new URL([...basePath.split('/'), `${this.name}.svg#icon`].join('/'), window.location.origin).toString();
|
|
116
|
-
}
|
|
117
|
-
fetchIcon() {
|
|
118
|
-
return new Promise((resolve, reject) => {
|
|
119
|
-
fetch(this.path)
|
|
120
|
-
.then(response => response.text())
|
|
121
|
-
.then(textResponse => {
|
|
122
|
-
// match "svg" out of "textResponse"
|
|
123
|
-
const match = textResponse.match(/^<svg\b([\s\S]*)><\/svg>/);
|
|
124
|
-
if (match !== null) {
|
|
125
|
-
// set "svgSource" and return "successfullyLoaded" with true
|
|
126
|
-
this.svgSource = match[0];
|
|
127
|
-
window.localStorage.setItem(`post-icon-${this.name}`, this.svgSource);
|
|
128
|
-
resolve(true);
|
|
129
|
-
}
|
|
130
|
-
else if (this.path !== this.getPath(CDN_URL)) {
|
|
131
|
-
// if used "path" is not CDN path, and fetch has loaded something else than a "svg", try to reload it from the CDN
|
|
132
|
-
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.`);
|
|
133
|
-
// trigger a component update, which will result in a refetch of the icon with the "CDN_URL"
|
|
134
|
-
this.pathForceCDN = true;
|
|
135
|
-
// return "successfullyLoaded" with false
|
|
136
|
-
resolve(false);
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
.catch(reject);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
createIcon() {
|
|
143
|
-
// create inline styles for some properties
|
|
144
|
-
const svgStyles = Object.entries({
|
|
145
|
-
scale: this.scale && !isNaN(Number(this.scale)) ? `${this.scale}` : null,
|
|
146
|
-
rotate: this.rotate && !isNaN(Number(this.rotate)) ? `${this.rotate}deg` : null,
|
|
147
|
-
})
|
|
148
|
-
.filter(([_key, value]) => value !== null)
|
|
149
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
150
|
-
.join(';');
|
|
151
|
-
// create svg in RAM and append the above styles, before defining the "svgOutput"
|
|
152
|
-
const helperElement = document.createElement('div');
|
|
153
|
-
helperElement.innerHTML = this.svgSource;
|
|
154
|
-
const svgElement = helperElement.querySelector('svg');
|
|
155
|
-
svgElement.setAttribute('style', svgStyles);
|
|
156
|
-
this.svgOutput = helperElement.innerHTML;
|
|
88
|
+
const metaBase = (_b = (_a = document.head
|
|
89
|
+
.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;
|
|
90
|
+
const fileBase = `${(_d = (_c = this.base) !== null && _c !== void 0 ? _c : metaBase) !== null && _d !== void 0 ? _d : CDN_URL}/`.replace(/\/\/$/, '/');
|
|
91
|
+
const fileName = `${this.name}.svg#icon`;
|
|
92
|
+
const filePath = `${fileBase}${fileName}`;
|
|
93
|
+
this.path = new URL(filePath, window.location.origin).toString();
|
|
157
94
|
}
|
|
158
95
|
render() {
|
|
159
|
-
return (h(Host, { "data-version": version }, h("
|
|
96
|
+
return (h(Host, { "data-version": version }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32" }, h("use", { href: this.path }))));
|
|
160
97
|
}
|
|
98
|
+
get host() { return this; }
|
|
161
99
|
static get watchers() { return {
|
|
162
100
|
"animation": ["validateAnimation"],
|
|
163
101
|
"base": ["validateBase"],
|
|
@@ -176,7 +114,7 @@ const PostIcon$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
176
114
|
"name": [1],
|
|
177
115
|
"rotate": [2],
|
|
178
116
|
"scale": [2],
|
|
179
|
-
"
|
|
117
|
+
"svgStyles": [32],
|
|
180
118
|
"svgOutput": [32]
|
|
181
119
|
}]);
|
|
182
120
|
function defineCustomElement$1() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"post-icon.js","mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;;SCEjC,OAAO,CAAsB,KAA2B;EACtE,OAAO,CAAC,GAAG,IAAO;IAChB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC;MAAE,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;GAC1D,CAAC;AACJ;;SCLgB,aAAa,CAAC,KAAc,EAAE,KAAa;EACzD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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["PostIcon"],"sources":["./src/utils/property-checkers/constants.ts","./src/utils/property-checkers/empty-or.ts","./src/utils/property-checkers/check-non-empty.ts","./src/utils/property-checkers/index.ts","./src/components/post-icon/post-icon.scss?tag=post-icon&encapsulation=shadow","./src/components/post-icon/post-icon.tsx"],"sourcesContent":["export const EMPTY_VALUES = [undefined, null, ''];\n","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","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","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","@use 'sass:map';\n\n$post-icon-animations: (\n 'cylon': icon-animation-cylon .75s ease-in-out infinite alternate,\n 'cylon-vertical': icon-animation-cylon-vertical .75s ease-in-out infinite alternate,\n 'spin': icon-animation-spin 2s linear infinite normal,\n 'spin-reverse': icon-animation-spin 2s linear infinite reverse,\n 'fade': icon-animation-fade .75s ease-in-out infinite alternate,\n 'throb': icon-animation-throb .75s ease-in-out infinite alternate\n);\n\n:host {\n display: inline-block;\n width: 1em;\n vertical-align: -0.15em;\n}\n\nsvg {\n display: block;\n width: 100%;\n fill: currentColor;\n}\n\n// flip\n\n:host([flip-h]) {\n svg { scale: -1 1; }\n}\n\n:host([flip-v]) {\n svg { scale: 1 -1; }\n}\n\n:host([flip-h][flip-v]) {\n svg { scale: -1; }\n}\n\n// scale\n// done with inline styling\n\n// rotate\n// done with inline styling\n\n// animation\n\n:host([animation]) {\n svg {\n transform-origin: center;\n }\n}\n\n@each $key, $value in $post-icon-animations {\n :host([animation=\"#{$key}\"]) {\n svg {\n animation: $value;\n }\n }\n}\n\n@keyframes icon-animation-cylon {\n from { transform: translateX(-25%) }\n to { transform: translateX(25%) }\n}\n\n@keyframes icon-animation-cylon-vertical {\n from { transform: translateY(25%); }\n to { transform: translateY(-25%); }\n}\n\n@keyframes icon-animation-fade {\n from { opacity: .1; }\n to { opacity: 1; }\n}\n\n@keyframes icon-animation-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(359deg); }\n}\n\n@keyframes icon-animation-throb {\n from {\n opacity: .5;\n transform: scale(0.5);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n","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"],"version":3}
|
|
1
|
+
{"file":"post-icon.js","mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;;SCEjC,OAAO,CAAsB,KAA2B;EACtE,OAAO,CAAC,GAAG,IAAO;IAChB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC;MAAE,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;GAC1D,CAAC;AACJ;;SCLgB,aAAa,CAAC,KAAc,EAAE,KAAa;EACzD,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE;IACvC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;GACxB;AACH;;ACFO,MAAM,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC9C,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;;ACLlD,MAAM,WAAW,GAAG,qzCAAqzC;;ACIz0C,MAAM,OAAO,GAAG,oEAAoE,CAAC;AACrF,MAAM,eAAe,GAAG;EACtB,OAAO;EACP,gBAAgB;EAChB,MAAM;EACN,cAAc;EACd,MAAM;EACN,OAAO;CACC,CAAC;AACX,MAAM,cAAc,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC;MAY/BA,UAAQ;;;;;;;qBAW6B,IAAI;gBAiBZ,IAAI;iBAUT,KAAK;iBAUL,KAAK;;kBAqBE,IAAI;iBAUL,IAAI;;EAjE7C,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;IACzC,IAAI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,CAAC;GAChB;EAEO,OAAO;;;IAEb,MAAM,QAAQ,GACZ,MAAA,MAAA,QAAQ,CAAC,IAAI;OACV,aAAa,CAAC,0DAA0D,CAAC,0CACxE,YAAY,CAAC,qBAAqB,CAAC,mCAAI,IAAI,CAAC;IAElD,MAAM,QAAQ,GAAG,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,mCAAI,QAAQ,mCAAI,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,IAAI,WAAW,CAAC;IACzC,MAAM,QAAQ,GAAG,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE1C,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;GAClE;EAED,MAAM;IACJ,QACE,EAAC,IAAI,oBAAe,OAAO,IACzB,WAAK,KAAK,EAAC,4BAA4B,EAAC,OAAO,EAAC,WAAW,IACzD,WAAK,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI,CACpB,CACD,EACP;GACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["PostIcon"],"sources":["./src/utils/property-checkers/constants.ts","./src/utils/property-checkers/empty-or.ts","./src/utils/property-checkers/check-non-empty.ts","./src/utils/property-checkers/index.ts","./src/components/post-icon/post-icon.scss?tag=post-icon&encapsulation=shadow","./src/components/post-icon/post-icon.tsx"],"sourcesContent":["export const EMPTY_VALUES = [undefined, null, ''];\n","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","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","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","@use 'sass:map';\n\n$post-icon-animations: (\n 'cylon': icon-animation-cylon 0.75s ease-in-out infinite alternate,\n 'cylon-vertical': icon-animation-cylon-vertical 0.75s ease-in-out infinite alternate,\n 'spin': icon-animation-spin 2s linear infinite normal,\n 'spin-reverse': icon-animation-spin 2s linear infinite reverse,\n 'fade': icon-animation-fade 0.75s ease-in-out infinite alternate,\n 'throb': icon-animation-throb 0.75s ease-in-out infinite alternate,\n);\n\n:host {\n display: inline-block;\n width: 1em;\n vertical-align: -0.15em;\n}\n\nsvg {\n display: block;\n width: 100%;\n fill: currentColor;\n}\n\n// flip\n\n:host([flip-h]:not([flip-h='false'])) {\n svg {\n scale: -1 1;\n }\n}\n\n:host([flip-v]:not([flip-v='false'])) {\n svg {\n scale: 1 -1;\n }\n}\n\n:host([flip-h][flip-v]:not([flip-h='false'], [flip-v='false'])) {\n svg {\n scale: -1;\n }\n}\n\n// scale\n// done with inline styling\n\n// rotate\n// done with inline styling\n\n// animation\n\n:host([animation]) {\n transform-origin: center;\n}\n\n@each $key, $value in $post-icon-animations {\n :host([animation='#{$key}']) {\n animation: $value;\n }\n}\n\n@keyframes icon-animation-cylon {\n from {\n transform: translateX(-25%);\n }\n to {\n transform: translateX(25%);\n }\n}\n\n@keyframes icon-animation-cylon-vertical {\n from {\n transform: translateY(25%);\n }\n to {\n transform: translateY(-25%);\n }\n}\n\n@keyframes icon-animation-fade {\n from {\n opacity: 0.1;\n }\n to {\n opacity: 1;\n }\n}\n\n@keyframes icon-animation-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(359deg);\n }\n}\n\n@keyframes icon-animation-throb {\n from {\n opacity: 0.5;\n transform: scale(0.5);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n","import { Component, Element, Host, h, Prop, State, Watch } from '@stencil/core';\nimport { checkNonEmpty, checkType, checkEmptyOrType, checkEmptyOrOneOf } from '../../utils';\nimport { version } from '../../../package.json';\n\nconst CDN_URL = 'https://unpkg.com/@swisspost/design-system-icons/public/post-icons';\nconst ANIMATION_NAMES = [\n 'cylon',\n 'cylon-vertical',\n 'spin',\n 'spin-reverse',\n 'fade',\n 'throb',\n] as const;\nconst ANIMATION_KEYS = [...ANIMATION_NAMES];\n\ntype Animation = (typeof ANIMATION_NAMES)[number];\n\n/**\n * @class PostIcon - representing a stencil component\n */\n@Component({\n tag: 'post-icon',\n styleUrl: 'post-icon.scss',\n shadow: true,\n})\nexport class PostIcon {\n private path: string;\n\n @Element() host: HTMLPostIconElement;\n\n @State() svgStyles: string;\n @State() svgOutput: string;\n\n /**\n * The name of the animation.\n */\n @Prop() readonly animation?: Animation | null = null;\n\n @Watch('animation')\n validateAnimation(newValue = this.animation) {\n if (newValue !== undefined)\n checkEmptyOrOneOf(\n newValue,\n ANIMATION_KEYS,\n `The post-icon \"animation\" prop requires one of the following values: ${ANIMATION_KEYS.join(\n ', ',\n )}.`,\n );\n }\n\n /**\n * The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url.\n */\n @Prop() readonly base?: string | null = null;\n\n @Watch('base')\n validateBase(newValue = this.base) {\n checkEmptyOrType(newValue, 'string', 'The post-icon \"base\" prop should be a string.');\n }\n\n /**\n * When set to `true`, the icon will be flipped horizontally.\n */\n @Prop() readonly flipH?: boolean = false;\n\n @Watch('flipH')\n validateFlipH(newValue = this.flipH) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipH\" prop should be a boolean.');\n }\n\n /**\n * When set to `true`, the icon will be flipped vertically.\n */\n @Prop() readonly flipV?: boolean = false;\n\n @Watch('flipV')\n validateFlipV(newValue = this.flipV) {\n checkEmptyOrType(newValue, 'boolean', 'The post-icon \"flipV\" prop should be a boolean.');\n }\n\n /**\n * The name/id of the icon (e.g. 1000, 1001, ...).\n */\n @Prop() readonly name!: string;\n\n @Watch('name')\n validateName(newValue = this.name) {\n checkNonEmpty(newValue, 'The post-icon \"name\" prop is required!.');\n checkType(newValue, 'string', 'The post-icon \"name\" prop should be a string.');\n }\n\n /**\n * The number of degree for the css rotate transformation.\n */\n @Prop() readonly rotate?: number | null = null;\n\n @Watch('rotate')\n validateRotate(newValue = this.rotate) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"rotate\" prop should be a number.');\n }\n\n /**\n * The number for the css scale transformation.\n */\n @Prop() readonly scale?: number | null = null;\n\n @Watch('scale')\n validateScale(newValue = this.scale) {\n checkEmptyOrType(newValue, 'number', 'The post-icon \"scale\" prop should be a number.');\n }\n\n componentWillLoad() {\n this.validateBase();\n this.validateName();\n this.validateFlipH();\n this.validateFlipV();\n this.validateScale();\n this.validateRotate();\n this.validateAnimation();\n }\n\n componentWillRender() {\n this.setPath();\n }\n\n private setPath() {\n // Construct icon path from different possible sources\n const metaBase =\n document.head\n .querySelector('meta[name=\"design-system-settings\"][data-post-icon-base]')\n ?.getAttribute('data-post-icon-base') ?? null;\n\n const fileBase = `${this.base ?? metaBase ?? CDN_URL}/`.replace(/\\/\\/$/, '/');\n const fileName = `${this.name}.svg#icon`;\n const filePath = `${fileBase}${fileName}`;\n\n this.path = new URL(filePath, window.location.origin).toString();\n }\n\n render() {\n return (\n <Host data-version={version}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\">\n <use href={this.path} />\n </svg>\n </Host>\n );\n }\n}\n"],"version":3}
|
package/dist/docs.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"timestamp": "2023-
|
|
2
|
+
"timestamp": "2023-06-12T16:11:07",
|
|
3
3
|
"compiler": {
|
|
4
4
|
"name": "@stencil/core",
|
|
5
|
-
"version": "3.
|
|
6
|
-
"typescriptVersion": "
|
|
5
|
+
"version": "3.3.1",
|
|
6
|
+
"typescriptVersion": "5.0.4"
|
|
7
7
|
},
|
|
8
8
|
"components": [
|
|
9
9
|
{
|
|
@@ -88,14 +88,36 @@
|
|
|
88
88
|
"props": [
|
|
89
89
|
{
|
|
90
90
|
"name": "animation",
|
|
91
|
-
"type": "
|
|
91
|
+
"type": "\"cylon\" | \"cylon-vertical\" | \"fade\" | \"spin\" | \"spin-reverse\" | \"throb\"",
|
|
92
92
|
"mutable": false,
|
|
93
93
|
"attr": "animation",
|
|
94
94
|
"reflectToAttr": false,
|
|
95
|
-
"docs": "The name of the animation
|
|
95
|
+
"docs": "The name of the animation.",
|
|
96
96
|
"docsTags": [],
|
|
97
|
+
"default": "null",
|
|
97
98
|
"values": [
|
|
98
99
|
{
|
|
100
|
+
"value": "cylon",
|
|
101
|
+
"type": "string"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"value": "cylon-vertical",
|
|
105
|
+
"type": "string"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"value": "fade",
|
|
109
|
+
"type": "string"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"value": "spin",
|
|
113
|
+
"type": "string"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"value": "spin-reverse",
|
|
117
|
+
"type": "string"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"value": "throb",
|
|
99
121
|
"type": "string"
|
|
100
122
|
}
|
|
101
123
|
],
|
|
@@ -108,8 +130,9 @@
|
|
|
108
130
|
"mutable": false,
|
|
109
131
|
"attr": "base",
|
|
110
132
|
"reflectToAttr": false,
|
|
111
|
-
"docs": "The base path, where the icons are located (must be a public url).",
|
|
133
|
+
"docs": "The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url.",
|
|
112
134
|
"docsTags": [],
|
|
135
|
+
"default": "null",
|
|
113
136
|
"values": [
|
|
114
137
|
{
|
|
115
138
|
"type": "string"
|
|
@@ -126,6 +149,7 @@
|
|
|
126
149
|
"reflectToAttr": false,
|
|
127
150
|
"docs": "When set to `true`, the icon will be flipped horizontally.",
|
|
128
151
|
"docsTags": [],
|
|
152
|
+
"default": "false",
|
|
129
153
|
"values": [
|
|
130
154
|
{
|
|
131
155
|
"type": "boolean"
|
|
@@ -142,6 +166,7 @@
|
|
|
142
166
|
"reflectToAttr": false,
|
|
143
167
|
"docs": "When set to `true`, the icon will be flipped vertically.",
|
|
144
168
|
"docsTags": [],
|
|
169
|
+
"default": "false",
|
|
145
170
|
"values": [
|
|
146
171
|
{
|
|
147
172
|
"type": "boolean"
|
|
@@ -164,7 +189,7 @@
|
|
|
164
189
|
}
|
|
165
190
|
],
|
|
166
191
|
"optional": false,
|
|
167
|
-
"required":
|
|
192
|
+
"required": true
|
|
168
193
|
},
|
|
169
194
|
{
|
|
170
195
|
"name": "rotate",
|
|
@@ -172,8 +197,9 @@
|
|
|
172
197
|
"mutable": false,
|
|
173
198
|
"attr": "rotate",
|
|
174
199
|
"reflectToAttr": false,
|
|
175
|
-
"docs": "The
|
|
200
|
+
"docs": "The number of degree for the css rotate transformation.",
|
|
176
201
|
"docsTags": [],
|
|
202
|
+
"default": "null",
|
|
177
203
|
"values": [
|
|
178
204
|
{
|
|
179
205
|
"type": "number"
|
|
@@ -188,8 +214,9 @@
|
|
|
188
214
|
"mutable": false,
|
|
189
215
|
"attr": "scale",
|
|
190
216
|
"reflectToAttr": false,
|
|
191
|
-
"docs": "The
|
|
217
|
+
"docs": "The number for the css scale transformation.",
|
|
192
218
|
"docsTags": [],
|
|
219
|
+
"default": "null",
|
|
193
220
|
"values": [
|
|
194
221
|
{
|
|
195
222
|
"type": "number"
|
|
@@ -591,15 +591,16 @@ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) =>
|
|
|
591
591
|
* @param vnodes a list of virtual DOM nodes to remove
|
|
592
592
|
* @param startIdx the index at which to start removing nodes (inclusive)
|
|
593
593
|
* @param endIdx the index at which to stop removing nodes (inclusive)
|
|
594
|
-
* @param vnode a VNode
|
|
595
|
-
* @param elm an element
|
|
596
594
|
*/
|
|
597
|
-
const removeVnodes = (vnodes, startIdx, endIdx
|
|
598
|
-
for (
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
elm
|
|
595
|
+
const removeVnodes = (vnodes, startIdx, endIdx) => {
|
|
596
|
+
for (let index = startIdx; index <= endIdx; ++index) {
|
|
597
|
+
const vnode = vnodes[index];
|
|
598
|
+
if (vnode) {
|
|
599
|
+
const elm = vnode.$elm$;
|
|
600
|
+
if (elm) {
|
|
601
|
+
// remove the vnode's element from the dom
|
|
602
|
+
elm.remove();
|
|
603
|
+
}
|
|
603
604
|
}
|
|
604
605
|
}
|
|
605
606
|
};
|
|
@@ -894,23 +895,67 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
|
894
895
|
const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
|
895
896
|
return writeTask(dispatch) ;
|
|
896
897
|
};
|
|
898
|
+
/**
|
|
899
|
+
* Dispatch initial-render and update lifecycle hooks, enqueuing calls to
|
|
900
|
+
* component lifecycle methods like `componentWillLoad` as well as
|
|
901
|
+
* {@link updateComponent}, which will kick off the virtual DOM re-render.
|
|
902
|
+
*
|
|
903
|
+
* @param hostRef a reference to a host DOM node
|
|
904
|
+
* @param isInitialLoad whether we're on the initial load or not
|
|
905
|
+
* @returns an empty Promise which is used to enqueue a series of operations for
|
|
906
|
+
* the component
|
|
907
|
+
*/
|
|
897
908
|
const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
898
909
|
const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
|
899
910
|
const instance = hostRef.$lazyInstance$ ;
|
|
900
|
-
|
|
911
|
+
// We're going to use this variable together with `enqueue` to implement a
|
|
912
|
+
// little promise-based queue. We start out with it `undefined`. When we add
|
|
913
|
+
// the first function to the queue we'll set this variable to be that
|
|
914
|
+
// function's return value. When we attempt to add subsequent values to the
|
|
915
|
+
// queue we'll check that value and, if it was a `Promise`, we'll then chain
|
|
916
|
+
// the new function off of that `Promise` using `.then()`. This will give our
|
|
917
|
+
// queue two nice properties:
|
|
918
|
+
//
|
|
919
|
+
// 1. If all functions added to the queue are synchronous they'll be called
|
|
920
|
+
// synchronously right away.
|
|
921
|
+
// 2. If all functions added to the queue are asynchronous they'll all be
|
|
922
|
+
// called in order after `dispatchHooks` exits.
|
|
923
|
+
let maybePromise;
|
|
901
924
|
if (isInitialLoad) {
|
|
902
925
|
{
|
|
903
|
-
|
|
926
|
+
// If `componentWillLoad` returns a `Promise` then we want to wait on
|
|
927
|
+
// whatever's going on in that `Promise` before we launch into
|
|
928
|
+
// rendering the component, doing other lifecycle stuff, etc. So
|
|
929
|
+
// in that case we assign the returned promise to the variable we
|
|
930
|
+
// declared above to hold a possible 'queueing' Promise
|
|
931
|
+
maybePromise = safeCall(instance, 'componentWillLoad');
|
|
904
932
|
}
|
|
905
933
|
}
|
|
906
934
|
{
|
|
907
|
-
|
|
935
|
+
maybePromise = enqueue(maybePromise, () => safeCall(instance, 'componentWillRender'));
|
|
908
936
|
}
|
|
909
937
|
endSchedule();
|
|
910
|
-
return
|
|
938
|
+
return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
|
|
911
939
|
};
|
|
940
|
+
/**
|
|
941
|
+
* This function uses a Promise to implement a simple first-in, first-out queue
|
|
942
|
+
* of functions to be called.
|
|
943
|
+
*
|
|
944
|
+
* The queue is ordered on the basis of the first argument. If it's
|
|
945
|
+
* `undefined`, then nothing is on the queue yet, so the provided function can
|
|
946
|
+
* be called synchronously (although note that this function may return a
|
|
947
|
+
* `Promise`). The idea is that then the return value of that enqueueing
|
|
948
|
+
* operation is kept around, so that if it was a `Promise` then subsequent
|
|
949
|
+
* functions can be enqueued by calling this function again with that `Promise`
|
|
950
|
+
* as the first argument.
|
|
951
|
+
*
|
|
952
|
+
* @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
|
|
953
|
+
* @param fn a function to enqueue
|
|
954
|
+
* @returns either a `Promise` or the return value of the provided function
|
|
955
|
+
*/
|
|
956
|
+
const enqueue = (maybePromise, fn) => maybePromise instanceof Promise ? maybePromise.then(fn) : fn();
|
|
912
957
|
const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
913
|
-
|
|
958
|
+
var _a;
|
|
914
959
|
const elm = hostRef.$hostElement$;
|
|
915
960
|
const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
|
916
961
|
const rc = elm['s-rc'];
|
|
@@ -932,7 +977,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
932
977
|
endRender();
|
|
933
978
|
endUpdate();
|
|
934
979
|
{
|
|
935
|
-
const childrenPromises = elm['s-p'];
|
|
980
|
+
const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
|
|
936
981
|
const postUpdate = () => postUpdateComponent(hostRef);
|
|
937
982
|
if (childrenPromises.length === 0) {
|
|
938
983
|
postUpdate();
|
|
@@ -1033,9 +1078,6 @@ const safeCall = (instance, method, arg) => {
|
|
|
1033
1078
|
}
|
|
1034
1079
|
return undefined;
|
|
1035
1080
|
};
|
|
1036
|
-
const then = (promise, thenFn) => {
|
|
1037
|
-
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
1038
|
-
};
|
|
1039
1081
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
1040
1082
|
;
|
|
1041
1083
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
@@ -1196,9 +1238,9 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1196
1238
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
1197
1239
|
// initializeComponent
|
|
1198
1240
|
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
1241
|
+
// Let the runtime know that the component has been initialized
|
|
1242
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
1199
1243
|
{
|
|
1200
|
-
// we haven't initialized this element yet
|
|
1201
|
-
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
1202
1244
|
// lazy loaded components
|
|
1203
1245
|
// request the component's implementation to be
|
|
1204
1246
|
// wired up with the host element
|
|
@@ -1533,4 +1575,4 @@ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
|
1533
1575
|
|
|
1534
1576
|
export { Host as H, bootstrapLazy as b, getElement as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
|
|
1535
1577
|
|
|
1536
|
-
//# sourceMappingURL=index-
|
|
1578
|
+
//# sourceMappingURL=index-0cfe0348.js.map
|