react-native-unistyles 1.2.0 → 2.0.0-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.cpp +255 -0
- package/cxx/UnistylesRuntime.h +60 -0
- package/ios/UnistylesHelpers.h +4 -0
- package/ios/UnistylesHelpers.mm +20 -0
- package/ios/UnistylesModule.h +10 -0
- package/ios/UnistylesModule.mm +158 -0
- package/lib/commonjs/common.js +26 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/core/UnistyleRegistry.js +38 -0
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/core/Unistyles.js +31 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js +9 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +66 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.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/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useInitialTheme.js +17 -0
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +54 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +35 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/common.js +2 -0
- package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mq.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.js.map +1 -0
- package/lib/commonjs/useStyles.js +49 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +44 -82
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +6 -1
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +25 -30
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +89 -0
- package/lib/commonjs/utils/mq.js.map +1 -0
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/styles.js +6 -53
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +20 -0
- package/lib/commonjs/utils/variants.js.map +1 -0
- package/lib/module/common.js +22 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/core/UnistyleRegistry.js +31 -0
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/core/Unistyles.js +25 -0
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +3 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +59 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.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/index.js +2 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +47 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/index.js +13 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mq.js +2 -0
- package/lib/module/types/mq.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +43 -82
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +5 -0
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +5 -3
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +83 -0
- package/lib/module/utils/mq.js.map +1 -0
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/styles.js +7 -55
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +13 -0
- package/lib/module/utils/variants.js.map +1 -0
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/Unistyles.d.ts +13 -0
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +3 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +7 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- 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 +12 -13
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +34 -18
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +5 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +3 -0
- package/lib/typescript/src/types/mq.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +37 -0
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +10 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +5 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +5 -3
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +21 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -0
- package/lib/typescript/src/utils/mqParser.d.ts +3 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +4 -49
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +3 -0
- package/lib/typescript/src/utils/variants.d.ts.map +1 -0
- package/package.json +30 -19
- package/react-native-unistyles.podspec +22 -0
- package/src/common.ts +19 -0
- package/src/core/UnistyleRegistry.ts +41 -0
- package/src/core/Unistyles.ts +34 -0
- package/src/core/UnistylesModule.ts +7 -0
- package/src/core/UnistylesRuntime.ts +73 -0
- package/src/core/index.ts +1 -0
- package/src/createStyleSheet.ts +9 -0
- package/src/global.ts +5 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +55 -0
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +16 -19
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +42 -24
- package/src/types/index.ts +5 -9
- package/src/types/mq.ts +3 -0
- package/src/types/unistyles.ts +45 -0
- package/src/useStyles.ts +56 -0
- package/src/utils/breakpoints.ts +57 -88
- package/src/utils/common.ts +6 -0
- package/src/utils/index.ts +5 -10
- package/src/utils/mq.ts +106 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +17 -64
- package/src/utils/variants.ts +17 -0
- 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/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -34
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/utils/mediaQueries.js +0 -189
- package/lib/commonjs/utils/mediaQueries.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/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -27
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/utils/mediaQueries.js +0 -176
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/examples/expo/src/App.d.ts +0 -3
- package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -9
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/index.d.ts +0 -2
- package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.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/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
- package/lib/typescript/src/utils/mediaQueries.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/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -34
- package/src/types/mediaQueries.ts +0 -10
- package/src/utils/mediaQueries.ts +0 -201
@@ -0,0 +1,255 @@
|
|
1
|
+
#include "UnistylesRuntime.h"
|
2
|
+
|
3
|
+
#include <string>
|
4
|
+
#include <vector>
|
5
|
+
|
6
|
+
#pragma region HostObject
|
7
|
+
|
8
|
+
std::vector<jsi::PropNameID> UnistylesRuntime::getPropertyNames(jsi::Runtime& runtime) {
|
9
|
+
std::vector<jsi::PropNameID> properties;
|
10
|
+
|
11
|
+
// getters
|
12
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("screenWidth")));
|
13
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("screenHeight")));
|
14
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("hasAdaptiveThemes")));
|
15
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("themeName")));
|
16
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("breakpoint")));
|
17
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("colorScheme")));
|
18
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("sortedBreakpointPairs")));
|
19
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useBreakpoints")));
|
20
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useTheme")));
|
21
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useAdaptiveThemes")));
|
22
|
+
|
23
|
+
// setters
|
24
|
+
properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("themes")));
|
25
|
+
|
26
|
+
return properties;
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) {
|
31
|
+
std::string propName = propNameId.utf8(runtime);
|
32
|
+
|
33
|
+
if (propName == "screenWidth") {
|
34
|
+
return jsi::Value(this->screenWidth);
|
35
|
+
}
|
36
|
+
|
37
|
+
if (propName == "screenHeight") {
|
38
|
+
return jsi::Value(this->screenHeight);
|
39
|
+
}
|
40
|
+
|
41
|
+
if (propName == "hasAdaptiveThemes") {
|
42
|
+
return jsi::Value(this->hasAdaptiveThemes);
|
43
|
+
}
|
44
|
+
|
45
|
+
if (propName == "themeName") {
|
46
|
+
return !this->themeName.empty()
|
47
|
+
? jsi::Value(jsi::String::createFromUtf8(runtime, this->themeName))
|
48
|
+
: this->getThemeOrFail(runtime);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (propName == "breakpoint") {
|
52
|
+
return !this->breakpoint.empty()
|
53
|
+
? jsi::Value(jsi::String::createFromUtf8(runtime, this->breakpoint))
|
54
|
+
: jsi::Value::undefined();
|
55
|
+
}
|
56
|
+
|
57
|
+
if (propName == "colorScheme") {
|
58
|
+
return jsi::Value(jsi::String::createFromUtf8(runtime, this->colorScheme));
|
59
|
+
}
|
60
|
+
|
61
|
+
if (propName == "sortedBreakpointPairs") {
|
62
|
+
std::unique_ptr<jsi::Array> sortedBreakpointEntriesArray = std::make_unique<jsi::Array>(runtime, this->sortedBreakpointPairs.size());
|
63
|
+
|
64
|
+
for (size_t i = 0; i < this->sortedBreakpointPairs.size(); ++i) {
|
65
|
+
std::unique_ptr<jsi::Array> pairArray = std::make_unique<jsi::Array>(runtime, 2);
|
66
|
+
jsi::String nameValue = jsi::String::createFromUtf8(runtime, this->sortedBreakpointPairs[i].first);
|
67
|
+
|
68
|
+
pairArray->setValueAtIndex(runtime, 0, nameValue);
|
69
|
+
pairArray->setValueAtIndex(runtime, 1, jsi::Value(this->sortedBreakpointPairs[i].second));
|
70
|
+
sortedBreakpointEntriesArray->setValueAtIndex(runtime, i, *pairArray);
|
71
|
+
}
|
72
|
+
|
73
|
+
return jsi::Value(runtime, *sortedBreakpointEntriesArray);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (propName == "useBreakpoints") {
|
77
|
+
return jsi::Function::createFromHostFunction(
|
78
|
+
runtime,
|
79
|
+
jsi::PropNameID::forAscii(runtime, "useBreakpoints"),
|
80
|
+
1,
|
81
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
82
|
+
jsi::Object breakpointsObj = arguments[0].asObject(runtime);
|
83
|
+
jsi::Array propertyNames = breakpointsObj.getPropertyNames(runtime);
|
84
|
+
std::vector<std::pair<std::string, double>> sortedBreakpointEntriesVec;
|
85
|
+
|
86
|
+
for (size_t i = 0; i < propertyNames.size(runtime); ++i) {
|
87
|
+
jsi::Value propNameValue = propertyNames.getValueAtIndex(runtime, i);
|
88
|
+
std::string name = propNameValue.asString(runtime).utf8(runtime);
|
89
|
+
jsi::PropNameID propNameID = jsi::PropNameID::forUtf8(runtime, name);
|
90
|
+
jsi::Value value = breakpointsObj.getProperty(runtime, propNameID);
|
91
|
+
|
92
|
+
if (value.isNumber()) {
|
93
|
+
double breakpointValue = value.asNumber();
|
94
|
+
sortedBreakpointEntriesVec.push_back(std::make_pair(name, breakpointValue));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
std::sort(sortedBreakpointEntriesVec.begin(), sortedBreakpointEntriesVec.end(), [](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) {
|
99
|
+
return a.second < b.second;
|
100
|
+
});
|
101
|
+
|
102
|
+
if (sortedBreakpointEntriesVec.size() == 0) {
|
103
|
+
throw jsi::JSError(runtime, UnistylesErrorBreakpointsCannotBeEmpty);
|
104
|
+
}
|
105
|
+
|
106
|
+
if (sortedBreakpointEntriesVec.at(0).second != 0) {
|
107
|
+
throw jsi::JSError(runtime, UnistylesErrorBreakpointsMustStartFromZero);
|
108
|
+
}
|
109
|
+
|
110
|
+
this->sortedBreakpointPairs = sortedBreakpointEntriesVec;
|
111
|
+
|
112
|
+
std::string breakpoint = this->getBreakpointFromScreenWidth(this->screenWidth, sortedBreakpointEntriesVec);
|
113
|
+
|
114
|
+
this->breakpoint = breakpoint;
|
115
|
+
|
116
|
+
return jsi::Value::undefined();
|
117
|
+
}
|
118
|
+
);
|
119
|
+
}
|
120
|
+
|
121
|
+
if (propName == "useTheme") {
|
122
|
+
return jsi::Function::createFromHostFunction(runtime,
|
123
|
+
jsi::PropNameID::forAscii(runtime, "useTheme"),
|
124
|
+
1,
|
125
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
126
|
+
std::string themeName = arguments[0].asString(runtime).utf8(runtime);
|
127
|
+
|
128
|
+
if (this->themeName != themeName) {
|
129
|
+
this->themeName = themeName;
|
130
|
+
this->onThemeChangeCallback(themeName);
|
131
|
+
}
|
132
|
+
|
133
|
+
return jsi::Value::undefined();
|
134
|
+
}
|
135
|
+
);
|
136
|
+
}
|
137
|
+
|
138
|
+
if (propName == "useAdaptiveThemes") {
|
139
|
+
return jsi::Function::createFromHostFunction(runtime,
|
140
|
+
jsi::PropNameID::forAscii(runtime, "useAdaptiveThemes"),
|
141
|
+
1,
|
142
|
+
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
143
|
+
bool enableAdaptiveThemes = arguments[0].asBool();
|
144
|
+
|
145
|
+
this->hasAdaptiveThemes = enableAdaptiveThemes;
|
146
|
+
|
147
|
+
if (!enableAdaptiveThemes || !this->supportsAutomaticColorScheme) {
|
148
|
+
return jsi::Value::undefined();
|
149
|
+
}
|
150
|
+
|
151
|
+
if (this->themeName != this->colorScheme) {
|
152
|
+
this->themeName = this->colorScheme;
|
153
|
+
this->onThemeChangeCallback(this->themeName);
|
154
|
+
}
|
155
|
+
|
156
|
+
return jsi::Value::undefined();
|
157
|
+
}
|
158
|
+
);
|
159
|
+
}
|
160
|
+
|
161
|
+
return jsi::Value::undefined();
|
162
|
+
}
|
163
|
+
|
164
|
+
void UnistylesRuntime::set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) {
|
165
|
+
std::string propName = propNameId.utf8(runtime);
|
166
|
+
|
167
|
+
if (propName == "themes" && value.isObject()) {
|
168
|
+
jsi::Array themes = value.asObject(runtime).asArray(runtime);
|
169
|
+
std::vector<std::string> themesVector;
|
170
|
+
size_t length = themes.size(runtime);
|
171
|
+
|
172
|
+
for (size_t i = 0; i < length; ++i) {
|
173
|
+
jsi::Value element = themes.getValueAtIndex(runtime, i);
|
174
|
+
|
175
|
+
if (element.isString()) {
|
176
|
+
std::string theme = element.asString(runtime).utf8(runtime);
|
177
|
+
themesVector.push_back(theme);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
if (themesVector.size() == 0) {
|
182
|
+
throw jsi::JSError(runtime, UnistylesErrorThemesCannotBeEmpty);
|
183
|
+
}
|
184
|
+
|
185
|
+
this->themes = themesVector;
|
186
|
+
this->themeName = "";
|
187
|
+
|
188
|
+
bool hasLightTheme = std::find(themesVector.begin(), themesVector.end(), "light") != themesVector.end();
|
189
|
+
bool hasDarkTheme = std::find(themesVector.begin(), themesVector.end(), "dark") != themesVector.end();
|
190
|
+
|
191
|
+
this->supportsAutomaticColorScheme = hasLightTheme && hasDarkTheme;
|
192
|
+
|
193
|
+
return;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
#pragma endregion
|
198
|
+
#pragma region Helpers
|
199
|
+
|
200
|
+
std::string UnistylesRuntime::getBreakpointFromScreenWidth(int width, const std::vector<std::pair<std::string, double>>& sortedBreakpointPairs) {
|
201
|
+
for (size_t i = 0; i < sortedBreakpointPairs.size(); ++i) {
|
202
|
+
const auto& [key, value] = sortedBreakpointPairs[i];
|
203
|
+
const double maxVal = (i + 1 < sortedBreakpointPairs.size()) ? sortedBreakpointPairs[i + 1].second : std::numeric_limits<double>::infinity();
|
204
|
+
|
205
|
+
if (width >= value && width < maxVal) {
|
206
|
+
return key;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
return sortedBreakpointPairs.empty() ? "" : sortedBreakpointPairs.back().first;
|
211
|
+
}
|
212
|
+
|
213
|
+
void UnistylesRuntime::handleScreenSizeChange(int width, int height) {
|
214
|
+
std::string breakpoint = this->getBreakpointFromScreenWidth(width, this->sortedBreakpointPairs);
|
215
|
+
bool shouldNotify = this->breakpoint != breakpoint || this->screenWidth != width || this->screenHeight != height;
|
216
|
+
|
217
|
+
this->breakpoint = breakpoint;
|
218
|
+
this->screenWidth = width;
|
219
|
+
this->screenHeight = height;
|
220
|
+
|
221
|
+
int orientation = width > height
|
222
|
+
? UnistylesOrientationLandscape
|
223
|
+
: UnistylesOrientationPortrait;
|
224
|
+
|
225
|
+
if (shouldNotify) {
|
226
|
+
this->onLayoutChangeCallback(breakpoint, orientation, width, height);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
void UnistylesRuntime::handleAppearanceChange(std::string colorScheme) {
|
231
|
+
this->colorScheme = colorScheme;
|
232
|
+
|
233
|
+
if (!this->supportsAutomaticColorScheme || !this->hasAdaptiveThemes) {
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
|
237
|
+
if (this->themeName != this->colorScheme) {
|
238
|
+
this->onThemeChangeCallback(this->colorScheme);
|
239
|
+
this->themeName = this->colorScheme;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
jsi::Value UnistylesRuntime::getThemeOrFail(jsi::Runtime& runtime) {
|
244
|
+
if (this->themes.size() == 1) {
|
245
|
+
std::string themeName = this->themes.at(0);
|
246
|
+
|
247
|
+
this->themeName = themeName;
|
248
|
+
|
249
|
+
return jsi::String::createFromUtf8(runtime, themeName);
|
250
|
+
}
|
251
|
+
|
252
|
+
return jsi::Value().undefined();
|
253
|
+
}
|
254
|
+
|
255
|
+
#pragma endregion
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <jsi/jsi.h>
|
4
|
+
#include <vector>
|
5
|
+
|
6
|
+
using namespace facebook;
|
7
|
+
|
8
|
+
const int UnistylesOrientationPortrait = 1;
|
9
|
+
const int UnistylesOrientationLandscape = 2;
|
10
|
+
|
11
|
+
const std::string UnistylesDarkScheme = "dark";
|
12
|
+
const std::string UnistylesLightScheme = "light";
|
13
|
+
const std::string UnistylesUnspecifiedScheme = "unspecified";
|
14
|
+
|
15
|
+
const std::string UnistylesErrorBreakpointsCannotBeEmpty = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY'";
|
16
|
+
const std::string UnistylesErrorBreakpointsMustStartFromZero = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZER0";
|
17
|
+
const std::string UnistylesErrorThemesCannotBeEmpty = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY";
|
18
|
+
|
19
|
+
class JSI_EXPORT UnistylesRuntime : public jsi::HostObject {
|
20
|
+
private:
|
21
|
+
std::function<void(std::string)> onThemeChangeCallback;
|
22
|
+
std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> onLayoutChangeCallback;
|
23
|
+
|
24
|
+
int screenWidth;
|
25
|
+
int screenHeight;
|
26
|
+
std::string colorScheme;
|
27
|
+
|
28
|
+
public:
|
29
|
+
UnistylesRuntime(
|
30
|
+
int screenWidth,
|
31
|
+
int screenHeight,
|
32
|
+
std::string colorScheme
|
33
|
+
): screenWidth(screenWidth), screenHeight(screenHeight), colorScheme(colorScheme) {}
|
34
|
+
|
35
|
+
bool hasAdaptiveThemes;
|
36
|
+
bool supportsAutomaticColorScheme;
|
37
|
+
|
38
|
+
std::string themeName;
|
39
|
+
std::string breakpoint;
|
40
|
+
std::vector<std::string> themes;
|
41
|
+
std::vector<std::pair<std::string, double>> sortedBreakpointPairs;
|
42
|
+
|
43
|
+
void onThemeChange(std::function<void(std::string)> callback) {
|
44
|
+
this->onThemeChangeCallback = callback;
|
45
|
+
}
|
46
|
+
|
47
|
+
void onLayoutChange(std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> callback) {
|
48
|
+
this->onLayoutChangeCallback = callback;
|
49
|
+
}
|
50
|
+
|
51
|
+
jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
|
52
|
+
void set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) override;
|
53
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override;
|
54
|
+
|
55
|
+
void handleScreenSizeChange(int width, int height);
|
56
|
+
void handleAppearanceChange(std::string colorScheme);
|
57
|
+
|
58
|
+
jsi::Value getThemeOrFail(jsi::Runtime&);
|
59
|
+
std::string getBreakpointFromScreenWidth(int width, const std::vector<std::pair<std::string, double>>& sortedBreakpointEntries);
|
60
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#import "UnistylesHelpers.h"
|
2
|
+
#import "UnistylesRuntime.h"
|
3
|
+
|
4
|
+
std::string getColorScheme() {
|
5
|
+
UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
|
6
|
+
|
7
|
+
switch (colorScheme) {
|
8
|
+
case UIUserInterfaceStyleLight:
|
9
|
+
return UnistylesLightScheme;
|
10
|
+
case UIUserInterfaceStyleDark:
|
11
|
+
return UnistylesDarkScheme;
|
12
|
+
case UIUserInterfaceStyleUnspecified:
|
13
|
+
default:
|
14
|
+
return UnistylesUnspecifiedScheme;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
NSString* cxxStringToNSString(std::string cxxString) {
|
19
|
+
return [NSString stringWithUTF8String:cxxString.c_str()];
|
20
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
2
|
+
#import <React/RCTEventEmitter.h>
|
3
|
+
#import <string>
|
4
|
+
|
5
|
+
@interface UnistylesModule : RCTEventEmitter<RCTBridgeModule>
|
6
|
+
|
7
|
+
@property (nonatomic, assign) BOOL hasListeners;
|
8
|
+
@property (nonatomic, assign) void* unistylesRuntime;
|
9
|
+
|
10
|
+
@end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#import "UnistylesModule.h"
|
2
|
+
#import "UnistylesHelpers.h"
|
3
|
+
#import "UnistylesRuntime.h"
|
4
|
+
|
5
|
+
#import <React/RCTAppearance.h>
|
6
|
+
#import <React/RCTBridge+Private.h>
|
7
|
+
#import <jsi/jsi.h>
|
8
|
+
|
9
|
+
using namespace facebook;
|
10
|
+
|
11
|
+
@implementation UnistylesModule
|
12
|
+
|
13
|
+
RCT_EXPORT_MODULE(Unistyles)
|
14
|
+
|
15
|
+
#pragma mark - Lifecycle
|
16
|
+
|
17
|
+
- (instancetype)init {
|
18
|
+
if ((self = [super init])) {
|
19
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
20
|
+
selector:@selector(handleOrientationChange:)
|
21
|
+
name:UIDeviceOrientationDidChangeNotification
|
22
|
+
object:nil];
|
23
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
24
|
+
selector:@selector(appearanceChanged:)
|
25
|
+
name:RCTUserInterfaceStyleDidChangeNotification
|
26
|
+
object:nil];
|
27
|
+
}
|
28
|
+
|
29
|
+
return self;
|
30
|
+
}
|
31
|
+
|
32
|
+
- (void)dealloc {
|
33
|
+
if (self.unistylesRuntime != nullptr) {
|
34
|
+
self.unistylesRuntime = nullptr;
|
35
|
+
}
|
36
|
+
|
37
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
+ (BOOL)requiresMainQueueSetup {
|
42
|
+
return YES;
|
43
|
+
}
|
44
|
+
|
45
|
+
#pragma mark - Event handlers
|
46
|
+
|
47
|
+
- (void)handleOrientationChange:(NSNotification *)notification {
|
48
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
49
|
+
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
|
50
|
+
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
|
51
|
+
|
52
|
+
if (self.unistylesRuntime != nullptr) {
|
53
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange((int)screenWidth, (int)screenHeight);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
- (void)appearanceChanged:(NSNotification *)notification {
|
59
|
+
std::string colorScheme = getColorScheme();
|
60
|
+
|
61
|
+
if (self.unistylesRuntime != nullptr) {
|
62
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
#pragma mark - Event emitter
|
67
|
+
- (NSArray<NSString *> *)supportedEvents {
|
68
|
+
return @[@"onChange"];
|
69
|
+
}
|
70
|
+
|
71
|
+
- (void)startObserving {
|
72
|
+
self.hasListeners = YES;
|
73
|
+
}
|
74
|
+
|
75
|
+
- (void)stopObserving {
|
76
|
+
self.hasListeners = NO;
|
77
|
+
}
|
78
|
+
|
79
|
+
- (void)emitEvent:(NSString *)eventName withBody:(NSDictionary *)body {
|
80
|
+
if (self.hasListeners) {
|
81
|
+
[self sendEventWithName:@"onChange" body:body];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
#pragma mark - Core
|
86
|
+
|
87
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
88
|
+
RCTBridge* bridge = [RCTBridge currentBridge];
|
89
|
+
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
90
|
+
|
91
|
+
if (cxxBridge == nil) {
|
92
|
+
return @false;
|
93
|
+
}
|
94
|
+
|
95
|
+
auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
|
96
|
+
|
97
|
+
if (jsiRuntime == nil) {
|
98
|
+
return @false;
|
99
|
+
}
|
100
|
+
|
101
|
+
auto& runtime = *jsiRuntime;
|
102
|
+
UnistylesModule *__weak weakSelf = self;
|
103
|
+
|
104
|
+
registerUnistylesHostObject(runtime, weakSelf);
|
105
|
+
|
106
|
+
NSLog(@"Installed Unistyles 🦄!");
|
107
|
+
|
108
|
+
return @true;
|
109
|
+
}
|
110
|
+
|
111
|
+
void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSelf) {
|
112
|
+
CGFloat initialScreenWidth = [UIScreen mainScreen].bounds.size.width;
|
113
|
+
CGFloat initialScreenHeight = [UIScreen mainScreen].bounds.size.height;
|
114
|
+
std::string initialColorScheme = getColorScheme();
|
115
|
+
|
116
|
+
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
|
117
|
+
(int)initialScreenWidth,
|
118
|
+
(int)initialScreenHeight,
|
119
|
+
initialColorScheme
|
120
|
+
);
|
121
|
+
|
122
|
+
unistylesRuntime.get()->onThemeChange([=](std::string theme) {
|
123
|
+
NSDictionary *body = @{
|
124
|
+
@"type": @"theme",
|
125
|
+
@"payload": @{
|
126
|
+
@"themeName": cxxStringToNSString(theme)
|
127
|
+
}
|
128
|
+
};
|
129
|
+
|
130
|
+
[weakSelf emitEvent:@"onChange" withBody:body];
|
131
|
+
});
|
132
|
+
|
133
|
+
unistylesRuntime.get()->onLayoutChange([=](std::string breakpoint, int orientation, int width, int height) {
|
134
|
+
NSDictionary *body = @{
|
135
|
+
@"type": @"layout",
|
136
|
+
@"payload": @{
|
137
|
+
@"breakpoint": cxxStringToNSString(breakpoint),
|
138
|
+
@"orientation": @(orientation),
|
139
|
+
@"screen": @{
|
140
|
+
@"width": @(width),
|
141
|
+
@"height": @(height)
|
142
|
+
}
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
[weakSelf emitEvent:@"onChange" withBody:body];
|
147
|
+
});
|
148
|
+
|
149
|
+
weakSelf.unistylesRuntime = unistylesRuntime.get();
|
150
|
+
|
151
|
+
auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
|
152
|
+
|
153
|
+
runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
|
154
|
+
}
|
155
|
+
|
156
|
+
@end
|
157
|
+
|
158
|
+
#pragma mark - End
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.UnistylesError = exports.ScreenOrientation = exports.CxxUnistylesEventTypes = void 0;
|
7
|
+
let CxxUnistylesEventTypes = exports.CxxUnistylesEventTypes = /*#__PURE__*/function (CxxUnistylesEventTypes) {
|
8
|
+
CxxUnistylesEventTypes["Theme"] = "theme";
|
9
|
+
CxxUnistylesEventTypes["Layout"] = "layout";
|
10
|
+
return CxxUnistylesEventTypes;
|
11
|
+
}({});
|
12
|
+
let UnistylesError = exports.UnistylesError = /*#__PURE__*/function (UnistylesError) {
|
13
|
+
UnistylesError["RuntimeUnavailable"] = "UNISTYLES_ERROR_RUNTIME_UNAVAILABLE";
|
14
|
+
UnistylesError["ThemeNotFound"] = "UNISTYLES_ERROR_THEME_NOT_FOUND";
|
15
|
+
UnistylesError["ThemeNotRegistered"] = "UNISTYLES_ERROR_THEME_NOT_REGISTERED";
|
16
|
+
UnistylesError["ThemesCannotBeEmpty"] = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY";
|
17
|
+
UnistylesError["BreakpointsCannotBeEmpty"] = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY";
|
18
|
+
UnistylesError["BreakpointsMustStartFromZero"] = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO";
|
19
|
+
return UnistylesError;
|
20
|
+
}({}); // todo to string?
|
21
|
+
let ScreenOrientation = exports.ScreenOrientation = /*#__PURE__*/function (ScreenOrientation) {
|
22
|
+
ScreenOrientation[ScreenOrientation["Portrait"] = 1] = "Portrait";
|
23
|
+
ScreenOrientation[ScreenOrientation["Landscape"] = 2] = "Landscape";
|
24
|
+
return ScreenOrientation;
|
25
|
+
}({});
|
26
|
+
//# sourceMappingURL=common.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["CxxUnistylesEventTypes","exports","UnistylesError","ScreenOrientation"],"sourceRoot":"../../src","sources":["common.ts"],"mappings":";;;;;;IAAYA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAA,IAKtBE,cAAc,GAAAD,OAAA,CAAAC,cAAA,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA,OAS1B;AAAA,IACYC,iBAAiB,GAAAF,OAAA,CAAAE,iBAAA,0BAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA"}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.UnistyleRegistry = void 0;
|
7
|
+
class UnistyleRegistry {
|
8
|
+
config = {};
|
9
|
+
themeNames = [];
|
10
|
+
themes = {};
|
11
|
+
breakpoints = {};
|
12
|
+
sortedBreakpointPairs = [];
|
13
|
+
constructor(unistylesBridge) {
|
14
|
+
this.unistylesBridge = unistylesBridge;
|
15
|
+
}
|
16
|
+
addThemes = themes => {
|
17
|
+
this.themes = themes;
|
18
|
+
const keys = Object.keys(themes);
|
19
|
+
this.unistylesBridge.themes = keys;
|
20
|
+
this.themeNames = keys;
|
21
|
+
return this;
|
22
|
+
};
|
23
|
+
addBreakpoints = breakpoints => {
|
24
|
+
this.breakpoints = breakpoints;
|
25
|
+
this.unistylesBridge.useBreakpoints(breakpoints);
|
26
|
+
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
|
27
|
+
return this;
|
28
|
+
};
|
29
|
+
addConfig = config => {
|
30
|
+
this.config = config;
|
31
|
+
if (config.adaptiveThemes) {
|
32
|
+
this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes);
|
33
|
+
}
|
34
|
+
return this;
|
35
|
+
};
|
36
|
+
}
|
37
|
+
exports.UnistyleRegistry = UnistyleRegistry;
|
38
|
+
//# sourceMappingURL=UnistyleRegistry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistyleRegistry","config","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,UAAU,GAAiC,EAAE;EAC7CC,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;IAEpB,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACN,MAAM,CAAiC;IAEhE,IAAI,CAACI,eAAe,CAACJ,MAAM,GAAGM,IAAI;IAClC,IAAI,CAACP,UAAU,GAAGO,IAAI;IAEtB,OAAO,IAAI;EACf,CAAC;EAEME,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,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,GAAIZ,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACa,cAAc,EAAE;MACvB,IAAI,CAACP,eAAe,CAACQ,iBAAiB,CAACd,MAAM,CAACa,cAAc,CAAC;IACjE;IAEA,OAAO,IAAI;EACf,CAAC;AACL;AAACE,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1,31 @@
|
|
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 _UnistyleRegistry = require("./UnistyleRegistry");
|
10
|
+
var _common = require("../common");
|
11
|
+
class Unistyles {
|
12
|
+
constructor() {
|
13
|
+
const isInstalled = _UnistylesModule.UnistylesModule?.install() ?? false;
|
14
|
+
if (!isInstalled) {
|
15
|
+
throw new Error(_common.UnistylesError.RuntimeUnavailable);
|
16
|
+
}
|
17
|
+
|
18
|
+
// @ts-ignore
|
19
|
+
this._bridge = global.__UNISTYLES__;
|
20
|
+
this._registry = new _UnistyleRegistry.UnistyleRegistry(this._bridge);
|
21
|
+
this._runtime = new _UnistylesRuntime.UnistylesRuntime(this._bridge, this._registry);
|
22
|
+
}
|
23
|
+
get registry() {
|
24
|
+
return this._registry;
|
25
|
+
}
|
26
|
+
get runtime() {
|
27
|
+
return this._runtime;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
const unistyles = exports.unistyles = new Unistyles();
|
31
|
+
//# sourceMappingURL=Unistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_UnistylesModule","require","_UnistylesRuntime","_UnistyleRegistry","_common","Unistyles","constructor","isInstalled","UnistylesModule","install","Error","UnistylesError","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","UnistyleRegistry","_runtime","UnistylesRuntime","registry","runtime","unistyles","exports"],"sourceRoot":"../../../src","sources":["core/Unistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AAEA,MAAMI,SAAS,CAAC;EAKZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGC,gCAAe,EAAEC,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACF,WAAW,EAAE;MACd,MAAM,IAAIG,KAAK,CAACC,sBAAc,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;EACtE;EAEA,IAAWI,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACJ,SAAS;EACzB;EAEA,IAAWK,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACH,QAAQ;EACxB;AACJ;AAEO,MAAMI,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIjB,SAAS,CAAC,CAAC"}
|
@@ -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":["core/UnistylesModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMO,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,0BAAa,EAAEC,SAAkC"}
|