@@ -328,10 +328,23 @@ const getUnionViewBox = (
328328const getSvgDefsContent = ( svg : string ) =>
329329 svg . match ( / < d e f s > ( [ \s \S ] * ?) < \/ d e f s > / ) ?. [ 1 ] ?? ""
330330
331- const getGerberLayerSvgContent = ( svg : string ) =>
332- svg . match (
331+ const hasRenderedSvgGeometry = ( svg : string ) =>
332+ / < ( p a t h | u s e | c i r c l e | r e c t | p o l y g o n | p o l y l i n e | l i n e | e l l i p s e ) \b / . test (
333+ svg . replace ( / < d e f s > [ \s \S ] * ?< \/ d e f s > / g, "" ) ,
334+ )
335+
336+ const getGerberLayerSvgContent = ( svg : string , layerName : string ) => {
337+ const contentMatch = svg . match (
333338 / < g t r a n s f o r m = " [ ^ " ] + " f i l l = " c u r r e n t C o l o r " s t r o k e = " c u r r e n t C o l o r " > ( [ \s \S ] * ?) < \/ g > < \/ s v g > $ / ,
334- ) ?. [ 1 ] ?? ""
339+ )
340+ if ( contentMatch ) return contentMatch [ 1 ]
341+
342+ if ( ! hasRenderedSvgGeometry ( svg ) ) return ""
343+
344+ throw new Error (
345+ `Could not extract rendered SVG content for Gerber layer "${ layerName } "` ,
346+ )
347+ }
335348
336349const renderGerberLayerOverlaySvg = async (
337350 gerberOutput : Record < string , string > ,
@@ -352,7 +365,7 @@ const renderGerberLayerOverlaySvg = async (
352365 svg,
353366 viewBox : parseSvgViewBox ( svg ) ,
354367 defs : getSvgDefsContent ( svg ) ,
355- content : getGerberLayerSvgContent ( svg ) ,
368+ content : getGerberLayerSvgContent ( svg , layerName ) ,
356369 }
357370 } ) ,
358371 )
0 commit comments