@tamagui/static 1.115.1 → 1.115.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/check-dep-versions.js +389 -0
  2. package/dist/checkDeps.js +26 -0
  3. package/dist/{constants.cjs → constants.js} +14 -29
  4. package/dist/exports.js +33 -0
  5. package/dist/extractor/accessSafe.js +47 -0
  6. package/dist/extractor/babelParse.js +59 -0
  7. package/dist/extractor/buildClassName.js +72 -0
  8. package/dist/extractor/bundle.js +133 -0
  9. package/dist/extractor/bundleConfig.js +350 -0
  10. package/dist/extractor/{createEvaluator.cjs → createEvaluator.js} +21 -37
  11. package/dist/extractor/createExtractor.js +1217 -0
  12. package/dist/extractor/createLogger.js +32 -0
  13. package/dist/extractor/ensureImportingConcat.js +50 -0
  14. package/dist/extractor/esbuildAliasPlugin.js +36 -0
  15. package/dist/extractor/evaluateAstNode.js +99 -0
  16. package/dist/extractor/extractHelpers.js +109 -0
  17. package/dist/extractor/extractMediaStyle.js +123 -0
  18. package/dist/extractor/extractToClassNames.js +291 -0
  19. package/dist/extractor/extractToNative.js +319 -0
  20. package/dist/extractor/findTopmostFunction.js +32 -0
  21. package/dist/extractor/generatedUid.js +42 -0
  22. package/dist/extractor/getPrefixLogs.js +23 -0
  23. package/dist/extractor/getPropValueFromAttributes.js +65 -0
  24. package/dist/extractor/getSourceModule.js +66 -0
  25. package/dist/extractor/{getStaticBindingsForScope.cjs → getStaticBindingsForScope.js} +61 -66
  26. package/dist/extractor/{getTamaguiConfigPathFromOptionsConfig.cjs → getTamaguiConfigPathFromOptionsConfig.js} +11 -16
  27. package/dist/extractor/{hoistClassNames.cjs → hoistClassNames.js} +32 -31
  28. package/dist/extractor/{literalToAst.cjs → literalToAst.js} +44 -38
  29. package/dist/extractor/{loadFile.cjs → loadFile.js} +6 -3
  30. package/dist/extractor/{loadTamagui.cjs → loadTamagui.js} +78 -99
  31. package/dist/extractor/logLines.js +30 -0
  32. package/dist/extractor/{normalizeTernaries.cjs → normalizeTernaries.js} +29 -38
  33. package/dist/extractor/{propsToFontFamilyCache.cjs → propsToFontFamilyCache.js} +14 -18
  34. package/dist/extractor/regenerateConfig.js +111 -0
  35. package/dist/extractor/{removeUnusedHooks.cjs → removeUnusedHooks.js} +27 -31
  36. package/dist/extractor/{timer.cjs → timer.js} +11 -16
  37. package/dist/extractor/{validHTMLAttributes.cjs → validHTMLAttributes.js} +11 -16
  38. package/dist/extractor/{watchTamaguiConfig.cjs → watchTamaguiConfig.js} +29 -30
  39. package/dist/{getPragmaOptions.cjs → getPragmaOptions.js} +17 -22
  40. package/dist/helpers/memoize.js +33 -0
  41. package/dist/helpers/requireTamaguiCore.js +30 -0
  42. package/dist/index.js +30 -0
  43. package/dist/registerRequire.js +96 -0
  44. package/dist/{server.cjs → server.js} +21 -38
  45. package/dist/setup.js +1 -0
  46. package/dist/types.js +14 -0
  47. package/package.json +16 -16
  48. package/dist/check-dep-versions.cjs +0 -267
  49. package/dist/checkDeps.cjs +0 -32
  50. package/dist/exports.cjs +0 -40
  51. package/dist/extractor/accessSafe.cjs +0 -46
  52. package/dist/extractor/babelParse.cjs +0 -54
  53. package/dist/extractor/buildClassName.cjs +0 -62
  54. package/dist/extractor/bundle.cjs +0 -146
  55. package/dist/extractor/bundleConfig.cjs +0 -322
  56. package/dist/extractor/createExtractor.cjs +0 -1008
  57. package/dist/extractor/createLogger.cjs +0 -45
  58. package/dist/extractor/ensureImportingConcat.cjs +0 -48
  59. package/dist/extractor/esbuildAliasPlugin.cjs +0 -44
  60. package/dist/extractor/evaluateAstNode.cjs +0 -83
  61. package/dist/extractor/extractHelpers.cjs +0 -120
  62. package/dist/extractor/extractMediaStyle.cjs +0 -129
  63. package/dist/extractor/extractToClassNames.cjs +0 -254
  64. package/dist/extractor/extractToNative.cjs +0 -274
  65. package/dist/extractor/findTopmostFunction.cjs +0 -34
  66. package/dist/extractor/generatedUid.cjs +0 -47
  67. package/dist/extractor/getPrefixLogs.cjs +0 -28
  68. package/dist/extractor/getPropValueFromAttributes.cjs +0 -67
  69. package/dist/extractor/getSourceModule.cjs +0 -68
  70. package/dist/extractor/logLines.cjs +0 -35
  71. package/dist/extractor/regenerateConfig.cjs +0 -144
  72. package/dist/helpers/memoize.cjs +0 -37
  73. package/dist/helpers/requireTamaguiCore.cjs +0 -33
  74. package/dist/index.cjs +0 -40
  75. package/dist/registerRequire.cjs +0 -102
  76. package/dist/setup.cjs +0 -0
  77. package/dist/types.cjs +0 -16
  78. /package/dist/{check-dep-versions.cjs.map → check-dep-versions.js.map} +0 -0
  79. /package/dist/{checkDeps.cjs.map → checkDeps.js.map} +0 -0
  80. /package/dist/{constants.cjs.map → constants.js.map} +0 -0
  81. /package/dist/{exports.cjs.map → exports.js.map} +0 -0
  82. /package/dist/extractor/{accessSafe.cjs.map → accessSafe.js.map} +0 -0
  83. /package/dist/extractor/{babelParse.cjs.map → babelParse.js.map} +0 -0
  84. /package/dist/extractor/{buildClassName.cjs.map → buildClassName.js.map} +0 -0
  85. /package/dist/extractor/{bundle.cjs.map → bundle.js.map} +0 -0
  86. /package/dist/extractor/{bundleConfig.cjs.map → bundleConfig.js.map} +0 -0
  87. /package/dist/extractor/{createEvaluator.cjs.map → createEvaluator.js.map} +0 -0
  88. /package/dist/extractor/{createExtractor.cjs.map → createExtractor.js.map} +0 -0
  89. /package/dist/extractor/{createLogger.cjs.map → createLogger.js.map} +0 -0
  90. /package/dist/extractor/{ensureImportingConcat.cjs.map → ensureImportingConcat.js.map} +0 -0
  91. /package/dist/extractor/{esbuildAliasPlugin.cjs.map → esbuildAliasPlugin.js.map} +0 -0
  92. /package/dist/extractor/{evaluateAstNode.cjs.map → evaluateAstNode.js.map} +0 -0
  93. /package/dist/extractor/{extractHelpers.cjs.map → extractHelpers.js.map} +0 -0
  94. /package/dist/extractor/{extractMediaStyle.cjs.map → extractMediaStyle.js.map} +0 -0
  95. /package/dist/extractor/{extractToClassNames.cjs.map → extractToClassNames.js.map} +0 -0
  96. /package/dist/extractor/{extractToNative.cjs.map → extractToNative.js.map} +0 -0
  97. /package/dist/extractor/{findTopmostFunction.cjs.map → findTopmostFunction.js.map} +0 -0
  98. /package/dist/extractor/{generatedUid.cjs.map → generatedUid.js.map} +0 -0
  99. /package/dist/extractor/{getPrefixLogs.cjs.map → getPrefixLogs.js.map} +0 -0
  100. /package/dist/extractor/{getPropValueFromAttributes.cjs.map → getPropValueFromAttributes.js.map} +0 -0
  101. /package/dist/extractor/{getSourceModule.cjs.map → getSourceModule.js.map} +0 -0
  102. /package/dist/extractor/{getStaticBindingsForScope.cjs.map → getStaticBindingsForScope.js.map} +0 -0
  103. /package/dist/extractor/{getTamaguiConfigPathFromOptionsConfig.cjs.map → getTamaguiConfigPathFromOptionsConfig.js.map} +0 -0
  104. /package/dist/extractor/{hoistClassNames.cjs.map → hoistClassNames.js.map} +0 -0
  105. /package/dist/extractor/{literalToAst.cjs.map → literalToAst.js.map} +0 -0
  106. /package/dist/extractor/{loadFile.cjs.map → loadFile.js.map} +0 -0
  107. /package/dist/extractor/{loadTamagui.cjs.map → loadTamagui.js.map} +0 -0
  108. /package/dist/extractor/{logLines.cjs.map → logLines.js.map} +0 -0
  109. /package/dist/extractor/{normalizeTernaries.cjs.map → normalizeTernaries.js.map} +0 -0
  110. /package/dist/extractor/{propsToFontFamilyCache.cjs.map → propsToFontFamilyCache.js.map} +0 -0
  111. /package/dist/extractor/{regenerateConfig.cjs.map → regenerateConfig.js.map} +0 -0
  112. /package/dist/extractor/{removeUnusedHooks.cjs.map → removeUnusedHooks.js.map} +0 -0
  113. /package/dist/extractor/{timer.cjs.map → timer.js.map} +0 -0
  114. /package/dist/extractor/{validHTMLAttributes.cjs.map → validHTMLAttributes.js.map} +0 -0
  115. /package/dist/extractor/{watchTamaguiConfig.cjs.map → watchTamaguiConfig.js.map} +0 -0
  116. /package/dist/{getPragmaOptions.cjs.map → getPragmaOptions.js.map} +0 -0
  117. /package/dist/helpers/{memoize.cjs.map → memoize.js.map} +0 -0
  118. /package/dist/helpers/{requireTamaguiCore.cjs.map → requireTamaguiCore.js.map} +0 -0
  119. /package/dist/{index.cjs.map → index.js.map} +0 -0
  120. /package/dist/{registerRequire.cjs.map → registerRequire.js.map} +0 -0
  121. /package/dist/{server.cjs.map → server.js.map} +0 -0
  122. /package/dist/{setup.cjs.map → setup.js.map} +0 -0
  123. /package/dist/{types.cjs.map → types.js.map} +0 -0
