zyzz 0.0.21 → 0.0.22

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.
Files changed (220) hide show
  1. package/Zyzz.podspec +16 -0
  2. package/dist/Style.d.ts +3 -1
  3. package/dist/Style.d.ts.map +1 -1
  4. package/dist/Style.js.map +1 -1
  5. package/dist/babel/NativeJsx.d.ts.map +1 -1
  6. package/dist/babel/NativeJsx.js +204 -12
  7. package/dist/babel/NativeJsx.js.map +1 -1
  8. package/dist/babel/index.d.ts +6 -2
  9. package/dist/babel/index.d.ts.map +1 -1
  10. package/dist/babel/index.js +10 -1
  11. package/dist/babel/index.js.map +1 -1
  12. package/dist/compiler/Graph.d.ts.map +1 -1
  13. package/dist/compiler/Graph.js +64 -0
  14. package/dist/compiler/Graph.js.map +1 -1
  15. package/dist/compiler/Native.d.ts +6 -3
  16. package/dist/compiler/Native.d.ts.map +1 -1
  17. package/dist/compiler/Native.js +142 -24
  18. package/dist/compiler/Native.js.map +1 -1
  19. package/dist/compiler/Source.d.ts +2 -0
  20. package/dist/compiler/Source.d.ts.map +1 -1
  21. package/dist/compiler/Source.js +17 -5
  22. package/dist/compiler/Source.js.map +1 -1
  23. package/dist/compiler/internal/Configurations.d.ts +2 -0
  24. package/dist/compiler/internal/Configurations.d.ts.map +1 -1
  25. package/dist/compiler/internal/Configurations.js +21 -3
  26. package/dist/compiler/internal/Configurations.js.map +1 -1
  27. package/dist/compiler/internal/Contract.d.ts.map +1 -1
  28. package/dist/compiler/internal/Contract.js +75 -38
  29. package/dist/compiler/internal/Contract.js.map +1 -1
  30. package/dist/compiler/internal/Contributions.d.ts.map +1 -1
  31. package/dist/compiler/internal/Contributions.js +7 -1
  32. package/dist/compiler/internal/Contributions.js.map +1 -1
  33. package/dist/compiler/internal/Descriptors.d.ts.map +1 -1
  34. package/dist/compiler/internal/Descriptors.js +11 -2
  35. package/dist/compiler/internal/Descriptors.js.map +1 -1
  36. package/dist/compiler/internal/NativeBindings.d.ts +24 -26
  37. package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
  38. package/dist/compiler/internal/NativeBindings.js +61 -8
  39. package/dist/compiler/internal/NativeBindings.js.map +1 -1
  40. package/dist/compiler/internal/NativeMedia.d.ts +14 -0
  41. package/dist/compiler/internal/NativeMedia.d.ts.map +1 -0
  42. package/dist/compiler/internal/NativeMedia.js +287 -0
  43. package/dist/compiler/internal/NativeMedia.js.map +1 -0
  44. package/dist/compiler/internal/NativeVars.d.ts +28 -0
  45. package/dist/compiler/internal/NativeVars.d.ts.map +1 -0
  46. package/dist/compiler/internal/NativeVars.js +157 -0
  47. package/dist/compiler/internal/NativeVars.js.map +1 -0
  48. package/dist/compiler/internal/PackedStyles.d.ts +2 -0
  49. package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
  50. package/dist/compiler/internal/PackedStyles.js +2 -0
  51. package/dist/compiler/internal/PackedStyles.js.map +1 -1
  52. package/dist/compiler/internal/Themes.d.ts +22 -1
  53. package/dist/compiler/internal/Themes.d.ts.map +1 -1
  54. package/dist/compiler/internal/Themes.js +118 -3
  55. package/dist/compiler/internal/Themes.js.map +1 -1
  56. package/dist/compiler/internal/Vars.d.ts +1 -1
  57. package/dist/compiler/internal/Vars.d.ts.map +1 -1
  58. package/dist/compiler/internal/Vars.js +7 -2
  59. package/dist/compiler/internal/Vars.js.map +1 -1
  60. package/dist/default.js.zyzz.json +1 -1
  61. package/dist/internal/Completion.d.ts +1 -1
  62. package/dist/internal/Completion.d.ts.map +1 -1
  63. package/dist/internal/Targets.d.ts.map +1 -1
  64. package/dist/internal/Targets.js +2 -0
  65. package/dist/internal/Targets.js.map +1 -1
  66. package/dist/internal/Token.d.ts +0 -2
  67. package/dist/internal/Token.d.ts.map +1 -1
  68. package/dist/internal/Token.js.map +1 -1
  69. package/dist/internal/Value.d.ts +7 -0
  70. package/dist/internal/Value.d.ts.map +1 -1
  71. package/dist/internal/Value.js.map +1 -1
  72. package/dist/metro/Graph.d.ts +22 -7
  73. package/dist/metro/Graph.d.ts.map +1 -1
  74. package/dist/metro/Graph.js +179 -42
  75. package/dist/metro/Graph.js.map +1 -1
  76. package/dist/metro/Watch.d.ts +28 -4
  77. package/dist/metro/Watch.d.ts.map +1 -1
  78. package/dist/metro/Watch.js +39 -7
  79. package/dist/metro/Watch.js.map +1 -1
  80. package/dist/metro/index.d.ts +15 -4
  81. package/dist/metro/index.d.ts.map +1 -1
  82. package/dist/metro/index.js +27 -0
  83. package/dist/metro/index.js.map +1 -1
  84. package/dist/metro/transformer.d.ts +5 -1
  85. package/dist/metro/transformer.d.ts.map +1 -1
  86. package/dist/metro/transformer.js +5 -3
  87. package/dist/metro/transformer.js.map +1 -1
  88. package/dist/react-native/StyleSheet.d.ts +3 -2
  89. package/dist/react-native/StyleSheet.d.ts.map +1 -1
  90. package/dist/react-native/StyleSheet.js +17 -34
  91. package/dist/react-native/StyleSheet.js.map +1 -1
  92. package/dist/react-native/index.d.ts +1 -1
  93. package/dist/react-native/index.d.ts.map +1 -1
  94. package/dist/react-native/index.js +1 -1
  95. package/dist/react-native/index.js.map +1 -1
  96. package/dist/react-native/index.native.d.ts +5 -0
  97. package/dist/react-native/index.native.js +20 -0
  98. package/dist/react-native/index.native.js.map +7 -0
  99. package/dist/react-native/internal/Calculation.d.ts +7 -0
  100. package/dist/react-native/internal/Calculation.d.ts.map +1 -0
  101. package/dist/react-native/internal/Calculation.js +134 -0
  102. package/dist/react-native/internal/Calculation.js.map +1 -0
  103. package/dist/react-native/internal/Device.js +191 -0
  104. package/dist/react-native/internal/Device.js.map +7 -0
  105. package/dist/react-native/internal/NativeZyzz.js +7 -0
  106. package/dist/react-native/internal/NativeZyzz.js.map +7 -0
  107. package/dist/react-native/internal/Scalar.d.ts.map +1 -1
  108. package/dist/react-native/internal/Scalar.js +9 -2
  109. package/dist/react-native/internal/Scalar.js.map +1 -1
  110. package/dist/react-native/internal/Store.d.ts +32 -0
  111. package/dist/react-native/internal/Store.d.ts.map +1 -0
  112. package/dist/react-native/internal/Store.js +57 -0
  113. package/dist/react-native/internal/Store.js.map +1 -0
  114. package/dist/react-native/internal/Tokens.d.ts +21 -0
  115. package/dist/react-native/internal/Tokens.d.ts.map +1 -0
  116. package/dist/react-native/internal/Tokens.js +58 -0
  117. package/dist/react-native/internal/Tokens.js.map +1 -0
  118. package/dist/react-native/internal/Viewport.d.ts +6 -0
  119. package/dist/react-native/internal/Viewport.d.ts.map +1 -0
  120. package/dist/react-native/internal/Viewport.js +4 -0
  121. package/dist/react-native/internal/Viewport.js.map +1 -0
  122. package/dist/react-native/react.d.ts +74 -11
  123. package/dist/react-native/react.d.ts.map +1 -1
  124. package/dist/react-native/react.js +111 -12
  125. package/dist/react-native/react.js.map +1 -1
  126. package/dist/react-native/reanimated.d.ts +39 -0
  127. package/dist/react-native/reanimated.d.ts.map +1 -0
  128. package/dist/react-native/reanimated.js +76 -0
  129. package/dist/react-native/reanimated.js.map +1 -0
  130. package/dist/runtime/NativeContext.d.ts +10 -1
  131. package/dist/runtime/NativeContext.d.ts.map +1 -1
  132. package/dist/runtime/NativeContext.js +67 -14
  133. package/dist/runtime/NativeContext.js.map +1 -1
  134. package/dist/runtime/NativeDynamic.d.ts +3 -2
  135. package/dist/runtime/NativeDynamic.d.ts.map +1 -1
  136. package/dist/runtime/NativeDynamic.js +32 -7
  137. package/dist/runtime/NativeDynamic.js.map +1 -1
  138. package/dist/runtime/NativeStatic.d.ts +23 -0
  139. package/dist/runtime/NativeStatic.d.ts.map +1 -0
  140. package/dist/runtime/NativeStatic.js +106 -0
  141. package/dist/runtime/NativeStatic.js.map +1 -0
  142. package/dist/runtime/NativeVars.d.ts +53 -0
  143. package/dist/runtime/NativeVars.d.ts.map +1 -0
  144. package/dist/runtime/NativeVars.js +77 -0
  145. package/dist/runtime/NativeVars.js.map +1 -0
  146. package/dist/runtime/index.d.ts +4 -0
  147. package/dist/runtime/index.d.ts.map +1 -1
  148. package/dist/runtime/index.js +4 -0
  149. package/dist/runtime/index.js.map +1 -1
  150. package/dist/runtime/internal/NativeMedia.d.ts +25 -0
  151. package/dist/runtime/internal/NativeMedia.d.ts.map +1 -0
  152. package/dist/runtime/internal/NativeMedia.js +36 -0
  153. package/dist/runtime/internal/NativeMedia.js.map +1 -0
  154. package/dist/vite/index.d.ts.map +1 -1
  155. package/dist/vite/index.js +7 -35
  156. package/dist/vite/index.js.map +1 -1
  157. package/dist/web/Css.d.ts.map +1 -1
  158. package/dist/web/Css.js +31 -19
  159. package/dist/web/Css.js.map +1 -1
  160. package/dist/web/internal/Themes.d.ts +0 -2
  161. package/dist/web/internal/Themes.d.ts.map +1 -1
  162. package/dist/web/internal/Themes.js +30 -28
  163. package/dist/web/internal/Themes.js.map +1 -1
  164. package/dist/web/page.d.ts +2 -0
  165. package/dist/web/page.d.ts.map +1 -1
  166. package/native/NativeZyzz.cpp +215 -0
  167. package/native/NativeZyzz.h +52 -0
  168. package/native/ZyzzSpecJSI.h +65 -0
  169. package/native/android/CMakeLists.txt +8 -0
  170. package/native/android/ZyzzSpec-generated.cpp +50 -0
  171. package/native/android/ZyzzSpec.h +31 -0
  172. package/native/ios/ZyzzModuleProvider.mm +13 -0
  173. package/package.json +39 -1
  174. package/react-native.config.ts +14 -0
  175. package/src/Style.ts +11 -8
  176. package/src/babel/NativeJsx.ts +305 -28
  177. package/src/babel/index.ts +21 -3
  178. package/src/compiler/Graph.ts +75 -0
  179. package/src/compiler/Native.ts +158 -26
  180. package/src/compiler/Source.ts +32 -5
  181. package/src/compiler/internal/Configurations.ts +25 -3
  182. package/src/compiler/internal/Contract.ts +98 -50
  183. package/src/compiler/internal/Contributions.ts +7 -1
  184. package/src/compiler/internal/Descriptors.ts +12 -8
  185. package/src/compiler/internal/NativeBindings.ts +98 -15
  186. package/src/compiler/internal/NativeMedia.ts +342 -0
  187. package/src/compiler/internal/NativeVars.ts +228 -0
  188. package/src/compiler/internal/PackedStyles.ts +4 -0
  189. package/src/compiler/internal/Themes.ts +187 -2
  190. package/src/compiler/internal/Vars.ts +12 -1
  191. package/src/internal/Completion.ts +6 -3
  192. package/src/internal/Targets.ts +2 -0
  193. package/src/internal/Token.ts +0 -2
  194. package/src/internal/Value.ts +20 -0
  195. package/src/metro/Graph.ts +235 -50
  196. package/src/metro/Watch.ts +95 -10
  197. package/src/metro/index.ts +62 -4
  198. package/src/metro/transformer.ts +21 -11
  199. package/src/react-native/StyleSheet.ts +28 -44
  200. package/src/react-native/index.native.ts +10 -0
  201. package/src/react-native/index.ts +1 -1
  202. package/src/react-native/internal/Calculation.ts +159 -0
  203. package/src/react-native/internal/Device.ts +231 -0
  204. package/src/react-native/internal/NativeZyzz.ts +20 -0
  205. package/src/react-native/internal/Scalar.ts +13 -2
  206. package/src/react-native/internal/Store.ts +78 -0
  207. package/src/react-native/internal/Tokens.ts +85 -0
  208. package/src/react-native/internal/Viewport.ts +8 -0
  209. package/src/react-native/react.ts +211 -19
  210. package/src/react-native/reanimated.ts +162 -0
  211. package/src/runtime/NativeContext.ts +88 -17
  212. package/src/runtime/NativeDynamic.ts +35 -10
  213. package/src/runtime/NativeStatic.ts +145 -0
  214. package/src/runtime/NativeVars.ts +189 -0
  215. package/src/runtime/index.ts +6 -0
  216. package/src/runtime/internal/NativeMedia.ts +63 -0
  217. package/src/vite/index.ts +9 -42
  218. package/src/web/Css.ts +42 -27
  219. package/src/web/internal/Themes.ts +34 -57
  220. package/src/web/page.ts +2 -0
