Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"*.{ts,tsx}": ["pnpm exec eslint --fix", "bash -c 'pnpm exec tsc --noEmit'"],
"*.{ts,tsx,jsonc,md}": ["pnpm exec prettier --write"]
"*.{ts,tsx,jsonc,md}": ["pnpm exec prettier --write"],
"**/*.svg": "tsx scripts/svgo-optimize.ts"
}
15 changes: 12 additions & 3 deletions assets/core/ts/components/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ function fetchSVG(
return promise;
}

let instanceCounter = 0;

const namespaceSvgIds = (svgContent: string, suffix: string) => {
return svgContent
.replace(/\bid="([a-zA-Z0-9_-]+)"/g, `id="$1${suffix}"`)
.replace(/url\(#([a-zA-Z0-9_-]+)\)/g, `url(#$1${suffix})`)
.replace(/(xlink:href|href)="#([a-zA-Z0-9_-]+)"/g, `$1="#$2${suffix}"`);
};

export const icon = (props: IconProps) => ({
name: props.name,
width: props.width || 16,
height: props.height || 16,
from: props.from || 'php',
ignoreKids: props.ignoreKids || false,
instanceId: `icon-${instanceCounter++}`,

async init() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -105,8 +115,7 @@ export const icon = (props: IconProps) => ({
}

const svg = await fetchSVG(this.name, this.width, this.height, this.from, this.ignoreKids);

$el.innerHTML = svg;
$el.innerHTML = namespaceSvgIds(svg, `-${this.instanceId}`);
},

async updateIcon(newName: string) {
Expand All @@ -117,7 +126,7 @@ export const icon = (props: IconProps) => ({
$el.innerHTML = createSvg({ width: this.width, height: this.height });

const svg = await fetchSVG(this.name, this.width, this.height, this.from, this.ignoreKids);
$el.innerHTML = svg;
$el.innerHTML = namespaceSvgIds(svg, `-${this.instanceId}`);
},
});

Expand Down
2 changes: 1 addition & 1 deletion assets/icons/active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/icons/add-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions assets/icons/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/icons/addons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/icons/ai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/icons/air-delivery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions assets/icons/alarm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/icons/alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions assets/icons/all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions assets/icons/analytics-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading