@m4l/graphics 1.0.8 → 1.0.9

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.
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,44 @@
1
+ import { createContext as c, useMemo as h } from "react";
2
+ import { CssBaseline as a } from "@mui/material";
3
+ import { G as d } from "../../components/GlobalStyle/index.b7393a44.js";
4
+ import { createTheme as p, experimental_extendTheme as x, Experimental_CssVarsProvider as f, StyledEngineProvider as T } from "@mui/material/styles";
5
+ import { jsxs as s, jsx as t } from "react/jsx-runtime";
6
+ const u = c(null);
7
+ function H(m) {
8
+ const {
9
+ children: i,
10
+ hostThemeOptions: l,
11
+ fnComponentsOverrides: o
12
+ } = m, n = h(() => {
13
+ const e = p({
14
+ ...l
15
+ }), r = x({
16
+ cssVarPrefix: "m4l",
17
+ colorSchemes: {
18
+ light: e,
19
+ finalTheme: e,
20
+ dark: e
21
+ }
22
+ });
23
+ return r.components = o(r), r;
24
+ }, []);
25
+ return /* @__PURE__ */ s(f, {
26
+ theme: n,
27
+ children: [/* @__PURE__ */ t(d, {}), /* @__PURE__ */ t(u.Provider, {
28
+ value: {
29
+ hostThemeOptions: n,
30
+ fnComponentsOverrides: o
31
+ },
32
+ children: /* @__PURE__ */ s(T, {
33
+ injectFirst: !0,
34
+ children: [/* @__PURE__ */ t(a, {
35
+ enableColorScheme: !0
36
+ }), i]
37
+ })
38
+ })]
39
+ });
40
+ }
41
+ export {
42
+ u as H,
43
+ H as a
44
+ };
@@ -1,2 +1,2 @@
1
- import { BreakPointsType } from './types';
1
+ import { BreakPointsType } from "./types";
2
2
  export declare const BREAKPOINTS: BreakPointsType;
@@ -19,7 +19,8 @@ export interface ResponsiveContainerState {
19
19
  isUpSm: boolean;
20
20
  isXs: boolean;
21
21
  }
22
- export declare type InitialResponsiveContainerProps = Pick<ResponsiveContainerState, 'breakPoint' | 'isUpSm' | 'isXs'>;
22
+ export interface InitialResponsiveContainerProps extends Pick<ResponsiveContainerState, 'breakPoint' | 'isUpSm' | 'isXs'> {
23
+ }
23
24
  export interface ResponsiveContainerStateWithActions extends ResponsiveContainerState {
24
25
  responsiveContainerActions: {
25
26
  setBreakpoint: (breakPoint: BreakpointType) => void;
@@ -1,2 +1,3 @@
1
1
  export * from './ThemeSettingsContext';
2
- export type {} from './SettingsContext/types';
2
+ export type { ThemeSettingsType, ThemeMode } from './types';
3
+ export { defaultThemeSettings } from './constants';
@@ -22,7 +22,11 @@ export interface ThemeSettingsStore {
22
22
  name: string | undefined;
23
23
  value: string;
24
24
  }[];
25
- setThemeSettings?: (newValue: ThemeSettingsType) => void;
25
+ /**
26
+ * "setterThemeSettings" es una función que se encarga de persistir en local storage los cambios de los settings
27
+ * Solo se instancia cuando esta en host, cuando esta storybook no se instancia
28
+ */
29
+ setterThemeSettings?: (newValue: ThemeSettingsType) => void;
26
30
  open: boolean;
27
31
  }
28
32
  export declare type DefaultThemeSettingsStoreProps = ThemeSettingsStore;
@@ -37,8 +41,7 @@ export interface ThemeSettingsStateWithActions extends ThemeSettingsStore {
37
41
  onChangeColor: (event: React.ChangeEvent<HTMLInputElement>) => void;
38
42
  onChangeLayout: (event: React.ChangeEvent<HTMLInputElement>) => void;
39
43
  handleOpen: () => void;
40
- setThemeOptions: (obj: any) => void;
41
- setSettings: (newValue: any) => void;
44
+ setThemeSettings: (newValue: Partial<ThemeSettingsType>) => void;
42
45
  };
43
46
  }
