@@ -122,6 +122,59 @@ describe("extractFromDesign", () => {
122122 } ) ;
123123} ) ;
124124
125+ describe ( "collapseSvgContainers" , ( ) => {
126+ it ( "collapses BOOLEAN_OPERATION nodes to IMAGE-SVG" , async ( ) => {
127+ const booleanOpNode = makeNode ( {
128+ id : "5:1" ,
129+ name : "Combined Shape" ,
130+ type : "BOOLEAN_OPERATION" ,
131+ booleanOperation : "UNION" ,
132+ children : [
133+ makeNode ( { id : "5:2" , name : "Circle" , type : "ELLIPSE" } ) ,
134+ makeNode ( { id : "5:3" , name : "Square" , type : "RECTANGLE" } ) ,
135+ ] ,
136+ } ) ;
137+
138+ const { nodes } = await extractFromDesign ( [ booleanOpNode ] , allExtractors , {
139+ afterChildren : collapseSvgContainers ,
140+ } ) ;
141+
142+ expect ( nodes ) . toHaveLength ( 1 ) ;
143+ expect ( nodes [ 0 ] . type ) . toBe ( "IMAGE-SVG" ) ;
144+ expect ( nodes [ 0 ] . children ) . toBeUndefined ( ) ;
145+ } ) ;
146+
147+ it ( "collapses a frame containing a BOOLEAN_OPERATION to IMAGE-SVG" , async ( ) => {
148+ const frameWithBoolOp = makeNode ( {
149+ id : "6:1" ,
150+ name : "Icon Frame" ,
151+ type : "FRAME" ,
152+ children : [
153+ makeNode ( {
154+ id : "6:2" ,
155+ name : "Union" ,
156+ type : "BOOLEAN_OPERATION" ,
157+ booleanOperation : "UNION" ,
158+ children : [
159+ makeNode ( { id : "6:3" , name : "A" , type : "RECTANGLE" } ) ,
160+ makeNode ( { id : "6:4" , name : "B" , type : "ELLIPSE" } ) ,
161+ ] ,
162+ } ) ,
163+ ] ,
164+ } ) ;
165+
166+ const { nodes } = await extractFromDesign ( [ frameWithBoolOp ] , allExtractors , {
167+ afterChildren : collapseSvgContainers ,
168+ } ) ;
169+
170+ // The BOOLEAN_OPERATION collapses to IMAGE-SVG first (bottom-up),
171+ // then the FRAME sees all children are SVG-eligible and collapses too.
172+ expect ( nodes ) . toHaveLength ( 1 ) ;
173+ expect ( nodes [ 0 ] . type ) . toBe ( "IMAGE-SVG" ) ;
174+ expect ( nodes [ 0 ] . children ) . toBeUndefined ( ) ;
175+ } ) ;
176+ } ) ;
177+
125178describe ( "simplifyRawFigmaObject" , ( ) => {
126179 it ( "produces a complete SimplifiedDesign from a mock API response" , async ( ) => {
127180 const mockResponse = {
0 commit comments