@maz-ui/themes 4.0.0-beta.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +163 -0
  3. package/dist/build/index.js +52 -0
  4. package/dist/composables/index.js +11 -0
  5. package/dist/composables/useTheme.js +95 -0
  6. package/dist/define-preset.js +11 -0
  7. package/dist/index.js +36 -0
  8. package/dist/plugin/index.js +8 -0
  9. package/dist/plugin.js +65 -0
  10. package/dist/presets/index.js +10 -0
  11. package/dist/presets/mazUi.js +62 -0
  12. package/dist/presets/obsidian.js +65 -0
  13. package/dist/presets/ocean.js +63 -0
  14. package/dist/presets/pristine.js +62 -0
  15. package/dist/types/build/index.d.ts +37 -0
  16. package/dist/types/build/index.d.ts.map +1 -0
  17. package/dist/types/composables/useTheme.d.ts +16 -0
  18. package/dist/types/composables/useTheme.d.ts.map +1 -0
  19. package/dist/types/define-preset.d.ts +44 -0
  20. package/dist/types/define-preset.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +10 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/plugin.d.ts +61 -0
  24. package/dist/types/plugin.d.ts.map +1 -0
  25. package/dist/types/presets/index.d.ts +5 -0
  26. package/dist/types/presets/index.d.ts.map +1 -0
  27. package/dist/types/presets/mazUi.d.ts +3 -0
  28. package/dist/types/presets/mazUi.d.ts.map +1 -0
  29. package/dist/types/presets/obsidian.d.ts +3 -0
  30. package/dist/types/presets/obsidian.d.ts.map +1 -0
  31. package/dist/types/presets/ocean.d.ts +3 -0
  32. package/dist/types/presets/ocean.d.ts.map +1 -0
  33. package/dist/types/presets/pristine.d.ts +3 -0
  34. package/dist/types/presets/pristine.d.ts.map +1 -0
  35. package/dist/types/types/index.d.ts +127 -0
  36. package/dist/types/types/index.d.ts.map +1 -0
  37. package/dist/types/utils/color-utils.d.ts +11 -0
  38. package/dist/types/utils/color-utils.d.ts.map +1 -0
  39. package/dist/types/utils/cookie-storage.d.ts +3 -0
  40. package/dist/types/utils/cookie-storage.d.ts.map +1 -0
  41. package/dist/types/utils/css-generator.d.ts +46 -0
  42. package/dist/types/utils/css-generator.d.ts.map +1 -0
  43. package/dist/types/utils/get-color-mode.d.ts +4 -0
  44. package/dist/types/utils/get-color-mode.d.ts.map +1 -0
  45. package/dist/types/utils/get-preset.d.ts +5 -0
  46. package/dist/types/utils/get-preset.d.ts.map +1 -0
  47. package/dist/types/utils/index.d.ts +6 -0
  48. package/dist/types/utils/index.d.ts.map +1 -0
  49. package/dist/types/utils/preset-merger.d.ts +4 -0
  50. package/dist/types/utils/preset-merger.d.ts.map +1 -0
  51. package/dist/utils/color-utils.js +77 -0
  52. package/dist/utils/cookie-storage.js +13 -0
  53. package/dist/utils/css-generator.js +166 -0
  54. package/dist/utils/get-color-mode.js +14 -0
  55. package/dist/utils/get-preset.js +28 -0
  56. package/dist/utils/index.js +22 -0
  57. package/dist/utils/preset-merger.js +34 -0
  58. package/package.json +104 -0
