aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2023-10-03 09:32:35 +0100
committerHayleigh Thompson <me@hayleigh.dev>2023-10-03 09:32:35 +0100
commit5e40f3e0388f865631e82f910f2a90dd9edad741 (patch)
treeea0c469cf154d11e5abb125367bf2b7d12cb675b
parent6aa65a01dc85edbf341102291064ba9743f5f338 (diff)
downloadlustre-5e40f3e0388f865631e82f910f2a90dd9edad741.tar.gz
lustre-5e40f3e0388f865631e82f910f2a90dd9edad741.zip
:sparkles: Merge style attributes at runtime.
-rw-r--r--src/runtime.ffi.mjs34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/runtime.ffi.mjs b/src/runtime.ffi.mjs
index 9b61ee5..bbc76b4 100644
--- a/src/runtime.ffi.mjs
+++ b/src/runtime.ffi.mjs
@@ -43,14 +43,13 @@ function createElement(prev, curr, ns, dispatch, parent = null) {
let attr = curr[1];
while (attr.head) {
- morphAttr(
- el,
- attr.head[0],
- attr.head[0] === "class" && el.className
- ? `${el.className} ${attr.head[1]}`
- : attr.head[1],
- dispatch
- );
+ if (attr.head[0] === "class") {
+ morphAttr(el, attr.head[0], `${el.className} ${attr.head[1]}`);
+ } else if (attr.head[0] === "style") {
+ morphAttr(el, attr.head[0], `${el.style.cssText} ${attr.head[1]}`);
+ } else {
+ morphAttr(el, attr.head[0], attr.head[1], dispatch);
+ }
attr = attr.tail;
}
@@ -93,12 +92,19 @@ function morphElement(prev, curr, ns, dispatch, parent) {
let currAttr = curr[1];
while (currAttr.head) {
- currAttrs.set(
- currAttr.head[0],
- currAttr.head[0] === "class" && currAttrs.has("class")
- ? `${currAttrs.get("class")} ${currAttr.head[1]}`
- : currAttr.head[1]
- );
+ if (currAttr.head[0] === "class" && currAttrs.has("class")) {
+ currAttrs.set(
+ currAttr.head[0],
+ `${currAttrs.get("class")} ${currAttr.head[1]}`
+ );
+ } else if (currAttr.head[0] === "style" && currAttrs.has("style")) {
+ currAttrs.set(
+ currAttr.head[0],
+ `${currAttrs.get("style")} ${currAttr.head[1]}`
+ );
+ } else {
+ currAttrs.set(currAttr.head[0], currAttr.head[1]);
+ }
currAttr = currAttr.tail;
}