Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function mapImageTreeToSvg(node: ImageNode): SvgElement {
switch (node.type) {
case IMAGE: {
let box = BBox.empty()
unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
box = BBox.add(box, layer.size)
})
const [xMin, yMin, width, height] = BBox.toViewBox(box)
const props = {
...BASE_SVG_PROPS,
width,
height,
viewBox: `${xMin} ${yMin} ${width} ${height}`,
}
return s('svg', props)
}
case IMAGE_LAYER: {
const vbox = BBox.toViewBox(node.size)
return s('g', {
transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
})
}
case IMAGE_SHAPE: {
return renderShape(node)
}
case IMAGE_PATH:
case IMAGE_REGION: {
return renderPath(node)
unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
box = BBox.add(box, layer.size)
})
const [xMin, yMin, width, height] = BBox.toViewBox(box)
const props = {
...BASE_SVG_PROPS,
width,
height,
viewBox: `${xMin} ${yMin} ${width} ${height}`,
}
return s('svg', props)
}
case IMAGE_LAYER: {
const vbox = BBox.toViewBox(node.size)
return s('g', {
transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
})
}
case IMAGE_SHAPE: {
return renderShape(node)
}
case IMAGE_PATH:
case IMAGE_REGION: {
return renderPath(node)
}
}
return s('metadata', [JSON.stringify(node)])
}
return s('g', {
transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
})
}
case IMAGE_SHAPE: {
return renderShape(node)
}
case IMAGE_PATH:
case IMAGE_REGION: {
return renderPath(node)
}
}
return s('metadata', [JSON.stringify(node)])
}