Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: better style binding support#1042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rigor789 merged 4 commits intomainfromfix/hmr-style-reset
Apr 18, 2023
Merged
Changes fromall 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
45 changes: 39 additions & 6 deletionssrc/renderer/modules/style.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
import { NSVElement } from "../../dom";
import { NormalizedStyle } from "@vue/shared";
import {
NormalizedStyle,
parseStringStyle,
isArray,
isString,
isObject,
} 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 (isString(style)) {
if (style.trim().charAt(0) === "{") {
return JSON.parse(style);
}

return parseStringStyle(style);
}

if (isArray(style)) {
return style.reduce(
(
normalizedStyle: NormalizedStyle,
currentStyle: NormalizedStyle | Style
) => {
return Object.assign(normalizedStyle, normalizeStyle(currentStyle));
},
{}
);
}

if (isObject(style)) {
return style as NormalizedStyle;
}

returnstyle as NormalizedStyle;
return{};
}

function normalizeProperty(property: string) {
Expand DownExpand Up@@ -51,7 +77,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

[8]ページ先頭

©2009-2025 Movatter.jp