import { getCombinedTransform , RenderContext } from '../utils' ; export function drawUse ( context , use , svgTransform ) { let href = use . href . baseVal ; if ( href . startsWith ( '#' ) ) { href = href . substring ( 1 ) ; } const defElement = context . idElements [ href ] as SVGElement ; if ( defElement ) { let useWidth , useHeight ; if ( use . getAttribute ( 'width' ) && use . getAttribute ( 'height' ) ) { useWidth = use . width . baseVal . value ; useHeight = use . height . baseVal . value ; } const x = use . x . baseVal . value ; const y = use . y . baseVal . value ; let matrix = context . sourceSvg . createSVGMatrix ( ) . translate ( x , y ) ; matrix = svgTransform ? svgTransform . matrix . multiply ( matrix ) : matrix ; const elementTransform = context . sourceSvg . createSVGTransformFromMatrix ( matrix ) ; if ( ! context . useElementContext ) { context . useElementContext = { root : use , referenced : defElement , parentContext : null } ; } else { const newContext = { root : use , referenced : defElement , parentContext : Object . assign ( { } , context . useElementContext ) } ; context . useElementContext = newContext ; } context . processElement ( context , defElement , getCombinedTransform ( context , defElement as SVGGraphicsElement , elementTransform ) , useWidth , useHeight ) ; if ( context . useElementContext . parentContext ) { context . useElementContext = context . useElementContext . parentContext ; } else { context . useElementContext = null ; } } }