@tamagui/static 1.88.12 → 1.89.0-1706308641099

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/constants.mjs +10 -0
  3. package/dist/esm/extractor/accessSafe.mjs +11 -0
  4. package/dist/esm/extractor/babelParse.mjs +18 -0
  5. package/dist/esm/extractor/buildClassName.mjs +26 -0
  6. package/dist/esm/extractor/bundle.mjs +94 -0
  7. package/dist/esm/extractor/bundleConfig.mjs +263 -0
  8. package/dist/esm/extractor/createEvaluator.mjs +34 -0
  9. package/dist/esm/extractor/createExtractor.mjs +952 -0
  10. package/dist/esm/extractor/ensureImportingConcat.mjs +13 -0
  11. package/dist/esm/extractor/esbuildAliasPlugin.mjs +20 -0
  12. package/dist/esm/extractor/evaluateAstNode.mjs +48 -0
  13. package/dist/esm/extractor/extractHelpers.mjs +72 -0
  14. package/dist/esm/extractor/extractMediaStyle.mjs +93 -0
  15. package/dist/esm/extractor/extractToClassNames.mjs +237 -0
  16. package/dist/esm/extractor/findTopmostFunction.mjs +10 -0
  17. package/dist/esm/extractor/generateTamaguiStudioConfig.mjs +108 -0
  18. package/dist/esm/extractor/generatedUid.mjs +12 -0
  19. package/dist/esm/extractor/getPrefixLogs.mjs +4 -0
  20. package/dist/esm/extractor/getPropValueFromAttributes.mjs +31 -0
  21. package/dist/esm/extractor/getSourceModule.mjs +33 -0
  22. package/dist/esm/extractor/getStaticBindingsForScope.mjs +112 -0
  23. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +5 -0
  24. package/dist/esm/extractor/hoistClassNames.mjs +24 -0
  25. package/dist/esm/extractor/literalToAst.mjs +48 -0
  26. package/dist/esm/extractor/loadFile.mjs +11 -0
  27. package/dist/esm/extractor/loadTamagui.mjs +233 -0
  28. package/dist/esm/extractor/logLines.mjs +11 -0
  29. package/dist/esm/extractor/normalizeTernaries.mjs +33 -0
  30. package/dist/esm/extractor/propsToFontFamilyCache.mjs +12 -0
  31. package/dist/esm/extractor/removeUnusedHooks.mjs +41 -0
  32. package/dist/esm/extractor/timer.mjs +19 -0
  33. package/dist/esm/extractor/validHTMLAttributes.mjs +49 -0
  34. package/dist/esm/getPragmaOptions.mjs +19 -0
  35. package/dist/esm/helpers/memoize.mjs +13 -0
  36. package/dist/esm/helpers/requireTamaguiCore.mjs +5 -0
  37. package/dist/esm/index.mjs +3 -0
  38. package/dist/esm/minifyCSS.mjs +12 -0
  39. package/dist/esm/registerRequire.mjs +74 -0
  40. package/dist/esm/server.mjs +40 -0
  41. package/dist/esm/setup.mjs +1 -0
  42. package/dist/esm/static.mjs +10 -0
  43. package/dist/esm/types.mjs +0 -0
  44. package/dist/esm/webpackPlugin.mjs +7 -0
  45. package/package.json +15 -15
