react-native-unistyles 2.0.0-alpha.1 → 2.0.0-alpha.3
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 +4 -4
- package/ios/UnistylesModule.h +12 -0
- package/ios/UnistylesModule.mm +163 -0
- package/ios/UnistylesRuntime.h +48 -0
- package/ios/UnistylesRuntime.mm +228 -0
- package/lib/commonjs/UnistyleRegistry.js +34 -0
- package/lib/commonjs/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/Unistyles.js +36 -0
- package/lib/commonjs/Unistyles.js.map +1 -0
- package/lib/commonjs/UnistylesEngine.js +22 -0
- package/lib/commonjs/UnistylesEngine.js.map +1 -0
- package/lib/commonjs/UnistylesModule.js +9 -0
- package/lib/commonjs/UnistylesModule.js.map +1 -0
- package/lib/commonjs/UnistylesRuntime.js +63 -0
- package/lib/commonjs/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/createStyleSheet.js +14 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -0
- package/lib/commonjs/global.js +2 -0
- package/lib/commonjs/global.js.map +1 -0
- package/lib/commonjs/hooks/useDimensions.web.js +3 -2
- package/lib/commonjs/hooks/useDimensions.web.js.map +1 -1
- package/lib/commonjs/index.js +33 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/cxx.js +23 -0
- package/lib/commonjs/types/cxx.js.map +1 -0
- package/lib/commonjs/types/index.js +26 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/normalizer.js +6 -0
- package/lib/commonjs/types/normalizer.js.map +1 -0
- package/lib/commonjs/useInitialTheme.js +13 -0
- package/lib/commonjs/useInitialTheme.js.map +1 -0
- package/lib/commonjs/useStyles.js +48 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/useUnistyles.js +57 -0
- package/lib/commonjs/useUnistyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +4 -2
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +3 -3
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +34 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/module.d.js +2 -0
- package/lib/commonjs/utils/module.d.js.map +1 -0
- package/lib/commonjs/utils/normalizeStyles.web.js +13 -13
- package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -1
- package/lib/commonjs/utils/normalizer.js +89 -0
- package/lib/commonjs/utils/normalizer.js.map +1 -0
- package/lib/commonjs/utils/styles.js +7 -7
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/UnistyleRegistry.js +27 -0
- package/lib/module/UnistyleRegistry.js.map +1 -0
- package/lib/module/Unistyles.js +30 -0
- package/lib/module/Unistyles.js.map +1 -0
- package/lib/module/UnistylesEngine.js +15 -0
- package/lib/module/UnistylesEngine.js.map +1 -0
- package/lib/module/UnistylesModule.js +3 -0
- package/lib/module/UnistylesModule.js.map +1 -0
- package/lib/module/UnistylesRuntime.js +56 -0
- package/lib/module/UnistylesRuntime.js.map +1 -0
- package/lib/module/createStyleSheet.js +7 -0
- package/lib/module/createStyleSheet.js.map +1 -0
- package/lib/module/global.js +2 -0
- package/lib/module/global.js.map +1 -0
- package/lib/module/hooks/useDimensions.web.js +3 -2
- package/lib/module/hooks/useDimensions.web.js.map +1 -1
- package/lib/module/index.js +18 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/cxx.js +17 -0
- package/lib/module/types/cxx.js.map +1 -0
- package/lib/module/types/index.js +2 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/normalizer.js +2 -0
- package/lib/module/types/normalizer.js.map +1 -0
- package/lib/module/useInitialTheme.js +6 -0
- package/lib/module/useInitialTheme.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/useUnistyles.js +50 -0
- package/lib/module/useUnistyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +4 -3
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +2 -1
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +2 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/module.d.js +2 -0
- package/lib/module/utils/module.d.js.map +1 -0
- package/lib/module/utils/normalizeStyles.web.js +13 -13
- package/lib/module/utils/normalizeStyles.web.js.map +1 -1
- package/lib/module/utils/normalizer.js +79 -0
- package/lib/module/utils/normalizer.js.map +1 -0
- package/lib/module/utils/styles.js +7 -8
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/examples/expo/src/App.d.ts +3 -0
- package/lib/typescript/examples/expo/src/App.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Cxx.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Cxx.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/index.d.ts +2 -0
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/index.d.ts +2 -0
- package/lib/typescript/examples/expo/src/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +8 -0
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/index.d.ts +16 -0
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +40 -0
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -0
- package/lib/typescript/src/UnistyleRegistry.d.ts +14 -0
- package/lib/typescript/src/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/Unistyles.d.ts +16 -0
- package/lib/typescript/src/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesEngine.d.ts +8 -0
- package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesRuntime.d.ts +60 -0
- package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +6 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +5 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +14 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +6 -7
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +4 -4
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/cxx.d.ts +53 -0
- package/lib/typescript/src/types/cxx.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +4 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/normalizer.d.ts +20 -0
- package/lib/typescript/src/types/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +46 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/useUnistyles.d.ts +45 -0
- package/lib/typescript/src/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -4
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +2 -1
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +2 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts +4 -1
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizer.d.ts +11 -0
- package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +4 -3
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +13 -3
- package/react-native-unistyles.podspec +21 -0
- package/src/UnistyleRegistry.ts +35 -0
- package/src/Unistyles.ts +41 -0
- package/src/UnistylesEngine.ts +15 -0
- package/src/UnistylesModule.ts +7 -0
- package/src/UnistylesRuntime.ts +69 -0
- package/src/createStyleSheet.ts +12 -0
- package/src/global.ts +2 -0
- package/src/hooks/useDimensions.web.ts +3 -2
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +9 -11
- package/src/types/core.ts +6 -6
- package/src/types/cxx.ts +65 -0
- package/src/types/index.ts +4 -3
- package/src/types/normalizer.ts +29 -0
- package/src/useInitialTheme.ts +7 -0
- package/src/useStyles.ts +49 -0
- package/src/useUnistyles.ts +66 -0
- package/src/utils/breakpoints.ts +16 -14
- package/src/utils/common.ts +2 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/module.d.ts +3 -0
- package/src/utils/normalizeStyles.web.ts +21 -42
- package/src/utils/normalizer.ts +99 -0
- package/src/utils/styles.ts +17 -19
- package/lib/commonjs/UnistylesTheme.js +0 -21
- package/lib/commonjs/UnistylesTheme.js.map +0 -1
- package/lib/commonjs/createUnistyles.js +0 -57
- package/lib/commonjs/createUnistyles.js.map +0 -1
- package/lib/module/UnistylesTheme.js +0 -12
- package/lib/module/UnistylesTheme.js.map +0 -1
- package/lib/module/createUnistyles.js +0 -50
- package/lib/module/createUnistyles.js.map +0 -1
- package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
- package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
- package/lib/typescript/src/createUnistyles.d.ts +0 -10
- package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
- package/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
package/README.md
CHANGED
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|
[](https://www.npmjs.com/package/react-native-unistyles)
|
|
11
|
-

|
|
12
12
|
[](https://opensource.org/licenses/MIT)
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
## Features
|
|
16
15
|
- ⚡ Blazing fast, adds around ~3ms on top of StyleSheet*
|
|
17
16
|
- 🎳 Share up to 100% of your styles across platforms in monorepo
|
|
@@ -19,7 +18,8 @@
|
|
|
19
18
|
- 🖥️ Supports custom breakpoints and css-like media queries
|
|
20
19
|
- 🎨 Access theme in your StyleSheets and components
|
|
21
20
|
- 🪄 Supports dynamic functions to access values from JSX
|
|
22
|
-
- 🥳 Compatible with Expo, Expo Go, Bare React Native
|
|
21
|
+
- 🥳 Compatible with Expo, Expo Go, Bare React Native, React Native Web and SSR
|
|
22
|
+
- 🛡️ ~99% Test coverage
|
|
23
23
|
- ⚔️ No 3rd party dependencies
|
|
24
24
|
|
|
25
25
|
*-based on this [benchmark](https://github.com/efstathiosntonas/react-native-style-libraries-benchmark)
|
|
@@ -41,7 +41,7 @@ There is ongoing work on branch [2.0](https://github.com/jpudysz/react-native-un
|
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
|
-
Join early testers and discussion [here](https://github.com/jpudysz/react-native-unistyles/discussions/41)
|
|
44
|
+
Join early testers and discussion [here](https://github.com/jpudysz/react-native-unistyles/discussions/41).
|
|
45
45
|
|
|
46
46
|
```cmd
|
|
47
47
|
yarn add react-native-unistyles@next
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
3
|
+
#import <string>
|
|
4
|
+
|
|
5
|
+
typedef void(^UnistylesThemeChangeEvent)(std::string);
|
|
6
|
+
typedef void(^UnistylesBreakpointChangeEvent)(std::string);
|
|
7
|
+
|
|
8
|
+
@interface UnistylesModule : RCTEventEmitter<RCTBridgeModule>
|
|
9
|
+
|
|
10
|
+
@property (nonatomic, assign) void* unistylesRuntime;
|
|
11
|
+
|
|
12
|
+
@end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#import "UnistylesModule.h"
|
|
2
|
+
#import "UnistylesRuntime.h"
|
|
3
|
+
#import "UnistylesModule.h"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#import <React/RCTAppearance.h>
|
|
7
|
+
#import <React/RCTBridge+Private.h>
|
|
8
|
+
#import <jsi/jsi.h>
|
|
9
|
+
|
|
10
|
+
@implementation UnistylesModule
|
|
11
|
+
|
|
12
|
+
BOOL hasListeners;
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
RCT_EXPORT_MODULE(Unistyles)
|
|
17
|
+
|
|
18
|
+
- (instancetype)init {
|
|
19
|
+
if ((self = [super init])) {
|
|
20
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
21
|
+
selector:@selector(handleOrientationChange:)
|
|
22
|
+
name:UIDeviceOrientationDidChangeNotification
|
|
23
|
+
object:nil];
|
|
24
|
+
// todo from iOS 13
|
|
25
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
26
|
+
selector:@selector(appearanceChanged:)
|
|
27
|
+
name:RCTUserInterfaceStyleDidChangeNotification
|
|
28
|
+
object:nil];
|
|
29
|
+
}
|
|
30
|
+
return self;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (void)handleOrientationChange:(NSNotification *)notification {
|
|
34
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
35
|
+
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
|
|
36
|
+
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
|
|
37
|
+
|
|
38
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange((int)screenWidth, (int)screenHeight);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (void)appearanceChanged:(NSNotification *)notification
|
|
43
|
+
{
|
|
44
|
+
std::string colorScheme = [self getColorScheme];
|
|
45
|
+
|
|
46
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (std::string)getColorScheme {
|
|
50
|
+
UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
|
|
51
|
+
|
|
52
|
+
// todo enums
|
|
53
|
+
switch (colorScheme) {
|
|
54
|
+
case UIUserInterfaceStyleLight:
|
|
55
|
+
return "light";
|
|
56
|
+
case UIUserInterfaceStyleDark:
|
|
57
|
+
return "dark";
|
|
58
|
+
case UIUserInterfaceStyleUnspecified:
|
|
59
|
+
default:
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (void)dealloc {
|
|
65
|
+
delete (UnistylesRuntime*)self.unistylesRuntime;
|
|
66
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
+ (BOOL)requiresMainQueueSetup
|
|
70
|
+
{
|
|
71
|
+
return YES;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
75
|
+
{
|
|
76
|
+
NSLog(@"Installing Unistyles 🦄...");
|
|
77
|
+
|
|
78
|
+
RCTBridge* bridge = [RCTBridge currentBridge];
|
|
79
|
+
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
|
80
|
+
|
|
81
|
+
if (cxxBridge == nil) {
|
|
82
|
+
return @false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
|
|
86
|
+
|
|
87
|
+
if (jsiRuntime == nil) {
|
|
88
|
+
return @false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
auto& runtime = *jsiRuntime;
|
|
92
|
+
UnistylesModule *__weak weakSelf = self;
|
|
93
|
+
|
|
94
|
+
registerUnistylesHostObject(runtime, weakSelf);
|
|
95
|
+
|
|
96
|
+
NSLog(@"Installed Unistyles 🦄!");
|
|
97
|
+
|
|
98
|
+
return @true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
102
|
+
return @[@"onChange"];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)startObserving
|
|
106
|
+
{
|
|
107
|
+
hasListeners = YES;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (void)stopObserving
|
|
111
|
+
{
|
|
112
|
+
hasListeners = NO;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)emitEvent:(NSString *)eventName withBody:(NSDictionary *)body {
|
|
116
|
+
if (hasListeners) {
|
|
117
|
+
[self sendEventWithName:@"onChange" body:body];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSelf) {
|
|
122
|
+
CGFloat initialScreenWidth = [UIScreen mainScreen].bounds.size.width;
|
|
123
|
+
CGFloat initialScreenHeight = [UIScreen mainScreen].bounds.size.height;
|
|
124
|
+
std::string initalColorScheme = [weakSelf getColorScheme];
|
|
125
|
+
UnistylesThemeChangeEvent onThemeChange = ^(std::string theme) {
|
|
126
|
+
NSString *nextTheme = [NSString stringWithUTF8String:theme.c_str()];
|
|
127
|
+
NSDictionary *body = @{
|
|
128
|
+
@"type": @"theme",
|
|
129
|
+
@"payload": @{
|
|
130
|
+
@"themeName": nextTheme
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
[weakSelf emitEvent:@"onChange" withBody:body];
|
|
135
|
+
};
|
|
136
|
+
UnistylesBreakpointChangeEvent onBreakpointChange = ^(std::string breakpoint) {
|
|
137
|
+
NSString *nextBreakpoint = [NSString stringWithUTF8String:breakpoint.c_str()];
|
|
138
|
+
NSDictionary *body = @{
|
|
139
|
+
@"type": @"breakpoint",
|
|
140
|
+
@"payload": @{
|
|
141
|
+
@"breakpoint": nextBreakpoint
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
[weakSelf emitEvent:@"onChange" withBody:body];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
|
|
149
|
+
onThemeChange,
|
|
150
|
+
onBreakpointChange,
|
|
151
|
+
(int)initialScreenWidth,
|
|
152
|
+
(int)initialScreenHeight,
|
|
153
|
+
initalColorScheme
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
weakSelf.unistylesRuntime = unistylesRuntime.get();
|
|
157
|
+
|
|
158
|
+
auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
|
|
159
|
+
|
|
160
|
+
runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import "UnistylesModule.h"
|
|
4
|
+
#import <jsi/jsi.h>
|
|
5
|
+
#import <vector>
|
|
6
|
+
|
|
7
|
+
using namespace facebook;
|
|
8
|
+
|
|
9
|
+
class JSI_EXPORT UnistylesRuntime : public jsi::HostObject {
|
|
10
|
+
private:
|
|
11
|
+
UnistylesThemeChangeEvent onThemeChange;
|
|
12
|
+
UnistylesBreakpointChangeEvent onBreakpointChange;
|
|
13
|
+
|
|
14
|
+
int screenWidth;
|
|
15
|
+
int screenHeight;
|
|
16
|
+
std::string colorScheme;
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
UnistylesRuntime(
|
|
20
|
+
UnistylesThemeChangeEvent onThemeChange,
|
|
21
|
+
UnistylesBreakpointChangeEvent onBreakpointChange,
|
|
22
|
+
float screenWidth,
|
|
23
|
+
float screenHeight,
|
|
24
|
+
std::string colorScheme
|
|
25
|
+
): onThemeChange(onThemeChange),
|
|
26
|
+
onBreakpointChange(onBreakpointChange),
|
|
27
|
+
screenWidth(screenWidth),
|
|
28
|
+
screenHeight(screenHeight),
|
|
29
|
+
colorScheme(colorScheme) {}
|
|
30
|
+
|
|
31
|
+
bool hasAdaptiveThemes;
|
|
32
|
+
bool supportsAutomaticColorScheme;
|
|
33
|
+
|
|
34
|
+
std::string theme;
|
|
35
|
+
std::string breakpoint;
|
|
36
|
+
std::vector<std::string> themes;
|
|
37
|
+
std::vector<std::pair<std::string, double>> sortedBreakpointEntries;
|
|
38
|
+
|
|
39
|
+
jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
|
|
40
|
+
void set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) override;
|
|
41
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override;
|
|
42
|
+
|
|
43
|
+
void handleScreenSizeChange(int width, int height);
|
|
44
|
+
void handleAppearanceChange(std::string colorScheme);
|
|
45
|
+
|
|
46
|
+
jsi::Value getThemeOrFail(jsi::Runtime&);
|
|
47
|
+
std::string getBreakpointFromScreenWidth(double width, const std::vector<std::pair<std::string, double>>& sortedBreakpointEntries);
|
|
48
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#import "UnistylesRuntime.h"
|
|
2
|
+
|
|
3
|
+
std::vector<jsi::PropNameID> UnistylesRuntime::getPropertyNames(jsi::Runtime& rt) {
|
|
4
|
+
std::vector<jsi::PropNameID> properties;
|
|
5
|
+
|
|
6
|
+
// getters
|
|
7
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("screenWidth")));
|
|
8
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("screenHeight")));
|
|
9
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("hasAdaptiveThemes")));
|
|
10
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("theme")));
|
|
11
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("breakpoint")));
|
|
12
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("colorScheme")));
|
|
13
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("sortedBreakpointPairs")));
|
|
14
|
+
|
|
15
|
+
// setters
|
|
16
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("themes")));
|
|
17
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("useBreakpoints")));
|
|
18
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("useTheme")));
|
|
19
|
+
properties.push_back(jsi::PropNameID::forUtf8(rt, std::string("useAdaptiveThemes")));
|
|
20
|
+
|
|
21
|
+
return properties;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) {
|
|
26
|
+
std::string propName = propNameId.utf8(runtime);
|
|
27
|
+
|
|
28
|
+
if (propName == "screenWidth") {
|
|
29
|
+
return jsi::Value(this->screenWidth);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (propName == "screenHeight") {
|
|
33
|
+
return jsi::Value(this->screenHeight);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (propName == "hasAdaptiveThemes") {
|
|
37
|
+
return jsi::Value(this->hasAdaptiveThemes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (propName == "theme") {
|
|
41
|
+
return !this->theme.empty()
|
|
42
|
+
? jsi::Value(jsi::String::createFromUtf8(runtime, this->theme))
|
|
43
|
+
: this->getThemeOrFail(runtime);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (propName == "breakpoint") {
|
|
47
|
+
return !this->breakpoint.empty()
|
|
48
|
+
? jsi::Value(jsi::String::createFromUtf8(runtime, this->breakpoint))
|
|
49
|
+
: jsi::Value::undefined();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (propName == "colorScheme") {
|
|
53
|
+
return jsi::Value(jsi::String::createFromUtf8(runtime, this->colorScheme));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (propName == "sortedBreakpointPairs") {
|
|
57
|
+
std::unique_ptr<jsi::Array> sortedBreakpointEntriesArray = std::make_unique<jsi::Array>(runtime, this->sortedBreakpointEntries.size());
|
|
58
|
+
|
|
59
|
+
for (size_t i = 0; i < this->sortedBreakpointEntries.size(); ++i) {
|
|
60
|
+
std::unique_ptr<jsi::Array> pairArray = std::make_unique<jsi::Array>(runtime, 2);
|
|
61
|
+
jsi::String nameValue = jsi::String::createFromUtf8(runtime, this->sortedBreakpointEntries[i].first);
|
|
62
|
+
|
|
63
|
+
pairArray->setValueAtIndex(runtime, 0, nameValue);
|
|
64
|
+
pairArray->setValueAtIndex(runtime, 1, jsi::Value(this->sortedBreakpointEntries[i].second));
|
|
65
|
+
sortedBreakpointEntriesArray->setValueAtIndex(runtime, i, *pairArray);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return jsi::Value(runtime, *sortedBreakpointEntriesArray);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (propName == "useBreakpoints") {
|
|
72
|
+
return jsi::Function::createFromHostFunction(
|
|
73
|
+
runtime,
|
|
74
|
+
jsi::PropNameID::forAscii(runtime, "useBreakpoints"),
|
|
75
|
+
1,
|
|
76
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
|
77
|
+
jsi::Object breakpointsObj = arguments[0].asObject(runtime);
|
|
78
|
+
jsi::Array propertyNames = breakpointsObj.getPropertyNames(runtime);
|
|
79
|
+
std::vector<std::pair<std::string, double>> sortedBreakpointEntriesVec;
|
|
80
|
+
|
|
81
|
+
for (size_t i = 0; i < propertyNames.size(runtime); ++i) {
|
|
82
|
+
jsi::Value propNameValue = propertyNames.getValueAtIndex(runtime, i);
|
|
83
|
+
std::string name = propNameValue.asString(runtime).utf8(runtime);
|
|
84
|
+
jsi::PropNameID propNameID = jsi::PropNameID::forUtf8(runtime, name);
|
|
85
|
+
jsi::Value value = breakpointsObj.getProperty(runtime, propNameID);
|
|
86
|
+
|
|
87
|
+
if (value.isNumber()) {
|
|
88
|
+
double breakpointValue = value.asNumber();
|
|
89
|
+
sortedBreakpointEntriesVec.push_back(std::make_pair(name, breakpointValue));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
std::sort(sortedBreakpointEntriesVec.begin(), sortedBreakpointEntriesVec.end(), [](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) {
|
|
94
|
+
return a.second < b.second;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
this->sortedBreakpointEntries = sortedBreakpointEntriesVec;
|
|
98
|
+
|
|
99
|
+
std::string breakpoint = this->getBreakpointFromScreenWidth(this->screenWidth, sortedBreakpointEntriesVec);
|
|
100
|
+
|
|
101
|
+
this->breakpoint = breakpoint;
|
|
102
|
+
|
|
103
|
+
return jsi::Value::undefined();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (propName == "useTheme") {
|
|
109
|
+
return jsi::Function::createFromHostFunction(runtime,
|
|
110
|
+
jsi::PropNameID::forAscii(runtime, "useTheme"),
|
|
111
|
+
1,
|
|
112
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
|
113
|
+
std::string themeName = arguments[0].asString(runtime).utf8(runtime);
|
|
114
|
+
NSString *currentTheme = [NSString stringWithUTF8String:themeName.c_str()];
|
|
115
|
+
|
|
116
|
+
this->theme = themeName;
|
|
117
|
+
this->onThemeChange(themeName);
|
|
118
|
+
|
|
119
|
+
return jsi::Value::undefined();
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (propName == "useAdaptiveThemes") {
|
|
125
|
+
return jsi::Function::createFromHostFunction(runtime,
|
|
126
|
+
jsi::PropNameID::forAscii(runtime, "useAdaptiveThemes"),
|
|
127
|
+
1,
|
|
128
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
|
129
|
+
bool enableAdaptiveThemes = arguments[0].asBool();
|
|
130
|
+
|
|
131
|
+
this->hasAdaptiveThemes = enableAdaptiveThemes;
|
|
132
|
+
|
|
133
|
+
if (!enableAdaptiveThemes || !this->supportsAutomaticColorScheme) {
|
|
134
|
+
return jsi::Value::undefined();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this->theme = this->colorScheme;
|
|
138
|
+
// this->onThemeChange(this->theme);
|
|
139
|
+
|
|
140
|
+
return jsi::Value::undefined();
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return jsi::Value::undefined();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
void UnistylesRuntime::set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) {
|
|
149
|
+
std::string propName = propNameId.utf8(runtime);
|
|
150
|
+
|
|
151
|
+
if (propName == "themes" && value.isObject()) {
|
|
152
|
+
jsi::Array themes = value.asObject(runtime).asArray(runtime);
|
|
153
|
+
std::vector<std::string> themesVector;
|
|
154
|
+
size_t length = themes.size(runtime);
|
|
155
|
+
|
|
156
|
+
for (size_t i = 0; i < length; ++i) {
|
|
157
|
+
jsi::Value element = themes.getValueAtIndex(runtime, i);
|
|
158
|
+
|
|
159
|
+
if (element.isString()) {
|
|
160
|
+
std::string theme = element.asString(runtime).utf8(runtime);
|
|
161
|
+
themesVector.push_back(theme);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this->themes = themesVector;
|
|
166
|
+
|
|
167
|
+
bool hasLightTheme = std::find(themesVector.begin(), themesVector.end(), "light") != themesVector.end();
|
|
168
|
+
bool hasDarkTheme = std::find(themesVector.begin(), themesVector.end(), "dark") != themesVector.end();
|
|
169
|
+
|
|
170
|
+
this->supportsAutomaticColorScheme = hasLightTheme && hasDarkTheme;
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
std::string UnistylesRuntime::getBreakpointFromScreenWidth(double width, const std::vector<std::pair<std::string, double>>& sortedBreakpointEntries) {
|
|
177
|
+
for (size_t i = 0; i < sortedBreakpointEntries.size(); ++i) {
|
|
178
|
+
const auto& [key, value] = sortedBreakpointEntries[i];
|
|
179
|
+
const double maxVal = (i + 1 < sortedBreakpointEntries.size()) ? sortedBreakpointEntries[i + 1].second : std::numeric_limits<double>::infinity();
|
|
180
|
+
|
|
181
|
+
if (width >= value && width < maxVal) {
|
|
182
|
+
return key;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return sortedBreakpointEntries.empty() ? "" : sortedBreakpointEntries.back().first;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
void UnistylesRuntime::handleScreenSizeChange(int width, int height) {
|
|
190
|
+
if (width != this->screenWidth) {
|
|
191
|
+
this->screenWidth = width;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (height != this->screenHeight) {
|
|
195
|
+
this->screenHeight = height;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
std::string currentBreakpoint = this->breakpoint;
|
|
199
|
+
std::string nextBreakpoint = this->getBreakpointFromScreenWidth(width, this->sortedBreakpointEntries);
|
|
200
|
+
|
|
201
|
+
if (currentBreakpoint != nextBreakpoint) {
|
|
202
|
+
this->breakpoint = nextBreakpoint;
|
|
203
|
+
this->onBreakpointChange(nextBreakpoint);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void UnistylesRuntime::handleAppearanceChange(std::string colorScheme) {
|
|
208
|
+
this->colorScheme = colorScheme;
|
|
209
|
+
|
|
210
|
+
if (!this->supportsAutomaticColorScheme || !this->hasAdaptiveThemes) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this->theme = this->colorScheme;
|
|
215
|
+
this->onThemeChange(this->theme);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
jsi::Value UnistylesRuntime::getThemeOrFail(jsi::Runtime& runtime) {
|
|
219
|
+
if (this->themes.size() == 1) {
|
|
220
|
+
std::string themeName = this->themes.at(0);
|
|
221
|
+
|
|
222
|
+
this->theme = themeName;
|
|
223
|
+
|
|
224
|
+
return jsi::String::createFromUtf8(runtime, themeName);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return jsi::Value().undefined();
|
|
228
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnistyleRegistry = void 0;
|
|
7
|
+
class UnistyleRegistry {
|
|
8
|
+
config = {};
|
|
9
|
+
themes = {};
|
|
10
|
+
breakpoints = {};
|
|
11
|
+
sortedBreakpointPairs = [];
|
|
12
|
+
constructor(unistylesBridge) {
|
|
13
|
+
this.unistylesBridge = unistylesBridge;
|
|
14
|
+
}
|
|
15
|
+
addThemes = themes => {
|
|
16
|
+
this.themes = themes;
|
|
17
|
+
this.unistylesBridge.themes = Object.keys(themes);
|
|
18
|
+
return this;
|
|
19
|
+
};
|
|
20
|
+
addBreakpoints = breakpoints => {
|
|
21
|
+
this.unistylesBridge.useBreakpoints(breakpoints);
|
|
22
|
+
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
addConfig = config => {
|
|
26
|
+
this.config = config;
|
|
27
|
+
if (config.adaptiveThemes) {
|
|
28
|
+
this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes);
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.UnistyleRegistry = UnistyleRegistry;
|
|
34
|
+
//# sourceMappingURL=UnistyleRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UnistyleRegistry","config","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","Object","keys","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","exports"],"sourceRoot":"../../src","sources":["UnistyleRegistry.ts"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EAExHC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIL,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACI,eAAe,CAACJ,MAAM,GAAGM,MAAM,CAACC,IAAI,CAACP,MAAM,CAAiC;IAEjF,OAAO,IAAI;EACf,CAAC;EAEMQ,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACG,eAAe,CAACK,cAAc,CAACR,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACE,eAAe,CAACF,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMQ,SAAS,GAAIX,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACY,cAAc,EAAE;MACvB,IAAI,CAACP,eAAe,CAACQ,iBAAiB,CAACb,MAAM,CAACY,cAAc,CAAC;IACjE;IAEA,OAAO,IAAI;EACf,CAAC;AACL;AAACE,OAAA,CAAAf,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unistyles = void 0;
|
|
7
|
+
var _UnistylesModule = require("./UnistylesModule");
|
|
8
|
+
var _UnistylesRuntime = require("./UnistylesRuntime");
|
|
9
|
+
var _UnistylesEngine = require("./UnistylesEngine");
|
|
10
|
+
var _UnistyleRegistry = require("./UnistyleRegistry");
|
|
11
|
+
var _types = require("./types");
|
|
12
|
+
class Unistyles {
|
|
13
|
+
constructor() {
|
|
14
|
+
const isInstalled = _UnistylesModule.UnistylesModule?.install() ?? false;
|
|
15
|
+
if (!isInstalled) {
|
|
16
|
+
throw new Error(_types.UnistylesError.RuntimeUnavailable);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
this._bridge = global.__UNISTYLES__;
|
|
21
|
+
this._registry = new _UnistyleRegistry.UnistyleRegistry(this._bridge);
|
|
22
|
+
this._runtime = new _UnistylesRuntime.UnistylesRuntime(this._bridge, this._registry);
|
|
23
|
+
this._engine = new _UnistylesEngine.UnistylesEngine(this._registry, this._runtime);
|
|
24
|
+
}
|
|
25
|
+
get registry() {
|
|
26
|
+
return this._registry;
|
|
27
|
+
}
|
|
28
|
+
get runtime() {
|
|
29
|
+
return this._runtime;
|
|
30
|
+
}
|
|
31
|
+
get engine() {
|
|
32
|
+
return this._engine;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const unistyles = exports.unistyles = new Unistyles();
|
|
36
|
+
//# sourceMappingURL=Unistyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_UnistylesModule","require","_UnistylesRuntime","_UnistylesEngine","_UnistyleRegistry","_types","Unistyles","constructor","isInstalled","UnistylesModule","install","Error","UnistylesError","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","UnistyleRegistry","_runtime","UnistylesRuntime","_engine","UnistylesEngine","registry","runtime","engine","unistyles","exports"],"sourceRoot":"../../src","sources":["Unistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,SAAS,CAAC;EAMZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGC,gCAAe,EAAEC,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACF,WAAW,EAAE;MACd,MAAM,IAAIG,KAAK,CAACC,qBAAc,CAACC,kBAAkB,CAAC;IACtD;;IAEA;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,aAAgC;IACtD,IAAI,CAACC,SAAS,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACJ,OAAO,CAAC;IACnD,IAAI,CAACK,QAAQ,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACN,OAAO,EAAE,IAAI,CAACG,SAAS,CAAC;IAClE,IAAI,CAACI,OAAO,GAAG,IAAIC,gCAAe,CAAC,IAAI,CAACL,SAAS,EAAE,IAAI,CAACE,QAAQ,CAAC;EACrE;EAEA,IAAWI,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACN,SAAS;EACzB;EAEA,IAAWO,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACL,QAAQ;EACxB;EAEA,IAAWM,MAAMA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACJ,OAAO;EACvB;AACJ;AAEO,MAAMK,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIpB,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnistylesEngine = void 0;
|
|
7
|
+
// todo implement engine
|
|
8
|
+
class UnistylesEngine {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
constructor(registry, runtime) {
|
|
11
|
+
this.registry = registry;
|
|
12
|
+
this.runtime = runtime;
|
|
13
|
+
this.registry = registry;
|
|
14
|
+
this.runtime = runtime;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// UnistylesEngine.parseStyleSheet
|
|
18
|
+
// UnistylesEngine.parseStyle
|
|
19
|
+
// UnistylesEngine.proxify
|
|
20
|
+
}
|
|
21
|
+
exports.UnistylesEngine = UnistylesEngine;
|
|
22
|
+
//# sourceMappingURL=UnistylesEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UnistylesEngine","constructor","registry","runtime","exports"],"sourceRoot":"../../src","sources":["UnistylesEngine.ts"],"mappings":";;;;;;AAGA;AACO,MAAMA,eAAe,CAAC;EACzB;EACAC,WAAWA,CAASC,QAA0B,EAAUC,OAAyB,EAAE;IAAA,KAA/DD,QAA0B,GAA1BA,QAA0B;IAAA,KAAUC,OAAyB,GAAzBA,OAAyB;IAC7E,IAAI,CAACD,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;;EAEA;EACA;EACA;AACJ;AAACC,OAAA,CAAAJ,eAAA,GAAAA,eAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnistylesModule = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
const UnistylesModule = exports.UnistylesModule = _reactNative.NativeModules?.Unistyles;
|
|
9
|
+
//# sourceMappingURL=UnistylesModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","UnistylesModule","exports","NativeModules","Unistyles"],"sourceRoot":"../../src","sources":["UnistylesModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMO,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,0BAAa,EAAEC,SAAkC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnistylesRuntime = void 0;
|
|
7
|
+
var _types = require("./types");
|
|
8
|
+
class UnistylesRuntime {
|
|
9
|
+
constructor(unistylesBridge, registry) {
|
|
10
|
+
this.unistylesBridge = unistylesBridge;
|
|
11
|
+
this.registry = registry;
|
|
12
|
+
}
|
|
13
|
+
get colorScheme() {
|
|
14
|
+
return this.unistylesBridge.colorScheme;
|
|
15
|
+
}
|
|
16
|
+
get hasAdaptiveThemes() {
|
|
17
|
+
return this.unistylesBridge.hasAdaptiveThemes;
|
|
18
|
+
}
|
|
19
|
+
get sortedBreakpoints() {
|
|
20
|
+
return this.registry.sortedBreakpointPairs;
|
|
21
|
+
}
|
|
22
|
+
get themeName() {
|
|
23
|
+
return this.unistylesBridge.theme;
|
|
24
|
+
}
|
|
25
|
+
get breakpoint() {
|
|
26
|
+
return this.unistylesBridge.breakpoint;
|
|
27
|
+
}
|
|
28
|
+
get screen() {
|
|
29
|
+
return {
|
|
30
|
+
width: this.unistylesBridge.screenWidth,
|
|
31
|
+
height: this.unistylesBridge.screenHeight
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
get orientation() {
|
|
35
|
+
const {
|
|
36
|
+
width,
|
|
37
|
+
height
|
|
38
|
+
} = this.screen;
|
|
39
|
+
if (width > height) {
|
|
40
|
+
return _types.ScreenOrientation.Landscape;
|
|
41
|
+
}
|
|
42
|
+
return _types.ScreenOrientation.Portrait;
|
|
43
|
+
}
|
|
44
|
+
setTheme = name => {
|
|
45
|
+
if (name !== this.themeName && this.hasTheme(name)) {
|
|
46
|
+
this.unistylesBridge.useTheme(name);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
getTheme = forName => {
|
|
52
|
+
if (!this.hasTheme(forName)) {
|
|
53
|
+
throw new Error(_types.UnistylesError.ThemeNotFound);
|
|
54
|
+
}
|
|
55
|
+
return this.registry.themes[forName];
|
|
56
|
+
};
|
|
57
|
+
setAdaptiveThemes = enable => {
|
|
58
|
+
this.unistylesBridge.useAdaptiveThemes(enable);
|
|
59
|
+
};
|
|
60
|
+
hasTheme = name => name in this.registry.themes;
|
|
61
|
+
}
|
|
62
|
+
exports.UnistylesRuntime = UnistylesRuntime;
|
|
63
|
+
//# sourceMappingURL=UnistylesRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_types","require","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","hasAdaptiveThemes","sortedBreakpoints","sortedBreakpointPairs","themeName","theme","breakpoint","screen","width","screenWidth","height","screenHeight","orientation","ScreenOrientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","getTheme","forName","Error","UnistylesError","ThemeNotFound","themes","setAdaptiveThemes","enable","useAdaptiveThemes","exports"],"sourceRoot":"../../src","sources":["UnistylesRuntime.ts"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,QAA0B,EAAE;IAAA,KAAtED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,QAA0B,GAA1BA,QAA0B;EAAG;EAE3F,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACN,eAAe,CAACO,KAAK;EACrC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACR,eAAe,CAACQ,UAAU;EAC1C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACV,eAAe,CAACW,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACZ,eAAe,CAACa;IACjC,CAAC;EACL;EAEA,IAAWC,WAAWA,CAAA,EAAG;IACrB,MAAM;MAAEJ,KAAK;MAAEE;IAAO,CAAC,GAAG,IAAI,CAACH,MAAM;IAErC,IAAIC,KAAK,GAAGE,MAAM,EAAE;MAChB,OAAOG,wBAAiB,CAACC,SAAS;IACtC;IAEA,OAAOD,wBAAiB,CAACE,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAIA,IAAI,KAAK,IAAI,CAACb,SAAS,IAAI,IAAI,CAACc,QAAQ,CAACD,IAAI,CAAC,EAAE;MAChD,IAAI,CAACnB,eAAe,CAACqB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,OAAO,KAAK;EAChB,CAAC;EAEMG,QAAQ,GAAIC,OAA8B,IAAK;IAClD,IAAI,CAAC,IAAI,CAACH,QAAQ,CAACG,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIC,KAAK,CAACC,qBAAc,CAACC,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAACzB,QAAQ,CAAC0B,MAAM,CAACJ,OAAO,CAAC;EACxC,CAAC;EAEMK,iBAAiB,GAAIC,MAAe,IAAK;IAC5C,IAAI,CAAC7B,eAAe,CAAC8B,iBAAiB,CAACD,MAAM,CAAC;EAClD,CAAC;EAEOT,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAAClB,QAAQ,CAAC0B,MAAM;AACpF;AAACI,OAAA,CAAAjC,gBAAA,GAAAA,gBAAA"}
|