@m4l/graphics 2.0.4 → 3.0.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,13 +1,12 @@
1
- import { useTheme as o } from "@mui/material/styles";
2
- import { GlobalStyles as e } from "@mui/material";
1
+ import { useTheme as e } from "@mui/material/styles";
2
+ import { GlobalStyles as o } from "@mui/material";
3
3
  import { globalRemSize as r } from "@m4l/styles";
4
4
  import { jsx as a } from "react/jsx-runtime";
5
5
  function s() {
6
- const t = o();
7
- return /* @__PURE__ */ a(e, {
6
+ const t = e();
7
+ return /* @__PURE__ */ a(o, {
8
8
  styles: {
9
9
  body: {
10
- /* backgroundColor: `${theme.vars.palette.background.background}!important`, */
11
10
  textRendering: "geometricPrecision",
12
11
  width: "100%",
13
12
  height: "100vh",
@@ -35,7 +34,7 @@ function s() {
35
34
  // Chrome
36
35
  "*::-webkit-scrollbar-thumb": {
37
36
  // barra que se mueve
38
- background: t.vars.palette.state.scrollBar,
37
+ background: t.vars.palette.general.scrollBar,
39
38
  borderRadius: "2px!important"
40
39
  },
41
40
  "& #root": {
@@ -1,6 +1,6 @@
1
1
  import { createContext as c, useMemo as a } from "react";
2
2
  import { CssBaseline as h } from "@mui/material";
3
- import { G as d } from "../../components/GlobalStyle/index-DHBkshRk.js";
3
+ import { G as d } from "../../components/GlobalStyle/index-BwMNLyTC.js";
4
4
  import { createTheme as p, experimental_extendTheme as x, Experimental_CssVarsProvider as f, StyledEngineProvider as u } from "@mui/material/styles";
5
5
  import { jsxs as s, jsx as t } from "react/jsx-runtime";
6
6
  const T = c(null);
@@ -1,5 +1,5 @@
1
1
  import { NetworkProps } from '@m4l/core';
2
- import { ThemeColorPresets } from '@m4l/styles';
2
+ import { PresetsOptions, ThemeColorPresets } from '@m4l/styles';
3
3
  import { CssVarsTheme, Theme } from '@mui/material/styles';
4
4
  import { ReactNode } from 'react';
5
5
  export declare type ThemeMode = 'light' | 'dark';
@@ -17,10 +17,7 @@ export interface ThemeSettingsStore {
17
17
  networkOperation: (props: NetworkProps) => Promise<any>;
18
18
  currentThemeSettings: ThemeSettingsType;
19
19
  themeOptions: Omit<Theme, 'palette' | 'applyStyles'> & CssVarsTheme;
20
- colorOption: {
21
- name: string | undefined;
22
- value: string;
23
- }[];
20
+ colorOption: PresetsOptions;
24
21
  /**
25
22
  * "setterThemeSettings" es una función que se encarga de persistir en local storage los cambios de los settings
26
23
  * Solo se instancia cuando esta en host, cuando esta storybook no se instancia
@@ -0,0 +1,264 @@
1
+ import { createContext as S, useRef as f, useMemo as b, useLayoutEffect as k } from "react";
2
+ import { c as T, d as C, i as v, l as P } from "../node_modules-BHhXVwYT.js";
3
+ import { jsx as y } from "react/jsx-runtime";
4
+ import { useNetwork as O, useLocalStorageWithListener as x } from "@m4l/core";
5
+ import { getPaletteByPreset as w, typography as E, shadows as d, getColorPresets as L, createCustomShadows as M, defaultThemeOptions as B, presetsOptions as A } from "@m4l/styles";
6
+ import { alpha as D } from "@mui/system";
7
+ const g = { xs: 600, sm: 900, md: 1200, lg: 1536, xl: 1920 }, z = (r) => {
8
+ const n = {
9
+ ...r
10
+ };
11
+ return T(
12
+ C(
13
+ v((o, t) => ({
14
+ ...n,
15
+ responsiveContainerActions: {
16
+ setBreakpoint: (e) => {
17
+ o((s) => {
18
+ s.breakPoint = e, s.isUpSm = e !== "xs" && e !== "sm", s.isXs = e == "xs";
19
+ });
20
+ }
21
+ }
22
+ })),
23
+ { name: "Responsive Relative Store" }
24
+ )
25
+ );
26
+ }, $ = S(null), H = (r) => {
27
+ const {
28
+ children: n,
29
+ observedDivRef: o
30
+ } = r, t = f();
31
+ t.current || (t.current = z({
32
+ breakPoint: "md",
33
+ isUpSm: !1,
34
+ isXs: !1
35
+ }));
36
+ const e = () => {
37
+ const m = o;
38
+ if (m instanceof HTMLElement && m.clientWidth) {
39
+ const c = Object.keys(g);
40
+ for (let h = 0; h < c.length; h++) {
41
+ const u = c[h];
42
+ if (m.clientWidth <= g[u]) {
43
+ t.current?.getState().responsiveContainerActions.setBreakpoint(u);
44
+ break;
45
+ } else h === c.length - 1 && m.clientWidth >= g[u] && t.current?.getState().responsiveContainerActions.setBreakpoint(u);
46
+ }
47
+ }
48
+ }, s = b(() => P.throttle(e, 200, {
49
+ leading: !1,
50
+ trailing: !0
51
+ }), [e]);
52
+ return k(() => {
53
+ const m = () => {
54
+ s();
55
+ }, c = o;
56
+ if (c && c instanceof Element) {
57
+ const h = new ResizeObserver((u) => {
58
+ m();
59
+ });
60
+ return h.observe(c), () => {
61
+ h.disconnect();
62
+ };
63
+ }
64
+ }, [o]), /* @__PURE__ */ y($.Provider, {
65
+ value: t.current,
66
+ children: n
67
+ });
68
+ }, p = {
69
+ themeMode: "light",
70
+ themeDirection: "ltr",
71
+ themeColorPresets: "patronus",
72
+ themeLayout: "horizontal",
73
+ themeStretch: !1
74
+ };
75
+ function R(r, n = "m4l") {
76
+ const o = document.querySelector('[data-mui-color-scheme="light"]');
77
+ if (!o) {
78
+ console.error('Element with data-mui-color-scheme="light" not found.');
79
+ return;
80
+ }
81
+ Object.keys(r).forEach((t) => {
82
+ const e = r[t];
83
+ if (typeof e == "string" || typeof e == "number") {
84
+ const s = `--${n}-${t}`;
85
+ o.style.setProperty(s, e.toString());
86
+ } else typeof e == "object" && e !== null && R(e, `${n}-${t}`);
87
+ });
88
+ }
89
+ const l = {
90
+ mainChannel: "",
91
+ lightChannel: "",
92
+ darkChannel: "",
93
+ contrastTextChannel: ""
94
+ }, i = (r) => {
95
+ const n = r.currentThemeSettings || p, o = n.themeMode === "light", t = w(n.themeColorPresets), e = o ? t.light : t.dark;
96
+ r.themeOptions = {
97
+ ...r.themeOptions,
98
+ typography: E,
99
+ palette: {
100
+ ...r.themeOptions?.palette ?? {},
101
+ ...e,
102
+ primary: {
103
+ ...e.primary,
104
+ ...l
105
+ },
106
+ secondary: {
107
+ ...e.secondary,
108
+ ...l
109
+ },
110
+ info: {
111
+ ...e.info,
112
+ ...l
113
+ },
114
+ error: {
115
+ ...e.error,
116
+ ...l
117
+ },
118
+ success: {
119
+ ...e.success,
120
+ ...l
121
+ },
122
+ warning: {
123
+ ...e.warning,
124
+ ...l
125
+ },
126
+ text: {
127
+ ...e.text,
128
+ primaryChannel: "",
129
+ secondaryChannel: ""
130
+ },
131
+ background: {
132
+ ...e.background,
133
+ defaultChannel: "",
134
+ paperChannel: ""
135
+ },
136
+ common: {
137
+ ...e.common,
138
+ background: "",
139
+ backgroundChannel: "",
140
+ onBackground: "",
141
+ onBackgroundChannel: ""
142
+ },
143
+ action: {
144
+ ...e.action,
145
+ activeChannel: "",
146
+ selectedChannel: ""
147
+ }
148
+ },
149
+ shape: { borderRadius: 8 },
150
+ direction: n.themeDirection,
151
+ shadows: o ? d.light : d.dark,
152
+ customShadows: {
153
+ primary: `0 8px 16px 0 ${D(
154
+ L(n.themeColorPresets)?.main || "#fff",
155
+ 0.2
156
+ )}`,
157
+ ...M(n.themeMode)
158
+ },
159
+ stretch: n.themeStretch
160
+ }, R(r.themeOptions);
161
+ }, a = (r) => {
162
+ r.setterThemeSettings && r.setterThemeSettings(r.currentThemeSettings);
163
+ }, j = (r) => T(
164
+ C(
165
+ v((n, o) => ({
166
+ ...r,
167
+ settingsActions: {
168
+ init: () => {
169
+ n((t) => {
170
+ i(t);
171
+ });
172
+ },
173
+ setThemeSettings: (t) => {
174
+ n((e) => {
175
+ e.currentThemeSettings = { ...e.currentThemeSettings, ...t }, a(e), i(e);
176
+ });
177
+ },
178
+ onChangeMode: (t) => {
179
+ n((e) => {
180
+ e.currentThemeSettings = {
181
+ ...e.currentThemeSettings,
182
+ themeMode: t.target.value
183
+ }, a(e), i(e);
184
+ });
185
+ },
186
+ handleOpen: () => {
187
+ n((t) => {
188
+ t.open = !t.open;
189
+ });
190
+ },
191
+ onChangeDirection: (t) => {
192
+ n((e) => {
193
+ e.currentThemeSettings = {
194
+ ...e.currentThemeSettings,
195
+ themeDirection: t.target.value
196
+ }, a(e), i(e);
197
+ });
198
+ },
199
+ onChangeColor: (t) => {
200
+ n((e) => {
201
+ e.currentThemeSettings = {
202
+ ...e.currentThemeSettings,
203
+ themeColorPresets: t.target.value
204
+ }, a(e), i(e);
205
+ });
206
+ },
207
+ onChangeLayout: (t) => {
208
+ n((e) => {
209
+ e.currentThemeSettings = {
210
+ ...e.currentThemeSettings,
211
+ themeLayout: t.target.value
212
+ }, a(e), i(e);
213
+ });
214
+ },
215
+ onToggleStretch: () => {
216
+ n((t) => {
217
+ t.currentThemeSettings = {
218
+ ...t.currentThemeSettings,
219
+ themeStretch: !t.currentThemeSettings.themeStretch
220
+ }, a(t), i(t);
221
+ });
222
+ },
223
+ onResetSetting: () => {
224
+ n((t) => {
225
+ t.currentThemeSettings = {
226
+ ...p
227
+ }, a(t), i(t);
228
+ });
229
+ }
230
+ }
231
+ })),
232
+ { name: "ThemeSettingsStore" }
233
+ )
234
+ ), W = S(null);
235
+ function I({
236
+ children: r,
237
+ themeSettings: n
238
+ }) {
239
+ const {
240
+ networkOperation: o
241
+ } = O(), [t, e] = x("theme_setting", {}), s = f();
242
+ return s.current || (s.current = j({
243
+ networkOperation: o,
244
+ currentThemeSettings: {
245
+ ...p,
246
+ ...n,
247
+ ...t
248
+ },
249
+ themeOptions: B,
250
+ colorOption: A,
251
+ open: !1,
252
+ setterThemeSettings: n ? void 0 : e
253
+ }), s.current.getState().settingsActions.init()), /* @__PURE__ */ y(W.Provider, {
254
+ value: s.current,
255
+ children: r
256
+ });
257
+ }
258
+ export {
259
+ $ as R,
260
+ W as T,
261
+ H as a,
262
+ I as b,
263
+ p as d
264
+ };
@@ -1,7 +1,7 @@
1
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-C5Z07fH1.js";
2
+ import { H as m } from "../contexts/HostThemeContext/index-KkaEtH_8.js";
3
3
  import { u as a } from "../node_modules-BHhXVwYT.js";
4
- import { T as l } from "../contexts/index-CvzLutB3.js";
4
+ import { T as l } from "../contexts/index-lSin3toV.js";
5
5
  function S() {
6
6
  const e = n(!0);
7
7
  return r(
@@ -1,6 +1,6 @@
1
1
  import { useContext as t } from "react";
2
2
  import { u as r } from "../../node_modules-BHhXVwYT.js";
3
- import { R as n } from "../../contexts/index-CvzLutB3.js";
3
+ import { R as n } from "../../contexts/index-lSin3toV.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,13 +1,13 @@
1
- import { G as s } from "./components/GlobalStyle/index-DHBkshRk.js";
1
+ import { G as s } from "./components/GlobalStyle/index-BwMNLyTC.js";
2
2
  import { L as r, a, g as i } from "./contexts/LocalesContext/index--VwMF60R.js";
3
3
  import { F as m, a as p } from "./contexts/FormatterContext/index-BHG3bJJo.js";
4
- import { R as x, a as f, T as d, b as l, d as v } from "./contexts/index-CvzLutB3.js";
5
- import { H as T, a as g } from "./contexts/HostThemeContext/index-C5Z07fH1.js";
4
+ import { R as x, a as f, T as d, b as l, d as v } from "./contexts/index-lSin3toV.js";
5
+ import { H as T, a as g } from "./contexts/HostThemeContext/index-KkaEtH_8.js";
6
6
  import { u as R } from "./hooks/useFirstRender/index-B-Q0TTn0.js";
7
7
  import { u as c } from "./hooks/useFormatter/index-DfdAcbzw.js";
8
- import { b as P, u as b, a as L, c as H, d as k } from "./hooks/index-Cg3zl6cl.js";
8
+ import { b as P, u as b, a as L, c as H, d as k } from "./hooks/index-BFpjMXdG.js";
9
9
  import { u as z } from "./hooks/useLocales/index-mTHn9nqY.js";
10
- import { u as I, a as M } from "./hooks/useResponsive/index-Cq8kt3PV.js";
10
+ import { u as I, a as M } from "./hooks/useResponsive/index-CH-gd9zy.js";
11
11
  import { u as y } from "./hooks/useIsMobile/index-Bro0dV28.js";
12
12
  import { C as D, g as E } from "./utils/index-DZG6QXjf.js";
13
13
  export {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "2.0.4",
3
+ "version": "3.0.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "dependencies": {
7
7
  "@m4l/core": "^2.0.0",
8
- "@m4l/styles": "^2.0.0",
8
+ "@m4l/styles": "^3.0.0",
9
9
  "date-fns": "^2.30.0",
10
10
  "zustand": "4.3.6",
11
11
  "immer": "^9.0.21"
package/vite-env.d.ts CHANGED
@@ -1 +1 @@
1
- /// <reference types="vite/client" />
1
+ /// <reference types="vite/client" />
@@ -1,278 +0,0 @@
1
- import { createContext as f, useRef as T, useMemo as O, useLayoutEffect as y } from "react";
2
- import { c as v, d as R, i as x, l as b } from "../node_modules-BHhXVwYT.js";
3
- import { jsx as P } from "react/jsx-runtime";
4
- import { useNetwork as E, useLocalStorageWithListener as M } from "@m4l/core";
5
- import { getColorPresets as g, getColorState as d, typography as w, palette as C, SECONDARY as L, COMMON as A, ERROR as N, WARNING as D, INFO as B, SUCCESS as z, shadows as p, createCustomShadows as W, defaultThemeOptions as $, colorPresets as j } from "@m4l/styles";
6
- import { alpha as _ } from "@mui/system";
7
- const u = { xs: 600, sm: 900, md: 1200, lg: 1536, xl: 1920 }, I = (r) => {
8
- const n = {
9
- ...r
10
- };
11
- return v(
12
- R(
13
- x((o, t) => ({
14
- ...n,
15
- responsiveContainerActions: {
16
- setBreakpoint: (e) => {
17
- o((s) => {
18
- s.breakPoint = e, s.isUpSm = e !== "xs" && e !== "sm", s.isXs = e == "xs";
19
- });
20
- }
21
- }
22
- })),
23
- { name: "Responsive Relative Store" }
24
- )
25
- );
26
- }, U = f(null), J = (r) => {
27
- const {
28
- children: n,
29
- observedDivRef: o
30
- } = r, t = T();
31
- t.current || (t.current = I({
32
- breakPoint: "md",
33
- isUpSm: !1,
34
- isXs: !1
35
- }));
36
- const e = () => {
37
- const i = o;
38
- if (i instanceof HTMLElement && i.clientWidth) {
39
- const a = Object.keys(u);
40
- for (let c = 0; c < a.length; c++) {
41
- const m = a[c];
42
- if (i.clientWidth <= u[m]) {
43
- t.current?.getState().responsiveContainerActions.setBreakpoint(m);
44
- break;
45
- } else c === a.length - 1 && i.clientWidth >= u[m] && t.current?.getState().responsiveContainerActions.setBreakpoint(m);
46
- }
47
- }
48
- }, s = O(() => b.throttle(e, 200, {
49
- leading: !1,
50
- trailing: !0
51
- }), [e]);
52
- return y(() => {
53
- const i = () => {
54
- s();
55
- }, a = o;
56
- if (a && a instanceof Element) {
57
- const c = new ResizeObserver((m) => {
58
- i();
59
- });
60
- return c.observe(a), () => {
61
- c.disconnect();
62
- };
63
- }
64
- }, [o]), /* @__PURE__ */ P(U.Provider, {
65
- value: t.current,
66
- children: n
67
- });
68
- }, S = {
69
- themeMode: "light",
70
- themeDirection: "ltr",
71
- themeColorPresets: "patronus",
72
- themeLayout: "horizontal",
73
- themeStretch: !1
74
- };
75
- function k(r, n = "m4l") {
76
- const o = document.querySelector('[data-mui-color-scheme="light"]');
77
- if (!o) {
78
- console.error('Element with data-mui-color-scheme="light" not found.');
79
- return;
80
- }
81
- Object.keys(r).forEach((t) => {
82
- const e = r[t];
83
- if (typeof e == "string" || typeof e == "number") {
84
- const s = `--${n}-${t}`;
85
- o.style.setProperty(s, e.toString());
86
- } else typeof e == "object" && e !== null && k(e, `${n}-${t}`);
87
- });
88
- }
89
- const h = (r) => {
90
- const n = r.currentThemeSettings || S;
91
- console.log("getColorPresets", g(n.themeColorPresets)), console.log(
92
- "getColorState",
93
- d(n.themeColorPresets, n.themeMode)
94
- );
95
- const o = n.themeMode === "light";
96
- r.themeOptions = {
97
- ...r.themeOptions,
98
- typography: w,
99
- palette: {
100
- ...r.themeOptions?.palette ?? {},
101
- ...o ? C.light : C.dark,
102
- primary: g(n.themeColorPresets),
103
- state: d(n.themeColorPresets, n.themeMode),
104
- representative: n.themeMode === "light" ? g(n.themeColorPresets)?.light : g(n.themeColorPresets)?.darker,
105
- secondary: {
106
- ...L,
107
- contrastText: "",
108
- mainChannel: "",
109
- lightChannel: "",
110
- darkChannel: "",
111
- contrastTextChannel: ""
112
- },
113
- common: {
114
- ...A,
115
- black: "#000",
116
- white: "#fff",
117
- background: "",
118
- backgroundChannel: "",
119
- onBackground: "",
120
- onBackgroundChannel: ""
121
- },
122
- error: {
123
- ...N,
124
- contrastText: "",
125
- mainChannel: "",
126
- lightChannel: "",
127
- darkChannel: "",
128
- contrastTextChannel: ""
129
- },
130
- warning: {
131
- ...D,
132
- contrastText: "",
133
- mainChannel: "",
134
- lightChannel: "",
135
- darkChannel: "",
136
- contrastTextChannel: ""
137
- },
138
- info: {
139
- ...B,
140
- contrastText: "",
141
- mainChannel: "",
142
- lightChannel: "",
143
- darkChannel: "",
144
- contrastTextChannel: ""
145
- },
146
- success: {
147
- ...z,
148
- contrastText: "",
149
- mainChannel: "",
150
- lightChannel: "",
151
- darkChannel: "",
152
- contrastTextChannel: ""
153
- }
154
- },
155
- shape: { borderRadius: 8 },
156
- direction: n.themeDirection,
157
- shadows: o ? p.light : p.dark,
158
- customShadows: {
159
- primary: `0 8px 16px 0 ${_(
160
- g(n.themeColorPresets)?.main || "#fff",
161
- 0.2
162
- )}`,
163
- ...W(n.themeMode)
164
- },
165
- stretch: n.themeStretch
166
- }, k(r.themeOptions);
167
- }, l = (r) => {
168
- r.setterThemeSettings && r.setterThemeSettings(r.currentThemeSettings);
169
- }, K = (r) => v(
170
- R(
171
- x((n, o) => ({
172
- ...r,
173
- settingsActions: {
174
- init: () => {
175
- n((t) => {
176
- h(t);
177
- });
178
- },
179
- // setThemeOptions: newObj => {
180
- // set(state => {
181
- // state.themeOptions = { ...state.themeOptions, ...newObj };
182
- // });
183
- // },
184
- setThemeSettings: (t) => {
185
- n((e) => {
186
- e.currentThemeSettings = { ...e.currentThemeSettings, ...t }, l(e), h(e);
187
- });
188
- },
189
- onChangeMode: (t) => {
190
- n((e) => {
191
- e.currentThemeSettings = {
192
- ...e.currentThemeSettings,
193
- themeMode: t.target.value
194
- }, l(e), h(e);
195
- });
196
- },
197
- handleOpen: () => {
198
- n((t) => {
199
- t.open = !t.open;
200
- });
201
- },
202
- onChangeDirection: (t) => {
203
- n((e) => {
204
- e.currentThemeSettings = {
205
- ...e.currentThemeSettings,
206
- themeDirection: t.target.value
207
- }, l(e), h(e);
208
- });
209
- },
210
- onChangeColor: (t) => {
211
- n((e) => {
212
- e.currentThemeSettings = {
213
- ...e.currentThemeSettings,
214
- themeColorPresets: t.target.value
215
- }, l(e), h(e);
216
- });
217
- },
218
- onChangeLayout: (t) => {
219
- n((e) => {
220
- e.currentThemeSettings = {
221
- ...e.currentThemeSettings,
222
- themeLayout: t.target.value
223
- }, l(e), h(e);
224
- });
225
- },
226
- onToggleStretch: () => {
227
- n((t) => {
228
- t.currentThemeSettings = {
229
- ...t.currentThemeSettings,
230
- themeStretch: !t.currentThemeSettings.themeStretch
231
- }, l(t), h(t);
232
- });
233
- },
234
- onResetSetting: () => {
235
- n((t) => {
236
- t.currentThemeSettings = {
237
- ...S
238
- }, l(t), h(t);
239
- });
240
- }
241
- }
242
- })),
243
- { name: "ExampleStore" }
244
- )
245
- ), X = f(null);
246
- function Q({
247
- children: r,
248
- themeSettings: n
249
- }) {
250
- const {
251
- networkOperation: o
252
- } = E(), [t, e] = M("theme_setting", {}), s = T();
253
- return s.current || (s.current = K({
254
- networkOperation: o,
255
- currentThemeSettings: {
256
- ...S,
257
- ...n,
258
- ...t
259
- },
260
- themeOptions: $,
261
- colorOption: j.map((i) => ({
262
- name: i.name,
263
- value: i.main
264
- })),
265
- open: !1,
266
- setterThemeSettings: n ? void 0 : e
267
- }), s.current.getState().settingsActions.init()), /* @__PURE__ */ P(X.Provider, {
268
- value: s.current,
269
- children: r
270
- });
271
- }
272
- export {
273
- U as R,
274
- X as T,
275
- J as a,
276
- Q as b,
277
- S as d
278
- };