@tamagui/static 1.0.1-beta.59 → 1.0.1-beta.62
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/createExtractor.js +49 -21
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +1 -1
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +1 -1
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +54 -24
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +1 -1
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +1 -1
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +54 -24
- package/dist/jsx/extractor/extractMediaStyle.js +1 -1
- package/dist/jsx/extractor/extractToClassNames.js +1 -1
- package/package.json +9 -7
- 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 +69 -0
- package/src/extractor/createExtractor.ts +1725 -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 +426 -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 +139 -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 +9 -0
- package/src/patchReactNativeWeb.ts +165 -0
- package/src/types.ts +97 -0
- package/types/extractor/createExtractor.d.ts +14 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
|
@@ -158,7 +158,16 @@ function createExtractor() {
|
|
|
158
158
|
}
|
|
159
159
|
tm.mark("load-tamagui", shouldPrintDebug === "verbose");
|
|
160
160
|
loadedTamaguiConfig = tamaguiConfig;
|
|
161
|
-
const
|
|
161
|
+
const proxiedTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
|
|
162
|
+
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
163
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
164
|
+
get(target2, key) {
|
|
165
|
+
if (key[0] === "$") {
|
|
166
|
+
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
167
|
+
}
|
|
168
|
+
return Reflect.get(target2, key);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
162
171
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
163
172
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
164
173
|
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
@@ -394,7 +403,7 @@ function createExtractor() {
|
|
|
394
403
|
let keys = [name];
|
|
395
404
|
let out = null;
|
|
396
405
|
if (staticConfig.propMapper) {
|
|
397
|
-
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" });
|
|
406
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
|
|
398
407
|
if (out) {
|
|
399
408
|
if (!Array.isArray(out)) {
|
|
400
409
|
console.warn(`Error expected array but got`, out);
|
|
@@ -423,7 +432,7 @@ function createExtractor() {
|
|
|
423
432
|
attr: path.node
|
|
424
433
|
};
|
|
425
434
|
}
|
|
426
|
-
if (import_validHTMLAttributes.validHTMLAttributes[key]) {
|
|
435
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
427
436
|
return attr;
|
|
428
437
|
}
|
|
429
438
|
if (shouldPrintDebug) {
|
|
@@ -890,6 +899,14 @@ function createExtractor() {
|
|
|
890
899
|
const shouldWrapThme = allOtherPropsExtractable && !!themeVal;
|
|
891
900
|
const canFlattenProps = inlined.size === 0 || shouldWrapThme || allOtherPropsExtractable;
|
|
892
901
|
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
902
|
+
if (disableExtractVariables) {
|
|
903
|
+
themeAccessListeners.add((key) => {
|
|
904
|
+
shouldFlatten = false;
|
|
905
|
+
if (shouldPrintDebug) {
|
|
906
|
+
console.log(" ! accessing theme key, avoid flatten", key);
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
}
|
|
893
910
|
if (shouldPrintDebug) {
|
|
894
911
|
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapThme, allOtherPropsExtractable, hasOnlyStringChildren }));
|
|
895
912
|
}
|
|
@@ -1035,32 +1052,43 @@ function createExtractor() {
|
|
|
1035
1052
|
press: false,
|
|
1036
1053
|
pressIn: false
|
|
1037
1054
|
};
|
|
1038
|
-
|
|
1039
|
-
|
|
1055
|
+
let foundStaticProps = {};
|
|
1056
|
+
for (const key in attrs) {
|
|
1057
|
+
const cur = attrs[key];
|
|
1040
1058
|
if (cur.type === "style") {
|
|
1041
1059
|
(0, import_core_node.normalizeStyleObject)(cur.value);
|
|
1042
|
-
|
|
1060
|
+
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
|
|
1061
|
+
continue;
|
|
1043
1062
|
}
|
|
1044
1063
|
if (cur.type === "attr") {
|
|
1045
1064
|
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1046
|
-
|
|
1065
|
+
continue;
|
|
1047
1066
|
}
|
|
1048
1067
|
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1049
|
-
|
|
1068
|
+
continue;
|
|
1050
1069
|
}
|
|
1051
|
-
const
|
|
1070
|
+
const key2 = cur.value.name.name;
|
|
1052
1071
|
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1053
|
-
if (value
|
|
1054
|
-
|
|
1072
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1073
|
+
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1074
|
+
[key2]: value
|
|
1075
|
+
});
|
|
1055
1076
|
}
|
|
1056
|
-
acc[key] = value;
|
|
1057
1077
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
const
|
|
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
|
+
}
|
|
1061
1088
|
if (shouldPrintDebug) {
|
|
1062
1089
|
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1063
1090
|
console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
|
|
1091
|
+
console.log(" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps)));
|
|
1064
1092
|
console.log(" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps)));
|
|
1065
1093
|
}
|
|
1066
1094
|
const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
|
|
@@ -1081,7 +1109,7 @@ function createExtractor() {
|
|
|
1081
1109
|
try {
|
|
1082
1110
|
const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
|
|
1083
1111
|
fallbackProps: completeProps
|
|
1084
|
-
}));
|
|
1112
|
+
}), void 0, props2["debug"]);
|
|
1085
1113
|
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
1086
1114
|
omitInvalidStyles(outStyle);
|
|
1087
1115
|
if (shouldPrintDebug) {
|
|
@@ -1102,7 +1130,7 @@ function createExtractor() {
|
|
|
1102
1130
|
if (!completeStyles) {
|
|
1103
1131
|
throw new Error(`Impossible, no styles`);
|
|
1104
1132
|
}
|
|
1105
|
-
const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(
|
|
1133
|
+
const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(foundStaticProps)) : [];
|
|
1106
1134
|
if (addInitialStyleKeys.length) {
|
|
1107
1135
|
const toAdd = (0, import_lodash.pick)(completeStyles, ...addInitialStyleKeys);
|
|
1108
1136
|
const firstGroup = attrs.find((x) => x.type === "style");
|
|
@@ -1118,14 +1146,11 @@ function createExtractor() {
|
|
|
1118
1146
|
}
|
|
1119
1147
|
if (shouldPrintDebug) {
|
|
1120
1148
|
console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "), { shouldFlatten });
|
|
1121
|
-
console.log(" -- completeStaticProps:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
|
|
1122
1149
|
console.log(" -- completeStyles:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStyles)));
|
|
1123
1150
|
}
|
|
1124
1151
|
let getStyleError = null;
|
|
1125
1152
|
for (const attr of attrs) {
|
|
1126
1153
|
try {
|
|
1127
|
-
if (shouldPrintDebug)
|
|
1128
|
-
console.log(" *", (0, import_extractHelpers.attrStr)(attr));
|
|
1129
1154
|
switch (attr.type) {
|
|
1130
1155
|
case "ternary":
|
|
1131
1156
|
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
@@ -1139,7 +1164,7 @@ function createExtractor() {
|
|
|
1139
1164
|
continue;
|
|
1140
1165
|
case "style":
|
|
1141
1166
|
if (shouldPrintDebug)
|
|
1142
|
-
console.log(" * styles in",
|
|
1167
|
+
console.log(" * styles in", attr.value);
|
|
1143
1168
|
const styles = getStyles(attr.value, "style");
|
|
1144
1169
|
if (shouldPrintDebug)
|
|
1145
1170
|
console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
@@ -1152,6 +1177,9 @@ function createExtractor() {
|
|
|
1152
1177
|
getStyleError = err;
|
|
1153
1178
|
}
|
|
1154
1179
|
}
|
|
1180
|
+
if (shouldPrintDebug) {
|
|
1181
|
+
console.log(" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1182
|
+
}
|
|
1155
1183
|
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1156
1184
|
if (getStyleError) {
|
|
1157
1185
|
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|