react-native-unistyles 3.0.0-beta.6 → 3.0.0-beta.8
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/README.md +19 -0
- package/android/CMakeLists.txt +2 -1
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +4 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +29 -2
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +4 -0
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +5 -0
- package/cxx/common/Helpers.h +85 -0
- package/cxx/core/HashGenerator.cpp +1 -1
- package/cxx/core/HostUnistyle.cpp +28 -4
- package/cxx/core/HostUnistyle.h +1 -0
- package/cxx/core/UnistyleWrapper.h +6 -6
- package/cxx/core/UnistylesCommitHook.cpp +20 -17
- package/cxx/core/UnistylesMountHook.cpp +2 -2
- package/cxx/core/UnistylesMountHook.h +1 -4
- package/cxx/core/UnistylesRegistry.cpp +8 -6
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
- package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
- package/cxx/parser/Parser.cpp +79 -14
- package/cxx/shadowTree/ShadowTrafficController.h +10 -4
- package/cxx/shadowTree/ShadowTreeManager.cpp +38 -35
- package/lib/commonjs/components/native/Animated.js +2 -2
- package/lib/commonjs/components/native/Animated.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.js +29 -33
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/NativeText.native.js.map +1 -1
- package/lib/commonjs/components/native/NativeView.native.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.js +1 -1
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +17 -10
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +5 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +5 -1
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +5 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +3 -3
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/warn.js +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -2
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +18 -9
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +1 -1
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/server/getServerUnistyles.js +1 -1
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/useServerUnistyles.js +2 -2
- package/lib/commonjs/server/useServerUnistyles.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.native.js +3 -3
- package/lib/commonjs/specs/index.native.js.map +1 -1
- package/lib/commonjs/web/convert/index.js +4 -4
- package/lib/commonjs/web/convert/index.js.map +1 -1
- package/lib/commonjs/web/convert/object/boxShadow.js +4 -4
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +3 -3
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/convert/object/transform.js +1 -1
- package/lib/commonjs/web/convert/object/transform.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/index.js +1 -1
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +1 -1
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +1 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +1 -1
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/utils/common.js +1 -1
- package/lib/commonjs/web/utils/unistyle.js +5 -5
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/native/Animated.js +2 -2
- package/lib/module/components/native/Animated.js.map +1 -1
- package/lib/module/components/native/ImageBackground.js +29 -33
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/NativeText.native.js.map +1 -1
- package/lib/module/components/native/NativeView.native.js.map +1 -1
- package/lib/module/components/native/Pressable.js +1 -1
- package/lib/module/components/native/Pressable.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +17 -10
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +3 -3
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +5 -1
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +5 -1
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +3 -3
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/warn.js +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +2 -2
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +19 -10
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +1 -1
- package/lib/module/hooks/useMedia.native.js.map +1 -1
- package/lib/module/mq.js.map +1 -1
- package/lib/module/server/getServerUnistyles.js +1 -1
- package/lib/module/server/getServerUnistyles.js.map +1 -1
- package/lib/module/server/hydrateServerUnistyles.js +1 -1
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/module/server/resetServerUnistyles.js +1 -1
- package/lib/module/server/resetServerUnistyles.js.map +1 -1
- package/lib/module/server/useServerUnistyles.js +2 -2
- package/lib/module/server/useServerUnistyles.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +1 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.native.js +4 -4
- package/lib/module/specs/index.native.js.map +1 -1
- package/lib/module/web/convert/index.js +5 -5
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/object/boxShadow.js +2 -2
- package/lib/module/web/convert/object/boxShadow.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +3 -3
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/convert/object/transform.js +1 -1
- package/lib/module/web/convert/object/transform.js.map +1 -1
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/index.js +1 -1
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +1 -1
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +1 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +1 -1
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/utils/common.js +1 -1
- package/lib/module/web/utils/unistyle.js +5 -5
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +2 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/mq.d.ts +1 -1
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +5 -5
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.native.d.ts +4 -4
- package/lib/typescript/src/specs/index.native.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +2 -2
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +1 -1
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +5 -5
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/utils.d.ts +2 -2
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +1 -1
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts +1 -1
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +1 -17
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/unistylesOnLoad.kt +35 -0
- package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +2 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -3
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +18 -18
- package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
- package/nitrogen/generated/shared/c++/Dimensions.hpp +2 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/Insets.hpp +2 -1
- package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +2 -1
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +2 -1
- package/package.json +31 -19
- package/plugin/index.d.ts +51 -18
- package/plugin/index.js +791 -189
- package/src/components/native/Animated.tsx +2 -2
- package/src/components/native/ImageBackground.tsx +6 -7
- package/src/components/native/NativeText.native.tsx +1 -1
- package/src/components/native/NativeView.native.tsx +1 -1
- package/src/components/native/Pressable.native.tsx +22 -12
- package/src/components/native/Pressable.tsx +1 -1
- package/src/core/createUnistylesElement.native.tsx +6 -1
- package/src/core/createUnistylesElement.tsx +3 -3
- package/src/core/createUnistylesImageBackground.tsx +6 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +4 -4
- package/src/core/warn.ts +1 -1
- package/src/core/withUnistyles/withUnistyles.native.tsx +47 -19
- package/src/core/withUnistyles/withUnistyles.tsx +4 -4
- package/src/hooks/useMedia.native.ts +1 -1
- package/src/mq.ts +1 -1
- package/src/server/getServerUnistyles.tsx +1 -1
- package/src/server/hydrateServerUnistyles.ts +1 -1
- package/src/server/resetServerUnistyles.ts +1 -1
- package/src/server/useServerUnistyles.tsx +2 -2
- package/src/specs/ShadowRegistry/index.ts +1 -0
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -3
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
- package/src/specs/UnistylesRuntime/index.ts +5 -5
- package/src/specs/index.native.ts +4 -4
- package/src/types/breakpoints.ts +2 -2
- package/src/types/core.ts +1 -1
- package/src/types/stylesheet.ts +5 -5
- package/src/web/convert/index.ts +5 -5
- package/src/web/convert/object/boxShadow.ts +2 -2
- package/src/web/convert/object/filter.ts +3 -3
- package/src/web/convert/object/transform.ts +2 -2
- package/src/web/convert/types.ts +1 -1
- package/src/web/convert/utils.ts +2 -2
- package/src/web/create.ts +1 -1
- package/src/web/index.ts +3 -3
- package/src/web/registry.ts +2 -2
- package/src/web/runtime.ts +2 -2
- package/src/web/shadowRegistry.ts +2 -2
- package/src/web/state.ts +4 -4
- package/src/web/utils/common.ts +1 -1
- package/src/web/utils/unistyle.ts +6 -6
- package/plugin/common.js +0 -142
- package/plugin/consts.js +0 -63
- package/plugin/exotic.js +0 -54
- package/plugin/import.js +0 -51
- package/plugin/ref.js +0 -11
- package/plugin/stylesheet.js +0 -239
- package/plugin/variants.js +0 -66
package/plugin/index.js
CHANGED
@@ -1,203 +1,805 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
7
29
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS
|
16
|
-
.concat(state.opts.autoProcessPaths ?? [])
|
17
|
-
.some(path => state.filename.includes(path))
|
18
|
-
|
19
|
-
state.file.hasAnyUnistyle = false
|
20
|
-
state.file.hasVariants = false
|
21
|
-
state.file.styleSheetLocalName = ''
|
22
|
-
state.file.tagNumber = 0
|
23
|
-
state.reactNativeImports = {}
|
24
|
-
state.file.forceProcessing = state.opts.autoProcessRoot
|
25
|
-
? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)
|
26
|
-
: false
|
27
|
-
},
|
28
|
-
exit(path, state) {
|
29
|
-
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
30
|
-
return
|
31
|
-
}
|
32
|
-
|
33
|
-
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
34
|
-
addUnistylesImport(t, path, state)
|
35
|
-
}
|
36
|
-
}
|
37
|
-
},
|
38
|
-
FunctionDeclaration(path, state) {
|
39
|
-
if (isInsideNodeModules(state)) {
|
40
|
-
return
|
41
|
-
}
|
42
|
-
|
43
|
-
const componentName = path.node.id
|
44
|
-
? path.node.id.name
|
45
|
-
: null
|
46
|
-
|
47
|
-
if (componentName) {
|
48
|
-
state.file.hasVariants = false
|
49
|
-
}
|
50
|
-
},
|
51
|
-
ClassDeclaration(path, state) {
|
52
|
-
if (isInsideNodeModules(state)) {
|
53
|
-
return
|
54
|
-
}
|
55
|
-
|
56
|
-
const componentName = path.node.id
|
57
|
-
? path.node.id.name
|
58
|
-
: null
|
59
|
-
|
60
|
-
if (componentName) {
|
61
|
-
state.file.hasVariants = false
|
62
|
-
}
|
63
|
-
},
|
64
|
-
VariableDeclaration(path, state) {
|
65
|
-
if (isInsideNodeModules(state)) {
|
66
|
-
return
|
67
|
-
}
|
68
|
-
|
69
|
-
path.node.declarations.forEach((declaration) => {
|
70
|
-
if (t.isArrowFunctionExpression(declaration.init) || t.isFunctionExpression(declaration.init)) {
|
71
|
-
const componentName = declaration.id
|
72
|
-
? declaration.id.name
|
73
|
-
: null
|
74
|
-
|
75
|
-
if (componentName) {
|
76
|
-
state.file.hasVariants = false
|
77
|
-
}
|
78
|
-
}
|
79
|
-
})
|
80
|
-
},
|
81
|
-
/** @param {import('./index').UnistylesPluginPass} state */
|
82
|
-
ImportDeclaration(path, state) {
|
83
|
-
const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
|
84
|
-
.concat(state.opts.autoRemapImports ?? [])
|
85
|
-
.find(exotic => state.filename.includes(exotic.path))
|
86
|
-
|
87
|
-
if (exoticImport) {
|
88
|
-
return handleExoticImport(t, path, state, exoticImport)
|
89
|
-
}
|
30
|
+
// plugin/src/index.ts
|
31
|
+
var index_exports = {};
|
32
|
+
__export(index_exports, {
|
33
|
+
default: () => index_default
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
36
|
+
var t6 = __toESM(require("@babel/types"));
|
90
37
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
extractVariants(t, path, state)
|
136
|
-
},
|
137
|
-
CallExpression(path, state) {
|
138
|
-
if (isInsideNodeModules(state)) {
|
139
|
-
return
|
140
|
-
}
|
38
|
+
// plugin/src/consts.ts
|
39
|
+
var REACT_NATIVE_COMPONENT_NAMES = [
|
40
|
+
"ActivityIndicator",
|
41
|
+
"View",
|
42
|
+
"Text",
|
43
|
+
"Image",
|
44
|
+
"ImageBackground",
|
45
|
+
"KeyboardAvoidingView",
|
46
|
+
"Pressable",
|
47
|
+
"ScrollView",
|
48
|
+
"FlatList",
|
49
|
+
"SectionList",
|
50
|
+
"Switch",
|
51
|
+
"TextInput",
|
52
|
+
"RefreshControl",
|
53
|
+
"TouchableHighlight",
|
54
|
+
"TouchableOpacity",
|
55
|
+
"VirtualizedList",
|
56
|
+
"Animated"
|
57
|
+
// Modal - there is no exposed native handle
|
58
|
+
// TouchableWithoutFeedback - can't accept a ref
|
59
|
+
];
|
60
|
+
var REPLACE_WITH_UNISTYLES_PATHS = [
|
61
|
+
"react-native-reanimated/src/component",
|
62
|
+
"react-native-gesture-handler/src/components"
|
63
|
+
];
|
64
|
+
var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
|
65
|
+
var NATIVE_COMPONENTS_PATHS = {
|
66
|
+
imports: [
|
67
|
+
{
|
68
|
+
name: "NativeText",
|
69
|
+
isDefault: false,
|
70
|
+
path: "react-native/Libraries/Text/TextNativeComponent",
|
71
|
+
mapTo: "NativeText"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
isDefault: true,
|
75
|
+
path: "react-native/Libraries/Components/View/ViewNativeComponent",
|
76
|
+
mapTo: "NativeView"
|
77
|
+
}
|
78
|
+
]
|
79
|
+
};
|
141
80
|
|
142
|
-
|
143
|
-
|
144
|
-
|
81
|
+
// plugin/src/exotic.ts
|
82
|
+
var t = __toESM(require("@babel/types"));
|
83
|
+
function handleExoticImport(path, state, exoticImport) {
|
84
|
+
const specifiers = path.node.specifiers;
|
85
|
+
const source = path.node.source;
|
86
|
+
if (path.node.importKind !== "value") {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
specifiers.forEach((specifier) => {
|
90
|
+
for (const rule of exoticImport.imports) {
|
91
|
+
const hasMatchingImportType = !rule.isDefault && t.isImportSpecifier(specifier) || rule.isDefault && t.isImportDefaultSpecifier(specifier);
|
92
|
+
const hasMatchingImportName = rule.isDefault || !rule.isDefault && rule.name === specifier.local.name;
|
93
|
+
const hasMatchingPath = rule.path === source.value;
|
94
|
+
if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
|
95
|
+
continue;
|
96
|
+
}
|
97
|
+
if (t.isImportDefaultSpecifier(specifier)) {
|
98
|
+
const newImport = t.importDeclaration(
|
99
|
+
[t.importDefaultSpecifier(t.identifier(specifier.local.name))],
|
100
|
+
t.stringLiteral(
|
101
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
102
|
+
)
|
103
|
+
);
|
104
|
+
path.replaceWith(newImport);
|
105
|
+
} else {
|
106
|
+
const newImport = t.importDeclaration(
|
107
|
+
[t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
|
108
|
+
t.stringLiteral(
|
109
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
110
|
+
)
|
111
|
+
);
|
112
|
+
path.node.specifiers = specifiers.filter((s) => s !== specifier);
|
113
|
+
if (path.node.specifiers.length === 0) {
|
114
|
+
path.replaceWith(newImport);
|
115
|
+
} else {
|
116
|
+
path.insertBefore(newImport);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
});
|
122
|
+
}
|
145
123
|
|
146
|
-
|
124
|
+
// plugin/src/import.ts
|
125
|
+
var t2 = __toESM(require("@babel/types"));
|
126
|
+
function addUnistylesImport(path, state) {
|
127
|
+
const localNames = Object.keys(state.reactNativeImports);
|
128
|
+
const names = Object.values(state.reactNativeImports);
|
129
|
+
const pairs = Object.entries(state.reactNativeImports);
|
130
|
+
const nodesToRemove = [];
|
131
|
+
path.node.body.forEach((node) => {
|
132
|
+
if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
|
133
|
+
node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
|
134
|
+
if (node.specifiers.length === 0) {
|
135
|
+
nodesToRemove.push(node);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
});
|
139
|
+
names.forEach((name) => {
|
140
|
+
const rnWebImport = path.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`);
|
141
|
+
if (rnWebImport) {
|
142
|
+
rnWebImport.specifiers = [];
|
143
|
+
}
|
144
|
+
});
|
145
|
+
pairs.forEach(([localName, name]) => {
|
146
|
+
const newImport = t2.importDeclaration(
|
147
|
+
[t2.importSpecifier(t2.identifier(localName), t2.identifier(name))],
|
148
|
+
t2.stringLiteral(
|
149
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/src/components/native/${name}`) ?? "" : `react-native-unistyles/components/native/${name}`
|
150
|
+
)
|
151
|
+
);
|
152
|
+
path.node.body.unshift(newImport);
|
153
|
+
});
|
154
|
+
nodesToRemove.forEach((node) => path.node.body.splice(path.node.body.indexOf(node), 1));
|
155
|
+
}
|
156
|
+
function isInsideNodeModules(state) {
|
157
|
+
return state.file.opts.filename?.includes("node_modules");
|
158
|
+
}
|
147
159
|
|
148
|
-
|
160
|
+
// plugin/src/ref.ts
|
161
|
+
var t3 = __toESM(require("@babel/types"));
|
162
|
+
function hasStringRef(path) {
|
163
|
+
return path.node.openingElement.attributes.find(
|
164
|
+
(attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
|
165
|
+
);
|
166
|
+
}
|
149
167
|
|
150
|
-
|
168
|
+
// plugin/src/stylesheet.ts
|
169
|
+
var t4 = __toESM(require("@babel/types"));
|
170
|
+
var UnistyleDependency = {
|
171
|
+
Theme: 0,
|
172
|
+
ThemeName: 1,
|
173
|
+
AdaptiveThemes: 2,
|
174
|
+
Breakpoints: 3,
|
175
|
+
Variants: 4,
|
176
|
+
ColorScheme: 5,
|
177
|
+
Dimensions: 6,
|
178
|
+
Orientation: 7,
|
179
|
+
ContentSizeCategory: 8,
|
180
|
+
Insets: 9,
|
181
|
+
PixelRatio: 10,
|
182
|
+
FontScale: 11,
|
183
|
+
StatusBar: 12,
|
184
|
+
NavigationBar: 13,
|
185
|
+
Ime: 14
|
186
|
+
};
|
187
|
+
function getProperty(property) {
|
188
|
+
if (!property) {
|
189
|
+
return void 0;
|
190
|
+
}
|
191
|
+
if (t4.isIdentifier(property)) {
|
192
|
+
const prop = property;
|
193
|
+
return {
|
194
|
+
properties: [prop.name]
|
195
|
+
};
|
196
|
+
}
|
197
|
+
if (t4.isObjectPattern(property)) {
|
198
|
+
const prop = property;
|
199
|
+
const matchingProperties = prop.properties.flatMap((p) => getProperty(p));
|
200
|
+
return {
|
201
|
+
properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
|
202
|
+
};
|
203
|
+
}
|
204
|
+
if (t4.isObjectProperty(property) && t4.isIdentifier(property.value)) {
|
205
|
+
const prop = property.key;
|
206
|
+
return {
|
207
|
+
properties: [prop.name]
|
208
|
+
};
|
209
|
+
}
|
210
|
+
if (t4.isObjectProperty(property) && t4.isObjectPattern(property.value)) {
|
211
|
+
const matchingProperties = property.value.properties.flatMap((p) => getProperty(p));
|
212
|
+
const prop = property.key;
|
213
|
+
return {
|
214
|
+
parent: prop.name,
|
215
|
+
properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
|
216
|
+
};
|
217
|
+
}
|
218
|
+
return void 0;
|
219
|
+
}
|
220
|
+
function toUnistylesDependency(dependency) {
|
221
|
+
switch (dependency) {
|
222
|
+
case "theme": {
|
223
|
+
return UnistyleDependency.Theme;
|
224
|
+
}
|
225
|
+
case "themeName": {
|
226
|
+
return UnistyleDependency.ThemeName;
|
227
|
+
}
|
228
|
+
case "adaptiveThemes": {
|
229
|
+
return UnistyleDependency.AdaptiveThemes;
|
230
|
+
}
|
231
|
+
case "breakpoint": {
|
232
|
+
return UnistyleDependency.Breakpoints;
|
233
|
+
}
|
234
|
+
case "colorScheme": {
|
235
|
+
return UnistyleDependency.ColorScheme;
|
236
|
+
}
|
237
|
+
case "screen": {
|
238
|
+
return UnistyleDependency.Dimensions;
|
239
|
+
}
|
240
|
+
case "isPortrait":
|
241
|
+
case "isLandscape": {
|
242
|
+
return UnistyleDependency.Orientation;
|
243
|
+
}
|
244
|
+
case "contentSizeCategory": {
|
245
|
+
return UnistyleDependency.ContentSizeCategory;
|
246
|
+
}
|
247
|
+
case "ime": {
|
248
|
+
return UnistyleDependency.Ime;
|
249
|
+
}
|
250
|
+
case "insets": {
|
251
|
+
return UnistyleDependency.Insets;
|
252
|
+
}
|
253
|
+
case "pixelRatio": {
|
254
|
+
return UnistyleDependency.PixelRatio;
|
255
|
+
}
|
256
|
+
case "fontScale": {
|
257
|
+
return UnistyleDependency.FontScale;
|
258
|
+
}
|
259
|
+
case "statusBar": {
|
260
|
+
return UnistyleDependency.StatusBar;
|
261
|
+
}
|
262
|
+
case "navigationBar": {
|
263
|
+
return UnistyleDependency.NavigationBar;
|
264
|
+
}
|
265
|
+
case "variants": {
|
266
|
+
return UnistyleDependency.Variants;
|
267
|
+
}
|
268
|
+
default:
|
269
|
+
return null;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
function getReturnStatementsFromBody(node, results = []) {
|
273
|
+
if (t4.isReturnStatement(node)) {
|
274
|
+
results.push(node);
|
275
|
+
}
|
276
|
+
if (t4.isBlockStatement(node)) {
|
277
|
+
node.body.forEach((child) => getReturnStatementsFromBody(child, results));
|
278
|
+
}
|
279
|
+
if (t4.isIfStatement(node)) {
|
280
|
+
getReturnStatementsFromBody(node.consequent, results);
|
281
|
+
if (node.alternate) {
|
282
|
+
getReturnStatementsFromBody(node.alternate, results);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
return results;
|
286
|
+
}
|
287
|
+
function stringToUniqueId(str) {
|
288
|
+
let hash = 0;
|
289
|
+
for (let i = 0; i < str.length; i++) {
|
290
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
291
|
+
hash |= 0;
|
292
|
+
}
|
293
|
+
const absHash = Math.abs(hash);
|
294
|
+
return absHash % 1e9;
|
295
|
+
}
|
296
|
+
function isUnistylesStyleSheet(path, state) {
|
297
|
+
const { callee } = path.node;
|
298
|
+
if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.property)) {
|
299
|
+
return callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
|
300
|
+
}
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
function isKindOfStyleSheet(path, state) {
|
304
|
+
if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
|
305
|
+
return false;
|
306
|
+
}
|
307
|
+
const { callee } = path.node;
|
308
|
+
return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
|
309
|
+
}
|
310
|
+
function addStyleSheetTag(path, state) {
|
311
|
+
const str = state.filename?.replace(state.cwd, "") ?? "";
|
312
|
+
const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
|
313
|
+
path.node.arguments.push(t4.numericLiteral(uniqueId));
|
314
|
+
}
|
315
|
+
function getStylesDependenciesFromObject(path) {
|
316
|
+
const detectedStylesWithVariants = /* @__PURE__ */ new Set();
|
317
|
+
const stylesheet = path.node.arguments[0];
|
318
|
+
if (t4.isObjectExpression(stylesheet)) {
|
319
|
+
stylesheet?.properties.forEach((property) => {
|
320
|
+
if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
if (t4.isObjectProperty(property)) {
|
324
|
+
if (t4.isObjectExpression(property.value)) {
|
325
|
+
property.value.properties.forEach((innerProp) => {
|
326
|
+
if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
|
327
|
+
detectedStylesWithVariants.add({
|
328
|
+
label: "variants",
|
329
|
+
key: property.key.name
|
330
|
+
});
|
331
|
+
}
|
332
|
+
});
|
333
|
+
}
|
334
|
+
}
|
335
|
+
if (t4.isArrowFunctionExpression(property.value)) {
|
336
|
+
if (t4.isObjectExpression(property.value.body)) {
|
337
|
+
property.value.body.properties.forEach((innerProp) => {
|
338
|
+
if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
|
339
|
+
detectedStylesWithVariants.add({
|
340
|
+
label: "variants",
|
341
|
+
key: property.key.name
|
342
|
+
});
|
343
|
+
}
|
344
|
+
});
|
345
|
+
}
|
346
|
+
}
|
347
|
+
});
|
348
|
+
}
|
349
|
+
const variants = Array.from(detectedStylesWithVariants);
|
350
|
+
return variants.reduce((acc, { key, label }) => {
|
351
|
+
if (acc[key]) {
|
352
|
+
acc[key] = [
|
353
|
+
...acc[key],
|
354
|
+
label
|
355
|
+
];
|
356
|
+
return acc;
|
357
|
+
}
|
358
|
+
acc[key] = [label];
|
359
|
+
return acc;
|
360
|
+
}, {});
|
361
|
+
}
|
362
|
+
function getStylesDependenciesFromFunction(path) {
|
363
|
+
const funcPath = path.get("arguments.0");
|
364
|
+
if (!funcPath) {
|
365
|
+
return;
|
366
|
+
}
|
367
|
+
if (Array.isArray(funcPath)) {
|
368
|
+
return;
|
369
|
+
}
|
370
|
+
if (!t4.isFunctionExpression(funcPath.node) && !t4.isArrowFunctionExpression(funcPath.node)) {
|
371
|
+
return;
|
372
|
+
}
|
373
|
+
const params = funcPath.node.params;
|
374
|
+
const [themeParam, rtParam] = params;
|
375
|
+
const themeNames = [];
|
376
|
+
if (t4.isObjectPattern(themeParam)) {
|
377
|
+
for (const prop of themeParam.properties) {
|
378
|
+
const property = getProperty(prop);
|
379
|
+
if (property) {
|
380
|
+
themeNames.push(property);
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
if (t4.isIdentifier(themeParam)) {
|
385
|
+
themeNames.push({
|
386
|
+
properties: [themeParam.name]
|
387
|
+
});
|
388
|
+
}
|
389
|
+
const rtNames = [];
|
390
|
+
if (t4.isObjectPattern(rtParam)) {
|
391
|
+
for (const prop of rtParam.properties) {
|
392
|
+
const property = getProperty(prop);
|
393
|
+
if (property) {
|
394
|
+
rtNames.push(property);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
if (t4.isIdentifier(rtParam)) {
|
399
|
+
rtNames.push({
|
400
|
+
properties: [rtParam.name]
|
401
|
+
});
|
402
|
+
}
|
403
|
+
let returnedObjectPath = null;
|
404
|
+
if (t4.isObjectExpression(funcPath.node.body)) {
|
405
|
+
returnedObjectPath = funcPath.get("body");
|
406
|
+
} else {
|
407
|
+
funcPath.traverse({
|
408
|
+
ReturnStatement(retPath) {
|
409
|
+
if (!returnedObjectPath && retPath.get("argument").isObjectExpression()) {
|
410
|
+
const argumentPath = retPath.get("argument");
|
411
|
+
if (argumentPath.isObjectExpression()) {
|
412
|
+
returnedObjectPath = argumentPath;
|
413
|
+
}
|
414
|
+
}
|
415
|
+
}
|
416
|
+
});
|
417
|
+
}
|
418
|
+
if (!returnedObjectPath) {
|
419
|
+
return;
|
420
|
+
}
|
421
|
+
const detectedStylesWithVariants = /* @__PURE__ */ new Set();
|
422
|
+
const properties = returnedObjectPath.get("properties");
|
423
|
+
properties.forEach((propPath) => {
|
424
|
+
const stylePath = propPath.get("key");
|
425
|
+
if (Array.isArray(stylePath)) {
|
426
|
+
return;
|
427
|
+
}
|
428
|
+
if (!stylePath.isIdentifier()) {
|
429
|
+
return;
|
430
|
+
}
|
431
|
+
const styleKey = stylePath.node.name;
|
432
|
+
const valuePath = propPath.get("value");
|
433
|
+
if (Array.isArray(valuePath)) {
|
434
|
+
return;
|
435
|
+
}
|
436
|
+
if (valuePath.isObjectExpression()) {
|
437
|
+
const hasVariants = valuePath.get("properties").some((innerProp) => {
|
438
|
+
const innerKey = innerProp.get("key");
|
439
|
+
if (Array.isArray(innerKey)) {
|
440
|
+
return;
|
441
|
+
}
|
442
|
+
return innerKey.isIdentifier() && innerKey.node.name === "variants";
|
443
|
+
});
|
444
|
+
if (hasVariants) {
|
445
|
+
detectedStylesWithVariants.add({
|
446
|
+
label: "variants",
|
447
|
+
key: styleKey
|
448
|
+
});
|
449
|
+
}
|
450
|
+
}
|
451
|
+
if (valuePath.isArrowFunctionExpression()) {
|
452
|
+
if (t4.isObjectExpression(valuePath.node.body)) {
|
453
|
+
const hasVariants = valuePath.node.body.properties.some((innerProp) => {
|
454
|
+
return t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && innerProp.key.name === "variants";
|
455
|
+
});
|
456
|
+
if (hasVariants) {
|
457
|
+
detectedStylesWithVariants.add({
|
458
|
+
label: "variants",
|
459
|
+
key: styleKey
|
460
|
+
});
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
});
|
465
|
+
const detectedStylesWithTheme = /* @__PURE__ */ new Set();
|
466
|
+
themeNames.forEach(({ properties: properties2 }) => {
|
467
|
+
properties2.forEach((property) => {
|
468
|
+
const binding = funcPath.scope.getBinding(property);
|
469
|
+
if (!binding) {
|
470
|
+
return;
|
471
|
+
}
|
472
|
+
binding.referencePaths.forEach((refPath) => {
|
473
|
+
const containerProp = refPath.findParent((parent) => parent.isObjectProperty() && parent.parentPath === returnedObjectPath);
|
474
|
+
if (!containerProp) {
|
475
|
+
return;
|
476
|
+
}
|
477
|
+
const keyNode = containerProp.get("key");
|
478
|
+
if (Array.isArray(keyNode)) {
|
479
|
+
return;
|
480
|
+
}
|
481
|
+
const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
|
482
|
+
const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
|
483
|
+
if (styleKey) {
|
484
|
+
detectedStylesWithTheme.add({
|
485
|
+
label: "theme",
|
486
|
+
key: styleKey
|
487
|
+
});
|
488
|
+
}
|
489
|
+
});
|
490
|
+
});
|
491
|
+
});
|
492
|
+
const detectedStylesWithRt = /* @__PURE__ */ new Set();
|
493
|
+
const localRtName = t4.isIdentifier(rtParam) ? rtParam.name : void 0;
|
494
|
+
rtNames.forEach(({ properties: properties2, parent }) => {
|
495
|
+
properties2.forEach((property) => {
|
496
|
+
const rtBinding = funcPath.scope.getBinding(property);
|
497
|
+
if (!rtBinding) {
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
const isValidDependency = Boolean(toUnistylesDependency(property));
|
501
|
+
let validRtName = property;
|
502
|
+
if (!isValidDependency && (!localRtName || localRtName && localRtName !== property)) {
|
503
|
+
if (!parent) {
|
504
|
+
return;
|
505
|
+
}
|
506
|
+
if (!toUnistylesDependency(parent)) {
|
507
|
+
return;
|
508
|
+
}
|
509
|
+
validRtName = parent;
|
510
|
+
}
|
511
|
+
rtBinding.referencePaths.forEach((refPath) => {
|
512
|
+
let usedLabel = validRtName;
|
513
|
+
if (refPath.parentPath?.isMemberExpression() && refPath.parentPath.get("object") === refPath) {
|
514
|
+
const memberExpr = refPath.parentPath;
|
515
|
+
const propPath = memberExpr.get("property");
|
516
|
+
if (propPath.isIdentifier()) {
|
517
|
+
if (localRtName) {
|
518
|
+
usedLabel = propPath.node.name;
|
519
|
+
}
|
520
|
+
if (usedLabel === "insets" && memberExpr.parentPath.isMemberExpression() && memberExpr.parentPath.get("object") === memberExpr) {
|
521
|
+
const secondPropPath = memberExpr.parentPath.get("property");
|
522
|
+
if (secondPropPath.isIdentifier() && secondPropPath.node.name === "ime") {
|
523
|
+
usedLabel = "ime";
|
524
|
+
}
|
525
|
+
}
|
526
|
+
if (usedLabel === "insets" && (memberExpr.parentPath.isBinaryExpression() || memberExpr.parentPath.isLogicalExpression())) {
|
527
|
+
const secondPropPath = memberExpr.node.property;
|
528
|
+
if (t4.isIdentifier(secondPropPath) && secondPropPath.name === "ime") {
|
529
|
+
usedLabel = "ime";
|
530
|
+
}
|
531
|
+
}
|
532
|
+
}
|
533
|
+
}
|
534
|
+
const containerProp = refPath.findParent((parent2) => parent2.isObjectProperty() && parent2.parentPath === returnedObjectPath);
|
535
|
+
if (!containerProp) {
|
536
|
+
return;
|
537
|
+
}
|
538
|
+
const keyNode = containerProp.get("key");
|
539
|
+
if (Array.isArray(keyNode)) {
|
540
|
+
return;
|
541
|
+
}
|
542
|
+
const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
|
543
|
+
const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
|
544
|
+
if (styleKey) {
|
545
|
+
detectedStylesWithRt.add({
|
546
|
+
label: usedLabel,
|
547
|
+
key: styleKey
|
548
|
+
});
|
549
|
+
}
|
550
|
+
});
|
551
|
+
});
|
552
|
+
});
|
553
|
+
const variants = Array.from(detectedStylesWithVariants);
|
554
|
+
const theme = Array.from(detectedStylesWithTheme);
|
555
|
+
const rt = Array.from(detectedStylesWithRt);
|
556
|
+
return theme.concat(rt).concat(variants).reduce((acc, { key, label }) => {
|
557
|
+
if (acc[key]) {
|
558
|
+
acc[key] = [
|
559
|
+
...acc[key],
|
560
|
+
label
|
561
|
+
];
|
562
|
+
return acc;
|
563
|
+
}
|
564
|
+
acc[key] = [label];
|
565
|
+
return acc;
|
566
|
+
}, {});
|
567
|
+
}
|
568
|
+
function addDependencies(state, styleName, unistyle, detectedDependencies) {
|
569
|
+
const debugMessage = (deps) => {
|
570
|
+
if (state.opts.debug) {
|
571
|
+
const mappedDeps = deps.map((dep) => Object.keys(UnistyleDependency).find((key) => UnistyleDependency[key] === dep)).join(", ");
|
572
|
+
console.log(`${state.filename?.replace(`${state.file.opts.root}/`, "")}: styles.${styleName}: [${mappedDeps}]`);
|
573
|
+
}
|
574
|
+
};
|
575
|
+
const styleDependencies = detectedDependencies.map(toUnistylesDependency);
|
576
|
+
if (styleDependencies.length > 0) {
|
577
|
+
const uniqueDependencies = Array.from(new Set(styleDependencies));
|
578
|
+
debugMessage(uniqueDependencies);
|
579
|
+
let targets = [];
|
580
|
+
if (t4.isArrowFunctionExpression(unistyle.value) || t4.isFunctionExpression(unistyle.value)) {
|
581
|
+
if (t4.isObjectExpression(unistyle.value.body)) {
|
582
|
+
targets.push(unistyle.value.body);
|
583
|
+
}
|
584
|
+
if (t4.isBlockStatement(unistyle.value.body)) {
|
585
|
+
targets = getReturnStatementsFromBody(unistyle.value.body).map((node) => {
|
586
|
+
if (t4.isIdentifier(node.argument)) {
|
587
|
+
node.argument = t4.objectExpression([
|
588
|
+
t4.spreadElement(node.argument)
|
589
|
+
]);
|
590
|
+
}
|
591
|
+
return node.argument;
|
592
|
+
}).filter((node) => t4.isObjectExpression(node));
|
593
|
+
}
|
594
|
+
}
|
595
|
+
if (t4.isObjectExpression(unistyle.value)) {
|
596
|
+
targets.push(unistyle.value);
|
597
|
+
}
|
598
|
+
if (t4.isMemberExpression(unistyle.value)) {
|
599
|
+
unistyle.value = t4.objectExpression([t4.spreadElement(unistyle.value)]);
|
600
|
+
targets.push(unistyle.value);
|
601
|
+
}
|
602
|
+
if (targets.length > 0) {
|
603
|
+
targets.forEach((target) => {
|
604
|
+
target.properties.push(
|
605
|
+
t4.objectProperty(
|
606
|
+
t4.identifier("uni__dependencies"),
|
607
|
+
t4.arrayExpression(uniqueDependencies.filter((dep) => dep !== void 0).map((dep) => t4.numericLiteral(dep)))
|
608
|
+
)
|
609
|
+
);
|
610
|
+
});
|
611
|
+
}
|
612
|
+
}
|
613
|
+
}
|
151
614
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
615
|
+
// plugin/src/variants.ts
|
616
|
+
var t5 = __toESM(require("@babel/types"));
|
617
|
+
function extractVariants(path, state) {
|
618
|
+
const maybeVariants = path.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
|
619
|
+
if (maybeVariants.length === 0) {
|
620
|
+
return;
|
621
|
+
}
|
622
|
+
const targetVariant = maybeVariants.find((variant) => {
|
623
|
+
if (!t5.isExpressionStatement(variant) || !t5.isCallExpression(variant.expression) || !t5.isMemberExpression(variant.expression.callee) || !t5.isIdentifier(variant.expression.callee.object)) {
|
624
|
+
return false;
|
625
|
+
}
|
626
|
+
const calleeName2 = variant.expression.callee.object.name;
|
627
|
+
return t5.isIdentifier(variant.expression.callee.object, { name: calleeName2 }) && t5.isIdentifier(variant.expression.callee.property, { name: "useVariants" }) && variant.expression.arguments.length === 1;
|
628
|
+
});
|
629
|
+
if (!targetVariant) {
|
630
|
+
return;
|
631
|
+
}
|
632
|
+
const node = targetVariant.expression;
|
633
|
+
if (!t5.isCallExpression(node)) {
|
634
|
+
return;
|
635
|
+
}
|
636
|
+
const callee = node.callee;
|
637
|
+
if (!t5.isMemberExpression(callee) || !t5.isIdentifier(callee.object)) {
|
638
|
+
return;
|
639
|
+
}
|
640
|
+
const calleeName = callee.object.name;
|
641
|
+
const newUniqueName = path.scope.generateUidIdentifier(calleeName);
|
642
|
+
const shadowDeclaration = t5.variableDeclaration("const", [
|
643
|
+
t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
|
644
|
+
]);
|
645
|
+
const newCallExpression = t5.callExpression(
|
646
|
+
t5.memberExpression(t5.identifier(newUniqueName.name), t5.identifier("useVariants")),
|
647
|
+
node.arguments
|
648
|
+
);
|
649
|
+
const finalDeclaration = t5.variableDeclaration("const", [
|
650
|
+
t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
|
651
|
+
]);
|
652
|
+
const pathIndex = path.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
|
653
|
+
const rest = path.node.body.slice(pathIndex + 1);
|
654
|
+
const statement = t5.blockStatement([
|
655
|
+
finalDeclaration,
|
656
|
+
...rest
|
657
|
+
]);
|
658
|
+
path.node.body = [
|
659
|
+
...path.node.body.slice(0, pathIndex),
|
660
|
+
shadowDeclaration,
|
661
|
+
statement
|
662
|
+
];
|
663
|
+
state.file.hasVariants = true;
|
664
|
+
}
|
157
665
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
666
|
+
// plugin/src/index.ts
|
667
|
+
function index_default() {
|
668
|
+
return {
|
669
|
+
name: "babel-react-native-unistyles",
|
670
|
+
visitor: {
|
671
|
+
Program: {
|
672
|
+
enter(_, state) {
|
673
|
+
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.concat(state.opts.autoProcessPaths ?? []).some((path) => state.filename?.includes(path));
|
674
|
+
state.file.hasAnyUnistyle = false;
|
675
|
+
state.file.hasUnistylesImport = false;
|
676
|
+
state.file.hasVariants = false;
|
677
|
+
state.file.styleSheetLocalName = "";
|
678
|
+
state.file.tagNumber = 0;
|
679
|
+
state.reactNativeImports = {};
|
680
|
+
state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`) : false;
|
681
|
+
},
|
682
|
+
exit(path, state) {
|
683
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
684
|
+
return;
|
685
|
+
}
|
686
|
+
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
687
|
+
addUnistylesImport(path, state);
|
688
|
+
}
|
689
|
+
}
|
690
|
+
},
|
691
|
+
FunctionDeclaration(path, state) {
|
692
|
+
if (isInsideNodeModules(state)) {
|
693
|
+
return;
|
694
|
+
}
|
695
|
+
const componentName = path.node.id ? path.node.id.name : null;
|
696
|
+
if (componentName) {
|
697
|
+
state.file.hasVariants = false;
|
698
|
+
}
|
699
|
+
},
|
700
|
+
ClassDeclaration(path, state) {
|
701
|
+
if (isInsideNodeModules(state)) {
|
702
|
+
return;
|
703
|
+
}
|
704
|
+
const componentName = path.node.id ? path.node.id.name : null;
|
705
|
+
if (componentName) {
|
706
|
+
state.file.hasVariants = false;
|
707
|
+
}
|
708
|
+
},
|
709
|
+
VariableDeclaration(path, state) {
|
710
|
+
if (isInsideNodeModules(state)) {
|
711
|
+
return;
|
712
|
+
}
|
713
|
+
path.node.declarations.forEach((declaration) => {
|
714
|
+
if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
|
715
|
+
const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
|
716
|
+
if (componentName) {
|
717
|
+
state.file.hasVariants = false;
|
718
|
+
}
|
719
|
+
}
|
720
|
+
});
|
721
|
+
},
|
722
|
+
ImportDeclaration(path, state) {
|
723
|
+
const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
|
724
|
+
if (exoticImport) {
|
725
|
+
return handleExoticImport(path, state, exoticImport);
|
726
|
+
}
|
727
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
728
|
+
return;
|
729
|
+
}
|
730
|
+
const importSource = path.node.source.value;
|
731
|
+
if (importSource.includes("react-native-unistyles")) {
|
732
|
+
state.file.hasUnistylesImport = true;
|
733
|
+
path.node.specifiers.forEach((specifier) => {
|
734
|
+
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
|
735
|
+
state.file.styleSheetLocalName = specifier.local.name;
|
736
|
+
}
|
737
|
+
});
|
738
|
+
}
|
739
|
+
if (importSource === "react-native") {
|
740
|
+
path.node.specifiers.forEach((specifier) => {
|
741
|
+
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
|
742
|
+
state.reactNativeImports[specifier.local.name] = specifier.imported.name;
|
743
|
+
}
|
744
|
+
});
|
745
|
+
}
|
746
|
+
if (importSource.includes("react-native/Libraries")) {
|
747
|
+
handleExoticImport(path, state, NATIVE_COMPONENTS_PATHS);
|
748
|
+
}
|
749
|
+
if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
|
750
|
+
state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
|
751
|
+
}
|
752
|
+
},
|
753
|
+
JSXElement(path, state) {
|
754
|
+
if (isInsideNodeModules(state)) {
|
755
|
+
return;
|
756
|
+
}
|
757
|
+
if (hasStringRef(path)) {
|
758
|
+
throw new Error("Detected string based ref which is not supported by Unistyles.");
|
759
|
+
}
|
760
|
+
},
|
761
|
+
BlockStatement(path, state) {
|
762
|
+
if (isInsideNodeModules(state)) {
|
763
|
+
return;
|
764
|
+
}
|
765
|
+
extractVariants(path, state);
|
766
|
+
},
|
767
|
+
CallExpression(path, state) {
|
768
|
+
if (isInsideNodeModules(state)) {
|
769
|
+
return;
|
770
|
+
}
|
771
|
+
if (!isUnistylesStyleSheet(path, state) && !isKindOfStyleSheet(path, state)) {
|
772
|
+
return;
|
773
|
+
}
|
774
|
+
state.file.hasAnyUnistyle = true;
|
775
|
+
addStyleSheetTag(path, state);
|
776
|
+
const arg = path.node.arguments[0];
|
777
|
+
if (t6.isObjectExpression(arg)) {
|
778
|
+
const detectedDependencies = getStylesDependenciesFromObject(path);
|
779
|
+
if (detectedDependencies) {
|
780
|
+
if (t6.isObjectExpression(arg)) {
|
781
|
+
arg.properties.forEach((property) => {
|
782
|
+
if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
|
783
|
+
addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
|
163
784
|
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
const body = t.isBlockStatement(arg.body)
|
177
|
-
? arg.body.body.find(statement => t.isReturnStatement(statement)).argument
|
178
|
-
: arg.body
|
179
|
-
|
180
|
-
// Ensure the function body returns an object
|
181
|
-
if (t.isObjectExpression(body)) {
|
182
|
-
body.properties.forEach(property => {
|
183
|
-
if (t.isObjectProperty(property)) {
|
184
|
-
const propertyValues = getUnistyles(t, property)
|
185
|
-
|
186
|
-
// maybe user used inlined theme? ({ container: theme.components.container })
|
187
|
-
if (propertyValues.length === 0 && t.isMemberExpression(property.value)) {
|
188
|
-
if (property.value.object.object.name === themeLocalName) {
|
189
|
-
addThemeDependencyToMemberExpression(t, property)
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
propertyValues.forEach(propertyValue => {
|
194
|
-
analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
|
195
|
-
})
|
196
|
-
}
|
197
|
-
})
|
198
|
-
}
|
785
|
+
});
|
786
|
+
}
|
787
|
+
}
|
788
|
+
}
|
789
|
+
if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
|
790
|
+
const detectedDependencies = getStylesDependenciesFromFunction(path);
|
791
|
+
if (detectedDependencies) {
|
792
|
+
const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
|
793
|
+
if (t6.isObjectExpression(body)) {
|
794
|
+
body.properties.forEach((property) => {
|
795
|
+
if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
|
796
|
+
addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
|
199
797
|
}
|
798
|
+
});
|
200
799
|
}
|
800
|
+
}
|
201
801
|
}
|
802
|
+
}
|
202
803
|
}
|
804
|
+
};
|
203
805
|
}
|