@tamagui/static 2.6.2 → 2.6.4

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.
@@ -44,6 +44,14 @@ function concatClassName(_cn) {
44
44
  for (let i = numNames - 1; i >= 0; i--) {
45
45
  const name = names[i];
46
46
  if (!name || name === " ") continue;
47
+ if (name.startsWith("font_")) {
48
+ if (usedPrefixes.has("fontFamily")) {
49
+ continue;
50
+ }
51
+ usedPrefixes.add("fontFamily");
52
+ final = name + " " + final;
53
+ continue;
54
+ }
47
55
  if (name[0] !== "_") {
48
56
  final = name + " " + final;
49
57
  continue;
@@ -1477,6 +1477,13 @@ function createExtractor({
1477
1477
  out.push(cur);
1478
1478
  return out;
1479
1479
  }, []).flat();
1480
+ const ternaryBranchProps = /* @__PURE__ */new Map();
1481
+ const allTernaries = attrs.flatMap(attr => attr.type === "ternary" ? attr.value : []);
1482
+ if (allTernaries.length > 1) {
1483
+ for (const ternary of (0, import_normalizeTernaries.normalizeTernaries)(allTernaries)) {
1484
+ ternaryBranchProps.set((0, import_normalizeTernaries.getTernaryKey)(ternary.test), ternary);
1485
+ }
1486
+ }
1480
1487
  if (themeVal) {
1481
1488
  if (!programPath) {
1482
1489
  console.warn(`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`);
@@ -1610,7 +1617,7 @@ function createExtractor({
1610
1617
  logger.info([" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1611
1618
  }
1612
1619
  let prev = null;
1613
- const getProps = (props, includeProps = false, debugName = "") => {
1620
+ const getProps = (props, includeProps = false, debugName = "", branchProps) => {
1614
1621
  if (!props) {
1615
1622
  if (shouldPrintDebug) logger.info([" getProps() no props"].join(" "));
1616
1623
  return {};
@@ -1626,6 +1633,10 @@ function createExtractor({
1626
1633
  const before = process.env.IS_STATIC;
1627
1634
  process.env.IS_STATIC = "is_static";
1628
1635
  try {
1636
+ const fallbackProps = branchProps ? {
1637
+ ...completeProps,
1638
+ ...branchProps
1639
+ } : completeProps;
1629
1640
  let extractedMediaLikeProps = null;
1630
1641
  let propsForSplit = props;
1631
1642
  for (const k in props) {
@@ -1647,7 +1658,7 @@ function createExtractor({
1647
1658
  const out = getSplitStyles(propsForSplit, staticConfig, defaultTheme, "", componentState, {
1648
1659
  ...styleProps,
1649
1660
  noClass: true,
1650
- fallbackProps: completeProps,
1661
+ fallbackProps,
1651
1662
  ...(platform2 === "native" && {
1652
1663
  resolveValues: "except-theme"
1653
1664
  })
@@ -1659,7 +1670,7 @@ function createExtractor({
1659
1670
  const blockOut = getSplitStyles(block, staticConfig, defaultTheme, "", componentState, {
1660
1671
  ...styleProps,
1661
1672
  noClass: true,
1662
- fallbackProps: completeProps
1673
+ fallbackProps
1663
1674
  }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1664
1675
  if (blockOut) {
1665
1676
  extractedMediaLikeProps[k] = {
@@ -1758,8 +1769,9 @@ function createExtractor({
1758
1769
  switch (attr.type) {
1759
1770
  case "ternary":
1760
1771
  {
1761
- const a = getProps(attr.value.alternate, false, "ternary.alternate");
1762
- const c = getProps(attr.value.consequent, false, "ternary.consequent");
1772
+ const branchProps = ternaryBranchProps.get((0, import_normalizeTernaries.getTernaryKey)(attr.value.test));
1773
+ const a = getProps(attr.value.alternate, false, "ternary.alternate", branchProps?.alternate);
1774
+ const c = getProps(attr.value.consequent, false, "ternary.consequent", branchProps?.consequent);
1763
1775
  if (a) attr.value.alternate = a;
1764
1776
  if (c) attr.value.consequent = c;
1765
1777
  if (shouldPrintDebug) logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
@@ -33,6 +33,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
33
33
  }), mod);
34
34
  var normalizeTernaries_exports = {};
35
35
  __export(normalizeTernaries_exports, {
36
+ getTernaryKey: () => getTernaryKey,
36
37
  normalizeTernaries: () => normalizeTernaries
37
38
  });
38
39
  module.exports = __toCommonJS(normalizeTernaries_exports);
@@ -41,6 +42,9 @@ var t = __toESM(require("@babel/types"));
41
42
  var import_web = require("@tamagui/web");
42
43
  var import_invariant = __toESM(require("invariant"));
43
44
  var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
45
+ function getTernaryKey(test) {
46
+ return (0, import_generator.default)(test).code;
47
+ }
44
48
  function normalizeTernaries(ternaries) {
45
49
  (0, import_invariant.default)(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
46
50
  if (ternaries.length === 0) {
@@ -69,7 +73,7 @@ function normalizeTernaries(ternaries) {
69
73
  shouldSwap = true;
70
74
  }
71
75
  }
72
- const key = (0, import_generator.default)(ternaryTest).code;
76
+ const key = getTernaryKey(ternaryTest);
73
77
  if (!ternariesByKey[key]) {
74
78
  ternariesByKey[key] = {
75
79
  ...rest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "2.6.2",
3
+ "version": "2.6.4",
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.6.2",
54
- "@tamagui/config-default": "2.6.2",
55
- "@tamagui/core": "2.6.2",
56
- "@tamagui/fake-react-native": "2.6.2",
57
- "@tamagui/generate-themes": "2.6.2",
58
- "@tamagui/helpers": "2.6.2",
59
- "@tamagui/helpers-node": "2.6.2",
60
- "@tamagui/proxy-worm": "2.6.2",
61
- "@tamagui/react-native-web-internals": "2.6.2",
62
- "@tamagui/react-native-web-lite": "2.6.2",
63
- "@tamagui/shorthands": "2.6.2",
64
- "@tamagui/types": "2.6.2",
65
- "@tamagui/web": "2.6.2",
53
+ "@tamagui/cli-color": "2.6.4",
54
+ "@tamagui/config-default": "2.6.4",
55
+ "@tamagui/core": "2.6.4",
56
+ "@tamagui/fake-react-native": "2.6.4",
57
+ "@tamagui/generate-themes": "2.6.4",
58
+ "@tamagui/helpers": "2.6.4",
59
+ "@tamagui/helpers-node": "2.6.4",
60
+ "@tamagui/proxy-worm": "2.6.4",
61
+ "@tamagui/react-native-web-internals": "2.6.4",
62
+ "@tamagui/react-native-web-lite": "2.6.4",
63
+ "@tamagui/shorthands": "2.6.4",
64
+ "@tamagui/types": "2.6.4",
65
+ "@tamagui/web": "2.6.4",
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.6.2",
82
+ "@tamagui/build": "2.6.4",
83
83
  "@types/babel__core": "^7.20.5",
84
84
  "@types/find-root": "^1.1.2",
85
85
  "@types/node": "^22.1.0",
@@ -32,6 +32,14 @@ export function concatClassName(_cn: Record<string, any> | null | undefined): st
32
32
  const name = names[i]
33
33
 
34
34
  if (!name || name === ' ') continue
35
+ if (name.startsWith('font_')) {
36
+ if (usedPrefixes.has('fontFamily')) {
37
+ continue
38
+ }
39
+ usedPrefixes.add('fontFamily')
40
+ final = name + ' ' + final
41
+ continue
42
+ }
35
43
  if (name[0] !== '_') {
36
44
  // not snack style (todo slightly stronger heuristic)
37
45
  final = name + ' ' + final
@@ -46,7 +46,7 @@ import { cleanupBeforeExit, getStaticBindingsForScope } from './getStaticBinding
46
46
  import { literalToAst } from './literalToAst'
47
47
  import { loadTamagui, loadTamaguiSync } from './loadTamagui'
48
48
  import { logLines } from './logLines'
49
- import { normalizeTernaries } from './normalizeTernaries'
49
+ import { getTernaryKey, normalizeTernaries } from './normalizeTernaries'
50
50
  import { setPropsToFontFamily } from './propsToFontFamilyCache'
51
51
  import { timer } from './timer'
52
52
  import { validHTMLAttributes } from './validHTMLAttributes'
@@ -2129,6 +2129,16 @@ export function createExtractor(
2129
2129
  }, [])
2130
2130
  .flat()
2131
2131
 
2132
+ const ternaryBranchProps = new Map<string, Ternary>()
2133
+ const allTernaries = attrs.flatMap((attr) =>
2134
+ attr.type === 'ternary' ? attr.value : []
2135
+ )
2136
+ if (allTernaries.length > 1) {
2137
+ for (const ternary of normalizeTernaries(allTernaries)) {
2138
+ ternaryBranchProps.set(getTernaryKey(ternary.test), ternary)
2139
+ }
2140
+ }
2141
+
2132
2142
  // wrap theme around children on flatten
2133
2143
  // account for shouldFlatten could change w the above block "if (disableExtractVariables)"
2134
2144
  if (themeVal) {
@@ -2397,7 +2407,8 @@ export function createExtractor(
2397
2407
  const getProps = (
2398
2408
  props: object | null,
2399
2409
  includeProps = false,
2400
- debugName = ''
2410
+ debugName = '',
2411
+ branchProps?: object | null
2401
2412
  ) => {
2402
2413
  if (!props) {
2403
2414
  if (shouldPrintDebug) logger.info([' getProps() no props'].join(' '))
@@ -2415,6 +2426,10 @@ export function createExtractor(
2415
2426
  const before = process.env.IS_STATIC
2416
2427
  process.env.IS_STATIC = 'is_static'
2417
2428
  try {
2429
+ const fallbackProps = branchProps
2430
+ ? { ...completeProps, ...branchProps }
2431
+ : completeProps
2432
+
2418
2433
  // $group-* / $theme-* keys carry block-form style objects that
2419
2434
  // getSplitStyles drops in static mode (no parent group context,
2420
2435
  // no theme value to read). Pluck them out so the atomic-CSS
@@ -2453,7 +2468,7 @@ export function createExtractor(
2453
2468
  {
2454
2469
  ...styleProps,
2455
2470
  noClass: true,
2456
- fallbackProps: completeProps,
2471
+ fallbackProps,
2457
2472
  ...(platform === 'native' && {
2458
2473
  resolveValues: 'except-theme',
2459
2474
  }),
@@ -2484,7 +2499,7 @@ export function createExtractor(
2484
2499
  {
2485
2500
  ...styleProps,
2486
2501
  noClass: true,
2487
- fallbackProps: completeProps,
2502
+ fallbackProps,
2488
2503
  },
2489
2504
  undefined,
2490
2505
  undefined,
@@ -2641,8 +2656,21 @@ export function createExtractor(
2641
2656
 
2642
2657
  switch (attr.type) {
2643
2658
  case 'ternary': {
2644
- const a = getProps(attr.value.alternate, false, 'ternary.alternate')
2645
- const c = getProps(attr.value.consequent, false, 'ternary.consequent')
2659
+ const branchProps = ternaryBranchProps.get(
2660
+ getTernaryKey(attr.value.test)
2661
+ )
2662
+ const a = getProps(
2663
+ attr.value.alternate,
2664
+ false,
2665
+ 'ternary.alternate',
2666
+ branchProps?.alternate
2667
+ )
2668
+ const c = getProps(
2669
+ attr.value.consequent,
2670
+ false,
2671
+ 'ternary.consequent',
2672
+ branchProps?.consequent
2673
+ )
2646
2674
  if (a) attr.value.alternate = a
2647
2675
  if (c) attr.value.consequent = c
2648
2676
  if (shouldPrintDebug)
@@ -5,6 +5,10 @@ import invariant from 'invariant'
5
5
  import type { Ternary } from '../types'
6
6
  import { forwardFontFamilyName } from './propsToFontFamilyCache'
7
7
 
8
+ export function getTernaryKey(test: t.Node) {
9
+ return generate(test).code
10
+ }
11
+
8
12
  export function normalizeTernaries(ternaries: Ternary[]) {
9
13
  invariant(
10
14
  Array.isArray(ternaries),
@@ -43,8 +47,7 @@ export function normalizeTernaries(ternaries: Ternary[]) {
43
47
  }
44
48
  }
45
49
 
46
- // @ts-ignore
47
- const key = generate(ternaryTest as any).code
50
+ const key = getTernaryKey(ternaryTest)
48
51
 
49
52
  if (!ternariesByKey[key]) {
50
53
  ternariesByKey[key] = {
@@ -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;;;;;;;EAmjF1D"}
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,3 +1,5 @@
1
+ import * as t from '@babel/types';
1
2
  import type { Ternary } from '../types';
3
+ export declare function getTernaryKey(test: t.Node): string;
2
4
  export declare function normalizeTernaries(ternaries: Ternary[]): Ternary[];
3
5
  //# sourceMappingURL=normalizeTernaries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeTernaries.d.ts","sourceRoot":"","sources":["../../src/extractor/normalizeTernaries.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,aAmEtD"}
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"}