-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (18 loc) · 746 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import manifest from "./package.json" assert { type: "json" }
let { name, description } = manifest
name = name.replace(/^(@[a-z-]+\/)?svgo-plugin-/, "")
const exists = ["stroke", "fill"]
const fn = ({ type }, { fill, stroke, auto, "0": aut0 }) => {
function enter({ children: [{ name, attributes }] }) {
if (name !== "svg") return
auto ??= aut0
if (!auto) return Object.assign(attributes, { fill, stroke })
const [attribute] = Object.entries(attributes)
.filter(([,value]) => value !== "none")
.find(([attribute]) => exists.includes(attribute)) ?? exists.slice(1)
attributes[attribute] = auto
}
return { [type]: { enter }}
}
export const chameleon = { name, description, fn }
export default chameleon