@tamagui/static 2.0.0-rc.9 → 2.0.0
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/check-dep-versions.cjs +201 -96
- package/dist/checkDeps.cjs +250 -46
- package/dist/constants.cjs +32 -30
- package/dist/exports.cjs +20 -13
- package/dist/extractor/accessSafe.cjs +25 -23
- package/dist/extractor/babelParse.cjs +30 -28
- package/dist/extractor/buildClassName.cjs +59 -35
- package/dist/extractor/bundle.cjs +187 -101
- package/dist/extractor/bundleConfig.cjs +568 -168
- package/dist/extractor/concatClassName.cjs +73 -32
- package/dist/extractor/createEvaluator.cjs +54 -41
- package/dist/extractor/createExtractor.cjs +1405 -574
- package/dist/extractor/createLogger.cjs +30 -25
- package/dist/extractor/detectModuleFormat.cjs +55 -0
- package/dist/extractor/ensureImportingConcat.cjs +31 -25
- package/dist/extractor/errors.cjs +12 -10
- package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
- package/dist/extractor/esbuildTsconfigPaths.cjs +60 -36
- package/dist/extractor/evaluateAstNode.cjs +104 -59
- package/dist/extractor/extractHelpers.cjs +130 -67
- package/dist/extractor/extractMediaStyle.cjs +110 -69
- package/dist/extractor/extractToClassNames.cjs +337 -229
- package/dist/extractor/extractToNative.cjs +248 -152
- package/dist/extractor/findTopmostFunction.cjs +22 -13
- package/dist/extractor/generatedUid.cjs +39 -28
- package/dist/extractor/getPrefixLogs.cjs +12 -10
- package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
- package/dist/extractor/getSourceModule.cjs +73 -37
- package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +20 -14
- package/dist/extractor/hasTopLevelAwait.cjs +62 -0
- package/dist/extractor/hoistClassNames.cjs +46 -32
- package/dist/extractor/literalToAst.cjs +67 -42
- package/dist/extractor/loadFile.cjs +9 -3
- package/dist/extractor/loadTamagui.cjs +151 -105
- package/dist/extractor/logLines.cjs +27 -19
- package/dist/extractor/normalizeTernaries.cjs +66 -44
- package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
- package/dist/extractor/regenerateConfig.cjs +109 -81
- package/dist/extractor/removeUnusedHooks.cjs +73 -41
- package/dist/extractor/timer.cjs +23 -14
- package/dist/extractor/validHTMLAttributes.cjs +61 -59
- package/dist/extractor/watchTamaguiConfig.cjs +35 -23
- package/dist/getPragmaOptions.cjs +34 -19
- package/dist/helpers/memoize.cjs +24 -16
- package/dist/helpers/requireTamaguiCore.cjs +22 -15
- package/dist/index.cjs +26 -24
- package/dist/registerRequire.cjs +168 -65
- package/dist/server.cjs +35 -28
- package/dist/types.cjs +7 -5
- package/dist/worker.cjs +62 -40
- package/package.json +27 -24
- package/src/checkDeps.ts +305 -68
- package/src/exports.ts +2 -0
- package/src/extractor/babelParse.ts +1 -0
- package/src/extractor/bundle.ts +172 -40
- package/src/extractor/bundleConfig.ts +459 -65
- package/src/extractor/concatClassName.ts +37 -20
- package/src/extractor/createExtractor.ts +300 -30
- package/src/extractor/detectModuleFormat.ts +42 -0
- package/src/extractor/esbuildTsconfigPaths.ts +6 -1
- package/src/extractor/extractToClassNames.ts +15 -9
- package/src/extractor/extractToNative.ts +65 -32
- package/src/extractor/hasTopLevelAwait.ts +28 -0
- package/src/extractor/loadTamagui.ts +5 -4
- package/src/registerRequire.ts +102 -9
- package/types/checkDeps.d.ts.map +1 -1
- package/types/exports.d.ts +2 -0
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +83 -1
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +15 -2
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/detectModuleFormat.d.ts +5 -0
- package/types/extractor/detectModuleFormat.d.ts.map +1 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts +8 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/hasTopLevelAwait.d.ts +2 -0
- package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +1 -1
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/registerRequire.d.ts.map +1 -1
- package/dist/check-dep-versions.js +0 -389
- package/dist/check-dep-versions.js.map +0 -6
- package/dist/checkDeps.js +0 -60
- package/dist/checkDeps.js.map +0 -6
- package/dist/constants.js +0 -34
- package/dist/constants.js.map +0 -6
- package/dist/exports.js +0 -34
- package/dist/exports.js.map +0 -6
- package/dist/extractor/accessSafe.js +0 -47
- package/dist/extractor/accessSafe.js.map +0 -6
- package/dist/extractor/babelParse.js +0 -59
- package/dist/extractor/babelParse.js.map +0 -6
- package/dist/extractor/buildClassName.js +0 -72
- package/dist/extractor/buildClassName.js.map +0 -6
- package/dist/extractor/bundle.js +0 -135
- package/dist/extractor/bundle.js.map +0 -6
- package/dist/extractor/bundleConfig.js +0 -352
- package/dist/extractor/bundleConfig.js.map +0 -6
- package/dist/extractor/concatClassName.js +0 -69
- package/dist/extractor/concatClassName.js.map +0 -6
- package/dist/extractor/createEvaluator.js +0 -66
- package/dist/extractor/createEvaluator.js.map +0 -6
- package/dist/extractor/createExtractor.js +0 -1212
- package/dist/extractor/createExtractor.js.map +0 -6
- package/dist/extractor/createLogger.js +0 -32
- package/dist/extractor/createLogger.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.js +0 -50
- package/dist/extractor/ensureImportingConcat.js.map +0 -6
- package/dist/extractor/errors.js +0 -22
- package/dist/extractor/errors.js.map +0 -6
- package/dist/extractor/esbuildAliasPlugin.js +0 -36
- package/dist/extractor/esbuildAliasPlugin.js.map +0 -6
- package/dist/extractor/esbuildTsconfigPaths.js +0 -79
- package/dist/extractor/esbuildTsconfigPaths.js.map +0 -6
- package/dist/extractor/evaluateAstNode.js +0 -99
- package/dist/extractor/evaluateAstNode.js.map +0 -6
- package/dist/extractor/extractHelpers.js +0 -108
- package/dist/extractor/extractHelpers.js.map +0 -6
- package/dist/extractor/extractMediaStyle.js +0 -123
- package/dist/extractor/extractMediaStyle.js.map +0 -6
- package/dist/extractor/extractToClassNames.js +0 -351
- package/dist/extractor/extractToClassNames.js.map +0 -6
- package/dist/extractor/extractToNative.js +0 -286
- package/dist/extractor/extractToNative.js.map +0 -6
- package/dist/extractor/findTopmostFunction.js +0 -32
- package/dist/extractor/findTopmostFunction.js.map +0 -6
- package/dist/extractor/generatedUid.js +0 -42
- package/dist/extractor/generatedUid.js.map +0 -6
- package/dist/extractor/getPrefixLogs.js +0 -24
- package/dist/extractor/getPrefixLogs.js.map +0 -6
- package/dist/extractor/getPropValueFromAttributes.js +0 -65
- package/dist/extractor/getPropValueFromAttributes.js.map +0 -6
- package/dist/extractor/getSourceModule.js +0 -62
- package/dist/extractor/getSourceModule.js.map +0 -6
- package/dist/extractor/getStaticBindingsForScope.js +0 -145
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -6
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js +0 -32
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js.map +0 -6
- package/dist/extractor/hoistClassNames.js +0 -63
- package/dist/extractor/hoistClassNames.js.map +0 -6
- package/dist/extractor/literalToAst.js +0 -90
- package/dist/extractor/literalToAst.js.map +0 -6
- package/dist/extractor/loadFile.js +0 -14
- package/dist/extractor/loadFile.js.map +0 -6
- package/dist/extractor/loadTamagui.js +0 -306
- package/dist/extractor/loadTamagui.js.map +0 -6
- package/dist/extractor/logLines.js +0 -30
- package/dist/extractor/logLines.js.map +0 -6
- package/dist/extractor/normalizeTernaries.js +0 -61
- package/dist/extractor/normalizeTernaries.js.map +0 -6
- package/dist/extractor/propsToFontFamilyCache.js +0 -33
- package/dist/extractor/propsToFontFamilyCache.js.map +0 -6
- package/dist/extractor/regenerateConfig.js +0 -123
- package/dist/extractor/regenerateConfig.js.map +0 -6
- package/dist/extractor/removeUnusedHooks.js +0 -72
- package/dist/extractor/removeUnusedHooks.js.map +0 -6
- package/dist/extractor/timer.js +0 -38
- package/dist/extractor/timer.js.map +0 -6
- package/dist/extractor/validHTMLAttributes.js +0 -72
- package/dist/extractor/validHTMLAttributes.js.map +0 -6
- package/dist/extractor/watchTamaguiConfig.js +0 -57
- package/dist/extractor/watchTamaguiConfig.js.map +0 -6
- package/dist/getPragmaOptions.js +0 -50
- package/dist/getPragmaOptions.js.map +0 -6
- package/dist/helpers/memoize.js +0 -33
- package/dist/helpers/memoize.js.map +0 -6
- package/dist/helpers/requireTamaguiCore.js +0 -30
- package/dist/helpers/requireTamaguiCore.js.map +0 -6
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -6
- package/dist/registerRequire.js +0 -100
- package/dist/registerRequire.js.map +0 -6
- package/dist/server.js +0 -58
- package/dist/server.js.map +0 -6
- package/dist/setup.js +0 -1
- package/dist/setup.js.map +0 -6
- package/dist/types.js +0 -14
- package/dist/types.js.map +0 -6
- package/dist/worker.js +0 -72
- package/dist/worker.js.map +0 -6
|
@@ -2,33 +2,35 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var extractHelpers_exports = {};
|
|
33
35
|
__export(extractHelpers_exports, {
|
|
34
36
|
attrStr: () => attrStr,
|
|
@@ -47,73 +49,134 @@ __export(extractHelpers_exports, {
|
|
|
47
49
|
ternaryStr: () => ternaryStr
|
|
48
50
|
});
|
|
49
51
|
module.exports = __toCommonJS(extractHelpers_exports);
|
|
50
|
-
var import_node_path = require("node:path")
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
var import_node_path = require("node:path");
|
|
53
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
54
|
+
var t = __toESM(require("@babel/types"));
|
|
55
|
+
var import_find_root = __toESM(require("find-root"));
|
|
56
|
+
var import_memoize = require("../helpers/memoize.cjs");
|
|
55
57
|
function isPresent(input) {
|
|
56
58
|
return input != null;
|
|
57
59
|
}
|
|
58
60
|
function isSimpleSpread(node) {
|
|
59
61
|
return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument);
|
|
60
62
|
}
|
|
61
|
-
const attrStr = attr =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const attrStr = attr => {
|
|
64
|
+
return !attr ? "" : attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
65
|
+
};
|
|
66
|
+
const objToStr = (obj, spacer = ", ") => {
|
|
67
|
+
if (!obj) {
|
|
68
|
+
return `${obj}`;
|
|
69
|
+
}
|
|
70
|
+
return `{${Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `${objToStr(v, ",")}` : JSON.stringify(v)}`).join(spacer)}}`;
|
|
71
|
+
};
|
|
72
|
+
const getNameAttr = attr => {
|
|
73
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
74
|
+
return `...${attr.argument["name"]}`;
|
|
75
|
+
}
|
|
76
|
+
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
77
|
+
};
|
|
78
|
+
const ternaryStr = x => {
|
|
79
|
+
const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] :
|
|
65
80
|
// @ts-ignore
|
|
66
|
-
(0, import_generator.default)(x.test).code
|
|
67
|
-
isFilledObj
|
|
81
|
+
(0, import_generator.default)(x.test).code;
|
|
82
|
+
return ["ternary(", conditional, isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}", isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}", ")"].flat().join("");
|
|
83
|
+
};
|
|
84
|
+
const isFilledObj = obj => obj && Object.keys(obj).length;
|
|
68
85
|
function findComponentName(scope) {
|
|
86
|
+
const componentName = "";
|
|
69
87
|
let cur = scope.path;
|
|
70
|
-
|
|
88
|
+
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
89
|
+
cur = cur.parentPath;
|
|
90
|
+
}
|
|
71
91
|
let node = cur.parent;
|
|
72
|
-
if (t.isExportNamedDeclaration(node)
|
|
92
|
+
if (t.isExportNamedDeclaration(node)) {
|
|
93
|
+
node = node.declaration;
|
|
94
|
+
}
|
|
95
|
+
if (t.isVariableDeclaration(node)) {
|
|
73
96
|
const [dec] = node.declarations;
|
|
74
|
-
if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id))
|
|
97
|
+
if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {
|
|
98
|
+
return dec.id.name;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (t.isFunctionDeclaration(node)) {
|
|
102
|
+
return node.id?.name;
|
|
75
103
|
}
|
|
76
|
-
return
|
|
104
|
+
return componentName;
|
|
77
105
|
}
|
|
78
106
|
function isValidThemeHook(props, jsxPath, n, sourcePath) {
|
|
79
|
-
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return
|
|
80
|
-
const
|
|
81
|
-
|
|
107
|
+
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false;
|
|
108
|
+
const bindings = jsxPath.scope.getAllBindings();
|
|
109
|
+
const binding = bindings[n.object.name];
|
|
110
|
+
if (!binding?.path) return false;
|
|
111
|
+
if (!binding.path.isVariableDeclarator()) return false;
|
|
82
112
|
const init = binding.path.node.init;
|
|
83
|
-
if (!init || !t.isCallExpression(init)
|
|
113
|
+
if (!init || !t.isCallExpression(init)) return false;
|
|
114
|
+
if (!t.isIdentifier(init.callee)) return false;
|
|
115
|
+
if (init.callee.name !== "useTheme") return false;
|
|
84
116
|
const importNode = binding.scope.getBinding("useTheme")?.path.parent;
|
|
85
|
-
|
|
117
|
+
if (!t.isImportDeclaration(importNode)) return false;
|
|
118
|
+
if (sourcePath && !isValidImport(props, sourcePath)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
86
122
|
}
|
|
87
|
-
const isInsideComponentPackage = (props, moduleName) =>
|
|
88
|
-
|
|
123
|
+
const isInsideComponentPackage = (props, moduleName) => {
|
|
124
|
+
return getValidComponentsPaths(props).some(path => {
|
|
125
|
+
return moduleName.startsWith(path);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const isComponentPackage = (props, srcName) => {
|
|
129
|
+
return getValidComponentsPaths(props).some(path => {
|
|
130
|
+
return srcName.startsWith(path);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
89
133
|
function getValidComponent(props, moduleName, componentName) {
|
|
90
|
-
if (componentName[0].toUpperCase() !== componentName[0])
|
|
134
|
+
if (componentName[0].toUpperCase() !== componentName[0]) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
91
137
|
for (const loaded of props.allLoadedComponents) {
|
|
92
138
|
if (!loaded) continue;
|
|
93
|
-
const isInModule = moduleName === "*" || moduleName.startsWith(loaded.moduleName)
|
|
94
|
-
|
|
95
|
-
if (isInModule && foundComponent)
|
|
139
|
+
const isInModule = moduleName === "*" || moduleName.startsWith(loaded.moduleName);
|
|
140
|
+
const foundComponent = loaded.nameToInfo[componentName];
|
|
141
|
+
if (isInModule && foundComponent) {
|
|
142
|
+
return foundComponent;
|
|
143
|
+
}
|
|
96
144
|
}
|
|
97
145
|
return null;
|
|
98
146
|
}
|
|
99
147
|
const isValidModule = (props, moduleName) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
148
|
+
if (typeof moduleName !== "string") {
|
|
149
|
+
throw new Error(`No module name`);
|
|
150
|
+
}
|
|
151
|
+
const isLocal = moduleName.startsWith(".");
|
|
152
|
+
return {
|
|
153
|
+
isLocal,
|
|
154
|
+
isValid: isLocal ? isInsideComponentPackage(props, moduleName) : isComponentPackage(props, moduleName)
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const getValidImport = (props, moduleName, componentName) => {
|
|
158
|
+
const {
|
|
159
|
+
isValid,
|
|
160
|
+
isLocal
|
|
161
|
+
} = isValidModule(props, moduleName);
|
|
162
|
+
if (!isValid || !componentName) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return getValidComponent(props, isLocal ? "*" : moduleName, componentName) || null;
|
|
166
|
+
};
|
|
167
|
+
const isValidImport = (props, moduleName, componentName) => {
|
|
168
|
+
if (!componentName) {
|
|
169
|
+
return isValidModule(props, moduleName).isValid;
|
|
170
|
+
}
|
|
171
|
+
return Boolean(getValidImport(props, moduleName, componentName));
|
|
172
|
+
};
|
|
173
|
+
const getValidComponentPackages = (0, import_memoize.memoize)(props => {
|
|
174
|
+
return [... /* @__PURE__ */new Set(["@tamagui/core", "tamagui", ...(props.components || [])])];
|
|
175
|
+
});
|
|
176
|
+
const getValidComponentsPaths = (0, import_memoize.memoize)(props => {
|
|
177
|
+
return getValidComponentPackages(props).flatMap(pkg => {
|
|
117
178
|
const root = (0, import_find_root.default)(pkg);
|
|
118
|
-
|
|
119
|
-
|
|
179
|
+
const based = (0, import_node_path.basename)(root);
|
|
180
|
+
return [based, pkg].filter(Boolean);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -2,76 +2,98 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var extractMediaStyle_exports = {};
|
|
33
35
|
__export(extractMediaStyle_exports, {
|
|
34
36
|
extractMediaStyle: () => extractMediaStyle,
|
|
35
37
|
isValidMediaCall: () => isValidMediaCall
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(extractMediaStyle_exports);
|
|
38
|
-
var t = __toESM(require("@babel/types"))
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function extractMediaStyle(props, ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug =
|
|
40
|
+
var t = __toESM(require("@babel/types"));
|
|
41
|
+
var core = __toESM(require("@tamagui/core"));
|
|
42
|
+
var import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs");
|
|
43
|
+
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
44
|
+
function extractMediaStyle(props, ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
|
|
43
45
|
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!mt)
|
|
46
|
+
getCSSStylesAtomic
|
|
47
|
+
} = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
|
|
48
|
+
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath);
|
|
49
|
+
if (!mt) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
48
52
|
const {
|
|
49
53
|
key
|
|
50
54
|
} = mt;
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
const mq = tamaguiConfig.media[key];
|
|
56
|
+
if (!mq) {
|
|
57
|
+
console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const getStyleObj = (styleObj, negate = false) => {
|
|
61
|
+
return styleObj ? {
|
|
53
62
|
styleObj,
|
|
54
63
|
negate
|
|
55
|
-
} : null
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
} : null;
|
|
65
|
+
};
|
|
66
|
+
const styleOpts = [getStyleObj(ternary.consequent, false), getStyleObj(ternary.alternate, true)].filter(import_extractHelpers.isPresent);
|
|
67
|
+
if (shouldPrintDebug && !styleOpts.length) {
|
|
68
|
+
console.info(" media query, no styles?");
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const mediaKeys = Object.keys(tamaguiConfig.media);
|
|
72
|
+
const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
|
|
73
|
+
acc[cur] = new Array(importance + 1).fill(":root").join("");
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
59
76
|
let mediaStyles = [];
|
|
60
77
|
for (const {
|
|
61
78
|
styleObj,
|
|
62
79
|
negate
|
|
63
80
|
} of styleOpts) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
const styles = getCSSStylesAtomic(styleObj);
|
|
82
|
+
const singleMediaStyles = styles.map(style => {
|
|
83
|
+
const mediaStyle = core.createMediaStyle(style, key, tamaguiConfig.media, true, negate);
|
|
84
|
+
const className = `.${mediaStyle[core.StyleObjectIdentifier]}`;
|
|
67
85
|
return {
|
|
68
86
|
...mediaStyle,
|
|
69
87
|
className
|
|
70
88
|
};
|
|
71
89
|
});
|
|
72
|
-
shouldPrintDebug === "verbose"
|
|
90
|
+
if (shouldPrintDebug === "verbose") {
|
|
91
|
+
console.info(" media styles:", importance, styleObj, singleMediaStyles.map(x => x[core.StyleObjectIdentifier]).join(", "));
|
|
92
|
+
}
|
|
93
|
+
mediaStyles = [...mediaStyles, ...singleMediaStyles];
|
|
73
94
|
}
|
|
74
|
-
|
|
95
|
+
ternary.remove();
|
|
96
|
+
return {
|
|
75
97
|
mediaStyles,
|
|
76
98
|
ternaryWithoutMedia: mt.ternaryWithoutMedia
|
|
77
99
|
};
|
|
@@ -79,40 +101,52 @@ function extractMediaStyle(props, ternary, jsxPath, tamaguiConfig, sourcePath, i
|
|
|
79
101
|
function getMediaQueryTernary(props, ternary, jsxPath, sourcePath) {
|
|
80
102
|
if (t.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
|
|
81
103
|
const mediaLeft = getMediaInfoFromExpression(props, ternary.test.left, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
82
|
-
if (mediaLeft)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
if (mediaLeft) {
|
|
105
|
+
return {
|
|
106
|
+
...mediaLeft,
|
|
107
|
+
ternaryWithoutMedia: {
|
|
108
|
+
...ternary,
|
|
109
|
+
test: ternary.test.right
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
89
113
|
}
|
|
90
114
|
const result = getMediaInfoFromExpression(props, ternary.test, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
if (result) {
|
|
116
|
+
return {
|
|
117
|
+
...result,
|
|
118
|
+
ternaryWithoutMedia: null
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
95
122
|
}
|
|
96
123
|
function getMediaInfoFromExpression(props, test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
97
|
-
if (inlineMediaQuery)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
if (inlineMediaQuery) {
|
|
125
|
+
return {
|
|
126
|
+
key: inlineMediaQuery,
|
|
127
|
+
bindingName: inlineMediaQuery
|
|
128
|
+
};
|
|
129
|
+
}
|
|
101
130
|
if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {
|
|
102
|
-
const name = test.object
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
const name = test.object["name"];
|
|
132
|
+
const key = test.property["name"];
|
|
133
|
+
const bindings = jsxPath.scope.getAllBindings();
|
|
134
|
+
const binding = bindings[name];
|
|
135
|
+
if (!binding) return false;
|
|
106
136
|
const bindingNode = binding.path?.node;
|
|
107
|
-
|
|
137
|
+
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false;
|
|
138
|
+
if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false;
|
|
139
|
+
return {
|
|
108
140
|
key,
|
|
109
141
|
bindingName: name
|
|
110
142
|
};
|
|
111
143
|
}
|
|
112
144
|
if (t.isIdentifier(test)) {
|
|
113
|
-
const key = test.name
|
|
114
|
-
|
|
115
|
-
|
|
145
|
+
const key = test.name;
|
|
146
|
+
const node = jsxPath.scope.getBinding(test.name)?.path?.node;
|
|
147
|
+
if (!t.isVariableDeclarator(node)) return false;
|
|
148
|
+
if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath)) return false;
|
|
149
|
+
return {
|
|
116
150
|
key,
|
|
117
151
|
bindingName: key
|
|
118
152
|
};
|
|
@@ -120,9 +154,16 @@ function getMediaInfoFromExpression(props, test, jsxPath, sourcePath, inlineMedi
|
|
|
120
154
|
return null;
|
|
121
155
|
}
|
|
122
156
|
function isValidMediaCall(props, jsxPath, init, sourcePath) {
|
|
123
|
-
if (!init || !t.isCallExpression(init)
|
|
124
|
-
|
|
125
|
-
if (
|
|
157
|
+
if (!init || !t.isCallExpression(init)) return false;
|
|
158
|
+
if (!t.isIdentifier(init.callee)) return false;
|
|
159
|
+
if (init.callee.name !== "useMedia") return false;
|
|
160
|
+
const bindings = jsxPath.scope.getAllBindings();
|
|
161
|
+
const mediaBinding = bindings["useMedia"];
|
|
162
|
+
if (!mediaBinding) return false;
|
|
126
163
|
const useMediaImport = mediaBinding.path.parent;
|
|
127
|
-
|
|
164
|
+
if (!t.isImportDeclaration(useMediaImport)) return false;
|
|
165
|
+
if (!(0, import_extractHelpers.isValidImport)(props, sourcePath)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
128
169
|
}
|