@lynx-js/lynx-library-headers 0.0.1-alpha.4

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 (135) hide show
  1. package/README.md +53 -0
  2. package/include/base/include/value/lynx_api_types.h +57 -0
  3. package/include/base/include/value/lynx_value_api.h +204 -0
  4. package/include/base/include/value/lynx_value_types.h +73 -0
  5. package/include/capi/lynx_env_capi.h +47 -0
  6. package/include/capi/lynx_event_reporter_service_capi.h +67 -0
  7. package/include/capi/lynx_export.h +27 -0
  8. package/include/capi/lynx_extension_module_capi.h +148 -0
  9. package/include/capi/lynx_extension_module_types_capi.h +17 -0
  10. package/include/capi/lynx_generic_resource_fetcher_capi.h +124 -0
  11. package/include/capi/lynx_group_capi.h +42 -0
  12. package/include/capi/lynx_http_service_capi.h +113 -0
  13. package/include/capi/lynx_load_meta_capi.h +52 -0
  14. package/include/capi/lynx_log_capi.h +69 -0
  15. package/include/capi/lynx_memory_capi.h +28 -0
  16. package/include/capi/lynx_native_module_capi.h +51 -0
  17. package/include/capi/lynx_native_view_capi.h +163 -0
  18. package/include/capi/lynx_resource_request_capi.h +71 -0
  19. package/include/capi/lynx_resource_response_capi.h +92 -0
  20. package/include/capi/lynx_runtime_lifecycle_observer_capi.h +62 -0
  21. package/include/capi/lynx_security_service_capi.h +52 -0
  22. package/include/capi/lynx_service_center_capi.h +50 -0
  23. package/include/capi/lynx_template_bundle_capi.h +39 -0
  24. package/include/capi/lynx_template_data_capi.h +33 -0
  25. package/include/capi/lynx_trace_capi.h +62 -0
  26. package/include/capi/lynx_trail_service_capi.h +35 -0
  27. package/include/capi/lynx_types.h +750 -0
  28. package/include/capi/lynx_update_meta_capi.h +33 -0
  29. package/include/capi/lynx_view_builder_capi.h +113 -0
  30. package/include/capi/lynx_view_capi.h +174 -0
  31. package/include/capi/lynx_view_client_capi.h +81 -0
  32. package/include/capi/lynx_vsync_monitor_capi.h +38 -0
  33. package/include/capi/lynx_windowless_renderer_capi.h +213 -0
  34. package/include/js_native_api.h +608 -0
  35. package/include/js_native_api_types.h +202 -0
  36. package/include/lynx/base/include/value/lynx_api_types.h +57 -0
  37. package/include/lynx/base/include/value/lynx_value_api.h +204 -0
  38. package/include/lynx/base/include/value/lynx_value_types.h +73 -0
  39. package/include/lynx/extension.h +6 -0
  40. package/include/lynx/platform/embedder/public/capi/lynx_env_capi.h +47 -0
  41. package/include/lynx/platform/embedder/public/capi/lynx_event_reporter_service_capi.h +67 -0
  42. package/include/lynx/platform/embedder/public/capi/lynx_export.h +27 -0
  43. package/include/lynx/platform/embedder/public/capi/lynx_extension_module_capi.h +148 -0
  44. package/include/lynx/platform/embedder/public/capi/lynx_extension_module_types_capi.h +17 -0
  45. package/include/lynx/platform/embedder/public/capi/lynx_generic_resource_fetcher_capi.h +124 -0
  46. package/include/lynx/platform/embedder/public/capi/lynx_group_capi.h +42 -0
  47. package/include/lynx/platform/embedder/public/capi/lynx_http_service_capi.h +113 -0
  48. package/include/lynx/platform/embedder/public/capi/lynx_load_meta_capi.h +52 -0
  49. package/include/lynx/platform/embedder/public/capi/lynx_log_capi.h +69 -0
  50. package/include/lynx/platform/embedder/public/capi/lynx_memory_capi.h +28 -0
  51. package/include/lynx/platform/embedder/public/capi/lynx_native_module_capi.h +51 -0
  52. package/include/lynx/platform/embedder/public/capi/lynx_native_view_capi.h +163 -0
  53. package/include/lynx/platform/embedder/public/capi/lynx_resource_request_capi.h +71 -0
  54. package/include/lynx/platform/embedder/public/capi/lynx_resource_response_capi.h +92 -0
  55. package/include/lynx/platform/embedder/public/capi/lynx_runtime_lifecycle_observer_capi.h +62 -0
  56. package/include/lynx/platform/embedder/public/capi/lynx_security_service_capi.h +52 -0
  57. package/include/lynx/platform/embedder/public/capi/lynx_service_center_capi.h +50 -0
  58. package/include/lynx/platform/embedder/public/capi/lynx_template_bundle_capi.h +39 -0
  59. package/include/lynx/platform/embedder/public/capi/lynx_template_data_capi.h +33 -0
  60. package/include/lynx/platform/embedder/public/capi/lynx_trace_capi.h +62 -0
  61. package/include/lynx/platform/embedder/public/capi/lynx_trail_service_capi.h +35 -0
  62. package/include/lynx/platform/embedder/public/capi/lynx_types.h +750 -0
  63. package/include/lynx/platform/embedder/public/capi/lynx_update_meta_capi.h +33 -0
  64. package/include/lynx/platform/embedder/public/capi/lynx_view_builder_capi.h +113 -0
  65. package/include/lynx/platform/embedder/public/capi/lynx_view_capi.h +174 -0
  66. package/include/lynx/platform/embedder/public/capi/lynx_view_client_capi.h +81 -0
  67. package/include/lynx/platform/embedder/public/capi/lynx_vsync_monitor_capi.h +38 -0
  68. package/include/lynx/platform/embedder/public/capi/lynx_windowless_renderer_capi.h +213 -0
  69. package/include/lynx/platform/embedder/public/lynx_env.h +104 -0
  70. package/include/lynx/platform/embedder/public/lynx_event_reporter_service.h +96 -0
  71. package/include/lynx/platform/embedder/public/lynx_event_simulation_proxy.h +31 -0
  72. package/include/lynx/platform/embedder/public/lynx_extension_module.h +521 -0
  73. package/include/lynx/platform/embedder/public/lynx_generic_resource_fetcher.h +178 -0
  74. package/include/lynx/platform/embedder/public/lynx_group.h +70 -0
  75. package/include/lynx/platform/embedder/public/lynx_http_service.h +211 -0
  76. package/include/lynx/platform/embedder/public/lynx_load_meta.h +120 -0
  77. package/include/lynx/platform/embedder/public/lynx_native_module.h +9 -0
  78. package/include/lynx/platform/embedder/public/lynx_native_view.h +201 -0
  79. package/include/lynx/platform/embedder/public/lynx_resource_request.h +56 -0
  80. package/include/lynx/platform/embedder/public/lynx_resource_response.h +63 -0
  81. package/include/lynx/platform/embedder/public/lynx_runtime_lifecycle_observer.h +102 -0
  82. package/include/lynx/platform/embedder/public/lynx_security_service.h +78 -0
  83. package/include/lynx/platform/embedder/public/lynx_service_center.h +64 -0
  84. package/include/lynx/platform/embedder/public/lynx_template_bundle.h +65 -0
  85. package/include/lynx/platform/embedder/public/lynx_template_data.h +104 -0
  86. package/include/lynx/platform/embedder/public/lynx_trail_service.h +81 -0
  87. package/include/lynx/platform/embedder/public/lynx_update_meta.h +56 -0
  88. package/include/lynx/platform/embedder/public/lynx_value.h +270 -0
  89. package/include/lynx/platform/embedder/public/lynx_view.h +364 -0
  90. package/include/lynx/platform/embedder/public/lynx_view_client.h +226 -0
  91. package/include/lynx/platform/embedder/public/lynx_vsync_monitor.h +70 -0
  92. package/include/lynx/platform/embedder/public/lynx_windowless_renderer.h +302 -0
  93. package/include/lynx/registration.h +178 -0
  94. package/include/lynx_env.h +104 -0
  95. package/include/lynx_event_reporter_service.h +96 -0
  96. package/include/lynx_event_simulation_proxy.h +31 -0
  97. package/include/lynx_extension.h +10 -0
  98. package/include/lynx_extension_module.h +521 -0
  99. package/include/lynx_generic_resource_fetcher.h +178 -0
  100. package/include/lynx_group.h +70 -0
  101. package/include/lynx_http_service.h +211 -0
  102. package/include/lynx_load_meta.h +120 -0
  103. package/include/lynx_native_module.h +9 -0
  104. package/include/lynx_native_view.h +201 -0
  105. package/include/lynx_resource_request.h +56 -0
  106. package/include/lynx_resource_response.h +63 -0
  107. package/include/lynx_runtime_lifecycle_observer.h +102 -0
  108. package/include/lynx_security_service.h +78 -0
  109. package/include/lynx_service_center.h +64 -0
  110. package/include/lynx_template_bundle.h +65 -0
  111. package/include/lynx_template_data.h +104 -0
  112. package/include/lynx_trail_service.h +81 -0
  113. package/include/lynx_update_meta.h +56 -0
  114. package/include/lynx_value.h +270 -0
  115. package/include/lynx_view.h +364 -0
  116. package/include/lynx_view_client.h +226 -0
  117. package/include/lynx_vsync_monitor.h +70 -0
  118. package/include/lynx_windowless_renderer.h +302 -0
  119. package/include/napi-inl.deprecated.h +186 -0
  120. package/include/napi-inl.h +6607 -0
  121. package/include/napi.h +3208 -0
  122. package/include/node_api.h +276 -0
  123. package/include/node_api_types.h +59 -0
  124. package/include/third_party/weak-node-api/headers/js_native_api.h +608 -0
  125. package/include/third_party/weak-node-api/headers/js_native_api_types.h +202 -0
  126. package/include/third_party/weak-node-api/headers/napi-inl.deprecated.h +186 -0
  127. package/include/third_party/weak-node-api/headers/napi-inl.h +6607 -0
  128. package/include/third_party/weak-node-api/headers/napi.h +3208 -0
  129. package/include/third_party/weak-node-api/headers/node_api.h +276 -0
  130. package/include/third_party/weak-node-api/headers/node_api_types.h +59 -0
  131. package/include/third_party/weak-node-api/headers/weak_napi_defines.h +331 -0
  132. package/include/third_party/weak-node-api/headers/weak_napi_undefs.h +282 -0
  133. package/include/weak_napi_defines.h +331 -0
  134. package/include/weak_napi_undefs.h +282 -0
  135. package/package.json +29 -0
