@stackone/malachite 2.88.1 → 2.88.2

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/index.d.ts CHANGED
@@ -2096,7 +2096,10 @@ export declare const ForwardArrowIcon: React.FC<IconProps_58>;
2096
2096
  export declare function getCurrentTheme(): MalachiteTheme;
2097
2097
 
2098
2098
  /**
2099
- * Get current theme mode from localStorage
2099
+ * The mode this page is painted in. Once anything has painted it, that is read from the document,
2100
+ * not localStorage: every tab shares the stored mode, so a tab painted light would otherwise mount
2101
+ * dark components because another tab saved dark. Before the first paint it is the saved mode, so
2102
+ * a reload keeps the last choice.
2100
2103
  */
2101
2104
  export declare function getCurrentThemeMode(): 'light' | 'dark';
2102
2105
 
package/dist/theme.js CHANGED
@@ -1093,7 +1093,7 @@ const A = [
1093
1093
  surfaceForeground: "rgb(134, 120, 186)"
1094
1094
  }
1095
1095
  }
1096
- }, O = "malachite-theme-mode", $ = "malachite-custom-theme", R = /^--[A-Za-z0-9_-]+$/, L = /[{};]|\/\*|\*\//, G = /^[A-Za-z0-9_-]+$/;
1096
+ }, O = "malachite-theme-mode", $ = "malachite-custom-theme", G = /^--[A-Za-z0-9_-]+$/, L = /[{};]|\/\*|\*\//, _ = /^[A-Za-z0-9_-]+$/;
1097
1097
  function T(r, l) {
1098
1098
  if (typeof r == "string") {
1099
1099
  if (L.test(r)) {
@@ -1108,7 +1108,7 @@ function T(r, l) {
1108
1108
  const a = {};
1109
1109
  for (const [o, n] of Object.entries(r)) {
1110
1110
  const u = l ? `${l}.${o}` : o;
1111
- if (!G.test(o)) {
1111
+ if (!_.test(o)) {
1112
1112
  console.warn(
1113
1113
  `Malachite: ignoring a theme key under ${l || "<root>"} — theme keys may contain only letters, digits, hyphens and underscores.`
1114
1114
  );
@@ -1120,29 +1120,29 @@ function T(r, l) {
1120
1120
  return a;
1121
1121
  }
1122
1122
  const x = /* @__PURE__ */ new Set();
1123
- function Y(r) {
1123
+ function U(r) {
1124
1124
  try {
1125
1125
  if (x.has(r))
1126
1126
  return;
1127
- x.add(r), D(r);
1127
+ x.add(r), N(r);
1128
1128
  } catch (l) {
1129
1129
  console.error("Error registering shadow root:", l);
1130
1130
  }
1131
1131
  }
1132
- function U(r) {
1132
+ function J(r) {
1133
1133
  try {
1134
1134
  x.delete(r);
1135
1135
  } catch (l) {
1136
1136
  console.error("Error unregistering shadow root:", l);
1137
1137
  }
1138
1138
  }
1139
- const _ = {
1139
+ const D = {
1140
1140
  rowVariant: "row-variant",
1141
1141
  boxShadow: "box-shadow"
1142
1142
  };
1143
1143
  function E(r, l, a) {
1144
1144
  Object.entries(r).forEach(([o, n]) => {
1145
- const u = _[o] ?? o;
1145
+ const u = D[o] ?? o;
1146
1146
  typeof n == "object" && n !== null ? Object.entries(n).forEach(([b, t]) => {
1147
1147
  const d = b.replace(/([A-Z])/g, "-$1").toLowerCase();
1148
1148
  typeof t == "object" && t !== null ? Object.entries(t).forEach(([g, s]) => {
@@ -1241,10 +1241,10 @@ function p(r, l, a = "light") {
1241
1241
  typeof c == "object" && c !== null ? Object.entries(c).forEach(([h, m]) => {
1242
1242
  const B = h.replace(/([A-Z])/g, "-$1").toLowerCase();
1243
1243
  typeof m == "object" && m !== null ? Object.entries(m).forEach(
1244
- ([z, Z]) => {
1245
- const M = z.replace(/([A-Z])/g, "-$1").toLowerCase();
1244
+ ([Z, M]) => {
1245
+ const R = Z.replace(/([A-Z])/g, "-$1").toLowerCase();
1246
1246
  t.push(
1247
- `--malachite-text-${i}-${B}-${M}: ${Z}`
1247
+ `--malachite-text-${i}-${B}-${R}: ${M}`
1248
1248
  );
1249
1249
  }
1250
1250
  ) : t.push(
@@ -1277,7 +1277,7 @@ function p(r, l, a = "light") {
1277
1277
  });
1278
1278
  const g = t.filter((s) => {
1279
1279
  if (!L.test(s)) return !0;
1280
- const c = s.split(":", 1)[0].trim(), i = R.test(c) ? c : "an unnamed token";
1280
+ const c = s.split(":", 1)[0].trim(), i = G.test(c) ? c : "an unnamed token";
1281
1281
  return console.warn(`Malachite: dropped an unsafe theme declaration for ${i}`), !1;
1282
1282
  });
1283
1283
  b.textContent = `:host { color-scheme: ${a}; ${g.join("; ")} }`;
@@ -1402,7 +1402,7 @@ function p(r, l, a = "light") {
1402
1402
  });
1403
1403
  }));
1404
1404
  }
1405
- function D(r) {
1405
+ function N(r) {
1406
1406
  try {
1407
1407
  const l = P(), a = V(), o = l === "dark" ? k : e, n = a ? w(o, a) : o;
1408
1408
  p(n, r, l);
@@ -1410,8 +1410,9 @@ function D(r) {
1410
1410
  console.error("Error applying theme to shadow root:", l);
1411
1411
  }
1412
1412
  }
1413
+ let j = !1;
1413
1414
  function P() {
1414
- return typeof window > "u" ? "light" : localStorage.getItem(O) || "light";
1415
+ return typeof window > "u" ? "light" : j ? document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light" : localStorage.getItem(O) || "light";
1415
1416
  }
1416
1417
  function V() {
1417
1418
  if (typeof window > "u") return null;
@@ -1423,10 +1424,10 @@ function V() {
1423
1424
  return localStorage.removeItem($), null;
1424
1425
  }
1425
1426
  }
1426
- function j(r) {
1427
+ function H(r) {
1427
1428
  typeof window < "u" && localStorage.setItem(O, r);
1428
1429
  }
1429
- function N(r) {
1430
+ function I(r) {
1430
1431
  typeof window < "u" && localStorage.setItem($, JSON.stringify(r));
1431
1432
  }
1432
1433
  function w(r, l) {
@@ -1501,45 +1502,45 @@ function w(r, l) {
1501
1502
  }
1502
1503
  return o;
1503
1504
  }
1504
- function I(r) {
1505
- N(r);
1505
+ function W(r) {
1506
+ I(r);
1506
1507
  const l = P(), o = w(l === "dark" ? k : e, r);
1507
1508
  p(o, document.documentElement), x.forEach((n) => {
1508
1509
  p(o, n, l);
1509
1510
  }), C(l);
1510
1511
  }
1511
- function J(r, l) {
1512
+ function q(r, l) {
1512
1513
  const a = l === "dark" ? k : e, o = V(), n = o ? w(a, o) : a;
1513
1514
  p(n, r, l);
1514
1515
  }
1515
1516
  const C = (r) => {
1516
- r === "dark" ? document.documentElement.setAttribute("data-theme", "dark") : document.documentElement.removeAttribute("data-theme");
1517
+ j = !0, r === "dark" ? document.documentElement.setAttribute("data-theme", "dark") : document.documentElement.removeAttribute("data-theme");
1517
1518
  };
1518
- function H() {
1519
- j("light"), C("light");
1519
+ function K() {
1520
+ H("light"), C("light");
1520
1521
  const r = V(), l = r ? w(e, r) : e;
1521
1522
  p(l, document.documentElement), x.forEach((a) => {
1522
1523
  p(l, a, "light");
1523
1524
  });
1524
1525
  }
1525
- function K() {
1526
- j("dark"), C("dark");
1526
+ function z() {
1527
+ H("dark"), C("dark");
1527
1528
  const r = V(), l = r ? w(k, r) : k;
1528
1529
  p(l, document.documentElement), x.forEach((a) => {
1529
1530
  p(l, a, "dark");
1530
1531
  });
1531
1532
  }
1532
- function q() {
1533
- return P() === "dark" ? (H(), "light") : (K(), "dark");
1533
+ function X() {
1534
+ return P() === "dark" ? (K(), "light") : (z(), "dark");
1534
1535
  }
1535
- function X(r) {
1536
- I(r);
1536
+ function Q(r) {
1537
+ W(r);
1537
1538
  }
1538
- function Q() {
1539
+ function rr() {
1539
1540
  const r = P();
1540
- localStorage.removeItem($), r === "dark" ? K() : H();
1541
+ localStorage.removeItem($), r === "dark" ? z() : K();
1541
1542
  }
1542
- function W() {
1543
+ function Y() {
1543
1544
  if (typeof window < "u") {
1544
1545
  const r = P(), l = V();
1545
1546
  if (r === "dark")
@@ -1556,7 +1557,7 @@ function W() {
1556
1557
  C(r);
1557
1558
  }
1558
1559
  }
1559
- function rr() {
1560
+ function er() {
1560
1561
  const r = getComputedStyle(document.documentElement), l = {};
1561
1562
  for (const a of A) {
1562
1563
  const o = r.getPropertyValue(v(a)).trim();
@@ -1987,25 +1988,25 @@ function rr() {
1987
1988
  };
1988
1989
  }
1989
1990
  let S = !1;
1990
- const er = () => {
1991
- S || (S = !0, W());
1991
+ const or = () => {
1992
+ S || (S = !0, Y());
1992
1993
  };
1993
1994
  export {
1994
1995
  f as CONTROL_HEIGHT,
1995
- X as applyCustomTheme,
1996
- K as applyDarkTheme,
1997
- H as applyLightTheme,
1998
- I as applyTheme,
1999
- J as applyThemeVars,
1996
+ Q as applyCustomTheme,
1997
+ z as applyDarkTheme,
1998
+ K as applyLightTheme,
1999
+ W as applyTheme,
2000
+ q as applyThemeVars,
2000
2001
  k as darkTheme,
2001
2002
  e as defaultTheme,
2002
- er as ensureThemeInitialized,
2003
- rr as getCurrentTheme,
2003
+ or as ensureThemeInitialized,
2004
+ er as getCurrentTheme,
2004
2005
  P as getCurrentThemeMode,
2005
- W as initializeTheme,
2006
- Y as registerShadowRoot,
2007
- Q as resetTheme,
2008
- q as toggleTheme,
2009
- U as unregisterShadowRoot
2006
+ Y as initializeTheme,
2007
+ U as registerShadowRoot,
2008
+ rr as resetTheme,
2009
+ X as toggleTheme,
2010
+ J as unregisterShadowRoot
2010
2011
  };
2011
2012
  //# sourceMappingURL=theme.js.map