@@ -0,0 +1,291 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var extractToClassNames_exports = {};
24
+ __export(extractToClassNames_exports, {
25
+ extractToClassNames: () => extractToClassNames
26
+ });
27
+ module.exports = __toCommonJS(extractToClassNames_exports);
28
+ var path = __toESM(require("node:path")), util = __toESM(require("node:util")), import_generator = __toESM(require("@babel/generator")), t = __toESM(require("@babel/types")), helpers = __toESM(require("@tamagui/helpers")), import_requireTamaguiCore = require("../helpers/requireTamaguiCore"), import_babelParse = require("./babelParse"), import_buildClassName = require("./buildClassName"), import_createLogger = require("./createLogger"), import_ensureImportingConcat = require("./ensureImportingConcat"), import_extractHelpers = require("./extractHelpers"), import_extractMediaStyle = require("./extractMediaStyle"), import_hoistClassNames = require("./hoistClassNames"), import_propsToFontFamilyCache = require("./propsToFontFamilyCache"), import_timer = require("./timer");
29
+ const mergeStyleGroups = {
30
+ shadowOpacity: !0,
31
+ shadowRadius: !0,
32
+ shadowColor: !0,
33
+ shadowOffset: !0
34
+ };
35
+ async function extractToClassNames({
36
+ extractor,
37
+ source,
38
+ sourcePath = "",
39
+ options,
40
+ shouldPrintDebug
41
+ }) {
42
+ const tm = (0, import_timer.timer)(), { getStylesAtomic } = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
43
+ if (sourcePath.includes("node_modules"))
44
+ return null;
45
+ if (shouldPrintDebug && console.warn(`--- ${sourcePath} ---
46
+
47
+ `), typeof source != "string")
48
+ throw new Error("`source` must be a string of javascript");
49
+ if (!path.isAbsolute(sourcePath))
50
+ throw new Error(
51
+ "`sourcePath` must be an absolute path to a .js file, got: " + sourcePath
52
+ );
53
+ /.[tj]sx?$/i.test(sourcePath || "") || console.warn(`${sourcePath.slice(0, 100)} - bad filename.`), !options.disableExtraction && !options._disableLoadTamagui && await extractor.loadTamagui(options);
54
+ const printLog = (0, import_createLogger.createLogger)(sourcePath, options);
55
+ let ast;
56
+ try {
57
+ ast = (0, import_babelParse.babelParse)(source, sourcePath);
58
+ } catch (err) {
59
+ throw console.error("babel parse error:", sourcePath.slice(0, 100)), err;
60
+ }
61
+ tm.mark("babel-parse", shouldPrintDebug === "verbose");
62
+ const cssMap = /* @__PURE__ */ new Map(), existingHoists = {};
63
+ let hasFlattened = !1;
64
+ const res = await extractor.parse(ast, {
65
+ shouldPrintDebug,
66
+ ...options,
67
+ platform: "web",
68
+ sourcePath,
69
+ extractStyledDefinitions: !0,
70
+ onStyleRule(identifier, rules) {
71
+ const css = rules.join(";");
72
+ shouldPrintDebug && console.info(`adding styled() rule: .${identifier} ${css}`), cssMap.set(`.${identifier}`, { css, commentTexts: [] });
73
+ },
74
+ getFlattenedNode: ({ tag }) => (hasFlattened = !0, tag),
75
+ onExtractTag: ({
76
+ parserProps,
77
+ attrs,
78
+ node,
79
+ attemptEval,
80
+ jsxPath,
81
+ originalNodeName,
82
+ filePath,
83
+ lineNumbers,
84
+ programPath,
85
+ isFlattened,
86
+ staticConfig
87
+ }) => {
88
+ if (staticConfig.acceptsClassName === !1) {
89
+ shouldPrintDebug && console.info("bail, acceptsClassName is false");
90
+ return;
91
+ }
92
+ const didFlattenThisTag = hasFlattened;
93
+ hasFlattened = !1;
94
+ let finalClassNames = [];
95
+ const finalAttrs = [];
96
+ let finalStyles = [], viewStyles = {};
97
+ for (const attr of attrs)
98
+ attr.type === "style" && (viewStyles = {
99
+ ...viewStyles,
100
+ ...attr.value
101
+ });
102
+ const ensureNeededPrevStyle = (style) => {
103
+ if (!Object.keys(style).some((key) => mergeStyleGroups[key]))
104
+ return style;
105
+ for (const k in mergeStyleGroups)
106
+ k in viewStyles && (style[k] = style[k] ?? viewStyles[k]);
107
+ return style;
108
+ }, addStyles = (style) => {
109
+ if (!style) return [];
110
+ const styleWithPrev = ensureNeededPrevStyle(style), res2 = getStylesAtomic(styleWithPrev);
111
+ return res2.length && (finalStyles = [...finalStyles, ...res2]), res2;
112
+ };
113
+ let lastMediaImportance = 1;
114
+ for (const attr of attrs)
115
+ switch (attr.type) {
116
+ case "style": {
117
+ if (isFlattened) {
118
+ const styles2 = addStyles(attr.value), newFontFamily = (0, import_propsToFontFamilyCache.getFontFamilyClassNameFromProps)(attr.value) || "", newClassNames = helpers.concatClassName(
119
+ styles2.map((x) => x[helpers.StyleObjectIdentifier]).join(" ") + newFontFamily
120
+ ), existing = finalClassNames.find(
121
+ (x) => x.type == "StringLiteral"
122
+ );
123
+ if (existing) {
124
+ let previous = existing.value;
125
+ newFontFamily && (shouldPrintDebug && console.info(` newFontFamily: ${newFontFamily}`), previous = previous.replace(/font_[a-z]+/i, "")), existing.value = `${previous} ${newClassNames}`;
126
+ } else
127
+ finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)];
128
+ } else {
129
+ const styles2 = getStylesAtomic(attr.value);
130
+ finalStyles = [...finalStyles, ...styles2];
131
+ for (const style of styles2) {
132
+ const prop = style[helpers.StyleObjectPseudo] ? `${style[helpers.StyleObjectProperty]}-${style[helpers.StyleObjectPseudo]}` : style[helpers.StyleObjectProperty];
133
+ finalAttrs.push(
134
+ t.jsxAttribute(
135
+ t.jsxIdentifier(prop),
136
+ t.stringLiteral(style[helpers.StyleObjectIdentifier])
137
+ )
138
+ );
139
+ }
140
+ }
141
+ break;
142
+ }
143
+ case "attr": {
144
+ const val = attr.value;
145
+ if (t.isJSXSpreadAttribute(val))
146
+ (0, import_extractHelpers.isSimpleSpread)(val) && finalClassNames.push(
147
+ t.logicalExpression(
148
+ "&&",
149
+ val.argument,
150
+ t.memberExpression(val.argument, t.identifier("className"))
151
+ )
152
+ );
153
+ else if (val.name.name === "className") {
154
+ const value = val.value;
155
+ if (value)
156
+ try {
157
+ const evaluatedValue = attemptEval(value);
158
+ finalClassNames.push(t.stringLiteral(evaluatedValue));
159
+ } catch {
160
+ finalClassNames.push(value.expression);
161
+ }
162
+ continue;
163
+ }
164
+ finalAttrs.push(val);
165
+ break;
166
+ }
167
+ case "ternary": {
168
+ const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(
169
+ parserProps,
170
+ attr.value,
171
+ jsxPath,
172
+ extractor.getTamagui(),
173
+ sourcePath || "",
174
+ lastMediaImportance,
175
+ shouldPrintDebug
176
+ );
177
+ if (shouldPrintDebug && mediaExtraction && console.info(
178
+ "ternary (mediaStyles)",
179
+ mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? "",
180
+ mediaExtraction.mediaStyles.map((x) => x[helpers.StyleObjectIdentifier]).join(".")
181
+ ), !mediaExtraction) {
182
+ shouldPrintDebug && mediaExtraction && console.info("add ternary"), addTernaryStyle(
183
+ attr.value,
184
+ addStyles(attr.value.consequent),
185
+ addStyles(attr.value.alternate)
186
+ );
187
+ continue;
188
+ }
189
+ lastMediaImportance++, mediaExtraction.mediaStyles && (finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]), mediaExtraction.ternaryWithoutMedia ? addTernaryStyle(
190
+ mediaExtraction.ternaryWithoutMedia,
191
+ mediaExtraction.mediaStyles,
192
+ []
193
+ ) : finalClassNames = [
194
+ ...finalClassNames,
195
+ ...mediaExtraction.mediaStyles.map(
196
+ (x) => t.stringLiteral(x[helpers.StyleObjectIdentifier])
197
+ )
198
+ ];
199
+ break;
200
+ }
201
+ }
202
+ function addTernaryStyle(ternary, a, b) {
203
+ const cCN = a.map((x) => x[helpers.StyleObjectIdentifier]).join(" "), aCN = b.map((x) => x[helpers.StyleObjectIdentifier]).join(" ");
204
+ a.length && b.length ? finalClassNames.push(
205
+ t.conditionalExpression(
206
+ ternary.test,
207
+ t.stringLiteral(cCN),
208
+ t.stringLiteral(aCN)
209
+ )
210
+ ) : finalClassNames.push(
211
+ t.conditionalExpression(
212
+ ternary.test,
213
+ t.stringLiteral(" " + cCN),
214
+ t.stringLiteral(" " + aCN)
215
+ )
216
+ );
217
+ }
218
+ if (shouldPrintDebug === "verbose" && console.info(` finalClassNames AST
219
+ `, JSON.stringify(finalClassNames, null, 2)), node.attributes = finalAttrs, finalClassNames.length) {
220
+ const extraClassNames = (() => {
221
+ let value = "";
222
+ return isFlattened && (process.env.TAMAGUI_DEBUG_OPTIMIZATIONS && (value += "is_tamagui_flattened"), staticConfig.componentName && (value += ` is_${staticConfig.componentName}`)), value;
223
+ })(), names = (0, import_buildClassName.buildClassName)(finalClassNames, extraClassNames), nameExpr = names ? (0, import_hoistClassNames.hoistClassNames)(jsxPath, existingHoists, names) : null;
224
+ let expr = nameExpr;
225
+ if (nameExpr && !t.isIdentifier(nameExpr) && didFlattenThisTag) {
226
+ (0, import_ensureImportingConcat.ensureImportingConcat)(programPath);
227
+ const simpleSpreads = attrs.filter((x) => x.type === "attr" && t.isJSXSpreadAttribute(x.value) && (0, import_extractHelpers.isSimpleSpread)(x.value));
228
+ expr = t.callExpression(t.identifier("concatClassName"), [
229
+ expr,
230
+ ...simpleSpreads.map((val) => val.value.argument)
231
+ ]);
232
+ }
233
+ node.attributes.push(
234
+ t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr))
235
+ );
236
+ }
237
+ const comment = util.format(
238
+ "/* %s:%s (%s) */",
239
+ filePath,
240
+ lineNumbers,
241
+ originalNodeName
242
+ );
243
+ for (const styleObject of finalStyles) {
244
+ const identifier = styleObject[helpers.StyleObjectIdentifier], rules = styleObject[helpers.StyleObjectRules], className = `.${identifier}`;
245
+ if (cssMap.has(className)) {
246
+ if (comment) {
247
+ const val = cssMap.get(className);
248
+ val.commentTexts.push(comment), cssMap.set(className, val);
249
+ }
250
+ } else rules.length && cssMap.set(className, {
251
+ css: rules.join(`
252
+ `),
253
+ commentTexts: [comment]
254
+ });
255
+ }
256
+ }
257
+ });
258
+ if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled)
259
+ return shouldPrintDebug && console.info("no res or none modified", res), null;
260
+ const styles = Array.from(cssMap.values()).map((x) => x.css).join(`
261
+ `).trim(), result = (0, import_generator.default)(
262
+ ast,
263
+ {
264
+ concise: !1,
265
+ filename: sourcePath,
266
+ // this makes the debug output terrible, and i think sourcemap works already
267
+ retainLines: !1,
268
+ sourceFileName: sourcePath,
269
+ sourceMaps: !0
270
+ },
271
+ source
272
+ );
273
+ return shouldPrintDebug && (console.info(
274
+ `
275
+ -------- output code -------
276
+
277
+ `,
278
+ result.code.split(`
279
+ `).filter((x) => !x.startsWith("//")).join(`
280
+ `)
281
+ ), console.info(`
282
+ -------- output style --------
283
+
284
+ `, styles)), printLog(res), {
285
+ ast,
286
+ styles,
287
+ js: result.code,
288
+ map: result.map
289
+ };
290
+ }
291
+ //# sourceMappingURL=extractToClassNames.js.map
@@ -0,0 +1,319 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var extractToNative_exports = {};
24
+ __export(extractToNative_exports, {
25
+ extractToNative: () => extractToNative,
26
+ getBabelParseDefinition: () => getBabelParseDefinition,
27
+ getBabelPlugin: () => getBabelPlugin
28
+ });
29
+ module.exports = __toCommonJS(extractToNative_exports);
30
+ var import_node_path = require("node:path"), import_core = require("@babel/core"), import_generator = __toESM(require("@babel/generator")), import_helper_plugin_utils = require("@babel/helper-plugin-utils"), import_parser = require("@babel/parser"), import_template = __toESM(require("@babel/template")), t = __toESM(require("@babel/types")), import_createExtractor = require("./createExtractor"), import_getPragmaOptions = require("../getPragmaOptions"), import_createLogger = require("./createLogger"), import_extractHelpers = require("./extractHelpers"), import_literalToAst = require("./literalToAst"), import_loadTamagui = require("./loadTamagui");
31
+ const importNativeView = (0, import_template.default)(`
32
+ const __ReactNativeView = require('react-native').View;
33
+ const __ReactNativeText = require('react-native').Text;
34
+ `), importStyleSheet = (0, import_template.default)(`
35
+ const __ReactNativeStyleSheet = require('react-native').StyleSheet;
36
+ `), importWithStyle = (0, import_template.default)(`
37
+ const __withStableStyle = require('@tamagui/core')._withStableStyle;
38
+ `), extractor = (0, import_createExtractor.createExtractor)({ platform: "native" });
39
+ let tamaguiBuildOptionsLoaded;
40
+ function extractToNative(sourceFileName, sourceCode, options) {
41
+ const ast = (0, import_parser.parse)(sourceCode, {
42
+ sourceType: "module",
43
+ plugins: ["jsx", "typescript"]
44
+ }), babelPlugin = getBabelPlugin(), out = (0, import_core.transformFromAstSync)(ast, sourceCode, {
45
+ plugins: [[babelPlugin, options]],
46
+ configFile: !1,
47
+ sourceFileName,
48
+ filename: sourceFileName
49
+ });
50
+ if (!out)
51
+ throw new Error("No output returned");
52
+ return out;
53
+ }
54
+ function getBabelPlugin() {
55
+ return (0, import_helper_plugin_utils.declare)((api, options) => (api.assertVersion(7), getBabelParseDefinition(options)));
56
+ }
57
+ function getBabelParseDefinition(options) {
58
+ return {
59
+ name: "tamagui",
60
+ visitor: {
61
+ Program: {
62
+ enter(root) {
63
+ let sourcePath = this.file.opts.filename;
64
+ if (sourcePath?.includes("node_modules") || !sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx"))
65
+ return;
66
+ process.env.SOURCE_ROOT?.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
67
+ let hasImportedView = !1, hasImportedViewWrapper = !1;
68
+ const sheetStyles = {}, sheetIdentifier = root.scope.generateUidIdentifier("sheet"), firstCommentContents = (
69
+ // join because you can join together multiple pragmas
70
+ root.node.body[0]?.leadingComments?.map((comment) => comment?.value || " ").join(" ") ?? ""
71
+ ), firstComment = firstCommentContents ? `//${firstCommentContents}` : "", { shouldPrintDebug, shouldDisable } = (0, import_getPragmaOptions.getPragmaOptions)({
72
+ source: firstComment,
73
+ path: sourcePath
74
+ });
75
+ if (shouldDisable)
76
+ return;
77
+ !options.config && !options.components && (tamaguiBuildOptionsLoaded ||= (0, import_loadTamagui.loadTamaguiBuildConfigSync)({}));
78
+ const finalOptions = {
79
+ // @ts-ignore just in case they leave it out
80
+ platform: "native",
81
+ ...tamaguiBuildOptionsLoaded,
82
+ ...options
83
+ }, printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
84
+ function addSheetStyle(style, node) {
85
+ let key = `${`${Object.keys(sheetStyles).length}`}`;
86
+ if (process.env.NODE_ENV === "development") {
87
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
88
+ key += `:${(0, import_node_path.basename)(sourcePath)}:${lineNumbers}`;
89
+ }
90
+ return sheetStyles[key] = style, readStyleExpr(key);
91
+ }
92
+ function readStyleExpr(key) {
93
+ return (0, import_template.default)("SHEET['KEY']")({
94
+ SHEET: sheetIdentifier.name,
95
+ KEY: key
96
+ }).expression;
97
+ }
98
+ let res;
99
+ try {
100
+ res = extractor.parseSync(root, {
101
+ importsWhitelist: ["constants.js", "colors.js"],
102
+ extractStyledDefinitions: options.forceExtractStyleDefinitions,
103
+ excludeProps: /* @__PURE__ */ new Set([
104
+ "className",
105
+ "userSelect",
106
+ "whiteSpace",
107
+ "textOverflow",
108
+ "cursor",
109
+ "contain"
110
+ ]),
111
+ shouldPrintDebug,
112
+ ...finalOptions,
113
+ // disable this extraction for now at least, need to figure out merging theme vs non-theme
114
+ // because theme need to stay in render(), whereas non-theme can be extracted
115
+ // for now just turn it off entirely at a small perf loss
116
+ disableExtractInlineMedia: !0,
117
+ // disable extracting variables as no native concept of them (only theme values)
118
+ disableExtractVariables: options.experimentalFlattenThemesOnNative ? !1 : "theme",
119
+ sourcePath,
120
+ // disabling flattening for now
121
+ // it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
122
+ // thinking it's not really worth the effort to do much compilation on native
123
+ // for now just disable flatten as it can only run in narrow places on native
124
+ // disableFlattening: 'styled',
125
+ getFlattenedNode({ isTextView }) {
126
+ return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
127
+ },
128
+ onExtractTag(props) {
129
+ const { isFlattened } = props;
130
+ if (!isFlattened)
131
+ return;
132
+ assertValidTag(props.node);
133
+ const stylesExpr = t.arrayExpression([]), hocStylesExpr = t.arrayExpression([]), expressions = [], finalAttrs = [], themeKeysUsed = /* @__PURE__ */ new Set();
134
+ function getStyleExpression(style) {
135
+ if (!style) return;
136
+ const { plain, themed } = splitThemeStyles(style);
137
+ let themeExpr = null;
138
+ if (themed && options.experimentalFlattenThemesOnNative) {
139
+ for (const key in themed)
140
+ themeKeysUsed.add(themed[key].split("$")[1]);
141
+ themeExpr = getThemedStyleExpression(themed);
142
+ }
143
+ const ident = addSheetStyle(plain, props.node);
144
+ return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
145
+ }
146
+ function addStyleExpression(expr, HOC = !1) {
147
+ Array.isArray(expr) ? (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr) : (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
148
+ }
149
+ function getThemedStyleExpression(styles) {
150
+ const themedStylesAst = (0, import_literalToAst.literalToAst)(styles);
151
+ return themedStylesAst.properties.forEach((_) => {
152
+ const prop = _;
153
+ prop.value.type === "StringLiteral" && (prop.value = t.memberExpression(
154
+ t.identifier("theme"),
155
+ t.identifier(prop.value.value.slice(1) + ".get()")
156
+ ));
157
+ }), themedStylesAst;
158
+ }
159
+ let hasDynamicStyle = !1;
160
+ for (const attr of props.attrs)
161
+ switch (attr.type) {
162
+ case "style": {
163
+ let styleExpr = getStyleExpression(attr.value);
164
+ addStyleExpression(styleExpr), options.experimentalFlattenThemesOnNative && addStyleExpression(styleExpr, !0);
165
+ break;
166
+ }
167
+ case "ternary": {
168
+ const { consequent, alternate } = attr.value, consExpr = getStyleExpression(consequent), altExpr = getStyleExpression(alternate);
169
+ options.experimentalFlattenThemesOnNative && (expressions.push(attr.value.test), addStyleExpression(
170
+ t.conditionalExpression(
171
+ t.identifier(`_expressions[${expressions.length - 1}]`),
172
+ consExpr || t.nullLiteral(),
173
+ altExpr || t.nullLiteral()
174
+ ),
175
+ !0
176
+ ));
177
+ const styleExpr = t.conditionalExpression(
178
+ attr.value.test,
179
+ consExpr || t.nullLiteral(),
180
+ altExpr || t.nullLiteral()
181
+ );
182
+ addStyleExpression(
183
+ styleExpr
184
+ // TODO: what is this for ?
185
+ // isFlattened ? simpleHash(JSON.stringify({ consequent, alternate })) : undefined
186
+ );
187
+ break;
188
+ }
189
+ case "dynamic-style": {
190
+ hasDynamicStyle = !0, expressions.push(attr.value), options.experimentalFlattenDynamicValues ? addStyleExpression(
191
+ t.objectExpression([
192
+ t.objectProperty(
193
+ t.identifier(attr.name),
194
+ t.identifier(`_expressions[${expressions.length - 1}]`)
195
+ )
196
+ ]),
197
+ !0
198
+ ) : addStyleExpression(
199
+ t.objectExpression([
200
+ t.objectProperty(
201
+ t.identifier(attr.name),
202
+ attr.value
203
+ )
204
+ ])
205
+ );
206
+ break;
207
+ }
208
+ case "attr": {
209
+ t.isJSXSpreadAttribute(attr.value) && (0, import_extractHelpers.isSimpleSpread)(attr.value) && (stylesExpr.elements.push(
210
+ t.memberExpression(attr.value.argument, t.identifier("style"))
211
+ ), options.experimentalFlattenThemesOnNative && hocStylesExpr.elements.push(
212
+ t.memberExpression(
213
+ attr.value.argument,
214
+ t.identifier("style")
215
+ )
216
+ )), finalAttrs.push(attr.value);
217
+ break;
218
+ }
219
+ }
220
+ if (props.node.attributes = finalAttrs, props.isFlattened)
221
+ if (options.experimentalFlattenThemesOnNative && (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle)) {
222
+ hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle()), hasImportedViewWrapper = !0);
223
+ const name = props.node.name.name, WrapperIdentifier = root.scope.generateUidIdentifier(
224
+ name + "Wrapper"
225
+ );
226
+ root.pushContainer(
227
+ "body",
228
+ t.variableDeclaration("const", [
229
+ t.variableDeclarator(
230
+ WrapperIdentifier,
231
+ t.callExpression(t.identifier("__withStableStyle"), [
232
+ t.identifier(name),
233
+ t.arrowFunctionExpression(
234
+ [t.identifier("theme"), t.identifier("_expressions")],
235
+ t.blockStatement([
236
+ t.returnStatement(
237
+ t.callExpression(
238
+ t.memberExpression(
239
+ t.identifier("React"),
240
+ t.identifier("useMemo")
241
+ ),
242
+ [
243
+ t.arrowFunctionExpression(
244
+ [],
245
+ t.blockStatement([
246
+ t.returnStatement(
247
+ t.arrayExpression([...hocStylesExpr.elements])
248
+ )
249
+ ])
250
+ ),
251
+ t.arrayExpression([
252
+ t.spreadElement(t.identifier("_expressions"))
253
+ ])
254
+ ]
255
+ )
256
+ )
257
+ ])
258
+ )
259
+ ])
260
+ )
261
+ ])
262
+ ), props.node.name = WrapperIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = WrapperIdentifier), expressions.length && props.node.attributes.push(
263
+ t.jsxAttribute(
264
+ t.jsxIdentifier("expressions"),
265
+ t.jsxExpressionContainer(t.arrayExpression(expressions))
266
+ )
267
+ );
268
+ } else
269
+ props.node.attributes.push(
270
+ t.jsxAttribute(
271
+ t.jsxIdentifier("style"),
272
+ t.jsxExpressionContainer(
273
+ stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr
274
+ )
275
+ )
276
+ );
277
+ }
278
+ });
279
+ } catch (err) {
280
+ if (err instanceof Error) {
281
+ let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
282
+ message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Tamagui parse, skipping", message, err.stack);
283
+ return;
284
+ }
285
+ }
286
+ if (!Object.keys(sheetStyles).length) {
287
+ shouldPrintDebug && console.info("END no styles"), res && printLog(res);
288
+ return;
289
+ }
290
+ const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles), sheetOuter = (0, import_template.default)(
291
+ "const SHEET = __ReactNativeStyleSheet.create(null)"
292
+ )({
293
+ SHEET: sheetIdentifier.name
294
+ });
295
+ sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
296
+ -------- output code -------
297
+ `), console.info(
298
+ (0, import_generator.default)(root.parent).code.split(`
299
+ `).filter((x) => !x.startsWith("//")).join(`
300
+ `)
301
+ )), res && printLog(res);
302
+ }
303
+ }
304
+ }
305
+ };
306
+ }
307
+ function assertValidTag(node) {
308
+ node.attributes.find((x) => x.type === "JSXAttribute" && x.name.name === "style") && process.env.DEBUG?.startsWith("tamagui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
309
+ }
310
+ function splitThemeStyles(style) {
311
+ const themed = {}, plain = {};
312
+ let noTheme = !0;
313
+ for (const key in style) {
314
+ const val = style[key];
315
+ val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
316
+ }
317
+ return { themed: noTheme ? null : themed, plain };
318
+ }
319
+ //# sourceMappingURL=extractToNative.js.map
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var findTopmostFunction_exports = {};
16
+ __export(findTopmostFunction_exports, {
17
+ findTopmostFunction: () => findTopmostFunction
18
+ });
19
+ module.exports = __toCommonJS(findTopmostFunction_exports);
20
+ function findTopmostFunction(jsxPath) {
21
+ const isFunction = (path) => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
22
+ let compFn = jsxPath.findParent(isFunction);
23
+ for (; compFn; ) {
24
+ const parent = compFn.findParent(isFunction);
25
+ if (parent)
26
+ compFn = parent;
27
+ else
28
+ break;
29
+ }
30
+ return compFn || null;
31
+ }
32
+ //# sourceMappingURL=findTopmostFunction.js.map