@@ -0,0 +1,215 @@
1
+ /** Applies scoped style changes and preserves them through Fabric commits. */
2
+ #include "NativeZyzz.h"
3
+ #include <functional>
4
+ #include <unordered_set>
5
+ #include <jsi/JSIDynamic.h>
6
+ #include <react/renderer/bridging/bridging.h>
7
+ #include <react/renderer/core/PropsParserContext.h>
8
+ #include <react/renderer/mounting/ShadowTree.h>
9
+ #include <react/renderer/mounting/ShadowTreeRegistry.h>
10
+
11
+ namespace facebook::react {
12
+
13
+ thread_local const NativeZyzz *NativeZyzz::writing_ = nullptr;
14
+
15
+ NativeZyzz::NativeZyzz(std::shared_ptr<CallInvoker> invoker)
16
+ : NativeZyzzCxxSpec(std::move(invoker)) {}
17
+
18
+ NativeZyzz::~NativeZyzz() {
19
+ if (manager_) manager_->unregisterCommitHook(*this);
20
+ }
21
+
22
+ double NativeZyzz::attach(jsi::Runtime &runtime, jsi::Object node, jsi::Object props) {
23
+ auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(
24
+ runtime, jsi::Value(runtime, node));
25
+ auto values = jsi::dynamicFromValue(runtime, jsi::Value(runtime, props));
26
+ if (!values.isObject()) throw jsi::JSError(runtime, "Native styles must be an object.");
27
+
28
+ if (!binding_) {
29
+ binding_ = UIManagerBinding::getBinding(runtime);
30
+ if (!binding_) throw jsi::JSError(runtime, "Zyzz requires Fabric.");
31
+ manager_ = &binding_->getUIManager();
32
+ manager_->registerCommitHook(*this);
33
+ }
34
+
35
+ double id;
36
+ {
37
+ std::lock_guard<std::mutex> lock(mutex_);
38
+ id = ++nextId_;
39
+ entries_.emplace(id, Entry{shadowNode->getFamilyShared(), values, values,
40
+ folly::dynamic::object(), shadowNode->getProps(), nullptr});
41
+ }
42
+ // A React commit can restore its earlier rendered props before the ref relinks.
43
+ write({{shadowNode->getTag(), std::move(values)}});
44
+ return id;
45
+ }
46
+
47
+ void NativeZyzz::detach(jsi::Runtime &, double id) {
48
+ std::shared_ptr<ShadowNodeFamily> family;
49
+ Props::Shared authored;
50
+ {
51
+ std::lock_guard<std::mutex> lock(mutex_);
52
+ const auto entry = entries_.find(id);
53
+ if (entry == entries_.end()) return;
54
+ if (!entry->second.overlay.empty()) {
55
+ family = entry->second.family.lock();
56
+ authored = entry->second.authored;
57
+ }
58
+ entries_.erase(entry);
59
+ }
60
+ if (!family || !authored) return;
61
+ // The React commit has already passed through the overlay hook when an old
62
+ // ref is detached. Restore that commit's authored props, not the old style.
63
+ manager_->getShadowTreeRegistry().visit(family->getSurfaceId(), [&](const ShadowTree &tree) {
64
+ tree.commit([&](const RootShadowNode &root) {
65
+ return std::static_pointer_cast<RootShadowNode>(root.cloneTree(*family,
66
+ [&](const ShadowNode &node) { return node.clone({.props = authored}); }));
67
+ }, {.mountSynchronously = true});
68
+ });
69
+ }
70
+
71
+ jsi::Object NativeZyzz::inspect(jsi::Runtime &runtime) {
72
+ std::lock_guard<std::mutex> lock(mutex_);
73
+ jsi::Object result(runtime);
74
+ result.setProperty(runtime, "batches", batches_);
75
+ result.setProperty(runtime, "bindings", static_cast<double>(entries_.size()));
76
+ result.setProperty(runtime, "writes", writes_);
77
+ return result;
78
+ }
79
+
80
+ void NativeZyzz::update(jsi::Runtime &runtime, std::vector<jsi::Object> updates) {
81
+ std::vector<std::pair<double, folly::dynamic>> selections;
82
+ for (const auto &update : updates) {
83
+ auto id = update.getProperty(runtime, "id").asNumber();
84
+ auto props = jsi::dynamicFromValue(runtime, update.getProperty(runtime, "props"));
85
+ if (!props.isObject()) throw jsi::JSError(runtime, "Native styles must be an object.");
86
+ selections.emplace_back(id, std::move(props));
87
+ }
88
+
89
+ std::unordered_map<Tag, folly::dynamic> patches;
90
+ {
91
+ std::lock_guard<std::mutex> lock(mutex_);
92
+ for (auto &[id, selected] : selections) {
93
+ auto entry = entries_.find(id);
94
+ if (entry == entries_.end()) continue;
95
+ auto family = entry->second.family.lock();
96
+ if (!family) {
97
+ entries_.erase(entry);
98
+ continue;
99
+ }
100
+ if (selected == entry->second.selected) continue;
101
+
102
+ folly::dynamic overlay = folly::dynamic::object();
103
+ for (const auto &item : selected.items()) {
104
+ auto rendered = entry->second.rendered.find(item.first);
105
+ if (rendered == entry->second.rendered.items().end() ||
106
+ rendered->second != item.second)
107
+ overlay[item.first] = item.second;
108
+ }
109
+ for (const auto &item : entry->second.rendered.items())
110
+ if (selected.find(item.first) == selected.items().end()) overlay[item.first] = nullptr;
111
+
112
+ auto patch = selected;
113
+ for (const auto &item : entry->second.selected.items())
114
+ if (selected.find(item.first) == selected.items().end()) patch[item.first] = nullptr;
115
+
116
+ entry->second.overlay = std::move(overlay);
117
+ entry->second.selected = std::move(selected);
118
+ patches.insert_or_assign(family->getTag(), std::move(patch));
119
+ }
120
+ if (patches.empty()) return;
121
+ ++batches_;
122
+ writes_ += patches.size();
123
+ }
124
+ write(std::move(patches));
125
+ }
126
+
127
+ void NativeZyzz::write(std::unordered_map<Tag, folly::dynamic> patches) {
128
+ const auto previous = writing_;
129
+ writing_ = this;
130
+ try {
131
+ manager_->updateShadowTree(std::move(patches));
132
+ } catch (...) {
133
+ writing_ = previous;
134
+ throw;
135
+ }
136
+ writing_ = previous;
137
+ }
138
+
139
+ std::shared_ptr<RootShadowNode> NativeZyzz::shadowTreeWillCommit(
140
+ const ShadowTree &tree,
141
+ const std::shared_ptr<const RootShadowNode> &,
142
+ const std::shared_ptr<RootShadowNode> &next) noexcept {
143
+ struct Overlay {
144
+ std::shared_ptr<ShadowNodeFamily> family;
145
+ folly::dynamic props;
146
+ double id;
147
+ };
148
+ std::unordered_map<const ShadowNodeFamily *, Overlay> overlays;
149
+ {
150
+ std::lock_guard<std::mutex> lock(mutex_);
151
+ for (auto entry = entries_.begin(); entry != entries_.end();) {
152
+ auto family = entry->second.family.lock();
153
+ if (!family) {
154
+ entry = entries_.erase(entry);
155
+ continue;
156
+ }
157
+ if (family->getSurfaceId() == tree.getSurfaceId() &&
158
+ !entry->second.overlay.empty())
159
+ overlays.emplace(family.get(), Overlay{family, entry->second.overlay, entry->first});
160
+ ++entry;
161
+ }
162
+ }
163
+ if (overlays.empty()) return next;
164
+
165
+ std::unordered_set<const ShadowNodeFamily *> paths;
166
+ for (const auto &[family, overlay] : overlays) {
167
+ paths.insert(family);
168
+ for (const auto &[ancestor, index] : overlay.family->getAncestors(*next))
169
+ paths.insert(&ancestor.get().getFamily());
170
+ }
171
+
172
+ PropsParserContext context{tree.getSurfaceId(),
173
+ *manager_->getContextContainer()};
174
+ std::function<std::shared_ptr<const ShadowNode>(
175
+ const std::shared_ptr<const ShadowNode> &)> visit =
176
+ [&](const std::shared_ptr<const ShadowNode> &node) {
177
+ if (paths.find(&node->getFamily()) == paths.end()) return node;
178
+
179
+ std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> children;
180
+ const auto &current = node->getChildren();
181
+ for (size_t index = 0; index < current.size(); ++index) {
182
+ auto child = visit(current[index]);
183
+ if (child == current[index]) continue;
184
+ if (!children)
185
+ children = std::make_shared<
186
+ std::vector<std::shared_ptr<const ShadowNode>>>(current);
187
+ (*children)[index] = std::move(child);
188
+ }
189
+
190
+ const auto overlay = overlays.find(&node->getFamily());
191
+ if (!children && overlay == overlays.end()) return node;
192
+ auto props = overlay == overlays.end()
193
+ ? node->getProps()
194
+ : node->getComponentDescriptor().cloneProps(
195
+ context, node->getProps(), RawProps(overlay->second.props));
196
+ if (overlay != overlays.end()) {
197
+ std::lock_guard<std::mutex> lock(mutex_);
198
+ const auto entry = entries_.find(overlay->second.id);
199
+ if (entry != entries_.end()) {
200
+ // Skip our own native patches and nodes reused from an earlier overlay.
201
+ if (writing_ != this && node->getProps() != entry->second.applied)
202
+ entry->second.authored = node->getProps();
203
+ entry->second.applied = props;
204
+ }
205
+ }
206
+ return std::shared_ptr<const ShadowNode>(node->clone({
207
+ .props = props,
208
+ .children = children ? children : ShadowNodeFragment::childrenPlaceholder(),
209
+ }));
210
+ };
211
+ return std::const_pointer_cast<RootShadowNode>(
212
+ std::static_pointer_cast<const RootShadowNode>(visit(next)));
213
+ }
214
+
215
+ }
@@ -0,0 +1,52 @@
1
+ /** Owns Fabric style overlays for one React Native runtime. */
2
+ #pragma once
3
+
4
+ #include "ZyzzSpecJSI.h"
5
+ #include <folly/dynamic.h>
6
+ #include <react/renderer/uimanager/UIManagerBinding.h>
7
+ #include <react/renderer/uimanager/UIManagerCommitHook.h>
8
+ #include <mutex>
9
+ #include <unordered_map>
10
+
11
+ namespace facebook::react {
12
+
13
+ class NativeZyzz : public NativeZyzzCxxSpec<NativeZyzz>, public UIManagerCommitHook {
14
+ public:
15
+ explicit NativeZyzz(std::shared_ptr<CallInvoker> invoker);
16
+ ~NativeZyzz() override;
17
+
18
+ double attach(jsi::Runtime &runtime, jsi::Object node, jsi::Object props);
19
+ void detach(jsi::Runtime &runtime, double id);
20
+ jsi::Object inspect(jsi::Runtime &runtime);
21
+ void update(jsi::Runtime &runtime, std::vector<jsi::Object> updates);
22
+
23
+ void commitHookWasRegistered(const UIManager &) noexcept override {}
24
+ void commitHookWasUnregistered(const UIManager &) noexcept override {}
25
+ std::shared_ptr<RootShadowNode> shadowTreeWillCommit(
26
+ const ShadowTree &tree,
27
+ const std::shared_ptr<const RootShadowNode> &previous,
28
+ const std::shared_ptr<RootShadowNode> &next) noexcept override;
29
+
30
+ private:
31
+ struct Entry {
32
+ std::weak_ptr<ShadowNodeFamily> family;
33
+ folly::dynamic rendered;
34
+ folly::dynamic selected;
35
+ folly::dynamic overlay;
36
+ Props::Shared authored;
37
+ Props::Shared applied;
38
+ };
39
+
40
+ void write(std::unordered_map<Tag, folly::dynamic> patches);
41
+ static thread_local const NativeZyzz *writing_;
42
+
43
+ std::shared_ptr<UIManagerBinding> binding_;
44
+ UIManager *manager_ = nullptr;
45
+ std::unordered_map<double, Entry> entries_;
46
+ std::mutex mutex_;
47
+ double nextId_ = 0;
48
+ double batches_ = 0;
49
+ double writes_ = 0;
50
+ };
51
+
52
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ template <typename T>
19
+ class JSI_EXPORT NativeZyzzCxxSpec : public TurboModule {
20
+ public:
21
+ static constexpr std::string_view kModuleName = "NativeZyzz";
22
+
23
+ protected:
24
+ NativeZyzzCxxSpec(std::shared_ptr<CallInvoker> jsInvoker) : TurboModule(std::string{NativeZyzzCxxSpec::kModuleName}, jsInvoker) {
25
+ methodMap_["attach"] = MethodMetadata {.argCount = 2, .invoker = __attach};
26
+ methodMap_["detach"] = MethodMetadata {.argCount = 1, .invoker = __detach};
27
+ methodMap_["inspect"] = MethodMetadata {.argCount = 0, .invoker = __inspect};
28
+ methodMap_["update"] = MethodMetadata {.argCount = 1, .invoker = __update};
29
+ }
30
+
31
+ private:
32
+ static jsi::Value __attach(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
33
+ static_assert(
34
+ bridging::getParameterCount(&T::attach) == 3,
35
+ "Expected attach(...) to have 3 parameters");
36
+ return bridging::callFromJs<double>(rt, &T::attach, static_cast<NativeZyzzCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
37
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt),
38
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asObject(rt));
39
+ }
40
+
41
+ static jsi::Value __detach(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
42
+ static_assert(
43
+ bridging::getParameterCount(&T::detach) == 2,
44
+ "Expected detach(...) to have 2 parameters");
45
+ bridging::callFromJs<void>(rt, &T::detach, static_cast<NativeZyzzCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
46
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber());return jsi::Value::undefined();
47
+ }
48
+
49
+ static jsi::Value __inspect(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) {
50
+ static_assert(
51
+ bridging::getParameterCount(&T::inspect) == 1,
52
+ "Expected inspect(...) to have 1 parameters");
53
+ return bridging::callFromJs<jsi::Object>(rt, &T::inspect, static_cast<NativeZyzzCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule));
54
+ }
55
+
56
+ static jsi::Value __update(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
57
+ static_assert(
58
+ bridging::getParameterCount(&T::update) == 2,
59
+ "Expected update(...) to have 2 parameters");
60
+ bridging::callFromJs<void>(rt, &T::update, static_cast<NativeZyzzCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
61
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt).asArray(rt));return jsi::Value::undefined();
62
+ }
63
+ };
64
+
65
+ } // namespace facebook::react
@@ -0,0 +1,8 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ project(zyzz)
3
+
4
+ add_library(react_codegen_ZyzzSpec STATIC ../NativeZyzz.cpp ZyzzSpec-generated.cpp)
5
+ target_include_directories(react_codegen_ZyzzSpec PUBLIC . ..)
6
+ target_link_libraries(react_codegen_ZyzzSpec ReactAndroid::reactnative ReactAndroid::jsi fbjni::fbjni)
7
+ target_compile_features(react_codegen_ZyzzSpec PUBLIC cxx_std_20)
8
+ set_target_properties(react_codegen_ZyzzSpec PROPERTIES POSITION_INDEPENDENT_CODE ON)
@@ -0,0 +1,50 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniCpp.js
9
+ */
10
+
11
+ #include "ZyzzSpec.h"
12
+
13
+ namespace facebook::react {
14
+
15
+ static facebook::jsi::Value __hostFunction_NativeZyzzSpecJSI_attach(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
16
+ static jmethodID cachedMethodId = nullptr;
17
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, NumberKind, "attach", "(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/ReadableMap;)D", args, count, cachedMethodId);
18
+ }
19
+
20
+ static facebook::jsi::Value __hostFunction_NativeZyzzSpecJSI_detach(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
21
+ static jmethodID cachedMethodId = nullptr;
22
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, VoidKind, "detach", "(D)V", args, count, cachedMethodId);
23
+ }
24
+
25
+ static facebook::jsi::Value __hostFunction_NativeZyzzSpecJSI_inspect(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
26
+ static jmethodID cachedMethodId = nullptr;
27
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ObjectKind, "inspect", "()Lcom/facebook/react/bridge/WritableMap;", args, count, cachedMethodId);
28
+ }
29
+
30
+ static facebook::jsi::Value __hostFunction_NativeZyzzSpecJSI_update(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
31
+ static jmethodID cachedMethodId = nullptr;
32
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, VoidKind, "update", "(Lcom/facebook/react/bridge/ReadableArray;)V", args, count, cachedMethodId);
33
+ }
34
+
35
+ NativeZyzzSpecJSI::NativeZyzzSpecJSI(const JavaTurboModule::InitParams &params)
36
+ : JavaTurboModule(params) {
37
+ methodMap_["attach"] = MethodMetadata {2, __hostFunction_NativeZyzzSpecJSI_attach};
38
+ methodMap_["detach"] = MethodMetadata {1, __hostFunction_NativeZyzzSpecJSI_detach};
39
+ methodMap_["inspect"] = MethodMetadata {0, __hostFunction_NativeZyzzSpecJSI_inspect};
40
+ methodMap_["update"] = MethodMetadata {1, __hostFunction_NativeZyzzSpecJSI_update};
41
+ }
42
+
43
+ std::shared_ptr<TurboModule> ZyzzSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
44
+ if (moduleName == "NativeZyzz") {
45
+ return std::make_shared<NativeZyzzSpecJSI>(params);
46
+ }
47
+ return nullptr;
48
+ }
49
+
50
+ } // namespace facebook::react
@@ -0,0 +1,31 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <ReactCommon/JavaTurboModule.h>
14
+ #include <ReactCommon/TurboModule.h>
15
+ #include <jsi/jsi.h>
16
+
17
+ namespace facebook::react {
18
+
19
+ /**
20
+ * JNI C++ class for module 'NativeZyzz'
21
+ */
22
+ class JSI_EXPORT NativeZyzzSpecJSI : public JavaTurboModule {
23
+ public:
24
+ NativeZyzzSpecJSI(const JavaTurboModule::InitParams &params);
25
+ };
26
+
27
+
28
+ JSI_EXPORT
29
+ std::shared_ptr<TurboModule> ZyzzSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
30
+
31
+ } // namespace facebook::react
@@ -0,0 +1,13 @@
1
+ /** Registers the shared C++ adapter with React Native on iOS. */
2
+ #import <ReactCommon/RCTTurboModule.h>
3
+ #import "NativeZyzz.h"
4
+
5
+ @interface ZyzzModuleProvider : NSObject <RCTModuleProvider>
6
+ @end
7
+
8
+ @implementation ZyzzModuleProvider
9
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
10
+ (const facebook::react::ObjCTurboModule::InitParams &)params {
11
+ return std::make_shared<facebook::react::NativeZyzz>(params.jsInvoker);
12
+ }
13
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyzz",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "license": "MIT",
5
5
  "description": "Modern, universal, simple styling library for the Web and React Native",
