@tamagui/static 1.0.0-alpha.5 → 1.0.0-alpha.53

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 (209) hide show
  1. package/dist/cjs/constants.js +43 -0
  2. package/dist/cjs/constants.js.map +7 -0
  3. package/dist/cjs/extractor/accessSafe.js +39 -0
  4. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  5. package/dist/cjs/extractor/babelParse.js +58 -0
  6. package/dist/cjs/extractor/babelParse.js.map +7 -0
  7. package/dist/cjs/extractor/buildClassName.js +68 -0
  8. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  9. package/dist/cjs/extractor/createEvaluator.js +79 -0
  10. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  11. package/dist/cjs/extractor/createExtractor.js +919 -0
  12. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  13. package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  15. package/dist/cjs/extractor/evaluateAstNode.js +122 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  17. package/dist/cjs/extractor/extractHelpers.js +124 -0
  18. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  19. package/dist/cjs/extractor/extractMediaStyle.js +193 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  21. package/dist/cjs/extractor/extractToClassNames.js +289 -0
  22. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  23. package/dist/cjs/extractor/findTopmostFunction.js +46 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  25. package/dist/cjs/extractor/generatedUid.js +56 -0
  26. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  27. package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
  28. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  29. package/dist/cjs/extractor/getSourceModule.js +97 -0
  30. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  31. package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
  32. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  33. package/dist/cjs/extractor/hoistClassNames.js +72 -0
  34. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  35. package/dist/cjs/extractor/literalToAst.js +62 -0
  36. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  37. package/dist/cjs/extractor/loadTamagui.js +67 -0
  38. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  39. package/dist/cjs/extractor/logLines.js +40 -0
  40. package/dist/cjs/extractor/logLines.js.map +7 -0
  41. package/dist/cjs/extractor/normalizeTernaries.js +108 -0
  42. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  43. package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
  44. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  45. package/dist/cjs/index.js +38 -0
  46. package/dist/cjs/index.js.map +7 -0
  47. package/dist/cjs/patchReactNativeWeb.js +157 -0
  48. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  49. package/dist/cjs/types.js +21 -0
  50. package/dist/cjs/types.js.map +7 -0
  51. package/dist/{constants.js → esm/constants.js} +4 -0
  52. package/dist/{constants.js.map → esm/constants.js.map} +3 -3
  53. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  54. package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
  55. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  56. package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
  57. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  58. package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
  59. package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
  60. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  61. package/dist/{extractor → esm/extractor}/createExtractor.js +128 -76
  62. package/dist/esm/extractor/createExtractor.js.map +7 -0
  63. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
  64. package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
  65. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  66. package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
  67. package/dist/{extractor → esm/extractor}/extractHelpers.js +6 -4
  68. package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +38 -35
  72. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  73. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  74. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
  75. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  76. package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
  77. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  78. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
  79. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  80. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
  81. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  82. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
  83. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  84. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
  85. package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
  86. package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
  87. package/dist/{extractor → esm/extractor}/loadTamagui.js +5 -2
  88. package/dist/esm/extractor/loadTamagui.js.map +7 -0
  89. package/dist/esm/extractor/logLines.js +17 -0
  90. package/dist/esm/extractor/logLines.js.map +7 -0
  91. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
  92. package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
  93. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
  94. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
  95. package/dist/{index.js → esm/index.js} +0 -0
  96. package/dist/{index.js.map → esm/index.js.map} +1 -1
  97. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +40 -3
  98. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  99. package/dist/{types.js → esm/types.js} +0 -0
  100. package/dist/{types.js.map → esm/types.js.map} +0 -0
  101. package/dist/jsx/constants.js +13 -0
  102. package/dist/jsx/extractor/accessSafe.js +10 -0
  103. package/dist/jsx/extractor/babelParse.js +29 -0
  104. package/dist/jsx/extractor/buildClassName.js +39 -0
  105. package/dist/jsx/extractor/createEvaluator.js +50 -0
  106. package/dist/jsx/extractor/createExtractor.js +856 -0
  107. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  108. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  109. package/dist/jsx/extractor/extractHelpers.js +95 -0
  110. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  111. package/dist/jsx/extractor/extractToClassNames.js +245 -0
  112. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  113. package/dist/jsx/extractor/generatedUid.js +27 -0
  114. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  115. package/dist/jsx/extractor/getSourceModule.js +68 -0
  116. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  117. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  118. package/dist/jsx/extractor/literalToAst.js +33 -0
  119. package/dist/jsx/extractor/loadTamagui.js +43 -0
  120. package/dist/jsx/extractor/logLines.js +16 -0
  121. package/dist/jsx/extractor/normalizeTernaries.js +52 -0
  122. package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
  123. package/dist/jsx/index.js +13 -0
  124. package/dist/jsx/patchReactNativeWeb.js +128 -0
  125. package/dist/jsx/types.js +0 -0
  126. package/package.json +25 -19
  127. package/types/constants.d.ts +6 -0
  128. package/types/constants.d.ts.map +1 -0
  129. package/types/extractor/accessSafe.d.ts +3 -0
  130. package/types/extractor/accessSafe.d.ts.map +1 -0
  131. package/types/extractor/babelParse.d.ts +5 -0
  132. package/types/extractor/babelParse.d.ts.map +1 -0
  133. package/types/extractor/buildClassName.d.ts +4 -0
  134. package/types/extractor/buildClassName.d.ts.map +1 -0
  135. package/types/extractor/createEvaluator.d.ts +12 -0
  136. package/types/extractor/createEvaluator.d.ts.map +1 -0
  137. package/types/extractor/createExtractor.d.ts +33 -0
  138. package/types/extractor/createExtractor.d.ts.map +1 -0
  139. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  140. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  141. package/types/extractor/evaluateAstNode.d.ts +3 -0
  142. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  143. package/types/extractor/extractHelpers.d.ts +12 -0
  144. package/types/extractor/extractHelpers.d.ts.map +1 -0
  145. package/types/extractor/extractMediaStyle.d.ts +10 -0
  146. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  147. package/types/extractor/extractToClassNames.d.ts +21 -0
  148. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  149. package/types/extractor/findTopmostFunction.d.ts +4 -0
  150. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  151. package/types/extractor/generatedUid.d.ts +5 -0
  152. package/types/extractor/generatedUid.d.ts.map +1 -0
  153. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  154. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  155. package/types/extractor/getSourceModule.d.ts +16 -0
  156. package/types/extractor/getSourceModule.d.ts.map +1 -0
  157. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  158. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  159. package/types/extractor/hoistClassNames.d.ts +6 -0
  160. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  161. package/types/extractor/literalToAst.d.ts +3 -0
  162. package/types/extractor/literalToAst.d.ts.map +1 -0
  163. package/types/extractor/loadTamagui.d.ts +9 -0
  164. package/types/extractor/loadTamagui.d.ts.map +1 -0
  165. package/types/extractor/logLines.d.ts +2 -0
  166. package/types/extractor/logLines.d.ts.map +1 -0
  167. package/types/extractor/normalizeTernaries.d.ts +3 -0
  168. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  169. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  170. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  171. package/types/index.d.ts +8 -0
  172. package/types/index.d.ts.map +1 -0
  173. package/types/patchReactNativeWeb.d.ts +2 -0
  174. package/types/patchReactNativeWeb.d.ts.map +1 -0
  175. package/types/types.d.ts +79 -0
  176. package/types/types.d.ts.map +1 -0
  177. package/dist/extractor/createEvaluator.js.map +0 -7
  178. package/dist/extractor/createExtractor.js.map +0 -7
  179. package/dist/extractor/ensureImportingConcat.js.map +0 -7
  180. package/dist/extractor/extractToClassNames.js.map +0 -7
  181. package/dist/extractor/loadTamagui.js.map +0 -7
  182. package/dist/index.cjs +0 -2085
  183. package/dist/index.cjs.map +0 -7
  184. package/dist/patchReactNativeWeb.js.map +0 -7
  185. package/src/constants.ts +0 -10
  186. package/src/extractor/accessSafe.ts +0 -18
  187. package/src/extractor/babelParse.ts +0 -27
  188. package/src/extractor/buildClassName.ts +0 -61
  189. package/src/extractor/createEvaluator.ts +0 -68
  190. package/src/extractor/createExtractor.ts +0 -1116
  191. package/src/extractor/ensureImportingConcat.ts +0 -33
  192. package/src/extractor/evaluateAstNode.ts +0 -121
  193. package/src/extractor/extractHelpers.ts +0 -102
  194. package/src/extractor/extractMediaStyle.ts +0 -191
  195. package/src/extractor/extractToClassNames.ts +0 -337
  196. package/src/extractor/findTopmostFunction.ts +0 -22
  197. package/src/extractor/generatedUid.ts +0 -43
  198. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  199. package/src/extractor/getSourceModule.ts +0 -101
  200. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  201. package/src/extractor/hoistClassNames.ts +0 -45
  202. package/src/extractor/literalToAst.ts +0 -32
  203. package/src/extractor/loadTamagui.ts +0 -61
  204. package/src/extractor/normalizeTernaries.ts +0 -60
  205. package/src/extractor/removeUnusedHooks.ts +0 -76
  206. package/src/index.ts +0 -9
  207. package/src/patchReactNativeWeb.ts +0 -107
  208. package/src/types.ts +0 -80
  209. package/types.d.ts +0 -210
