From 65a97a64a5c03a15183e04fe47eaf5ca159a4cbe Mon Sep 17 00:00:00 2001 From: LitoMore Date: Mon, 2 Sep 2024 07:00:21 +0800 Subject: [PATCH] perf: improve logoSize performance --- lib/svg-helpers.js | 22 ++++++---------------- package-lock.json | 34 +++++++++++++++++++++------------- package.json | 3 ++- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/svg-helpers.js b/lib/svg-helpers.js index 1ccb288992b40..18ff04cd4797a 100644 --- a/lib/svg-helpers.js +++ b/lib/svg-helpers.js @@ -1,4 +1,5 @@ -import SVGPathCommander from 'svg-path-commander' +import { svgPathBbox } from 'svg-path-bbox' +import svgpath from 'svgpath' import loadSimpleIcons from './load-simple-icons.js' const simpleIcons = loadSimpleIcons() @@ -14,24 +15,13 @@ function getIconSize(iconKey) { return undefined } - const { - width, - height, - x: x0, - y: y0, - x2: x1, - y2: y1, - } = SVGPathCommander.getPathBBox(simpleIcons[iconKey].path) - - return { width, height, x0, y0, x1, y1 } + const [x0, y0, x1, y1] = svgPathBbox(simpleIcons[iconKey].path) + return { width: x1 - x0, height: y1 - y0 } } function resetIconPosition(path) { - const { x: offsetX, y: offsetY } = SVGPathCommander.getPathBBox(path) - const pathReset = new SVGPathCommander(path) - .transform({ translate: [-offsetX, -offsetY] }) - .toString() - + const [offsetX, offsetY] = svgPathBbox(path) + const pathReset = svgpath(path).translate(-offsetX, -offsetY).toString() return pathReset } diff --git a/package-lock.json b/package-lock.json index 0d1c040f90471..d262fbb9eae59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,7 +53,8 @@ "semver": "~7.6.3", "simple-icons": "13.6.0", "smol-toml": "1.3.0", - "svg-path-commander": "^2.0.10", + "svg-path-bbox": "^2.0.0", + "svgpath": "^2.6.0", "webextension-store-meta": "^1.2.3", "xpath": "~0.0.34" }, @@ -5541,11 +5542,6 @@ "node": ">=14.16" } }, - "node_modules/@thednp/dommatrix": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/@thednp/dommatrix/-/dommatrix-2.0.7.tgz", - "integrity": "sha512-d5p07ZYa1Z6opXIGwKpBVvzxQity43T0kVnDXMbZNsMzaOrJGKtemRJA8Puj2GtvWQ5+JiNPkiwBWSk6plLVtA==" - }, "node_modules/@tokenizer/token": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", @@ -28142,16 +28138,19 @@ "integrity": "sha512-e4hG1hRwoOdRb37cIMSgzNsxyzKfayW6VOflrwvR+/bzrkyxY/31WkbgnQpgtrNp1SdpJvpUAGTa/ZoiPNDuRQ==", "dev": true }, - "node_modules/svg-path-commander": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/svg-path-commander/-/svg-path-commander-2.0.10.tgz", - "integrity": "sha512-DGYaXpW6cD0ML3Qj/Md/2al4p44wm/THVQMd2wL5w5LlbFWM/iU8BMvWjUDRzJXe8tpQG3LVsuEQftzdjQE+Vg==", + "node_modules/svg-path-bbox": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/svg-path-bbox/-/svg-path-bbox-2.0.0.tgz", + "integrity": "sha512-DP/dcKuwjfJ2GXiM1RsIKcWv+aGazBXTYPuAH9pWYZVm5+pZ6ho70BeLB0inqUGDCCHDmcUlQ2OcLlGuwhmkKQ==", + "license": "BSD-3-Clause", "dependencies": { - "@thednp/dommatrix": "^2.0.7" + "svgpath": "^2.6.0" + }, + "bin": { + "svg-path-bbox": "src/cli.js" }, "engines": { - "node": ">=16", - "pnpm": ">=8.6.0" + "node": ">=6.17.1" } }, "node_modules/svgo": { @@ -28188,6 +28187,15 @@ "node": ">= 10" } }, + "node_modules/svgpath": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/svgpath/-/svgpath-2.6.0.tgz", + "integrity": "sha512-OIWR6bKzXvdXYyO4DK/UWa1VA1JeKq8E+0ug2DG98Y/vOmMpfZNj+TIG988HjfYSqtcy/hFOtZq/n/j5GSESNg==", + "license": "MIT", + "funding": { + "url": "https://github.com/fontello/svg2ttf?sponsor=1" + } + }, "node_modules/synckit": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.1.tgz", diff --git a/package.json b/package.json index 877a903ae3d45..c4cc1033f155a 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,8 @@ "semver": "~7.6.3", "simple-icons": "13.6.0", "smol-toml": "1.3.0", - "svg-path-commander": "^2.0.10", + "svg-path-bbox": "^2.0.0", + "svgpath": "^2.6.0", "webextension-store-meta": "^1.2.3", "xpath": "~0.0.34" },