@ramme-io/ui 5.3.0 → 5.4.0

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,22 +1,32 @@
1
1
  import { jsx as c } from "react/jsx-runtime";
2
- import { memo as m, useState as l, useEffect as u } from "react";
2
+ import { memo as l, useState as u, useEffect as f } from "react";
3
3
  import I from "lucide-react/dynamicIconImports";
4
- const f = ({ name: o, className: i, ...t }) => {
5
- const [n, s] = l(null);
6
- return u(() => {
7
- let e = !0;
4
+ const a = ({ name: o, className: t, ...e }) => {
5
+ const [n, d] = u(null);
6
+ if (f(() => {
7
+ let i = !0;
8
8
  return (async () => {
9
9
  try {
10
- const r = await I[o]();
11
- e && s(() => r.default);
10
+ const s = await I[o]();
11
+ i && d(() => s.default);
12
12
  } catch {
13
13
  console.error(`Icon not found: ${o}`);
14
14
  }
15
15
  })(), () => {
16
- e = !1;
16
+ i = !1;
17
17
  };
18
- }, [o]), n ? /* @__PURE__ */ c(n, { className: i, ...t }) : /* @__PURE__ */ c("span", { style: { height: t.size || 24, width: t.size || 24, display: "inline-block" } });
19
- }, h = m(f);
18
+ }, [o]), n)
19
+ return /* @__PURE__ */ c(n, { className: t, ...e });
20
+ const m = !e.size && /(^|\s)(h|w|size)-/.test(t ?? ""), r = e.size || 24;
21
+ return /* @__PURE__ */ c(
22
+ "span",
23
+ {
24
+ "aria-hidden": "true",
25
+ className: ["inline-block shrink-0", t].filter(Boolean).join(" "),
26
+ style: m ? void 0 : { height: r, width: r }
27
+ }
28
+ );
29
+ }, w = l(a);
20
30
  export {
21
- h as Icon
31
+ w as Icon
22
32
  };
@@ -47,6 +47,12 @@ interface ThemeContextType {
47
47
  setFontSize: (size: string) => void;
48
48
  customTheme: ThemeConfig | null;
49
49
  setCustomTheme: (config: ThemeConfig | null) => void;
50
+ /**
51
+ * True while the browser is printing. <html> carries `data-ramme-print`
52
+ * meanwhile, which index.css answers with the light palette; anything that
53
+ * reads tokens in JavaScript (useChartTheme) re-reads on this.
54
+ */
55
+ isPrinting: boolean;
50
56
  }
