@spectrum-web-components/icon 0.12.1 → 0.12.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/icon",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -72,7 +72,7 @@
72
72
  ],
73
73
  "dependencies": {
74
74
  "@spectrum-web-components/base": "^0.7.0",
75
- "@spectrum-web-components/iconset": "^0.7.1",
75
+ "@spectrum-web-components/iconset": "^0.7.2",
76
76
  "tslib": "^2.0.0"
77
77
  },
78
78
  "devDependencies": {
@@ -84,5 +84,5 @@
84
84
  "./sp-*.js",
85
85
  "./**/*.dev.js"
86
86
  ],
87
- "gitHead": "15588c72c774b17cfac605b20ac52a27d123bd03"
87
+ "gitHead": "31d083d1eb61a1382335030c190c85d85f41e15d"
88
88
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["Icon.ts"],
4
- "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';\n\nimport { IconBase } from './IconBase.dev.js'\n\n/**\n * @element sp-icon\n */\nexport class Icon extends IconBase {\n @property()\n public src?: string;\n\n @property()\n public name?: string;\n\n @query('#container')\n private iconContainer?: HTMLElement;\n\n private updateIconPromise?: Promise<void>;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n window.addEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override firstUpdated(): void {\n this.updateIconPromise = this.updateIcon();\n }\n\n public override attributeChangedCallback(\n name: string,\n old: string,\n value: string\n ): void {\n super.attributeChangedCallback(name, old, value);\n this.updateIconPromise = this.updateIcon(); // any of our attributes change, update our icon\n }\n\n private iconsetListener = (event: CustomEvent): void => {\n if (!this.name) {\n return;\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n if (event.detail.name === icon.iconset) {\n this.updateIconPromise = this.updateIcon();\n }\n };\n\n protected override render(): TemplateResult {\n if (this.name) {\n return html`\n <div id=\"container\"></div>\n `;\n } else if (this.src) {\n return html`\n <img src=\"${this.src}\" alt=${ifDefined(this.label)} />\n `;\n }\n return super.render();\n }\n\n private async updateIcon(): Promise<void> {\n if (this.updateIconPromise) {\n await this.updateIconPromise;\n }\n if (!this.name) {\n return Promise.resolve();\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n // try to retrieve the iconset\n const iconset = IconsetRegistry.getInstance().getIconset(icon.iconset);\n if (!iconset) {\n // we can stop here as there's nothing to be done till we get the iconset\n return Promise.resolve();\n }\n if (!this.iconContainer) {\n return Promise.resolve();\n }\n this.iconContainer.innerHTML = '';\n return iconset.applyIconToElement(\n this.iconContainer,\n icon.icon,\n this.size || '',\n this.label ? this.label : ''\n );\n }\n\n private parseIcon(icon: string): { iconset: string; icon: string } {\n const iconParts = icon.split(':');\n let iconsetName = 'default';\n let iconName = icon;\n if (iconParts.length > 1) {\n iconsetName = iconParts[0];\n iconName = iconParts[1];\n }\n return { iconset: iconsetName, icon: iconName };\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.updateIconPromise;\n return complete;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;AAYA,SAAS,YAA4B;AACrC;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,SAAS,uBAAuB;AAEhC,SAAS,gBAAgB;AAKlB,aAAM,aAAa,SAAS;AAAA,EAA5B;AAAA;AAmCH,SAAQ,kBAAkB,CAAC,UAA6B;AACpD,UAAI,CAAC,KAAK,MAAM;AACZ;AAAA,MACJ;AAEA,YAAM,OAAO,KAAK,UAAU,KAAK,IAAI;AACrC,UAAI,MAAM,OAAO,SAAS,KAAK,SAAS;AACpC,aAAK,oBAAoB,KAAK,WAAW;AAAA,MAC7C;AAAA,IACJ;AAAA;AAAA,EAhCgB,oBAA0B;AACtC,UAAM,kBAAkB;AACxB,WAAO,iBAAiB,oBAAoB,KAAK,eAAe;AAAA,EACpE;AAAA,EAEgB,uBAA6B;AACzC,UAAM,qBAAqB;AAC3B,WAAO,oBAAoB,oBAAoB,KAAK,eAAe;AAAA,EACvE;AAAA,EAEgB,eAAqB;AACjC,SAAK,oBAAoB,KAAK,WAAW;AAAA,EAC7C;AAAA,EAEgB,yBACZ,MACA,KACA,OACI;AACJ,UAAM,yBAAyB,MAAM,KAAK,KAAK;AAC/C,SAAK,oBAAoB,KAAK,WAAW;AAAA,EAC7C;AAAA,EAamB,SAAyB;AACxC,QAAI,KAAK,MAAM;AACX,aAAO;AAAA;AAAA;AAAA,IAGX,WAAW,KAAK,KAAK;AACjB,aAAO;AAAA,4BACS,KAAK,YAAY,UAAU,KAAK,KAAK;AAAA;AAAA,IAEzD;AACA,WAAO,MAAM,OAAO;AAAA,EACxB;AAAA,EAEA,MAAc,aAA4B;AACtC,QAAI,KAAK,mBAAmB;AACxB,YAAM,KAAK;AAAA,IACf;AACA,QAAI,CAAC,KAAK,MAAM;AACZ,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AAEA,UAAM,OAAO,KAAK,UAAU,KAAK,IAAI;AAErC,UAAM,UAAU,gBAAgB,YAAY,EAAE,WAAW,KAAK,OAAO;AACrE,QAAI,CAAC,SAAS;AAEV,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AACA,QAAI,CAAC,KAAK,eAAe;AACrB,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AACA,SAAK,cAAc,YAAY;AAC/B,WAAO,QAAQ;AAAA,MACX,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ,KAAK,QAAQ;AAAA,IAC9B;AAAA,EACJ;AAAA,EAEQ,UAAU,MAAiD;AAC/D,UAAM,YAAY,KAAK,MAAM,GAAG;AAChC,QAAI,cAAc;AAClB,QAAI,WAAW;AACf,QAAI,UAAU,SAAS,GAAG;AACtB,oBAAc,UAAU;AACxB,iBAAW,UAAU;AAAA,IACzB;AACA,WAAO,EAAE,SAAS,aAAa,MAAM,SAAS;AAAA,EAClD;AAAA,EAEA,MAAyB,oBAAsC;AAC3D,UAAM,WAAY,MAAM,MAAM,kBAAkB;AAChD,UAAM,KAAK;AACX,WAAO;AAAA,EACX;AACJ;AApGW;AAAA,EADN,SAAS;AAAA,GADD,KAEF;AAGA;AAAA,EADN,SAAS;AAAA,GAJD,KAKF;AAGC;AAAA,EADP,MAAM,YAAY;AAAA,GAPV,KAQD;",
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';\n\nimport { IconBase } from './IconBase.dev.js'\n\n/**\n * @element sp-icon\n */\nexport class Icon extends IconBase {\n @property()\n public src?: string;\n\n @property()\n public override name?: string;\n\n @query('#container')\n private iconContainer?: HTMLElement;\n\n private updateIconPromise?: Promise<void>;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n window.addEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override firstUpdated(): void {\n this.updateIconPromise = this.updateIcon();\n }\n\n public override attributeChangedCallback(\n name: string,\n old: string,\n value: string\n ): void {\n super.attributeChangedCallback(name, old, value);\n this.updateIconPromise = this.updateIcon(); // any of our attributes change, update our icon\n }\n\n private iconsetListener = (event: CustomEvent): void => {\n if (!this.name) {\n return;\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n if (event.detail.name === icon.iconset) {\n this.updateIconPromise = this.updateIcon();\n }\n };\n\n protected override render(): TemplateResult {\n if (this.name) {\n return html`\n <div id=\"container\"></div>\n `;\n } else if (this.src) {\n return html`\n <img src=\"${this.src}\" alt=${ifDefined(this.label)} />\n `;\n }\n return super.render();\n }\n\n private async updateIcon(): Promise<void> {\n if (this.updateIconPromise) {\n await this.updateIconPromise;\n }\n if (!this.name) {\n return Promise.resolve();\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n // try to retrieve the iconset\n const iconset = IconsetRegistry.getInstance().getIconset(icon.iconset);\n if (!iconset) {\n // we can stop here as there's nothing to be done till we get the iconset\n return Promise.resolve();\n }\n if (!this.iconContainer) {\n return Promise.resolve();\n }\n this.iconContainer.innerHTML = '';\n return iconset.applyIconToElement(\n this.iconContainer,\n icon.icon,\n this.size || '',\n this.label ? this.label : ''\n );\n }\n\n private parseIcon(icon: string): { iconset: string; icon: string } {\n const iconParts = icon.split(':');\n let iconsetName = 'default';\n let iconName = icon;\n if (iconParts.length > 1) {\n iconsetName = iconParts[0];\n iconName = iconParts[1];\n }\n return { iconset: iconsetName, icon: iconName };\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.updateIconPromise;\n return complete;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;AAYA,SAAS,YAA4B;AACrC;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,SAAS,uBAAuB;AAEhC,SAAS,gBAAgB;AAKlB,aAAM,aAAa,SAAS;AAAA,EAA5B;AAAA;AAmCH,SAAQ,kBAAkB,CAAC,UAA6B;AACpD,UAAI,CAAC,KAAK,MAAM;AACZ;AAAA,MACJ;AAEA,YAAM,OAAO,KAAK,UAAU,KAAK,IAAI;AACrC,UAAI,MAAM,OAAO,SAAS,KAAK,SAAS;AACpC,aAAK,oBAAoB,KAAK,WAAW;AAAA,MAC7C;AAAA,IACJ;AAAA;AAAA,EAhCgB,oBAA0B;AACtC,UAAM,kBAAkB;AACxB,WAAO,iBAAiB,oBAAoB,KAAK,eAAe;AAAA,EACpE;AAAA,EAEgB,uBAA6B;AACzC,UAAM,qBAAqB;AAC3B,WAAO,oBAAoB,oBAAoB,KAAK,eAAe;AAAA,EACvE;AAAA,EAEgB,eAAqB;AACjC,SAAK,oBAAoB,KAAK,WAAW;AAAA,EAC7C;AAAA,EAEgB,yBACZ,MACA,KACA,OACI;AACJ,UAAM,yBAAyB,MAAM,KAAK,KAAK;AAC/C,SAAK,oBAAoB,KAAK,WAAW;AAAA,EAC7C;AAAA,EAamB,SAAyB;AACxC,QAAI,KAAK,MAAM;AACX,aAAO;AAAA;AAAA;AAAA,IAGX,WAAW,KAAK,KAAK;AACjB,aAAO;AAAA,4BACS,KAAK,YAAY,UAAU,KAAK,KAAK;AAAA;AAAA,IAEzD;AACA,WAAO,MAAM,OAAO;AAAA,EACxB;AAAA,EAEA,MAAc,aAA4B;AACtC,QAAI,KAAK,mBAAmB;AACxB,YAAM,KAAK;AAAA,IACf;AACA,QAAI,CAAC,KAAK,MAAM;AACZ,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AAEA,UAAM,OAAO,KAAK,UAAU,KAAK,IAAI;AAErC,UAAM,UAAU,gBAAgB,YAAY,EAAE,WAAW,KAAK,OAAO;AACrE,QAAI,CAAC,SAAS;AAEV,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AACA,QAAI,CAAC,KAAK,eAAe;AACrB,aAAO,QAAQ,QAAQ;AAAA,IAC3B;AACA,SAAK,cAAc,YAAY;AAC/B,WAAO,QAAQ;AAAA,MACX,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ,KAAK,QAAQ;AAAA,IAC9B;AAAA,EACJ;AAAA,EAEQ,UAAU,MAAiD;AAC/D,UAAM,YAAY,KAAK,MAAM,GAAG;AAChC,QAAI,cAAc;AAClB,QAAI,WAAW;AACf,QAAI,UAAU,SAAS,GAAG;AACtB,oBAAc,UAAU;AACxB,iBAAW,UAAU;AAAA,IACzB;AACA,WAAO,EAAE,SAAS,aAAa,MAAM,SAAS;AAAA,EAClD;AAAA,EAEA,MAAyB,oBAAsC;AAC3D,UAAM,WAAY,MAAM,MAAM,kBAAkB;AAChD,UAAM,KAAK;AACX,WAAO;AAAA,EACX;AACJ;AApGW;AAAA,EADN,SAAS;AAAA,GADD,KAEF;AAGS;AAAA,EADf,SAAS;AAAA,GAJD,KAKO;AAGR;AAAA,EADP,MAAM,YAAY;AAAA,GAPV,KAQD;",
6
6
  "names": []
