@tamagui/static 1.0.1-beta.59 → 1.0.1-beta.62

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 (48) hide show
  1. package/dist/cjs/extractor/createExtractor.js +49 -21
  2. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  3. package/dist/cjs/extractor/extractMediaStyle.js +1 -1
  4. package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
  5. package/dist/cjs/extractor/extractToClassNames.js +1 -1
  6. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  7. package/dist/esm/extractor/createExtractor.js +54 -24
  8. package/dist/esm/extractor/createExtractor.js.map +2 -2
  9. package/dist/esm/extractor/extractMediaStyle.js +1 -1
  10. package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
  11. package/dist/esm/extractor/extractToClassNames.js +1 -1
  12. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  13. package/dist/jsx/extractor/createExtractor.js +54 -24
  14. package/dist/jsx/extractor/extractMediaStyle.js +1 -1
  15. package/dist/jsx/extractor/extractToClassNames.js +1 -1
  16. package/package.json +9 -7
  17. package/src/constants.ts +13 -0
  18. package/src/extractor/accessSafe.ts +18 -0
  19. package/src/extractor/babelParse.ts +27 -0
  20. package/src/extractor/buildClassName.ts +61 -0
  21. package/src/extractor/createEvaluator.ts +69 -0
  22. package/src/extractor/createExtractor.ts +1725 -0
  23. package/src/extractor/ensureImportingConcat.ts +39 -0
  24. package/src/extractor/evaluateAstNode.ts +121 -0
  25. package/src/extractor/extractHelpers.ts +119 -0
  26. package/src/extractor/extractMediaStyle.ts +192 -0
  27. package/src/extractor/extractToClassNames.ts +426 -0
  28. package/src/extractor/findTopmostFunction.ts +22 -0
  29. package/src/extractor/generatedUid.ts +43 -0
  30. package/src/extractor/getPrefixLogs.ts +6 -0
  31. package/src/extractor/getPropValueFromAttributes.ts +92 -0
  32. package/src/extractor/getSourceModule.ts +101 -0
  33. package/src/extractor/getStaticBindingsForScope.ts +183 -0
  34. package/src/extractor/hoistClassNames.ts +45 -0
  35. package/src/extractor/literalToAst.ts +84 -0
  36. package/src/extractor/loadTamagui.ts +139 -0
  37. package/src/extractor/logLines.ts +16 -0
  38. package/src/extractor/normalizeTernaries.ts +63 -0
  39. package/src/extractor/removeUnusedHooks.ts +76 -0
  40. package/src/extractor/timer.ts +18 -0
  41. package/src/extractor/validHTMLAttributes.ts +99 -0
  42. package/src/index.ts +9 -0
  43. package/src/patchReactNativeWeb.ts +165 -0
  44. package/src/types.ts +97 -0
  45. package/types/extractor/createExtractor.d.ts +14 -1
  46. package/types/extractor/createExtractor.d.ts.map +1 -1
  47. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  48. package/types/extractor/extractToClassNames.d.ts.map +1 -1
@@ -158,7 +158,16 @@ function createExtractor() {
158
158
  }
159
159
  tm.mark("load-tamagui", shouldPrintDebug === "verbose");
160
160
  loadedTamaguiConfig = tamaguiConfig;
