Skip to content

Commit

Permalink
perf: improve logoSize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Sep 1, 2024
1 parent e001e94 commit 65a97a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
22 changes: 6 additions & 16 deletions lib/svg-helpers.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
}

Expand Down
34 changes: 21 additions & 13 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 65a97a6

Please sign in to comment.