@tamagui/static 1.0.0-alpha.38 → 1.0.0-alpha.39

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 (163) hide show
  1. package/dist/cjs/constants.js +33 -0
  2. package/dist/cjs/constants.js.map +7 -0
  3. package/dist/cjs/extractor/accessSafe.js +33 -0
  4. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  5. package/dist/cjs/extractor/babelParse.js +52 -0
  6. package/dist/cjs/extractor/babelParse.js.map +7 -0
  7. package/dist/cjs/extractor/buildClassName.js +62 -0
  8. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  9. package/dist/cjs/extractor/createEvaluator.js +73 -0
  10. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  11. package/dist/cjs/extractor/createExtractor.js +903 -0
  12. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  13. package/dist/cjs/extractor/ensureImportingConcat.js +46 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  15. package/dist/cjs/extractor/evaluateAstNode.js +116 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  17. package/dist/cjs/extractor/extractHelpers.js +118 -0
  18. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  19. package/dist/cjs/extractor/extractMediaStyle.js +187 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  21. package/dist/cjs/extractor/extractToClassNames.js +279 -0
  22. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  23. package/dist/cjs/extractor/findTopmostFunction.js +29 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  25. package/dist/cjs/extractor/generatedUid.js +50 -0
  26. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  27. package/dist/cjs/extractor/getPropValueFromAttributes.js +71 -0
  28. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  29. package/dist/cjs/extractor/getSourceModule.js +91 -0
  30. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  31. package/dist/cjs/extractor/getStaticBindingsForScope.js +150 -0
  32. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  33. package/dist/cjs/extractor/hoistClassNames.js +66 -0
  34. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  35. package/dist/cjs/extractor/literalToAst.js +56 -0
  36. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  37. package/dist/cjs/extractor/loadTamagui.js +63 -0
  38. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  39. package/dist/cjs/extractor/logLines.js +23 -0
  40. package/dist/cjs/extractor/logLines.js.map +7 -0
  41. package/dist/cjs/extractor/normalizeTernaries.js +102 -0
  42. package/dist/{extractor → cjs/extractor}/normalizeTernaries.js.map +2 -2
  43. package/dist/cjs/extractor/removeUnusedHooks.js +101 -0
  44. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  45. package/dist/cjs/index.js +37 -0
  46. package/dist/cjs/index.js.map +7 -0
  47. package/dist/cjs/patchReactNativeWeb.js +129 -0
  48. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  49. package/dist/cjs/types.js +4 -0
  50. package/dist/cjs/types.js.map +7 -0
  51. package/dist/{constants.js → esm/constants.js} +0 -0
  52. package/dist/{constants.js.map → esm/constants.js.map} +1 -1
  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 +0 -0
  60. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  61. package/dist/{extractor → esm/extractor}/createExtractor.js +148 -109
  62. package/dist/esm/extractor/createExtractor.js.map +7 -0
  63. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +0 -0
  64. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js.map +1 -1
  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 +8 -4
  68. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +13 -10
  70. package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +26 -29
  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 -7
  82. package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
  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/esm/extractor/loadTamagui.js +41 -0
  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/esm/extractor/normalizeTernaries.js.map +7 -0
  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} +1 -1
  96. package/dist/{index.js.map → esm/index.js.map} +2 -2
  97. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +30 -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 +9 -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 +846 -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 +241 -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 +40 -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 +106 -0
  125. package/dist/jsx/types.js +0 -0
  126. package/package.json +7 -7
  127. package/types/constants.d.ts.map +1 -0
  128. package/types/extractor/accessSafe.d.ts.map +1 -0
  129. package/types/extractor/babelParse.d.ts.map +1 -0
  130. package/types/extractor/buildClassName.d.ts.map +1 -0
  131. package/types/extractor/createEvaluator.d.ts.map +1 -0
  132. package/types/extractor/createExtractor.d.ts.map +1 -0
  133. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  134. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  135. package/types/extractor/extractHelpers.d.ts.map +1 -0
  136. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  137. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  138. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  139. package/types/extractor/generatedUid.d.ts.map +1 -0
  140. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  141. package/types/extractor/getSourceModule.d.ts.map +1 -0
  142. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  143. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  144. package/types/extractor/literalToAst.d.ts.map +1 -0
  145. package/types/extractor/loadTamagui.d.ts.map +1 -0
  146. package/types/extractor/logLines.d.ts.map +1 -0
  147. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  148. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  149. package/types/index.d.ts.map +1 -0
  150. package/types/patchReactNativeWeb.d.ts.map +1 -0
  151. package/types/types.d.ts.map +1 -0
  152. package/dist/.buildinfo +0 -1
  153. package/dist/extractor/createEvaluator.js.map +0 -7
  154. package/dist/extractor/createExtractor.js.map +0 -7
  155. package/dist/extractor/extractHelpers.js.map +0 -7
  156. package/dist/extractor/extractMediaStyle.js.map +0 -7
  157. package/dist/extractor/extractToClassNames.js.map +0 -7
  158. package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
  159. package/dist/forwardPropsList.js +0 -140
  160. package/dist/forwardPropsList.js.map +0 -7
  161. package/dist/index.cjs +0 -2044
  162. package/dist/index.cjs.map +0 -7
  163. package/dist/patchReactNativeWeb.js.map +0 -7
