@spectrum-web-components/iconset 0.6.6 → 0.6.9-devmode.24

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/iconset",
3
- "version": "0.6.6",
3
+ "version": "0.6.9-devmode.24+07474d44f",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -19,9 +19,27 @@
19
19
  "main": "./src/index.js",
20
20
  "module": "./src/index.js",
21
21
  "exports": {
22
- ".": "./src/index.js",
23
- "./src/*": "./src/*",
24
- "./package.json": "./package.json"
22
+ ".": {
23
+ "development": "./src/index.dev.js",
24
+ "default": "./src/index.js"
25
+ },
26
+ "./package.json": "./package.json",
27
+ "./src/iconset-registry.js": {
28
+ "development": "./src/iconset-registry.dev.js",
29
+ "default": "./src/iconset-registry.js"
30
+ },
31
+ "./src/iconset-svg.js": {
32
+ "development": "./src/iconset-svg.dev.js",
33
+ "default": "./src/iconset-svg.js"
34
+ },
35
+ "./src/iconset.js": {
36
+ "development": "./src/iconset.dev.js",
37
+ "default": "./src/iconset.js"
38
+ },
39
+ "./src/index.js": {
40
+ "development": "./src/index.dev.js",
41
+ "default": "./src/index.js"
42
+ }
25
43
  },
26
44
  "scripts": {
27
45
  "test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
@@ -41,7 +59,7 @@
41
59
  "lit-html"
42
60
  ],
43
61
  "dependencies": {
44
- "@spectrum-web-components/base": "^0.5.6",
62
+ "@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
45
63
  "tslib": "^2.0.0"
46
64
  },
47
65
  "types": "./src/index.d.ts",
@@ -50,5 +68,5 @@
50
68
  "./src/index.js",
51
69
  "./stories/icons-demo.js"
52
70
  ],
53
- "gitHead": "32e049a0da090ffc1a54cfe3234be4d5efc73339"
71
+ "gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
54
72
  }