51
57
  export interface ThemeProviderProps {
52
58
  children: React.ReactNode;
@@ -1,6 +1,8 @@
1
- import { jsx as W } from "react/jsx-runtime";
2
- import { useState as h, useEffect as M, useCallback as S, useMemo as X, createContext as Z, useContext as ee } from "react";
3
- const E = [
1
+ import { jsx as Z } from "react/jsx-runtime";
2
+ import { useState as f, useEffect as $, useCallback as S, useMemo as ee, createContext as oe, useContext as re } from "react";
3
+ import { flushSync as te } from "react-dom";
4
+ import { DERIVED_THEME_VARS as ae } from "../lib/theme/themeUtils.js";
5
+ const M = [
4
6
  "light",
5
7
  "dark",
6
8
  "system",
@@ -8,7 +10,7 @@ const E = [
8
10
  "midnight",
9
11
  "blueprint",
10
12
  "markets"
11
- ], p = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace', K = {
13
+ ], p = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace', q = {
12
14
  light: {
13
15
  sans: '"Inter", system-ui, sans-serif',
14
16
  serif: "Georgia, serif",
@@ -46,7 +48,7 @@ const E = [
46
48
  serif: "Georgia, serif",
47
49
  mono: `"Menlo", ${p}`
48
50
  }
49
- }, oe = 550, re = 100, V = {
51
+ }, se = 550, ne = 100, J = {
50
52
  name: "TAY Dreamboat",
51
53
  borderRadius: "0.5rem",
52
54
  fonts: {
@@ -102,37 +104,37 @@ const E = [
102
104
  danger: "239 68 68",
103
105
  dangerForeground: "255 255 255"
104
106
  }
105
- }, J = Z(void 0), q = {
106
- [V.name]: V
107
- }, se = ({
108
- children: T,
107
+ }, j = oe(void 0), U = {
108
+ [J.name]: J
109
+ }, pe = ({
110
+ children: w,
109
111
  defaultTheme: l,
110
- defaultCustomTheme: i,
112
+ defaultCustomTheme: d,
111
113
  appId: L,
112
114
  instanceConfig: c
113
115
  }) => {
114
- var O, z, G;
115
- const v = (O = c == null ? void 0 : c.fonts) == null ? void 0 : O.sans, F = (z = c == null ? void 0 : c.fonts) == null ? void 0 : z.serif, R = (G = c == null ? void 0 : c.fonts) == null ? void 0 : G.mono, t = L ? `ramme:theme:${L}` : "ramme:theme:global", [f, $] = h(() => {
116
+ var G, H, V;
117
+ const E = (G = c == null ? void 0 : c.fonts) == null ? void 0 : G.sans, F = (H = c == null ? void 0 : c.fonts) == null ? void 0 : H.serif, R = (V = c == null ? void 0 : c.fonts) == null ? void 0 : V.mono, t = L ? `ramme:theme:${L}` : "ramme:theme:global", [b, v] = f(() => {
116
118
  if (typeof window < "u") {
117
119
  const o = localStorage.getItem(`${t}:mode`);
118
- return i && !o ? l || "system" : o && E.includes(o) ? o : l || "system";
120
+ return d && !o ? l || "system" : o && M.includes(o) ? o : l || "system";
119
121
  }
120
122
  return l || "system";
121
- }), [x, _] = h("light"), [u, k] = h("0.5rem"), [w, I] = h("1rem"), [a, b] = h(() => {
123
+ }), [x, _] = f("light"), [u, I] = f("0.5rem"), [T, k] = f("1rem"), [a, y] = f(() => {
122
124
  if (typeof window < "u") {
123
125
  const o = localStorage.getItem(`${t}:custom`);
124
126
  if (o)
125
127
  try {
126
128
  const e = JSON.parse(o);
127
- return e != null && e.name && q[e.name] ? q[e.name] : e;
129
+ return e != null && e.name && U[e.name] ? U[e.name] : e;
128
130
  } catch {
129
131
  }
130
- if (i && !o)
131
- return i;
132
+ if (d && !o)
133
+ return d;
132
134
  }
133
- return i || null;
135
+ return d || null;
134
136
  });
135
- M(() => {
137
+ $(() => {
136
138
  if (typeof window < "u") {
137
139
  const o = window.matchMedia("(prefers-color-scheme: dark)");
138
140
  _(o.matches ? "dark" : "light");
@@ -140,34 +142,34 @@ const E = [
140
142
  _(g.matches ? "dark" : "light");
141
143
  };
142
144
  o.addEventListener("change", e);
143
- const d = localStorage.getItem(`${t}:borderRadius`), A = localStorage.getItem(`${t}:fontSize`);
144
- return d && k(d), A && I(A), () => o.removeEventListener("change", e);
145
+ const i = localStorage.getItem(`${t}:borderRadius`), A = localStorage.getItem(`${t}:fontSize`);
146
+ return i && I(i), A && k(A), () => o.removeEventListener("change", e);
145
147
  }
146
- }, [i, t]);
147
- const B = S(() => {
148
- localStorage.removeItem(`${t}:mode`), localStorage.removeItem(`${t}:custom`), localStorage.removeItem(`${t}:borderRadius`), localStorage.removeItem(`${t}:fontSize`), k("0.5rem"), I("1rem"), i ? ($("system"), b(i)) : l ? ($(l), b(null)) : ($("system"), b(null));
149
- }, [l, i, t]), N = S((o) => {
150
- $(o), localStorage.setItem(`${t}:mode`, o), ["light", "dark", "system"].includes(o) || (b(null), localStorage.removeItem(`${t}:custom`));
148
+ }, [d, t]);
149
+ const D = S(() => {
150
+ localStorage.removeItem(`${t}:mode`), localStorage.removeItem(`${t}:custom`), localStorage.removeItem(`${t}:borderRadius`), localStorage.removeItem(`${t}:fontSize`), I("0.5rem"), k("1rem"), d ? (v("system"), y(d)) : l ? (v(l), y(null)) : (v("system"), y(null));
151
+ }, [l, d, t]), P = S((o) => {
152
+ v(o), localStorage.setItem(`${t}:mode`, o), ["light", "dark", "system"].includes(o) || (y(null), localStorage.removeItem(`${t}:custom`));
153
+ }, [t]), B = S((o) => {
154
+ y(o), o ? localStorage.setItem(`${t}:custom`, JSON.stringify(o)) : localStorage.removeItem(`${t}:custom`);
155
+ }, [t]), N = S((o) => {
156
+ I(o), localStorage.setItem(`${t}:borderRadius`, o);
151
157
  }, [t]), Y = S((o) => {
152
- b(o), o ? localStorage.setItem(`${t}:custom`, JSON.stringify(o)) : localStorage.removeItem(`${t}:custom`);
153
- }, [t]), D = S((o) => {
154
- k(o), localStorage.setItem(`${t}:borderRadius`, o);
155
- }, [t]), P = S((o) => {
156
- I(o), localStorage.setItem(`${t}:fontSize`, o);
158
+ k(o), localStorage.setItem(`${t}:fontSize`, o);
157
159
  }, [t]);
158
- M(() => {
160
+ $(() => {
159
161
  const o = document.documentElement;
160
162
  let e;
161
- const d = requestAnimationFrame(() => {
162
- e = window.setTimeout(() => o.setAttribute("data-theme-ready", ""), re);
163
+ const i = requestAnimationFrame(() => {
164
+ e = window.setTimeout(() => o.setAttribute("data-theme-ready", ""), ne);
163
165
  });
164
166
  return () => {
165
- cancelAnimationFrame(d), e !== void 0 && window.clearTimeout(e), o.removeAttribute("data-theme-ready");
167
+ cancelAnimationFrame(i), e !== void 0 && window.clearTimeout(e), o.removeAttribute("data-theme-ready");
166
168
  };
167
- }, []), M(() => {
169
+ }, []), $(() => {
168
170
  const o = document.documentElement;
169
- E.forEach((s) => o.classList.remove(s)), o.classList.remove("custom-theme");
170
- const e = (s, n) => o.style.setProperty(s, n), d = (s) => o.style.removeProperty(s), A = [
171
+ M.forEach((s) => o.classList.remove(s)), o.classList.remove("custom-theme");
172
+ const e = (s, n) => o.style.setProperty(s, n), i = (s) => o.style.removeProperty(s), A = [
171
173
  "system-ui",
172
174
  "Inter",
173
175
  "Georgia",
@@ -191,12 +193,12 @@ const E = [
191
193
  if (Array.from(
192
194
  document.querySelectorAll('link[rel="stylesheet"]')
193
195
  ).some((m) => new RegExp(`family=${r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?=[:&]|$)`).test(m.href.toLowerCase()))) return;
194
- const C = `google-font-${n.replace(/\s+/g, "-")}`;
195
- if (!document.getElementById(C)) {
196
+ const K = `google-font-${n.replace(/\s+/g, "-")}`;
197
+ if (!document.getElementById(K)) {
196
198
  const m = document.createElement("link");
197
- m.id = C, m.rel = "stylesheet", m.href = `https://fonts.googleapis.com/css2?family=${n.replace(/\s+/g, "+")}:wght@400;500;600;700&display=swap`, document.head.appendChild(m);
199
+ m.id = K, m.rel = "stylesheet", m.href = `https://fonts.googleapis.com/css2?family=${n.replace(/\s+/g, "+")}:wght@400;500;600;700&display=swap`, document.head.appendChild(m);
198
200
  }
199
- }, j = [
201
+ }, W = [
200
202
  "--app-primary-color",
201
203
  "--app-primary-foreground-color",
202
204
  "--app-secondary-color",
@@ -226,56 +228,71 @@ const E = [
226
228
  "--app-font-size-base",
227
229
  "--app-border-radius-sm",
228
230
  "--app-border-radius-md",
229
- "--app-border-radius-lg"
230
- ], y = f === "system" ? x : f;
231
+ "--app-border-radius-lg",
232
+ // ThemeLab paints through applyThemeToDom, which also writes these.
233
+ "--app-surface-hover",
234
+ ...ae
235
+ ], h = b === "system" ? x : b;
231
236
  if (a) {
232
237
  o.classList.add("custom-theme");
233
- const s = y === "dark" || y === "midnight" || y === "markets";
238
+ const s = h === "dark" || h === "midnight" || h === "markets";
234
239
  s && o.classList.add("dark");
235
240
  const n = a.colors, r = s ? a.darkColors || n : a.lightColors || n;
236
241
  if (!r) {
237
242
  console.error("ThemeEngine: Invalid customTheme payload", a);
238
243
  return;
239
244
  }
240
- e("--app-primary-color", r.primary), e("--app-primary-foreground-color", r.primaryForeground), e("--app-secondary-color", r.secondary), e("--app-secondary-foreground-color", r.secondaryForeground), e("--app-accent-color", r.accent), e("--app-accent-foreground-color", r.accentForeground), e("--app-danger-color", r.danger), e("--app-danger-foreground-color", r.dangerForeground), r.success ? e("--app-success-color", r.success) : d("--app-success-color"), r.warning ? e("--app-warning-color", r.warning) : d("--app-warning-color"), e("--app-bg-color", r.background), e("--app-card-bg-color", r.card), e("--app-text-color", r.text), e("--app-border-color", r.border), e("--app-muted-bg", r.muted), e("--app-muted-text", r.mutedForeground), e("--app-input-bg-color", r.input), e("--app-input-border-color", r.inputBorder), e("--app-input-focus-ring-color", r.ring), e("--app-table-header-bg", r.muted), e("--app-table-header-text", r.text), e("--app-table-row-hover-bg", r.muted), e("--app-table-grid-line-color", r.border), a.fonts && (g(a.fonts.sans), a.fonts.serif && g(a.fonts.serif), e("--app-font-serif", a.fonts.serif), e("--app-font-sans", a.fonts.sans), e("--app-font-mono", a.fonts.mono)), document.body.style.backgroundColor = `rgb(${r.background})`, document.body.style.color = `rgb(${r.text})`, e("--app-border-radius-md", a.borderRadius), e("--app-border-radius-sm", `calc(${a.borderRadius} - 0.25rem)`), e("--app-border-radius-lg", `calc(${a.borderRadius} + 0.25rem)`);
245
+ e("--app-primary-color", r.primary), e("--app-primary-foreground-color", r.primaryForeground), e("--app-secondary-color", r.secondary), e("--app-secondary-foreground-color", r.secondaryForeground), e("--app-accent-color", r.accent), e("--app-accent-foreground-color", r.accentForeground), e("--app-danger-color", r.danger), e("--app-danger-foreground-color", r.dangerForeground), r.success ? e("--app-success-color", r.success) : i("--app-success-color"), r.warning ? e("--app-warning-color", r.warning) : i("--app-warning-color"), e("--app-bg-color", r.background), e("--app-card-bg-color", r.card), e("--app-text-color", r.text), e("--app-border-color", r.border), e("--app-muted-bg", r.muted), e("--app-muted-text", r.mutedForeground), e("--app-input-bg-color", r.input), e("--app-input-border-color", r.inputBorder), e("--app-input-focus-ring-color", r.ring), e("--app-table-header-bg", r.muted), e("--app-table-header-text", r.text), e("--app-table-row-hover-bg", r.muted), e("--app-table-grid-line-color", r.border), a.fonts && (g(a.fonts.sans), a.fonts.serif && g(a.fonts.serif), e("--app-font-serif", a.fonts.serif), e("--app-font-sans", a.fonts.sans), e("--app-font-mono", a.fonts.mono)), document.body.style.backgroundColor = `rgb(${r.background})`, document.body.style.color = `rgb(${r.text})`, e("--app-border-radius-md", a.borderRadius), e("--app-border-radius-sm", `calc(${a.borderRadius} - 0.25rem)`), e("--app-border-radius-lg", `calc(${a.borderRadius} + 0.25rem)`);
241
246
  } else {
242
- o.classList.add(y), j.forEach(d);
243
- const s = K[y] || K.light, n = v || s.sans, r = F || s.serif, H = R || s.mono;
244
- v || g(n), F || g(r), e("--app-font-sans", n), e("--app-font-serif", r), e("--app-font-mono", H), document.body.style.backgroundColor = "", document.body.style.color = "", e("--app-border-radius-md", u), e("--app-border-radius-sm", `calc(${u} - 0.25rem)`), e("--app-border-radius-lg", `calc(${u} + 0.25rem)`);
247
+ o.classList.add(h), W.forEach(i);
248
+ const s = q[h] || q.light, n = E || s.sans, r = F || s.serif, C = R || s.mono;
249
+ E || g(n), F || g(r), e("--app-font-sans", n), e("--app-font-serif", r), e("--app-font-mono", C), document.body.style.backgroundColor = "", document.body.style.color = "", e("--app-border-radius-md", u), e("--app-border-radius-sm", `calc(${u} - 0.25rem)`), e("--app-border-radius-lg", `calc(${u} + 0.25rem)`);
245
250
  }
246
- if (e("--app-font-size-base", w), !o.hasAttribute("data-theme-ready")) return;
251
+ if (e("--app-font-size-base", T), !o.hasAttribute("data-theme-ready")) return;
247
252
  o.setAttribute("data-theme-morphing", "");
248
- const Q = window.setTimeout(
253
+ const X = window.setTimeout(
249
254
  () => o.removeAttribute("data-theme-morphing"),
250
- oe
255
+ se
251
256
  );
252
- return () => window.clearTimeout(Q);
253
- }, [f, x, a, u, w, v, F, R]);
254
- const U = X(
257
+ return () => window.clearTimeout(X);
258
+ }, [b, x, a, u, T, E, F, R]);
259
+ const [O, z] = f(!1);
260
+ $(() => {
261
+ const o = document.documentElement, e = () => {
262
+ o.setAttribute("data-ramme-print", ""), te(() => z(!0));
263
+ }, i = () => {
264
+ o.removeAttribute("data-ramme-print"), z(!1);
265
+ };
266
+ return window.addEventListener("beforeprint", e), window.addEventListener("afterprint", i), () => {
267
+ window.removeEventListener("beforeprint", e), window.removeEventListener("afterprint", i), o.removeAttribute("data-ramme-print");
268
+ };
269
+ }, []);
270
+ const Q = ee(
255
271
  () => ({
256
- theme: f,
257
- availableThemes: E,
258
- setTheme: N,
259
- resetTheme: B,
272
+ theme: b,
273
+ availableThemes: M,
274
+ setTheme: P,
275
+ resetTheme: D,
260
276
  borderRadius: u,
261
- setBorderRadius: D,
262
- fontSize: w,
263
- setFontSize: P,
277
+ setBorderRadius: N,
278
+ fontSize: T,
279
+ setFontSize: Y,
264
280
  customTheme: a,
265
- setCustomTheme: Y
281
+ setCustomTheme: B,
282
+ isPrinting: O
266
283
  }),
267
- [f, N, B, u, D, w, P, a, Y]
284
+ [b, P, D, u, N, T, Y, a, B, O]
268
285
  );
269
- return /* @__PURE__ */ W(J.Provider, { value: U, children: T });
270
- }, ne = () => {
271
- const T = ee(J);
272
- if (T === void 0)
286
+ return /* @__PURE__ */ Z(j.Provider, { value: Q, children: w });
287
+ }, le = () => {
288
+ const w = re(j);
289
+ if (w === void 0)
273
290
  throw new Error("useTheme must be used within a ThemeProvider");
274
- return T;
291
+ return w;
275
292
  };
276
293
  export {
277
- V as TAY_DREAMBOAT_THEME,
278
- se as ThemeProvider,
279
- E as availableThemes,
280
- ne as useTheme
294
+ J as TAY_DREAMBOAT_THEME,
295
+ pe as ThemeProvider,
296
+ M as availableThemes,
297
+ le as useTheme
281
298
  };