@@ -1,10 +1,9 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { join } from "path";
4
3
  import traverse from "@babel/traverse";
5
4
  import * as t from "@babel/types";
6
5
  import * as CoreNode from "@tamagui/core-node";
7
- import { pseudos } from "@tamagui/helpers";
6
+ import { stylePropsTransform } from "@tamagui/helpers";
8
7
  import { difference, pick } from "lodash";
9
8
  import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
10
9
  import { evaluateAstNode } from "./evaluateAstNode";
@@ -12,9 +11,11 @@ import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from
12
11
  import { findTopmostFunction } from "./findTopmostFunction";
13
12
  import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
14
13
  import { literalToAst } from "./literalToAst";
14
+ import { loadTamagui } from "./loadTamagui";
15
+ import { logLines } from "./logLines";
15
16
  import { normalizeTernaries } from "./normalizeTernaries";
16
17
  import { removeUnusedHooks } from "./removeUnusedHooks";
17
- const { mediaQueryConfig, postProcessStyles } = CoreNode;
18
+ const { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
18
19
  const FAILED_EVAL = Symbol("failed_style_eval");
19
20
  const UNTOUCHED_PROPS = {
20
21
  key: true,
@@ -27,44 +28,18 @@ const validHooks = {
27
28
  useTheme: true
28
29
  };
29
30
  const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
30
- let loadedTamagui = null;
31
- function loadTamagui(props) {
32
- if (loadedTamagui) {
33
- return loadedTamagui;
34
- }
35
- process.env.IS_STATIC = "is_static";
36
- const proxyWorm = require("@dish/proxy-worm");
37
- const Mod = require("module");
38
- const og = Mod.prototype.require;
39
- Mod.prototype.require = function(path) {
40
- if (path.startsWith("react-native")) {
41
- return proxyWorm;
42
- }
43
- return og.apply(this, arguments);
44
- };
45
- const tamaguiConfigExport = require(join(process.cwd(), props.config));
46
- const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
47
- const components = {};
48
- for (const module of props.components) {
49
- const exported = require(module);
50
- Object.assign(components, exported);
51
- }
52
- process.env.IS_STATIC = void 0;
53
- Mod.prototype.require = og;
54
- return {
55
- components,
56
- tamaguiConfig
57
- };
58
- }
59
- __name(loadTamagui, "loadTamagui");
60
31
  function createExtractor() {
61
- console.log("create");
62
- const shouldAddDebugProp = process.env.TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
32
+ 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);
63
33
  require("esbuild-register/dist/node").register({
64
34
  target: "es2019",
65
35
  format: "cjs"
66
36
  });
37
+ let loadedTamaguiConfig;
38
+ let hasLogged = false;
67
39
  return {
40
+ getTamagui() {
41
+ return loadedTamaguiConfig;
42
+ },
68
43
  parse: (fileOrPath, {
69
44
  config = "tamagui.config.ts",
70
45
  importsWhitelist = ["constants.js"],
@@ -73,29 +48,42 @@ function createExtractor() {
73
48
  sourcePath = "",
74
49
  onExtractTag,
75
50
  getFlattenedNode,
76
- onDidFlatten,
51
+ disableExtraction,
52
+ disableExtractInlineMedia,
53
+ disableExtractVariables,
54
+ disableDebugAttr,
77
55
  ...props
78
56
  }) => {
79
57
  if (sourcePath === "") {
80
58
  throw new Error(`Must provide a source file name`);
81
59
  }
60
+ if (!Array.isArray(props.components)) {
61
+ throw new Error(`Must provide components array with list of Tamagui component modules`);
62
+ }
82
63
  const { components, tamaguiConfig } = loadTamagui({
83
64
  config,
84
65
  components: props.components || ["tamagui"]
85
66
  });
86
- let doesUseValidImport = false;
67
+ loadedTamaguiConfig = tamaguiConfig;
68
+ const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
87
69
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
88
- const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
89
- const validComponents = Object.keys(components).filter((key) => !!components[key]?.staticConfig).reduce((obj, name) => {
70
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
71
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
72
+ }, "isInternalImport");
73
+ const validComponents = Object.keys(components).filter((key) => {
74
+ var _a;
75
+ return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
76
+ }).reduce((obj, name) => {
90
77
  obj[name] = components[name];
91
78
  return obj;
92
79
  }, {});
80
+ let doesUseValidImport = false;
93
81
  for (const bodyPath of body) {
94
82
  if (bodyPath.type !== "ImportDeclaration")
95
83
  continue;
96
84
  const node = "node" in bodyPath ? bodyPath.node : bodyPath;
97
85
  const from = node.source.value;
98
- if (from === "tamagui" || isInternalImport(from)) {
86
+ if (props.components.includes(from) || isInternalImport(from)) {
99
87
  if (node.specifiers.some((specifier) => {
100
88
  const name = specifier.local.name;
101
89
  return validComponents[name] || validHooks[name];
@@ -118,6 +106,11 @@ function createExtractor() {
118
106
  return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
119
107
  }, "callTraverse");
120
108
  let programPath;
109
+ const res = {
110
+ flattened: 0,
111
+ optimized: 0,
112
+ modified: 0
113
+ };
121
114
  callTraverse({
122
115
  Program: {
123
116
  enter(path) {
@@ -125,11 +118,12 @@ function createExtractor() {
125
118
  }
126
119
  },
127
120
  JSXElement(traversePath) {
121
+ var _a, _b, _c, _d, _e, _f, _g;
128
122
  const node = traversePath.node.openingElement;
129
123
  const ogAttributes = node.attributes;
130
124
  const componentName = findComponentName(traversePath.scope);
131
125
  const closingElement = traversePath.node.closingElement;
132
- if (t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
126
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
133
127
  return;
134
128
  }
135
129
  const binding = traversePath.scope.getBinding(node.name.name);
@@ -138,7 +132,7 @@ function createExtractor() {
138
132
  return;
139
133
  }
140
134
  const source = binding.path.parent.source;
141
- if (source.value !== "tamagui" && !isInternalImport(source.value)) {
135
+ if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
142
136
  return;
143
137
  }
144
138
  if (!validComponents[binding.identifier.name]) {
@@ -149,11 +143,29 @@ function createExtractor() {
149
143
  if (!component || !component.staticConfig) {
150
144
  return;
151
145
  }
152
- const { staticConfig } = component;
153
146
  const originalNodeName = node.name.name;
147
+ if (shouldPrintDebug) {
148
+ console.log(`
149
+ <${originalNodeName} />`);
150
+ }
151
+ const filePath = sourcePath.replace(process.cwd(), ".");
152
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
153
+ if (shouldAddDebugProp && !disableDebugAttr) {
154
+ const preName = componentName ? `${componentName}:` : "";
155
+ res.modified++;
156
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
157
+ }
158
+ if (disableExtraction) {
159
+ if (!hasLogged) {
160
+ console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
161
+ hasLogged = true;
162
+ }
163
+ return;
164
+ }
165
+ const { staticConfig } = component;
154
166
  const isTextView = staticConfig.isText || false;
155
- const validStyles = staticConfig?.validStyles ?? {};
156
- let tagName = isTextView ? "span" : "div";
167
+ const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
168
+ let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
157
169
  traversePath.get("openingElement").get("attributes").forEach((path) => {
158
170
  const attr = path.node;
159
171
  if (t.isJSXSpreadAttribute(attr))
@@ -167,26 +179,22 @@ function createExtractor() {
167
179
  });
168
180
  const flatNode = getFlattenedNode({ isTextView, tag: tagName });
169
181
  const deoptProps = new Set([
170
- ...props.deoptProps ?? [],
171
- ...staticConfig.deoptProps ?? []
182
+ ...(_d = props.deoptProps) != null ? _d : [],
183
+ ...(_e = staticConfig.deoptProps) != null ? _e : []
172
184
  ]);
173
- const excludeProps = new Set(props.excludeProps ?? []);
185
+ const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
174
186
  const isExcludedProp = /* @__PURE__ */ __name((name) => {
175
- const res = excludeProps.has(name);
176
- if (res && shouldPrintDebug)
187
+ const res2 = excludeProps.has(name);
188
+ if (res2 && shouldPrintDebug)
177
189
  console.log(` excluding ${name}`);
178
- return res;
190
+ return res2;
179
191
  }, "isExcludedProp");
180
192
  const isDeoptedProp = /* @__PURE__ */ __name((name) => {
181
- const res = deoptProps.has(name);
182
- if (res && shouldPrintDebug)
193
+ const res2 = deoptProps.has(name);
194
+ if (res2 && shouldPrintDebug)
183
195
  console.log(` deopting ${name}`);
184
- return res;
196
+ return res2;
185
197
  }, "isDeoptedProp");
186
- if (shouldPrintDebug) {
187
- console.log(`
188
- <${originalNodeName} />`);
189
- }
190
198
  const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
191
199
  const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
192
200
  tamaguiConfig,
@@ -259,11 +267,11 @@ function createExtractor() {
259
267
  let isFlattened = false;
260
268
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
261
269
  try {
262
- const res = evaluateAttribute(path);
263
- if (!res) {
270
+ const res2 = evaluateAttribute(path);
271
+ if (!res2) {
264
272
  path.remove();
265
273
  }
266
- return res;
274
+ return res2;
267
275
  } catch (err) {
268
276
  console.log("Error extracting attribute", err.message, err.stack);
269
277
  console.log("node", path.node);
@@ -274,7 +282,8 @@ function createExtractor() {
274
282
  }
275
283
  }).flat(4).filter(isPresent);
276
284
  function isStaticAttributeName(name) {
277
- return !!validStyles[name] || staticConfig.validPropsExtra?.[name] || !!pseudos[name];
285
+ var _a2, _b2;
286
+ return !!(!!validStyles[name] || ((_a2 = staticConfig.validPropsExtra) == null ? void 0 : _a2[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
278
287
  }
279
288
  __name(isStaticAttributeName, "isStaticAttributeName");
280
289
  function isExtractable(obj) {
@@ -284,8 +293,10 @@ function createExtractor() {
284
293
  return false;
285
294
  }
286
295
  const propName = prop.key["name"];
287
- if (!isStaticAttributeName(propName)) {
288
- console.log(" not a valid style prop!", propName);
296
+ if (!isStaticAttributeName(propName) && propName !== "tag") {
297
+ if (shouldPrintDebug) {
298
+ console.log(" not a valid style prop!", propName);
299
+ }
289
300
  return false;
290
301
  }
291
302
  return true;
@@ -345,13 +356,15 @@ function createExtractor() {
345
356
  const attr = { type: "attr", value: attribute };
346
357
  if (t.isJSXSpreadAttribute(attribute)) {
347
358
  const arg = attribute.argument;
348
- const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.alternate, arg.consequent] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
359
+ const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
349
360
  if (conditional) {
350
361
  const [test, alt, cons] = conditional;
351
362
  if (!test)
352
363
  throw new Error(`no test`);
353
364
  if ([alt, cons].some((side) => side && !isExtractable(side))) {
354
- console.log("not extractable", alt, cons);
365
+ if (shouldPrintDebug) {
366
+ console.log("not extractable", alt, cons);
367
+ }
355
368
  return attr;
356
369
  }
357
370
  return [
@@ -381,7 +394,10 @@ function createExtractor() {
381
394
  if (UNTOUCHED_PROPS[name]) {
382
395
  return attr;
383
396
  }
384
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
397
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
398
+ if (disableExtractInlineMedia) {
399
+ return attr;
400
+ }
385
401
  const shortname = name.slice(1);
386
402
  if (mediaQueryConfig[shortname]) {
387
403
  const expression = attribute.value.expression;
@@ -399,7 +415,7 @@ function createExtractor() {
399
415
  }
400
416
  }
401
417
  const [value, valuePath] = (() => {
402
- if (t.isJSXExpressionContainer(attribute?.value)) {
418
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
403
419
  return [attribute.value.expression, path.get("value")];
404
420
  } else {
405
421
  return [attribute.value, path.get("value")];
@@ -415,11 +431,33 @@ function createExtractor() {
415
431
  inlinePropCount++;
416
432
  return attr;
417
433
  }
434
+ if (name === "tag") {
435
+ return {
436
+ type: "attr",
437
+ value: path.node
438
+ };
439
+ }
440
+ if (disableExtractVariables) {
441
+ if (value) {
442
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
443
+ if (shouldPrintDebug) {
444
+ console.log(" native, disable extract var", value.value);
445
+ }
446
+ inlinePropCount++;
447
+ return attr;
448
+ }
449
+ }
450
+ }
418
451
  const styleValue = attemptEvalSafe(value);
419
452
  if (!isStaticAttributeName(name)) {
420
453
  let keys = [name];
421
- console.warn("\u26A0\uFE0F NEED TO DO PROP MAPPING HERE");
422
- if (keys.some((k) => !isStaticAttributeName(k))) {
454
+ if (staticConfig.propMapper) {
455
+ const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
456
+ if (out) {
457
+ keys = Object.keys(out);
458
+ }
459
+ }
460
+ if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
423
461
  if (shouldPrintDebug) {
424
462
  console.log(" ! inlining, not static attribute name", name);
425
463
  }
@@ -430,7 +468,9 @@ function createExtractor() {
430
468
  if (styleValue !== FAILED_EVAL) {
431
469
  return {
432
470
  type: "style",
433
- value: { [name]: styleValue }
471
+ value: { [name]: styleValue },
472
+ name,
473
+ attr: path.node
434
474
  };
435
475
  }
436
476
  if (t.isBinaryExpression(value)) {
@@ -492,6 +532,9 @@ function createExtractor() {
492
532
  function getStaticConditional(value2) {
493
533
  if (t.isConditionalExpression(value2)) {
494
534
  try {
535
+ if (shouldPrintDebug) {
536
+ console.log("attempt", value2.alternate, value2.consequent);
537
+ }
495
538
  const aVal = attemptEval(value2.alternate);
496
539
  const cVal = attemptEval(value2.consequent);
497
540
  if (shouldPrintDebug) {
@@ -540,7 +583,7 @@ function createExtractor() {
540
583
  }
541
584
  __name(evaluateAttribute, "evaluateAttribute");
542
585
  if (shouldPrintDebug) {
543
- console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
586
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
544
587
  }
545
588
  node.attributes = attrs.filter(isAttr).map((x) => x.value);
546
589
  if (couldntParse) {
@@ -554,8 +597,6 @@ function createExtractor() {
554
597
  if (parentFn) {
555
598
  modifiedComponents.add(parentFn);
556
599
  }
557
- const filePath = sourcePath.replace(process.cwd(), ".");
558
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
559
600
  let ternaries = [];
560
601
  attrs = attrs.reduce((out, cur) => {
561
602
  const next = attrs[attrs.indexOf(cur) + 1];
@@ -616,16 +657,19 @@ function createExtractor() {
616
657
  const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
617
658
  if (!shouldFlatten) {
618
659
  attrs = attrs.reduce((acc, cur) => {
660
+ var _a2, _b2;
619
661
  if (cur.type === "style") {
620
662
  for (const key in cur.value) {
621
- const shouldInsertNull = !!staticConfig.ensureOverriddenProp?.[key];
663
+ const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
622
664
  const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
623
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
624
- if (shouldInsertNullOverride) {
625
- acc.push({
626
- type: "attr",
627
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
628
- });
665
+ if (!isSetInAttrsAlready) {
666
+ const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
667
+ if (isVariant || shouldEnsureOverridden) {
668
+ acc.push({
669
+ type: "attr",
670
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
671
+ });
672
+ }
629
673
  }
630
674
  }
631
675
  }
@@ -634,7 +678,7 @@ function createExtractor() {
634
678
  }, []);
635
679
  }
636
680
  if (shouldPrintDebug) {
637
- console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
681
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
638
682
  }
639
683
  attrs = attrs.reduce((acc, cur) => {
640
684
  if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
@@ -652,15 +696,12 @@ function createExtractor() {
652
696
  return acc;
653
697
  }, []);
654
698
  if (shouldPrintDebug) {
655
- console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
699
+ console.log(" - attrs (evaluated styles): \n", logLines(attrs.map(attrStr).join(", ")));
656
700
  }
657
701
  let prev = null;
658
702
  attrs = attrs.reduce((acc, cur) => {
659
703
  if (cur.type === "style") {
660
- if (prev?.type === "style") {
661
- if (shouldPrintDebug) {
662
- console.log(" \u{1F500} merging style");
663
- }
704
+ if ((prev == null ? void 0 : prev.type) === "style") {
664
705
  Object.assign(prev.value, cur.value);
665
706
  return acc;
666
707
  }
@@ -670,9 +711,10 @@ function createExtractor() {
670
711
  return acc;
671
712
  }, []);
672
713
  if (shouldPrintDebug) {
673
- console.log(" - attrs (combined styles): ", attrs.map(attrStr).join(", "));
714
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
674
715
  }
675
716
  const getStyles = /* @__PURE__ */ __name((props2) => {
717
+ var _a2;
676
718
  if (!props2)
677
719
  return;
678
720
  if (!!excludeProps.size) {
@@ -681,12 +723,13 @@ function createExtractor() {
681
723
  delete props2[key];
682
724
  }
683
725
  }
684
- const out = postProcessStyles(props2, staticConfig);
685
- const next = out?.style ?? props2;
726
+ const out = postProcessStyles(props2, staticConfig, defaultTheme);
727
+ const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
686
728
  if (shouldPrintDebug) {
687
- console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
688
- console.log(" >> style: ", objToStr(out.style));
689
- console.log(" >> viewp: ", objToStr(out.viewProps));
729
+ console.log(" getStyles props >>\n", logLines(objToStr(props2)));
730
+ console.log(" getStyles next >>\n", logLines(objToStr(next)));
731
+ console.log(" getStyles style >>\n", logLines(objToStr(out.style)));
732
+ console.log(" getStyles viewp >>\n", logLines(objToStr(out.viewProps)));
690
733
  }
691
734
  if (staticConfig.validStyles) {
692
735
  for (const key in next) {
@@ -697,9 +740,6 @@ function createExtractor() {
697
740
  }
698
741
  return next;
699
742
  }, "getStyles");
700
- if (shouldPrintDebug) {
701
- console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
702
- }
703
743
  const completeStylesProcessed = getStyles({
704
744
  ...staticConfig.defaultProps,
705
745
  ...completeStaticProps
@@ -719,8 +759,8 @@ function createExtractor() {
719
759
  }
720
760
  }
721
761
  if (shouldPrintDebug) {
722
- console.log(" completeStaticProps", objToStr(completeStaticProps));
723
- console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
762
+ console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
763
+ console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
724
764
  }
725
765
  for (const attr of attrs) {
726
766
  try {
@@ -737,7 +777,11 @@ function createExtractor() {
737
777
  case "style":
738
778
  const next = {};
739
779
  for (const key in attr.value) {
740
- next[key] = completeStylesProcessed[key] ?? attr.value[key];
780
+ if (key in stylePropsTransform) {
781
+ next["transform"] = completeStylesProcessed["transform"];
782
+ } else {
783
+ next[key] = (_g = completeStylesProcessed[key]) != null ? _g : attr.value[key];
784
+ }
741
785
  }
742
786
  attr.value = next;
743
787
  break;
@@ -751,14 +795,7 @@ function createExtractor() {
751
795
  }
752
796
  }
753
797
  if (shouldPrintDebug) {
754
- console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
755
- }
756
- if (shouldAddDebugProp) {
757
- const preName = componentName ? `${componentName}:` : "";
758
- attrs.unshift({
759
- type: "attr",
760
- value: t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
761
- });
798
+ console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
762
799
  }
763
800
  if (shouldFlatten) {
764
801
  if (shouldPrintDebug) {
@@ -766,15 +803,16 @@ function createExtractor() {
766
803
  }
767
804
  isFlattened = true;
768
805
  node.name.name = flatNode;
769
- onDidFlatten?.();
806
+ res.flattened++;
770
807
  if (closingElement) {
771
808
  closingElement.name.name = flatNode;
772
809
  }
773
810
  }
774
811
  if (shouldPrintDebug) {
775
812
  console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
776
- console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
813
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
777
814
  }
815
+ res.optimized++;
778
816
  onExtractTag({
779
817
  attrs,
780
818
  node,
@@ -797,6 +835,7 @@ function createExtractor() {
797
835
  removeUnusedHooks(comp, shouldPrintDebug);
798
836
  }
799
837
  }
838
+ return res;
800
839
  }
801
840
  };
802
841
  }