@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,237 @@
1
+ import * as path from "path";
2
+ import { basename } from "path";
3
+ import * as util from "util";
4
+ import generate from "@babel/generator";
5
+ import * as t from "@babel/types";
6
+ import { concatClassName } from "@tamagui/helpers";
7
+ import { requireTamaguiCore } from "../helpers/requireTamaguiCore.mjs";
8
+ import { babelParse } from "./babelParse.mjs";
9
+ import { buildClassName } from "./buildClassName.mjs";
10
+ import { ensureImportingConcat } from "./ensureImportingConcat.mjs";
11
+ import { isSimpleSpread } from "./extractHelpers.mjs";
12
+ import { extractMediaStyle } from "./extractMediaStyle.mjs";
13
+ import { getPrefixLogs } from "./getPrefixLogs.mjs";
14
+ import { hoistClassNames } from "./hoistClassNames.mjs";
15
+ import { logLines } from "./logLines.mjs";
16
+ import { getFontFamilyClassNameFromProps } from "./propsToFontFamilyCache.mjs";
17
+ import { timer } from "./timer.mjs";
18
+ const mergeStyleGroups = {
19
+ shadowOpacity: !0,
20
+ shadowRadius: !0,
21
+ shadowColor: !0,
22
+ shadowOffset: !0
23
+ };
24
+ async function extractToClassNames({
25
+ extractor,
26
+ source,
27
+ sourcePath,
28
+ options,
29
+ shouldPrintDebug
30
+ }) {
31
+ const tm = timer(),
32
+ {
33
+ getStylesAtomic
34
+ } = requireTamaguiCore("web");
35
+ if (sourcePath?.includes("node_modules")) return null;
36
+ if (shouldPrintDebug && console.warn(`--- ${sourcePath} ---
37
+
38
+ `), typeof source != "string") throw new Error("`source` must be a string of javascript");
39
+ if (sourcePath && !path.isAbsolute(sourcePath)) throw new Error("`sourcePath` must be an absolute path to a .js file, got: " + sourcePath);
40
+ /.[tj]sx?$/i.test(sourcePath || "") || console.warn(`${sourcePath?.slice(0, 100)} - bad filename.`), !options.disableExtraction && !options._disableLoadTamagui && (await extractor.loadTamagui(options));
41
+ const shouldLogTiming = options.logTimings ?? !0,
42
+ start = Date.now(),
43
+ mem = process.env.TAMAGUI_SHOW_MEMORY_USAGE && shouldLogTiming ? process.memoryUsage() : null;
44
+ let ast;
45
+ try {
46
+ ast = babelParse(source, sourcePath);
47
+ } catch (err) {
48
+ throw console.error("babel parse error:", sourcePath?.slice(0, 100)), err;
49
+ }
50
+ tm.mark("babel-parse", shouldPrintDebug === "verbose");
51
+ const cssMap = /* @__PURE__ */new Map(),
52
+ existingHoists = {};
53
+ let hasFlattened = !1;
54
+ const res = await extractor.parse(ast, {
55
+ shouldPrintDebug,
56
+ ...options,
57
+ sourcePath,
58
+ extractStyledDefinitions: !0,
59
+ onStyleRule(identifier, rules) {
60
+ const css = rules.join(";");
61
+ shouldPrintDebug && console.info(`adding styled() rule: .${identifier} ${css}`), cssMap.set(`.${identifier}`, {
62
+ css,
63
+ commentTexts: []
64
+ });
65
+ },
66
+ getFlattenedNode: ({
67
+ tag
68
+ }) => (hasFlattened = !0, tag),
69
+ onExtractTag: ({
70
+ parserProps,
71
+ attrs,
72
+ node,
73
+ attemptEval,
74
+ jsxPath,
75
+ originalNodeName,
76
+ filePath,
77
+ lineNumbers,
78
+ programPath,
79
+ isFlattened,
80
+ config,
81
+ completeProps,
82
+ staticConfig
83
+ }) => {
84
+ if (staticConfig.acceptsClassName === !1) {
85
+ shouldPrintDebug && console.info("bail, acceptsClassName is false");
86
+ return;
87
+ }
88
+ const didFlattenThisTag = hasFlattened;
89
+ hasFlattened = !1;
90
+ let finalClassNames = [];
91
+ const finalAttrs = [];
92
+ let finalStyles = [],
93
+ viewStyles = {};
94
+ for (const attr of attrs) attr.type === "style" && (viewStyles = {
95
+ ...viewStyles,
96
+ ...attr.value
97
+ });
98
+ const ensureNeededPrevStyle = style => {
99
+ if (!Object.keys(style).some(key => mergeStyleGroups[key])) return style;
100
+ for (const k in mergeStyleGroups) k in viewStyles && (style[k] = style[k] ?? viewStyles[k]);
101
+ return style;
102
+ },
103
+ addStyles = style => {
104
+ if (!style) return [];
105
+ const styleWithPrev = ensureNeededPrevStyle(style),
106
+ res2 = getStylesAtomic(styleWithPrev);
107
+ return res2.length && (finalStyles = [...finalStyles, ...res2]), res2;
108
+ };
109
+ let lastMediaImportance = 1;
110
+ for (const attr of attrs) switch (attr.type) {
111
+ case "style":
112
+ {
113
+ if (isFlattened) {
114
+ const styles2 = addStyles(attr.value),
115
+ newFontFamily = getFontFamilyClassNameFromProps(attr.value) || "",
116
+ newClassNames = concatClassName(styles2.map(x => x.identifier).join(" ") + newFontFamily),
117
+ existing = finalClassNames.find(x => x.type == "StringLiteral");
118
+ if (existing) {
119
+ let previous = existing.value;
120
+ newFontFamily && (shouldPrintDebug && console.info(` newFontFamily: ${newFontFamily}`), previous = previous.replace(/font_[a-z]+/i, "")), existing.value = `${previous} ${newClassNames}`;
121
+ } else finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)];
122
+ } else {
123
+ const styles2 = getStylesAtomic(attr.value);
124
+ finalStyles = [...finalStyles, ...styles2];
125
+ for (const style of styles2) {
126
+ const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property;
127
+ finalAttrs.push(t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier)));
128
+ }
129
+ }
130
+ break;
131
+ }
132
+ case "attr":
133
+ {
134
+ const val = attr.value;
135
+ if (t.isJSXSpreadAttribute(val)) isSimpleSpread(val) && finalClassNames.push(t.logicalExpression("&&", val.argument, t.memberExpression(val.argument, t.identifier("className"))));else if (val.name.name === "className") {
136
+ const value = val.value;
137
+ if (value) try {
138
+ const evaluatedValue = attemptEval(value);
139
+ finalClassNames.push(t.stringLiteral(evaluatedValue));
140
+ } catch {
141
+ finalClassNames.push(value.expression);
142
+ }
143
+ continue;
144
+ }
145
+ finalAttrs.push(val);
146
+ break;
147
+ }
148
+ case "ternary":
149
+ {
150
+ const mediaExtraction = extractMediaStyle(parserProps, attr.value, jsxPath, extractor.getTamagui(), sourcePath || "", lastMediaImportance, shouldPrintDebug);
151
+ if (shouldPrintDebug && mediaExtraction && console.info("ternary (mediaStyles)", mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? "", mediaExtraction.mediaStyles.map(x => x.identifier).join(".")), !mediaExtraction) {
152
+ addTernaryStyle(attr.value, addStyles(attr.value.consequent), addStyles(attr.value.alternate));
153
+ continue;
154
+ }
155
+ lastMediaImportance++, mediaExtraction.mediaStyles && (finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]), mediaExtraction.ternaryWithoutMedia ? addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, []) : finalClassNames = [...finalClassNames, ...mediaExtraction.mediaStyles.map(x => t.stringLiteral(x.identifier))];
156
+ break;
157
+ }
158
+ }
159
+ function addTernaryStyle(ternary, a, b) {
160
+ const cCN = a.map(x => x.identifier).join(" "),
161
+ aCN = b.map(x => x.identifier).join(" ");
162
+ a.length && b.length ? finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))) : finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
163
+ }
164
+ if (shouldPrintDebug && console.info(` finalClassNames
165
+ `, logLines(finalClassNames.map(x => x.value).join(" "))), node.attributes = finalAttrs, finalClassNames.length) {
166
+ const extraClassNames = (() => {
167
+ let value = "";
168
+ return isFlattened && (process.env.TAMAGUI_DEBUG_OPTIMIZATIONS && (value += "is_tamagui_flattened"), staticConfig.componentName && (value += ` is_${staticConfig.componentName}`)), value;
169
+ })(),
170
+ names = buildClassName(finalClassNames, extraClassNames),
171
+ nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
172
+ let expr = nameExpr;
173
+ if (nameExpr && !t.isIdentifier(nameExpr) && didFlattenThisTag) {
174
+ ensureImportingConcat(programPath);
175
+ const simpleSpreads = attrs.filter(x => x.type === "attr" && t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
176
+ expr = t.callExpression(t.identifier("concatClassName"), [expr, ...simpleSpreads.map(val => val.value.argument)]);
177
+ }
178
+ node.attributes.push(t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr)));
179
+ }
180
+ const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
181
+ for (const {
182
+ identifier,
183
+ rules
184
+ } of finalStyles) {
185
+ const className = `.${identifier}`;
186
+ if (cssMap.has(className)) {
187
+ if (comment) {
188
+ const val = cssMap.get(className);
189
+ val.commentTexts.push(comment), cssMap.set(className, val);
190
+ }
191
+ } else rules.length && cssMap.set(className, {
192
+ css: rules.join(`
193
+ `),
194
+ commentTexts: [comment]
195
+ });
196
+ }
197
+ }
198
+ });
199
+ if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) return shouldPrintDebug && console.info("no res or none modified", res), null;
200
+ const styles = Array.from(cssMap.values()).map(x => x.css).join(`
201
+ `).trim(),
202
+ result = generate(ast, {
203
+ concise: !1,
204
+ filename: sourcePath,
205
+ // this makes the debug output terrible, and i think sourcemap works already
206
+ retainLines: !1,
207
+ sourceFileName: sourcePath,
208
+ sourceMaps: !0
209
+ }, source);
210
+ if (shouldPrintDebug && (console.info(`
211
+ -------- output code -------
212
+
213
+ `, result.code.split(`
214
+ `).filter(x => !x.startsWith("//")).join(`
215
+ `)), console.info(`
216
+ -------- output style --------
217
+
218
+ `, styles)), shouldLogTiming) {
219
+ const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0,
220
+ path2 = basename(sourcePath || "").replace(/\.[jt]sx?$/, "").slice(0, 22).trim().padStart(24),
221
+ numOptimized = `${res.optimized + res.styled}`.padStart(3),
222
+ numFound = `${res.found + res.styled}`.padStart(3),
223
+ numFlattened = `${res.flattened}`.padStart(3),
224
+ memory = memUsed ? ` ${memUsed}MB` : "",
225
+ timingStr = `${Date.now() - start}ms`.padStart(6),
226
+ pre = getPrefixLogs(options),
227
+ memStr = memory ? `(${memory})` : "";
228
+ console.info(`${pre} ${path2} \xB7 ${numFound} found \xB7 ${numOptimized} opt \xB7 ${numFlattened} flat ${timingStr} ${memStr}`);
229
+ }
230
+ return {
231
+ ast,
232
+ styles,
233
+ js: result.code,
234
+ map: result.map
235
+ };
236
+ }
237
+ export { extractToClassNames };
@@ -0,0 +1,10 @@
1
+ function findTopmostFunction(jsxPath) {
2
+ const isFunction = path => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
3
+ let compFn = jsxPath.findParent(isFunction);
4
+ for (; compFn;) {
5
+ const parent = compFn.findParent(isFunction);
6
+ if (parent) compFn = parent;else break;
7
+ }
8
+ return compFn || null;
9
+ }
10
+ export { findTopmostFunction };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../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+ import { dirname, join } from "path";
2
+ import { generateThemes, writeGeneratedThemes } from "@tamagui/generate-themes";
3
+ import fs, { readFile } from "fs-extra";
4
+ import { requireTamaguiCore } from "../helpers/requireTamaguiCore.mjs";
5
+ import { getBundledConfig } from "./bundleConfig.mjs";
6
+ const tamaguiDir = join(process.cwd(), ".tamagui"),
7
+ confFile = join(tamaguiDir, "tamagui.config.json");
8
+ async function generateTamaguiStudioConfig(tamaguiOptions, configIn, rebuild = !1) {
9
+ try {
10
+ const config = configIn ?? (await getBundledConfig(tamaguiOptions, rebuild));
11
+ if (!config) return;
12
+ const out = transformConfig(config, tamaguiOptions.platform);
13
+ await fs.ensureDir(dirname(confFile)), await fs.writeJSON(confFile, out, {
14
+ spaces: 2
15
+ });
16
+ } catch (err) {
17
+ (process.env.DEBUG?.includes("tamagui") || process.env.IS_TAMAGUI_DEV) && console.warn("generateTamaguiStudioConfig error", err);
18
+ }
19
+ }
20
+ function generateTamaguiStudioConfigSync(_tamaguiOptions, config) {
21
+ try {
22
+ fs.ensureDirSync(dirname(confFile)), fs.writeJSONSync(confFile, transformConfig(config, _tamaguiOptions.platform), {
23
+ spaces: 2
24
+ });
25
+ } catch (err) {
26
+ (process.env.DEBUG?.includes("tamagui") || process.env.IS_TAMAGUI_DEV) && console.warn("generateTamaguiStudioConfig error", err);
27
+ }
28
+ }
29
+ async function generateTamaguiThemes(tamaguiOptions, force = !1) {
30
+ if (!tamaguiOptions.themeBuilder) return;
31
+ const {
32
+ input,
33
+ output
34
+ } = tamaguiOptions.themeBuilder,
35
+ inPath = resolveRelativePath(input),
36
+ outPath = resolveRelativePath(output),
37
+ generatedOutput = await generateThemes(inPath),
38
+ hasChanged = force || (await (async () => {
39
+ try {
40
+ if (!(await fs.pathExists(join(tamaguiDir, "theme-builder.json")))) return !0;
41
+ if (!generatedOutput) return !1;
42
+ const next = generatedOutput.generated,
43
+ current = await readFile(outPath, "utf-8");
44
+ return next !== current;
45
+ } catch {}
46
+ return !0;
47
+ })());
48
+ return hasChanged && (await writeGeneratedThemes(tamaguiDir, outPath, generatedOutput)), hasChanged;
49
+ }
50
+ const resolveRelativePath = inputPath => inputPath.startsWith(".") ? join(process.cwd(), inputPath) : require.resolve(inputPath);
51
+ function cloneDeepSafe(x, excludeKeys = {}) {
52
+ return x && (Array.isArray(x) ? x.map(_ => cloneDeepSafe(_)) : typeof x == "function" ? "Function" : typeof x != "object" ? x : "$$typeof" in x ? "Component" : Object.fromEntries(Object.entries(x).flatMap(([k, v]) => excludeKeys[k] ? [] : [[k, cloneDeepSafe(v)]])));
53
+ }
54
+ function transformConfig(config, platform) {
55
+ if (!config) return null;
56
+ const {
57
+ getVariableValue
58
+ } = requireTamaguiCore(platform),
59
+ next = cloneDeepSafe(config, {
60
+ validStyles: !0
61
+ }),
62
+ {
63
+ components,
64
+ nameToPaths,
65
+ tamaguiConfig
66
+ } = next,
67
+ {
68
+ themes,
69
+ tokens
70
+ } = tamaguiConfig;
71
+ for (const key in themes) {
72
+ const theme = themes[key];
73
+ theme.id = key;
74
+ for (const tkey in theme) theme[tkey] = getVariableValue(theme[tkey]);
75
+ }
76
+ for (const key in tokens) {
77
+ const token = {
78
+ ...tokens[key]
79
+ };
80
+ for (const tkey in token) token[tkey] = getVariableValue(token[tkey]);
81
+ }
82
+ for (const component of components) for (const _ in component.nameToInfo) {
83
+ const compDefinition = {
84
+ ...component.nameToInfo[_]
85
+ };
86
+ component.nameToInfo[_] = compDefinition;
87
+ const {
88
+ parentStaticConfig,
89
+ ...rest
90
+ } = compDefinition.staticConfig;
91
+ compDefinition.staticConfig = rest;
92
+ }
93
+ next.nameToPaths = {};
94
+ for (const key in nameToPaths) next.nameToPaths[key] = [...nameToPaths[key]];
95
+ const {
96
+ fontsParsed,
97
+ getCSS,
98
+ tokensParsed,
99
+ themeConfig,
100
+ ...cleanedConfig
101
+ } = next.tamaguiConfig;
102
+ return {
103
+ components,
104
+ nameToPaths,
105
+ tamaguiConfig: cleanedConfig
106
+ };
107
+ }
108
+ export { generateTamaguiStudioConfig, generateTamaguiStudioConfigSync, generateTamaguiThemes };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/generateTamaguiStudioConfig.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA8B,iBAE9B,yBAAqD,qCAErD,kBAA6B,8BAE7B,4BAAmC,0CAEnC,sBAAgD;AAEhD,MAAM,iBAAa,kBAAK,QAAQ,IAAI,GAAG,UAAU,GAC3C,eAAW,kBAAK,YAAY,qBAAqB;AAMvD,eAAsB,4BACpB,gBACA,UACA,UAAU,IACV;AArBF;AAsBE,MAAI;AACF,UAAM,SAAS,YAAa,UAAM,sCAAiB,gBAAgB,OAAO;AAC1E,QAAI,CAAC;AAAQ;AACb,UAAM,MAAM,gBAAgB,QAAQ,eAAe,QAAQ;AAE3D,UAAM,gBAAAA,QAAG,cAAU,qBAAQ,QAAQ,CAAC,GACpC,MAAM,gBAAAA,QAAG,UAAU,UAAU,KAAK;AAAA,MAChC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,MAAI,aAAQ,IAAI,UAAZ,WAAmB,SAAS,cAAc,QAAQ,IAAI,mBACxD,QAAQ,KAAK,qCAAqC,GAAG;AAAA,EAGzD;AACF;AAEO,SAAS,gCACd,iBACA,QACA;AA1CF;AA2CE,MAAI;AACF,oBAAAA,QAAG,kBAAc,qBAAQ,QAAQ,CAAC,GAClC,gBAAAA,QAAG,cAAc,UAAU,gBAAgB,QAAQ,gBAAgB,QAAQ,GAAG;AAAA,MAC5E,QAAQ;AAAA,IACV,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,MAAI,aAAQ,IAAI,UAAZ,WAAmB,SAAS,cAAc,QAAQ,IAAI,mBACxD,QAAQ,KAAK,qCAAqC,GAAG;AAAA,EAGzD;AACF;AAEA,eAAsB,sBACpB,gBACA,QAA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AAe;AACvD,qBAAe,eAAe;AAAA,IAChC;AAIF,OAAK,cAAc,CAAC;AACpB,aAAW,OAAO;AAChB,SAAK,YAAY,GAAG,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC;AAI9C,QAAM,EAAE,aAAa,QAAQ,cAAc,aAAa,GAAG,cAAc,IACvE,KAAK;AAEP,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,eAAe;AAAA,EACjB;AACF;",
5
5
  "names": ["fs"]
