@hanzogui/theme 2.0.0-rc.41-hanzoai.5

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/_mutateTheme.cjs +141 -0
  4. package/dist/cjs/_mutateTheme.native.js +137 -0
  5. package/dist/cjs/_mutateTheme.native.js.map +1 -0
  6. package/dist/cjs/addTheme.cjs +35 -0
  7. package/dist/cjs/addTheme.native.js +38 -0
  8. package/dist/cjs/addTheme.native.js.map +1 -0
  9. package/dist/cjs/index.cjs +32 -0
  10. package/dist/cjs/index.native.js +35 -0
  11. package/dist/cjs/index.native.js.map +1 -0
  12. package/dist/cjs/replaceTheme.cjs +40 -0
  13. package/dist/cjs/replaceTheme.native.js +44 -0
  14. package/dist/cjs/replaceTheme.native.js.map +1 -0
  15. package/dist/cjs/updateTheme.cjs +39 -0
  16. package/dist/cjs/updateTheme.native.js +43 -0
  17. package/dist/cjs/updateTheme.native.js.map +1 -0
  18. package/dist/esm/_mutateTheme.mjs +115 -0
  19. package/dist/esm/_mutateTheme.mjs.map +1 -0
  20. package/dist/esm/_mutateTheme.native.js +108 -0
  21. package/dist/esm/_mutateTheme.native.js.map +1 -0
  22. package/dist/esm/addTheme.mjs +10 -0
  23. package/dist/esm/addTheme.mjs.map +1 -0
  24. package/dist/esm/addTheme.native.js +10 -0
  25. package/dist/esm/addTheme.native.js.map +1 -0
  26. package/dist/esm/index.js +6 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/index.mjs +6 -0
  29. package/dist/esm/index.mjs.map +1 -0
  30. package/dist/esm/index.native.js +6 -0
  31. package/dist/esm/index.native.js.map +1 -0
  32. package/dist/esm/replaceTheme.mjs +15 -0
  33. package/dist/esm/replaceTheme.mjs.map +1 -0
  34. package/dist/esm/replaceTheme.native.js +16 -0
  35. package/dist/esm/replaceTheme.native.js.map +1 -0
  36. package/dist/esm/updateTheme.mjs +14 -0
  37. package/dist/esm/updateTheme.mjs.map +1 -0
  38. package/dist/esm/updateTheme.native.js +15 -0
  39. package/dist/esm/updateTheme.native.js.map +1 -0
  40. package/package.json +48 -0
  41. package/src/_mutateTheme.ts +197 -0
  42. package/src/addTheme.ts +11 -0
  43. package/src/index.ts +5 -0
  44. package/src/replaceTheme.ts +14 -0
  45. package/src/updateTheme.ts +13 -0
  46. package/types/_mutateTheme.d.ts +27 -0
  47. package/types/_mutateTheme.d.ts.map +1 -0
  48. package/types/addTheme.d.ts +11 -0
  49. package/types/addTheme.d.ts.map +1 -0
  50. package/types/index.d.ts +6 -0
  51. package/types/index.d.ts.map +1 -0
  52. package/types/replaceTheme.d.ts +10 -0
  53. package/types/replaceTheme.d.ts.map +1 -0
  54. package/types/updateTheme.d.ts +10 -0
  55. package/types/updateTheme.d.ts.map +1 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var updateTheme_exports = {};
