@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
|
@@ -21,7 +21,6 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
24
|
var __objRest = (source, exclude) => {
|
|
26
25
|
var target = {};
|
|
27
26
|
for (var prop in source)
|
|
@@ -85,12 +84,12 @@ const INLINE_EXTRACTABLE = {
|
|
|
85
84
|
onPressIn: "onMouseDown",
|
|
86
85
|
onPressOut: "onMouseUp"
|
|
87
86
|
};
|
|
88
|
-
const isAttr =
|
|
87
|
+
const isAttr = (x) => x.type === "attr";
|
|
89
88
|
const validHooks = {
|
|
90
89
|
useMedia: true,
|
|
91
90
|
useTheme: true
|
|
92
91
|
};
|
|
93
|
-
const createTernary =
|
|
92
|
+
const createTernary = (x) => x;
|
|
94
93
|
function createExtractor() {
|
|
95
94
|
if (!process.env.TAMAGUI_TARGET) {
|
|
96
95
|
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
@@ -99,6 +98,10 @@ function createExtractor() {
|
|
|
99
98
|
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);
|
|
100
99
|
let loadedTamaguiConfig;
|
|
101
100
|
let hasLogged = false;
|
|
101
|
+
function isValidStyleKey(name, staticConfig) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!import_core_node.pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
104
|
+
}
|
|
102
105
|
return {
|
|
103
106
|
getTamagui() {
|
|
104
107
|
return loadedTamaguiConfig;
|
|
@@ -111,14 +114,17 @@ function createExtractor() {
|
|
|
111
114
|
shouldPrintDebug = false,
|
|
112
115
|
sourcePath = "",
|
|
113
116
|
onExtractTag,
|
|
117
|
+
onStyleRule,
|
|
114
118
|
getFlattenedNode,
|
|
115
119
|
disable,
|
|
116
120
|
disableExtraction,
|
|
117
121
|
disableExtractInlineMedia,
|
|
118
122
|
disableExtractVariables,
|
|
119
123
|
disableDebugAttr,
|
|
124
|
+
extractStyledDefinitions = false,
|
|
120
125
|
prefixLogs,
|
|
121
|
-
excludeProps
|
|
126
|
+
excludeProps,
|
|
127
|
+
target
|
|
122
128
|
} = _b, props = __objRest(_b, [
|
|
123
129
|
"config",
|
|
124
130
|
"importsWhitelist",
|
|
@@ -126,14 +132,17 @@ function createExtractor() {
|
|
|
126
132
|
"shouldPrintDebug",
|
|
127
133
|
"sourcePath",
|
|
128
134
|
"onExtractTag",
|
|
135
|
+
"onStyleRule",
|
|
129
136
|
"getFlattenedNode",
|
|
130
137
|
"disable",
|
|
131
138
|
"disableExtraction",
|
|
132
139
|
"disableExtractInlineMedia",
|
|
133
140
|
"disableExtractVariables",
|
|
134
141
|
"disableDebugAttr",
|
|
142
|
+
"extractStyledDefinitions",
|
|
135
143
|
"prefixLogs",
|
|
136
|
-
"excludeProps"
|
|
144
|
+
"excludeProps",
|
|
145
|
+
"target"
|
|
137
146
|
]);
|
|
138
147
|
if (disable) {
|
|
139
148
|
return null;
|
|
@@ -144,6 +153,7 @@ function createExtractor() {
|
|
|
144
153
|
if (!Array.isArray(props.components)) {
|
|
145
154
|
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
146
155
|
}
|
|
156
|
+
const isTargetingHTML = target === "html";
|
|
147
157
|
const ogDebug = shouldPrintDebug;
|
|
148
158
|
const tm = (0, import_timer.timer)();
|
|
149
159
|
const { components, tamaguiConfig } = (0, import_loadTamagui.loadTamagui)({
|
|
@@ -155,11 +165,20 @@ function createExtractor() {
|
|
|
155
165
|
}
|
|
156
166
|
tm.mark("load-tamagui", shouldPrintDebug === "verbose");
|
|
157
167
|
loadedTamaguiConfig = tamaguiConfig;
|
|
158
|
-
const
|
|
168
|
+
const proxiedTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
|
|
169
|
+
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
170
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
171
|
+
get(target2, key) {
|
|
172
|
+
if (key[0] === "$") {
|
|
173
|
+
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
174
|
+
}
|
|
175
|
+
return Reflect.get(target2, key);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
159
178
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
160
|
-
const isInternalImport =
|
|
179
|
+
const isInternalImport = (importStr) => {
|
|
161
180
|
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
162
|
-
}
|
|
181
|
+
};
|
|
163
182
|
const validComponents = Object.keys(components).filter((key) => {
|
|
164
183
|
var _a2;
|
|
165
184
|
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
@@ -177,11 +196,21 @@ function createExtractor() {
|
|
|
177
196
|
continue;
|
|
178
197
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
179
198
|
const from = node.source.value;
|
|
199
|
+
if (extractStyledDefinitions) {
|
|
200
|
+
if (from === "@tamagui/core" || from === "tamagui") {
|
|
201
|
+
if (node.specifiers.some((specifier) => {
|
|
202
|
+
return specifier.local.name === "styled";
|
|
203
|
+
})) {
|
|
204
|
+
doesUseValidImport = true;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
180
209
|
const isValidImport = props.components.includes(from) || isInternalImport(from);
|
|
181
210
|
if (isValidImport) {
|
|
182
211
|
const isValidComponent = node.specifiers.some((specifier) => {
|
|
183
212
|
const name = specifier.local.name;
|
|
184
|
-
return validComponents[name] || validHooks[name];
|
|
213
|
+
return !!(validComponents[name] || validHooks[name]);
|
|
185
214
|
});
|
|
186
215
|
if (shouldPrintDebug === "verbose") {
|
|
187
216
|
console.log("import from", from, { isValidComponent });
|
|
@@ -202,11 +231,12 @@ function createExtractor() {
|
|
|
202
231
|
let couldntParse = false;
|
|
203
232
|
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
204
233
|
const bindingCache = {};
|
|
205
|
-
const callTraverse =
|
|
234
|
+
const callTraverse = (a) => {
|
|
206
235
|
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
207
|
-
}
|
|
236
|
+
};
|
|
208
237
|
let programPath;
|
|
209
238
|
const res = {
|
|
239
|
+
styled: 0,
|
|
210
240
|
flattened: 0,
|
|
211
241
|
optimized: 0,
|
|
212
242
|
modified: 0,
|
|
@@ -218,8 +248,97 @@ function createExtractor() {
|
|
|
218
248
|
programPath = path;
|
|
219
249
|
}
|
|
220
250
|
},
|
|
251
|
+
CallExpression(path) {
|
|
252
|
+
var _a2;
|
|
253
|
+
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
260
|
+
const definition = path.node.arguments[1];
|
|
261
|
+
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const Component = validComponents[name];
|
|
265
|
+
if (!Component) {
|
|
266
|
+
if (shouldPrintDebug) {
|
|
267
|
+
console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
|
|
268
|
+
}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
272
|
+
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
273
|
+
...Component.staticConfig.inlineProps || [],
|
|
274
|
+
...Component.staticConfig.deoptProps || [],
|
|
275
|
+
"variants",
|
|
276
|
+
"defaultVariants",
|
|
277
|
+
"fontFamily",
|
|
278
|
+
"name"
|
|
279
|
+
]);
|
|
280
|
+
const skipped = [];
|
|
281
|
+
const styles = {};
|
|
282
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
283
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
284
|
+
tamaguiConfig,
|
|
285
|
+
staticNamespace,
|
|
286
|
+
sourcePath,
|
|
287
|
+
shouldPrintDebug
|
|
288
|
+
});
|
|
289
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
290
|
+
for (const property of definition.properties) {
|
|
291
|
+
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)) {
|
|
292
|
+
skipped.push(property);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const out2 = attemptEvalSafe(property.value);
|
|
296
|
+
if (out2 === import_constants.FAILED_EVAL) {
|
|
297
|
+
skipped.push(property);
|
|
298
|
+
} else {
|
|
299
|
+
styles[property.key.name] = out2;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const out = (0, import_core_node.getSplitStyles)(styles, Component.staticConfig, defaultTheme, {
|
|
303
|
+
focus: false,
|
|
304
|
+
hover: false,
|
|
305
|
+
mounted: false,
|
|
306
|
+
press: false,
|
|
307
|
+
pressIn: false,
|
|
308
|
+
resolveVariablesAs: "variable"
|
|
309
|
+
});
|
|
310
|
+
const classNames = __spreadValues({}, out.classNames);
|
|
311
|
+
const atomics = (0, import_core_node.getStylesAtomic)(out.style);
|
|
312
|
+
if (shouldPrintDebug) {
|
|
313
|
+
console.log("Exctacting styled()", styles, out, "to", atomics);
|
|
314
|
+
}
|
|
315
|
+
for (const atomic of atomics) {
|
|
316
|
+
for (const rule of atomic.rules) {
|
|
317
|
+
out.rulesToInsert = out.rulesToInsert || [];
|
|
318
|
+
out.rulesToInsert.push([atomic.identifier, rule]);
|
|
319
|
+
}
|
|
320
|
+
classNames[atomic.property] = atomic.identifier;
|
|
321
|
+
}
|
|
322
|
+
definition.properties = skipped;
|
|
323
|
+
for (const cn in classNames) {
|
|
324
|
+
if (componentSkipProps.has(cn)) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const val = classNames[cn];
|
|
328
|
+
definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
|
|
329
|
+
}
|
|
330
|
+
if (out.rulesToInsert) {
|
|
331
|
+
for (const [identifier, rule] of out.rulesToInsert) {
|
|
332
|
+
onStyleRule == null ? void 0 : onStyleRule(identifier, [rule]);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
res.styled++;
|
|
336
|
+
if (shouldPrintDebug) {
|
|
337
|
+
console.log(`Extracted styled(${name}) props:`, styles);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
221
340
|
JSXElement(traversePath) {
|
|
222
|
-
var _a2, _b2, _c;
|
|
341
|
+
var _a2, _b2, _c, _d;
|
|
223
342
|
tm.mark("jsx-element", shouldPrintDebug === "verbose");
|
|
224
343
|
const node = traversePath.node.openingElement;
|
|
225
344
|
const ogAttributes = node.attributes;
|
|
@@ -261,10 +380,7 @@ function createExtractor() {
|
|
|
261
380
|
shouldPrintDebug = debugPropValue;
|
|
262
381
|
}
|
|
263
382
|
try {
|
|
264
|
-
let
|
|
265
|
-
var _a3;
|
|
266
|
-
return !!(!!validStyles[name] || !!import_core_node.pseudos[name] || ((_a3 = staticConfig.variants) == null ? void 0 : _a3[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
267
|
-
}, evaluateAttribute = function(path) {
|
|
383
|
+
let evaluateAttribute = function(path) {
|
|
268
384
|
const attribute = path.node;
|
|
269
385
|
const attr = { type: "attr", value: attribute };
|
|
270
386
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
@@ -355,9 +471,9 @@ function createExtractor() {
|
|
|
355
471
|
return [attribute.value, path.get("value")];
|
|
356
472
|
}
|
|
357
473
|
})();
|
|
358
|
-
const remove =
|
|
474
|
+
const remove = () => {
|
|
359
475
|
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
360
|
-
}
|
|
476
|
+
};
|
|
361
477
|
if (name === "ref") {
|
|
362
478
|
if (shouldPrintDebug) {
|
|
363
479
|
console.log(" ! inlining, ref", name);
|
|
@@ -387,29 +503,39 @@ function createExtractor() {
|
|
|
387
503
|
return attr;
|
|
388
504
|
}
|
|
389
505
|
const styleValue = attemptEvalSafe(value);
|
|
390
|
-
if (!isValidStyleKey(name)) {
|
|
506
|
+
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
391
507
|
let keys = [name];
|
|
392
508
|
let out = null;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (out) {
|
|
396
|
-
|
|
397
|
-
|
|
509
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
|
|
510
|
+
if (out) {
|
|
511
|
+
if (!Array.isArray(out)) {
|
|
512
|
+
console.warn(`Error expected array but got`, out);
|
|
513
|
+
couldntParse = true;
|
|
514
|
+
shouldDeopt = true;
|
|
515
|
+
} else {
|
|
516
|
+
out = Object.fromEntries(out);
|
|
398
517
|
keys = Object.keys(out);
|
|
399
518
|
}
|
|
400
519
|
}
|
|
520
|
+
if (out) {
|
|
521
|
+
if (isTargetingHTML) {
|
|
522
|
+
out = (0, import_core_node.createDOMProps)(isTextView ? "span" : "div", out);
|
|
523
|
+
delete out.className;
|
|
524
|
+
}
|
|
525
|
+
keys = Object.keys(out);
|
|
526
|
+
}
|
|
401
527
|
let didInline = false;
|
|
402
528
|
const attributes = keys.map((key) => {
|
|
403
529
|
const val = out[key];
|
|
404
|
-
if (isValidStyleKey(key)) {
|
|
530
|
+
if (isValidStyleKey(key, staticConfig)) {
|
|
405
531
|
return {
|
|
406
532
|
type: "style",
|
|
407
|
-
value: { [
|
|
408
|
-
name,
|
|
533
|
+
value: { [key]: styleValue },
|
|
534
|
+
name: key,
|
|
409
535
|
attr: path.node
|
|
410
536
|
};
|
|
411
537
|
}
|
|
412
|
-
if (import_validHTMLAttributes.validHTMLAttributes[key]) {
|
|
538
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
413
539
|
return attr;
|
|
414
540
|
}
|
|
415
541
|
if (shouldPrintDebug) {
|
|
@@ -428,7 +554,10 @@ function createExtractor() {
|
|
|
428
554
|
return attributes;
|
|
429
555
|
}
|
|
430
556
|
if (styleValue !== import_constants.FAILED_EVAL) {
|
|
431
|
-
if (
|
|
557
|
+
if (inlineWhenUnflattened.has(name)) {
|
|
558
|
+
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
559
|
+
}
|
|
560
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
432
561
|
if (shouldPrintDebug) {
|
|
433
562
|
console.log(` style: ${name} =`, styleValue);
|
|
434
563
|
}
|
|
@@ -445,6 +574,9 @@ function createExtractor() {
|
|
|
445
574
|
attr: path.node
|
|
446
575
|
};
|
|
447
576
|
} else {
|
|
577
|
+
if (variants[name]) {
|
|
578
|
+
variantValues.set(name, styleValue);
|
|
579
|
+
}
|
|
448
580
|
inlined.set(name, true);
|
|
449
581
|
return attr;
|
|
450
582
|
}
|
|
@@ -513,7 +645,6 @@ function createExtractor() {
|
|
|
513
645
|
}
|
|
514
646
|
return null;
|
|
515
647
|
}
|
|
516
|
-
__name(addBinaryConditional, "addBinaryConditional");
|
|
517
648
|
function getStaticConditional(value2) {
|
|
518
649
|
if (t.isConditionalExpression(value2)) {
|
|
519
650
|
try {
|
|
@@ -537,7 +668,6 @@ function createExtractor() {
|
|
|
537
668
|
}
|
|
538
669
|
return null;
|
|
539
670
|
}
|
|
540
|
-
__name(getStaticConditional, "getStaticConditional");
|
|
541
671
|
function getStaticLogical(value2) {
|
|
542
672
|
if (t.isLogicalExpression(value2)) {
|
|
543
673
|
if (value2.operator === "&&") {
|
|
@@ -561,7 +691,6 @@ function createExtractor() {
|
|
|
561
691
|
}
|
|
562
692
|
return null;
|
|
563
693
|
}
|
|
564
|
-
__name(getStaticLogical, "getStaticLogical");
|
|
565
694
|
}, isExtractable = function(obj) {
|
|
566
695
|
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
567
696
|
if (!t.isObjectProperty(prop)) {
|
|
@@ -569,7 +698,7 @@ function createExtractor() {
|
|
|
569
698
|
return false;
|
|
570
699
|
}
|
|
571
700
|
const propName = prop.key["name"];
|
|
572
|
-
if (!isValidStyleKey(propName) && propName !== "tag") {
|
|
701
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
573
702
|
if (shouldPrintDebug) {
|
|
574
703
|
console.log(" not a valid style prop!", propName);
|
|
575
704
|
}
|
|
@@ -643,10 +772,10 @@ function createExtractor() {
|
|
|
643
772
|
alternate: null
|
|
644
773
|
}));
|
|
645
774
|
});
|
|
646
|
-
}, mergeStyles = function(prev2,
|
|
647
|
-
(0, import_core_node.
|
|
775
|
+
}, mergeStyles = function(prev2, nextIn) {
|
|
776
|
+
const next = (0, import_core_node.expandStyles)(nextIn);
|
|
648
777
|
for (const key in next) {
|
|
649
|
-
if (import_core_node.
|
|
778
|
+
if (import_core_node.pseudoDescriptors[key]) {
|
|
650
779
|
prev2[key] = prev2[key] || {};
|
|
651
780
|
if (shouldPrintDebug) {
|
|
652
781
|
if (!next[key] || !prev2[key]) {
|
|
@@ -658,12 +787,17 @@ function createExtractor() {
|
|
|
658
787
|
prev2[key] = next[key];
|
|
659
788
|
}
|
|
660
789
|
}
|
|
790
|
+
}, omitInvalidStyles = function(style) {
|
|
791
|
+
if (staticConfig.validStyles) {
|
|
792
|
+
for (const key in style) {
|
|
793
|
+
if (import_core_node.stylePropsTransform[key] || !staticConfig.validStyles[key] && !import_core_node.pseudoDescriptors[key] && !/(hoverStyle|focusStyle|pressStyle)$/.test(key)) {
|
|
794
|
+
if (shouldPrintDebug)
|
|
795
|
+
console.log(" delete invalid style", key);
|
|
796
|
+
delete style[key];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
661
800
|
};
|
|
662
|
-
__name(isValidStyleKey, "isValidStyleKey");
|
|
663
|
-
__name(evaluateAttribute, "evaluateAttribute");
|
|
664
|
-
__name(isExtractable, "isExtractable");
|
|
665
|
-
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
666
|
-
__name(mergeStyles, "mergeStyles");
|
|
667
801
|
node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
|
|
668
802
|
if (shouldPrintDebug) {
|
|
669
803
|
console.log("\n");
|
|
@@ -676,17 +810,19 @@ function createExtractor() {
|
|
|
676
810
|
}
|
|
677
811
|
const shouldLog = !hasLogged;
|
|
678
812
|
if (shouldLog) {
|
|
813
|
+
console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
|
|
679
814
|
const prefix = " |";
|
|
680
|
-
console.log(prefixLogs || prefix, "
|
|
815
|
+
console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
|
|
681
816
|
hasLogged = true;
|
|
682
817
|
}
|
|
683
818
|
if (disableExtraction) {
|
|
684
819
|
return;
|
|
685
820
|
}
|
|
686
821
|
const { staticConfig } = component;
|
|
822
|
+
const variants = staticConfig.variants || {};
|
|
687
823
|
const isTextView = staticConfig.isText || false;
|
|
688
824
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
689
|
-
let tagName =
|
|
825
|
+
let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
|
|
690
826
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
691
827
|
const attr = path.node;
|
|
692
828
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -708,6 +844,7 @@ function createExtractor() {
|
|
|
708
844
|
...props.deoptProps || [],
|
|
709
845
|
...staticConfig.deoptProps || []
|
|
710
846
|
]);
|
|
847
|
+
const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
|
|
711
848
|
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
712
849
|
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
713
850
|
tamaguiConfig,
|
|
@@ -765,27 +902,12 @@ function createExtractor() {
|
|
|
765
902
|
}
|
|
766
903
|
tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
|
|
767
904
|
node.attributes = flattenedAttrs;
|
|
768
|
-
if (staticConfig.defaultProps) {
|
|
769
|
-
for (const key in staticConfig.defaultProps) {
|
|
770
|
-
if (isValidStyleKey(key)) {
|
|
771
|
-
continue;
|
|
772
|
-
}
|
|
773
|
-
const serialize = require("babel-literal-to-ast");
|
|
774
|
-
const val = staticConfig.defaultProps[key];
|
|
775
|
-
try {
|
|
776
|
-
const serializedDefaultProp = serialize(val);
|
|
777
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
|
|
778
|
-
} catch (err) {
|
|
779
|
-
console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
|
|
780
|
-
error: ${err}
|
|
781
|
-
value:`, val, "\n defaultProps:", staticConfig.defaultProps);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
905
|
let attrs = [];
|
|
786
906
|
let shouldDeopt = false;
|
|
787
907
|
const inlined = /* @__PURE__ */ new Map();
|
|
908
|
+
const variantValues = /* @__PURE__ */ new Map();
|
|
788
909
|
let hasSetOptimized = false;
|
|
910
|
+
const inlineWhenUnflattenedOGVals = {};
|
|
789
911
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
790
912
|
try {
|
|
791
913
|
const res2 = evaluateAttribute(path);
|
|
@@ -799,6 +921,7 @@ function createExtractor() {
|
|
|
799
921
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
800
922
|
console.log("node", path.node);
|
|
801
923
|
}
|
|
924
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
802
925
|
return {
|
|
803
926
|
type: "attr",
|
|
804
927
|
value: path.node
|
|
@@ -854,18 +977,30 @@ function createExtractor() {
|
|
|
854
977
|
}, []).flat();
|
|
855
978
|
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
856
979
|
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
857
|
-
|
|
980
|
+
const themeVal = inlined.get("theme");
|
|
858
981
|
inlined.delete("theme");
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
|
|
982
|
+
for (const [key] of [...inlined]) {
|
|
983
|
+
if (INLINE_EXTRACTABLE[key] || ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key])) {
|
|
984
|
+
inlined.delete(key);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
const canFlattenProps = inlined.size === 0;
|
|
862
988
|
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
989
|
+
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
990
|
+
if (disableExtractVariables) {
|
|
991
|
+
themeAccessListeners.add((key) => {
|
|
992
|
+
shouldFlatten = false;
|
|
993
|
+
if (shouldPrintDebug) {
|
|
994
|
+
console.log(" ! accessing theme key, avoid flatten", key);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
863
998
|
if (shouldPrintDebug) {
|
|
864
|
-
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps,
|
|
999
|
+
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
|
|
865
1000
|
}
|
|
866
|
-
if (shouldFlatten &&
|
|
1001
|
+
if (shouldFlatten && shouldWrapTheme) {
|
|
867
1002
|
if (shouldPrintDebug) {
|
|
868
|
-
console.log(" - wrapping theme",
|
|
1003
|
+
console.log(" - wrapping theme", themeVal);
|
|
869
1004
|
}
|
|
870
1005
|
attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
|
|
871
1006
|
if (!hasImportedTheme) {
|
|
@@ -876,9 +1011,9 @@ function createExtractor() {
|
|
|
876
1011
|
t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
|
|
877
1012
|
]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
878
1013
|
}
|
|
879
|
-
if (shouldFlatten
|
|
1014
|
+
if (shouldFlatten) {
|
|
880
1015
|
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
881
|
-
if (!isValidStyleKey(key)) {
|
|
1016
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
882
1017
|
return [];
|
|
883
1018
|
}
|
|
884
1019
|
const value = staticConfig.defaultProps[key];
|
|
@@ -924,14 +1059,83 @@ function createExtractor() {
|
|
|
924
1059
|
console.log(" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
925
1060
|
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
926
1061
|
}
|
|
1062
|
+
const state = {
|
|
1063
|
+
noClassNames: false,
|
|
1064
|
+
focus: false,
|
|
1065
|
+
hover: false,
|
|
1066
|
+
mounted: true,
|
|
1067
|
+
press: false,
|
|
1068
|
+
pressIn: false
|
|
1069
|
+
};
|
|
1070
|
+
let foundStaticProps = {};
|
|
1071
|
+
for (const key in attrs) {
|
|
1072
|
+
const cur = attrs[key];
|
|
1073
|
+
if (cur.type === "style") {
|
|
1074
|
+
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
if (cur.type === "attr") {
|
|
1078
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
const key2 = cur.value.name.name;
|
|
1085
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1086
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1087
|
+
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1088
|
+
[key2]: value
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
const completeProps = {};
|
|
1094
|
+
for (const key in staticConfig.defaultProps) {
|
|
1095
|
+
if (!(key in foundStaticProps)) {
|
|
1096
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
for (const key in foundStaticProps) {
|
|
1100
|
+
completeProps[key] = foundStaticProps[key];
|
|
1101
|
+
}
|
|
927
1102
|
attrs = attrs.reduce((acc, cur) => {
|
|
928
|
-
if (!cur)
|
|
1103
|
+
if (!cur)
|
|
929
1104
|
return acc;
|
|
930
|
-
}
|
|
931
1105
|
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
932
1106
|
if (shouldFlatten) {
|
|
933
|
-
|
|
934
|
-
|
|
1107
|
+
const name = cur.value.name.name;
|
|
1108
|
+
if (typeof name === "string") {
|
|
1109
|
+
if (name === "tag") {
|
|
1110
|
+
return acc;
|
|
1111
|
+
}
|
|
1112
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1113
|
+
let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, __spreadProps(__spreadValues({}, state), { resolveVariablesAs: "auto" }), void 0, shouldPrintDebug) || []);
|
|
1114
|
+
if (out && isTargetingHTML) {
|
|
1115
|
+
const cn = out.className;
|
|
1116
|
+
out = (0, import_core_node.createDOMProps)(isTextView ? "span" : "div", out);
|
|
1117
|
+
out.className = cn;
|
|
1118
|
+
}
|
|
1119
|
+
if (shouldPrintDebug) {
|
|
1120
|
+
console.log(" - expanded variant", name, out);
|
|
1121
|
+
}
|
|
1122
|
+
for (const key2 in out) {
|
|
1123
|
+
const value2 = out[key2];
|
|
1124
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1125
|
+
acc.push({
|
|
1126
|
+
type: "style",
|
|
1127
|
+
value: { [key2]: value2 },
|
|
1128
|
+
name: key2,
|
|
1129
|
+
attr: cur.value
|
|
1130
|
+
});
|
|
1131
|
+
} else {
|
|
1132
|
+
acc.push({
|
|
1133
|
+
type: "attr",
|
|
1134
|
+
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
935
1139
|
}
|
|
936
1140
|
}
|
|
937
1141
|
}
|
|
@@ -970,7 +1174,7 @@ function createExtractor() {
|
|
|
970
1174
|
if (cur.type === "style") {
|
|
971
1175
|
const key = Object.keys(cur.value)[0];
|
|
972
1176
|
const value = cur.value[key];
|
|
973
|
-
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !import_core_node.
|
|
1177
|
+
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !import_core_node.pseudoDescriptors[key] && !key.startsWith("data-");
|
|
974
1178
|
if (shouldKeepOriginalAttr) {
|
|
975
1179
|
if (shouldPrintDebug) {
|
|
976
1180
|
console.log(" - keeping as non-style", key);
|
|
@@ -998,43 +1202,13 @@ function createExtractor() {
|
|
|
998
1202
|
acc.push(cur);
|
|
999
1203
|
return acc;
|
|
1000
1204
|
}, []);
|
|
1001
|
-
const state = {
|
|
1002
|
-
noClassNames: true,
|
|
1003
|
-
focus: false,
|
|
1004
|
-
hover: false,
|
|
1005
|
-
mounted: true,
|
|
1006
|
-
press: false,
|
|
1007
|
-
pressIn: false
|
|
1008
|
-
};
|
|
1009
|
-
const completeStaticProps = Object.keys(attrs).reduce((acc, index) => {
|
|
1010
|
-
const cur = attrs[index];
|
|
1011
|
-
if (cur.type === "style") {
|
|
1012
|
-
(0, import_core_node.normalizeStyleObject)(cur.value);
|
|
1013
|
-
Object.assign(acc, cur.value);
|
|
1014
|
-
}
|
|
1015
|
-
if (cur.type === "attr") {
|
|
1016
|
-
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1017
|
-
return acc;
|
|
1018
|
-
}
|
|
1019
|
-
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1020
|
-
return acc;
|
|
1021
|
-
}
|
|
1022
|
-
const key = cur.value.name.name;
|
|
1023
|
-
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1024
|
-
if (value === import_constants.FAILED_EVAL) {
|
|
1025
|
-
return acc;
|
|
1026
|
-
}
|
|
1027
|
-
acc[key] = value;
|
|
1028
|
-
}
|
|
1029
|
-
return acc;
|
|
1030
|
-
}, {});
|
|
1031
|
-
const completeProps = __spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps);
|
|
1032
1205
|
if (shouldPrintDebug) {
|
|
1033
1206
|
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1034
1207
|
console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
|
|
1035
|
-
console.log(" -
|
|
1208
|
+
console.log(" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps)));
|
|
1209
|
+
console.log(" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps)));
|
|
1036
1210
|
}
|
|
1037
|
-
const getStyles =
|
|
1211
|
+
const getStyles = (props2, debugName = "") => {
|
|
1038
1212
|
if (!props2 || !Object.keys(props2).length) {
|
|
1039
1213
|
if (shouldPrintDebug)
|
|
1040
1214
|
console.log(" getStyles() no props");
|
|
@@ -1052,38 +1226,21 @@ function createExtractor() {
|
|
|
1052
1226
|
try {
|
|
1053
1227
|
const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
|
|
1054
1228
|
fallbackProps: completeProps
|
|
1055
|
-
}));
|
|
1229
|
+
}), void 0, props2["debug"]);
|
|
1056
1230
|
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
1057
|
-
if (staticConfig.validStyles) {
|
|
1058
|
-
for (const key in outStyle) {
|
|
1059
|
-
if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key] && !/(hover|focus|press)Style$/.test(key)) {
|
|
1060
|
-
if (shouldPrintDebug)
|
|
1061
|
-
console.log(" delete invalid style", key);
|
|
1062
|
-
delete outStyle[key];
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
if (shouldPrintDebug) {
|
|
1067
|
-
console.log(` getStyles ${debugName} (props):
|
|
1068
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
|
|
1069
|
-
console.log(` getStyles ${debugName} (out.viewProps):
|
|
1070
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.viewProps)));
|
|
1071
|
-
console.log(` getStyles ${debugName} (out.style):
|
|
1072
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outStyle || {}), true));
|
|
1073
|
-
}
|
|
1074
1231
|
return outStyle;
|
|
1075
1232
|
} catch (err) {
|
|
1076
1233
|
console.log("error", err.message, err.stack);
|
|
1077
1234
|
return {};
|
|
1078
1235
|
}
|
|
1079
|
-
}
|
|
1080
|
-
const
|
|
1081
|
-
if (!
|
|
1236
|
+
};
|
|
1237
|
+
const completeStyles = getStyles(completeProps, "completeStyles");
|
|
1238
|
+
if (!completeStyles) {
|
|
1082
1239
|
throw new Error(`Impossible, no styles`);
|
|
1083
1240
|
}
|
|
1084
|
-
const
|
|
1085
|
-
if (
|
|
1086
|
-
const toAdd = (0, import_lodash.pick)(
|
|
1241
|
+
const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(foundStaticProps)) : [];
|
|
1242
|
+
if (addInitialStyleKeys.length) {
|
|
1243
|
+
const toAdd = (0, import_lodash.pick)(completeStyles, ...addInitialStyleKeys);
|
|
1087
1244
|
const firstGroup = attrs.find((x) => x.type === "style");
|
|
1088
1245
|
if (shouldPrintDebug) {
|
|
1089
1246
|
console.log(" toAdd", (0, import_extractHelpers.objToStr)(toAdd));
|
|
@@ -1091,19 +1248,17 @@ function createExtractor() {
|
|
|
1091
1248
|
if (!firstGroup) {
|
|
1092
1249
|
attrs.unshift({ type: "style", value: toAdd });
|
|
1093
1250
|
} else {
|
|
1251
|
+
omitInvalidStyles(firstGroup.value);
|
|
1094
1252
|
Object.assign(firstGroup.value, toAdd);
|
|
1095
1253
|
}
|
|
1096
1254
|
}
|
|
1097
1255
|
if (shouldPrintDebug) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
console.log(" -- completeStylesProcessed:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStylesProcessed)));
|
|
1256
|
+
if (shouldFlatten)
|
|
1257
|
+
console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "));
|
|
1101
1258
|
}
|
|
1102
1259
|
let getStyleError = null;
|
|
1103
1260
|
for (const attr of attrs) {
|
|
1104
1261
|
try {
|
|
1105
|
-
if (shouldPrintDebug)
|
|
1106
|
-
console.log(" *", (0, import_extractHelpers.attrStr)(attr));
|
|
1107
1262
|
switch (attr.type) {
|
|
1108
1263
|
case "ternary":
|
|
1109
1264
|
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
@@ -1116,20 +1271,23 @@ function createExtractor() {
|
|
|
1116
1271
|
console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
|
|
1117
1272
|
continue;
|
|
1118
1273
|
case "style":
|
|
1119
|
-
if (shouldPrintDebug)
|
|
1120
|
-
console.log(" * styles in", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
|
|
1121
1274
|
const styles = getStyles(attr.value, "style");
|
|
1122
|
-
if (shouldPrintDebug)
|
|
1123
|
-
console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
1124
1275
|
if (styles) {
|
|
1125
|
-
attr.value =
|
|
1276
|
+
attr.value = styles;
|
|
1126
1277
|
}
|
|
1278
|
+
if (shouldPrintDebug)
|
|
1279
|
+
console.log(" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
|
|
1280
|
+
if (shouldPrintDebug)
|
|
1281
|
+
console.log(" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
1127
1282
|
continue;
|
|
1128
1283
|
}
|
|
1129
1284
|
} catch (err) {
|
|
1130
1285
|
getStyleError = err;
|
|
1131
1286
|
}
|
|
1132
1287
|
}
|
|
1288
|
+
if (shouldPrintDebug) {
|
|
1289
|
+
console.log(" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1290
|
+
}
|
|
1133
1291
|
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1134
1292
|
if (getStyleError) {
|
|
1135
1293
|
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
@@ -1139,7 +1297,7 @@ function createExtractor() {
|
|
|
1139
1297
|
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1140
1298
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1141
1299
|
const attr = attrs[i];
|
|
1142
|
-
if (shouldFlatten
|
|
1300
|
+
if (shouldFlatten) {
|
|
1143
1301
|
if (attr.type === "attr") {
|
|
1144
1302
|
if (t.isJSXAttribute(attr.value)) {
|
|
1145
1303
|
if (t.isJSXIdentifier(attr.value.name)) {
|
|
@@ -1147,6 +1305,9 @@ function createExtractor() {
|
|
|
1147
1305
|
if (INLINE_EXTRACTABLE[name]) {
|
|
1148
1306
|
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1149
1307
|
}
|
|
1308
|
+
if ((_d = staticConfig.variants) == null ? void 0 : _d[name]) {
|
|
1309
|
+
const expanded = getStyles({});
|
|
1310
|
+
}
|
|
1150
1311
|
}
|
|
1151
1312
|
}
|
|
1152
1313
|
}
|
|
@@ -1164,6 +1325,21 @@ function createExtractor() {
|
|
|
1164
1325
|
}
|
|
1165
1326
|
}
|
|
1166
1327
|
}
|
|
1328
|
+
if (!shouldFlatten) {
|
|
1329
|
+
if (Object.keys(inlineWhenUnflattenedOGVals).length) {
|
|
1330
|
+
for (const [index, attr] of attrs.entries()) {
|
|
1331
|
+
if (attr.type === "style") {
|
|
1332
|
+
for (const key in attr.value) {
|
|
1333
|
+
const val = inlineWhenUnflattenedOGVals[key];
|
|
1334
|
+
if (val) {
|
|
1335
|
+
delete attr.value[key];
|
|
1336
|
+
attrs.splice(index - 1, 0, val.attr);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1167
1343
|
if (shouldFlatten) {
|
|
1168
1344
|
if (shouldPrintDebug) {
|
|
1169
1345
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
@@ -1189,8 +1365,6 @@ function createExtractor() {
|
|
|
1189
1365
|
isFlattened: shouldFlatten,
|
|
1190
1366
|
programPath
|
|
1191
1367
|
});
|
|
1192
|
-
} catch (err) {
|
|
1193
|
-
throw err;
|
|
1194
1368
|
} finally {
|
|
1195
1369
|
if (debugPropValue) {
|
|
1196
1370
|
shouldPrintDebug = ogDebug;
|
|
@@ -1213,7 +1387,6 @@ function createExtractor() {
|
|
|
1213
1387
|
}
|
|
1214
1388
|
};
|
|
1215
1389
|
}
|
|
1216
|
-
__name(createExtractor, "createExtractor");
|
|
1217
1390
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1218
1391
|
0 && (module.exports = {
|
|
1219
1392
|
createExtractor
|