@tamagui/static 2.5.2 → 2.6.0
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.
- package/dist/extractor/createExtractor.cjs +1 -31
- package/dist/extractor/extractToNative.cjs +11 -3
- package/package.json +15 -15
- package/src/extractor/createExtractor.ts +1 -59
- package/src/extractor/extractToNative.ts +21 -4
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
|
@@ -71,12 +71,6 @@ let hasLoggedBaseInfo = false;
|
|
|
71
71
|
function isFullyDisabled(props) {
|
|
72
72
|
return props.disableExtraction && props.disableDebugAttr;
|
|
73
73
|
}
|
|
74
|
-
function styleValueHasToken(v) {
|
|
75
|
-
if (typeof v === "string") return v.charCodeAt(0) === 36;
|
|
76
|
-
if (Array.isArray(v)) return v.some(styleValueHasToken);
|
|
77
|
-
if (v && typeof v === "object") return Object.values(v).some(styleValueHasToken);
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
74
|
function hasUntilMeasuredAncestor(path, groupName) {
|
|
81
75
|
let current = path.parentPath;
|
|
82
76
|
while (current) {
|
|
@@ -1394,31 +1388,7 @@ function createExtractor({
|
|
|
1394
1388
|
neverFlatten: staticConfig.neverFlatten
|
|
1395
1389
|
})}`);
|
|
1396
1390
|
}
|
|
1397
|
-
|
|
1398
|
-
if (platform2 === "native" && !staticConfig.isHOC && !staticConfig.isStyledHOC && !ogAttributes.some(a => t.isJSXSpreadAttribute(a) || t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === "style")) {
|
|
1399
|
-
const staticStyle = {};
|
|
1400
|
-
const consumed = /* @__PURE__ */new Set();
|
|
1401
|
-
for (const a of attrs) {
|
|
1402
|
-
if (a.type !== "style" || !a.name || !a.attr) continue;
|
|
1403
|
-
if (pseudoDescriptors[a.name]) continue;
|
|
1404
|
-
if (!t.isJSXAttribute(a.attr) || !t.isJSXIdentifier(a.attr.name)) continue;
|
|
1405
|
-
if (styleValueHasToken(a.value)) continue;
|
|
1406
|
-
Object.assign(staticStyle, a.value);
|
|
1407
|
-
consumed.add(a.attr.name.name);
|
|
1408
|
-
}
|
|
1409
|
-
if (consumed.size >= 2) {
|
|
1410
|
-
const kept = ogAttributes.filter(a => {
|
|
1411
|
-
if (!t.isJSXAttribute(a) || !t.isJSXIdentifier(a.name)) return true;
|
|
1412
|
-
const n = a.name.name;
|
|
1413
|
-
if (consumed.has(n)) return false;
|
|
1414
|
-
if (n === "hoverStyle") return false;
|
|
1415
|
-
if (n.startsWith("$group-") && getGroupPseudo(n) === "hover") return false;
|
|
1416
|
-
return true;
|
|
1417
|
-
});
|
|
1418
|
-
partial = [t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(staticStyle))), ...kept];
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
node.attributes = partial ?? ogAttributes;
|
|
1391
|
+
node.attributes = ogAttributes;
|
|
1422
1392
|
return;
|
|
1423
1393
|
}
|
|
1424
1394
|
let skipMap = false;
|
|
@@ -178,6 +178,7 @@ function getBabelParseDefinition(options) {
|
|
|
178
178
|
const stylesExpr = t.arrayExpression([]);
|
|
179
179
|
const hocStylesExpr = t.arrayExpression([]);
|
|
180
180
|
const expressions = [];
|
|
181
|
+
const mediaExpressionIndexes = /* @__PURE__ */new Set();
|
|
181
182
|
const finalAttrs = [];
|
|
182
183
|
const themeKeysUsed = /* @__PURE__ */new Set();
|
|
183
184
|
function getStyleExpression(style, forTernary = false) {
|
|
@@ -253,7 +254,14 @@ function getBabelParseDefinition(options) {
|
|
|
253
254
|
if (attr.value.inlineMediaQuery) {
|
|
254
255
|
hasMediaKeys = true;
|
|
255
256
|
}
|
|
256
|
-
|
|
257
|
+
let expression = attr.value.test;
|
|
258
|
+
if (attr.value.inlineMediaQuery && t.isLogicalExpression(attr.value.test, {
|
|
259
|
+
operator: "&&"
|
|
260
|
+
}) && t.isStringLiteral(attr.value.test.left)) {
|
|
261
|
+
expression = t.arrayExpression([t.stringLiteral(attr.value.inlineMediaQuery), t.unaryExpression("!", t.unaryExpression("!", attr.value.test.right))]);
|
|
262
|
+
mediaExpressionIndexes.add(expressions.length);
|
|
263
|
+
}
|
|
264
|
+
expressions.push(expression);
|
|
257
265
|
addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), true);
|
|
258
266
|
const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
|
|
259
267
|
addStyleExpression(styleExpr);
|
|
@@ -273,7 +281,7 @@ function getBabelParseDefinition(options) {
|
|
|
273
281
|
}
|
|
274
282
|
}
|
|
275
283
|
props.node.attributes = finalAttrs;
|
|
276
|
-
if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
|
|
284
|
+
if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle || hasMediaKeys) {
|
|
277
285
|
if (!hasImportedViewWrapper) {
|
|
278
286
|
root.unshiftContainer("body", importWithStyle);
|
|
279
287
|
hasImportedViewWrapper = true;
|
|
@@ -292,7 +300,7 @@ function getBabelParseDefinition(options) {
|
|
|
292
300
|
props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName);
|
|
293
301
|
}
|
|
294
302
|
if (expressions.length) {
|
|
295
|
-
const safeExpressions = expressions.map(expr => t.isStringLiteral(expr) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
|
|
303
|
+
const safeExpressions = expressions.map((expr, index) => t.isStringLiteral(expr) || mediaExpressionIndexes.has(index) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
|
|
296
304
|
props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(safeExpressions))));
|
|
297
305
|
}
|
|
298
306
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
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.
|
|
54
|
-
"@tamagui/config-default": "2.
|
|
55
|
-
"@tamagui/core": "2.
|
|
56
|
-
"@tamagui/fake-react-native": "2.
|
|
57
|
-
"@tamagui/generate-themes": "2.
|
|
58
|
-
"@tamagui/helpers": "2.
|
|
59
|
-
"@tamagui/helpers-node": "2.
|
|
60
|
-
"@tamagui/proxy-worm": "2.
|
|
61
|
-
"@tamagui/react-native-web-internals": "2.
|
|
62
|
-
"@tamagui/react-native-web-lite": "2.
|
|
63
|
-
"@tamagui/shorthands": "2.
|
|
64
|
-
"@tamagui/types": "2.
|
|
65
|
-
"@tamagui/web": "2.
|
|
53
|
+
"@tamagui/cli-color": "2.6.0",
|
|
54
|
+
"@tamagui/config-default": "2.6.0",
|
|
55
|
+
"@tamagui/core": "2.6.0",
|
|
56
|
+
"@tamagui/fake-react-native": "2.6.0",
|
|
57
|
+
"@tamagui/generate-themes": "2.6.0",
|
|
58
|
+
"@tamagui/helpers": "2.6.0",
|
|
59
|
+
"@tamagui/helpers-node": "2.6.0",
|
|
60
|
+
"@tamagui/proxy-worm": "2.6.0",
|
|
61
|
+
"@tamagui/react-native-web-internals": "2.6.0",
|
|
62
|
+
"@tamagui/react-native-web-lite": "2.6.0",
|
|
63
|
+
"@tamagui/shorthands": "2.6.0",
|
|
64
|
+
"@tamagui/types": "2.6.0",
|
|
65
|
+
"@tamagui/web": "2.6.0",
|
|
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.
|
|
82
|
+
"@tamagui/build": "2.6.0",
|
|
83
83
|
"@types/babel__core": "^7.20.5",
|
|
84
84
|
"@types/find-root": "^1.1.2",
|
|
85
85
|
"@types/node": "^22.1.0",
|
|
@@ -76,16 +76,6 @@ function isFullyDisabled(props: TamaguiOptions) {
|
|
|
76
76
|
return props.disableExtraction && props.disableDebugAttr
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
// a compile-evaluated style value carries a theme token if any leaf string is
|
|
80
|
-
// "$"-prefixed (e.g. "$gray2"). such styles must NOT be flattened into a static
|
|
81
|
-
// `style` object — the token is resolved at runtime so theme switching keeps working.
|
|
82
|
-
function styleValueHasToken(v: any): boolean {
|
|
83
|
-
if (typeof v === 'string') return v.charCodeAt(0) === 36 // '$'
|
|
84
|
-
if (Array.isArray(v)) return v.some(styleValueHasToken)
|
|
85
|
-
if (v && typeof v === 'object') return Object.values(v).some(styleValueHasToken)
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
79
|
// Walk up JSX ancestors looking for one that declares `group="<groupName>"` together
|
|
90
80
|
// with the `untilMeasured` prop. Used to deopt children whose styles depend on a
|
|
91
81
|
// parent that the runtime measures before emitting child styles (can't be modeled
|
|
@@ -2036,55 +2026,7 @@ export function createExtractor(
|
|
|
2036
2026
|
})}`
|
|
2037
2027
|
)
|
|
2038
2028
|
}
|
|
2039
|
-
|
|
2040
|
-
// path (pseudo/group/dynamic keep it deopted), pre-merge the pure-static
|
|
2041
|
-
// style props into a single `style={…}` so the runtime skips its per-prop
|
|
2042
|
-
// loop for them (the dominant deopt cost on RN). theme tokens ($…) and
|
|
2043
|
-
// dynamic props stay inline so theme/media switching + dynamics are
|
|
2044
|
-
// unaffected; dead native hoverStyle is dropped (no-op on touch).
|
|
2045
|
-
let partial: (t.JSXAttribute | t.JSXSpreadAttribute)[] | null = null
|
|
2046
|
-
if (
|
|
2047
|
-
platform === 'native' &&
|
|
2048
|
-
!staticConfig.isHOC &&
|
|
2049
|
-
!staticConfig.isStyledHOC &&
|
|
2050
|
-
!ogAttributes.some(
|
|
2051
|
-
(a) =>
|
|
2052
|
-
t.isJSXSpreadAttribute(a) ||
|
|
2053
|
-
(t.isJSXAttribute(a) &&
|
|
2054
|
-
t.isJSXIdentifier(a.name) &&
|
|
2055
|
-
a.name.name === 'style')
|
|
2056
|
-
)
|
|
2057
|
-
) {
|
|
2058
|
-
const staticStyle: Record<string, any> = {}
|
|
2059
|
-
const consumed = new Set<string>()
|
|
2060
|
-
for (const a of attrs) {
|
|
2061
|
-
if (a.type !== 'style' || !a.name || !a.attr) continue
|
|
2062
|
-
if (pseudoDescriptors[a.name]) continue
|
|
2063
|
-
if (!t.isJSXAttribute(a.attr) || !t.isJSXIdentifier(a.attr.name)) continue
|
|
2064
|
-
if (styleValueHasToken(a.value)) continue
|
|
2065
|
-
Object.assign(staticStyle, a.value)
|
|
2066
|
-
consumed.add(a.attr.name.name)
|
|
2067
|
-
}
|
|
2068
|
-
if (consumed.size >= 2) {
|
|
2069
|
-
const kept = ogAttributes.filter((a) => {
|
|
2070
|
-
if (!t.isJSXAttribute(a) || !t.isJSXIdentifier(a.name)) return true
|
|
2071
|
-
const n = a.name.name
|
|
2072
|
-
if (consumed.has(n)) return false
|
|
2073
|
-
if (n === 'hoverStyle') return false
|
|
2074
|
-
if (n.startsWith('$group-') && getGroupPseudo(n) === 'hover')
|
|
2075
|
-
return false
|
|
2076
|
-
return true
|
|
2077
|
-
})
|
|
2078
|
-
partial = [
|
|
2079
|
-
t.jsxAttribute(
|
|
2080
|
-
t.jsxIdentifier('style'),
|
|
2081
|
-
t.jsxExpressionContainer(literalToAst(staticStyle) as t.Expression)
|
|
2082
|
-
),
|
|
2083
|
-
...kept,
|
|
2084
|
-
]
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
node.attributes = partial ?? ogAttributes
|
|
2029
|
+
node.attributes = ogAttributes
|
|
2088
2030
|
return
|
|
2089
2031
|
}
|
|
2090
2032
|
|
|
@@ -207,6 +207,7 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
|
|
|
207
207
|
const stylesExpr = t.arrayExpression([])
|
|
208
208
|
const hocStylesExpr = t.arrayExpression([])
|
|
209
209
|
const expressions: t.Expression[] = []
|
|
210
|
+
const mediaExpressionIndexes = new Set<number>()
|
|
210
211
|
const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
|
|
211
212
|
const themeKeysUsed = new Set<string>()
|
|
212
213
|
|
|
@@ -299,7 +300,22 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
|
|
|
299
300
|
hasMediaKeys = true
|
|
300
301
|
}
|
|
301
302
|
|
|
302
|
-
|
|
303
|
+
let expression = attr.value.test
|
|
304
|
+
if (
|
|
305
|
+
attr.value.inlineMediaQuery &&
|
|
306
|
+
t.isLogicalExpression(attr.value.test, { operator: '&&' }) &&
|
|
307
|
+
t.isStringLiteral(attr.value.test.left)
|
|
308
|
+
) {
|
|
309
|
+
expression = t.arrayExpression([
|
|
310
|
+
t.stringLiteral(attr.value.inlineMediaQuery),
|
|
311
|
+
t.unaryExpression(
|
|
312
|
+
'!',
|
|
313
|
+
t.unaryExpression('!', attr.value.test.right)
|
|
314
|
+
),
|
|
315
|
+
])
|
|
316
|
+
mediaExpressionIndexes.add(expressions.length)
|
|
317
|
+
}
|
|
318
|
+
expressions.push(expression)
|
|
303
319
|
addStyleExpression(
|
|
304
320
|
t.conditionalExpression(
|
|
305
321
|
t.identifier(`_expressions[${expressions.length - 1}]`),
|
|
@@ -340,7 +356,8 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
|
|
|
340
356
|
if (
|
|
341
357
|
themeKeysUsed.size ||
|
|
342
358
|
hocStylesExpr.elements.length > 1 ||
|
|
343
|
-
hasDynamicStyle
|
|
359
|
+
hasDynamicStyle ||
|
|
360
|
+
hasMediaKeys
|
|
344
361
|
) {
|
|
345
362
|
if (!hasImportedViewWrapper) {
|
|
346
363
|
root.unshiftContainer('body', importWithStyle)
|
|
@@ -386,8 +403,8 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
|
|
|
386
403
|
if (expressions.length) {
|
|
387
404
|
// coerce runtime expressions to boolean so they can't be
|
|
388
405
|
// confused with string media keys at runtime
|
|
389
|
-
const safeExpressions = expressions.map((expr) =>
|
|
390
|
-
t.isStringLiteral(expr)
|
|
406
|
+
const safeExpressions = expressions.map((expr, index) =>
|
|
407
|
+
t.isStringLiteral(expr) || mediaExpressionIndexes.has(index)
|
|
391
408
|
? expr
|
|
392
409
|
: t.unaryExpression('!', t.unaryExpression('!', expr))
|
|
393
410
|
)
|
|
@@ -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;
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractToNative.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,aAAa,CAAA;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAsB9C,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,eAAe,CAoBjB;AAED,wBAAgB,cAAc,QAK7B;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;wBAM3C,GAAG;;;
|
|
1
|
+
{"version":3,"file":"extractToNative.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,aAAa,CAAA;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAsB9C,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,eAAe,CAoBjB;AAED,wBAAgB,cAAc,QAK7B;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;wBAM3C,GAAG;;;EA0ZtB"}
|