File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,9 @@ export class Element {
196196 }
197197 this . addAsset ( this . node , 'png' )
198198 }
199+ const css = await this . getCss ( )
200+ if ( this . node . width === 1 && ! ( 'width' in css ) )
201+ this . additionalProps . w = '1px'
199202 break
200203 }
201204 case 'FRAME' :
@@ -286,8 +289,14 @@ export class Element {
286289 return
287290 }
288291 if ( this . parent ) this . parent . addAsset ( node , type )
289- else
290- this . assets [ node . name + '.' + type ] = async ( ) => {
292+ else {
293+ let key = node . name
294+ let idx = 0
295+ while ( key + '.' + type in this . assets ) {
296+ key = node . name + '_' + idx
297+ idx ++
298+ }
299+ this . assets [ key + '.' + type ] = async ( ) => {
291300 const isSvg = type === 'svg'
292301 const options : ExportSettings = {
293302 format : isSvg ? 'SVG' : 'PNG' ,
@@ -303,6 +312,7 @@ export class Element {
303312 const data = await node . exportAsync ( options )
304313 return data
305314 }
315+ }
306316 }
307317
308318 async getComponents ( ) : Promise < Record < string , ( ) => Promise < string > > > {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ function createNode(
1818 componentProperties,
1919 getMainComponentAsync,
2020 visible = true ,
21+ css,
2122 ...props
2223 } : {
2324 [ _ : string ] : any
@@ -34,7 +35,7 @@ function createNode(
3435) : SceneNode {
3536 const ret = {
3637 type,
37- getCSSAsync : async ( ) => props ,
38+ getCSSAsync : async ( ) => css ?? props ,
3839 exportAsync : async ( ) => '<svg>\n<path/>\n</svg>' ,
3940 getStyledTextSegments : ( ) => styledTextSegments ,
4041 layoutSizingHorizontal,
@@ -1450,6 +1451,15 @@ describe('Element', () => {
14501451 expect ( await element . getComponentType ( ) ) . toEqual ( 'Box' )
14511452 expect ( await element . render ( ) ) . toEqual ( '<Box bg="red" />' )
14521453 }
1454+ {
1455+ const element = createElement ( 'RECTANGLE' , {
1456+ width : '1px' ,
1457+ height : '10px' ,
1458+ fills : [ ] ,
1459+ css : { height : '10px' } ,
1460+ } )
1461+ expect ( await element . render ( ) ) . toEqual ( '<Box h="10px" w="1px" />' )
1462+ }
14531463 } )
14541464 } )
14551465
@@ -1696,6 +1706,7 @@ export function Component(props: ComponentProps) {
16961706 await element . render ( )
16971707 expect ( await element . getAssets ( ) ) . toEqual ( {
16981708 'image.svg' : expect . any ( Function ) ,
1709+ 'image_0.svg' : expect . any ( Function ) ,
16991710 } )
17001711 }
17011712 } )
Original file line number Diff line number Diff line change @@ -163,11 +163,13 @@ describe('exportAssets', () => {
163163 ] ,
164164 } )
165165 ; ( globalThis as any ) . figma . currentPage . selection = [ node ]
166+ vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
166167 ; ( node . exportAsync as any ) = vi . fn ( ) . mockRejectedValue ( 'test' )
167168 await exportAssets ( )
168169 expect ( notifyMock ) . toHaveBeenCalledWith ( 'Error exporting assets' , {
169170 timeout : 3000 ,
170171 error : true ,
171172 } )
173+ vi . spyOn ( console , 'error' ) . mockRestore ( )
172174 } )
173175} )
Original file line number Diff line number Diff line change @@ -164,10 +164,12 @@ describe('exportComponents', () => {
164164 ] ,
165165 } )
166166 ; ( globalThis as any ) . figma . currentPage . selection = [ node ]
167+ vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
167168 await exportComponents ( )
168169 expect ( notifyMock ) . toHaveBeenCalledWith ( 'Error exporting components' , {
169170 timeout : 3000 ,
170171 error : true ,
171172 } )
173+ vi . spyOn ( console , 'error' ) . mockRestore ( )
172174 } )
173175} )
You can’t perform that action at this time.
0 commit comments