@tamagui/static 1.88.12 → 1.88.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/extractor/createExtractor.js.map +1 -1
  3. package/dist/cjs/extractor/createExtractor.native.js.map +1 -1
  4. package/dist/cjs/extractor/extractMediaStyle.js.map +1 -1
  5. package/dist/cjs/extractor/extractMediaStyle.native.js.map +1 -1
  6. package/dist/cjs/extractor/generateTamaguiStudioConfig.js.map +1 -1
  7. package/dist/cjs/extractor/generateTamaguiStudioConfig.native.js.map +1 -1
  8. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -1
  9. package/dist/cjs/extractor/getStaticBindingsForScope.native.js.map +1 -1
  10. package/dist/esm/constants.mjs +10 -0
  11. package/dist/esm/extractor/accessSafe.mjs +11 -0
  12. package/dist/esm/extractor/babelParse.mjs +18 -0
  13. package/dist/esm/extractor/buildClassName.mjs +26 -0
  14. package/dist/esm/extractor/bundle.mjs +94 -0
  15. package/dist/esm/extractor/bundleConfig.mjs +263 -0
  16. package/dist/esm/extractor/createEvaluator.mjs +34 -0
  17. package/dist/esm/extractor/createExtractor.js.map +1 -1
  18. package/dist/esm/extractor/createExtractor.mjs +952 -0
  19. package/dist/esm/extractor/createExtractor.native.js.map +1 -1
  20. package/dist/esm/extractor/ensureImportingConcat.mjs +13 -0
  21. package/dist/esm/extractor/esbuildAliasPlugin.mjs +20 -0
  22. package/dist/esm/extractor/evaluateAstNode.mjs +48 -0
  23. package/dist/esm/extractor/extractHelpers.mjs +72 -0
  24. package/dist/esm/extractor/extractMediaStyle.js.map +1 -1
  25. package/dist/esm/extractor/extractMediaStyle.mjs +93 -0
  26. package/dist/esm/extractor/extractMediaStyle.native.js.map +1 -1
  27. package/dist/esm/extractor/extractToClassNames.mjs +237 -0
  28. package/dist/esm/extractor/findTopmostFunction.mjs +10 -0
  29. package/dist/esm/extractor/generateTamaguiStudioConfig.js.map +1 -1
  30. package/dist/esm/extractor/generateTamaguiStudioConfig.mjs +108 -0
  31. package/dist/esm/extractor/generateTamaguiStudioConfig.native.js.map +1 -1
  32. package/dist/esm/extractor/generatedUid.mjs +12 -0
  33. package/dist/esm/extractor/getPrefixLogs.mjs +4 -0
  34. package/dist/esm/extractor/getPropValueFromAttributes.mjs +31 -0
  35. package/dist/esm/extractor/getSourceModule.mjs +33 -0
  36. package/dist/esm/extractor/getStaticBindingsForScope.js.map +1 -1
  37. package/dist/esm/extractor/getStaticBindingsForScope.mjs +112 -0
  38. package/dist/esm/extractor/getStaticBindingsForScope.native.js.map +1 -1
  39. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +5 -0
  40. package/dist/esm/extractor/hoistClassNames.mjs +24 -0
  41. package/dist/esm/extractor/literalToAst.mjs +48 -0
  42. package/dist/esm/extractor/loadFile.mjs +11 -0
  43. package/dist/esm/extractor/loadTamagui.mjs +233 -0
  44. package/dist/esm/extractor/logLines.mjs +11 -0
  45. package/dist/esm/extractor/normalizeTernaries.mjs +33 -0
  46. package/dist/esm/extractor/propsToFontFamilyCache.mjs +12 -0
  47. package/dist/esm/extractor/removeUnusedHooks.mjs +41 -0
  48. package/dist/esm/extractor/timer.mjs +19 -0
  49. package/dist/esm/extractor/validHTMLAttributes.mjs +49 -0
  50. package/dist/esm/getPragmaOptions.mjs +19 -0
  51. package/dist/esm/helpers/memoize.mjs +13 -0
  52. package/dist/esm/helpers/requireTamaguiCore.mjs +5 -0
  53. package/dist/esm/index.mjs +3 -0
  54. package/dist/esm/minifyCSS.mjs +12 -0
  55. package/dist/esm/registerRequire.mjs +74 -0
  56. package/dist/esm/server.mjs +40 -0
  57. package/dist/esm/setup.mjs +1 -0
  58. package/dist/esm/static.mjs +10 -0
  59. package/dist/esm/types.mjs +0 -0
  60. package/dist/esm/webpackPlugin.mjs +7 -0
  61. package/package.json +15 -15
  62. package/src/extractor/babelParse.ts +1 -1
  63. package/src/extractor/bundle.ts +1 -1
  64. package/src/extractor/bundleConfig.ts +1 -1
  65. package/src/extractor/createEvaluator.ts +2 -2
  66. package/src/extractor/createExtractor.ts +3 -2
  67. package/src/extractor/ensureImportingConcat.ts +1 -1
  68. package/src/extractor/extractMediaStyle.ts +3 -2
  69. package/src/extractor/extractToClassNames.ts +1 -1
  70. package/src/extractor/findTopmostFunction.ts +2 -2
  71. package/src/extractor/generateTamaguiStudioConfig.ts +4 -3
  72. package/src/extractor/getPrefixLogs.ts +1 -1
  73. package/src/extractor/getStaticBindingsForScope.ts +3 -2
  74. package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +1 -1
  75. package/src/extractor/hoistClassNames.ts +1 -1
  76. package/src/extractor/loadTamagui.ts +1 -1
  77. package/src/extractor/normalizeTernaries.ts +1 -1
  78. package/src/extractor/removeUnusedHooks.ts +1 -1
  79. package/src/helpers/requireTamaguiCore.ts +1 -1
  80. package/src/registerRequire.ts +1 -1
  81. package/src/server.ts +1 -1
  82. package/src/types.ts +2 -2
  83. package/types/extractor/babelParse.d.ts +1 -1
  84. package/types/extractor/babelParse.d.ts.map +1 -1
  85. package/types/extractor/bundle.d.ts +1 -1
  86. package/types/extractor/bundle.d.ts.map +1 -1
  87. package/types/extractor/bundleConfig.d.ts +1 -1
  88. package/types/extractor/bundleConfig.d.ts.map +1 -1
  89. package/types/extractor/createEvaluator.d.ts +2 -2
  90. package/types/extractor/createEvaluator.d.ts.map +1 -1
  91. package/types/extractor/createExtractor.d.ts +2 -2
  92. package/types/extractor/createExtractor.d.ts.map +1 -1
  93. package/types/extractor/ensureImportingConcat.d.ts +1 -1
  94. package/types/extractor/ensureImportingConcat.d.ts.map +1 -1
  95. package/types/extractor/extractMediaStyle.d.ts +2 -2
  96. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  97. package/types/extractor/extractToClassNames.d.ts +1 -1
  98. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  99. package/types/extractor/findTopmostFunction.d.ts +2 -2
  100. package/types/extractor/findTopmostFunction.d.ts.map +1 -1
  101. package/types/extractor/generateTamaguiStudioConfig.d.ts +2 -2
  102. package/types/extractor/generateTamaguiStudioConfig.d.ts.map +1 -1
  103. package/types/extractor/getPrefixLogs.d.ts +1 -1
  104. package/types/extractor/getPrefixLogs.d.ts.map +1 -1
  105. package/types/extractor/getStaticBindingsForScope.d.ts +1 -1
  106. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -1
  107. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts +1 -1
  108. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts.map +1 -1
  109. package/types/extractor/hoistClassNames.d.ts +1 -1
  110. package/types/extractor/hoistClassNames.d.ts.map +1 -1
  111. package/types/extractor/loadTamagui.d.ts +1 -1
  112. package/types/extractor/loadTamagui.d.ts.map +1 -1
  113. package/types/extractor/normalizeTernaries.d.ts +1 -1
  114. package/types/extractor/normalizeTernaries.d.ts.map +1 -1
  115. package/types/extractor/removeUnusedHooks.d.ts +1 -1
  116. package/types/extractor/removeUnusedHooks.d.ts.map +1 -1
  117. package/types/helpers/requireTamaguiCore.d.ts +1 -1
  118. package/types/helpers/requireTamaguiCore.d.ts.map +1 -1
  119. package/types/registerRequire.d.ts +1 -1
  120. package/types/registerRequire.d.ts.map +1 -1
  121. package/types/server.d.ts +1 -1
  122. package/types/server.d.ts.map +1 -1
  123. package/types/types.d.ts +2 -2
  124. package/types/types.d.ts.map +1 -1