7
7
  }
package/src/Icon.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["Icon.ts"],
4
- "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';\n\nimport { IconBase } from './IconBase.js';\n\n/**\n * @element sp-icon\n */\nexport class Icon extends IconBase {\n @property()\n public src?: string;\n\n @property()\n public name?: string;\n\n @query('#container')\n private iconContainer?: HTMLElement;\n\n private updateIconPromise?: Promise<void>;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n window.addEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override firstUpdated(): void {\n this.updateIconPromise = this.updateIcon();\n }\n\n public override attributeChangedCallback(\n name: string,\n old: string,\n value: string\n ): void {\n super.attributeChangedCallback(name, old, value);\n this.updateIconPromise = this.updateIcon(); // any of our attributes change, update our icon\n }\n\n private iconsetListener = (event: CustomEvent): void => {\n if (!this.name) {\n return;\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n if (event.detail.name === icon.iconset) {\n this.updateIconPromise = this.updateIcon();\n }\n };\n\n protected override render(): TemplateResult {\n if (this.name) {\n return html`\n <div id=\"container\"></div>\n `;\n } else if (this.src) {\n return html`\n <img src=\"${this.src}\" alt=${ifDefined(this.label)} />\n `;\n }\n return super.render();\n }\n\n private async updateIcon(): Promise<void> {\n if (this.updateIconPromise) {\n await this.updateIconPromise;\n }\n if (!this.name) {\n return Promise.resolve();\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n // try to retrieve the iconset\n const iconset = IconsetRegistry.getInstance().getIconset(icon.iconset);\n if (!iconset) {\n // we can stop here as there's nothing to be done till we get the iconset\n return Promise.resolve();\n }\n if (!this.iconContainer) {\n return Promise.resolve();\n }\n this.iconContainer.innerHTML = '';\n return iconset.applyIconToElement(\n this.iconContainer,\n icon.icon,\n this.size || '',\n this.label ? this.label : ''\n );\n }\n\n private parseIcon(icon: string): { iconset: string; icon: string } {\n const iconParts = icon.split(':');\n let iconsetName = 'default';\n let iconName = icon;\n if (iconParts.length > 1) {\n iconsetName = iconParts[0];\n iconName = iconParts[1];\n }\n return { iconset: iconsetName, icon: iconName };\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.updateIconPromise;\n return complete;\n }\n}\n"],
5
- "mappings": "qNAYA,OAAS,QAAAA,MAA4B,gCACrC,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,OAAS,aAAAC,MAAiB,kDAE1B,OAAS,mBAAAC,MAAuB,2DAEhC,OAAS,YAAAC,MAAgB,gBAKlB,aAAM,aAAaA,CAAS,CAA5B,kCAmCH,KAAQ,gBAAmBC,GAA6B,CACpD,GAAI,CAAC,KAAK,KACN,OAGJ,MAAMC,EAAO,KAAK,UAAU,KAAK,IAAI,EACjCD,EAAM,OAAO,OAASC,EAAK,UAC3B,KAAK,kBAAoB,KAAK,WAAW,EAEjD,EAhCgB,mBAA0B,CACtC,MAAM,kBAAkB,EACxB,OAAO,iBAAiB,mBAAoB,KAAK,eAAe,CACpE,CAEgB,sBAA6B,CACzC,MAAM,qBAAqB,EAC3B,OAAO,oBAAoB,mBAAoB,KAAK,eAAe,CACvE,CAEgB,cAAqB,CACjC,KAAK,kBAAoB,KAAK,WAAW,CAC7C,CAEgB,yBACZC,EACAC,EACAC,EACI,CACJ,MAAM,yBAAyBF,EAAMC,EAAKC,CAAK,EAC/C,KAAK,kBAAoB,KAAK,WAAW,CAC7C,CAamB,QAAyB,CACxC,OAAI,KAAK,KACEV;AAAA;AAAA,cAGA,KAAK,IACLA;AAAA,4BACS,KAAK,YAAYG,EAAU,KAAK,KAAK;AAAA,cAGlD,MAAM,OAAO,CACxB,CAEA,MAAc,YAA4B,CAItC,GAHI,KAAK,mBACL,MAAM,KAAK,kBAEX,CAAC,KAAK,KACN,OAAO,QAAQ,QAAQ,EAG3B,MAAMI,EAAO,KAAK,UAAU,KAAK,IAAI,EAE/BI,EAAUP,EAAgB,YAAY,EAAE,WAAWG,EAAK,OAAO,EAKrE,MAJI,CAACI,GAID,CAAC,KAAK,cACC,QAAQ,QAAQ,GAE3B,KAAK,cAAc,UAAY,GACxBA,EAAQ,mBACX,KAAK,cACLJ,EAAK,KACL,KAAK,MAAQ,GACb,KAAK,MAAQ,KAAK,MAAQ,EAC9B,EACJ,CAEQ,UAAUA,EAAiD,CAC/D,MAAMK,EAAYL,EAAK,MAAM,GAAG,EAChC,IAAIM,EAAc,UACdC,EAAWP,EACf,OAAIK,EAAU,OAAS,IACnBC,EAAcD,EAAU,GACxBE,EAAWF,EAAU,IAElB,CAAE,QAASC,EAAa,KAAMC,CAAS,CAClD,CAEA,MAAyB,mBAAsC,CAC3D,MAAMC,EAAY,MAAM,MAAM,kBAAkB,EAChD,aAAM,KAAK,kBACJA,CACX,CACJ,CApGWC,EAAA,CADNf,EAAS,GADD,KAEF,mBAGAe,EAAA,CADNf,EAAS,GAJD,KAKF,oBAGCe,EAAA,CADPd,EAAM,YAAY,GAPV,KAQD",
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';\n\nimport { IconBase } from './IconBase.js';\n\n/**\n * @element sp-icon\n */\nexport class Icon extends IconBase {\n @property()\n public src?: string;\n\n @property()\n public override name?: string;\n\n @query('#container')\n private iconContainer?: HTMLElement;\n\n private updateIconPromise?: Promise<void>;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n window.addEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-added', this.iconsetListener);\n }\n\n public override firstUpdated(): void {\n this.updateIconPromise = this.updateIcon();\n }\n\n public override attributeChangedCallback(\n name: string,\n old: string,\n value: string\n ): void {\n super.attributeChangedCallback(name, old, value);\n this.updateIconPromise = this.updateIcon(); // any of our attributes change, update our icon\n }\n\n private iconsetListener = (event: CustomEvent): void => {\n if (!this.name) {\n return;\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n if (event.detail.name === icon.iconset) {\n this.updateIconPromise = this.updateIcon();\n }\n };\n\n protected override render(): TemplateResult {\n if (this.name) {\n return html`\n <div id=\"container\"></div>\n `;\n } else if (this.src) {\n return html`\n <img src=\"${this.src}\" alt=${ifDefined(this.label)} />\n `;\n }\n return super.render();\n }\n\n private async updateIcon(): Promise<void> {\n if (this.updateIconPromise) {\n await this.updateIconPromise;\n }\n if (!this.name) {\n return Promise.resolve();\n }\n // parse the icon name to get iconset name\n const icon = this.parseIcon(this.name);\n // try to retrieve the iconset\n const iconset = IconsetRegistry.getInstance().getIconset(icon.iconset);\n if (!iconset) {\n // we can stop here as there's nothing to be done till we get the iconset\n return Promise.resolve();\n }\n if (!this.iconContainer) {\n return Promise.resolve();\n }\n this.iconContainer.innerHTML = '';\n return iconset.applyIconToElement(\n this.iconContainer,\n icon.icon,\n this.size || '',\n this.label ? this.label : ''\n );\n }\n\n private parseIcon(icon: string): { iconset: string; icon: string } {\n const iconParts = icon.split(':');\n let iconsetName = 'default';\n let iconName = icon;\n if (iconParts.length > 1) {\n iconsetName = iconParts[0];\n iconName = iconParts[1];\n }\n return { iconset: iconsetName, icon: iconName };\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.updateIconPromise;\n return complete;\n }\n}\n"],
5
+ "mappings": "qNAYA,OAAS,QAAAA,MAA4B,gCACrC,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,OAAS,aAAAC,MAAiB,kDAE1B,OAAS,mBAAAC,MAAuB,2DAEhC,OAAS,YAAAC,MAAgB,gBAKlB,aAAM,aAAaA,CAAS,CAA5B,kCAmCH,KAAQ,gBAAmBC,GAA6B,CACpD,GAAI,CAAC,KAAK,KACN,OAGJ,MAAMC,EAAO,KAAK,UAAU,KAAK,IAAI,EACjCD,EAAM,OAAO,OAASC,EAAK,UAC3B,KAAK,kBAAoB,KAAK,WAAW,EAEjD,EAhCgB,mBAA0B,CACtC,MAAM,kBAAkB,EACxB,OAAO,iBAAiB,mBAAoB,KAAK,eAAe,CACpE,CAEgB,sBAA6B,CACzC,MAAM,qBAAqB,EAC3B,OAAO,oBAAoB,mBAAoB,KAAK,eAAe,CACvE,CAEgB,cAAqB,CACjC,KAAK,kBAAoB,KAAK,WAAW,CAC7C,CAEgB,yBACZC,EACAC,EACAC,EACI,CACJ,MAAM,yBAAyBF,EAAMC,EAAKC,CAAK,EAC/C,KAAK,kBAAoB,KAAK,WAAW,CAC7C,CAamB,QAAyB,CACxC,OAAI,KAAK,KACEV;AAAA;AAAA,cAGA,KAAK,IACLA;AAAA,4BACS,KAAK,YAAYG,EAAU,KAAK,KAAK;AAAA,cAGlD,MAAM,OAAO,CACxB,CAEA,MAAc,YAA4B,CAItC,GAHI,KAAK,mBACL,MAAM,KAAK,kBAEX,CAAC,KAAK,KACN,OAAO,QAAQ,QAAQ,EAG3B,MAAMI,EAAO,KAAK,UAAU,KAAK,IAAI,EAE/BI,EAAUP,EAAgB,YAAY,EAAE,WAAWG,EAAK,OAAO,EAKrE,MAJI,CAACI,GAID,CAAC,KAAK,cACC,QAAQ,QAAQ,GAE3B,KAAK,cAAc,UAAY,GACxBA,EAAQ,mBACX,KAAK,cACLJ,EAAK,KACL,KAAK,MAAQ,GACb,KAAK,MAAQ,KAAK,MAAQ,EAC9B,EACJ,CAEQ,UAAUA,EAAiD,CAC/D,MAAMK,EAAYL,EAAK,MAAM,GAAG,EAChC,IAAIM,EAAc,UACdC,EAAWP,EACf,OAAIK,EAAU,OAAS,IACnBC,EAAcD,EAAU,GACxBE,EAAWF,EAAU,IAElB,CAAE,QAASC,EAAa,KAAMC,CAAS,CAClD,CAEA,MAAyB,mBAAsC,CAC3D,MAAMC,EAAY,MAAM,MAAM,kBAAkB,EAChD,aAAM,KAAK,kBACJA,CACX,CACJ,CApGWC,EAAA,CADNf,EAAS,GADD,KAEF,mBAGSe,EAAA,CADff,EAAS,GAJD,KAKO,oBAGRe,EAAA,CADPd,EAAM,YAAY,GAPV,KAQD",
6
6
  "names": ["html", "property", "query", "ifDefined", "IconsetRegistry", "IconBase", "event", "icon", "name", "old", "value", "iconset", "iconParts", "iconsetName", "iconName", "complete", "__decorateClass"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["icon.test-vrt.ts"],
4
- "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/icon.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('IconStories', stories);\n"],
5
- "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAE/B,eAAe,eAAe,OAAO;",
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/icon.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('IconStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,eAAe,OAA+B;",
6
6
  "names": []
7
7
  }