@floegence/floe-webapp-core 0.101.50 → 0.101.52
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/components/media/ImageAnnotationSurface.js +99 -92
- package/dist/components/ui/ThemePicker.d.ts +2 -0
- package/dist/components/ui/ThemePicker.js +43 -37
- package/dist/components/ui/ThemeStudio.d.ts +11 -0
- package/dist/components/ui/ThemeStudio.js +285 -0
- package/dist/context/FloeConfigContext.d.ts +1 -0
- package/dist/context/ThemeContext.js +43 -43
- package/dist/styles/themes/themeDocument.d.ts +13 -0
- package/dist/styles/themes/themeDocument.js +65 -0
- package/dist/styles.css +1 -1
- package/dist/themes.d.ts +1 -0
- package/dist/themes.js +14 -9
- package/dist/ui.css +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { insert as i, createComponent as a, memo as j, setStyleProperty as s, effect as H, template as y, use as ne, delegateEvents as re } from "solid-js/web";
|
|
2
|
+
import { createSignal as $, createEffect as le, onCleanup as ie, createMemo as E, Show as O, For as K } from "solid-js";
|
|
3
|
+
import { Plus as ae, Pencil as ce, Upload as oe, Download as de, Sparkles as ue, Check as se } from "../icons/index.js";
|
|
4
|
+
import { Button as g } from "./Button.js";
|
|
5
|
+
import { Input as ge, Textarea as ve } from "./Input.js";
|
|
6
|
+
import { Dialog as fe } from "./Dialog.js";
|
|
7
|
+
import { readFloeThemeDocument as q, resolveFloeThemeDocument as me, floeThemeContrastIssue as be, FLOE_THEME_FILE_LIMIT as he } from "../../styles/themes/themeDocument.js";
|
|
8
|
+
var _e = /* @__PURE__ */ y("<div class=floe-theme-studio__actions><input hidden type=file accept=.json,application/json>"), G = /* @__PURE__ */ y("<p role=alert class=floe-theme-picker__error>"), $e = /* @__PURE__ */ y("<div class=floe-theme-studio__body><label></label><div class=floe-theme-studio__sample aria-hidden=true><aside><i></i><i></i><i></i></aside><div><strong>Aa</strong><span></span><section></section></div></div><fieldset><legend></legend><div class=floe-theme-studio__swatches></div></fieldset><details><summary>"), ye = /* @__PURE__ */ y("<i>"), ke = /* @__PURE__ */ y("<label><input type=color>");
|
|
9
|
+
function Le(e) {
|
|
10
|
+
const [L, m] = $(!1), [u, z] = $(!1), [I, k] = $(""), [D, Q] = $(), [w, b] = $("");
|
|
11
|
+
let N, o = 0;
|
|
12
|
+
le(() => {
|
|
13
|
+
e.active || (o++, m(!1), b(""));
|
|
14
|
+
}), ie(() => {
|
|
15
|
+
o++;
|
|
16
|
+
});
|
|
17
|
+
const v = E(() => {
|
|
18
|
+
try {
|
|
19
|
+
return {
|
|
20
|
+
doc: q(I())
|
|
21
|
+
};
|
|
22
|
+
} catch (t) {
|
|
23
|
+
return {
|
|
24
|
+
issue: t instanceof SyntaxError ? "JSON" : t.message
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}), d = E(() => {
|
|
28
|
+
const t = v().doc;
|
|
29
|
+
return t && me("draft", t);
|
|
30
|
+
}), S = E(() => {
|
|
31
|
+
const t = v().doc;
|
|
32
|
+
return t ? be(t) : v().issue;
|
|
33
|
+
}), C = E(() => {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(I());
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}), F = (t, r) => {
|
|
40
|
+
Q(r), k(JSON.stringify(t, null, 2)), b(""), m(!0);
|
|
41
|
+
}, V = async (t) => {
|
|
42
|
+
if (!t || !e.active) return;
|
|
43
|
+
const r = ++o;
|
|
44
|
+
try {
|
|
45
|
+
if (t.size > he) throw new Error("32 KiB");
|
|
46
|
+
const l = q(await t.text());
|
|
47
|
+
r === o && e.active && F(l);
|
|
48
|
+
} catch (l) {
|
|
49
|
+
r === o && b(`${e.label("invalid")}: ${l instanceof SyntaxError ? "JSON" : l.message}`);
|
|
50
|
+
}
|
|
51
|
+
}, W = () => {
|
|
52
|
+
const t = e.current, r = URL.createObjectURL(new Blob([JSON.stringify(t, null, 2) + `
|
|
53
|
+
`], {
|
|
54
|
+
type: "application/json"
|
|
55
|
+
})), l = document.createElement("a");
|
|
56
|
+
l.download = `${t.name.replace(/[^\p{L}\p{N}_-]+/gu, "-").slice(0, 64)}.floe-theme.json`, l.href = r, l.click(), setTimeout(() => URL.revokeObjectURL(r), 1e3);
|
|
57
|
+
}, X = async () => {
|
|
58
|
+
const t = v().doc;
|
|
59
|
+
if (!t || S() || !L() || !e.active || u()) return;
|
|
60
|
+
z(!0), b("");
|
|
61
|
+
const r = o;
|
|
62
|
+
try {
|
|
63
|
+
await e.save(t, D()), r === o && m(!1);
|
|
64
|
+
} catch {
|
|
65
|
+
r === o && b(e.label("failed"));
|
|
66
|
+
} finally {
|
|
67
|
+
z(!1);
|
|
68
|
+
}
|
|
69
|
+
}, Y = ["background", "card", "sidebar", "foreground", "primary", "border"];
|
|
70
|
+
return [(() => {
|
|
71
|
+
var t = _e(), r = t.firstChild;
|
|
72
|
+
r.addEventListener("change", (h) => {
|
|
73
|
+
const x = h.currentTarget.files?.[0];
|
|
74
|
+
h.currentTarget.value = "", V(x);
|
|
75
|
+
});
|
|
76
|
+
var l = N;
|
|
77
|
+
return typeof l == "function" ? ne(l, r) : N = r, i(t, a(g, {
|
|
78
|
+
size: "sm",
|
|
79
|
+
icon: ae,
|
|
80
|
+
variant: "outline",
|
|
81
|
+
get disabled() {
|
|
82
|
+
return !e.active;
|
|
83
|
+
},
|
|
84
|
+
onClick: () => F({
|
|
85
|
+
...e.current,
|
|
86
|
+
name: e.label("create")
|
|
87
|
+
}),
|
|
88
|
+
get children() {
|
|
89
|
+
return e.label("create");
|
|
90
|
+
}
|
|
91
|
+
}), null), i(t, a(O, {
|
|
92
|
+
get when() {
|
|
93
|
+
return e.currentID;
|
|
94
|
+
},
|
|
95
|
+
get children() {
|
|
96
|
+
return a(g, {
|
|
97
|
+
size: "icon",
|
|
98
|
+
icon: ce,
|
|
99
|
+
get disabled() {
|
|
100
|
+
return !e.active;
|
|
101
|
+
},
|
|
102
|
+
variant: "ghost",
|
|
103
|
+
get "aria-label"() {
|
|
104
|
+
return e.label("edit");
|
|
105
|
+
},
|
|
106
|
+
get title() {
|
|
107
|
+
return e.label("edit");
|
|
108
|
+
},
|
|
109
|
+
onClick: () => F(e.current, e.currentID)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}), null), i(t, a(g, {
|
|
113
|
+
size: "icon",
|
|
114
|
+
icon: oe,
|
|
115
|
+
get disabled() {
|
|
116
|
+
return !e.active;
|
|
117
|
+
},
|
|
118
|
+
variant: "ghost",
|
|
119
|
+
get "aria-label"() {
|
|
120
|
+
return e.label("import");
|
|
121
|
+
},
|
|
122
|
+
get title() {
|
|
123
|
+
return e.label("import");
|
|
124
|
+
},
|
|
125
|
+
onClick: () => N.click()
|
|
126
|
+
}), null), i(t, a(g, {
|
|
127
|
+
size: "icon",
|
|
128
|
+
icon: de,
|
|
129
|
+
get disabled() {
|
|
130
|
+
return !e.active;
|
|
131
|
+
},
|
|
132
|
+
variant: "ghost",
|
|
133
|
+
get "aria-label"() {
|
|
134
|
+
return e.label("export");
|
|
135
|
+
},
|
|
136
|
+
get title() {
|
|
137
|
+
return e.label("export");
|
|
138
|
+
},
|
|
139
|
+
onClick: W
|
|
140
|
+
}), null), i(t, a(O, {
|
|
141
|
+
get when() {
|
|
142
|
+
return e.generate;
|
|
143
|
+
},
|
|
144
|
+
get children() {
|
|
145
|
+
return a(g, {
|
|
146
|
+
size: "sm",
|
|
147
|
+
icon: ue,
|
|
148
|
+
get disabled() {
|
|
149
|
+
return !e.active;
|
|
150
|
+
},
|
|
151
|
+
variant: "secondary",
|
|
152
|
+
onClick: () => e.generate?.(e.current),
|
|
153
|
+
get children() {
|
|
154
|
+
return e.label("generate");
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}), null), t;
|
|
159
|
+
})(), a(O, {
|
|
160
|
+
get when() {
|
|
161
|
+
return j(() => !!w())() && !L();
|
|
162
|
+
},
|
|
163
|
+
get children() {
|
|
164
|
+
var t = G();
|
|
165
|
+
return i(t, w), t;
|
|
166
|
+
}
|
|
167
|
+
}), a(fe, {
|
|
168
|
+
get open() {
|
|
169
|
+
return j(() => !!e.active)() && L();
|
|
170
|
+
},
|
|
171
|
+
get title() {
|
|
172
|
+
return e.label(D() ? "edit" : "create");
|
|
173
|
+
},
|
|
174
|
+
get closeLabel() {
|
|
175
|
+
return e.label("cancel");
|
|
176
|
+
},
|
|
177
|
+
onOpenChange: (t) => {
|
|
178
|
+
u() || m(t);
|
|
179
|
+
},
|
|
180
|
+
get footer() {
|
|
181
|
+
return [a(g, {
|
|
182
|
+
variant: "ghost",
|
|
183
|
+
get disabled() {
|
|
184
|
+
return u();
|
|
185
|
+
},
|
|
186
|
+
onClick: () => m(!1),
|
|
187
|
+
get children() {
|
|
188
|
+
return e.label("cancel");
|
|
189
|
+
}
|
|
190
|
+
}), a(g, {
|
|
191
|
+
icon: se,
|
|
192
|
+
get loading() {
|
|
193
|
+
return u();
|
|
194
|
+
},
|
|
195
|
+
get disabled() {
|
|
196
|
+
return !!S();
|
|
197
|
+
},
|
|
198
|
+
onClick: () => {
|
|
199
|
+
X();
|
|
200
|
+
},
|
|
201
|
+
get children() {
|
|
202
|
+
return e.label("save");
|
|
203
|
+
}
|
|
204
|
+
})];
|
|
205
|
+
},
|
|
206
|
+
get children() {
|
|
207
|
+
var t = $e(), r = t.firstChild, l = r.nextSibling, h = l.firstChild, x = h.nextSibling, Z = x.firstChild, R = Z.nextSibling, p = R.nextSibling, J = l.nextSibling, U = J.firstChild, ee = U.nextSibling, P = J.nextSibling, te = P.firstChild;
|
|
208
|
+
return i(r, () => e.label("name"), null), i(r, a(ge, {
|
|
209
|
+
maxLength: 80,
|
|
210
|
+
get value() {
|
|
211
|
+
return j(() => typeof C()?.name == "string")() ? C().name : "";
|
|
212
|
+
},
|
|
213
|
+
get disabled() {
|
|
214
|
+
return u() || !C();
|
|
215
|
+
},
|
|
216
|
+
onInput: (n) => {
|
|
217
|
+
const c = C();
|
|
218
|
+
c && k(JSON.stringify({
|
|
219
|
+
...c,
|
|
220
|
+
name: n.currentTarget.value
|
|
221
|
+
}, null, 2));
|
|
222
|
+
}
|
|
223
|
+
}), null), i(p, a(K, {
|
|
224
|
+
get each() {
|
|
225
|
+
return d()?.preview?.colors;
|
|
226
|
+
},
|
|
227
|
+
children: (n) => (() => {
|
|
228
|
+
var c = ye();
|
|
229
|
+
return s(c, "background", n), c;
|
|
230
|
+
})()
|
|
231
|
+
})), i(U, () => e.label("colors")), i(ee, a(K, {
|
|
232
|
+
each: Y,
|
|
233
|
+
children: (n) => (() => {
|
|
234
|
+
var c = ke(), _ = c.firstChild;
|
|
235
|
+
return _.$$input = (T) => {
|
|
236
|
+
const f = v().doc;
|
|
237
|
+
f && k(JSON.stringify({
|
|
238
|
+
...f,
|
|
239
|
+
colors: {
|
|
240
|
+
...f.colors,
|
|
241
|
+
[`--${n}`]: T.currentTarget.value
|
|
242
|
+
}
|
|
243
|
+
}, null, 2));
|
|
244
|
+
}, i(c, () => e.label(n), null), H(() => _.value = d()?.semanticTokens?.[`--${n}`]), c;
|
|
245
|
+
})()
|
|
246
|
+
})), i(te, () => e.label("advanced")), i(P, a(ve, {
|
|
247
|
+
get "aria-label"() {
|
|
248
|
+
return e.label("advanced");
|
|
249
|
+
},
|
|
250
|
+
get value() {
|
|
251
|
+
return I();
|
|
252
|
+
},
|
|
253
|
+
rows: 9,
|
|
254
|
+
spellcheck: !1,
|
|
255
|
+
get disabled() {
|
|
256
|
+
return u();
|
|
257
|
+
},
|
|
258
|
+
onInput: (n) => k(n.currentTarget.value)
|
|
259
|
+
}), null), i(t, a(O, {
|
|
260
|
+
get when() {
|
|
261
|
+
return w() || S();
|
|
262
|
+
},
|
|
263
|
+
get children() {
|
|
264
|
+
var n = G();
|
|
265
|
+
return i(n, () => w() || `${e.label("invalid")}: ${S()}`), n;
|
|
266
|
+
}
|
|
267
|
+
}), null), H((n) => {
|
|
268
|
+
var c = d()?.preview?.background, _ = d()?.semanticTokens?.["--foreground"], T = d()?.preview?.border, f = d()?.preview?.sidebar, B = d()?.preview?.surface, M = d()?.preview?.primary, A = u() || !v().doc;
|
|
269
|
+
return c !== n.e && s(l, "background", n.e = c), _ !== n.t && s(l, "color", n.t = _), T !== n.a && s(l, "border-color", n.a = T), f !== n.o && s(h, "background", n.o = f), B !== n.i && s(x, "background", n.i = B), M !== n.n && s(R, "background", n.n = M), A !== n.s && (J.disabled = n.s = A), n;
|
|
270
|
+
}, {
|
|
271
|
+
e: void 0,
|
|
272
|
+
t: void 0,
|
|
273
|
+
a: void 0,
|
|
274
|
+
o: void 0,
|
|
275
|
+
i: void 0,
|
|
276
|
+
n: void 0,
|
|
277
|
+
s: void 0
|
|
278
|
+
}), t;
|
|
279
|
+
}
|
|
280
|
+
})];
|
|
281
|
+
}
|
|
282
|
+
re(["input"]);
|
|
283
|
+
export {
|
|
284
|
+
Le as ThemeStudio
|
|
285
|
+
};
|
|
@@ -87,6 +87,7 @@ export interface FloeThemeConfig {
|
|
|
87
87
|
presets?: readonly FloeThemePreset[];
|
|
88
88
|
/** Optional shell-wide presets. Kept separate from product-scoped presets such as chart palettes. */
|
|
89
89
|
shellPresets?: readonly FloeThemePreset[];
|
|
90
|
+
additionalShellPresets?: () => readonly FloeThemePreset[];
|
|
90
91
|
/** Optional per-mode defaults for shell presets. Falls back to the first compatible preset. */
|
|
91
92
|
defaultShellPreset?: Partial<Record<'light' | 'dark', string>>;
|
|
92
93
|
/** Storage key for the versioned per-mode shell preset selection map. */
|
|
@@ -1,10 +1,10 @@
|
|
|
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 v, createMemo as w, 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
|
|
5
|
+
import { isFloeSurfaceStyle as L, 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 P(o, s, r) {
|
|
8
8
|
if (s.length !== 0)
|
|
9
9
|
return o && s.some((n) => n.name === o) ? o : r && s.some((n) => n.name === r) ? r : s[0]?.name;
|
|
10
10
|
}
|
|
@@ -17,74 +17,74 @@ function Y(o) {
|
|
|
17
17
|
material: o.getAttribute("data-floe-surface-style"),
|
|
18
18
|
shell: o.getAttribute("data-floe-shell-theme"),
|
|
19
19
|
themeScope: o.getAttribute("data-floe-theme")
|
|
20
|
-
} : void 0,
|
|
21
|
-
const t =
|
|
20
|
+
} : void 0, g = /* @__PURE__ */ new Map(), M = (e) => {
|
|
21
|
+
const t = g.get(e);
|
|
22
22
|
t?.value ? o?.style.setProperty(e, t.value, t.priority) : o?.style.removeProperty(e);
|
|
23
23
|
};
|
|
24
|
-
let
|
|
25
|
-
const f = () => s.config.theme.storageKey,
|
|
26
|
-
|
|
27
|
-
const [
|
|
28
|
-
_(
|
|
24
|
+
let $ = !1;
|
|
25
|
+
const f = () => s.config.theme.storageKey, E = () => s.config.theme.defaultTheme, N = () => s.config.theme.surfaceStyleStorageKey ?? `${f()}-surface-style`, T = "soft-neumorphic", k = s.persist.load(N(), T);
|
|
26
|
+
L(k) || s.persist.remove(N());
|
|
27
|
+
const [F, _] = p(L(k) ? k : T), ee = (e) => {
|
|
28
|
+
_(L(e) ? e : T);
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
const te = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], b = () => s.config.theme.presetStorageKey ?? `${f()}-preset`, u = () =>
|
|
30
|
+
v(() => I(F(), r));
|
|
31
|
+
const te = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], b = () => s.config.theme.presetStorageKey ?? `${f()}-preset`, u = () => P(s.config.theme.defaultPreset, c()), h = w(() => [...s.config.theme.shellPresets ?? [], ...s.config.theme.additionalShellPresets?.() ?? []]), V = () => s.config.theme.shellPresetStorageKey ?? `${f()}-shell-preset`, O = () => s.config.theme.defaultShellPreset ?? {}, j = s.persist.load(f(), E()), oe = de(j) ? j : E(), [x, se] = p(oe), re = s.persist.load(b(), u()), [A, q] = p(P(re, c(), u())), ne = s.persist.load(V(), void 0), [K, z] = p(W(ne, h(), O())), [le, ie] = p(Se());
|
|
32
32
|
let d = [];
|
|
33
|
-
const
|
|
34
|
-
const e =
|
|
33
|
+
const Q = w(() => {
|
|
34
|
+
const e = P(A(), c(), u());
|
|
35
35
|
if (e)
|
|
36
36
|
return c().find((t) => t.name === e);
|
|
37
37
|
}), S = () => {
|
|
38
38
|
const e = x();
|
|
39
39
|
return e === "system" ? le() : e;
|
|
40
|
-
},
|
|
40
|
+
}, R = (e) => {
|
|
41
41
|
const t = K()[e];
|
|
42
42
|
if (t)
|
|
43
43
|
return h().find((l) => l.name === t && X(l, e));
|
|
44
|
-
},
|
|
45
|
-
if (
|
|
46
|
-
const e =
|
|
47
|
-
A() !== e &&
|
|
48
|
-
}),
|
|
49
|
-
const e = K(), t = W(e, h(),
|
|
50
|
-
(e.light !== t.light || e.dark !== t.dark) &&
|
|
44
|
+
}, B = w(() => R(S()));
|
|
45
|
+
if (v(() => {
|
|
46
|
+
const e = P(A(), c(), u());
|
|
47
|
+
A() !== e && q(e);
|
|
48
|
+
}), v(() => {
|
|
49
|
+
const e = K(), t = W(e, h(), O());
|
|
50
|
+
(e.light !== t.light || e.dark !== t.dark) && z(t);
|
|
51
51
|
}), typeof window < "u") {
|
|
52
52
|
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (l) => {
|
|
53
53
|
ie(l.matches ? "dark" : "light");
|
|
54
54
|
};
|
|
55
55
|
e.addEventListener("change", t), H(() => e.removeEventListener("change", t));
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
const e = x(), t = S(), l =
|
|
57
|
+
v(() => {
|
|
58
|
+
const e = x(), t = S(), l = B();
|
|
59
59
|
o && o.setAttribute("data-floe-theme", ""), ye(e, r), J(l?.name, r);
|
|
60
|
-
const m = pe(t, te(), l?.tokens,
|
|
60
|
+
const m = pe(t, te(), l?.tokens, Q()?.tokens);
|
|
61
61
|
if (o)
|
|
62
62
|
for (const i of Object.keys(m))
|
|
63
|
-
|
|
63
|
+
g.has(i) || g.set(i, {
|
|
64
64
|
value: o.style.getPropertyValue(i),
|
|
65
65
|
priority: o.style.getPropertyPriority(i)
|
|
66
66
|
});
|
|
67
67
|
const y = d;
|
|
68
68
|
if (d = U(m, y, r), o)
|
|
69
|
-
for (const i of y) d.includes(i) ||
|
|
69
|
+
for (const i of y) d.includes(i) || M(i);
|
|
70
70
|
r && queueMicrotask(() => {
|
|
71
|
-
if (
|
|
71
|
+
if ($) return;
|
|
72
72
|
const i = /* @__PURE__ */ new Set();
|
|
73
73
|
for (; ; ) {
|
|
74
|
-
const
|
|
74
|
+
const G = (r.getAnimations?.({
|
|
75
75
|
subtree: !0
|
|
76
76
|
}) ?? []).filter((a) => !i.has(a) && "transitionProperty" in a && /(^|-)color$|^(fill|stroke|box-shadow)$/.test(String(a.transitionProperty)));
|
|
77
|
-
if (
|
|
78
|
-
for (const a of
|
|
77
|
+
if (G.length === 0) break;
|
|
78
|
+
for (const a of G)
|
|
79
79
|
i.add(a), a.finish();
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
}), H(() => {
|
|
83
|
-
if (
|
|
83
|
+
if ($ = !0, I(void 0, r), J(void 0, r), d = U(void 0, d, r), o && n) {
|
|
84
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
85
|
for (const [e, t] of [["data-floe-surface-style", n.material], ["data-floe-shell-theme", n.shell], ["data-floe-theme", n.themeScope]])
|
|
86
86
|
t === null ? o.removeAttribute(e) : o.setAttribute(e, t);
|
|
87
|
-
for (const e of
|
|
87
|
+
for (const e of g.keys()) M(e);
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
const C = (e) => {
|
|
@@ -93,13 +93,13 @@ function Y(o) {
|
|
|
93
93
|
const e = S();
|
|
94
94
|
C(e === "light" ? "dark" : "light");
|
|
95
95
|
}, me = (e) => {
|
|
96
|
-
const t =
|
|
97
|
-
if (
|
|
96
|
+
const t = P(e, c(), u());
|
|
97
|
+
if (q(t), !t) {
|
|
98
98
|
s.persist.remove(b());
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
s.persist.debouncedSave(b(), t);
|
|
102
|
-
},
|
|
102
|
+
}, D = (e, t) => {
|
|
103
103
|
const l = h().find((i) => i.name === t && X(i, e));
|
|
104
104
|
if (!l) return !1;
|
|
105
105
|
const m = K();
|
|
@@ -109,29 +109,29 @@ function Y(o) {
|
|
|
109
109
|
version: 1,
|
|
110
110
|
[e]: l.name
|
|
111
111
|
};
|
|
112
|
-
return
|
|
112
|
+
return z(y), s.persist.debouncedSave(V(), y), !0;
|
|
113
113
|
};
|
|
114
114
|
return {
|
|
115
|
-
surfaceStyle:
|
|
115
|
+
surfaceStyle: F,
|
|
116
116
|
setSurfaceStyle: ee,
|
|
117
117
|
theme: x,
|
|
118
118
|
resolvedTheme: S,
|
|
119
119
|
setTheme: C,
|
|
120
120
|
toggleTheme: ce,
|
|
121
121
|
themePresets: c,
|
|
122
|
-
themePreset:
|
|
122
|
+
themePreset: Q,
|
|
123
123
|
setThemePreset: me,
|
|
124
124
|
shellPresets: h,
|
|
125
|
-
shellPreset:
|
|
126
|
-
shellPresetForMode:
|
|
125
|
+
shellPreset: B,
|
|
126
|
+
shellPresetForMode: R,
|
|
127
127
|
setShellPreset: (e) => {
|
|
128
128
|
const t = h().find((m) => m.name === e);
|
|
129
129
|
if (!t) return;
|
|
130
130
|
const l = t.mode === "light" || t.mode === "dark" ? t.mode : S();
|
|
131
|
-
|
|
131
|
+
D(l, e);
|
|
132
132
|
},
|
|
133
133
|
selectShellTheme: (e, t) => {
|
|
134
|
-
|
|
134
|
+
D(e, t) && C(e);
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FloeThemePreset } from './index';
|
|
2
|
+
export interface FloeThemeDocument {
|
|
3
|
+
version: 1;
|
|
4
|
+
name: string;
|
|
5
|
+
base: string;
|
|
6
|
+
colors: Record<string, string>;
|
|
7
|
+
editor?: Record<string, string>;
|
|
8
|
+
syntax?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare const FLOE_THEME_FILE_LIMIT: number;
|
|
11
|
+
export declare function floeThemeContrastIssue(doc: FloeThemeDocument): string | undefined;
|
|
12
|
+
export declare function readFloeThemeDocument(input: unknown): FloeThemeDocument;
|
|
13
|
+
export declare function resolveFloeThemeDocument(id: string, input: FloeThemeDocument): FloeThemePreset;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { builtInShellThemePresets as k } from "./presets.js";
|
|
2
|
+
const u = 32 * 1024, m = new Map(k.map((r) => [r.name, r])), b = /^#[0-9a-f]{6}$/i, p = /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i, h = (r) => r !== null && typeof r == "object" && !Array.isArray(r);
|
|
3
|
+
function d(r, e, o) {
|
|
4
|
+
if (!h(r)) throw new Error("colors");
|
|
5
|
+
return Object.fromEntries(Object.entries(r).map(([n, t]) => {
|
|
6
|
+
if (!e.includes(n) || typeof t != "string" || !o.test(t)) throw new Error(`colors: ${n.slice(0, 80)}`);
|
|
7
|
+
return [n, t.toLowerCase()];
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
function g(r) {
|
|
11
|
+
const e = [1, 3, 5].map((o) => Number.parseInt(r.slice(o, o + 2), 16) / 255).map((o) => o <= 0.04045 ? o / 12.92 : ((o + 0.055) / 1.055) ** 2.4);
|
|
12
|
+
return e[0] * 0.2126 + e[1] * 0.7152 + e[2] * 0.0722;
|
|
13
|
+
}
|
|
14
|
+
function E(r) {
|
|
15
|
+
const e = { ...m.get(r.base)?.semanticTokens, ...r.colors };
|
|
16
|
+
for (const [o, n] of [["--background", "--foreground"], ["--primary", "--primary-foreground"], ["--card", "--card-foreground"], ["--sidebar", "--sidebar-foreground"]]) {
|
|
17
|
+
if (!r.colors[o] && !r.colors[n]) continue;
|
|
18
|
+
const t = g(e[o]), c = g(e[n]), s = (Math.max(t, c) + 0.05) / (Math.min(t, c) + 0.05);
|
|
19
|
+
if (s < 4.5) return `${n} / ${o}: ${s.toFixed(2)}:1 < 4.5:1`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function y(r) {
|
|
23
|
+
if (typeof r == "string" && (r.length > u || new TextEncoder().encode(r).length > u)) throw new Error("32 KiB");
|
|
24
|
+
const e = typeof r == "string" ? JSON.parse(r) : r;
|
|
25
|
+
if (!h(e) || e.version !== 1 || Object.keys(e).some((c) => !["version", "name", "base", "colors", "editor", "syntax"].includes(c))) throw new Error("version");
|
|
26
|
+
if (typeof e.name != "string" || !e.name.trim() || e.name.length > 80 || /[\p{Cc}\p{Cf}]/u.test(e.name)) throw new Error("name");
|
|
27
|
+
const o = typeof e.base == "string" && m.get(e.base);
|
|
28
|
+
if (!o || o.mode !== "light" && o.mode !== "dark") throw new Error("base");
|
|
29
|
+
const n = o.monaco?.[o.mode], t = d(e.colors, Object.keys(o.semanticTokens ?? {}).filter((c) => !c.includes("shadow")), b);
|
|
30
|
+
return {
|
|
31
|
+
version: 1,
|
|
32
|
+
name: e.name.trim(),
|
|
33
|
+
base: o.name,
|
|
34
|
+
colors: t,
|
|
35
|
+
...e.editor === void 0 ? {} : { editor: d(e.editor, Object.keys(n?.colors ?? {}), p) },
|
|
36
|
+
...e.syntax === void 0 ? {} : { syntax: d(e.syntax, n?.rules.map((c) => c.token) ?? [], b) }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function x(r, e) {
|
|
40
|
+
const o = y(e), n = m.get(o.base), t = n.mode, c = { ...n.semanticTokens, ...o.colors }, s = (a) => c[`--${a}`], i = n.monaco[t], f = { ...i.colors };
|
|
41
|
+
for (const [a, l] of Object.entries({ "editor.background": "--background", "editorGutter.background": "--background", "editor.foreground": "--foreground", "editorCursor.foreground": "--primary", "editor.selectionBackground": "--selection-bg", "editor.selectionForeground": "--selection-fg" }))
|
|
42
|
+
o.colors[l] && (f[a] = o.colors[l]);
|
|
43
|
+
return {
|
|
44
|
+
name: r,
|
|
45
|
+
displayName: o.name,
|
|
46
|
+
mode: t,
|
|
47
|
+
semanticTokens: c,
|
|
48
|
+
tokens: { [t]: c },
|
|
49
|
+
preview: {
|
|
50
|
+
background: s("background"),
|
|
51
|
+
surface: s("card"),
|
|
52
|
+
sidebar: s("sidebar"),
|
|
53
|
+
primary: s("primary"),
|
|
54
|
+
border: s("border"),
|
|
55
|
+
colors: [s("chart-1"), s("chart-2"), s("chart-3"), s("chart-4"), s("chart-5")]
|
|
56
|
+
},
|
|
57
|
+
monaco: { [t]: { ...i, colors: { ...f, ...o.editor }, rules: i.rules.map((a) => ({ ...a, foreground: o.syntax?.[a.token] ?? a.foreground })) } }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
u as FLOE_THEME_FILE_LIMIT,
|
|
62
|
+
E as floeThemeContrastIssue,
|
|
63
|
+
y as readFloeThemeDocument,
|
|
64
|
+
x as resolveFloeThemeDocument
|
|
65
|
+
};
|