@tamagui/static 2.7.1 → 2.7.3

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.
@@ -459,6 +459,7 @@ function createExtractor({
459
459
  }
460
460
  tm.mark("import-check", !!shouldPrintDebug);
461
461
  let couldntParse = false;
462
+ let didDynamicLoad = false;
462
463
  const modifiedComponents = /* @__PURE__ */new Set();
463
464
  const bindingCache = {};
464
465
  const callTraverse = a => {
@@ -503,10 +504,9 @@ function createExtractor({
503
504
  return;
504
505
  }
505
506
  let Component = getValidImportedComponent(parentName) || getValidImportedComponent(variableName);
506
- if (!Component) {
507
- if (!enableDynamicEvaluation) {
508
- return;
509
- }
507
+ const declaresVariants = !didDynamicLoad && definition.properties.some(prop => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "variants");
508
+ if ((!Component || declaresVariants) && enableDynamicEvaluation) {
509
+ didDynamicLoad = true;
510
510
  try {
511
511
  if (shouldPrintDebug) {
512
512
  logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
@@ -516,19 +516,17 @@ function createExtractor({
516
516
  components: [sourcePath],
517
517
  cacheKey: version
518
518
  });
519
- if (!out2?.components) {
520
- if (shouldPrintDebug) {
521
- logger.info(`Couldn't load, got ${out2}`);
522
- }
523
- return;
524
- }
525
- propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components];
526
- Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0];
527
- if (!out2.cached) {
528
- const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
529
- if (foundNames) {
530
- (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Tamagui found dynamic components: ${foundNames}`);
519
+ if (out2?.components) {
520
+ propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components];
521
+ Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0] || Component;
522
+ if (!out2.cached) {
523
+ const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
524
+ if (foundNames) {
525
+ (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Tamagui found dynamic components: ${foundNames}`);
526
+ }
531
527
  }
528
+ } else if (shouldPrintDebug) {
529
+ logger.info(`Couldn't load, got ${out2}`);
532
530
  }
533
531
  } catch (err) {
534
532
  if (shouldPrintDebug) {
@@ -1690,7 +1688,11 @@ function createExtractor({
1690
1688
  if (deoptProps.has(key)) {
1691
1689
  shouldFlatten = false;
1692
1690
  }
1693
- if (platform2 === "native" && key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$group-") && getGroupPseudo(key) !== "hover")) {
1691
+ if (platform2 === "native" && key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$group-") && getGroupPseudo(key) !== "hover" ||
1692
+ // same story for a breakpoint a variant brought with it:
1693
+ // native matches media at render time, so there is nothing
1694
+ // to write it to here
1695
+ mediaQueryConfig[key.slice(1)])) {
1694
1696
  shouldFlatten = false;
1695
1697
  }
1696
1698
  }
@@ -1761,6 +1763,7 @@ function createExtractor({
1761
1763
  logger.info([" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1762
1764
  }
1763
1765
  let getStyleError = null;
1766
+ const mediaFromVariants = [];
1764
1767
  for (const attr of attrs) {
1765
1768
  try {
1766
1769
  if (shouldPrintDebug) {
@@ -1781,6 +1784,22 @@ function createExtractor({
1781
1784
  {
1782
1785
  const styles = getProps(attr.value, false, "style");
1783
1786
  if (styles) {
1787
+ for (const key in styles) {
1788
+ if (key[0] !== "$") continue;
1789
+ const mediaKey = key.slice(1);
1790
+ if (!mediaQueryConfig[mediaKey]) continue;
1791
+ mediaFromVariants.push({
1792
+ type: "ternary",
1793
+ value: {
1794
+ inlineMediaQuery: mediaKey,
1795
+ test: t.stringLiteral(mediaKey),
1796
+ consequent: styles[key],
1797
+ alternate: null,
1798
+ remove() {}
1799
+ }
1800
+ });
1801
+ delete styles[key];
1802
+ }
1784
1803
  attr.value = styles;
1785
1804
  }
1786
1805
  if (shouldPrintDebug) logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" "));
@@ -1812,6 +1831,9 @@ function createExtractor({
1812
1831
  getStyleError = err;
1813
1832
  }
1814
1833
  }
1834
+ if (mediaFromVariants.length) {
1835
+ attrs.push(...mediaFromVariants);
1836
+ }
1815
1837
  if (shouldPrintDebug) {
1816
1838
  logger.info([" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1817
1839
  }
@@ -85,11 +85,12 @@ function normalizeTernaries(ternaries) {
85
85
  }
86
86
  const altStyle = (shouldSwap ? consequent : alternate) ?? {};
87
87
  const consStyle = (shouldSwap ? alternate : consequent) ?? {};
88
+ const mediaLastWins = Boolean(rest.inlineMediaQuery);
88
89
  const nextAlt = ternariesByKey[key].alternate;
89
- ternariesByKey[key].alternate = (0, import_web.mergeProps)(altStyle, nextAlt);
90
+ ternariesByKey[key].alternate = mediaLastWins ? (0, import_web.mergeProps)(nextAlt, altStyle) : (0, import_web.mergeProps)(altStyle, nextAlt);
90
91
  (0, import_propsToFontFamilyCache.forwardFontFamilyName)(altStyle, ternariesByKey[key].alternate);
91
92
  const nextCons = ternariesByKey[key].consequent;
92
- ternariesByKey[key].consequent = (0, import_web.mergeProps)(consStyle, nextCons);
93
+ ternariesByKey[key].consequent = mediaLastWins ? (0, import_web.mergeProps)(nextCons, consStyle) : (0, import_web.mergeProps)(consStyle, nextCons);
93
94
  (0, import_propsToFontFamilyCache.forwardFontFamilyName)(consStyle, ternariesByKey[key].consequent);
94
95
  }
95
96
  const ternaryExpression = Object.keys(ternariesByKey).map(key => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "license": "MIT",
6
6
  "source": "src/index.ts",
@@ -50,19 +50,19 @@
50
50
  "@babel/template": "^7.25.0",
51
51
  "@babel/traverse": "^7.25.4",
52
52
  "@babel/types": "^7.25.4",
53
- "@tamagui/cli-color": "2.7.1",
54
- "@tamagui/config-default": "2.7.1",
55
- "@tamagui/core": "2.7.1",
56
- "@tamagui/fake-react-native": "2.7.1",
57
- "@tamagui/generate-themes": "2.7.1",
58
- "@tamagui/helpers": "2.7.1",
59
- "@tamagui/helpers-node": "2.7.1",
60
- "@tamagui/proxy-worm": "2.7.1",
61
- "@tamagui/react-native-web-internals": "2.7.1",
62
- "@tamagui/react-native-web-lite": "2.7.1",
63
- "@tamagui/shorthands": "2.7.1",
64
- "@tamagui/types": "2.7.1",
65
- "@tamagui/web": "2.7.1",
53
+ "@tamagui/cli-color": "2.7.3",
54
+ "@tamagui/config-default": "2.7.3",
55
+ "@tamagui/core": "2.7.3",
56
+ "@tamagui/fake-react-native": "2.7.3",
57
+ "@tamagui/generate-themes": "2.7.3",
58
+ "@tamagui/helpers": "2.7.3",
59
+ "@tamagui/helpers-node": "2.7.3",
60
+ "@tamagui/proxy-worm": "2.7.3",
61
+ "@tamagui/react-native-web-internals": "2.7.3",
62
+ "@tamagui/react-native-web-lite": "2.7.3",
63
+ "@tamagui/shorthands": "2.7.3",
64
+ "@tamagui/types": "2.7.3",
65
+ "@tamagui/web": "2.7.3",
66
66
  "babel-literal-to-ast": "^2.1.0",
67
67
  "browserslist": "^4.28.1",
68
68
  "check-dependency-version-consistency": "^4.1.0",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "devDependencies": {
81
81
  "@babel/plugin-syntax-typescript": "^7.25.4",
82
- "@tamagui/build": "2.7.1",
82
+ "@tamagui/build": "2.7.3",
83
83
  "@types/babel__core": "^7.20.5",
84
84
  "@types/find-root": "^1.1.2",
85
85
  "@types/node": "^22.1.0",
@@ -624,6 +624,8 @@ export function createExtractor(
624
624
  tm.mark('import-check', !!shouldPrintDebug)
625
625
 
626
626
  let couldntParse = false
627
+ // evaluating the file resolves every styled() in it at once, so once is enough
628
+ let didDynamicLoad = false
627
629
  const modifiedComponents = new Set<NodePath<any>>()
628
630
 
629
631
  // only keeping a cache around per-file, reset it if it changes
@@ -696,11 +698,21 @@ export function createExtractor(
696
698
  let Component =
697
699
  getValidImportedComponent(parentName) || getValidImportedComponent(variableName)
698
700
 
699
- if (!Component) {
700
- if (!enableDynamicEvaluation) {
701
- return
702
- }
701
+ // the parent's staticConfig knows nothing about the variants this call
702
+ // declares, so a JSX site passing one reads as an unknown prop and
703
+ // de-opts the whole element. evaluating the file gives us the real
704
+ // staticConfig, variants included.
705
+ const declaresVariants =
706
+ !didDynamicLoad &&
707
+ definition.properties.some(
708
+ (prop) =>
709
+ t.isObjectProperty(prop) &&
710
+ t.isIdentifier(prop.key) &&
711
+ prop.key.name === 'variants'
712
+ )
703
713
 
714
+ if ((!Component || declaresVariants) && enableDynamicEvaluation) {
715
+ didDynamicLoad = true
704
716
  try {
705
717
  if (shouldPrintDebug) {
706
718
  logger.info(
@@ -714,32 +726,31 @@ export function createExtractor(
714
726
  cacheKey: version,
715
727
  })
716
728
 
717
- if (!out?.components) {
718
- if (shouldPrintDebug) {
719
- logger.info(`Couldn't load, got ${out}`)
720
- }
721
- return
722
- }
723
-
724
- propsWithFileInfo.allLoadedComponents = [
725
- ...propsWithFileInfo.allLoadedComponents,
726
- ...out.components,
727
- ]
728
-
729
- Component = out.components.flatMap((x) => x.nameToInfo[variableName] ?? [])[0]
730
-
731
- if (!out.cached) {
732
- const foundNames = out.components
733
- ?.map((x) => Object.keys(x.nameToInfo).join(', '))
734
- .join(', ')
735
- .trim()
736
-
737
- if (foundNames) {
738
- colorLog(
739
- Color.FgYellow,
740
- ` | Tamagui found dynamic components: ${foundNames}`
741
- )
729
+ if (out?.components) {
730
+ propsWithFileInfo.allLoadedComponents = [
731
+ ...propsWithFileInfo.allLoadedComponents,
732
+ ...out.components,
733
+ ]
734
+
735
+ Component =
736
+ out.components.flatMap((x) => x.nameToInfo[variableName] ?? [])[0] ||
737
+ Component
738
+
739
+ if (!out.cached) {
740
+ const foundNames = out.components
741
+ ?.map((x) => Object.keys(x.nameToInfo).join(', '))
742
+ .join(', ')
743
+ .trim()
744
+
745
+ if (foundNames) {
746
+ colorLog(
747
+ Color.FgYellow,
748
+ ` | Tamagui found dynamic components: ${foundNames}`
749
+ )
750
+ }
742
751
  }
752
+ } else if (shouldPrintDebug) {
753
+ logger.info(`Couldn't load, got ${out}`)
743
754
  }
744
755
  } catch (err: any) {
745
756
  if (shouldPrintDebug) {
@@ -2539,7 +2550,11 @@ export function createExtractor(
2539
2550
  platform === 'native' &&
2540
2551
  key[0] === '$' &&
2541
2552
  (key.startsWith('$theme-') ||
2542
- (key.startsWith('$group-') && getGroupPseudo(key) !== 'hover'))
2553
+ (key.startsWith('$group-') && getGroupPseudo(key) !== 'hover') ||
2554
+ // same story for a breakpoint a variant brought with it:
2555
+ // native matches media at render time, so there is nothing
2556
+ // to write it to here
2557
+ mediaQueryConfig[key.slice(1)])
2543
2558
  ) {
2544
2559
  shouldFlatten = false
2545
2560
  }
@@ -2647,6 +2662,13 @@ export function createExtractor(
2647
2662
 
2648
2663
  let getStyleError: any = null
2649
2664
 
2665
+ // a variant can carry its own media blocks ($md/$lg inside a variant
2666
+ // value). getSplitStyles leaves those nested rather than folding them
2667
+ // into the flat style, so hand them to the same media path a $md/$lg
2668
+ // prop takes. they go on the end because a variant is a prop, and so
2669
+ // outranks the media the styled() frame declared in its defaults.
2670
+ const mediaFromVariants: ExtractedAttr[] = []
2671
+
2650
2672
  // fix up ternaries, combine final style values
2651
2673
  for (const attr of attrs) {
2652
2674
  try {
@@ -2681,6 +2703,22 @@ export function createExtractor(
2681
2703
  // expand variants and such
2682
2704
  const styles = getProps(attr.value, false, 'style')
2683
2705
  if (styles) {
2706
+ for (const key in styles) {
2707
+ if (key[0] !== '$') continue
2708
+ const mediaKey = key.slice(1)
2709
+ if (!mediaQueryConfig[mediaKey]) continue
2710
+ mediaFromVariants.push({
2711
+ type: 'ternary',
2712
+ value: {
2713
+ inlineMediaQuery: mediaKey,
2714
+ test: t.stringLiteral(mediaKey),
2715
+ consequent: styles[key],
2716
+ alternate: null,
2717
+ remove() {},
2718
+ },
2719
+ })
2720
+ delete styles[key]
2721
+ }
2684
2722
  // @ts-ignore
2685
2723
  attr.value = styles
2686
2724
  }
@@ -2736,6 +2774,10 @@ export function createExtractor(
2736
2774
  }
2737
2775
  }
2738
2776
 
2777
+ if (mediaFromVariants.length) {
2778
+ attrs.push(...mediaFromVariants)
2779
+ }
2780
+
2739
2781
  if (shouldPrintDebug) {
2740
2782
  // prettier-ignore
2741
2783
  logger.info(
@@ -61,12 +61,23 @@ export function normalizeTernaries(ternaries: Ternary[]) {
61
61
  const altStyle = (shouldSwap ? consequent : alternate) ?? {}
62
62
  const consStyle = (shouldSwap ? alternate : consequent) ?? {}
63
63
 
64
+ // a media "ternary" is a breakpoint bucket, not a runtime branch: two of
65
+ // them for the same breakpoint are just two writes to it, and these arrive
66
+ // defaults-first, so a $lg on the JSX has to beat the $lg the styled()
67
+ // frame declared. real ternaries keep merging the other way, which the
68
+ // branch expansion below depends on.
69
+ const mediaLastWins = Boolean(rest.inlineMediaQuery)
70
+
64
71
  const nextAlt = ternariesByKey[key].alternate!
65
- ternariesByKey[key].alternate = mergeProps(altStyle, nextAlt)
72
+ ternariesByKey[key].alternate = mediaLastWins
73
+ ? mergeProps(nextAlt, altStyle)
74
+ : mergeProps(altStyle, nextAlt)
66
75
  forwardFontFamilyName(altStyle, ternariesByKey[key].alternate)
67
76
 
68
77
  const nextCons = ternariesByKey[key].consequent!
69
- ternariesByKey[key].consequent = mergeProps(consStyle, nextCons)
78
+ ternariesByKey[key].consequent = mediaLastWins
79
+ ? mergeProps(nextCons, consStyle)
80
+ : mergeProps(consStyle, nextCons)
70
81
  forwardFontFamilyName(consStyle, ternariesByKey[key].consequent)
71
82
  }
72
83
 
@@ -1 +1 @@
1
- {"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AAEhE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAmBjC,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EAGf,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAoB,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAc1E,OAAO,EAAE,iBAAiB,EAA6B,MAAM,6BAA6B,CAAA;AAwB1F,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAE1D,KAAK,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AA6C9C,wBAAgB,eAAe,CAC7B,EAAE,MAAgB,EAAE,QAAgB,EAAE,GAAE,gBAAsC;;;;;yBAsJnD,cAAc;6BAPhB,cAAc;;mBAwBtB,UAAU,SAAS,mBAAmB;;;;;;;eAKpC,UAAU,SAAS,mBAAmB;;;;;;;EA+kF1D"}
1
+ {"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AAEhE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAmBjC,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EAGf,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAoB,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAc1E,OAAO,EAAE,iBAAiB,EAA6B,MAAM,6BAA6B,CAAA;AAwB1F,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAE1D,KAAK,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AA6C9C,wBAAgB,eAAe,CAC7B,EAAE,MAAgB,EAAE,QAAgB,EAAE,GAAE,gBAAsC;;;;;yBAsJnD,cAAc;6BAPhB,cAAc;;mBAwBtB,UAAU,SAAS,mBAAmB;;;;;;;eAKpC,UAAU,SAAS,mBAAmB;;;;;;;EAynF1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeTernaries.d.ts","sourceRoot":"","sources":["../../src/extractor/normalizeTernaries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAGjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,wBAAgB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,UAEzC;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,aAkEtD"}
1
+ {"version":3,"file":"normalizeTernaries.d.ts","sourceRoot":"","sources":["../../src/extractor/normalizeTernaries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAGjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,wBAAgB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,UAEzC;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,aA6EtD"}