@@ -0,0 +1,33 @@
1
+ import * as t from "@babel/types";
2
+ function getSourceModule(itemName, itemBinding) {
3
+ if (!itemBinding.constant) return null;
4
+ let sourceModule,
5
+ imported,
6
+ local,
7
+ destructured,
8
+ usesImportSyntax = !1;
9
+ const itemNode = itemBinding.path.node;
10
+ if (
11
+ // import x from 'y';
12
+ t.isImportDefaultSpecifier(itemNode) ||
13
+ // import {x} from 'y';
14
+ t.isImportSpecifier(itemNode)) t.isImportDeclaration(itemBinding.path.parent) && (sourceModule = itemBinding.path.parent.source.value, local = itemNode.local.name, usesImportSyntax = !0, t.isImportSpecifier(itemNode) ? (imported = itemNode.imported.name, destructured = !0) : (imported = itemNode.local.name, destructured = !1));else if (t.isVariableDeclarator(itemNode) && itemNode.init != null && t.isCallExpression(itemNode.init) && t.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
15
+ const firstArg = itemNode.init.arguments[0];
16
+ if (!t.isStringLiteral(firstArg)) return null;
17
+ if (sourceModule = firstArg.value, t.isIdentifier(itemNode.id)) local = itemNode.id.name, imported = itemNode.id.name, destructured = !1;else if (t.isObjectPattern(itemNode.id)) {
18
+ for (const objProp of itemNode.id.properties) if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
19
+ local = objProp.value.name, imported = objProp.key.name, destructured = !0;
20
+ break;
21
+ }
22
+ if (!local || !imported) return console.error("could not find prop with value `%s`", itemName), null;
23
+ } else return console.error("Unhandled id type: %s", itemNode.id.type), null;
24
+ } else return null;
25
+ return {
26
+ destructured,
27
+ imported,
28
+ local,
29
+ sourceModule,
30
+ usesImportSyntax
31
+ };
32
+ }
33
+ export { getSourceModule };
@@ -0,0 +1,112 @@
1
+ import { fork } from "child_process";
2
+ import { dirname, extname, join, resolve } from "path";
3
+ import * as t from "@babel/types";
4
+ import { evaluateAstNode } from "./evaluateAstNode.mjs";
5
+ import { getSourceModule } from "./getSourceModule.mjs";
6
+ const isLocalImport = path => path.startsWith(".") || path.startsWith("/");
7
+ function resolveImportPath(sourcePath, path) {
8
+ const sourceDir = dirname(sourcePath);
9
+ return isLocalImport(path) ? (extname(path) === "" && (path += ".js"), resolve(sourceDir, path)) : path;
10
+ }
11
+ const cache = /* @__PURE__ */new Map(),
12
+ pending = /* @__PURE__ */new Map(),
13
+ loadCmd = `${join(__dirname, "loadFile.js")}`;
14
+ let exited = !1,
15
+ child = null;
16
+ function forkChild() {
17
+ child = fork(loadCmd, [], {
18
+ execArgv: ["-r", "esbuild-register"],
19
+ detached: !1,
20
+ stdio: "ignore"
21
+ });
22
+ }
23
+ function cleanupBeforeExit() {
24
+ exited || child && (child.removeAllListeners(), child.unref(), child.disconnect(), child.kill(), exited = !0);
25
+ }
26
+ process.once("SIGTERM", cleanupBeforeExit);
27
+ process.once("SIGINT", cleanupBeforeExit);
28
+ process.once("beforeExit", cleanupBeforeExit);
29
+ function importModule(path) {
30
+ if (child || forkChild(), pending.has(path)) return pending.get(path);
31
+ const promise = new Promise((res, rej) => {
32
+ if (!child) return;
33
+ if (cache.size > 2e3 && cache.clear(), cache.has(path)) return cache.get(path);
34
+ const listener = msg => {
35
+ if (!child || !msg || typeof msg != "string") return;
36
+ if (msg[0] === "-") {
37
+ rej(new Error(msg.slice(1)));
38
+ return;
39
+ }
40
+ child.removeListener("message", listener);
41
+ const val = JSON.parse(msg);
42
+ cache.set(path, val), res(val);
43
+ };
44
+ child.once("message", listener), child.send(`${path.replace(".js", "")}`);
45
+ });
46
+ return pending.set(path, promise), promise;
47
+ }
48
+ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
49
+ const bindings = scope.getAllBindings(),
50
+ ret = {},
51
+ program = scope.getProgramParent().block;
52
+ for (const node of program.body) if (t.isImportDeclaration(node)) {
53
+ const importPath = node.source.value;
54
+ if (!node.specifiers.length || !isLocalImport(importPath)) continue;
55
+ const moduleName = resolveImportPath(sourcePath, importPath);
56
+ if (!whitelist.some(test => moduleName.endsWith(test))) continue;
57
+ try {
58
+ const src = await importModule(moduleName);
59
+ if (!src) continue;
60
+ for (const specifier of node.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && typeof src[specifier.imported.name] < "u") {
61
+ const val = src[specifier.local.name];
62
+ ret[specifier.local.name] = val;
63
+ }
64
+ } catch (err) {
65
+ shouldPrintDebug ? console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=tamagui for more)`) : process.env.DEBUG?.startsWith("tamagui") && console.info("Error in partial evaluation", err.message, err.stack);
66
+ }
67
+ }
68
+ if (!bindingCache) throw new Error("BindingCache is a required param");
69
+ for (const k in bindings) {
70
+ const binding = bindings[k],
71
+ sourceModule = getSourceModule(k, binding);
72
+ if (sourceModule) {
73
+ if (!sourceModule.sourceModule) continue;
74
+ const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
75
+ if (whitelist.some(test => moduleName.endsWith(test))) {
76
+ const src = importModule(moduleName);
77
+ if (!src) return console.info(` | \u26A0\uFE0F Missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`), {};
78
+ sourceModule.destructured ? sourceModule.imported && (ret[k] = src[sourceModule.imported]) : ret[k] = src;
79
+ }
80
+ continue;
81
+ }
82
+ const {
83
+ parent
84
+ } = binding.path;
85
+ if (!t.isVariableDeclaration(parent) || parent.kind !== "const") continue;
86
+ const dec = parent.declarations.find(d => t.isIdentifier(d.id) && d.id.name === k);
87
+ if (!dec || !dec.init) continue;
88
+ if (typeof dec.id.start != "number" || typeof dec.id.end != "number") {
89
+ console.error("dec.id.start/end is not a number");
90
+ continue;
91
+ }
92
+ if (!t.isIdentifier(dec.id)) {
93
+ console.error("dec is not an identifier");
94
+ continue;
95
+ }
96
+ const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
97
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
98
+ ret[k] = bindingCache[cacheKey];
99
+ continue;
100
+ }
101
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
102
+ ret[k] = bindingCache[cacheKey];
103
+ continue;
104
+ }
105
+ try {
106
+ ret[k] = evaluateAstNode(dec.init, void 0, shouldPrintDebug), bindingCache[cacheKey] = ret[k];
107
+ continue;
108
+ } catch {}
109
+ }
110
+ return ret;
111
+ }
112
+ export { cleanupBeforeExit, getStaticBindingsForScope };
@@ -0,0 +1,5 @@
1
+ import { isAbsolute, join } from "path";
2
+ function getTamaguiConfigPathFromOptionsConfig(config) {
3
+ return isAbsolute(config) ? config : join(process.cwd(), config);
4
+ }
5
+ export { getTamaguiConfigPathFromOptionsConfig };
@@ -0,0 +1,24 @@
1
+ import * as t from "@babel/types";
2
+ function hoistClassNames(path, existing, expr) {
3
+ const hoist = hoistClassNames.bind(null, path, existing);
4
+ if (t.isStringLiteral(expr)) {
5
+ if (expr.value.trim() === "") return expr;
6
+ if (existing[expr.value]) return existing[expr.value];
7
+ const identifier = replaceStringWithVariable(expr);
8
+ return existing[expr.value] = identifier, identifier;
9
+ }
10
+ if (t.isBinaryExpression(expr)) return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
11
+ if (t.isLogicalExpression(expr)) return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
12
+ if (t.isConditionalExpression(expr)) return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
13
+ return expr;
14
+ function replaceStringWithVariable(str) {
15
+ const uid = path.scope.generateUidIdentifier("cn"),
16
+ parent = path.findParent(path2 => path2.isProgram());
17
+ if (!parent) throw new Error("no program?");
18
+ const variable = t.variableDeclaration("const", [
19
+ // adding a space for extra safety
20
+ t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))]);
21
+ return parent.unshiftContainer("body", variable), uid;
22
+ }
23
+ }
24
+ export { hoistClassNames };
@@ -0,0 +1,48 @@
1
+ import * as t from "@babel/types";
2
+ function literalToAst(literal) {
3
+ if (literal === null) return t.nullLiteral();
4
+ switch (typeof literal) {
5
+ case "function":
6
+ throw new Error("Unsupported");
7
+ case "number":
8
+ return t.numericLiteral(literal);
9
+ case "string":
10
+ return t.stringLiteral(literal);
11
+ case "boolean":
12
+ return t.booleanLiteral(literal);
13
+ case "undefined":
14
+ return t.unaryExpression("void", t.numericLiteral(0), !0);
15
+ default:
16
+ return Array.isArray(literal) ? t.arrayExpression(literal.map(literalToAst)) : t.objectExpression(Object.keys(literal).filter(k => typeof literal[k] < "u").map(k => t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))));
17
+ }
18
+ }
19
+ const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
20
+ function astToLiteral(node) {
21
+ if (node) {
22
+ if (easyPeasies.includes(node.type)) return node.value;
23
+ if (!(node.name === "undefined" && !node.value)) {
24
+ if (t.isNullLiteral(node)) return null;
25
+ if (t.isObjectExpression(node)) return computeProps(node.properties);
26
+ if (t.isArrayExpression(node)) return node.elements.reduce(
27
+ // @ts-ignore
28
+ (acc, element) => [...acc, ...(element?.type === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)])], []);
29
+ }
30
+ }
31
+ }
32
+ function computeProps(props) {
33
+ return props.reduce((acc, prop) => {
34
+ if (prop.type === "SpreadElement") return {
35
+ ...acc,
36
+ ...astToLiteral(prop.argument)
37
+ };
38
+ if (prop.type !== "ObjectMethod") {
39
+ const val = astToLiteral(prop.value);
40
+ if (val !== void 0) return {
41
+ ...acc,
42
+ [prop.key.name]: val
43
+ };
44
+ }
45
+ return acc;
46
+ }, {});
47
+ }
48
+ export { astToLiteral, literalToAst };
@@ -0,0 +1,11 @@
1
+ process.on("message", path => {
2
+ if (typeof path != "string") throw new Error(`Not a string: ${path}`);
3
+ try {
4
+ const out = require(path);
5
+ process.send?.(JSON.stringify(out));
6
+ } catch (err) {
7
+ err instanceof Error ? process.send?.(`-${err.message}
8
+ ${err.stack}`) : process.send?.(`-${err}`);
9
+ }
10
+ });
11
+ setInterval(() => {}, 1e3);
@@ -0,0 +1,233 @@
1
+ import { writeFileSync } from "fs";
2
+ import { basename, dirname, extname, join, relative, resolve } from "path";
3
+ import { Color, colorLog } from "@tamagui/cli-color";
4
+ import { getDefaultTamaguiConfig } from "@tamagui/config-default";
5
+ import esbuild from "esbuild";
6
+ import { existsSync, pathExists, readJSON, writeFile } from "fs-extra";
7
+ import { SHOULD_DEBUG } from "../constants.mjs";
8
+ import { requireTamaguiCore } from "../helpers/requireTamaguiCore.mjs";
9
+ import { minifyCSS } from "../minifyCSS.mjs";
10
+ import { getNameToPaths, registerRequire } from "../registerRequire.mjs";
11
+ import { TamaguiProjectInfo, getBundledConfig, hasBundledConfigChanged, loadComponents } from "./bundleConfig.mjs";
12
+ import { generateTamaguiStudioConfig, generateTamaguiStudioConfigSync, generateTamaguiThemes } from "./generateTamaguiStudioConfig.mjs";
13
+ import { getTamaguiConfigPathFromOptionsConfig } from "./getTamaguiConfigPathFromOptionsConfig.mjs";
14
+ const getFilledOptions = propsIn => ({
15
+ // defaults
16
+ platform: "web",
17
+ config: "tamagui.config.ts",
18
+ components: ["tamagui"],
19
+ ...propsIn
20
+ });
21
+ async function loadTamagui(propsIn) {
22
+ const props = getFilledOptions(propsIn),
23
+ bundleInfo = await getBundledConfig(props);
24
+ if (!bundleInfo) return console.warn("No bundled config generated, maybe an error in bundling. Set DEBUG=tamagui and re-run to get logs."), null;
25
+ if (await generateThemesAndLog(props, !0), !hasBundledConfigChanged()) return bundleInfo;
26
+ if (bundleInfo) {
27
+ const {
28
+ createTamagui
29
+ } = requireTamaguiCore(props.platform),
30
+ config = createTamagui(bundleInfo.tamaguiConfig);
31
+ if (props.outputCSS) {
32
+ colorLog(Color.FgYellow, ` \u27A1 [tamagui] output css: ${props.outputCSS}
33
+ `);
34
+ const css = props.disableMinifyCSS === !1 ? minifyCSS(config.getCSS()).code : config.getCSS();
35
+ await writeFile(props.outputCSS, css);
36
+ }
37
+ }
38
+ return process.env.NODE_ENV === "development" && (await generateTamaguiStudioConfig(props, bundleInfo)), bundleInfo;
39
+ }
40
+ let waiting = !1,
41
+ hasLoggedOnce = !1;
42
+ const generateThemesAndLog = async (options, force = !1) => {
43
+ if (!waiting && options.themeBuilder) try {
44
+ waiting = !0, await new Promise(res => setTimeout(res, 30));
45
+ const didGenerate = await generateTamaguiThemes(options, force);
46
+ !hasLoggedOnce && didGenerate && (hasLoggedOnce = !0, colorLog(Color.FgYellow, `
47
+ \u27A1 [tamagui] generated themes: ${relative(process.cwd(), options.themeBuilder.output)}`));
48
+ } finally {
49
+ waiting = !1;
50
+ }
51
+ },
52
+ last = {},
53
+ lastVersion = {};
54
+ function loadTamaguiSync({
55
+ forceExports,
56
+ cacheKey,
57
+ ...propsIn
58
+ }) {
59
+ const key = JSON.stringify(propsIn);
60
+ if (last[key] && !hasBundledConfigChanged() && (!lastVersion[key] || lastVersion[key] === cacheKey)) return last[key];
61
+ lastVersion[key] = cacheKey || "";
62
+ const props = getFilledOptions(propsIn);
63
+ process.env.IS_STATIC = "is_static", process.env.TAMAGUI_IS_SERVER = "true";
64
+ const {
65
+ unregister
66
+ } = registerRequire(props.platform, {
67
+ proxyWormImports: !!forceExports
68
+ });
69
+ try {
70
+ const devValueOG = globalThis.__DEV__;
71
+ globalThis.__DEV__ = process.env.NODE_ENV === "development";
72
+ try {
73
+ let tamaguiConfig = null;
74
+ if (propsIn.config) {
75
+ const configPath = getTamaguiConfigPathFromOptionsConfig(propsIn.config),
76
+ exp = require(configPath);
77
+ if (tamaguiConfig = exp.default || exp.config || exp, !tamaguiConfig || !tamaguiConfig.parsed) {
78
+ const confPath = require.resolve(configPath);
79
+ throw new Error(`Can't find valid config in ${confPath}:
80
+
81
+ Be sure you "export default" or "export const config" the config.`);
82
+ }
83
+ if (tamaguiConfig) {
84
+ const {
85
+ createTamagui
86
+ } = requireTamaguiCore(props.platform);
87
+ createTamagui(tamaguiConfig);
88
+ }
89
+ }
90
+ const components = loadComponents(props, forceExports);
91
+ if (!components) throw new Error("No components loaded");
92
+ process.env.DEBUG === "tamagui" && console.info("components", components), process.env.IS_STATIC = void 0, globalThis.__DEV__ = devValueOG;
93
+ const info = {
94
+ components,
95
+ tamaguiConfig,
96
+ nameToPaths: getNameToPaths()
97
+ };
98
+ if (tamaguiConfig) {
99
+ if (props.outputCSS) {
100
+ colorLog(Color.FgYellow, ` \u27A1 [tamagui] output css: ${props.outputCSS}
101
+ `);
102
+ const css = props.disableMinifyCSS === !1 ? minifyCSS(tamaguiConfig.getCSS()).code : tamaguiConfig.getCSS();
103
+ writeFileSync(props.outputCSS, css);
104
+ }
105
+ generateTamaguiStudioConfigSync(props, info);
106
+ }
107
+ return last[key] = {
108
+ ...info,
109
+ cached: !0
110
+ }, info;
111
+ } catch (err) {
112
+ err instanceof Error ? !SHOULD_DEBUG && !forceExports ? (console.warn("Error loading tamagui.config.ts (set DEBUG=tamagui to see full stack), running tamagui without custom config"), console.info(`
113
+
114
+ ${err.message}
115
+
116
+ `)) : SHOULD_DEBUG && console.error(err) : console.error("Error loading tamagui.config.ts", err);
117
+ const {
118
+ createTamagui
119
+ } = requireTamaguiCore(props.platform);
120
+ return {
121
+ components: [],
122
+ tamaguiConfig: createTamagui(getDefaultTamaguiConfig()),
123
+ nameToPaths: {}
124
+ };
125
+ }
126
+ } finally {
127
+ unregister();
128
+ }
129
+ }
130
+ async function getOptions({
131
+ root = process.cwd(),
132
+ tsconfigPath = "tsconfig.json",
133
+ tamaguiOptions,
134
+ host,
135
+ debug
136
+ } = {}) {
137
+ const dotDir = join(root, ".tamagui");
138
+ let pkgJson = {};
139
+ try {
140
+ pkgJson = await readJSON(join(root, "package.json"));
141
+ } catch {}
142
+ return {
143
+ mode: process.env.NODE_ENV === "production" ? "production" : "development",
144
+ root,
145
+ host: host || "127.0.0.1",
146
+ pkgJson,
147
+ debug,
148
+ tsconfigPath,
149
+ tamaguiOptions: {
150
+ platform: "web",
151
+ components: ["tamagui"],
152
+ ...tamaguiOptions,
153
+ config: await getDefaultTamaguiConfigPath(root, tamaguiOptions?.config)
154
+ },
155
+ paths: {
156
+ dotDir,
157
+ conf: join(dotDir, "tamagui.config.json"),
158
+ types: join(dotDir, "types.json")
159
+ }
160
+ };
161
+ }
162
+ function resolveWebOrNativeSpecificEntry(entry) {
163
+ const workspaceRoot = resolve(),
164
+ resolved = require.resolve(entry, {
165
+ paths: [workspaceRoot]
166
+ }),
167
+ ext = extname(resolved),
168
+ fileName = basename(resolved).replace(ext, ""),
169
+ specificFile = join(dirname(resolved), fileName + "." + "web" + ext);
170
+ return existsSync(specificFile) ? specificFile : entry;
171
+ }
172
+ const defaultPaths = ["tamagui.config.ts", join("src", "tamagui.config.ts")];
173
+ let hasWarnedOnce = !1;
174
+ async function getDefaultTamaguiConfigPath(root, configPath) {
175
+ const searchPaths = [...new Set([configPath, ...defaultPaths].filter(Boolean).map(p => join(root, p)))];
176
+ for (const path of searchPaths) if (await pathExists(path)) return path;
177
+ hasWarnedOnce || (hasWarnedOnce = !0, console.warn(`Warning: couldn't find tamagui.config.ts in the following paths given configuration "${configPath}":
178
+ ${searchPaths.join(`
179
+ `)}
180
+ `));
181
+ }
182
+ async function watchTamaguiConfig(tamaguiOptions) {
183
+ const options = await getOptions({
184
+ tamaguiOptions
185
+ });
186
+ if (!options.tamaguiOptions.config) throw new Error("No config");
187
+ if (process.env.NODE_ENV === "production") return {
188
+ dispose() {}
189
+ };
190
+ const disposeConfigWatcher = await esbuildWatchFiles(options.tamaguiOptions.config, () => {
191
+ generateTamaguiStudioConfig(options.tamaguiOptions, null, !0);
192
+ }),
193
+ themeBuilderInput = options.tamaguiOptions.themeBuilder?.input;
194
+ let disposeThemesWatcher;
195
+ if (themeBuilderInput) {
196
+ let inputPath = themeBuilderInput;
197
+ try {
198
+ inputPath = require.resolve(themeBuilderInput);
199
+ } catch {}
200
+ disposeThemesWatcher = await esbuildWatchFiles(inputPath, () => {
201
+ generateThemesAndLog(options.tamaguiOptions);
202
+ });
203
+ }
204
+ return {
205
+ dispose() {
206
+ disposeConfigWatcher(), disposeThemesWatcher?.();
207
+ }
208
+ };
209
+ }
210
+ async function esbuildWatchFiles(entry, onChanged) {
211
+ let hasRunOnce = !1;
212
+ const context = await esbuild.context({
213
+ bundle: !0,
214
+ entryPoints: [entry],
215
+ resolveExtensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
216
+ logLevel: "silent",
217
+ write: !1,
218
+ plugins: [{
219
+ name: "on-rebuild",
220
+ setup({
221
+ onEnd
222
+ }) {
223
+ onEnd(() => {
224
+ hasRunOnce ? onChanged() : hasRunOnce = !0;
225
+ });
226
+ }
227
+ }]
228
+ });
229
+ return context.watch(), () => {
230
+ context.dispose();
231
+ };
232
+ }
233
+ export { TamaguiProjectInfo, getOptions, loadTamagui, loadTamaguiSync, resolveWebOrNativeSpecificEntry, watchTamaguiConfig };
@@ -0,0 +1,11 @@
1
+ const prefix = " ",
2
+ logLines = (str, singleLine = !1) => {
3
+ if (singleLine) return prefix + str.split(" ").join(`
4
+ ${prefix}`);
5
+ const lines = [""],
6
+ items = str.split(" ");
7
+ for (const item of items) item.length + lines[lines.length - 1].length > 85 && lines.push(""), lines[lines.length - 1] += item + " ";
8
+ return lines.map((line, i) => prefix + (i == 0 ? "" : " ") + line.trim()).join(`
9
+ `);
10
+ };
11
+ export { logLines };
@@ -0,0 +1,33 @@
1
+ import generate from "@babel/generator";
2
+ import * as t from "@babel/types";
3
+ import invariant from "invariant";
4
+ function normalizeTernaries(ternaries) {
5
+ if (invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries"), ternaries.length === 0) return [];
6
+ const ternariesByKey = {};
7
+ for (let idx = -1, len = ternaries.length; ++idx < len;) {
8
+ const {
9
+ test,
10
+ consequent,
11
+ alternate,
12
+ remove,
13
+ ...rest
14
+ } = ternaries[idx];
15
+ let ternaryTest = test;
16
+ t.isExpressionStatement(test) && (ternaryTest = test.expression);
17
+ let shouldSwap = !1;
18
+ t.isUnaryExpression(test) && test.operator === "!" ? (ternaryTest = test.argument, shouldSwap = !0) : t.isBinaryExpression(test) && (test.operator === "!==" || test.operator === "!=") && (ternaryTest = t.binaryExpression(test.operator.replace("!", "="), test.left, test.right), shouldSwap = !0);
19
+ const key = generate(ternaryTest).code;
20
+ ternariesByKey[key] || (ternariesByKey[key] = {
21
+ ...rest,
22
+ alternate: {},
23
+ consequent: {},
24
+ test: ternaryTest,
25
+ remove
26
+ });
27
+ const altStyle = (shouldSwap ? consequent : alternate) ?? {},
28
+ consStyle = (shouldSwap ? alternate : consequent) ?? {};
29
+ Object.assign(ternariesByKey[key].alternate, altStyle), Object.assign(ternariesByKey[key].consequent, consStyle);
30
+ }
31
+ return Object.keys(ternariesByKey).map(key => ternariesByKey[key]);
32
+ }
33
+ export { normalizeTernaries };
@@ -0,0 +1,12 @@
1
+ const cache = /* @__PURE__ */new WeakMap();
2
+ function setPropsToFontFamily(props, ff) {
3
+ cache.set(props, ff);
4
+ }
5
+ function getPropsToFontFamily(props) {
6
+ return cache.get(props);
7
+ }
8
+ function getFontFamilyClassNameFromProps(props) {
9
+ const ff = getPropsToFontFamily(props);
10
+ if (ff) return ` font_${ff.replace("$", "")}`;
11
+ }
12
+ export { getFontFamilyClassNameFromProps, getPropsToFontFamily, setPropsToFontFamily };
@@ -0,0 +1,41 @@
1
+ import * as t from "@babel/types";
2
+ const hooks = {
3
+ useMedia: !0,
4
+ useTheme: !0
5
+ };
6
+ function removeUnusedHooks(compFn, shouldPrintDebug) {
7
+ compFn.scope.crawl();
8
+ let bodyStatements = compFn?.get("body");
9
+ if (!bodyStatements) {
10
+ console.info("no body statemnts?", compFn);
11
+ return;
12
+ }
13
+ if (Array.isArray(bodyStatements) || (bodyStatements.isFunctionExpression() ? bodyStatements = bodyStatements.scope.path.get("body") : bodyStatements = bodyStatements.get("body")), !bodyStatements || !Array.isArray(bodyStatements)) return;
14
+ const statements = bodyStatements;
15
+ for (const statement of statements) {
16
+ if (!statement.isVariableDeclaration()) continue;
17
+ const declarations = statement.get("declarations");
18
+ if (!Array.isArray(declarations)) continue;
19
+ const isBindingReferenced = name => !!statement.scope.getBinding(name)?.referenced;
20
+ for (const declarator of declarations) {
21
+ const id = declarator.get("id"),
22
+ init = declarator.node.init;
23
+ if (Array.isArray(id) || Array.isArray(init)) continue;
24
+ (() => {
25
+ if (!(init && t.isCallExpression(init) && t.isIdentifier(init.callee) && hooks[init.callee.name])) return !1;
26
+ if (t.isIdentifier(id.node)) {
27
+ const name = id.node.name;
28
+ return !isBindingReferenced(name);
29
+ }
30
+ return t.isObjectPattern(id.node) ? id.get("properties").every(prop => {
31
+ if (!prop.isObjectProperty()) return !1;
32
+ const value = prop.get("value");
33
+ if (Array.isArray(value) || !value.isIdentifier()) return !1;
34
+ const name = value.node.name;
35
+ return !isBindingReferenced(name);
36
+ }) : !1;
37
+ })() && (declarator.remove(), shouldPrintDebug && console.info(` [\u{1FA9D}] removed ${id.node.name ?? ""}`));
38
+ }
39
+ }
40
+ }
41
+ export { removeUnusedHooks };
@@ -0,0 +1,19 @@
1
+ const timer = () => {
2
+ const start = Date.now();
3
+ let last = start;
4
+ return {
5
+ mark: (name, print = !1) => {
6
+ if (print) {
7
+ const took = Date.now() - last;
8
+ last = Date.now(), console.info(`Time ${name}: ${took}ms`), took > 10 && console.info(" long timer");
9
+ }
10
+ },
11
+ done: (print = !1) => {
12
+ if (print) {
13
+ const total = Date.now() - start;
14
+ console.info(`Total time: ${total}ms`), total > 50 && console.info(" long timer");
15
+ }
16
+ }
17
+ };
18
+ };
19
+ export { timer };
@@ -0,0 +1,49 @@
1
+ const validHTMLAttributes = {
2
+ autocomplete: !0,
3
+ border: !0,
4
+ contenteditable: !0,
5
+ crossorigin: !0,
6
+ dir: !0,
7
+ draggable: !0,
8
+ enctype: !0,
9
+ formenctype: !0,
10
+ formmethod: !0,
11
+ formtarget: !0,
12
+ inputmode: !0,
13
+ kind: !0,
14
+ link: !0,
15
+ method: !0,
16
+ preload: !0,
17
+ referrerpolicy: !0,
18
+ rel: !0,
19
+ rev: !0,
20
+ role: !0,
21
+ sandbox: !0,
22
+ shape: !0,
23
+ spellcheck: !0,
24
+ target: !0,
25
+ translate: !0,
26
+ type: !0,
27
+ wrap: !0,
28
+ "aria-autocomplete": !0,
29
+ "aria-busy": !0,
30
+ "aria-checked": !0,
31
+ "aria-current": !0,
32
+ "aria-disabled": !0,
33
+ "aria-expanded": !0,
34
+ "aria-haspopup": !0,
35
+ "aria-hidden": !0,
36
+ "aria-invalid": !0,
37
+ "aria-polite": !0,
38
+ "aria-modal": !0,
39
+ "aria-multiline": !0,
40
+ "aria-multiselectable": !0,
41
+ "aria-orientation": !0,
42
+ "aria-pressed": !0,
43
+ "aria-readonly": !0,
44
+ "aria-relevant": !0,
45
+ "aria-required": !0,
46
+ "aria-selected": !0,
47
+ "aria-sort": !0
48
+ };
49
+ export { validHTMLAttributes };
@@ -0,0 +1,19 @@
1
+ function getPragmaOptions({
2
+ source,
3
+ path,
4
+ disableCommentCheck
5
+ }) {
6
+ if (!disableCommentCheck && !source.startsWith("//") && !source.startsWith("/*")) return {
7
+ shouldPrintDebug: !1,
8
+ shouldDisable: !1
9
+ };
10
+ let shouldPrintDebug = !1,
11
+ shouldDisable = !1;
12
+ const firstLine = source.slice(0, 800).split(`
13
+ `)[0];
14
+ return firstLine.includes("tamagui-ignore") && (shouldDisable = !0), firstLine.includes("debug") && (shouldPrintDebug = !0), firstLine.includes("debug-verbose") && (shouldPrintDebug = "verbose"), process.env.TAMAGUI_DEBUG_FILE && path.includes(process.env.TAMAGUI_DEBUG_FILE) && (shouldPrintDebug = "verbose"), process.env.DEBUG?.includes("tamagui") && (shouldPrintDebug ||= !0), process.env.DEBUG?.includes("tamagui-verbose") && (shouldPrintDebug = "verbose"), {
15
+ shouldPrintDebug,
16
+ shouldDisable
17
+ };
18
+ }
19
+ export { getPragmaOptions };
@@ -0,0 +1,13 @@
1
+ function memoize(func, resolver) {
2
+ if (typeof func != "function" || resolver != null && typeof resolver != "function") throw new TypeError("Expected a function");
3
+ const memoized = function (...args) {
4
+ const key = resolver ? resolver.apply(this, args) : args[0],
5
+ cache = memoized.cache;
6
+ if (cache.has(key)) return cache.get(key);
7
+ const result = func.apply(this, args);
8
+ return memoized.cache = cache.set(key, result) || cache, result;
9
+ };
10
+ return memoized.cache = new (memoize.Cache || Map)(), memoized;
11
+ }
12
+ memoize.Cache = Map;
13
+ export { memoize };