6
6
  }
@@ -0,0 +1,12 @@
1
+ import * as t from "@babel/types";
2
+ function generateUid(scope, name) {
3
+ if (typeof scope != "object") throw "generateUid expects a scope object as its first parameter";
4
+ if (!(typeof name == "string" && name !== "")) throw "generateUid expects a valid name as its second parameter";
5
+ name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
6
+ let uid,
7
+ i = 0;
8
+ do i > 1 ? uid = name + i : uid = name, i++; while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
9
+ const program = scope.getProgramParent();
10
+ return program.references[uid] = !0, program.uids[uid] = !0, uid;
11
+ }
12
+ export { generateUid };
@@ -0,0 +1,4 @@
1
+ function getPrefixLogs(options) {
2
+ return options?.prefixLogs ?? ` ${options?.platform || "web"} | `;
3
+ }
4
+ export { getPrefixLogs };
@@ -0,0 +1,31 @@
1
+ import generate from "@babel/generator";
2
+ import * as t from "@babel/types";
3
+ import { accessSafe } from "./accessSafe.mjs";
4
+ function getPropValueFromAttributes(propName, attrs) {
5
+ let propIndex = -1,
6
+ jsxAttr = null;
7
+ for (let idx = -1, len = attrs.length; ++idx < len;) {
8
+ const attr = attrs[idx];
9
+ if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
10
+ propIndex = idx, jsxAttr = attr;
11
+ break;
12
+ }
13
+ }
14
+ if (!jsxAttr || jsxAttr.value == null) return null;
15
+ let propValue = jsxAttr.value;
16
+ if (t.isJSXExpressionContainer(propValue) && (propValue = propValue.expression), t.isJSXEmptyExpression(propValue)) return console.error("encountered JSXEmptyExpression"), null;
17
+ const applicableSpreads = attrs.filter(
18
+ // 1. idx is greater than propValue prop index
19
+ // 2. attr is a spread operator
20
+ (attr, idx) => {
21
+ if (t.isJSXSpreadAttribute(attr)) {
22
+ if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) return idx > propIndex;
23
+ if (t.isLogicalExpression(attr.argument)) return !1;
24
+ throw new Error(`unsupported spread of type "${attr.argument.type}": ${// @ts-ignore
25
+ generate(attr).code}`);
26
+ }
27
+ return !1;
28
+ }).map(attr => attr.argument);
29
+ return applicableSpreads.length > 0 && (propValue = applicableSpreads.reduce((acc, val) => t.logicalExpression("||", accessSafe(val, propName), acc), propValue)), propValue;
30
+ }
31
+ export { getPropValueFromAttributes };
@@ -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 };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
4
- "mappings": "AAAA,SAAuB,YAAY;AACnC,SAAS,SAAS,SAAS,MAAM,eAAe;AAGhD,YAAY,OAAO;AAEnB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAEhC,MAAM,gBAAgB,CAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG;AAEnF,SAAS,kBAAkB,YAAoB,MAAc;AAC3D,QAAM,YAAY,QAAQ,UAAU;AACpC,SAAI,cAAc,IAAI,KAChB,QAAQ,IAAI,MAAM,OACpB,QAAQ,QAEH,QAAQ,WAAW,IAAI,KAEzB;AACT;AAEA,MAAM,QAAQ,oBAAI,IAAI,GAChB,UAAU,oBAAI,IAA0B,GAExC,UAAU,GAAG,KAAK,WAAW,aAAa,CAAC;AAEjD,IAAI,SAAS,IAET,QAA6B;AAEjC,SAAS,YAAY;AACnB,UAAQ,KAAK,SAAS,CAAC,GAAG;AAAA,IACxB,UAAU,CAAC,MAAM,kBAAkB;AAAA,IACnC,UAAU;AAAA,IACV,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,EAAI,UACC,UACL,MAAM,mBAAmB,GACzB,MAAM,MAAM,GACZ,MAAM,WAAW,GACjB,MAAM,KAAK,GACX,SAAS;AACX;AAEA,QAAQ,KAAK,WAAW,iBAAiB;AACzC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yB,UAAU,QAAQ,UAAU,WAAW,aAAa,YAAY;AAAA,UAC3F,GACO,CAAC;AAEV,QAAI,aAAa,eACX,aAAa,aACf,IAAI,CAAC,IAAI,IAAI,aAAa,QAAQ,KAGpC,IAAI,CAAC,IAAI;AAAA,MAEb;AACA;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI,QAAQ;AAE3B,QAAI,CAAC,EAAE,sBAAsB,MAAM,KAAK,OAAO,SAAS;AACtD;AAIF,UAAM,MAAM,OAAO,aAAa,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;AAInF,QAAI,CAAC,OAAO,CAAC,IAAI;AACf;AAIF,QAAI,OAAO,IAAI,GAAG,SAAU,YAAY,OAAO,IAAI,GAAG,OAAQ,UAAU;AACtE,cAAQ,MAAM,kCAAkC;AAChD;AAAA,IACF;AAEA,QAAI,CAAC,EAAE,aAAa,IAAI,EAAE,GAAG;AAC3B,cAAQ,MAAM,0BAA0B;AACxC;AAAA,IACF;AAEA,UAAM,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,GAAG;AAG7D,QAAI,OAAO,eAAe,KAAK,cAAc,QAAQ,GAAG;AACtD,UAAI,CAAC,IAAI,aAAa,QAAQ;AAC9B;AAAA,IACF;AAEA,QAAI,OAAO,eAAe,KAAK,cAAc,QAAQ,GAAG;AACtD,UAAI,CAAC,IAAI,aAAa,QAAQ;AAC9B;AAAA,IACF;AAGA,QAAI;AACF,UAAI,CAAC,IAAI,gBAAgB,IAAI,MAAM,QAAW,gBAAgB,GAC9D,aAAa,QAAQ,IAAI,IAAI,CAAC;AAC9B;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,SAAO;AACT;",
5
5
  "names": []
