@m4l/graphics 3.0.3 → 6.0.1

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.
Files changed (60) hide show
  1. package/components/GlobalStyles/index.d.ts +0 -1
  2. package/contexts/FormatterContext/index.d.ts +1 -2
  3. package/contexts/FormatterContext/{index-Ch6IW7j8.js → index.js} +1 -1
  4. package/contexts/FormatterContext/types.d.ts +2 -2
  5. package/contexts/HostThemeContext/index.d.ts +1 -2
  6. package/contexts/HostThemeContext/index.js +46 -0
  7. package/contexts/HostThemeContext/types.d.ts +6 -5
  8. package/contexts/LocalesContext/helper.js +35 -0
  9. package/contexts/LocalesContext/index.d.ts +1 -2
  10. package/contexts/LocalesContext/index.js +69 -0
  11. package/contexts/LocalesContext/types.d.ts +4 -4
  12. package/contexts/ResponsiveContainerContext/constants.js +4 -0
  13. package/contexts/ResponsiveContainerContext/index.d.ts +3 -4
  14. package/contexts/ResponsiveContainerContext/index.js +51 -0
  15. package/contexts/ResponsiveContainerContext/store.d.ts +3 -3
  16. package/contexts/ResponsiveContainerContext/store.js +26 -0
  17. package/contexts/ResponsiveContainerContext/types.d.ts +4 -5
  18. package/contexts/ThemeSettingsContext/ThemeSettingsContext.d.ts +4 -5
  19. package/contexts/ThemeSettingsContext/ThemeSettingsContext.js +32 -0
  20. package/contexts/ThemeSettingsContext/constants.js +11 -0
  21. package/contexts/ThemeSettingsContext/index.js +1 -0
  22. package/contexts/ThemeSettingsContext/store.d.ts +2 -2
  23. package/contexts/ThemeSettingsContext/store.js +118 -0
  24. package/contexts/ThemeSettingsContext/types.d.ts +14 -11
  25. package/contexts/index.js +1 -0
  26. package/hooks/index.js +1 -0
  27. package/hooks/useFormatter/index.d.ts +1 -1
  28. package/hooks/useFormatter/index.js +11 -0
  29. package/hooks/useHostTheme/index.d.ts +1 -1
  30. package/hooks/useHostTheme/index.js +11 -0
  31. package/hooks/useIsMobile/{index-Bro0dV28.js → index.js} +5 -5
  32. package/hooks/useIsMountedRef/index.d.ts +1 -2
  33. package/hooks/useIsMountedRef/index.js +13 -0
  34. package/hooks/useLocales/index.d.ts +1 -1
  35. package/hooks/useLocales/index.js +11 -0
  36. package/hooks/useOffSetTop.js +12 -0
  37. package/hooks/useResizeObserver/index.d.ts +1 -2
  38. package/hooks/useResizeObserver/index.js +18 -0
  39. package/hooks/useResponsive/index.js +7 -0
  40. package/hooks/useResponsiveContainer/index.js +12 -0
  41. package/hooks/useThemSettingsStore/index.js +12 -0
  42. package/index.js +44 -35
  43. package/package.json +55 -11
  44. package/utils/anchorEl.d.ts +2 -2
  45. package/utils/anchorEl.js +49 -0
  46. package/utils/index.js +1 -0
  47. package/utils/strings.js +4 -0
  48. package/commonjs-BCz0-aDl.js +0 -9
  49. package/contexts/HostThemeContext/index-BMSwOCtA.js +0 -44
  50. package/contexts/LocalesContext/index-C89UlO0s.js +0 -101
  51. package/contexts/index-DEyJidab.js +0 -262
  52. package/hooks/index-Y3uj_IzK.js +0 -52
  53. package/hooks/useFormatter/index-BBgQ4lJL.js +0 -10
  54. package/hooks/useLocales/index-_thMBNE7.js +0 -10
  55. package/hooks/useResponsive/index-Dki-WJi8.js +0 -16
  56. package/node_modules-BHhXVwYT.js +0 -4569
  57. package/utils/index-DZG6QXjf.js +0 -51
  58. /package/components/{GlobalStyle/index-C3p7OfnO.js → GlobalStyles/index.js} +0 -0
  59. /package/components/{index-l0sNRNKZ.js → index.js} +0 -0
  60. /package/hooks/useFirstRender/{index-B-Q0TTn0.js → index.js} +0 -0
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare function GlobalStyles(): import("react").JSX.Element;
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { FormatterProviderProps, Formatters } from './types';
3
- declare const FormatterContext: import("react").Context<Formatters | null>;
2
+ declare const FormatterContext: import('react').Context<Formatters | null>;
4
3
  /**
5
4
  * @function
6
5
  * Componente encargado de proveer un contexto que permita saber los diferentes forrmatos,
@@ -1,7 +1,7 @@
1
1
  import { jsx as D } from "react/jsx-runtime";
2
2
  import { createContext as C, useState as k, useCallback as p, useEffect as v } from "react";
3
3
  import { useHostTools as R, usePropageteMF as h, EmitEvents as f } from "@m4l/core";
4
- import { u as V } from "../../hooks/useFirstRender/index-B-Q0TTn0.js";
4
+ import { u as V } from "../../hooks/useFirstRender/index.js";
5
5
  const x = C(null);
6
6
  function I(T) {
7
7
  const { children: b, isMicroFrontEnd: F, currencyFormatter: l, numberFormatter: M, dateFormatter: t } = T, r = l?.decimalDigits || 0, o = l?.code || "USD", a = M?.decimalSymbol || 0.1.toLocaleString().substring(1, 2), s = M?.thousandsSymbol || 1e3.toLocaleString().substring(1, 2), m = t?.dateFormat || "yyyy-MM-dd", n = t?.dateMask || "____-__-__", c = t?.datetimeFormat || "yyyy-MM-dd HH:mm:ss", i = t?.datetimeMask || "____-__-__ __:__:__", _ = t?.timeFormat || "HH:mm:ss", d = t?.timeMask || "__:__:__", u = t?.formatDate || (() => {
@@ -1,4 +1,4 @@
1
- import type { Locale } from 'date-fns';
1
+ import { Locale } from 'date-fns';
2
2
  import { ReactNode } from 'react';
3
3
  export interface CurrencyFormatter {
4
4
  code: string;
@@ -52,4 +52,4 @@ export interface FormatterProviderProps extends OptionalFormatters {
52
52
  isMicroFrontEnd: boolean;
53
53
  children: ReactNode;
54
54
  }
55
- export declare type FormatterContextProps = Formatters;
55
+ export type FormatterContextProps = Formatters;
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
1
  import { HostThemeProviderProps } from './types';
3
- declare const HostThemeContext: import("react").Context<import("./types").HostThemeType | null>;
2
+ declare const HostThemeContext: import('react').Context<import('./types').HostThemeType | null>;
4
3
  declare function HostThemeProvider(props: HostThemeProviderProps): import("react").JSX.Element;
5
4
  export { HostThemeProvider, HostThemeContext };
@@ -0,0 +1,46 @@
1
+ import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
+ import { createContext as h, useMemo as d } from "react";
3
+ import { CssBaseline as p } from "@mui/material";
4
+ import { deepmerge as t } from "@mui/utils";
5
+ import { G as f } from "../../components/GlobalStyles/index.js";
6
+ import { createTheme as u, experimental_extendTheme as x, Experimental_CssVarsProvider as T, StyledEngineProvider as v } from "@mui/material/styles";
7
+ const C = h(null);
8
+ function y(l) {
9
+ const { children: c, hostThemeOptions: n, fnComponentsOverrides: s, isMobile: m } = l, a = d(() => {
10
+ const e = {
11
+ ...u(),
12
+ ...n
13
+ }, r = x({
14
+ cssVarPrefix: "m4l",
15
+ colorSchemes: {
16
+ light: t({}, e),
17
+ finalTheme: t({}, e),
18
+ dark: t({}, e)
19
+ },
20
+ generalSettings: {
21
+ isMobile: m
22
+ }
23
+ });
24
+ return r.components = s(r), r;
25
+ }, [m]);
26
+ return /* @__PURE__ */ i(T, { theme: a, children: [
27
+ /* @__PURE__ */ o(f, {}),
28
+ /* @__PURE__ */ o(
29
+ C.Provider,
30
+ {
31
+ value: {
32
+ hostThemeOptions: n,
33
+ fnComponentsOverrides: s
34
+ },
35
+ children: /* @__PURE__ */ i(v, { injectFirst: !0, children: [
36
+ /* @__PURE__ */ o(p, { enableColorScheme: !0 }),
37
+ c
38
+ ] })
39
+ }
40
+ )
41
+ ] });
42
+ }
43
+ export {
44
+ C as H,
45
+ y as a
46
+ };
@@ -1,8 +1,9 @@
1
- import type { Theme, CssVarsTheme } from '@mui/material/styles';
2
- import type { ReactNode } from 'react';
3
- export declare type EventFunListener = (...args: any[]) => void;
1
+ import { OurTheme } from '@m4l/styles';
2
+ import { Theme, CssVarsTheme } from '@mui/material/styles';
3
+ import { ReactNode } from 'react';
4
+ export type EventFunListener = (...args: any[]) => void;
4
5
  export interface HostThemeType {
5
- hostThemeOptions: Theme;
6
+ hostThemeOptions: OurTheme;
6
7
  fnComponentsOverrides: (theme: Omit<Theme, 'palette' | 'applyStyles'> & CssVarsTheme) => any;
7
8
  }
