@tamagui/static 1.0.0-alpha.7 → 1.0.0-beta.172

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 (231) hide show
  1. package/README.md +3 -19
  2. package/dist/cjs/constants.js +36 -0
  3. package/dist/cjs/constants.js.map +7 -0
  4. package/dist/cjs/extractor/accessSafe.js +32 -0
  5. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  6. package/dist/cjs/extractor/babelParse.js +51 -0
  7. package/dist/cjs/extractor/babelParse.js.map +7 -0
  8. package/dist/cjs/extractor/buildClassName.js +61 -0
  9. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  10. package/dist/cjs/extractor/createEvaluator.js +73 -0
  11. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  12. package/dist/cjs/extractor/createExtractor.js +1100 -0
  13. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js +45 -0
  15. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js +115 -0
  17. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  18. package/dist/cjs/extractor/extractHelpers.js +124 -0
  19. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js +186 -0
  21. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  22. package/dist/cjs/extractor/extractToClassNames.js +324 -0
  23. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js +41 -0
  25. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  26. package/dist/cjs/extractor/generatedUid.js +49 -0
  27. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  28. package/dist/cjs/extractor/getPrefixLogs.js +29 -0
  29. package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
  30. package/dist/cjs/extractor/getPropValueFromAttributes.js +70 -0
  31. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  32. package/dist/cjs/extractor/getSourceModule.js +90 -0
  33. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  34. package/dist/cjs/extractor/getStaticBindingsForScope.js +149 -0
  35. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  36. package/dist/cjs/extractor/hoistClassNames.js +65 -0
  37. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  38. package/dist/cjs/extractor/literalToAst.js +114 -0
  39. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  40. package/dist/cjs/extractor/loadTamagui.js +83 -0
  41. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  42. package/dist/cjs/extractor/logLines.js +40 -0
  43. package/dist/cjs/extractor/logLines.js.map +7 -0
  44. package/dist/cjs/extractor/normalizeTernaries.js +101 -0
  45. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  46. package/dist/cjs/extractor/removeUnusedHooks.js +100 -0
  47. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  48. package/dist/cjs/extractor/validHTMLAttributes.js +71 -0
  49. package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
  50. package/dist/cjs/index.js +34 -0
  51. package/dist/cjs/index.js.map +7 -0
  52. package/dist/cjs/patchReactNativeWeb.js +151 -0
  53. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  54. package/dist/cjs/types.js +16 -0
  55. package/dist/cjs/types.js.map +7 -0
  56. package/dist/{constants.js → esm/constants.js} +4 -0
  57. package/dist/{constants.js.map → esm/constants.js.map} +3 -3
  58. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  59. package/dist/{extractor → esm/extractor}/accessSafe.js.map +2 -2
  60. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  61. package/dist/{extractor → esm/extractor}/babelParse.js.map +2 -2
  62. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  63. package/dist/{extractor → esm/extractor}/buildClassName.js.map +2 -2
  64. package/dist/{extractor → esm/extractor}/createEvaluator.js +3 -2
  65. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  66. package/dist/{extractor → esm/extractor}/createExtractor.js +430 -199
  67. package/dist/esm/extractor/createExtractor.js.map +7 -0
  68. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
  69. package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
  70. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  71. package/dist/esm/extractor/evaluateAstNode.js.map +7 -0
  72. package/dist/{extractor → esm/extractor}/extractHelpers.js +20 -11
  73. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  74. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  75. package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
  76. package/dist/{extractor → esm/extractor}/extractToClassNames.js +101 -48
  77. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  78. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  79. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +2 -2
  80. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  81. package/dist/{extractor → esm/extractor}/generatedUid.js.map +2 -2
  82. package/dist/esm/extractor/getPrefixLogs.js +12 -0
  83. package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
  84. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  85. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +2 -2
  86. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  87. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +2 -2
  88. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  89. package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
  90. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  91. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +2 -2
  92. package/dist/esm/extractor/literalToAst.js +80 -0
  93. package/dist/esm/extractor/literalToAst.js.map +7 -0
  94. package/dist/{extractor → esm/extractor}/loadTamagui.js +27 -3
  95. package/dist/esm/extractor/loadTamagui.js.map +7 -0
  96. package/dist/esm/extractor/logLines.js +22 -0
  97. package/dist/esm/extractor/logLines.js.map +7 -0
  98. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
  99. package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
  100. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
  101. package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
  102. package/dist/esm/extractor/validHTMLAttributes.js +52 -0
  103. package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
  104. package/dist/{index.js → esm/index.js} +0 -0
  105. package/dist/{index.js.map → esm/index.js.map} +1 -1
  106. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +37 -14
  107. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  108. package/dist/{types.js → esm/types.js} +0 -0
  109. package/dist/{types.js.map → esm/types.js.map} +0 -0
  110. package/dist/jsx/constants.js +13 -0
  111. package/dist/jsx/extractor/accessSafe.js +10 -0
  112. package/dist/jsx/extractor/babelParse.js +29 -0
  113. package/dist/jsx/extractor/buildClassName.js +39 -0
  114. package/dist/jsx/extractor/createEvaluator.js +51 -0
  115. package/dist/jsx/extractor/createExtractor.js +1050 -0
  116. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  117. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  118. package/dist/jsx/extractor/extractHelpers.js +102 -0
  119. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  120. package/dist/jsx/extractor/extractToClassNames.js +287 -0
  121. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  122. package/dist/jsx/extractor/generatedUid.js +27 -0
  123. package/dist/jsx/extractor/getPrefixLogs.js +11 -0
  124. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  125. package/dist/jsx/extractor/getSourceModule.js +68 -0
  126. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  127. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  128. package/dist/jsx/extractor/literalToAst.js +79 -0
  129. package/dist/jsx/extractor/loadTamagui.js +64 -0
  130. package/dist/jsx/extractor/logLines.js +21 -0
  131. package/dist/jsx/extractor/normalizeTernaries.js +52 -0
  132. package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
  133. package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
  134. package/dist/jsx/index.js +13 -0
  135. package/{src/patchReactNativeWeb.ts → dist/jsx/patchReactNativeWeb.js} +65 -59
  136. package/dist/jsx/types.js +0 -0
  137. package/package.json +26 -22
  138. package/types/constants.d.ts +6 -0
  139. package/types/constants.d.ts.map +1 -0
  140. package/types/extractor/accessSafe.d.ts +3 -0
  141. package/types/extractor/accessSafe.d.ts.map +1 -0
  142. package/types/extractor/babelParse.d.ts +5 -0
  143. package/types/extractor/babelParse.d.ts.map +1 -0
  144. package/types/extractor/buildClassName.d.ts +4 -0
  145. package/types/extractor/buildClassName.d.ts.map +1 -0
  146. package/types/extractor/createEvaluator.d.ts +12 -0
  147. package/types/extractor/createEvaluator.d.ts.map +1 -0
  148. package/types/extractor/createExtractor.d.ts +27 -0
  149. package/types/extractor/createExtractor.d.ts.map +1 -0
  150. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  151. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  152. package/types/extractor/evaluateAstNode.d.ts +3 -0
  153. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  154. package/types/extractor/extractHelpers.d.ts +12 -0
  155. package/types/extractor/extractHelpers.d.ts.map +1 -0
  156. package/types/extractor/extractMediaStyle.d.ts +10 -0
  157. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  158. package/types/extractor/extractToClassNames.d.ts +23 -0
  159. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  160. package/types/extractor/findTopmostFunction.d.ts +4 -0
  161. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  162. package/types/extractor/generatedUid.d.ts +5 -0
  163. package/types/extractor/generatedUid.d.ts.map +1 -0
  164. package/types/extractor/getPrefixLogs.d.ts +3 -0
  165. package/types/extractor/getPrefixLogs.d.ts.map +1 -0
  166. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  167. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  168. package/types/extractor/getSourceModule.d.ts +16 -0
  169. package/types/extractor/getSourceModule.d.ts.map +1 -0
  170. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  171. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  172. package/types/extractor/hoistClassNames.d.ts +6 -0
  173. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  174. package/types/extractor/literalToAst.d.ts +4 -0
  175. package/types/extractor/literalToAst.d.ts.map +1 -0
  176. package/types/extractor/loadTamagui.d.ts +9 -0
  177. package/types/extractor/loadTamagui.d.ts.map +1 -0
  178. package/types/extractor/logLines.d.ts +2 -0
  179. package/types/extractor/logLines.d.ts.map +1 -0
  180. package/types/extractor/normalizeTernaries.d.ts +3 -0
  181. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  182. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  183. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  184. package/types/extractor/validHTMLAttributes.d.ts +49 -0
  185. package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
  186. package/types/index.d.ts +8 -0
  187. package/types/index.d.ts.map +1 -0
  188. package/types/patchReactNativeWeb.d.ts +2 -0
  189. package/types/patchReactNativeWeb.d.ts.map +1 -0
  190. package/types/types.d.ts +85 -0
  191. package/types/types.d.ts.map +1 -0
  192. package/dist/extractor/createEvaluator.js.map +0 -7
  193. package/dist/extractor/createExtractor.js.map +0 -7
  194. package/dist/extractor/ensureImportingConcat.js.map +0 -7
  195. package/dist/extractor/evaluateAstNode.js.map +0 -7
  196. package/dist/extractor/extractHelpers.js.map +0 -7
  197. package/dist/extractor/extractMediaStyle.js.map +0 -7
  198. package/dist/extractor/extractToClassNames.js.map +0 -7
  199. package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
  200. package/dist/extractor/literalToAst.js +0 -34
  201. package/dist/extractor/literalToAst.js.map +0 -7
  202. package/dist/extractor/loadTamagui.js.map +0 -7
  203. package/dist/extractor/normalizeTernaries.js.map +0 -7
  204. package/dist/extractor/removeUnusedHooks.js.map +0 -7
  205. package/dist/index.cjs +0 -2109
  206. package/dist/index.cjs.map +0 -7
  207. package/dist/patchReactNativeWeb.js.map +0 -7
  208. package/src/constants.ts +0 -10
  209. package/src/extractor/accessSafe.ts +0 -18
  210. package/src/extractor/babelParse.ts +0 -27
  211. package/src/extractor/buildClassName.ts +0 -61
  212. package/src/extractor/createEvaluator.ts +0 -68
  213. package/src/extractor/createExtractor.ts +0 -1139
  214. package/src/extractor/ensureImportingConcat.ts +0 -33
  215. package/src/extractor/evaluateAstNode.ts +0 -121
  216. package/src/extractor/extractHelpers.ts +0 -102
  217. package/src/extractor/extractMediaStyle.ts +0 -191
  218. package/src/extractor/extractToClassNames.ts +0 -326
  219. package/src/extractor/findTopmostFunction.ts +0 -22
  220. package/src/extractor/generatedUid.ts +0 -43
  221. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  222. package/src/extractor/getSourceModule.ts +0 -101
  223. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  224. package/src/extractor/hoistClassNames.ts +0 -45
  225. package/src/extractor/literalToAst.ts +0 -32
  226. package/src/extractor/loadTamagui.ts +0 -61
  227. package/src/extractor/normalizeTernaries.ts +0 -60
  228. package/src/extractor/removeUnusedHooks.ts +0 -76
  229. package/src/index.ts +0 -9
  230. package/src/types.ts +0 -84
  231. package/types.d.ts +0 -217
