@tamagui/generate-themes 2.7.7 → 3.0.0-beta.643.1
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/dist/cjs/generate-themes.cjs +146 -135
- package/dist/cjs/generate-themes.native.cjs +225 -0
- package/dist/cjs/generate-themes.native.js +174 -161
- package/dist/cjs/generate-themes.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +22 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/write-generate-themes.cjs +29 -39
- package/dist/cjs/write-generate-themes.native.cjs +49 -0
- package/dist/cjs/write-generate-themes.native.js +31 -40
- package/dist/cjs/write-generate-themes.native.js.map +1 -1
- package/dist/esm/generate-themes.mjs +132 -117
- package/dist/esm/generate-themes.mjs.map +1 -1
- package/dist/esm/generate-themes.native.js +160 -144
- package/dist/esm/generate-themes.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/write-generate-themes.mjs +13 -13
- package/dist/esm/write-generate-themes.mjs.map +1 -1
- package/dist/esm/write-generate-themes.native.js +15 -15
- package/dist/esm/write-generate-themes.native.js.map +1 -1
- package/package.json +6 -6
- package/src/generate-themes.ts +34 -18
- package/types/generate-themes.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,51 +6,40 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
30
26
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
28
|
var write_generate_themes_exports = {};
|
|
35
|
-
__export(write_generate_themes_exports, {
|
|
36
|
-
writeGeneratedThemes: () => writeGeneratedThemes
|
|
37
|
-
});
|
|
29
|
+
__export(write_generate_themes_exports, { writeGeneratedThemes: () => writeGeneratedThemes });
|
|
38
30
|
module.exports = __toCommonJS(write_generate_themes_exports);
|
|
39
31
|
var fs = __toESM(require("fs-extra"), 1);
|
|
40
32
|
async function writeGeneratedThemes(tamaguiDotDir, outPath, generatedOutput) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const newContent = `// @ts-nocheck
|
|
33
|
+
if (!generatedOutput) return;
|
|
34
|
+
const { generated } = generatedOutput;
|
|
35
|
+
if (process.env.DEBUG === "tamagui") {
|
|
36
|
+
console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));
|
|
37
|
+
}
|
|
38
|
+
const newContent = `// @ts-nocheck
|
|
49
39
|
` + generated;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
40
|
+
const existingContent = await fs.readFile(outPath, "utf-8").catch(() => null);
|
|
41
|
+
if (existingContent === newContent) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
await fs.writeFile(outPath, newContent);
|
|
45
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var write_generate_themes_exports = {};
|
|
31
|
+
__export(write_generate_themes_exports, { writeGeneratedThemes: () => writeGeneratedThemes });
|
|
32
|
+
module.exports = __toCommonJS(write_generate_themes_exports);
|
|
33
|
+
var fs = __toESM(require("fs-extra"), 1);
|
|
34
|
+
async function writeGeneratedThemes(tamaguiDotDir, outPath, generatedOutput) {
|
|
35
|
+
if (!generatedOutput) return;
|
|
36
|
+
var { generated } = generatedOutput;
|
|
37
|
+
if (process.env.DEBUG === "tamagui") {
|
|
38
|
+
console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));
|
|
39
|
+
}
|
|
40
|
+
var newContent = `// @ts-nocheck
|
|
41
|
+
` + generated;
|
|
42
|
+
var existingContent = await fs.readFile(outPath, "utf-8").catch(function() {
|
|
43
|
+
return null;
|
|
44
|
+
});
|
|
45
|
+
if (existingContent === newContent) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await fs.writeFile(outPath, newContent);
|
|
49
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,54 +8,44 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var write_generate_themes_exports = {};
|
|
37
|
-
__export(write_generate_themes_exports, {
|
|
38
|
-
writeGeneratedThemes: () => writeGeneratedThemes
|
|
39
|
-
});
|
|
31
|
+
__export(write_generate_themes_exports, { writeGeneratedThemes: () => writeGeneratedThemes });
|
|
40
32
|
module.exports = __toCommonJS(write_generate_themes_exports);
|
|
41
33
|
var fs = __toESM(require("fs-extra"), 1);
|
|
42
34
|
async function writeGeneratedThemes(tamaguiDotDir, outPath, generatedOutput) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
var newContent = `// @ts-nocheck
|
|
35
|
+
if (!generatedOutput) return;
|
|
36
|
+
var { generated } = generatedOutput;
|
|
37
|
+
if (process.env.DEBUG === "tamagui") {
|
|
38
|
+
console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));
|
|
39
|
+
}
|
|
40
|
+
var newContent = `// @ts-nocheck
|
|
51
41
|
` + generated;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
var existingContent = await fs.readFile(outPath, "utf-8").catch(function() {
|
|
43
|
+
return null;
|
|
44
|
+
});
|
|
45
|
+
if (existingContent === newContent) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await fs.writeFile(outPath, newContent);
|
|
59
49
|
}
|
|
50
|
+
|
|
60
51
|
//# sourceMappingURL=write-generate-themes.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"write-generate-themes.native.js","names":[],"sources":["cjs/write-generate-themes.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar write_generate_themes_exports = {};\n__export(write_generate_themes_exports, {\n writeGeneratedThemes: () => writeGeneratedThemes\n});\nmodule.exports = __toCommonJS(write_generate_themes_exports);\nvar fs = __toESM(require(\"fs-extra\"), 1);\nasync function writeGeneratedThemes(tamaguiDotDir, outPath, generatedOutput) {\n if (!generatedOutput) return;\n var { generated } = generatedOutput;\n if (process.env.DEBUG === \"tamagui\") {\n console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));\n }\n var newContent = `// @ts-nocheck\n` + generated;\n var existingContent = await fs.readFile(outPath, \"utf-8\").catch(function() {\n return null;\n });\n if (existingContent === newContent) {\n return;\n }\n await fs.writeFile(outPath, newContent);\n}\n//# sourceMappingURL=write-generate-themes.js.map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,KAAK,qBAAqB,KAAK,UAAU,iBAAiB,MAAM,CAAC,CAAC;CAC5E;CACA,IAAI,aAAa;IACf;CACF,IAAI,kBAAkB,MAAM,GAAG,SAAS,SAAS,OAAO,EAAE,MAAM,WAAW;EACzE,OAAO;CACT,CAAC;CACD,IAAI,oBAAoB,YAAY;EAClC;CACF;CACA,MAAM,GAAG,UAAU,SAAS,UAAU;AACxC"}
|
|
@@ -1,69 +1,82 @@
|
|
|
1
|
+
import Module from "node:module";
|
|
1
2
|
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const ModuleInternals = Module;
|
|
2
10
|
let didRegisterOnce = false;
|
|
3
11
|
async function generateThemes(inputFile) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
const inputFilePath = inputFile[0] === "." ? join(process.cwd(), inputFile) : inputFile;
|
|
13
|
+
if (!didRegisterOnce) {
|
|
14
|
+
didRegisterOnce = true;
|
|
15
|
+
const nodeResolve = ModuleInternals._resolveFilename;
|
|
16
|
+
__require("esbuild-register/dist/node").register({ hookIgnoreNodeModules: false });
|
|
17
|
+
const chained = ModuleInternals._resolveFilename;
|
|
18
|
+
ModuleInternals._resolveFilename = function(request, ...args) {
|
|
19
|
+
if (request[0] !== "." && !request.startsWith("/")) {
|
|
20
|
+
try {
|
|
21
|
+
return nodeResolve.call(this, request, ...args);
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
return chained.call(this, request, ...args);
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
purgeCache(inputFilePath);
|
|
28
|
+
}
|
|
29
|
+
let og = process.env.TAMAGUI_KEEP_THEMES;
|
|
30
|
+
process.env.TAMAGUI_KEEP_THEMES = "1";
|
|
31
|
+
try {
|
|
32
|
+
const requiredThemes = __require(inputFilePath);
|
|
33
|
+
const themes = requiredThemes["default"] || requiredThemes["themes"] || requiredThemes[Object.keys(requiredThemes)[0]];
|
|
34
|
+
const generatedThemes = generatedThemesToTypescript(themes);
|
|
35
|
+
return { generated: generatedThemes };
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.warn(` \u26A0\uFE0F Error running theme builder:
|
|
25
38
|
`, err?.["stack"] || err);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
} finally {
|
|
40
|
+
process.env.TAMAGUI_KEEP_THEMES = og;
|
|
41
|
+
}
|
|
29
42
|
}
|
|
30
|
-
const dedupedTokens = /* @__PURE__ */new Map();
|
|
31
43
|
function generatedThemesToTypescript(themes) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
const dedupedTokens = /* @__PURE__ */ new Map();
|
|
45
|
+
const dedupedThemes = /* @__PURE__ */ new Map();
|
|
46
|
+
const dedupedThemeToNames = /* @__PURE__ */ new Map();
|
|
47
|
+
let i = 0;
|
|
48
|
+
for (const name in themes) {
|
|
49
|
+
i++;
|
|
50
|
+
const theme = themes[name];
|
|
51
|
+
let j = 0;
|
|
52
|
+
for (const [key2, value] of Object.entries(theme)) {
|
|
53
|
+
i++;
|
|
54
|
+
const uniqueKey = `t${i}${j}`;
|
|
55
|
+
if (!dedupedTokens.has(value)) {
|
|
56
|
+
dedupedTokens.set(value, uniqueKey);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const key = JSON.stringify(theme);
|
|
60
|
+
if (dedupedThemes.has(key)) {
|
|
61
|
+
dedupedThemeToNames.set(key, [...dedupedThemeToNames.get(key), name]);
|
|
62
|
+
} else {
|
|
63
|
+
dedupedThemes.set(key, theme);
|
|
64
|
+
dedupedThemeToNames.set(key, [name]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!themes) {
|
|
68
|
+
throw new Error(`Didn't find any themes exported or returned`);
|
|
69
|
+
}
|
|
70
|
+
const baseKeys = Object.entries(themes.light || themes[Object.keys(themes)[0]]);
|
|
71
|
+
const baseTypeString = `export type Theme = {
|
|
59
72
|
${baseKeys.map(([k]) => {
|
|
60
|
-
|
|
73
|
+
return ` ${JSON.stringify(k)}: string;
|
|
61
74
|
`;
|
|
62
|
-
|
|
75
|
+
}).join("")}
|
|
63
76
|
}`;
|
|
64
|
-
|
|
77
|
+
let out = `${baseTypeString}
|
|
65
78
|
`;
|
|
66
|
-
|
|
79
|
+
out += `
|
|
67
80
|
function t(a: [number, number][]) {
|
|
68
81
|
let res: Record<string,string> = {}
|
|
69
82
|
for (const [ki, vi] of a) {
|
|
@@ -72,89 +85,91 @@ function t(a: [number, number][]) {
|
|
|
72
85
|
return res as Theme
|
|
73
86
|
}
|
|
74
87
|
`;
|
|
75
|
-
|
|
88
|
+
out += `export const colors = [
|
|
76
89
|
`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
let index = 0;
|
|
91
|
+
const valueToIndex = {};
|
|
92
|
+
dedupedTokens.forEach((name, value) => {
|
|
93
|
+
valueToIndex[value] = index;
|
|
94
|
+
index++;
|
|
95
|
+
out += ` '${value}',
|
|
83
96
|
`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
});
|
|
98
|
+
out += "]\n\n";
|
|
99
|
+
const keys = baseKeys.map(([k]) => k);
|
|
100
|
+
out += `const ks = [
|
|
88
101
|
`;
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
out += keys.map((k) => JSON.stringify(k)).join(",\n");
|
|
103
|
+
out += `]
|
|
91
104
|
|
|
92
105
|
`;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
let nameI = 0;
|
|
107
|
+
let themeTypes = `export type ThemeNames =`;
|
|
108
|
+
let exported = `export type Themes = Record<ThemeNames, Theme>
|
|
96
109
|
|
|
97
110
|
export const themes: Themes = {`;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
dedupedThemes.forEach((theme) => {
|
|
112
|
+
nameI++;
|
|
113
|
+
const key = JSON.stringify(theme);
|
|
114
|
+
const names = dedupedThemeToNames.get(key);
|
|
115
|
+
const name = `n${nameI}`;
|
|
116
|
+
const baseTheme = `const ${name} = ${objectToJsString(theme, keys, valueToIndex)}`;
|
|
117
|
+
out += `
|
|
105
118
|
${baseTheme}`;
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
names.forEach((n) => {
|
|
120
|
+
exported += `
|
|
108
121
|
${n}: ${name},`;
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
if (n.toLowerCase() === n) {
|
|
123
|
+
themeTypes += `
|
|
111
124
|
| '${n}'`;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
out += `
|
|
116
129
|
|
|
117
130
|
${themeTypes}
|
|
118
131
|
|
|
119
132
|
${exported}
|
|
120
133
|
}
|
|
121
134
|
`;
|
|
122
|
-
|
|
135
|
+
return out;
|
|
123
136
|
}
|
|
124
137
|
function objectToJsString(obj, keys, valueToIndex) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
let arrItems = [];
|
|
139
|
+
for (const key in obj) {
|
|
140
|
+
const ki = keys.indexOf(key);
|
|
141
|
+
const vi = valueToIndex[obj[key]];
|
|
142
|
+
arrItems.push(`[${ki}, ${vi}]`);
|
|
143
|
+
}
|
|
144
|
+
return `t([${arrItems.join(",")}])`;
|
|
132
145
|
}
|
|
133
146
|
function purgeCache(moduleName) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
searchCache(moduleName, (mod) => {
|
|
148
|
+
delete __require.cache[mod.id];
|
|
149
|
+
});
|
|
150
|
+
const pathCache = ModuleInternals._pathCache;
|
|
151
|
+
if (!pathCache) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
Object.keys(pathCache).forEach((cacheKey) => {
|
|
155
|
+
if (cacheKey.indexOf(moduleName) > 0) {
|
|
156
|
+
delete pathCache[cacheKey];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
145
159
|
}
|
|
146
160
|
function searchCache(moduleName, callback) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
let mod = __require.resolve(moduleName);
|
|
162
|
+
if (mod && (mod = __require.cache[mod]) !== void 0) {
|
|
163
|
+
;
|
|
164
|
+
(function traverse(mod2, depth = 0) {
|
|
165
|
+
if (depth > 10) return;
|
|
166
|
+
mod2.children.forEach((child) => {
|
|
167
|
+
traverse(child, depth + 1);
|
|
168
|
+
});
|
|
169
|
+
callback(mod2);
|
|
170
|
+
})(mod);
|
|
171
|
+
}
|
|
158
172
|
}
|
|
173
|
+
|
|
159
174
|
export { generateThemes };
|
|
160
175
|
//# sourceMappingURL=generate-themes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"generate-themes.js","names":[],"sources":["esm/generate-themes.js"],"sourcesContent":["import Module from \"node:module\";\nimport { join } from \"node:path\";\nconst ModuleInternals = Module;\nlet didRegisterOnce = false;\nasync function generateThemes(inputFile) {\n const inputFilePath = inputFile[0] === \".\" ? join(process.cwd(), inputFile) : inputFile;\n if (!didRegisterOnce) {\n didRegisterOnce = true;\n const nodeResolve = ModuleInternals._resolveFilename;\n require(\"esbuild-register/dist/node\").register({\n hookIgnoreNodeModules: false\n });\n const chained = ModuleInternals._resolveFilename;\n ModuleInternals._resolveFilename = function(request, ...args) {\n if (request[0] !== \".\" && !request.startsWith(\"/\")) {\n try {\n return nodeResolve.call(this, request, ...args);\n } catch {\n }\n }\n return chained.call(this, request, ...args);\n };\n } else {\n purgeCache(inputFilePath);\n }\n let og = process.env.TAMAGUI_KEEP_THEMES;\n process.env.TAMAGUI_KEEP_THEMES = \"1\";\n try {\n const requiredThemes = require(inputFilePath);\n const themes = requiredThemes[\"default\"] || requiredThemes[\"themes\"] || requiredThemes[Object.keys(requiredThemes)[0]];\n const generatedThemes = generatedThemesToTypescript(themes);\n return {\n generated: generatedThemes\n };\n } catch (err) {\n console.warn(` \\u26A0\\uFE0F Error running theme builder:\n`, err?.[\"stack\"] || err);\n } finally {\n process.env.TAMAGUI_KEEP_THEMES = og;\n }\n}\nfunction generatedThemesToTypescript(themes) {\n const dedupedTokens = /* @__PURE__ */ new Map();\n const dedupedThemes = /* @__PURE__ */ new Map();\n const dedupedThemeToNames = /* @__PURE__ */ new Map();\n let i = 0;\n for (const name in themes) {\n i++;\n const theme = themes[name];\n let j = 0;\n for (const [key2, value] of Object.entries(theme)) {\n i++;\n const uniqueKey = `t${i}${j}`;\n if (!dedupedTokens.has(value)) {\n dedupedTokens.set(value, uniqueKey);\n }\n }\n const key = JSON.stringify(theme);\n if (dedupedThemes.has(key)) {\n dedupedThemeToNames.set(key, [...dedupedThemeToNames.get(key), name]);\n } else {\n dedupedThemes.set(key, theme);\n dedupedThemeToNames.set(key, [name]);\n }\n }\n if (!themes) {\n throw new Error(`Didn't find any themes exported or returned`);\n }\n const baseKeys = Object.entries(themes.light || themes[Object.keys(themes)[0]]);\n const baseTypeString = `export type Theme = {\n${baseKeys.map(([k]) => {\n return ` ${JSON.stringify(k)}: string;\n`;\n }).join(\"\")}\n}`;\n let out = `${baseTypeString}\n`;\n out += `\nfunction t(a: [number, number][]) {\n let res: Record<string,string> = {}\n for (const [ki, vi] of a) {\n res[ks[ki] as string] = colors[vi] as string\n }\n return res as Theme\n}\n`;\n out += `export const colors = [\n`;\n let index = 0;\n const valueToIndex = {};\n dedupedTokens.forEach((name, value) => {\n valueToIndex[value] = index;\n index++;\n out += ` '${value}',\n`;\n });\n out += \"]\\n\\n\";\n const keys = baseKeys.map(([k]) => k);\n out += `const ks = [\n`;\n out += keys.map((k) => JSON.stringify(k)).join(\",\\n\");\n out += `]\n\n`;\n let nameI = 0;\n let themeTypes = `export type ThemeNames =`;\n let exported = `export type Themes = Record<ThemeNames, Theme>\n\nexport const themes: Themes = {`;\n dedupedThemes.forEach((theme) => {\n nameI++;\n const key = JSON.stringify(theme);\n const names = dedupedThemeToNames.get(key);\n const name = `n${nameI}`;\n const baseTheme = `const ${name} = ${objectToJsString(theme, keys, valueToIndex)}`;\n out += `\n${baseTheme}`;\n names.forEach((n) => {\n exported += `\n ${n}: ${name},`;\n if (n.toLowerCase() === n) {\n themeTypes += `\n | '${n}'`;\n }\n });\n });\n out += `\n\n${themeTypes}\n\n${exported}\n}\n`;\n return out;\n}\nfunction objectToJsString(obj, keys, valueToIndex) {\n let arrItems = [];\n for (const key in obj) {\n const ki = keys.indexOf(key);\n const vi = valueToIndex[obj[key]];\n arrItems.push(`[${ki}, ${vi}]`);\n }\n return `t([${arrItems.join(\",\")}])`;\n}\nfunction purgeCache(moduleName) {\n searchCache(moduleName, (mod) => {\n delete require.cache[mod.id];\n });\n const pathCache = ModuleInternals._pathCache;\n if (!pathCache) {\n return;\n }\n Object.keys(pathCache).forEach((cacheKey) => {\n if (cacheKey.indexOf(moduleName) > 0) {\n delete pathCache[cacheKey];\n }\n });\n}\nfunction searchCache(moduleName, callback) {\n let mod = require.resolve(moduleName);\n if (mod && (mod = require.cache[mod]) !== void 0) {\n ;\n (function traverse(mod2, depth = 0) {\n if (depth > 10) return;\n mod2.children.forEach((child) => {\n traverse(child, depth + 1);\n });\n callback(mod2);\n })(mod);\n }\n}\nexport {\n generateThemes\n};\n//# sourceMappingURL=generate-themes.js.map\n"],"mappings":";;;;;;;;;;;AAEA,MAAM,kBAAkB;AACxB,IAAI,kBAAkB;AACtB,eAAe,eAAe,WAAW;CACvC,MAAM,gBAAgB,UAAU,OAAO,MAAM,KAAK,QAAQ,IAAI,GAAG,SAAS,IAAI;CAC9E,IAAI,CAAC,iBAAiB;EACpB,kBAAkB;EAClB,MAAM,cAAc,gBAAgB;EACpC,UAAQ,4BAA4B,EAAE,SAAS,EAC7C,uBAAuB,MACzB,CAAC;EACD,MAAM,UAAU,gBAAgB;EAChC,gBAAgB,mBAAmB,SAAS,SAAS,GAAG,MAAM;GAC5D,IAAI,QAAQ,OAAO,OAAO,CAAC,QAAQ,WAAW,GAAG,GAAG;IAClD,IAAI;KACF,OAAO,YAAY,KAAK,MAAM,SAAS,GAAG,IAAI;IAChD,QAAQ,CACR;GACF;GACA,OAAO,QAAQ,KAA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