diff --git a/custom_components/fontawesome/main.js b/custom_components/fontawesome/main.js index 2671471..628f23d 100644 --- a/custom_components/fontawesome/main.js +++ b/custom_components/fontawesome/main.js @@ -1 +1 @@ -(()=>{const t="fontawesome",o={},e={"fa-primary":"primary","fa-secondary":"secondary",primary:"primary",secondary:"secondary"},n=(n,s)=>new Promise((async(r,a)=>{const c=`${n}:${s}`;o[c]&&r(o[c]),o[c]=(async(o,n)=>{const[s,r]=n.split("#"),a=await fetch(`/${t}/icons/${o}/${s}.svg`),c=await a.text(),i=(new DOMParser).parseFromString(c,"text/html");if(!i||!i.querySelector("svg"))return{};const l=i.querySelector("svg").getAttribute("viewBox"),d=i.querySelectorAll("path"),h={};let p="";for(const t of d){p+=t.getAttribute("d");const o=t.classList[0];e[o]&&(h[e[o]]=t.getAttribute("d"))}let y=null;const u=i.querySelector("svg");return Array.from(u.attributes).some((t=>t.name.startsWith("on")))||u.getElementsByTagName("script").length||(y=u),{viewBox:l,path:p,paths:h,format:r,fullCode:y}})(n,s),r(o[c])})),s=async o=>{const e=await fetch(`/${t}/list/${o}`),n=await e.text();return JSON.parse(n)};"customIconsets"in window||(window.customIconsets={}),"customIcons"in window||(window.customIcons={}),window.customIcons.fab={getIcon:t=>n("brands",t),getIconList:()=>s("brands")},window.customIcons.far={getIcon:t=>n("regular",t),getIconList:()=>s("regular")},window.customIcons.fas={getIcon:t=>n("solid",t),getIconList:()=>s("solid")},window.customIcons.fapro={getIcon:t=>n("pro",t),getIconList:()=>s("pro")},window.customIconsets.facustom=t=>n("pro",t),customElements.whenDefined("ha-icon").then((()=>{customElements.get("ha-icon").prototype._setCustomPath=async function(t,o){const e=await t;if(o!==this.icon)return;this._path=e.path,this._viewBox=e.viewBox,await this.UpdateComplete;const n=this.shadowRoot.querySelector("ha-svg-icon");if(n&&n.setPaths)if(n.clearPaths(),e.fullCode&&"fullcolor"===e.format){await n.updateComplete;const t=n.shadowRoot.querySelector("svg"),o=document.createElement("style");o.innerHTML="\n svg:first-child>g:first-of-type>path {\n display: none;\n }\n ",t.appendChild(o),t.appendChild(e.fullCode.cloneNode(!0))}else n.setPaths(e.paths),e.format&&n.classList.add(...e.format.split("-"))}})),customElements.whenDefined("ha-svg-icon").then((()=>{const t=customElements.get("ha-svg-icon");t.prototype.clearPaths=async function(){await this.updateComplete;const t=this.shadowRoot.querySelector("svg");for(;t&&t.children.length>1;)t.removeChild(t.lastChild);const o=this.shadowRoot.querySelector("g");for(;o&&o.children.length>1;)o.removeChild(o.lastChild);for(;this.shadowRoot.querySelector("style");){const t=this.shadowRoot.querySelector("style");t.parentNode.removeChild(t)}},t.prototype.setPaths=async function(t){if(await this.updateComplete,null==t||0===Object.keys(t).length)return;const o=this.shadowRoot.querySelector("style")||document.createElement("style");o.innerHTML="\n .secondary {\n opacity: 0.4;\n }\n :host(.invert) .secondary {\n opacity: 1;\n }\n :host(.invert) .primary {\n opacity: 0.4;\n }\n :host(.color) .primary {\n opacity: 1;\n }\n :host(.color) .secondary {\n opacity: 1;\n }\n :host(.color:not(.invert)) .secondary {\n fill: var(--icon-secondary-color, var(--disabled-text-color));\n }\n :host(.color.invert) .primary {\n fill: var(--icon-secondary-color, var(--disabled-text-color));\n }\n path:not(.primary):not(.secondary) {\n opacity: 0;\n }\n ",this.shadowRoot.appendChild(o);const e=this.shadowRoot.querySelector("g");for(const o in t){const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",t[o]),n.classList.add(o),e.appendChild(n)}}}))})(); \ No newline at end of file +(()=>{const t="fontawesome",o={},e={"fa-primary":"primary","fa-secondary":"secondary",primary:"primary",secondary:"secondary"},s=(s,n)=>new Promise((async(a,r)=>{const c=`${s}:${n}`;o[c]&&a(o[c]),o[c]=(async(o,s)=>{const[n,a]=s.split("#"),r=await fetch(`/${t}/icons/${o}/${n}.svg`),c=await r.text(),i=(new DOMParser).parseFromString(c,"text/html");if(!i||!i.querySelector("svg"))return{};const l=i.querySelector("svg").getAttribute("viewBox"),d=i.querySelectorAll("path"),h={};let p="";for(const t of d){p+=t.getAttribute("d");const o=t.classList[0];e[o]&&(h[e[o]]=t.getAttribute("d"))}let m=null;const y=i.querySelector("svg");return Array.from(y.attributes).some((t=>t.name.startsWith("on")))||y.getElementsByTagName("script").length||(m=y),{viewBox:l,path:p,paths:h,format:a,fullCode:m}})(s,n),a(o[c])})),n=async o=>{const e=await fetch(`/${t}/list/${o}`),s=await e.text();return JSON.parse(s)};"customIconsets"in window||(window.customIconsets={}),"customIcons"in window||(window.customIcons={}),window.customIcons.fab={getIcon:t=>s("brands",t),getIconList:()=>n("brands")},window.customIcons.far={getIcon:t=>s("regular",t),getIconList:()=>n("regular")},window.customIcons.fas={getIcon:t=>s("solid",t),getIconList:()=>n("solid")},window.customIcons.fapro={getIcon:t=>s("pro",t),getIconList:()=>n("pro")},window.customIconsets.facustom=t=>s("pro",t),customElements.whenDefined("ha-icon").then((()=>{customElements.get("ha-icon").prototype._setCustomPath=async function(t,o){const e=await t;if(o!==this.icon)return;this._path=e.path,this._viewBox=e.viewBox,await this.UpdateComplete;const s=this.shadowRoot.querySelector("ha-svg-icon");if(s&&s.setPaths)if(s.clearPaths(),e.fullCode&&"fullcolor"===e.format){await s.updateComplete;const t=s.shadowRoot.querySelector("svg"),o=document.createElement("style");o.innerHTML="\n svg:first-child>g:first-of-type>path {\n display: none;\n }\n ",t.appendChild(o),t.appendChild(e.fullCode.cloneNode(!0))}else s.setPaths(e.paths),e.format&&s.classList.add(...e.format.split("-"))}})),customElements.whenDefined("ha-svg-icon").then((()=>{const t=customElements.get("ha-svg-icon");t.prototype.clearPaths=async function(){await this.updateComplete;const t=this.shadowRoot.querySelector("svg");for(;t&&t.children.length>1;)t.removeChild(t.lastChild);const o=this.shadowRoot.querySelector("g");for(;o&&o.children.length>1;)o.removeChild(o.lastChild);for(;this.shadowRoot.querySelector("style.fontawesome");){const t=this.shadowRoot.querySelector("style.fontawesome");t.parentNode.removeChild(t)}},t.prototype.setPaths=async function(t){if(await this.updateComplete,null==t||0===Object.keys(t).length)return;const o=this.shadowRoot.querySelector("style.fontawesome")||document.createElement("style");o.classList.add("fontawesome"),o.innerHTML="\n .secondary {\n opacity: 0.4;\n }\n :host(.invert) .secondary {\n opacity: 1;\n }\n :host(.invert) .primary {\n opacity: 0.4;\n }\n :host(.color) .primary {\n opacity: 1;\n }\n :host(.color) .secondary {\n opacity: 1;\n }\n :host(.color:not(.invert)) .secondary {\n fill: var(--icon-secondary-color, var(--disabled-text-color));\n }\n :host(.color.invert) .primary {\n fill: var(--icon-secondary-color, var(--disabled-text-color));\n }\n path:not(.primary):not(.secondary) {\n opacity: 0;\n }\n ",this.shadowRoot.appendChild(o);const e=this.shadowRoot.querySelector("g");for(const o in t){const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",t[o]),s.classList.add(o),e.appendChild(s)}}}))})(); \ No newline at end of file diff --git a/custom_components/fontawesome/manifest.json b/custom_components/fontawesome/manifest.json index 5dcdc3a..47a0c1d 100644 --- a/custom_components/fontawesome/manifest.json +++ b/custom_components/fontawesome/manifest.json @@ -6,6 +6,6 @@ "codeowners": [], "requirements": [], "config_flow": true, - "version": "2.1.4", + "version": "2.1.5", "iot_class": "local_polling" } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 12a6300..bc86f34 100644 --- a/js/main.js +++ b/js/main.js @@ -149,8 +149,8 @@ customElements.whenDefined("ha-svg-icon").then(() => { while (svgGroup && svgGroup.children.length > 1) svgGroup.removeChild(svgGroup.lastChild); - while (this.shadowRoot.querySelector("style")) { - const el = this.shadowRoot.querySelector("style"); + while (this.shadowRoot.querySelector("style.fontawesome")) { + const el = this.shadowRoot.querySelector("style.fontawesome"); el.parentNode.removeChild(el); } }; @@ -159,7 +159,9 @@ customElements.whenDefined("ha-svg-icon").then(() => { await this.updateComplete; if (paths == undefined || Object.keys(paths).length === 0) return; const styleEl = - this.shadowRoot.querySelector("style") || document.createElement("style"); + this.shadowRoot.querySelector("style.fontawesome") || + document.createElement("style"); + styleEl.classList.add("fontawesome"); styleEl.innerHTML = ` .secondary { opacity: 0.4; diff --git a/package-lock.json b/package-lock.json index 8c07590..159b36c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "fontawesome", - "version": "2.0.0", + "version": "2.1.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ddb2d7a..57457d6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fontawesome", "private": true, - "version": "2.1.4", + "version": "2.1.5", "description": "", "scripts": { "export": "./export.sh", diff --git a/test/configuration.yaml b/test/configuration.yaml index 52c5625..248260a 100644 --- a/test/configuration.yaml +++ b/test/configuration.yaml @@ -1,3 +1,5 @@ default_config: demo: + +hacs: