@floegence/floe-webapp-core 0.101.34 → 0.101.35

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,154 @@
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 P, 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 ye, applyTheme as Se, 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 g(o, s, r) {
8
+ if (s.length !== 0)
9
+ return o && s.some((i) => i.name === o) ? o : r && s.some((i) => i.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), i = 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
+ } : void 0, v = /* @__PURE__ */ new Map(), L = (e) => {
20
+ const t = v.get(e);
21
+ t?.value ? o?.style.setProperty(e, t.value, t.priority) : o?.style.removeProperty(e);
15
22
  };
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());
23
+ let M = !1;
24
+ 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);
25
+ w(k) || s.persist.remove(E());
26
+ const [N, _] = p(w(k) ? k : T), ee = (e) => {
27
+ _(w(e) ? e : T);
28
+ };
29
+ P(() => I(N(), r));
30
+ const te = () => s.config.theme.tokens, c = () => s.config.theme.presets ?? [], b = () => s.config.theme.presetStorageKey ?? `${f()}-preset`, u = () => g(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()), [K, j] = p(g(re, c(), u())), ne = s.persist.load(F(), void 0), [A, q] = p(W(ne, h(), V())), [le, ie] = p(ye());
31
+ let d = [];
32
+ const z = G(() => {
33
+ const e = g(K(), c(), u());
21
34
  if (e)
22
35
  return c().find((t) => t.name === e);
23
- }), f = () => {
24
- const e = P();
25
- return e === "system" ? X() : e;
26
- }, N = (e) => {
27
- const t = K()[e];
36
+ }), y = () => {
37
+ const e = x();
38
+ return e === "system" ? le() : e;
39
+ }, Q = (e) => {
40
+ const t = A()[e];
28
41
  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);
