@tamagui/static 2.7.7 → 3.0.0-beta.643.1
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/check-dep-versions.cjs +355 -0
- package/dist/cjs/checkDeps.cjs +302 -0
- package/dist/cjs/compiler.cjs +286 -0
- package/dist/cjs/compilerHost.cjs +1695 -0
- package/dist/cjs/constants.cjs +33 -0
- package/dist/cjs/domStructuralPass.cjs +112 -0
- package/dist/cjs/exports.cjs +42 -0
- package/dist/cjs/extractor/addLocalExports.cjs +64 -0
- package/dist/cjs/extractor/bundle.cjs +203 -0
- package/dist/cjs/extractor/bundleConfig.cjs +747 -0
- package/dist/cjs/extractor/concatClassName.cjs +117 -0
- package/dist/cjs/extractor/detectModuleFormat.cjs +54 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.cjs +47 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +92 -0
- package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +38 -0
- package/dist/cjs/extractor/loadTamagui.cjs +344 -0
- package/dist/cjs/extractor/regenerateConfig.cjs +161 -0
- package/dist/cjs/extractor/watchTamaguiConfig.cjs +64 -0
- package/dist/cjs/getPragmaOptions.cjs +67 -0
- package/dist/cjs/helpers/memoize.cjs +42 -0
- package/dist/cjs/helpers/requireTamaguiCore.cjs +40 -0
- package/dist/cjs/index.cjs +34 -0
- package/dist/cjs/registerRequire.cjs +220 -0
- package/dist/cjs/server.cjs +66 -0
- package/dist/cjs/staticEvaluationIgnoredModules.cjs +86 -0
- package/dist/cjs/types.cjs +17 -0
- package/dist/cjs/zero/artifact.cjs +145 -0
- package/dist/cjs/zero/graph.cjs +209 -0
- package/dist/cjs/zero/identity.cjs +61 -0
- package/dist/cjs/zero/index.cjs +26 -0
- package/dist/cjs/zero/islands.cjs +232 -0
- package/dist/cjs/zero/options.cjs +163 -0
- package/dist/cjs/zero/ownership.cjs +79 -0
- package/dist/cjs/zero/theme.cjs +328 -0
- package/dist/cjs/zero/transform.cjs +203 -0
- package/dist/esm/check-dep-versions.mjs +329 -0
- package/dist/esm/check-dep-versions.mjs.map +1 -0
- package/dist/esm/checkDeps.mjs +279 -0
- package/dist/esm/checkDeps.mjs.map +1 -0
- package/dist/esm/compiler.mjs +255 -0
- package/dist/esm/compiler.mjs.map +1 -0
- package/dist/esm/compilerHost.mjs +1675 -0
- package/dist/esm/compilerHost.mjs.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/domStructuralPass.mjs +92 -0
- package/dist/esm/domStructuralPass.mjs.map +1 -0
- package/dist/esm/exports.mjs +26 -0
- package/dist/esm/extractor/addLocalExports.mjs +44 -0
- package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
- package/dist/esm/extractor/bundle.mjs +173 -0
- package/dist/esm/extractor/bundle.mjs.map +1 -0
- package/dist/esm/extractor/bundleConfig.mjs +706 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
- package/dist/esm/extractor/concatClassName.mjs +96 -0
- package/dist/esm/extractor/concatClassName.mjs.map +1 -0
- package/dist/esm/extractor/detectModuleFormat.mjs +31 -0
- package/dist/esm/extractor/detectModuleFormat.mjs.map +1 -0
- package/dist/esm/extractor/esbuildAliasPlugin.mjs +26 -0
- package/dist/esm/extractor/esbuildAliasPlugin.mjs.map +1 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.mjs +63 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.mjs.map +1 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +18 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
- package/dist/esm/extractor/loadTamagui.mjs +306 -0
- package/dist/esm/extractor/loadTamagui.mjs.map +1 -0
- package/dist/esm/extractor/regenerateConfig.mjs +131 -0
- package/dist/esm/extractor/regenerateConfig.mjs.map +1 -0
- package/dist/esm/extractor/watchTamaguiConfig.mjs +43 -0
- package/dist/esm/extractor/watchTamaguiConfig.mjs.map +1 -0
- package/dist/esm/getPragmaOptions.mjs +46 -0
- package/dist/esm/getPragmaOptions.mjs.map +1 -0
- package/dist/esm/helpers/memoize.mjs +21 -0
- package/dist/esm/helpers/memoize.mjs.map +1 -0
- package/dist/esm/helpers/requireTamaguiCore.mjs +19 -0
- package/dist/esm/helpers/requireTamaguiCore.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/registerRequire.mjs +195 -0
- package/dist/esm/registerRequire.mjs.map +1 -0
- package/dist/esm/server.mjs +40 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/esm/setup.mjs +0 -0
- package/dist/esm/staticEvaluationIgnoredModules.mjs +61 -0
- package/dist/esm/staticEvaluationIgnoredModules.mjs.map +1 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/zero/artifact.mjs +119 -0
- package/dist/esm/zero/artifact.mjs.map +1 -0
- package/dist/esm/zero/graph.mjs +170 -0
- package/dist/esm/zero/graph.mjs.map +1 -0
- package/dist/esm/zero/identity.mjs +36 -0
- package/dist/esm/zero/identity.mjs.map +1 -0
- package/dist/esm/zero/index.mjs +15 -0
- package/dist/esm/zero/islands.mjs +197 -0
- package/dist/esm/zero/islands.mjs.map +1 -0
- package/dist/esm/zero/options.mjs +129 -0
- package/dist/esm/zero/options.mjs.map +1 -0
- package/dist/esm/zero/ownership.mjs +48 -0
- package/dist/esm/zero/ownership.mjs.map +1 -0
- package/dist/esm/zero/theme.mjs +303 -0
- package/dist/esm/zero/theme.mjs.map +1 -0
- package/dist/esm/zero/transform.mjs +177 -0
- package/dist/esm/zero/transform.mjs.map +1 -0
- package/package.json +33 -43
- package/src/check-dep-versions.ts +2 -2
- package/src/checkDeps.ts +3 -2
- package/src/compiler.ts +425 -0
- package/src/compilerHost.ts +3125 -0
- package/src/constants.ts +0 -5
- package/src/domStructuralPass.ts +170 -0
- package/src/exports.ts +3 -6
- package/src/extractor/addLocalExports.ts +49 -0
- package/src/extractor/bundle.ts +20 -35
- package/src/extractor/bundleConfig.ts +334 -187
- package/src/extractor/concatClassName.ts +13 -20
- package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +5 -4
- package/src/extractor/loadTamagui.ts +196 -143
- package/src/extractor/regenerateConfig.ts +65 -13
- package/src/extractor/watchTamaguiConfig.ts +6 -1
- package/src/helpers/requireTamaguiCore.ts +6 -1
- package/src/registerRequire.ts +94 -132
- package/src/staticEvaluationIgnoredModules.ts +74 -0
- package/src/types.ts +2 -107
- package/src/zero/artifact.ts +142 -0
- package/src/zero/graph.ts +359 -0
- package/src/zero/identity.ts +73 -0
- package/src/zero/index.ts +8 -0
- package/src/zero/islands.ts +262 -0
- package/src/zero/options.ts +239 -0
- package/src/zero/ownership.ts +113 -0
- package/src/zero/theme.ts +478 -0
- package/src/zero/transform.ts +320 -0
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/compiler.d.ts +117 -0
- package/types/compiler.d.ts.map +1 -0
- package/types/compilerHost.d.ts +25 -0
- package/types/compilerHost.d.ts.map +1 -0
- package/types/constants.d.ts +0 -1
- package/types/constants.d.ts.map +1 -1
- package/types/domStructuralPass.d.ts +3 -0
- package/types/domStructuralPass.d.ts.map +1 -0
- package/types/exports.d.ts +3 -6
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/addLocalExports.d.ts +3 -0
- package/types/extractor/addLocalExports.d.ts.map +1 -0
- package/types/extractor/bundle.d.ts +66 -65
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +19 -4
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
- package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts +1 -1
- package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts.map +1 -1
- package/types/extractor/loadTamagui.d.ts +26 -3
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/extractor/regenerateConfig.d.ts +1 -1
- package/types/extractor/regenerateConfig.d.ts.map +1 -1
- package/types/extractor/watchTamaguiConfig.d.ts.map +1 -1
- package/types/getPragmaOptions.d.ts +1 -1
- package/types/helpers/memoize.d.ts +1 -1
- package/types/helpers/memoize.d.ts.map +1 -1
- package/types/helpers/requireTamaguiCore.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/registerRequire.d.ts +2 -2
- package/types/registerRequire.d.ts.map +1 -1
- package/types/staticEvaluationIgnoredModules.d.ts +9 -0
- package/types/staticEvaluationIgnoredModules.d.ts.map +1 -0
- package/types/types.d.ts +2 -90
- package/types/types.d.ts.map +1 -1
- package/types/zero/artifact.d.ts +44 -0
- package/types/zero/artifact.d.ts.map +1 -0
- package/types/zero/graph.d.ts +139 -0
- package/types/zero/graph.d.ts.map +1 -0
- package/types/zero/identity.d.ts +33 -0
- package/types/zero/identity.d.ts.map +1 -0
- package/types/zero/index.d.ts +9 -0
- package/types/zero/index.d.ts.map +1 -0
- package/types/zero/islands.d.ts +56 -0
- package/types/zero/islands.d.ts.map +1 -0
- package/types/zero/options.d.ts +58 -0
- package/types/zero/options.d.ts.map +1 -0
- package/types/zero/ownership.d.ts +51 -0
- package/types/zero/ownership.d.ts.map +1 -0
- package/types/zero/theme.d.ts +83 -0
- package/types/zero/theme.d.ts.map +1 -0
- package/types/zero/transform.d.ts +53 -0
- package/types/zero/transform.d.ts.map +1 -0
- package/dist/check-dep-versions.cjs +0 -372
- package/dist/checkDeps.cjs +0 -271
- package/dist/constants.cjs +0 -51
- package/dist/exports.cjs +0 -48
- package/dist/extractor/accessSafe.cjs +0 -48
- package/dist/extractor/babelParse.cjs +0 -56
- package/dist/extractor/buildClassName.cjs +0 -86
- package/dist/extractor/bundle.cjs +0 -234
- package/dist/extractor/bundleConfig.cjs +0 -729
- package/dist/extractor/concatClassName.cjs +0 -129
- package/dist/extractor/createEvaluator.cjs +0 -88
- package/dist/extractor/createExtractor.cjs +0 -1968
- package/dist/extractor/createLogger.cjs +0 -50
- package/dist/extractor/detectModuleFormat.cjs +0 -55
- package/dist/extractor/ensureImportingConcat.cjs +0 -54
- package/dist/extractor/errors.cjs +0 -28
- package/dist/extractor/esbuildAliasPlugin.cjs +0 -56
- package/dist/extractor/esbuildTsconfigPaths.cjs +0 -108
- package/dist/extractor/evaluateAstNode.cjs +0 -128
- package/dist/extractor/extractHelpers.cjs +0 -182
- package/dist/extractor/extractMediaStyle.cjs +0 -169
- package/dist/extractor/extractToClassNames.cjs +0 -475
- package/dist/extractor/extractToNative.cjs +0 -369
- package/dist/extractor/findTopmostFunction.cjs +0 -43
- package/dist/extractor/generatedUid.cjs +0 -58
- package/dist/extractor/getPrefixLogs.cjs +0 -31
- package/dist/extractor/getPropValueFromAttributes.cjs +0 -85
- package/dist/extractor/getSourceModule.cjs +0 -100
- package/dist/extractor/getStaticBindingsForScope.cjs +0 -213
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +0 -41
- package/dist/extractor/hasTopLevelAwait.cjs +0 -62
- package/dist/extractor/hoistClassNames.cjs +0 -76
- package/dist/extractor/literalToAst.cjs +0 -109
- package/dist/extractor/loadFile.cjs +0 -17
- package/dist/extractor/loadTamagui.cjs +0 -373
- package/dist/extractor/logLines.cjs +0 -43
- package/dist/extractor/normalizeTernaries.cjs +0 -100
- package/dist/extractor/propsToFontFamilyCache.cjs +0 -42
- package/dist/extractor/regenerateConfig.cjs +0 -178
- package/dist/extractor/removeUnusedHooks.cjs +0 -108
- package/dist/extractor/timer.cjs +0 -52
- package/dist/extractor/validHTMLAttributes.cjs +0 -79
- package/dist/extractor/watchTamaguiConfig.cjs +0 -70
- package/dist/getPragmaOptions.cjs +0 -73
- package/dist/helpers/memoize.cjs +0 -45
- package/dist/helpers/requireTamaguiCore.cjs +0 -40
- package/dist/index.cjs +0 -42
- package/dist/registerRequire.cjs +0 -209
- package/dist/server.cjs +0 -82
- package/dist/types.cjs +0 -18
- package/dist/worker.cjs +0 -111
- package/src/extractor/accessSafe.ts +0 -22
- package/src/extractor/babelParse.ts +0 -38
- package/src/extractor/buildClassName.ts +0 -76
- package/src/extractor/createEvaluator.ts +0 -82
- package/src/extractor/createExtractor.ts +0 -2970
- package/src/extractor/createLogger.ts +0 -41
- package/src/extractor/ensureImportingConcat.ts +0 -36
- package/src/extractor/errors.ts +0 -1
- package/src/extractor/evaluateAstNode.ts +0 -136
- package/src/extractor/extractHelpers.ts +0 -211
- package/src/extractor/extractMediaStyle.ts +0 -194
- package/src/extractor/extractToClassNames.ts +0 -733
- package/src/extractor/extractToNative.ts +0 -506
- package/src/extractor/findTopmostFunction.ts +0 -24
- package/src/extractor/generatedUid.ts +0 -41
- package/src/extractor/getPrefixLogs.ts +0 -9
- package/src/extractor/getPropValueFromAttributes.ts +0 -95
- package/src/extractor/getSourceModule.ts +0 -96
- package/src/extractor/getStaticBindingsForScope.ts +0 -237
- package/src/extractor/hasTopLevelAwait.ts +0 -28
- package/src/extractor/hoistClassNames.ts +0 -52
- package/src/extractor/literalToAst.ts +0 -85
- package/src/extractor/loadFile.ts +0 -17
- package/src/extractor/logLines.ts +0 -16
- package/src/extractor/normalizeTernaries.ts +0 -89
- package/src/extractor/propsToFontFamilyCache.ts +0 -18
- package/src/extractor/removeUnusedHooks.ts +0 -83
- package/src/extractor/timer.ts +0 -25
- package/src/extractor/validHTMLAttributes.ts +0 -52
- package/src/worker.ts +0 -142
- package/types/extractor/accessSafe.d.ts +0 -3
- package/types/extractor/accessSafe.d.ts.map +0 -1
- package/types/extractor/babelParse.d.ts +0 -5
- package/types/extractor/babelParse.d.ts.map +0 -1
- package/types/extractor/buildClassName.d.ts +0 -7
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/createEvaluator.d.ts +0 -12
- package/types/extractor/createEvaluator.d.ts.map +0 -1
- package/types/extractor/createExtractor.d.ts +0 -32
- package/types/extractor/createExtractor.d.ts.map +0 -1
- package/types/extractor/createLogger.d.ts +0 -3
- package/types/extractor/createLogger.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -4
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/errors.d.ts +0 -3
- package/types/extractor/errors.d.ts.map +0 -1
- package/types/extractor/evaluateAstNode.d.ts +0 -3
- package/types/extractor/evaluateAstNode.d.ts.map +0 -1
- package/types/extractor/extractHelpers.d.ts +0 -28
- package/types/extractor/extractHelpers.d.ts.map +0 -1
- package/types/extractor/extractMediaStyle.d.ts +0 -11
- package/types/extractor/extractMediaStyle.d.ts.map +0 -1
- package/types/extractor/extractToClassNames.d.ts +0 -25
- package/types/extractor/extractToClassNames.d.ts.map +0 -1
- package/types/extractor/extractToNative.d.ts +0 -13
- package/types/extractor/extractToNative.d.ts.map +0 -1
- package/types/extractor/findTopmostFunction.d.ts +0 -4
- package/types/extractor/findTopmostFunction.d.ts.map +0 -1
- package/types/extractor/generatedUid.d.ts +0 -5
- package/types/extractor/generatedUid.d.ts.map +0 -1
- package/types/extractor/getPrefixLogs.d.ts +0 -3
- package/types/extractor/getPrefixLogs.d.ts.map +0 -1
- package/types/extractor/getPropValueFromAttributes.d.ts +0 -19
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
- package/types/extractor/getSourceModule.d.ts +0 -16
- package/types/extractor/getSourceModule.d.ts.map +0 -1
- package/types/extractor/getStaticBindingsForScope.d.ts +0 -5
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
- package/types/extractor/hasTopLevelAwait.d.ts +0 -2
- package/types/extractor/hasTopLevelAwait.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts +0 -6
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
- package/types/extractor/literalToAst.d.ts +0 -4
- package/types/extractor/literalToAst.d.ts.map +0 -1
- package/types/extractor/loadFile.d.ts +0 -1
- package/types/extractor/loadFile.d.ts.map +0 -1
- package/types/extractor/logLines.d.ts +0 -2
- package/types/extractor/logLines.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts +0 -5
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/extractor/propsToFontFamilyCache.d.ts +0 -4
- package/types/extractor/propsToFontFamilyCache.d.ts.map +0 -1
- package/types/extractor/removeUnusedHooks.d.ts +0 -3
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
- package/types/extractor/timer.d.ts +0 -5
- package/types/extractor/timer.d.ts.map +0 -1
- package/types/extractor/validHTMLAttributes.d.ts +0 -52
- package/types/extractor/validHTMLAttributes.d.ts.map +0 -1
- package/types/worker.d.ts +0 -46
- package/types/worker.d.ts.map +0 -1
- /package/dist/{setup.cjs → cjs/setup.cjs} +0 -0
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
34
|
-
var extractMediaStyle_exports = {};
|
|
35
|
-
__export(extractMediaStyle_exports, {
|
|
36
|
-
extractMediaStyle: () => extractMediaStyle,
|
|
37
|
-
isValidMediaCall: () => isValidMediaCall
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(extractMediaStyle_exports);
|
|
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) {
|
|
45
|
-
const {
|
|
46
|
-
getCSSStylesAtomic
|
|
47
|
-
} = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
|
|
48
|
-
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath);
|
|
49
|
-
if (!mt) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const {
|
|
53
|
-
key
|
|
54
|
-
} = mt;
|
|
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 ? {
|
|
62
|
-
styleObj,
|
|
63
|
-
negate
|
|
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
|
-
}, {});
|
|
76
|
-
let mediaStyles = [];
|
|
77
|
-
for (const {
|
|
78
|
-
styleObj,
|
|
79
|
-
negate
|
|
80
|
-
} of styleOpts) {
|
|
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]}`;
|
|
85
|
-
return {
|
|
86
|
-
...mediaStyle,
|
|
87
|
-
className
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
if (shouldPrintDebug === "verbose") {
|
|
91
|
-
console.info(" media styles:", importance, styleObj, singleMediaStyles.map(x => x[core.StyleObjectIdentifier]).join(", "));
|
|
92
|
-
}
|
|
93
|
-
mediaStyles = [...mediaStyles, ...singleMediaStyles];
|
|
94
|
-
}
|
|
95
|
-
ternary.remove();
|
|
96
|
-
return {
|
|
97
|
-
mediaStyles,
|
|
98
|
-
ternaryWithoutMedia: mt.ternaryWithoutMedia
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function getMediaQueryTernary(props, ternary, jsxPath, sourcePath) {
|
|
102
|
-
if (t.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
|
|
103
|
-
const mediaLeft = getMediaInfoFromExpression(props, ternary.test.left, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
104
|
-
if (mediaLeft) {
|
|
105
|
-
return {
|
|
106
|
-
...mediaLeft,
|
|
107
|
-
ternaryWithoutMedia: {
|
|
108
|
-
...ternary,
|
|
109
|
-
test: ternary.test.right
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const result = getMediaInfoFromExpression(props, ternary.test, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
115
|
-
if (result) {
|
|
116
|
-
return {
|
|
117
|
-
...result,
|
|
118
|
-
ternaryWithoutMedia: null
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
function getMediaInfoFromExpression(props, test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
124
|
-
if (inlineMediaQuery) {
|
|
125
|
-
return {
|
|
126
|
-
key: inlineMediaQuery,
|
|
127
|
-
bindingName: inlineMediaQuery
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {
|
|
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;
|
|
136
|
-
const bindingNode = binding.path?.node;
|
|
137
|
-
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false;
|
|
138
|
-
if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false;
|
|
139
|
-
return {
|
|
140
|
-
key,
|
|
141
|
-
bindingName: name
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (t.isIdentifier(test)) {
|
|
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 {
|
|
150
|
-
key,
|
|
151
|
-
bindingName: key
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
function isValidMediaCall(props, jsxPath, init, sourcePath) {
|
|
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;
|
|
163
|
-
const useMediaImport = mediaBinding.path.parent;
|
|
164
|
-
if (!t.isImportDeclaration(useMediaImport)) return false;
|
|
165
|
-
if (!(0, import_extractHelpers.isValidImport)(props, sourcePath)) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
34
|
-
var extractToClassNames_exports = {};
|
|
35
|
-
__export(extractToClassNames_exports, {
|
|
36
|
-
extractToClassNames: () => extractToClassNames
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(extractToClassNames_exports);
|
|
39
|
-
var import_generator = __toESM(require("@babel/generator"));
|
|
40
|
-
var t = __toESM(require("@babel/types"));
|
|
41
|
-
var import_web = require("@tamagui/web");
|
|
42
|
-
var path = __toESM(require("node:path"));
|
|
43
|
-
var util = __toESM(require("node:util"));
|
|
44
|
-
var import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs");
|
|
45
|
-
var import_babelParse = require("./babelParse.cjs");
|
|
46
|
-
var import_createLogger = require("./createLogger.cjs");
|
|
47
|
-
var import_extractMediaStyle = require("./extractMediaStyle.cjs");
|
|
48
|
-
var import_normalizeTernaries = require("./normalizeTernaries.cjs");
|
|
49
|
-
var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
|
|
50
|
-
var import_timer = require("./timer.cjs");
|
|
51
|
-
var import_errors = require("./errors.cjs");
|
|
52
|
-
var import_concatClassName = require("./concatClassName.cjs");
|
|
53
|
-
const remove = () => {};
|
|
54
|
-
const spaceString = t.stringLiteral(" ");
|
|
55
|
-
async function extractToClassNames({
|
|
56
|
-
extractor,
|
|
57
|
-
source,
|
|
58
|
-
sourcePath = "",
|
|
59
|
-
options,
|
|
60
|
-
shouldPrintDebug
|
|
61
|
-
}) {
|
|
62
|
-
const tm = (0, import_timer.timer)();
|
|
63
|
-
const {
|
|
64
|
-
getCSSStylesAtomic,
|
|
65
|
-
createMediaStyle
|
|
66
|
-
} = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
|
|
67
|
-
if (sourcePath.includes("node_modules")) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
if (shouldPrintDebug) {
|
|
71
|
-
console.warn(`--- ${sourcePath} ---
|
|
72
|
-
|
|
73
|
-
`);
|
|
74
|
-
}
|
|
75
|
-
if (typeof source !== "string") {
|
|
76
|
-
throw new Error("`source` must be a string of javascript");
|
|
77
|
-
}
|
|
78
|
-
if (!path.isAbsolute(sourcePath)) {
|
|
79
|
-
throw new Error("`sourcePath` must be an absolute path to a .js file, got: " + sourcePath);
|
|
80
|
-
}
|
|
81
|
-
if (!/.[tj]sx?$/i.test(sourcePath || "")) {
|
|
82
|
-
console.warn(`${sourcePath.slice(0, 100)} - bad filename.`);
|
|
83
|
-
}
|
|
84
|
-
if (!options.disableExtraction && !options["_disableLoadTamagui"]) {
|
|
85
|
-
await extractor.loadTamagui(options);
|
|
86
|
-
}
|
|
87
|
-
const printLog = (0, import_createLogger.createLogger)(sourcePath, options);
|
|
88
|
-
let ast;
|
|
89
|
-
try {
|
|
90
|
-
ast = (0, import_babelParse.babelParse)(source, sourcePath);
|
|
91
|
-
} catch (err) {
|
|
92
|
-
console.error("babel parse error:", sourcePath.slice(0, 100));
|
|
93
|
-
throw err;
|
|
94
|
-
}
|
|
95
|
-
tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
|
|
96
|
-
const cssMap = /* @__PURE__ */new Map();
|
|
97
|
-
const tamaguiConfig = extractor.getTamagui();
|
|
98
|
-
const res = await extractor.parse(ast, {
|
|
99
|
-
shouldPrintDebug,
|
|
100
|
-
...options,
|
|
101
|
-
platform: "web",
|
|
102
|
-
sourcePath,
|
|
103
|
-
extractStyledDefinitions: true,
|
|
104
|
-
onStyledDefinitionRule(identifier, rules) {
|
|
105
|
-
const css = rules.join("\n");
|
|
106
|
-
if (shouldPrintDebug) {
|
|
107
|
-
console.info(`adding styled() rule: .${identifier} ${css}`);
|
|
108
|
-
}
|
|
109
|
-
cssMap.set(`.${identifier}`, {
|
|
110
|
-
css,
|
|
111
|
-
commentTexts: []
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
getFlattenedNode: ({
|
|
115
|
-
tag
|
|
116
|
-
}) => {
|
|
117
|
-
return tag;
|
|
118
|
-
},
|
|
119
|
-
onExtractTag: ({
|
|
120
|
-
parserProps,
|
|
121
|
-
attrs,
|
|
122
|
-
node,
|
|
123
|
-
attemptEval,
|
|
124
|
-
jsxPath,
|
|
125
|
-
originalNodeName,
|
|
126
|
-
filePath,
|
|
127
|
-
lineNumbers,
|
|
128
|
-
staticConfig
|
|
129
|
-
}) => {
|
|
130
|
-
if (staticConfig.acceptsClassName === false) {
|
|
131
|
-
throw new import_errors.BailOptimizationError();
|
|
132
|
-
}
|
|
133
|
-
const finalAttrs = [];
|
|
134
|
-
let mergeForwardBaseStyle = null;
|
|
135
|
-
let attrClassName = null;
|
|
136
|
-
let baseFontFamily = "";
|
|
137
|
-
let mediaStylesSeen = 1;
|
|
138
|
-
const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
|
|
139
|
-
let staticGroupName = null;
|
|
140
|
-
for (const attr of jsxPath.node.openingElement.attributes) {
|
|
141
|
-
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) continue;
|
|
142
|
-
if (attr.name.name !== "group") continue;
|
|
143
|
-
if (t.isStringLiteral(attr.value)) {
|
|
144
|
-
staticGroupName = attr.value.value;
|
|
145
|
-
} else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
|
|
146
|
-
staticGroupName = attr.value.expression.value;
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
if (staticGroupName) {
|
|
151
|
-
const containerIdentifier = `t_group_${staticGroupName}`;
|
|
152
|
-
const containerType = tamaguiConfig.settings?.webContainerType || "inline-size";
|
|
153
|
-
const containerSelector = `.${containerIdentifier}`;
|
|
154
|
-
if (!cssMap.has(containerSelector)) {
|
|
155
|
-
cssMap.set(containerSelector, {
|
|
156
|
-
css: `${containerSelector} { container-name: ${staticGroupName}; container-type: ${containerType}; }`,
|
|
157
|
-
commentTexts: [comment]
|
|
158
|
-
});
|
|
159
|
-
} else {
|
|
160
|
-
cssMap.get(containerSelector).commentTexts.push(comment);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
const hasCSSOnlyAnimationDriver = tamaguiConfig.animations.outputStyle === "css" && !tamaguiConfig.animationDrivers;
|
|
164
|
-
let elementIsAnimated = false;
|
|
165
|
-
for (const attr of jsxPath.node.openingElement.attributes) {
|
|
166
|
-
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) continue;
|
|
167
|
-
const n = attr.name.name;
|
|
168
|
-
if (n === "transition" && hasCSSOnlyAnimationDriver) continue;
|
|
169
|
-
if (n === "animation" || n === "transition" || n === "animateOnly" || n === "animatePresence" || n === "animatedBy" || n === "enterStyle" || n === "exitStyle") {
|
|
170
|
-
elementIsAnimated = true;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function addStyle(style) {
|
|
175
|
-
const identifier = style[import_web.StyleObjectIdentifier];
|
|
176
|
-
const rules = style[import_web.StyleObjectRules];
|
|
177
|
-
const selector = `.${identifier}`;
|
|
178
|
-
if (cssMap.has(selector)) {
|
|
179
|
-
const val = cssMap.get(selector);
|
|
180
|
-
val.commentTexts.push(comment);
|
|
181
|
-
} else if (rules.length) {
|
|
182
|
-
cssMap.set(selector, {
|
|
183
|
-
css: rules.join("\n"),
|
|
184
|
-
commentTexts: [comment]
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return identifier;
|
|
188
|
-
}
|
|
189
|
-
function addStyles(style) {
|
|
190
|
-
const cssStyles = getCSSStylesAtomic(style);
|
|
191
|
-
const classNames = [];
|
|
192
|
-
for (const style2 of cssStyles) {
|
|
193
|
-
const property = style2[0];
|
|
194
|
-
const mediaName = property.slice(1);
|
|
195
|
-
if (mediaName.startsWith("group-")) {
|
|
196
|
-
if (elementIsAnimated) {
|
|
197
|
-
throw new import_errors.BailOptimizationError();
|
|
198
|
-
}
|
|
199
|
-
const mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, "group", false, mediaStylesSeen);
|
|
200
|
-
const identifier2 = addStyle(mediaStyle);
|
|
201
|
-
classNames.push(identifier2);
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
|
|
205
|
-
if (mediaTypeMatch) {
|
|
206
|
-
const mediaType = mediaTypeMatch[1];
|
|
207
|
-
if (mediaType === "theme" && elementIsAnimated) {
|
|
208
|
-
throw new import_errors.BailOptimizationError();
|
|
209
|
-
}
|
|
210
|
-
const innerKey = mediaType === "theme" ? mediaName.slice("theme-".length) : mediaName;
|
|
211
|
-
const mediaStyle = createMediaStyle(style2, innerKey, extractor.getTamagui().media, mediaType, false, mediaStylesSeen);
|
|
212
|
-
const identifier2 = addStyle(mediaStyle);
|
|
213
|
-
classNames.push(identifier2);
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (mediaName in tamaguiConfig.media) {
|
|
217
|
-
const mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, true, false, mediaStylesSeen);
|
|
218
|
-
const identifier2 = addStyle(mediaStyle);
|
|
219
|
-
classNames.push(identifier2);
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
const identifier = addStyle(style2);
|
|
223
|
-
classNames.push(identifier);
|
|
224
|
-
}
|
|
225
|
-
return classNames;
|
|
226
|
-
}
|
|
227
|
-
const onlyTernaries = attrs.flatMap(attr => {
|
|
228
|
-
if (attr.type === "attr") {
|
|
229
|
-
const value = attr.value;
|
|
230
|
-
if (t.isJSXSpreadAttribute(value)) {
|
|
231
|
-
console.error(`Should never happen`);
|
|
232
|
-
return [];
|
|
233
|
-
}
|
|
234
|
-
if (value.name.name === "className") {
|
|
235
|
-
let inner = value.value;
|
|
236
|
-
if (t.isJSXExpressionContainer(inner)) {
|
|
237
|
-
inner = inner.expression;
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
const evaluatedValue = inner ? attemptEval(inner) : null;
|
|
241
|
-
if (typeof evaluatedValue === "string") {
|
|
242
|
-
attrClassName = t.stringLiteral(evaluatedValue);
|
|
243
|
-
}
|
|
244
|
-
} catch (e) {
|
|
245
|
-
if (inner) {
|
|
246
|
-
attrClassName ||= inner;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return [];
|
|
250
|
-
}
|
|
251
|
-
finalAttrs.push(value);
|
|
252
|
-
return [];
|
|
253
|
-
}
|
|
254
|
-
if (attr.type === "style") {
|
|
255
|
-
mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, attr.value);
|
|
256
|
-
baseFontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(attr.value) || "";
|
|
257
|
-
return [];
|
|
258
|
-
}
|
|
259
|
-
let ternary = attr.value;
|
|
260
|
-
if (ternary.inlineMediaQuery) {
|
|
261
|
-
const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.getTamagui(), sourcePath || "", mediaStylesSeen++, shouldPrintDebug);
|
|
262
|
-
if (mediaExtraction) {
|
|
263
|
-
if (mediaExtraction.mediaStyles) {
|
|
264
|
-
mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, {
|
|
265
|
-
[`$${ternary.inlineMediaQuery}`]: attr.value.consequent
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
if (mediaExtraction.ternaryWithoutMedia) {
|
|
269
|
-
ternary = mediaExtraction.ternaryWithoutMedia;
|
|
270
|
-
} else {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
let mergedAlternate;
|
|
276
|
-
let mergedConsequent;
|
|
277
|
-
if (ternary.alternate && Object.keys(ternary.alternate).length) {
|
|
278
|
-
mergedAlternate = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.alternate || {});
|
|
279
|
-
(0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.alternate, mergedAlternate, baseFontFamily);
|
|
280
|
-
}
|
|
281
|
-
if (ternary.consequent && Object.keys(ternary.consequent).length) {
|
|
282
|
-
mergedConsequent = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.consequent || {});
|
|
283
|
-
(0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.consequent, mergedConsequent, baseFontFamily);
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
...ternary,
|
|
287
|
-
alternate: mergedAlternate,
|
|
288
|
-
consequent: mergedConsequent
|
|
289
|
-
};
|
|
290
|
-
});
|
|
291
|
-
const hasTernaries = Boolean(onlyTernaries.length);
|
|
292
|
-
const baseClassNames = mergeForwardBaseStyle ? addStyles(mergeForwardBaseStyle) : null;
|
|
293
|
-
let baseClassNameStr = !baseClassNames ? "" : baseClassNames.join(" ");
|
|
294
|
-
if (baseFontFamily) {
|
|
295
|
-
baseClassNameStr = `font_${baseFontFamily}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
|
|
296
|
-
}
|
|
297
|
-
if (staticGroupName) {
|
|
298
|
-
baseClassNameStr = `t_group_${staticGroupName}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
|
|
299
|
-
}
|
|
300
|
-
const baseTypeClass = staticConfig.isText ? "is_Text" : "is_View";
|
|
301
|
-
baseClassNameStr = `${baseTypeClass}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
|
|
302
|
-
const componentNameFinal = staticConfig.componentName;
|
|
303
|
-
let base = componentNameFinal && componentNameFinal !== "Text" ? t.stringLiteral(`is_${componentNameFinal}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`) : t.stringLiteral(baseClassNameStr || "");
|
|
304
|
-
attrClassName = attrClassName;
|
|
305
|
-
const baseClassNameExpression = (() => {
|
|
306
|
-
if (attrClassName) {
|
|
307
|
-
if (t.isStringLiteral(attrClassName)) {
|
|
308
|
-
return t.stringLiteral(base.value ? `${base.value} ${attrClassName.value}` : attrClassName.value);
|
|
309
|
-
} else {
|
|
310
|
-
return t.binaryExpression("+", t.binaryExpression("+", attrClassName, spaceString), base);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return base;
|
|
314
|
-
})();
|
|
315
|
-
const expandedTernaries = [];
|
|
316
|
-
if (onlyTernaries.length) {
|
|
317
|
-
const normalizedTernaries = (0, import_normalizeTernaries.normalizeTernaries)(onlyTernaries);
|
|
318
|
-
for (const ternary of normalizedTernaries) {
|
|
319
|
-
if (!expandedTernaries.length) {
|
|
320
|
-
expandTernary(ternary);
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
const prevTernaries = [...expandedTernaries];
|
|
324
|
-
for (const prev of prevTernaries) {
|
|
325
|
-
expandTernary(ternary, prev);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function expandTernary(ternary, prev) {
|
|
330
|
-
if (ternary.consequent && Object.keys(ternary.consequent).length) {
|
|
331
|
-
const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.consequent);
|
|
332
|
-
expandedTernaries.push({
|
|
333
|
-
fontFamily,
|
|
334
|
-
// prevTest && test: merge consequent
|
|
335
|
-
test: prev ? t.logicalExpression("&&", prev.test, ternary.test) : ternary.test,
|
|
336
|
-
consequent: prev ? (0, import_web.mergeProps)(prev.consequent, ternary.consequent) : ternary.consequent,
|
|
337
|
-
remove,
|
|
338
|
-
alternate: null
|
|
339
|
-
});
|
|
340
|
-
if (prev) {
|
|
341
|
-
expandedTernaries.push({
|
|
342
|
-
fontFamily,
|
|
343
|
-
// !prevTest && test: just consequent
|
|
344
|
-
test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
|
|
345
|
-
consequent: ternary.consequent,
|
|
346
|
-
alternate: null,
|
|
347
|
-
remove
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (ternary.alternate && Object.keys(ternary.alternate).length) {
|
|
352
|
-
const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.alternate);
|
|
353
|
-
const negated = t.unaryExpression("!", ternary.test);
|
|
354
|
-
expandedTernaries.push({
|
|
355
|
-
fontFamily,
|
|
356
|
-
// prevTest && !test: merge alternate
|
|
357
|
-
test: prev ? t.logicalExpression("&&", prev.test, negated) : negated,
|
|
358
|
-
consequent: prev ? (0, import_web.mergeProps)(prev.alternate, ternary.alternate) : ternary.alternate,
|
|
359
|
-
remove,
|
|
360
|
-
alternate: null
|
|
361
|
-
});
|
|
362
|
-
if (prev) {
|
|
363
|
-
expandedTernaries.push({
|
|
364
|
-
fontFamily,
|
|
365
|
-
test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
|
|
366
|
-
consequent: ternary.alternate,
|
|
367
|
-
remove,
|
|
368
|
-
alternate: null
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
let ternaryClassNameExpr = null;
|
|
374
|
-
if (hasTernaries) {
|
|
375
|
-
for (const ternary of expandedTernaries) {
|
|
376
|
-
if (!ternary.consequent) continue;
|
|
377
|
-
const classNames = addStyles(ternary.consequent);
|
|
378
|
-
if (ternary.fontFamily) {
|
|
379
|
-
classNames.unshift(`font_${ternary.fontFamily}`);
|
|
380
|
-
}
|
|
381
|
-
const baseString = t.isStringLiteral(baseClassNameExpression) ? baseClassNameExpression.value : "";
|
|
382
|
-
const fullClassNameWithDups = (baseString ? `${baseString} ` : "") + classNames.join(" ");
|
|
383
|
-
const fullClassName = (0, import_concatClassName.concatClassName)(fullClassNameWithDups);
|
|
384
|
-
const classNameLiteral = t.stringLiteral(fullClassName);
|
|
385
|
-
if (!ternaryClassNameExpr) {
|
|
386
|
-
ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, baseClassNameExpression);
|
|
387
|
-
} else {
|
|
388
|
-
ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, ternaryClassNameExpr);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
let finalExpression = ternaryClassNameExpr || baseClassNameExpression || null;
|
|
393
|
-
if (shouldPrintDebug) {
|
|
394
|
-
console.info("attrs", JSON.stringify(attrs, null, 2));
|
|
395
|
-
console.info("expandedTernaries", JSON.stringify(expandedTernaries, null, 2));
|
|
396
|
-
console.info("finalExpression", JSON.stringify(finalExpression, null, 2));
|
|
397
|
-
console.info({
|
|
398
|
-
hasTernaries,
|
|
399
|
-
baseClassNameExpression
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
if (finalExpression) {
|
|
403
|
-
finalExpression = hoistClassNames(jsxPath, finalExpression);
|
|
404
|
-
const classNameProp = t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(finalExpression));
|
|
405
|
-
finalAttrs.unshift(classNameProp);
|
|
406
|
-
}
|
|
407
|
-
node.attributes = finalAttrs;
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) {
|
|
411
|
-
if (shouldPrintDebug) {
|
|
412
|
-
console.info("no res or none modified", res);
|
|
413
|
-
}
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
const styles = Array.from(cssMap.values()).map(x => x.css).join("\n").trim();
|
|
417
|
-
const result = (0, import_generator.default)(ast, {
|
|
418
|
-
concise: false,
|
|
419
|
-
filename: sourcePath,
|
|
420
|
-
// this makes the debug output terrible, and i think sourcemap works already
|
|
421
|
-
retainLines: false,
|
|
422
|
-
sourceFileName: sourcePath,
|
|
423
|
-
sourceMaps: true
|
|
424
|
-
}, source);
|
|
425
|
-
if (shouldPrintDebug) {
|
|
426
|
-
console.info("\n -------- output code ------- \n\n", result.code.split("\n").filter(x => !x.startsWith("//")).join("\n"));
|
|
427
|
-
console.info("\n -------- output style -------- \n\n", styles);
|
|
428
|
-
}
|
|
429
|
-
printLog(res);
|
|
430
|
-
return {
|
|
431
|
-
ast,
|
|
432
|
-
styles,
|
|
433
|
-
js: result.code,
|
|
434
|
-
map: result.map,
|
|
435
|
-
stats: {
|
|
436
|
-
styled: res.styled,
|
|
437
|
-
flattened: res.flattened,
|
|
438
|
-
optimized: res.optimized,
|
|
439
|
-
found: res.found
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
function hoistClassNames(path2, expr) {
|
|
444
|
-
if (t.isStringLiteral(expr)) {
|
|
445
|
-
return hoistClassName(path2, expr.value);
|
|
446
|
-
}
|
|
447
|
-
if (t.isLogicalExpression(expr)) {
|
|
448
|
-
const left = t.isStringLiteral(expr.left) ? hoistClassName(path2, expr.left.value) : expr.left;
|
|
449
|
-
const right = t.isStringLiteral(expr.right) ? hoistClassName(path2, expr.right.value) : hoistClassNames(path2, expr.right);
|
|
450
|
-
return t.logicalExpression(expr.operator, left, right);
|
|
451
|
-
}
|
|
452
|
-
if (t.isConditionalExpression(expr)) {
|
|
453
|
-
const cons = t.isStringLiteral(expr.consequent) ? hoistClassName(path2, expr.consequent.value) : hoistClassNames(path2, expr.consequent);
|
|
454
|
-
const alt = t.isStringLiteral(expr.alternate) ? hoistClassName(path2, expr.alternate.value) : hoistClassNames(path2, expr.alternate);
|
|
455
|
-
return t.conditionalExpression(expr.test, cons, alt);
|
|
456
|
-
}
|
|
457
|
-
return expr;
|
|
458
|
-
}
|
|
459
|
-
function hoistClassName(path2, str) {
|
|
460
|
-
const uid = path2.scope.generateUidIdentifier("cn");
|
|
461
|
-
const parent = path2.findParent(path3 => path3.isProgram());
|
|
462
|
-
if (!parent) throw new Error(`no program?`);
|
|
463
|
-
const variable = t.variableDeclaration("const", [t.variableDeclarator(uid, t.stringLiteral(cleanupClassName(str)))]);
|
|
464
|
-
parent.unshiftContainer("body", variable);
|
|
465
|
-
return uid;
|
|
466
|
-
}
|
|
467
|
-
function cleanupClassName(inStr) {
|
|
468
|
-
const out = /* @__PURE__ */new Set();
|
|
469
|
-
for (const part of inStr.split(" ")) {
|
|
470
|
-
if (!part || part === " ") continue;
|
|
471
|
-
if (part === "font_") continue;
|
|
472
|
-
out.add(part);
|
|
473
|
-
}
|
|
474
|
-
return [...out].join(" ");
|
|
475
|
-
}
|