@floegence/floe-webapp-core 0.101.34 → 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.
@@ -4,6 +4,8 @@ export interface FloeProviderProps {
4
4
  children: JSX.Element;
5
5
  /** Global Floe configuration (storage, keybinds, strings, defaults). */
6
6
  config?: DeepPartial<FloeConfig>;
7
+ /** Stable owned element for embedded theme tokens and palette motion. */
8
+ themeTarget?: HTMLElement;
7
9
  /**
8
10
  * Allows consumers to inject their own providers *after* ThemeProvider,
9
11
  * while ensuring the inner tree is created inside the injected provider.
@@ -3,22 +3,22 @@ import { FloeConfigProvider as i } from "../context/FloeConfigContext.js";
3
3
  import { ThemeProvider as n } from "../context/ThemeContext.js";
4
4
  import { NotificationProvider as m } from "../context/NotificationContext.js";
5
5
  import { ComponentRegistryProvider as d } from "../context/ComponentRegistry.js";
6
- import { LayoutProvider as c } from "../context/LayoutContext.js";
7
- import { CommandProvider as f } from "../context/CommandContext.js";
8
- import { WidgetRegistryProvider as g } from "../context/WidgetRegistry.js";
6
+ import { LayoutProvider as g } from "../context/LayoutContext.js";
7
+ import { CommandProvider as c } from "../context/CommandContext.js";
8
+ import { WidgetRegistryProvider as f } from "../context/WidgetRegistry.js";
9
9
  import { DeckProvider as h } from "../context/DeckContext.js";
10
10
  function w(e) {
11
11
  const t = () => r(m, {
12
12
  get children() {
13
13
  return r(d, {
14
14
  get children() {
15
- return r(c, {
15
+ return r(g, {
16
16
  get children() {
17
- return r(g, {
17
+ return r(f, {
18
18
  get children() {
19
19
  return r(h, {
20
20
  get children() {
21
- return r(f, {
21
+ return r(c, {
22
22
  get children() {
23
23
  return e.children;
24
24
  }
@@ -39,6 +39,9 @@ function w(e) {
39
39
  },
40
40
  get children() {
41
41
  return r(n, {
42
+ get target() {
43
+ return e.themeTarget;
44
+ },
42
45
  get children() {
43
46
  return o(() => !!e.wrapAfterTheme)() ? e.wrapAfterTheme(t) : t();
44
47
  }
@@ -1,4 +1,4 @@
1
- import { type Accessor } from 'solid-js';
1
+ import { type Accessor, type JSX } from 'solid-js';
2
2
  import { type FloeShellThemeMode, type FloeThemePreset, type ThemeType, type FloeSurfaceStyle } from '../styles/themes';
3
3
  export interface ThemeContextValue {
4
4
  surfaceStyle: Accessor<FloeSurfaceStyle>;
@@ -16,7 +16,11 @@ export interface ThemeContextValue {
16
16
  setShellPreset: (presetName: string) => void;
17
17
  selectShellTheme: (mode: FloeShellThemeMode, presetName: string) => void;
18
18
  }
19
- export declare function createThemeService(): ThemeContextValue;
20
- export declare const ThemeProvider: (props: {
21
- children: import("solid-js").JSX.Element;
22
- }) => import("solid-js").JSX.Element, useTheme: () => ThemeContextValue;
19
+ /** An explicit target is owned for this service's lifetime. Its theme changes
20
+ * and palette motion never reach an enclosing document or sibling surface. */
21
+ export declare function createThemeService(target?: HTMLElement): ThemeContextValue;
22
+ export declare const useTheme: () => ThemeContextValue;
23
+ export declare function ThemeProvider(props: {
24
+ children: JSX.Element; /** Stable owned element; omitted uses the document root. */
25
+ target?: HTMLElement;
26
+ }): JSX.Element;
@@ -1,118 +1,155 @@
1
- import { createSignal as u, createEffect as p, createMemo as z, onCleanup as O } from "solid-js";
2
- import { createSimpleContext as ee } from "./createSimpleContext.js";
3
- import { useResolvedFloeConfig as te } from "./FloeConfigContext.js";
4
- import { isFloeSurfaceStyle as b, applySurfaceStyleAttribute as Q, isThemeType as se, getSystemTheme as re, applyTheme as oe, applyShellThemeAttribute as R, syncThemeTokenOverrides as V, resolveThemeTokens as ne } from "../styles/themes/index.js";
5
- import { normalizeShellThemeSelection as j, presetSupportsMode as B } from "../styles/themes/presets.js";
6
- function S(s, o, l) {
7
- if (o.length !== 0)
8
- return s && o.some((m) => m.name === s) ? s : l && o.some((m) => m.name === l) ? l : o[0]?.name;
1
+ import { createComponent as he } from "solid-js/web";
2
+ import { untrack as ae, createSignal as p, createEffect as g, createMemo as G, onCleanup as H } from "solid-js";
3
+ import { createSimpleContext as fe } from "./createSimpleContext.js";
4
+ import { useResolvedFloeConfig as ue } from "./FloeConfigContext.js";
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
+ import { normalizeShellThemeSelection as W, presetSupportsMode as X } from "../styles/themes/presets.js";
7
+ function v(o, s, r) {
8
+ if (s.length !== 0)
9
+ return o && s.some((n) => n.name === o) ? o : r && s.some((n) => n.name === r) ? r : s[0]?.name;
9
10
  }
10
- function ce() {
11
- const s = te(), o = () => s.config.theme.storageKey, l = () => s.config.theme.defaultTheme, m = () => s.config.theme.surfaceStyleStorageKey ?? `${o()}-surface-style`, T = "soft-neumorphic", y = s.persist.load(m(), T);
12
- b(y) || s.persist.remove(m());
13
- const [w, D] = u(b(y) ? y : T), G = (e) => {
14
- D(b(e) ? e : T);
11
+ function Y(o) {
12
+ const s = ue(), r = o ?? (typeof document > "u" ? void 0 : document.documentElement), n = o ? {
13
+ light: o.classList.contains("light"),
14
+ dark: o.classList.contains("dark"),
15
+ colorScheme: o.style.getPropertyValue("color-scheme"),
16
+ colorSchemePriority: o.style.getPropertyPriority("color-scheme"),
17
+ material: o.getAttribute("data-floe-surface-style"),
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);
22
+ t?.value ? o?.style.setProperty(e, t.value, t.priority) : o?.style.removeProperty(e);
15
23
  };
16
- p(() => Q(w()));
17
- const H = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], v = () => s.config.theme.presetStorageKey ?? `${o()}-preset`, a = () => S(s.config.theme.defaultPreset, c()), h = () => s.config.theme.shellPresets ?? [], M = () => s.config.theme.shellPresetStorageKey ?? `${o()}-shell-preset`, $ = () => s.config.theme.defaultShellPreset ?? {}, C = s.persist.load(o(), l()), I = se(C) ? C : l(), [P, J] = u(I), U = s.persist.load(v(), a()), [k, E] = u(S(U, c(), a())), W = s.persist.load(M(), void 0), [K, A] = u(j(W, h(), $())), [X, Y] = u(re());
18
- let g = [];
19
- const F = z(() => {
20
- const e = S(k(), c(), a());
24
+ let M = !1;
25
+ const f = () => s.config.theme.storageKey, $ = () => s.config.theme.defaultTheme, E = () => s.config.theme.surfaceStyleStorageKey ?? `${f()}-surface-style`, T = "soft-neumorphic", k = s.persist.load(E(), T);
26
+ w(k) || s.persist.remove(E());
27
+ const [N, _] = p(w(k) ? k : T), ee = (e) => {
28
+ _(w(e) ? e : T);
29
+ };
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());
32
+ let d = [];
33
+ const z = G(() => {
34
+ const e = v(A(), c(), u());
21
35
  if (e)
22
36
  return c().find((t) => t.name === e);
23
- }), f = () => {
24
- const e = P();
25
- return e === "system" ? X() : e;
26
- }, N = (e) => {
37
+ }), S = () => {
38
+ const e = x();
39
+ return e === "system" ? le() : e;
40
+ }, Q = (e) => {
27
41
  const t = K()[e];
28
42
  if (t)
29
- return h().find((r) => r.name === t && B(r, e));
30
- }, L = z(() => N(f()));
31
- if (p(() => {
32
- const e = S(k(), c(), a());
33
- k() !== e && E(e);
34
- }), p(() => {
35
- const e = K(), t = j(e, h(), $());
36
- (e.light !== t.light || e.dark !== t.dark) && A(t);
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());
50
+ (e.light !== t.light || e.dark !== t.dark) && q(t);
37
51
  }), typeof window < "u") {
38
- const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (r) => {
39
- Y(r.matches ? "dark" : "light");
52
+ const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (l) => {
53
+ ie(l.matches ? "dark" : "light");
40
54
  };
41
- e.addEventListener("change", t), O(() => e.removeEventListener("change", t));
55
+ e.addEventListener("change", t), H(() => e.removeEventListener("change", t));
42
56
  }
43
- p(() => {
44
- const e = P(), t = f(), r = L();
45
- oe(e), R(r?.name), g = V(ne(t, H(), r?.tokens, F()?.tokens), g), typeof document < "u" && queueMicrotask(() => {
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);
61
+ if (o)
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)
66
+ });
67
+ const y = d;
68
+ if (d = U(m, y, r), o)
69
+ for (const i of y) d.includes(i) || L(i);
70
+ r && queueMicrotask(() => {
71
+ if (M) return;
46
72
  const i = /* @__PURE__ */ new Set();
47
73
  for (; ; ) {
48
- const d = (document.documentElement.getAnimations?.({
74
+ const D = (r.getAnimations?.({
49
75
  subtree: !0
50
- }) ?? []).filter((n) => !i.has(n) && "transitionProperty" in n && /(^|-)color$|^(fill|stroke|box-shadow)$/.test(String(n.transitionProperty)));
51
- if (d.length === 0) break;
52
- for (const n of d)
53
- i.add(n), n.finish();
76
+ }) ?? []).filter((a) => !i.has(a) && "transitionProperty" in a && /(^|-)color$|^(fill|stroke|box-shadow)$/.test(String(a.transitionProperty)));
77
+ if (D.length === 0) break;
78
+ for (const a of D)
79
+ i.add(a), a.finish();
54
80
  }
55
81
  });
56
- }), O(() => {
57
- Q(void 0), R(void 0), g = V(void 0, g);
82
+ }), H(() => {
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]])
86
+ t === null ? o.removeAttribute(e) : o.setAttribute(e, t);
87
+ for (const e of P.keys()) L(e);
88
+ }
58
89
  });
