Skip to content

Commit 2a835a9

Browse files
fix svg width redeclaretion
1 parent ef62dfe commit 2a835a9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app/generate/page.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,25 @@ export default function UploadPage() {
202202
};
203203

204204
const fixSvg = (svg: string) => {
205-
// Find width and height in the <svg> tag
205+
// get width/height
206206
const widthMatch = svg.match(/width="(\d+)"/);
207207
const heightMatch = svg.match(/height="(\d+)"/);
208208

209209
if (widthMatch && heightMatch) {
210210
const width = widthMatch[1];
211211
const height = heightMatch[1];
212212

213-
// If no viewBox exists, inject one
213+
// make width/height to 100%
214+
svg = svg
215+
.replace(/width="[^"]*"/, 'width="100%"')
216+
.replace(/height="[^"]*"/, 'height="100%"');
217+
218+
// add viewBox if missing
214219
if (!/viewBox=/.test(svg)) {
215220
svg = svg.replace(
216221
/<svg([^>]*)>/,
217-
`<svg$1 viewBox="0 0 ${width} ${height}" width="100%" height="100%">`,
222+
`<svg$1 viewBox="0 0 ${width} ${height}">`
218223
);
219-
} else {
220-
// Still normalize width/height
221-
svg = svg
222-
.replace(/width="[^"]*"/, 'width="100%"')
223-
.replace(/height="[^"]*"/, 'height="100%"');
224224
}
225225
}
226226

0 commit comments

Comments
 (0)