@@ -1720,6 +1720,42 @@ QUnit.module('vectorizer', function(hooks) {
17201720 rect . remove ( ) ;
17211721 } ) ;
17221722
1723+ QUnit . test ( 'nested SVG elements' , function ( assert ) {
1724+
1725+ // SVG > g(A) > g > nested SVG > g > rect(B)
1726+ var elA = V ( 'g' , { id : 'outer-g' , transform : 'translate(10, 20)' } ) ;
1727+ var elB = V ( 'rect' , { id : 'inner-rect' , width : 10 , height : 10 } ) ;
1728+ var nestedSvg = V ( 'svg' , { id : 'nested-svg' , x : '30' , y : '40' } ) ;
1729+ var innerGroup = V ( 'g' , { id : 'inner-g' , transform : 'translate(5, 5)' } ) ;
1730+
1731+ innerGroup . append ( elB ) ;
1732+ nestedSvg . append ( innerGroup ) ;
1733+ var outerGroup = V ( 'g' ) ;
1734+ outerGroup . append ( nestedSvg ) ;
1735+ elA . append ( outerGroup ) ;
1736+
1737+ var container = V ( svgContainer ) ;
1738+ container . append ( elA ) ;
1739+
1740+ var epsilon = 0.01 ;
1741+
1742+ // getTransformToElement(A, B) maps from A's coordinate space into B's.
1743+ // B is offset from A by nested SVG (x=30,y=40) + inner-g translate(5,5),
1744+ // so the transform into B's space negates that: translate(-35,-45).
1745+ var matrix = elA . getTransformToElement ( elB . node ) ;
1746+ assert . ok ( matrix , 'Returns a matrix for elements across nested SVG boundary' ) ;
1747+ assert . ok ( Math . abs ( matrix . e - ( - 35 ) ) < epsilon , 'Matrix tx is ~-35 (got ' + matrix . e + ')' ) ;
1748+ assert . ok ( Math . abs ( matrix . f - ( - 45 ) ) < epsilon , 'Matrix ty is ~-45 (got ' + matrix . f + ')' ) ;
1749+
1750+ // Safe mode (DOM-walk based) should also return a non-null matrix across nested SVG.
1751+ // Note: safe mode does not account for <svg> x/y attributes, only transform attributes.
1752+ var safeMatrix = elA . getTransformToElement ( elB . node , { safe : true } ) ;
1753+ assert . ok ( safeMatrix , 'Safe mode returns a matrix for elements across nested SVG boundary' ) ;
1754+ assert . ok ( Math . abs ( safeMatrix . e - ( - 5 ) ) < epsilon , 'Safe mode matrix tx is ~-5 (got ' + safeMatrix . e + ')' ) ;
1755+ assert . ok ( Math . abs ( safeMatrix . f - ( - 5 ) ) < epsilon , 'Safe mode matrix ty is ~-5 (got ' + safeMatrix . f + ')' ) ;
1756+
1757+ elA . remove ( ) ;
1758+ } ) ;
17231759
17241760 } ) ;
17251761} ) ;
0 commit comments