@tamagui/static 1.132.14 → 1.132.16-1754534218765
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.js +44 -107
- package/dist/extractor/createExtractor.js.map +1 -1
- package/dist/extractor/createExtractor.native.js +52 -112
- package/dist/extractor/createExtractor.native.js.map +2 -2
- package/dist/extractor/extractMediaStyle.js +1 -1
- package/dist/extractor/extractMediaStyle.js.map +1 -1
- package/dist/extractor/extractMediaStyle.native.js +1 -1
- package/dist/extractor/extractMediaStyle.native.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +184 -168
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/extractToClassNames.native.js +185 -186
- package/dist/extractor/extractToClassNames.native.js.map +2 -2
- package/dist/extractor/extractToNative.js +47 -78
- package/dist/extractor/extractToNative.js.map +1 -1
- package/dist/extractor/extractToNative.native.js +23 -39
- package/dist/extractor/extractToNative.native.js.map +2 -2
- package/dist/extractor/normalizeTernaries.js +5 -2
- package/dist/extractor/normalizeTernaries.js.map +1 -1
- package/dist/extractor/normalizeTernaries.native.js +2 -2
- package/dist/extractor/normalizeTernaries.native.js.map +2 -2
- package/dist/registerRequire.js +1 -1
- package/dist/registerRequire.js.map +1 -1
- package/dist/registerRequire.native.js +1 -1
- package/dist/registerRequire.native.js.map +1 -1
- package/dist/types.native.js.map +1 -1
- package/package.json +15 -15
- package/src/extractor/createExtractor.ts +74 -172
- package/src/extractor/extractMediaStyle.ts +1 -1
- package/src/extractor/extractToClassNames.ts +334 -260
- package/src/extractor/extractToNative.ts +68 -111
- package/src/extractor/normalizeTernaries.ts +7 -3
- package/src/registerRequire.ts +1 -1
- package/src/types.ts +9 -13
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/normalizeTernaries.d.ts.map +1 -1
- package/types/types.d.ts +8 -10
- package/types/types.d.ts.map +1 -1
- package/dist/extractor/buildClassName.js +0 -72
- package/dist/extractor/buildClassName.js.map +0 -6
- package/dist/extractor/buildClassName.native.js +0 -67
- package/dist/extractor/buildClassName.native.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.js +0 -50
- package/dist/extractor/ensureImportingConcat.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.native.js +0 -49
- package/dist/extractor/ensureImportingConcat.native.js.map +0 -6
- package/dist/extractor/hoistClassNames.js +0 -63
- package/dist/extractor/hoistClassNames.js.map +0 -6
- package/dist/extractor/hoistClassNames.native.js +0 -66
- package/dist/extractor/hoistClassNames.native.js.map +0 -6
- package/src/extractor/buildClassName.ts +0 -76
- package/src/extractor/ensureImportingConcat.ts +0 -36
- package/src/extractor/hoistClassNames.ts +0 -52
- package/types/extractor/buildClassName.d.ts +0 -7
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -4
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts +0 -6
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
@@ -46,7 +46,6 @@ import { loadTamagui, loadTamaguiSync } from './loadTamagui'
|
|
46
46
|
import { logLines } from './logLines'
|
47
47
|
import { normalizeTernaries } from './normalizeTernaries'
|
48
48
|
import { setPropsToFontFamily } from './propsToFontFamilyCache'
|
49
|
-
import { removeUnusedHooks } from './removeUnusedHooks'
|
50
49
|
import { timer } from './timer'
|
51
50
|
import { validHTMLAttributes } from './validHTMLAttributes'
|
52
51
|
|
@@ -164,11 +163,10 @@ export function createExtractor(
|
|
164
163
|
evaluateVars = true,
|
165
164
|
sourcePath = '',
|
166
165
|
onExtractTag,
|
167
|
-
|
166
|
+
onStyledDefinitionRule,
|
168
167
|
getFlattenedNode,
|
169
168
|
disable,
|
170
169
|
disableExtraction,
|
171
|
-
disableExtractInlineMedia,
|
172
170
|
disableExtractVariables,
|
173
171
|
disableDebugAttr,
|
174
172
|
enableDynamicEvaluation = false,
|
@@ -676,7 +674,7 @@ export function createExtractor(
|
|
676
674
|
if (out.rulesToInsert) {
|
677
675
|
for (const key in out.rulesToInsert) {
|
678
676
|
const styleObject = out.rulesToInsert[key]
|
679
|
-
|
677
|
+
onStyledDefinitionRule?.(
|
680
678
|
styleObject[StyleObjectIdentifier],
|
681
679
|
styleObject[StyleObjectRules]
|
682
680
|
)
|
@@ -1018,12 +1016,9 @@ export function createExtractor(
|
|
1018
1016
|
}
|
1019
1017
|
// split into individual ternaries per object property
|
1020
1018
|
return [
|
1021
|
-
...(
|
1019
|
+
...(flattenNestedTernaries(test, alt) || []),
|
1022
1020
|
...((cons &&
|
1023
|
-
|
1024
|
-
t.unaryExpression('!', test),
|
1025
|
-
cons
|
1026
|
-
)) ||
|
1021
|
+
flattenNestedTernaries(t.unaryExpression('!', test), cons)) ||
|
1027
1022
|
[]),
|
1028
1023
|
].map((ternary) => ({
|
1029
1024
|
type: 'ternary',
|
@@ -1099,18 +1094,9 @@ export function createExtractor(
|
|
1099
1094
|
if (name[0] === '$' && t.isJSXExpressionContainer(attribute?.value)) {
|
1100
1095
|
const shortname = name.slice(1)
|
1101
1096
|
if (mediaQueryConfig[shortname]) {
|
1102
|
-
if (platform === 'native') {
|
1103
|
-
shouldDeopt = true
|
1104
|
-
}
|
1105
|
-
|
1106
|
-
// allow disabling this extraction
|
1107
|
-
if (disableExtractInlineMedia) {
|
1108
|
-
return attr
|
1109
|
-
}
|
1110
|
-
|
1111
1097
|
const expression = attribute.value.expression
|
1112
1098
|
if (!t.isJSXEmptyExpression(expression)) {
|
1113
|
-
const ternaries =
|
1099
|
+
const ternaries = flattenNestedTernaries(
|
1114
1100
|
t.stringLiteral(shortname),
|
1115
1101
|
expression,
|
1116
1102
|
{
|
@@ -1332,17 +1318,6 @@ export function createExtractor(
|
|
1332
1318
|
return { type: 'ternary', value: staticLogical }
|
1333
1319
|
}
|
1334
1320
|
|
1335
|
-
// Disabling: this probably doesn't optimize much and needs to be done a bit differently
|
1336
|
-
if (options.experimentalFlattenDynamicValues) {
|
1337
|
-
if (isValidStyleKey(name, staticConfig)) {
|
1338
|
-
return {
|
1339
|
-
type: 'dynamic-style',
|
1340
|
-
value,
|
1341
|
-
name: tamaguiConfig?.shorthands[name] || name,
|
1342
|
-
}
|
1343
|
-
}
|
1344
|
-
}
|
1345
|
-
|
1346
1321
|
// if we've made it this far, the prop stays inline
|
1347
1322
|
inlined.set(name, true)
|
1348
1323
|
if (shouldPrintDebug) {
|
@@ -1461,7 +1436,7 @@ export function createExtractor(
|
|
1461
1436
|
// => Ternary<test && x, { background: 'red' }, null>
|
1462
1437
|
// => Ternary<test && !x, { background: 'green' }, null>
|
1463
1438
|
// => Ternary<test && '$gtSm', { color: 'green' }, null>
|
1464
|
-
function
|
1439
|
+
function flattenNestedTernaries(
|
1465
1440
|
test: t.Expression,
|
1466
1441
|
side: t.Expression | null,
|
1467
1442
|
ternaryPartial: Partial<Ternary> = {}
|
@@ -1476,34 +1451,6 @@ export function createExtractor(
|
|
1476
1451
|
if (!t.isObjectProperty(property)) {
|
1477
1452
|
throw new Error('expected object property')
|
1478
1453
|
}
|
1479
|
-
// handle media queries inside spread/conditional objects
|
1480
|
-
if (t.isIdentifier(property.key)) {
|
1481
|
-
const key = property.key.name
|
1482
|
-
const mediaQueryKey = key.slice(1)
|
1483
|
-
const isMediaQuery = key[0] === '$' && mediaQueryConfig[mediaQueryKey]
|
1484
|
-
if (isMediaQuery) {
|
1485
|
-
if (t.isExpression(property.value)) {
|
1486
|
-
const ternaries = createTernariesFromObjectProperties(
|
1487
|
-
t.stringLiteral(mediaQueryKey),
|
1488
|
-
property.value,
|
1489
|
-
{
|
1490
|
-
inlineMediaQuery: mediaQueryKey,
|
1491
|
-
}
|
1492
|
-
)
|
1493
|
-
if (ternaries) {
|
1494
|
-
return ternaries.map((value) => ({
|
1495
|
-
...ternaryPartial,
|
1496
|
-
...value,
|
1497
|
-
// ensure media query test stays on left side (see getMediaQueryTernary)
|
1498
|
-
test: t.logicalExpression('&&', value.test, test),
|
1499
|
-
}))
|
1500
|
-
}
|
1501
|
-
logger.info(['⚠️ no ternaries?', property].join(' '))
|
1502
|
-
} else {
|
1503
|
-
logger.info(['⚠️ not expression', property].join(' '))
|
1504
|
-
}
|
1505
|
-
}
|
1506
|
-
}
|
1507
1454
|
// this could be a recurse here if we want to get fancy
|
1508
1455
|
if (t.isConditionalExpression(property.value)) {
|
1509
1456
|
// merge up into the parent conditional, split into two
|
@@ -1619,66 +1566,70 @@ export function createExtractor(
|
|
1619
1566
|
}
|
1620
1567
|
})
|
1621
1568
|
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
if (
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1569
|
+
if (!shouldFlatten) {
|
1570
|
+
// were no longer partially optimizing, it adds a lot of complexity for dubious performance
|
1571
|
+
if (shouldPrintDebug) {
|
1572
|
+
logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
|
1573
|
+
}
|
1574
|
+
node.attributes = ogAttributes
|
1575
|
+
return
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
// ensure the default styles are there
|
1579
|
+
let skipMap = false
|
1580
|
+
const defaultStyleAttrs = Object.keys(defaultProps).flatMap((key) => {
|
1581
|
+
if (skipMap) return []
|
1582
|
+
const value = defaultProps[key]
|
1583
|
+
if (key === 'theme' && !themeVal) {
|
1584
|
+
if (platform === 'native') {
|
1585
|
+
shouldFlatten = false
|
1586
|
+
skipMap = true
|
1587
|
+
inlined.set('theme', { value: t.stringLiteral(value) })
|
1588
|
+
}
|
1589
|
+
themeVal = { value: t.stringLiteral(value) }
|
1590
|
+
return []
|
1591
|
+
}
|
1592
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
1593
|
+
return []
|
1594
|
+
}
|
1595
|
+
const name = tamaguiConfig?.shorthands[key] || key
|
1596
|
+
if (value === undefined) {
|
1597
|
+
logger.warn(
|
1598
|
+
`⚠️ Error evaluating default style for component, prop ${key} ${value}`
|
1599
|
+
)
|
1600
|
+
shouldDeopt = true
|
1601
|
+
return
|
1602
|
+
}
|
1603
|
+
if (name[0] === '$' && mediaQueryConfig[name.slice(1)]) {
|
1604
|
+
defaultProps[key] = undefined
|
1605
|
+
return evaluateAttribute({
|
1606
|
+
node: t.jsxAttribute(
|
1607
|
+
t.jsxIdentifier(name),
|
1608
|
+
t.jsxExpressionContainer(
|
1609
|
+
t.objectExpression(
|
1610
|
+
Object.keys(value)
|
1611
|
+
.filter((k) => {
|
1612
|
+
return typeof value[k] !== 'undefined'
|
1613
|
+
})
|
1614
|
+
.map((k) => {
|
1615
|
+
return t.objectProperty(t.identifier(k), literalToAst(value[k]))
|
1616
|
+
})
|
1666
1617
|
)
|
1667
|
-
)
|
1668
|
-
|
1669
|
-
}
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
|
1618
|
+
)
|
1619
|
+
),
|
1620
|
+
} as any)
|
1621
|
+
}
|
1622
|
+
const attr: ExtractedAttrStyle = {
|
1623
|
+
type: 'style',
|
1624
|
+
name,
|
1625
|
+
value: { [name]: value },
|
1626
|
+
}
|
1627
|
+
return attr
|
1628
|
+
}) as ExtractedAttr[]
|
1677
1629
|
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
}
|
1630
|
+
if (!skipMap) {
|
1631
|
+
if (defaultStyleAttrs.length) {
|
1632
|
+
attrs = [...defaultStyleAttrs, ...attrs]
|
1682
1633
|
}
|
1683
1634
|
}
|
1684
1635
|
|
@@ -1723,10 +1674,9 @@ export function createExtractor(
|
|
1723
1674
|
}, [])
|
1724
1675
|
.flat()
|
1725
1676
|
|
1726
|
-
const shouldWrapTheme = shouldFlatten && themeVal
|
1727
1677
|
// wrap theme around children on flatten
|
1728
1678
|
// account for shouldFlatten could change w the above block "if (disableExtractVariables)"
|
1729
|
-
if (
|
1679
|
+
if (themeVal) {
|
1730
1680
|
if (!programPath) {
|
1731
1681
|
console.warn(
|
1732
1682
|
`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
|
@@ -1774,38 +1724,6 @@ export function createExtractor(
|
|
1774
1724
|
}
|
1775
1725
|
}
|
1776
1726
|
|
1777
|
-
if (shouldPrintDebug) {
|
1778
|
-
try {
|
1779
|
-
// prettier-ignore
|
1780
|
-
logger.info(
|
1781
|
-
[
|
1782
|
-
' flatten?',
|
1783
|
-
shouldFlatten,
|
1784
|
-
objToStr({
|
1785
|
-
hasSpread,
|
1786
|
-
shouldDeopt,
|
1787
|
-
canFlattenProps,
|
1788
|
-
shouldWrapTheme,
|
1789
|
-
hasOnlyStringChildren,
|
1790
|
-
}),
|
1791
|
-
'inlined',
|
1792
|
-
inlined.size,
|
1793
|
-
[...inlined],
|
1794
|
-
].join(' ')
|
1795
|
-
)
|
1796
|
-
} catch {
|
1797
|
-
// ok
|
1798
|
-
}
|
1799
|
-
}
|
1800
|
-
|
1801
|
-
if (shouldDeopt || !shouldFlatten) {
|
1802
|
-
if (shouldPrintDebug) {
|
1803
|
-
logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
|
1804
|
-
}
|
1805
|
-
node.attributes = ogAttributes
|
1806
|
-
return
|
1807
|
-
}
|
1808
|
-
|
1809
1727
|
if (shouldPrintDebug) {
|
1810
1728
|
logger.info(
|
1811
1729
|
[' - attrs (flattened): \n', logLines(attrs.map(attrStr).join(', '))].join(
|
@@ -2101,12 +2019,10 @@ export function createExtractor(
|
|
2101
2019
|
}
|
2102
2020
|
|
2103
2021
|
// add default props
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
})
|
2109
|
-
}
|
2022
|
+
attrs.unshift({
|
2023
|
+
type: 'style',
|
2024
|
+
value: defaultProps,
|
2025
|
+
})
|
2110
2026
|
|
2111
2027
|
attrs = attrs.reduce<ExtractedAttr[]>((acc, cur) => {
|
2112
2028
|
if (cur.type === 'style') {
|
@@ -2296,15 +2212,6 @@ export function createExtractor(
|
|
2296
2212
|
}
|
2297
2213
|
}
|
2298
2214
|
}
|
2299
|
-
|
2300
|
-
if (attr.type === 'dynamic-style') {
|
2301
|
-
if (existingStyleKeys.has(attr.name)) {
|
2302
|
-
//@ts-ignore
|
2303
|
-
attrs[i] = undefined
|
2304
|
-
} else {
|
2305
|
-
existingStyleKeys.add(attr.name)
|
2306
|
-
}
|
2307
|
-
}
|
2308
2215
|
}
|
2309
2216
|
|
2310
2217
|
if (options.experimentalFlattenThemesOnNative) {
|
@@ -2337,10 +2244,7 @@ export function createExtractor(
|
|
2337
2244
|
|
2338
2245
|
// delete empty styles:
|
2339
2246
|
attrs = attrs.filter((x) => {
|
2340
|
-
if (
|
2341
|
-
(x.type === 'style' || x.type === 'dynamic-style') &&
|
2342
|
-
Object.keys(x.value).length === 0
|
2343
|
-
) {
|
2247
|
+
if (x.type === 'style' && Object.keys(x.value).length === 0) {
|
2344
2248
|
return false
|
2345
2249
|
}
|
2346
2250
|
return true
|
@@ -2394,7 +2298,6 @@ export function createExtractor(
|
|
2394
2298
|
staticConfig.neverFlatten ? 'neverFlatten' : '',
|
2395
2299
|
].join(' ')
|
2396
2300
|
)
|
2397
|
-
logger.info(` - shouldFlatten/isFlattened: ${shouldFlatten}`)
|
2398
2301
|
logger.info(` - attrs (end):\n ${logLines(attrs.map(attrStr).join(', '))}`)
|
2399
2302
|
}
|
2400
2303
|
|
@@ -2408,7 +2311,6 @@ export function createExtractor(
|
|
2408
2311
|
attemptEval,
|
2409
2312
|
jsxPath: traversePath,
|
2410
2313
|
originalNodeName,
|
2411
|
-
isFlattened: shouldFlatten,
|
2412
2314
|
programPath: programPath!,
|
2413
2315
|
completeProps,
|
2414
2316
|
staticConfig,
|
@@ -17,7 +17,7 @@ export function extractMediaStyle(
|
|
17
17
|
importance = 0,
|
18
18
|
shouldPrintDebug: boolean | 'verbose' = false
|
19
19
|
) {
|
20
|
-
const { getCSSStylesAtomic
|
20
|
+
const { getCSSStylesAtomic } = requireTamaguiCore('web')
|
21
21
|
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
|
22
22
|
if (!mt) {
|
23
23
|
return null
|