File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 99 */
1010export function extractSvgDimensions ( svgContent : string ) : { width : number ; height : number } {
1111 // Try to get dimensions from viewBox first
12- const viewBoxMatch = svgContent . match ( / v i e w B o x = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ) ;
12+ const viewBoxRegex = / v i e w B o x = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ;
13+ const viewBoxMatch = viewBoxRegex . exec ( svgContent ) ;
1314 if ( viewBoxMatch ) {
1415 const [ , , width , height ] = viewBoxMatch [ 1 ] . split ( / \s + / ) . map ( Number ) ;
1516 // Check that both width and height are valid numbers (not NaN and not undefined)
@@ -19,8 +20,10 @@ export function extractSvgDimensions(svgContent: string): { width: number; heigh
1920 }
2021
2122 // Try to get from width/height attributes
22- const widthMatch = svgContent . match ( / w i d t h = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ) ;
23- const heightMatch = svgContent . match ( / h e i g h t = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ) ;
23+ const widthRegex = / w i d t h = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ;
24+ const widthMatch = widthRegex . exec ( svgContent ) ;
25+ const heightRegex = / h e i g h t = [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ;
26+ const heightMatch = heightRegex . exec ( svgContent ) ;
2427
2528 const width = widthMatch ? Number . parseInt ( widthMatch [ 1 ] , 10 ) : 200 ;
2629 const height = heightMatch ? Number . parseInt ( heightMatch [ 1 ] , 10 ) : 100 ;
You can’t perform that action at this time.
0 commit comments