@tamagui/static 1.0.0-beta.9 → 1.0.1-beta.101
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/cjs/extractor/accessSafe.js +0 -2
- package/dist/cjs/extractor/accessSafe.js.map +1 -1
- package/dist/cjs/extractor/babelParse.js +15 -16
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +0 -2
- package/dist/cjs/extractor/buildClassName.js.map +1 -1
- package/dist/cjs/extractor/createEvaluator.js +9 -7
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +318 -145
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +0 -2
- package/dist/cjs/extractor/ensureImportingConcat.js.map +1 -1
- package/dist/cjs/extractor/evaluateAstNode.js +0 -2
- package/dist/cjs/extractor/evaluateAstNode.js.map +1 -1
- package/dist/cjs/extractor/extractHelpers.js +11 -16
- package/dist/cjs/extractor/extractHelpers.js.map +1 -1
- package/dist/cjs/extractor/extractMediaStyle.js +3 -8
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +27 -42
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +1 -3
- package/dist/cjs/extractor/findTopmostFunction.js.map +1 -1
- package/dist/cjs/extractor/generatedUid.js +0 -2
- package/dist/cjs/extractor/generatedUid.js.map +1 -1
- package/dist/cjs/extractor/getPrefixLogs.js +0 -2
- package/dist/cjs/extractor/getPrefixLogs.js.map +1 -1
- package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -2
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +1 -1
- package/dist/cjs/extractor/getSourceModule.js +0 -2
- package/dist/cjs/extractor/getSourceModule.js.map +1 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js +1 -5
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/cjs/extractor/hoistClassNames.js +0 -3
- package/dist/cjs/extractor/hoistClassNames.js.map +1 -1
- package/dist/cjs/extractor/literalToAst.js +0 -4
- package/dist/cjs/extractor/literalToAst.js.map +1 -1
- package/dist/cjs/extractor/loadTamagui.js +43 -10
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +2 -3
- package/dist/cjs/extractor/logLines.js.map +1 -1
- package/dist/cjs/extractor/normalizeTernaries.js +0 -2
- package/dist/cjs/extractor/normalizeTernaries.js.map +1 -1
- package/dist/cjs/extractor/removeUnusedHooks.js +2 -4
- package/dist/cjs/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/cjs/extractor/timer.js +2 -3
- package/dist/cjs/extractor/timer.js.map +1 -1
- package/dist/cjs/extractor/validHTMLAttributes.js +51 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/accessSafe.js +0 -3
- package/dist/esm/extractor/accessSafe.js.map +1 -1
- package/dist/esm/extractor/babelParse.js +15 -17
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/buildClassName.js +0 -3
- package/dist/esm/extractor/buildClassName.js.map +1 -1
- package/dist/esm/extractor/createEvaluator.js +9 -8
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +405 -195
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +0 -3
- package/dist/esm/extractor/ensureImportingConcat.js.map +1 -1
- package/dist/esm/extractor/evaluateAstNode.js +0 -3
- package/dist/esm/extractor/evaluateAstNode.js.map +1 -1
- package/dist/esm/extractor/extractHelpers.js +11 -17
- package/dist/esm/extractor/extractHelpers.js.map +1 -1
- package/dist/esm/extractor/extractMediaStyle.js +29 -20
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +53 -52
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +1 -4
- package/dist/esm/extractor/findTopmostFunction.js.map +1 -1
- package/dist/esm/extractor/generatedUid.js +0 -3
- package/dist/esm/extractor/generatedUid.js.map +1 -1
- package/dist/esm/extractor/getPrefixLogs.js +1 -5
- package/dist/esm/extractor/getPrefixLogs.js.map +1 -1
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -3
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +1 -1
- package/dist/esm/extractor/getSourceModule.js +0 -3
- package/dist/esm/extractor/getSourceModule.js.map +1 -1
- package/dist/esm/extractor/getStaticBindingsForScope.js +1 -6
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/esm/extractor/hoistClassNames.js +0 -4
- package/dist/esm/extractor/hoistClassNames.js.map +1 -1
- package/dist/esm/extractor/literalToAst.js +21 -11
- package/dist/esm/extractor/literalToAst.js.map +1 -1
- package/dist/esm/extractor/loadTamagui.js +44 -11
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/logLines.js +2 -4
- package/dist/esm/extractor/logLines.js.map +1 -1
- package/dist/esm/extractor/normalizeTernaries.js +35 -9
- package/dist/esm/extractor/normalizeTernaries.js.map +1 -1
- package/dist/esm/extractor/removeUnusedHooks.js +5 -9
- package/dist/esm/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/esm/extractor/timer.js +2 -4
- package/dist/esm/extractor/timer.js.map +1 -1
- package/dist/esm/extractor/validHTMLAttributes.js +50 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/jsx/constants.js +1 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/extractor/accessSafe.js +1 -3
- package/dist/jsx/extractor/accessSafe.js.map +7 -0
- package/dist/jsx/extractor/babelParse.js +16 -17
- package/dist/jsx/extractor/babelParse.js.map +7 -0
- package/dist/jsx/extractor/buildClassName.js +1 -3
- package/dist/jsx/extractor/buildClassName.js.map +7 -0
- package/dist/jsx/extractor/createEvaluator.js +10 -8
- package/dist/jsx/extractor/createEvaluator.js.map +7 -0
- package/dist/jsx/extractor/createExtractor.js +325 -150
- package/dist/jsx/extractor/createExtractor.js.map +7 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +1 -3
- package/dist/jsx/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/jsx/extractor/evaluateAstNode.js +1 -3
- package/dist/jsx/extractor/evaluateAstNode.js.map +7 -0
- package/dist/jsx/extractor/extractHelpers.js +12 -17
- package/dist/jsx/extractor/extractHelpers.js.map +7 -0
- package/dist/jsx/extractor/extractMediaStyle.js +4 -9
- package/dist/jsx/extractor/extractMediaStyle.js.map +7 -0
- package/dist/jsx/extractor/extractToClassNames.js +31 -43
- package/dist/jsx/extractor/extractToClassNames.js.map +7 -0
- package/dist/jsx/extractor/findTopmostFunction.js +2 -4
- package/dist/jsx/extractor/findTopmostFunction.js.map +7 -0
- package/dist/jsx/extractor/generatedUid.js +1 -3
- package/dist/jsx/extractor/generatedUid.js.map +7 -0
- package/dist/jsx/extractor/getPrefixLogs.js +1 -3
- package/dist/jsx/extractor/getPrefixLogs.js.map +7 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +1 -3
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/jsx/extractor/getSourceModule.js +1 -3
- package/dist/jsx/extractor/getSourceModule.js.map +7 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +2 -6
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/jsx/extractor/hoistClassNames.js +1 -4
- package/dist/jsx/extractor/hoistClassNames.js.map +7 -0
- package/dist/jsx/extractor/literalToAst.js +1 -5
- package/dist/jsx/extractor/literalToAst.js.map +7 -0
- package/dist/jsx/extractor/loadTamagui.js +30 -11
- package/dist/jsx/extractor/loadTamagui.js.map +7 -0
- package/dist/jsx/extractor/logLines.js +3 -4
- package/dist/jsx/extractor/logLines.js.map +7 -0
- package/dist/jsx/extractor/normalizeTernaries.js +1 -3
- package/dist/jsx/extractor/normalizeTernaries.js.map +7 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +3 -5
- package/dist/jsx/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/jsx/extractor/timer.js +3 -4
- package/dist/jsx/extractor/timer.js.map +7 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
- package/dist/jsx/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/jsx/index.js +3 -1
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/package.json +28 -20
- package/src/constants.ts +13 -0
- package/src/extractor/accessSafe.ts +18 -0
- package/src/extractor/babelParse.ts +27 -0
- package/src/extractor/buildClassName.ts +61 -0
- package/src/extractor/createEvaluator.ts +75 -0
- package/src/extractor/createExtractor.ts +1928 -0
- package/src/extractor/ensureImportingConcat.ts +39 -0
- package/src/extractor/evaluateAstNode.ts +121 -0
- package/src/extractor/extractHelpers.ts +119 -0
- package/src/extractor/extractMediaStyle.ts +192 -0
- package/src/extractor/extractToClassNames.ts +393 -0
- package/src/extractor/findTopmostFunction.ts +22 -0
- package/src/extractor/generatedUid.ts +43 -0
- package/src/extractor/getPrefixLogs.ts +6 -0
- package/src/extractor/getPropValueFromAttributes.ts +92 -0
- package/src/extractor/getSourceModule.ts +101 -0
- package/src/extractor/getStaticBindingsForScope.ts +183 -0
- package/src/extractor/hoistClassNames.ts +45 -0
- package/src/extractor/literalToAst.ts +84 -0
- package/src/extractor/loadTamagui.ts +145 -0
- package/src/extractor/logLines.ts +16 -0
- package/src/extractor/normalizeTernaries.ts +63 -0
- package/src/extractor/removeUnusedHooks.ts +76 -0
- package/src/extractor/timer.ts +18 -0
- package/src/extractor/validHTMLAttributes.ts +99 -0
- package/src/index.ts +10 -0
- package/src/types.ts +96 -0
- package/types/constants.d.ts +0 -0
- package/types/constants.d.ts.map +0 -0
- package/types/extractor/accessSafe.d.ts +0 -0
- package/types/extractor/accessSafe.d.ts.map +0 -0
- package/types/extractor/babelParse.d.ts +0 -0
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/buildClassName.d.ts +0 -0
- package/types/extractor/buildClassName.d.ts.map +0 -0
- package/types/extractor/createEvaluator.d.ts +1 -1
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +3 -4
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -0
- package/types/extractor/evaluateAstNode.d.ts +0 -0
- package/types/extractor/evaluateAstNode.d.ts.map +0 -0
- package/types/extractor/extractHelpers.d.ts +1 -1
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +0 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +1 -6
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/findTopmostFunction.d.ts +0 -0
- package/types/extractor/findTopmostFunction.d.ts.map +0 -0
- package/types/extractor/generatedUid.d.ts +0 -0
- package/types/extractor/generatedUid.d.ts.map +0 -0
- package/types/extractor/getPrefixLogs.d.ts +0 -0
- package/types/extractor/getPrefixLogs.d.ts.map +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -0
- package/types/extractor/getSourceModule.d.ts +0 -0
- package/types/extractor/getSourceModule.d.ts.map +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -0
- package/types/extractor/hoistClassNames.d.ts +0 -0
- package/types/extractor/hoistClassNames.d.ts.map +0 -0
- package/types/extractor/literalToAst.d.ts +0 -0
- package/types/extractor/literalToAst.d.ts.map +0 -0
- package/types/extractor/loadTamagui.d.ts +10 -4
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/extractor/logLines.d.ts +0 -0
- package/types/extractor/logLines.d.ts.map +0 -0
- package/types/extractor/normalizeTernaries.d.ts +0 -0
- package/types/extractor/normalizeTernaries.d.ts.map +0 -0
- package/types/extractor/removeUnusedHooks.d.ts +0 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -0
- package/types/extractor/timer.d.ts +0 -0
- package/types/extractor/timer.d.ts.map +0 -0
- package/types/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -1
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +6 -7
- package/types/types.d.ts.map +1 -1
- package/dist/cjs/patchReactNativeWeb.js +0 -167
- package/dist/cjs/patchReactNativeWeb.js.map +0 -7
- package/dist/esm/patchReactNativeWeb.js +0 -142
- package/dist/esm/patchReactNativeWeb.js.map +0 -7
- package/dist/jsx/patchReactNativeWeb.js +0 -141
- package/types/patchReactNativeWeb.d.ts +0 -2
- package/types/patchReactNativeWeb.d.ts.map +0 -1
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
3
32
|
import { relative } from "path";
|
|
4
33
|
import traverse from "@babel/traverse";
|
|
5
34
|
import * as t from "@babel/types";
|
|
6
35
|
import {
|
|
36
|
+
createDOMProps,
|
|
37
|
+
expandStyles,
|
|
7
38
|
getSplitStyles,
|
|
39
|
+
getStylesAtomic,
|
|
8
40
|
mediaQueryConfig,
|
|
9
|
-
normalizeStyleObject,
|
|
10
41
|
proxyThemeVariables,
|
|
11
|
-
|
|
12
|
-
|
|
42
|
+
pseudoDescriptors,
|
|
43
|
+
stylePropsTransform
|
|
13
44
|
} from "@tamagui/core-node";
|
|
14
45
|
import { difference, pick } from "lodash";
|
|
15
46
|
import { FAILED_EVAL } from "../constants";
|
|
@@ -39,12 +70,12 @@ const INLINE_EXTRACTABLE = {
|
|
|
39
70
|
onPressIn: "onMouseDown",
|
|
40
71
|
onPressOut: "onMouseUp"
|
|
41
72
|
};
|
|
42
|
-
const isAttr =
|
|
73
|
+
const isAttr = (x) => x.type === "attr";
|
|
43
74
|
const validHooks = {
|
|
44
75
|
useMedia: true,
|
|
45
76
|
useTheme: true
|
|
46
77
|
};
|
|
47
|
-
const createTernary =
|
|
78
|
+
const createTernary = (x) => x;
|
|
48
79
|
function createExtractor() {
|
|
49
80
|
if (!process.env.TAMAGUI_TARGET) {
|
|
50
81
|
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
@@ -53,27 +84,52 @@ function createExtractor() {
|
|
|
53
84
|
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);
|
|
54
85
|
let loadedTamaguiConfig;
|
|
55
86
|
let hasLogged = false;
|
|
87
|
+
function isValidStyleKey(name, staticConfig) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
90
|
+
}
|
|
56
91
|
return {
|
|
57
92
|
getTamagui() {
|
|
58
93
|
return loadedTamaguiConfig;
|
|
59
94
|
},
|
|
60
|
-
parse: (fileOrPath, {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
parse: (fileOrPath, _a) => {
|
|
96
|
+
var _b = _a, {
|
|
97
|
+
config = "tamagui.config.ts",
|
|
98
|
+
importsWhitelist = ["constants.js"],
|
|
99
|
+
evaluateVars = true,
|
|
100
|
+
shouldPrintDebug = false,
|
|
101
|
+
sourcePath = "",
|
|
102
|
+
onExtractTag,
|
|
103
|
+
onStyleRule,
|
|
104
|
+
getFlattenedNode,
|
|
105
|
+
disable,
|
|
106
|
+
disableExtraction,
|
|
107
|
+
disableExtractInlineMedia,
|
|
108
|
+
disableExtractVariables,
|
|
109
|
+
disableDebugAttr,
|
|
110
|
+
extractStyledDefinitions = false,
|
|
111
|
+
prefixLogs,
|
|
112
|
+
excludeProps,
|
|
113
|
+
target
|
|
114
|
+
} = _b, props = __objRest(_b, [
|
|
115
|
+
"config",
|
|
116
|
+
"importsWhitelist",
|
|
117
|
+
"evaluateVars",
|
|
118
|
+
"shouldPrintDebug",
|
|
119
|
+
"sourcePath",
|
|
120
|
+
"onExtractTag",
|
|
121
|
+
"onStyleRule",
|
|
122
|
+
"getFlattenedNode",
|
|
123
|
+
"disable",
|
|
124
|
+
"disableExtraction",
|
|
125
|
+
"disableExtractInlineMedia",
|
|
126
|
+
"disableExtractVariables",
|
|
127
|
+
"disableDebugAttr",
|
|
128
|
+
"extractStyledDefinitions",
|
|
129
|
+
"prefixLogs",
|
|
130
|
+
"excludeProps",
|
|
131
|
+
"target"
|
|
132
|
+
]);
|
|
77
133
|
if (disable) {
|
|
78
134
|
return null;
|
|
79
135
|
}
|
|
@@ -83,6 +139,7 @@ function createExtractor() {
|
|
|
83
139
|
if (!Array.isArray(props.components)) {
|
|
84
140
|
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
85
141
|
}
|
|
142
|
+
const isTargetingHTML = target === "html";
|
|
86
143
|
const ogDebug = shouldPrintDebug;
|
|
87
144
|
const tm = timer();
|
|
88
145
|
const { components, tamaguiConfig } = loadTamagui({
|
|
@@ -94,14 +151,23 @@ function createExtractor() {
|
|
|
94
151
|
}
|
|
95
152
|
tm.mark("load-tamagui", shouldPrintDebug === "verbose");
|
|
96
153
|
loadedTamaguiConfig = tamaguiConfig;
|
|
97
|
-
const
|
|
154
|
+
const proxiedTheme = proxyThemeVariables(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
|
|
155
|
+
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
156
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
157
|
+
get(target2, key) {
|
|
158
|
+
if (key[0] === "$") {
|
|
159
|
+
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
160
|
+
}
|
|
161
|
+
return Reflect.get(target2, key);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
98
164
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
99
|
-
const isInternalImport =
|
|
165
|
+
const isInternalImport = (importStr) => {
|
|
100
166
|
return isInsideTamagui(sourcePath) && importStr[0] === ".";
|
|
101
|
-
}
|
|
167
|
+
};
|
|
102
168
|
const validComponents = Object.keys(components).filter((key) => {
|
|
103
|
-
var
|
|
104
|
-
return key[0].toUpperCase() === key[0] && !!((
|
|
169
|
+
var _a2;
|
|
170
|
+
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
105
171
|
}).reduce((obj, name) => {
|
|
106
172
|
obj[name] = components[name];
|
|
107
173
|
return obj;
|
|
@@ -116,11 +182,21 @@ function createExtractor() {
|
|
|
116
182
|
continue;
|
|
117
183
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
118
184
|
const from = node.source.value;
|
|
185
|
+
if (extractStyledDefinitions) {
|
|
186
|
+
if (from === "@tamagui/core" || from === "tamagui") {
|
|
187
|
+
if (node.specifiers.some((specifier) => {
|
|
188
|
+
return specifier.local.name === "styled";
|
|
189
|
+
})) {
|
|
190
|
+
doesUseValidImport = true;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
119
195
|
const isValidImport = props.components.includes(from) || isInternalImport(from);
|
|
120
196
|
if (isValidImport) {
|
|
121
197
|
const isValidComponent = node.specifiers.some((specifier) => {
|
|
122
198
|
const name = specifier.local.name;
|
|
123
|
-
return validComponents[name] || validHooks[name];
|
|
199
|
+
return !!(validComponents[name] || validHooks[name]);
|
|
124
200
|
});
|
|
125
201
|
if (shouldPrintDebug === "verbose") {
|
|
126
202
|
console.log("import from", from, { isValidComponent });
|
|
@@ -141,11 +217,12 @@ function createExtractor() {
|
|
|
141
217
|
let couldntParse = false;
|
|
142
218
|
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
143
219
|
const bindingCache = {};
|
|
144
|
-
const callTraverse =
|
|
220
|
+
const callTraverse = (a) => {
|
|
145
221
|
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
146
|
-
}
|
|
222
|
+
};
|
|
147
223
|
let programPath;
|
|
148
224
|
const res = {
|
|
225
|
+
styled: 0,
|
|
149
226
|
flattened: 0,
|
|
150
227
|
optimized: 0,
|
|
151
228
|
modified: 0,
|
|
@@ -157,8 +234,97 @@ function createExtractor() {
|
|
|
157
234
|
programPath = path;
|
|
158
235
|
}
|
|
159
236
|
},
|
|
237
|
+
CallExpression(path) {
|
|
238
|
+
var _a2;
|
|
239
|
+
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
246
|
+
const definition = path.node.arguments[1];
|
|
247
|
+
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const Component = validComponents[name];
|
|
251
|
+
if (!Component) {
|
|
252
|
+
if (shouldPrintDebug) {
|
|
253
|
+
console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
258
|
+
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
259
|
+
...Component.staticConfig.inlineProps || [],
|
|
260
|
+
...Component.staticConfig.deoptProps || [],
|
|
261
|
+
"variants",
|
|
262
|
+
"defaultVariants",
|
|
263
|
+
"fontFamily",
|
|
264
|
+
"name"
|
|
265
|
+
]);
|
|
266
|
+
const skipped = [];
|
|
267
|
+
const styles = {};
|
|
268
|
+
const staticNamespace = getStaticBindingsForScope(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
269
|
+
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
270
|
+
tamaguiConfig,
|
|
271
|
+
staticNamespace,
|
|
272
|
+
sourcePath,
|
|
273
|
+
shouldPrintDebug
|
|
274
|
+
});
|
|
275
|
+
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
276
|
+
for (const property of definition.properties) {
|
|
277
|
+
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || ((_a2 = Component.staticConfig.variants) == null ? void 0 : _a2[property.key.name]) || componentSkipProps.has(property.key.name)) {
|
|
278
|
+
skipped.push(property);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const out2 = attemptEvalSafe(property.value);
|
|
282
|
+
if (out2 === FAILED_EVAL) {
|
|
283
|
+
skipped.push(property);
|
|
284
|
+
} else {
|
|
285
|
+
styles[property.key.name] = out2;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, {
|
|
289
|
+
focus: false,
|
|
290
|
+
hover: false,
|
|
291
|
+
mounted: false,
|
|
292
|
+
press: false,
|
|
293
|
+
pressIn: false,
|
|
294
|
+
resolveVariablesAs: "variable"
|
|
295
|
+
});
|
|
296
|
+
const classNames = __spreadValues({}, out.classNames);
|
|
297
|
+
const atomics = getStylesAtomic(out.style);
|
|
298
|
+
if (shouldPrintDebug) {
|
|
299
|
+
console.log("Exctacting styled()", styles, out, "to", atomics);
|
|
300
|
+
}
|
|
301
|
+
for (const atomic of atomics) {
|
|
302
|
+
for (const rule of atomic.rules) {
|
|
303
|
+
out.rulesToInsert = out.rulesToInsert || [];
|
|
304
|
+
out.rulesToInsert.push([atomic.identifier, rule]);
|
|
305
|
+
}
|
|
306
|
+
classNames[atomic.property] = atomic.identifier;
|
|
307
|
+
}
|
|
308
|
+
definition.properties = skipped;
|
|
309
|
+
for (const cn in classNames) {
|
|
310
|
+
if (componentSkipProps.has(cn)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const val = classNames[cn];
|
|
314
|
+
definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
|
|
315
|
+
}
|
|
316
|
+
if (out.rulesToInsert) {
|
|
317
|
+
for (const [identifier, rule] of out.rulesToInsert) {
|
|
318
|
+
onStyleRule == null ? void 0 : onStyleRule(identifier, [rule]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
res.styled++;
|
|
322
|
+
if (shouldPrintDebug) {
|
|
323
|
+
console.log(`Extracted styled(${name}) props:`, styles);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
160
326
|
JSXElement(traversePath) {
|
|
161
|
-
var
|
|
327
|
+
var _a2, _b2, _c, _d;
|
|
162
328
|
tm.mark("jsx-element", shouldPrintDebug === "verbose");
|
|
163
329
|
const node = traversePath.node.openingElement;
|
|
164
330
|
const ogAttributes = node.attributes;
|
|
@@ -200,10 +366,7 @@ function createExtractor() {
|
|
|
200
366
|
shouldPrintDebug = debugPropValue;
|
|
201
367
|
}
|
|
202
368
|
try {
|
|
203
|
-
let
|
|
204
|
-
var _a2;
|
|
205
|
-
return !!(!!validStyles[name] || !!pseudos[name] || ((_a2 = staticConfig.variants) == null ? void 0 : _a2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
206
|
-
}, evaluateAttribute = function(path) {
|
|
369
|
+
let evaluateAttribute = function(path) {
|
|
207
370
|
const attribute = path.node;
|
|
208
371
|
const attr = { type: "attr", value: attribute };
|
|
209
372
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
@@ -294,9 +457,9 @@ function createExtractor() {
|
|
|
294
457
|
return [attribute.value, path.get("value")];
|
|
295
458
|
}
|
|
296
459
|
})();
|
|
297
|
-
const remove =
|
|
460
|
+
const remove = () => {
|
|
298
461
|
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
299
|
-
}
|
|
462
|
+
};
|
|
300
463
|
if (name === "ref") {
|
|
301
464
|
if (shouldPrintDebug) {
|
|
302
465
|
console.log(" ! inlining, ref", name);
|
|
@@ -326,29 +489,39 @@ function createExtractor() {
|
|
|
326
489
|
return attr;
|
|
327
490
|
}
|
|
328
491
|
const styleValue = attemptEvalSafe(value);
|
|
329
|
-
if (!isValidStyleKey(name)) {
|
|
492
|
+
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
330
493
|
let keys = [name];
|
|
331
494
|
let out = null;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (out) {
|
|
335
|
-
|
|
336
|
-
|
|
495
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
|
|
496
|
+
if (out) {
|
|
497
|
+
if (!Array.isArray(out)) {
|
|
498
|
+
console.warn(`Error expected array but got`, out);
|
|
499
|
+
couldntParse = true;
|
|
500
|
+
shouldDeopt = true;
|
|
501
|
+
} else {
|
|
502
|
+
out = Object.fromEntries(out);
|
|
337
503
|
keys = Object.keys(out);
|
|
338
504
|
}
|
|
339
505
|
}
|
|
506
|
+
if (out) {
|
|
507
|
+
if (isTargetingHTML) {
|
|
508
|
+
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
509
|
+
delete out.className;
|
|
510
|
+
}
|
|
511
|
+
keys = Object.keys(out);
|
|
512
|
+
}
|
|
340
513
|
let didInline = false;
|
|
341
514
|
const attributes = keys.map((key) => {
|
|
342
515
|
const val = out[key];
|
|
343
|
-
if (isValidStyleKey(key)) {
|
|
516
|
+
if (isValidStyleKey(key, staticConfig)) {
|
|
344
517
|
return {
|
|
345
518
|
type: "style",
|
|
346
|
-
value: { [
|
|
347
|
-
name,
|
|
519
|
+
value: { [key]: styleValue },
|
|
520
|
+
name: key,
|
|
348
521
|
attr: path.node
|
|
349
522
|
};
|
|
350
523
|
}
|
|
351
|
-
if (validHTMLAttributes[key]) {
|
|
524
|
+
if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
352
525
|
return attr;
|
|
353
526
|
}
|
|
354
527
|
if (shouldPrintDebug) {
|
|
@@ -367,7 +540,10 @@ function createExtractor() {
|
|
|
367
540
|
return attributes;
|
|
368
541
|
}
|
|
369
542
|
if (styleValue !== FAILED_EVAL) {
|
|
370
|
-
if (
|
|
543
|
+
if (inlineWhenUnflattened.has(name)) {
|
|
544
|
+
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
545
|
+
}
|
|
546
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
371
547
|
if (shouldPrintDebug) {
|
|
372
548
|
console.log(` style: ${name} =`, styleValue);
|
|
373
549
|
}
|
|
@@ -384,6 +560,9 @@ function createExtractor() {
|
|
|
384
560
|
attr: path.node
|
|
385
561
|
};
|
|
386
562
|
} else {
|
|
563
|
+
if (variants[name]) {
|
|
564
|
+
variantValues.set(name, styleValue);
|
|
565
|
+
}
|
|
387
566
|
inlined.set(name, true);
|
|
388
567
|
return attr;
|
|
389
568
|
}
|
|
@@ -452,7 +631,6 @@ function createExtractor() {
|
|
|
452
631
|
}
|
|
453
632
|
return null;
|
|
454
633
|
}
|
|
455
|
-
__name(addBinaryConditional, "addBinaryConditional");
|
|
456
634
|
function getStaticConditional(value2) {
|
|
457
635
|
if (t.isConditionalExpression(value2)) {
|
|
458
636
|
try {
|
|
@@ -476,7 +654,6 @@ function createExtractor() {
|
|
|
476
654
|
}
|
|
477
655
|
return null;
|
|
478
656
|
}
|
|
479
|
-
__name(getStaticConditional, "getStaticConditional");
|
|
480
657
|
function getStaticLogical(value2) {
|
|
481
658
|
if (t.isLogicalExpression(value2)) {
|
|
482
659
|
if (value2.operator === "&&") {
|
|
@@ -500,7 +677,6 @@ function createExtractor() {
|
|
|
500
677
|
}
|
|
501
678
|
return null;
|
|
502
679
|
}
|
|
503
|
-
__name(getStaticLogical, "getStaticLogical");
|
|
504
680
|
}, isExtractable = function(obj) {
|
|
505
681
|
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
506
682
|
if (!t.isObjectProperty(prop)) {
|
|
@@ -508,7 +684,7 @@ function createExtractor() {
|
|
|
508
684
|
return false;
|
|
509
685
|
}
|
|
510
686
|
const propName = prop.key["name"];
|
|
511
|
-
if (!isValidStyleKey(propName) && propName !== "tag") {
|
|
687
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
512
688
|
if (shouldPrintDebug) {
|
|
513
689
|
console.log(" not a valid style prop!", propName);
|
|
514
690
|
}
|
|
@@ -537,9 +713,7 @@ function createExtractor() {
|
|
|
537
713
|
inlineMediaQuery: mediaQueryKey
|
|
538
714
|
});
|
|
539
715
|
if (ternaries2) {
|
|
540
|
-
return ternaries2.map((value) => ({
|
|
541
|
-
...ternaryPartial,
|
|
542
|
-
...value,
|
|
716
|
+
return ternaries2.map((value) => __spreadProps(__spreadValues(__spreadValues({}, ternaryPartial), value), {
|
|
543
717
|
test: t.logicalExpression("&&", value.test, test)
|
|
544
718
|
}));
|
|
545
719
|
} else {
|
|
@@ -556,39 +730,38 @@ function createExtractor() {
|
|
|
556
730
|
t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
|
|
557
731
|
].map((x) => attemptEval(x));
|
|
558
732
|
return [
|
|
559
|
-
createTernary({
|
|
733
|
+
createTernary(__spreadProps(__spreadValues({
|
|
560
734
|
remove() {
|
|
561
|
-
}
|
|
562
|
-
|
|
735
|
+
}
|
|
736
|
+
}, ternaryPartial), {
|
|
563
737
|
test: t.logicalExpression("&&", test, property.value.test),
|
|
564
738
|
consequent: truthy,
|
|
565
739
|
alternate: null
|
|
566
|
-
}),
|
|
567
|
-
createTernary({
|
|
568
|
-
...ternaryPartial,
|
|
740
|
+
})),
|
|
741
|
+
createTernary(__spreadProps(__spreadValues({}, ternaryPartial), {
|
|
569
742
|
test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
|
|
570
743
|
consequent: falsy,
|
|
571
744
|
alternate: null,
|
|
572
745
|
remove() {
|
|
573
746
|
}
|
|
574
|
-
})
|
|
747
|
+
}))
|
|
575
748
|
];
|
|
576
749
|
}
|
|
577
750
|
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
578
751
|
const consequent = attemptEval(obj);
|
|
579
|
-
return createTernary({
|
|
752
|
+
return createTernary(__spreadProps(__spreadValues({
|
|
580
753
|
remove() {
|
|
581
|
-
}
|
|
582
|
-
|
|
754
|
+
}
|
|
755
|
+
}, ternaryPartial), {
|
|
583
756
|
test,
|
|
584
757
|
consequent,
|
|
585
758
|
alternate: null
|
|
586
|
-
});
|
|
759
|
+
}));
|
|
587
760
|
});
|
|
588
|
-
}, mergeStyles = function(prev2,
|
|
589
|
-
|
|
761
|
+
}, mergeStyles = function(prev2, nextIn) {
|
|
762
|
+
const next = expandStyles(nextIn);
|
|
590
763
|
for (const key in next) {
|
|
591
|
-
if (
|
|
764
|
+
if (pseudoDescriptors[key]) {
|
|
592
765
|
prev2[key] = prev2[key] || {};
|
|
593
766
|
if (shouldPrintDebug) {
|
|
594
767
|
if (!next[key] || !prev2[key]) {
|
|
@@ -600,12 +773,17 @@ function createExtractor() {
|
|
|
600
773
|
prev2[key] = next[key];
|
|
601
774
|
}
|
|
602
775
|
}
|
|
776
|
+
}, omitInvalidStyles = function(style) {
|
|
777
|
+
if (staticConfig.validStyles) {
|
|
778
|
+
for (const key in style) {
|
|
779
|
+
if (stylePropsTransform[key] || !staticConfig.validStyles[key] && !pseudoDescriptors[key] && !/(hoverStyle|focusStyle|pressStyle)$/.test(key)) {
|
|
780
|
+
if (shouldPrintDebug)
|
|
781
|
+
console.log(" delete invalid style", key);
|
|
782
|
+
delete style[key];
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
603
786
|
};
|
|
604
|
-
__name(isValidStyleKey, "isValidStyleKey");
|
|
605
|
-
__name(evaluateAttribute, "evaluateAttribute");
|
|
606
|
-
__name(isExtractable, "isExtractable");
|
|
607
|
-
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
608
|
-
__name(mergeStyles, "mergeStyles");
|
|
609
787
|
node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
|
|
610
788
|
if (shouldPrintDebug) {
|
|
611
789
|
console.log("\n");
|
|
@@ -618,17 +796,19 @@ function createExtractor() {
|
|
|
618
796
|
}
|
|
619
797
|
const shouldLog = !hasLogged;
|
|
620
798
|
if (shouldLog) {
|
|
799
|
+
console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
|
|
621
800
|
const prefix = " |";
|
|
622
|
-
console.log(prefixLogs || prefix, "
|
|
801
|
+
console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
|
|
623
802
|
hasLogged = true;
|
|
624
803
|
}
|
|
625
804
|
if (disableExtraction) {
|
|
626
805
|
return;
|
|
627
806
|
}
|
|
628
807
|
const { staticConfig } = component;
|
|
808
|
+
const variants = staticConfig.variants || {};
|
|
629
809
|
const isTextView = staticConfig.isText || false;
|
|
630
|
-
const validStyles = (
|
|
631
|
-
let tagName =
|
|
810
|
+
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
811
|
+
let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
|
|
632
812
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
633
813
|
const attr = path.node;
|
|
634
814
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -650,6 +830,7 @@ function createExtractor() {
|
|
|
650
830
|
...props.deoptProps || [],
|
|
651
831
|
...staticConfig.deoptProps || []
|
|
652
832
|
]);
|
|
833
|
+
const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
|
|
653
834
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
654
835
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
655
836
|
tamaguiConfig,
|
|
@@ -707,27 +888,12 @@ function createExtractor() {
|
|
|
707
888
|
}
|
|
708
889
|
tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
|
|
709
890
|
node.attributes = flattenedAttrs;
|
|
710
|
-
if (staticConfig.defaultProps) {
|
|
711
|
-
for (const key in staticConfig.defaultProps) {
|
|
712
|
-
if (isValidStyleKey(key)) {
|
|
713
|
-
continue;
|
|
714
|
-
}
|
|
715
|
-
const serialize = require("babel-literal-to-ast");
|
|
716
|
-
const val = staticConfig.defaultProps[key];
|
|
717
|
-
try {
|
|
718
|
-
const serializedDefaultProp = serialize(val);
|
|
719
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
|
|
720
|
-
} catch (err) {
|
|
721
|
-
console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
|
|
722
|
-
error: ${err}
|
|
723
|
-
value:`, val, "\n defaultProps:", staticConfig.defaultProps);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
891
|
let attrs = [];
|
|
728
892
|
let shouldDeopt = false;
|
|
729
893
|
const inlined = /* @__PURE__ */ new Map();
|
|
894
|
+
const variantValues = /* @__PURE__ */ new Map();
|
|
730
895
|
let hasSetOptimized = false;
|
|
896
|
+
const inlineWhenUnflattenedOGVals = {};
|
|
731
897
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
732
898
|
try {
|
|
733
899
|
const res2 = evaluateAttribute(path);
|
|
@@ -741,6 +907,7 @@ function createExtractor() {
|
|
|
741
907
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
742
908
|
console.log("node", path.node);
|
|
743
909
|
}
|
|
910
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
744
911
|
return {
|
|
745
912
|
type: "attr",
|
|
746
913
|
value: path.node
|
|
@@ -769,14 +936,14 @@ function createExtractor() {
|
|
|
769
936
|
ternaries.push(cur.value);
|
|
770
937
|
}
|
|
771
938
|
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
772
|
-
const normalized = normalizeTernaries(ternaries).map((
|
|
939
|
+
const normalized = normalizeTernaries(ternaries).map((_a3) => {
|
|
940
|
+
var _b3 = _a3, { alternate, consequent } = _b3, rest = __objRest(_b3, ["alternate", "consequent"]);
|
|
773
941
|
return {
|
|
774
942
|
type: "ternary",
|
|
775
|
-
value: {
|
|
776
|
-
...rest,
|
|
943
|
+
value: __spreadProps(__spreadValues({}, rest), {
|
|
777
944
|
alternate: alternate || null,
|
|
778
945
|
consequent: consequent || null
|
|
779
|
-
}
|
|
946
|
+
})
|
|
780
947
|
};
|
|
781
948
|
});
|
|
782
949
|
try {
|
|
@@ -796,18 +963,30 @@ function createExtractor() {
|
|
|
796
963
|
}, []).flat();
|
|
797
964
|
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
798
965
|
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
799
|
-
|
|
966
|
+
const themeVal = inlined.get("theme");
|
|
800
967
|
inlined.delete("theme");
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
968
|
+
for (const [key] of [...inlined]) {
|
|
969
|
+
if (INLINE_EXTRACTABLE[key] || ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key])) {
|
|
970
|
+
inlined.delete(key);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
const canFlattenProps = inlined.size === 0;
|
|
804
974
|
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
975
|
+
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
976
|
+
if (disableExtractVariables) {
|
|
977
|
+
themeAccessListeners.add((key) => {
|
|
978
|
+
shouldFlatten = false;
|
|
979
|
+
if (shouldPrintDebug) {
|
|
980
|
+
console.log(" ! accessing theme key, avoid flatten", key);
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
805
984
|
if (shouldPrintDebug) {
|
|
806
|
-
console.log(" - flatten?", objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps,
|
|
985
|
+
console.log(" - flatten?", objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
|
|
807
986
|
}
|
|
808
|
-
if (shouldFlatten &&
|
|
987
|
+
if (shouldFlatten && shouldWrapTheme) {
|
|
809
988
|
if (shouldPrintDebug) {
|
|
810
|
-
console.log(" - wrapping theme",
|
|
989
|
+
console.log(" - wrapping theme", themeVal);
|
|
811
990
|
}
|
|
812
991
|
attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
|
|
813
992
|
if (!hasImportedTheme) {
|
|
@@ -818,9 +997,9 @@ function createExtractor() {
|
|
|
818
997
|
t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
|
|
819
998
|
]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
820
999
|
}
|
|
821
|
-
if (shouldFlatten
|
|
1000
|
+
if (shouldFlatten) {
|
|
822
1001
|
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
823
|
-
if (!isValidStyleKey(key)) {
|
|
1002
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
824
1003
|
return [];
|
|
825
1004
|
}
|
|
826
1005
|
const value = staticConfig.defaultProps[key];
|
|
@@ -850,10 +1029,10 @@ function createExtractor() {
|
|
|
850
1029
|
for (const cur of attrs) {
|
|
851
1030
|
if (cur.type === "style") {
|
|
852
1031
|
for (const key in cur.value) {
|
|
853
|
-
const shouldEnsureOverridden = !!((
|
|
1032
|
+
const shouldEnsureOverridden = !!((_b2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _b2[key]);
|
|
854
1033
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
855
1034
|
if (!isSetInAttrsAlready) {
|
|
856
|
-
const isVariant = !!((
|
|
1035
|
+
const isVariant = !!((_c = staticConfig.variants) == null ? void 0 : _c[cur.name || ""]);
|
|
857
1036
|
if (isVariant || shouldEnsureOverridden) {
|
|
858
1037
|
ensureOverridden[key] = true;
|
|
859
1038
|
}
|
|
@@ -866,14 +1045,83 @@ function createExtractor() {
|
|
|
866
1045
|
console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
867
1046
|
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
868
1047
|
}
|
|
1048
|
+
const state = {
|
|
1049
|
+
noClassNames: false,
|
|
1050
|
+
focus: false,
|
|
1051
|
+
hover: false,
|
|
1052
|
+
mounted: true,
|
|
1053
|
+
press: false,
|
|
1054
|
+
pressIn: false
|
|
1055
|
+
};
|
|
1056
|
+
let foundStaticProps = {};
|
|
1057
|
+
for (const key in attrs) {
|
|
1058
|
+
const cur = attrs[key];
|
|
1059
|
+
if (cur.type === "style") {
|
|
1060
|
+
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), expandStyles(cur.value));
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
if (cur.type === "attr") {
|
|
1064
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
const key2 = cur.value.name.name;
|
|
1071
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1072
|
+
if (value !== FAILED_EVAL) {
|
|
1073
|
+
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1074
|
+
[key2]: value
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
const completeProps = {};
|
|
1080
|
+
for (const key in staticConfig.defaultProps) {
|
|
1081
|
+
if (!(key in foundStaticProps)) {
|
|
1082
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
for (const key in foundStaticProps) {
|
|
1086
|
+
completeProps[key] = foundStaticProps[key];
|
|
1087
|
+
}
|
|
869
1088
|
attrs = attrs.reduce((acc, cur) => {
|
|
870
|
-
if (!cur)
|
|
1089
|
+
if (!cur)
|
|
871
1090
|
return acc;
|
|
872
|
-
}
|
|
873
1091
|
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
874
1092
|
if (shouldFlatten) {
|
|
875
|
-
|
|
876
|
-
|
|
1093
|
+
const name = cur.value.name.name;
|
|
1094
|
+
if (typeof name === "string") {
|
|
1095
|
+
if (name === "tag") {
|
|
1096
|
+
return acc;
|
|
1097
|
+
}
|
|
1098
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1099
|
+
let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, __spreadProps(__spreadValues({}, state), { resolveVariablesAs: "auto" }), void 0, shouldPrintDebug) || []);
|
|
1100
|
+
if (out && isTargetingHTML) {
|
|
1101
|
+
const cn = out.className;
|
|
1102
|
+
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
1103
|
+
out.className = cn;
|
|
1104
|
+
}
|
|
1105
|
+
if (shouldPrintDebug) {
|
|
1106
|
+
console.log(" - expanded variant", name, out);
|
|
1107
|
+
}
|
|
1108
|
+
for (const key2 in out) {
|
|
1109
|
+
const value2 = out[key2];
|
|
1110
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1111
|
+
acc.push({
|
|
1112
|
+
type: "style",
|
|
1113
|
+
value: { [key2]: value2 },
|
|
1114
|
+
name: key2,
|
|
1115
|
+
attr: cur.value
|
|
1116
|
+
});
|
|
1117
|
+
} else {
|
|
1118
|
+
acc.push({
|
|
1119
|
+
type: "attr",
|
|
1120
|
+
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)))
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
877
1125
|
}
|
|
878
1126
|
}
|
|
879
1127
|
}
|
|
@@ -912,7 +1160,7 @@ function createExtractor() {
|
|
|
912
1160
|
if (cur.type === "style") {
|
|
913
1161
|
const key = Object.keys(cur.value)[0];
|
|
914
1162
|
const value = cur.value[key];
|
|
915
|
-
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !
|
|
1163
|
+
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudoDescriptors[key] && !key.startsWith("data-");
|
|
916
1164
|
if (shouldKeepOriginalAttr) {
|
|
917
1165
|
if (shouldPrintDebug) {
|
|
918
1166
|
console.log(" - keeping as non-style", key);
|
|
@@ -940,46 +1188,13 @@ function createExtractor() {
|
|
|
940
1188
|
acc.push(cur);
|
|
941
1189
|
return acc;
|
|
942
1190
|
}, []);
|
|
943
|
-
const state = {
|
|
944
|
-
noClassNames: true,
|
|
945
|
-
focus: false,
|
|
946
|
-
hover: false,
|
|
947
|
-
mounted: true,
|
|
948
|
-
press: false,
|
|
949
|
-
pressIn: false
|
|
950
|
-
};
|
|
951
|
-
const completeStaticProps = Object.keys(attrs).reduce((acc, index) => {
|
|
952
|
-
const cur = attrs[index];
|
|
953
|
-
if (cur.type === "style") {
|
|
954
|
-
normalizeStyleObject(cur.value);
|
|
955
|
-
Object.assign(acc, cur.value);
|
|
956
|
-
}
|
|
957
|
-
if (cur.type === "attr") {
|
|
958
|
-
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
959
|
-
return acc;
|
|
960
|
-
}
|
|
961
|
-
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
962
|
-
return acc;
|
|
963
|
-
}
|
|
964
|
-
const key = cur.value.name.name;
|
|
965
|
-
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
966
|
-
if (value === FAILED_EVAL) {
|
|
967
|
-
return acc;
|
|
968
|
-
}
|
|
969
|
-
acc[key] = value;
|
|
970
|
-
}
|
|
971
|
-
return acc;
|
|
972
|
-
}, {});
|
|
973
|
-
const completeProps = {
|
|
974
|
-
...staticConfig.defaultProps,
|
|
975
|
-
...completeStaticProps
|
|
976
|
-
};
|
|
977
1191
|
if (shouldPrintDebug) {
|
|
978
1192
|
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
979
1193
|
console.log(" - defaultProps: \n", logLines(objToStr(staticConfig.defaultProps)));
|
|
980
|
-
console.log(" -
|
|
1194
|
+
console.log(" - foundStaticProps: \n", logLines(objToStr(foundStaticProps)));
|
|
1195
|
+
console.log(" - completeProps: \n", logLines(objToStr(completeProps)));
|
|
981
1196
|
}
|
|
982
|
-
const getStyles =
|
|
1197
|
+
const getStyles = (props2, debugName = "") => {
|
|
983
1198
|
if (!props2 || !Object.keys(props2).length) {
|
|
984
1199
|
if (shouldPrintDebug)
|
|
985
1200
|
console.log(" getStyles() no props");
|
|
@@ -995,44 +1210,23 @@ function createExtractor() {
|
|
|
995
1210
|
}
|
|
996
1211
|
}
|
|
997
1212
|
try {
|
|
998
|
-
const out = getSplitStyles(props2, staticConfig, defaultTheme, {
|
|
999
|
-
...state,
|
|
1213
|
+
const out = getSplitStyles(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
|
|
1000
1214
|
fallbackProps: completeProps
|
|
1001
|
-
});
|
|
1002
|
-
const outStyle = {
|
|
1003
|
-
...out.style,
|
|
1004
|
-
...out.pseudos
|
|
1005
|
-
};
|
|
1006
|
-
if (staticConfig.validStyles) {
|
|
1007
|
-
for (const key in outStyle) {
|
|
1008
|
-
if (!staticConfig.validStyles[key] && !pseudos[key] && !/(hover|focus|press)Style$/.test(key)) {
|
|
1009
|
-
if (shouldPrintDebug)
|
|
1010
|
-
console.log(" delete invalid style", key);
|
|
1011
|
-
delete outStyle[key];
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
if (shouldPrintDebug) {
|
|
1016
|
-
console.log(` getStyles ${debugName} (props):
|
|
1017
|
-
`, logLines(objToStr(props2)));
|
|
1018
|
-
console.log(` getStyles ${debugName} (out.viewProps):
|
|
1019
|
-
`, logLines(objToStr(out.viewProps)));
|
|
1020
|
-
console.log(` getStyles ${debugName} (out.style):
|
|
1021
|
-
`, logLines(objToStr(outStyle || {}), true));
|
|
1022
|
-
}
|
|
1215
|
+
}), void 0, props2["debug"]);
|
|
1216
|
+
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
1023
1217
|
return outStyle;
|
|
1024
1218
|
} catch (err) {
|
|
1025
1219
|
console.log("error", err.message, err.stack);
|
|
1026
1220
|
return {};
|
|
1027
1221
|
}
|
|
1028
|
-
}
|
|
1029
|
-
const
|
|
1030
|
-
if (!
|
|
1222
|
+
};
|
|
1223
|
+
const completeStyles = getStyles(completeProps, "completeStyles");
|
|
1224
|
+
if (!completeStyles) {
|
|
1031
1225
|
throw new Error(`Impossible, no styles`);
|
|
1032
1226
|
}
|
|
1033
|
-
const
|
|
1034
|
-
if (
|
|
1035
|
-
const toAdd = pick(
|
|
1227
|
+
const addInitialStyleKeys = shouldFlatten ? difference(Object.keys(completeStyles), Object.keys(foundStaticProps)) : [];
|
|
1228
|
+
if (addInitialStyleKeys.length) {
|
|
1229
|
+
const toAdd = pick(completeStyles, ...addInitialStyleKeys);
|
|
1036
1230
|
const firstGroup = attrs.find((x) => x.type === "style");
|
|
1037
1231
|
if (shouldPrintDebug) {
|
|
1038
1232
|
console.log(" toAdd", objToStr(toAdd));
|
|
@@ -1040,19 +1234,17 @@ function createExtractor() {
|
|
|
1040
1234
|
if (!firstGroup) {
|
|
1041
1235
|
attrs.unshift({ type: "style", value: toAdd });
|
|
1042
1236
|
} else {
|
|
1237
|
+
omitInvalidStyles(firstGroup.value);
|
|
1043
1238
|
Object.assign(firstGroup.value, toAdd);
|
|
1044
1239
|
}
|
|
1045
1240
|
}
|
|
1046
1241
|
if (shouldPrintDebug) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
|
|
1242
|
+
if (shouldFlatten)
|
|
1243
|
+
console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "));
|
|
1050
1244
|
}
|
|
1051
1245
|
let getStyleError = null;
|
|
1052
1246
|
for (const attr of attrs) {
|
|
1053
1247
|
try {
|
|
1054
|
-
if (shouldPrintDebug)
|
|
1055
|
-
console.log(" *", attrStr(attr));
|
|
1056
1248
|
switch (attr.type) {
|
|
1057
1249
|
case "ternary":
|
|
1058
1250
|
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
@@ -1065,20 +1257,23 @@ function createExtractor() {
|
|
|
1065
1257
|
console.log(" => tern ", attrStr(attr));
|
|
1066
1258
|
continue;
|
|
1067
1259
|
case "style":
|
|
1068
|
-
if (shouldPrintDebug)
|
|
1069
|
-
console.log(" * styles in", logLines(objToStr(attr.value)));
|
|
1070
1260
|
const styles = getStyles(attr.value, "style");
|
|
1071
|
-
if (shouldPrintDebug)
|
|
1072
|
-
console.log(" * styles out", logLines(objToStr(styles)));
|
|
1073
1261
|
if (styles) {
|
|
1074
|
-
attr.value =
|
|
1262
|
+
attr.value = styles;
|
|
1075
1263
|
}
|
|
1264
|
+
if (shouldPrintDebug)
|
|
1265
|
+
console.log(" * styles (in)", logLines(objToStr(attr.value)));
|
|
1266
|
+
if (shouldPrintDebug)
|
|
1267
|
+
console.log(" * styles (out)", logLines(objToStr(styles)));
|
|
1076
1268
|
continue;
|
|
1077
1269
|
}
|
|
1078
1270
|
} catch (err) {
|
|
1079
1271
|
getStyleError = err;
|
|
1080
1272
|
}
|
|
1081
1273
|
}
|
|
1274
|
+
if (shouldPrintDebug) {
|
|
1275
|
+
console.log(" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
1276
|
+
}
|
|
1082
1277
|
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1083
1278
|
if (getStyleError) {
|
|
1084
1279
|
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
@@ -1088,7 +1283,7 @@ function createExtractor() {
|
|
|
1088
1283
|
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1089
1284
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1090
1285
|
const attr = attrs[i];
|
|
1091
|
-
if (shouldFlatten
|
|
1286
|
+
if (shouldFlatten) {
|
|
1092
1287
|
if (attr.type === "attr") {
|
|
1093
1288
|
if (t.isJSXAttribute(attr.value)) {
|
|
1094
1289
|
if (t.isJSXIdentifier(attr.value.name)) {
|
|
@@ -1096,6 +1291,9 @@ function createExtractor() {
|
|
|
1096
1291
|
if (INLINE_EXTRACTABLE[name]) {
|
|
1097
1292
|
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1098
1293
|
}
|
|
1294
|
+
if ((_d = staticConfig.variants) == null ? void 0 : _d[name]) {
|
|
1295
|
+
const expanded = getStyles({});
|
|
1296
|
+
}
|
|
1099
1297
|
}
|
|
1100
1298
|
}
|
|
1101
1299
|
}
|
|
@@ -1113,6 +1311,21 @@ function createExtractor() {
|
|
|
1113
1311
|
}
|
|
1114
1312
|
}
|
|
1115
1313
|
}
|
|
1314
|
+
if (!shouldFlatten) {
|
|
1315
|
+
if (Object.keys(inlineWhenUnflattenedOGVals).length) {
|
|
1316
|
+
for (const [index, attr] of attrs.entries()) {
|
|
1317
|
+
if (attr.type === "style") {
|
|
1318
|
+
for (const key in attr.value) {
|
|
1319
|
+
const val = inlineWhenUnflattenedOGVals[key];
|
|
1320
|
+
if (val) {
|
|
1321
|
+
delete attr.value[key];
|
|
1322
|
+
attrs.splice(index - 1, 0, val.attr);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1116
1329
|
if (shouldFlatten) {
|
|
1117
1330
|
if (shouldPrintDebug) {
|
|
1118
1331
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
@@ -1138,8 +1351,6 @@ function createExtractor() {
|
|
|
1138
1351
|
isFlattened: shouldFlatten,
|
|
1139
1352
|
programPath
|
|
1140
1353
|
});
|
|
1141
|
-
} catch (err) {
|
|
1142
|
-
throw err;
|
|
1143
1354
|
} finally {
|
|
1144
1355
|
if (debugPropValue) {
|
|
1145
1356
|
shouldPrintDebug = ogDebug;
|
|
@@ -1162,7 +1373,6 @@ function createExtractor() {
|
|
|
1162
1373
|
}
|
|
1163
1374
|
};
|
|
1164
1375
|
}
|
|
1165
|
-
__name(createExtractor, "createExtractor");
|
|
1166
1376
|
export {
|
|
1167
1377
|
createExtractor
|
|
1168
1378
|
};
|