26
+ __export(updateTheme_exports, {
27
+ updateTheme: () => updateTheme
28
+ });
29
+ module.exports = __toCommonJS(updateTheme_exports);
30
+ var import_mutateTheme = require("./_mutateTheme.native.js");
31
+ function updateTheme(param) {
32
+ var {
33
+ name,
34
+ theme
35
+ } = param;
36
+ return (0, import_mutateTheme._mutateTheme)({
37
+ name,
38
+ theme,
39
+ insertCSS: true,
40
+ mutationType: "update"
41
+ });
42
+ }
43
+ //# sourceMappingURL=updateTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","updateTheme_exports","updateTheme","module","exports","import_mutateTheme","require","param","theme","_mutateTheme","insertCSS","mutationType"],"sources":["updateTheme.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar updateTheme_exports = {};\n__export(updateTheme_exports, {\n updateTheme: () => updateTheme\n});\nmodule.exports = __toCommonJS(updateTheme_exports);\nvar import_mutateTheme = require(\"./_mutateTheme\");\nfunction updateTheme(param) {\n var { name, theme } = param;\n return (0, import_mutateTheme._mutateTheme)({\n name,\n theme,\n insertCSS: true,\n mutationType: \"update\"\n });\n}\n//# sourceMappingURL=updateTheme.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAAC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AAW,EAAEA,CAAA,KAAMA;AACrB,CAAC,CAAC;AACFC,MAAM,CAACC,OAAO,GAAGN,YAAY,CAACG,mBAAmB,CAAC;AAClD,IAAII,kBAAkB,GAAGC,OAAO,CAAC,0BAAgB,CAAC;AAClD,SAASJ,WAAWA,CAACK,KAAK,EAAE;EAC1B,IAAI;IAAEnB,IAAI;IAAEoB;EAAM,CAAC,GAAGD,KAAK;EAC3B,OAAO,CAAC,CAAC,EAAEF,kBAAkB,CAACI,YAAY,EAAE;IAC1CrB,IAAI;IACJoB,KAAK;IACLE,SAAS,EAAE,IAAI;IACfC,YAAY,EAAE;EAChB,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,115 @@
1
+ import { isServer } from "@hanzogui/constants";
2
+ import { startTransition } from "@hanzogui/start-transition";
3
+ import { ensureThemeVariable, forceUpdateThemes, getConfig, getThemeCSSRules, mutatedAutoVariables, proxyThemeToParents, simpleHash, updateConfig } from "@hanzogui/web";
4
+ function mutateThemes({
5
+ themes,
6
+ batch,
7
+ insertCSS = true,
8
+ ...props
9
+ }) {
10
+ const allThemesProxied = {};
11
+ const allThemesRaw = {};
12
+ for (const {
13
+ name,
14
+ theme
15
+ } of themes) {
16
+ const res = _mutateTheme({
17
+ ...props,
18
+ name,
19
+ theme,
20
+ avoidUpdate: true,
21
+ mutationType: "add"
22
+ });
23
+ if (res) {
24
+ allThemesProxied[name] = res.theme;
25
+ allThemesRaw[name] = res.themeRaw;
26
+ }
27
+ }
28
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
29
+ startTransition(() => {
30
+ for (const themeName in allThemesProxied) {
31
+ const theme = allThemesProxied[themeName];
32
+ updateThemeConfig(themeName, theme);
33
+ }
34
+ updateThemeStates();
35
+ });
36
+ return {
37
+ themes: allThemesProxied,
38
+ themesRaw: allThemesRaw,
39
+ cssRules
40
+ };
41
+ }
42
+ function _mutateTheme(props) {
43
+ if (isServer) {
44
+ if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
45
+ return;
46
+ }
47
+ const config = getConfig();
48
+ const {
49
+ name: themeName,
50
+ theme: themeIn,
51
+ insertCSS,
52
+ mutationType
53
+ } = props;
54
+ if (process.env.NODE_ENV === "development") {
55
+ if (!config) throw new Error("No config");
56
+ const theme2 = config.themes[props.name];
57
+ if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
58
+ }
59
+ const theme = {
60
+ ...(mutationType === "update" ? config.themes[themeName] ?? {} : {}),
61
+ ...themeIn
62
+ };
63
+ for (const key in theme) ensureThemeVariable(theme, key);
64
+ const themeProxied = proxyThemeToParents(themeName, theme);
65
+ const response = {
66
+ themeRaw: theme,
67
+ theme: themeProxied,
68
+ cssRules: []
69
+ };
70
+ if (props.avoidUpdate) return response;
71
+ if (insertCSS) response.cssRules = insertThemeCSS({
72
+ [themeName]: theme
73
+ });
74
+ updateThemeConfig(themeName, themeProxied);
75
+ updateThemeStates();
76
+ return response;
77
+ }
78
+ function updateThemeConfig(themeName, theme) {
79
+ const config = getConfig();
80
+ config.themes[themeName] = theme;
81
+ updateConfig("themes", config.themes);
82
+ }
83
+ function updateThemeStates() {
84
+ forceUpdateThemes();
85
+ }
86
+ function insertThemeCSS(themes, batch = false) {
87
+ const config = getConfig();
88
+ let cssRules = [];
89
+ for (const themeName in themes) {
90
+ const theme = themes[themeName];
91
+ const rules = getThemeCSSRules({
92
+ config,
93
+ themeName,
94
+ names: [themeName],
95
+ hasDarkLight: true,
96
+ theme,
97
+ useMutatedVariables: true
98
+ });
99
+ cssRules = [...cssRules, ...rules];
100
+ if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
101
+ }
102
+ if (mutatedAutoVariables.length > 0) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariables.map(v => `--${v.name}:${v.val}`).join(";")}}`]);
103
+ if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : simpleHash(Object.keys(themes).join(""))}`, cssRules);
104
+ return cssRules;
105
+ }
106
+ function updateStyle(id, rules) {
107
+ const existing = document.querySelector(`#${id}`);
108
+ const style = document.createElement("style");
109
+ style.id = id;
110
+ style.appendChild(document.createTextNode(rules.join("\n")));
111
+ document.head.appendChild(style);
112
+ if (existing) existing.parentElement?.removeChild(existing);
113
+ }
114
+ export { _mutateTheme, mutateThemes };
115
+ //# sourceMappingURL=_mutateTheme.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isServer","startTransition","ensureThemeVariable","forceUpdateThemes","getConfig","getThemeCSSRules","mutatedAutoVariables","proxyThemeToParents","simpleHash","updateConfig","mutateThemes","themes","batch","insertCSS","props","allThemesProxied","allThemesRaw","name","theme","res","_mutateTheme","avoidUpdate","mutationType","themeRaw","cssRules","insertThemeCSS","themeName","updateThemeConfig","updateThemeStates","themesRaw","process","env","NODE_ENV","console","warn","config","themeIn","Error","theme2","key","themeProxied","response","rules","names","hasDarkLight","useMutatedVariables","updateStyle","length","map","v","val","join","Object","keys","id","existing","document","querySelector","style","createElement","appendChild","createTextNode","head","parentElement","removeChild"],"sources":["../../src/_mutateTheme.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,SAASC,eAAA,QAAuB;AAEhC,SAAAC,mBAAA,EAAAC,iBAAA,EAAAC,SAAA,EAAAC,gBAAA,EAAAC,oBAAA,EAAAC,mBAAA,EAAAC,UAAA,EAAAC,YAAA;AAAA,SACEC,aAAA;EAAAC,MAAA;EAAAC,KAAA;EAAAC,SAAA;EAAA,GAAAC;AAAA;EAAA,MACAC,gBAAA;EAAA,MACAC,YAAA;EAAA,KACA;IAAAC,IAAA;IAAAC;EAAA,KAAAP,MAAA;IACA,MAAAQ,GAAA,GAAAC,YAAA;MACA,GAAAN,KAAA;MACAG,IAAA;MACAC,KAAA;MAAAG,WACK;MAmBAC,YAAS;IACd;IACA,IAAAH,GAAA;MACAJ,gBAAY,CAAAE,IAAA,IAAAE,GAAA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3B,QAAA;EAAA,OACdA,QAAA;AAAA;AAGH,SAAAsB,WAAkBA,CAAAQ,EAAA,EAAAZ,KAAA,EAAW;EAC7B,MAAAa,QAAA,GAAAC,QAAkB,CAAAC,aAAA,KAAAH,EAAA;EAElB,MAAAI,KAAO,GAAAF,QAAA,CAAAG,aAAA;EACTD,KAAA,CAAAJ,EAAA,GAAAA,EAAA;EAEAI,KAAA,CAAAE,WAAS,CAAAJ,QAAkB,CAAAK,cAAmB,CAAAnB,KAAoB,CAAAS,IAAA;EAChEK,QAAM,CAAAM,IAAA,CAAAF,WAAS,CAAUF,KAAA;EACzB,IAAAH,QAAO,EAAAA,QAAO,CAAAQ,aAAa,EAAAC,WAAA,CAAAT,QAAA;AAC3B;AACF,SAAAnC,YAAA,EAAAV,YAAA","ignoreList":[]}
@@ -0,0 +1,108 @@
1
+ import { isServer } from "@hanzogui/constants";
2
+ import { startTransition } from "@hanzogui/start-transition";
3
+ import { ensureThemeVariable, forceUpdateThemes, getConfig, getThemeCSSRules, mutatedAutoVariables, proxyThemeToParents, simpleHash, updateConfig } from "@hanzogui/web";
4
+ function mutateThemes(param) {
5
+ var {
6
+ themes,
7
+ batch,
8
+ insertCSS = true,
9
+ ...props
10
+ } = param;
11
+ var allThemesProxied = {};
12
+ var allThemesRaw = {};
13
+ var _iteratorNormalCompletion = true,
14
+ _didIteratorError = false,
15
+ _iteratorError = void 0;
16
+ try {
17
+ for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
18
+ var {
19
+ name,
20
+ theme
21
+ } = _step.value;
22
+ var res = _mutateTheme({
23
+ ...props,
24
+ name,
25
+ theme,
26
+ avoidUpdate: true,
27
+ mutationType: "add"
28
+ });
29
+ if (res) {
30
+ allThemesProxied[name] = res.theme;
31
+ allThemesRaw[name] = res.themeRaw;
32
+ }
33
+ }
34
+ } catch (err) {
35
+ _didIteratorError = true;
36
+ _iteratorError = err;
37
+ } finally {
38
+ try {
39
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
40
+ } finally {
41
+ if (_didIteratorError) throw _iteratorError;
42
+ }
43
+ }
44
+ var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
45
+ startTransition(function () {
46
+ for (var themeName in allThemesProxied) {
47
+ var theme2 = allThemesProxied[themeName];
48
+ updateThemeConfig(themeName, theme2);
49
+ }
50
+ updateThemeStates();
51
+ });
52
+ return {
53
+ themes: allThemesProxied,
54
+ themesRaw: allThemesRaw,
55
+ cssRules
56
+ };
57
+ }
58
+ function _mutateTheme(props) {
59
+ if (isServer) {
60
+ if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
61
+ return;
62
+ }
63
+ var config = getConfig();
64
+ var {
65
+ name: themeName,
66
+ theme: themeIn,
67
+ insertCSS,
68
+ mutationType
69
+ } = props;
70
+ if (process.env.NODE_ENV === "development") {
71
+ if (!config) throw new Error("No config");
72
+ var theme = config.themes[props.name];
73
+ if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
74
+ }
75
+ var _config_themes_themeName;
76
+ var theme1 = {
77
+ ...(mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {}),
78
+ ...themeIn
79
+ };
80
+ for (var key in theme1) ensureThemeVariable(theme1, key);
81
+ var themeProxied = proxyThemeToParents(themeName, theme1);
82
+ var response = {
83
+ themeRaw: theme1,
84
+ theme: themeProxied,
85
+ cssRules: []
86
+ };
87
+ if (props.avoidUpdate) return response;
88
+ if (insertCSS) response.cssRules = insertThemeCSS({
89
+ [themeName]: theme1
90
+ });
91
+ updateThemeConfig(themeName, themeProxied);
92
+ updateThemeStates();
93
+ return response;
94
+ }
95
+ function updateThemeConfig(themeName, theme) {
96
+ var config = getConfig();
97
+ config.themes[themeName] = theme;
98
+ updateConfig("themes", config.themes);
99
+ }
100
+ function updateThemeStates() {
101
+ forceUpdateThemes();
102
+ }
103
+ function insertThemeCSS(themes) {
104
+ arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
105
+ return [];
106
+ }
107
+ export { _mutateTheme, mutateThemes };
108
+ //# sourceMappingURL=_mutateTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isServer","startTransition","ensureThemeVariable","forceUpdateThemes","getConfig","getThemeCSSRules","mutatedAutoVariables","proxyThemeToParents","simpleHash","updateConfig","mutateThemes","param","themes","batch","insertCSS","props","allThemesProxied","allThemesRaw","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","name","theme","value","res","_mutateTheme","avoidUpdate","mutationType","themeRaw","err","return","cssRules","insertThemeCSS","themeName","theme2","updateThemeConfig","updateThemeStates","themesRaw","process","env","NODE_ENV","console","warn","config","themeIn","Error","_config_themes_themeName","theme1","key","themeProxied","response","arguments","length"],"sources":["../../src/_mutateTheme.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,SAASC,eAAA,QAAuB;AAEhC,SAAAC,mBAAA,EAAAC,iBAAA,EAAAC,SAAA,EAAAC,gBAAA,EAAAC,oBAAA,EAAAC,mBAAA,EAAAC,UAAA,EAAAC,YAAA;AAAA,SACEC,aAAAC,KAAA;EAAA,IACA;IAAAC,MAAA;IAAAC,KAAA;IAAAC,SAAA;IAAA,GAAAC;EAAA,IAAAJ,KAAA;EAAA,IACAK,gBAAA;EAAA,IACAC,YAAA;EAAA,IACAC,yBAAA;IAAAC,iBAAA;IAAAC,cAAA;EAAA,IACA;IACA,SAAAC,SAAA,GAAAT,MAAA,CAAAU,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAC,IAAA,GAAAR,yBAAA;MACA;QAAAS,IAAA;QAAAC;MAAA,IAAAJ,KAAA,CAAAK,KAAA;MAAA,I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SS: true,
6
+ mutationType: "add"
7
+ });
8
+ }
9
+ export { addTheme };
10
+ //# sourceMappingURL=addTheme.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","addTheme","props","insertCSS","mutationType"],"sources":["../../src/addTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,SAASC,KAAA,EAItB;EACD,OAAOF,YAAA,CAAa;IAAE,GAAGE,KAAA;IAAOC,SAAA,EAAW;IAAMC,YAAA,EAAc;EAAM,CAAC;AACxE","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import { _mutateTheme } from "./_mutateTheme.native.js";
2
+ function addTheme(props) {
3
+ return _mutateTheme({
4
+ ...props,
5
+ insertCSS: true,
6
+ mutationType: "add"
7
+ });
8
+ }
9
+ export { addTheme };
10
+ //# sourceMappingURL=addTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","addTheme","props"],"sources":["../../src/addTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,SAASC,KAAA,EAItB;EACD,OAAOF,YAAA,CAAa;IACtB,GAAAE,KAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export * from "./addTheme.mjs";
2
+ export * from "./updateTheme.mjs";
3
+ export * from "./replaceTheme.mjs";
4
+ import { mutateThemes } from "./_mutateTheme.mjs";
5
+ export { mutateThemes };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mutateThemes"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASA,YAAA,QAAoB","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export * from "./addTheme.mjs";
2
+ export * from "./updateTheme.mjs";
3
+ export * from "./replaceTheme.mjs";
4
+ import { mutateThemes } from "./_mutateTheme.mjs";
5
+ export { mutateThemes };
6
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mutateThemes"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASA,YAAA,QAAoB","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export * from "./addTheme.native.js";
2
+ export * from "./updateTheme.native.js";
3
+ export * from "./replaceTheme.native.js";
4
+ import { mutateThemes } from "./_mutateTheme.native.js";
5
+ export { mutateThemes };
6
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mutateThemes"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAASA,YAAA,QAAoB","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import { _mutateTheme } from "./_mutateTheme.mjs";
2
+ function replaceTheme({
3
+ name,
4
+ theme
5
+ }) {
6
+ const next = _mutateTheme({
7
+ name,
8
+ theme,
9
+ insertCSS: true,
10
+ mutationType: "replace"
11
+ });
12
+ return next;
13
+ }
14
+ export { replaceTheme };
15
+ //# sourceMappingURL=replaceTheme.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","replaceTheme","name","theme","next","insertCSS","mutationType"],"sources":["../../src/replaceTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,aAAa;EAC3BC,IAAA;EACAC;AACF,GAGG;EACD,MAAMC,IAAA,GAAOJ,YAAA,CAAa;IAAEE,IAAA;IAAMC,KAAA;IAAOE,SAAA,EAAW;IAAMC,YAAA,EAAc;EAAU,CAAC;EACnF,OAAOF,IAAA;AACT","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import { _mutateTheme } from "./_mutateTheme.native.js";
2
+ function replaceTheme(param) {
3
+ var {
4
+ name,
5
+ theme
6
+ } = param;
7
+ var next = _mutateTheme({
8
+ name,
9
+ theme,
10
+ insertCSS: true,
11
+ mutationType: "replace"
12
+ });
13
+ return next;
14
+ }
15
+ export { replaceTheme };
16
+ //# sourceMappingURL=replaceTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","replaceTheme","param","name","theme","next","insertCSS","mutationType"],"sources":["../../src/replaceTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,aAAaC,KAAA;EAC3B;IAAAC,IAAA;IAAAC;EAAA,IAAAF,KAAA;EACA,IAAAG,IAAA,GAAAL,YAAA;IAICG,IAAA;IACDC,KAAM;IACNE,SAAO;IACTC,YAAA","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import { _mutateTheme } from "./_mutateTheme.mjs";
2
+ function updateTheme({
3
+ name,
4
+ theme
5
+ }) {
6
+ return _mutateTheme({
7
+ name,
8
+ theme,
9
+ insertCSS: true,
10
+ mutationType: "update"
11
+ });
12
+ }
13
+ export { updateTheme };
14
+ //# sourceMappingURL=updateTheme.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","updateTheme","name","theme","insertCSS","mutationType"],"sources":["../../src/updateTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,YAAY;EAC1BC,IAAA;EACAC;AACF,GAGG;EACD,OAAOH,YAAA,CAAa;IAAEE,IAAA;IAAMC,KAAA;IAAOC,SAAA,EAAW;IAAMC,YAAA,EAAc;EAAS,CAAC;AAC9E","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import { _mutateTheme } from "./_mutateTheme.native.js";
2
+ function updateTheme(param) {
3
+ var {
4
+ name,
5
+ theme
6
+ } = param;
7
+ return _mutateTheme({
8
+ name,
9
+ theme,
10
+ insertCSS: true,
11
+ mutationType: "update"
12
+ });
13
+ }
14
+ export { updateTheme };
15
+ //# sourceMappingURL=updateTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mutateTheme","updateTheme","param","name","theme","insertCSS"],"sources":["../../src/updateTheme.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,YAAA,QAAoB;AAEtB,SAASC,YAAYC,KAAA;EAC1B;IAAAC,IAAA;IAAAC;EAAA,IAAAF,KAAA;EACA,OAAAF,YAAA;IAICG,IAAA;IACDC,KAAO;IACTC,SAAA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@hanzogui/theme",
3
+ "version": "2.0.0-rc.41-hanzoai.5",
4
+ "source": "src/index.ts",
5
+ "files": [
6
+ "src",
7
+ "types",
8
+ "dist"
9
+ ],
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "main": "dist/cjs",
13
+ "module": "dist/esm",
14
+ "types": "./types/index.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ ".": {
18
+ "types": "./types/index.d.ts",
19
+ "react-native": "./dist/esm/index.native.js",
20
+ "browser": "./dist/esm/index.mjs",
21
+ "module": "./dist/esm/index.mjs",
22
+ "import": "./dist/esm/index.mjs",
23
+ "require": "./dist/cjs/index.cjs",
24
+ "default": "./dist/esm/index.mjs"
25
+ }
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "hanzogui-build",
32
+ "watch": "hanzogui-build --watch",
33
+ "clean": "hanzogui-build clean",
34
+ "clean:build": "hanzogui-build clean:build"
35
+ },
36
+ "dependencies": {
37
+ "@hanzogui/constants": "2.0.0-rc.41-hanzoai.5",
38
+ "@hanzogui/start-transition": "2.0.0-rc.41-hanzoai.5",
39
+ "@hanzogui/web": "2.0.0-rc.41-hanzoai.5"
40
+ },
41
+ "devDependencies": {
42
+ "@hanzogui/build": "2.0.0-rc.41-hanzoai.5",
43
+ "react": ">=19"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=19"
47
+ }
48
+ }