Skip to content

Commit 93dfd1e

Browse files
committed
function for parsing image sizes
1 parent c0ee072 commit 93dfd1e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class ConfigClass {
8585

8686
inputElement!.addEventListener("input", updateDisplayedValue);
8787
}
88-
88+
8989
else if (type === "image") {
9090
const imageFile = await zip.file(widget_object.file)?.async("blob");
9191

@@ -94,8 +94,8 @@ export class ConfigClass {
9494

9595
img.src = URL.createObjectURL(imageFile);
9696

97-
if (widget_object.width) img.style = `max-width: ${typeof widget_object.width === "string" ? widget_object.width : widget_object.width.toString() + "px"};`;
98-
else if (widget_object.height) img.style = `max-height: ${typeof widget_object.height === "string" ? widget_object.height : widget_object.height.toString() + "px"};`;
97+
if (widget_object.width) img.style = `max-width: ${parseImageSize(widget_object.width)};`;
98+
else if (widget_object.height) img.style = `max-height: ${parseImageSize(widget_object.height)};`;
9999
}
100100
}
101101

@@ -210,6 +210,10 @@ export class ConfigClass {
210210

211211
}
212212

213+
function parseImageSize(dimension: string | number) {
214+
return typeof dimension === "string" ? dimension : dimension.toString() + "px";
215+
}
216+
213217
function getElementSuffix(element: NumberWidget | SliderWidget) {
214218
let suffix = "";
215219

0 commit comments

Comments
 (0)