@@ -0,0 +1,270 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_VALUE_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_VALUE_H_
6
+
7
+ #include <functional>
8
+ #include <memory>
9
+ #include <string>
10
+ #include <utility>
11
+
12
+ #include "base/include/value/lynx_value_api.h"
13
+ namespace lynx {
14
+ namespace pub {
15
+
16
+ class LynxValue;
17
+ using LynxValueIterator =
18
+ std::function<void(const LynxValue&, const LynxValue&)>;
19
+ using LynxValueIteratorCallback =
20
+ std::function<void(lynx_api_env, const lynx_value&, const lynx_value&)>;
21
+
22
+ class LynxValue {
23
+ public:
24
+ ~LynxValue() { lynx_value_remove_reference(env_, value_, nullptr); }
25
+
26
+ LynxValue(const LynxValue& val) {
27
+ if (this == &val) return;
28
+ lynx_value_add_reference(env_, val.value_, nullptr);
29
+ value_ = val.value_;
30
+ }
31
+
32
+ LynxValue(LynxValue&& val) noexcept {
33
+ value_ = val.value_;
34
+ val.value_.type = lynx_value_null;
35
+ }
36
+
37
+ LynxValue& operator=(const LynxValue& val) {
38
+ if (this != &val) {
39
+ lynx_value_add_reference(env_, val.value_, nullptr);
40
+ lynx_value_remove_reference(env_, value_, nullptr);
41
+ value_ = val.value_;
42
+ }
43
+ return *this;
44
+ }
45
+
46
+ LynxValue& operator=(LynxValue&& val) noexcept {
47
+ if (this != &val) {
48
+ this->~LynxValue();
49
+ new (this) LynxValue(std::move(val));
50
+ }
51
+ return *this;
52
+ }
53
+
54
+ explicit LynxValue(bool val) { lynx_value_create_bool(env_, val, &value_); }
55
+
56
+ explicit LynxValue(int32_t val) {
57
+ lynx_value_create_int32(env_, val, &value_);
58
+ }
59
+
60
+ explicit LynxValue(int64_t val) {
61
+ lynx_value_create_int64(env_, val, &value_);
62
+ }
63
+
64
+ explicit LynxValue(uint32_t val) {
65
+ lynx_value_create_uint32(env_, val, &value_);
66
+ }
67
+
68
+ explicit LynxValue(uint64_t val) {
69
+ lynx_value_create_uint64(env_, val, &value_);
70
+ }
71
+
72
+ explicit LynxValue(double val) {
73
+ lynx_value_create_double(env_, val, &value_);
74
+ }
75
+
76
+ explicit LynxValue(const char* str) {
77
+ lynx_value_create_string_utf8(
78
+ env_, str, str == nullptr ? 0 : std::strlen(str), &value_);
79
+ }
80
+
81
+ explicit LynxValue(const std::string& str) {
82
+ lynx_value_create_string_utf8(env_, str.c_str(), str.size(), &value_);
83
+ }
84
+
85
+ enum CreateAsNullTag {
86
+ kCreateAsNullTag,
87
+ };
88
+ explicit LynxValue(CreateAsNullTag) { lynx_value_create_null(env_, &value_); }
89
+
90
+ enum CreateAsArrayTag {
91
+ kCreateAsArrayTag,
92
+ };
93
+ explicit LynxValue(CreateAsArrayTag) {
94
+ lynx_value_create_array(env_, &value_);
95
+ }
96
+
97
+ enum CreateAsMapTag {
98
+ kCreateAsMapTag,
99
+ };
100
+ explicit LynxValue(CreateAsMapTag) { lynx_value_create_map(env_, &value_); }
101
+
102
+ explicit LynxValue(const lynx_value& val) : value_(val) {
103
+ lynx_value_add_reference(env_, value_, nullptr);
104
+ }
105
+
106
+ explicit LynxValue(lynx_value&& val) : value_(std::move(val)) {}
107
+
108
+ lynx_value_type Type() const {
109
+ lynx_value_type type;
110
+ lynx_value_typeof(env_, value_, &type);
111
+ return type;
112
+ }
113
+
114
+ lynx_value Value() const { return value_; }
115
+
116
+ bool Bool() const {
117
+ bool ret;
118
+ lynx_api_status status = lynx_value_get_bool(env_, value_, &ret);
119
+ if (status != lynx_api_ok) return false;
120
+ return ret;
121
+ }
122
+
123
+ double Number() const {
124
+ double ret;
125
+ lynx_api_status status = lynx_value_get_number(env_, value_, &ret);
126
+ if (status != lynx_api_ok) return 0.f;
127
+ return ret;
128
+ }
129
+
130
+ double Double() const {
131
+ double ret;
132
+ lynx_api_status status = lynx_value_get_double(env_, value_, &ret);
133
+ if (status != lynx_api_ok) return 0.f;
134
+ return ret;
135
+ }
136
+
137
+ int32_t Int32() const {
138
+ int32_t ret;
139
+ lynx_api_status status = lynx_value_get_int32(env_, value_, &ret);
140
+ if (status != lynx_api_ok) return 0;
141
+ return ret;
142
+ }
143
+
144
+ uint32_t UInt32() const {
145
+ uint32_t ret;
146
+ lynx_api_status status = lynx_value_get_uint32(env_, value_, &ret);
147
+ if (status != lynx_api_ok) return 0;
148
+ return ret;
149
+ }
150
+
151
+ int64_t Int64() const {
152
+ int64_t ret;
153
+ lynx_api_status status = lynx_value_get_int64(env_, value_, &ret);
154
+ if (status != lynx_api_ok) return 0;
155
+ return ret;
156
+ }
157
+
158
+ uint64_t UInt64() const {
159
+ uint64_t ret;
160
+ lynx_api_status status = lynx_value_get_uint64(env_, value_, &ret);
161
+ if (status != lynx_api_ok) return 0;
162
+ return ret;
163
+ }
164
+
165
+ std::string StdString() const {
166
+ size_t str_size;
167
+ lynx_api_status status =
168
+ lynx_value_get_string_utf8(env_, value_, nullptr, 0, &str_size);
169
+ if (status != lynx_api_ok) return "";
170
+ auto buf = std::make_unique<char[]>(str_size + 1);
171
+ status = lynx_value_get_string_utf8(env_, value_, buf.get(), str_size + 1,
172
+ &str_size);
173
+ if (status != lynx_api_ok) return "";
174
+ return std::string(buf.get(), str_size);
175
+ }
176
+
177
+ uint32_t ArrayLength() const {
178
+ uint32_t ret;
179
+ lynx_value_get_array_length(env_, value_, &ret);
180
+ return ret;
181
+ }
182
+
183
+ bool InsertValue(uint32_t idx, const LynxValue& val) {
184
+ lynx_api_status status =
185
+ lynx_value_set_element(env_, value_, idx, val.value_);
186
+ if (status != lynx_api_ok) return false;
187
+ return true;
188
+ }
189
+
190
+ LynxValue GetValueAt(uint32_t idx) const {
191
+ lynx_value ret;
192
+ lynx_api_status status = lynx_value_get_element(env_, value_, idx, &ret);
193
+ if (status != lynx_api_ok) return LynxValue(kCreateAsNullTag);
194
+ return LynxValue(std::move(ret));
195
+ }
196
+
197
+ bool HasProperty(const char* key) const {
198
+ bool ret;
199
+ lynx_api_status status = lynx_value_has_property(env_, value_, key, &ret);
200
+ if (status != lynx_api_ok) return false;
201
+ return ret;
202
+ }
203
+
204
+ bool SetProperty(const char* key, const LynxValue& val) {
205
+ lynx_api_status status =
206
+ lynx_value_set_named_property(env_, value_, key, val.value_);
207
+ if (status != lynx_api_ok) return false;
208
+ return true;
209
+ }
210
+
211
+ LynxValue GetProperty(const char* key) const {
212
+ lynx_value ret;
213
+ lynx_api_status status =
214
+ lynx_value_get_named_property(env_, value_, key, &ret);
215
+ if (status != lynx_api_ok) return LynxValue(kCreateAsNullTag);
216
+ return LynxValue(std::move(ret));
217
+ }
218
+
219
+ void IteratorValue(const LynxValueIterator& callback) const {
220
+ LynxValueIteratorCallback callback_wrap =
221
+ [&callback](lynx_api_env env, const lynx_value& key,
222
+ const lynx_value& value) {
223
+ LynxValue keyWrap(key);
224
+ lynx_value v = value;
225
+ LynxValue valueWrap(std::move(v));
226
+ callback(keyWrap, valueWrap);
227
+ };
228
+ lynx_value_iterate_value(env_, value_, InternalLynxValueIteratorCallback,
229
+ reinterpret_cast<void*>(&callback_wrap), nullptr);
230
+ }
231
+
232
+ static void ForEachLynxValue(const LynxValue& val, LynxValueIterator func) {
233
+ lynx_api_env env = val.env_;
234
+ lynx_value property_names;
235
+ lynx_api_status status =
236
+ lynx_value_get_property_names(env, val.value_, &property_names);
237
+ if (status != lynx_api_ok) return;
238
+ uint32_t len;
239
+ lynx_value_get_array_length(env, property_names, &len);
240
+ for (uint32_t i = 0; i < len; i++) {
241
+ lynx_value element;
242
+ lynx_value_get_element(env, property_names, i, &element);
243
+ auto key = LynxValue(std::move(element));
244
+ lynx_value property;
245
+ lynx_value_get_named_property(env, val.value_, key.StdString().c_str(),
246
+ &property);
247
+ auto value = LynxValue(std::move(property));
248
+ func(key, value);
249
+ }
250
+ lynx_value_remove_reference(env, property_names, nullptr);
251
+ }
252
+
253
+ private:
254
+ static inline void InternalLynxValueIteratorCallback(lynx_api_env env,
255
+ lynx_value key,
256
+ lynx_value value,
257
+ void* pfunc,
258
+ void* raw_data) {
259
+ reinterpret_cast<LynxValueIteratorCallback*>(pfunc)->operator()(env, key,
260
+ value);
261
+ }
262
+
263
+ lynx_value value_;
264
+ lynx_api_env env_ = nullptr;
265
+ };
266
+
267
+ } // namespace pub
268
+ } // namespace lynx
269
+
270
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_VALUE_H_
@@ -0,0 +1,364 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_VIEW_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_VIEW_H_
6
+
7
+ #include <algorithm>
8
+ #include <memory>
9
+ #include <string>
10
+ #include <unordered_map>
11
+ #include <utility>
12
+ #include <vector>
13
+
14
+ #include "capi/lynx_view_builder_capi.h"
15
+ #include "capi/lynx_view_capi.h"
16
+ #include "lynx_event_simulation_proxy.h"
17
+ #include "lynx_generic_resource_fetcher.h"
18
+ #include "lynx_group.h"
19
+ #include "lynx_load_meta.h"
20
+ #include "lynx_native_module.h"
21
+ #include "lynx_runtime_lifecycle_observer.h"
22
+ #include "lynx_update_meta.h"
23
+ #include "lynx_view_client.h"
24
+ #include "lynx_windowless_renderer.h"
25
+
26
+ // Forward declaration of internal struct
27
+ struct lynx_view_t;
28
+
29
+ namespace lynx {
30
+ namespace pub {
31
+
32
+ /**
33
+ * @apidoc
34
+ * @brief LynxView is the main entry point for rendering and interacting with
35
+ * Lynx. It provides methods for loading and rendering templates, updating data,
36
+ * and sending events.
37
+ */
38
+ class LynxView {
39
+ public:
40
+ class Builder {
41
+ public:
42
+ Builder() : builder_(lynx_view_builder_create()) {}
43
+ ~Builder() { lynx_view_builder_release(builder_); }
44
+
45
+ Builder& SetScreenSize(float width, float height, float pixel_ratio) {
46
+ lynx_view_builder_set_screen_size(builder_, width, height, pixel_ratio);
47
+ return *this;
48
+ }
49
+
50
+ Builder& SetFrame(float x, float y, float width, float height) {
51
+ lynx_view_builder_set_frame(builder_, x, y, width, height);
52
+ return *this;
53
+ }
54
+
55
+ Builder& SetFontScale(float scale) {
56
+ lynx_view_builder_set_font_scale(builder_, scale);
57
+ return *this;
58
+ }
59
+
60
+ Builder& SetICUDataPath(const std::string& icu_data_path) {
61
+ lynx_view_builder_set_icu_data_path(builder_, icu_data_path.c_str());
62
+ return *this;
63
+ }
64
+
65
+ Builder& SetWebView2FixedRuntimePath(
66
+ const std::string& webview2_fixed_runtime_path) {
67
+ lynx_view_builder_set_webview2_fixed_runtime_path(
68
+ builder_, webview2_fixed_runtime_path.c_str());
69
+ return *this;
70
+ }
71
+
72
+ Builder& SetLynxGroup(std::shared_ptr<LynxGroup> group) {
73
+ group_ = std::move(group);
74
+ lynx_view_builder_set_lynx_group(builder_, group_->Impl());
75
+ return *this;
76
+ }
77
+
78
+ Builder& SetParent(NativeWindow parent) {
79
+ lynx_view_builder_set_parent(builder_, parent);
80
+ return *this;
81
+ }
82
+ Builder& SetWindowlessRenderer(
83
+ std::shared_ptr<LynxWindowlessRenderer> renderer) {
84
+ renderer->InitIfNeeded();
85
+ lynx_view_builder_set_windowless_renderer(builder_, renderer->Impl());
86
+ windowless_renderer_ = renderer;
87
+ return *this;
88
+ }
89
+ Builder& SetGenericResourceFetcher(
90
+ std::shared_ptr<LynxGenericResourceFetcher> fetcher) {
91
+ fetcher->InitIfNeeded();
92
+ lynx_view_builder_set_generic_resource_fetcher(builder_, fetcher->Impl());
93
+ generic_fetcher_ = fetcher;
94
+ return *this;
95
+ }
96
+
97
+ Builder& RegisterNativeModule(const std::string& module_name,
98
+ napi_module_creator creator, void* opaque) {
99
+ lynx_view_builder_register_native_module(builder_, module_name.c_str(),
100
+ creator, opaque);
101
+ return *this;
102
+ }
103
+
104
+ template <typename T>
105
+ Builder& RegisterNativeView(const std::string& tag_name,
106
+ void* opaque = nullptr) {
107
+ lynx_view_builder_register_native_view(
108
+ builder_, tag_name.c_str(),
109
+ [](void* opaque) -> lynx_native_view_t* {
110
+ return (new T(opaque))->native_view();
111
+ },
112
+ opaque);
113
+ return *this;
114
+ }
115
+
116
+ lynx_view_builder_t* Impl() { return builder_; }
117
+
118
+ std::unique_ptr<LynxView> Build() {
119
+ std::unique_ptr<LynxView> view = std::make_unique<LynxView>(this);
120
+ view->generic_fetcher_ = std::move(generic_fetcher_);
121
+ view->windowless_renderer_ = std::move(windowless_renderer_);
122
+ return view;
123
+ }
124
+
125
+ Builder(const Builder&) = delete;
126
+ Builder& operator=(const Builder&) = delete;
127
+
128
+ private:
129
+ lynx_view_builder_t* builder_;
130
+ std::shared_ptr<LynxGroup> group_;
131
+ std::shared_ptr<LynxWindowlessRenderer> windowless_renderer_;
132
+ std::shared_ptr<LynxGenericResourceFetcher> generic_fetcher_;
133
+ friend class LynxView;
134
+ };
135
+
136
+ static LynxView* Unwrap(lynx_view_t* view) {
137
+ if (view == nullptr) {
138
+ return nullptr;
139
+ }
140
+ return static_cast<LynxView*>(lynx_view_get_user_data(view));
141
+ }
142
+
143
+ explicit LynxView(Builder* builder)
144
+ : lynx_view_(lynx_view_create(builder->builder_, this)) {}
145
+
146
+ virtual ~LynxView() { lynx_view_release(lynx_view_); }
147
+
148
+ /**
149
+ * @apidoc
150
+ * @brief Register a native view for the `LynxView`.
151
+ * @param tag_name The tag name of element, specifying exists tag name will
152
+ * override corresponding builtin element.
153
+ * @param opaque An opaque pointer to user-specific data.
154
+ */
155
+ template <typename T>
156
+ LynxView& RegisterNativeView(const std::string& tag_name,
157
+ void* opaque = nullptr) {
158
+ lynx_view_register_native_view(
159
+ lynx_view_, tag_name.c_str(),
160
+ [](void* opaque) -> lynx_native_view_t* {
161
+ return (new T(opaque))->native_view();
162
+ },
163
+ opaque);
164
+ return *this;
165
+ }
166
+
167
+ /**
168
+ * @apidoc
169
+ * @brief Register lifecycle event observer `LynxViewClient` for the
170
+ * `LynxView`.
171
+ * @param client The structure implemented by the client and registered to
172
+ * the `LynxView` instance is used to obtain the callbacks of each process
173
+ * in the `LynxView` lifecycle.
174
+ */
175
+ void AddClient(std::shared_ptr<LynxViewClient> client) {
176
+ if (std::find(lynx_view_clients_.begin(), lynx_view_clients_.end(),
177
+ client) == lynx_view_clients_.end()) {
178
+ lynx_view_add_client(lynx_view_, client->Impl());
179
+ lynx_view_clients_.emplace_back(client);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * @apidoc
185
+ * @brief Remove `LynxView` lifecycle event monitoring.
186
+ * @param client The structure implemented by the client and registered to the
187
+ * `LynxView` instance is used to obtain the callbacks of each process in the
188
+ * LynxView life cycle.
189
+ */
190
+ void RemoveClient(std::shared_ptr<LynxViewClient> client) {
191
+ lynx_view_remove_client(lynx_view_, client->Impl());
192
+ lynx_view_clients_.erase(std::remove(lynx_view_clients_.begin(),
193
+ lynx_view_clients_.end(), client),
194
+ lynx_view_clients_.end());
195
+ }
196
+
197
+ void RegisterRuntimeLifecycleObserver(
198
+ std::shared_ptr<LynxRuntimeLifecycleObserver> observer) {
199
+ observer->InitIfNeeded();
200
+ lynx_view_register_runtime_lifecycle_observer(lynx_view_, observer->Impl());
201
+ runtime_lifecycle_observer_ = observer;
202
+ }
203
+
204
+ /**
205
+ * @apidoc
206
+ * @brief Using `LynxLoadMeta` to render `LynxView`, it is the main entrance
207
+ * for the client to load `Lynx` templates.
208
+ * @param load_meta Lynx template loads metadata, and developers use this data
209
+ * structure to specify optional data loaded by the template.
210
+ */
211
+ void LoadTemplate(std::shared_ptr<LynxLoadMeta> load_meta) {
212
+ lynx_view_load_template(lynx_view_, load_meta->Impl());
213
+ }
214
+
215
+ /**
216
+ * @apidoc
217
+ * @brief Using `LynxUpdateMeta` to update `LynxView`, it is the main entrance
218
+ * for the client to update template data.
219
+ * @param meta Lynx template update metadata, developers use this data
220
+ * structure to specify the optional data content of the update template.
221
+ */
222
+ void UpdateData(std::shared_ptr<LynxUpdateMeta> update_meta) {
223
+ lynx_view_update_data(lynx_view_, update_meta->Impl());
224
+ }
225
+
226
+ /**
227
+ * @apidoc
228
+ * @brief Reload the `LynxView` template with new data.
229
+ * @param data The template data to be loaded.
230
+ * @param global_props The global properties of the template.
231
+ */
232
+ void ReloadTemplate(std::shared_ptr<LynxTemplateData> data,
233
+ std::shared_ptr<LynxTemplateData> global_props) {
234
+ lynx_view_reload_template(lynx_view_, data->Impl(),
235
+ global_props ? global_props->Impl() : nullptr);
236
+ }
237
+
238
+ /**
239
+ * @apidoc
240
+ * @brief Send global events to the front end through the client, and the
241
+ * front end can listen to the event through `GlobalEventEmitter`.
242
+ * @param name Global event name.
243
+ * @param params Parameters carried by global events.
244
+ */
245
+ void SendGlobalEvent(const std::string& name, const std::string& json) {
246
+ lynx_view_send_global_event(lynx_view_, name.c_str(), json.c_str());
247
+ }
248
+
249
+ void SendTouchEvent(const std::string& name, int32_t id, float x, float y,
250
+ float client_x, float client_y, float page_x,
251
+ float page_y) {
252
+ lynx_view_send_touch_event(lynx_view_, name.c_str(), id, x, y, client_x,
253
+ client_y, page_x, page_y);
254
+ }
255
+
256
+ int GetNodeForLocation(int x, int y) {
257
+ return lynx_view_get_node_for_location(lynx_view_, x, y);
258
+ }
259
+
260
+ void EmulateMouseEvent(const std::string& event_name, float x, float y,
261
+ float delta_x = 0.f, float delta_y = 0.f) {
262
+ lynx_view_emulate_mouse_event(lynx_view_, event_name.c_str(), x, y, delta_x,
263
+ delta_y);
264
+ }
265
+
266
+ /**
267
+ * @apidoc
268
+ * @brief Update the screen metrics of the `LynxView`.
269
+ * @param width The width of the screen.
270
+ * @param height The height of the screen.
271
+ * @param pixel_ratio The pixel ratio of the screen.
272
+ */
273
+ void UpdateScreenMetrics(float width, float height, float pixel_ratio) {
274
+ lynx_view_update_screen_metrics(lynx_view_, width, height, pixel_ratio);
275
+ }
276
+
277
+ /**
278
+ * @apidoc
279
+ * @brief Set the position and size of the `LynxView` in the window.
280
+ * @param x The x coordinate of the `LynxView` position.
281
+ * @param y The y coordinate of the `LynxView` position.
282
+ * @param width The width of the `LynxView`.
283
+ * @param height The height of the `LynxView`.
284
+ */
285
+ void SetFrame(float x, float y, float width, float height) {
286
+ lynx_view_set_frame(lynx_view_, x, y, width, height);
287
+ }
288
+
289
+ /**
290
+ * @apidoc
291
+ * @brief Changing the font scaling ratio in client settings will
292
+ * automatically change the text size.
293
+ * @param scale The new font scaling ratio.
294
+ */
295
+ void SetFontScale(float scale) {
296
+ lynx_view_set_font_scale(lynx_view_, scale);
297
+ }
298
+
299
+ /**
300
+ * @apidoc
301
+ * @brief Set the parent window of the `LynxView`.
302
+ * @param parent The parent window of the `LynxView`.
303
+ */
304
+ void SetParent(NativeWindow parent) {
305
+ lynx_view_set_parent(lynx_view_, parent);
306
+ }
307
+
308
+ NativeWindow GetNativeWindow() {
309
+ return lynx_view_get_native_window(lynx_view_);
310
+ }
311
+
312
+ /**
313
+ * @apidoc
314
+ * @brief Notify the `LynxView` that it has entered the foreground.
315
+ */
316
+ void OnEnterForeground() { lynx_view_enter_foreground(lynx_view_); }
317
+
318
+ /**
319
+ * @apidoc
320
+ * @brief Notify the `LynxView` that it has entered the background.
321
+ */
322
+ void OnEnterBackground() { lynx_view_enter_background(lynx_view_); }
323
+
324
+ void InjectBubbleEvent(const std::string& params) {
325
+ lynx_view_inject_bubble_event(lynx_view_, params.c_str());
326
+ }
327
+
328
+ void SetEventSimulationProxy(
329
+ std::shared_ptr<LynxEventSimulationProxy> proxy) {
330
+ event_proxy_ = std::move(proxy);
331
+ if (event_proxy_) {
332
+ lynx_view_set_event_simulation_proxy(
333
+ lynx_view_,
334
+ [](void* ctx, const char* event_type, int x, int y,
335
+ const char* button, float delta_x, float delta_y, int modifiers,
336
+ int click_count) {
337
+ static_cast<LynxEventSimulationProxy*>(ctx)->EmulateTouch(
338
+ event_type, x, y, button, delta_x, delta_y, modifiers,
339
+ click_count);
340
+ },
341
+ event_proxy_.get());
342
+ } else {
343
+ lynx_view_set_event_simulation_proxy(lynx_view_, nullptr, nullptr);
344
+ }
345
+ }
346
+
347
+ lynx_view_t* Impl() { return lynx_view_; }
348
+
349
+ LynxView(const LynxView&) = delete;
350
+ LynxView& operator=(const LynxView&) = delete;
351
+
352
+ private:
353
+ lynx_view_t* lynx_view_;
354
+ std::shared_ptr<LynxGenericResourceFetcher> generic_fetcher_;
355
+ std::vector<std::shared_ptr<LynxViewClient>> lynx_view_clients_;
356
+ std::shared_ptr<LynxWindowlessRenderer> windowless_renderer_;
357
+ std::shared_ptr<LynxRuntimeLifecycleObserver> runtime_lifecycle_observer_;
358
+ std::shared_ptr<LynxEventSimulationProxy> event_proxy_;
359
+ };
360
+
361
+ } // namespace pub
362
+ } // namespace lynx
363
+
364
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_VIEW_H_