6
6
  "repository": {
@@ -16,6 +16,9 @@
16
16
  "files": [
17
17
  "dist",
18
18
  "src",
19
+ "native",
20
+ "react-native.config.ts",
21
+ "Zyzz.podspec",
19
22
  "!src/**/*.bench-d.ts",
20
23
  "!src/**/*.bench.ts",
21
24
  "!src/**/*.test-d.ts",
@@ -25,6 +28,20 @@
25
28
  "./src/reset.css",
26
29
  "./dist/reset.css"
27
30
  ],
31
+ "codegenConfig": {
32
+ "name": "ZyzzSpec",
33
+ "type": "modules",
34
+ "jsSrcsDir": "src/react-native/internal",
35
+ "android": {
36
+ "javaPackageName": "xyz.wevm.zyzz"
37
+ },
38
+ "ios": {
39
+ "modulesProvider": {
40
+ "NativeZyzz": "ZyzzModuleProvider"
41
+ }
42
+ },
43
+ "includesGeneratedCode": true
44
+ },
28
45
  "module": "./dist/index.js",
29
46
  "types": "./dist/index.d.ts",
30
47
  "exports": {
@@ -84,11 +101,24 @@
84
101
  "default": "./dist/oxlint/index.js"
85
102
  },
86
103
  "./react-native": {
104
+ "react-native": {
105
+ "types": "./dist/react-native/index.native.d.ts",
106
+ "default": "./dist/react-native/index.native.js"
107
+ },
87
108
  "src": "./src/react-native/index.ts",
88
109
  "types": "./dist/react-native/index.d.ts",
89
110
  "default": "./dist/react-native/index.js"
90
111
  },
112
+ "./react-native/reanimated": {
113
+ "src": "./src/react-native/reanimated.ts",
114
+ "types": "./dist/react-native/reanimated.d.ts",
115
+ "default": "./dist/react-native/reanimated.js"
116
+ },
91
117
  "./react-native/react": {
118
+ "react-native": {
119
+ "types": "./dist/react-native/react.d.ts",
120
+ "default": "./dist/react-native/internal/Device.js"
121
+ },
92
122
  "src": "./src/react-native/react.ts",
93
123
  "types": "./dist/react-native/react.d.ts",
94
124
  "default": "./dist/react-native/react.js"
@@ -146,6 +176,8 @@
146
176
  "@babel/core": "^7.29.7",
147
177
  "next": "^16.3.5",
148
178
  "react": "^19.0.0",
179
+ "react-native": ">=0.86.0 <1.0.0",
180
+ "react-native-reanimated": ">=4.5.3 <5.0.0",
149
181
  "vite": "^8.0.0"
150
182
  },
151
183
  "peerDependenciesMeta": {
@@ -158,6 +190,12 @@
158
190
  "react": {
159
191
  "optional": true
160
192
  },
193
+ "react-native": {
194
+ "optional": true
195
+ },
196
+ "react-native-reanimated": {
197
+ "optional": true
198
+ },
161
199
  "vite": {
162
200
  "optional": true
163
201
  }
@@ -0,0 +1,14 @@
1
+ /** Autolinks the shared native adapter without application registration. @module */
2
+ export default {
3
+ dependency: {
4
+ platforms: {
5
+ android: {
6
+ cxxModuleCMakeListsModuleName: 'react_codegen_ZyzzSpec',
7
+ cxxModuleCMakeListsPath: 'CMakeLists.txt',
8
+ cxxModuleHeaderName: 'NativeZyzz',
9
+ sourceDir: 'native/android',
10
+ },
11
+ ios: {},
12
+ },
13
+ },
14
+ }
package/src/Style.ts CHANGED
@@ -75,14 +75,17 @@ export type Accepted<
75
75
  ? LiteralDeclarations
76
76
  : DeclarationProperties<tokens>)[key] extends style[key]
77
77
  ? style[key]
78
- : Value.Accepted<
79
- Pick<style, key>,
80
- literal extends true
81
- ? LiteralDeclarations
82
- : DeclarationProperties<tokens>
83
- >[key] &
84
- Value.Checked<Pick<style, key>, tokens>[key] &
85
- Value.Tokens<style[key], tokens, key>
78
+ : // Naming the expected tokens avoids a `never` diagnostic and keeps completions to accepted values.
79
+ [Value.Tokens<style[key], tokens, key>] extends [never]
80
+ ? Value.Mismatch<tokens, key>
81
+ : Value.Accepted<
82
+ Pick<style, key>,
83
+ literal extends true
84
+ ? LiteralDeclarations
85
+ : DeclarationProperties<tokens>
86
+ >[key] &
87
+ Value.Checked<Pick<style, key>, tokens>[key] &
88
+ Value.Tokens<style[key], tokens, key>
86
89
  : key extends Condition.Keys<tokens, key>
87
90
  ? [style[key]] extends [undefined]
88
91
  ? never