@tamagui/static 2.7.7 → 3.0.0-beta.1093.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 +354 -0
- package/dist/cjs/checkDeps.cjs +301 -0
- package/dist/cjs/compiler.cjs +349 -0
- package/dist/cjs/compilerHost.cjs +2285 -0
- package/dist/cjs/componentDiscovery.cjs +94 -0
- package/dist/cjs/constants.cjs +32 -0
- package/dist/cjs/domStructuralPass.cjs +121 -0
- package/dist/cjs/exports.cjs +44 -0
- package/dist/cjs/extractor/addLocalExports.cjs +63 -0
- package/dist/cjs/extractor/bundle.cjs +229 -0
- package/dist/cjs/extractor/bundleConfig.cjs +769 -0
- package/dist/cjs/extractor/concatClassName.cjs +120 -0
- package/dist/cjs/extractor/detectModuleFormat.cjs +53 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.cjs +46 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +91 -0
- package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +42 -0
- package/dist/cjs/extractor/loadTamagui.cjs +394 -0
- package/dist/cjs/extractor/regenerateConfig.cjs +160 -0
- package/dist/cjs/extractor/watchTamaguiConfig.cjs +63 -0
- package/dist/cjs/getPragmaOptions.cjs +66 -0
- package/dist/cjs/helpers/memoize.cjs +41 -0
- package/dist/cjs/helpers/requireTamaguiCore.cjs +39 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/registerRequire.cjs +219 -0
- package/dist/cjs/server.cjs +65 -0
- package/dist/cjs/staticEvaluationIgnoredModules.cjs +85 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/zero/artifact.cjs +144 -0
- package/dist/cjs/zero/graph.cjs +208 -0
- package/dist/cjs/zero/identity.cjs +60 -0
- package/dist/cjs/zero/index.cjs +33 -0
- package/dist/cjs/zero/islands.cjs +234 -0
- package/dist/cjs/zero/options.cjs +162 -0
- package/dist/cjs/zero/ownership.cjs +78 -0
- package/dist/cjs/zero/theme.cjs +337 -0
- package/dist/cjs/zero/transform.cjs +207 -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 +319 -0
- package/dist/esm/compiler.mjs.map +1 -0
- package/dist/esm/compilerHost.mjs +2263 -0
- package/dist/esm/compilerHost.mjs.map +1 -0
- package/dist/esm/componentDiscovery.mjs +69 -0
- package/dist/esm/componentDiscovery.mjs.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/domStructuralPass.mjs +102 -0
- package/dist/esm/domStructuralPass.mjs.map +1 -0
- package/dist/esm/exports.mjs +29 -0
- package/dist/esm/extractor/addLocalExports.mjs +44 -0
- package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
- package/dist/esm/extractor/bundle.mjs +199 -0
- package/dist/esm/extractor/bundle.mjs.map +1 -0
- package/dist/esm/extractor/bundleConfig.mjs +728 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
- package/dist/esm/extractor/concatClassName.mjs +100 -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 +23 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
- package/dist/esm/extractor/loadTamagui.mjs +357 -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 +19 -0
- package/dist/esm/zero/islands.mjs +200 -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 +313 -0
- package/dist/esm/zero/theme.mjs.map +1 -0
- package/dist/esm/zero/transform.mjs +182 -0
- package/dist/esm/zero/transform.mjs.map +1 -0
- package/package.json +38 -47
- package/src/check-dep-versions.ts +2 -2
- package/src/checkDeps.ts +3 -2
- package/src/compiler.ts +506 -0
- package/src/compilerHost.ts +3752 -0
- package/src/componentDiscovery.ts +105 -0
- package/src/constants.ts +0 -5
- package/src/domStructuralPass.ts +190 -0
- package/src/exports.ts +5 -6
- package/src/extractor/addLocalExports.ts +49 -0
- package/src/extractor/bundle.ts +38 -40
- package/src/extractor/bundleConfig.ts +368 -187
- package/src/extractor/concatClassName.ts +21 -24
- package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +13 -5
- 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 +9 -0
- package/src/zero/islands.ts +265 -0
- package/src/zero/options.ts +239 -0
- package/src/zero/ownership.ts +113 -0
- package/src/zero/theme.ts +526 -0
- package/src/zero/transform.ts +329 -0
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/compiler.d.ts +134 -0
- package/types/compiler.d.ts.map +1 -0
- package/types/compilerHost.d.ts +38 -0
- package/types/compilerHost.d.ts.map +1 -0
- package/types/componentDiscovery.d.ts +27 -0
- package/types/componentDiscovery.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 +5 -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 +26 -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 +10 -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 +85 -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
|
@@ -0,0 +1,2263 @@
|
|
|
1
|
+
import { collectLeaves, zeroRuleMessage, zeroThemeBoundaryMessage } from "@tamagui/compiler-core";
|
|
2
|
+
import { StyleObjectIdentifier, StyleObjectProperty, StyleObjectRules, StyleObjectValue, stylePropsAll, stylePropsInput, stylePropsText, validStyles } from "@tamagui/helpers";
|
|
3
|
+
import { ATTRIBUTES, DISPLAY_WEB_RESET, EVENTS, NATIVE_BACKING, NATIVE_BLOCK_DEFAULTS, NATIVE_ELEMENT_DEFAULTS, NATIVE_FLEX_DEFAULTS, NATIVE_INPUT_TYPES, NATIVE_PRIMITIVE_MODULE, TAGS, TAG_WEB_DEFAULTS } from "@tamagui/dom";
|
|
4
|
+
import { resolveTransition, toCSSTransition } from "@tamagui/animation-helpers";
|
|
5
|
+
import { createModifierRegistry, parseTransition, parseValue } from "@tamagui/style-grammar/tooling";
|
|
6
|
+
import { isValidStyleKey } from "@tamagui/web";
|
|
7
|
+
import { concatClassName } from "./extractor/concatClassName.mjs";
|
|
8
|
+
import { requireTamaguiCore } from "./helpers/requireTamaguiCore.mjs";
|
|
9
|
+
|
|
10
|
+
function createComponentRegistry(components, componentModules) {
|
|
11
|
+
return {
|
|
12
|
+
modulesById: new Map(componentModules.map((module) => [module.resolvedId, module.moduleName])),
|
|
13
|
+
componentsByModule: new Map(components.map((component) => [component.moduleName, component]))
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const DOM_FRONTENDS = /* @__PURE__ */ new Set([
|
|
17
|
+
"tamagui",
|
|
18
|
+
"tamagui/dom",
|
|
19
|
+
"@tamagui/core",
|
|
20
|
+
"@tamagui/core/dom",
|
|
21
|
+
"@tamagui/tailwind"
|
|
22
|
+
]);
|
|
23
|
+
const componentState = {
|
|
24
|
+
focus: false,
|
|
25
|
+
focusVisible: false,
|
|
26
|
+
focusWithin: false,
|
|
27
|
+
hover: false,
|
|
28
|
+
unmounted: true,
|
|
29
|
+
press: false,
|
|
30
|
+
pressIn: false,
|
|
31
|
+
disabled: false
|
|
32
|
+
};
|
|
33
|
+
function staticObject(value) {
|
|
34
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
const flatClausePattern = /(?:^|\s)@?[A-Za-z][A-Za-z0-9-]*(?:\/[A-Za-z0-9_-]+)?:/;
|
|
37
|
+
const nativeInheritedKeywordPattern = /(?:^|:)(?:inherit|unset)(?=\s|$)/;
|
|
38
|
+
const nativeInitialKeywordPattern = /(?:^|:)initial(?=\s|$)/;
|
|
39
|
+
const nativeRuntimeOnlyStyleProperties = /* @__PURE__ */ new Set(["textIndent"]);
|
|
40
|
+
function componentKey(resolvedId, exportName) {
|
|
41
|
+
return `${resolvedId}#${exportName}`;
|
|
42
|
+
}
|
|
43
|
+
function cssFromRules(rules) {
|
|
44
|
+
return Object.values(rules).flatMap((styleObject) => {
|
|
45
|
+
const identifier = styleObject?.[StyleObjectIdentifier];
|
|
46
|
+
const styleRules = styleObject?.[StyleObjectRules];
|
|
47
|
+
return identifier && Array.isArray(styleRules) ? styleRules : [];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function jsxClassName(value) {
|
|
51
|
+
return `className=${JSON.stringify(value)}`;
|
|
52
|
+
}
|
|
53
|
+
function objectClassName(value) {
|
|
54
|
+
return `className: ${JSON.stringify(value)}`;
|
|
55
|
+
}
|
|
56
|
+
function serializedStyle(style, dynamicProperties) {
|
|
57
|
+
if (dynamicProperties.length === 0) return style ? JSON.stringify(style) : "";
|
|
58
|
+
return `{ ${[...style ? Object.entries(style).map(([name, value]) => `${JSON.stringify(name)}: ${JSON.stringify(value)}`) : [], ...dynamicProperties].join(", ")} }`;
|
|
59
|
+
}
|
|
60
|
+
function jsxStyleAttributes(className, style, dynamicProperties = []) {
|
|
61
|
+
const serialized = serializedStyle(style, dynamicProperties);
|
|
62
|
+
return [className ? jsxClassName(className) : "", serialized ? `style={${serialized}}` : ""].filter(Boolean).join(" ");
|
|
63
|
+
}
|
|
64
|
+
function objectStyleProperties(className, style, dynamicProperties = []) {
|
|
65
|
+
const serialized = serializedStyle(style, dynamicProperties);
|
|
66
|
+
return [className ? objectClassName(className) : "", serialized ? `style: ${serialized}` : ""].filter(Boolean).join(", ");
|
|
67
|
+
}
|
|
68
|
+
function extractedStyleArtifacts(split, props, config, includeRuntimeBase = true, hasStyleFrontend = false) {
|
|
69
|
+
const callerClassName = !hasStyleFrontend && typeof props.className === "string" ? props.className : "";
|
|
70
|
+
const viewClassName = typeof split.viewProps?.className === "string" ? split.viewProps.className : "";
|
|
71
|
+
const classNameWithoutCaller = callerClassName && viewClassName.endsWith(callerClassName) ? viewClassName.slice(0, -callerClassName.length).trimEnd() : viewClassName;
|
|
72
|
+
const rules = split.rulesToInsert ?? {};
|
|
73
|
+
const mediaNames = new Set(Object.keys(config.media ?? {}));
|
|
74
|
+
const pseudoNames = [
|
|
75
|
+
"hover",
|
|
76
|
+
"press",
|
|
77
|
+
"focus",
|
|
78
|
+
"focusVisible",
|
|
79
|
+
"focusWithin",
|
|
80
|
+
"disabled"
|
|
81
|
+
];
|
|
82
|
+
const buckets = {
|
|
83
|
+
group: [],
|
|
84
|
+
normal: [],
|
|
85
|
+
pseudo: [],
|
|
86
|
+
theme: [],
|
|
87
|
+
media: []
|
|
88
|
+
};
|
|
89
|
+
const classKeys = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const [key, identifier] of Object.entries(split.classNames ?? {})) {
|
|
91
|
+
if (typeof identifier === "string") classKeys.set(identifier, key);
|
|
92
|
+
}
|
|
93
|
+
const identifiers = /* @__PURE__ */ new Set([...classKeys.keys(), ...Object.values(rules).flatMap((styleObject) => {
|
|
94
|
+
const identifier = styleObject?.[StyleObjectIdentifier];
|
|
95
|
+
return typeof identifier === "string" ? [identifier] : [];
|
|
96
|
+
})]);
|
|
97
|
+
for (const identifier of identifiers) {
|
|
98
|
+
const key = classKeys.get(identifier) ?? "";
|
|
99
|
+
const css2 = cssFromRules(Object.fromEntries(Object.entries(rules).filter(([, styleObject]) => styleObject?.[StyleObjectIdentifier] === identifier))).join("");
|
|
100
|
+
if (identifier.startsWith("t_group_")) {
|
|
101
|
+
buckets.group.push(identifier);
|
|
102
|
+
} else if (pseudoNames.some((name) => key.endsWith(`-${name}`))) {
|
|
103
|
+
buckets.pseudo.push(identifier);
|
|
104
|
+
} else if (css2.includes(".t_")) {
|
|
105
|
+
buckets.theme.push(identifier);
|
|
106
|
+
} else if ([...mediaNames].some((name) => key.endsWith(`-${name}`))) {
|
|
107
|
+
buckets.media.push(identifier);
|
|
108
|
+
} else {
|
|
109
|
+
buckets.normal.push(identifier);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const orderedIdentifiers = [
|
|
113
|
+
...buckets.group,
|
|
114
|
+
...buckets.normal,
|
|
115
|
+
...buckets.pseudo,
|
|
116
|
+
...buckets.theme,
|
|
117
|
+
...buckets.media
|
|
118
|
+
];
|
|
119
|
+
const orderedSet = new Set(orderedIdentifiers);
|
|
120
|
+
const baseViewClassName = includeRuntimeBase ? classNameWithoutCaller.split(/\s+/).filter((token) => token && !orderedSet.has(token)).join(" ") : "";
|
|
121
|
+
const css = orderedIdentifiers.flatMap((identifier) => {
|
|
122
|
+
const identifierRules = cssFromRules(Object.fromEntries(Object.entries(rules).filter(([, styleObject]) => styleObject?.[StyleObjectIdentifier] === identifier)));
|
|
123
|
+
return buckets.theme.includes(identifier) ? identifierRules.map((rule) => rule.replace(":root:root:root.t_", ":root:root:root:root.t_")) : identifierRules;
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
className: concatClassName(baseViewClassName, orderedIdentifiers, callerClassName),
|
|
127
|
+
css
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function spreadNonStyleReplacement(form, entry, isPropIgnored, rewriteProp) {
|
|
131
|
+
if (entry.kind !== "spread" || entry.value.kind !== "static" || !staticObject(entry.value.value)) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
const nonStyleEntries = Object.entries(entry.value.value).filter(([key]) => !isPropIgnored(key)).map(([key, value]) => rewriteProp(key, value));
|
|
135
|
+
if (nonStyleEntries.length === 0) return "";
|
|
136
|
+
const objectSource = `{ ${nonStyleEntries.map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)}`).join(", ")} }`;
|
|
137
|
+
return form === "jsx" ? `{...${objectSource}}` : `...${objectSource}`;
|
|
138
|
+
}
|
|
139
|
+
function compiledPropsEdits(input, styleEntries, replacement, spreadReplacement) {
|
|
140
|
+
const propsSpan = input.element.propsSpan;
|
|
141
|
+
if (!propsSpan) return null;
|
|
142
|
+
const original = input.source.slice(propsSpan.start, propsSpan.end);
|
|
143
|
+
const trimmed = original.trim();
|
|
144
|
+
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
|
|
145
|
+
return [{
|
|
146
|
+
start: propsSpan.start,
|
|
147
|
+
end: propsSpan.end,
|
|
148
|
+
content: `{ ${replacement} }`,
|
|
149
|
+
origin: propsSpan
|
|
150
|
+
}];
|
|
151
|
+
}
|
|
152
|
+
if (styleEntries.length === 0) {
|
|
153
|
+
const close = original.lastIndexOf("}");
|
|
154
|
+
const separator = original.slice(1, close).trim() ? ", " : " ";
|
|
155
|
+
const position = propsSpan.start + close;
|
|
156
|
+
return [{
|
|
157
|
+
start: position,
|
|
158
|
+
end: position,
|
|
159
|
+
content: `${separator}${replacement} `,
|
|
160
|
+
origin: propsSpan
|
|
161
|
+
}];
|
|
162
|
+
}
|
|
163
|
+
const edits = [];
|
|
164
|
+
for (const [index, entry] of styleEntries.entries()) {
|
|
165
|
+
let start = entry.span.start;
|
|
166
|
+
let end = entry.span.end;
|
|
167
|
+
const nonStyle = spreadReplacement?.(entry) ?? "";
|
|
168
|
+
if (index === 0) {
|
|
169
|
+
const content = [replacement, nonStyle].filter(Boolean).join(", ");
|
|
170
|
+
edits.push({
|
|
171
|
+
start,
|
|
172
|
+
end,
|
|
173
|
+
content,
|
|
174
|
+
origin: entry.span
|
|
175
|
+
});
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
let cursor = end - propsSpan.start;
|
|
179
|
+
while (cursor < original.length - 1 && /\s/.test(original[cursor])) cursor++;
|
|
180
|
+
if (original[cursor] === ",") {
|
|
181
|
+
end = propsSpan.start + cursor + 1;
|
|
182
|
+
} else {
|
|
183
|
+
cursor = start - propsSpan.start - 1;
|
|
184
|
+
while (cursor > 0 && /\s/.test(original[cursor])) cursor--;
|
|
185
|
+
if (original[cursor] === ",") start = propsSpan.start + cursor;
|
|
186
|
+
}
|
|
187
|
+
edits.push({
|
|
188
|
+
start,
|
|
189
|
+
end,
|
|
190
|
+
content: nonStyle,
|
|
191
|
+
origin: entry.span
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const merged = [];
|
|
195
|
+
for (const edit of edits.sort((left, right) => left.start - right.start)) {
|
|
196
|
+
const previous = merged.at(-1);
|
|
197
|
+
if (previous && edit.start <= previous.end && !previous.content && !edit.content) {
|
|
198
|
+
previous.end = Math.max(previous.end, edit.end);
|
|
199
|
+
} else {
|
|
200
|
+
merged.push(edit);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return merged;
|
|
204
|
+
}
|
|
205
|
+
const compilerStyleProps = /* @__PURE__ */ new Set([
|
|
206
|
+
"className",
|
|
207
|
+
"style",
|
|
208
|
+
"group",
|
|
209
|
+
"transition",
|
|
210
|
+
"animation",
|
|
211
|
+
"animatePresence",
|
|
212
|
+
"animatedBy",
|
|
213
|
+
"fontFamily",
|
|
214
|
+
"render"
|
|
215
|
+
]);
|
|
216
|
+
const runtimeAnimationProps = /* @__PURE__ */ new Set([
|
|
217
|
+
"transition",
|
|
218
|
+
"animation",
|
|
219
|
+
"animatePresence",
|
|
220
|
+
"animatedBy"
|
|
221
|
+
]);
|
|
222
|
+
const componentOnlyProps = /* @__PURE__ */ new Set([
|
|
223
|
+
"asChild",
|
|
224
|
+
"disableOptimization",
|
|
225
|
+
"themeInverse"
|
|
226
|
+
]);
|
|
227
|
+
const cssShorthandConflicts = {
|
|
228
|
+
background: [
|
|
229
|
+
"backgroundAttachment",
|
|
230
|
+
"backgroundBlendMode",
|
|
231
|
+
"backgroundClip",
|
|
232
|
+
"backgroundColor",
|
|
233
|
+
"backgroundImage",
|
|
234
|
+
"backgroundOrigin",
|
|
235
|
+
"backgroundPosition",
|
|
236
|
+
"backgroundRepeat",
|
|
237
|
+
"backgroundSize"
|
|
238
|
+
],
|
|
239
|
+
border: [
|
|
240
|
+
"borderTop",
|
|
241
|
+
"borderTopColor",
|
|
242
|
+
"borderTopStyle",
|
|
243
|
+
"borderTopWidth",
|
|
244
|
+
"borderRight",
|
|
245
|
+
"borderRightColor",
|
|
246
|
+
"borderRightStyle",
|
|
247
|
+
"borderRightWidth",
|
|
248
|
+
"borderBottom",
|
|
249
|
+
"borderBottomColor",
|
|
250
|
+
"borderBottomStyle",
|
|
251
|
+
"borderBottomWidth",
|
|
252
|
+
"borderLeft",
|
|
253
|
+
"borderLeftColor",
|
|
254
|
+
"borderLeftStyle",
|
|
255
|
+
"borderLeftWidth",
|
|
256
|
+
"borderColor",
|
|
257
|
+
"borderStyle",
|
|
258
|
+
"borderWidth",
|
|
259
|
+
"borderImage",
|
|
260
|
+
"borderImageOutset",
|
|
261
|
+
"borderImageRepeat",
|
|
262
|
+
"borderImageSlice",
|
|
263
|
+
"borderImageSource",
|
|
264
|
+
"borderImageWidth",
|
|
265
|
+
"borderInlineColor",
|
|
266
|
+
"borderInlineEndColor",
|
|
267
|
+
"borderInlineEndStyle",
|
|
268
|
+
"borderInlineEndWidth",
|
|
269
|
+
"borderInlineStartColor",
|
|
270
|
+
"borderInlineStartStyle",
|
|
271
|
+
"borderInlineStartWidth",
|
|
272
|
+
"borderInlineStyle",
|
|
273
|
+
"borderInlineWidth"
|
|
274
|
+
],
|
|
275
|
+
borderTop: [
|
|
276
|
+
"borderTopColor",
|
|
277
|
+
"borderTopStyle",
|
|
278
|
+
"borderTopWidth"
|
|
279
|
+
],
|
|
280
|
+
borderRight: [
|
|
281
|
+
"borderRightColor",
|
|
282
|
+
"borderRightStyle",
|
|
283
|
+
"borderRightWidth",
|
|
284
|
+
"borderInlineColor",
|
|
285
|
+
"borderInlineEndColor",
|
|
286
|
+
"borderInlineEndStyle",
|
|
287
|
+
"borderInlineEndWidth",
|
|
288
|
+
"borderInlineStartColor",
|
|
289
|
+
"borderInlineStartStyle",
|
|
290
|
+
"borderInlineStartWidth",
|
|
291
|
+
"borderInlineStyle",
|
|
292
|
+
"borderInlineWidth"
|
|
293
|
+
],
|
|
294
|
+
borderBottom: [
|
|
295
|
+
"borderBottomColor",
|
|
296
|
+
"borderBottomStyle",
|
|
297
|
+
"borderBottomWidth"
|
|
298
|
+
],
|
|
299
|
+
borderLeft: [
|
|
300
|
+
"borderLeftColor",
|
|
301
|
+
"borderLeftStyle",
|
|
302
|
+
"borderLeftWidth",
|
|
303
|
+
"borderInlineColor",
|
|
304
|
+
"borderInlineEndColor",
|
|
305
|
+
"borderInlineEndStyle",
|
|
306
|
+
"borderInlineEndWidth",
|
|
307
|
+
"borderInlineStartColor",
|
|
308
|
+
"borderInlineStartStyle",
|
|
309
|
+
"borderInlineStartWidth",
|
|
310
|
+
"borderInlineStyle",
|
|
311
|
+
"borderInlineWidth"
|
|
312
|
+
],
|
|
313
|
+
borderImage: [
|
|
314
|
+
"borderImageOutset",
|
|
315
|
+
"borderImageRepeat",
|
|
316
|
+
"borderImageSlice",
|
|
317
|
+
"borderImageSource",
|
|
318
|
+
"borderImageWidth"
|
|
319
|
+
],
|
|
320
|
+
outline: [
|
|
321
|
+
"outlineColor",
|
|
322
|
+
"outlineStyle",
|
|
323
|
+
"outlineWidth"
|
|
324
|
+
],
|
|
325
|
+
gap: ["columnGap", "rowGap"],
|
|
326
|
+
gridColumn: ["gridColumnEnd", "gridColumnStart"],
|
|
327
|
+
gridRow: ["gridRowEnd", "gridRowStart"],
|
|
328
|
+
marginInline: [
|
|
329
|
+
"marginInlineEnd",
|
|
330
|
+
"marginInlineStart",
|
|
331
|
+
"marginEnd",
|
|
332
|
+
"marginStart",
|
|
333
|
+
"marginLeft",
|
|
334
|
+
"marginRight"
|
|
335
|
+
],
|
|
336
|
+
paddingInline: [
|
|
337
|
+
"paddingInlineEnd",
|
|
338
|
+
"paddingInlineStart",
|
|
339
|
+
"paddingEnd",
|
|
340
|
+
"paddingStart",
|
|
341
|
+
"paddingLeft",
|
|
342
|
+
"paddingRight"
|
|
343
|
+
],
|
|
344
|
+
insetInline: [
|
|
345
|
+
"insetInlineEnd",
|
|
346
|
+
"insetInlineStart",
|
|
347
|
+
"end",
|
|
348
|
+
"start",
|
|
349
|
+
"left",
|
|
350
|
+
"right"
|
|
351
|
+
],
|
|
352
|
+
borderInlineColor: [
|
|
353
|
+
"borderInlineEndColor",
|
|
354
|
+
"borderInlineStartColor",
|
|
355
|
+
"borderEndColor",
|
|
356
|
+
"borderStartColor",
|
|
357
|
+
"borderLeftColor",
|
|
358
|
+
"borderRightColor"
|
|
359
|
+
],
|
|
360
|
+
borderInlineStyle: [
|
|
361
|
+
"borderInlineEndStyle",
|
|
362
|
+
"borderInlineStartStyle",
|
|
363
|
+
"borderEndStyle",
|
|
364
|
+
"borderStartStyle",
|
|
365
|
+
"borderLeftStyle",
|
|
366
|
+
"borderRightStyle"
|
|
367
|
+
],
|
|
368
|
+
borderInlineWidth: [
|
|
369
|
+
"borderInlineEndWidth",
|
|
370
|
+
"borderInlineStartWidth",
|
|
371
|
+
"borderEndWidth",
|
|
372
|
+
"borderStartWidth",
|
|
373
|
+
"borderLeftWidth",
|
|
374
|
+
"borderRightWidth"
|
|
375
|
+
],
|
|
376
|
+
mask: [
|
|
377
|
+
"maskBorder",
|
|
378
|
+
"maskBorderMode",
|
|
379
|
+
"maskBorderOutset",
|
|
380
|
+
"maskBorderRepeat",
|
|
381
|
+
"maskBorderSlice",
|
|
382
|
+
"maskBorderSource",
|
|
383
|
+
"maskBorderWidth",
|
|
384
|
+
"maskClip",
|
|
385
|
+
"maskComposite",
|
|
386
|
+
"maskImage",
|
|
387
|
+
"maskMode",
|
|
388
|
+
"maskOrigin",
|
|
389
|
+
"maskPosition",
|
|
390
|
+
"maskRepeat",
|
|
391
|
+
"maskSize"
|
|
392
|
+
],
|
|
393
|
+
maskBorder: [
|
|
394
|
+
"maskBorderMode",
|
|
395
|
+
"maskBorderOutset",
|
|
396
|
+
"maskBorderRepeat",
|
|
397
|
+
"maskBorderSlice",
|
|
398
|
+
"maskBorderSource",
|
|
399
|
+
"maskBorderWidth"
|
|
400
|
+
]
|
|
401
|
+
};
|
|
402
|
+
const cssConflictFamilies = [
|
|
403
|
+
/* @__PURE__ */ new Set(["width", "inlineSize"]),
|
|
404
|
+
/* @__PURE__ */ new Set(["minWidth", "minInlineSize"]),
|
|
405
|
+
/* @__PURE__ */ new Set(["maxWidth", "maxInlineSize"]),
|
|
406
|
+
/* @__PURE__ */ new Set(["height", "blockSize"]),
|
|
407
|
+
/* @__PURE__ */ new Set(["minHeight", "minBlockSize"]),
|
|
408
|
+
/* @__PURE__ */ new Set(["maxHeight", "maxBlockSize"]),
|
|
409
|
+
/* @__PURE__ */ new Set([
|
|
410
|
+
"marginInline",
|
|
411
|
+
"marginInlineEnd",
|
|
412
|
+
"marginInlineStart",
|
|
413
|
+
"marginEnd",
|
|
414
|
+
"marginStart",
|
|
415
|
+
"marginLeft",
|
|
416
|
+
"marginRight"
|
|
417
|
+
]),
|
|
418
|
+
/* @__PURE__ */ new Set([
|
|
419
|
+
"paddingInline",
|
|
420
|
+
"paddingInlineEnd",
|
|
421
|
+
"paddingInlineStart",
|
|
422
|
+
"paddingEnd",
|
|
423
|
+
"paddingStart",
|
|
424
|
+
"paddingLeft",
|
|
425
|
+
"paddingRight"
|
|
426
|
+
]),
|
|
427
|
+
/* @__PURE__ */ new Set([
|
|
428
|
+
"insetInline",
|
|
429
|
+
"insetInlineEnd",
|
|
430
|
+
"insetInlineStart",
|
|
431
|
+
"end",
|
|
432
|
+
"start",
|
|
433
|
+
"left",
|
|
434
|
+
"right"
|
|
435
|
+
]),
|
|
436
|
+
/* @__PURE__ */ new Set([
|
|
437
|
+
"borderInlineColor",
|
|
438
|
+
"borderInlineEndColor",
|
|
439
|
+
"borderInlineStartColor",
|
|
440
|
+
"borderEndColor",
|
|
441
|
+
"borderStartColor",
|
|
442
|
+
"borderLeftColor",
|
|
443
|
+
"borderRightColor"
|
|
444
|
+
]),
|
|
445
|
+
/* @__PURE__ */ new Set([
|
|
446
|
+
"borderInlineStyle",
|
|
447
|
+
"borderInlineEndStyle",
|
|
448
|
+
"borderInlineStartStyle",
|
|
449
|
+
"borderEndStyle",
|
|
450
|
+
"borderStartStyle",
|
|
451
|
+
"borderLeftStyle",
|
|
452
|
+
"borderRightStyle"
|
|
453
|
+
]),
|
|
454
|
+
/* @__PURE__ */ new Set([
|
|
455
|
+
"borderInlineWidth",
|
|
456
|
+
"borderInlineEndWidth",
|
|
457
|
+
"borderInlineStartWidth",
|
|
458
|
+
"borderEndWidth",
|
|
459
|
+
"borderStartWidth",
|
|
460
|
+
"borderLeftWidth",
|
|
461
|
+
"borderRightWidth"
|
|
462
|
+
])
|
|
463
|
+
];
|
|
464
|
+
function cssOwnersConflict(left, right) {
|
|
465
|
+
for (const leftOwner of left) {
|
|
466
|
+
for (const rightOwner of right) {
|
|
467
|
+
if (leftOwner === rightOwner || cssShorthandConflicts[leftOwner]?.includes(rightOwner) || cssShorthandConflicts[rightOwner]?.includes(leftOwner) || cssConflictFamilies.some((family) => family.has(leftOwner) && family.has(rightOwner))) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
const runtimeEventProps = /* @__PURE__ */ new Set([
|
|
475
|
+
"onHoverIn",
|
|
476
|
+
"onHoverOut",
|
|
477
|
+
"onLongPress",
|
|
478
|
+
"onPress",
|
|
479
|
+
"onPressIn",
|
|
480
|
+
"onPressOut"
|
|
481
|
+
]);
|
|
482
|
+
const DOM_STYLE_ATTRIBUTES = new Map(Object.entries(ATTRIBUTES).filter(([name, row]) => row.native !== "none" && row.nativeProp && row.nativeProp !== name && row.nativeProp in stylePropsText).map(([name, row]) => [name, row.nativeProp]));
|
|
483
|
+
const nativePointerEventProps = /* @__PURE__ */ new Set([
|
|
484
|
+
"onPointerCancel",
|
|
485
|
+
"onPointerDown",
|
|
486
|
+
"onPointerEnter",
|
|
487
|
+
"onPointerLeave",
|
|
488
|
+
"onPointerMove",
|
|
489
|
+
"onPointerUp"
|
|
490
|
+
]);
|
|
491
|
+
function isSerializableNativeStyle(value) {
|
|
492
|
+
if (value == null || typeof value === "number" || typeof value === "boolean") {
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
if (typeof value === "string") return true;
|
|
496
|
+
if (Array.isArray(value)) return value.every(isSerializableNativeStyle);
|
|
497
|
+
if (!staticObject(value)) return false;
|
|
498
|
+
const prototype = Object.getPrototypeOf(value);
|
|
499
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
500
|
+
return Object.values(value).every(isSerializableNativeStyle);
|
|
501
|
+
}
|
|
502
|
+
function unusedIdentifier(source, base) {
|
|
503
|
+
let candidate = base;
|
|
504
|
+
let suffix = 0;
|
|
505
|
+
while (new RegExp(`\\b${candidate}\\b`).test(source)) {
|
|
506
|
+
candidate = `${base}${++suffix}`;
|
|
507
|
+
}
|
|
508
|
+
return candidate;
|
|
509
|
+
}
|
|
510
|
+
const VIEW_WRAPPER_PROPS = /^(aria-|accessibilityState$|accessibilityValue$|id$|tabIndex$|nativeID$)/;
|
|
511
|
+
function isBareHostView(element) {
|
|
512
|
+
return !element.entries.some((entry) => entry.kind === "child" || entry.kind === "spread" || entry.kind === "prop" && VIEW_WRAPPER_PROPS.test(entry.name));
|
|
513
|
+
}
|
|
514
|
+
function entrySource(input, entry) {
|
|
515
|
+
return entry.value.kind === "static" ? JSON.stringify(entry.value.value) : input.source.slice(entry.value.span.start, entry.value.span.end);
|
|
516
|
+
}
|
|
517
|
+
function renamedPropEdit(input, entry, name) {
|
|
518
|
+
if (entry.name === name) return null;
|
|
519
|
+
const content = input.source.slice(entry.span.start, entry.span.end);
|
|
520
|
+
const offset = content.indexOf(entry.name);
|
|
521
|
+
if (offset === -1) return null;
|
|
522
|
+
const quoted = content[offset - 1] === "\"" || content[offset - 1] === "'";
|
|
523
|
+
return {
|
|
524
|
+
start: entry.span.start + offset,
|
|
525
|
+
end: entry.span.start + offset + entry.name.length,
|
|
526
|
+
content: input.element.form === "jsx" || quoted ? name : JSON.stringify(name),
|
|
527
|
+
origin: entry.span
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function serializedProps(form, props) {
|
|
531
|
+
return props.map(([name, value]) => form === "jsx" ? `${name}={${value}}` : `${JSON.stringify(name)}: ${value}`).join(form === "jsx" ? " " : ", ");
|
|
532
|
+
}
|
|
533
|
+
function nativeDOMProps(input, tag) {
|
|
534
|
+
const consumed = [];
|
|
535
|
+
const edits = [];
|
|
536
|
+
const additions = [];
|
|
537
|
+
const nested = /* @__PURE__ */ new Map();
|
|
538
|
+
const entries = input.element.entries.filter((entry) => entry.kind === "prop");
|
|
539
|
+
const names = new Set(entries.map((entry) => entry.name));
|
|
540
|
+
if (names.has("ref") || tag === "br") additions.push(["__tag", JSON.stringify(tag)]);
|
|
541
|
+
if (TAGS[tag].backing === "text" || TAGS[tag].backing === "textinput") {
|
|
542
|
+
additions.push(["__inherit", "true"]);
|
|
543
|
+
}
|
|
544
|
+
const add = (name, value) => additions.push([name, value]);
|
|
545
|
+
const consume = (entry) => consumed.push(entry);
|
|
546
|
+
for (const entry of entries) {
|
|
547
|
+
const value = entrySource(input, entry);
|
|
548
|
+
const attribute = (entry.name in ATTRIBUTES ? ATTRIBUTES[entry.name] : void 0) ?? (entry.name.startsWith("data-") ? ATTRIBUTES["data-*"] : void 0);
|
|
549
|
+
const event = entry.name in EVENTS ? EVENTS[entry.name] : void 0;
|
|
550
|
+
if (event) {
|
|
551
|
+
if (event.native === "none") {
|
|
552
|
+
return {
|
|
553
|
+
consumed,
|
|
554
|
+
edits,
|
|
555
|
+
additions,
|
|
556
|
+
diagnostic: `${entry.name} has no native DOM event equivalent`,
|
|
557
|
+
diagnosticSpan: entry.span
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
if (entry.name === "onKeyDown" && tag !== "input" && tag !== "textarea") {
|
|
561
|
+
return {
|
|
562
|
+
consumed,
|
|
563
|
+
edits,
|
|
564
|
+
additions,
|
|
565
|
+
diagnostic: `onKeyDown requires a native text-entry control`,
|
|
566
|
+
diagnosticSpan: entry.span
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
if ([
|
|
570
|
+
"onClick",
|
|
571
|
+
"onLoad",
|
|
572
|
+
"onError",
|
|
573
|
+
"onChange",
|
|
574
|
+
"onInput",
|
|
575
|
+
"onKeyDown"
|
|
576
|
+
].includes(entry.name)) {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (event.nativeProp) {
|
|
580
|
+
const edit2 = renamedPropEdit(input, entry, event.nativeProp);
|
|
581
|
+
if (edit2) edits.push(edit2);
|
|
582
|
+
}
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (!attribute || attribute.native === "none" || entry.name === "style") continue;
|
|
586
|
+
if (DOM_STYLE_ATTRIBUTES.has(entry.name)) {
|
|
587
|
+
if (entry.value.kind !== "static") {
|
|
588
|
+
return {
|
|
589
|
+
consumed,
|
|
590
|
+
edits,
|
|
591
|
+
additions,
|
|
592
|
+
diagnostic: `html.${tag} ${entry.name} must be statically known for native lowering`,
|
|
593
|
+
diagnosticSpan: entry.span
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
consume(entry);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if (entry.name === "hidden") {
|
|
600
|
+
if (entry.value.kind !== "static") {
|
|
601
|
+
return {
|
|
602
|
+
consumed,
|
|
603
|
+
edits,
|
|
604
|
+
additions,
|
|
605
|
+
diagnostic: `html.${tag} hidden must be statically known for native lowering`,
|
|
606
|
+
diagnosticSpan: entry.span
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
consume(entry);
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (entry.name === "tabIndex") {
|
|
613
|
+
consume(entry);
|
|
614
|
+
add("focusable", `(${value}) === 0`);
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (entry.name === "readOnly") {
|
|
618
|
+
consume(entry);
|
|
619
|
+
add("editable", `!(${value})`);
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
if (entry.name === "disabled") {
|
|
623
|
+
consume(entry);
|
|
624
|
+
add("disabled", value);
|
|
625
|
+
add("focusable", `!(${value})`);
|
|
626
|
+
if (tag === "input" || tag === "textarea") add("editable", `!(${value})`);
|
|
627
|
+
const state = nested.get("accessibilityState") ?? [];
|
|
628
|
+
state.push(["disabled", value]);
|
|
629
|
+
nested.set("accessibilityState", state);
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
if (entry.name === "type") {
|
|
633
|
+
consume(entry);
|
|
634
|
+
if (tag === "input" && entry.value.kind !== "static") {
|
|
635
|
+
return {
|
|
636
|
+
consumed,
|
|
637
|
+
edits,
|
|
638
|
+
additions,
|
|
639
|
+
diagnostic: `html.input type must be statically known for native lowering`,
|
|
640
|
+
diagnosticSpan: entry.span
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
if (tag === "input" && entry.value.kind === "static") {
|
|
644
|
+
const type = entry.value.value;
|
|
645
|
+
if (type === "password") add("secureTextEntry", "true");
|
|
646
|
+
else if (typeof type === "string" && type !== "text" && NATIVE_INPUT_TYPES.includes(type)) {
|
|
647
|
+
if (!names.has("inputMode")) {
|
|
648
|
+
add("inputMode", JSON.stringify(type === "number" ? "numeric" : type));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
if (entry.name === "aria-hidden") {
|
|
655
|
+
consume(entry);
|
|
656
|
+
add("accessibilityElementsHidden", value);
|
|
657
|
+
add("importantForAccessibility", `(${value}) ? "no-hide-descendants" : "auto"`);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (entry.name === "aria-live") {
|
|
661
|
+
consume(entry);
|
|
662
|
+
add("accessibilityLiveRegion", entry.value.kind === "static" && entry.value.value === "off" ? "\"none\"" : value);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const nativeProp = attribute.nativeProp;
|
|
666
|
+
if (!nativeProp) continue;
|
|
667
|
+
if (nativeProp.includes(".")) {
|
|
668
|
+
consume(entry);
|
|
669
|
+
const [parent, child] = nativeProp.split(".");
|
|
670
|
+
const values = nested.get(parent) ?? [];
|
|
671
|
+
values.push([child, value]);
|
|
672
|
+
nested.set(parent, values);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
const edit = renamedPropEdit(input, entry, nativeProp);
|
|
676
|
+
if (edit) edits.push(edit);
|
|
677
|
+
}
|
|
678
|
+
for (const [name, values] of nested) {
|
|
679
|
+
add(name, `{ ${values.map(([key, value]) => `${key}: ${value}`).join(", ")} }`);
|
|
680
|
+
}
|
|
681
|
+
if (!names.has("role") && TAGS[tag].role) add("role", JSON.stringify(TAGS[tag].role));
|
|
682
|
+
if (tag === "textarea") add("multiline", "true");
|
|
683
|
+
return {
|
|
684
|
+
consumed,
|
|
685
|
+
edits,
|
|
686
|
+
additions
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
function webDOMProps(input, tag) {
|
|
690
|
+
const edits = [];
|
|
691
|
+
const additions = [];
|
|
692
|
+
const entries = input.element.entries.filter((entry) => entry.kind === "prop");
|
|
693
|
+
const names = new Set(entries.map((entry) => entry.name));
|
|
694
|
+
for (const entry of entries) {
|
|
695
|
+
if (entry.name === "for") {
|
|
696
|
+
const edit = renamedPropEdit(input, entry, "htmlFor");
|
|
697
|
+
if (edit) edits.push(edit);
|
|
698
|
+
}
|
|
699
|
+
if (entry.name === "role" && entry.value.kind === "static" && entry.value.value === "none") {
|
|
700
|
+
edits.push({
|
|
701
|
+
start: entry.value.span.start,
|
|
702
|
+
end: entry.value.span.end,
|
|
703
|
+
content: JSON.stringify("presentation"),
|
|
704
|
+
origin: entry.value.span
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (tag === "button" && !names.has("type")) additions.push(["type", "\"button\""]);
|
|
709
|
+
if ((tag === "input" || tag === "textarea") && !names.has("dir")) {
|
|
710
|
+
additions.push(["dir", "\"auto\""]);
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
edits,
|
|
714
|
+
additions
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function createTamaguiCompilerHost(options) {
|
|
718
|
+
const platform = options.target === "native" ? "native" : "web";
|
|
719
|
+
const core = requireTamaguiCore(platform);
|
|
720
|
+
const compilerVariantStyleResolver = core.styled(core.View, {}).staticConfig.variantStyleResolver;
|
|
721
|
+
const firstThemeName = Object.keys(options.tamaguiConfig.themes ?? {})[0] ?? "";
|
|
722
|
+
const firstTheme = options.tamaguiConfig.themes?.[firstThemeName] ?? {};
|
|
723
|
+
const theme = firstTheme;
|
|
724
|
+
const modifierRegistry = createModifierRegistry({
|
|
725
|
+
mediaNames: options.tamaguiConfig.media ?? {},
|
|
726
|
+
themeNames: options.tamaguiConfig.themes ?? {}
|
|
727
|
+
}).registry;
|
|
728
|
+
const isClauseObjectValue = (value) => {
|
|
729
|
+
if (!staticObject(value)) return false;
|
|
730
|
+
if ("default" in value) return true;
|
|
731
|
+
for (const key in value) {
|
|
732
|
+
if (key.length === 0) return false;
|
|
733
|
+
let start = 0;
|
|
734
|
+
for (let index = 0; index <= key.length; index++) {
|
|
735
|
+
if (index !== key.length && key.charCodeAt(index) !== 58) continue;
|
|
736
|
+
if (modifierRegistry.get(key.slice(start, index)) === void 0) return false;
|
|
737
|
+
start = index + 1;
|
|
738
|
+
}
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
return false;
|
|
742
|
+
};
|
|
743
|
+
const platformModifiersRegistered = modifierRegistry.get("web") === "platform" && modifierRegistry.get("native") === "platform";
|
|
744
|
+
const nativeClauseValue = (value) => {
|
|
745
|
+
if (typeof value !== "string" || !flatClausePattern.test(value)) {
|
|
746
|
+
return isClauseObjectValue(value) ? "live" : null;
|
|
747
|
+
}
|
|
748
|
+
if (!platformModifiersRegistered) return "live";
|
|
749
|
+
const parsed = parseValue(value, modifierRegistry);
|
|
750
|
+
if (!parsed.ok || parsed.value.clauses.length === 0) return "live";
|
|
751
|
+
let payload = parsed.value.base;
|
|
752
|
+
let matched = parsed.value.base !== null;
|
|
753
|
+
for (const clause of parsed.value.clauses) {
|
|
754
|
+
if (clause.modifiers.includes("web")) continue;
|
|
755
|
+
if (clause.modifiers.length !== 1 || clause.modifiers[0] !== "native") return "live";
|
|
756
|
+
payload = clause.payload;
|
|
757
|
+
matched = true;
|
|
758
|
+
}
|
|
759
|
+
return {
|
|
760
|
+
payload,
|
|
761
|
+
matched
|
|
762
|
+
};
|
|
763
|
+
};
|
|
764
|
+
const configuredAnimationDriver = options.tamaguiConfig.animations;
|
|
765
|
+
const configuredCssAnimationDriver = platform === "web" && configuredAnimationDriver?.outputStyle === "css" && !options.tamaguiConfig.animationDrivers ? configuredAnimationDriver : null;
|
|
766
|
+
const resolveStaticCssTransition = (value, transitionPresets) => {
|
|
767
|
+
if (platform !== "web" || typeof value !== "string") return null;
|
|
768
|
+
const transitionPresetNames = new Set(Object.keys(transitionPresets));
|
|
769
|
+
const program = parseValue(value, modifierRegistry);
|
|
770
|
+
if (!program.ok) return null;
|
|
771
|
+
const resolvedPayloads = [];
|
|
772
|
+
const payloads = [program.value.base, ...program.value.clauses.map((clause) => clause.payload)].filter((payload) => payload !== null);
|
|
773
|
+
if (payloads.length === 0) return null;
|
|
774
|
+
for (const payload of payloads) {
|
|
775
|
+
const transition = parseTransition(payload, transitionPresetNames);
|
|
776
|
+
if (!transition.ok) return null;
|
|
777
|
+
if (transition.value.kind === "global") {
|
|
778
|
+
resolvedPayloads.push(payload);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
const resolved2 = resolveTransition(payload, { animations: transitionPresets });
|
|
782
|
+
if (resolved2.diagnostics.length > 0) return null;
|
|
783
|
+
if (!resolved2.fused) {
|
|
784
|
+
resolvedPayloads.push(payload);
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
const css = toCSSTransition(resolved2);
|
|
788
|
+
if (css === void 0) return null;
|
|
789
|
+
resolvedPayloads.push(css);
|
|
790
|
+
}
|
|
791
|
+
let payloadIndex = 0;
|
|
792
|
+
const resolved = [];
|
|
793
|
+
if (program.value.base !== null) {
|
|
794
|
+
resolved.push(resolvedPayloads[payloadIndex++]);
|
|
795
|
+
}
|
|
796
|
+
for (const clause of program.value.clauses) {
|
|
797
|
+
resolved.push(`${clause.modifiers.join(":")}:${resolvedPayloads[payloadIndex++]}`);
|
|
798
|
+
}
|
|
799
|
+
return resolved.join(" ");
|
|
800
|
+
};
|
|
801
|
+
const { modulesById, componentsByModule } = options.registry ?? createComponentRegistry(options.components, options.componentModules);
|
|
802
|
+
const normalizedStyleConfigs = /* @__PURE__ */ new WeakMap();
|
|
803
|
+
const normalizeStaticConfig = (staticConfig) => {
|
|
804
|
+
if (!staticConfig.styleFrontend) return staticConfig;
|
|
805
|
+
const normalized = core.getStyleStaticConfig(staticConfig, options.tamaguiConfig);
|
|
806
|
+
const result = {
|
|
807
|
+
...staticConfig,
|
|
808
|
+
baseStyle: normalized.baseStyle,
|
|
809
|
+
defaultProps: normalized.defaultProps,
|
|
810
|
+
variants: normalized.variants,
|
|
811
|
+
passthroughClassName: normalized.passthroughClassName
|
|
812
|
+
};
|
|
813
|
+
normalizedStyleConfigs.set(result, normalized);
|
|
814
|
+
return result;
|
|
815
|
+
};
|
|
816
|
+
const directStaticConfig = (element) => {
|
|
817
|
+
const identity = element.component.provenance;
|
|
818
|
+
if (!identity) return null;
|
|
819
|
+
const moduleName = modulesById.get(identity.resolvedId);
|
|
820
|
+
const component = moduleName ? componentsByModule.get(moduleName) : void 0;
|
|
821
|
+
const info = component?.nameToInfo[identity.importedName];
|
|
822
|
+
return info ? {
|
|
823
|
+
key: componentKey(identity.resolvedId, identity.importedName),
|
|
824
|
+
staticConfig: normalizeStaticConfig(info.staticConfig),
|
|
825
|
+
displayName: info.displayName
|
|
826
|
+
} : null;
|
|
827
|
+
};
|
|
828
|
+
const domStaticConfig = (element) => {
|
|
829
|
+
const identity = element.component.provenance;
|
|
830
|
+
const tag = element.component.name;
|
|
831
|
+
if (identity?.importedName !== "html" || !DOM_FRONTENDS.has(identity.specifier) || !(tag in TAGS)) {
|
|
832
|
+
return null;
|
|
833
|
+
}
|
|
834
|
+
const row = TAGS[tag];
|
|
835
|
+
const textLike = row.backing === "text" || row.backing === "textinput";
|
|
836
|
+
const base = (textLike ? core.Text : core.View)?.staticConfig;
|
|
837
|
+
if (!base) return null;
|
|
838
|
+
const platformDefaults = platform === "web" ? {
|
|
839
|
+
...DISPLAY_WEB_RESET[row.display],
|
|
840
|
+
...row.defaults,
|
|
841
|
+
...TAG_WEB_DEFAULTS[tag]
|
|
842
|
+
} : {
|
|
843
|
+
...NATIVE_ELEMENT_DEFAULTS,
|
|
844
|
+
...row.display === "block" ? NATIVE_BLOCK_DEFAULTS : null,
|
|
845
|
+
...row.defaults,
|
|
846
|
+
...row.nativeDefaults
|
|
847
|
+
};
|
|
848
|
+
return {
|
|
849
|
+
key: componentKey(identity.resolvedId, `html.${tag}`),
|
|
850
|
+
tag,
|
|
851
|
+
displayName: tag,
|
|
852
|
+
staticConfig: normalizeStaticConfig({
|
|
853
|
+
...base,
|
|
854
|
+
isInput: row.backing === "textinput",
|
|
855
|
+
validStyles: {
|
|
856
|
+
...validStyles,
|
|
857
|
+
...row.backing === "textinput" ? stylePropsInput : stylePropsText
|
|
858
|
+
},
|
|
859
|
+
defaultProps: {
|
|
860
|
+
...base.defaultProps,
|
|
861
|
+
...platformDefaults
|
|
862
|
+
}
|
|
863
|
+
})
|
|
864
|
+
};
|
|
865
|
+
};
|
|
866
|
+
const styledStaticConfig = (definition) => {
|
|
867
|
+
if (!definition || definition.options.kind !== "static") return null;
|
|
868
|
+
const staticConfig = definition.staticConfig;
|
|
869
|
+
if (staticConfig && (staticConfig.kind !== "static" || !staticObject(staticConfig.value))) {
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
const base = directStaticConfig({
|
|
873
|
+
kind: "element",
|
|
874
|
+
form: "jsx",
|
|
875
|
+
id: definition.id,
|
|
876
|
+
span: definition.span,
|
|
877
|
+
propsSpan: null,
|
|
878
|
+
component: definition.base,
|
|
879
|
+
complete: true,
|
|
880
|
+
entries: [],
|
|
881
|
+
bailouts: []
|
|
882
|
+
});
|
|
883
|
+
if (!base || !staticObject(definition.options.value)) return null;
|
|
884
|
+
const { variants, defaultVariants, displayName, context, contextProps, ...defaultProps } = definition.options.value;
|
|
885
|
+
const baseClassName = definition.baseClassName?.kind === "static" && typeof definition.baseClassName.value === "string" ? definition.baseClassName.value : void 0;
|
|
886
|
+
const localStaticConfig = {
|
|
887
|
+
...base.staticConfig,
|
|
888
|
+
...staticConfig?.value,
|
|
889
|
+
variants: {
|
|
890
|
+
...base.staticConfig.variants,
|
|
891
|
+
...variants
|
|
892
|
+
},
|
|
893
|
+
defaultProps: {
|
|
894
|
+
...base.staticConfig.defaultProps,
|
|
895
|
+
...defaultProps,
|
|
896
|
+
...defaultVariants
|
|
897
|
+
},
|
|
898
|
+
defaultVariants,
|
|
899
|
+
baseClassName: [base.staticConfig.baseClassName, baseClassName].filter(Boolean).join(" "),
|
|
900
|
+
context: context ?? base.staticConfig.context,
|
|
901
|
+
contextProps: context ? contextProps : contextProps ?? base.staticConfig.contextProps
|
|
902
|
+
};
|
|
903
|
+
localStaticConfig.variantStyleResolver = compilerVariantStyleResolver;
|
|
904
|
+
return {
|
|
905
|
+
key: componentKey(definition.id, definition.name),
|
|
906
|
+
displayName: displayName || base.displayName,
|
|
907
|
+
staticConfig: normalizeStaticConfig(localStaticConfig)
|
|
908
|
+
};
|
|
909
|
+
};
|
|
910
|
+
const resolve = (element, styledDefinition) => {
|
|
911
|
+
const dom = domStaticConfig(element);
|
|
912
|
+
const resolved = dom ?? directStaticConfig(element) ?? styledStaticConfig(styledDefinition);
|
|
913
|
+
if (!resolved) return null;
|
|
914
|
+
const defaultProps = resolved.staticConfig.defaultProps ?? {};
|
|
915
|
+
return {
|
|
916
|
+
key: resolved.key,
|
|
917
|
+
canFlatten: resolved.staticConfig.acceptsClassName !== false && !resolved.staticConfig.neverFlatten && !resolved.staticConfig.context,
|
|
918
|
+
staticConfig: resolved.staticConfig,
|
|
919
|
+
displayName: resolved.displayName,
|
|
920
|
+
...dom && { domTag: dom.tag },
|
|
921
|
+
partialRuntimeSafe: !dom && !styledDefinition && Object.keys(defaultProps).length === 0 && !resolved.staticConfig.defaultVariants && !resolved.staticConfig.baseClassName && !resolved.staticConfig.baseStyle
|
|
922
|
+
};
|
|
923
|
+
};
|
|
924
|
+
const isStyleProp = (name, component) => {
|
|
925
|
+
const staticConfig = component.staticConfig;
|
|
926
|
+
return compilerStyleProps.has(name) || name in (options.tamaguiConfig.shorthands ?? {}) || !!staticConfig.validStyles?.[name] || !!staticConfig.variants?.[name];
|
|
927
|
+
};
|
|
928
|
+
const runtimeOnlyStyleProps = /* @__PURE__ */ new Set([
|
|
929
|
+
"className",
|
|
930
|
+
"style",
|
|
931
|
+
"group",
|
|
932
|
+
"transition",
|
|
933
|
+
"animation",
|
|
934
|
+
"animatePresence",
|
|
935
|
+
"animatedBy",
|
|
936
|
+
"render"
|
|
937
|
+
]);
|
|
938
|
+
const isFrontendClassName = (name, component) => name === "className" && !!component.staticConfig.styleFrontend;
|
|
939
|
+
const canLowerConditionalStyleProp = (name, component) => isStyleProp(name, component) && (!runtimeOnlyStyleProps.has(name) || isFrontendClassName(name, component));
|
|
940
|
+
const frontendClassDomain = (entry, component) => {
|
|
941
|
+
if (entry.kind !== "prop" || entry.value.kind !== "bailout" || !isFrontendClassName(entry.name, component)) {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
const dynamic = entry.value.dynamic;
|
|
945
|
+
if (dynamic?.type !== "string" || !dynamic.values?.length) return null;
|
|
946
|
+
return dynamic.values.map(String);
|
|
947
|
+
};
|
|
948
|
+
const conditionalClassEntry = (entry, component) => entry.value.kind === "conditional" && canLowerConditionalStyleProp(entry.name, component) || frontendClassDomain(entry, component) !== null;
|
|
949
|
+
const isInvalidHostStyleProp = (name, component) => {
|
|
950
|
+
const staticConfig = component.staticConfig;
|
|
951
|
+
const validStyles$1 = staticConfig.validStyles || (staticConfig.isInput ? stylePropsInput : staticConfig.isText ? stylePropsText : validStyles);
|
|
952
|
+
return name in stylePropsAll && !isValidStyleKey(name, validStyles$1);
|
|
953
|
+
};
|
|
954
|
+
const directStyleName = (name, component) => {
|
|
955
|
+
if (compilerStyleProps.has(name) || name === "style") {
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
const staticConfig = component.staticConfig;
|
|
959
|
+
if (staticConfig.variants?.[name]) return null;
|
|
960
|
+
const expanded = options.tamaguiConfig.shorthands?.[name] ?? name;
|
|
961
|
+
return staticConfig.validStyles?.[expanded] ? expanded : null;
|
|
962
|
+
};
|
|
963
|
+
const resolveSplitStyles = (props, staticConfig, animationDriver, displayName) => {
|
|
964
|
+
const previousStatic = process.env.IS_STATIC;
|
|
965
|
+
const previousTarget = process.env.TAMAGUI_TARGET;
|
|
966
|
+
if (platform === "native") {
|
|
967
|
+
process.env.IS_STATIC = "is_static";
|
|
968
|
+
} else {
|
|
969
|
+
delete process.env.IS_STATIC;
|
|
970
|
+
}
|
|
971
|
+
process.env.TAMAGUI_TARGET = platform;
|
|
972
|
+
try {
|
|
973
|
+
return core.getSplitStyles(props, staticConfig, theme, firstThemeName, componentState, {
|
|
974
|
+
isStatic: true,
|
|
975
|
+
resolveValues: platform === "native" ? "except-theme" : "variable",
|
|
976
|
+
noClass: platform === "native",
|
|
977
|
+
isAnimated: false,
|
|
978
|
+
displayName
|
|
979
|
+
}, void 0, void 0, void 0, void 0, void 0, void 0, animationDriver, normalizedStyleConfigs.get(staticConfig));
|
|
980
|
+
} finally {
|
|
981
|
+
if (previousStatic === void 0) delete process.env.IS_STATIC;
|
|
982
|
+
else process.env.IS_STATIC = previousStatic;
|
|
983
|
+
if (previousTarget === void 0) delete process.env.TAMAGUI_TARGET;
|
|
984
|
+
else process.env.TAMAGUI_TARGET = previousTarget;
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
const partialStaticConfig = (staticConfig) => ({
|
|
988
|
+
...staticConfig,
|
|
989
|
+
baseStyle: void 0,
|
|
990
|
+
defaultProps: {},
|
|
991
|
+
defaultVariants: void 0,
|
|
992
|
+
variants: {}
|
|
993
|
+
});
|
|
994
|
+
const styleOwners = (name, value, staticConfig) => {
|
|
995
|
+
const split = resolveSplitStyles({ [name]: value }, partialStaticConfig(staticConfig));
|
|
996
|
+
if (!split) return null;
|
|
997
|
+
const inlineStyle = split.viewProps?.style;
|
|
998
|
+
if (staticObject(inlineStyle) && Object.keys(inlineStyle).length > 0) {
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
const owners = new Set(Object.keys(split.classNames ?? {}));
|
|
1002
|
+
for (const styleObject of Object.values(split.rulesToInsert ?? {})) {
|
|
1003
|
+
const property = styleObject?.[StyleObjectProperty];
|
|
1004
|
+
if (typeof property === "string") owners.add(property);
|
|
1005
|
+
}
|
|
1006
|
+
return owners.size > 0 ? owners : null;
|
|
1007
|
+
};
|
|
1008
|
+
const dynamicStyleOwners = (name, staticConfig) => {
|
|
1009
|
+
const probeValue = name === "transform" ? [{ scale: 1 }] : name === "transformMatrix" ? [
|
|
1010
|
+
1,
|
|
1011
|
+
0,
|
|
1012
|
+
0,
|
|
1013
|
+
1,
|
|
1014
|
+
0,
|
|
1015
|
+
0
|
|
1016
|
+
] : name === "shadowOffset" ? {
|
|
1017
|
+
width: 0,
|
|
1018
|
+
height: 0
|
|
1019
|
+
} : name === "shadowColor" ? "black" : name === "border" || name === "outline" ? "0 solid transparent" : name === "position" ? "relative" : name === "objectFit" ? "contain" : 0;
|
|
1020
|
+
const owners = styleOwners(name, probeValue, staticConfig);
|
|
1021
|
+
if (!owners || name !== "flex") return owners;
|
|
1022
|
+
const shorthandOwners = styleOwners(name, "0 1 auto", staticConfig);
|
|
1023
|
+
if (!shorthandOwners) return null;
|
|
1024
|
+
for (const owner of shorthandOwners) owners.add(owner);
|
|
1025
|
+
return owners;
|
|
1026
|
+
};
|
|
1027
|
+
const developmentDebugInstrumentation = (input, result) => {
|
|
1028
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
1029
|
+
const debugEntry = input.element.entries.find((entry) => entry.kind === "prop" && entry.name === "debug" && entry.value.kind === "static" && entry.value.value === "verbose");
|
|
1030
|
+
if (!debugEntry) return;
|
|
1031
|
+
const component = input.component;
|
|
1032
|
+
const styleEntries = input.element.entries.filter((entry) => entry.kind === "prop" && entry.name !== "debug" && (entry.name === "style" || isStyleProp(entry.name, component)));
|
|
1033
|
+
const flattened = result.ok && !!result.flattened;
|
|
1034
|
+
const tiers = result.ok ? [
|
|
1035
|
+
"lowered",
|
|
1036
|
+
...flattened ? ["flattened"] : [],
|
|
1037
|
+
...input.styledDefinition ? ["styled"] : []
|
|
1038
|
+
] : ["bailed"];
|
|
1039
|
+
const why = result.ok ? flattened ? "Static styles were lowered and the component was flattened to a host element." : "Static styles were lowered while the Tamagui component remained at runtime." : result.bailout.message;
|
|
1040
|
+
const styles = styleEntries.map((entry) => {
|
|
1041
|
+
if (!result.ok) {
|
|
1042
|
+
return {
|
|
1043
|
+
prop: entry.name,
|
|
1044
|
+
tier: "bailed",
|
|
1045
|
+
runtime: true,
|
|
1046
|
+
why: `${result.bailout.message}. The Tamagui runtime resolved this prop.`
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
const edited = result.edits.some((edit) => edit.start < entry.span.end && edit.end > entry.span.start);
|
|
1050
|
+
if (!flattened && !edited) {
|
|
1051
|
+
return {
|
|
1052
|
+
prop: entry.name,
|
|
1053
|
+
tier: "bailed",
|
|
1054
|
+
runtime: true,
|
|
1055
|
+
why: "This prop remained for Tamagui runtime resolution."
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
if (entry.value.kind === "static") {
|
|
1059
|
+
const split = resolveSplitStyles({ [entry.name]: entry.value.value }, partialStaticConfig(component.staticConfig));
|
|
1060
|
+
const hasOutput = Boolean(split && (Object.keys(split.classNames ?? {}).length > 0 || Object.keys(split.rulesToInsert ?? {}).length > 0 || staticObject(split.style) && Object.keys(split.style).length > 0 || staticObject(split.viewProps?.style) && Object.keys(split.viewProps.style).length > 0));
|
|
1061
|
+
if (!hasOutput) {
|
|
1062
|
+
return {
|
|
1063
|
+
prop: entry.name,
|
|
1064
|
+
tier: flattened ? "flattened" : "lowered",
|
|
1065
|
+
dropped: true,
|
|
1066
|
+
why: `No ${platform} style output was produced for this prop.`
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
prop: entry.name,
|
|
1072
|
+
tier: flattened ? "flattened" : "lowered",
|
|
1073
|
+
why: flattened ? "The compiler emitted this prop on the flattened host element." : "The compiler lowered this prop while retaining the Tamagui component."
|
|
1074
|
+
};
|
|
1075
|
+
});
|
|
1076
|
+
const receipt = JSON.stringify({
|
|
1077
|
+
component: input.element.component.name,
|
|
1078
|
+
tiers,
|
|
1079
|
+
why,
|
|
1080
|
+
styles
|
|
1081
|
+
});
|
|
1082
|
+
const content = flattened ? input.element.form === "jsx" ? `{...(console.info('\u{1F539} Tamagui style receipt', ${receipt}), {})}` : `...(console.info('\u{1F539} Tamagui style receipt', ${receipt}), {})` : input.element.form === "jsx" ? `debug="verbose" __tamaguiStyleDebugReceipt={${receipt}}` : `debug: "verbose", __tamaguiStyleDebugReceipt: ${receipt}`;
|
|
1083
|
+
return [{
|
|
1084
|
+
start: debugEntry.span.start,
|
|
1085
|
+
end: debugEntry.span.end,
|
|
1086
|
+
content,
|
|
1087
|
+
origin: debugEntry.span
|
|
1088
|
+
}];
|
|
1089
|
+
};
|
|
1090
|
+
return {
|
|
1091
|
+
resolveComponent: resolve,
|
|
1092
|
+
isStyleProp,
|
|
1093
|
+
canLowerDynamicStyleProp(name, component, valueKind) {
|
|
1094
|
+
if (!options.disablePartialExtraction && valueKind === "conditional" && canLowerConditionalStyleProp(name, component)) {
|
|
1095
|
+
return true;
|
|
1096
|
+
}
|
|
1097
|
+
if (component.staticConfig.resolvers?.length) {
|
|
1098
|
+
return false;
|
|
1099
|
+
}
|
|
1100
|
+
if (!options.disablePartialExtraction && platform === "web" && isFrontendClassName(name, component)) {
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
return !options.disablePartialExtraction && (platform === "web" && !!directStyleName(name, component) || platform === "native" && directStyleName(name, component) === "opacity");
|
|
1104
|
+
},
|
|
1105
|
+
developmentDebugInstrumentation,
|
|
1106
|
+
lowerCandidate(input) {
|
|
1107
|
+
const component = input.component;
|
|
1108
|
+
if (!component.canFlatten) {
|
|
1109
|
+
const reason = component.staticConfig.acceptsClassName === false ? `${component.key} does not accept className` : component.staticConfig.neverFlatten ? `${component.key} is never flattened (behavior HOC)` : `${component.key} provides a styled context`;
|
|
1110
|
+
return bailout(input, "local/unsupported-target", reason, input.element.span, { rule: 6 });
|
|
1111
|
+
}
|
|
1112
|
+
if (options.zeroRuntime) {
|
|
1113
|
+
const spread = input.element.entries.find((entry) => entry.kind === "spread");
|
|
1114
|
+
if (spread) {
|
|
1115
|
+
return bailout(input, "local/unsafe-style-spread", "Zero-runtime rejects prop spreads", spread.span, {
|
|
1116
|
+
rule: 1,
|
|
1117
|
+
message: zeroRuleMessage(1, { component: input.element.component.name })
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
const props = {};
|
|
1122
|
+
for (const entry of input.element.entries) {
|
|
1123
|
+
if (entry.kind === "child" || entry.value.kind !== "static") continue;
|
|
1124
|
+
if (entry.kind === "spread") {
|
|
1125
|
+
if (!staticObject(entry.value.value)) {
|
|
1126
|
+
return bailout(input, "local/unsafe-style-spread", "Static spread did not materialize to an object", entry.span);
|
|
1127
|
+
}
|
|
1128
|
+
Object.assign(props, entry.value.value);
|
|
1129
|
+
} else {
|
|
1130
|
+
props[entry.name] = entry.value.value;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
if (component.staticConfig.resolvers?.length) {
|
|
1134
|
+
const unresolvedProps = input.element.entries.filter((entry) => entry.kind === "prop" && entry.value.kind !== "static");
|
|
1135
|
+
const onlyStaticBranchConditional = unresolvedProps.length === 1 && unresolvedProps[0]?.kind === "prop" && unresolvedProps[0].value.kind === "conditional" && canLowerConditionalStyleProp(unresolvedProps[0].name, component);
|
|
1136
|
+
const unresolvedProp = onlyStaticBranchConditional ? void 0 : unresolvedProps[0];
|
|
1137
|
+
if (unresolvedProp?.kind === "prop") {
|
|
1138
|
+
return bailout(input, "local/dynamic-style-value", `Component resolver prop ${unresolvedProp.name} could not be evaluated`, unresolvedProp.span, void 0, unresolvedProp.name);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
const componentOnlyProp = (name) => {
|
|
1142
|
+
let span;
|
|
1143
|
+
let unknown = false;
|
|
1144
|
+
for (const entry of input.element.entries) {
|
|
1145
|
+
if (entry.kind !== "prop" || entry.name !== name) continue;
|
|
1146
|
+
span = entry.span;
|
|
1147
|
+
if (entry.value.kind !== "static") unknown = true;
|
|
1148
|
+
}
|
|
1149
|
+
return {
|
|
1150
|
+
unknown,
|
|
1151
|
+
span
|
|
1152
|
+
};
|
|
1153
|
+
};
|
|
1154
|
+
const disableOptimization = componentOnlyProp("disableOptimization");
|
|
1155
|
+
if (disableOptimization.unknown || props.disableOptimization) {
|
|
1156
|
+
return bailout(input, "local/unsupported-target", "disableOptimization keeps the component on the runtime path", disableOptimization.span);
|
|
1157
|
+
}
|
|
1158
|
+
if (component.domTag && props.hidden) props.display = "none";
|
|
1159
|
+
if (component.domTag && platform === "native") {
|
|
1160
|
+
for (const [name, styleKey] of DOM_STYLE_ATTRIBUTES) {
|
|
1161
|
+
if (name in props) {
|
|
1162
|
+
props[styleKey] = props[name];
|
|
1163
|
+
delete props[name];
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (platform === "native" && component.domTag === "input" && typeof props.type === "string" && !NATIVE_INPUT_TYPES.includes(props.type)) {
|
|
1168
|
+
return bailout(input, "local/unsupported-target", `input type ${props.type} has no native text-entry control`);
|
|
1169
|
+
}
|
|
1170
|
+
let styleObjectStatic = null;
|
|
1171
|
+
const styleMemberEntries = [];
|
|
1172
|
+
for (const entry of input.element.entries) {
|
|
1173
|
+
if (entry.kind !== "prop" || entry.name !== "style" || entry.value.kind !== "object") {
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
styleObjectStatic = {};
|
|
1177
|
+
for (const member of entry.value.members) {
|
|
1178
|
+
if (member.value.kind === "static") {
|
|
1179
|
+
styleObjectStatic[member.name] = member.value.value;
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
if (!isStyleProp(member.name, component)) {
|
|
1183
|
+
return bailout(input, "local/dynamic-style-value", `Style prop ${member.name} could not be evaluated`, member.span);
|
|
1184
|
+
}
|
|
1185
|
+
styleMemberEntries.push({
|
|
1186
|
+
kind: "prop",
|
|
1187
|
+
name: member.name,
|
|
1188
|
+
span: member.span,
|
|
1189
|
+
value: member.value,
|
|
1190
|
+
styleMember: true
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
if (Object.keys(styleObjectStatic).length === 0) styleObjectStatic = null;
|
|
1194
|
+
}
|
|
1195
|
+
if (styleObjectStatic) props.style = styleObjectStatic;
|
|
1196
|
+
const dynamicStyleEntries = [...input.element.entries.filter((entry) => entry.kind === "prop" && (entry.value.kind === "bailout" || entry.value.kind === "conditional") && isStyleProp(entry.name, component)), ...styleMemberEntries];
|
|
1197
|
+
{
|
|
1198
|
+
const needsRuntimeMapping = (name) => runtimeEventProps.has(name) || platform === "native" && !component.domTag && nativePointerEventProps.has(name);
|
|
1199
|
+
const directRuntimeEvent = input.element.entries.find((entry) => entry.kind === "prop" && needsRuntimeMapping(entry.name));
|
|
1200
|
+
const runtimeEvent = directRuntimeEvent?.kind === "prop" ? directRuntimeEvent.name : Object.keys(props).find(needsRuntimeMapping);
|
|
1201
|
+
if (runtimeEvent) {
|
|
1202
|
+
return bailout(input, "local/unsupported-target", `${runtimeEvent} requires Tamagui runtime event mapping`);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
const animationDefaultProps = component.staticConfig.defaultProps ?? {};
|
|
1206
|
+
const animationProps = core.mergeProps(animationDefaultProps, props);
|
|
1207
|
+
const animationNames = /* @__PURE__ */ new Set([...input.element.entries.flatMap((entry) => entry.kind === "prop" && runtimeAnimationProps.has(entry.name) ? [entry.name] : []), ...Object.keys(animationProps).filter((name) => runtimeAnimationProps.has(name) && animationProps[name] !== void 0)]);
|
|
1208
|
+
const transitionEntry = input.element.entries.find((entry) => entry.kind === "prop" && entry.name === "transition");
|
|
1209
|
+
const animatedBy = typeof animationProps.animatedBy === "string" ? animationProps.animatedBy.trim() : null;
|
|
1210
|
+
const namedAnimationDriver = animatedBy === null ? null : options.tamaguiConfig.animationDrivers?.[animatedBy];
|
|
1211
|
+
const namedCssAnimationDriver = platform === "web" && namedAnimationDriver && !namedAnimationDriver.isStub && namedAnimationDriver.outputStyle === "css" ? namedAnimationDriver : null;
|
|
1212
|
+
const cssAnimationDriver = namedCssAnimationDriver ?? (animatedBy === null || animatedBy === "default" ? configuredCssAnimationDriver : null);
|
|
1213
|
+
const resolvedCssTransition = animationNames.has("transition") && cssAnimationDriver ? resolveStaticCssTransition(animationProps.transition, cssAnimationDriver.animations ?? {}) : null;
|
|
1214
|
+
if (resolvedCssTransition !== null) {
|
|
1215
|
+
props.transition = resolvedCssTransition;
|
|
1216
|
+
}
|
|
1217
|
+
const animatedByNeedsRuntime = animationNames.has("animatedBy") && !animationNames.has("transition") && (dynamicStyleEntries.length > 0 || Object.keys(animationProps).some((name) => name !== "animatedBy" && (isStyleProp(name, component) && typeof animationProps[name] === "string" && animationProps[name].includes(":") || name === "animationConfig" || name === "forceStyle" || name === "onTransition")));
|
|
1218
|
+
const runtimeAnimationRequired = animationNames.has("transition") && resolvedCssTransition === null || [...animationNames].some((name) => name !== "transition" && name !== "animatedBy") || animatedByNeedsRuntime;
|
|
1219
|
+
let dynamicHostStyleProperties = null;
|
|
1220
|
+
let laneAEntries = [];
|
|
1221
|
+
const laneAOwners = /* @__PURE__ */ new Set();
|
|
1222
|
+
const laneAMemberOwners = /* @__PURE__ */ new Set();
|
|
1223
|
+
const conflictsWithInline = (owners, dynamicOwners, memberOwners) => [...owners].some((owner) => !memberOwners.has(owner) && cssOwnersConflict(/* @__PURE__ */ new Set([owner]), dynamicOwners));
|
|
1224
|
+
const laneAAttempts = [dynamicStyleEntries];
|
|
1225
|
+
{
|
|
1226
|
+
const rest2 = dynamicStyleEntries.filter((entry) => !conditionalClassEntry(entry, component));
|
|
1227
|
+
if (rest2.length > 0 && rest2.length < dynamicStyleEntries.length) {
|
|
1228
|
+
laneAAttempts.push(rest2);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (platform === "web" && !options.disablePartialExtraction && (input.element.form === "jsx" || input.element.propsSpan !== null) && dynamicStyleEntries.length > 0 && !input.element.entries.some((entry) => entry.kind === "spread" && entry.value.kind !== "static")) {
|
|
1232
|
+
for (const attempt of laneAAttempts) {
|
|
1233
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1234
|
+
const properties = [];
|
|
1235
|
+
const dynamicOwners = /* @__PURE__ */ new Set();
|
|
1236
|
+
const memberOwners = /* @__PURE__ */ new Set();
|
|
1237
|
+
for (const entry of attempt) {
|
|
1238
|
+
if (entry.kind !== "prop" || entry.value.kind !== "bailout" && entry.value.kind !== "conditional") {
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
const name = directStyleName(entry.name, component);
|
|
1242
|
+
if (!name || seen.has(name)) {
|
|
1243
|
+
properties.length = 0;
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
const owners = dynamicStyleOwners(name, component.staticConfig);
|
|
1247
|
+
if (!owners) {
|
|
1248
|
+
properties.length = 0;
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1251
|
+
let property = null;
|
|
1252
|
+
const expression = input.source.slice(entry.value.span.start, entry.value.span.end);
|
|
1253
|
+
if (resolvedCssTransition !== null && (name === "opacity" || name === "scale")) {
|
|
1254
|
+
property = name === "opacity" ? `opacity: (${expression})` : `transform: "scale(" + (${expression}) + ")"`;
|
|
1255
|
+
} else if (entry.value.kind === "bailout" && owners.has(name)) {
|
|
1256
|
+
const dynamic = entry.value.dynamic;
|
|
1257
|
+
if (dynamic?.type === "number") {
|
|
1258
|
+
property = `${JSON.stringify(name)}: (${expression})`;
|
|
1259
|
+
} else if (dynamic?.type === "string" && dynamic.values?.length) {
|
|
1260
|
+
let valuesStayLiteral = true;
|
|
1261
|
+
for (const value of dynamic.values) {
|
|
1262
|
+
const split2 = resolveSplitStyles({ [entry.name]: value }, partialStaticConfig(component.staticConfig));
|
|
1263
|
+
const atomics = Object.values(split2?.rulesToInsert ?? {});
|
|
1264
|
+
if (atomics.length !== 1 || atomics[0]?.[StyleObjectProperty] !== name || atomics[0]?.[StyleObjectValue] !== value) {
|
|
1265
|
+
valuesStayLiteral = false;
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
if (valuesStayLiteral) {
|
|
1270
|
+
property = `${JSON.stringify(name)}: (${expression})`;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
if (!property) {
|
|
1275
|
+
properties.length = 0;
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
seen.add(name);
|
|
1279
|
+
for (const owner of owners) {
|
|
1280
|
+
dynamicOwners.add(owner);
|
|
1281
|
+
if (entry.styleMember) memberOwners.add(owner);
|
|
1282
|
+
}
|
|
1283
|
+
properties.push(property);
|
|
1284
|
+
}
|
|
1285
|
+
if (properties.length === attempt.length && !input.element.entries.some((entry) => {
|
|
1286
|
+
if (entry.kind !== "prop" || entry.value.kind !== "static") return false;
|
|
1287
|
+
const name = directStyleName(entry.name, component);
|
|
1288
|
+
if (!name) return false;
|
|
1289
|
+
const owners = styleOwners(name, entry.value.value, component.staticConfig);
|
|
1290
|
+
return !!owners && conflictsWithInline(owners, dynamicOwners, memberOwners);
|
|
1291
|
+
}) && !Object.entries(staticObject(props.style) ? props.style : {}).some(([name, value]) => {
|
|
1292
|
+
const owners = styleOwners(name, value, component.staticConfig);
|
|
1293
|
+
return !!owners && cssOwnersConflict(owners, dynamicOwners);
|
|
1294
|
+
})) {
|
|
1295
|
+
dynamicHostStyleProperties = properties;
|
|
1296
|
+
laneAEntries = attempt;
|
|
1297
|
+
for (const owner of dynamicOwners) laneAOwners.add(owner);
|
|
1298
|
+
for (const owner of memberOwners) laneAMemberOwners.add(owner);
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
const laneACoversAll = dynamicHostStyleProperties !== null && laneAEntries.length === dynamicStyleEntries.length;
|
|
1304
|
+
const webClassEntries = dynamicHostStyleProperties === null ? dynamicStyleEntries : dynamicStyleEntries.filter((entry) => !laneAEntries.includes(entry));
|
|
1305
|
+
const supportsWebConditionalClasses = platform === "web" && !options.disablePartialExtraction && (input.element.form === "jsx" || input.element.propsSpan !== null) && !laneACoversAll && webClassEntries.length > 0 && webClassEntries.every((entry) => conditionalClassEntry(entry, component));
|
|
1306
|
+
const themeEntry = componentOnlyProp("theme");
|
|
1307
|
+
const themeInverseEntry = componentOnlyProp("themeInverse");
|
|
1308
|
+
const themeBoundary = themeEntry.unknown || "theme" in props;
|
|
1309
|
+
if (themeBoundary || themeInverseEntry.unknown || props.themeInverse) {
|
|
1310
|
+
const themeProp = themeBoundary ? "theme" : "themeInverse";
|
|
1311
|
+
return bailout(input, "local/unsupported-target", "Theme boundary candidates remain on the runtime path", input.element.span, {
|
|
1312
|
+
rule: 4,
|
|
1313
|
+
message: zeroThemeBoundaryMessage(input.element.component.name, themeProp)
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
const asChild = componentOnlyProp("asChild");
|
|
1317
|
+
if (asChild.unknown || props.asChild) {
|
|
1318
|
+
return bailout(input, "local/unsupported-target", "asChild renders a Slot, not a host view", asChild.span);
|
|
1319
|
+
}
|
|
1320
|
+
if (platform === "native" && ("group" in props || "container" in props || "containerName" in props || "containerType" in props)) {
|
|
1321
|
+
return bailout(input, "local/unsupported-target", "Native group and container providers remain on the runtime path");
|
|
1322
|
+
}
|
|
1323
|
+
if (runtimeAnimationRequired && !cssAnimationDriver) {
|
|
1324
|
+
return bailout(input, "local/unsupported-target", "Animated candidates remain on the runtime path", transitionEntry?.span, {
|
|
1325
|
+
rule: 5,
|
|
1326
|
+
message: zeroRuleMessage(5, { detail: `the animation configured on ${input.element.component.name}` })
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
if (platform === "web" && (dynamicStyleEntries.length > 0 || runtimeAnimationRequired) && !laneACoversAll && !supportsWebConditionalClasses && component.partialRuntimeSafe) {
|
|
1330
|
+
const hasSpread = input.element.entries.some((entry) => entry.kind === "spread" && entry.value.kind !== "static");
|
|
1331
|
+
const unsupportedRuntimeStyle = input.element.entries.find((entry) => entry.kind === "prop" && isStyleProp(entry.name, component) && !runtimeAnimationProps.has(entry.name) && !directStyleName(entry.name, component));
|
|
1332
|
+
if (!hasSpread && !unsupportedRuntimeStyle) {
|
|
1333
|
+
const dynamicOwners = /* @__PURE__ */ new Set();
|
|
1334
|
+
let canProveDynamicOwnership = true;
|
|
1335
|
+
for (const entry of dynamicStyleEntries) {
|
|
1336
|
+
if (entry.kind !== "prop") continue;
|
|
1337
|
+
const name = directStyleName(entry.name, component);
|
|
1338
|
+
if (!name) {
|
|
1339
|
+
canProveDynamicOwnership = false;
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
const owners = dynamicStyleOwners(name, component.staticConfig);
|
|
1343
|
+
if (!owners) {
|
|
1344
|
+
canProveDynamicOwnership = false;
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
for (const owner of owners) dynamicOwners.add(owner);
|
|
1348
|
+
}
|
|
1349
|
+
const staticStyleEntries = canProveDynamicOwnership ? input.element.entries.filter((entry) => {
|
|
1350
|
+
if (entry.kind !== "prop" || entry.value.kind !== "static") return false;
|
|
1351
|
+
if (runtimeAnimationProps.has(entry.name)) return false;
|
|
1352
|
+
const name = directStyleName(entry.name, component);
|
|
1353
|
+
if (!name) return false;
|
|
1354
|
+
const owners = styleOwners(name, entry.value.value, component.staticConfig);
|
|
1355
|
+
return !!owners && !cssOwnersConflict(owners, dynamicOwners);
|
|
1356
|
+
}) : [];
|
|
1357
|
+
if (staticStyleEntries.length > 0) {
|
|
1358
|
+
const partialProps = {};
|
|
1359
|
+
for (const entry of staticStyleEntries) {
|
|
1360
|
+
if (entry.kind === "prop" && entry.value.kind === "static") {
|
|
1361
|
+
partialProps[entry.name] = entry.value.value;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
const partialSplit = resolveSplitStyles(partialProps, partialStaticConfig(component.staticConfig));
|
|
1365
|
+
const partialInlineStyle = partialSplit?.viewProps?.style;
|
|
1366
|
+
const hasPartialInlineStyle = staticObject(partialInlineStyle) && Object.keys(partialInlineStyle).length > 0;
|
|
1367
|
+
if (partialSplit && !hasPartialInlineStyle) {
|
|
1368
|
+
const artifacts2 = extractedStyleArtifacts(partialSplit, partialProps, options.tamaguiConfig, false);
|
|
1369
|
+
if (artifacts2.className) {
|
|
1370
|
+
if (input.element.form !== "jsx") {
|
|
1371
|
+
const propsEdits = compiledPropsEdits(input, staticStyleEntries, objectClassName(artifacts2.className));
|
|
1372
|
+
if (propsEdits) {
|
|
1373
|
+
return {
|
|
1374
|
+
ok: true,
|
|
1375
|
+
edits: propsEdits,
|
|
1376
|
+
css: artifacts2.css,
|
|
1377
|
+
imports: [],
|
|
1378
|
+
flattened: false
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
} else {
|
|
1382
|
+
const [first2, ...rest2] = staticStyleEntries;
|
|
1383
|
+
return {
|
|
1384
|
+
ok: true,
|
|
1385
|
+
edits: [{
|
|
1386
|
+
start: first2.span.start,
|
|
1387
|
+
end: first2.span.end,
|
|
1388
|
+
content: jsxClassName(artifacts2.className),
|
|
1389
|
+
origin: first2.span
|
|
1390
|
+
}, ...rest2.map((entry) => ({
|
|
1391
|
+
start: entry.span.start,
|
|
1392
|
+
end: entry.span.end,
|
|
1393
|
+
content: "",
|
|
1394
|
+
origin: entry.span
|
|
1395
|
+
}))],
|
|
1396
|
+
css: artifacts2.css,
|
|
1397
|
+
imports: [],
|
|
1398
|
+
flattened: false
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
if (runtimeAnimationRequired) {
|
|
1407
|
+
return bailout(input, "local/unsupported-target", "Animated candidates remain on the runtime path", transitionEntry?.span, {
|
|
1408
|
+
rule: 5,
|
|
1409
|
+
message: zeroRuleMessage(5, { detail: `the animation configured on ${input.element.component.name}` })
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
const supportsNativeDynamicStyles = platform === "native" && !options.disablePartialExtraction && (input.element.form === "jsx" || input.element.propsSpan !== null) && dynamicStyleEntries.every((entry) => entry.kind === "prop" && (directStyleName(entry.name, component) === "opacity" || entry.value.kind === "conditional" && canLowerConditionalStyleProp(entry.name, component)));
|
|
1413
|
+
if (dynamicStyleEntries.length > 0 && !laneACoversAll && !supportsNativeDynamicStyles && !supportsWebConditionalClasses) {
|
|
1414
|
+
const entry = dynamicStyleEntries[0];
|
|
1415
|
+
return bailout(input, "local/dynamic-style-value", `Style prop ${entry.kind === "prop" ? entry.name : "unknown"} could not be safely extracted`, entry.span);
|
|
1416
|
+
}
|
|
1417
|
+
const resolvedStyleStaticConfig = core.getStyleStaticConfig(component.staticConfig, core.getConfig());
|
|
1418
|
+
const staticDefaultProps = resolvedStyleStaticConfig.defaultProps ?? {};
|
|
1419
|
+
const defaultProps = platform === "web" && !component.staticConfig.isText && options.tamaguiConfig.settings.defaultPosition === "relative" && staticDefaultProps.position === void 0 ? core.mergeProps({ position: "relative" }, staticDefaultProps) : staticDefaultProps;
|
|
1420
|
+
let completeProps = core.mergeProps(defaultProps, props);
|
|
1421
|
+
if (platform === "native" && component.domTag && props.display === "flex") {
|
|
1422
|
+
completeProps = core.mergeProps(core.mergeProps(defaultProps, NATIVE_FLEX_DEFAULTS), props);
|
|
1423
|
+
}
|
|
1424
|
+
const domStyleProgram = input.element.entries.find((entry) => entry.kind === "prop" && entry.name === "style" && entry.value.kind === "dom-style");
|
|
1425
|
+
if (platform === "native" && !component.domTag && domStyleProgram) {
|
|
1426
|
+
return bailout(input, "local/unsupported-target", "Native style() pieces remain on the runtime path");
|
|
1427
|
+
}
|
|
1428
|
+
const propsForConditional = (target, value) => {
|
|
1429
|
+
const branchProps = {};
|
|
1430
|
+
if (styleObjectStatic) branchProps.style = styleObjectStatic;
|
|
1431
|
+
if (target.styleMember) {
|
|
1432
|
+
branchProps.style = {
|
|
1433
|
+
...styleObjectStatic,
|
|
1434
|
+
[target.name]: value
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
for (const entry of input.element.entries) {
|
|
1438
|
+
if (entry === target) {
|
|
1439
|
+
branchProps[target.name] = value;
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
if (entry.kind === "child" || entry.value.kind !== "static") continue;
|
|
1443
|
+
if (entry.kind === "spread") {
|
|
1444
|
+
if (staticObject(entry.value.value)) Object.assign(branchProps, entry.value.value);
|
|
1445
|
+
} else {
|
|
1446
|
+
branchProps[entry.name] = entry.value.value;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (component.domTag && branchProps.hidden) branchProps.display = "none";
|
|
1450
|
+
if (resolvedCssTransition !== null) {
|
|
1451
|
+
branchProps.transition = resolvedCssTransition;
|
|
1452
|
+
}
|
|
1453
|
+
if (component.domTag && platform === "native") {
|
|
1454
|
+
for (const [name, styleKey] of DOM_STYLE_ATTRIBUTES) {
|
|
1455
|
+
if (name in branchProps) {
|
|
1456
|
+
branchProps[styleKey] = branchProps[name];
|
|
1457
|
+
delete branchProps[name];
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
const branchCompleteProps = platform === "native" && component.domTag && branchProps.display === "flex" ? core.mergeProps(core.mergeProps(defaultProps, NATIVE_FLEX_DEFAULTS), branchProps) : core.mergeProps(defaultProps, branchProps);
|
|
1462
|
+
if (platform === "native") {
|
|
1463
|
+
for (const [name, value2] of Object.entries(branchCompleteProps)) {
|
|
1464
|
+
const clause = isStyleProp(name, component) ? nativeClauseValue(value2) : null;
|
|
1465
|
+
if (clause === null || clause === "live") continue;
|
|
1466
|
+
if (clause.matched) branchCompleteProps[name] = clause.payload;
|
|
1467
|
+
else delete branchCompleteProps[name];
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
branchProps,
|
|
1472
|
+
branchCompleteProps
|
|
1473
|
+
};
|
|
1474
|
+
};
|
|
1475
|
+
if (platform === "native") {
|
|
1476
|
+
const isClauseValue = (name, value) => isStyleProp(name, component) && (typeof value === "string" && flatClausePattern.test(value) || isClauseObjectValue(value));
|
|
1477
|
+
const defaultVariants = component.staticConfig.defaultVariants ?? {};
|
|
1478
|
+
const definitionCarriesClause = Object.entries(resolvedStyleStaticConfig.baseStyle ?? {}).some(([name, value]) => isClauseValue(name, value)) || Object.entries(component.staticConfig.variants ?? {}).some(([variantName, definitions]) => (completeProps[variantName] !== void 0 || defaultVariants[variantName] !== void 0) && staticObject(definitions) && Object.values(definitions).some((definition) => staticObject(definition) && Object.entries(definition).some(([name, value]) => isClauseValue(name, value))));
|
|
1479
|
+
if (definitionCarriesClause) {
|
|
1480
|
+
return bailout(input, "local/unsupported-target", "Native conditional value programs remain on the runtime path");
|
|
1481
|
+
}
|
|
1482
|
+
const reducedProps = {};
|
|
1483
|
+
for (const [name, value] of Object.entries(completeProps)) {
|
|
1484
|
+
const clause = isStyleProp(name, component) ? nativeClauseValue(value) : null;
|
|
1485
|
+
if (clause === "live") {
|
|
1486
|
+
return bailout(input, "local/unsupported-target", "Native conditional value programs remain on the runtime path");
|
|
1487
|
+
}
|
|
1488
|
+
if (clause === null) {
|
|
1489
|
+
reducedProps[name] = value;
|
|
1490
|
+
continue;
|
|
1491
|
+
}
|
|
1492
|
+
if (clause.matched) reducedProps[name] = clause.payload;
|
|
1493
|
+
}
|
|
1494
|
+
completeProps = reducedProps;
|
|
1495
|
+
for (const entry of dynamicStyleEntries) {
|
|
1496
|
+
if (entry.value.kind !== "conditional") continue;
|
|
1497
|
+
for (const leaf of collectLeaves(entry.value.tree)) {
|
|
1498
|
+
if (nativeClauseValue(leaf.value) !== "live") continue;
|
|
1499
|
+
return bailout(input, "local/unsupported-target", "Native conditional value programs remain on the runtime path");
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
const split = resolveSplitStyles(completeProps, component.staticConfig, cssAnimationDriver, component.displayName);
|
|
1504
|
+
if (!split) {
|
|
1505
|
+
return bailout(input, "local/style-resolution-failed", "getSplitStyles returned no static result");
|
|
1506
|
+
}
|
|
1507
|
+
if (split.programLifecycleStyleKeys?.enter?.size || split.programLifecycleStyleKeys?.exit?.size) {
|
|
1508
|
+
return bailout(input, "local/unsupported-target", "Lifecycle value programs remain on the runtime path", input.element.span, {
|
|
1509
|
+
rule: 5,
|
|
1510
|
+
message: zeroRuleMessage(5, { detail: `an enter or exit style program on ${input.element.component.name}` })
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
const flatTag = component.domTag ?? (typeof props.render === "string" ? props.render : typeof defaultProps.render === "string" ? defaultProps.render : component.staticConfig.isText ? "span" : "div");
|
|
1514
|
+
const tagEdits = [input.element.component.span, input.element.component.closingSpan].filter((span) => !!span).map((span) => ({
|
|
1515
|
+
start: span.start,
|
|
1516
|
+
end: span.end,
|
|
1517
|
+
content: input.element.form === "jsx" ? flatTag : JSON.stringify(flatTag),
|
|
1518
|
+
origin: span
|
|
1519
|
+
}));
|
|
1520
|
+
const isPropIgnored = (name) => isStyleProp(name, component) || isInvalidHostStyleProp(name, component) || componentOnlyProps.has(name);
|
|
1521
|
+
const spreadReplacement = (form, entry) => spreadNonStyleReplacement(form, entry, isPropIgnored, (name, value) => {
|
|
1522
|
+
if (platform !== "web") return [name, value];
|
|
1523
|
+
if (name === "testID") return ["data-testid", value];
|
|
1524
|
+
if (component.domTag && name === "for") return ["htmlFor", value];
|
|
1525
|
+
if (component.domTag && name === "role" && value === "none") {
|
|
1526
|
+
return ["role", "presentation"];
|
|
1527
|
+
}
|
|
1528
|
+
return [name, value];
|
|
1529
|
+
});
|
|
1530
|
+
let styleEntries = input.element.entries.filter((entry) => entry.kind === "prop" && isPropIgnored(entry.name) || entry.kind === "spread" && entry.value.kind === "static" && staticObject(entry.value.value) && Object.keys(entry.value.value).some(isPropIgnored));
|
|
1531
|
+
let invalidHostStyle;
|
|
1532
|
+
for (const entry of input.element.entries) {
|
|
1533
|
+
if (entry.kind === "prop") {
|
|
1534
|
+
if (isInvalidHostStyleProp(entry.name, component)) {
|
|
1535
|
+
invalidHostStyle = {
|
|
1536
|
+
entry,
|
|
1537
|
+
name: entry.name
|
|
1538
|
+
};
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1543
|
+
if (entry.kind === "spread" && entry.value.kind === "static" && staticObject(entry.value.value)) {
|
|
1544
|
+
const name = Object.keys(entry.value.value).find((name2) => isInvalidHostStyleProp(name2, component));
|
|
1545
|
+
if (name) {
|
|
1546
|
+
invalidHostStyle = {
|
|
1547
|
+
entry,
|
|
1548
|
+
name
|
|
1549
|
+
};
|
|
1550
|
+
break;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
if (invalidHostStyle) {
|
|
1555
|
+
return bailout(input, "local/unsupported-target", `"${invalidHostStyle.name}" is a text style prop and this component is not text. Use a Text-based component, or html.* for raw web elements.`, invalidHostStyle.entry.span);
|
|
1556
|
+
}
|
|
1557
|
+
if (platform === "native" && component.domTag) {
|
|
1558
|
+
const mixedSpread = styleEntries.find((entry) => entry.kind === "spread" && entry.value.kind === "static" && staticObject(entry.value.value) && Object.keys(entry.value.value).some((name) => !isPropIgnored(name)));
|
|
1559
|
+
if (mixedSpread) {
|
|
1560
|
+
return bailout(input, "local/unsafe-style-spread", "Native DOM prop mapping requires non-style spread props to remain on the runtime path", mixedSpread.span);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
const webPropEdits = platform === "web" ? input.element.entries.flatMap((entry) => {
|
|
1564
|
+
if (entry.kind !== "prop" || entry.name !== "testID") return [];
|
|
1565
|
+
const content = input.source.slice(entry.span.start, entry.span.end);
|
|
1566
|
+
const nameOffset = content.indexOf("testID");
|
|
1567
|
+
if (nameOffset === -1) return [];
|
|
1568
|
+
const alreadyQuoted = content[nameOffset - 1] === "\"" || content[nameOffset - 1] === "'";
|
|
1569
|
+
return [{
|
|
1570
|
+
start: entry.span.start + nameOffset,
|
|
1571
|
+
end: entry.span.start + nameOffset + "testID".length,
|
|
1572
|
+
content: input.element.form === "jsx" || alreadyQuoted ? "data-testid" : `'data-testid'`,
|
|
1573
|
+
origin: entry.span
|
|
1574
|
+
}];
|
|
1575
|
+
}) : [];
|
|
1576
|
+
const webDOMResult = platform === "web" && component.domTag ? webDOMProps(input, component.domTag) : {
|
|
1577
|
+
edits: [],
|
|
1578
|
+
additions: []
|
|
1579
|
+
};
|
|
1580
|
+
webPropEdits.push(...webDOMResult.edits);
|
|
1581
|
+
if (platform === "native") {
|
|
1582
|
+
const nativeStyleResolved = split.viewProps?.style;
|
|
1583
|
+
let themedStyleKeys = null;
|
|
1584
|
+
let nativeStyle = nativeStyleResolved;
|
|
1585
|
+
if (staticObject(nativeStyleResolved)) {
|
|
1586
|
+
for (const [styleKey, styleValue] of Object.entries(nativeStyleResolved)) {
|
|
1587
|
+
if (!core.containsThemeRef(styleValue)) continue;
|
|
1588
|
+
const themeKey = core.themeRefKey(styleValue);
|
|
1589
|
+
if (!themeKey) {
|
|
1590
|
+
return bailout(input, "local/dynamic-style-value", `Style ${styleKey} uses a theme value in a compound or modified position that compiled output cannot represent`);
|
|
1591
|
+
}
|
|
1592
|
+
;
|
|
1593
|
+
(themedStyleKeys ||= {})[styleKey] = themeKey;
|
|
1594
|
+
}
|
|
1595
|
+
if (themedStyleKeys) {
|
|
1596
|
+
const plain = {};
|
|
1597
|
+
for (const [styleKey, styleValue] of Object.entries(nativeStyleResolved)) {
|
|
1598
|
+
if (!(styleKey in themedStyleKeys)) plain[styleKey] = styleValue;
|
|
1599
|
+
}
|
|
1600
|
+
nativeStyle = plain;
|
|
1601
|
+
}
|
|
1602
|
+
} else if (core.containsThemeRef(nativeStyleResolved)) {
|
|
1603
|
+
return bailout(input, "local/dynamic-style-value", "Theme values inside non-object native style output stay on the runtime path");
|
|
1604
|
+
}
|
|
1605
|
+
if (!isSerializableNativeStyle(nativeStyle)) {
|
|
1606
|
+
return bailout(input, "local/unsupported-target", "Native style output is not a static serializable value");
|
|
1607
|
+
}
|
|
1608
|
+
const nativeStyleLocal = unusedIdentifier(input.source, `__TamaguiNativeStyle${input.element.span.start}`);
|
|
1609
|
+
const nativeStyleImports = [{
|
|
1610
|
+
content: `
|
|
1611
|
+
function ${nativeStyleLocal}() { return ${nativeStyleLocal}._ ?? (${nativeStyleLocal}._ = ${JSON.stringify(nativeStyle ?? {})}); } ${nativeStyleLocal}();`,
|
|
1612
|
+
origin: input.element.component.span
|
|
1613
|
+
}];
|
|
1614
|
+
const nativeStyleSource = `${nativeStyleLocal}._ ?? ${nativeStyleLocal}()`;
|
|
1615
|
+
let nativeFastPath;
|
|
1616
|
+
if (themedStyleKeys && options.experimentalNativeFastPath && dynamicStyleEntries.length === 0 && !input.element.entries.some((entry) => entry.kind === "spread")) {
|
|
1617
|
+
const mappingLocal = unusedIdentifier(input.source, `__TamaguiNativeMapping${input.element.span.start}`);
|
|
1618
|
+
nativeFastPath = {
|
|
1619
|
+
mappingLocal,
|
|
1620
|
+
imports: [{
|
|
1621
|
+
content: `
|
|
1622
|
+
const ${mappingLocal} = ${JSON.stringify(themedStyleKeys)};`,
|
|
1623
|
+
origin: input.element.component.span
|
|
1624
|
+
}]
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
if (component.domTag) {
|
|
1628
|
+
if (themedStyleKeys) {
|
|
1629
|
+
return bailout(input, "local/unsupported-target", "Theme values on DOM-tag native output stay on the runtime path");
|
|
1630
|
+
}
|
|
1631
|
+
const row = TAGS[component.domTag];
|
|
1632
|
+
const basePrimitive = NATIVE_BACKING[row.backing].primitive;
|
|
1633
|
+
let primitive = basePrimitive;
|
|
1634
|
+
const propsResult = nativeDOMProps(input, component.domTag);
|
|
1635
|
+
if (propsResult.diagnostic) {
|
|
1636
|
+
return bailout(input, "local/unsupported-target", propsResult.diagnostic, propsResult.diagnosticSpan);
|
|
1637
|
+
}
|
|
1638
|
+
styleEntries = [.../* @__PURE__ */ new Set([...styleEntries, ...propsResult.consumed])];
|
|
1639
|
+
let nativeDOMStyleSource = nativeStyleSource;
|
|
1640
|
+
let runtimeStyleSource = null;
|
|
1641
|
+
if (domStyleProgram?.kind === "prop" && domStyleProgram.value.kind === "dom-style") {
|
|
1642
|
+
const needsRuntime = domStyleProgram.value.items.some((item) => item.value.kind === "static" && staticObject(item.value.value) && (Object.keys(item.value.value).some((property) => nativeRuntimeOnlyStyleProperties.has(property)) || Object.values(item.value.value).some((value) => typeof value === "string" && (flatClausePattern.test(value) || nativeInheritedKeywordPattern.test(value)) || isClauseObjectValue(value))));
|
|
1643
|
+
const itemSources = [];
|
|
1644
|
+
for (const item of domStyleProgram.value.items) {
|
|
1645
|
+
if (item.value.kind !== "static" || !staticObject(item.value.value)) {
|
|
1646
|
+
return bailout(input, "local/dynamic-style-value", "Every style() handle in a style array must be statically evaluable", item.value.span);
|
|
1647
|
+
}
|
|
1648
|
+
if (Object.values(item.value.value).some((value2) => typeof value2 === "string" && nativeInitialKeywordPattern.test(value2))) {
|
|
1649
|
+
return bailout(input, "local/unsupported-target", "Native DOM style() does not support the CSS initial keyword, matching the pinned upstream limitation", item.value.span);
|
|
1650
|
+
}
|
|
1651
|
+
let value;
|
|
1652
|
+
if (needsRuntime) {
|
|
1653
|
+
value = JSON.stringify(item.value.value);
|
|
1654
|
+
} else {
|
|
1655
|
+
const itemSplit = resolveSplitStyles(item.value.value, partialStaticConfig(component.staticConfig));
|
|
1656
|
+
const itemStyle = itemSplit?.viewProps?.style;
|
|
1657
|
+
if (!isSerializableNativeStyle(itemStyle) || core.containsThemeRef(itemStyle)) {
|
|
1658
|
+
return bailout(input, "local/unsupported-target", "Native style() output is not serializable", item.value.span);
|
|
1659
|
+
}
|
|
1660
|
+
value = JSON.stringify(itemStyle ?? {});
|
|
1661
|
+
}
|
|
1662
|
+
const condition = item.condition ? input.source.slice(item.condition.start, item.condition.end) : null;
|
|
1663
|
+
itemSources.push(condition ? `(${condition}) && ${value}` : value);
|
|
1664
|
+
}
|
|
1665
|
+
if (needsRuntime) {
|
|
1666
|
+
primitive = `DOMRuntime${basePrimitive.slice("DOM".length)}`;
|
|
1667
|
+
runtimeStyleSource = `[${itemSources.join(", ")}]`;
|
|
1668
|
+
} else {
|
|
1669
|
+
nativeDOMStyleSource = `[${[nativeDOMStyleSource, ...itemSources].join(", ")}]`;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
const nativeLocal2 = unusedIdentifier(input.source, `__Tamagui${primitive}`);
|
|
1673
|
+
const propertyContent = [
|
|
1674
|
+
input.element.form === "jsx" ? `style={${nativeDOMStyleSource}}` : `style: ${nativeDOMStyleSource}`,
|
|
1675
|
+
runtimeStyleSource ? input.element.form === "jsx" ? `__styles={${runtimeStyleSource}}` : `__styles: ${runtimeStyleSource}` : "",
|
|
1676
|
+
serializedProps(input.element.form, propsResult.additions)
|
|
1677
|
+
].filter(Boolean).join(input.element.form === "jsx" ? " " : ", ");
|
|
1678
|
+
const primitiveTagEdits = [input.element.component.span, input.element.component.closingSpan].filter((span) => !!span).map((span) => ({
|
|
1679
|
+
start: span.start,
|
|
1680
|
+
end: span.end,
|
|
1681
|
+
content: input.element.form === "jsx" ? nativeLocal2 : JSON.stringify(nativeLocal2).slice(1, -1),
|
|
1682
|
+
origin: span
|
|
1683
|
+
}));
|
|
1684
|
+
const literalEdits = [];
|
|
1685
|
+
const imports = [...nativeStyleImports, {
|
|
1686
|
+
content: `
|
|
1687
|
+
import { ${primitive} as ${nativeLocal2} } from ${JSON.stringify(NATIVE_PRIMITIVE_MODULE)}
|
|
1688
|
+
`,
|
|
1689
|
+
origin: input.element.component.span
|
|
1690
|
+
}];
|
|
1691
|
+
if (NATIVE_BACKING[row.backing].wrapsLiteralText) {
|
|
1692
|
+
const textLocal = unusedIdentifier(input.source, "__TamaguiDOMText");
|
|
1693
|
+
const createElementLocal = unusedIdentifier(input.source, "__TamaguiCreateElement");
|
|
1694
|
+
let needsText = false;
|
|
1695
|
+
let needsCreateElement = false;
|
|
1696
|
+
for (const entry of input.element.entries) {
|
|
1697
|
+
if (entry.kind !== "child") continue;
|
|
1698
|
+
if (entry.value.kind === "empty" || entry.value.kind === "element" || entry.value.kind === "static" && (entry.value.value === null || typeof entry.value.value === "boolean")) {
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
if (entry.value.kind !== "static" || entry.value.literalOrigin !== true || typeof entry.value.value !== "string" && typeof entry.value.value !== "number") {
|
|
1702
|
+
return bailout(input, "local/unsupported-child", `html.${component.domTag} has a direct child that may render unwrapped native text; write a literal as JSX text or wrap the child in html.span`, entry.span);
|
|
1703
|
+
}
|
|
1704
|
+
needsText = true;
|
|
1705
|
+
const child = input.source.slice(entry.span.start, entry.span.end);
|
|
1706
|
+
if (input.element.form === "jsx") {
|
|
1707
|
+
literalEdits.push({
|
|
1708
|
+
start: entry.span.start,
|
|
1709
|
+
end: entry.span.end,
|
|
1710
|
+
content: `<${textLocal} __inherit>${child}</${textLocal}>`,
|
|
1711
|
+
origin: entry.span
|
|
1712
|
+
});
|
|
1713
|
+
} else {
|
|
1714
|
+
needsCreateElement = true;
|
|
1715
|
+
literalEdits.push({
|
|
1716
|
+
start: entry.span.start,
|
|
1717
|
+
end: entry.span.end,
|
|
1718
|
+
content: `${createElementLocal}(${textLocal}, { __inherit: true }, ${child})`,
|
|
1719
|
+
origin: entry.span
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
if (needsText) {
|
|
1724
|
+
imports.push({
|
|
1725
|
+
content: `
|
|
1726
|
+
import { DOMText as ${textLocal} } from ${JSON.stringify(NATIVE_PRIMITIVE_MODULE)}
|
|
1727
|
+
`,
|
|
1728
|
+
origin: input.element.component.span
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
if (needsCreateElement) {
|
|
1732
|
+
imports.push({
|
|
1733
|
+
content: `
|
|
1734
|
+
import { createElement as ${createElementLocal} } from "react"
|
|
1735
|
+
`,
|
|
1736
|
+
origin: input.element.component.span
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
const [first3, ...rest3] = styleEntries;
|
|
1741
|
+
const firstNonStyle3 = first3 ? spreadReplacement("jsx", first3) : "";
|
|
1742
|
+
const propsEdits = input.element.form === "jsx" ? styleEntries.length === 0 ? [{
|
|
1743
|
+
start: input.element.component.span.end,
|
|
1744
|
+
end: input.element.component.span.end,
|
|
1745
|
+
content: ` ${propertyContent}`,
|
|
1746
|
+
origin: input.element.component.span
|
|
1747
|
+
}] : [{
|
|
1748
|
+
start: first3.span.start,
|
|
1749
|
+
end: first3.span.end,
|
|
1750
|
+
content: [propertyContent, firstNonStyle3].filter(Boolean).join(" "),
|
|
1751
|
+
origin: first3.span
|
|
1752
|
+
}, ...rest3.map((entry) => ({
|
|
1753
|
+
start: entry.span.start,
|
|
1754
|
+
end: entry.span.end,
|
|
1755
|
+
content: spreadReplacement("jsx", entry),
|
|
1756
|
+
origin: entry.span
|
|
1757
|
+
}))] : compiledPropsEdits(input, styleEntries, propertyContent, (entry) => spreadReplacement(input.element.form, entry));
|
|
1758
|
+
if (!propsEdits) {
|
|
1759
|
+
return bailout(input, "local/unsupported-target", `Compiled ${input.element.form} call has no editable props argument`);
|
|
1760
|
+
}
|
|
1761
|
+
return {
|
|
1762
|
+
ok: true,
|
|
1763
|
+
edits: [
|
|
1764
|
+
...primitiveTagEdits,
|
|
1765
|
+
...propsResult.edits,
|
|
1766
|
+
...propsEdits,
|
|
1767
|
+
...literalEdits
|
|
1768
|
+
],
|
|
1769
|
+
css: [],
|
|
1770
|
+
imports,
|
|
1771
|
+
flattened: true
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
const nativeName = component.staticConfig.isText ? "Text" : "View";
|
|
1775
|
+
const useHostView = options.experimentalNativeFastPath && nativeName === "View" && isBareHostView(input.element);
|
|
1776
|
+
const nativeExport = useHostView ? "unstable_NativeView" : nativeName;
|
|
1777
|
+
const nativeLocal = unusedIdentifier(input.source, `__TamaguiNative${useHostView ? "HostView" : nativeName}`);
|
|
1778
|
+
if (themedStyleKeys && options.disablePartialExtraction) {
|
|
1779
|
+
return bailout(input, "local/dynamic-style-value", "Theme values require partial extraction, which is disabled");
|
|
1780
|
+
}
|
|
1781
|
+
if (dynamicStyleEntries.length > 0 || themedStyleKeys) {
|
|
1782
|
+
if (nativeFastPath) {
|
|
1783
|
+
const fastLocal = `__TamaguiNativeFast${nativeName}${input.element.span.start}`;
|
|
1784
|
+
const tagEdits4 = [input.element.component.span, input.element.component.closingSpan].filter((span) => !!span).map((span) => ({
|
|
1785
|
+
start: span.start,
|
|
1786
|
+
end: span.end,
|
|
1787
|
+
content: fastLocal,
|
|
1788
|
+
origin: span
|
|
1789
|
+
}));
|
|
1790
|
+
const [first4, ...rest4] = styleEntries;
|
|
1791
|
+
const styleEdits = styleEntries.length === 0 ? [] : input.element.form === "jsx" ? [{
|
|
1792
|
+
start: first4.span.start,
|
|
1793
|
+
end: first4.span.end,
|
|
1794
|
+
content: "",
|
|
1795
|
+
origin: first4.span
|
|
1796
|
+
}, ...rest4.map((entry) => ({
|
|
1797
|
+
start: entry.span.start,
|
|
1798
|
+
end: entry.span.end,
|
|
1799
|
+
content: "",
|
|
1800
|
+
origin: entry.span
|
|
1801
|
+
}))] : compiledPropsEdits(input, styleEntries, `_expressions: []`);
|
|
1802
|
+
if (!styleEdits) {
|
|
1803
|
+
return bailout(input, "local/unsupported-target", `Compiled ${input.element.form} call has no editable props argument`);
|
|
1804
|
+
}
|
|
1805
|
+
return {
|
|
1806
|
+
ok: true,
|
|
1807
|
+
edits: [...tagEdits4, ...styleEdits],
|
|
1808
|
+
css: [],
|
|
1809
|
+
imports: [
|
|
1810
|
+
...nativeStyleImports,
|
|
1811
|
+
...nativeFastPath.imports,
|
|
1812
|
+
{
|
|
1813
|
+
content: `
|
|
1814
|
+
const ${nativeLocal} = require('react-native').${nativeExport};`,
|
|
1815
|
+
origin: input.element.component.span
|
|
1816
|
+
},
|
|
1817
|
+
{
|
|
1818
|
+
content: `
|
|
1819
|
+
const ${fastLocal} = require('@tamagui/core')._withNativeStyle(${nativeLocal}, ${nativeStyleSource}, ${nativeFastPath.mappingLocal});`,
|
|
1820
|
+
origin: input.element.component.span
|
|
1821
|
+
}
|
|
1822
|
+
],
|
|
1823
|
+
flattened: true
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
const stableLocal = `__TamaguiStable${nativeName}${input.element.span.start}`;
|
|
1827
|
+
const expressions = [];
|
|
1828
|
+
const plainDynamicParts = [];
|
|
1829
|
+
const conditionalParts = [];
|
|
1830
|
+
const conditionalKeys = /* @__PURE__ */ new Set();
|
|
1831
|
+
const baseStyleForDiff = staticObject(nativeStyleResolved) ? nativeStyleResolved : {};
|
|
1832
|
+
for (const entry of dynamicStyleEntries) {
|
|
1833
|
+
if (entry.value.kind === "conditional" && directStyleName(entry.name, component) !== "opacity") {
|
|
1834
|
+
let serializeNativeTree = function(node) {
|
|
1835
|
+
if (node.kind === "leaf") {
|
|
1836
|
+
const diff = leafDiffs.get(node) ?? {};
|
|
1837
|
+
return JSON.stringify(diff);
|
|
1838
|
+
}
|
|
1839
|
+
const index = expressions.length;
|
|
1840
|
+
expressions.push(input.source.slice(node.test.start, node.test.end));
|
|
1841
|
+
return `expressions[${index}] ? ${serializeNativeTree(node.whenTrue)} : ${serializeNativeTree(node.whenFalse)}`;
|
|
1842
|
+
};
|
|
1843
|
+
const tree = entry.value.tree;
|
|
1844
|
+
const leaves = collectLeaves(tree);
|
|
1845
|
+
const leafDiffs = /* @__PURE__ */ new Map();
|
|
1846
|
+
for (const leaf of leaves) {
|
|
1847
|
+
const { branchCompleteProps } = propsForConditional(entry, leaf.value);
|
|
1848
|
+
const branchSplit = resolveSplitStyles(branchCompleteProps, component.staticConfig, cssAnimationDriver, component.displayName);
|
|
1849
|
+
const branchStyle = branchSplit?.viewProps?.style ?? {};
|
|
1850
|
+
if (!staticObject(branchStyle)) {
|
|
1851
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch did not resolve to a static native style`, entry.value.span);
|
|
1852
|
+
}
|
|
1853
|
+
for (const viewPropsKey of /* @__PURE__ */ new Set([...Object.keys(branchSplit?.viewProps ?? {}), ...Object.keys(split.viewProps ?? {})])) {
|
|
1854
|
+
if (viewPropsKey === "style") continue;
|
|
1855
|
+
if (JSON.stringify(branchSplit?.viewProps?.[viewPropsKey]) !== JSON.stringify(split.viewProps?.[viewPropsKey])) {
|
|
1856
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch changes ${viewPropsKey}, which the compiled style array cannot express`, entry.value.span);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
for (const key of Object.keys(baseStyleForDiff)) {
|
|
1860
|
+
if (!(key in branchStyle)) {
|
|
1861
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch removes ${key}, which an additive style array cannot express`, entry.value.span);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
const diff = {};
|
|
1865
|
+
for (const [key, value] of Object.entries(branchStyle)) {
|
|
1866
|
+
if (JSON.stringify(baseStyleForDiff[key]) !== JSON.stringify(value)) {
|
|
1867
|
+
diff[key] = value;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
if (!isSerializableNativeStyle(diff) || core.containsThemeRef(diff)) {
|
|
1871
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch style is not statically representable`, entry.value.span);
|
|
1872
|
+
}
|
|
1873
|
+
for (const key of Object.keys(diff)) {
|
|
1874
|
+
if (conditionalKeys.has(key)) {
|
|
1875
|
+
return bailout(input, "local/dynamic-style-value", `Multiple conditionals contribute ${key}; their interaction cannot be resolved per-branch`, entry.value.span);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
leafDiffs.set(leaf, diff);
|
|
1879
|
+
}
|
|
1880
|
+
for (const diff of leafDiffs.values()) {
|
|
1881
|
+
for (const key of Object.keys(diff)) conditionalKeys.add(key);
|
|
1882
|
+
}
|
|
1883
|
+
conditionalParts.push(serializeNativeTree(tree));
|
|
1884
|
+
} else {
|
|
1885
|
+
const index = expressions.length;
|
|
1886
|
+
expressions.push(input.source.slice(entry.value.span.start, entry.value.span.end));
|
|
1887
|
+
plainDynamicParts.push(`${JSON.stringify(directStyleName(entry.name, component))}: expressions[${index}]`);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
const dynamicStyle = plainDynamicParts.join(", ");
|
|
1891
|
+
const themedStyle = themedStyleKeys ? Object.entries(themedStyleKeys).map(([styleKey, themeKey]) => `${JSON.stringify(styleKey)}: _theme[${JSON.stringify(themeKey)}]?.get()`).join(", ") : null;
|
|
1892
|
+
const styleParts = [
|
|
1893
|
+
nativeStyleSource,
|
|
1894
|
+
...themedStyle ? [`{ ${themedStyle} }`] : [],
|
|
1895
|
+
...conditionalParts,
|
|
1896
|
+
...dynamicStyle ? [`{ ${dynamicStyle} }`] : []
|
|
1897
|
+
];
|
|
1898
|
+
const tagEdits3 = [input.element.component.span, input.element.component.closingSpan].filter((span) => !!span).map((span) => ({
|
|
1899
|
+
start: span.start,
|
|
1900
|
+
end: span.end,
|
|
1901
|
+
content: stableLocal,
|
|
1902
|
+
origin: span
|
|
1903
|
+
}));
|
|
1904
|
+
const [first3, ...rest3] = styleEntries;
|
|
1905
|
+
const firstNonStyle3 = first3 ? spreadReplacement("jsx", first3) : "";
|
|
1906
|
+
const expressionEdits = styleEntries.length === 0 ? [] : input.element.form === "jsx" ? [{
|
|
1907
|
+
start: first3.span.start,
|
|
1908
|
+
end: first3.span.end,
|
|
1909
|
+
content: [expressions.length > 0 ? `_expressions={[${expressions.join(", ")}]}` : "", firstNonStyle3].filter(Boolean).join(" "),
|
|
1910
|
+
origin: first3.span
|
|
1911
|
+
}, ...rest3.map((entry) => ({
|
|
1912
|
+
start: entry.span.start,
|
|
1913
|
+
end: entry.span.end,
|
|
1914
|
+
content: spreadReplacement("jsx", entry),
|
|
1915
|
+
origin: entry.span
|
|
1916
|
+
}))] : compiledPropsEdits(input, styleEntries, `_expressions: [${expressions.join(", ")}]`, (entry) => spreadReplacement(input.element.form, entry));
|
|
1917
|
+
if (!expressionEdits) {
|
|
1918
|
+
return bailout(input, "local/unsupported-target", `Compiled ${input.element.form} call has no editable props argument`);
|
|
1919
|
+
}
|
|
1920
|
+
return {
|
|
1921
|
+
ok: true,
|
|
1922
|
+
edits: [...tagEdits3, ...expressionEdits],
|
|
1923
|
+
css: [],
|
|
1924
|
+
imports: [
|
|
1925
|
+
...nativeStyleImports,
|
|
1926
|
+
{
|
|
1927
|
+
content: `
|
|
1928
|
+
const ${nativeLocal} = require('react-native').${nativeExport};`,
|
|
1929
|
+
origin: input.element.component.span
|
|
1930
|
+
},
|
|
1931
|
+
{
|
|
1932
|
+
content: `
|
|
1933
|
+
const ${stableLocal} = require('@tamagui/core')._withStableStyle(${nativeLocal}, (_theme, expressions) => [${styleParts.join(", ")}], ${themedStyleKeys ? "true" : "false"}, false);`,
|
|
1934
|
+
origin: input.element.component.span
|
|
1935
|
+
}
|
|
1936
|
+
],
|
|
1937
|
+
flattened: true
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
const styleContent = `style: ${nativeStyleSource}`;
|
|
1941
|
+
const tagEdits2 = [input.element.component.span, input.element.component.closingSpan].filter((span) => !!span).map((span) => ({
|
|
1942
|
+
start: span.start,
|
|
1943
|
+
end: span.end,
|
|
1944
|
+
content: nativeLocal,
|
|
1945
|
+
origin: span
|
|
1946
|
+
}));
|
|
1947
|
+
if (input.element.form !== "jsx") {
|
|
1948
|
+
const propsEdits = compiledPropsEdits(input, styleEntries, styleContent, (entry) => spreadReplacement(input.element.form, entry));
|
|
1949
|
+
if (!propsEdits) {
|
|
1950
|
+
return bailout(input, "local/unsupported-target", `Compiled ${input.element.form} call has no editable props argument`);
|
|
1951
|
+
}
|
|
1952
|
+
return {
|
|
1953
|
+
ok: true,
|
|
1954
|
+
edits: [...tagEdits2, ...propsEdits],
|
|
1955
|
+
css: [],
|
|
1956
|
+
imports: [...nativeStyleImports, {
|
|
1957
|
+
content: `
|
|
1958
|
+
const ${nativeLocal} = require('react-native').${nativeExport};`,
|
|
1959
|
+
origin: input.element.component.span
|
|
1960
|
+
}],
|
|
1961
|
+
flattened: true
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
if (styleEntries.length === 0) {
|
|
1965
|
+
return {
|
|
1966
|
+
ok: true,
|
|
1967
|
+
edits: [...tagEdits2, {
|
|
1968
|
+
start: input.element.component.span.end,
|
|
1969
|
+
end: input.element.component.span.end,
|
|
1970
|
+
content: ` style={${nativeStyleSource}}`,
|
|
1971
|
+
origin: input.element.component.span
|
|
1972
|
+
}],
|
|
1973
|
+
css: [],
|
|
1974
|
+
imports: [...nativeStyleImports, {
|
|
1975
|
+
content: `
|
|
1976
|
+
const ${nativeLocal} = require('react-native').${nativeExport};`,
|
|
1977
|
+
origin: input.element.component.span
|
|
1978
|
+
}],
|
|
1979
|
+
flattened: true
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
const [first2, ...rest2] = styleEntries;
|
|
1983
|
+
const firstNonStyle2 = first2 ? spreadReplacement("jsx", first2) : "";
|
|
1984
|
+
return {
|
|
1985
|
+
ok: true,
|
|
1986
|
+
edits: [
|
|
1987
|
+
...tagEdits2,
|
|
1988
|
+
...webPropEdits,
|
|
1989
|
+
{
|
|
1990
|
+
start: first2.span.start,
|
|
1991
|
+
end: first2.span.end,
|
|
1992
|
+
content: [`style={${nativeStyleSource}}`, firstNonStyle2].filter(Boolean).join(" "),
|
|
1993
|
+
origin: first2.span
|
|
1994
|
+
},
|
|
1995
|
+
...rest2.map((entry) => ({
|
|
1996
|
+
start: entry.span.start,
|
|
1997
|
+
end: entry.span.end,
|
|
1998
|
+
content: spreadReplacement("jsx", entry),
|
|
1999
|
+
origin: entry.span
|
|
2000
|
+
}))
|
|
2001
|
+
],
|
|
2002
|
+
css: [],
|
|
2003
|
+
imports: [...nativeStyleImports, {
|
|
2004
|
+
content: `
|
|
2005
|
+
const ${nativeLocal} = require('react-native').${nativeExport};`,
|
|
2006
|
+
origin: input.element.component.span
|
|
2007
|
+
}],
|
|
2008
|
+
flattened: true
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
const artifacts = extractedStyleArtifacts(split, props, options.tamaguiConfig, !component.domTag, Boolean(component.staticConfig.styleFrontend));
|
|
2012
|
+
const className = artifacts.className;
|
|
2013
|
+
const rawInlineStyle = split.viewProps?.style;
|
|
2014
|
+
const inlineStyle = staticObject(rawInlineStyle) && Object.keys(rawInlineStyle).length > 0 ? rawInlineStyle : null;
|
|
2015
|
+
if (rawInlineStyle && !inlineStyle && !isSerializableNativeStyle(rawInlineStyle)) {
|
|
2016
|
+
return bailout(input, "local/unsupported-target", "Web inline style output is not a static serializable value");
|
|
2017
|
+
}
|
|
2018
|
+
const programCSS = [];
|
|
2019
|
+
const programClassSources = [];
|
|
2020
|
+
if (domStyleProgram?.kind === "prop" && domStyleProgram.value.kind === "dom-style") {
|
|
2021
|
+
for (const item of domStyleProgram.value.items) {
|
|
2022
|
+
if (item.value.kind !== "static" || !staticObject(item.value.value)) {
|
|
2023
|
+
return bailout(input, "local/dynamic-style-value", "Every style() handle in a style array must be statically evaluable", item.value.span);
|
|
2024
|
+
}
|
|
2025
|
+
const itemSplit = resolveSplitStyles(item.value.value, partialStaticConfig(component.staticConfig));
|
|
2026
|
+
if (!itemSplit) {
|
|
2027
|
+
return bailout(input, "local/style-resolution-failed", "A style() handle could not be resolved", item.value.span);
|
|
2028
|
+
}
|
|
2029
|
+
const itemInline = itemSplit.viewProps?.style;
|
|
2030
|
+
if (staticObject(itemInline) && Object.keys(itemInline).length > 0) {
|
|
2031
|
+
return bailout(input, "local/unsupported-target", "Conditional web style() handles must lower to CSS classes", item.value.span);
|
|
2032
|
+
}
|
|
2033
|
+
const itemArtifacts = extractedStyleArtifacts(itemSplit, item.value.value, options.tamaguiConfig, false);
|
|
2034
|
+
programCSS.push(...itemArtifacts.css);
|
|
2035
|
+
if (itemArtifacts.className) {
|
|
2036
|
+
const condition = item.condition ? input.source.slice(item.condition.start, item.condition.end) : null;
|
|
2037
|
+
programClassSources.push(condition ? `(${condition}) && ${JSON.stringify(itemArtifacts.className)}` : JSON.stringify(itemArtifacts.className));
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
const baseStaticClasses = new Set(className.split(" ").filter(Boolean));
|
|
2042
|
+
const staticClasses = new Set(baseStaticClasses);
|
|
2043
|
+
const webConditionalCSS = [];
|
|
2044
|
+
const webConditionalKeys = /* @__PURE__ */ new Set();
|
|
2045
|
+
const webConditionalEntries = supportsWebConditionalClasses ? webClassEntries : [];
|
|
2046
|
+
let webInlineStyle = inlineStyle;
|
|
2047
|
+
const conditionalInlineProperties = [];
|
|
2048
|
+
for (const entry of webConditionalEntries) {
|
|
2049
|
+
let serializeWebTree = function(node) {
|
|
2050
|
+
if (node.kind === "leaf") return JSON.stringify(leafClasses(node));
|
|
2051
|
+
const test = input.source.slice(node.test.start, node.test.end);
|
|
2052
|
+
const truePart = serializeWebTree(node.whenTrue);
|
|
2053
|
+
const falsePart = serializeWebTree(node.whenFalse);
|
|
2054
|
+
return `(${test}) ? ${truePart} : ${falsePart}`;
|
|
2055
|
+
};
|
|
2056
|
+
const tree = entry.value.kind === "conditional" ? entry.value.tree : null;
|
|
2057
|
+
const domain = frontendClassDomain(entry, component);
|
|
2058
|
+
if (!tree && !domain) continue;
|
|
2059
|
+
const leaves = tree ? collectLeaves(tree) : domain.map((value) => ({
|
|
2060
|
+
value,
|
|
2061
|
+
dependencies: []
|
|
2062
|
+
}));
|
|
2063
|
+
const leafArtifactsMap = /* @__PURE__ */ new Map();
|
|
2064
|
+
const leafStyles = /* @__PURE__ */ new Map();
|
|
2065
|
+
const entryConditionalKeys = /* @__PURE__ */ new Set();
|
|
2066
|
+
for (const leaf of leaves) {
|
|
2067
|
+
const { branchProps, branchCompleteProps } = propsForConditional(entry, leaf.value);
|
|
2068
|
+
const branchSplit = resolveSplitStyles(branchCompleteProps, component.staticConfig, cssAnimationDriver, component.displayName);
|
|
2069
|
+
if (!branchSplit) {
|
|
2070
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch could not be resolved`, entry.value.span);
|
|
2071
|
+
}
|
|
2072
|
+
for (const viewPropsKey of /* @__PURE__ */ new Set([...Object.keys(branchSplit.viewProps ?? {}), ...Object.keys(split.viewProps ?? {})])) {
|
|
2073
|
+
if (viewPropsKey === "className" || viewPropsKey === "style") continue;
|
|
2074
|
+
if (JSON.stringify(branchSplit.viewProps?.[viewPropsKey]) !== JSON.stringify(split.viewProps?.[viewPropsKey])) {
|
|
2075
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch changes ${viewPropsKey}, which conditional classes cannot express`, entry.value.span);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
const branchInline = branchSplit.viewProps?.style;
|
|
2079
|
+
if (branchInline !== void 0 && !staticObject(branchInline)) {
|
|
2080
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch style is not a static object`, entry.value.span);
|
|
2081
|
+
}
|
|
2082
|
+
leafStyles.set(leaf, staticObject(branchInline) ? branchInline : {});
|
|
2083
|
+
const changedKeys = /* @__PURE__ */ new Set();
|
|
2084
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(branchSplit.classNames ?? {}), ...Object.keys(split.classNames ?? {})])) {
|
|
2085
|
+
if (JSON.stringify(branchSplit.classNames?.[key]) !== JSON.stringify(split.classNames?.[key])) {
|
|
2086
|
+
changedKeys.add(key);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
const branchStyle = branchSplit.viewProps?.style;
|
|
2090
|
+
const baseStyle = split.viewProps?.style;
|
|
2091
|
+
if (staticObject(branchStyle) || staticObject(baseStyle)) {
|
|
2092
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(staticObject(branchStyle) ? branchStyle : {}), ...Object.keys(staticObject(baseStyle) ? baseStyle : {})])) {
|
|
2093
|
+
if (JSON.stringify(staticObject(branchStyle) ? branchStyle[key] : void 0) !== JSON.stringify(staticObject(baseStyle) ? baseStyle[key] : void 0)) {
|
|
2094
|
+
changedKeys.add(key);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
for (const key of changedKeys) {
|
|
2099
|
+
if (webConditionalKeys.has(key)) {
|
|
2100
|
+
return bailout(input, "local/dynamic-style-value", `Multiple conditionals contribute ${key}; their interaction cannot be resolved per-branch`, entry.value.span);
|
|
2101
|
+
}
|
|
2102
|
+
entryConditionalKeys.add(key);
|
|
2103
|
+
}
|
|
2104
|
+
if (conflictsWithInline(changedKeys, laneAOwners, laneAMemberOwners)) {
|
|
2105
|
+
return bailout(input, "local/dynamic-style-value", `${entry.name} and an inline dynamic style both contribute a CSS property; their precedence cannot be resolved per-branch`, entry.value.span);
|
|
2106
|
+
}
|
|
2107
|
+
const branchArtifacts = extractedStyleArtifacts(branchSplit, branchProps, options.tamaguiConfig, !component.domTag, Boolean(component.staticConfig.styleFrontend));
|
|
2108
|
+
leafArtifactsMap.set(leaf, {
|
|
2109
|
+
classes: branchArtifacts.className.split(" ").filter(Boolean),
|
|
2110
|
+
css: branchArtifacts.css
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
for (const key of entryConditionalKeys) webConditionalKeys.add(key);
|
|
2114
|
+
const styleKeys = new Set(Object.keys(webInlineStyle ?? {}));
|
|
2115
|
+
for (const leaf of leaves) {
|
|
2116
|
+
for (const key of Object.keys(leafStyles.get(leaf) ?? {})) styleKeys.add(key);
|
|
2117
|
+
}
|
|
2118
|
+
for (const key of styleKeys) {
|
|
2119
|
+
const serialized = leaves.map((leaf) => JSON.stringify(leafStyles.get(leaf)?.[key]));
|
|
2120
|
+
if (serialized.every((value) => value === serialized[0])) {
|
|
2121
|
+
if (serialized[0] === JSON.stringify(webInlineStyle?.[key])) continue;
|
|
2122
|
+
const next = { ...webInlineStyle };
|
|
2123
|
+
if (serialized[0] === void 0) delete next[key];
|
|
2124
|
+
else next[key] = leafStyles.get(leaves[0])[key];
|
|
2125
|
+
webInlineStyle = Object.keys(next).length > 0 ? next : null;
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
if (!tree) {
|
|
2129
|
+
return bailout(input, "local/dynamic-style-value", `Conditional ${entry.name} branch changes style, which a class table cannot express`, entry.value.span);
|
|
2130
|
+
}
|
|
2131
|
+
const serializeValue = (node) => {
|
|
2132
|
+
if (node.kind === "leaf") return String(JSON.stringify(leafStyles.get(node)?.[key]));
|
|
2133
|
+
const test = input.source.slice(node.test.start, node.test.end);
|
|
2134
|
+
return `(${test}) ? ${serializeValue(node.whenTrue)} : ${serializeValue(node.whenFalse)}`;
|
|
2135
|
+
};
|
|
2136
|
+
conditionalInlineProperties.push(`${JSON.stringify(key)}: (${serializeValue(tree)})`);
|
|
2137
|
+
}
|
|
2138
|
+
for (const artifacts2 of leafArtifactsMap.values()) {
|
|
2139
|
+
webConditionalCSS.push(...artifacts2.css);
|
|
2140
|
+
}
|
|
2141
|
+
const allLeafArtifacts = leaves.map((l) => leafArtifactsMap.get(l));
|
|
2142
|
+
const sharedInConditional = new Set(allLeafArtifacts[0]?.classes.filter((c) => allLeafArtifacts.every((a) => a.classes.includes(c))) ?? []);
|
|
2143
|
+
for (const cls of baseStaticClasses) {
|
|
2144
|
+
if (!sharedInConditional.has(cls)) staticClasses.delete(cls);
|
|
2145
|
+
}
|
|
2146
|
+
for (const cls of sharedInConditional) {
|
|
2147
|
+
if (!baseStaticClasses.has(cls)) staticClasses.add(cls);
|
|
2148
|
+
}
|
|
2149
|
+
const leafClasses = (leaf) => {
|
|
2150
|
+
const artifacts2 = leafArtifactsMap.get(leaf);
|
|
2151
|
+
const only = artifacts2 ? artifacts2.classes.filter((item) => !sharedInConditional.has(item)) : [];
|
|
2152
|
+
return only.join(" ");
|
|
2153
|
+
};
|
|
2154
|
+
if (leaves.every((leaf) => leafClasses(leaf) === "")) {} else if (tree) {
|
|
2155
|
+
programClassSources.push(serializeWebTree(tree));
|
|
2156
|
+
} else {
|
|
2157
|
+
const table = Object.fromEntries(leaves.map((leaf) => [leaf.value, leafClasses(leaf)]));
|
|
2158
|
+
const key = input.source.slice(entry.value.span.start, entry.value.span.end);
|
|
2159
|
+
programClassSources.push(`(${JSON.stringify(table)})[${key}]`);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
const webClassName = [...staticClasses].join(" ");
|
|
2163
|
+
const hasStyleProgram = programClassSources.length > 0;
|
|
2164
|
+
const classNameExpression = hasStyleProgram ? `[${[JSON.stringify(webClassName), ...programClassSources].join(", ")}].filter(Boolean).join(" ")` : null;
|
|
2165
|
+
const webInlineProperties = [...dynamicHostStyleProperties ?? [], ...conditionalInlineProperties];
|
|
2166
|
+
const serializedInlineStyle = serializedStyle(webInlineStyle, webInlineProperties);
|
|
2167
|
+
const jsxWebStyle = classNameExpression ? [`className={${classNameExpression}}`, serializedInlineStyle ? `style={${serializedInlineStyle}}` : ""].filter(Boolean).join(" ") : jsxStyleAttributes(webClassName, webInlineStyle, webInlineProperties);
|
|
2168
|
+
const objectWebStyle = classNameExpression ? [`className: ${classNameExpression}`, serializedInlineStyle ? `style: ${serializedInlineStyle}` : ""].filter(Boolean).join(", ") : objectStyleProperties(webClassName, webInlineStyle, webInlineProperties);
|
|
2169
|
+
const webCSS = [.../* @__PURE__ */ new Set([
|
|
2170
|
+
...artifacts.css,
|
|
2171
|
+
...programCSS,
|
|
2172
|
+
...webConditionalCSS
|
|
2173
|
+
])];
|
|
2174
|
+
const webExtraProps = serializedProps(input.element.form, webDOMResult.additions);
|
|
2175
|
+
if (input.element.form !== "jsx") {
|
|
2176
|
+
const replacement = [objectWebStyle, webExtraProps].filter(Boolean).join(", ");
|
|
2177
|
+
const propsEdits = compiledPropsEdits(input, styleEntries, replacement, (entry) => spreadReplacement(input.element.form, entry));
|
|
2178
|
+
if (!propsEdits) {
|
|
2179
|
+
return bailout(input, "local/unsupported-target", `Compiled ${input.element.form} call has no editable props argument`);
|
|
2180
|
+
}
|
|
2181
|
+
return {
|
|
2182
|
+
ok: true,
|
|
2183
|
+
edits: [
|
|
2184
|
+
...tagEdits,
|
|
2185
|
+
...webPropEdits,
|
|
2186
|
+
...propsEdits
|
|
2187
|
+
],
|
|
2188
|
+
css: webCSS,
|
|
2189
|
+
imports: [],
|
|
2190
|
+
flattened: true
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
if (styleEntries.length === 0) {
|
|
2194
|
+
const attributes2 = [jsxWebStyle, webExtraProps].filter(Boolean).join(" ");
|
|
2195
|
+
return {
|
|
2196
|
+
ok: true,
|
|
2197
|
+
edits: attributes2 ? [
|
|
2198
|
+
...tagEdits,
|
|
2199
|
+
...webPropEdits,
|
|
2200
|
+
{
|
|
2201
|
+
start: input.element.component.span.end,
|
|
2202
|
+
end: input.element.component.span.end,
|
|
2203
|
+
content: ` ${attributes2}`,
|
|
2204
|
+
origin: input.element.component.span
|
|
2205
|
+
}
|
|
2206
|
+
] : [...tagEdits, ...webPropEdits],
|
|
2207
|
+
css: webCSS,
|
|
2208
|
+
imports: [],
|
|
2209
|
+
flattened: true
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
const [first, ...rest] = styleEntries;
|
|
2213
|
+
const firstNonStyle = first ? spreadReplacement("jsx", first) : "";
|
|
2214
|
+
const attributes = [
|
|
2215
|
+
jsxWebStyle,
|
|
2216
|
+
webExtraProps,
|
|
2217
|
+
firstNonStyle
|
|
2218
|
+
].filter(Boolean).join(" ");
|
|
2219
|
+
return {
|
|
2220
|
+
ok: true,
|
|
2221
|
+
edits: [
|
|
2222
|
+
...tagEdits,
|
|
2223
|
+
...webPropEdits,
|
|
2224
|
+
{
|
|
2225
|
+
start: first.span.start,
|
|
2226
|
+
end: first.span.end,
|
|
2227
|
+
content: attributes,
|
|
2228
|
+
origin: first.span
|
|
2229
|
+
},
|
|
2230
|
+
...rest.map((entry) => ({
|
|
2231
|
+
start: entry.span.start,
|
|
2232
|
+
end: entry.span.end,
|
|
2233
|
+
content: spreadReplacement("jsx", entry),
|
|
2234
|
+
origin: entry.span
|
|
2235
|
+
}))
|
|
2236
|
+
],
|
|
2237
|
+
css: webCSS,
|
|
2238
|
+
imports: [],
|
|
2239
|
+
flattened: true
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
function bailout(input, code, message, span = input.element.span, zero, prop) {
|
|
2245
|
+
return {
|
|
2246
|
+
ok: false,
|
|
2247
|
+
bailout: {
|
|
2248
|
+
code,
|
|
2249
|
+
kind: "local",
|
|
2250
|
+
message,
|
|
2251
|
+
span,
|
|
2252
|
+
component: input.element.component.name,
|
|
2253
|
+
...prop && { prop },
|
|
2254
|
+
...zero && {
|
|
2255
|
+
zeroRule: zero.rule,
|
|
2256
|
+
zeroMessage: zero.message
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
export { createComponentRegistry, createTamaguiCompilerHost };
|
|
2263
|
+
//# sourceMappingURL=compilerHost.mjs.map
|