@tamagui/theme 1.11.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.
- package/README.md +1 -0
- package/dist/cjs/addTheme.js +76 -0
- package/dist/cjs/addTheme.js.map +7 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/updateTheme.js +47 -0
- package/dist/cjs/updateTheme.js.map +7 -0
- package/dist/esm/addTheme.js +58 -0
- package/dist/esm/addTheme.js.map +7 -0
- package/dist/esm/addTheme.mjs +58 -0
- package/dist/esm/addTheme.mjs.map +7 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/updateTheme.js +23 -0
- package/dist/esm/updateTheme.js.map +7 -0
- package/dist/esm/updateTheme.mjs +23 -0
- package/dist/esm/updateTheme.mjs.map +7 -0
- package/dist/jsx/addTheme.js +57 -0
- package/dist/jsx/addTheme.js.map +7 -0
- package/dist/jsx/addTheme.mjs +57 -0
- package/dist/jsx/addTheme.mjs.map +7 -0
- package/dist/jsx/index.js +3 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/index.mjs +3 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/dist/jsx/updateTheme.js +23 -0
- package/dist/jsx/updateTheme.js.map +7 -0
- package/dist/jsx/updateTheme.mjs +23 -0
- package/dist/jsx/updateTheme.mjs.map +7 -0
- package/package.json +33 -0
- package/src/addTheme.ts +68 -0
- package/src/index.ts +2 -0
- package/src/updateTheme.ts +27 -0
- package/types/addTheme.d.ts +32 -0
- package/types/addTheme.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
- package/types/updateTheme.d.ts +30 -0
- package/types/updateTheme.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
## addFont
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var addTheme_exports = {};
|
|
20
|
+
__export(addTheme_exports, {
|
|
21
|
+
addTheme: () => addTheme
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(addTheme_exports);
|
|
24
|
+
var import_constants = require("@tamagui/constants");
|
|
25
|
+
var import_web = require("@tamagui/web");
|
|
26
|
+
function addTheme(props) {
|
|
27
|
+
var _a;
|
|
28
|
+
const config = (0, import_web.getConfig)();
|
|
29
|
+
if (process.env.NODE_ENV === "development") {
|
|
30
|
+
if (!config) {
|
|
31
|
+
throw new Error("No config");
|
|
32
|
+
}
|
|
33
|
+
const theme2 = config.themes[props.name];
|
|
34
|
+
if (!props.update && theme2) {
|
|
35
|
+
return { theme: theme2 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
39
|
+
const theme = { ...themeIn };
|
|
40
|
+
for (const key in theme) {
|
|
41
|
+
(0, import_web.ensureThemeVariable)(theme, key);
|
|
42
|
+
}
|
|
43
|
+
const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme, config.themes);
|
|
44
|
+
config.themes[themeName] = themeProxied;
|
|
45
|
+
let cssRules = [];
|
|
46
|
+
if (import_constants.isWeb) {
|
|
47
|
+
if (insertCSS) {
|
|
48
|
+
cssRules = (0, import_web.getThemeCSSRules)({
|
|
49
|
+
// @ts-ignore this works but should be fixed types
|
|
50
|
+
config,
|
|
51
|
+
themeName,
|
|
52
|
+
names: [themeName],
|
|
53
|
+
theme
|
|
54
|
+
});
|
|
55
|
+
const id = `t_theme_style_${themeName}`;
|
|
56
|
+
const existing = document.querySelector(`#${id}`);
|
|
57
|
+
const style = document.createElement("style");
|
|
58
|
+
style.id = id;
|
|
59
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
60
|
+
document.head.appendChild(style);
|
|
61
|
+
if (existing) {
|
|
62
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
(0, import_web.updateConfig)("themes", { ...config.themes, [themeName]: themeProxied });
|
|
67
|
+
return {
|
|
68
|
+
theme: themeProxied,
|
|
69
|
+
cssRules
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
addTheme
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=addTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n ensureThemeVariable,\n getConfig,\n getThemeCSSRules,\n proxyThemeToParents,\n updateConfig,\n} from '@tamagui/web'\nimport type { ThemeDefinition, ThemeParsed } from '@tamagui/web'\n\nexport function addTheme(props: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const theme = config.themes[props.name]\n if (!props.update && theme) {\n return { theme }\n }\n }\n\n const { name: themeName, theme: themeIn, insertCSS } = props\n const theme = { ...themeIn } as ThemeParsed\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n let cssRules: string[] = []\n\n if (isWeb) {\n if (insertCSS) {\n cssRules = getThemeCSSRules({\n // @ts-ignore this works but should be fixed types\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const id = `t_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n }\n\n updateConfig('themes', { ...config.themes, [themeName]: themeProxied })\n\n // trigger updates in components\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,iBAMO;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,aAAS,sBAAU;AAEzB,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wCAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,mBAAe,gCAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,wBAAO;AACT,QAAI,WAAW;AACb,qBAAW,6BAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,+BAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["theme"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./addTheme"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./updateTheme"), module.exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var updateTheme_exports = {};
|
|
20
|
+
__export(updateTheme_exports, {
|
|
21
|
+
updateTheme: () => updateTheme
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(updateTheme_exports);
|
|
24
|
+
var import_web = require("@tamagui/web");
|
|
25
|
+
var import_addTheme = require("./addTheme.js");
|
|
26
|
+
function updateTheme({
|
|
27
|
+
name,
|
|
28
|
+
theme
|
|
29
|
+
}) {
|
|
30
|
+
const next = (0, import_addTheme.addTheme)({ name, theme, insertCSS: true, update: true });
|
|
31
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
32
|
+
import_web.activeThemeManagers.forEach((manager) => {
|
|
33
|
+
if (manager.state.name === name) {
|
|
34
|
+
manager.updateState({
|
|
35
|
+
name,
|
|
36
|
+
forceTheme: next.theme
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
updateTheme
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=updateTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { activeThemeManagers } from '@tamagui/web'\nimport type { ThemeDefinition } from '@tamagui/web'\n\nimport { addTheme } from './addTheme.js'\n\nexport function updateTheme({\n name,\n theme,\n}: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n}) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.state.name === name) {\n manager.updateState({\n name,\n forceTheme: next.theme,\n })\n }\n })\n }\n\n return next\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AAGpC,sBAAyB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,WAAO,0BAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,mCAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function addTheme(props) {
|
|
10
|
+
var _a;
|
|
11
|
+
const config = getConfig();
|
|
12
|
+
if (process.env.NODE_ENV === "development") {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error("No config");
|
|
15
|
+
}
|
|
16
|
+
const theme2 = config.themes[props.name];
|
|
17
|
+
if (!props.update && theme2) {
|
|
18
|
+
return { theme: theme2 };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
22
|
+
const theme = { ...themeIn };
|
|
23
|
+
for (const key in theme) {
|
|
24
|
+
ensureThemeVariable(theme, key);
|
|
25
|
+
}
|
|
26
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
27
|
+
config.themes[themeName] = themeProxied;
|
|
28
|
+
let cssRules = [];
|
|
29
|
+
if (isWeb) {
|
|
30
|
+
if (insertCSS) {
|
|
31
|
+
cssRules = getThemeCSSRules({
|
|
32
|
+
// @ts-ignore this works but should be fixed types
|
|
33
|
+
config,
|
|
34
|
+
themeName,
|
|
35
|
+
names: [themeName],
|
|
36
|
+
theme
|
|
37
|
+
});
|
|
38
|
+
const id = `t_theme_style_${themeName}`;
|
|
39
|
+
const existing = document.querySelector(`#${id}`);
|
|
40
|
+
const style = document.createElement("style");
|
|
41
|
+
style.id = id;
|
|
42
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
43
|
+
document.head.appendChild(style);
|
|
44
|
+
if (existing) {
|
|
45
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
50
|
+
return {
|
|
51
|
+
theme: themeProxied,
|
|
52
|
+
cssRules
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
addTheme
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=addTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n ensureThemeVariable,\n getConfig,\n getThemeCSSRules,\n proxyThemeToParents,\n updateConfig,\n} from '@tamagui/web'\nimport type { ThemeDefinition, ThemeParsed } from '@tamagui/web'\n\nexport function addTheme(props: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const theme = config.themes[props.name]\n if (!props.update && theme) {\n return { theme }\n }\n }\n\n const { name: themeName, theme: themeIn, insertCSS } = props\n const theme = { ...themeIn } as ThemeParsed\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n let cssRules: string[] = []\n\n if (isWeb) {\n if (insertCSS) {\n cssRules = getThemeCSSRules({\n // @ts-ignore this works but should be fixed types\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const id = `t_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n }\n\n updateConfig('themes', { ...config.themes, [themeName]: themeProxied })\n\n // trigger updates in components\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,SAAS,UAAU;AAEzB,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["theme"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function addTheme(props) {
|
|
10
|
+
var _a;
|
|
11
|
+
const config = getConfig();
|
|
12
|
+
if (process.env.NODE_ENV === "development") {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error("No config");
|
|
15
|
+
}
|
|
16
|
+
const theme2 = config.themes[props.name];
|
|
17
|
+
if (!props.update && theme2) {
|
|
18
|
+
return { theme: theme2 };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
22
|
+
const theme = { ...themeIn };
|
|
23
|
+
for (const key in theme) {
|
|
24
|
+
ensureThemeVariable(theme, key);
|
|
25
|
+
}
|
|
26
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
27
|
+
config.themes[themeName] = themeProxied;
|
|
28
|
+
let cssRules = [];
|
|
29
|
+
if (isWeb) {
|
|
30
|
+
if (insertCSS) {
|
|
31
|
+
cssRules = getThemeCSSRules({
|
|
32
|
+
// @ts-ignore this works but should be fixed types
|
|
33
|
+
config,
|
|
34
|
+
themeName,
|
|
35
|
+
names: [themeName],
|
|
36
|
+
theme
|
|
37
|
+
});
|
|
38
|
+
const id = `t_theme_style_${themeName}`;
|
|
39
|
+
const existing = document.querySelector(`#${id}`);
|
|
40
|
+
const style = document.createElement("style");
|
|
41
|
+
style.id = id;
|
|
42
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
43
|
+
document.head.appendChild(style);
|
|
44
|
+
if (existing) {
|
|
45
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
50
|
+
return {
|
|
51
|
+
theme: themeProxied,
|
|
52
|
+
cssRules
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
addTheme
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=addTheme.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n ensureThemeVariable,\n getConfig,\n getThemeCSSRules,\n proxyThemeToParents,\n updateConfig,\n} from '@tamagui/web'\nimport type { ThemeDefinition, ThemeParsed } from '@tamagui/web'\n\nexport function addTheme(props: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const theme = config.themes[props.name]\n if (!props.update && theme) {\n return { theme }\n }\n }\n\n const { name: themeName, theme: themeIn, insertCSS } = props\n const theme = { ...themeIn } as ThemeParsed\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n let cssRules: string[] = []\n\n if (isWeb) {\n if (insertCSS) {\n cssRules = getThemeCSSRules({\n // @ts-ignore this works but should be fixed types\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const id = `t_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n }\n\n updateConfig('themes', { ...config.themes, [themeName]: themeProxied })\n\n // trigger updates in components\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,SAAS,UAAU;AAEzB,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["theme"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { addTheme } from "./addTheme.js";
|
|
3
|
+
function updateTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = addTheme({ name, theme, insertCSS: true, update: true });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
updateTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=updateTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { activeThemeManagers } from '@tamagui/web'\nimport type { ThemeDefinition } from '@tamagui/web'\n\nimport { addTheme } from './addTheme.js'\n\nexport function updateTheme({\n name,\n theme,\n}: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n}) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.state.name === name) {\n manager.updateState({\n name,\n forceTheme: next.theme,\n })\n }\n })\n }\n\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,gBAAgB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { addTheme } from "./addTheme.js";
|
|
3
|
+
function updateTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = addTheme({ name, theme, insertCSS: true, update: true });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
updateTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=updateTheme.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { activeThemeManagers } from '@tamagui/web'\nimport type { ThemeDefinition } from '@tamagui/web'\n\nimport { addTheme } from './addTheme.js'\n\nexport function updateTheme({\n name,\n theme,\n}: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n}) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.state.name === name) {\n manager.updateState({\n name,\n forceTheme: next.theme,\n })\n }\n })\n }\n\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,gBAAgB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function addTheme(props) {
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
if (!config) {
|
|
13
|
+
throw new Error("No config");
|
|
14
|
+
}
|
|
15
|
+
const theme2 = config.themes[props.name];
|
|
16
|
+
if (!props.update && theme2) {
|
|
17
|
+
return { theme: theme2 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
21
|
+
const theme = { ...themeIn };
|
|
22
|
+
for (const key in theme) {
|
|
23
|
+
ensureThemeVariable(theme, key);
|
|
24
|
+
}
|
|
25
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
26
|
+
config.themes[themeName] = themeProxied;
|
|
27
|
+
let cssRules = [];
|
|
28
|
+
if (isWeb) {
|
|
29
|
+
if (insertCSS) {
|
|
30
|
+
cssRules = getThemeCSSRules({
|
|
31
|
+
// @ts-ignore this works but should be fixed types
|
|
32
|
+
config,
|
|
33
|
+
themeName,
|
|
34
|
+
names: [themeName],
|
|
35
|
+
theme
|
|
36
|
+
});
|
|
37
|
+
const id = `t_theme_style_${themeName}`;
|
|
38
|
+
const existing = document.querySelector(`#${id}`);
|
|
39
|
+
const style = document.createElement("style");
|
|
40
|
+
style.id = id;
|
|
41
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
42
|
+
document.head.appendChild(style);
|
|
43
|
+
if (existing) {
|
|
44
|
+
existing.parentElement?.removeChild(existing);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
49
|
+
return {
|
|
50
|
+
theme: themeProxied,
|
|
51
|
+
cssRules
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
addTheme
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=addTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n ensureThemeVariable,\n getConfig,\n getThemeCSSRules,\n proxyThemeToParents,\n updateConfig,\n} from '@tamagui/web'\nimport type { ThemeDefinition, ThemeParsed } from '@tamagui/web'\n\nexport function addTheme(props: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const theme = config.themes[props.name]\n if (!props.update && theme) {\n return { theme }\n }\n }\n\n const { name: themeName, theme: themeIn, insertCSS } = props\n const theme = { ...themeIn } as ThemeParsed\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n let cssRules: string[] = []\n\n if (isWeb) {\n if (insertCSS) {\n cssRules = getThemeCSSRules({\n // @ts-ignore this works but should be fixed types\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const id = `t_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n }\n\n updateConfig('themes', { ...config.themes, [themeName]: themeProxied })\n\n // trigger updates in components\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AACD,QAAM,SAAS,UAAU;AAEzB,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,iBAAS,eAAe,YAAY,QAAQ;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["theme"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function addTheme(props) {
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
if (!config) {
|
|
13
|
+
throw new Error("No config");
|
|
14
|
+
}
|
|
15
|
+
const theme2 = config.themes[props.name];
|
|
16
|
+
if (!props.update && theme2) {
|
|
17
|
+
return { theme: theme2 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
21
|
+
const theme = { ...themeIn };
|
|
22
|
+
for (const key in theme) {
|
|
23
|
+
ensureThemeVariable(theme, key);
|
|
24
|
+
}
|
|
25
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
26
|
+
config.themes[themeName] = themeProxied;
|
|
27
|
+
let cssRules = [];
|
|
28
|
+
if (isWeb) {
|
|
29
|
+
if (insertCSS) {
|
|
30
|
+
cssRules = getThemeCSSRules({
|
|
31
|
+
// @ts-ignore this works but should be fixed types
|
|
32
|
+
config,
|
|
33
|
+
themeName,
|
|
34
|
+
names: [themeName],
|
|
35
|
+
theme
|
|
36
|
+
});
|
|
37
|
+
const id = `t_theme_style_${themeName}`;
|
|
38
|
+
const existing = document.querySelector(`#${id}`);
|
|
39
|
+
const style = document.createElement("style");
|
|
40
|
+
style.id = id;
|
|
41
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
42
|
+
document.head.appendChild(style);
|
|
43
|
+
if (existing) {
|
|
44
|
+
existing.parentElement?.removeChild(existing);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
49
|
+
return {
|
|
50
|
+
theme: themeProxied,
|
|
51
|
+
cssRules
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
addTheme
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=addTheme.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n ensureThemeVariable,\n getConfig,\n getThemeCSSRules,\n proxyThemeToParents,\n updateConfig,\n} from '@tamagui/web'\nimport type { ThemeDefinition, ThemeParsed } from '@tamagui/web'\n\nexport function addTheme(props: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const theme = config.themes[props.name]\n if (!props.update && theme) {\n return { theme }\n }\n }\n\n const { name: themeName, theme: themeIn, insertCSS } = props\n const theme = { ...themeIn } as ThemeParsed\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n let cssRules: string[] = []\n\n if (isWeb) {\n if (insertCSS) {\n cssRules = getThemeCSSRules({\n // @ts-ignore this works but should be fixed types\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const id = `t_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n }\n\n updateConfig('themes', { ...config.themes, [themeName]: themeProxied })\n\n // trigger updates in components\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AACD,QAAM,SAAS,UAAU;AAEzB,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,iBAAS,eAAe,YAAY,QAAQ;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["theme"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { addTheme } from "./addTheme.js";
|
|
3
|
+
function updateTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = addTheme({ name, theme, insertCSS: true, update: true });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
updateTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=updateTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { activeThemeManagers } from '@tamagui/web'\nimport type { ThemeDefinition } from '@tamagui/web'\n\nimport { addTheme } from './addTheme.js'\n\nexport function updateTheme({\n name,\n theme,\n}: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n}) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.state.name === name) {\n manager.updateState({\n name,\n forceTheme: next.theme,\n })\n }\n })\n }\n\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,gBAAgB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { addTheme } from "./addTheme.js";
|
|
3
|
+
function updateTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = addTheme({ name, theme, insertCSS: true, update: true });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
updateTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=updateTheme.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { activeThemeManagers } from '@tamagui/web'\nimport type { ThemeDefinition } from '@tamagui/web'\n\nimport { addTheme } from './addTheme.js'\n\nexport function updateTheme({\n name,\n theme,\n}: {\n name: string\n theme: Partial<Record<keyof ThemeDefinition, any>>\n}) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.state.name === name) {\n manager.updateState({\n name,\n forceTheme: next.theme,\n })\n }\n })\n }\n\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,gBAAgB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/theme",
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"source": "src/index.ts",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"main": "dist/cjs",
|
|
8
|
+
"module": "dist/esm",
|
|
9
|
+
"module:jsx": "dist/jsx",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"types",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tamagui-build",
|
|
17
|
+
"watch": "tamagui-build --watch"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@tamagui/constants": "1.11.0",
|
|
21
|
+
"@tamagui/web": "1.11.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tamagui/build": "1.11.0",
|
|
28
|
+
"react": "^18.2.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/addTheme.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isWeb } from '@tamagui/constants'
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig,
|
|
8
|
+
} from '@tamagui/web'
|
|
9
|
+
import type { ThemeDefinition, ThemeParsed } from '@tamagui/web'
|
|
10
|
+
|
|
11
|
+
export function addTheme(props: {
|
|
12
|
+
name: string
|
|
13
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
14
|
+
insertCSS?: boolean
|
|
15
|
+
update?: boolean
|
|
16
|
+
}) {
|
|
17
|
+
const config = getConfig()
|
|
18
|
+
|
|
19
|
+
if (process.env.NODE_ENV === 'development') {
|
|
20
|
+
if (!config) {
|
|
21
|
+
throw new Error('No config')
|
|
22
|
+
}
|
|
23
|
+
const theme = config.themes[props.name]
|
|
24
|
+
if (!props.update && theme) {
|
|
25
|
+
return { theme }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { name: themeName, theme: themeIn, insertCSS } = props
|
|
30
|
+
const theme = { ...themeIn } as ThemeParsed
|
|
31
|
+
for (const key in theme) {
|
|
32
|
+
ensureThemeVariable(theme, key)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes)
|
|
36
|
+
config.themes[themeName] = themeProxied
|
|
37
|
+
|
|
38
|
+
let cssRules: string[] = []
|
|
39
|
+
|
|
40
|
+
if (isWeb) {
|
|
41
|
+
if (insertCSS) {
|
|
42
|
+
cssRules = getThemeCSSRules({
|
|
43
|
+
// @ts-ignore this works but should be fixed types
|
|
44
|
+
config,
|
|
45
|
+
themeName,
|
|
46
|
+
names: [themeName],
|
|
47
|
+
theme,
|
|
48
|
+
})
|
|
49
|
+
const id = `t_theme_style_${themeName}`
|
|
50
|
+
const existing = document.querySelector(`#${id}`)
|
|
51
|
+
const style = document.createElement('style')
|
|
52
|
+
style.id = id
|
|
53
|
+
style.appendChild(document.createTextNode(cssRules.join('\n')))
|
|
54
|
+
document.head.appendChild(style)
|
|
55
|
+
if (existing) {
|
|
56
|
+
existing.parentElement?.removeChild(existing)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
|
|
62
|
+
|
|
63
|
+
// trigger updates in components
|
|
64
|
+
return {
|
|
65
|
+
theme: themeProxied,
|
|
66
|
+
cssRules,
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { activeThemeManagers } from '@tamagui/web'
|
|
2
|
+
import type { ThemeDefinition } from '@tamagui/web'
|
|
3
|
+
|
|
4
|
+
import { addTheme } from './addTheme.js'
|
|
5
|
+
|
|
6
|
+
export function updateTheme({
|
|
7
|
+
name,
|
|
8
|
+
theme,
|
|
9
|
+
}: {
|
|
10
|
+
name: string
|
|
11
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
12
|
+
}) {
|
|
13
|
+
const next = addTheme({ name, theme, insertCSS: true, update: true })
|
|
14
|
+
|
|
15
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
16
|
+
activeThemeManagers.forEach((manager) => {
|
|
17
|
+
if (manager.state.name === name) {
|
|
18
|
+
manager.updateState({
|
|
19
|
+
name,
|
|
20
|
+
forceTheme: next.theme,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return next
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ThemeDefinition } from '@tamagui/web';
|
|
2
|
+
export declare function addTheme(props: {
|
|
3
|
+
name: string;
|
|
4
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>;
|
|
5
|
+
insertCSS?: boolean;
|
|
6
|
+
update?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
theme: {
|
|
9
|
+
[x: string]: import("@tamagui/web").Variable<any>;
|
|
10
|
+
background?: import("@tamagui/web").Variable<any> | undefined;
|
|
11
|
+
backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
12
|
+
backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
13
|
+
backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
14
|
+
color?: import("@tamagui/web").Variable<any> | undefined;
|
|
15
|
+
colorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
16
|
+
colorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
17
|
+
colorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
18
|
+
borderColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
19
|
+
borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
20
|
+
borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
21
|
+
borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
22
|
+
shadowColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
23
|
+
shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
24
|
+
shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
25
|
+
shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
26
|
+
};
|
|
27
|
+
cssRules?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
theme: any;
|
|
30
|
+
cssRules: string[];
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=addTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAEhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;;;;;;;;;;;;;;;;;;;;;;;;EAoDA"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ThemeDefinition } from '@tamagui/web';
|
|
2
|
+
export declare function updateTheme({ name, theme, }: {
|
|
3
|
+
name: string;
|
|
4
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>;
|
|
5
|
+
}): {
|
|
6
|
+
theme: {
|
|
7
|
+
[x: string]: import("@tamagui/web").Variable<any>;
|
|
8
|
+
background?: import("@tamagui/web").Variable<any> | undefined;
|
|
9
|
+
backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
10
|
+
backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
11
|
+
backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
12
|
+
color?: import("@tamagui/web").Variable<any> | undefined;
|
|
13
|
+
colorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
14
|
+
colorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
15
|
+
colorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
16
|
+
borderColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
17
|
+
borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
18
|
+
borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
19
|
+
borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
20
|
+
shadowColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
21
|
+
shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
22
|
+
shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
23
|
+
shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
24
|
+
};
|
|
25
|
+
cssRules?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
theme: any;
|
|
28
|
+
cssRules: string[];
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=updateTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;EAeA"}
|