Skip to content

Commit

Permalink
Better icon cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Nov 3, 2021
1 parent 55dc083 commit 8d2c140
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/fontawesome/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion custom_components/fontawesome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"codeowners": [],
"requirements": [],
"config_flow": true,
"version": "2.1.3",
"version": "2.1.4",
"iot_class": "local_polling"
}
22 changes: 21 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ window.customIconsets["facustom"] = (iconName) => getIcon("pro", iconName);
// Duotone patches
customElements.whenDefined("ha-icon").then(() => {
const HaIcon = customElements.get("ha-icon");
HaIcon.prototype._setCustomPath = async function (promise) {
HaIcon.prototype._setCustomPath = async function (promise, requestedIcon) {
const icon = await promise;
if (requestedIcon !== this.icon) return;
this._path = icon.path;
this._viewBox = icon.viewBox;

Expand All @@ -112,6 +113,8 @@ customElements.whenDefined("ha-icon").then(() => {
if (!el || !el.setPaths) {
return;
}
el.clearPaths();

if (icon.fullCode && icon.format === "fullcolor") {
await el.updateComplete;
const root = el.shadowRoot.querySelector("svg");
Expand All @@ -135,6 +138,23 @@ customElements.whenDefined("ha-icon").then(() => {
customElements.whenDefined("ha-svg-icon").then(() => {
const HaSvgIcon = customElements.get("ha-svg-icon");

HaSvgIcon.prototype.clearPaths = async function () {
await this.updateComplete;

const svgRoot = this.shadowRoot.querySelector("svg");
while (svgRoot && svgRoot.children.length > 1)
svgRoot.removeChild(svgRoot.lastChild);

const svgGroup = this.shadowRoot.querySelector("g");
while (svgGroup && svgGroup.children.length > 1)
svgGroup.removeChild(svgGroup.lastChild);

while (this.shadowRoot.querySelector("style")) {
const el = this.shadowRoot.querySelector("style");
el.parentNode.removeChild(el);
}
};

HaSvgIcon.prototype.setPaths = async function (paths) {
await this.updateComplete;
if (paths == undefined || Object.keys(paths).length === 0) return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fontawesome",
"private": true,
"version": "2.1.3",
"version": "2.1.4",
"description": "",
"scripts": {
"export": "./export.sh",
Expand Down

0 comments on commit 8d2c140

Please sign in to comment.