@@ -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 };
@@ -0,0 +1,5 @@
1
+ function requireTamaguiCore(platform, ogRequire = require) {
2
+ if (!platform) throw new Error("No platform given to requireTamaguiCore");
3
+ return ogRequire(platform === "native" ? "@tamagui/core/native" : "@tamagui/core");
4
+ }
5
+ export { requireTamaguiCore };
@@ -0,0 +1,3 @@
1
+ import "./setup.mjs";
2
+ export * from "./static.mjs";
3
+ export * from "./minifyCSS.mjs";
@@ -0,0 +1,12 @@
1
+ import browserslist from "browserslist";
2
+ import { browserslistToTargets, transform } from "lightningcss";
3
+ function minifyCSS(input) {
4
+ return transform({
5
+ filename: "style.css",
6
+ code: Buffer.from(input),
7
+ minify: !0,
8
+ targets: browserslistToTargets(browserslist(">= 0.5%")),
9
+ sourceMap: !0
10
+ });
11
+ }
12
+ export { minifyCSS };
@@ -0,0 +1,74 @@
1
+ import { register } from "esbuild-register/dist/node";
2
+ import { requireTamaguiCore } from "./helpers/requireTamaguiCore.mjs";
3
+ const nameToPaths = {},
4
+ Module = require("module"),
5
+ getNameToPaths = () => nameToPaths,
6
+ proxyWorm = require("@tamagui/proxy-worm"),
7
+ rnw = require("react-native-web");
8
+ let isRegistered = !1,
9
+ og;
10
+ const whitelisted = {
11
+ react: !0
12
+ },
13
+ compiled = {};
14
+ function setRequireResult(name, result) {
15
+ compiled[name] = result;
16
+ }
17
+ function registerRequire(platform, {
18
+ proxyWormImports
19
+ } = {
20
+ proxyWormImports: !1
21
+ }) {
22
+ if (isRegistered) return {
23
+ tamaguiRequire: require,
24
+ unregister: () => {}
25
+ };
26
+ const {
27
+ unregister
28
+ } = register({
29
+ hookIgnoreNodeModules: !1
30
+ });
31
+ og || (og = Module.prototype.require), isRegistered = !0, Module.prototype.require = tamaguiRequire;
32
+ function tamaguiRequire(path) {
33
+ if (path === "tamagui" && platform === "native") return og.apply(this, ["tamagui/native"]);
34
+ if (path === "@tamagui/core" || path === "@tamagui/web") return requireTamaguiCore(platform, path2 => og.apply(this, [path2]));
35
+ if (path in compiled) return compiled[path];
36
+ if (/\.(gif|jpe?g|png|svg|ttf|otf|woff2?|bmp|webp)$/i.test(path)) return {};
37
+ if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated") || path === "expo-linear-gradient" || path === "@expo/vector-icons" || path === "tamagui/linear-gradient" || path === "react-native-svg") return proxyWorm;
38
+ if (path === "react-native/package.json") return packageJson;
39
+ if (path === "react-native-web-lite" || path.startsWith("react-native")) return rnw;
40
+ if (path in knownIgnorableModules) return proxyWorm;
41
+ if (!whitelisted[path] && proxyWormImports && !path.includes(".tamagui-dynamic-eval")) return path === "tamagui" ? og.apply(this, [path]) : proxyWorm;
42
+ try {
43
+ return og.apply(this, arguments);
44
+ } catch (err) {
45
+ return !process.env.TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD && path.includes("tamagui-dynamic-eval") ? void 0 : (allowedIgnores[path] || IGNORES === "true" || (!process.env.TAMAGUI_SHOW_FULL_BUNDLE_ERRORS && !process.env.DEBUG ? hasWarnedForModules.has(path) || (hasWarnedForModules.add(path), console.info(` tamagui: skipping ${path} tamagui.dev/docs/intro/errors#warning-001`)) : console.error(`Tamagui failed loading "${path}"
46
+
47
+ ${err.message}
48
+ ${err.stack}
49
+
50
+ `)), proxyWorm);
51
+ }
52
+ }
53
+ return {
54
+ tamaguiRequire,
55
+ unregister: () => {
56
+ unregister(), isRegistered = !1, Module.prototype.require = og;
57
+ }
58
+ };
59
+ }
60
+ const packageJson = require("react-native-web/package.json"),
61
+ IGNORES = process.env.TAMAGUI_IGNORE_BUNDLE_ERRORS,
62
+ extraIgnores = IGNORES === "true" ? [] : process.env.TAMAGUI_IGNORE_BUNDLE_ERRORS?.split(","),
63
+ knownIgnorableModules = {
64
+ "expo-modules": !0,
65
+ solito: !0,
66
+ ...Object.fromEntries(extraIgnores?.map(k => [k, !0]) || [])
67
+ },
68
+ hasWarnedForModules = /* @__PURE__ */new Set(),
69
+ allowedIgnores = {
70
+ "expo-constants": !0,
71
+ "./ExpoHaptics": !0,
72
+ "./js/MaskedView": !0
73
+ };
74
+ export { getNameToPaths, registerRequire, setRequireResult };
@@ -0,0 +1,40 @@
1
+ import net from "node:net";
2
+ async function startServer(options) {
3
+ const port = await getAvailablePort(),
4
+ server = net.createServer();
5
+ server.unref(), await new Promise((resolve, reject) => {
6
+ server.on("error", reject), server.on("connection", conn => {
7
+ conn.on("data", data => {
8
+ console.info("got", data.toString());
9
+ });
10
+ }), server.listen({
11
+ port
12
+ }, () => {
13
+ const {
14
+ port: port2
15
+ } = server.address();
16
+ server.close(() => {
17
+ resolve(port2);
18
+ });
19
+ });
20
+ });
21
+ }
22
+ async function getAvailablePort(port = 8089) {
23
+ return checkAvailablePort(port).catch(() => getAvailablePort(port + 1));
24
+ }
25
+ function checkAvailablePort(port) {
26
+ return new Promise((resolve, reject) => {
27
+ const server = net.createServer();
28
+ server.unref(), server.on("error", reject), server.listen({
29
+ port
30
+ }, () => {
31
+ const {
32
+ port: port2
33
+ } = server.address();
34
+ server.close(() => {
35
+ resolve(port2);
36
+ });
37
+ });
38
+ });
39
+ }
40
+ export { startServer };
@@ -0,0 +1 @@
1
+ process.env.IS_STATIC = "is_static";