6
6
  }
@@ -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 };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAmC,0BACnC,cAAgD,iBAGhD,IAAmB,kCAEnB,yBAAgC,8BAChC,yBAAgC;AAEhC,MAAM,gBAAgB,CAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG;AAEnF,SAAS,kBAAkB,YAAoB,MAAc;AAC3D,QAAM,gBAAY,qBAAQ,UAAU;AACpC,SAAI,cAAc,IAAI,SAChB,qBAAQ,IAAI,MAAM,OACpB,QAAQ,YAEH,qBAAQ,WAAW,IAAI,KAEzB;AACT;AAEA,MAAM,QAAQ,oBAAI,IAAI,GAChB,UAAU,oBAAI,IAA0B,GAExC,UAAU,OAAG,kBAAK,WAAW,aAAa,CAAC;AAEjD,IAAI,SAAS,IAET,QAA6B;AAEjC,SAAS,YAAY;AACnB,cAAQ,2BAAK,SAAS,CAAC,GAAG;AAAA,IACxB,UAAU,CAAC,MAAM,kBAAkB;AAAA,IACnC,UAAU;AAAA,IACV,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,EAAI,UACC,UACL,MAAM,mBAAmB,GACzB,MAAM,MAAM,GACZ,MAAM,WAAW,GACjB,MAAM,KAAK,GACX,SAAS;AACX;AAEA,QAAQ,KAAK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 @@
1
+ import { isAbsolute, join } from "path";
2
+ function getTamaguiConfigPathFromOptionsConfig(config) {
3
+ return isAbsolute(config) ? config : join(process.cwd(), config);
4
+ }
5
+ export { getTamaguiConfigPathFromOptionsConfig };