@floegence/floe-webapp-core 0.101.35 → 0.101.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/ThemeContext.js +55 -54
- package/dist/full.js +187 -181
- package/dist/index.js +87 -81
- package/dist/primitives.css +4 -2
- package/dist/styles.css +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { createComponent as he } from "solid-js/web";
|
|
2
|
-
import { untrack as ae, createSignal as p, createEffect as
|
|
2
|
+
import { untrack as ae, createSignal as p, createEffect as g, createMemo as G, onCleanup as H } from "solid-js";
|
|
3
3
|
import { createSimpleContext as fe } from "./createSimpleContext.js";
|
|
4
4
|
import { useResolvedFloeConfig as ue } from "./FloeConfigContext.js";
|
|
5
|
-
import { isFloeSurfaceStyle as w, applySurfaceStyleAttribute as I, isThemeType as de, getSystemTheme as
|
|
5
|
+
import { isFloeSurfaceStyle as w, applySurfaceStyleAttribute as I, isThemeType as de, getSystemTheme as Se, applyTheme as ye, applyShellThemeAttribute as J, resolveThemeTokens as pe, syncThemeTokenOverrides as U } from "../styles/themes/index.js";
|
|
6
6
|
import { normalizeShellThemeSelection as W, presetSupportsMode as X } from "../styles/themes/presets.js";
|
|
7
|
-
function
|
|
7
|
+
function v(o, s, r) {
|
|
8
8
|
if (s.length !== 0)
|
|
9
|
-
return o && s.some((
|
|
9
|
+
return o && s.some((n) => n.name === o) ? o : r && s.some((n) => n.name === r) ? r : s[0]?.name;
|
|
10
10
|
}
|
|
11
11
|
function Y(o) {
|
|
12
|
-
const s = ue(), r = o ?? (typeof document > "u" ? void 0 : document.documentElement),
|
|
12
|
+
const s = ue(), r = o ?? (typeof document > "u" ? void 0 : document.documentElement), n = o ? {
|
|
13
13
|
light: o.classList.contains("light"),
|
|
14
14
|
dark: o.classList.contains("dark"),
|
|
15
15
|
colorScheme: o.style.getPropertyValue("color-scheme"),
|
|
16
16
|
colorSchemePriority: o.style.getPropertyPriority("color-scheme"),
|
|
17
17
|
material: o.getAttribute("data-floe-surface-style"),
|
|
18
|
-
shell: o.getAttribute("data-floe-shell-theme")
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
shell: o.getAttribute("data-floe-shell-theme"),
|
|
19
|
+
themeScope: o.getAttribute("data-floe-theme")
|
|
20
|
+
} : void 0, P = /* @__PURE__ */ new Map(), L = (e) => {
|
|
21
|
+
const t = P.get(e);
|
|
21
22
|
t?.value ? o?.style.setProperty(e, t.value, t.priority) : o?.style.removeProperty(e);
|
|
22
23
|
};
|
|
23
24
|
let M = !1;
|
|
@@ -26,95 +27,95 @@ function Y(o) {
|
|
|
26
27
|
const [N, _] = p(w(k) ? k : T), ee = (e) => {
|
|
27
28
|
_(w(e) ? e : T);
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
-
const te = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], b = () => s.config.theme.presetStorageKey ?? `${f()}-preset`, u = () =>
|
|
30
|
+
g(() => I(N(), r));
|
|
31
|
+
const te = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], b = () => s.config.theme.presetStorageKey ?? `${f()}-preset`, u = () => v(s.config.theme.defaultPreset, c()), h = () => s.config.theme.shellPresets ?? [], F = () => s.config.theme.shellPresetStorageKey ?? `${f()}-shell-preset`, V = () => s.config.theme.defaultShellPreset ?? {}, O = s.persist.load(f(), $()), oe = de(O) ? O : $(), [x, se] = p(oe), re = s.persist.load(b(), u()), [A, j] = p(v(re, c(), u())), ne = s.persist.load(F(), void 0), [K, q] = p(W(ne, h(), V())), [le, ie] = p(Se());
|
|
31
32
|
let d = [];
|
|
32
33
|
const z = G(() => {
|
|
33
|
-
const e =
|
|
34
|
+
const e = v(A(), c(), u());
|
|
34
35
|
if (e)
|
|
35
36
|
return c().find((t) => t.name === e);
|
|
36
|
-
}),
|
|
37
|
+
}), S = () => {
|
|
37
38
|
const e = x();
|
|
38
39
|
return e === "system" ? le() : e;
|
|
39
40
|
}, Q = (e) => {
|
|
40
|
-
const t =
|
|
41
|
+
const t = K()[e];
|
|
41
42
|
if (t)
|
|
42
|
-
return h().find((
|
|
43
|
-
}, R = G(() => Q(
|
|
44
|
-
if (
|
|
45
|
-
const e =
|
|
46
|
-
|
|
47
|
-
}),
|
|
48
|
-
const e =
|
|
43
|
+
return h().find((l) => l.name === t && X(l, e));
|
|
44
|
+
}, R = G(() => Q(S()));
|
|
45
|
+
if (g(() => {
|
|
46
|
+
const e = v(A(), c(), u());
|
|
47
|
+
A() !== e && j(e);
|
|
48
|
+
}), g(() => {
|
|
49
|
+
const e = K(), t = W(e, h(), V());
|
|
49
50
|
(e.light !== t.light || e.dark !== t.dark) && q(t);
|
|
50
51
|
}), typeof window < "u") {
|
|
51
|
-
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (
|
|
52
|
-
ie(
|
|
52
|
+
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (l) => {
|
|
53
|
+
ie(l.matches ? "dark" : "light");
|
|
53
54
|
};
|
|
54
55
|
e.addEventListener("change", t), H(() => e.removeEventListener("change", t));
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
const e = x(), t =
|
|
58
|
-
|
|
59
|
-
const m = pe(t, te(),
|
|
57
|
+
g(() => {
|
|
58
|
+
const e = x(), t = S(), l = R();
|
|
59
|
+
o && o.setAttribute("data-floe-theme", ""), ye(e, r), J(l?.name, r);
|
|
60
|
+
const m = pe(t, te(), l?.tokens, z()?.tokens);
|
|
60
61
|
if (o)
|
|
61
|
-
for (const
|
|
62
|
-
|
|
63
|
-
value: o.style.getPropertyValue(
|
|
64
|
-
priority: o.style.getPropertyPriority(
|
|
62
|
+
for (const i of Object.keys(m))
|
|
63
|
+
P.has(i) || P.set(i, {
|
|
64
|
+
value: o.style.getPropertyValue(i),
|
|
65
|
+
priority: o.style.getPropertyPriority(i)
|
|
65
66
|
});
|
|
66
|
-
const
|
|
67
|
-
if (d = U(m,
|
|
68
|
-
for (const
|
|
67
|
+
const y = d;
|
|
68
|
+
if (d = U(m, y, r), o)
|
|
69
|
+
for (const i of y) d.includes(i) || L(i);
|
|
69
70
|
r && queueMicrotask(() => {
|
|
70
71
|
if (M) return;
|
|
71
|
-
const
|
|
72
|
+
const i = /* @__PURE__ */ new Set();
|
|
72
73
|
for (; ; ) {
|
|
73
74
|
const D = (r.getAnimations?.({
|
|
74
75
|
subtree: !0
|
|
75
|
-
}) ?? []).filter((a) => !
|
|
76
|
+
}) ?? []).filter((a) => !i.has(a) && "transitionProperty" in a && /(^|-)color$|^(fill|stroke|box-shadow)$/.test(String(a.transitionProperty)));
|
|
76
77
|
if (D.length === 0) break;
|
|
77
78
|
for (const a of D)
|
|
78
|
-
|
|
79
|
+
i.add(a), a.finish();
|
|
79
80
|
}
|
|
80
81
|
});
|
|
81
82
|
}), H(() => {
|
|
82
|
-
if (M = !0, I(void 0, r), J(void 0, r), d = U(void 0, d, r), o &&
|
|
83
|
-
o.classList.toggle("light",
|
|
84
|
-
for (const [e, t] of [["data-floe-surface-style",
|
|
83
|
+
if (M = !0, I(void 0, r), J(void 0, r), d = U(void 0, d, r), o && n) {
|
|
84
|
+
o.classList.toggle("light", n.light), o.classList.toggle("dark", n.dark), n.colorScheme ? o.style.setProperty("color-scheme", n.colorScheme, n.colorSchemePriority) : o.style.removeProperty("color-scheme");
|
|
85
|
+
for (const [e, t] of [["data-floe-surface-style", n.material], ["data-floe-shell-theme", n.shell], ["data-floe-theme", n.themeScope]])
|
|
85
86
|
t === null ? o.removeAttribute(e) : o.setAttribute(e, t);
|
|
86
|
-
for (const e of
|
|
87
|
+
for (const e of P.keys()) L(e);
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
const C = (e) => {
|
|
90
91
|
se(e), s.persist.debouncedSave(f(), e);
|
|
91
92
|
}, ce = () => {
|
|
92
|
-
const e =
|
|
93
|
+
const e = S();
|
|
93
94
|
C(e === "light" ? "dark" : "light");
|
|
94
95
|
}, me = (e) => {
|
|
95
|
-
const t =
|
|
96
|
+
const t = v(e, c(), u());
|
|
96
97
|
if (j(t), !t) {
|
|
97
98
|
s.persist.remove(b());
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
100
101
|
s.persist.debouncedSave(b(), t);
|
|
101
102
|
}, B = (e, t) => {
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
const m =
|
|
105
|
-
if (m[e] ===
|
|
106
|
-
const
|
|
103
|
+
const l = h().find((i) => i.name === t && X(i, e));
|
|
104
|
+
if (!l) return !1;
|
|
105
|
+
const m = K();
|
|
106
|
+
if (m[e] === l.name) return !0;
|
|
107
|
+
const y = {
|
|
107
108
|
...m,
|
|
108
109
|
version: 1,
|
|
109
|
-
[e]:
|
|
110
|
+
[e]: l.name
|
|
110
111
|
};
|
|
111
|
-
return q(
|
|
112
|
+
return q(y), s.persist.debouncedSave(F(), y), !0;
|
|
112
113
|
};
|
|
113
114
|
return {
|
|
114
115
|
surfaceStyle: N,
|
|
115
116
|
setSurfaceStyle: ee,
|
|
116
117
|
theme: x,
|
|
117
|
-
resolvedTheme:
|
|
118
|
+
resolvedTheme: S,
|
|
118
119
|
setTheme: C,
|
|
119
120
|
toggleTheme: ce,
|
|
120
121
|
themePresets: c,
|
|
@@ -126,8 +127,8 @@ function Y(o) {
|
|
|
126
127
|
setShellPreset: (e) => {
|
|
127
128
|
const t = h().find((m) => m.name === e);
|
|
128
129
|
if (!t) return;
|
|
129
|
-
const
|
|
130
|
-
B(
|
|
130
|
+
const l = t.mode === "light" || t.mode === "dark" ? t.mode : S();
|
|
131
|
+
B(l, e);
|
|
131
132
|
},
|
|
132
133
|
selectShellTheme: (e, t) => {
|
|
133
134
|
B(e, t) && C(e);
|
|
@@ -137,7 +138,7 @@ function Y(o) {
|
|
|
137
138
|
const Z = fe({
|
|
138
139
|
name: "Theme",
|
|
139
140
|
init: Y
|
|
140
|
-
}),
|
|
141
|
+
}), Ke = Z.use;
|
|
141
142
|
function Ce(o) {
|
|
142
143
|
const s = Y(ae(() => o.target));
|
|
143
144
|
return he(Z.Context.Provider, {
|
|
@@ -150,5 +151,5 @@ function Ce(o) {
|
|
|
150
151
|
export {
|
|
151
152
|
Ce as ThemeProvider,
|
|
152
153
|
Y as createThemeService,
|
|
153
|
-
|
|
154
|
+
Ke as useTheme
|
|
154
155
|
};
|