Skip to content

Commit eec452f

Browse files
patch
1 parent eda1ece commit eec452f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tests/fixtures/preload.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,23 @@ const getUnionViewBox = (
328328
const getSvgDefsContent = (svg: string) =>
329329
svg.match(/<defs>([\s\S]*?)<\/defs>/)?.[1] ?? ""
330330

331-
const getGerberLayerSvgContent = (svg: string) =>
332-
svg.match(
331+
const hasRenderedSvgGeometry = (svg: string) =>
332+
/<(path|use|circle|rect|polygon|polyline|line|ellipse)\b/.test(
333+
svg.replace(/<defs>[\s\S]*?<\/defs>/g, ""),
334+
)
335+
336+
const getGerberLayerSvgContent = (svg: string, layerName: string) => {
337+
const contentMatch = svg.match(
333338
/<g transform="[^"]+" fill="currentColor" stroke="currentColor">([\s\S]*?)<\/g><\/svg>$/,
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

336349
const 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

Comments
 (0)