-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
// This module contains convenient helper functions return ElementSetup.
import { type ElementSetup } from "./dom.js";
import { effect, isReactive, type ReactiveOrStatic } from "./signals.js";
export function classList<T extends Element>(
...values: readonly ReactiveOrStatic<string | null>[]
): ElementSetup<T> {
return (el) => {
for (const value of values) {
if (isReactive(value)) {
effect(() => {
const v = value.get();
if (v) {
el.classList.add(v);
return () => {
el.classList.remove(v);
};
}
});
continue;
}
if (value) {
el.classList.add(value);
}
}
};
}
export function style<T extends HTMLElement | SVGElement>(
name: string,
value: ReactiveOrStatic<string | null>,
): ElementSetup<T> {
return (el) => {
if (isReactive(value)) {
effect(() => {
const v = value.get();
if (v === null) {
el.style.removeProperty(name);
return;
}
el.style.setProperty(name, v);
});
return;
}
if (value === null) {
el.style.removeProperty(name);
return;
}
el.style.setProperty(name, value);
};
}