react-native-unistyles 3.0.0-alpha.7 → 3.0.0-alpha.9
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/common/Helpers.h +58 -0
- package/cxx/core/Unistyle.h +0 -6
- package/cxx/core/UnistyleData.h +3 -2
- package/cxx/core/UnistyleWrapper.h +6 -6
- package/cxx/core/UnistylesRegistry.cpp +11 -10
- package/cxx/core/UnistylesRegistry.h +4 -3
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -2
- package/cxx/parser/Parser.cpp +24 -78
- package/cxx/parser/Parser.h +1 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +33 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +70 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/package.json +1 -1
- package/plugin/__tests__/dependencies.spec.js +5 -5
- package/plugin/__tests__/ref.spec.js +132 -17
- package/plugin/__tests__/stylesheet.spec.js +9 -9
- package/plugin/index.js +12 -13
- package/plugin/ref.js +18 -14
- package/plugin/style.js +13 -7
- package/src/specs/ShadowRegistry/index.ts +4 -4
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /package/{web → src/web}/pseudo.ts +0 -0
package/cxx/common/Helpers.h
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <jsi/jsi.h>
|
4
|
+
#include <jsi/JSIDynamic.h>
|
5
|
+
#include <folly/dynamic.h>
|
4
6
|
#include <unordered_set>
|
5
7
|
|
6
8
|
using namespace facebook;
|
@@ -114,4 +116,60 @@ inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
|
|
114
116
|
return pairs;
|
115
117
|
}
|
116
118
|
|
119
|
+
inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array& arguments) {
|
120
|
+
std::vector<folly::dynamic> parsedArgument{};
|
121
|
+
size_t count = arguments.size(rt);
|
122
|
+
|
123
|
+
parsedArgument.reserve(count);
|
124
|
+
|
125
|
+
for (size_t i = 0; i < count; i++) {
|
126
|
+
jsi::Value arg = arguments.getValueAtIndex(rt, i);
|
127
|
+
|
128
|
+
if (arg.isBool()) {
|
129
|
+
parsedArgument.push_back(folly::dynamic(arg.asBool()));
|
130
|
+
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
|
134
|
+
if (arg.isNumber()) {
|
135
|
+
parsedArgument.push_back(folly::dynamic(arg.asNumber()));
|
136
|
+
|
137
|
+
continue;
|
138
|
+
}
|
139
|
+
|
140
|
+
if (arg.isString()) {
|
141
|
+
parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
|
142
|
+
|
143
|
+
continue;
|
144
|
+
}
|
145
|
+
|
146
|
+
if (arg.isUndefined()) {
|
147
|
+
parsedArgument.push_back(folly::dynamic());
|
148
|
+
|
149
|
+
continue;
|
150
|
+
}
|
151
|
+
|
152
|
+
if (arg.isNull()) {
|
153
|
+
parsedArgument.push_back(folly::dynamic(nullptr));
|
154
|
+
|
155
|
+
continue;
|
156
|
+
}
|
157
|
+
|
158
|
+
if (!arg.isObject()) {
|
159
|
+
continue;;
|
160
|
+
}
|
161
|
+
|
162
|
+
auto argObj = arg.asObject(rt);
|
163
|
+
|
164
|
+
// allow arrays and objects too
|
165
|
+
if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
|
166
|
+
parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
|
167
|
+
|
168
|
+
continue;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
return parsedArgument;
|
173
|
+
}
|
174
|
+
|
117
175
|
}
|
package/cxx/core/Unistyle.h
CHANGED
@@ -14,11 +14,6 @@ enum class UnistyleType {
|
|
14
14
|
DynamicFunction
|
15
15
|
};
|
16
16
|
|
17
|
-
struct DynamicFunctionMetadata {
|
18
|
-
size_t count;
|
19
|
-
std::vector<folly::dynamic> arguments;
|
20
|
-
};
|
21
|
-
|
22
17
|
struct Unistyle {
|
23
18
|
using Shared = std::shared_ptr<Unistyle>;
|
24
19
|
|
@@ -75,7 +70,6 @@ struct UnistyleDynamicFunction: public Unistyle {
|
|
75
70
|
|
76
71
|
std::optional<jsi::Object> unprocessedValue;
|
77
72
|
std::optional<jsi::Function> proxiedFunction = std::nullopt;
|
78
|
-
std::optional<DynamicFunctionMetadata> dynamicFunctionMetadata = std::nullopt;
|
79
73
|
};
|
80
74
|
|
81
75
|
}
|
package/cxx/core/UnistyleData.h
CHANGED
@@ -8,8 +8,8 @@ namespace margelo::nitro::unistyles::core {
|
|
8
8
|
using Variants = std::vector<std::pair<std::string, std::string>>;
|
9
9
|
|
10
10
|
struct UnistyleData {
|
11
|
-
UnistyleData(Unistyle::Shared unistyle, const Variants& variants)
|
12
|
-
: unistyle{unistyle}, variants(std::move(variants)) {}
|
11
|
+
UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments)
|
12
|
+
: unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)} {}
|
13
13
|
|
14
14
|
UnistyleData(const UnistyleData&) = delete;
|
15
15
|
UnistyleData(UnistyleData&& other): unistyle{other.unistyle}, variants(std::move(other.variants)) {}
|
@@ -17,6 +17,7 @@ struct UnistyleData {
|
|
17
17
|
core::Unistyle::Shared unistyle;
|
18
18
|
core::Variants variants;
|
19
19
|
std::optional<jsi::Object> parsedStyle = std::nullopt;
|
20
|
+
std::optional<std::vector<folly::dynamic>> dynamicFunctionMetadata = std::nullopt;
|
20
21
|
};
|
21
22
|
|
22
23
|
}
|
@@ -26,24 +26,24 @@ inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Va
|
|
26
26
|
|
27
27
|
inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
28
28
|
auto wrappedUnistyle = std::make_shared<UnistyleWrapper>(unistyle);
|
29
|
-
|
29
|
+
|
30
30
|
if (unistyle->type == UnistyleType::Object) {
|
31
31
|
jsi::Object obj = jsi::Object(rt);
|
32
|
-
|
32
|
+
|
33
33
|
obj.setNativeState(rt, std::move(wrappedUnistyle));
|
34
34
|
helpers::defineHiddenProperty(rt, obj, helpers::UNISTYLES_ID.c_str(), unistyle->styleKey);
|
35
|
-
|
35
|
+
|
36
36
|
helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
|
37
|
-
|
37
|
+
|
38
38
|
return obj;
|
39
39
|
}
|
40
|
-
|
40
|
+
|
41
41
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
42
42
|
auto hostFn = jsi::Value(rt, unistyleFn->proxiedFunction.value()).asObject(rt).asFunction(rt);
|
43
43
|
|
44
44
|
hostFn.setNativeState(rt, std::move(wrappedUnistyle));
|
45
45
|
hostFn.setProperty(rt, helpers::UNISTYLES_ID.c_str(), unistyleFn->styleKey);
|
46
|
-
|
46
|
+
|
47
47
|
return std::move(hostFn);
|
48
48
|
}
|
49
49
|
|
@@ -74,19 +74,20 @@ void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeNa
|
|
74
74
|
void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
75
75
|
const ShadowNodeFamily* shadowNodeFamily,
|
76
76
|
const core::Unistyle::Shared unistyle,
|
77
|
-
Variants& variants
|
77
|
+
Variants& variants,
|
78
|
+
std::vector<folly::dynamic>& arguments
|
78
79
|
) {
|
79
80
|
if (!this->_shadowRegistry.contains(shadowNodeFamily)) {
|
80
81
|
this->_shadowRegistry[shadowNodeFamily] = {};
|
81
82
|
}
|
82
83
|
|
83
|
-
this->_shadowRegistry[shadowNodeFamily].emplace_back(std::
|
84
|
+
this->_shadowRegistry[shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
|
84
85
|
}
|
85
86
|
|
86
87
|
void core::UnistylesRegistry::unlinkShadowNodeWithUnistyle(const ShadowNodeFamily* shadowNodeFamily, const core::Unistyle::Shared unistyle) {
|
87
88
|
auto& unistylesVec = this->_shadowRegistry[shadowNodeFamily];
|
88
|
-
auto it = std::find_if(unistylesVec.begin(), unistylesVec.end(), [unistyle](std::
|
89
|
-
return
|
89
|
+
auto it = std::find_if(unistylesVec.begin(), unistylesVec.end(), [unistyle](std::shared_ptr<UnistyleData> unistyleData){
|
90
|
+
return unistyleData->unistyle == unistyle;
|
90
91
|
});
|
91
92
|
|
92
93
|
if (it != unistylesVec.end()) {
|
@@ -124,12 +125,12 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
124
125
|
for (const auto& pair : this->_shadowRegistry) {
|
125
126
|
const auto& [family, unistyles] = pair;
|
126
127
|
|
127
|
-
for (const auto&
|
128
|
-
if (unistyle !=
|
128
|
+
for (const auto& unistyleData : unistyles) {
|
129
|
+
if (unistyle != unistyleData->unistyle) {
|
129
130
|
continue;
|
130
131
|
}
|
131
132
|
|
132
|
-
dependencyMap[styleSheet][family].emplace_back(
|
133
|
+
dependencyMap[styleSheet][family].emplace_back(unistyleData);
|
133
134
|
}
|
134
135
|
}
|
135
136
|
}
|
@@ -146,12 +147,12 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
146
147
|
for (const auto& pair : this->_shadowRegistry) {
|
147
148
|
const auto& [family, unistyles] = pair;
|
148
149
|
|
149
|
-
for (const auto&
|
150
|
-
if (unistyle !=
|
150
|
+
for (const auto& unistyleData : unistyles) {
|
151
|
+
if (unistyle != unistyleData->unistyle) {
|
151
152
|
continue;
|
152
153
|
}
|
153
154
|
|
154
|
-
dependencyMap[styleSheet][family].emplace_back(
|
155
|
+
dependencyMap[styleSheet][family].emplace_back(unistyleData);
|
155
156
|
}
|
156
157
|
}
|
157
158
|
}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
#include "set"
|
4
4
|
#include <jsi/jsi.h>
|
5
|
+
#include <folly/dynamic.h>
|
5
6
|
#include <react/renderer/uimanager/UIManager.h>
|
6
7
|
#include <unordered_map>
|
7
8
|
#include <unordered_set>
|
@@ -20,7 +21,7 @@ using namespace facebook::react;
|
|
20
21
|
|
21
22
|
using DependencyMap = std::unordered_map<
|
22
23
|
std::shared_ptr<core::StyleSheet>,
|
23
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<UnistyleData
|
24
|
+
std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>
|
24
25
|
>;
|
25
26
|
|
26
27
|
struct UnistylesRegistry: public StyleSheetRegistry {
|
@@ -37,7 +38,7 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
37
38
|
|
38
39
|
UnistylesState& getState(jsi::Runtime& rt);
|
39
40
|
void createState(jsi::Runtime& rt);
|
40
|
-
void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants);
|
41
|
+
void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants, std::vector<folly::dynamic>&);
|
41
42
|
void unlinkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared);
|
42
43
|
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
43
44
|
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
@@ -48,7 +49,7 @@ private:
|
|
48
49
|
|
49
50
|
std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
|
50
51
|
std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
|
51
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<std::
|
52
|
+
std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>> _shadowRegistry{};
|
52
53
|
};
|
53
54
|
|
54
55
|
UnistylesRegistry& UnistylesRegistry::get() {
|
@@ -4,15 +4,17 @@ using namespace margelo::nitro::unistyles;
|
|
4
4
|
using namespace facebook::react;
|
5
5
|
|
6
6
|
jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
7
|
-
helpers::assertThat(rt, count ==
|
7
|
+
helpers::assertThat(rt, count == 4, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 4 arguments.");
|
8
8
|
|
9
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
10
10
|
core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
|
11
11
|
core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
|
12
|
+
auto rawArguments = args[3].asObject(rt).asArray(rt);
|
13
|
+
std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
|
12
14
|
|
13
15
|
auto& registry = core::UnistylesRegistry::get();
|
14
16
|
|
15
|
-
registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants);
|
17
|
+
registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
|
16
18
|
|
17
19
|
return jsi::Value::undefined();
|
18
20
|
}
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -91,7 +91,8 @@ void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_
|
|
91
91
|
continue;
|
92
92
|
}
|
93
93
|
|
94
|
-
|
94
|
+
// todo skip dynamic functions
|
95
|
+
this->rebuildUnistyle(rt, styleSheet, unistyle, variants, std::nullopt);
|
95
96
|
}
|
96
97
|
}
|
97
98
|
|
@@ -101,22 +102,24 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
|
|
101
102
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
|
102
103
|
|
103
104
|
for (auto& [shadowNode, unistyles] : map) {
|
104
|
-
for (auto&
|
105
|
+
for (auto& unistyleData : unistyles) {
|
106
|
+
auto& unistyle = unistyleData->unistyle;
|
107
|
+
|
105
108
|
// StyleSheet might have styles that are not affected
|
106
109
|
if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
|
107
110
|
continue;
|
108
111
|
}
|
109
112
|
|
110
113
|
unistyle->rawValue = unwrappedStyleSheet.getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
|
111
|
-
this->rebuildUnistyle(rt, styleSheet, unistyle, variants);
|
112
|
-
parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
114
|
+
this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
|
115
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
113
116
|
}
|
114
117
|
}
|
115
118
|
}
|
116
119
|
}
|
117
120
|
|
118
121
|
// rebuild single unistyle
|
119
|
-
void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants) {
|
122
|
+
void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>> metadata) {
|
120
123
|
if (unistyle->type == core::UnistyleType::Object) {
|
121
124
|
auto result = this->parseFirstLevel(rt, unistyle, variants);
|
122
125
|
|
@@ -125,20 +128,17 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
125
128
|
|
126
129
|
// for functions we need to call memoized function
|
127
130
|
// with last know arguments and parse it with new theme and mini runtime
|
128
|
-
if (unistyle->type == core::UnistyleType::DynamicFunction) {
|
131
|
+
if (unistyle->type == core::UnistyleType::DynamicFunction && metadata.has_value()) {
|
129
132
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
130
|
-
auto maybeMetadata = unistyleFn->dynamicFunctionMetadata;
|
131
|
-
|
132
|
-
helpers::assertThat(rt, maybeMetadata.has_value(), "Unistyles: Your dynamic function '" + unistyleFn->styleKey + "' has no metadata and can't be processed.");
|
133
133
|
|
134
134
|
// convert arguments to jsi::Value
|
135
|
-
auto
|
135
|
+
auto dynamicFunctionMetadata = metadata.value();
|
136
136
|
std::vector<jsi::Value> args{};
|
137
137
|
|
138
|
-
args.reserve(
|
138
|
+
args.reserve(dynamicFunctionMetadata.size());
|
139
139
|
|
140
|
-
for (int i = 0; i <
|
141
|
-
folly::dynamic& arg =
|
140
|
+
for (int i = 0; i < dynamicFunctionMetadata.size(); i++) {
|
141
|
+
folly::dynamic& arg = dynamicFunctionMetadata.at(i);
|
142
142
|
|
143
143
|
args.emplace_back(jsi::valueFromDynamic(rt, arg));
|
144
144
|
}
|
@@ -146,7 +146,7 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
146
146
|
const jsi::Value *argStart = args.data();
|
147
147
|
|
148
148
|
// call cached function with memoized arguments
|
149
|
-
auto functionResult = unistyleFn->proxiedFunction.value().callAsConstructor(rt, argStart,
|
149
|
+
auto functionResult = unistyleFn->proxiedFunction.value().callAsConstructor(rt, argStart, dynamicFunctionMetadata.size()).asObject(rt);
|
150
150
|
|
151
151
|
unistyleFn->unprocessedValue = std::move(functionResult);
|
152
152
|
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
@@ -160,9 +160,9 @@ shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core:
|
|
160
160
|
|
161
161
|
for (const auto& [styleSheet, map] : dependencyMap) {
|
162
162
|
for (const auto& [shadowNode, unistyles] : map) {
|
163
|
-
for (const auto&
|
164
|
-
auto rawProps = this->parseStylesToShadowTreeStyles(rt, parsedStyle.value());
|
165
|
-
|
163
|
+
for (const auto& unistyleData : unistyles) {
|
164
|
+
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyleData->parsedStyle.value());
|
165
|
+
|
166
166
|
if (updates.contains(shadowNode)) {
|
167
167
|
updates[shadowNode].emplace_back(std::move(rawProps));
|
168
168
|
|
@@ -177,62 +177,6 @@ shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core:
|
|
177
177
|
return updates;
|
178
178
|
}
|
179
179
|
|
180
|
-
// convert jsi::Value arguments to folly::dynamic
|
181
|
-
std::vector<folly::dynamic> parser::Parser::parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments) {
|
182
|
-
std::vector<folly::dynamic> parsedArgument{};
|
183
|
-
|
184
|
-
parsedArgument.reserve(3);
|
185
|
-
|
186
|
-
for (size_t i = 0; i < count; i++) {
|
187
|
-
auto& arg = arguments[i];
|
188
|
-
|
189
|
-
if (arg.isBool()) {
|
190
|
-
parsedArgument.push_back(folly::dynamic(arg.asBool()));
|
191
|
-
|
192
|
-
continue;
|
193
|
-
}
|
194
|
-
|
195
|
-
if (arg.isNumber()) {
|
196
|
-
parsedArgument.push_back(folly::dynamic(arg.asNumber()));
|
197
|
-
|
198
|
-
continue;
|
199
|
-
}
|
200
|
-
|
201
|
-
if (arg.isString()) {
|
202
|
-
parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
|
203
|
-
|
204
|
-
continue;
|
205
|
-
}
|
206
|
-
|
207
|
-
if (arg.isUndefined()) {
|
208
|
-
parsedArgument.push_back(folly::dynamic());
|
209
|
-
|
210
|
-
continue;
|
211
|
-
}
|
212
|
-
|
213
|
-
if (arg.isNull()) {
|
214
|
-
parsedArgument.push_back(folly::dynamic(nullptr));
|
215
|
-
|
216
|
-
continue;
|
217
|
-
}
|
218
|
-
|
219
|
-
if (!arg.isObject()) {
|
220
|
-
continue;;
|
221
|
-
}
|
222
|
-
|
223
|
-
auto argObj = arg.asObject(rt);
|
224
|
-
|
225
|
-
// allow arrays and objects too
|
226
|
-
if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
|
227
|
-
parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
|
228
|
-
|
229
|
-
continue;
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
return parsedArgument;
|
234
|
-
}
|
235
|
-
|
236
180
|
// first level of StyleSheet, we can expect here different properties than on second level
|
237
181
|
// eg. variants, compoundVariants, mq, breakpoints etc.
|
238
182
|
jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants) {
|
@@ -352,13 +296,15 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
352
296
|
|
353
297
|
// memoize metadata to call it later
|
354
298
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
299
|
+
jsi::Array arguments = jsi::Array(rt, count);
|
355
300
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
};
|
301
|
+
for (size_t i = 0; i < count; i++) {
|
302
|
+
arguments.setValueAtIndex(rt, i, args[i]);
|
303
|
+
}
|
360
304
|
|
361
305
|
unistyleFn->unprocessedValue = jsi::Value(rt, result).asObject(rt);
|
306
|
+
|
307
|
+
// todo pass here variants
|
362
308
|
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, std::nullopt);
|
363
309
|
unistyleFn->seal();
|
364
310
|
|
@@ -532,7 +478,7 @@ jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, const std::stri
|
|
532
478
|
? selectedVariant.value().c_str()
|
533
479
|
: "default";
|
534
480
|
auto hasKey = groupValue.hasProperty(rt, selectedVariantKey);
|
535
|
-
|
481
|
+
|
536
482
|
if (hasKey && !selectedVariant.has_value()) {
|
537
483
|
// add 'default' selection to variants map
|
538
484
|
variants.emplace_back(groupName, selectedVariantKey);
|
package/cxx/parser/Parser.h
CHANGED
@@ -28,12 +28,11 @@ struct Parser {
|
|
28
28
|
shadow::ShadowLeafUpdates dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap);
|
29
29
|
|
30
30
|
private:
|
31
|
-
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants);
|
31
|
+
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>>);
|
32
32
|
jsi::Object unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
|
33
33
|
jsi::Object parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants);
|
34
34
|
jsi::Value parseSecondLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Value& nestedObject);
|
35
35
|
jsi::Function createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle);
|
36
|
-
std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments);
|
37
36
|
std::vector<UnistyleDependency> parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies);
|
38
37
|
jsi::Value parseTransforms(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
|
39
38
|
jsi::Value getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
|
@@ -14,11 +14,11 @@ const findShadowNodeForHandle = handle => {
|
|
14
14
|
}
|
15
15
|
return node;
|
16
16
|
};
|
17
|
-
HybridShadowRegistry.add = (handle, style, variants) => {
|
17
|
+
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
18
18
|
if (!handle || !style?.__unid) {
|
19
19
|
return;
|
20
20
|
}
|
21
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {});
|
21
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
|
22
22
|
};
|
23
23
|
HybridShadowRegistry.remove = (handle, style) => {
|
24
24
|
if (!handle || !style?.__unid) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","__unid","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,KAAK;
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","__unid","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAf,oBAAoB,CAACgB,IAAI,CAACb,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDd,oBAAoB,CAACiB,MAAM,GAAG,CAACb,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAf,oBAAoB,CAACkB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQM,MAAMO,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAGnB,oBAA4D","ignoreList":[]}
|
@@ -7,7 +7,7 @@ var _exportNames = {
|
|
7
7
|
getSSRUnistyles: true
|
8
8
|
};
|
9
9
|
exports.getSSRUnistyles = void 0;
|
10
|
-
var _web = require("
|
10
|
+
var _web = require("../web");
|
11
11
|
Object.keys(_web).forEach(function (key) {
|
12
12
|
if (key === "default" || key === "__esModule") return;
|
13
13
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getBoxShadowStyle = void 0;
|
7
|
+
var _typestyle = require("typestyle");
|
8
|
+
var _utils = require("../utils");
|
9
|
+
var _shadow = require("./shadow");
|
10
|
+
var _breakpoint = require("./breakpoint");
|
11
|
+
var _types = require("./types");
|
12
|
+
var _utils2 = require("./utils");
|
13
|
+
const createBoxShadowValue = style => {
|
14
|
+
// at this point every prop is present
|
15
|
+
const {
|
16
|
+
shadowColor,
|
17
|
+
shadowOffset,
|
18
|
+
shadowOpacity,
|
19
|
+
shadowRadius
|
20
|
+
} = style;
|
21
|
+
const offsetX = (0, _utils2.normalizeNumericValue)(shadowOffset.width);
|
22
|
+
const offsetY = (0, _utils2.normalizeNumericValue)(shadowOffset.height);
|
23
|
+
const radius = (0, _utils2.normalizeNumericValue)(shadowRadius);
|
24
|
+
const color = (0, _utils2.normalizeColor)(shadowColor, shadowOpacity);
|
25
|
+
return `${offsetX} ${offsetY} ${radius} ${color}`;
|
26
|
+
};
|
27
|
+
const getBoxShadowStyle = styles => {
|
28
|
+
const missingStyles = _types.BOX_SHADOW_STYLES.filter(key => !(key in styles));
|
29
|
+
if (missingStyles.length) {
|
30
|
+
(0, _utils.warn)(`can't apply box shadow as you miss these properties: ${missingStyles.join(', ')}`);
|
31
|
+
return {};
|
32
|
+
}
|
33
|
+
const breakpointsSet = new Set();
|
34
|
+
try {
|
35
|
+
(0, _shadow.validateShadow)(_types.BOX_SHADOW_STYLES, styles, breakpointsSet);
|
36
|
+
} catch (error) {
|
37
|
+
if (typeof error === 'string') {
|
38
|
+
(0, _utils.warn)(error);
|
39
|
+
}
|
40
|
+
return {};
|
41
|
+
}
|
42
|
+
const breakpoints = Array.from(breakpointsSet);
|
43
|
+
|
44
|
+
// If no breakpoints were used return styles without media queries
|
45
|
+
if (breakpoints.length === 0) {
|
46
|
+
return {
|
47
|
+
boxShadow: createBoxShadowValue(styles)
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
51
|
+
// Create boxShadow for each breakpoint
|
52
|
+
const breakpointStyles = breakpoints.map(breakpoint => {
|
53
|
+
const color = (0, _utils2.extractShadowValue)('shadowColor', breakpoint, styles);
|
54
|
+
const {
|
55
|
+
width,
|
56
|
+
height
|
57
|
+
} = (0, _utils2.extractShadowValue)('shadowOffset', breakpoint, styles);
|
58
|
+
const radius = (0, _utils2.extractShadowValue)('shadowRadius', breakpoint, styles);
|
59
|
+
const opacity = (0, _utils2.extractShadowValue)('shadowOpacity', breakpoint, styles);
|
60
|
+
return (0, _typestyle.media)((0, _breakpoint.convertBreakpoint)(breakpoint), {
|
61
|
+
boxShadow: createBoxShadowValue({
|
62
|
+
shadowColor: color,
|
63
|
+
shadowOffset: {
|
64
|
+
width,
|
65
|
+
height
|
66
|
+
},
|
67
|
+
shadowRadius: radius,
|
68
|
+
shadowOpacity: opacity
|
69
|
+
})
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
// Merge all breakpoints styles into one
|
74
|
+
return (0, _utils.deepMergeObjects)(...breakpointStyles);
|
75
|
+
};
|
76
|
+
exports.getBoxShadowStyle = getBoxShadowStyle;
|
77
|
+
//# sourceMappingURL=boxShadow.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_typestyle","require","_utils","_shadow","_breakpoint","_types","_utils2","createBoxShadowValue","style","shadowColor","shadowOffset","shadowOpacity","shadowRadius","offsetX","normalizeNumericValue","width","offsetY","height","radius","color","normalizeColor","getBoxShadowStyle","styles","missingStyles","BOX_SHADOW_STYLES","filter","key","length","warn","join","breakpointsSet","Set","validateShadow","error","breakpoints","Array","from","boxShadow","breakpointStyles","map","breakpoint","extractShadowValue","opacity","media","convertBreakpoint","deepMergeObjects","exports"],"sourceRoot":"../../../../src","sources":["web/convert/boxShadow.ts"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA,MAAMM,oBAAoB,GAAIC,KAAgB,IAAK;EAC/C;EACA,MAAM;IAAEC,WAAW;IAAEC,YAAY;IAAEC,aAAa;IAAEC;EAAa,CAAC,GAAGJ,KAAK;EACxE,MAAMK,OAAO,GAAG,IAAAC,6BAAqB,EAACJ,YAAY,CAACK,KAAK,CAAC;EACzD,MAAMC,OAAO,GAAG,IAAAF,6BAAqB,EAACJ,YAAY,CAACO,MAAM,CAAC;EAC1D,MAAMC,MAAM,GAAG,IAAAJ,6BAAqB,EAACF,YAAY,CAAC;EAClD,MAAMO,KAAK,GAAG,IAAAC,sBAAc,EAACX,WAAW,EAAYE,aAAuB,CAAC;EAE5E,OAAO,GAAGE,OAAO,IAAIG,OAAO,IAAIE,MAAM,IAAIC,KAAK,EAAE;AACrD,CAAC;AAEM,MAAME,iBAAiB,GAAIC,MAA2B,IAA0B;EACnF,MAAMC,aAAa,GAAGC,wBAAiB,CAACC,MAAM,CAACC,GAAG,IAAI,EAAEA,GAAG,IAAIJ,MAAM,CAAC,CAAC;EAEvE,IAAIC,aAAa,CAACI,MAAM,EAAE;IACtB,IAAAC,WAAI,EAAC,wDAAwDL,aAAa,CAACM,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAExF,OAAO,CAAC,CAAC;EACb;EAEA,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAAS,CAAC;EAExC,IAAI;IACA,IAAAC,sBAAc,EAACR,wBAAiB,EAAEF,MAAM,EAAEQ,cAAc,CAAC;EAC7D,CAAC,CAAC,OAAOG,KAAK,EAAE;IACZ,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC3B,IAAAL,WAAI,EAACK,KAAK,CAAC;IACf;IAEA,OAAO,CAAC,CAAC;EACb;EAEA,MAAMC,WAAW,GAAGC,KAAK,CAACC,IAAI,CAACN,cAAc,CAAC;;EAE9C;EACA,IAAII,WAAW,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAO;MACHU,SAAS,EAAE9B,oBAAoB,CAACe,MAAmB;IACvD,CAAC;EACL;;EAEA;EACA,MAAMgB,gBAAgB,GAAGJ,WAAW,CAACK,GAAG,CAACC,UAAU,IAAI;IACnD,MAAMrB,KAAK,GAAG,IAAAsB,0BAAkB,EAAC,aAAa,EAAED,UAAU,EAAElB,MAAM,CAAC;IACnE,MAAM;MAAEP,KAAK;MAAEE;IAAO,CAAC,GAAG,IAAAwB,0BAAkB,EAAC,cAAc,EAAED,UAAU,EAAElB,MAAM,CAAC;IAChF,MAAMJ,MAAM,GAAG,IAAAuB,0BAAkB,EAAC,cAAc,EAAED,UAAU,EAAElB,MAAM,CAAC;IACrE,MAAMoB,OAAO,GAAG,IAAAD,0BAAkB,EAAC,eAAe,EAAED,UAAU,EAAElB,MAAM,CAAC;IAEvE,OAAO,IAAAqB,gBAAK,EAAC,IAAAC,6BAAiB,EAACJ,UAAU,CAAC,EAAE;MACxCH,SAAS,EAAE9B,oBAAoB,CAAC;QAC5BE,WAAW,EAAEU,KAAK;QAClBT,YAAY,EAAE;UACVK,KAAK;UACLE;QACJ,CAAC;QACDL,YAAY,EAAEM,MAAM;QACpBP,aAAa,EAAE+B;MACnB,CAAC;IACL,CAAC,CAAC;EACN,CAAC,CAAC;;EAEF;EACA,OAAO,IAAAG,uBAAgB,EAAC,GAAGP,gBAAgB,CAAC;AAChD,CAAC;AAAAQ,OAAA,CAAAzB,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.convertBreakpoint = void 0;
|
7
|
+
var _state = require("../state");
|
8
|
+
var _utils = require("../utils");
|
9
|
+
var _mq = require("../mq");
|
10
|
+
var _types = require("../../specs/types");
|
11
|
+
const convertBreakpoint = breakpoint => {
|
12
|
+
if (Object.values(_types.Orientation).includes(breakpoint)) {
|
13
|
+
return {
|
14
|
+
orientation: breakpoint
|
15
|
+
};
|
16
|
+
}
|
17
|
+
if ((0, _mq.isUnistylesMq)(breakpoint)) {
|
18
|
+
return (0, _mq.parseMq)(breakpoint);
|
19
|
+
}
|
20
|
+
return {
|
21
|
+
minWidth: _state.UnistylesState.breakpoints && (0, _utils.keyInObject)(_state.UnistylesState.breakpoints, breakpoint) ? _state.UnistylesState.breakpoints[breakpoint] : undefined
|
22
|
+
};
|
23
|
+
};
|
24
|
+
exports.convertBreakpoint = convertBreakpoint;
|
25
|
+
//# sourceMappingURL=breakpoint.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_state","require","_utils","_mq","_types","convertBreakpoint","breakpoint","Object","values","Orientation","includes","orientation","isUnistylesMq","parseMq","minWidth","UnistylesState","breakpoints","keyInObject","undefined","exports"],"sourceRoot":"../../../../src","sources":["web/convert/breakpoint.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,iBAAiB,GAAIC,UAAkB,IAAiB;EACjE,IAAIC,MAAM,CAACC,MAAM,CAACC,kBAAW,CAAC,CAACC,QAAQ,CAACJ,UAAyB,CAAC,EAAE;IAChE,OAAO;MACHK,WAAW,EAAEL;IACjB,CAAC;EACL;EAEA,IAAI,IAAAM,iBAAa,EAACN,UAAU,CAAC,EAAE;IAC3B,OAAO,IAAAO,WAAO,EAACP,UAAU,CAAC;EAC9B;EAEA,OAAO;IACHQ,QAAQ,EAAEC,qBAAc,CAACC,WAAW,IAAI,IAAAC,kBAAW,EAACF,qBAAc,CAACC,WAAW,EAAEV,UAAU,CAAC,GAAGS,qBAAc,CAACC,WAAW,CAACV,UAAU,CAAC,GAAGY;EAC3I,CAAC;AACL,CAAC;AAAAC,OAAA,CAAAd,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|