@floegence/floe-webapp-core 0.35.16 → 0.35.17

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.
@@ -1,5 +1,5 @@
1
1
  import { type JSX } from 'solid-js';
2
- import type { FloeThemeTokenOverrides, ThemeType } from '../styles/themes';
2
+ import type { FloeThemePreset, FloeThemeTokenOverrides, ThemeType } from '../styles/themes';
3
3
  export interface FloeStorageAdapter {
4
4
  getItem: (key: string) => string | null;
5
5
  setItem: (key: string, value: string) => void;
@@ -73,6 +73,12 @@ export interface FloeLayoutConfig {
73
73
  export interface FloeThemeConfig {
74
74
  storageKey: string;
75
75
  defaultTheme: ThemeType;
76
+ /** Optional storage key for the active named token preset. Defaults to `${storageKey}-preset`. */
77
+ presetStorageKey?: string;
78
+ /** Optional default named token preset. Falls back to the first preset when omitted. */
79
+ defaultPreset?: string;
80
+ /** Optional named token presets for switching visual palettes without changing light/dark mode. */
81
+ presets?: readonly FloeThemePreset[];
76
82
  /**
77
83
  * Optional CSS variable overrides applied at the document root.
78
84
  * `shared` applies to both themes, while `light` / `dark` only apply
@@ -1,10 +1,13 @@
1
1
  import { type Accessor } from 'solid-js';
2
- import { type ThemeType } from '../styles/themes';
2
+ import { type FloeThemePreset, type ThemeType } from '../styles/themes';
3
3
  export interface ThemeContextValue {
4
4
  theme: Accessor<ThemeType>;
5
5
  resolvedTheme: Accessor<'light' | 'dark'>;
6
6
  setTheme: (theme: ThemeType) => void;
7
7
  toggleTheme: () => void;
8
+ themePresets: Accessor<readonly FloeThemePreset[]>;
9
+ themePreset: Accessor<FloeThemePreset | undefined>;
10
+ setThemePreset: (presetName: string | undefined) => void;
8
11
  }
9
12
  export declare function createThemeService(): ThemeContextValue;
10
13
  export declare const ThemeProvider: (props: {
@@ -1,48 +1,69 @@
1
- import { createSignal as i, onCleanup as h, createEffect as v } from "solid-js";
2
- import { createSimpleContext as y } from "./createSimpleContext.js";
3
- import { useResolvedFloeConfig as k } from "./FloeConfigContext.js";
4
- import { getSystemTheme as S, applyTheme as C, syncThemeTokenOverrides as a, resolveThemeTokenOverrides as w } from "../styles/themes/index.js";
5
- function E() {
6
- const t = k(), m = () => t.config.theme.storageKey, d = () => t.config.theme.defaultTheme, l = () => t.config.theme.tokens, T = t.persist.load(m(), d()), [r, f] = i(T), [g, u] = i(S());
7
- let o = [];
8
- const s = () => {
9
- const e = r();
10
- return e === "system" ? g() : e;
1
+ import { createSignal as g, createMemo as E, createEffect as p, onCleanup as P } from "solid-js";
2
+ import { createSimpleContext as N } from "./createSimpleContext.js";
3
+ import { useResolvedFloeConfig as L } from "./FloeConfigContext.js";
4
+ import { getSystemTheme as M, applyTheme as F, syncThemeTokenOverrides as y, resolveThemeTokens as O } from "../styles/themes/index.js";
5
+ function i(t, n, r) {
6
+ if (n.length !== 0)
7
+ return t && n.some((m) => m.name === t) ? t : r && n.some((m) => m.name === r) ? r : n[0]?.name;
8
+ }
9
+ function Q() {
10
+ const t = L(), n = () => t.config.theme.storageKey, r = () => t.config.theme.defaultTheme, m = () => t.config.theme.tokens, s = () => t.config.theme.presets ?? [], a = () => t.config.theme.presetStorageKey ?? `${n()}-preset`, c = () => i(t.config.theme.defaultPreset, s()), S = t.persist.load(n(), r()), [d, k] = g(S), x = t.persist.load(a(), c()), [f, l] = g(i(x, s(), c())), [C, K] = g(M());
11
+ let h = [];
12
+ const T = E(() => {
13
+ const e = i(f(), s(), c());
14
+ if (e)
15
+ return s().find((o) => o.name === e);
16
+ }), u = () => {
17
+ const e = d();
18
+ return e === "system" ? C() : e;
11
19
  };
12
- if (typeof window < "u") {
13
- const e = window.matchMedia("(prefers-color-scheme: dark)"), n = (p) => {
14
- u(p.matches ? "dark" : "light");
20
+ if (p(() => {
21
+ const e = i(f(), s(), c());
22
+ f() !== e && l(e);
23
+ }), typeof window < "u") {
24
+ const e = window.matchMedia("(prefers-color-scheme: dark)"), o = (w) => {
25
+ K(w.matches ? "dark" : "light");
15
26
  };
16
- e.addEventListener("change", n), h(() => e.removeEventListener("change", n));
27
+ e.addEventListener("change", o), P(() => e.removeEventListener("change", o));
17
28
  }
18
- v(() => {
19
- const e = r(), n = s();
20
- C(e), o = a(w(l(), n), o);
21
- }), h(() => {
22
- o = a(void 0, o);
29
+ p(() => {
30
+ const e = d(), o = u();
31
+ F(e), h = y(O(o, m(), T()?.tokens), h);
32
+ }), P(() => {
33
+ h = y(void 0, h);
23
34
  });
24
- const c = (e) => {
25
- f(e), t.persist.debouncedSave(m(), e);
35
+ const v = (e) => {
36
+ k(e), t.persist.debouncedSave(n(), e);
26
37
  };
27
38
  return {
28
- theme: r,
29
- resolvedTheme: s,
30
- setTheme: c,
39
+ theme: d,
40
+ resolvedTheme: u,
41
+ setTheme: v,
31
42
  toggleTheme: () => {
32
- const e = s();
33
- c(e === "light" ? "dark" : "light");
43
+ const e = u();
44
+ v(e === "light" ? "dark" : "light");
45
+ },
46
+ themePresets: s,
47
+ themePreset: T,
48
+ setThemePreset: (e) => {
49
+ const o = i(e, s(), c());
50
+ if (l(o), !o) {
51
+ t.persist.remove(a());
52
+ return;
53
+ }
54
+ t.persist.debouncedSave(a(), o);
34
55
  }
35
56
  };
36
57
  }
37
58
  const {
38
- Provider: b,
39
- use: F
40
- } = y({
59
+ Provider: A,
60
+ use: B
61
+ } = N({
41
62
  name: "Theme",
42
- init: E
63
+ init: Q
43
64
  });
44
65
  export {
45
- b as ThemeProvider,
46
- E as createThemeService,
47
- F as useTheme
66
+ A as ThemeProvider,
67
+ Q as createThemeService,
68
+ B as useTheme
48
69
  };