@@ -0,0 +1,166 @@
1
+ import { generateColorScale as C } from "./color-utils.js";
2
+ const h = [
3
+ "background",
4
+ "foreground",
5
+ "primary",
6
+ "primary-foreground",
7
+ "secondary",
8
+ "secondary-foreground",
9
+ "accent",
10
+ "accent-foreground",
11
+ "destructive",
12
+ "destructive-foreground",
13
+ "success",
14
+ "success-foreground",
15
+ "warning",
16
+ "warning-foreground",
17
+ "info",
18
+ "info-foreground",
19
+ "contrast",
20
+ "contrast-foreground",
21
+ "muted",
22
+ "shadow",
23
+ "border"
24
+ ], b = [
25
+ "radius",
26
+ "font-family",
27
+ "base-font-size",
28
+ "border-width"
29
+ ], S = ["primary", "secondary", "accent", "destructive", "success", "warning", "info", "contrast", "background", "foreground", "border", "muted", "overlay", "shadow"];
30
+ function O(r, o = {}) {
31
+ const {
32
+ criticalColors: e = h,
33
+ criticalFoundation: c = b,
34
+ mode: n = "both",
35
+ darkSelectorStrategy: a = "class",
36
+ prefix: i = "maz"
37
+ } = o, d = m(r.colors.light, e), s = m(r.colors.dark, e), l = y(r.foundation, c);
38
+ let t = `@layer maz-ui-theme {
39
+ `;
40
+ return (n === "light" || n === "both") && (t += f({
41
+ selector: ":root",
42
+ colors: d,
43
+ foundation: l,
44
+ prefix: i
45
+ })), (n === "dark" || n === "both") && (t += f({
46
+ selector: a === "media" ? ":root" : ".dark",
47
+ mediaQuery: a === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
48
+ colors: s,
49
+ foundation: l,
50
+ prefix: i
51
+ })), t += `}
52
+ `, t;
53
+ }
54
+ function j(r, o = {}) {
55
+ const {
56
+ excludeCritical: e = h,
57
+ mode: c = "both",
58
+ darkSelectorStrategy: n = "class",
59
+ prefix: a = "maz",
60
+ includeColorScales: i = !0
61
+ } = o, d = g(r.colors.light, e), s = g(r.colors.dark, e), l = k(r.foundation, b);
62
+ let t = `@layer maz-ui-theme {
63
+ `;
64
+ return (c === "light" || c === "both") && (t += f({
65
+ selector: ":root",
66
+ colors: d,
67
+ foundation: l,
68
+ prefix: a,
69
+ includeScales: i,
70
+ preset: r
71
+ })), (c === "dark" || c === "both") && (t += f({
72
+ selector: n === "media" ? ":root" : ".dark",
73
+ mediaQuery: n === "media" ? "@media (prefers-color-scheme: dark)" : void 0,
74
+ colors: s,
75
+ foundation: c === "dark" ? l : void 0,
76
+ // Appearance only if dark mode only
77
+ prefix: a,
78
+ includeScales: i,
79
+ preset: r,
80
+ isDark: !0
81
+ })), t += `}
82
+ `, t;
83
+ }
84
+ function m(r, o) {
85
+ return Object.fromEntries(
86
+ o.filter((e) => r[e]).map((e) => [e, r[e]])
87
+ );
88
+ }
89
+ function y(r, o) {
90
+ return r ? Object.fromEntries(
91
+ o.filter((e) => r[e]).map((e) => [e, r[e]])
92
+ ) : {};
93
+ }
94
+ function g(r, o) {
95
+ return Object.fromEntries(
96
+ Object.entries(r).filter(([e]) => !o.includes(e))
97
+ );
98
+ }
99
+ function k(r, o) {
100
+ return r ? Object.fromEntries(
101
+ Object.entries(r).filter(([e]) => !o.includes(e))
102
+ ) : {};
103
+ }
104
+ function f({
105
+ selector: r,
106
+ mediaQuery: o,
107
+ colors: e,
108
+ foundation: c,
109
+ prefix: n,
110
+ includeScales: a = !1,
111
+ preset: i,
112
+ isDark: d = !1
113
+ }) {
114
+ const s = [];
115
+ if (e && Object.entries(e).forEach(([t, u]) => {
116
+ u && s.push(` --${n}-${t}: ${u};`);
117
+ }), c && Object.entries(c).forEach(([t, u]) => {
118
+ u && s.push(` --${n}-${t}: ${u};`);
119
+ }), a && i) {
120
+ const t = d ? i.colors.dark : i.colors.light, u = E(t, n);
121
+ s.push(...u);
122
+ }
123
+ const l = s.join(`
124
+ `);
125
+ return o ? `
126
+ ${o} {
127
+ ${r} {
128
+ ${l.replace(/^/gm, " ")}
129
+ }
130
+ }
131
+ ` : `
132
+ ${r} {
133
+ ${l}
134
+ }
135
+ `;
136
+ }
137
+ function E(r, o) {
138
+ const e = [];
139
+ return S.forEach((c) => {
140
+ const n = r[c];
141
+ if (n) {
142
+ const a = C(n);
143
+ Object.entries(a).forEach(([i, d]) => {
144
+ e.push(` --${o}-${c}-${i}: ${d};`);
145
+ });
146
+ }
147
+ }), e;
148
+ }
149
+ function p(r, o = "maz-theme-vars") {
150
+ if (typeof document > "u")
151
+ return;
152
+ let e = document.getElementById(o);
153
+ e || (e = document.createElement("style"), e.id = o, document.head.appendChild(e)), e.textContent = r;
154
+ }
155
+ function v(r = "maz-theme-vars") {
156
+ if (typeof document > "u")
157
+ return;
158
+ const o = document.getElementById(r);
159
+ o && o.remove();
160
+ }
161
+ export {
162
+ O as generateCriticalCSS,
163
+ j as generateFullCSS,
164
+ p as injectCSS,
165
+ v as removeCSS
166
+ };
@@ -0,0 +1,14 @@
1
+ import { getCookie as t } from "./cookie-storage.js";
2
+ function o(e) {
3
+ if (e && ["light", "dark"].includes(e))
4
+ return e;
5
+ const r = t("maz-color-mode");
6
+ return r && ["light", "dark"].includes(r) ? r : i();
7
+ }
8
+ function i() {
9
+ return typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
10
+ }
11
+ export {
12
+ o as getColorMode,
13
+ i as getSystemPrefersDark
14
+ };
@@ -0,0 +1,28 @@
1
+ function t(i) {
2
+ return typeof i == "object" && i !== null && !!i.name;
3
+ }
4
+ async function o(i) {
5
+ if (t(i))
6
+ return i;
7
+ if (i === "mazUi" || !i || i === "maz-ui") {
8
+ const { mazUi: n } = await import("../presets/mazUi.js");
9
+ return n;
10
+ }
11
+ if (i === "ocean") {
12
+ const { ocean: n } = await import("../presets/ocean.js");
13
+ return n;
14
+ }
15
+ if (i === "pristine") {
16
+ const { pristine: n } = await import("../presets/pristine.js");
17
+ return n;
18
+ }
19
+ if (i === "obsidian") {
20
+ const { obsidian: n } = await import("../presets/obsidian.js");
21
+ return n;
22
+ }
23
+ throw new TypeError(`[@maz-ui/themes] Preset ${i} not found`);
24
+ }
25
+ export {
26
+ o as getPreset,
27
+ t as isPresetObject
28
+ };
@@ -0,0 +1,22 @@
1
+ import { adjustColorLightness as o, formatHSL as t, generateColorScale as s, getContrastColor as C, parseHSL as S } from "./color-utils.js";
2
+ import { getCookie as g, setCookie as m } from "./cookie-storage.js";
3
+ import { generateCriticalCSS as l, generateFullCSS as p, injectCSS as f, removeCSS as n } from "./css-generator.js";
4
+ import { getPreset as c, isPresetObject as j } from "./get-preset.js";
5
+ import { deepMerge as P, mergePresets as d } from "./preset-merger.js";
6
+ export {
7
+ o as adjustColorLightness,
8
+ P as deepMerge,
9
+ t as formatHSL,
10
+ s as generateColorScale,
11
+ l as generateCriticalCSS,
12
+ p as generateFullCSS,
13
+ C as getContrastColor,
14
+ g as getCookie,
15
+ c as getPreset,
16
+ f as injectCSS,
17
+ j as isPresetObject,
18
+ d as mergePresets,
19
+ S as parseHSL,
20
+ n as removeCSS,
21
+ m as setCookie
22
+ };
@@ -0,0 +1,34 @@
1
+ function f(n, o) {
2
+ return {
3
+ name: o.name || n.name,
4
+ foundation: {
5
+ ...n.foundation,
6
+ ...o.foundation
7
+ },
8
+ colors: {
9
+ light: u(n.colors.light, o.colors?.light),
10
+ dark: u(n.colors.dark, o.colors?.dark)
11
+ }
12
+ };
13
+ }
14
+ function u(n, o) {
15
+ return o ? {
16
+ ...n,
17
+ ...o
18
+ } : n;
19
+ }
20
+ function l(n, o) {
21
+ const t = { ...n };
22
+ for (const r in o) {
23
+ const c = o[r], e = t[r];
24
+ c !== void 0 && (i(c) && i(e) ? t[r] = l(e, c) : t[r] = c);
25
+ }
26
+ return t;
27
+ }
28
+ function i(n) {
29
+ return n !== null && typeof n == "object" && !Array.isArray(n);
30
+ }
31
+ export {
32
+ l as deepMerge,
33
+ f as mergePresets
34
+ };
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@maz-ui/themes",
3
+ "type": "module",
4
+ "version": "4.0.0-beta.0",
5
+ "description": "Theme system for Maz-UI with TypeScript support and CSS variables",
6
+ "author": "Louis Mazel <me@loicmazuel.com>",
7
+ "license": "MIT",
8
+ "homepage": "https://maz-ui.com/guide/themes",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/LouisMazel/maz-ui.git"
12
+ },
13
+ "bugs": "https://github.com/LouisMazel/maz-ui/issues",
14
+ "keywords": [
15
+ "vue",
16
+ "theme",
17
+ "css-variables",
18
+ "typescript",
19
+ "maz-ui"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/types/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./presets": {
30
+ "types": "./dist/types/presets/index.d.ts",
31
+ "import": "./dist/presets/index.js"
32
+ },
33
+ "./presets/*": {
34
+ "types": "./dist/types/presets/*.d.ts",
35
+ "import": "./dist/presets/*.js"
36
+ },
37
+ "./composables": {
38
+ "types": "./dist/types/composables/index.d.ts",
39
+ "import": "./dist/composables/index.js"
40
+ },
41
+ "./composables/*": {
42
+ "types": "./dist/types/composables/*.d.ts",
43
+ "import": "./dist/composables/*.js"
44
+ },
45
+ "./utils": {
46
+ "types": "./dist/types/utils/index.d.ts",
47
+ "import": "./dist/utils/index.js"
48
+ },
49
+ "./utils/*": {
50
+ "types": "./dist/types/utils/*.d.ts",
51
+ "import": "./dist/utils/*.js"
52
+ },
53
+ "./build": {
54
+ "types": "./dist/types/build/index.d.ts",
55
+ "import": "./dist/build/index.js"
56
+ },
57
+ "./build/*": {
58
+ "types": "./dist/types/build/*.d.ts",
59
+ "import": "./dist/build/*.js"
60
+ },
61
+ "./plugin": {
62
+ "types": "./dist/types/plugin.d.ts",
63
+ "import": "./dist/plugin/index.js"
64
+ },
65
+ "./*": "./*"
66
+ },
67
+ "main": "./dist/index.js",
68
+ "module": "./dist/index.js",
69
+ "types": "./dist/types/index.d.ts",
70
+ "files": [
71
+ "LICENSE",
72
+ "dist"
73
+ ],
74
+ "engines": {
75
+ "node": ">=18.0.0"
76
+ },
77
+ "scripts": {
78
+ "build": "vite build",
79
+ "vite:dev": "vite build --watch",
80
+ "typecheck": "vue-tsc --noEmit",
81
+ "lint": "eslint .",
82
+ "lint:fix": "eslint . --fix",
83
+ "pre-commit": "lint-staged",
84
+ "test": "vitest",
85
+ "test:unit": "vitest",
86
+ "test:unit:watch": "vitest watch",
87
+ "test:unit:coverage": "vitest run --coverage",
88
+ "test:unit:coverage:watch": "vitest watch --coverage",
89
+ "test:unit:coverage:master": "vitest run --coverage --changed master"
90
+ },
91
+ "peerDependencies": {
92
+ "vue": "^3.5.0"
93
+ },
94
+ "devDependencies": {
95
+ "glob": "catalog:",
96
+ "typescript": "^5.8.3",
97
+ "vue": "catalog:",
98
+ "vue-tsc": "^2.2.10"
99
+ },
100
+ "lint-staged": {
101
+ "*.{js,ts,vue,mjs,mts,cjs,md}": "cross-env NODE_ENV=production eslint --fix"
102
+ },
103
+ "gitHead": "9ef7beb4feeee0b0cb44e7df8af7115d5d5ef334"
104
+ }