@tamagui/static 1.0.0-beta.187 → 1.0.0-beta.230

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.
@@ -74,6 +74,15 @@ const UNTOUCHED_PROPS = {
74
74
  style: true,
75
75
  className: true
76
76
  };
77
+ const INLINE_EXTRACTABLE = {
78
+ ref: "ref",
79
+ key: "key",
80
+ onPress: "onClick",
81
+ onHoverIn: "onMouseEnter",
82
+ onHoverOut: "onMouseLeave",
83
+ onPressIn: "onMouseDown",
84
+ onPressOut: "onMouseUp"
85
+ };
77
86
  const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
78
87
  const validHooks = {
79
88
  useMedia: true,
@@ -81,6 +90,10 @@ const validHooks = {
81
90
  };
82
91
  const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
83
92
  function createExtractor() {
93
+ if (!process.env.TAMAGUI_TARGET) {
94
+ console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
95
+ process.exit(1);
96
+ }
84
97
  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);
85
98
  require("esbuild-register/dist/node").register({
86
99
  target: "es2019",
@@ -151,6 +164,7 @@ function createExtractor() {
151
164
  return obj;
152
165
  }, {});
153
166
  let doesUseValidImport = false;
167
+ let hasImportedTheme = false;
154
168
  for (const bodyPath of body) {
155
169
  if (bodyPath.type !== "ImportDeclaration")
156
170
  continue;
@@ -219,16 +233,17 @@ function createExtractor() {
219
233
  }
220
234
  const originalNodeName = node.name.name;
221
235
  res.found++;
236
+ const filePath = sourcePath.replace(process.cwd(), ".");
237
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
238
+ const preName = componentName ? `${componentName}.` : "";
239
+ const tagId = `${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`;
222
240
  if (shouldPrintDebug) {
223
241
  console.log(`
224
- <${originalNodeName} />`);
242
+ <${originalNodeName} /> (${tagId})`);
225
243
  }
226
- const filePath = sourcePath.replace(process.cwd(), ".");
227
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
228
244
  if (shouldAddDebugProp && !disableDebugAttr) {
229
- const preName = componentName ? `${componentName}.` : "";
230
245
  res.modified++;
231
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(`${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`)));
246
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId)));
232
247
  }
233
248
  const shouldLog = !hasLogged;
234
249
  if (shouldLog) {
@@ -265,6 +280,7 @@ function createExtractor() {
265
280
  ...staticConfig.inlineProps || []
266
281
  ]);
267
282
  const deoptProps = /* @__PURE__ */ new Set([
283
+ "animation",
268
284
  ...props.deoptProps || [],
269
285
  ...staticConfig.deoptProps || []
270
286
  ]);
@@ -343,7 +359,7 @@ function createExtractor() {
343
359
  }
344
360
  let attrs = [];
345
361
  let shouldDeopt = false;
346
- let inlinePropCount = 0;
362
+ const inlined = /* @__PURE__ */ new Map();
347
363
  let hasSetOptimized = false;
348
364
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
349
365
  try {
@@ -395,7 +411,7 @@ function createExtractor() {
395
411
  if (shouldPrintDebug) {
396
412
  console.log(" ! inlining, spread attr");
397
413
  }
398
- inlinePropCount++;
414
+ inlined.set(`${Math.random()}`, "spread");
399
415
  return attr;
400
416
  }
401
417
  const name = attribute.name.name;
@@ -406,7 +422,7 @@ function createExtractor() {
406
422
  return null;
407
423
  }
408
424
  if (inlineProps.has(name)) {
409
- inlinePropCount++;
425
+ inlined.set(name, name);
410
426
  if (shouldPrintDebug) {
411
427
  console.log(" ! inlining, inline prop", name);
412
428
  }
@@ -414,7 +430,7 @@ function createExtractor() {
414
430
  }
415
431
  if (deoptProps.has(name)) {
416
432
  shouldDeopt = true;
417
- inlinePropCount++;
433
+ inlined.set(name, name);
418
434
  if (shouldPrintDebug) {
419
435
  console.log(" ! inlining, deopted prop", name);
420
436
  }
@@ -423,6 +439,10 @@ function createExtractor() {
423
439
  if (UNTOUCHED_PROPS[name]) {
424
440
  return attr;
425
441
  }
442
+ if (INLINE_EXTRACTABLE[name]) {
443
+ inlined.set(name, INLINE_EXTRACTABLE[name]);
444
+ return attr;
445
+ }
426
446
  if (name.startsWith("data-")) {
427
447
  return attr;
428
448
  }
@@ -460,7 +480,7 @@ function createExtractor() {
460
480
  if (shouldPrintDebug) {
461
481
  console.log(" ! inlining, ref", name);
462
482
  }
463
- inlinePropCount++;
483
+ inlined.set("ref", "ref");
464
484
  return attr;
465
485
  }
466
486
  if (name === "tag") {
@@ -475,7 +495,7 @@ function createExtractor() {
475
495
  if (shouldPrintDebug) {
476
496
  console.log(` ! inlining, native disable extract: ${name} =`, value.value);
477
497
  }
478
- inlinePropCount++;
498
+ inlined.set(name, true);
479
499
  return attr;
480
500
  }
481
501
  }
@@ -485,26 +505,56 @@ function createExtractor() {
485
505
  let keys = [name];
486
506
  let out = null;
487
507
  if (staticConfig.propMapper) {
488
- out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, staticConfig);
508
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, "auto");
489
509
  if (out) {
490
510
  out = import_core_node.rnw.createDOMProps(isTextView ? "span" : "div", out);
491
511
  delete out.className;
492
512
  keys = Object.keys(out);
493
513
  }
494
514
  }
515
+ let didInline = false;
495
516
  const attributes = keys.map((key) => {
496
517
  const val = out[key];
497
- if (!isValidStyleKey(key)) {
498
- if (import_validHTMLAttributes.validHTMLAttributes[key]) {
499
- return {
500
- type: "attr",
501
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(val)))
502
- };
503
- }
504
- if (shouldPrintDebug) {
505
- console.log(" ! inlining, non-static", key);
518
+ if (key === "theme") {
519
+ inlined.set(key, val);
520
+ return attr;
521
+ }
522
+ if (isValidStyleKey(key)) {
523
+ return {
524
+ type: "style",
525
+ value: { [name]: styleValue },
526
+ name,
527
+ attr: path.node
528
+ };
529
+ }
530
+ if (import_validHTMLAttributes.validHTMLAttributes[key]) {
531
+ return attr;
532
+ }
533
+ if (shouldPrintDebug) {
534
+ console.log(" ! inlining, non-static", key);
535
+ }
536
+ didInline = true;
537
+ inlined.set(key, val);
538
+ return val;
539
+ });
540
+ if (didInline) {
541
+ if (shouldPrintDebug) {
542
+ console.log(" bailing flattening due to attributes", attributes);
543
+ }
544
+ return attr;
545
+ }
546
+ return attributes;
547
+ }
548
+ if (styleValue !== import_constants.FAILED_EVAL) {
549
+ if (isValidStyleKey(name)) {
550
+ if (shouldPrintDebug) {
551
+ console.log(` style: ${name} =`, styleValue);
552
+ }
553
+ if (!(name in staticConfig.defaultProps)) {
554
+ if (!hasSetOptimized) {
555
+ res.optimized++;
556
+ hasSetOptimized = true;
506
557
  }
507
- inlinePropCount++;
508
558
  }
509
559
  return {
510
560
  type: "style",
@@ -512,28 +562,10 @@ function createExtractor() {
512
562
  name,
513
563
  attr: path.node
514
564
  };
515
- });
516
- if (inlinePropCount) {
565
+ } else {
566
+ inlined.set(name, true);
517
567
  return attr;
518
568
  }
519
- return attributes;
520
- }
521
- if (styleValue !== import_constants.FAILED_EVAL) {
522
- if (shouldPrintDebug) {
523
- console.log(` style: ${name} =`, styleValue);
524
- }
525
- if (!(name in staticConfig.defaultProps)) {
526
- if (!hasSetOptimized) {
527
- res.optimized++;
528
- hasSetOptimized = true;
529
- }
530
- }
531
- return {
532
- type: "style",
533
- value: { [name]: styleValue },
534
- name,
535
- attr: path.node
536
- };
537
569
  }
538
570
  if (t.isBinaryExpression(value)) {
539
571
  if (shouldPrintDebug) {
@@ -558,7 +590,7 @@ function createExtractor() {
558
590
  if (shouldPrintDebug) {
559
591
  console.log(` evalBinaryExpression cant extract`);
560
592
  }
561
- inlinePropCount++;
593
+ inlined.set(name, true);
562
594
  return attr;
563
595
  }
564
596
  const staticConditional = getStaticConditional(value);
@@ -575,12 +607,9 @@ function createExtractor() {
575
607
  }
576
608
  return { type: "ternary", value: staticLogical };
577
609
  }
610
+ inlined.set(name, true);
578
611
  if (shouldPrintDebug) {
579
- console.log(" ! inline prop via no match", name, value.type);
580
- }
581
- inlinePropCount++;
582
- if (shouldPrintDebug) {
583
- console.log(` inlining ${name} = `, value);
612
+ console.log(` ! inline no match ${name}`, value);
584
613
  }
585
614
  return attr;
586
615
  function addBinaryConditional(operator, staticExpr, cond) {
@@ -808,7 +837,28 @@ function createExtractor() {
808
837
  }, {}));
809
838
  const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
810
839
  const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
811
- const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
840
+ const themeVal = inlined.get("theme");
841
+ inlined.delete("theme");
842
+ const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
843
+ const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
844
+ const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
845
+ let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
846
+ if (shouldFlatten && shouldWrapInnerTheme) {
847
+ if (typeof themeVal !== "string") {
848
+ console.warn("??");
849
+ return;
850
+ }
851
+ if (shouldPrintDebug) {
852
+ console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
853
+ }
854
+ if (!hasImportedTheme) {
855
+ hasImportedTheme = true;
856
+ programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
857
+ }
858
+ traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
859
+ t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
860
+ ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
861
+ }
812
862
  if (shouldFlatten && staticConfig.defaultProps) {
813
863
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
814
864
  if (!isValidStyleKey(key)) {
@@ -863,8 +913,12 @@ function createExtractor() {
863
913
  if (!cur) {
864
914
  return acc;
865
915
  }
866
- if (shouldFlatten && cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value) && cur.value.name.name === "tag") {
867
- return acc;
916
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
917
+ if (shouldFlatten) {
918
+ if (cur.value.name.name === "tag") {
919
+ return acc;
920
+ }
921
+ }
868
922
  }
869
923
  if (cur.type !== "style") {
870
924
  acc.push(cur);
@@ -942,6 +996,7 @@ function createExtractor() {
942
996
  if (shouldPrintDebug) {
943
997
  console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
944
998
  }
999
+ const completeProps = __spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps);
945
1000
  const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
946
1001
  if (!props2)
947
1002
  return;
@@ -955,9 +1010,22 @@ function createExtractor() {
955
1010
  }
956
1011
  }
957
1012
  const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, {
958
- noClassNames: true
1013
+ noClassNames: true,
1014
+ fallbackProps: completeProps,
1015
+ focus: false,
1016
+ hover: false,
1017
+ mounted: true,
1018
+ press: false,
1019
+ pressIn: false
959
1020
  });
960
1021
  const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
1022
+ for (const key in outStyle) {
1023
+ if (staticConfig.validStyles) {
1024
+ if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key]) {
1025
+ delete outStyle[key];
1026
+ }
1027
+ }
1028
+ }
961
1029
  if (shouldPrintDebug === "verbose") {
962
1030
  console.log(` getStyles ${debugName} (props):
963
1031
  `, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
@@ -966,16 +1034,9 @@ function createExtractor() {
966
1034
  console.log(` getStyles ${debugName} (out.style):
967
1035
  `, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outStyle || {}), true));
968
1036
  }
969
- for (const key in outStyle) {
970
- if (staticConfig.validStyles) {
971
- if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key]) {
972
- delete outStyle[key];
973
- }
974
- }
975
- }
976
1037
  return outStyle;
977
1038
  }, "getStyles");
978
- const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps), "completeStylesProcessed");
1039
+ const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
979
1040
  if (!completeStylesProcessed) {
980
1041
  throw new Error(`Impossible, no styles`);
981
1042
  }
@@ -1034,6 +1095,18 @@ function createExtractor() {
1034
1095
  const existingStyleKeys = /* @__PURE__ */ new Set();
1035
1096
  for (let i = attrs.length - 1; i >= 0; i--) {
1036
1097
  const attr = attrs[i];
1098
+ if (shouldFlatten && canFlattenProps) {
1099
+ if (attr.type === "attr") {
1100
+ if (t.isJSXAttribute(attr.value)) {
1101
+ if (t.isJSXIdentifier(attr.value.name)) {
1102
+ const name = attr.value.name.name;
1103
+ if (INLINE_EXTRACTABLE[name]) {
1104
+ attr.value.name.name = INLINE_EXTRACTABLE[name];
1105
+ }
1106
+ }
1107
+ }
1108
+ }
1109
+ }
1037
1110
  if (attr.type === "style") {
1038
1111
  for (const key in attr.value) {
1039
1112
  if (existingStyleKeys.has(key)) {
@@ -1044,9 +1117,6 @@ function createExtractor() {
1044
1117
  }
1045
1118
  }
1046
1119
  }
1047
- if (shouldPrintDebug) {
1048
- console.log(" - attrs (after):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
1049
- }
1050
1120
  if (shouldFlatten) {
1051
1121
  if (shouldPrintDebug) {
1052
1122
  console.log(" [\u2705] flattening", originalNodeName, flatNode);
@@ -1058,7 +1128,7 @@ function createExtractor() {
1058
1128
  }
1059
1129
  }
1060
1130
  if (shouldPrintDebug) {
1061
- console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1131
+ console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1062
1132
  console.log(" - attrs (end):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
1063
1133
  }
1064
1134
  onExtractTag({