161
- const defaultTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
161
+ const proxiedTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
162
+ const themeAccessListeners = /* @__PURE__ */ new Set();
163
+ const defaultTheme = new Proxy(proxiedTheme, {
164
+ get(target2, key) {
165
+ if (key[0] === "$") {
166
+ themeAccessListeners.forEach((cb) => cb(String(key)));
167
+ }
168
+ return Reflect.get(target2, key);
169
+ }
170
+ });
162
171
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
163
172
  const isInternalImport = /* @__PURE__ */ __name((importStr) => {
164
173
  return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
@@ -394,7 +403,7 @@ function createExtractor() {
394
403
  let keys = [name];
395
404
  let out = null;
396
405
  if (staticConfig.propMapper) {
397
- out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" });
406
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
398
407
  if (out) {
399
408
  if (!Array.isArray(out)) {
400
409
  console.warn(`Error expected array but got`, out);
@@ -423,7 +432,7 @@ function createExtractor() {
423
432
  attr: path.node
424
433
  };
425
434
  }
426
- if (import_validHTMLAttributes.validHTMLAttributes[key]) {
435
+ if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
427
436
  return attr;
428
437
  }
429
438
  if (shouldPrintDebug) {
@@ -890,6 +899,14 @@ function createExtractor() {
890
899
  const shouldWrapThme = allOtherPropsExtractable && !!themeVal;
891
900
  const canFlattenProps = inlined.size === 0 || shouldWrapThme || allOtherPropsExtractable;
892
901
  let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
902
+ if (disableExtractVariables) {
903
+ themeAccessListeners.add((key) => {
904
+ shouldFlatten = false;
905
+ if (shouldPrintDebug) {
906
+ console.log(" ! accessing theme key, avoid flatten", key);
907
+ }
908
+ });
909
+ }
893
910
  if (shouldPrintDebug) {
894
911
  console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapThme, allOtherPropsExtractable, hasOnlyStringChildren }));
895
912
  }
@@ -1035,32 +1052,43 @@ function createExtractor() {
1035
1052
  press: false,
1036
1053
  pressIn: false
1037
1054
  };
1038
- const completeStaticProps = Object.keys(attrs).reduce((acc, index) => {
1039
- const cur = attrs[index];
1055
+ let foundStaticProps = {};
1056
+ for (const key in attrs) {
1057
+ const cur = attrs[key];
1040
1058
  if (cur.type === "style") {
1041
1059
  (0, import_core_node.normalizeStyleObject)(cur.value);
1042
- Object.assign(acc, cur.value);
1060
+ foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
1061
+ continue;
1043
1062
  }
1044
1063
  if (cur.type === "attr") {
1045
1064
  if (t.isJSXSpreadAttribute(cur.value)) {
1046
- return acc;
1065
+ continue;
1047
1066
  }
1048
1067
  if (!t.isJSXIdentifier(cur.value.name)) {
1049
- return acc;
1068
+ continue;
1050
1069
  }
1051
- const key = cur.value.name.name;
1070
+ const key2 = cur.value.name.name;
1052
1071
  const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1053
- if (value === import_constants.FAILED_EVAL) {
1054
- return acc;
1072
+ if (value !== import_constants.FAILED_EVAL) {
1073
+ foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
1074
+ [key2]: value
1075
+ });
1055
1076
  }
1056
- acc[key] = value;
1057
1077
  }
1058
- return acc;
1059
- }, {});
1060
- const completeProps = __spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps);
1078
+ }
1079
+ const completeProps = {};
1080
+ for (const key in staticConfig.defaultProps) {
1081
+ if (!(key in foundStaticProps)) {
1082
+ completeProps[key] = staticConfig.defaultProps[key];
1083
+ }
1084
+ }
1085
+ for (const key in foundStaticProps) {
1086
+ completeProps[key] = foundStaticProps[key];
1087
+ }
1061
1088
  if (shouldPrintDebug) {
1062
1089
  console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
1063
1090
  console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
1091
+ console.log(" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps)));
1064
1092
  console.log(" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps)));
1065
1093
  }
1066
1094
  const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
@@ -1081,7 +1109,7 @@ function createExtractor() {
1081
1109
  try {
1082
1110
  const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
1083
1111
  fallbackProps: completeProps
1084
- }));
1112
+ }), void 0, props2["debug"]);
1085
1113
  const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
1086
1114
  omitInvalidStyles(outStyle);
1087
1115
  if (shouldPrintDebug) {
@@ -1102,7 +1130,7 @@ function createExtractor() {
1102
1130
  if (!completeStyles) {
1103
1131
  throw new Error(`Impossible, no styles`);
1104
1132
  }
1105
- const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(completeStaticProps)) : [];
1133
+ const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(foundStaticProps)) : [];
1106
1134
  if (addInitialStyleKeys.length) {
1107
1135
  const toAdd = (0, import_lodash.pick)(completeStyles, ...addInitialStyleKeys);
1108
1136
  const firstGroup = attrs.find((x) => x.type === "style");
@@ -1118,14 +1146,11 @@ function createExtractor() {
1118
1146
  }
1119
1147
  if (shouldPrintDebug) {
1120
1148
  console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "), { shouldFlatten });
1121
- console.log(" -- completeStaticProps:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
1122
1149
  console.log(" -- completeStyles:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStyles)));
1123
1150
  }
1124
1151
  let getStyleError = null;
1125
1152
  for (const attr of attrs) {
1126
1153
  try {
1127
- if (shouldPrintDebug)
1128
- console.log(" *", (0, import_extractHelpers.attrStr)(attr));
1129
1154
  switch (attr.type) {
1130
1155
  case "ternary":
1131
1156
  const a = getStyles(attr.value.alternate, "ternary.alternate");
@@ -1139,7 +1164,7 @@ function createExtractor() {
1139
1164
  continue;
1140
1165
  case "style":
1141
1166
  if (shouldPrintDebug)
1142
- console.log(" * styles in", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
1167
+ console.log(" * styles in", attr.value);
1143
1168
  const styles = getStyles(attr.value, "style");
1144
1169
  if (shouldPrintDebug)
1145
1170
  console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
@@ -1152,6 +1177,9 @@ function createExtractor() {
1152
1177
  getStyleError = err;
1153
1178
  }
1154
1179
  }
1180
+ if (shouldPrintDebug) {
1181
+ console.log(" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
1182
+ }
1155
1183
  tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
1156
1184
  if (getStyleError) {
1157
1185
  console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);