Created
July 8, 2021 20:58
-
-
Save starakaj/ddb358f9c17d52a2fb69352e837137df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onopentag(name: string, attribs: {[s: string]: string}) { | |
if (name === "rect") { | |
if (viewBox !== undefined) { | |
let x = t.numericLiteral( | |
2 * Number.parseFloat(attribs.x || "0") / viewBox[2] - 1 | |
); | |
let y = t.numericLiteral( | |
1 - 2 * Number.parseFloat(attribs.y || "0") / viewBox[3] | |
); | |
let w = t.numericLiteral( | |
2 * Number.parseFloat(attribs.width || "0") / viewBox[2] | |
); | |
let h = t.numericLiteral( | |
2 * Number.parseFloat(attribs.height || "0") / viewBox[3] | |
); | |
let rectStatements; | |
if (attribs.class) { | |
const styleFunctionName = t.identifier(createLegalName(attribs.class)); | |
rectStatements = makeStyledRectDrawStatements({ styleFunctionName, x, y, w, h }); | |
} else { | |
rectStatements = makeRectDrawStatements({ x, y, w, h }); | |
} | |
paintStatements = paintStatements.concat(rectStatements); | |
} else { | |
console.warn("rect tag outside of svg parent tag with defined viewBox, skipping"); | |
} | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment