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/stylesheet.js
DELETED
@@ -1,239 +0,0 @@
|
|
1
|
-
const { getIdentifierNameFromExpression, getSecondPropertyName } = require('./common')
|
2
|
-
|
3
|
-
const UnistyleDependency = {
|
4
|
-
Theme: 0,
|
5
|
-
ThemeName: 1,
|
6
|
-
AdaptiveThemes: 2,
|
7
|
-
Breakpoints: 3,
|
8
|
-
Variants: 4,
|
9
|
-
ColorScheme: 5,
|
10
|
-
Dimensions: 6,
|
11
|
-
Orientation: 7,
|
12
|
-
ContentSizeCategory: 8,
|
13
|
-
Insets: 9,
|
14
|
-
PixelRatio: 10,
|
15
|
-
FontScale: 11,
|
16
|
-
StatusBar: 12,
|
17
|
-
NavigationBar: 13,
|
18
|
-
Ime: 14
|
19
|
-
}
|
20
|
-
|
21
|
-
function stringToUniqueId(str) {
|
22
|
-
let hash = 0;
|
23
|
-
|
24
|
-
for (let i = 0; i < str.length; i++) {
|
25
|
-
hash = (hash << 5) - hash + str.charCodeAt(i)
|
26
|
-
hash |= 0
|
27
|
-
}
|
28
|
-
|
29
|
-
const absHash = Math.abs(hash)
|
30
|
-
|
31
|
-
return absHash % 1000000000
|
32
|
-
}
|
33
|
-
|
34
|
-
function isUnistylesStyleSheet(t, path, state) {
|
35
|
-
const callee = path.get('callee')
|
36
|
-
|
37
|
-
return (
|
38
|
-
t.isMemberExpression(callee.node) &&
|
39
|
-
callee.node.property.name === 'create' &&
|
40
|
-
t.isIdentifier(callee.node.object) &&
|
41
|
-
callee.node.object.name === state.file.styleSheetLocalName
|
42
|
-
)
|
43
|
-
}
|
44
|
-
|
45
|
-
function isKindOfStyleSheet(t, path, state) {
|
46
|
-
if (!state.file.forceProcessing) {
|
47
|
-
return false
|
48
|
-
}
|
49
|
-
|
50
|
-
const callee = path.get('callee')
|
51
|
-
|
52
|
-
return (
|
53
|
-
t.isMemberExpression(callee.node) &&
|
54
|
-
callee.node.property.name === 'create' &&
|
55
|
-
t.isIdentifier(callee.node.object)
|
56
|
-
)
|
57
|
-
}
|
58
|
-
|
59
|
-
function addStyleSheetTag(t, path, state) {
|
60
|
-
const callee = path.get('callee')
|
61
|
-
const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
|
62
|
-
|
63
|
-
callee.container.arguments.push(t.numericLiteral(uniqueId))
|
64
|
-
}
|
65
|
-
|
66
|
-
/** @param {import('./index').UnistylesPluginPass} state */
|
67
|
-
function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
68
|
-
const debugMessage = deps => {
|
69
|
-
if (state.opts.debug) {
|
70
|
-
const mappedDeps = deps
|
71
|
-
.map(dep => Object.keys(UnistyleDependency).find(key => UnistyleDependency[key] === dep))
|
72
|
-
.join(', ')
|
73
|
-
|
74
|
-
console.log(`${state.filename.replace(`${state.file.opts.root}/`, '')}: styles.${name}: [${mappedDeps}]`)
|
75
|
-
}
|
76
|
-
}
|
77
|
-
const unistyle = unistyleObj.properties
|
78
|
-
const dependencies = []
|
79
|
-
|
80
|
-
Object.values(unistyle).forEach(uni => {
|
81
|
-
const identifier = getIdentifierNameFromExpression(t, uni.value)
|
82
|
-
|
83
|
-
if (identifier.includes(themeName)) {
|
84
|
-
dependencies.push(UnistyleDependency.Theme)
|
85
|
-
}
|
86
|
-
|
87
|
-
if (identifier.includes(rtName)) {
|
88
|
-
const propertyNames = getSecondPropertyName(t, uni.value)
|
89
|
-
|
90
|
-
propertyNames
|
91
|
-
.filter(Boolean)
|
92
|
-
.forEach(propertyName => {
|
93
|
-
switch (propertyName) {
|
94
|
-
case 'themeName': {
|
95
|
-
dependencies.push(UnistyleDependency.ThemeName)
|
96
|
-
|
97
|
-
return
|
98
|
-
}
|
99
|
-
case 'adaptiveThemes': {
|
100
|
-
dependencies.push(UnistyleDependency.AdaptiveThemes)
|
101
|
-
|
102
|
-
return
|
103
|
-
}
|
104
|
-
case 'breakpoint': {
|
105
|
-
dependencies.push(UnistyleDependency.Breakpoints)
|
106
|
-
|
107
|
-
return
|
108
|
-
}
|
109
|
-
case 'colorScheme': {
|
110
|
-
dependencies.push(UnistyleDependency.ColorScheme)
|
111
|
-
|
112
|
-
return
|
113
|
-
}
|
114
|
-
case 'screen': {
|
115
|
-
dependencies.push(UnistyleDependency.Dimensions)
|
116
|
-
|
117
|
-
return
|
118
|
-
}
|
119
|
-
case 'isPortrait':
|
120
|
-
case 'isLandscape': {
|
121
|
-
dependencies.push(UnistyleDependency.Orientation)
|
122
|
-
|
123
|
-
return
|
124
|
-
}
|
125
|
-
case 'contentSizeCategory': {
|
126
|
-
dependencies.push(UnistyleDependency.ContentSizeCategory)
|
127
|
-
|
128
|
-
return
|
129
|
-
}
|
130
|
-
case 'ime': {
|
131
|
-
dependencies.push(UnistyleDependency.Ime)
|
132
|
-
|
133
|
-
return
|
134
|
-
}
|
135
|
-
case 'insets': {
|
136
|
-
dependencies.push(UnistyleDependency.Insets)
|
137
|
-
|
138
|
-
return
|
139
|
-
}
|
140
|
-
case 'pixelRatio': {
|
141
|
-
dependencies.push(UnistyleDependency.PixelRatio)
|
142
|
-
|
143
|
-
return
|
144
|
-
}
|
145
|
-
case 'fontScale': {
|
146
|
-
dependencies.push(UnistyleDependency.FontScale)
|
147
|
-
|
148
|
-
return
|
149
|
-
}
|
150
|
-
case 'statusBar': {
|
151
|
-
dependencies.push(UnistyleDependency.StatusBar)
|
152
|
-
|
153
|
-
return
|
154
|
-
}
|
155
|
-
case 'navigationBar': {
|
156
|
-
dependencies.push(UnistyleDependency.NavigationBar)
|
157
|
-
|
158
|
-
return
|
159
|
-
}
|
160
|
-
}
|
161
|
-
})
|
162
|
-
}
|
163
|
-
|
164
|
-
if (uni.key && uni.key.name === 'variants') {
|
165
|
-
dependencies.push(UnistyleDependency.Variants)
|
166
|
-
}
|
167
|
-
|
168
|
-
// breakpoints are too complex and are handled by C++
|
169
|
-
})
|
170
|
-
|
171
|
-
// add dependencies to the unistyle object if any found
|
172
|
-
if (dependencies.length > 0) {
|
173
|
-
const uniqueDependencies = Array.from(new Set(dependencies))
|
174
|
-
|
175
|
-
debugMessage(uniqueDependencies)
|
176
|
-
|
177
|
-
unistyleObj.properties.push(
|
178
|
-
t.objectProperty(
|
179
|
-
t.identifier('uni__dependencies'),
|
180
|
-
t.arrayExpression(uniqueDependencies.map(dep => t.numericLiteral(dep)))
|
181
|
-
)
|
182
|
-
)
|
183
|
-
}
|
184
|
-
}
|
185
|
-
|
186
|
-
function getUnistyles(t, property) {
|
187
|
-
const propertyValue = t.isArrowFunctionExpression(property.value)
|
188
|
-
? property.value.body
|
189
|
-
: property.value
|
190
|
-
|
191
|
-
if (t.isObjectExpression(propertyValue)) {
|
192
|
-
return [propertyValue]
|
193
|
-
}
|
194
|
-
|
195
|
-
if (t.isBlockStatement(propertyValue)) {
|
196
|
-
// here we might have single return statement
|
197
|
-
// or if-else statements with return statements
|
198
|
-
return propertyValue.body
|
199
|
-
.flatMap(value => {
|
200
|
-
if (t.isReturnStatement(value)) {
|
201
|
-
return [value]
|
202
|
-
}
|
203
|
-
|
204
|
-
if (!t.isIfStatement(value)) {
|
205
|
-
return []
|
206
|
-
}
|
207
|
-
|
208
|
-
return [value.consequent, value.alternate]
|
209
|
-
.filter(Boolean)
|
210
|
-
.flatMap(value => {
|
211
|
-
if (t.isBlockStatement(value)) {
|
212
|
-
return value.body.filter(t.isReturnStatement)
|
213
|
-
}
|
214
|
-
})
|
215
|
-
})
|
216
|
-
.map(value => value.argument)
|
217
|
-
}
|
218
|
-
|
219
|
-
return []
|
220
|
-
}
|
221
|
-
|
222
|
-
function addThemeDependencyToMemberExpression(t, path) {
|
223
|
-
path.value = t.objectExpression([
|
224
|
-
t.spreadElement(path.value),
|
225
|
-
t.objectProperty(
|
226
|
-
t.identifier('uni__dependencies'),
|
227
|
-
t.arrayExpression([t.numericLiteral(UnistyleDependency.Theme)])
|
228
|
-
)
|
229
|
-
])
|
230
|
-
}
|
231
|
-
|
232
|
-
module.exports = {
|
233
|
-
isUnistylesStyleSheet,
|
234
|
-
analyzeDependencies,
|
235
|
-
addStyleSheetTag,
|
236
|
-
getUnistyles,
|
237
|
-
isKindOfStyleSheet,
|
238
|
-
addThemeDependencyToMemberExpression
|
239
|
-
}
|
package/plugin/variants.js
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
function extractVariants(t, path, state) {
|
2
|
-
const maybeVariants = path.node.body.filter(node => (
|
3
|
-
t.isExpressionStatement(node) &&
|
4
|
-
t.isCallExpression(node.expression) &&
|
5
|
-
t.isMemberExpression(node.expression.callee)
|
6
|
-
))
|
7
|
-
|
8
|
-
if (maybeVariants.length === 0) {
|
9
|
-
return
|
10
|
-
}
|
11
|
-
|
12
|
-
const targetVariant = maybeVariants.find(variant => {
|
13
|
-
const calleeName = variant.expression.callee.object.name
|
14
|
-
|
15
|
-
return (
|
16
|
-
t.isIdentifier(variant.expression.callee.object, { name: calleeName }) &&
|
17
|
-
t.isIdentifier(variant.expression.callee.property, { name: 'useVariants' }) &&
|
18
|
-
variant.expression.arguments.length === 1
|
19
|
-
)
|
20
|
-
})
|
21
|
-
|
22
|
-
if (!targetVariant) {
|
23
|
-
return
|
24
|
-
}
|
25
|
-
|
26
|
-
const calleeName = targetVariant.expression.callee.object.name
|
27
|
-
const node = targetVariant.expression
|
28
|
-
const newUniqueName = path.scope.generateUidIdentifier(calleeName)
|
29
|
-
|
30
|
-
// Create shadow declaration eg. const _styles = styles
|
31
|
-
const shadowDeclaration = t.variableDeclaration('const', [
|
32
|
-
t.variableDeclarator(newUniqueName, t.identifier(calleeName))
|
33
|
-
])
|
34
|
-
|
35
|
-
// Create the new call expression eg. const styles = _styles.useVariants(...)
|
36
|
-
const newCallExpression = t.callExpression(
|
37
|
-
t.memberExpression(t.identifier(newUniqueName.name), t.identifier('useVariants')),
|
38
|
-
node.arguments
|
39
|
-
)
|
40
|
-
const finalDeclaration = t.variableDeclaration('const', [
|
41
|
-
t.variableDeclarator(t.identifier(calleeName), newCallExpression)
|
42
|
-
])
|
43
|
-
|
44
|
-
// Find the current node's index, we will move everything after to new block
|
45
|
-
const pathIndex = path.node.body
|
46
|
-
.findIndex(bodyPath => bodyPath === targetVariant)
|
47
|
-
const rest = path.node.body.slice(pathIndex + 1)
|
48
|
-
|
49
|
-
// move rest to new block (scope)
|
50
|
-
const blockStatement = t.blockStatement([
|
51
|
-
finalDeclaration,
|
52
|
-
...rest
|
53
|
-
])
|
54
|
-
|
55
|
-
path.node.body = [
|
56
|
-
...path.node.body.slice(0, pathIndex),
|
57
|
-
shadowDeclaration,
|
58
|
-
blockStatement
|
59
|
-
]
|
60
|
-
|
61
|
-
state.file.hasVariants = true
|
62
|
-
}
|
63
|
-
|
64
|
-
module.exports = {
|
65
|
-
extractVariants
|
66
|
-
}
|