8
9
  export interface HostThemeProviderProps extends HostThemeType {
@@ -10,4 +11,4 @@ export interface HostThemeProviderProps extends HostThemeType {
10
11
  children: ReactNode;
11
12
  isMobile: boolean;
12
13
  }
13
- export declare type HostThemeContextType = HostThemeType;
14
+ export type HostThemeContextType = HostThemeType;
@@ -0,0 +1,35 @@
1
+ import o from "date-fns/locale/en-US";
2
+ async function g(n, e, s) {
3
+ const r = l(n), i = { ...n };
4
+ let t;
5
+ return r === "es" ? t = (await import("date-fns/locale/es")).default : r === "fr" ? t = (await import("date-fns/locale/fr")).default : r === "en-US" ? t = o : (t = o, i.lang = "en", i.script = void 0, i.region = "US", i.url_icon = `${e}/${s}/frontend/commons/assets/icons/langs/lang_en.svg`, i.name = "English US*"), {
6
+ ...i,
7
+ module: t,
8
+ localeString: l(i)
9
+ };
10
+ }
11
+ function l(n) {
12
+ let e = n.lang;
13
+ return n.script && n.script !== "" && (e = e + "-" + n.script), n.region && n.region !== "" && (e = e + "-" + n.region), e;
14
+ }
15
+ function a(n) {
16
+ try {
17
+ const e = new Intl.Locale(n);
18
+ return {
19
+ lang: e.language || "",
20
+ script: e.script,
21
+ region: e.region
22
+ };
23
+ } catch {
24
+ return {
25
+ lang: "en",
26
+ script: void 0,
27
+ region: "US"
28
+ };
29
+ }
30
+ }
31
+ export {
32
+ g,
33
+ l as j,
34
+ a as s
35
+ };
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
1
  import { LocalesProviderProps, LocalesContextProps } from './types';
3
- declare const LocalesContext: import("react").Context<LocalesContextProps | null>;
2
+ declare const LocalesContext: import('react').Context<LocalesContextProps | null>;
4
3
  declare function LocalesProvider(props: LocalesProviderProps): import("react").JSX.Element | null;
5
4
  export { LocalesProvider, LocalesContext };
@@ -0,0 +1,69 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { createContext as A, useState as d, useCallback as O, useEffect as E } from "react";
3
+ import { AdapterDateFns as k } from "@mui/x-date-pickers/AdapterDateFns";
4
+ import { LocalizationProvider as x } from "@mui/x-date-pickers";
5
+ import { useEnvironment as F, useNetwork as P, useHostTools as j, useLocalStorageWithListener as G, EmitEvents as i } from "@m4l/core";
6
+ import { s as I, j as V } from "./helper.js";
7
+ const U = A(null);
8
+ function B(_) {
9
+ const { children: g, isMicroFrontEnd: e, localeHost: a, getLocaleFromNetwork: s } = _;
10
+ if (e && !a)
11
+ throw Error("Must set localeHost in microfrontend");
12
+ if (!e && !s)
13
+ throw Error("Must set getLocaleFromNetwork in host");
14
+ const { domain_token: L, host_static_assets: p, environment_assets: h } = F(), { networkOperation: v } = P(), { events_add_listener: S, events_remove_listener: C, events_emit: T } = j(), [r, l] = d(() => {
15
+ if (e)
16
+ return a;
17
+ }), [o, c] = G(
18
+ "localeHost",
19
+ navigator.language
20
+ ), [H, N] = d(""), u = O((t) => {
21
+ l(t);
22
+ }, []);
23
+ if (E(() => (e && S(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, u), () => {
24
+ e && C(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, u);
25
+ }), []), E(() => {
26
+ let t = !0;
27
+ if (!e && s && !(o === H && o !== ""))
28
+ return v({
29
+ method: "POST",
30
+ endPoint: "na/locales",
31
+ data: { ...I(o), domain_token: L }
32
+ }).then((f) => {
33
+ t && s(f.data, p, h).then(
34
+ (n) => {
35
+ l(n), N(n.localeString), o !== n.localeString && c(n.localeString), T(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, n);
36
+ }
37
+ );
38
+ }).finally(() => {
39
+ }), function() {
40
+ t = !1;
41
+ };
42
+ }, [o]), !r)
43
+ return null;
44
+ const M = (t) => {
45
+ (t.lang !== r.lang || t.script !== r.script || t.region !== r.region) && c(V(t));
46
+ };
47
+ return /* @__PURE__ */ m(
48
+ U.Provider,
49
+ {
50
+ value: {
51
+ currentLocale: r,
52
+ onChangeLocale: M
53
+ },
54
+ children: /* @__PURE__ */ m(
55
+ x,
56
+ {
57
+ dateAdapter: k,
58
+ adapterLocale: r.module,
59
+ dateFormats: { hours24h: "23" },
60
+ children: g
61
+ }
62
+ )
63
+ }
64
+ );
65
+ }
66
+ export {
67
+ U as L,
68
+ B as a
69
+ };
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import type { Locale } from 'date-fns';
3
- export declare type SupportedLocales = 'en-US' | 'es' | 'fr';
2
+ import { Locale } from 'date-fns';
3
+ export type SupportedLocales = 'en-US' | 'es' | 'fr';
4
4
  export interface BaseLocale {
5
5
  lang: string;
6
6
  script?: string;
@@ -14,13 +14,13 @@ export interface LocaleType extends NetworkLocaleType {
14
14
  module: Locale;
15
15
  localeString: string;
16
16
  }
17
- export declare type LocalesProviderProps = {
17
+ export type LocalesProviderProps = {
18
18
  isMicroFrontEnd: boolean;
19
19
  localeHost?: LocaleType;
20
20
  getLocaleFromNetwork?: (locale: NetworkLocaleType, host_static_assets: string, environment_assets: string) => Promise<LocaleType>;
21
21
  children: ReactNode;
22
22
  };
23
- export declare type LocalesContextProps = {
23
+ export type LocalesContextProps = {
24
24
  currentLocale?: LocaleType;
25
25
  onChangeLocale: (newLocaleString: BaseLocale) => void;
26
26
  };
@@ -0,0 +1,4 @@
1
+ const s = { xs: 600, sm: 900, md: 1200, lg: 1536, xl: 1920 };
2
+ export {
3
+ s as B
4
+ };
@@ -1,11 +1,10 @@
1
- /// <reference types="react" />
2
1
  import { ResponsiveContainerProviderProps } from './types';
3
- declare const ResponsiveContainerContext: import("react").Context<(Omit<Omit<import("zustand").StoreApi<import("./types").ResponsiveContainerStateWithActions>, "setState"> & {
2
+ declare const ResponsiveContainerContext: import('react').Context<(Omit<Omit<import('zustand').StoreApi<import('./types').ResponsiveContainerStateWithActions>, "setState"> & {
4
3
  setState<A extends string | {
5
4
  type: unknown;
6
- }>(partial: import("./types").ResponsiveContainerStateWithActions | Partial<import("./types").ResponsiveContainerStateWithActions> | ((state: import("./types").ResponsiveContainerStateWithActions) => import("./types").ResponsiveContainerStateWithActions | Partial<import("./types").ResponsiveContainerStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
5
+ }>(partial: import('./types').ResponsiveContainerStateWithActions | Partial<import('./types').ResponsiveContainerStateWithActions> | ((state: import('./types').ResponsiveContainerStateWithActions) => import('./types').ResponsiveContainerStateWithActions | Partial<import('./types').ResponsiveContainerStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
7
6
  }, "setState"> & {
8
- setState(nextStateOrUpdater: import("./types").ResponsiveContainerStateWithActions | Partial<import("./types").ResponsiveContainerStateWithActions> | ((state: import("immer/dist/internal").WritableDraft<import("./types").ResponsiveContainerStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
7
+ setState(nextStateOrUpdater: import('./types').ResponsiveContainerStateWithActions | Partial<import('./types').ResponsiveContainerStateWithActions> | ((state: import('immer/dist/internal').WritableDraft<import('./types').ResponsiveContainerStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
9
8
  type: unknown;
10
9
  } | undefined): void;
11
10
  }) | null>;
@@ -0,0 +1,51 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { createContext as p, useRef as v, useCallback as u, useMemo as d, useLayoutEffect as R } from "react";
3
+ import { B as i } from "./constants.js";
4
+ import b from "lodash.throttle";
5
+ import { c as h } from "./store.js";
6
+ const k = p(null), y = (l) => {
7
+ const { children: f, observedDivRef: s } = l, o = v();
8
+ o.current || (o.current = h({
9
+ breakPoint: "md",
10
+ isUpSm: !1,
11
+ isXs: !1
12
+ }));
13
+ const c = u(() => {
14
+ const n = s;
15
+ if (n instanceof HTMLElement && n.clientWidth) {
16
+ const e = Object.keys(
17
+ i
18
+ );
19
+ for (let t = 0; t < e.length; t++) {
20
+ const r = e[t];
21
+ if (n.clientWidth <= i[r]) {
22
+ o.current?.getState().responsiveContainerActions.setBreakpoint(r);
23
+ break;
24
+ } else t === e.length - 1 && n.clientWidth >= i[r] && o.current?.getState().responsiveContainerActions.setBreakpoint(r);
25
+ }
26
+ }
27
+ }, [s]), a = d(
28
+ () => b(c, 200, {
29
+ leading: !1,
30
+ trailing: !0
31
+ }),
32
+ [c]
33
+ );
34
+ return R(() => {
35
+ const n = () => {
36
+ a();
37
+ }, e = s;
38
+ if (e && e instanceof Element) {
39
+ const t = new ResizeObserver((r) => {
40
+ n();
41
+ });
42
+ return t.observe(e), () => {
43
+ t.disconnect();
44
+ };
45
+ }
46
+ }, [s, a]), /* @__PURE__ */ m(k.Provider, { value: o.current, children: f });
47
+ };
48
+ export {
49
+ k as R,
50
+ y as a
51
+ };
@@ -1,11 +1,11 @@
1
1
  import { InitialResponsiveContainerProps, ResponsiveContainerStateWithActions } from './types';
2
- export declare const createResponsiveContainerStore: (initProps: InitialResponsiveContainerProps) => Omit<Omit<import("zustand").StoreApi<ResponsiveContainerStateWithActions>, "setState"> & {
2
+ export declare const createResponsiveContainerStore: (initProps: InitialResponsiveContainerProps) => Omit<Omit<import('zustand').StoreApi<ResponsiveContainerStateWithActions>, "setState"> & {
3
3
  setState<A extends string | {
4
4
  type: unknown;
5
5
  }>(partial: ResponsiveContainerStateWithActions | Partial<ResponsiveContainerStateWithActions> | ((state: ResponsiveContainerStateWithActions) => ResponsiveContainerStateWithActions | Partial<ResponsiveContainerStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
6
6
  }, "setState"> & {
7
- setState(nextStateOrUpdater: ResponsiveContainerStateWithActions | Partial<ResponsiveContainerStateWithActions> | ((state: import("immer/dist/internal").WritableDraft<ResponsiveContainerStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
7
+ setState(nextStateOrUpdater: ResponsiveContainerStateWithActions | Partial<ResponsiveContainerStateWithActions> | ((state: import('immer/dist/internal').WritableDraft<ResponsiveContainerStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
8
8
  type: unknown;
9
9
  } | undefined): void;
10
10
  };
11
- export declare type ResponsiveContainerStore = ReturnType<typeof createResponsiveContainerStore>;
11
+ export type ResponsiveContainerStore = ReturnType<typeof createResponsiveContainerStore>;
@@ -0,0 +1,26 @@
1
+ import { createStore as i } from "zustand";
2
+ import { devtools as m } from "zustand/middleware";
3
+ import { immer as n } from "zustand/middleware/immer";
4
+ const S = (r) => {
5
+ const s = {
6
+ ...r
7
+ };
8
+ return i(
9
+ m(
10
+ n((t, p) => ({
11
+ ...s,
12
+ responsiveContainerActions: {
13
+ setBreakpoint: (e) => {
14
+ t((o) => {
15
+ o.breakPoint = e, o.isUpSm = e !== "xs" && e !== "sm", o.isXs = e === "xs";
16
+ });
17
+ }
18
+ }
19
+ })),
20
+ { name: "Responsive Relative Store" }
21
+ )
22
+ );
23
+ };
24
+ export {
25
+ S as c
26
+ };
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
- export declare type BreakpointType = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
3
- export declare type BreakPointsType = Record<BreakpointType, number>;
1
+ export type BreakpointType = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2
+ export type BreakPointsType = Record<BreakpointType, number>;
4
3
  export interface ResponsiveRelativeContextProps {
5
4
  breakPoint: BreakpointType;
6
5
  }
@@ -8,7 +7,7 @@ export interface ResponsiveContainerProviderProps {
8
7
  observedDivRef: Element | Text | null;
9
8
  children: React.ReactNode;
10
9
  }
11
- export declare type CurrentState = {
10
+ export type CurrentState = {
12
11
  width: number;
13
12
  height: number;
14
13
  mounted: boolean;
@@ -19,7 +18,7 @@ export interface ResponsiveContainerState {
19
18
  isUpSm: boolean;
20
19
  isXs: boolean;
21
20
  }
22
- export declare type InitialResponsiveContainerProps = Pick<ResponsiveContainerState, 'breakPoint' | 'isUpSm' | 'isXs'>;
21
+ export type InitialResponsiveContainerProps = Pick<ResponsiveContainerState, 'breakPoint' | 'isUpSm' | 'isXs'>;
23
22
  export interface ResponsiveContainerStateWithActions extends ResponsiveContainerState {
24
23
  responsiveContainerActions: {
25
24
  setBreakpoint: (breakPoint: BreakpointType) => void;
@@ -1,11 +1,10 @@
1
- /// <reference types="react" />
2
- import type { ThemeSettingsProviderProps } from './types';
3
- declare const ThemeSettingsContext: import("react").Context<(Omit<Omit<import("zustand").StoreApi<import("./types").ThemeSettingsStateWithActions>, "setState"> & {
1
+ import { ThemeSettingsProviderProps } from './types';
2
+ declare const ThemeSettingsContext: import('react').Context<(Omit<Omit<import('zustand').StoreApi<import('./types').ThemeSettingsStateWithActions>, "setState"> & {
4
3
  setState<A extends string | {
5
4
  type: unknown;
6
- }>(partial: import("./types").ThemeSettingsStateWithActions | Partial<import("./types").ThemeSettingsStateWithActions> | ((state: import("./types").ThemeSettingsStateWithActions) => import("./types").ThemeSettingsStateWithActions | Partial<import("./types").ThemeSettingsStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
5
+ }>(partial: import('./types').ThemeSettingsStateWithActions | Partial<import('./types').ThemeSettingsStateWithActions> | ((state: import('./types').ThemeSettingsStateWithActions) => import('./types').ThemeSettingsStateWithActions | Partial<import('./types').ThemeSettingsStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
7
6
  }, "setState"> & {
8
- setState(nextStateOrUpdater: import("./types").ThemeSettingsStateWithActions | Partial<import("./types").ThemeSettingsStateWithActions> | ((state: import("immer/dist/internal").WritableDraft<import("./types").ThemeSettingsStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
7
+ setState(nextStateOrUpdater: import('./types').ThemeSettingsStateWithActions | Partial<import('./types').ThemeSettingsStateWithActions> | ((state: import('immer/dist/internal').WritableDraft<import('./types').ThemeSettingsStateWithActions>) => void), shouldReplace?: boolean | undefined, action?: string | {
9
8
  type: unknown;
10
9
  } | undefined): void;
11
10
  }) | null>;
@@ -0,0 +1,32 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { createContext as c, useRef as a, useEffect as u } from "react";
3
+ import { useNetwork as f, useLocalStorageWithListener as g } from "@m4l/core";
4
+ import { OUR_THEME as p, presetsOptions as S } from "@m4l/styles";
5
+ import { c as h } from "./store.js";
6
+ import { d as l } from "./constants.js";
7
+ import { u as T } from "../../hooks/useIsMobile/index.js";
8
+ const d = c(null);
9
+ function b({ children: o, themeSettings: t }) {
10
+ const { networkOperation: s } = f(), r = T(), [n, i] = g(
11
+ "theme_setting",
12
+ {}
13
+ ), e = a();
14
+ return e.current || (e.current = h({
15
+ networkOperation: s,
16
+ currentThemeSettings: {
17
+ ...l,
18
+ ...t,
19
+ ...n
20
+ },
21
+ themeOptions: p,
22
+ colorOption: S,
23
+ open: !1,
24
+ setterThemeSettings: t ? void 0 : i
25
+ }), e.current.getState().settingsActions.init()), u(() => {
26
+ e.current?.getState().settingsActions.setThemeSettings({ isMobile: r });
27
+ }, [r]), /* @__PURE__ */ m(d.Provider, { value: e.current, children: o });
28
+ }
29
+ export {
30
+ d as T,
31
+ b as a
32
+ };
@@ -0,0 +1,11 @@
1
+ const e = {
2
+ themeMode: "light",
3
+ themeDirection: "ltr",
4
+ themeColorPresets: "patronus",
5
+ themeLayout: "horizontal",
6
+ themeStretch: !1,
7
+ isMobile: !1
8
+ };
9
+ export {
10
+ e as d
11
+ };
@@ -1,6 +1,6 @@
1
1
  import { InitialThemeSettingsStoreProps, ThemeSettingsStateWithActions } from './types';
2
2
  import { WritableDraft } from 'immer/dist/internal';
3
- export declare const createThemeSettingsStore: (initialState: InitialThemeSettingsStoreProps) => Omit<Omit<import("zustand").StoreApi<ThemeSettingsStateWithActions>, "setState"> & {
3
+ export declare const createThemeSettingsStore: (initialState: InitialThemeSettingsStoreProps) => Omit<Omit<import('zustand').StoreApi<ThemeSettingsStateWithActions>, "setState"> & {
4
4
  setState<A extends string | {
5
5
  type: unknown;
6
6
  }>(partial: ThemeSettingsStateWithActions | Partial<ThemeSettingsStateWithActions> | ((state: ThemeSettingsStateWithActions) => ThemeSettingsStateWithActions | Partial<ThemeSettingsStateWithActions>), replace?: boolean | undefined, action?: A | undefined): void;
@@ -9,4 +9,4 @@ export declare const createThemeSettingsStore: (initialState: InitialThemeSettin
9
9
  type: unknown;
10
10
  } | undefined): void;
11
11
  };
12
- export declare type ThemeSettingsStore = ReturnType<typeof createThemeSettingsStore>;
12
+ export type ThemeSettingsStore = ReturnType<typeof createThemeSettingsStore>;
@@ -0,0 +1,118 @@
1
+ import { createStore as l } from "zustand";
2
+ import { devtools as u } from "zustand/middleware";
3
+ import { immer as S } from "zustand/middleware/immer";
4
+ import { getPaletteByPreset as p, typography as T, shadows as h, getColorPresets as a, createCustomShadows as d } from "@m4l/styles";
5
+ import { alpha as f } from "@mui/system";
6
+ import { d as c } from "./constants.js";
7
+ function g(n, r = "m4l") {
8
+ const m = document.querySelector('[data-mui-color-scheme="light"]');
9
+ if (!m) {
10
+ console.error('Element with data-mui-color-scheme="light" not found.');
11
+ return;
12
+ }
13
+ Object.keys(n).forEach((t) => {
14
+ const e = n[t];
15
+ if (typeof e == "string" || typeof e == "number") {
16
+ const s = `--${r}-${t}`;
17
+ m.style.setProperty(s, e.toString());
18
+ } else typeof e == "object" && e !== null && g(e, `${r}-${t}`);
19
+ });
20
+ }
21
+ const o = (n) => {
22
+ const r = n.currentThemeSettings || c, m = r.themeMode === "light", t = p(r.themeColorPresets), e = m ? t.light : t.dark;
23
+ n.themeOptions = {
24
+ ...n.themeOptions,
25
+ typography: T,
26
+ palette: {
27
+ ...n.themeOptions?.palette ?? {},
28
+ ...e
29
+ },
30
+ shape: { borderRadius: 8 },
31
+ direction: r.themeDirection,
32
+ shadows: m ? h.light : h.dark,
33
+ customShadows: {
34
+ primary: `0 8px 16px 0 ${f(
35
+ a(r.themeColorPresets)?.main || "#fff",
36
+ 0.2
37
+ )}`,
38
+ ...d(r.themeMode)
39
+ },
40
+ stretch: r.themeStretch
41
+ }, g(n.themeOptions);
42
+ }, i = (n) => {
43
+ n.setterThemeSettings && n.setterThemeSettings(n.currentThemeSettings);
44
+ }, b = (n) => l(
45
+ u(
46
+ S((r, m) => ({
47
+ ...n,
48
+ settingsActions: {
49
+ init: () => {
50
+ r((t) => {
51
+ o(t);
52
+ });
53
+ },
54
+ setThemeSettings: (t) => {
55
+ r((e) => {
56
+ e.currentThemeSettings = { ...e.currentThemeSettings, ...t }, i(e), o(e);
57
+ });
58
+ },
59
+ onChangeMode: (t) => {
60
+ r((e) => {
61
+ e.currentThemeSettings = {
62
+ ...e.currentThemeSettings,
63
+ themeMode: t.target.value
64
+ }, i(e), o(e);
65
+ });
66
+ },
67
+ handleOpen: () => {
68
+ r((t) => {
69
+ t.open = !t.open;
70
+ });
71
+ },
72
+ onChangeDirection: (t) => {
73
+ r((e) => {
74
+ e.currentThemeSettings = {
75
+ ...e.currentThemeSettings,
76
+ themeDirection: t.target.value
77
+ }, i(e), o(e);
78
+ });
79
+ },
80
+ onChangeColor: (t) => {
81
+ r((e) => {
82
+ e.currentThemeSettings = {
83
+ ...e.currentThemeSettings,
84
+ themeColorPresets: t.target.value
85
+ }, i(e), o(e);
86
+ });
87
+ },
88
+ onChangeLayout: (t) => {
89
+ r((e) => {
90
+ e.currentThemeSettings = {
91
+ ...e.currentThemeSettings,
92
+ themeLayout: t.target.value
93
+ }, i(e), o(e);
94
+ });
95
+ },
96
+ onToggleStretch: () => {
97
+ r((t) => {
98
+ t.currentThemeSettings = {
99
+ ...t.currentThemeSettings,
100
+ themeStretch: !t.currentThemeSettings.themeStretch
101
+ }, i(t), o(t);
102
+ });
103
+ },
104
+ onResetSetting: () => {
105
+ r((t) => {
106
+ t.currentThemeSettings = {
107
+ ...c
108
+ }, i(t), o(t);
109
+ });
110
+ }
111
+ }
112
+ })),
113
+ { name: "ThemeSettingsStore" }
114
+ )
115
+ );
116
+ export {
117
+ b as c
118
+ };
@@ -1,15 +1,15 @@
1
1
  import { NetworkProps } from '@m4l/core';
2
- import { PresetsOptions, ThemeColorPresets } from '@m4l/styles';
2
+ import { OurTheme, PresetsOptions, ThemeColorOptionsType } from '@m4l/styles';
3
3
  import { CssVarsTheme, Theme } from '@mui/material/styles';
4
4
  import { ReactNode } from 'react';
5
- export declare type ThemeMode = 'light' | 'dark';
6
- export declare type ThemeDirection = 'rtl' | 'ltr';
7
- export declare type ThemeLayout = 'vertical' | 'horizontal';
8
- export declare type ThemeStretch = boolean;
9
- export declare type ThemeSettingsType = {
5
+ export type ThemeMode = 'light' | 'dark';
6
+ export type ThemeDirection = 'rtl' | 'ltr';
7
+ export type ThemeLayout = 'vertical' | 'horizontal';
8
+ export type ThemeStretch = boolean;
9
+ export type ThemeSettingsType = {
10
10
  themeMode: ThemeMode;
11
11
  themeDirection: ThemeDirection;
12
- themeColorPresets: ThemeColorPresets;
12
+ themeColorPresets: ThemeColorOptionsType;
13
13
  themeStretch: ThemeStretch;
14
14
  themeLayout: ThemeLayout;
15
15
  isMobile: boolean;
@@ -17,7 +17,10 @@ export declare type ThemeSettingsType = {
17
17
  export interface ThemeSettingsStore {
18
18
  networkOperation: (props: NetworkProps) => Promise<any>;
19
19
  currentThemeSettings: ThemeSettingsType;
20
- themeOptions: Omit<Theme, 'palette' | 'applyStyles'> & CssVarsTheme;
20
+ /**
21
+ * Contiene la configuración incial del tema como la paleta, tipografía, sombras, etc. También puede contener el tema convertido a css vars.
22
+ */
23
+ themeOptions: (Omit<Theme, 'palette' | 'applyStyles'> & CssVarsTheme) | OurTheme;
21
24
  colorOption: PresetsOptions;
22
25
  /**
23
26
  * "setterThemeSettings" es una función que se encarga de persistir en local storage los cambios de los settings
@@ -26,8 +29,8 @@ export interface ThemeSettingsStore {
26
29
  setterThemeSettings?: (newValue: ThemeSettingsType) => void;
27
30
  open: boolean;
28
31
  }
29
- export declare type DefaultThemeSettingsStoreProps = ThemeSettingsStore;
30
- export declare type InitialThemeSettingsStoreProps = DefaultThemeSettingsStoreProps;
32
+ export type DefaultThemeSettingsStoreProps = ThemeSettingsStore;
33
+ export type InitialThemeSettingsStoreProps = DefaultThemeSettingsStoreProps;
31
34
  export interface ThemeSettingsStateWithActions extends ThemeSettingsStore {
32
35
  settingsActions: {
33
36
  init: () => void;
@@ -41,7 +44,7 @@ export interface ThemeSettingsStateWithActions extends ThemeSettingsStore {
41
44
  setThemeSettings: (newValue: Partial<ThemeSettingsType>) => void;
42
45
  };
43
46
  }
44
- export declare type ThemeSettingsProviderProps = {
47
+ export type ThemeSettingsProviderProps = {
45
48
  themeSettings?: ThemeSettingsType;
46
49
  children: ReactNode;
47
50
  };