@tamagui/generate-themes 1.33.4

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.
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var generate_themes_exports = {};
30
+ __export(generate_themes_exports, {
31
+ generateThemes: () => generateThemes
32
+ });
33
+ module.exports = __toCommonJS(generate_themes_exports);
34
+ var import_module = __toESM(require("module"));
35
+ var import_fs_extra = __toESM(require("fs-extra"));
36
+ async function generateThemes(options) {
37
+ require("esbuild-register/dist/node").register();
38
+ let promise = null;
39
+ const ogRequire = import_module.default.prototype.require;
40
+ import_module.default.prototype.require = function(id) {
41
+ const out = ogRequire.apply(this, arguments);
42
+ if (id === "@tamagui/create-theme/theme-builder") {
43
+ if (!promise) {
44
+ let resolve;
45
+ promise = new Promise((res) => {
46
+ resolve = res;
47
+ });
48
+ return createThemeIntercept(out, {
49
+ onComplete: (result) => {
50
+ resolve == null ? void 0 : resolve(result.themeBuilder);
51
+ }
52
+ });
53
+ }
54
+ }
55
+ return out;
56
+ };
57
+ try {
58
+ const requiredThemes = require(options.inPath);
59
+ const themes = requiredThemes["default"] || requiredThemes["themes"];
60
+ const generatedThemes = generatedThemesToTypescript(themes);
61
+ const themeBuilder = promise ? await promise : null;
62
+ await Promise.all([
63
+ import_fs_extra.default.writeFile(options.outPath, generatedThemes),
64
+ (themeBuilder == null ? void 0 : themeBuilder.state) ? import_fs_extra.default.writeFile(
65
+ `${options.outPath}.theme-builder.json`,
66
+ JSON.stringify(themeBuilder == null ? void 0 : themeBuilder.state)
67
+ ) : null
68
+ ]);
69
+ } finally {
70
+ import_module.default.prototype.require = ogRequire;
71
+ }
72
+ }
73
+ function generatedThemesToTypescript(themes) {
74
+ const deduped = /* @__PURE__ */ new Map();
75
+ const dedupedToNames = /* @__PURE__ */ new Map();
76
+ for (const name in themes) {
77
+ const theme = themes[name];
78
+ const key = JSON.stringify(theme);
79
+ if (deduped.has(key)) {
80
+ dedupedToNames.set(key, [...dedupedToNames.get(key), name]);
81
+ } else {
82
+ deduped.set(key, theme);
83
+ dedupedToNames.set(key, [name]);
84
+ }
85
+ }
86
+ const baseTypeString = `type Theme = {
87
+ ${Object.entries(themes.light || themes[Object.keys(themes)[0]]).map(([k]) => {
88
+ return ` ${k}: string;
89
+ `;
90
+ }).join("")}
91
+ }`;
92
+ let themesString = `${baseTypeString}
93
+ `;
94
+ deduped.forEach((theme) => {
95
+ const key = JSON.stringify(theme);
96
+ const [baseName, ...restNames] = dedupedToNames.get(key);
97
+ const baseTheme = `export const ${baseName} = ${objectToJsString(theme)} as Theme`;
98
+ themesString += `
99
+ ${baseTheme}`;
100
+ if (restNames.length) {
101
+ const duplicateThemes = restNames.map(
102
+ (name) => `export const ${name} = ${baseName} as Theme`
103
+ );
104
+ themesString += `
105
+
106
+ ` + duplicateThemes.join("\n");
107
+ }
108
+ });
109
+ return themesString;
110
+ }
111
+ function objectToJsString(obj, indent = 4) {
112
+ const whitespace = new Array(indent).fill(" ").join("");
113
+ return `{
114
+ ${Object.entries(obj).map(([k, v]) => `${whitespace}${k}: '${v}'`).join(",\n")}
115
+ }`;
116
+ }
117
+ function createThemeIntercept(createThemeExport, themeBuilderInterceptOpts) {
118
+ return new Proxy(createThemeExport, {
119
+ get(target, key) {
120
+ const out = Reflect.get(target, key);
121
+ if (key === "createThemeBuilder") {
122
+ return new Proxy(out, {
123
+ apply(target2, thisArg, argArray) {
124
+ const builder = Reflect.apply(target2, thisArg, argArray);
125
+ return themeBuilderIntercept(builder, themeBuilderInterceptOpts);
126
+ }
127
+ });
128
+ }
129
+ return out;
130
+ }
131
+ });
132
+ }
133
+ function themeBuilderIntercept(themeBuilder, themeBuilderInterceptOpts) {
134
+ return new Proxy(themeBuilder, {
135
+ get(target, key) {
136
+ const out = Reflect.get(target, key);
137
+ if (key === "build") {
138
+ themeBuilderInterceptOpts.onComplete({
139
+ themeBuilder
140
+ });
141
+ }
142
+ return out;
143
+ }
144
+ });
145
+ }
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ generateThemes
149
+ });
150
+ //# sourceMappingURL=generate-themes.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/generate-themes.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAGnB,sBAAe;AAMf,eAAsB,eAAe,SAA8C;AACjF,UAAQ,4BAA4B,EAAE,SAAS;AAE/C,MAAI,UAAoD;AAExD,QAAM,YAAY,cAAAA,QAAO,UAAU;AAEnC,gBAAAA,QAAO,U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,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAEA,SAAS,sBACP,cACA,2BACA;AACA,SAAO,IAAI,MAAM,cAAc;AAAA,IAC7B,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,SAAS;AAEnB,kCAA0B,WAAW;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;",
5
+ "names": ["Module", "fs", "target"]
6
+ }
@@ -0,0 +1,23 @@
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("./generate-themes"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./generate-themes")
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;",
5
+ "names": []
6
+ }
@@ -0,0 +1,116 @@
1
+ import Module from "module";
2
+ import fs from "fs-extra";
3
+ async function generateThemes(options) {
4
+ require("esbuild-register/dist/node").register();
5
+ let promise = null;
6
+ const ogRequire = Module.prototype.require;
7
+ Module.prototype.require = function(id) {
8
+ const out = ogRequire.apply(this, arguments);
9
+ if (id === "@tamagui/create-theme/theme-builder") {
10
+ if (!promise) {
11
+ let resolve;
12
+ promise = new Promise((res) => {
13
+ resolve = res;
14
+ });
15
+ return createThemeIntercept(out, {
16
+ onComplete: (result) => {
17
+ resolve == null ? void 0 : resolve(result.themeBuilder);
18
+ }
19
+ });
20
+ }
21
+ }
22
+ return out;
23
+ };
24
+ try {
25
+ const requiredThemes = require(options.inPath);
26
+ const themes = requiredThemes["default"] || requiredThemes["themes"];
27
+ const generatedThemes = generatedThemesToTypescript(themes);
28
+ const themeBuilder = promise ? await promise : null;
29
+ await Promise.all([
30
+ fs.writeFile(options.outPath, generatedThemes),
31
+ (themeBuilder == null ? void 0 : themeBuilder.state) ? fs.writeFile(
32
+ `${options.outPath}.theme-builder.json`,
33
+ JSON.stringify(themeBuilder == null ? void 0 : themeBuilder.state)
34
+ ) : null
35
+ ]);
36
+ } finally {
37
+ Module.prototype.require = ogRequire;
38
+ }
39
+ }
40
+ function generatedThemesToTypescript(themes) {
41
+ const deduped = /* @__PURE__ */ new Map();
42
+ const dedupedToNames = /* @__PURE__ */ new Map();
43
+ for (const name in themes) {
44
+ const theme = themes[name];
45
+ const key = JSON.stringify(theme);
46
+ if (deduped.has(key)) {
47
+ dedupedToNames.set(key, [...dedupedToNames.get(key), name]);
48
+ } else {
49
+ deduped.set(key, theme);
50
+ dedupedToNames.set(key, [name]);
51
+ }
52
+ }
53
+ const baseTypeString = `type Theme = {
54
+ ${Object.entries(themes.light || themes[Object.keys(themes)[0]]).map(([k]) => {
55
+ return ` ${k}: string;
56
+ `;
57
+ }).join("")}
58
+ }`;
59
+ let themesString = `${baseTypeString}
60
+ `;
61
+ deduped.forEach((theme) => {
62
+ const key = JSON.stringify(theme);
63
+ const [baseName, ...restNames] = dedupedToNames.get(key);
64
+ const baseTheme = `export const ${baseName} = ${objectToJsString(theme)} as Theme`;
65
+ themesString += `
66
+ ${baseTheme}`;
67
+ if (restNames.length) {
68
+ const duplicateThemes = restNames.map(
69
+ (name) => `export const ${name} = ${baseName} as Theme`
70
+ );
71
+ themesString += `
72
+
73
+ ` + duplicateThemes.join("\n");
74
+ }
75
+ });
76
+ return themesString;
77
+ }
78
+ function objectToJsString(obj, indent = 4) {
79
+ const whitespace = new Array(indent).fill(" ").join("");
80
+ return `{
81
+ ${Object.entries(obj).map(([k, v]) => `${whitespace}${k}: '${v}'`).join(",\n")}
82
+ }`;
83
+ }
84
+ function createThemeIntercept(createThemeExport, themeBuilderInterceptOpts) {
85
+ return new Proxy(createThemeExport, {
86
+ get(target, key) {
87
+ const out = Reflect.get(target, key);
88
+ if (key === "createThemeBuilder") {
89
+ return new Proxy(out, {
90
+ apply(target2, thisArg, argArray) {
91
+ const builder = Reflect.apply(target2, thisArg, argArray);
92
+ return themeBuilderIntercept(builder, themeBuilderInterceptOpts);
93
+ }
94
+ });
95
+ }
96
+ return out;
97
+ }
98
+ });
99
+ }
100
+ function themeBuilderIntercept(themeBuilder, themeBuilderInterceptOpts) {
101
+ return new Proxy(themeBuilder, {
102
+ get(target, key) {
103
+ const out = Reflect.get(target, key);
104
+ if (key === "build") {
105
+ themeBuilderInterceptOpts.onComplete({
106
+ themeBuilder
107
+ });
108
+ }
109
+ return out;
110
+ }
111
+ });
112
+ }
113
+ export {
114
+ generateThemes
115
+ };
116
+ //# sourceMappingURL=generate-themes.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/generate-themes.ts"],
4
+ "mappings": "AAAA,OAAO,YAAY;AAGnB,OAAO,QAAQ;AAMf,eAAsB,eAAe,SAA8C;AACjF,UAAQ,4BAA4B,EAAE,SAAS;AAE/C,MAAI,UAAoD;AAExD,QAAM,YAAY,OAAO,UAAU;AAEnC,SAAO,UAAU,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AAA,EACF,CAAC;AACH;AAEA,SAAS,sBACP,cACA,2BACA;AACA,SAAO,IAAI,MAAM,cAAc;AAAA,IAC7B,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,SAAS;AAEnB,kCAA0B,WAAW;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;",
5
+ "names": ["target"]
6
+ }
@@ -0,0 +1,116 @@
1
+ import Module from "module";
2
+ import fs from "fs-extra";
3
+ async function generateThemes(options) {
4
+ require("esbuild-register/dist/node").register();
5
+ let promise = null;
6
+ const ogRequire = Module.prototype.require;
7
+ Module.prototype.require = function(id) {
8
+ const out = ogRequire.apply(this, arguments);
9
+ if (id === "@tamagui/create-theme/theme-builder") {
10
+ if (!promise) {
11
+ let resolve;
12
+ promise = new Promise((res) => {
13
+ resolve = res;
14
+ });
15
+ return createThemeIntercept(out, {
16
+ onComplete: (result) => {
17
+ resolve == null ? void 0 : resolve(result.themeBuilder);
18
+ }
19
+ });
20
+ }
21
+ }
22
+ return out;
23
+ };
24
+ try {
25
+ const requiredThemes = require(options.inPath);
26
+ const themes = requiredThemes["default"] || requiredThemes["themes"];
27
+ const generatedThemes = generatedThemesToTypescript(themes);
28
+ const themeBuilder = promise ? await promise : null;
29
+ await Promise.all([
30
+ fs.writeFile(options.outPath, generatedThemes),
31
+ (themeBuilder == null ? void 0 : themeBuilder.state) ? fs.writeFile(
32
+ `${options.outPath}.theme-builder.json`,
33
+ JSON.stringify(themeBuilder == null ? void 0 : themeBuilder.state)
34
+ ) : null
35
+ ]);
36
+ } finally {
37
+ Module.prototype.require = ogRequire;
38
+ }
39
+ }
40
+ function generatedThemesToTypescript(themes) {
41
+ const deduped = /* @__PURE__ */ new Map();
42
+ const dedupedToNames = /* @__PURE__ */ new Map();
43
+ for (const name in themes) {
44
+ const theme = themes[name];
45
+ const key = JSON.stringify(theme);
46
+ if (deduped.has(key)) {
47
+ dedupedToNames.set(key, [...dedupedToNames.get(key), name]);
48
+ } else {
49
+ deduped.set(key, theme);
50
+ dedupedToNames.set(key, [name]);
51
+ }
52
+ }
53
+ const baseTypeString = `type Theme = {
54
+ ${Object.entries(themes.light || themes[Object.keys(themes)[0]]).map(([k]) => {
55
+ return ` ${k}: string;
56
+ `;
57
+ }).join("")}
58
+ }`;
59
+ let themesString = `${baseTypeString}
60
+ `;
61
+ deduped.forEach((theme) => {
62
+ const key = JSON.stringify(theme);
63
+ const [baseName, ...restNames] = dedupedToNames.get(key);
64
+ const baseTheme = `export const ${baseName} = ${objectToJsString(theme)} as Theme`;
65
+ themesString += `
66
+ ${baseTheme}`;
67
+ if (restNames.length) {
68
+ const duplicateThemes = restNames.map(
69
+ (name) => `export const ${name} = ${baseName} as Theme`
70
+ );
71
+ themesString += `
72
+
73
+ ` + duplicateThemes.join("\n");
74
+ }
75
+ });
76
+ return themesString;
77
+ }
78
+ function objectToJsString(obj, indent = 4) {
79
+ const whitespace = new Array(indent).fill(" ").join("");
80
+ return `{
81
+ ${Object.entries(obj).map(([k, v]) => `${whitespace}${k}: '${v}'`).join(",\n")}
82
+ }`;
83
+ }
84
+ function createThemeIntercept(createThemeExport, themeBuilderInterceptOpts) {
85
+ return new Proxy(createThemeExport, {
86
+ get(target, key) {
87
+ const out = Reflect.get(target, key);
88
+ if (key === "createThemeBuilder") {
89
+ return new Proxy(out, {
90
+ apply(target2, thisArg, argArray) {
91
+ const builder = Reflect.apply(target2, thisArg, argArray);
92
+ return themeBuilderIntercept(builder, themeBuilderInterceptOpts);
93
+ }
94
+ });
95
+ }
96
+ return out;
97
+ }
98
+ });
99
+ }
100
+ function themeBuilderIntercept(themeBuilder, themeBuilderInterceptOpts) {
101
+ return new Proxy(themeBuilder, {
102
+ get(target, key) {
103
+ const out = Reflect.get(target, key);
104
+ if (key === "build") {
105
+ themeBuilderInterceptOpts.onComplete({
106
+ themeBuilder
107
+ });
108
+ }
109
+ return out;
110
+ }
111
+ });
112
+ }
113
+ export {
114
+ generateThemes
115
+ };
116
+ //# sourceMappingURL=generate-themes.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/generate-themes.ts"],
4
+ "mappings": "AAAA,OAAO,YAAY;AAGnB,OAAO,QAAQ;AAMf,eAAsB,eAAe,SAA8C;AACjF,UAAQ,4BAA4B,EAAE,SAAS;AAE/C,MAAI,UAAoD;AAExD,QAAM,YAAY,OAAO,UAAU;AAEnC,SAAO,UAAU,UAAU,SAAU,IAAI;AAEvC,UAAM,MAAM,UAAU,MAAM,MAAM,SAAS;AAC3C,QAAI,OAAO,uCAAuC;AAChD,UAAI,CAAC,SAAS;AACZ,YAAI;AACJ,kBAAU,IAAI,QAAQ,CAAC,QAAQ;AAC7B,oBAAU;AAAA,QACZ,CAAC;AACD,eAAO,qBAAqB,KAAK;AAAA,UAC/B,YAAY,CAAC,WAAW;AACtB,+CAAU,OAAO;AAAA,UACnB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,iBAAiB,QAAQ,QAAQ,MAAM;AAC7C,UAAM,SAAS,eAAe,SAAS,KAAK,eAAe,QAAQ;AACnE,UAAM,kBAAkB,4BAA4B,MAAM;AAE1D,UAAM,eAAe,UAAU,MAAM,UAAU;AAE/C,UAAM,QAAQ,IAAI;AAAA,MAChB,GAAG,UAAU,QAAQ,SAAS,eAAe;AAAA,OAC7C,6CAAc,SACV,GAAG;AAAA,QACD,GAAG,QAAQ;AAAA,QACX,KAAK,UAAU,6CAAc,KAAK;AAAA,MACpC,IACA;AAAA,IACN,CAAC;AAAA,EACH,UAAE;AACA,WAAO,UAAU,UAAU;AAAA,EAC7B;AACF;AAEA,SAAS,4BAA4B,QAA6B;AAChE,QAAM,UAAU,oBAAI,IAAoB;AACxC,QAAM,iBAAiB,oBAAI,IAAsB;AAEjD,aAAW,QAAQ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IAAI,MAAM,mBAAmB;AAAA,IAClC,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,sBAAsB;AAChC,eAAO,IAAI,MAAM,KAAK;AAAA,UACpB,MAAMA,SAAQ,SAAS,UAAU;AAC/B,kBAAM,UAAU,QAAQ,MAAMA,SAAQ,SAAS,QAAQ;AACvD,mBAAO,sBAAsB,SAAS,yBAAyB;AAAA,UACjE;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAEA,SAAS,sBACP,cACA,2BACA;AACA,SAAO,IAAI,MAAM,cAAc;AAAA,IAC7B,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,SAAS;AAEnB,kCAA0B,WAAW;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;",
5
+ "names": ["target"]
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./generate-themes";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./generate-themes";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var generate_themes_exports = {};
30
+ __export(generate_themes_exports, {
31
+ generateThemes: () => generateThemes
32
+ });
33
+ module.exports = __toCommonJS(generate_themes_exports);
34
+ var import_module = __toESM(require("module"));
35
+ var import_fs_extra = __toESM(require("fs-extra"));
36
+ async function generateThemes(options) {
37
+ require("esbuild-register/dist/node").register();
38
+ let promise = null;
39
+ const ogRequire = import_module.default.prototype.require;
40
+ import_module.default.prototype.require = function(id) {
41
+ const out = ogRequire.apply(this, arguments);
42
+ if (id === "@tamagui/create-theme/theme-builder") {
43
+ if (!promise) {
44
+ let resolve;
45
+ promise = new Promise((res) => {
46
+ resolve = res;
47
+ });
48
+ return createThemeIntercept(out, {
49
+ onComplete: (result) => {
50
+ resolve == null ? void 0 : resolve(result.themeBuilder);
51
+ }
52
+ });
53
+ }
54
+ }
55
+ return out;
56
+ };
57
+ const requiredThemes = require(options.inPath);
58
+ const themes = requiredThemes["default"] || requiredThemes["themes"];
59
+ const generatedThemes = generatedThemesToTypescript(themes);
60
+ const themeBuilder = promise ? await promise : null;
61
+ await Promise.all([
62
+ import_fs_extra.default.writeFile(options.outPath, generatedThemes),
63
+ (themeBuilder == null ? void 0 : themeBuilder.state) ? import_fs_extra.default.writeFile(
64
+ `${options.outPath}.theme-builder.json`,
65
+ JSON.stringify(themeBuilder == null ? void 0 : themeBuilder.state)
66
+ ) : null
67
+ ]);
68
+ }
69
+ function generatedThemesToTypescript(themes) {
70
+ const deduped = /* @__PURE__ */ new Map();
71
+ const dedupedToNames = /* @__PURE__ */ new Map();
72
+ for (const name in themes) {
73
+ const theme = themes[name];
74
+ const key = JSON.stringify(theme);
75
+ if (deduped.has(key)) {
76
+ dedupedToNames.set(key, [...dedupedToNames.get(key), name]);
77
+ } else {
78
+ deduped.set(key, theme);
79
+ dedupedToNames.set(key, [name]);
80
+ }
81
+ }
82
+ const baseTypeString = `type Theme = {
83
+ ${Object.entries(themes.light || themes[Object.keys(themes)[0]]).map(([k]) => {
84
+ return ` ${k}: string;
85
+ `;
86
+ }).join("")}
87
+ }`;
88
+ let themesString = `${baseTypeString}
89
+ `;
90
+ deduped.forEach((theme) => {
91
+ const key = JSON.stringify(theme);
92
+ const [baseName, ...restNames] = dedupedToNames.get(key);
93
+ const baseTheme = `export const ${baseName} = ${objectToJsString(theme)} as Theme`;
94
+ themesString += `
95
+ ${baseTheme}`;
96
+ if (restNames.length) {
97
+ const duplicateThemes = restNames.map(
98
+ (name) => `export const ${name} = ${baseName} as Theme`
99
+ );
100
+ themesString += `
101
+
102
+ ` + duplicateThemes.join("\n");
103
+ }
104
+ });
105
+ return themesString;
106
+ }
107
+ function objectToJsString(obj, indent = 4) {
108
+ const whitespace = new Array(indent).fill(" ").join("");
109
+ return `{
110
+ ${Object.entries(obj).map(([k, v]) => `${whitespace}${k}: '${v}'`).join(",\n")}
111
+ }`;
112
+ }
113
+ function createThemeIntercept(createThemeExport, themeBuilderInterceptOpts) {
114
+ return new Proxy(createThemeExport, {
115
+ get(target, key) {
116
+ const out = Reflect.get(target, key);
117
+ if (key === "createThemeBuilder") {
118
+ return new Proxy(out, {
119
+ apply(target2, thisArg, argArray) {
120
+ const builder = Reflect.apply(target2, thisArg, argArray);
121
+ return themeBuilderIntercept(builder, themeBuilderInterceptOpts);
122
+ }
123
+ });
124
+ }
125
+ return out;
126
+ }
127
+ });
128
+ }
129
+ function themeBuilderIntercept(themeBuilder, themeBuilderInterceptOpts) {
130
+ return new Proxy(themeBuilder, {
131
+ get(target, key) {
132
+ const out = Reflect.get(target, key);
133
+ if (key === "build") {
134
+ themeBuilderInterceptOpts.onComplete({
135
+ themeBuilder
136
+ });
137
+ }
138
+ return out;
139
+ }
140
+ });
141
+ }
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ generateThemes
145
+ });
146
+ //# sourceMappingURL=generate-themes.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/generate-themes.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAGnB,sBAAe;AAMf,eAAsB,eAAe,SAA8C;AACjF,UAAQ,4BAA4B,EAAE,SAAS;AAE/C,MAAI,UAAoD;AAExD,QAAM,YAAY,cAAAA,QAAO,UAAU;AAEnC,gBAAAA,QAAO,UAAU,UAAU,SAAU,IAAI;AAEvC,UAAM,MAAM,UAAU,MAAM,MAAM,SAAS;AAC3C,QAAI,OAAO,uCAAuC;AAChD,UAAI,CAAC,SAAS;AACZ,YAAI;AACJ,kBAAU,IAAI,QAAQ,CAAC,QAAQ;AAC7B,oBAAU;AAAA,QACZ,CAAC;AACD,eAAO,qBAAqB,KAAK;AAAA,UAC/B,YAAY,CAAC,WAAW;AACtB,+CAAU,OAAO;AAAA,UACnB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,QAAQ,QAAQ,MAA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AM,kBAAkB,UAAU;AAAA,QAChC,CAAC,SAAS,gBAAgB,UAAU;AAAA,MACtC;AACA,sBAAgB;AAAA;AAAA,IAAS,gBAAgB,KAAK,IAAI;AAAA,IACpD;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,SAAS,iBAAiB,KAAa,SAAS,GAAG;AACjD,QAAM,aAAa,IAAI,MAAM,MAAM,EAAE,KAAK,GAAG,EAAE,KAAK,EAAE;AACtD,SAAO;AAAA,EACP,OAAO,QAAQ,GAAG,EACjB,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,aAAa,OAAO,IAAI,EAC3C,KAAK,KAAK;AAAA;AAEb;AAEA,SAAS,qBACP,mBACA,2BACA;AACA,SAAO,IAAI,MAAM,mBAAmB;AAAA,IAClC,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,sBAAsB;AAChC,eAAO,IAAI,MAAM,KAAK;AAAA,UACpB,MAAMC,SAAQ,SAAS,UAAU;AAC/B,kBAAM,UAAU,QAAQ,MAAMA,SAAQ,SAAS,QAAQ;AACvD,mBAAO,sBAAsB,SAAS,yBAAyB;AAAA,UACjE;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAEA,SAAS,sBACP,cACA,2BACA;AACA,SAAO,IAAI,MAAM,cAAc;AAAA,IAC7B,IAAI,QAAQ,KAAK;AACf,YAAM,MAAM,QAAQ,IAAI,QAAQ,GAAG;AACnC,UAAI,QAAQ,SAAS;AAEnB,kCAA0B,WAAW;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;",
5
+ "names": ["Module", "fs", "target"]
6
+ }
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
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("./generate-themes"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./generate-themes")
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;",
5
+ "names": []
6
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tamagui/generate-themes",
3
+ "version": "1.33.4",
4
+ "source": "src/index.ts",
5
+ "types": "./types/index.d.ts",
6
+ "main": "dist/cjs",
7
+ "module": "dist/esm",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "types",
14
+ "dist"
15
+ ],
16
+ "exports": {
17
+ "./package.json": "./package.json",
18
+ ".": {
19
+ "types": "./types/index.d.ts",
20
+ "import": "./dist/esm/index.js",
21
+ "require": "./dist/cjs/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "tamagui-build --output-mjs",
26
+ "watch": "yarn build --watch",
27
+ "clean": "tamagui-build clean",
28
+ "clean:build": "tamagui-build clean:build"
29
+ },
30
+ "dependencies": {
31
+ "@tamagui/create-theme": "1.33.4",
32
+ "@tamagui/types": "1.33.4",
33
+ "esbuild-register": "^3.4.2",
34
+ "fs-extra": "^11.1.0"
35
+ }
36
+ }
@@ -0,0 +1,144 @@
1
+ import Module from 'module'
2
+
3
+ import type { ThemeBuilder } from '@tamagui/create-theme/theme-builder'
4
+ import fs from 'fs-extra'
5
+
6
+ type ThemeBuilderInterceptOpts = {
7
+ onComplete: (result: { themeBuilder: ThemeBuilder<any> }) => void
8
+ }
9
+
10
+ export async function generateThemes(options: { inPath: string; outPath: string }) {
11
+ require('esbuild-register/dist/node').register()
12
+
13
+ let promise: Promise<null | ThemeBuilder<any>> | null = null as any
14
+
15
+ const ogRequire = Module.prototype.require
16
+ // @ts-ignore
17
+ Module.prototype.require = function (id) {
18
+ // @ts-ignore
19
+ const out = ogRequire.apply(this, arguments)
20
+ if (id === '@tamagui/create-theme/theme-builder') {
21
+ if (!promise) {
22
+ let resolve: Function
23
+ promise = new Promise((res) => {
24
+ resolve = res
25
+ })
26
+ return createThemeIntercept(out, {
27
+ onComplete: (result) => {
28
+ resolve?.(result.themeBuilder)
29
+ },
30
+ })
31
+ }
32
+ }
33
+ return out
34
+ }
35
+
36
+ try {
37
+ const requiredThemes = require(options.inPath)
38
+ const themes = requiredThemes['default'] || requiredThemes['themes']
39
+ const generatedThemes = generatedThemesToTypescript(themes)
40
+
41
+ const themeBuilder = promise ? await promise : null
42
+
43
+ await Promise.all([
44
+ fs.writeFile(options.outPath, generatedThemes),
45
+ themeBuilder?.state
46
+ ? fs.writeFile(
47
+ `${options.outPath}.theme-builder.json`,
48
+ JSON.stringify(themeBuilder?.state)
49
+ )
50
+ : null,
51
+ ])
52
+ } finally {
53
+ Module.prototype.require = ogRequire
54
+ }
55
+ }
56
+
57
+ function generatedThemesToTypescript(themes: Record<string, any>) {
58
+ const deduped = new Map<string, Object>()
59
+ const dedupedToNames = new Map<string, string[]>()
60
+
61
+ for (const name in themes) {
62
+ const theme = themes[name]
63
+ const key = JSON.stringify(theme)
64
+ if (deduped.has(key)) {
65
+ dedupedToNames.set(key, [...dedupedToNames.get(key)!, name])
66
+ } else {
67
+ deduped.set(key, theme)
68
+ dedupedToNames.set(key, [name])
69
+ }
70
+ }
71
+
72
+ const baseTypeString = `type Theme = {
73
+ ${Object.entries(themes.light || themes[Object.keys(themes)[0]])
74
+ .map(([k]) => {
75
+ return ` ${k}: string;\n`
76
+ })
77
+ .join('')}
78
+ }`
79
+
80
+ let themesString = `${baseTypeString}\n`
81
+
82
+ deduped.forEach((theme) => {
83
+ const key = JSON.stringify(theme)
84
+ const [baseName, ...restNames] = dedupedToNames.get(key)!
85
+ const baseTheme = `export const ${baseName} = ${objectToJsString(theme)} as Theme`
86
+ themesString += `\n${baseTheme}`
87
+
88
+ if (restNames.length) {
89
+ const duplicateThemes = restNames.map(
90
+ (name) => `export const ${name} = ${baseName} as Theme`
91
+ )
92
+ themesString += `\n\n` + duplicateThemes.join('\n')
93
+ }
94
+ })
95
+
96
+ return themesString
97
+ }
98
+
99
+ function objectToJsString(obj: Object, indent = 4) {
100
+ const whitespace = new Array(indent).fill(' ').join('')
101
+ return `{
102
+ ${Object.entries(obj)
103
+ .map(([k, v]) => `${whitespace}${k}: '${v}'`)
104
+ .join(',\n')}
105
+ }`
106
+ }
107
+
108
+ function createThemeIntercept(
109
+ createThemeExport: any,
110
+ themeBuilderInterceptOpts: ThemeBuilderInterceptOpts
111
+ ) {
112
+ return new Proxy(createThemeExport, {
113
+ get(target, key) {
114
+ const out = Reflect.get(target, key)
115
+ if (key === 'createThemeBuilder') {
116
+ return new Proxy(out, {
117
+ apply(target, thisArg, argArray) {
118
+ const builder = Reflect.apply(target, thisArg, argArray) as any
119
+ return themeBuilderIntercept(builder, themeBuilderInterceptOpts)
120
+ },
121
+ })
122
+ }
123
+ return out
124
+ },
125
+ })
126
+ }
127
+
128
+ function themeBuilderIntercept(
129
+ themeBuilder: any,
130
+ themeBuilderInterceptOpts: ThemeBuilderInterceptOpts
131
+ ) {
132
+ return new Proxy(themeBuilder, {
133
+ get(target, key) {
134
+ const out = Reflect.get(target, key)
135
+ if (key === 'build') {
136
+ // get the state and return!
137
+ themeBuilderInterceptOpts.onComplete({
138
+ themeBuilder,
139
+ })
140
+ }
141
+ return out
142
+ },
143
+ })
144
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './generate-themes'
@@ -0,0 +1,5 @@
1
+ export declare function generateThemes(options: {
2
+ inPath: string;
3
+ outPath: string;
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=generate-themes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-themes.d.ts","sourceRoot":"","sources":["../src/generate-themes.ts"],"names":[],"mappings":"AASA,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,iBA6ChF"}
@@ -0,0 +1,2 @@
1
+ export * from './generate-themes';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}