59
- const x = (e) => {
60
- J(e), s.persist.debouncedSave(o(), e);
61
- }, Z = () => {
62
- const e = f();
63
- x(e === "light" ? "dark" : "light");
64
- }, _ = (e) => {
65
- const t = S(e, c(), a());
66
- if (E(t), !t) {
67
- s.persist.remove(v());
90
+ const C = (e) => {
91
+ se(e), s.persist.debouncedSave(f(), e);
92
+ }, ce = () => {
93
+ const e = S();
94
+ C(e === "light" ? "dark" : "light");
95
+ }, me = (e) => {
96
+ const t = v(e, c(), u());
97
+ if (j(t), !t) {
98
+ s.persist.remove(b());
68
99
  return;
69
100
  }
70
- s.persist.debouncedSave(v(), t);
71
- }, q = (e, t) => {
72
- const r = h().find((n) => n.name === t && B(n, e));
73
- if (!r) return !1;
74
- const i = K();
75
- if (i[e] === r.name) return !0;
76
- const d = {
77
- ...i,
101
+ s.persist.debouncedSave(b(), t);
102
+ }, B = (e, t) => {
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 = {
108
+ ...m,
78
109
  version: 1,
79
- [e]: r.name
110
+ [e]: l.name
80
111
  };
81
- return A(d), s.persist.debouncedSave(M(), d), !0;
112
+ return q(y), s.persist.debouncedSave(F(), y), !0;
82
113
  };
83
114
  return {
84
- surfaceStyle: w,
85
- setSurfaceStyle: G,
86
- theme: P,
87
- resolvedTheme: f,
88
- setTheme: x,
89
- toggleTheme: Z,
115
+ surfaceStyle: N,
116
+ setSurfaceStyle: ee,
117
+ theme: x,
118
+ resolvedTheme: S,
119
+ setTheme: C,
120
+ toggleTheme: ce,
90
121
  themePresets: c,
91
- themePreset: F,
92
- setThemePreset: _,
122
+ themePreset: z,
123
+ setThemePreset: me,
93
124
  shellPresets: h,
94
- shellPreset: L,
95
- shellPresetForMode: N,
125
+ shellPreset: R,
126
+ shellPresetForMode: Q,
96
127
  setShellPreset: (e) => {
97
- const t = h().find((i) => i.name === e);
128
+ const t = h().find((m) => m.name === e);
98
129
  if (!t) return;
99
- const r = t.mode === "light" || t.mode === "dark" ? t.mode : f();
100
- q(r, e);
130
+ const l = t.mode === "light" || t.mode === "dark" ? t.mode : S();
131
+ B(l, e);
101
132
  },
102
133
  selectShellTheme: (e, t) => {
103
- q(e, t) && x(e);
134
+ B(e, t) && C(e);
104
135
  }
105
136
  };
106
137
  }
107
- const {
108
- Provider: ue,
109
- use: Se
110
- } = ee({
138
+ const Z = fe({
111
139
  name: "Theme",
112
- init: ce
113
- });
140
+ init: Y
141
+ }), Ke = Z.use;
142
+ function Ce(o) {
143
+ const s = Y(ae(() => o.target));
144
+ return he(Z.Context.Provider, {
145
+ value: s,
146
+ get children() {
147
+ return o.children;
148
+ }
149
+ });
150
+ }
114
151
  export {
115
- ue as ThemeProvider,
116
- ce as createThemeService,
117
- Se as useTheme
152
+ Ce as ThemeProvider,
153
+ Y as createThemeService,
154
+ Ke as useTheme
118
155
  };