@alphakits/ui 2.6.2 → 2.7.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,45 +1,56 @@
1
- import { jsx as g } from "react/jsx-runtime";
2
- import { createContext as k, useState as x, useCallback as u, useEffect as y, useContext as _ } from "react";
3
- var b = /* @__PURE__ */ ((t) => (t.DARK = "dark", t.LIGHT = "light", t))(b || {});
4
- const f = k({
1
+ import { jsx as A } from "react/jsx-runtime";
2
+ import { createContext as C, useState as g, useCallback as u, useEffect as k, useContext as w } from "react";
3
+ var x = /* @__PURE__ */ ((e) => (e.DARK = "dark", e.LIGHT = "light", e))(x || {});
4
+ const E = C({
5
5
  setTheme: () => {
6
6
  },
7
7
  currentTheme: void 0
8
- }), i = "theme", E = "theme-styles", v = "data-theme", S = ({
9
- children: t,
8
+ }), v = "theme", i = "theme-styles", _ = "data-theme", b = () => {
9
+ try {
10
+ return window.localStorage?.getItem(v) || void 0;
11
+ } catch {
12
+ return;
13
+ }
14
+ }, S = (e) => {
15
+ try {
16
+ window.localStorage?.setItem(v, e);
17
+ } catch {
18
+ }
19
+ }, j = ({
20
+ children: e,
10
21
  themes: c,
11
- selectedTheme: r
22
+ selectedTheme: s
12
23
  }) => {
13
- const [A, C] = x(), n = u((e) => {
14
- document?.documentElement.setAttribute(v, e), localStorage.setItem(i, e), C(e);
15
- }, []), m = u((e) => {
16
- let o = document.getElementById(E), s = "";
17
- o || (o = document.createElement("style"), o.id = E, document.head.appendChild(o)), Object.keys(e).forEach((a) => {
18
- s += `html[data-theme='${a}'] {`;
19
- const h = e[a];
20
- Object.keys(h).forEach((T) => {
21
- const l = h[T];
22
- Object.keys(l).forEach((d) => {
23
- s += `--color-${T}-${d}: ${l[d]};
24
+ const [f, y] = g(), n = u((t) => {
25
+ document?.documentElement.setAttribute(_, t), S(t), y(t);
26
+ }, []), a = u((t) => {
27
+ let o = document.getElementById(i), r = "";
28
+ o || (o = document.createElement("style"), o.id = i, document.head.appendChild(o)), Object.keys(t).forEach((m) => {
29
+ r += `html[data-theme='${m}'] {`;
30
+ const h = t[m];
31
+ Object.keys(h).forEach((d) => {
32
+ const T = h[d];
33
+ Object.keys(T).forEach((l) => {
34
+ r += `--color-${d}-${l}: ${T[l]};
24
35
  `;
25
36
  });
26
- }), s += `}
27
- `, o.textContent = s;
37
+ }), r += `}
38
+ `, o.textContent = r;
28
39
  });
29
40
  }, []);
30
- return y(() => {
31
- const e = localStorage?.getItem(i), o = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
32
- n(r || e || o), m(c);
33
- }, [c, r, n, m]), /* @__PURE__ */ g(f.Provider, { value: { setTheme: n, currentTheme: A }, children: t });
34
- }, j = () => {
35
- const { setTheme: t, currentTheme: c } = _(f);
36
- return { setTheme: t, currentTheme: c };
41
+ return k(() => {
42
+ const t = b(), o = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
43
+ n(s || t || o), a(c);
44
+ }, [c, s, n, a]), /* @__PURE__ */ A(E.Provider, { value: { setTheme: n, currentTheme: f }, children: e });
45
+ }, p = () => {
46
+ const { setTheme: e, currentTheme: c } = w(E);
47
+ return { setTheme: e, currentTheme: c };
37
48
  };
38
49
  export {
39
- i as LOACAL_STORAGE_THEME_KEY,
40
- E as STYLE_TAG_ID,
41
- b as THEME,
42
- v as THEME_DATA_ATTR,
43
- S as ThemeProvider,
44
- j as useTheme
50
+ v as LOACAL_STORAGE_THEME_KEY,
51
+ i as STYLE_TAG_ID,
52
+ x as THEME,
53
+ _ as THEME_DATA_ATTR,
54
+ j as ThemeProvider,
55
+ p as useTheme
45
56
  };
@@ -1,16 +1,19 @@
1
1
  import { currency as R } from "../data/currency-codes.js";
2
- import { getCurrencySymbol as _ } from "../get-currency-symbol/util.js";
3
- import { splitAmount as C } from "../split-amount/util.js";
4
- const O = 3, S = 4, T = "−", a = " ", e = ",", l = (t) => t === "USD" || t === "CHF" || t === "GBP" || t === "CAD" || t === "AUD" || t === "NZD" || t === "ARS" || t === "BRL" || t === "TWD" || t === "MXN" || t === "JPY" || t === "SGD" || t === "TRY" || t === "GEL" || t === "ILS" || t === "UAH", N = (t, o, i) => o ? t ? l(i) ? `${o}${a}${t}` : `${t}${a}${o}` : "" : t, U = (t) => t ? t.length > 2 ? t.slice(0, 2) : t.length < 2 ? `${t}0` : t : "00", h = (t, o, i) => {
5
- const r = U(t);
2
+ import { getCurrencySymbol as S } from "../get-currency-symbol/util.js";
3
+ import { splitAmount as _ } from "../split-amount/util.js";
4
+ const C = 3, O = 4, T = "−", f = " ", e = ",", l = (t) => t === "USD" || t === "CHF" || t === "GBP" || t === "CAD" || t === "AUD" || t === "NZD" || t === "ARS" || t === "BRL" || t === "TWD" || t === "MXN" || t === "JPY" || t === "SGD" || t === "TRY" || t === "GEL" || t === "ILS" || t === "UAH", h = (t, o, i) => o ? t ? l(i) ? `${o}${f}${t}` : `${t}${f}${o}` : "" : t, N = (t) => t ? t.length > 2 ? t.slice(0, 2) : t.length < 2 ? `${t}0` : t : "00", U = (t, o, i) => {
5
+ const r = N(t);
6
6
  return !i && r === "00" ? null : !i && r[1] === "0" ? r.slice(0, 1) : r === "00" && !o ? null : r;
7
+ }, p = (t) => {
8
+ const o = Math.abs(Math.round(t));
9
+ return [`${Math.floor(o / 100)}`, `${o % 100}`.padStart(2, "0")];
7
10
  }, $ = ({
8
11
  value: t,
9
12
  currency: o,
10
13
  showMinorPart: i,
11
14
  type: r
12
15
  }) => {
13
- const m = !!o && !!R.CURRENCY_SYMBOLS[o], n = m ? _(o) : o;
16
+ const m = !!o && !!R.CURRENCY_SYMBOLS[o], n = m ? S(o) : o;
14
17
  if (t === null)
15
18
  return {
16
19
  majorPart: "",
@@ -19,19 +22,19 @@ const O = 3, S = 4, T = "−", a = " ", e = ",", l = (t) => t === "USD" || t =
19
22
  currencySymbol: n,
20
23
  formattedWithCurrency: ""
21
24
  };
22
- const [M, s] = r === "default" ? `${t}`.split(".") : [`${t}`.slice(0, -2), `${t}`.slice(-2)], A = C(
23
- `${Math.abs(+M || 0)}`,
24
- O,
25
- a,
26
- S
27
- ), f = t < 0 ? T + A : A, P = s ? f + e + s : f;
25
+ const [P, s] = r === "default" ? `${t}`.split(".") : p(t), M = _(
26
+ `${Math.abs(+P || 0)}`,
27
+ C,
28
+ f,
29
+ O
30
+ ), a = t < 0 ? T + M : M, A = s ? a + e + s : a;
28
31
  return {
29
- majorPart: f,
30
- minorPart: h(s, i, m),
32
+ majorPart: a,
33
+ minorPart: U(s, i, m),
31
34
  currencySymbol: n,
32
- formatted: P,
33
- formattedWithCurrency: N(
34
- P,
35
+ formatted: A,
36
+ formattedWithCurrency: h(
37
+ A,
35
38
  n || "",
36
39
  o
37
40
  )
@@ -39,7 +42,7 @@ const O = 3, S = 4, T = "−", a = " ", e = ",", l = (t) => t === "USD" || t =
39
42
  };
40
43
  export {
41
44
  e as AMOUNT_MAJOR_MINOR_PARTS_SEPARATOR,
42
- a as THINSP,
45
+ f as THINSP,
43
46
  $ as formatAmount,
44
47
  l as isCurrencyFirst
45
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphakits/ui",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],