42
+ return h().find((n) => n.name === t && X(n, e));
43
+ }, R = G(() => Q(y()));
44
+ if (P(() => {
45
+ const e = g(K(), c(), u());
46
+ K() !== e && j(e);
47
+ }), P(() => {
48
+ const e = A(), t = W(e, h(), V());
49
+ (e.light !== t.light || e.dark !== t.dark) && q(t);
37
50
  }), typeof window < "u") {
38
- const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (r) => {
39
- Y(r.matches ? "dark" : "light");
51
+ const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (n) => {
52
+ ie(n.matches ? "dark" : "light");
40
53
  };
41
- e.addEventListener("change", t), O(() => e.removeEventListener("change", t));
54
+ e.addEventListener("change", t), H(() => e.removeEventListener("change", t));
42
55
  }
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(() => {
46
- const i = /* @__PURE__ */ new Set();
56
+ P(() => {
57
+ const e = x(), t = y(), n = R();
58
+ Se(e, r), J(n?.name, r);
59
+ const m = pe(t, te(), n?.tokens, z()?.tokens);
60
+ if (o)
61
+ for (const l of Object.keys(m))
62
+ v.has(l) || v.set(l, {
63
+ value: o.style.getPropertyValue(l),
64
+ priority: o.style.getPropertyPriority(l)
65
+ });
66
+ const S = d;
67
+ if (d = U(m, S, r), o)
68
+ for (const l of S) d.includes(l) || L(l);
69
+ r && queueMicrotask(() => {
70
+ if (M) return;
71
+ const l = /* @__PURE__ */ new Set();
47
72
  for (; ; ) {
48
- const d = (document.documentElement.getAnimations?.({
73
+ const D = (r.getAnimations?.({
49
74
  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();
75
+ }) ?? []).filter((a) => !l.has(a) && "transitionProperty" in a && /(^|-)color$|^(fill|stroke|box-shadow)$/.test(String(a.transitionProperty)));
76
+ if (D.length === 0) break;
77
+ for (const a of D)
78
+ l.add(a), a.finish();
54
79
  }
55
80
  });
56
- }), O(() => {
57
- Q(void 0), R(void 0), g = V(void 0, g);
81
+ }), H(() => {
82
+ if (M = !0, I(void 0, r), J(void 0, r), d = U(void 0, d, r), o && i) {
83
+ o.classList.toggle("light", i.light), o.classList.toggle("dark", i.dark), i.colorScheme ? o.style.setProperty("color-scheme", i.colorScheme, i.colorSchemePriority) : o.style.removeProperty("color-scheme");
84
+ for (const [e, t] of [["data-floe-surface-style", i.material], ["data-floe-shell-theme", i.shell]])
85
+ t === null ? o.removeAttribute(e) : o.setAttribute(e, t);
86
+ for (const e of v.keys()) L(e);
87
+ }
58
88
  });
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());
89
+ const C = (e) => {
90
+ se(e), s.persist.debouncedSave(f(), e);
91
+ }, ce = () => {
92
+ const e = y();
93
+ C(e === "light" ? "dark" : "light");
94
+ }, me = (e) => {
95
+ const t = g(e, c(), u());
96
+ if (j(t), !t) {
97
+ s.persist.remove(b());
68
98
  return;
69
99
  }
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,
100
+ s.persist.debouncedSave(b(), t);
101
+ }, B = (e, t) => {
102
+ const n = h().find((l) => l.name === t && X(l, e));
103
+ if (!n) return !1;
104
+ const m = A();
105
+ if (m[e] === n.name) return !0;
106
+ const S = {
107
+ ...m,
78
108
  version: 1,
79
- [e]: r.name
109
+ [e]: n.name
80
110
  };
81
- return A(d), s.persist.debouncedSave(M(), d), !0;
111
+ return q(S), s.persist.debouncedSave(F(), S), !0;
82
112
  };
83
113
  return {
84
- surfaceStyle: w,
85
- setSurfaceStyle: G,
86
- theme: P,
87
- resolvedTheme: f,
88
- setTheme: x,
89
- toggleTheme: Z,
114
+ surfaceStyle: N,
115
+ setSurfaceStyle: ee,
116
+ theme: x,
117
+ resolvedTheme: y,
118
+ setTheme: C,
119
+ toggleTheme: ce,
90
120
  themePresets: c,
91
- themePreset: F,
92
- setThemePreset: _,
121
+ themePreset: z,
122
+ setThemePreset: me,
93
123
  shellPresets: h,
94
- shellPreset: L,
95
- shellPresetForMode: N,
124
+ shellPreset: R,
125
+ shellPresetForMode: Q,
96
126
  setShellPreset: (e) => {
97
- const t = h().find((i) => i.name === e);
127
+ const t = h().find((m) => m.name === e);
98
128
  if (!t) return;
99
- const r = t.mode === "light" || t.mode === "dark" ? t.mode : f();
100
- q(r, e);
129
+ const n = t.mode === "light" || t.mode === "dark" ? t.mode : y();
130
+ B(n, e);
101
131
  },
102
132
  selectShellTheme: (e, t) => {
103
- q(e, t) && x(e);
133
+ B(e, t) && C(e);
104
134
  }
105
135
  };
106
136
  }
107
- const {
108
- Provider: ue,
109
- use: Se
110
- } = ee({
137
+ const Z = fe({
111
138
  name: "Theme",
112
- init: ce
113
- });
139
+ init: Y
140
+ }), Ae = Z.use;
141
+ function Ce(o) {
142
+ const s = Y(ae(() => o.target));
143
+ return he(Z.Context.Provider, {
144
+ value: s,
145
+ get children() {
146
+ return o.children;
147
+ }
148
+ });
149
+ }
114
150
  export {
115
- ue as ThemeProvider,
116
- ce as createThemeService,
117
- Se as useTheme
151
+ Ce as ThemeProvider,
152
+ Y as createThemeService,
153
+ Ae as useTheme
118
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.101.34",
3
+ "version": "0.101.35",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",