package/dist/index.cjs DELETED
@@ -1,2085 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
26
- var __objRest = (source, exclude) => {
27
- var target = {};
28
- for (var prop in source)
29
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
- target[prop] = source[prop];
31
- if (source != null && __getOwnPropSymbols)
32
- for (var prop of __getOwnPropSymbols(source)) {
33
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
- target[prop] = source[prop];
35
- }
36
- return target;
37
- };
38
- var __export = (target, all) => {
39
- __markAsModule(target);
40
- for (var name in all)
41
- __defProp(target, name, { get: all[name], enumerable: true });
42
- };
43
- var __reExport = (target, module2, desc) => {
44
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
45
- for (let key of __getOwnPropNames(module2))
46
- if (!__hasOwnProp.call(target, key) && key !== "default")
47
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
48
- }
49
- return target;
50
- };
51
- var __toModule = (module2) => {
52
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
53
- };
54
-
55
- // src/index.ts
56
- __export(exports, {
57
- CONCAT_CLASSNAME_IMPORT: () => CONCAT_CLASSNAME_IMPORT,
58
- CSS_FILE_NAME: () => CSS_FILE_NAME,
59
- MEDIA_SEP: () => MEDIA_SEP,
60
- attrStr: () => attrStr,
61
- cacheDir: () => cacheDir,
62
- createExtractor: () => createExtractor,
63
- extractToClassNames: () => extractToClassNames,
64
- findComponentName: () => findComponentName,
65
- isInsideTamagui: () => isInsideTamagui,
66
- isPresent: () => isPresent,
67
- isSimpleSpread: () => isSimpleSpread,
68
- isValidThemeHook: () => isValidThemeHook,
69
- literalToAst: () => literalToAst,
70
- objToStr: () => objToStr,
71
- patchReactNativeWeb: () => patchReactNativeWeb,
72
- ternaryStr: () => ternaryStr
73
- });
74
-
75
- // src/extractor/createExtractor.ts
76
- var import_traverse = __toModule(require("@babel/traverse"));
77
- var t9 = __toModule(require("@babel/types"));
78
- var CoreNode = __toModule(require("@tamagui/core-node"));
79
- var import_helpers = __toModule(require("@tamagui/helpers"));
80
- var import_lodash = __toModule(require("lodash"));
81
-
82
- // src/extractor/createEvaluator.ts
83
- var import_vm = __toModule(require("vm"));
84
- var import_generator = __toModule(require("@babel/generator"));
85
- var t3 = __toModule(require("@babel/types"));
86
-
87
- // src/extractor/evaluateAstNode.ts
88
- var t = __toModule(require("@babel/types"));
89
- function evaluateAstNode(exprNode, evalFn, shouldPrintDebug) {
90
- if (exprNode === void 0) {
91
- return void 0;
92
- }
93
- if (exprNode === null) {
94
- return true;
95
- }
96
- if (t.isJSXExpressionContainer(exprNode)) {
97
- return evaluateAstNode(exprNode.expression);
98
- }
99
- if (t.isObjectExpression(exprNode)) {
100
- const ret = {};
101
- for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
102
- const value = exprNode.properties[idx];
103
- if (!t.isObjectProperty(value)) {
104
- throw new Error("evaluateAstNode can only evaluate object properties");
105
- }
106
- let key;
107
- if (value.computed) {
108
- if (typeof evalFn !== "function") {
109
- throw new Error("evaluateAstNode does not support computed keys unless an eval function is provided");
110
- }
111
- key = evaluateAstNode(value.key, evalFn);
112
- } else if (t.isIdentifier(value.key)) {
113
- key = value.key.name;
114
- } else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {
115
- key = value.key.value;
116
- } else {
117
- throw new Error("Unsupported key type: " + value.key.type);
118
- }
119
- if (typeof key !== "string" && typeof key !== "number") {
120
- throw new Error("key must be either a string or a number");
121
- }
122
- ret[key] = evaluateAstNode(value.value, evalFn);
123
- }
124
- return ret;
125
- }
126
- if (t.isArrayExpression(exprNode)) {
127
- return exprNode.elements.map((x) => {
128
- return evaluateAstNode(x, evalFn);
129
- });
130
- }
131
- if (t.isUnaryExpression(exprNode) && exprNode.operator === "-") {
132
- const ret = evaluateAstNode(exprNode.argument, evalFn);
133
- if (ret == null) {
134
- return null;
135
- }
136
- return -ret;
137
- }
138
- if (t.isTemplateLiteral(exprNode)) {
139
- if (typeof evalFn !== "function") {
140
- throw new Error("evaluateAstNode does not support template literals unless an eval function is provided");
141
- }
142
- let ret = "";
143
- for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {
144
- const quasi = exprNode.quasis[idx];
145
- const expr = exprNode.expressions[idx];
146
- ret += quasi.value.raw;
147
- if (expr) {
148
- ret += evaluateAstNode(expr, evalFn);
149
- }
150
- }
151
- return ret;
152
- }
153
- if (t.isNullLiteral(exprNode)) {
154
- return null;
155
- }
156
- if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {
157
- return exprNode.value;
158
- }
159
- if (t.isBinaryExpression(exprNode)) {
160
- if (exprNode.operator === "+") {
161
- return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn);
162
- } else if (exprNode.operator === "-") {
163
- return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn);
164
- } else if (exprNode.operator === "*") {
165
- return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn);
166
- } else if (exprNode.operator === "/") {
167
- return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn);
168
- }
169
- }
170
- if (typeof evalFn !== "function") {
171
- throw new Error("evaluateAstNode does not support non-literal values unless an eval function is provided");
172
- }
173
- return evalFn(exprNode);
174
- }
175
- __name(evaluateAstNode, "evaluateAstNode");
176
-
177
- // src/extractor/extractHelpers.ts
178
- var t2 = __toModule(require("@babel/types"));
179
- function isPresent(input) {
180
- return input != null;
181
- }
182
- __name(isPresent, "isPresent");
183
- function isSimpleSpread(node) {
184
- return t2.isIdentifier(node.argument) || t2.isMemberExpression(node.argument);
185
- }
186
- __name(isSimpleSpread, "isSimpleSpread");
187
- var attrStr = /* @__PURE__ */ __name((attr) => {
188
- return attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
189
- }, "attrStr");
190
- var objToStr = /* @__PURE__ */ __name((obj) => {
191
- return Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : v}`).join(", ");
192
- }, "objToStr");
193
- var getNameAttr = /* @__PURE__ */ __name((attr) => {
194
- if (t2.isJSXSpreadAttribute(attr)) {
195
- return `...${attr.argument["name"]}`;
196
- }
197
- return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
198
- }, "getNameAttr");
199
- var ternaryStr = /* @__PURE__ */ __name((x) => {
200
- return [
201
- "ternary:",
202
- t2.isIdentifier(x.test) ? x.test.name : t2.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : x.test,
203
- x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u26AB\uFE0F",
204
- x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u26AB\uFE0F"
205
- ].flat().join("");
206
- }, "ternaryStr");
207
- function findComponentName(scope) {
208
- var _a;
209
- let componentName = "";
210
- let cur = scope.path;
211
- while (cur.parentPath && !t2.isProgram(cur.parentPath.parent)) {
212
- cur = cur.parentPath;
213
- }
214
- let node = cur.parent;
215
- if (t2.isExportNamedDeclaration(node)) {
216
- node = node.declaration;
217
- }
218
- if (t2.isVariableDeclaration(node)) {
219
- const [dec] = node.declarations;
220
- if (t2.isVariableDeclarator(dec) && t2.isIdentifier(dec.id)) {
221
- return dec.id.name;
222
- }
223
- }
224
- if (t2.isFunctionDeclaration(node)) {
225
- return (_a = node.id) == null ? void 0 : _a.name;
226
- }
227
- return componentName;
228
- }
229
- __name(findComponentName, "findComponentName");
230
- function isValidThemeHook(jsxPath, n, sourcePath) {
231
- var _a;
232
- if (!t2.isIdentifier(n.object) || !t2.isIdentifier(n.property))
233
- return false;
234
- const bindings = jsxPath.scope.getAllBindings();
235
- const binding = bindings[n.object.name];
236
- if (!(binding == null ? void 0 : binding.path))
237
- return false;
238
- if (!binding.path.isVariableDeclarator())
239
- return false;
240
- const init = binding.path.node.init;
241
- if (!t2.isCallExpression(init))
242
- return false;
243
- if (!t2.isIdentifier(init.callee))
244
- return false;
245
- if (init.callee.name !== "useTheme")
246
- return false;
247
- const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
248
- if (!t2.isImportDeclaration(importNode))
249
- return false;
250
- if (importNode.source.value !== "tamagui") {
251
- if (!isInsideTamagui(sourcePath)) {
252
- return false;
253
- }
254
- }
255
- return true;
256
- }
257
- __name(isValidThemeHook, "isValidThemeHook");
258
- var isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
259
- return srcName.includes("/tamagui/_jsx") || srcName.includes("/core/src");
260
- }, "isInsideTamagui");
261
-
262
- // src/extractor/createEvaluator.ts
263
- function createEvaluator({
264
- tamaguiConfig,
265
- staticNamespace,
266
- sourcePath,
267
- traversePath,
268
- shouldPrintDebug
269
- }) {
270
- const evalFn = /* @__PURE__ */ __name((n) => {
271
- if (t3.isMemberExpression(n) && t3.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {
272
- const key = n.property.name;
273
- if (shouldPrintDebug) {
274
- console.log(" > found theme prop", key);
275
- }
276
- console.log("SHOULD FIND THEME (NESTED NOW)", key);
277
- return `var(--${key})`;
278
- }
279
- if (t3.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {
280
- return staticNamespace[n.name];
281
- }
282
- const evalContext = import_vm.default.createContext(staticNamespace);
283
- const code = `(${(0, import_generator.default)(n).code})`;
284
- return import_vm.default.runInContext(code, evalContext);
285
- }, "evalFn");
286
- return (n) => {
287
- return evaluateAstNode(n, evalFn);
288
- };
289
- }
290
- __name(createEvaluator, "createEvaluator");
291
- function createSafeEvaluator(attemptEval) {
292
- return (n) => {
293
- try {
294
- return attemptEval(n);
295
- } catch (err) {
296
- return FAILED_EVAL;
297
- }
298
- };
299
- }
300
- __name(createSafeEvaluator, "createSafeEvaluator");
301
-
302
- // src/extractor/findTopmostFunction.ts
303
- function findTopmostFunction(jsxPath) {
304
- const isFunction = /* @__PURE__ */ __name((path3) => path3.isArrowFunctionExpression() || path3.isFunctionDeclaration() || path3.isFunctionExpression(), "isFunction");
305
- let compFn = jsxPath.findParent(isFunction);
306
- while (compFn) {
307
- const parent = compFn.findParent(isFunction);
308
- if (parent) {
309
- compFn = parent;
310
- } else {
311
- break;
312
- }
313
- }
314
- if (!compFn) {
315
- return null;
316
- }
317
- return compFn;
318
- }
319
- __name(findTopmostFunction, "findTopmostFunction");
320
-
321
- // src/extractor/getStaticBindingsForScope.ts
322
- var import_path = __toModule(require("path"));
323
- var t5 = __toModule(require("@babel/types"));
324
- var import_fs_extra = __toModule(require("fs-extra"));
325
-
326
- // src/extractor/getSourceModule.ts
327
- var t4 = __toModule(require("@babel/types"));
328
- function getSourceModule(itemName, itemBinding) {
329
- if (!itemBinding.constant) {
330
- return null;
331
- }
332
- let sourceModule;
333
- let imported;
334
- let local;
335
- let destructured;
336
- let usesImportSyntax = false;
337
- const itemNode = itemBinding.path.node;
338
- if (t4.isImportDefaultSpecifier(itemNode) || t4.isImportSpecifier(itemNode)) {
339
- if (t4.isImportDeclaration(itemBinding.path.parent)) {
340
- sourceModule = itemBinding.path.parent.source.value;
341
- local = itemNode.local.name;
342
- usesImportSyntax = true;
343
- if (t4.isImportSpecifier(itemNode)) {
344
- imported = itemNode.imported["name"];
345
- destructured = true;
346
- } else {
347
- imported = itemNode.local.name;
348
- destructured = false;
349
- }
350
- }
351
- } else if (t4.isVariableDeclarator(itemNode) && itemNode.init != null && t4.isCallExpression(itemNode.init) && t4.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
352
- const firstArg = itemNode.init.arguments[0];
353
- if (!t4.isStringLiteral(firstArg)) {
354
- return null;
355
- }
356
- sourceModule = firstArg.value;
357
- if (t4.isIdentifier(itemNode.id)) {
358
- local = itemNode.id.name;
359
- imported = itemNode.id.name;
360
- destructured = false;
361
- } else if (t4.isObjectPattern(itemNode.id)) {
362
- for (const objProp of itemNode.id.properties) {
363
- if (t4.isObjectProperty(objProp) && t4.isIdentifier(objProp.value) && objProp.value.name === itemName) {
364
- local = objProp.value.name;
365
- imported = objProp.key.name;
366
- destructured = true;
367
- break;
368
- }
369
- }
370
- if (!local || !imported) {
371
- console.error("could not find prop with value `%s`", itemName);
372
- return null;
373
- }
374
- } else {
375
- console.error("Unhandled id type: %s", itemNode.id.type);
376
- return null;
377
- }
378
- } else {
379
- return null;
380
- }
381
- return {
382
- destructured,
383
- imported,
384
- local,
385
- sourceModule,
386
- usesImportSyntax
387
- };
388
- }
389
- __name(getSourceModule, "getSourceModule");
390
-
391
- // src/extractor/getStaticBindingsForScope.ts
392
- var isLocalImport = /* @__PURE__ */ __name((path3) => path3.startsWith(".") || path3.startsWith("/"), "isLocalImport");
393
- function resolveImportPath(sourcePath, path3) {
394
- const sourceDir = (0, import_path.dirname)(sourcePath);
395
- if (isLocalImport(path3)) {
396
- if ((0, import_path.extname)(path3) === "") {
397
- path3 += ".js";
398
- }
399
- return (0, import_path.resolve)(sourceDir, path3);
400
- }
401
- return path3;
402
- }
403
- __name(resolveImportPath, "resolveImportPath");
404
- function importModule(path3) {
405
- const filenames = [path3.replace(".js", ".tsx"), path3.replace(".js", ".ts"), path3];
406
- for (const file of filenames) {
407
- if ((0, import_fs_extra.existsSync)(file)) {
408
- return require(file);
409
- }
410
- }
411
- return null;
412
- }
413
- __name(importModule, "importModule");
414
- function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
415
- const bindings = scope.getAllBindings();
416
- const ret = {};
417
- if (shouldPrintDebug) {
418
- console.log(" ", Object.keys(bindings).length, "variables in scope");
419
- }
420
- const program = scope.getProgramParent().block;
421
- for (const node of program.body) {
422
- if (t5.isImportDeclaration(node)) {
423
- const importPath = node.source.value;
424
- if (!node.specifiers.length)
425
- continue;
426
- if (!isLocalImport(importPath)) {
427
- continue;
428
- }
429
- const moduleName = resolveImportPath(sourcePath, importPath);
430
- const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
431
- if (!isOnWhitelist)
432
- continue;
433
- const src = importModule(moduleName);
434
- if (!src)
435
- continue;
436
- for (const specifier of node.specifiers) {
437
- if (t5.isImportSpecifier(specifier) && t5.isIdentifier(specifier.imported)) {
438
- if (typeof src[specifier.imported.name] !== "undefined") {
439
- const val = src[specifier.local.name];
440
- ret[specifier.local.name] = val;
441
- }
442
- }
443
- }
444
- }
445
- }
446
- if (!bindingCache) {
447
- throw new Error("bindingCache is a required param");
448
- }
449
- for (const k in bindings) {
450
- const binding = bindings[k];
451
- const sourceModule = getSourceModule(k, binding);
452
- if (sourceModule) {
453
- if (!sourceModule.sourceModule) {
454
- continue;
455
- }
456
- const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
457
- const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
458
- if (isOnWhitelist) {
459
- const src = importModule(moduleName);
460
- if (!src) {
461
- console.log(`\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`);
462
- return {};
463
- }
464
- if (sourceModule.destructured) {
465
- if (sourceModule.imported) {
466
- ret[k] = src[sourceModule.imported];
467
- }
468
- } else {
469
- ret[k] = src;
470
- }
471
- }
472
- continue;
473
- }
474
- const { parent, parentPath } = binding.path;
475
- if (!t5.isVariableDeclaration(parent) || parent.kind !== "const") {
476
- continue;
477
- }
478
- const dec = parent.declarations.find((d) => t5.isIdentifier(d.id) && d.id.name === k);
479
- if (!dec || !dec.init) {
480
- continue;
481
- }
482
- if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
483
- console.error("dec.id.start/end is not a number");
484
- continue;
485
- }
486
- if (!t5.isIdentifier(dec.id)) {
487
- console.error("dec is not an identifier");
488
- continue;
489
- }
490
- const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
491
- if (bindingCache.hasOwnProperty(cacheKey)) {
492
- ret[k] = bindingCache[cacheKey];
493
- continue;
494
- }
495
- if (bindingCache.hasOwnProperty(cacheKey)) {
496
- ret[k] = bindingCache[cacheKey];
497
- continue;
498
- }
499
- try {
500
- ret[k] = evaluateAstNode(dec.init, void 0, shouldPrintDebug);
501
- bindingCache[cacheKey] = ret[k];
502
- continue;
503
- } catch (e) {
504
- }
505
- }
506
- return ret;
507
- }
508
- __name(getStaticBindingsForScope, "getStaticBindingsForScope");
509
-
510
- // src/extractor/literalToAst.ts
511
- var t6 = __toModule(require("@babel/types"));
512
- function literalToAst(literal) {
513
- if (literal === null) {
514
- return t6.nullLiteral();
515
- }
516
- switch (typeof literal) {
517
- case "function":
518
- throw new Error("Unsupported");
519
- case "number":
520
- return t6.numericLiteral(literal);
521
- case "string":
522
- return t6.stringLiteral(literal);
523
- case "boolean":
524
- return t6.booleanLiteral(literal);
525
- case "undefined":
526
- return t6.unaryExpression("void", t6.numericLiteral(0), true);
527
- default:
528
- if (Array.isArray(literal)) {
529
- return t6.arrayExpression(literal.map(literalToAst));
530
- }
531
- return t6.objectExpression(Object.keys(literal).filter((k) => {
532
- return typeof literal[k] !== "undefined";
533
- }).map((k) => {
534
- return t6.objectProperty(t6.stringLiteral(k), literalToAst(literal[k]));
535
- }));
536
- }
537
- }
538
- __name(literalToAst, "literalToAst");
539
-
540
- // src/extractor/loadTamagui.ts
541
- var import_path2 = __toModule(require("path"));
542
- var import_core_node = __toModule(require("@tamagui/core-node"));
543
- var loadedTamagui = null;
544
- function loadTamagui(props) {
545
- if (loadedTamagui) {
546
- return loadedTamagui;
547
- }
548
- process.env.IS_STATIC = "is_static";
549
- const proxyWorm = require("@tamagui/fake-react-native");
550
- const Mod = require("module");
551
- const og = Mod.prototype.require;
552
- Mod.prototype.require = function(path3) {
553
- if (path3.startsWith("react-native") && !path3.startsWith("react-native-web/dist/cjs/exports")) {
554
- return proxyWorm;
555
- }
556
- return og.apply(this, arguments);
557
- };
558
- const configPath = (0, import_path2.join)(process.cwd(), props.config);
559
- const tamaguiConfigExport = require(configPath);
560
- const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
561
- const components = {};
562
- for (const module2 of props.components) {
563
- const exported = require(module2);
564
- Object.assign(components, exported);
565
- }
566
- process.env.IS_STATIC = void 0;
567
- Mod.prototype.require = og;
568
- (0, import_core_node.createTamagui)(tamaguiConfig);
569
- loadedTamagui = {
570
- components,
571
- tamaguiConfig
572
- };
573
- return loadedTamagui;
574
- }
575
- __name(loadTamagui, "loadTamagui");
576
-
577
- // src/extractor/normalizeTernaries.ts
578
- var import_generator2 = __toModule(require("@babel/generator"));
579
- var t7 = __toModule(require("@babel/types"));
580
- var import_invariant = __toModule(require("invariant"));
581
- function normalizeTernaries(ternaries) {
582
- (0, import_invariant.default)(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
583
- if (ternaries.length === 0) {
584
- return [];
585
- }
586
- const ternariesByKey = {};
587
- for (let idx = -1, len = ternaries.length; ++idx < len; ) {
588
- const _a = ternaries[idx], { test, consequent, alternate, remove } = _a, rest = __objRest(_a, ["test", "consequent", "alternate", "remove"]);
589
- let ternaryTest = test;
590
- if (t7.isExpressionStatement(test)) {
591
- ternaryTest = test.expression;
592
- }
593
- let shouldSwap = false;
594
- if (t7.isUnaryExpression(test) && test.operator === "!") {
595
- ternaryTest = test.argument;
596
- shouldSwap = true;
597
- } else if (t7.isBinaryExpression(test)) {
598
- if (test.operator === "!==" || test.operator === "!=") {
599
- ternaryTest = t7.binaryExpression(test.operator, test.left, test.right);
600
- shouldSwap = true;
601
- }
602
- }
603
- const key = (0, import_generator2.default)(ternaryTest).code;
604
- if (!ternariesByKey[key]) {
605
- ternariesByKey[key] = __spreadProps(__spreadValues({}, rest), {
606
- alternate: {},
607
- consequent: {},
608
- test: ternaryTest,
609
- remove
610
- });
611
- }
612
- const altStyle = (shouldSwap ? consequent : alternate) ?? {};
613
- const consStyle = (shouldSwap ? alternate : consequent) ?? {};
614
- Object.assign(ternariesByKey[key].alternate, altStyle);
615
- Object.assign(ternariesByKey[key].consequent, consStyle);
616
- }
617
- const ternaryExpression = Object.keys(ternariesByKey).map((key) => {
618
- return ternariesByKey[key];
619
- });
620
- return ternaryExpression;
621
- }
622
- __name(normalizeTernaries, "normalizeTernaries");
623
-
624
- // src/extractor/removeUnusedHooks.ts
625
- var t8 = __toModule(require("@babel/types"));
626
- var hooks = {
627
- useMedia: true,
628
- useTheme: true
629
- };
630
- function removeUnusedHooks(compFn, shouldPrintDebug) {
631
- compFn.scope.crawl();
632
- let bodyStatements = compFn == null ? void 0 : compFn.get("body");
633
- if (!bodyStatements) {
634
- console.log("no body statemnts?", compFn);
635
- return;
636
- }
637
- if (!Array.isArray(bodyStatements)) {
638
- if (bodyStatements.isFunctionExpression()) {
639
- bodyStatements = bodyStatements.scope.path.get("body");
640
- } else {
641
- bodyStatements = bodyStatements.get("body");
642
- }
643
- }
644
- if (!bodyStatements || !Array.isArray(bodyStatements)) {
645
- return;
646
- }
647
- const statements = bodyStatements;
648
- for (const statement of statements) {
649
- if (!statement.isVariableDeclaration()) {
650
- continue;
651
- }
652
- const declarations = statement.get("declarations");
653
- if (!Array.isArray(declarations)) {
654
- continue;
655
- }
656
- const isBindingReferenced = /* @__PURE__ */ __name((name) => {
657
- var _a;
658
- return !!((_a = statement.scope.getBinding(name)) == null ? void 0 : _a.referenced);
659
- }, "isBindingReferenced");
660
- for (const declarator of declarations) {
661
- const id = declarator.get("id");
662
- const init = declarator.node.init;
663
- if (Array.isArray(id) || Array.isArray(init)) {
664
- continue;
665
- }
666
- const shouldRemove = (() => {
667
- const isHook = t8.isCallExpression(init) && t8.isIdentifier(init.callee) && hooks[init.callee.name];
668
- if (!isHook) {
669
- return false;
670
- }
671
- if (t8.isIdentifier(id.node)) {
672
- const name = id.node.name;
673
- return !isBindingReferenced(name);
674
- } else if (t8.isObjectPattern(id.node)) {
675
- const propPaths = id.get("properties");
676
- return propPaths.every((prop) => {
677
- if (!prop.isObjectProperty())
678
- return false;
679
- const value = prop.get("value");
680
- if (Array.isArray(value) || !value.isIdentifier())
681
- return false;
682
- const name = value.node.name;
683
- return !isBindingReferenced(name);
684
- });
685
- }
686
- return false;
687
- })();
688
- if (shouldRemove) {
689
- declarator.remove();
690
- if (shouldPrintDebug) {
691
- console.log(` [\u{1FA9D}] removed ${id.node["name"] ?? ""}`);
692
- }
693
- }
694
- }
695
- }
696
- }
697
- __name(removeUnusedHooks, "removeUnusedHooks");
698
-
699
- // src/extractor/createExtractor.ts
700
- var { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
701
- var FAILED_EVAL = Symbol("failed_style_eval");
702
- var UNTOUCHED_PROPS = {
703
- key: true,
704
- style: true,
705
- className: true
706
- };
707
- var isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
708
- var validHooks = {
709
- useMedia: true,
710
- useTheme: true
711
- };
712
- var createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
713
- function createExtractor() {
714
- const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
715
- require("esbuild-register/dist/node").register({
716
- target: "es2019",
717
- format: "cjs"
718
- });
719
- let loadedTamaguiConfig;
720
- return {
721
- getTamaguiConfig() {
722
- return loadedTamaguiConfig;
723
- },
724
- parse: (fileOrPath, _a) => {
725
- var _b = _a, {
726
- config = "tamagui.config.ts",
727
- importsWhitelist = ["constants.js"],
728
- evaluateVars = true,
729
- shouldPrintDebug = false,
730
- sourcePath = "",
731
- onExtractTag,
732
- getFlattenedNode,
733
- onDidFlatten
734
- } = _b, props = __objRest(_b, [
735
- "config",
736
- "importsWhitelist",
737
- "evaluateVars",
738
- "shouldPrintDebug",
739
- "sourcePath",
740
- "onExtractTag",
741
- "getFlattenedNode",
742
- "onDidFlatten"
743
- ]);
744
- if (sourcePath === "") {
745
- throw new Error(`Must provide a source file name`);
746
- }
747
- if (!Array.isArray(props.components)) {
748
- throw new Error(`Must provide components array with list of Tamagui component modules`);
749
- }
750
- const { components, tamaguiConfig } = loadTamagui({
751
- config,
752
- components: props.components || ["tamagui"]
753
- });
754
- loadedTamaguiConfig = tamaguiConfig;
755
- const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
756
- let doesUseValidImport = false;
757
- const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
758
- const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
759
- const validComponents = Object.keys(components).filter((key) => {
760
- var _a2;
761
- return !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
762
- }).reduce((obj, name) => {
763
- obj[name] = components[name];
764
- return obj;
765
- }, {});
766
- for (const bodyPath of body) {
767
- if (bodyPath.type !== "ImportDeclaration")
768
- continue;
769
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
770
- const from = node.source.value;
771
- if (props.components.includes(from) || isInternalImport(from)) {
772
- if (node.specifiers.some((specifier) => {
773
- const name = specifier.local.name;
774
- return validComponents[name] || validHooks[name];
775
- })) {
776
- doesUseValidImport = true;
777
- break;
778
- }
779
- }
780
- }
781
- if (shouldPrintDebug) {
782
- console.log(sourcePath, { doesUseValidImport });
783
- }
784
- if (!doesUseValidImport) {
785
- return null;
786
- }
787
- let couldntParse = false;
788
- const modifiedComponents = new Set();
789
- const bindingCache = {};
790
- const callTraverse = /* @__PURE__ */ __name((a) => {
791
- return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
792
- }, "callTraverse");
793
- let programPath;
794
- callTraverse({
795
- Program: {
796
- enter(path3) {
797
- programPath = path3;
798
- }
799
- },
800
- JSXElement(traversePath) {
801
- var _a2;
802
- const node = traversePath.node.openingElement;
803
- const ogAttributes = node.attributes;
804
- const componentName = findComponentName(traversePath.scope);
805
- const closingElement = traversePath.node.closingElement;
806
- if (t9.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t9.isJSXIdentifier(node.name)) {
807
- return;
808
- }
809
- const binding = traversePath.scope.getBinding(node.name.name);
810
- if (binding) {
811
- if (!t9.isImportDeclaration(binding.path.parent)) {
812
- return;
813
- }
814
- const source = binding.path.parent.source;
815
- if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
816
- return;
817
- }
818
- if (!validComponents[binding.identifier.name]) {
819
- return;
820
- }
821
- }
822
- const component = validComponents[node.name.name];
823
- if (!component || !component.staticConfig) {
824
- return;
825
- }
826
- const { staticConfig } = component;
827
- const originalNodeName = node.name.name;
828
- const isTextView = staticConfig.isText || false;
829
- const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
830
- let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
831
- traversePath.get("openingElement").get("attributes").forEach((path3) => {
832
- const attr = path3.node;
833
- if (t9.isJSXSpreadAttribute(attr))
834
- return;
835
- if (attr.name.name !== "tag")
836
- return;
837
- const val = attr.value;
838
- if (!t9.isStringLiteral(val))
839
- return;
840
- tagName = val.value;
841
- });
842
- const flatNode = getFlattenedNode({ isTextView, tag: tagName });
843
- const deoptProps = new Set([
844
- ...props.deoptProps ?? [],
845
- ...staticConfig.deoptProps ?? []
846
- ]);
847
- const excludeProps = new Set(props.excludeProps ?? []);
848
- const isExcludedProp = /* @__PURE__ */ __name((name) => {
849
- const res = excludeProps.has(name);
850
- if (res && shouldPrintDebug)
851
- console.log(` excluding ${name}`);
852
- return res;
853
- }, "isExcludedProp");
854
- const isDeoptedProp = /* @__PURE__ */ __name((name) => {
855
- const res = deoptProps.has(name);
856
- if (res && shouldPrintDebug)
857
- console.log(` deopting ${name}`);
858
- return res;
859
- }, "isDeoptedProp");
860
- if (shouldPrintDebug) {
861
- console.log(`
862
- <${originalNodeName} />`);
863
- }
864
- const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
865
- const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
866
- tamaguiConfig,
867
- staticNamespace,
868
- sourcePath,
869
- traversePath,
870
- shouldPrintDebug
871
- });
872
- const attemptEvalSafe = createSafeEvaluator(attemptEval);
873
- if (shouldPrintDebug) {
874
- console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
875
- }
876
- const hasDeopt = /* @__PURE__ */ __name((obj) => {
877
- return Object.keys(obj).some(isDeoptedProp);
878
- }, "hasDeopt");
879
- const flattenedAttrs = [];
880
- traversePath.get("openingElement").get("attributes").forEach((path3) => {
881
- const attr = path3.node;
882
- if (!t9.isJSXSpreadAttribute(attr)) {
883
- flattenedAttrs.push(attr);
884
- return;
885
- }
886
- let arg;
887
- try {
888
- arg = attemptEval(attr.argument);
889
- } catch (e) {
890
- if (shouldPrintDebug) {
891
- console.log(" couldnt parse spread", e.message);
892
- }
893
- flattenedAttrs.push(attr);
894
- return;
895
- }
896
- if (typeof arg !== "undefined") {
897
- try {
898
- if (typeof arg !== "object" || arg == null) {
899
- if (shouldPrintDebug) {
900
- console.log(" non object or null arg", arg);
901
- }
902
- flattenedAttrs.push(attr);
903
- } else {
904
- for (const k in arg) {
905
- const value = arg[k];
906
- if (!value && typeof value === "object") {
907
- console.log("shouldnt we handle this?", k, value, arg);
908
- continue;
909
- }
910
- flattenedAttrs.push(t9.jsxAttribute(t9.jsxIdentifier(k), t9.jsxExpressionContainer(literalToAst(value))));
911
- }
912
- }
913
- } catch (err) {
914
- console.warn("cant parse spread, caught err", err);
915
- couldntParse = true;
916
- }
917
- }
918
- });
919
- if (couldntParse) {
920
- return;
921
- }
922
- node.attributes = flattenedAttrs;
923
- if (staticConfig.defaultProps) {
924
- for (const key in staticConfig.defaultProps) {
925
- const serialize = require("babel-literal-to-ast");
926
- const val = staticConfig.defaultProps[key];
927
- node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier(key), typeof val === "string" ? t9.stringLiteral(val) : t9.jsxExpressionContainer(serialize(val))));
928
- }
929
- }
930
- let attrs = [];
931
- let shouldDeopt = false;
932
- let inlinePropCount = 0;
933
- let isFlattened = false;
934
- attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
935
- try {
936
- const res = evaluateAttribute(path3);
937
- if (!res) {
938
- path3.remove();
939
- }
940
- return res;
941
- } catch (err) {
942
- console.log("Error extracting attribute", err.message, err.stack);
943
- console.log("node", path3.node);
944
- return {
945
- type: "attr",
946
- value: path3.node
947
- };
948
- }
949
- }).flat(4).filter(isPresent);
950
- function isStaticAttributeName(name) {
951
- var _a3, _b2;
952
- return !!(!!validStyles[name] || ((_a3 = staticConfig.validPropsExtra) == null ? void 0 : _a3[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
953
- }
954
- __name(isStaticAttributeName, "isStaticAttributeName");
955
- function isExtractable(obj) {
956
- return t9.isObjectExpression(obj) && obj.properties.every((prop) => {
957
- if (!t9.isObjectProperty(prop)) {
958
- console.log("not object prop", prop);
959
- return false;
960
- }
961
- const propName = prop.key["name"];
962
- if (!isStaticAttributeName(propName) && propName !== "tag") {
963
- if (shouldPrintDebug) {
964
- console.log(" not a valid style prop!", propName);
965
- }
966
- return false;
967
- }
968
- return true;
969
- });
970
- }
971
- __name(isExtractable, "isExtractable");
972
- function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
973
- if (!side) {
974
- return null;
975
- }
976
- if (!isExtractable(side)) {
977
- throw new Error("not extractable");
978
- }
979
- return side.properties.flatMap((property) => {
980
- if (!t9.isObjectProperty(property)) {
981
- throw new Error("expected object property");
982
- }
983
- if (t9.isConditionalExpression(property.value)) {
984
- const [truthy, falsy] = [
985
- t9.objectExpression([t9.objectProperty(property.key, property.value.consequent)]),
986
- t9.objectExpression([t9.objectProperty(property.key, property.value.alternate)])
987
- ].map((x) => attemptEval(x));
988
- return [
989
- createTernary(__spreadProps(__spreadValues({
990
- remove() {
991
- }
992
- }, ternaryPartial), {
993
- test: t9.logicalExpression("&&", test, property.value.test),
994
- consequent: truthy,
995
- alternate: null
996
- })),
997
- createTernary(__spreadProps(__spreadValues({}, ternaryPartial), {
998
- test: t9.logicalExpression("&&", test, t9.unaryExpression("!", property.value.test)),
999
- consequent: falsy,
1000
- alternate: null,
1001
- remove() {
1002
- }
1003
- }))
1004
- ];
1005
- }
1006
- const obj = t9.objectExpression([t9.objectProperty(property.key, property.value)]);
1007
- const consequent = attemptEval(obj);
1008
- return createTernary(__spreadProps(__spreadValues({
1009
- remove() {
1010
- }
1011
- }, ternaryPartial), {
1012
- test,
1013
- consequent,
1014
- alternate: null
1015
- }));
1016
- });
1017
- }
1018
- __name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
1019
- function evaluateAttribute(path3) {
1020
- const attribute = path3.node;
1021
- const attr = { type: "attr", value: attribute };
1022
- if (t9.isJSXSpreadAttribute(attribute)) {
1023
- const arg = attribute.argument;
1024
- const conditional = t9.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t9.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
1025
- if (conditional) {
1026
- const [test, alt, cons] = conditional;
1027
- if (!test)
1028
- throw new Error(`no test`);
1029
- if ([alt, cons].some((side) => side && !isExtractable(side))) {
1030
- if (shouldPrintDebug) {
1031
- console.log("not extractable", alt, cons);
1032
- }
1033
- return attr;
1034
- }
1035
- return [
1036
- ...createTernariesFromObjectProperties(test, alt) || [],
1037
- ...cons && createTernariesFromObjectProperties(t9.unaryExpression("!", test), cons) || []
1038
- ].map((ternary) => ({
1039
- type: "ternary",
1040
- value: ternary
1041
- }));
1042
- }
1043
- }
1044
- if (t9.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
1045
- inlinePropCount++;
1046
- return attr;
1047
- }
1048
- const name = attribute.name.name;
1049
- if (isExcludedProp(name)) {
1050
- return null;
1051
- }
1052
- if (isDeoptedProp(name)) {
1053
- if (shouldPrintDebug) {
1054
- console.log(" ! inlining, deopt prop", name);
1055
- }
1056
- inlinePropCount++;
1057
- return attr;
1058
- }
1059
- if (UNTOUCHED_PROPS[name]) {
1060
- return attr;
1061
- }
1062
- if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
1063
- const shortname = name.slice(1);
1064
- if (mediaQueryConfig[shortname]) {
1065
- const expression = attribute.value.expression;
1066
- if (!t9.isJSXEmptyExpression(expression)) {
1067
- const ternaries2 = createTernariesFromObjectProperties(t9.stringLiteral(shortname), expression, {
1068
- inlineMediaQuery: shortname
1069
- });
1070
- if (ternaries2) {
1071
- return ternaries2.map((value2) => ({
1072
- type: "ternary",
1073
- value: value2
1074
- }));
1075
- }
1076
- }
1077
- }
1078
- }
1079
- const [value, valuePath] = (() => {
1080
- if (t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
1081
- return [attribute.value.expression, path3.get("value")];
1082
- } else {
1083
- return [attribute.value, path3.get("value")];
1084
- }
1085
- })();
1086
- const remove = /* @__PURE__ */ __name(() => {
1087
- Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
1088
- }, "remove");
1089
- if (name === "ref") {
1090
- if (shouldPrintDebug) {
1091
- console.log(" ! inlining, ref", name);
1092
- }
1093
- inlinePropCount++;
1094
- return attr;
1095
- }
1096
- if (name === "tag") {
1097
- return {
1098
- type: "attr",
1099
- value: path3.node
1100
- };
1101
- }
1102
- const styleValue = attemptEvalSafe(value);
1103
- if (!isStaticAttributeName(name)) {
1104
- let keys = [name];
1105
- if (staticConfig.propMapper) {
1106
- const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
1107
- if (out) {
1108
- keys = Object.keys(out);
1109
- }
1110
- }
1111
- if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
1112
- if (shouldPrintDebug) {
1113
- console.log(" ! inlining, not static attribute name", name);
1114
- }
1115
- inlinePropCount++;
1116
- return attr;
1117
- }
1118
- }
1119
- if (styleValue !== FAILED_EVAL) {
1120
- return {
1121
- type: "style",
1122
- value: { [name]: styleValue }
1123
- };
1124
- }
1125
- if (t9.isBinaryExpression(value)) {
1126
- const { operator, left, right } = value;
1127
- const lVal = attemptEvalSafe(left);
1128
- const rVal = attemptEvalSafe(right);
1129
- if (shouldPrintDebug) {
1130
- console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
1131
- }
1132
- if (lVal !== FAILED_EVAL && t9.isConditionalExpression(right)) {
1133
- const ternary = addBinaryConditional(operator, left, right);
1134
- if (ternary)
1135
- return ternary;
1136
- }
1137
- if (rVal !== FAILED_EVAL && t9.isConditionalExpression(left)) {
1138
- const ternary = addBinaryConditional(operator, right, left);
1139
- if (ternary)
1140
- return ternary;
1141
- }
1142
- if (shouldPrintDebug) {
1143
- console.log(` evalBinaryExpression cant extract`);
1144
- }
1145
- inlinePropCount++;
1146
- return attr;
1147
- }
1148
- const staticConditional = getStaticConditional(value);
1149
- if (staticConditional) {
1150
- return { type: "ternary", value: staticConditional };
1151
- }
1152
- const staticLogical = getStaticLogical(value);
1153
- if (staticLogical) {
1154
- return { type: "ternary", value: staticLogical };
1155
- }
1156
- if (shouldPrintDebug) {
1157
- console.log(" ! inline prop via no match", name, value.type);
1158
- }
1159
- inlinePropCount++;
1160
- return attr;
1161
- function addBinaryConditional(operator, staticExpr, cond) {
1162
- if (getStaticConditional(cond)) {
1163
- const alt = attemptEval(t9.binaryExpression(operator, staticExpr, cond.alternate));
1164
- const cons = attemptEval(t9.binaryExpression(operator, staticExpr, cond.consequent));
1165
- if (shouldPrintDebug) {
1166
- console.log(" binaryConditional", cond.test, cons, alt);
1167
- }
1168
- return {
1169
- type: "ternary",
1170
- value: {
1171
- test: cond.test,
1172
- remove,
1173
- alternate: { [name]: alt },
1174
- consequent: { [name]: cons }
1175
- }
1176
- };
1177
- }
1178
- return null;
1179
- }
1180
- __name(addBinaryConditional, "addBinaryConditional");
1181
- function getStaticConditional(value2) {
1182
- if (t9.isConditionalExpression(value2)) {
1183
- try {
1184
- if (shouldPrintDebug) {
1185
- console.log("attempt", value2.alternate, value2.consequent);
1186
- }
1187
- const aVal = attemptEval(value2.alternate);
1188
- const cVal = attemptEval(value2.consequent);
1189
- if (shouldPrintDebug) {
1190
- const type = value2.test.type;
1191
- console.log(" static ternary", type, cVal, aVal);
1192
- }
1193
- return {
1194
- test: value2.test,
1195
- remove,
1196
- consequent: { [name]: cVal },
1197
- alternate: { [name]: aVal }
1198
- };
1199
- } catch (err) {
1200
- if (shouldPrintDebug) {
1201
- console.log(" cant eval ternary", err.message);
1202
- }
1203
- }
1204
- }
1205
- return null;
1206
- }
1207
- __name(getStaticConditional, "getStaticConditional");
1208
- function getStaticLogical(value2) {
1209
- if (t9.isLogicalExpression(value2)) {
1210
- if (value2.operator === "&&") {
1211
- try {
1212
- const val = attemptEval(value2.right);
1213
- if (shouldPrintDebug) {
1214
- console.log(" staticLogical", value2.left, name, val);
1215
- }
1216
- return {
1217
- test: value2.left,
1218
- remove,
1219
- consequent: { [name]: val },
1220
- alternate: null
1221
- };
1222
- } catch (err) {
1223
- if (shouldPrintDebug) {
1224
- console.log(" cant static eval logical", err);
1225
- }
1226
- }
1227
- }
1228
- }
1229
- return null;
1230
- }
1231
- __name(getStaticLogical, "getStaticLogical");
1232
- }
1233
- __name(evaluateAttribute, "evaluateAttribute");
1234
- if (shouldPrintDebug) {
1235
- console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
1236
- }
1237
- node.attributes = attrs.filter(isAttr).map((x) => x.value);
1238
- if (couldntParse) {
1239
- if (shouldPrintDebug) {
1240
- console.log(` cancel:`, { couldntParse, shouldDeopt });
1241
- }
1242
- node.attributes = ogAttributes;
1243
- return;
1244
- }
1245
- const parentFn = findTopmostFunction(traversePath);
1246
- if (parentFn) {
1247
- modifiedComponents.add(parentFn);
1248
- }
1249
- const filePath = sourcePath.replace(process.cwd(), ".");
1250
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
1251
- let ternaries = [];
1252
- attrs = attrs.reduce((out, cur) => {
1253
- const next = attrs[attrs.indexOf(cur) + 1];
1254
- if (cur.type === "ternary") {
1255
- ternaries.push(cur.value);
1256
- }
1257
- if ((!next || next.type !== "ternary") && ternaries.length) {
1258
- const normalized = normalizeTernaries(ternaries).map((_a3) => {
1259
- var _b2 = _a3, { alternate, consequent } = _b2, rest = __objRest(_b2, ["alternate", "consequent"]);
1260
- return {
1261
- type: "ternary",
1262
- value: __spreadProps(__spreadValues({}, rest), {
1263
- alternate: alternate || null,
1264
- consequent: consequent || null
1265
- })
1266
- };
1267
- });
1268
- try {
1269
- return [...out, ...normalized];
1270
- } finally {
1271
- if (shouldPrintDebug) {
1272
- console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
1273
- }
1274
- ternaries = [];
1275
- }
1276
- }
1277
- if (cur.type === "ternary") {
1278
- return out;
1279
- }
1280
- out.push(cur);
1281
- return out;
1282
- }, []).flat();
1283
- const completeStaticProps = __spreadValues({}, Object.keys(attrs).reduce((acc, index) => {
1284
- const cur = attrs[index];
1285
- if (cur.type === "style") {
1286
- Object.assign(acc, cur.value);
1287
- }
1288
- if (cur.type === "attr") {
1289
- if (t9.isJSXSpreadAttribute(cur.value)) {
1290
- return acc;
1291
- }
1292
- if (!t9.isJSXIdentifier(cur.value.name)) {
1293
- return acc;
1294
- }
1295
- const key = cur.value.name.name;
1296
- const value = attemptEvalSafe(cur.value.value || t9.booleanLiteral(true));
1297
- if (value === FAILED_EVAL) {
1298
- return acc;
1299
- }
1300
- acc[key] = value;
1301
- }
1302
- return acc;
1303
- }, {}));
1304
- const hasSpread = node.attributes.some((x) => t9.isJSXSpreadAttribute(x));
1305
- const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
1306
- const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
1307
- if (!shouldFlatten) {
1308
- attrs = attrs.reduce((acc, cur) => {
1309
- var _a3;
1310
- if (cur.type === "style") {
1311
- for (const key in cur.value) {
1312
- const shouldInsertNull = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
1313
- const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
1314
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
1315
- if (shouldInsertNullOverride) {
1316
- acc.push({
1317
- type: "attr",
1318
- value: t9.jsxAttribute(t9.jsxIdentifier(key), t9.jsxExpressionContainer(t9.nullLiteral()))
1319
- });
1320
- }
1321
- }
1322
- }
1323
- acc.push(cur);
1324
- return acc;
1325
- }, []);
1326
- }
1327
- if (shouldPrintDebug) {
1328
- console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
1329
- }
1330
- attrs = attrs.reduce((acc, cur) => {
1331
- if (cur.type !== "attr" || !t9.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
1332
- if (cur.type === "style") {
1333
- const key = Object.keys(cur.value)[0];
1334
- if (!validStyles[key] && !pseudos[key]) {
1335
- if (shouldPrintDebug) {
1336
- console.log(" \u274C excluding", key);
1337
- }
1338
- return acc;
1339
- }
1340
- }
1341
- }
1342
- acc.push(cur);
1343
- return acc;
1344
- }, []);
1345
- if (shouldPrintDebug) {
1346
- console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
1347
- }
1348
- let prev = null;
1349
- attrs = attrs.reduce((acc, cur) => {
1350
- if (cur.type === "style") {
1351
- if ((prev == null ? void 0 : prev.type) === "style") {
1352
- Object.assign(prev.value, cur.value);
1353
- return acc;
1354
- }
1355
- }
1356
- acc.push(cur);
1357
- prev = cur;
1358
- return acc;
1359
- }, []);
1360
- if (shouldPrintDebug) {
1361
- console.log(" - attrs (combined \u{1F500}): ", attrs.map(attrStr).join(", "));
1362
- }
1363
- const getStyles = /* @__PURE__ */ __name((props2) => {
1364
- if (!props2)
1365
- return;
1366
- if (!!excludeProps.size) {
1367
- for (const key in props2) {
1368
- if (isExcludedProp(key))
1369
- delete props2[key];
1370
- }
1371
- }
1372
- const out = postProcessStyles(props2, staticConfig, defaultTheme);
1373
- const next = (out == null ? void 0 : out.style) ?? props2;
1374
- if (shouldPrintDebug) {
1375
- console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
1376
- console.log(" >> style: ", objToStr(out.style));
1377
- console.log(" >> viewp: ", objToStr(out.viewProps));
1378
- }
1379
- if (staticConfig.validStyles) {
1380
- for (const key in next) {
1381
- if (!staticConfig.validStyles[key] && !pseudos[key]) {
1382
- delete next[key];
1383
- }
1384
- }
1385
- }
1386
- return next;
1387
- }, "getStyles");
1388
- if (shouldPrintDebug) {
1389
- console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
1390
- }
1391
- const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps));
1392
- const stylesToAddToInitialGroup = (0, import_lodash.difference)(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
1393
- if (stylesToAddToInitialGroup.length) {
1394
- const toAdd = (0, import_lodash.pick)(completeStylesProcessed, ...stylesToAddToInitialGroup);
1395
- const firstGroup = attrs.find((x) => x.type === "style");
1396
- if (shouldPrintDebug) {
1397
- console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
1398
- console.log(" toAdd", objToStr(toAdd));
1399
- }
1400
- if (!firstGroup) {
1401
- attrs.unshift({ type: "style", value: toAdd });
1402
- } else {
1403
- Object.assign(firstGroup.value, toAdd);
1404
- }
1405
- }
1406
- if (shouldPrintDebug) {
1407
- console.log(" completeStaticProps", objToStr(completeStaticProps));
1408
- console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
1409
- }
1410
- for (const attr of attrs) {
1411
- try {
1412
- switch (attr.type) {
1413
- case "ternary":
1414
- const a = getStyles(attr.value.alternate);
1415
- const c = getStyles(attr.value.consequent);
1416
- attr.value.alternate = a;
1417
- attr.value.consequent = c;
1418
- if (shouldPrintDebug) {
1419
- console.log(" => tern ", attrStr(attr));
1420
- }
1421
- break;
1422
- case "style":
1423
- const next = {};
1424
- for (const key in attr.value) {
1425
- if (key in import_helpers.stylePropsTransform) {
1426
- next["transform"] = completeStylesProcessed["transform"];
1427
- } else {
1428
- next[key] = completeStylesProcessed[key] ?? attr.value[key];
1429
- }
1430
- }
1431
- attr.value = next;
1432
- break;
1433
- }
1434
- } catch (err) {
1435
- if (shouldPrintDebug) {
1436
- console.log(" postprocessing error, deopt", err);
1437
- node.attributes = ogAttributes;
1438
- return node;
1439
- }
1440
- }
1441
- }
1442
- if (shouldPrintDebug) {
1443
- console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
1444
- }
1445
- if (shouldAddDebugProp) {
1446
- const preName = componentName ? `${componentName}:` : "";
1447
- attrs.unshift({
1448
- type: "attr",
1449
- value: t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
1450
- });
1451
- }
1452
- if (shouldFlatten) {
1453
- if (shouldPrintDebug) {
1454
- console.log(" [\u2705] flattening", originalNodeName, flatNode);
1455
- }
1456
- isFlattened = true;
1457
- node.name.name = flatNode;
1458
- onDidFlatten == null ? void 0 : onDidFlatten();
1459
- if (closingElement) {
1460
- closingElement.name.name = flatNode;
1461
- }
1462
- }
1463
- if (shouldPrintDebug) {
1464
- console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
1465
- console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
1466
- }
1467
- onExtractTag({
1468
- attrs,
1469
- node,
1470
- lineNumbers,
1471
- filePath,
1472
- attemptEval,
1473
- jsxPath: traversePath,
1474
- originalNodeName,
1475
- isFlattened,
1476
- programPath
1477
- });
1478
- }
1479
- });
1480
- if (modifiedComponents.size) {
1481
- const all = Array.from(modifiedComponents);
1482
- if (shouldPrintDebug) {
1483
- console.log(" [\u{1FA9D}] hook check", all.length);
1484
- }
1485
- for (const comp of all) {
1486
- removeUnusedHooks(comp, shouldPrintDebug);
1487
- }
1488
- }
1489
- }
1490
- };
1491
- }
1492
- __name(createExtractor, "createExtractor");
1493
-
1494
- // src/constants.ts
1495
- var import_find_cache_dir = __toModule(require("find-cache-dir"));
1496
- var CSS_FILE_NAME = "__snack.css";
1497
- var MEDIA_SEP = "_";
1498
- var cacheDir = (0, import_find_cache_dir.default)({ name: "tamagui", create: true });
1499
-
1500
- // src/extractor/extractToClassNames.ts
1501
- var path = __toModule(require("path"));
1502
- var import_path3 = __toModule(require("path"));
1503
- var util = __toModule(require("util"));
1504
- var import_generator3 = __toModule(require("@babel/generator"));
1505
- var t14 = __toModule(require("@babel/types"));
1506
- var import_core_node3 = __toModule(require("@tamagui/core-node"));
1507
- var import_helpers2 = __toModule(require("@tamagui/helpers"));
1508
- var import_invariant2 = __toModule(require("invariant"));
1509
- var import_loader_utils = __toModule(require("loader-utils"));
1510
-
1511
- // src/extractor/babelParse.ts
1512
- var babelParser = __toModule(require("@babel/parser"));
1513
- var parserOptions = Object.freeze({
1514
- plugins: [
1515
- "asyncGenerators",
1516
- "classProperties",
1517
- "dynamicImport",
1518
- "functionBind",
1519
- "jsx",
1520
- "numericSeparator",
1521
- "objectRestSpread",
1522
- "optionalCatchBinding",
1523
- "decorators-legacy",
1524
- "typescript",
1525
- "optionalChaining",
1526
- "nullishCoalescingOperator"
1527
- ],
1528
- sourceType: "module"
1529
- });
1530
- var parser = babelParser.parse.bind(babelParser);
1531
- function babelParse(code) {
1532
- return parser(code.toString(), parserOptions);
1533
- }
1534
- __name(babelParse, "babelParse");
1535
-
1536
- // src/extractor/buildClassName.ts
1537
- var t10 = __toModule(require("@babel/types"));
1538
- function buildClassName(classNameObjects) {
1539
- return classNameObjects.reduce((acc, val) => {
1540
- if (acc == null) {
1541
- if (t10.isConditionalExpression(val) || t10.isStringLiteral(val) || t10.isNumericLiteral(val)) {
1542
- return val;
1543
- }
1544
- return t10.logicalExpression("||", val, t10.stringLiteral(""));
1545
- }
1546
- let inner;
1547
- if (t10.isStringLiteral(val)) {
1548
- if (t10.isStringLiteral(acc)) {
1549
- return t10.stringLiteral(`${acc.value} ${val.value}`);
1550
- }
1551
- inner = t10.stringLiteral(` ${val.value}`);
1552
- } else if (t10.isLiteral(val)) {
1553
- inner = t10.binaryExpression("+", t10.stringLiteral(" "), val);
1554
- } else if (t10.isConditionalExpression(val) || t10.isBinaryExpression(val)) {
1555
- if (t10.isStringLiteral(acc)) {
1556
- return t10.binaryExpression("+", t10.stringLiteral(`${acc.value} `), val);
1557
- }
1558
- inner = t10.binaryExpression("+", t10.stringLiteral(" "), val);
1559
- } else if (t10.isIdentifier(val) || t10.isMemberExpression(val)) {
1560
- inner = t10.conditionalExpression(val, t10.binaryExpression("+", t10.stringLiteral(" "), val), t10.stringLiteral(""));
1561
- } else {
1562
- if (t10.isStringLiteral(acc)) {
1563
- return t10.binaryExpression("+", t10.stringLiteral(`${acc.value} `), t10.logicalExpression("||", val, t10.stringLiteral("")));
1564
- }
1565
- inner = t10.binaryExpression("+", t10.stringLiteral(" "), t10.logicalExpression("||", val, t10.stringLiteral("")));
1566
- }
1567
- return t10.binaryExpression("+", acc, inner);
1568
- }, null);
1569
- }
1570
- __name(buildClassName, "buildClassName");
1571
-
1572
- // src/extractor/ensureImportingConcat.ts
1573
- var t11 = __toModule(require("@babel/types"));
1574
- var importConcatPkg = "@tamagui/helpers";
1575
- function ensureImportingConcat(path3) {
1576
- const bodyPath = path3.get("body");
1577
- const imported = bodyPath.find((x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg);
1578
- const importSpecifier2 = t11.importSpecifier(t11.identifier(CONCAT_CLASSNAME_IMPORT), t11.identifier(CONCAT_CLASSNAME_IMPORT));
1579
- if (!imported) {
1580
- path3.node.body.push(t11.importDeclaration([importSpecifier2], t11.stringLiteral(importConcatPkg)));
1581
- return;
1582
- }
1583
- const specifiers = imported.node.specifiers;
1584
- const alreadyImported = specifiers.some((x) => t11.isImportSpecifier(x) && t11.isIdentifier(x.imported) && x.imported.name === CONCAT_CLASSNAME_IMPORT);
1585
- if (!alreadyImported) {
1586
- specifiers.push(t11.importSpecifier(t11.identifier(CONCAT_CLASSNAME_IMPORT), t11.identifier(CONCAT_CLASSNAME_IMPORT)));
1587
- }
1588
- }
1589
- __name(ensureImportingConcat, "ensureImportingConcat");
1590
-
1591
- // src/extractor/extractMediaStyle.ts
1592
- var t12 = __toModule(require("@babel/types"));
1593
- var import_core_node2 = __toModule(require("@tamagui/core-node"));
1594
- function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
1595
- const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath);
1596
- if (!mt) {
1597
- return null;
1598
- }
1599
- const { key } = mt;
1600
- const mq = tamaguiConfig.media[key];
1601
- if (!mq) {
1602
- console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`);
1603
- return null;
1604
- }
1605
- const getStyleObj = /* @__PURE__ */ __name((styleObj, negate = false) => {
1606
- return styleObj ? { styleObj, negate } : null;
1607
- }, "getStyleObj");
1608
- const styleOpts = [
1609
- getStyleObj(ternary.consequent, false),
1610
- getStyleObj(ternary.alternate, true)
1611
- ].filter(isPresent);
1612
- if (shouldPrintDebug && !styleOpts.length) {
1613
- console.log(" media query, no styles?");
1614
- return null;
1615
- }
1616
- const mediaKeys = Object.keys(tamaguiConfig.media);
1617
- const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
1618
- acc[cur] = new Array(importance + 1).fill(":root").join("");
1619
- return acc;
1620
- }, {});
1621
- let mediaStyles = [];
1622
- for (const { styleObj, negate } of styleOpts) {
1623
- const styles = (0, import_core_node2.getStylesAtomic)(styleObj);
1624
- const singleMediaStyles = styles.map((style) => {
1625
- const negKey = negate ? "0" : "";
1626
- const ogPrefix = style.identifier.slice(0, style.identifier.indexOf("-") + 1);
1627
- const identifier3 = `${style.identifier.replace(ogPrefix, `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`)}`;
1628
- const className = `.${identifier3}`;
1629
- const mediaSelector = (0, import_core_node2.mediaObjectToString)(tamaguiConfig.media[key]);
1630
- const screenStr = negate ? "not all" : "screen";
1631
- const mediaQuery = `${screenStr} and ${mediaSelector}`;
1632
- const precendencePrefix = mediaKeyPrecendence[key];
1633
- const styleInner = style.rules[0].replace(style.identifier, identifier3);
1634
- let styleRule = "";
1635
- if (styleInner.includes("@media")) {
1636
- styleRule = styleInner.replace("{", ` and ${mediaQuery} {`);
1637
- } else {
1638
- styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`;
1639
- }
1640
- return __spreadProps(__spreadValues({}, style), {
1641
- identifier: identifier3,
1642
- className,
1643
- rules: [styleRule]
1644
- });
1645
- });
1646
- if (shouldPrintDebug) {
1647
- console.log(" media styles:", importance, singleMediaStyles.map((x) => x.identifier).join(", "));
1648
- }
1649
- mediaStyles = [...mediaStyles, ...singleMediaStyles];
1650
- }
1651
- ternary.remove();
1652
- return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia };
1653
- }
1654
- __name(extractMediaStyle, "extractMediaStyle");
1655
- function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
1656
- if (t12.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
1657
- const mediaLeft = getMediaInfoFromExpression(ternary.test.left, jsxPath, sourcePath, ternary.inlineMediaQuery);
1658
- if (mediaLeft) {
1659
- return __spreadProps(__spreadValues({}, mediaLeft), {
1660
- ternaryWithoutMedia: __spreadProps(__spreadValues({}, ternary), {
1661
- test: ternary.test.right
1662
- })
1663
- });
1664
- }
1665
- }
1666
- const result = getMediaInfoFromExpression(ternary.test, jsxPath, sourcePath, ternary.inlineMediaQuery);
1667
- if (result) {
1668
- return __spreadProps(__spreadValues({}, result), {
1669
- ternaryWithoutMedia: null
1670
- });
1671
- }
1672
- return null;
1673
- }
1674
- __name(getMediaQueryTernary, "getMediaQueryTernary");
1675
- function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
1676
- var _a, _b, _c;
1677
- if (inlineMediaQuery) {
1678
- return {
1679
- key: inlineMediaQuery,
1680
- bindingName: inlineMediaQuery
1681
- };
1682
- }
1683
- if (t12.isMemberExpression(test) && t12.isIdentifier(test.object) && t12.isIdentifier(test.property)) {
1684
- const name = test.object["name"];
1685
- const key = test.property["name"];
1686
- const bindings = jsxPath.scope.getAllBindings();
1687
- const binding = bindings[name];
1688
- if (!binding)
1689
- return false;
1690
- const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
1691
- if (!t12.isVariableDeclarator(bindingNode) || !bindingNode.init)
1692
- return false;
1693
- if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
1694
- return false;
1695
- return { key, bindingName: name };
1696
- }
1697
- if (t12.isIdentifier(test)) {
1698
- const key = test.name;
1699
- const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
1700
- if (!t12.isVariableDeclarator(node))
1701
- return false;
1702
- if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
1703
- return false;
1704
- return { key, bindingName: key };
1705
- }
1706
- return null;
1707
- }
1708
- __name(getMediaInfoFromExpression, "getMediaInfoFromExpression");
1709
- function isValidMediaCall(jsxPath, init, sourcePath) {
1710
- if (!t12.isCallExpression(init))
1711
- return false;
1712
- if (!t12.isIdentifier(init.callee))
1713
- return false;
1714
- if (init.callee.name !== "useMedia")
1715
- return false;
1716
- const bindings = jsxPath.scope.getAllBindings();
1717
- const mediaBinding = bindings["useMedia"];
1718
- if (!mediaBinding)
1719
- return false;
1720
- const useMediaImport = mediaBinding.path.parent;
1721
- if (!t12.isImportDeclaration(useMediaImport))
1722
- return false;
1723
- if (useMediaImport.source.value !== "tamagui") {
1724
- if (!isInsideTamagui(sourcePath)) {
1725
- return false;
1726
- }
1727
- }
1728
- return true;
1729
- }
1730
- __name(isValidMediaCall, "isValidMediaCall");
1731
-
1732
- // src/extractor/hoistClassNames.ts
1733
- var t13 = __toModule(require("@babel/types"));
1734
- function hoistClassNames(path3, existing, expr) {
1735
- const hoist = hoistClassNames.bind(null, path3, existing);
1736
- if (t13.isStringLiteral(expr)) {
1737
- if (expr.value.trim() === "") {
1738
- return expr;
1739
- }
1740
- if (existing[expr.value]) {
1741
- return existing[expr.value];
1742
- }
1743
- const identifier3 = replaceStringWithVariable(expr);
1744
- existing[expr.value] = identifier3;
1745
- return identifier3;
1746
- }
1747
- if (t13.isBinaryExpression(expr)) {
1748
- return t13.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
1749
- }
1750
- if (t13.isLogicalExpression(expr)) {
1751
- return t13.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
1752
- }
1753
- if (t13.isConditionalExpression(expr)) {
1754
- return t13.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
1755
- }
1756
- return expr;
1757
- function replaceStringWithVariable(str) {
1758
- const uid = path3.scope.generateUidIdentifier("cn");
1759
- const parent = path3.findParent((path4) => path4.isProgram());
1760
- if (!parent)
1761
- throw new Error(`no program?`);
1762
- const variable = t13.variableDeclaration("const", [
1763
- t13.variableDeclarator(uid, t13.stringLiteral(` ${str.value}`))
1764
- ]);
1765
- parent.unshiftContainer("body", variable);
1766
- return uid;
1767
- }
1768
- __name(replaceStringWithVariable, "replaceStringWithVariable");
1769
- }
1770
- __name(hoistClassNames, "hoistClassNames");
1771
-
1772
- // src/extractor/extractToClassNames.ts
1773
- var CONCAT_CLASSNAME_IMPORT = "concatClassName";
1774
- var mergeStyleGroups = {
1775
- shadowOpacity: true,
1776
- shadowRadius: true,
1777
- shadowColor: true,
1778
- shadowOffset: true
1779
- };
1780
- function extractToClassNames({
1781
- loader,
1782
- extractor,
1783
- source,
1784
- sourcePath,
1785
- options,
1786
- shouldPrintDebug,
1787
- threaded,
1788
- cssPath
1789
- }) {
1790
- if (typeof source !== "string") {
1791
- throw new Error("`source` must be a string of javascript");
1792
- }
1793
- (0, import_invariant2.default)(typeof sourcePath === "string" && path.isAbsolute(sourcePath), "`sourcePath` must be an absolute path to a .js file");
1794
- const shouldLogTiming = shouldPrintDebug || options.logTimings;
1795
- const start = Date.now();
1796
- const mem = shouldLogTiming ? process.memoryUsage() : null;
1797
- let ast;
1798
- try {
1799
- ast = babelParse(source);
1800
- } catch (err) {
1801
- console.error("babel parse error:", sourcePath);
1802
- throw err;
1803
- }
1804
- const cssMap = new Map();
1805
- const existingHoists = {};
1806
- let flattened = 0;
1807
- let optimized = 0;
1808
- extractor.parse(ast, __spreadProps(__spreadValues({
1809
- sourcePath,
1810
- shouldPrintDebug
1811
- }, options), {
1812
- getFlattenedNode: ({ tag }) => tag,
1813
- onDidFlatten() {
1814
- flattened++;
1815
- },
1816
- onExtractTag: ({
1817
- attrs,
1818
- node,
1819
- attemptEval,
1820
- jsxPath,
1821
- originalNodeName,
1822
- filePath,
1823
- lineNumbers,
1824
- programPath
1825
- }) => {
1826
- optimized++;
1827
- let finalClassNames = [];
1828
- let finalAttrs = [];
1829
- let finalStyles = [];
1830
- const viewStyles = {};
1831
- for (const attr of attrs) {
1832
- if (attr.type === "style") {
1833
- Object.assign(viewStyles, attr.value);
1834
- }
1835
- }
1836
- const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
1837
- const keys = Object.keys(style);
1838
- if (!keys.some((key) => mergeStyleGroups[key])) {
1839
- return style;
1840
- }
1841
- for (const k in mergeStyleGroups) {
1842
- if (k in viewStyles) {
1843
- style[k] = style[k] ?? viewStyles[k];
1844
- }
1845
- }
1846
- return style;
1847
- }, "ensureNeededPrevStyle");
1848
- const addStyles = /* @__PURE__ */ __name((style) => {
1849
- if (!style)
1850
- return [];
1851
- const styleWithPrev = ensureNeededPrevStyle(style);
1852
- const res = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
1853
- if (res.length) {
1854
- finalStyles = [...finalStyles, ...res];
1855
- }
1856
- return res;
1857
- }, "addStyles");
1858
- let lastMediaImportance = 1;
1859
- for (const attr of attrs) {
1860
- switch (attr.type) {
1861
- case "style":
1862
- const styles2 = addStyles(attr.value);
1863
- const newClassNames = (0, import_helpers2.concatClassName)(styles2.map((x) => x.identifier).join(" "));
1864
- if (shouldPrintDebug) {
1865
- console.log(" classnames", newClassNames, finalClassNames);
1866
- }
1867
- const existing = finalClassNames.find((x) => x.type == "StringLiteral");
1868
- if (existing) {
1869
- existing.value = `${existing.value} ${newClassNames}`;
1870
- } else {
1871
- finalClassNames = [...finalClassNames, t14.stringLiteral(newClassNames)];
1872
- }
1873
- if (shouldPrintDebug) {
1874
- console.log(" classnames (after)", finalClassNames.map((x) => x["value"]).join(" "));
1875
- }
1876
- break;
1877
- case "attr":
1878
- const val = attr.value;
1879
- if (t14.isJSXSpreadAttribute(val)) {
1880
- if (isSimpleSpread(val)) {
1881
- finalClassNames.push(t14.logicalExpression("&&", val.argument, t14.memberExpression(val.argument, t14.identifier("className"))));
1882
- }
1883
- } else if (val.name.name === "className") {
1884
- const value = val.value;
1885
- if (value) {
1886
- try {
1887
- const evaluatedValue = attemptEval(value);
1888
- finalClassNames.push(t14.stringLiteral(evaluatedValue));
1889
- } catch (e) {
1890
- finalClassNames.push(value["expression"]);
1891
- }
1892
- }
1893
- continue;
1894
- }
1895
- finalAttrs.push(val);
1896
- break;
1897
- case "ternary":
1898
- const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamaguiConfig(), sourcePath, lastMediaImportance, shouldPrintDebug);
1899
- if (mediaExtraction) {
1900
- lastMediaImportance++;
1901
- finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
1902
- finalClassNames = [
1903
- ...finalClassNames,
1904
- ...mediaExtraction.mediaStyles.map((x) => t14.stringLiteral(x.identifier))
1905
- ];
1906
- if (!mediaExtraction.ternaryWithoutMedia) {
1907
- continue;
1908
- }
1909
- }
1910
- const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
1911
- const consInfo = addStyles(ternary.consequent);
1912
- const altInfo = addStyles(ternary.alternate);
1913
- const cCN = consInfo.map((x) => x.identifier).join(" ");
1914
- const aCN = altInfo.map((x) => x.identifier).join(" ");
1915
- if (consInfo.length && altInfo.length) {
1916
- finalClassNames.push(t14.conditionalExpression(ternary.test, t14.stringLiteral(cCN), t14.stringLiteral(aCN)));
1917
- } else {
1918
- finalClassNames.push(t14.conditionalExpression(ternary.test, t14.stringLiteral(" " + cCN), t14.stringLiteral(" " + aCN)));
1919
- }
1920
- break;
1921
- }
1922
- }
1923
- node.attributes = finalAttrs;
1924
- if (finalClassNames.length) {
1925
- const names = buildClassName(finalClassNames);
1926
- const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
1927
- let expr = nameExpr;
1928
- if (nameExpr && !t14.isIdentifier(nameExpr)) {
1929
- ensureImportingConcat(programPath);
1930
- const simpleSpreads = attrs.filter((x) => t14.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
1931
- expr = t14.callExpression(t14.identifier(CONCAT_CLASSNAME_IMPORT), [
1932
- expr,
1933
- ...simpleSpreads.map((val) => val.value["argument"])
1934
- ]);
1935
- }
1936
- node.attributes.push(t14.jsxAttribute(t14.jsxIdentifier("className"), t14.jsxExpressionContainer(expr)));
1937
- }
1938
- const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
1939
- for (const { className, rules } of finalStyles) {
1940
- if (cssMap.has(className)) {
1941
- if (comment) {
1942
- const val = cssMap.get(className);
1943
- val.commentTexts.push(comment);
1944
- cssMap.set(className, val);
1945
- }
1946
- } else if (rules.length) {
1947
- if (rules.length > 1) {
1948
- console.log(" rules error", { rules });
1949
- throw new Error(`Shouldn't have more than one rule`);
1950
- }
1951
- cssMap.set(className, {
1952
- css: rules[0],
1953
- commentTexts: [comment]
1954
- });
1955
- }
1956
- }
1957
- }
1958
- }));
1959
- if (!optimized) {
1960
- return null;
1961
- }
1962
- const styles = Array.from(cssMap.values()).map((x) => {
1963
- return x.css;
1964
- }).join("\n").trim();
1965
- if (styles) {
1966
- const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
1967
- const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
1968
- const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`;
1969
- ast.program.body.unshift(t14.importDeclaration([], t14.stringLiteral(importPath)));
1970
- }
1971
- const result = (0, import_generator3.default)(ast, {
1972
- concise: false,
1973
- filename: sourcePath,
1974
- retainLines: false,
1975
- sourceFileName: sourcePath,
1976
- sourceMaps: true
1977
- }, source);
1978
- if (shouldPrintDebug) {
1979
- console.log("\n -------- output code ------- \n\n", result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n"));
1980
- console.log("\n -------- output style -------- \n\n", styles);
1981
- }
1982
- if (shouldLogTiming && mem) {
1983
- const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
1984
- console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${optimized}`.padStart(4)} optimized \xB7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
1985
- }
1986
- return {
1987
- ast,
1988
- styles,
1989
- js: result.code,
1990
- map: result.map
1991
- };
1992
- }
1993
- __name(extractToClassNames, "extractToClassNames");
1994
-
1995
- // src/patchReactNativeWeb.ts
1996
- var fs = __toModule(require("fs"));
1997
- var import_path4 = __toModule(require("path"));
1998
- function patchReactNativeWeb() {
1999
- const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
2000
- fs.writeFileSync(import_path4.default.join(rootDir, "dist", "tamagui-exports.js"), moduleExports);
2001
- fs.writeFileSync(import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js"), cjsExports);
2002
- const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
2003
- const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
2004
- if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
2005
- fs.writeFileSync(moduleEntry, `${removePatch(moduleEntrySrc)}
2006
-
2007
- // tamagui-patch-v4
2008
- import * as TExports from './tamagui-exports'
2009
- export const TamaguiExports = TExports
2010
- // tamagui-patch-end
2011
- `);
2012
- }
2013
- const cjsEntry = import_path4.default.join(rootDir, "dist", "cjs", "index.js");
2014
- const cjsEntrySrc = fs.readFileSync(cjsEntry, "utf-8");
2015
- if (!cjsEntrySrc.includes("// tamagui-patch-v4")) {
2016
- fs.writeFileSync(cjsEntry, `${removePatch(cjsEntrySrc)}
2017
-
2018
- // tamagui-patch-v4
2019
- exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
2020
- // tamagui-patch-end
2021
- `);
2022
- console.log(`Tamagui patched react-native-web`);
2023
- }
2024
- }
2025
- __name(patchReactNativeWeb, "patchReactNativeWeb");
2026
- function removePatch(source) {
2027
- return source.replace(/\/\/ tamagui-patch([.\s\S]*)/g, "");
2028
- }
2029
- __name(removePatch, "removePatch");
2030
- var forwardedPropsObj = `{
2031
- ...fwdProps.defaultProps,
2032
- ...fwdProps.accessibilityProps,
2033
- ...fwdProps.clickProps,
2034
- ...fwdProps.focusProps,
2035
- ...fwdProps.keyboardProps,
2036
- ...fwdProps.mouseProps,
2037
- ...fwdProps.touchProps,
2038
- ...fwdProps.styleProps,
2039
- href: true,
2040
- lang: true,
2041
- onScroll: true,
2042
- onWheel: true,
2043
- pointerEvents: true
2044
- }
2045
- `;
2046
- var moduleExports = `
2047
- export { atomic } from './exports/StyleSheet/compile'
2048
- export { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'
2049
- export { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'
2050
- export { default as i18Style } from './exports/StyleSheet/i18nStyle'
2051
- export { default as createDOMProps } from './modules/createDOMProps'
2052
- export { default as AccessibilityUtil } from './modules/AccessibilityUtil'
2053
- export { default as createElement } from './exports/createElement'
2054
- export { default as css } from './exports/StyleSheet/css'
2055
- export { default as TextAncestorContext } from './exports/Text/TextAncestorContext'
2056
- export { default as pick } from './modules/pick'
2057
- export { default as useElementLayout } from './modules/useElementLayout'
2058
- export { default as useMergeRefs } from './modules/useMergeRefs'
2059
- export { default as usePlatformMethods } from './modules/usePlatformMethods'
2060
- export { default as useResponderEvents } from './modules/useResponderEvents'
2061
- import * as fwdProps from './modules/forwardedProps'
2062
- export const forwardedProps = ${forwardedPropsObj}
2063
- `;
2064
- var cjsExports = `
2065
- exports.atomic = require('./exports/StyleSheet/compile').atomic
2066
- exports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')
2067
- exports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')
2068
- exports.i18Style = require('./exports/StyleSheet/i18nStyle')
2069
- exports.createDOMProps = require('./modules/createDOMProps')
2070
- exports.AccessibilityUtil = require('./modules/AccessibilityUtil')
2071
- exports.createElement = require('./exports/createElement')
2072
- exports.css = require('./exports/StyleSheet/css')
2073
- exports.TextAncestorContext = require('./exports/Text/TextAncestorContext')
2074
- exports.pick = require('./modules/pick')
2075
- exports.useElementLayout = require('./modules/useElementLayout')
2076
- exports.useMergeRefs = require('./modules/useMergeRefs')
2077
- exports.usePlatformMethods = require('./modules/usePlatformMethods')
2078
- exports.useResponderEvents = require('./modules/useResponderEvents')
2079
- const fwdProps = require('./modules/forwardedProps')
2080
- exports.forwardedProps = ${forwardedPropsObj}
2081
- `;
2082
-
2083
- // src/index.ts
2084
- process.env.TAMAGUI_COMPILE_PROCESS = "1";
2085
- //# sourceMappingURL=index.cjs.map