44
47
  export declare type ThemeSettingsProviderProps = {
@@ -0,0 +1,279 @@
1
+ import { createContext as f, useRef as T, useMemo as k, useLayoutEffect as y, useEffect as b } from "react";
2
+ import { c as v, d as R, i as P, l as M } from "../node_modules.7cdb697c.js";
3
+ import { jsx as x } from "react/jsx-runtime";
4
+ import { useNetwork as E, useLocalStorageWithListener as w } from "@m4l/core";
5
+ import { getColorPresets as m, getColorState as d, typography as L, palette as S, SECONDARY as A, COMMON as N, ERROR as D, WARNING as z, INFO as W, SUCCESS as B, shadows as p, createCustomShadows as $, defaultThemeOptions as j, defaultPreset as _, colorPresets as F } from "@m4l/styles";
6
+ import { alpha as I } from "@mui/system";
7
+ import { u as U } from "../hooks/useFirstRender/index.1e9b02fb.js";
8
+ const C = { xs: 600, sm: 900, md: 1200, lg: 1536, xl: 1920 }, K = (r) => {
9
+ const t = {
10
+ ...r
11
+ };
12
+ return v(
13
+ R(
14
+ P((o, n) => ({
15
+ ...t,
16
+ responsiveContainerActions: {
17
+ setBreakpoint: (e) => {
18
+ o(
19
+ (i) => {
20
+ console.log("current breakpoint", e), i.breakPoint = e, i.isUpSm = e !== "xs" && e !== "sm", i.isXs = e == "xs";
21
+ }
22
+ );
23
+ }
24
+ }
25
+ })),
26
+ { name: "Responsive Relative Store" }
27
+ )
28
+ );
29
+ }, X = f(null), te = (r) => {
30
+ const {
31
+ children: t,
32
+ observedDivRef: o
33
+ } = r, n = T();
34
+ n.current || (n.current = K({
35
+ breakPoint: "md",
36
+ isUpSm: !1,
37
+ isXs: !1
38
+ }));
39
+ const e = () => {
40
+ const s = o;
41
+ if (s instanceof HTMLElement && s.clientWidth) {
42
+ const c = Object.keys(C);
43
+ for (let l = 0; l < c.length; l++) {
44
+ const g = c[l];
45
+ if (s.clientWidth <= C[g]) {
46
+ n.current?.getState().responsiveContainerActions.setBreakpoint(g);
47
+ break;
48
+ }
49
+ }
50
+ console.log("node.clientWidth", s.clientWidth), console.log("onResizeMemo", n.current?.getState().breakPoint);
51
+ }
52
+ }, i = k(() => M.exports.throttle(e, 200, {
53
+ leading: !1,
54
+ trailing: !0
55
+ }), [e]);
56
+ return y(() => {
57
+ const s = () => {
58
+ i();
59
+ }, c = o;
60
+ if (c && c instanceof Element) {
61
+ const l = new ResizeObserver((g) => {
62
+ s();
63
+ });
64
+ return l.observe(c), () => {
65
+ l.disconnect();
66
+ };
67
+ }
68
+ }, [o]), /* @__PURE__ */ x(X.Provider, {
69
+ value: n.current,
70
+ children: t
71
+ });
72
+ }, u = {
73
+ themeMode: "light",
74
+ themeDirection: "ltr",
75
+ themeColorPresets: "patronus",
76
+ themeLayout: "horizontal",
77
+ themeStretch: !1
78
+ };
79
+ function O(r, t = "m4l") {
80
+ const o = document.querySelector('[data-mui-color-scheme="light"]');
81
+ if (!o) {
82
+ console.error('Element with data-mui-color-scheme="light" not found.');
83
+ return;
84
+ }
85
+ Object.keys(r).forEach((n) => {
86
+ const e = r[n];
87
+ if (typeof e == "string" || typeof e == "number") {
88
+ const i = `--${t}-${n}`;
89
+ o.style.setProperty(i, e.toString());
90
+ } else
91
+ typeof e == "object" && e !== null && O(e, `${t}-${n}`);
92
+ });
93
+ }
94
+ const a = (r) => {
95
+ const t = r.currentThemeSettings || u;
96
+ console.log("getColorPresets", m(t.themeColorPresets)), console.log(
97
+ "getColorState",
98
+ d(t.themeColorPresets, t.themeMode)
99
+ );
100
+ const o = t.themeMode === "light";
101
+ r.themeOptions = {
102
+ ...r.themeOptions,
103
+ typography: L,
104
+ palette: {
105
+ ...r.themeOptions.palette,
106
+ ...o ? S.light : S.dark,
107
+ primary: m(t.themeColorPresets),
108
+ state: d(t.themeColorPresets, t.themeMode),
109
+ representative: t.themeMode === "light" ? m(t.themeColorPresets)?.light : m(t.themeColorPresets)?.darker,
110
+ secondary: {
111
+ ...A,
112
+ contrastText: "",
113
+ mainChannel: "",
114
+ lightChannel: "",
115
+ darkChannel: "",
116
+ contrastTextChannel: ""
117
+ },
118
+ common: {
119
+ ...N,
120
+ black: "#000",
121
+ white: "#fff",
122
+ background: "",
123
+ backgroundChannel: "",
124
+ onBackground: "",
125
+ onBackgroundChannel: ""
126
+ },
127
+ error: {
128
+ ...D,
129
+ contrastText: "",
130
+ mainChannel: "",
131
+ lightChannel: "",
132
+ darkChannel: "",
133
+ contrastTextChannel: ""
134
+ },
135
+ warning: {
136
+ ...z,
137
+ contrastText: "",
138
+ mainChannel: "",
139
+ lightChannel: "",
140
+ darkChannel: "",
141
+ contrastTextChannel: ""
142
+ },
143
+ info: {
144
+ ...W,
145
+ contrastText: "",
146
+ mainChannel: "",
147
+ lightChannel: "",
148
+ darkChannel: "",
149
+ contrastTextChannel: ""
150
+ },
151
+ success: {
152
+ ...B,
153
+ contrastText: "",
154
+ mainChannel: "",
155
+ lightChannel: "",
156
+ darkChannel: "",
157
+ contrastTextChannel: ""
158
+ }
159
+ },
160
+ shape: { borderRadius: 8 },
161
+ direction: t.themeDirection,
162
+ shadows: o ? p.light : p.dark,
163
+ customShadows: {
164
+ primary: `0 8px 16px 0 ${I(
165
+ m(t.themeColorPresets)?.main || "#fff",
166
+ 0.2
167
+ )}`,
168
+ ...$(t.themeMode)
169
+ },
170
+ stretch: t.themeStretch
171
+ }, console.log("state.themeOptions", r.themeOptions), O(r.themeOptions);
172
+ }, h = (r) => {
173
+ r.setterThemeSettings && r.setterThemeSettings(r.currentThemeSettings);
174
+ }, q = (r) => v(
175
+ R(
176
+ P((t, o) => ({
177
+ ...r,
178
+ settingsActions: {
179
+ init: () => {
180
+ t((n) => {
181
+ a(n);
182
+ });
183
+ },
184
+ setThemeSettings: (n) => {
185
+ t((e) => {
186
+ e.currentThemeSettings = { ...e.currentThemeSettings, ...n }, h(e), a(e);
187
+ });
188
+ },
189
+ onChangeMode: (n) => {
190
+ t((e) => {
191
+ e.currentThemeSettings = {
192
+ ...e.currentThemeSettings,
193
+ themeMode: n.target.value
194
+ }, h(e), a(e);
195
+ });
196
+ },
197
+ handleOpen: () => {
198
+ t((n) => {
199
+ n.open = !n.open;
200
+ });
201
+ },
202
+ onChangeDirection: (n) => {
203
+ t((e) => {
204
+ e.currentThemeSettings = {
205
+ ...e.currentThemeSettings,
206
+ themeDirection: n.target.value
207
+ }, h(e), a(e);
208
+ });
209
+ },
210
+ onChangeColor: (n) => {
211
+ t((e) => {
212
+ e.currentThemeSettings = {
213
+ ...e.currentThemeSettings,
214
+ themeColorPresets: n.target.value
215
+ }, h(e), a(e);
216
+ });
217
+ },
218
+ onChangeLayout: (n) => {
219
+ t((e) => {
220
+ e.currentThemeSettings = {
221
+ ...e.currentThemeSettings,
222
+ themeLayout: n.target.value
223
+ }, h(e), a(e);
224
+ });
225
+ },
226
+ onToggleStretch: () => {
227
+ t((n) => {
228
+ n.currentThemeSettings = {
229
+ ...n.currentThemeSettings,
230
+ themeStretch: !n.currentThemeSettings.themeStretch
231
+ }, h(n), a(n);
232
+ });
233
+ },
234
+ onResetSetting: () => {
235
+ t((n) => {
236
+ n.currentThemeSettings = {
237
+ ...u
238
+ }, h(n), a(n);
239
+ });
240
+ }
241
+ }
242
+ })),
243
+ { name: "ExampleStore" }
244
+ )
245
+ ), G = f(null);
246
+ function ne({
247
+ children: r,
248
+ themeSettings: t
249
+ }) {
250
+ const {
251
+ networkOperation: o
252
+ } = E(), [n, e] = w("theme_setting", u), i = U([t]), s = T();
253
+ return s.current || (s.current = q({
254
+ networkOperation: o,
255
+ currentThemeSettings: {
256
+ ...t ?? n
257
+ },
258
+ themeOptions: j,
259
+ currentPreset: _,
260
+ colorOption: F.map((c) => ({
261
+ name: c.name,
262
+ value: c.main
263
+ })),
264
+ open: !1,
265
+ setterThemeSettings: t ? void 0 : e
266
+ }), s.current.getState().settingsActions.init()), b(() => {
267
+ !i && s.current && t && s.current.getState().settingsActions.setThemeSettings(t);
268
+ }, [t]), /* @__PURE__ */ x(G.Provider, {
269
+ value: s.current,
270
+ children: r
271
+ });
272
+ }
273
+ export {
274
+ X as R,
275
+ G as T,
276
+ te as a,
277
+ ne as b,
278
+ u as d
279
+ };
@@ -6,5 +6,5 @@ export type { BreakpointType } from './ResponsiveContainerContext/types';
6
6
  export type { NetworkLocaleType, LocaleType } from './LocalesContext/types';
7
7
  export { getLocaleFromNetwork } from './LocalesContext/helper';
8
8
  export * from './HostThemeContext';
9
- export * from './ThemeSettingsContext/ThemeSettingsContext';
9
+ export * from './ThemeSettingsContext';
10
10
  export type { HostThemeType } from './HostThemeContext/types';
@@ -0,0 +1,54 @@
1
+ import { useRef as n, useEffect as r, useState as i, useContext as u, useLayoutEffect as c } from "react";
2
+ import { H as m } from "../contexts/HostThemeContext/index.02e36f38.js";
3
+ import { u as a } from "../node_modules.7cdb697c.js";
4
+ import { T as l } from "../contexts/index.1d935da9.js";
5
+ function S() {
6
+ const e = n(!0);
7
+ return r(
8
+ () => () => {
9
+ e.current = !1;
10
+ },
11
+ []
12
+ ), e;
13
+ }
14
+ function x(e) {
15
+ const [s, t] = i(!1), o = e || 100;
16
+ return r(() => (window.onscroll = () => {
17
+ window.pageYOffset > o ? t(!0) : t(!1);
18
+ }, () => {
19
+ window.onscroll = null;
20
+ }), [o]), s;
21
+ }
22
+ const h = () => {
23
+ const e = u(m);
24
+ if (!e)
25
+ throw new Error("useHostTheme context must be use inside HostThemeProvider");
26
+ return e;
27
+ };
28
+ function b(e) {
29
+ const s = n(null);
30
+ return c(() => {
31
+ const t = s?.current;
32
+ if (!t)
33
+ return;
34
+ const o = new ResizeObserver((f) => {
35
+ e(t, f[0]);
36
+ });
37
+ return o.observe(t), () => {
38
+ o.disconnect();
39
+ };
40
+ }, [e, s.current]), s;
41
+ }
42
+ function g(e, s) {
43
+ const t = u(l);
44
+ if (!t)
45
+ throw new Error("useSettingsStore context must be use inside SettignsContext");
46
+ return a(t, e, s);
47
+ }
48
+ export {
49
+ x as a,
50
+ h as b,
51
+ b as c,
52
+ g as d,
53
+ S as u
54
+ };
@@ -1,17 +1,11 @@
1
1
  import { useState as n, useEffect as o } from "react";
2
- import { t as s } from "../../node_modules.9eeccca4.js";
2
+ import { t as s } from "../../node_modules.7cdb697c.js";
3
3
  const t = () => typeof navigator > "u" ? !1 : /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), l = () => {
4
4
  const [i, r] = n(t());
5
5
  return o(() => {
6
- const e = s(
7
- () => {
8
- r(t());
9
- },
10
- 200,
11
- {
12
- trailing: !0
13
- }
14
- );
6
+ const e = s(() => {
7
+ r(t());
8
+ }, 200);
15
9
  return window.addEventListener("resize", e), e(), () => {
16
10
  window.removeEventListener("resize", e), e.cancel();
17
11
  };
@@ -1,6 +1,6 @@
1
1
  import { useContext as t } from "react";
2
- import { u as r } from "../../node_modules.9eeccca4.js";
3
- import { R as n } from "../../contexts/index.acf54acf.js";
2
+ import { u as r } from "../../node_modules.7cdb697c.js";
3
+ import { R as n } from "../../contexts/index.1d935da9.js";
4
4
  import { useResponsive as i } from "@m4l/styles";
5
5
  function f(e, s) {
6
6
  const o = t(n);
package/index.js CHANGED
@@ -1,51 +1,52 @@
1
- import { G as v } from "./components/GlobalStyle/index.b7393a44.js";
2
- import { F as d, a as R } from "./contexts/FormatterContext/index.92336f4c.js";
3
- import { L as g, a as h, g as S } from "./contexts/LocalesContext/index.53f0b702.js";
4
- import { R as F, a as P, T as b, b as L } from "./contexts/index.acf54acf.js";
5
- import { H as k, a as w } from "./contexts/HostThemeContext/index.f53d14b8.js";
6
- import { u as G } from "./hooks/useFirstRender/index.1e9b02fb.js";
7
- import { u as M } from "./hooks/useFormatter/index.57ac8cca.js";
8
- import { b as y, u as A, a as D, c as E, d as N } from "./hooks/index.315d954d.js";
9
- import { u as j } from "./hooks/useLocales/index.d5a80aff.js";
10
- import { u as B, a as J } from "./hooks/useResponsive/index.f415f47d.js";
11
- import { u as Q } from "./hooks/useIsMobile/index.e9f29b1d.js";
12
- import { C as V, g as X } from "./utils/index.6909c662.js";
1
+ import { G as l } from "./components/GlobalStyle/index.b7393a44.js";
2
+ import { L as C, a as T, g } from "./contexts/LocalesContext/index.53f0b702.js";
3
+ import { F as R, a as S } from "./contexts/FormatterContext/index.92336f4c.js";
4
+ import { R as F, a as P, T as b, b as L, d as H } from "./contexts/index.1d935da9.js";
5
+ import { H as w, a as z } from "./contexts/HostThemeContext/index.02e36f38.js";
6
+ import { u as I } from "./hooks/useFirstRender/index.1e9b02fb.js";
7
+ import { u as O } from "./hooks/useFormatter/index.57ac8cca.js";
8
+ import { b as A, u as D, a as E, c as N, d as W } from "./hooks/index.e4fb3c4e.js";
9
+ import { u as q } from "./hooks/useLocales/index.d5a80aff.js";
10
+ import { u as J, a as K } from "./hooks/useResponsive/index.0881f166.js";
11
+ import { u as U } from "./hooks/useIsMobile/index.1afbcd66.js";
12
+ import { C as X, g as Y } from "./utils/index.6909c662.js";
13
13
  import "@mui/material/styles";
14
14
  import "@mui/material";
15
15
  import "@m4l/styles";
16
16
  import "react/jsx-runtime";
17
17
  import "react";
18
- import "@m4l/core";
19
18
  import "@mui/x-date-pickers/AdapterDateFns";
20
19
  import "@mui/x-date-pickers";
20
+ import "@m4l/core";
21
21
  import "date-fns/locale/en-US";
22
- import "./node_modules.9eeccca4.js";
22
+ import "./node_modules.7cdb697c.js";
23
23
  import "./commonjs.e3daa2e5.js";
24
24
  import "@mui/system";
25
25
  export {
26
- V as Capitalize,
27
- d as FormatterContext,
28
- R as FormatterProvider,
29
- v as GlobalStyles,
30
- k as HostThemeContext,
31
- w as HostThemeProvider,
32
- g as LocalesContext,
33
- h as LocalesProvider,
26
+ X as Capitalize,
27
+ R as FormatterContext,
28
+ S as FormatterProvider,
29
+ l as GlobalStyles,
30
+ w as HostThemeContext,
31
+ z as HostThemeProvider,
32
+ C as LocalesContext,
33
+ T as LocalesProvider,
34
34
  F as ResponsiveContainerContext,
35
35
  P as ResponsiveContainerProvider,
36
36
  b as ThemeSettingsContext,
37
37
  L as ThemeSettingsProvider,
38
- X as getAnchorElPositionWindow,
39
- S as getLocaleFromNetwork,
40
- G as useFirstRender,
41
- M as useFormatter,
42
- y as useHostTheme,
43
- Q as useIsMobile,
44
- A as useIsMountedRef,
45
- j as useLocales,
46
- D as useOffSetTop,
47
- E as useResizeObserver,
48
- B as useResponsiveContainerStore,
49
- J as useResponsiveDesktop,
50
- N as useThemeSettingsStore
38
+ H as defaultThemeSettings,
39
+ Y as getAnchorElPositionWindow,
40
+ g as getLocaleFromNetwork,
41
+ I as useFirstRender,
42
+ O as useFormatter,
43
+ A as useHostTheme,
44
+ U as useIsMobile,
45
+ D as useIsMountedRef,
46
+ q as useLocales,
47
+ E as useOffSetTop,
48
+ N as useResizeObserver,
49
+ J as useResponsiveContainerStore,
50
+ K as useResponsiveDesktop,
51
+ W as useThemeSettingsStore
51
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "dependencies": {
package/vite-env.d.ts CHANGED
@@ -1 +1 @@
1
- /// <reference types="vite/client" />
1
+ /// <reference types="vite/client" />
@@ -1,4 +0,0 @@
1
- import "@mui/material/styles";
2
- import "@mui/material";
3
- import "@m4l/styles";
4
- import "react/jsx-runtime";
@@ -1,44 +0,0 @@
1
- import { createContext as c, useMemo as a } from "react";
2
- import { CssBaseline as h } from "@mui/material";
3
- import { G as d } from "../../components/GlobalStyle/index.b7393a44.js";
4
- import { createTheme as p, experimental_extendTheme as f, Experimental_CssVarsProvider as x, StyledEngineProvider as T } from "@mui/material/styles";
5
- import { jsxs as m, jsx as o } from "react/jsx-runtime";
6
- const u = c(null);
7
- function j(i) {
8
- const {
9
- children: l,
10
- hostThemeOptions: t,
11
- fnComponentsOverrides: n
12
- } = i, e = p({
13
- ...t
14
- }), s = a(() => {
15
- const r = f({
16
- cssVarPrefix: "m4l",
17
- colorSchemes: {
18
- light: e,
19
- finalTheme: e,
20
- dark: e
21
- }
22
- });
23
- return r.components = n(r), r;
24
- }, []);
25
- return console.log("finalTheme", s), /* @__PURE__ */ m(x, {
26
- theme: s,
27
- children: [/* @__PURE__ */ o(d, {}), /* @__PURE__ */ o(u.Provider, {
28
- value: {
29
- hostThemeOptions: t,
30
- fnComponentsOverrides: n
31
- },
32
- children: /* @__PURE__ */ m(T, {
33
- injectFirst: !0,
34
- children: [/* @__PURE__ */ o(h, {
35
- enableColorScheme: !0
36
- }), l]
37
- })
38
- })]
39
- });
40
- }
41
- export {
42
- u as H,
43
- j as a
44
- };
@@ -1,283 +0,0 @@
1
- import "./FormatterContext/index.92336f4c.js";
2
- import "./LocalesContext/index.53f0b702.js";
3
- import { createContext as T, useRef as v, useMemo as y, useLayoutEffect as b } from "react";
4
- import { c as O, d as P, i as R, l as M } from "../node_modules.9eeccca4.js";
5
- import { jsx as x } from "react/jsx-runtime";
6
- import "date-fns/locale/en-US";
7
- import "./HostThemeContext/index.f53d14b8.js";
8
- import { useNetwork as E, useLocalStorageWithListener as w } from "@m4l/core";
9
- import { getColorPresets as m, getColorState as p, typography as L, palette as d, SECONDARY as N, COMMON as A, ERROR as D, WARNING as z, INFO as B, SUCCESS as $, shadows as S, createCustomShadows as j, defaultThemeOptions as C, defaultPreset as W, colorPresets as _ } from "@m4l/styles";
10
- import { alpha as I } from "@mui/system";
11
- const f = { xs: 600, sm: 900, md: 1200, lg: 1536, xl: 1920 }, U = (o) => {
12
- const n = {
13
- ...o
14
- };
15
- return O(
16
- P(
17
- R((r, t) => ({
18
- ...n,
19
- responsiveContainerActions: {
20
- setBreakpoint: (e) => {
21
- r((s) => {
22
- s.breakPoint = e, s.isUpSm = e !== "xs" && e !== "sm", s.isXs = e == "xs";
23
- });
24
- }
25
- }
26
- })),
27
- { name: "Responsive Relative Store" }
28
- )
29
- );
30
- }, K = T(null), ne = (o) => {
31
- const {
32
- children: n,
33
- observedDivRef: r
34
- } = o, t = v();
35
- t.current || (t.current = U({
36
- breakPoint: "md",
37
- isUpSm: !1,
38
- isXs: !1
39
- }));
40
- const e = () => {
41
- const i = r;
42
- if (i instanceof HTMLElement && i.clientWidth) {
43
- const l = Object.keys(f);
44
- for (let c = 0; c < l.length; c++) {
45
- const g = l[c];
46
- if (i.clientWidth <= f[g]) {
47
- t.current?.getState().responsiveContainerActions.setBreakpoint(g);
48
- break;
49
- }
50
- }
51
- }
52
- }, s = y(() => M.exports.throttle(e, 200, {
53
- leading: !1,
54
- trailing: !0
55
- }), [e]);
56
- return b(() => {
57
- const i = () => {
58
- s();
59
- }, l = r;
60
- if (l && l instanceof Element) {
61
- const c = new ResizeObserver((g) => {
62
- i();
63
- });
64
- return c.observe(l), () => {
65
- c.disconnect();
66
- };
67
- }
68
- }, [r]), /* @__PURE__ */ x(K.Provider, {
69
- value: t.current,
70
- children: n
71
- });
72
- }, u = {
73
- themeMode: "light",
74
- themeDirection: "ltr",
75
- themeColorPresets: "patronus",
76
- themeStretch: !1,
77
- themeLayout: "horizontal"
78
- };
79
- function k(o, n = "m4l") {
80
- const r = document.querySelector('[data-mui-color-scheme="light"]');
81
- if (!r) {
82
- console.error('Element with data-mui-color-scheme="light" not found.');
83
- return;
84
- }
85
- Object.keys(o).forEach((t) => {
86
- const e = o[t];
87
- if (typeof e == "string" || typeof e == "number") {
88
- const s = `--${n}-${t}`;
89
- r.style.setProperty(s, e.toString());
90
- } else
91
- typeof e == "object" && e !== null && k(e, `${n}-${t}`);
92
- });
93
- }
94
- const h = (o) => {
95
- const n = o.currentThemeSettings || u;
96
- console.log("getColorPresets", m(n.themeColorPresets)), console.log(
97
- "getColorState",
98
- p(n.themeColorPresets, n.themeMode)
99
- );
100
- const r = n.themeMode === "light";
101
- o.themeOptions = {
102
- ...o.themeOptions,
103
- typography: L,
104
- palette: {
105
- ...o.themeOptions.palette,
106
- ...r ? d.light : d.dark,
107
- primary: m(n.themeColorPresets),
108
- state: p(n.themeColorPresets, n.themeMode),
109
- representative: n.themeMode === "light" ? m(n.themeColorPresets)?.light : m(n.themeColorPresets)?.darker,
110
- secondary: {
111
- ...N,
112
- contrastText: "",
113
- mainChannel: "",
114
- lightChannel: "",
115
- darkChannel: "",
116
- contrastTextChannel: ""
117
- },
118
- common: {
119
- ...A,
120
- black: "#000",
121
- white: "#fff",
122
- background: "",
123
- backgroundChannel: "",
124
- onBackground: "",
125
- onBackgroundChannel: ""
126
- },
127
- error: {
128
- ...D,
129
- contrastText: "",
130
- mainChannel: "",
131
- lightChannel: "",
132
- darkChannel: "",
133
- contrastTextChannel: ""
134
- },
135
- warning: {
136
- ...z,
137
- contrastText: "",
138
- mainChannel: "",
139
- lightChannel: "",
140
- darkChannel: "",
141
- contrastTextChannel: ""
142
- },
143
- info: {
144
- ...B,
145
- contrastText: "",
146
- mainChannel: "",
147
- lightChannel: "",
148
- darkChannel: "",
149
- contrastTextChannel: ""
150
- },
151
- success: {
152
- ...$,
153
- contrastText: "",
154
- mainChannel: "",
155
- lightChannel: "",
156
- darkChannel: "",
157
- contrastTextChannel: ""
158
- }
159
- },
160
- shape: { borderRadius: 8 },
161
- direction: n.themeDirection,
162
- shadows: r ? S.light : S.dark,
163
- customShadows: {
164
- primary: `0 8px 16px 0 ${I(
165
- m(n.themeColorPresets)?.main || "#fff",
166
- 0.2
167
- )}`,
168
- ...j(n.themeMode)
169
- },
170
- stretch: n.themeStretch
171
- }, console.log("state.themeOptions", o.themeOptions), k(o.themeOptions);
172
- }, a = (o) => {
173
- o.setThemeSettings && o.setThemeSettings(o.currentThemeSettings);
174
- }, X = (o) => O(
175
- P(
176
- R((n, r) => ({
177
- ...o,
178
- settingsActions: {
179
- init: () => {
180
- n((t) => {
181
- h(t);
182
- });
183
- },
184
- setThemeOptions: (t) => {
185
- n((e) => {
186
- e.themeOptions = { ...e.themeOptions, ...t };
187
- });
188
- },
189
- setSettings: (t) => {
190
- n((e) => {
191
- e.currentThemeSettings = { ...t }, a(e), h(e);
192
- });
193
- },
194
- onChangeMode: (t) => {
195
- n((e) => {
196
- e.currentThemeSettings = {
197
- ...e.currentThemeSettings,
198
- themeMode: t.target.value
199
- }, a(e), h(e);
200
- });
201
- },
202
- handleOpen: () => {
203
- n((t) => {
204
- t.open = !t.open;
205
- });
206
- },
207
- onChangeDirection: (t) => {
208
- n((e) => {
209
- e.currentThemeSettings = {
210
- ...e.currentThemeSettings,
211
- themeDirection: t.target.value
212
- }, a(e), h(e);
213
- });
214
- },
215
- onChangeColor: (t) => {
216
- n((e) => {
217
- e.currentThemeSettings = {
218
- ...e.currentThemeSettings,
219
- themeColorPresets: t.target.value
220
- }, a(e), h(e);
221
- });
222
- },
223
- onChangeLayout: (t) => {
224
- n((e) => {
225
- e.currentThemeSettings = {
226
- ...e.currentThemeSettings,
227
- themeLayout: t.target.value
228
- }, a(e), h(e);
229
- });
230
- },
231
- onToggleStretch: () => {
232
- n((t) => {
233
- t.currentThemeSettings = {
234
- ...t.currentThemeSettings,
235
- themeStretch: !t.currentThemeSettings.themeStretch
236
- }, a(t), h(t);
237
- });
238
- },
239
- onResetSetting: () => {
240
- n((t) => {
241
- t.currentThemeSettings = {
242
- ...u
243
- }, a(t), h(t);
244
- });
245
- }
246
- }
247
- })),
248
- { name: "ExampleStore" }
249
- )
250
- ), q = T(null);
251
- function oe({
252
- children: o,
253
- themeSettings: n
254
- }) {
255
- const {
256
- networkOperation: r
257
- } = E(), [t, e] = w("theme_setting", u);
258
- console.log("defaultThemeOptions", C);
259
- const s = v();
260
- return s.current || (s.current = X({
261
- networkOperation: r,
262
- currentThemeSettings: {
263
- ...n ?? t
264
- },
265
- themeOptions: C,
266
- currentPreset: W,
267
- colorOption: _.map((i) => ({
268
- name: i.name,
269
- value: i.main
270
- })),
271
- open: !1,
272
- setThemeSettings: n ? void 0 : e
273
- }), s.current.getState().settingsActions.init()), /* @__PURE__ */ x(q.Provider, {
274
- value: s.current,
275
- children: o
276
- });
277
- }
278
- export {
279
- K as R,
280
- q as T,
281
- ne as a,
282
- oe as b
283
- };
@@ -1,57 +0,0 @@
1
- import { useRef as r, useEffect as n, useState as f, useContext as u, useLayoutEffect as c } from "react";
2
- import { H as m } from "../contexts/HostThemeContext/index.f53d14b8.js";
3
- import { u as a } from "../node_modules.9eeccca4.js";
4
- import { T as p } from "../contexts/index.acf54acf.js";
5
- import "../contexts/FormatterContext/index.92336f4c.js";
6
- import "../contexts/LocalesContext/index.53f0b702.js";
7
- import "@m4l/styles";
8
- function b() {
9
- const e = r(!0);
10
- return n(
11
- () => () => {
12
- e.current = !1;
13
- },
14
- []
15
- ), e;
16
- }
17
- function g(e) {
18
- const [o, t] = f(!1), s = e || 100;
19
- return n(() => (window.onscroll = () => {
20
- window.pageYOffset > s ? t(!0) : t(!1);
21
- }, () => {
22
- window.onscroll = null;
23
- }), [s]), o;
24
- }
25
- const v = () => {
26
- const e = u(m);
27
- if (!e)
28
- throw new Error("useHostTheme context must be use inside HostThemeProvider");
29
- return e;
30
- };
31
- function H(e) {
32
- const o = r(null);
33
- return c(() => {
34
- const t = o?.current;
35
- if (!t)
36
- return;
37
- const s = new ResizeObserver((i) => {
38
- e(t, i[0]);
39
- });
40
- return s.observe(t), () => {
41
- s.disconnect();
42
- };
43
- }, [e, o.current]), o;
44
- }
45
- function O(e, o) {
46
- const t = u(p);
47
- if (!t)
48
- throw new Error("useSettingsStore context must be use inside SettignsContext");
49
- return a(t, e, o);
50
- }
51
- export {
52
- g as a,
53
- v as b,
54
- H as c,
55
- O as d,
56
- b as u
57
- };