@@ -0,0 +1,33 @@
1
+ export class IconsetRegistry {
2
+ constructor() {
3
+ this.iconsetMap = /* @__PURE__ */ new Map();
4
+ }
5
+ static getInstance() {
6
+ if (!IconsetRegistry.instance) {
7
+ IconsetRegistry.instance = new IconsetRegistry();
8
+ }
9
+ return IconsetRegistry.instance;
10
+ }
11
+ addIconset(name, iconset) {
12
+ this.iconsetMap.set(name, iconset);
13
+ const event = new CustomEvent("sp-iconset-added", {
14
+ bubbles: true,
15
+ composed: true,
16
+ detail: { name, iconset }
17
+ });
18
+ setTimeout(() => window.dispatchEvent(event), 0);
19
+ }
20
+ removeIconset(name) {
21
+ this.iconsetMap.delete(name);
22
+ const event = new CustomEvent("sp-iconset-removed", {
23
+ bubbles: true,
24
+ composed: true,
25
+ detail: { name }
26
+ });
27
+ setTimeout(() => window.dispatchEvent(event), 0);
28
+ }
29
+ getIconset(name) {
30
+ return this.iconsetMap.get(name);
31
+ }
32
+ }
33
+ //# sourceMappingURL=iconset-registry.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["iconset-registry.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*/\nimport { Iconset } from './iconset.dev.js'\nexport interface IconsetAddedDetail {\n name: string;\n iconset: Iconset;\n}\nexport interface IconsetRemovedDetail {\n name: string;\n}\n\nexport class IconsetRegistry {\n // singleton getter\n public static getInstance(): IconsetRegistry {\n if (!IconsetRegistry.instance) {\n IconsetRegistry.instance = new IconsetRegistry();\n }\n return IconsetRegistry.instance;\n }\n private static instance: IconsetRegistry;\n\n private iconsetMap = new Map<string, Iconset>();\n\n public addIconset(name: string, iconset: Iconset): void {\n this.iconsetMap.set(name, iconset);\n\n // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-added', {\n bubbles: true,\n composed: true,\n detail: { name, iconset },\n });\n // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event\n // listeners caused by connection to the dom and first render to complete, this way any icons listening for\n // this iconset will be able to access the completed iconset\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public removeIconset(name: string): void {\n this.iconsetMap.delete(name);\n // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-removed', {\n bubbles: true,\n composed: true,\n detail: { name },\n });\n // we're dispatching this event in the next tick To keep the event model consistent with the added event\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public getIconset(name: string): Iconset | undefined {\n return this.iconsetMap.get(name);\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-iconset-added': CustomEvent<IconsetAddedDetail>;\n 'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;\n }\n}\n"],
5
+ "mappings": "AAoBO,aAAM,gBAAgB;AAAA,EAAtB;AAUK,sBAAa,oBAAI,IAAqB;AAAA;AAAA,SARhC,cAA+B;AACzC,QAAI,CAAC,gBAAgB,UAAU;AAC3B,sBAAgB,WAAW,IAAI,gBAAgB;AAAA,IACnD;AACA,WAAO,gBAAgB;AAAA,EAC3B;AAAA,EAKO,WAAW,MAAc,SAAwB;AACpD,SAAK,WAAW,IAAI,MAAM,OAAO;AAKjC,UAAM,QAAQ,IAAI,YAAY,oBAAoB;AAAA,MAC9C,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAID,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,cAAc,MAAoB;AACrC,SAAK,WAAW,OAAO,IAAI;AAI3B,UAAM,QAAQ,IAAI,YAAY,sBAAsB;AAAA,MAChD,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,KAAK;AAAA,IACnB,CAAC;AAED,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,WAAW,MAAmC;AACjD,WAAO,KAAK,WAAW,IAAI,IAAI;AAAA,EACnC;AACJ;",
6
+ "names": []
7
+ }
@@ -1,44 +1,33 @@
1
1
  export class IconsetRegistry {
2
- constructor() {
3
- this.iconsetMap = new Map();
4
- }
5
- // singleton getter
6
- static getInstance() {
7
- if (!IconsetRegistry.instance) {
8
- IconsetRegistry.instance = new IconsetRegistry();
9
- }
10
- return IconsetRegistry.instance;
11
- }
12
- addIconset(name, iconset) {
13
- this.iconsetMap.set(name, iconset);
14
- // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset
15
- // note we're using window here for efficiency since we don't need to bubble through the dom since everyone
16
- // will know where to look for this event
17
- const event = new CustomEvent('sp-iconset-added', {
18
- bubbles: true,
19
- composed: true,
20
- detail: { name, iconset },
21
- });
22
- // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event
23
- // listeners caused by connection to the dom and first render to complete, this way any icons listening for
24
- // this iconset will be able to access the completed iconset
25
- setTimeout(() => window.dispatchEvent(event), 0);
26
- }
27
- removeIconset(name) {
28
- this.iconsetMap.delete(name);
29
- // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset
30
- // note we're using window here for efficiency since we don't need to bubble through the dom since everyone
31
- // will know where to look for this event
32
- const event = new CustomEvent('sp-iconset-removed', {
33
- bubbles: true,
34
- composed: true,
35
- detail: { name },
36
- });
37
- // we're dispatching this event in the next tick To keep the event model consistent with the added event
38
- setTimeout(() => window.dispatchEvent(event), 0);
39
- }
40
- getIconset(name) {
41
- return this.iconsetMap.get(name);
2
+ constructor() {
3
+ this.iconsetMap = /* @__PURE__ */ new Map();
4
+ }
5
+ static getInstance() {
6
+ if (!IconsetRegistry.instance) {
7
+ IconsetRegistry.instance = new IconsetRegistry();
42
8
  }
9
+ return IconsetRegistry.instance;
10
+ }
11
+ addIconset(name, iconset) {
12
+ this.iconsetMap.set(name, iconset);
13
+ const event = new CustomEvent("sp-iconset-added", {
14
+ bubbles: true,
15
+ composed: true,
16
+ detail: { name, iconset }
17
+ });
18
+ setTimeout(() => window.dispatchEvent(event), 0);
19
+ }
20
+ removeIconset(name) {
21
+ this.iconsetMap.delete(name);
22
+ const event = new CustomEvent("sp-iconset-removed", {
23
+ bubbles: true,
24
+ composed: true,
25
+ detail: { name }
26
+ });
27
+ setTimeout(() => window.dispatchEvent(event), 0);
28
+ }
29
+ getIconset(name) {
30
+ return this.iconsetMap.get(name);
31
+ }
43
32
  }
44
- //# sourceMappingURL=iconset-registry.js.map
33
+ //# sourceMappingURL=iconset-registry.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"iconset-registry.js","sourceRoot":"","sources":["iconset-registry.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,eAAe;IAA5B;QAUY,eAAU,GAAG,IAAI,GAAG,EAAmB,CAAC;IAkCpD,CAAC;IA3CG,mBAAmB;IACZ,MAAM,CAAC,WAAW;QACrB,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;YAC3B,eAAe,CAAC,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;SACpD;QACD,OAAO,eAAe,CAAC,QAAQ,CAAC;IACpC,CAAC;IAKM,UAAU,CAAC,IAAY,EAAE,OAAgB;QAC5C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEnC,yFAAyF;QACzF,2GAA2G;QAC3G,yCAAyC;QACzC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,kBAAkB,EAAE;YAC9C,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SAC5B,CAAC,CAAC;QACH,6GAA6G;QAC7G,2GAA2G;QAC3G,4DAA4D;QAC5D,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IACM,aAAa,CAAC,IAAY;QAC7B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,2FAA2F;QAC3F,2GAA2G;QAC3G,yCAAyC;QACzC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,oBAAoB,EAAE;YAChD,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,EAAE,IAAI,EAAE;SACnB,CAAC,CAAC;QACH,wGAAwG;QACxG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IACM,UAAU,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ","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*/\nimport { Iconset } from './iconset.js';\nexport interface IconsetAddedDetail {\n name: string;\n iconset: Iconset;\n}\nexport interface IconsetRemovedDetail {\n name: string;\n}\n\nexport class IconsetRegistry {\n // singleton getter\n public static getInstance(): IconsetRegistry {\n if (!IconsetRegistry.instance) {\n IconsetRegistry.instance = new IconsetRegistry();\n }\n return IconsetRegistry.instance;\n }\n private static instance: IconsetRegistry;\n\n private iconsetMap = new Map<string, Iconset>();\n\n public addIconset(name: string, iconset: Iconset): void {\n this.iconsetMap.set(name, iconset);\n\n // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-added', {\n bubbles: true,\n composed: true,\n detail: { name, iconset },\n });\n // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event\n // listeners caused by connection to the dom and first render to complete, this way any icons listening for\n // this iconset will be able to access the completed iconset\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public removeIconset(name: string): void {\n this.iconsetMap.delete(name);\n // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-removed', {\n bubbles: true,\n composed: true,\n detail: { name },\n });\n // we're dispatching this event in the next tick To keep the event model consistent with the added event\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public getIconset(name: string): Iconset | undefined {\n return this.iconsetMap.get(name);\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-iconset-added': CustomEvent<IconsetAddedDetail>;\n 'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;\n }\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["iconset-registry.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*/\nimport { Iconset } from './iconset.js';\nexport interface IconsetAddedDetail {\n name: string;\n iconset: Iconset;\n}\nexport interface IconsetRemovedDetail {\n name: string;\n}\n\nexport class IconsetRegistry {\n // singleton getter\n public static getInstance(): IconsetRegistry {\n if (!IconsetRegistry.instance) {\n IconsetRegistry.instance = new IconsetRegistry();\n }\n return IconsetRegistry.instance;\n }\n private static instance: IconsetRegistry;\n\n private iconsetMap = new Map<string, Iconset>();\n\n public addIconset(name: string, iconset: Iconset): void {\n this.iconsetMap.set(name, iconset);\n\n // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-added', {\n bubbles: true,\n composed: true,\n detail: { name, iconset },\n });\n // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event\n // listeners caused by connection to the dom and first render to complete, this way any icons listening for\n // this iconset will be able to access the completed iconset\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public removeIconset(name: string): void {\n this.iconsetMap.delete(name);\n // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-removed', {\n bubbles: true,\n composed: true,\n detail: { name },\n });\n // we're dispatching this event in the next tick To keep the event model consistent with the added event\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public getIconset(name: string): Iconset | undefined {\n return this.iconsetMap.get(name);\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-iconset-added': CustomEvent<IconsetAddedDetail>;\n 'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;\n }\n}\n"],
5
+ "mappings": "AAoBO,aAAM,gBAAgB;AAAA,EAAtB;AAUK,sBAAa,oBAAI,IAAqB;AAAA;AAAA,SARhC,cAA+B;AACzC,QAAI,CAAC,gBAAgB,UAAU;AAC3B,sBAAgB,WAAW,IAAI,gBAAgB;AAAA,IACnD;AACA,WAAO,gBAAgB;AAAA,EAC3B;AAAA,EAKO,WAAW,MAAc,SAAwB;AACpD,SAAK,WAAW,IAAI,MAAM,OAAO;AAKjC,UAAM,QAAQ,IAAI,YAAY,oBAAoB;AAAA,MAC9C,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAID,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,cAAc,MAAoB;AACrC,SAAK,WAAW,OAAO,IAAI;AAI3B,UAAM,QAAQ,IAAI,YAAY,sBAAsB;AAAA,MAChD,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,KAAK;AAAA,IACnB,CAAC;AAED,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,WAAW,MAAmC;AACjD,WAAO,KAAK,WAAW,IAAI,IAAI;AAAA,EACnC;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,108 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ html
14
+ } from "@spectrum-web-components/base";
15
+ import { query } from "@spectrum-web-components/base/src/decorators.js";
16
+ import { Iconset } from "./iconset.dev.js";
17
+ export class IconsetSVG extends Iconset {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.iconMap = /* @__PURE__ */ new Map();
21
+ }
22
+ updated(changedProperties) {
23
+ if (!this.slotContainer) {
24
+ return;
25
+ }
26
+ const currentSVGNodes = this.getSVGNodes(this.slotContainer);
27
+ this.updateSVG(currentSVGNodes);
28
+ super.updated(changedProperties);
29
+ }
30
+ async applyIconToElement(el, icon, _size, label) {
31
+ await this.updateComplete;
32
+ const iconSymbol = this.iconMap.get(icon);
33
+ if (!iconSymbol) {
34
+ throw new Error(`Unable to find icon ${icon}`);
35
+ }
36
+ const clonedNode = this.prepareSvgClone(iconSymbol);
37
+ clonedNode.setAttribute("role", "img");
38
+ if (label) {
39
+ clonedNode.setAttribute("aria-label", label);
40
+ } else {
41
+ clonedNode.setAttribute("aria-hidden", "true");
42
+ }
43
+ if (el.shadowRoot) {
44
+ el.shadowRoot.appendChild(clonedNode);
45
+ } else {
46
+ el.appendChild(clonedNode);
47
+ }
48
+ }
49
+ getIconList() {
50
+ return [...this.iconMap.keys()];
51
+ }
52
+ prepareSvgClone(sourceSvg) {
53
+ const content = sourceSvg.cloneNode(true);
54
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
55
+ const viewBox = content.getAttribute("viewBox") || "";
56
+ const cssText = "pointer-events: none; display: block; width: 100%; height: 100%;";
57
+ svg.style.cssText = cssText;
58
+ svg.setAttribute("viewBox", viewBox);
59
+ svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
60
+ svg.setAttribute("focusable", "false");
61
+ while (content.childNodes.length > 0) {
62
+ svg.appendChild(content.childNodes[0]);
63
+ }
64
+ return svg;
65
+ }
66
+ getSVGIconName(icon) {
67
+ return icon;
68
+ }
69
+ getSanitizedIconName(icon) {
70
+ return icon;
71
+ }
72
+ renderDefaultContent() {
73
+ return html``;
74
+ }
75
+ render() {
76
+ return html`
77
+ <slot @slotchange=${this.onSlotChange}>
78
+ ${this.renderDefaultContent()}
79
+ </slot>
80
+ `;
81
+ }
82
+ updateSVG(nodes) {
83
+ const symbols = nodes.reduce((prev, svgNode) => {
84
+ const containedSymbols = svgNode.querySelectorAll("symbol");
85
+ prev.push(...containedSymbols);
86
+ return prev;
87
+ }, []);
88
+ symbols.forEach((symbol) => {
89
+ this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);
90
+ });
91
+ }
92
+ getSVGNodes(slotTarget) {
93
+ const nodes = slotTarget.assignedNodes({ flatten: true });
94
+ const svgNodes = nodes.filter((node) => {
95
+ return node.nodeName === "svg";
96
+ });
97
+ return svgNodes;
98
+ }
99
+ onSlotChange(event) {
100
+ const slotTarget = event.target;
101
+ const svgNodes = this.getSVGNodes(slotTarget);
102
+ this.updateSVG(svgNodes);
103
+ }
104
+ }
105
+ __decorateClass([
106
+ query("slot")
107
+ ], IconsetSVG.prototype, "slotContainer", 2);
108
+ //# sourceMappingURL=iconset-svg.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["iconset-svg.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 {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { query } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Iconset } from './iconset.dev.js'\n\nexport abstract class IconsetSVG extends Iconset {\n private iconMap: Map<string, SVGSymbolElement> = new Map();\n\n @query('slot')\n private slotContainer?: HTMLSlotElement;\n\n /**\n * First updated handler just ensures we've processed any slotted symbols\n */\n public override updated(changedProperties: PropertyValues): void {\n if (!this.slotContainer) {\n return;\n }\n const currentSVGNodes = this.getSVGNodes(this.slotContainer);\n this.updateSVG(currentSVGNodes);\n super.updated(changedProperties);\n }\n /**\n * Applies the requested icon from this iconset instance to the given element.\n *\n * @param el - the element to apply the icon to\n * @param icon - the name of the icon within this set to apply.\n */\n public async applyIconToElement(\n el: HTMLElement,\n icon: string,\n _size: string,\n label: string\n ): Promise<void> {\n await this.updateComplete;\n const iconSymbol = this.iconMap.get(icon);\n if (!iconSymbol) {\n throw new Error(`Unable to find icon ${icon}`);\n }\n // we cannot share a single SVG globally across shadowroot boundaries\n // so copy the template node so we can inject it where we need it\n const clonedNode = this.prepareSvgClone(iconSymbol);\n clonedNode.setAttribute('role', 'img');\n if (label) {\n clonedNode.setAttribute('aria-label', label);\n } else {\n clonedNode.setAttribute('aria-hidden', 'true');\n }\n // append the svg to the node either in its shadowroot or directly into its dom\n if (el.shadowRoot) {\n el.shadowRoot.appendChild(clonedNode);\n } else {\n el.appendChild(clonedNode);\n }\n }\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public getIconList(): string[] {\n return [...this.iconMap.keys()];\n }\n\n protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement {\n const content = sourceSvg.cloneNode(true) as SVGSymbolElement;\n // we're going to create a new svg element that will have our symbol geometry inside\n const svg = document.createElementNS(\n 'http://www.w3.org/2000/svg',\n 'svg'\n );\n const viewBox = content.getAttribute('viewBox') || '';\n // inline style isn't ideal but will work in all cases and means our icons don't need to know\n // if they are svg or spritesheet provided\n const cssText =\n 'pointer-events: none; display: block; width: 100%; height: 100%;';\n svg.style.cssText = cssText;\n // copy the viewbox and other properties into the svg\n svg.setAttribute('viewBox', viewBox);\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false');\n // move all the child nodes over to the svg\n while (content.childNodes.length > 0) {\n svg.appendChild(content.childNodes[0]);\n }\n return svg;\n }\n protected getSVGIconName(icon: string): string {\n return icon;\n }\n protected getSanitizedIconName(icon: string): string {\n return icon;\n }\n protected renderDefaultContent(): TemplateResult {\n return html``;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}>\n ${this.renderDefaultContent()}\n </slot>\n `;\n }\n\n protected updateSVG(nodes: SVGElement[]): void {\n // iterate over the nodes that were passed in, and find all the top level symbols\n const symbols = nodes.reduce((prev, svgNode) => {\n const containedSymbols = svgNode.querySelectorAll('symbol');\n prev.push(...containedSymbols);\n return prev;\n }, [] as SVGSymbolElement[]);\n symbols.forEach((symbol) => {\n this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);\n });\n }\n\n protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[] {\n const nodes = slotTarget.assignedNodes({ flatten: true });\n // find all the svg nodes\n const svgNodes = nodes.filter((node) => {\n return node.nodeName === 'svg';\n }) as SVGElement[];\n return svgNodes;\n }\n\n private onSlotChange(event: Event): void {\n const slotTarget = event.target as HTMLSlotElement;\n const svgNodes = this.getSVGNodes(slotTarget);\n this.updateSVG(svgNodes);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAKA;AAEA;AAEO,aAAe,mBAAmB,QAAQ;AAAA,EAA1C;AAAA;AACK,mBAAyC,oBAAI,IAAI;AAAA;AAAA,EAQzC,QAAQ,mBAAyC;AAC7D,QAAI,CAAC,KAAK,eAAe;AACrB;AAAA,IACJ;AACA,UAAM,kBAAkB,KAAK,YAAY,KAAK,aAAa;AAC3D,SAAK,UAAU,eAAe;AAC9B,UAAM,QAAQ,iBAAiB;AAAA,EACnC;AAAA,QAOa,mBACT,IACA,MACA,OACA,OACa;AACb,UAAM,KAAK;AACX,UAAM,aAAa,KAAK,QAAQ,IAAI,IAAI;AACxC,QAAI,CAAC,YAAY;AACb,YAAM,IAAI,MAAM,uBAAuB,MAAM;AAAA,IACjD;AAGA,UAAM,aAAa,KAAK,gBAAgB,UAAU;AAClD,eAAW,aAAa,QAAQ,KAAK;AACrC,QAAI,OAAO;AACP,iBAAW,aAAa,cAAc,KAAK;AAAA,IAC/C,OAAO;AACH,iBAAW,aAAa,eAAe,MAAM;AAAA,IACjD;AAEA,QAAI,GAAG,YAAY;AACf,SAAG,WAAW,YAAY,UAAU;AAAA,IACxC,OAAO;AACH,SAAG,YAAY,UAAU;AAA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AACD,WAAO;AAAA,EACX;AAAA,EAEQ,aAAa,OAAoB;AACrC,UAAM,aAAa,MAAM;AACzB,UAAM,WAAW,KAAK,YAAY,UAAU;AAC5C,SAAK,UAAU,QAAQ;AAAA,EAC3B;AACJ;AAzHY;AAAA,EADR,AAAC,MAAM,MAAM;AAAA,GACL,AAJL,WAIK;",
6
+ "names": []
7
+ }
@@ -1,131 +1,108 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { __decorate } from "tslib";
13
- import { html, } from '@spectrum-web-components/base';
14
- import { query } from '@spectrum-web-components/base/src/decorators.js';
15
- import { Iconset } from './iconset.js';
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ html
14
+ } from "@spectrum-web-components/base";
15
+ import { query } from "@spectrum-web-components/base/src/decorators.js";
16
+ import { Iconset } from "./iconset.js";
16
17
  export class IconsetSVG extends Iconset {
17
- constructor() {
18
- super(...arguments);
19
- this.iconMap = new Map();
18
+ constructor() {
19
+ super(...arguments);
20
+ this.iconMap = /* @__PURE__ */ new Map();
21
+ }
22
+ updated(changedProperties) {
23
+ if (!this.slotContainer) {
24
+ return;
20
25
  }
21
- /**
22
- * First updated handler just ensures we've processed any slotted symbols
23
- */
24
- updated(changedProperties) {
25
- if (!this.slotContainer) {
26
- return;
27
- }
28
- const currentSVGNodes = this.getSVGNodes(this.slotContainer);
29
- this.updateSVG(currentSVGNodes);
30
- super.updated(changedProperties);
26
+ const currentSVGNodes = this.getSVGNodes(this.slotContainer);
27
+ this.updateSVG(currentSVGNodes);
28
+ super.updated(changedProperties);
29
+ }
30
+ async applyIconToElement(el, icon, _size, label) {
31
+ await this.updateComplete;
32
+ const iconSymbol = this.iconMap.get(icon);
33
+ if (!iconSymbol) {
34
+ throw new Error(`Unable to find icon ${icon}`);
31
35
  }
32
- /**
33
- * Applies the requested icon from this iconset instance to the given element.
34
- *
35
- * @param el - the element to apply the icon to
36
- * @param icon - the name of the icon within this set to apply.
37
- */
38
- async applyIconToElement(el, icon, _size, label) {
39
- await this.updateComplete;
40
- const iconSymbol = this.iconMap.get(icon);
41
- if (!iconSymbol) {
42
- throw new Error(`Unable to find icon ${icon}`);
43
- }
44
- // we cannot share a single SVG globally across shadowroot boundaries
45
- // so copy the template node so we can inject it where we need it
46
- const clonedNode = this.prepareSvgClone(iconSymbol);
47
- clonedNode.setAttribute('role', 'img');
48
- if (label) {
49
- clonedNode.setAttribute('aria-label', label);
50
- }
51
- else {
52
- clonedNode.setAttribute('aria-hidden', 'true');
53
- }
54
- // append the svg to the node either in its shadowroot or directly into its dom
55
- if (el.shadowRoot) {
56
- el.shadowRoot.appendChild(clonedNode);
57
- }
58
- else {
59
- el.appendChild(clonedNode);
60
- }
36
+ const clonedNode = this.prepareSvgClone(iconSymbol);
37
+ clonedNode.setAttribute("role", "img");
38
+ if (label) {
39
+ clonedNode.setAttribute("aria-label", label);
40
+ } else {
41
+ clonedNode.setAttribute("aria-hidden", "true");
61
42
  }
62
- /**
63
- * Returns a list of all icons in this iconset.
64
- */
65
- getIconList() {
66
- return [...this.iconMap.keys()];
43
+ if (el.shadowRoot) {
44
+ el.shadowRoot.appendChild(clonedNode);
45
+ } else {
46
+ el.appendChild(clonedNode);
67
47
  }
68
- prepareSvgClone(sourceSvg) {
69
- const content = sourceSvg.cloneNode(true);
70
- // we're going to create a new svg element that will have our symbol geometry inside
71
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
72
- const viewBox = content.getAttribute('viewBox') || '';
73
- // inline style isn't ideal but will work in all cases and means our icons don't need to know
74
- // if they are svg or spritesheet provided
75
- const cssText = 'pointer-events: none; display: block; width: 100%; height: 100%;';
76
- svg.style.cssText = cssText;
77
- // copy the viewbox and other properties into the svg
78
- svg.setAttribute('viewBox', viewBox);
79
- svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
80
- svg.setAttribute('focusable', 'false');
81
- // move all the child nodes over to the svg
82
- while (content.childNodes.length > 0) {
83
- svg.appendChild(content.childNodes[0]);
84
- }
85
- return svg;
48
+ }
49
+ getIconList() {
50
+ return [...this.iconMap.keys()];
51
+ }
52
+ prepareSvgClone(sourceSvg) {
53
+ const content = sourceSvg.cloneNode(true);
54
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
55
+ const viewBox = content.getAttribute("viewBox") || "";
56
+ const cssText = "pointer-events: none; display: block; width: 100%; height: 100%;";
57
+ svg.style.cssText = cssText;
58
+ svg.setAttribute("viewBox", viewBox);
59
+ svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
60
+ svg.setAttribute("focusable", "false");
61
+ while (content.childNodes.length > 0) {
62
+ svg.appendChild(content.childNodes[0]);
86
63
  }
87
- getSVGIconName(icon) {
88
- return icon;
89
- }
90
- getSanitizedIconName(icon) {
91
- return icon;
92
- }
93
- renderDefaultContent() {
94
- return html ``;
95
- }
96
- render() {
97
- return html `
64
+ return svg;
65
+ }
66
+ getSVGIconName(icon) {
67
+ return icon;
68
+ }
69
+ getSanitizedIconName(icon) {
70
+ return icon;
71
+ }
72
+ renderDefaultContent() {
73
+ return html``;
74
+ }
75
+ render() {
76
+ return html`
98
77
  <slot @slotchange=${this.onSlotChange}>
99
78
  ${this.renderDefaultContent()}
100
79
  </slot>
101
80
  `;
102
- }
103
- updateSVG(nodes) {
104
- // iterate over the nodes that were passed in, and find all the top level symbols
105
- const symbols = nodes.reduce((prev, svgNode) => {
106
- const containedSymbols = svgNode.querySelectorAll('symbol');
107
- prev.push(...containedSymbols);
108
- return prev;
109
- }, []);
110
- symbols.forEach((symbol) => {
111
- this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);
112
- });
113
- }
114
- getSVGNodes(slotTarget) {
115
- const nodes = slotTarget.assignedNodes({ flatten: true });
116
- // find all the svg nodes
117
- const svgNodes = nodes.filter((node) => {
118
- return node.nodeName === 'svg';
119
- });
120
- return svgNodes;
121
- }
122
- onSlotChange(event) {
123
- const slotTarget = event.target;
124
- const svgNodes = this.getSVGNodes(slotTarget);
125
- this.updateSVG(svgNodes);
126
- }
81
+ }
82
+ updateSVG(nodes) {
83
+ const symbols = nodes.reduce((prev, svgNode) => {
84
+ const containedSymbols = svgNode.querySelectorAll("symbol");
85
+ prev.push(...containedSymbols);
86
+ return prev;
87
+ }, []);
88
+ symbols.forEach((symbol) => {
89
+ this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);
90
+ });
91
+ }
92
+ getSVGNodes(slotTarget) {
93
+ const nodes = slotTarget.assignedNodes({ flatten: true });
94
+ const svgNodes = nodes.filter((node) => {
95
+ return node.nodeName === "svg";
96
+ });
97
+ return svgNodes;
98
+ }
99
+ onSlotChange(event) {
100
+ const slotTarget = event.target;
101
+ const svgNodes = this.getSVGNodes(slotTarget);
102
+ this.updateSVG(svgNodes);
103
+ }
127
104
  }
128
- __decorate([
129
- query('slot')
130
- ], IconsetSVG.prototype, "slotContainer", void 0);
131
- //# sourceMappingURL=iconset-svg.js.map
105
+ __decorateClass([
106
+ query("slot")
107
+ ], IconsetSVG.prototype, "slotContainer", 2);
108
+ //# sourceMappingURL=iconset-svg.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"iconset-svg.js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","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 {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { query } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Iconset } from './iconset.js';\n\nexport abstract class IconsetSVG extends Iconset {\n private iconMap: Map<string, SVGSymbolElement> = new Map();\n\n @query('slot')\n private slotContainer?: HTMLSlotElement;\n\n /**\n * First updated handler just ensures we've processed any slotted symbols\n */\n public updated(changedProperties: PropertyValues): void {\n if (!this.slotContainer) {\n return;\n }\n const currentSVGNodes = this.getSVGNodes(this.slotContainer);\n this.updateSVG(currentSVGNodes);\n super.updated(changedProperties);\n }\n /**\n * Applies the requested icon from this iconset instance to the given element.\n *\n * @param el - the element to apply the icon to\n * @param icon - the name of the icon within this set to apply.\n */\n public async applyIconToElement(\n el: HTMLElement,\n icon: string,\n _size: string,\n label: string\n ): Promise<void> {\n await this.updateComplete;\n const iconSymbol = this.iconMap.get(icon);\n if (!iconSymbol) {\n throw new Error(`Unable to find icon ${icon}`);\n }\n // we cannot share a single SVG globally across shadowroot boundaries\n // so copy the template node so we can inject it where we need it\n const clonedNode = this.prepareSvgClone(iconSymbol);\n clonedNode.setAttribute('role', 'img');\n if (label) {\n clonedNode.setAttribute('aria-label', label);\n } else {\n clonedNode.setAttribute('aria-hidden', 'true');\n }\n // append the svg to the node either in its shadowroot or directly into its dom\n if (el.shadowRoot) {\n el.shadowRoot.appendChild(clonedNode);\n } else {\n el.appendChild(clonedNode);\n }\n }\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public getIconList(): string[] {\n return [...this.iconMap.keys()];\n }\n\n protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement {\n const content = sourceSvg.cloneNode(true) as SVGSymbolElement;\n // we're going to create a new svg element that will have our symbol geometry inside\n const svg = document.createElementNS(\n 'http://www.w3.org/2000/svg',\n 'svg'\n );\n const viewBox = content.getAttribute('viewBox') || '';\n // inline style isn't ideal but will work in all cases and means our icons don't need to know\n // if they are svg or spritesheet provided\n const cssText =\n 'pointer-events: none; display: block; width: 100%; height: 100%;';\n svg.style.cssText = cssText;\n // copy the viewbox and other properties into the svg\n svg.setAttribute('viewBox', viewBox);\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false');\n // move all the child nodes over to the svg\n while (content.childNodes.length > 0) {\n svg.appendChild(content.childNodes[0]);\n }\n return svg;\n }\n protected getSVGIconName(icon: string): string {\n return icon;\n }\n protected getSanitizedIconName(icon: string): string {\n return icon;\n }\n protected renderDefaultContent(): TemplateResult {\n return html``;\n }\n\n protected render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}>\n ${this.renderDefaultContent()}\n </slot>\n `;\n }\n\n protected updateSVG(nodes: SVGElement[]): void {\n // iterate over the nodes that were passed in, and find all the top level symbols\n const symbols = nodes.reduce((prev, svgNode) => {\n const containedSymbols = svgNode.querySelectorAll('symbol');\n prev.push(...containedSymbols);\n return prev;\n }, [] as SVGSymbolElement[]);\n symbols.forEach((symbol) => {\n this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);\n });\n }\n\n protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[] {\n const nodes = slotTarget.assignedNodes({ flatten: true });\n // find all the svg nodes\n const svgNodes = nodes.filter((node) => {\n return node.nodeName === 'svg';\n }) as SVGElement[];\n return svgNodes;\n }\n\n private onSlotChange(event: Event): void {\n const slotTarget = event.target as HTMLSlotElement;\n const svgNodes = this.getSVGNodes(slotTarget);\n this.updateSVG(svgNodes);\n }\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["iconset-svg.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 {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { query } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Iconset } from './iconset.js';\n\nexport abstract class IconsetSVG extends Iconset {\n private iconMap: Map<string, SVGSymbolElement> = new Map();\n\n @query('slot')\n private slotContainer?: HTMLSlotElement;\n\n /**\n * First updated handler just ensures we've processed any slotted symbols\n */\n public override updated(changedProperties: PropertyValues): void {\n if (!this.slotContainer) {\n return;\n }\n const currentSVGNodes = this.getSVGNodes(this.slotContainer);\n this.updateSVG(currentSVGNodes);\n super.updated(changedProperties);\n }\n /**\n * Applies the requested icon from this iconset instance to the given element.\n *\n * @param el - the element to apply the icon to\n * @param icon - the name of the icon within this set to apply.\n */\n public async applyIconToElement(\n el: HTMLElement,\n icon: string,\n _size: string,\n label: string\n ): Promise<void> {\n await this.updateComplete;\n const iconSymbol = this.iconMap.get(icon);\n if (!iconSymbol) {\n throw new Error(`Unable to find icon ${icon}`);\n }\n // we cannot share a single SVG globally across shadowroot boundaries\n // so copy the template node so we can inject it where we need it\n const clonedNode = this.prepareSvgClone(iconSymbol);\n clonedNode.setAttribute('role', 'img');\n if (label) {\n clonedNode.setAttribute('aria-label', label);\n } else {\n clonedNode.setAttribute('aria-hidden', 'true');\n }\n // append the svg to the node either in its shadowroot or directly into its dom\n if (el.shadowRoot) {\n el.shadowRoot.appendChild(clonedNode);\n } else {\n el.appendChild(clonedNode);\n }\n }\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public getIconList(): string[] {\n return [...this.iconMap.keys()];\n }\n\n protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement {\n const content = sourceSvg.cloneNode(true) as SVGSymbolElement;\n // we're going to create a new svg element that will have our symbol geometry inside\n const svg = document.createElementNS(\n 'http://www.w3.org/2000/svg',\n 'svg'\n );\n const viewBox = content.getAttribute('viewBox') || '';\n // inline style isn't ideal but will work in all cases and means our icons don't need to know\n // if they are svg or spritesheet provided\n const cssText =\n 'pointer-events: none; display: block; width: 100%; height: 100%;';\n svg.style.cssText = cssText;\n // copy the viewbox and other properties into the svg\n svg.setAttribute('viewBox', viewBox);\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false');\n // move all the child nodes over to the svg\n while (content.childNodes.length > 0) {\n svg.appendChild(content.childNodes[0]);\n }\n return svg;\n }\n protected getSVGIconName(icon: string): string {\n return icon;\n }\n protected getSanitizedIconName(icon: string): string {\n return icon;\n }\n protected renderDefaultContent(): TemplateResult {\n return html``;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}>\n ${this.renderDefaultContent()}\n </slot>\n `;\n }\n\n protected updateSVG(nodes: SVGElement[]): void {\n // iterate over the nodes that were passed in, and find all the top level symbols\n const symbols = nodes.reduce((prev, svgNode) => {\n const containedSymbols = svgNode.querySelectorAll('symbol');\n prev.push(...containedSymbols);\n return prev;\n }, [] as SVGSymbolElement[]);\n symbols.forEach((symbol) => {\n this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);\n });\n }\n\n protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[] {\n const nodes = slotTarget.assignedNodes({ flatten: true });\n // find all the svg nodes\n const svgNodes = nodes.filter((node) => {\n return node.nodeName === 'svg';\n }) as SVGElement[];\n return svgNodes;\n }\n\n private onSlotChange(event: Event): void {\n const slotTarget = event.target as HTMLSlot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