Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/renderer/modules/style.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { NSVElement } from "../../dom";
import { NormalizedStyle } from "@vue/shared";

type Style = string | null;
type Style = string | Record<string, string | number> | null;

function normalizeStyle(style: NormalizedStyle | Style): NormalizedStyle {
if (!style) {
return null;
}

if (typeof style === "string" && style?.trim().charAt(0) === "{") {
return JSON.parse(style);
if (typeof style === "string") {
if (style?.trim().charAt(0) === "{") {
return JSON.parse(style);
}
// todo: check if a style can be a string but not json?
}

return style as NormalizedStyle;
Expand Down Expand Up @@ -51,7 +54,14 @@ function removeStyleProperty(el: NSVElement, property: string) {
// changing the attribute will not update our originalValue, so when removing
// the previous color will be applied. Fixing this would involve listening to
// individual attribute changes, and it's not worth the overhead.
el.style[property] = originalValue;
try {
el.style[property] = originalValue;
} catch (err) {
// hack: if the original value is invalid, we can't set it back to it's original value
// instead we set it to null, which will remove the style, however this may
// still lead to incorrect styling in some cases.
el.style[property] = null;
}
}
}

Expand Down