@tamagui/static 1.0.1-beta.20 → 1.0.1-beta.201
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/constants.js → constants.js} +9 -4
- package/dist/constants.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/accessSafe.js +14 -4
- package/dist/{esm/extractor → extractor}/accessSafe.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/babelParse.js +20 -17
- package/dist/extractor/babelParse.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/buildClassName.js +40 -11
- package/dist/extractor/buildClassName.js.map +7 -0
- package/dist/extractor/bundle.js +117 -0
- package/dist/extractor/bundle.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/createEvaluator.js +19 -14
- package/dist/extractor/createEvaluator.js.map +7 -0
- package/dist/extractor/createExtractor.js +1650 -0
- package/dist/extractor/createExtractor.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/ensureImportingConcat.js +18 -8
- package/dist/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/evaluateAstNode.js +14 -6
- package/dist/{esm/extractor → extractor}/evaluateAstNode.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/extractHelpers.js +91 -27
- package/dist/extractor/extractHelpers.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/extractMediaStyle.js +49 -50
- package/dist/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/extractToClassNames.js +161 -109
- package/dist/extractor/extractToClassNames.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/findTopmostFunction.js +2 -3
- package/dist/{esm/extractor → extractor}/findTopmostFunction.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/generatedUid.js +9 -4
- package/dist/{cjs/extractor → extractor}/generatedUid.js.map +3 -3
- package/dist/{cjs/extractor → extractor}/getPrefixLogs.js +1 -2
- package/dist/extractor/getPrefixLogs.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/getPropValueFromAttributes.js +24 -15
- package/dist/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/getSourceModule.js +5 -3
- package/dist/{esm/extractor → extractor}/getSourceModule.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/getStaticBindingsForScope.js +88 -38
- package/dist/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/hoistClassNames.js +5 -4
- package/dist/{esm/extractor → extractor}/hoistClassNames.js.map +3 -3
- package/dist/{cjs/extractor → extractor}/literalToAst.js +26 -34
- package/dist/{cjs/extractor → extractor}/literalToAst.js.map +2 -2
- package/dist/extractor/loadFile.js +21 -0
- package/dist/extractor/loadFile.js.map +7 -0
- package/dist/extractor/loadTamagui.js +421 -0
- package/dist/extractor/loadTamagui.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/logLines.js +3 -3
- package/dist/{cjs/extractor → extractor}/logLines.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/normalizeTernaries.js +13 -36
- package/dist/extractor/normalizeTernaries.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/removeUnusedHooks.js +7 -5
- package/dist/{cjs/extractor → extractor}/removeUnusedHooks.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/timer.js +11 -4
- package/dist/extractor/timer.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/validHTMLAttributes.js +52 -0
- package/dist/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/getPragmaOptions.js +68 -0
- package/dist/getPragmaOptions.js.map +7 -0
- package/dist/helpers/memoize.js +46 -0
- package/dist/helpers/memoize.js.map +7 -0
- package/dist/{cjs/index.js → index.js} +10 -7
- package/dist/index.js.map +7 -0
- package/dist/require.js +90 -0
- package/dist/require.js.map +7 -0
- package/dist/tamagui-node/tamagui.config.js +6781 -0
- package/dist/{jsx/types.js → tamagui-node/tamaguicore-components.config.js} +0 -0
- package/dist/tamagui-node/tamaguitestdesignsystem-components.config.js +31 -0
- package/dist/{cjs/types.js → types.js} +1 -0
- package/dist/types.js.map +7 -0
- package/dist/webpackPlugin.js +35 -0
- package/dist/webpackPlugin.js.map +7 -0
- package/package.json +47 -35
- package/src/constants.ts +14 -0
- package/src/extractor/accessSafe.ts +18 -0
- package/src/extractor/babelParse.ts +28 -0
- package/src/extractor/buildClassName.ts +77 -0
- package/src/extractor/bundle.ts +110 -0
- package/src/extractor/createEvaluator.ts +73 -0
- package/src/extractor/createExtractor.ts +2147 -0
- package/src/extractor/ensureImportingConcat.ts +32 -0
- package/src/extractor/evaluateAstNode.ts +121 -0
- package/src/extractor/extractHelpers.ts +201 -0
- package/src/extractor/extractMediaStyle.ts +199 -0
- package/src/extractor/extractToClassNames.ts +445 -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 +227 -0
- package/src/extractor/hoistClassNames.ts +45 -0
- package/src/extractor/literalToAst.ts +84 -0
- package/src/extractor/loadFile.ts +17 -0
- package/src/extractor/loadTamagui.ts +478 -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 +29 -0
- package/src/extractor/validHTMLAttributes.ts +99 -0
- package/src/getPragmaOptions.ts +53 -0
- package/src/helpers/memoize.ts +21 -0
- package/src/index.ts +11 -0
- package/src/require.ts +107 -0
- package/src/types.ts +98 -0
- package/src/webpackPlugin.ts +9 -0
- package/tamagui.tsconfig.json +5 -0
- package/types/constants.d.ts +1 -1
- package/types/extractor/babelParse.d.ts +2 -1
- package/types/extractor/buildClassName.d.ts +5 -2
- package/types/extractor/bundle.d.ts +13 -0
- package/types/extractor/createEvaluator.d.ts +4 -4
- package/types/extractor/createExtractor.d.ts +26 -11
- package/types/extractor/extractHelpers.d.ts +16 -4
- package/types/extractor/extractMediaStyle.d.ts +3 -3
- package/types/extractor/extractToClassNames.d.ts +5 -9
- package/types/extractor/getPrefixLogs.d.ts +1 -1
- package/types/extractor/getPropValueFromAttributes.d.ts +16 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +2 -1
- package/types/extractor/loadFile.d.ts +1 -0
- package/types/extractor/loadTamagui.d.ts +22 -6
- package/types/extractor/normalizeTernaries.d.ts +1 -1
- package/types/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/getPragmaOptions.d.ts +9 -0
- package/types/helpers/memoize.d.ts +8 -0
- package/types/index.d.ts +9 -7
- package/types/require.d.ts +4 -0
- package/types/types.d.ts +32 -32
- package/types/webpackPlugin.d.ts +4 -0
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/extractor/accessSafe.js.map +0 -7
- package/dist/cjs/extractor/babelParse.js.map +0 -7
- package/dist/cjs/extractor/buildClassName.js.map +0 -7
- package/dist/cjs/extractor/createEvaluator.js.map +0 -7
- package/dist/cjs/extractor/createExtractor.js +0 -1221
- package/dist/cjs/extractor/createExtractor.js.map +0 -7
- package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/cjs/extractor/evaluateAstNode.js.map +0 -7
- package/dist/cjs/extractor/extractHelpers.js.map +0 -7
- package/dist/cjs/extractor/extractMediaStyle.js.map +0 -7
- package/dist/cjs/extractor/extractToClassNames.js.map +0 -7
- package/dist/cjs/extractor/findTopmostFunction.js.map +0 -7
- package/dist/cjs/extractor/getPrefixLogs.js.map +0 -7
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/cjs/extractor/getSourceModule.js.map +0 -7
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/cjs/extractor/hoistClassNames.js.map +0 -7
- package/dist/cjs/extractor/loadTamagui.js +0 -106
- package/dist/cjs/extractor/loadTamagui.js.map +0 -7
- package/dist/cjs/extractor/normalizeTernaries.js.map +0 -7
- package/dist/cjs/extractor/timer.js.map +0 -7
- package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/patchReactNativeWeb.js +0 -167
- package/dist/cjs/patchReactNativeWeb.js.map +0 -7
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/constants.js +0 -14
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/extractor/accessSafe.js +0 -11
- package/dist/esm/extractor/babelParse.js +0 -30
- package/dist/esm/extractor/babelParse.js.map +0 -7
- package/dist/esm/extractor/buildClassName.js +0 -40
- package/dist/esm/extractor/buildClassName.js.map +0 -7
- package/dist/esm/extractor/createEvaluator.js +0 -52
- package/dist/esm/extractor/createEvaluator.js.map +0 -7
- package/dist/esm/extractor/createExtractor.js +0 -1169
- package/dist/esm/extractor/createExtractor.js.map +0 -7
- package/dist/esm/extractor/ensureImportingConcat.js +0 -24
- package/dist/esm/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/esm/extractor/evaluateAstNode.js +0 -94
- package/dist/esm/extractor/extractHelpers.js +0 -103
- package/dist/esm/extractor/extractHelpers.js.map +0 -7
- package/dist/esm/extractor/extractMediaStyle.js +0 -152
- package/dist/esm/extractor/extractMediaStyle.js.map +0 -7
- package/dist/esm/extractor/extractToClassNames.js +0 -293
- package/dist/esm/extractor/extractToClassNames.js.map +0 -7
- package/dist/esm/extractor/findTopmostFunction.js +0 -23
- package/dist/esm/extractor/generatedUid.js +0 -28
- package/dist/esm/extractor/generatedUid.js.map +0 -7
- package/dist/esm/extractor/getPrefixLogs.js +0 -12
- package/dist/esm/extractor/getPrefixLogs.js.map +0 -7
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -49
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/esm/extractor/getSourceModule.js +0 -69
- package/dist/esm/extractor/getStaticBindingsForScope.js +0 -137
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/esm/extractor/hoistClassNames.js +0 -44
- package/dist/esm/extractor/literalToAst.js +0 -80
- package/dist/esm/extractor/literalToAst.js.map +0 -7
- package/dist/esm/extractor/loadTamagui.js +0 -84
- package/dist/esm/extractor/loadTamagui.js.map +0 -7
- package/dist/esm/extractor/logLines.js +0 -22
- package/dist/esm/extractor/logLines.js.map +0 -7
- package/dist/esm/extractor/normalizeTernaries.js +0 -53
- package/dist/esm/extractor/normalizeTernaries.js.map +0 -7
- package/dist/esm/extractor/removeUnusedHooks.js +0 -80
- package/dist/esm/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/esm/extractor/timer.js +0 -24
- package/dist/esm/extractor/timer.js.map +0 -7
- package/dist/esm/extractor/validHTMLAttributes.js +0 -52
- package/dist/esm/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/esm/index.js +0 -14
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/patchReactNativeWeb.js +0 -142
- package/dist/esm/patchReactNativeWeb.js.map +0 -7
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/jsx/constants.js +0 -13
- package/dist/jsx/extractor/accessSafe.js +0 -10
- package/dist/jsx/extractor/babelParse.js +0 -29
- package/dist/jsx/extractor/buildClassName.js +0 -39
- package/dist/jsx/extractor/createEvaluator.js +0 -51
- package/dist/jsx/extractor/createExtractor.js +0 -1168
- package/dist/jsx/extractor/ensureImportingConcat.js +0 -23
- package/dist/jsx/extractor/evaluateAstNode.js +0 -93
- package/dist/jsx/extractor/extractHelpers.js +0 -102
- package/dist/jsx/extractor/extractMediaStyle.js +0 -151
- package/dist/jsx/extractor/extractToClassNames.js +0 -292
- package/dist/jsx/extractor/findTopmostFunction.js +0 -22
- package/dist/jsx/extractor/generatedUid.js +0 -27
- package/dist/jsx/extractor/getPrefixLogs.js +0 -11
- package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -48
- package/dist/jsx/extractor/getSourceModule.js +0 -68
- package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -136
- package/dist/jsx/extractor/hoistClassNames.js +0 -43
- package/dist/jsx/extractor/literalToAst.js +0 -79
- package/dist/jsx/extractor/loadTamagui.js +0 -83
- package/dist/jsx/extractor/logLines.js +0 -21
- package/dist/jsx/extractor/normalizeTernaries.js +0 -52
- package/dist/jsx/extractor/removeUnusedHooks.js +0 -79
- package/dist/jsx/extractor/timer.js +0 -23
- package/dist/jsx/extractor/validHTMLAttributes.js +0 -51
- package/dist/jsx/index.js +0 -13
- package/dist/jsx/patchReactNativeWeb.js +0 -141
- package/types/constants.d.ts.map +0 -1
- package/types/extractor/accessSafe.d.ts.map +0 -1
- package/types/extractor/babelParse.d.ts.map +0 -1
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/createEvaluator.d.ts.map +0 -1
- package/types/extractor/createExtractor.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/evaluateAstNode.d.ts.map +0 -1
- package/types/extractor/extractHelpers.d.ts.map +0 -1
- package/types/extractor/extractMediaStyle.d.ts.map +0 -1
- package/types/extractor/extractToClassNames.d.ts.map +0 -1
- package/types/extractor/findTopmostFunction.d.ts.map +0 -1
- package/types/extractor/generatedUid.d.ts.map +0 -1
- package/types/extractor/getPrefixLogs.d.ts.map +0 -1
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
- package/types/extractor/getSourceModule.d.ts.map +0 -1
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
- package/types/extractor/literalToAst.d.ts.map +0 -1
- package/types/extractor/loadTamagui.d.ts.map +0 -1
- package/types/extractor/logLines.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
- package/types/extractor/timer.d.ts.map +0 -1
- package/types/extractor/validHTMLAttributes.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/patchReactNativeWeb.d.ts +0 -2
- package/types/patchReactNativeWeb.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
8
|
var __export = (target, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,46 +17,57 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var extractHelpers_exports = {};
|
|
23
26
|
__export(extractHelpers_exports, {
|
|
24
27
|
attrStr: () => attrStr,
|
|
25
28
|
findComponentName: () => findComponentName,
|
|
26
|
-
|
|
29
|
+
getValidComponent: () => getValidComponent,
|
|
30
|
+
getValidImport: () => getValidImport,
|
|
31
|
+
isComponentPackage: () => isComponentPackage,
|
|
32
|
+
isInsideComponentPackage: () => isInsideComponentPackage,
|
|
27
33
|
isPresent: () => isPresent,
|
|
28
34
|
isSimpleSpread: () => isSimpleSpread,
|
|
35
|
+
isValidImport: () => isValidImport,
|
|
36
|
+
isValidModule: () => isValidModule,
|
|
29
37
|
isValidThemeHook: () => isValidThemeHook,
|
|
30
38
|
objToStr: () => objToStr,
|
|
31
39
|
ternaryStr: () => ternaryStr
|
|
32
40
|
});
|
|
33
41
|
module.exports = __toCommonJS(extractHelpers_exports);
|
|
42
|
+
var import_path = require("path");
|
|
34
43
|
var import_generator = __toESM(require("@babel/generator"));
|
|
35
44
|
var t = __toESM(require("@babel/types"));
|
|
45
|
+
var import_find_root = __toESM(require("find-root"));
|
|
46
|
+
var import_memoize = require("../helpers/memoize.js");
|
|
36
47
|
function isPresent(input) {
|
|
37
48
|
return input != null;
|
|
38
49
|
}
|
|
39
|
-
__name(isPresent, "isPresent");
|
|
40
50
|
function isSimpleSpread(node) {
|
|
41
51
|
return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument);
|
|
42
52
|
}
|
|
43
|
-
|
|
44
|
-
const attrStr = /* @__PURE__ */ __name((attr) => {
|
|
53
|
+
const attrStr = (attr) => {
|
|
45
54
|
return !attr ? "" : attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
46
|
-
}
|
|
47
|
-
const objToStr =
|
|
55
|
+
};
|
|
56
|
+
const objToStr = (obj, spacer = ", ") => {
|
|
48
57
|
if (!obj) {
|
|
49
58
|
return `${obj}`;
|
|
50
59
|
}
|
|
51
|
-
return `{${Object.entries(obj).map(
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
return `{${Object.entries(obj).map(
|
|
61
|
+
([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `${objToStr(v, ",")}` : JSON.stringify(v)}`
|
|
62
|
+
).join(spacer)}}`;
|
|
63
|
+
};
|
|
64
|
+
const getNameAttr = (attr) => {
|
|
54
65
|
if (t.isJSXSpreadAttribute(attr)) {
|
|
55
66
|
return `...${attr.argument["name"]}`;
|
|
56
67
|
}
|
|
57
68
|
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
58
|
-
}
|
|
59
|
-
const ternaryStr =
|
|
69
|
+
};
|
|
70
|
+
const ternaryStr = (x) => {
|
|
60
71
|
const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (0, import_generator.default)(x.test).code;
|
|
61
72
|
return [
|
|
62
73
|
"ternary(",
|
|
@@ -65,11 +76,11 @@ const ternaryStr = /* @__PURE__ */ __name((x) => {
|
|
|
65
76
|
isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
|
|
66
77
|
")"
|
|
67
78
|
].flat().join("");
|
|
68
|
-
}
|
|
69
|
-
const isFilledObj =
|
|
79
|
+
};
|
|
80
|
+
const isFilledObj = (obj) => obj && Object.keys(obj).length;
|
|
70
81
|
function findComponentName(scope) {
|
|
71
82
|
var _a;
|
|
72
|
-
|
|
83
|
+
const componentName = "";
|
|
73
84
|
let cur = scope.path;
|
|
74
85
|
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
75
86
|
cur = cur.parentPath;
|
|
@@ -89,8 +100,7 @@ function findComponentName(scope) {
|
|
|
89
100
|
}
|
|
90
101
|
return componentName;
|
|
91
102
|
}
|
|
92
|
-
|
|
93
|
-
function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
103
|
+
function isValidThemeHook(props, jsxPath, n, sourcePath) {
|
|
94
104
|
var _a;
|
|
95
105
|
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
|
|
96
106
|
return false;
|
|
@@ -110,24 +120,78 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
|
110
120
|
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
111
121
|
if (!t.isImportDeclaration(importNode))
|
|
112
122
|
return false;
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
123
|
+
if (!isValidImport(props, sourcePath)) {
|
|
124
|
+
return false;
|
|
117
125
|
}
|
|
118
126
|
return true;
|
|
119
127
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
128
|
+
const isInsideComponentPackage = (props, moduleName) => {
|
|
129
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
130
|
+
return moduleName.startsWith(path);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const isComponentPackage = (props, srcName) => {
|
|
134
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
135
|
+
return srcName.startsWith(path);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
function getValidComponent(props, moduleName, componentName) {
|
|
139
|
+
if (componentName[0].toUpperCase() !== componentName[0]) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
for (const loaded of props.allLoadedComponents) {
|
|
143
|
+
const isInModule = moduleName === "*" || moduleName.startsWith(loaded.moduleName);
|
|
144
|
+
const foundComponent = loaded.nameToInfo[componentName];
|
|
145
|
+
if (isInModule && foundComponent) {
|
|
146
|
+
return foundComponent;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const isValidModule = (props, moduleName) => {
|
|
152
|
+
if (typeof moduleName !== "string") {
|
|
153
|
+
throw new Error(`No module name`);
|
|
154
|
+
}
|
|
155
|
+
const isLocal = moduleName.startsWith(".");
|
|
156
|
+
return {
|
|
157
|
+
isLocal,
|
|
158
|
+
isValid: isLocal ? isInsideComponentPackage(props, moduleName) : isComponentPackage(props, moduleName)
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const getValidImport = (props, moduleName, componentName) => {
|
|
162
|
+
const { isValid, isLocal } = isValidModule(props, moduleName);
|
|
163
|
+
if (!isValid || !componentName) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return getValidComponent(props, isLocal ? "*" : moduleName, componentName) || null;
|
|
167
|
+
};
|
|
168
|
+
const isValidImport = (props, moduleName, componentName) => {
|
|
169
|
+
if (!componentName) {
|
|
170
|
+
return isValidModule(props, moduleName).isValid;
|
|
171
|
+
}
|
|
172
|
+
return Boolean(getValidImport(props, moduleName, componentName));
|
|
173
|
+
};
|
|
174
|
+
const getValidComponentPackages = (0, import_memoize.memoize)((props) => {
|
|
175
|
+
return [.../* @__PURE__ */ new Set(["@tamagui/core", "tamagui", ...props.components])];
|
|
176
|
+
});
|
|
177
|
+
const getValidComponentsPaths = (0, import_memoize.memoize)((props) => {
|
|
178
|
+
return getValidComponentPackages(props).map((pkg) => {
|
|
179
|
+
const root = (0, import_find_root.default)(pkg);
|
|
180
|
+
return (0, import_path.basename)(root);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
124
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
184
|
0 && (module.exports = {
|
|
126
185
|
attrStr,
|
|
127
186
|
findComponentName,
|
|
128
|
-
|
|
187
|
+
getValidComponent,
|
|
188
|
+
getValidImport,
|
|
189
|
+
isComponentPackage,
|
|
190
|
+
isInsideComponentPackage,
|
|
129
191
|
isPresent,
|
|
130
192
|
isSimpleSpread,
|
|
193
|
+
isValidImport,
|
|
194
|
+
isValidModule,
|
|
131
195
|
isValidThemeHook,
|
|
132
196
|
objToStr,
|
|
133
197
|
ternaryStr
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/extractor/extractHelpers.ts"],
|
|
4
|
+
"sourcesContent": ["import { basename, relative } from 'path'\n\nimport generate from '@babel/generator'\nimport type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport findRoot from 'find-root'\n\nimport { memoize } from '../helpers/memoize.js'\nimport type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'\n\n// import { astToLiteral } from './literalToAst'\n\nexport function isPresent<T extends Object>(input: null | void | undefined | T): input is T {\n return input != null\n}\n\nexport function isSimpleSpread(node: t.JSXSpreadAttribute) {\n return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)\n}\n\nexport const attrStr = (attr?: ExtractedAttr) => {\n return !attr\n ? ''\n : attr.type === 'attr'\n ? getNameAttr(attr.value)\n : attr.type === 'ternary'\n ? `...${ternaryStr(attr.value)}`\n : `${attr.type}(${objToStr(attr.value)})`\n}\n\nexport const objToStr = (obj: any, spacer = ', ') => {\n if (!obj) {\n return `${obj}`\n }\n return `{${Object.entries(obj)\n .map(\n ([k, v]) =>\n `${k}:${\n Array.isArray(v)\n ? `[...]`\n : v && typeof v === 'object'\n ? `${objToStr(v, ',')}`\n : JSON.stringify(v)\n }`\n )\n .join(spacer)}}`\n}\n\nconst getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {\n if (t.isJSXSpreadAttribute(attr)) {\n return `...${attr.argument['name']}`\n }\n return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`\n}\n\nexport const ternaryStr = (x: Ternary) => {\n const conditional = t.isIdentifier(x.test)\n ? x.test.name\n : t.isMemberExpression(x.test)\n ? [x.test.object['name'], x.test.property['name']]\n : generate(x.test as any).code\n return [\n 'ternary(',\n conditional,\n isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : ' ? \uD83D\uDEAB',\n isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : ' : \uD83D\uDEAB',\n ')',\n ]\n .flat()\n .join('')\n}\n\nconst isFilledObj = (obj: any) => obj && Object.keys(obj).length\n\nexport function findComponentName(scope) {\n const componentName = ''\n let cur = scope.path\n while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {\n cur = cur.parentPath\n }\n let node = cur.parent\n if (t.isExportNamedDeclaration(node)) {\n node = node.declaration\n }\n if (t.isVariableDeclaration(node)) {\n const [dec] = node.declarations\n if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {\n return dec.id.name\n }\n }\n if (t.isFunctionDeclaration(node)) {\n return node.id?.name\n }\n return componentName\n}\n\nexport function isValidThemeHook(\n props: TamaguiOptionsWithFileInfo,\n jsxPath: NodePath<t.JSXElement>,\n n: t.MemberExpression,\n sourcePath: string\n) {\n if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[n.object.name]\n if (!binding?.path) return false\n if (!binding.path.isVariableDeclarator()) return false\n const init = binding.path.node.init\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useTheme by looking up import first\n if (init.callee.name !== 'useTheme') return false\n const importNode = binding.scope.getBinding('useTheme')?.path.parent\n if (!t.isImportDeclaration(importNode)) return false\n if (!isValidImport(props, sourcePath)) {\n return false\n }\n return true\n}\n\nexport const isInsideComponentPackage = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {\n return getValidComponentsPaths(props).some((path) => {\n return moduleName.startsWith(path)\n })\n}\n\nexport const isComponentPackage = (props: TamaguiOptionsWithFileInfo, srcName: string) => {\n return getValidComponentsPaths(props).some((path) => {\n return srcName.startsWith(path)\n })\n}\n\nexport function getValidComponent(\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName: string\n) {\n // must be uppercase of course\n if (componentName[0].toUpperCase() !== componentName[0]) {\n return false\n }\n\n for (const loaded of props.allLoadedComponents) {\n const isInModule = moduleName === '*' || moduleName.startsWith(loaded.moduleName)\n const foundComponent = loaded.nameToInfo[componentName]\n // eslint-disable-next-line no-console\n if (isInModule && foundComponent) {\n return foundComponent\n }\n }\n\n return null\n}\n\nexport const isValidModule = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {\n if (typeof moduleName !== 'string') {\n throw new Error(`No module name`)\n }\n const isLocal = moduleName.startsWith('.')\n return {\n isLocal,\n isValid: isLocal\n ? isInsideComponentPackage(props, moduleName)\n : isComponentPackage(props, moduleName),\n }\n}\n\nexport const getValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n const { isValid, isLocal } = isValidModule(props, moduleName)\n if (!isValid || !componentName) {\n return null\n }\n return getValidComponent(props, isLocal ? '*' : moduleName, componentName) || null\n}\n\nexport const isValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n if (!componentName) {\n return isValidModule(props, moduleName).isValid\n }\n return Boolean(getValidImport(props, moduleName, componentName))\n}\n\nconst getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {\n // just always look for `tamagui` and `@tamagui/core`\n return [...new Set(['@tamagui/core', 'tamagui', ...props.components])]\n})\n\nconst getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {\n return getValidComponentPackages(props).map((pkg) => {\n const root = findRoot(pkg)\n return basename(root)\n })\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmC;AAEnC,uBAAqB;AAErB,QAAmB;AACnB,uBAAqB;AAErB,qBAAwB;AAKjB,SAAS,UAA4B,OAAgD;AAC1F,SAAO,SAAS;AAClB;AAEO,SAAS,eAAe,MAA4B;AACzD,SAAO,EAAE,aAAa,KAAK,QAAQ,KAAK,EAAE,mBAAmB,KAAK,QAAQ;AAC5E;AAEO,MAAM,UAAU,CAAC,SAAyB;AAC/C,SAAO,CAAC,OACJ,KACA,KAAK,SAAS,SACd,YAAY,KAAK,KAAK,IACtB,KAAK,SAAS,YACd,MAAM,WAAW,KAAK,KAAK,MAC3B,GAAG,KAAK,QAAQ,SAAS,KAAK,KAAK;AACzC;AAEO,MAAM,WAAW,CAAC,KAAU,SAAS,SAAS;AACnD,MAAI,CAAC,KAAK;AACR,WAAO,GAAG;AAAA,EACZ;AACA,SAAO,IAAI,OAAO,QAAQ,GAAG,EAC1B;AAAA,IACC,CAAC,CAAC,GAAG,CAAC,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|
|
@@ -1,27 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
8
|
var __export = (target, all) => {
|
|
26
9
|
for (var name in all)
|
|
27
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -34,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
34
17
|
}
|
|
35
18
|
return to;
|
|
36
19
|
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
38
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
25
|
var extractMediaStyle_exports = {};
|
|
40
26
|
__export(extractMediaStyle_exports, {
|
|
@@ -44,10 +30,10 @@ __export(extractMediaStyle_exports, {
|
|
|
44
30
|
module.exports = __toCommonJS(extractMediaStyle_exports);
|
|
45
31
|
var t = __toESM(require("@babel/types"));
|
|
46
32
|
var import_core_node = require("@tamagui/core-node");
|
|
47
|
-
var import_constants = require("../constants");
|
|
48
|
-
var import_extractHelpers = require("./extractHelpers");
|
|
49
|
-
function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
|
|
50
|
-
const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath);
|
|
33
|
+
var import_constants = require("../constants.js");
|
|
34
|
+
var import_extractHelpers = require("./extractHelpers.js");
|
|
35
|
+
function extractMediaStyle(props, ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
|
|
36
|
+
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath);
|
|
51
37
|
if (!mt) {
|
|
52
38
|
return null;
|
|
53
39
|
}
|
|
@@ -57,9 +43,9 @@ function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importan
|
|
|
57
43
|
console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`);
|
|
58
44
|
return null;
|
|
59
45
|
}
|
|
60
|
-
const getStyleObj =
|
|
46
|
+
const getStyleObj = (styleObj, negate = false) => {
|
|
61
47
|
return styleObj ? { styleObj, negate } : null;
|
|
62
|
-
}
|
|
48
|
+
};
|
|
63
49
|
const styleOpts = [
|
|
64
50
|
getStyleObj(ternary.consequent, false),
|
|
65
51
|
getStyleObj(ternary.alternate, true)
|
|
@@ -79,24 +65,28 @@ function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importan
|
|
|
79
65
|
const singleMediaStyles = styles.map((style) => {
|
|
80
66
|
const negKey = negate ? "0" : "";
|
|
81
67
|
const ogPrefix = style.identifier.slice(0, style.identifier.indexOf("-") + 1);
|
|
82
|
-
const identifier = `${style.identifier.replace(
|
|
68
|
+
const identifier = `${style.identifier.replace(
|
|
69
|
+
ogPrefix,
|
|
70
|
+
`${ogPrefix}${import_constants.MEDIA_SEP}${key}${negKey}${import_constants.MEDIA_SEP}`
|
|
71
|
+
)}`;
|
|
83
72
|
const className = `.${identifier}`;
|
|
84
73
|
const mediaSelector = (0, import_core_node.mediaObjectToString)(tamaguiConfig.media[key]);
|
|
85
74
|
const screenStr = negate ? "not all" : "screen";
|
|
86
75
|
const mediaQuery = `${screenStr} and ${mediaSelector}`;
|
|
87
76
|
const precendencePrefix = mediaKeyPrecendence[key];
|
|
88
|
-
const styleInner = style.rules
|
|
77
|
+
const styleInner = style.rules.map((rule) => rule.replace(style.identifier, identifier)).join(";");
|
|
89
78
|
let styleRule = "";
|
|
90
79
|
if (styleInner.includes("@media")) {
|
|
91
80
|
styleRule = styleInner.replace("{", ` and ${mediaQuery} {`);
|
|
92
81
|
} else {
|
|
93
82
|
styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`;
|
|
94
83
|
}
|
|
95
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
...style,
|
|
96
86
|
identifier,
|
|
97
87
|
className,
|
|
98
88
|
rules: [styleRule]
|
|
99
|
-
}
|
|
89
|
+
};
|
|
100
90
|
});
|
|
101
91
|
if (shouldPrintDebug === "verbose") {
|
|
102
92
|
console.log(" media styles:", importance, styleObj, singleMediaStyles.map((x) => x.identifier).join(", "));
|
|
@@ -106,28 +96,41 @@ function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importan
|
|
|
106
96
|
ternary.remove();
|
|
107
97
|
return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia };
|
|
108
98
|
}
|
|
109
|
-
|
|
110
|
-
function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
|
|
99
|
+
function getMediaQueryTernary(props, ternary, jsxPath, sourcePath) {
|
|
111
100
|
if (t.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
|
|
112
|
-
const mediaLeft = getMediaInfoFromExpression(
|
|
101
|
+
const mediaLeft = getMediaInfoFromExpression(
|
|
102
|
+
props,
|
|
103
|
+
ternary.test.left,
|
|
104
|
+
jsxPath,
|
|
105
|
+
sourcePath,
|
|
106
|
+
ternary.inlineMediaQuery
|
|
107
|
+
);
|
|
113
108
|
if (mediaLeft) {
|
|
114
|
-
return
|
|
115
|
-
|
|
109
|
+
return {
|
|
110
|
+
...mediaLeft,
|
|
111
|
+
ternaryWithoutMedia: {
|
|
112
|
+
...ternary,
|
|
116
113
|
test: ternary.test.right
|
|
117
|
-
}
|
|
118
|
-
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
|
-
const result = getMediaInfoFromExpression(
|
|
118
|
+
const result = getMediaInfoFromExpression(
|
|
119
|
+
props,
|
|
120
|
+
ternary.test,
|
|
121
|
+
jsxPath,
|
|
122
|
+
sourcePath,
|
|
123
|
+
ternary.inlineMediaQuery
|
|
124
|
+
);
|
|
122
125
|
if (result) {
|
|
123
|
-
return
|
|
126
|
+
return {
|
|
127
|
+
...result,
|
|
124
128
|
ternaryWithoutMedia: null
|
|
125
|
-
}
|
|
129
|
+
};
|
|
126
130
|
}
|
|
127
131
|
return null;
|
|
128
132
|
}
|
|
129
|
-
|
|
130
|
-
function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
133
|
+
function getMediaInfoFromExpression(props, test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
131
134
|
var _a, _b, _c;
|
|
132
135
|
if (inlineMediaQuery) {
|
|
133
136
|
return {
|
|
@@ -145,7 +148,7 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
145
148
|
const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
|
|
146
149
|
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init)
|
|
147
150
|
return false;
|
|
148
|
-
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
|
|
151
|
+
if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath))
|
|
149
152
|
return false;
|
|
150
153
|
return { key, bindingName: name };
|
|
151
154
|
}
|
|
@@ -154,14 +157,13 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
154
157
|
const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
|
|
155
158
|
if (!t.isVariableDeclarator(node))
|
|
156
159
|
return false;
|
|
157
|
-
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
|
|
160
|
+
if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath))
|
|
158
161
|
return false;
|
|
159
162
|
return { key, bindingName: key };
|
|
160
163
|
}
|
|
161
164
|
return null;
|
|
162
165
|
}
|
|
163
|
-
|
|
164
|
-
function isValidMediaCall(jsxPath, init, sourcePath) {
|
|
166
|
+
function isValidMediaCall(props, jsxPath, init, sourcePath) {
|
|
165
167
|
if (!t.isCallExpression(init))
|
|
166
168
|
return false;
|
|
167
169
|
if (!t.isIdentifier(init.callee))
|
|
@@ -175,14 +177,11 @@ function isValidMediaCall(jsxPath, init, sourcePath) {
|
|
|
175
177
|
const useMediaImport = mediaBinding.path.parent;
|
|
176
178
|
if (!t.isImportDeclaration(useMediaImport))
|
|
177
179
|
return false;
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
180
|
+
if (!(0, import_extractHelpers.isValidImport)(props, sourcePath)) {
|
|
181
|
+
return false;
|
|
182
182
|
}
|
|
183
183
|
return true;
|
|
184
184
|
}
|
|
185
|
-
__name(isValidMediaCall, "isValidMediaCall");
|
|
186
185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
187
186
|
0 && (module.exports = {
|
|
188
187
|
extractMediaStyle,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/extractor/extractMediaStyle.ts"],
|
|
4
|
+
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { TamaguiInternalConfig, getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'\nimport type { ViewStyle } from 'react-native'\n\nimport { MEDIA_SEP } from '../constants.js'\nimport type { StyleObject, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'\nimport { isPresent, isValidImport } from './extractHelpers.js'\n\nexport function extractMediaStyle(\n props: TamaguiOptionsWithFileInfo,\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n tamaguiConfig: TamaguiInternalConfig,\n sourcePath: string,\n importance = 0,\n shouldPrintDebug: boolean | 'verbose' = false\n) {\n const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)\n if (!mt) {\n return null\n }\n const { key } = mt\n const mq = tamaguiConfig.media[key]\n if (!mq) {\n // eslint-disable-next-line no-console\n console.error(`Media query \"${key}\" not found: ${Object.keys(tamaguiConfig.media)}`)\n return null\n }\n const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {\n return styleObj ? { styleObj, negate } : null\n }\n const styleOpts = [\n getStyleObj(ternary.consequent, false),\n getStyleObj(ternary.alternate, true),\n ].filter(isPresent)\n if (shouldPrintDebug && !styleOpts.length) {\n // eslint-disable-next-line no-console\n console.log(' media query, no styles?')\n return null\n }\n // for now order first strongest\n const mediaKeys = Object.keys(tamaguiConfig.media)\n const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {\n acc[cur] = new Array(importance + 1).fill(':root').join('')\n return acc\n }, {})\n let mediaStyles: StyleObject[] = []\n for (const { styleObj, negate } of styleOpts) {\n const styles = getStylesAtomic(styleObj)\n const singleMediaStyles = styles.map((style) => {\n const negKey = negate ? '0' : ''\n const ogPrefix = style.identifier.slice(0, style.identifier.indexOf('-') + 1)\n // adds an extra separator before and after to detect later in concatClassName\n // so it goes from: \"_f-[hash]\"\n // to: \"_f-_sm0_[hash]\" or \"_f-_sm_[hash]\"\n const identifier = `${style.identifier.replace(\n ogPrefix,\n `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`\n )}`\n const className = `.${identifier}`\n const mediaSelector = mediaObjectToString(tamaguiConfig.media[key])\n const screenStr = negate ? 'not all' : 'screen'\n const mediaQuery = `${screenStr} and ${mediaSelector}`\n const precendencePrefix = mediaKeyPrecendence[key]\n const styleInner = style.rules\n .map((rule) => rule.replace(style.identifier, identifier))\n .join(';')\n // combines media queries if they already exist\n let styleRule = ''\n if (styleInner.includes('@media')) {\n // combine\n styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)\n } else {\n styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`\n }\n return {\n ...style,\n identifier,\n className,\n rules: [styleRule],\n }\n })\n if (shouldPrintDebug === 'verbose') {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.log(' media styles:', importance, styleObj, singleMediaStyles.map(x => x.identifier).join(', '))\n }\n // add to output\n mediaStyles = [...mediaStyles, ...singleMediaStyles]\n }\n // filter out\n ternary.remove()\n return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }\n}\n\nfunction getMediaQueryTernary(\n props: TamaguiOptionsWithFileInfo,\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string\n): null | {\n key: string\n bindingName: string\n ternaryWithoutMedia: Ternary | null\n} {\n // this handles unwrapping logical && media query ternarys\n // first, unwrap if it has media logicalExpression\n if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {\n // *should* be normalized to always be on left side\n const mediaLeft = getMediaInfoFromExpression(\n props,\n ternary.test.left,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (mediaLeft) {\n return {\n ...mediaLeft,\n ternaryWithoutMedia: {\n ...ternary,\n test: ternary.test.right,\n },\n }\n }\n }\n // const media = useMedia()\n // ... media.sm\n const result = getMediaInfoFromExpression(\n props,\n ternary.test,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (result) {\n return {\n ...result,\n ternaryWithoutMedia: null,\n }\n }\n return null\n}\n\nfunction getMediaInfoFromExpression(\n props: TamaguiOptionsWithFileInfo,\n test: t.Expression,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string,\n inlineMediaQuery?: string\n) {\n if (inlineMediaQuery) {\n return {\n key: inlineMediaQuery,\n bindingName: inlineMediaQuery,\n }\n }\n if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {\n const name = test.object['name']\n const key = test.property['name']\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[name]\n if (!binding) return false\n const bindingNode = binding.path?.node\n if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false\n if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false\n return { key, bindingName: name }\n }\n if (t.isIdentifier(test)) {\n const key = test.name\n const node = jsxPath.scope.getBinding(test.name)?.path?.node\n if (!t.isVariableDeclarator(node)) return false\n if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath)) return false\n return { key, bindingName: key }\n }\n return null\n}\n\nexport function isValidMediaCall(\n props: TamaguiOptionsWithFileInfo,\n jsxPath: NodePath<t.JSXElement>,\n init: t.Expression,\n sourcePath: string\n) {\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useMedia by looking up import first\n if (init.callee.name !== 'useMedia') return false\n const bindings = jsxPath.scope.getAllBindings()\n const mediaBinding = bindings['useMedia']\n if (!mediaBinding) return false\n const useMediaImport = mediaBinding.path.parent\n if (!t.isImportDeclaration(useMediaImport)) return false\n if (!isValidImport(props, sourcePath)) {\n return false\n }\n return true\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,QAAmB;AACnB,uBAA4E;AAG5E,uBAA0B;AAE1B,4BAAyC;AAElC,SAAS,kBACd,OACA,SACA,SACA,eACA,YACA,aAAa,GACb,mBAAwC,OACxC;AACA,QAAM,KAAK,qBAAqB,OAAO,SAAS,SAAS,UAAU;AACnE,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,EACT;AACA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,KAAK,cAAc,MAAM;AAC/B,MAAI,CAAC,IAAI;AAEP,YAAQ,MAAM,gBAAgB,mBAAmB,OAAO,KAAK,cAAc,KAAK,GAAG;AACnF,WAAO;AAAA,EACT;AACA,QAAM,cAAc,CAAC,UAA4B,SAAS,UAAU;AAClE,WAAO,WAAW,EAAE,UAAU,OAAO,IAAI;AAAA,EAC3C;AACA,QAAM,YAAY;AAAA,IAChB,YAAY,QAAQ,YAAY,KAAK;AAAA,IACrC,YAAY,QAAQ,WAAW,IAAI;AAAA,EACrC,EAAE,OAAO,+BAAS;AAClB,MAAI,oBAAoB,CAAC,UAAU,QAAQ;AAEzC,YAAQ,IAAI,2BAA2B;AACvC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,KAAK,cAAc,KAAK;AACjD,QAAM,sBAAsB,UAAU,OAAO,CAAC,KAAK,KAAK,MAAM;AAC5D,QAAI,OAAO,IAAI,MAAM,aAAa,CAAC,EAAE,KAAK,OAAO,EAAE,KAAK,EAAE;AAC1D,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,MAAI,cAA6B,CAAC;AAClC,aAAW,EAAE,UAAU,OAAO,KAAK,WAAW;AAC5C,UAAM,aAAS,kCAAgB,QAAQ;AACvC,UA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