@maz-ui/themes 4.0.1 → 4.1.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,10 +1,10 @@
1
+ import { initThemeState as T, useTheme as a } from "./useTheme.js";
1
2
  import "vue";
2
3
  import "../utils/cookie-storage.js";
3
4
  import "../utils/css-generator.js";
4
5
  import "../utils/get-color-mode.js";
5
6
  import "../utils/get-preset.js";
6
7
  import "../utils/preset-merger.js";
7
- import { initThemeState as T, useTheme as a } from "./useTheme.js";
8
8
  export {
9
9
  T as initThemeState,
10
10
  a as useTheme
@@ -1,20 +1,60 @@
1
- import { ref as g, computed as a, watchEffect as p, inject as v, getCurrentInstance as c, watch as y } from "vue";
2
- import { setCookie as k } from "../utils/cookie-storage.js";
3
- import { generateCriticalCSS as S, generateFullCSS as M, injectCSS as s, CSS_IDS as u } from "../utils/css-generator.js";
4
- import { getColorMode as h, isSystemPrefersDark as P } from "../utils/get-color-mode.js";
5
- import { getPreset as C } from "../utils/get-preset.js";
6
- import { mergePresets as T } from "../utils/preset-merger.js";
7
- const r = g();
8
- function d(e) {
1
+ import { ref as d, onMounted as k, computed as s, toValue as P, watch as y, watchEffect as w, inject as T, getCurrentInstance as S } from "vue";
2
+ import { setCookie as C } from "../utils/cookie-storage.js";
3
+ import { generateCriticalCSS as z, generateFullCSS as E, injectCSS as p, CSS_IDS as v } from "../utils/css-generator.js";
4
+ import { getColorMode as L, isSystemPrefersDark as x } from "../utils/get-color-mode.js";
5
+ import { getPreset as D } from "../utils/get-preset.js";
6
+ import { mergePresets as I } from "../utils/preset-merger.js";
7
+ function O() {
8
+ return typeof document > "u" || typeof globalThis.window > "u";
9
+ }
10
+ function $() {
11
+ return typeof document < "u";
12
+ }
13
+ function F(e) {
14
+ return !!e;
15
+ }
16
+ function R(e, o, r = {}) {
17
+ const {
18
+ internalWindow: u = $() ? globalThis : void 0,
19
+ ...l
20
+ } = r;
21
+ let n;
22
+ const c = d(!1);
23
+ k(() => {
24
+ c.value = (u && "MutationObserver" in u) ?? !1;
25
+ });
26
+ const m = () => {
27
+ n && (n.disconnect(), n = void 0);
28
+ }, h = s(() => {
29
+ const a = P(e);
30
+ let i;
31
+ return a && "$el" in a ? i = a.$el : a && (i = a), new Set([i].filter(F));
32
+ }), b = y(
33
+ h,
34
+ (a) => {
35
+ m(), c.value && a.size && (n = new MutationObserver(o), a.forEach((i) => n.observe(i, l)));
36
+ },
37
+ { immediate: !0, flush: "post" }
38
+ );
39
+ return {
40
+ isSupported: c,
41
+ stop: () => {
42
+ b(), m();
43
+ },
44
+ takeRecords: () => n?.takeRecords()
45
+ };
46
+ }
47
+ const t = d();
48
+ function M(e) {
9
49
  typeof document > "u" || !e || e.darkModeStrategy === "media" || e.mode === "light" || (e.isDark ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark"));
10
50
  }
11
- function w() {
12
- const e = c()?.appContext.app;
13
- e && r.value && (e.config.globalProperties.$mazThemeState = r.value);
51
+ function U() {
52
+ const e = S()?.appContext.app;
53
+ e && t.value && (e.config.globalProperties.$mazThemeState = t.value);
14
54
  }
15
- function b(e) {
55
+ function j(e) {
16
56
  if (e.currentPreset && e.colorMode !== void 0) {
17
- l({
57
+ g({
18
58
  currentPreset: e.currentPreset,
19
59
  colorMode: e.colorMode,
20
60
  mode: e.mode,
@@ -24,86 +64,98 @@ function b(e) {
24
64
  });
25
65
  return;
26
66
  }
27
- const t = h(e.colorMode), o = t === "auto" ? P() : t === "dark";
28
- l({
67
+ const o = L(e.colorMode), r = o === "auto" ? x() : o === "dark";
68
+ g({
29
69
  currentPreset: e.currentPreset,
30
- colorMode: t,
70
+ colorMode: o,
31
71
  mode: e.mode,
32
- isDark: o,
72
+ isDark: r,
33
73
  strategy: e.strategy,
34
74
  darkModeStrategy: e.darkModeStrategy
35
75
  });
36
76
  }
37
- function l(e) {
38
- if (r.value = e, typeof globalThis.window < "u" && r.value.colorMode === "auto") {
39
- const t = globalThis.matchMedia("(prefers-color-scheme: dark)"), o = () => {
40
- r.value && r.value.colorMode === "auto" && (r.value.isDark = t.matches);
77
+ function g(e) {
78
+ if (t.value = e, typeof globalThis.window < "u" && t.value.colorMode === "auto") {
79
+ const o = globalThis.matchMedia("(prefers-color-scheme: dark)"), r = () => {
80
+ t.value && t.value.colorMode === "auto" && (t.value.isDark = o.matches);
41
81
  };
42
- t.addEventListener("change", o), o();
82
+ o.addEventListener("change", r), r();
43
83
  }
44
- p(() => {
45
- r.value && (d(r.value), w());
84
+ w(() => {
85
+ t.value && (M(t.value), U());
46
86
  });
47
87
  }
48
- const z = a({
49
- get: () => r.value?.colorMode,
50
- set: (e) => n(e)
51
- }), E = a(() => r.value?.isDark ?? !1), L = a(() => r.value?.strategy), x = a(() => r.value?.mode), I = a(() => r.value?.darkModeStrategy), D = a(() => r.value?.currentPreset?.name);
52
- async function F(e) {
53
- if (!r.value)
88
+ const N = s({
89
+ get: () => t.value?.colorMode,
90
+ set: (e) => f(e)
91
+ }), W = s(() => t.value?.isDark ?? !1), _ = s(() => t.value?.strategy), A = s(() => t.value?.mode), G = s(() => t.value?.darkModeStrategy), Q = s(() => t.value?.currentPreset?.name);
92
+ async function V(e) {
93
+ if (!t.value)
54
94
  return;
55
- const t = typeof e == "string" ? await C(e) : e;
56
- if (!t || !r.value.currentPreset) {
95
+ const o = typeof e == "string" ? await D(e) : e;
96
+ if (!o || !t.value.currentPreset) {
57
97
  console.error("[@maz-ui/themes] No preset found - If you are using the buildtime strategy, you must provide a complete preset");
58
98
  return;
59
99
  }
60
- const o = "name" in t && t.name !== r.value.currentPreset.name ? t : T(r.value.currentPreset, t);
61
- if (r.value.currentPreset = o, r.value.strategy === "runtime" || r.value.strategy === "hybrid") {
62
- const i = {
63
- mode: r.value.mode,
64
- darkSelectorStrategy: r.value.darkModeStrategy,
100
+ const r = "name" in o && o.name !== t.value.currentPreset.name ? o : I(t.value.currentPreset, o);
101
+ if (t.value.currentPreset = r, t.value.strategy === "runtime" || t.value.strategy === "hybrid") {
102
+ const u = {
103
+ mode: t.value.mode,
104
+ darkSelectorStrategy: t.value.darkModeStrategy,
65
105
  prefix: "maz"
66
- }, m = S(o, i), f = M(o, i);
67
- s(u.CRITICAL, m), s(u.FULL, f);
106
+ }, l = z(r, u), n = E(r, u);
107
+ p(v.CRITICAL, l), p(v.FULL, n);
68
108
  }
69
109
  }
70
- function n(e) {
71
- r.value && (r.value.colorMode = e, e === "auto" ? r.value.isDark = typeof globalThis.window < "u" && globalThis.matchMedia("(prefers-color-scheme: dark)").matches : r.value.isDark = e === "dark", d(r.value), k("maz-color-mode", e));
110
+ function f(e) {
111
+ t.value && (t.value.colorMode = e, e === "auto" ? t.value.isDark = typeof globalThis.window < "u" && globalThis.matchMedia("(prefers-color-scheme: dark)").matches : t.value.isDark = e === "dark", M(t.value), C("maz-color-mode", e));
72
112
  }
73
- function U() {
74
- r.value && n(r.value.isDark ? "light" : "dark");
113
+ function Y() {
114
+ t.value && f(t.value.isDark ? "light" : "dark");
75
115
  }
76
- function O() {
77
- let e;
116
+ function te() {
117
+ const e = d();
118
+ k(() => {
119
+ e.value = document.documentElement;
120
+ }), R(
121
+ e,
122
+ () => {
123
+ !t.value || O() || (t.value.isDark = document.documentElement.classList.contains("dark"));
124
+ },
125
+ {
126
+ attributes: !0
127
+ }
128
+ );
129
+ let o;
78
130
  try {
79
- if (e = v("mazThemeState", void 0), !e)
131
+ if (o = T("mazThemeState", void 0), !o)
80
132
  throw new Error("mazThemeState not found");
81
133
  } catch {
82
- const t = c();
83
- t?.appContext?.app?.config?.globalProperties && (e = t.appContext.app.config.globalProperties.$mazThemeState);
134
+ const r = S();
135
+ r?.appContext?.app?.config?.globalProperties && (o = r.appContext.app.config.globalProperties.$mazThemeState);
84
136
  }
85
- if (e && (r.value ? (typeof document > "u" || typeof globalThis.window > "u") && (r.value = {
86
- ...r.value,
87
- ...e
88
- }) : b(e)), y(() => e?.currentPreset, (t) => {
89
- r.value && t && (r.value.currentPreset = t);
137
+ if (o && (t.value ? (typeof document > "u" || typeof globalThis.window > "u") && (t.value = {
138
+ ...t.value,
139
+ ...o
140
+ }) : j(o)), y(() => o?.currentPreset, (r) => {
141
+ t.value && r && (t.value.currentPreset = r);
90
142
  }, {
91
143
  once: !0
92
- }), !r.value)
144
+ }), !t.value)
93
145
  throw new Error("[@maz-ui/themes] You must install the MazUi or MazUiTheme plugin before using useTheme composable");
94
146
  return {
95
- presetName: D,
96
- colorMode: z,
97
- isDark: E,
98
- strategy: L,
99
- updateTheme: F,
100
- setColorMode: n,
101
- toggleDarkMode: U,
102
- mode: x,
103
- darkModeStrategy: I
147
+ presetName: Q,
148
+ colorMode: N,
149
+ isDark: W,
150
+ strategy: _,
151
+ updateTheme: V,
152
+ setColorMode: f,
153
+ toggleDarkMode: Y,
154
+ mode: A,
155
+ darkModeStrategy: G
104
156
  };
105
157
  }
106
158
  export {
107
- l as initThemeState,
108
- O as useTheme
159
+ g as initThemeState,
160
+ te as useTheme
109
161
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../src/composables/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA2DhJ,wBAAgB,cAAc,CAAC,YAAY,EAAE,UAAU,QAsBtD;AAaD,iBAAe,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,oBAAoB,GAAG,eAAe,iBA8BtF;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,SAAS,QAgBzC;AAED,iBAAS,cAAc,SAKtB;AAED,wBAAgB,QAAQ;;;;;;;;;;EAoDvB"}
1
+ {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../src/composables/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QA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AmB,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,kBAGR,GACA,MAAM,CAwCR;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,cAGR,GACA,MAAM,CA4CR;AAoHD,oBAAY,OAAO;IACjB,IAAI,mBAAmB;IACvB,QAAQ,uBAAuB;CAChC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CA2BxD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAS3C"}
@@ -27,164 +27,178 @@ const h = [
27
27
  "base-font-size",
28
28
  "border-width"
29
29
  ], S = ["primary", "secondary", "accent", "destructive", "success", "warning", "info", "contrast", "background", "foreground", "border", "muted", "overlay", "shadow"];
30
- function j(e, o = {
30
+ function j(r, t = {
31
31
  mode: "both",
32
32
  darkSelectorStrategy: "class"
33
33
  }) {
34
34
  const {
35
- criticalColors: r = h,
36
- criticalFoundation: c = C,
37
- mode: t,
38
- darkSelectorStrategy: s,
35
+ criticalColors: e = h,
36
+ criticalFoundation: o = C,
37
+ mode: n,
38
+ darkSelectorStrategy: l,
39
39
  prefix: i = "maz"
40
- } = o, l = y(e.foundation, c);
41
- let n = `@layer maz-ui-theme {
40
+ } = t, s = y(r.foundation, o);
41
+ let c = `@layer maz-ui-theme {
42
42
  `;
43
- if (t === "light" || t === "both") {
44
- const a = m(e.colors.light, r);
45
- n += f({
43
+ if (n === "light" || n === "both") {
44
+ const a = m(r.colors.light, e);
45
+ c += f({
46
46
  selector: ":root",
47
47
  colors: a,
48
- foundation: l,
48
+ foundation: s,
49
49
  prefix: i
50
50
  });
51
51
  }
52
- if (t === "dark" || t === "both") {
53
- const a = m(e.colors.dark, r);
54
- n += f({
55
- selector: s === "media" ? ":root" : ".dark",
56
- mediaQuery: s === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
52
+ if (n === "dark" || n === "both") {
53
+ const a = m(r.colors.dark, e);
54
+ c += f({
55
+ selector: l === "media" ? ":root" : ".dark",
56
+ mediaQuery: l === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
57
57
  colors: a,
58
- foundation: l,
58
+ foundation: s,
59
59
  prefix: i
60
60
  });
61
61
  }
62
- return n += `}
63
- `, n;
62
+ return c += `}
63
+ `, c;
64
64
  }
65
- function p(e, o = {
65
+ function p(r, t = {
66
66
  mode: "both",
67
67
  darkSelectorStrategy: "class"
68
68
  }) {
69
69
  const {
70
- excludeCritical: r = h,
71
- mode: c,
72
- darkSelectorStrategy: t,
73
- prefix: s = "maz",
70
+ excludeCritical: e = h,
71
+ mode: o,
72
+ darkSelectorStrategy: n,
73
+ prefix: l = "maz",
74
74
  includeColorScales: i = !0
75
- } = o, l = k(e.foundation, C);
76
- let n = `@layer maz-ui-theme {
75
+ } = t, s = k(r.foundation, C);
76
+ let c = `@layer maz-ui-theme {
77
77
  `;
78
- if (c === "light" || c === "both") {
79
- const a = g(e.colors.light, r);
80
- n += f({
78
+ if (o === "light" || o === "both") {
79
+ const a = g(r.colors.light, e);
80
+ c += f({
81
81
  selector: ":root",
82
82
  colors: a,
83
- foundation: l,
84
- prefix: s,
83
+ foundation: s,
84
+ prefix: l,
85
85
  includeScales: i,
86
- preset: e
86
+ preset: r
87
87
  });
88
88
  }
89
- if (c === "dark" || c === "both") {
90
- const a = g(e.colors.dark, r);
91
- n += f({
92
- selector: t === "media" ? ":root" : ".dark",
93
- mediaQuery: t === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
89
+ if (o === "dark" || o === "both") {
90
+ const a = g(r.colors.dark, e);
91
+ c += f({
92
+ selector: n === "media" ? ":root" : ".dark",
93
+ mediaQuery: n === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
94
94
  colors: a,
95
- foundation: c === "dark" ? l : void 0,
95
+ foundation: o === "dark" ? s : void 0,
96
96
  // Appearance only if dark mode only
97
- prefix: s,
97
+ prefix: l,
98
98
  includeScales: i,
99
- preset: e,
99
+ preset: r,
100
100
  isDark: !0
101
101
  });
102
102
  }
103
- return n += `}
104
- `, n;
103
+ return c += `}
104
+ `, c;
105
105
  }
106
- function m(e, o) {
106
+ function m(r, t) {
107
107
  return Object.fromEntries(
108
- o.filter((r) => e[r]).map((r) => [r, e[r]])
108
+ t.filter((e) => r[e]).map((e) => [e, r[e]])
109
109
  );
110
110
  }
111
- function y(e, o) {
112
- return e ? Object.fromEntries(
113
- o.filter((r) => e[r]).map((r) => [r, e[r]])
111
+ function y(r, t) {
112
+ return r ? Object.fromEntries(
113
+ t.filter((e) => r[e]).map((e) => [e, r[e]])
114
114
  ) : {};
115
115
  }
116
- function g(e, o) {
116
+ function g(r, t) {
117
117
  return Object.fromEntries(
118
- Object.entries(e).filter(([r]) => !o.includes(r))
118
+ Object.entries(r).filter(([e]) => !t.includes(e))
119
119
  );
120
120
  }
121
- function k(e, o) {
122
- return e ? Object.fromEntries(
123
- Object.entries(e).filter(([r]) => !o.includes(r))
121
+ function k(r, t) {
122
+ return r ? Object.fromEntries(
123
+ Object.entries(r).filter(([e]) => !t.includes(e))
124
124
  ) : {};
125
125
  }
126
126
  function f({
127
- selector: e,
128
- mediaQuery: o,
129
- colors: r,
130
- foundation: c,
131
- prefix: t,
132
- includeScales: s = !1,
127
+ selector: r,
128
+ mediaQuery: t,
129
+ colors: e,
130
+ foundation: o,
131
+ prefix: n,
132
+ includeScales: l = !1,
133
133
  preset: i,
134
- isDark: l = !1
134
+ isDark: s = !1
135
135
  }) {
136
- const n = [];
137
- if (r && Object.entries(r).forEach(([u, d]) => {
138
- d && n.push(` --${t}-${u}: ${d};`);
139
- }), c && Object.entries(c).forEach(([u, d]) => {
140
- d && n.push(` --${t}-${u}: ${d};`);
141
- }), s && i) {
142
- const u = l ? i.colors.dark : i.colors.light, d = E(u, t);
143
- n.push(...d);
136
+ const c = [];
137
+ if (e && Object.entries(e).forEach(([u, d]) => {
138
+ d && c.push(` --${n}-${u}: ${d};`);
139
+ }), o && Object.entries(o).forEach(([u, d]) => {
140
+ d && c.push(` --${n}-${u}: ${d};`);
141
+ }), l && i) {
142
+ const u = s ? i.colors.dark : i.colors.light, d = $(u, n);
143
+ c.push(...d);
144
144
  }
145
- const a = n.join(`
145
+ const a = c.join(`
146
146
  `);
147
- return o ? `
148
- ${o} {
149
- ${e} {
147
+ return t ? `
148
+ ${t} {
149
+ ${r} {
150
150
  ${a.replace(/^/gm, " ")}
151
151
  }
152
152
  }
153
153
  ` : `
154
- ${e} {
154
+ ${r} {
155
155
  ${a}
156
156
  }
157
157
  `;
158
158
  }
159
- function E(e, o) {
160
- const r = [];
161
- return S.forEach((c) => {
162
- const t = e[c];
163
- if (t) {
164
- const s = b(t);
165
- Object.entries(s).forEach(([i, l]) => {
166
- r.push(` --${o}-${c}-${i}: ${l};`);
159
+ function $(r, t) {
160
+ const e = [];
161
+ return S.forEach((o) => {
162
+ const n = r[o];
163
+ if (n) {
164
+ const l = b(n);
165
+ Object.entries(l).forEach(([i, s]) => {
166
+ e.push(` --${t}-${o}-${i}: ${s};`);
167
167
  });
168
168
  }
169
- }), r;
169
+ }), e;
170
170
  }
171
- var $ = /* @__PURE__ */ ((e) => (e.FULL = "maz-theme-full", e.CRITICAL = "maz-theme-critical", e))($ || {});
172
- function v(e, o) {
171
+ var E = /* @__PURE__ */ ((r) => (r.FULL = "maz-theme-full", r.CRITICAL = "maz-theme-critical", r))(E || {});
172
+ function v(r, t) {
173
173
  if (typeof document > "u")
174
174
  return;
175
- let r = document.getElementById(e);
176
- r || (r = document.createElement("style"), r.id = e, document.head.appendChild(r)), r.textContent = o;
175
+ const e = document.querySelectorAll(`#${r}`);
176
+ if (!e || e.length === 0) {
177
+ const o = document.createElement("style");
178
+ o.id = r, document.head.appendChild(o), o.textContent = t;
179
+ return;
180
+ }
181
+ if (e.length === 1) {
182
+ e[0].textContent = t;
183
+ return;
184
+ }
185
+ if (e.length > 1) {
186
+ for (let o = 0; o < e.length - 1; o++)
187
+ e[o].remove();
188
+ e[e.length - 1].textContent = t;
189
+ }
177
190
  }
178
- function F(e) {
191
+ function x(r) {
179
192
  if (typeof document > "u")
180
193
  return;
181
- const o = document.getElementById(e);
182
- o && o.remove();
194
+ const t = document.querySelectorAll(`#${r}`);
195
+ for (const e of t)
196
+ e && e.remove();
183
197
  }
184
198
  export {
185
- $ as CSS_IDS,
199
+ E as CSS_IDS,
186
200
  j as generateCriticalCSS,
187
201
  p as generateFullCSS,
188
202
  v as injectCSS,
189
- F as removeCSS
203
+ x as removeCSS
190
204
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maz-ui/themes",
3
3
  "type": "module",
4
- "version": "4.0.1",
4
+ "version": "4.1.0",
5
5
  "description": "Theme system for Maz-UI with TypeScript support and CSS variables",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -102,5 +102,5 @@
102
102
  "lint-staged": {
103
103
  "*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
104
104
  },
105
- "gitHead": "39f013f863dab2a784450b73aa0da3fdda6c56d8"
105
+ "gitHead": "2f2ef4e0c3db8e64b814aa3c7c5a409e06af48af"
106
106
  }