@@ -2,9 +2,14 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import traverse from "@babel/traverse";
4
4
  import * as t from "@babel/types";
5
- import * as CoreNode from "@tamagui/core-node";
6
- import { stylePropsTransform } from "@tamagui/helpers";
5
+ import {
6
+ getSplitStyles,
7
+ mediaQueryConfig,
8
+ pseudos,
9
+ rnw
10
+ } from "@tamagui/core-node";
7
11
  import { difference, pick } from "lodash";
12
+ import { FAILED_EVAL } from "../constants";
8
13
  import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
9
14
  import { evaluateAstNode } from "./evaluateAstNode";
10
15
  import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
@@ -12,10 +17,10 @@ import { findTopmostFunction } from "./findTopmostFunction";
12
17
  import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
13
18
  import { literalToAst } from "./literalToAst";
14
19
  import { loadTamagui } from "./loadTamagui";
20
+ import { logLines } from "./logLines";
15
21
  import { normalizeTernaries } from "./normalizeTernaries";
16
22
  import { removeUnusedHooks } from "./removeUnusedHooks";
17
- const { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
18
- const FAILED_EVAL = Symbol("failed_style_eval");
23
+ import { validHTMLAttributes } from "./validHTMLAttributes";
19
24
  const UNTOUCHED_PROPS = {
20
25
  key: true,
21
26
  style: true,
@@ -36,7 +41,7 @@ function createExtractor() {
36
41
  let loadedTamaguiConfig;
37
42
  let hasLogged = false;
38
43
  return {
39
- getTamaguiConfig() {
44
+ getTamagui() {
40
45
  return loadedTamaguiConfig;
41
46
  },
42
47
  parse: (fileOrPath, {
@@ -47,11 +52,18 @@ function createExtractor() {
47
52
  sourcePath = "",
48
53
  onExtractTag,
49
54
  getFlattenedNode,
55
+ disable,
50
56
  disableExtraction,
51
57
  disableExtractInlineMedia,
58
+ disableExtractVariables,
52
59
  disableDebugAttr,
60
+ prefixLogs,
61
+ excludeProps,
53
62
  ...props
54
63
  }) => {
64
+ if (disable) {
65
+ return null;
66
+ }
55
67
  if (sourcePath === "") {
56
68
  throw new Error(`Must provide a source file name`);
57
69
  }
@@ -65,8 +77,13 @@ function createExtractor() {
65
77
  loadedTamaguiConfig = tamaguiConfig;
66
78
  const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
67
79
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
68
- const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
69
- const validComponents = Object.keys(components).filter((key) => key[0].toUpperCase() === key[0] && !!components[key]?.staticConfig).reduce((obj, name) => {
80
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
81
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
82
+ }, "isInternalImport");
83
+ const validComponents = Object.keys(components).filter((key) => {
84
+ var _a;
85
+ return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
86
+ }).reduce((obj, name) => {
70
87
  obj[name] = components[name];
71
88
  return obj;
72
89
  }, {});
@@ -93,7 +110,7 @@ function createExtractor() {
93
110
  return null;
94
111
  }
95
112
  let couldntParse = false;
96
- const modifiedComponents = new Set();
113
+ const modifiedComponents = /* @__PURE__ */ new Set();
97
114
  const bindingCache = {};
98
115
  const callTraverse = /* @__PURE__ */ __name((a) => {
99
116
  return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
@@ -102,7 +119,8 @@ function createExtractor() {
102
119
  const res = {
103
120
  flattened: 0,
104
121
  optimized: 0,
105
- modified: 0
122
+ modified: 0,
123
+ found: 0
106
124
  };
107
125
  callTraverse({
108
126
  Program: {
@@ -111,11 +129,12 @@ function createExtractor() {
111
129
  }
112
130
  },
113
131
  JSXElement(traversePath) {
132
+ var _a, _b, _c, _d, _e;
114
133
  const node = traversePath.node.openingElement;
115
134
  const ogAttributes = node.attributes;
116
135
  const componentName = findComponentName(traversePath.scope);
117
136
  const closingElement = traversePath.node.closingElement;
118
- if (t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
137
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
119
138
  return;
120
139
  }
121
140
  const binding = traversePath.scope.getBinding(node.name.name);
@@ -136,6 +155,7 @@ function createExtractor() {
136
155
  return;
137
156
  }
138
157
  const originalNodeName = node.name.name;
158
+ res.found++;
139
159
  if (shouldPrintDebug) {
140
160
  console.log(`
141
161
  <${originalNodeName} />`);
@@ -143,21 +163,28 @@ function createExtractor() {
143
163
  const filePath = sourcePath.replace(process.cwd(), ".");
144
164
  const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
145
165
  if (shouldAddDebugProp && !disableDebugAttr) {
146
- const preName = componentName ? `${componentName}:` : "";
166
+ const preName = componentName ? `${componentName}.` : "";
147
167
  res.modified++;
148
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
168
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(`${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`)));
169
+ }
170
+ const shouldLog = !hasLogged;
171
+ if (shouldLog) {
172
+ const prefix = " |";
173
+ console.log(prefixLogs || prefix, " total \xB7 optimized \xB7 flattened ");
174
+ hasLogged = true;
149
175
  }
150
176
  if (disableExtraction) {
151
- if (!hasLogged) {
152
- console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
153
- hasLogged = true;
154
- }
155
177
  return;
156
178
  }
157
179
  const { staticConfig } = component;
158
180
  const isTextView = staticConfig.isText || false;
159
- const validStyles = staticConfig?.validStyles ?? {};
160
- let tagName = staticConfig.defaultProps?.tag ?? (isTextView ? "span" : "div");
181
+ const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
182
+ function isValidStyleKey(name) {
183
+ var _a2;
184
+ return !!(!!validStyles[name] || !!pseudos[name] || ((_a2 = staticConfig.variants) == null ? void 0 : _a2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
185
+ }
186
+ __name(isValidStyleKey, "isValidStyleKey");
187
+ let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
161
188
  traversePath.get("openingElement").get("attributes").forEach((path) => {
162
189
  const attr = path.node;
163
190
  if (t.isJSXSpreadAttribute(attr))
@@ -170,23 +197,14 @@ function createExtractor() {
170
197
  tagName = val.value;
171
198
  });
172
199
  const flatNode = getFlattenedNode({ isTextView, tag: tagName });
173
- const deoptProps = new Set([
174
- ...props.deoptProps ?? [],
175
- ...staticConfig.deoptProps ?? []
200
+ const inlineProps = /* @__PURE__ */ new Set([
201
+ ...props.inlineProps || [],
202
+ ...staticConfig.inlineProps || []
203
+ ]);
204
+ const deoptProps = /* @__PURE__ */ new Set([
205
+ ...props.deoptProps || [],
206
+ ...staticConfig.deoptProps || []
176
207
  ]);
177
- const excludeProps = new Set(props.excludeProps ?? []);
178
- const isExcludedProp = /* @__PURE__ */ __name((name) => {
179
- const res2 = excludeProps.has(name);
180
- if (res2 && shouldPrintDebug)
181
- console.log(` excluding ${name}`);
182
- return res2;
183
- }, "isExcludedProp");
184
- const isDeoptedProp = /* @__PURE__ */ __name((name) => {
185
- const res2 = deoptProps.has(name);
186
- if (res2 && shouldPrintDebug)
187
- console.log(` deopting ${name}`);
188
- return res2;
189
- }, "isDeoptedProp");
190
208
  const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
191
209
  const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
192
210
  tamaguiConfig,
@@ -199,9 +217,6 @@ function createExtractor() {
199
217
  if (shouldPrintDebug) {
200
218
  console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
201
219
  }
202
- const hasDeopt = /* @__PURE__ */ __name((obj) => {
203
- return Object.keys(obj).some(isDeoptedProp);
204
- }, "hasDeopt");
205
220
  const flattenedAttrs = [];
206
221
  traversePath.get("openingElement").get("attributes").forEach((path) => {
207
222
  const attr = path.node;
@@ -219,7 +234,7 @@ function createExtractor() {
219
234
  flattenedAttrs.push(attr);
220
235
  return;
221
236
  }
222
- if (typeof arg !== "undefined") {
237
+ if (arg !== void 0) {
223
238
  try {
224
239
  if (typeof arg !== "object" || arg == null) {
225
240
  if (shouldPrintDebug) {
@@ -248,15 +263,25 @@ function createExtractor() {
248
263
  node.attributes = flattenedAttrs;
249
264
  if (staticConfig.defaultProps) {
250
265
  for (const key in staticConfig.defaultProps) {
266
+ if (isValidStyleKey(key)) {
267
+ continue;
268
+ }
251
269
  const serialize = require("babel-literal-to-ast");
252
270
  const val = staticConfig.defaultProps[key];
253
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serialize(val))));
271
+ try {
272
+ const serializedDefaultProp = serialize(val);
273
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
274
+ } catch (err) {
275
+ console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
276
+ error: ${err}
277
+ value:`, val, "\n defaultProps:", staticConfig.defaultProps);
278
+ }
254
279
  }
255
280
  }
256
281
  let attrs = [];
257
282
  let shouldDeopt = false;
258
283
  let inlinePropCount = 0;
259
- let isFlattened = false;
284
+ let hasSetOptimized = false;
260
285
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
261
286
  try {
262
287
  const res2 = evaluateAttribute(path);
@@ -265,83 +290,19 @@ function createExtractor() {
265
290
  }
266
291
  return res2;
267
292
  } catch (err) {
268
- console.log("Error extracting attribute", err.message, err.stack);
269
- console.log("node", path.node);
293
+ if (shouldPrintDebug) {
294
+ console.log("Error extracting attribute", err.message, err.stack);
295
+ console.log("node", path.node);
296
+ }
270
297
  return {
271
298
  type: "attr",
272
299
  value: path.node
273
300
  };
274
301
  }
275
302
  }).flat(4).filter(isPresent);
276
- function isStaticAttributeName(name) {
277
- return !!(!!validStyles[name] || staticConfig.validPropsExtra?.[name] || !!pseudos[name] || staticConfig.variants?.[name] || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
278
- }
279
- __name(isStaticAttributeName, "isStaticAttributeName");
280
- function isExtractable(obj) {
281
- return t.isObjectExpression(obj) && obj.properties.every((prop) => {
282
- if (!t.isObjectProperty(prop)) {
283
- console.log("not object prop", prop);
284
- return false;
285
- }
286
- const propName = prop.key["name"];
287
- if (!isStaticAttributeName(propName) && propName !== "tag") {
288
- if (shouldPrintDebug) {
289
- console.log(" not a valid style prop!", propName);
290
- }
291
- return false;
292
- }
293
- return true;
294
- });
295
- }
296
- __name(isExtractable, "isExtractable");
297
- function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
298
- if (!side) {
299
- return null;
300
- }
301
- if (!isExtractable(side)) {
302
- throw new Error("not extractable");
303
- }
304
- return side.properties.flatMap((property) => {
305
- if (!t.isObjectProperty(property)) {
306
- throw new Error("expected object property");
307
- }
308
- if (t.isConditionalExpression(property.value)) {
309
- const [truthy, falsy] = [
310
- t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
311
- t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
312
- ].map((x) => attemptEval(x));
313
- return [
314
- createTernary({
315
- remove() {
316
- },
317
- ...ternaryPartial,
318
- test: t.logicalExpression("&&", test, property.value.test),
319
- consequent: truthy,
320
- alternate: null
321
- }),
322
- createTernary({
323
- ...ternaryPartial,
324
- test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
325
- consequent: falsy,
326
- alternate: null,
327
- remove() {
328
- }
329
- })
330
- ];
331
- }
332
- const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
333
- const consequent = attemptEval(obj);
334
- return createTernary({
335
- remove() {
336
- },
337
- ...ternaryPartial,
338
- test,
339
- consequent,
340
- alternate: null
341
- });
342
- });
303
+ if (shouldPrintDebug) {
304
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
343
305
  }
344
- __name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
345
306
  function evaluateAttribute(path) {
346
307
  const attribute = path.node;
347
308
  const attr = { type: "attr", value: attribute };
@@ -368,24 +329,44 @@ function createExtractor() {
368
329
  }
369
330
  }
370
331
  if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
332
+ if (shouldPrintDebug) {
333
+ console.log(" ! inlining, spread attr");
334
+ }
371
335
  inlinePropCount++;
372
336
  return attr;
373
337
  }
374
338
  const name = attribute.name.name;
375
- if (isExcludedProp(name)) {
339
+ if (excludeProps == null ? void 0 : excludeProps.has(name)) {
340
+ if (shouldPrintDebug) {
341
+ console.log(" excluding prop", name);
342
+ }
376
343
  return null;
377
344
  }
378
- if (isDeoptedProp(name)) {
345
+ if (inlineProps.has(name)) {
346
+ inlinePropCount++;
379
347
  if (shouldPrintDebug) {
380
- console.log(" ! inlining, deopt prop", name);
348
+ console.log(" ! inlining, inline prop", name);
381
349
  }
350
+ return attr;
351
+ }
352
+ if (deoptProps.has(name)) {
353
+ shouldDeopt = true;
382
354
  inlinePropCount++;
355
+ if (shouldPrintDebug) {
356
+ console.log(" ! inlining, deopted prop", name);
357
+ }
383
358
  return attr;
384
359
  }
385
360
  if (UNTOUCHED_PROPS[name]) {
386
361
  return attr;
387
362
  }
388
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value) && !disableExtractInlineMedia) {
363
+ if (name.startsWith("data-")) {
364
+ return attr;
365
+ }
366
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
367
+ if (disableExtractInlineMedia) {
368
+ return attr;
369
+ }
389
370
  const shortname = name.slice(1);
390
371
  if (mediaQueryConfig[shortname]) {
391
372
  const expression = attribute.value.expression;
@@ -403,7 +384,7 @@ function createExtractor() {
403
384
  }
404
385
  }
405
386
  const [value, valuePath] = (() => {
406
- if (t.isJSXExpressionContainer(attribute?.value)) {
387
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
407
388
  return [attribute.value.expression, path.get("value")];
408
389
  } else {
409
390
  return [attribute.value, path.get("value")];
@@ -425,30 +406,76 @@ function createExtractor() {
425
406
  value: path.node
426
407
  };
427
408
  }
409
+ if (disableExtractVariables) {
410
+ if (value) {
411
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
412
+ if (shouldPrintDebug) {
413
+ console.log(` ! inlining, native disable extract: ${name} =`, value.value);
414
+ }
415
+ inlinePropCount++;
416
+ return attr;
417
+ }
418
+ }
419
+ }
428
420
  const styleValue = attemptEvalSafe(value);
429
- if (!isStaticAttributeName(name)) {
421
+ if (!isValidStyleKey(name)) {
430
422
  let keys = [name];
423
+ let out = null;
431
424
  if (staticConfig.propMapper) {
432
- const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
425
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, staticConfig);
433
426
  if (out) {
427
+ out = rnw.createDOMProps(isTextView ? "span" : "div", out);
428
+ delete out.className;
434
429
  keys = Object.keys(out);
435
430
  }
436
431
  }
437
- if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
438
- if (shouldPrintDebug) {
439
- console.log(" ! inlining, not static attribute name", name);
432
+ const attributes = keys.map((key) => {
433
+ const val = out[key];
434
+ if (!isValidStyleKey(key)) {
435
+ if (validHTMLAttributes[key]) {
436
+ return {
437
+ type: "attr",
438
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(literalToAst(val)))
439
+ };
440
+ }
441
+ if (shouldPrintDebug) {
442
+ console.log(" ! inlining, non-static", key);
443
+ }
444
+ inlinePropCount++;
440
445
  }
441
- inlinePropCount++;
446
+ return {
447
+ type: "style",
448
+ value: { [name]: styleValue },
449
+ name,
450
+ attr: path.node
451
+ };
452
+ });
453
+ if (inlinePropCount) {
442
454
  return attr;
443
455
  }
456
+ return attributes;
444
457
  }
445
458
  if (styleValue !== FAILED_EVAL) {
459
+ if (shouldPrintDebug) {
460
+ console.log(` style: ${name} =`, styleValue);
461
+ }
462
+ if (!(name in staticConfig.defaultProps)) {
463
+ if (!hasSetOptimized) {
464
+ res.optimized++;
465
+ hasSetOptimized = true;
466
+ }
467
+ }
446
468
  return {
447
469
  type: "style",
448
- value: { [name]: styleValue }
470
+ value: { [name]: styleValue },
471
+ name,
472
+ attr: path.node
449
473
  };
450
474
  }
451
475
  if (t.isBinaryExpression(value)) {
476
+ if (shouldPrintDebug) {
477
+ console.log(` binary expression ${name} = `, value);
478
+ }
452
479
  const { operator, left, right } = value;
453
480
  const lVal = attemptEvalSafe(left);
454
481
  const rVal = attemptEvalSafe(right);
@@ -473,16 +500,25 @@ function createExtractor() {
473
500
  }
474
501
  const staticConditional = getStaticConditional(value);
475
502
  if (staticConditional) {
503
+ if (shouldPrintDebug) {
504
+ console.log(` static conditional ${name} = `, value);
505
+ }
476
506
  return { type: "ternary", value: staticConditional };
477
507
  }
478
508
  const staticLogical = getStaticLogical(value);
479
509
  if (staticLogical) {
510
+ if (shouldPrintDebug) {
511
+ console.log(` static ternary ${name} = `, value);
512
+ }
480
513
  return { type: "ternary", value: staticLogical };
481
514
  }
482
515
  if (shouldPrintDebug) {
483
516
  console.log(" ! inline prop via no match", name, value.type);
484
517
  }
485
518
  inlinePropCount++;
519
+ if (shouldPrintDebug) {
520
+ console.log(` inlining ${name} = `, value);
521
+ }
486
522
  return attr;
487
523
  function addBinaryConditional(operator, staticExpr, cond) {
488
524
  if (getStaticConditional(cond)) {
@@ -557,13 +593,98 @@ function createExtractor() {
557
593
  __name(getStaticLogical, "getStaticLogical");
558
594
  }
559
595
  __name(evaluateAttribute, "evaluateAttribute");
560
- if (shouldPrintDebug) {
561
- console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
596
+ function isExtractable(obj) {
597
+ return t.isObjectExpression(obj) && obj.properties.every((prop) => {
598
+ if (!t.isObjectProperty(prop)) {
599
+ console.log("not object prop", prop);
600
+ return false;
601
+ }
602
+ const propName = prop.key["name"];
603
+ if (!isValidStyleKey(propName) && propName !== "tag") {
604
+ if (shouldPrintDebug) {
605
+ console.log(" not a valid style prop!", propName);
606
+ }
607
+ return false;
608
+ }
609
+ return true;
610
+ });
562
611
  }
612
+ __name(isExtractable, "isExtractable");
613
+ function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
614
+ if (!side) {
615
+ return null;
616
+ }
617
+ if (!isExtractable(side)) {
618
+ throw new Error("not extractable");
619
+ }
620
+ return side.properties.flatMap((property) => {
621
+ if (!t.isObjectProperty(property)) {
622
+ throw new Error("expected object property");
623
+ }
624
+ if (t.isIdentifier(property.key)) {
625
+ const key = property.key.name;
626
+ const mediaQueryKey = key.slice(1);
627
+ const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
628
+ if (isMediaQuery) {
629
+ if (t.isExpression(property.value)) {
630
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
631
+ inlineMediaQuery: mediaQueryKey
632
+ });
633
+ if (ternaries2) {
634
+ return ternaries2.map((value) => ({
635
+ ...ternaryPartial,
636
+ ...value,
637
+ test: t.logicalExpression("&&", value.test, test)
638
+ }));
639
+ } else {
640
+ console.log("\u26A0\uFE0F no ternaries?", property);
641
+ }
642
+ } else {
643
+ console.log("\u26A0\uFE0F not expression", property);
644
+ }
645
+ }
646
+ }
647
+ if (t.isConditionalExpression(property.value)) {
648
+ const [truthy, falsy] = [
649
+ t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
650
+ t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
651
+ ].map((x) => attemptEval(x));
652
+ return [
653
+ createTernary({
654
+ remove() {
655
+ },
656
+ ...ternaryPartial,
657
+ test: t.logicalExpression("&&", test, property.value.test),
658
+ consequent: truthy,
659
+ alternate: null
660
+ }),
661
+ createTernary({
662
+ ...ternaryPartial,
663
+ test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
664
+ consequent: falsy,
665
+ alternate: null,
666
+ remove() {
667
+ }
668
+ })
669
+ ];
670
+ }
671
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
672
+ const consequent = attemptEval(obj);
673
+ return createTernary({
674
+ remove() {
675
+ },
676
+ ...ternaryPartial,
677
+ test,
678
+ consequent,
679
+ alternate: null
680
+ });
681
+ });
682
+ }
683
+ __name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
563
684
  node.attributes = attrs.filter(isAttr).map((x) => x.value);
564
- if (couldntParse) {
685
+ if (couldntParse || shouldDeopt) {
565
686
  if (shouldPrintDebug) {
566
- console.log(` cancel:`, { couldntParse, shouldDeopt });
687
+ console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
567
688
  }
568
689
  node.attributes = ogAttributes;
569
690
  return;
@@ -630,99 +751,196 @@ function createExtractor() {
630
751
  const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
631
752
  const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
632
753
  const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
754
+ if (shouldFlatten && staticConfig.defaultProps) {
755
+ const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
756
+ if (!isValidStyleKey(key)) {
757
+ return;
758
+ }
759
+ try {
760
+ const serialize = require("babel-literal-to-ast");
761
+ const val = staticConfig.defaultProps[key];
762
+ const value = serialize(val);
763
+ const name = tamaguiConfig.shorthands[key] || key;
764
+ return {
765
+ type: "style",
766
+ name,
767
+ value
768
+ };
769
+ } catch (err) {
770
+ console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key}
771
+ error: ${err}`);
772
+ shouldDeopt = true;
773
+ }
774
+ });
775
+ if (defaultStyleAttrs.length) {
776
+ attrs = [...defaultStyleAttrs, ...attrs];
777
+ }
778
+ }
779
+ if (shouldDeopt) {
780
+ node.attributes = ogAttributes;
781
+ return;
782
+ }
783
+ const ensureOverridden = {};
633
784
  if (!shouldFlatten) {
634
- attrs = attrs.reduce((acc, cur) => {
785
+ for (const cur of attrs) {
635
786
  if (cur.type === "style") {
636
787
  for (const key in cur.value) {
637
- const shouldInsertNull = !!staticConfig.ensureOverriddenProp?.[key];
788
+ const shouldEnsureOverridden = !!((_d = staticConfig.ensureOverriddenProp) == null ? void 0 : _d[key]);
638
789
  const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
639
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
640
- if (shouldInsertNullOverride) {
641
- acc.push({
642
- type: "attr",
643
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
644
- });
790
+ if (!isSetInAttrsAlready) {
791
+ const isVariant = !!((_e = staticConfig.variants) == null ? void 0 : _e[cur.name || ""]);
792
+ if (isVariant || shouldEnsureOverridden) {
793
+ ensureOverridden[key] = true;
794
+ }
645
795
  }
646
796
  }
647
797
  }
648
- acc.push(cur);
649
- return acc;
650
- }, []);
798
+ }
651
799
  }
652
800
  if (shouldPrintDebug) {
653
- console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
801
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
802
+ console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
654
803
  }
655
804
  attrs = attrs.reduce((acc, cur) => {
656
- if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
657
- if (cur.type === "style") {
658
- const key = Object.keys(cur.value)[0];
659
- if (!validStyles[key] && !pseudos[key]) {
660
- if (shouldPrintDebug) {
661
- console.log(" \u274C excluding", key);
662
- }
663
- return acc;
805
+ if (!cur) {
806
+ return acc;
807
+ }
808
+ if (shouldFlatten && cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value) && cur.value.name.name === "tag") {
809
+ return acc;
810
+ }
811
+ if (cur.type !== "style") {
812
+ acc.push(cur);
813
+ return acc;
814
+ }
815
+ let key = Object.keys(cur.value)[0];
816
+ const value = cur.value[key];
817
+ const fullKey = tamaguiConfig.shorthands[key];
818
+ if (fullKey) {
819
+ cur.value = { [fullKey]: value };
820
+ key = fullKey;
821
+ }
822
+ if (disableExtractVariables) {
823
+ if (value[0] === "$") {
824
+ if (shouldPrintDebug) {
825
+ console.log(` keeping variable inline: ${key} =`, value);
664
826
  }
827
+ acc.push({
828
+ type: "attr",
829
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
830
+ });
831
+ return acc;
665
832
  }
666
833
  }
667
834
  acc.push(cur);
668
835
  return acc;
669
836
  }, []);
670
837
  if (shouldPrintDebug) {
671
- console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
838
+ console.log(" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", ")));
672
839
  }
673
840
  let prev = null;
841
+ function mergeStyles(prev2, next) {
842
+ for (const key in next) {
843
+ if (pseudos[key]) {
844
+ prev2[key] = prev2[key] || {};
845
+ Object.assign(prev2[key], next[key]);
846
+ } else {
847
+ prev2[key] = next[key];
848
+ }
849
+ }
850
+ }
851
+ __name(mergeStyles, "mergeStyles");
674
852
  attrs = attrs.reduce((acc, cur) => {
675
853
  if (cur.type === "style") {
676
- if (prev?.type === "style") {
677
- Object.assign(prev.value, cur.value);
854
+ const key = Object.keys(cur.value)[0];
855
+ const value = cur.value[key];
856
+ const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudos[key] && !key.startsWith("data-");
857
+ if (shouldPrintDebug) {
858
+ console.log("go", {
859
+ key,
860
+ value,
861
+ prevType: prev == null ? void 0 : prev.type,
862
+ shouldKeepOriginalAttr,
863
+ ensureOverridden: ensureOverridden[key]
864
+ });
865
+ }
866
+ if (shouldKeepOriginalAttr) {
867
+ if (shouldPrintDebug) {
868
+ console.log(" - keeping as non-style", key);
869
+ }
870
+ prev = cur;
871
+ acc.push({
872
+ type: "attr",
873
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
874
+ });
875
+ acc.push(cur);
876
+ return acc;
877
+ }
878
+ if (ensureOverridden[key]) {
879
+ acc.push({
880
+ type: "attr",
881
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
882
+ });
883
+ }
884
+ if ((prev == null ? void 0 : prev.type) === "style") {
885
+ mergeStyles(prev.value, cur.value);
678
886
  return acc;
679
887
  }
680
888
  }
681
- acc.push(cur);
682
889
  prev = cur;
890
+ acc.push(cur);
683
891
  return acc;
684
892
  }, []);
685
893
  if (shouldPrintDebug) {
686
- console.log(" - attrs (combined \u{1F500}): ", attrs.map(attrStr).join(", "));
894
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
687
895
  }
688
- const getStyles = /* @__PURE__ */ __name((props2) => {
896
+ const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
689
897
  if (!props2)
690
898
  return;
691
- if (!!excludeProps.size) {
899
+ if (!Object.keys(props2).length)
900
+ return;
901
+ if (excludeProps && !!excludeProps.size) {
692
902
  for (const key in props2) {
693
- if (isExcludedProp(key))
903
+ if (excludeProps.has(key)) {
694
904
  delete props2[key];
905
+ }
695
906
  }
696
907
  }
697
- const out = postProcessStyles(props2, staticConfig, defaultTheme);
698
- const next = out?.style ?? props2;
699
- if (shouldPrintDebug) {
700
- console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
701
- console.log(" >> style: ", objToStr(out.style));
702
- console.log(" >> viewp: ", objToStr(out.viewProps));
908
+ const out = getSplitStyles(props2, staticConfig, defaultTheme, {
909
+ noClassNames: true
910
+ });
911
+ const outStyle = {
912
+ ...out.style,
913
+ ...out.pseudos
914
+ };
915
+ if (shouldPrintDebug === "verbose") {
916
+ console.log(` getStyles ${debugName} (props):
917
+ `, logLines(objToStr(props2)));
918
+ console.log(` getStyles ${debugName} (out.viewProps):
919
+ `, logLines(objToStr(out.viewProps)));
920
+ console.log(` getStyles ${debugName} (out.style):
921
+ `, logLines(objToStr(outStyle || {}), true));
703
922
  }
704
- if (staticConfig.validStyles) {
705
- for (const key in next) {
923
+ for (const key in outStyle) {
924
+ if (staticConfig.validStyles) {
706
925
  if (!staticConfig.validStyles[key] && !pseudos[key]) {
707
- delete next[key];
926
+ delete outStyle[key];
708
927
  }
709
928
  }
710
929
  }
711
- return next;
930
+ return outStyle;
712
931
  }, "getStyles");
713
- if (shouldPrintDebug) {
714
- console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
715
- }
716
932
  const completeStylesProcessed = getStyles({
717
933
  ...staticConfig.defaultProps,
718
934
  ...completeStaticProps
719
- });
720
- const stylesToAddToInitialGroup = difference(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
935
+ }, "completeStylesProcessed");
936
+ if (!completeStylesProcessed) {
937
+ throw new Error(`Impossible, no styles`);
938
+ }
939
+ const stylesToAddToInitialGroup = shouldFlatten ? difference(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps)) : [];
721
940
  if (stylesToAddToInitialGroup.length) {
722
941
  const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
723
942
  const firstGroup = attrs.find((x) => x.type === "style");
724
943
  if (shouldPrintDebug) {
725
- console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
726
944
  console.log(" toAdd", objToStr(toAdd));
727
945
  }
728
946
  if (!firstGroup) {
@@ -732,49 +950,64 @@ function createExtractor() {
732
950
  }
733
951
  }
734
952
  if (shouldPrintDebug) {
735
- console.log(" completeStaticProps", objToStr(completeStaticProps));
736
- console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
953
+ console.log(" -- stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "), { shouldFlatten });
954
+ console.log(" -- completeStaticProps:\n", logLines(objToStr(completeStaticProps)));
955
+ console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
737
956
  }
957
+ let getStyleError = null;
738
958
  for (const attr of attrs) {
739
959
  try {
960
+ if (shouldPrintDebug)
961
+ console.log(" *", attrStr(attr));
740
962
  switch (attr.type) {
741
963
  case "ternary":
742
- const a = getStyles(attr.value.alternate);
743
- const c = getStyles(attr.value.consequent);
744
- attr.value.alternate = a;
745
- attr.value.consequent = c;
746
- if (shouldPrintDebug) {
964
+ const a = getStyles(attr.value.alternate, "ternary.alternate");
965
+ const c = getStyles(attr.value.consequent, "ternary.consequent");
966
+ if (a)
967
+ attr.value.alternate = a;
968
+ if (c)
969
+ attr.value.consequent = c;
970
+ if (shouldPrintDebug)
747
971
  console.log(" => tern ", attrStr(attr));
748
- }
749
- break;
972
+ continue;
750
973
  case "style":
751
- const next = {};
752
- for (const key in attr.value) {
753
- if (key in stylePropsTransform) {
754
- next["transform"] = completeStylesProcessed["transform"];
755
- } else {
756
- next[key] = completeStylesProcessed[key] ?? attr.value[key];
757
- }
974
+ const styles = getStyles(attr.value, "style");
975
+ if (styles) {
976
+ attr.value = Object.fromEntries(Object.keys(styles).map((k) => [k, completeStylesProcessed[k]]));
977
+ } else {
978
+ console.warn("?????????");
758
979
  }
759
- attr.value = next;
760
- break;
980
+ continue;
761
981
  }
762
982
  } catch (err) {
763
- if (shouldPrintDebug) {
764
- console.log(" postprocessing error, deopt", err);
765
- node.attributes = ogAttributes;
766
- return node;
983
+ getStyleError = err;
984
+ }
985
+ }
986
+ if (getStyleError) {
987
+ console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
988
+ node.attributes = ogAttributes;
989
+ return node;
990
+ }
991
+ const existingStyleKeys = /* @__PURE__ */ new Set();
992
+ for (let i = attrs.length - 1; i >= 0; i--) {
993
+ const attr = attrs[i];
994
+ if (attr.type === "style") {
995
+ for (const key in attr.value) {
996
+ if (existingStyleKeys.has(key)) {
997
+ delete attr.value[key];
998
+ } else {
999
+ existingStyleKeys.add(key);
1000
+ }
767
1001
  }
768
1002
  }
769
1003
  }
770
1004
  if (shouldPrintDebug) {
771
- console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
1005
+ console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
772
1006
  }
773
1007
  if (shouldFlatten) {
774
1008
  if (shouldPrintDebug) {
775
1009
  console.log(" [\u2705] flattening", originalNodeName, flatNode);
776
1010
  }
777
- isFlattened = true;
778
1011
  node.name.name = flatNode;
779
1012
  res.flattened++;
780
1013
  if (closingElement) {
@@ -782,10 +1015,9 @@ function createExtractor() {
782
1015
  }
783
1016
  }
784
1017
  if (shouldPrintDebug) {
785
- console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
786
- console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
1018
+ console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1019
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
787
1020
  }
788
- res.optimized++;
789
1021
  onExtractTag({
790
1022
  attrs,
791
1023
  node,
@@ -794,7 +1026,7 @@ function createExtractor() {
794
1026
  attemptEval,
795
1027
  jsxPath: traversePath,
796
1028
  originalNodeName,
797
- isFlattened,
1029
+ isFlattened: shouldFlatten,
798
1030
  programPath
799
1031
  });
800
1032
  }
@@ -814,7 +1046,6 @@ function createExtractor() {
814
1046
  }
815
1047
  __name(createExtractor, "createExtractor");
816
1048
  export {
817
- FAILED_EVAL,
818
1049
  createExtractor
819
1050
  };
820
1051
  //# sourceMappingURL=createExtractor.js.map