@elurjs/android 0.0.0-stage → 0.2.0

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 (145) hide show
  1. package/README.md +10 -2
  2. package/index.mjs +11 -0
  3. package/package.json +29 -4
  4. package/template/.gitkeep +0 -0
  5. package/template/app/build.gradle.kts +192 -0
  6. package/template/app/proguard-rules-elur.pro +12 -0
  7. package/template/app/proguard-rules.pro +3 -0
  8. package/template/app/src/main/AndroidManifest.xml +81 -0
  9. package/template/app/src/main/assets/oss-notices.txt +153 -0
  10. package/template/app/src/main/assets/tck_pixel.png +0 -0
  11. package/template/app/src/main/cpp/CMakeLists.txt +117 -0
  12. package/template/app/src/main/cpp/dlEncoder.h +117 -0
  13. package/template/app/src/main/cpp/dlEncoderJsi.cpp +315 -0
  14. package/template/app/src/main/cpp/dlEncoderQjs.cpp +394 -0
  15. package/template/app/src/main/cpp/dlOps.inc +145 -0
  16. package/template/app/src/main/cpp/elurBridge.cpp +1350 -0
  17. package/template/app/src/main/cpp/elurBridgeHermes.cpp +1294 -0
  18. package/template/app/src/main/cpp/elurSkia.cpp +287 -0
  19. package/template/app/src/main/cpp/elurSkiaTree.cpp +448 -0
  20. package/template/app/src/main/cpp/elurUiWorklet.cpp +1233 -0
  21. package/template/app/src/main/cpp/elurYoga.cpp +1060 -0
  22. package/template/app/src/main/cpp/elurYoga.h +82 -0
  23. package/template/app/src/main/cpp/hermes-libs/LICENSE +21 -0
  24. package/template/app/src/main/cpp/hermes-libs/arm64-v8a/libhermesvm.so +0 -0
  25. package/template/app/src/main/cpp/hermes-libs/include/hermes/AsyncDebuggerAPI.h +276 -0
  26. package/template/app/src/main/cpp/hermes-libs/include/hermes/CompileJS.h +97 -0
  27. package/template/app/src/main/cpp/hermes-libs/include/hermes/DebuggerAPI.h +502 -0
  28. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CrashManager.h +107 -0
  29. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CtorConfig.h +145 -0
  30. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/DebuggerTypes.h +193 -0
  31. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCConfig.h +211 -0
  32. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCTripwireContext.h +40 -0
  33. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/HermesExport.h +14 -0
  34. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/JSOutOfMemoryError.h +27 -0
  35. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/RuntimeConfig.h +141 -0
  36. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/SamplingProfiler.h +270 -0
  37. package/template/app/src/main/cpp/hermes-libs/include/hermes/RuntimeTaskRunner.h +64 -0
  38. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTrace.h +1566 -0
  39. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTraceParser.h +37 -0
  40. package/template/app/src/main/cpp/hermes-libs/include/hermes/ThreadSafetyAnalysis.h +75 -0
  41. package/template/app/src/main/cpp/hermes-libs/include/hermes/TimerStats.h +23 -0
  42. package/template/app/src/main/cpp/hermes-libs/include/hermes/TraceInterpreter.h +334 -0
  43. package/template/app/src/main/cpp/hermes-libs/include/hermes/TracingRuntime.h +328 -0
  44. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPAgent.h +131 -0
  45. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPDebugAPI.h +73 -0
  46. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CallbackOStream.h +89 -0
  47. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ConsoleMessage.h +135 -0
  48. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainAgent.h +280 -0
  49. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainCoordinator.h +137 -0
  50. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainAgent.h +107 -0
  51. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainState.h +140 -0
  52. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/HeapProfilerDomainAgent.h +71 -0
  53. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/JSONValueInterfaces.h +40 -0
  54. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageConverters.h +82 -0
  55. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageInterfaces.h +72 -0
  56. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypes.h +1279 -0
  57. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypesInlines.h +313 -0
  58. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ProfilerDomainAgent.h +38 -0
  59. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectConverters.h +77 -0
  60. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectsTable.h +127 -0
  61. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RuntimeDomainAgent.h +138 -0
  62. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Dummy.h +24 -0
  63. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Extensions.h +20 -0
  64. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/ExtensionsBytecode.h +23 -0
  65. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Intrinsics.h +44 -0
  66. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/JSIUtils.h +123 -0
  67. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/TextEncoder.h +29 -0
  68. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribDummy.h +24 -0
  69. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribExtensions.h +23 -0
  70. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoder.h +30 -0
  71. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoderUtils.h +113 -0
  72. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes.h +242 -0
  73. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes_tracing.h +52 -0
  74. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIHelpers.h +295 -0
  75. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIRuntimeWrapper.h +25 -0
  76. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_abi.h +642 -0
  77. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_vtable.h +29 -0
  78. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/HermesSandboxRuntime.h +41 -0
  79. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_compiled.h +12 -0
  80. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled-impl.h +8516 -0
  81. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled.h +137 -0
  82. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled-impl.h +3945 -0
  83. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled.h +119 -0
  84. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-fb.h +124 -0
  85. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-impl.h +66 -0
  86. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt.h +456 -0
  87. package/template/app/src/main/cpp/hermes-libs/include/jsi/JSIDynamic.h +26 -0
  88. package/template/app/src/main/cpp/hermes-libs/include/jsi/decorator.h +1157 -0
  89. package/template/app/src/main/cpp/hermes-libs/include/jsi/hermes-interfaces.h +242 -0
  90. package/template/app/src/main/cpp/hermes-libs/include/jsi/instrumentation.h +132 -0
  91. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi-inl.h +434 -0
  92. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi.h +2266 -0
  93. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsilib.h +59 -0
  94. package/template/app/src/main/cpp/hermes-libs/include/jsi/threadsafe.h +79 -0
  95. package/template/app/src/main/cpp/hermes-libs/jsi-impl/jsi.cpp +1111 -0
  96. package/template/app/src/main/cpp/hermes-libs/x86_64/libhermesvm.so +0 -0
  97. package/template/app/src/main/java/com/elur/universal/BinaryCodec.kt +121 -0
  98. package/template/app/src/main/java/com/elur/universal/DlDecoder.kt +260 -0
  99. package/template/app/src/main/java/com/elur/universal/DlOpsDecode.kt +158 -0
  100. package/template/app/src/main/java/com/elur/universal/ElurBoxDrawable.kt +161 -0
  101. package/template/app/src/main/java/com/elur/universal/ElurBridge.kt +238 -0
  102. package/template/app/src/main/java/com/elur/universal/ElurBridgeHermes.kt +223 -0
  103. package/template/app/src/main/java/com/elur/universal/ElurCanvasView.kt +202 -0
  104. package/template/app/src/main/java/com/elur/universal/ElurCryptoModule.kt +206 -0
  105. package/template/app/src/main/java/com/elur/universal/ElurCustomLayout.kt +185 -0
  106. package/template/app/src/main/java/com/elur/universal/ElurEditText.kt +17 -0
  107. package/template/app/src/main/java/com/elur/universal/ElurFontRegistry.kt +190 -0
  108. package/template/app/src/main/java/com/elur/universal/ElurHttpModule.kt +306 -0
  109. package/template/app/src/main/java/com/elur/universal/ElurImageService.kt +348 -0
  110. package/template/app/src/main/java/com/elur/universal/ElurLicensesActivity.kt +84 -0
  111. package/template/app/src/main/java/com/elur/universal/ElurListView.kt +954 -0
  112. package/template/app/src/main/java/com/elur/universal/ElurManifest.kt +117 -0
  113. package/template/app/src/main/java/com/elur/universal/ElurMetrics.kt +325 -0
  114. package/template/app/src/main/java/com/elur/universal/ElurModuleRegistrar.kt +14 -0
  115. package/template/app/src/main/java/com/elur/universal/ElurPermissionGate.kt +36 -0
  116. package/template/app/src/main/java/com/elur/universal/ElurRenderer.kt +6164 -0
  117. package/template/app/src/main/java/com/elur/universal/ElurRowYoga.kt +130 -0
  118. package/template/app/src/main/java/com/elur/universal/ElurScrollView.kt +240 -0
  119. package/template/app/src/main/java/com/elur/universal/ElurShellView.kt +117 -0
  120. package/template/app/src/main/java/com/elur/universal/ElurSkiaCanvasView.kt +162 -0
  121. package/template/app/src/main/java/com/elur/universal/ElurSkiaTreeRenderer.kt +968 -0
  122. package/template/app/src/main/java/com/elur/universal/ElurStateModule.kt +69 -0
  123. package/template/app/src/main/java/com/elur/universal/ElurSwipeDriver.kt +34 -0
  124. package/template/app/src/main/java/com/elur/universal/ElurTckModule.kt +99 -0
  125. package/template/app/src/main/java/com/elur/universal/ElurTextMeasure.kt +16 -0
  126. package/template/app/src/main/java/com/elur/universal/ElurTrace.kt +24 -0
  127. package/template/app/src/main/java/com/elur/universal/ElurUiModule.kt +48 -0
  128. package/template/app/src/main/java/com/elur/universal/ElurUiWorklet.kt +305 -0
  129. package/template/app/src/main/java/com/elur/universal/JsBridge.kt +67 -0
  130. package/template/app/src/main/java/com/elur/universal/JsThread.kt +189 -0
  131. package/template/app/src/main/java/com/elur/universal/MainActivity.kt +844 -0
  132. package/template/app/src/main/java/com/elur/universal/ModuleRegistry.kt +701 -0
  133. package/template/app/src/main/java/com/elur/universal/YogaRowScope.kt +97 -0
  134. package/template/app/src/main/res/values/ids.xml +10 -0
  135. package/template/app/src/main/res/values/strings.xml +8 -0
  136. package/template/app/src/main/res/values-es/strings.xml +5 -0
  137. package/template/app/src/main/res/xml/network_security_config.xml +10 -0
  138. package/template/build.gradle.kts +5 -0
  139. package/template/gradle/libs.versions.toml +12 -0
  140. package/template/gradle/wrapper/gradle-wrapper.jar +0 -0
  141. package/template/gradle/wrapper/gradle-wrapper.properties +8 -0
  142. package/template/gradle.properties +23 -0
  143. package/template/gradlew +251 -0
  144. package/template/gradlew.bat +94 -0
  145. package/template/settings.gradle.kts +32 -0
@@ -0,0 +1,394 @@
1
+ // dlEncoderQjs.cpp — walker QuickJS del Display List binario (ABI v2)
2
+ // Equivalente byte-exacto a encodeDisplayList() de src/transport/format.ts.
3
+ // JSON de style/props via JSON.stringify del propio contexto.
4
+
5
+ #include "dlEncoder.h"
6
+ #include "elurYoga.h"
7
+ #include "quickjs.h"
8
+ #include <string>
9
+
10
+ namespace elur {
11
+
12
+ static std::string propStr(JSContext *ctx, JSValueConst o, const char *name) {
13
+ JSValue v = JS_GetPropertyStr(ctx, o, name);
14
+ const char *s = JS_ToCString(ctx, v);
15
+ std::string out = s ? s : "";
16
+ JS_FreeCString(ctx, s);
17
+ JS_FreeValue(ctx, v);
18
+ return out;
19
+ }
20
+
21
+ static int32_t propI32(JSContext *ctx, JSValueConst o, const char *name) {
22
+ JSValue v = JS_GetPropertyStr(ctx, o, name);
23
+ int32_t n = 0;
24
+ JS_ToInt32(ctx, &n, v);
25
+ JS_FreeValue(ctx, v);
26
+ return n;
27
+ }
28
+
29
+ static bool propBool(JSContext *ctx, JSValueConst o, const char *name) {
30
+ JSValue v = JS_GetPropertyStr(ctx, o, name);
31
+ int b = JS_ToBool(ctx, v);
32
+ JS_FreeValue(ctx, v);
33
+ return b != 0;
34
+ }
35
+
36
+ static std::string jsonStringify(JSContext *ctx, JSValueConst v) {
37
+ JSValue global = JS_GetGlobalObject(ctx);
38
+ JSValue json = JS_GetPropertyStr(ctx, global, "JSON");
39
+ JSValue stringify = JS_GetPropertyStr(ctx, json, "stringify");
40
+ JSValue r = JS_Call(ctx, stringify, json, 1, &v);
41
+ // stringify puede lanzar (circular, BigInt, OOM): la excepción queda
42
+ // armada en el runtime aunque devolvamos "" — consumirla aquí o
43
+ // contamina el siguiente JS_Call con un error ajeno y tardío.
44
+ if (JS_IsException(r)) {
45
+ JSValue exc = JS_GetException(ctx);
46
+ JS_FreeValue(ctx, exc);
47
+ }
48
+ const char *s = JS_IsString(r) ? JS_ToCString(ctx, r) : nullptr;
49
+ std::string out = s ? s : "";
50
+ JS_FreeCString(ctx, s);
51
+ JS_FreeValue(ctx, r);
52
+ JS_FreeValue(ctx, stringify);
53
+ JS_FreeValue(ctx, json);
54
+ JS_FreeValue(ctx, global);
55
+ return out;
56
+ }
57
+
58
+ // ABI v5 (ADR-0050): style como entradas tipadas — i32 count +
59
+ // [str16 key · u8 tag · f64|str16|∅]. El objeto Style solo admite
60
+ // number|string|null — no hay JSON embebido en el camino caliente.
61
+ static void encodeStyleQjs(JSContext *ctx, JSValueConst style, DLBuf &w) {
62
+ JSPropertyEnum *ptab = nullptr;
63
+ uint32_t plen = 0;
64
+ if (!JS_IsObject(style) ||
65
+ JS_GetOwnPropertyNames(ctx, &ptab, &plen, style,
66
+ JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) {
67
+ w.i32(0);
68
+ return;
69
+ }
70
+ w.i32(static_cast<int32_t>(plen));
71
+ for (uint32_t i = 0; i < plen; i++) {
72
+ JSAtom atom = ptab[i].atom;
73
+ JSValue kval = JS_AtomToValue(ctx, atom);
74
+ const char *kstr = JS_ToCString(ctx, kval);
75
+ w.str16(kstr ? kstr : "");
76
+ JS_FreeCString(ctx, kstr);
77
+ JS_FreeValue(ctx, kval);
78
+ JSValue v = JS_GetProperty(ctx, style, atom);
79
+ if (JS_IsNumber(v)) {
80
+ double d = 0;
81
+ JS_ToFloat64(ctx, &d, v);
82
+ w.u8(0);
83
+ w.f64(d);
84
+ } else if (JS_IsString(v)) {
85
+ const char *s = JS_ToCString(ctx, v);
86
+ w.u8(1);
87
+ w.str16(s ? s : "");
88
+ JS_FreeCString(ctx, s);
89
+ } else {
90
+ w.u8(2); // null/undefined/otro → retirada de la clave
91
+ }
92
+ JS_FreeValue(ctx, v);
93
+ }
94
+ JS_FreePropertyEnum(ctx, ptab, plen);
95
+ }
96
+
97
+ // ADR-0108 — entries de update-semantics: idéntico a encodeStyleQjs +
98
+ // tag 3 = bool(u8) — el vocabulario a11y es mayormente flags.
99
+ static void encodeSemanticsQjs(JSContext *ctx, JSValueConst sem, DLBuf &w) {
100
+ JSPropertyEnum *ptab = nullptr;
101
+ uint32_t plen = 0;
102
+ if (!JS_IsObject(sem) ||
103
+ JS_GetOwnPropertyNames(ctx, &ptab, &plen, sem,
104
+ JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) {
105
+ w.i32(0);
106
+ return;
107
+ }
108
+ w.i32(static_cast<int32_t>(plen));
109
+ for (uint32_t i = 0; i < plen; i++) {
110
+ JSAtom atom = ptab[i].atom;
111
+ JSValue kval = JS_AtomToValue(ctx, atom);
112
+ const char *kstr = JS_ToCString(ctx, kval);
113
+ w.str16(kstr ? kstr : "");
114
+ JS_FreeCString(ctx, kstr);
115
+ JS_FreeValue(ctx, kval);
116
+ JSValue v = JS_GetProperty(ctx, sem, atom);
117
+ if (JS_IsBool(v)) {
118
+ w.u8(3);
119
+ w.u8(JS_ToBool(ctx, v) ? 1 : 0);
120
+ } else if (JS_IsNumber(v)) {
121
+ double d = 0;
122
+ JS_ToFloat64(ctx, &d, v);
123
+ w.u8(0);
124
+ w.f64(d);
125
+ } else if (JS_IsString(v)) {
126
+ const char *s = JS_ToCString(ctx, v);
127
+ w.u8(1);
128
+ w.str16(s ? s : "");
129
+ JS_FreeCString(ctx, s);
130
+ } else {
131
+ w.u8(2); // null/undefined/otro → retirada de la clave
132
+ }
133
+ JS_FreeValue(ctx, v);
134
+ }
135
+ JS_FreePropertyEnum(ctx, ptab, plen);
136
+ }
137
+
138
+ static uint8_t transitionCode(JSContext *ctx, JSValueConst op) {
139
+ JSValue t = JS_GetPropertyStr(ctx, op, "transition");
140
+ uint8_t code = 0;
141
+ if (JS_IsObject(t)) {
142
+ std::string kind = propStr(ctx, t, "kind");
143
+ if (kind == "none")
144
+ code = 1;
145
+ else if (kind == "custom")
146
+ code = 2;
147
+ }
148
+ JS_FreeValue(ctx, t);
149
+ return code;
150
+ }
151
+
152
+ // ADR-0032: estado post-commit autoritativo de las ops nav-*
153
+ // (u16 depth · u8 navV · u8 n · str16 stack[n]).
154
+ static void navStateQjs(JSContext *ctx, JSValueConst op, DLBuf &w) {
155
+ w.u16(static_cast<uint32_t>(propI32(ctx, op, "depth")));
156
+ w.u8(static_cast<uint8_t>(propI32(ctx, op, "v")));
157
+ JSValue stack = JS_GetPropertyStr(ctx, op, "stack");
158
+ int64_t n = 0;
159
+ if (JS_IsArray(stack)) {
160
+ JSValue lv = JS_GetPropertyStr(ctx, stack, "length");
161
+ JS_ToInt64(ctx, &n, lv);
162
+ JS_FreeValue(ctx, lv);
163
+ }
164
+ // >0xff no cabe en el prefijo u8: fail-fast — truncar escribiría más
165
+ // str16 de los que el decoder lee (espejo del guard de format.ts).
166
+ if (n > 0xff) {
167
+ JS_FreeValue(ctx, stack);
168
+ throw std::overflow_error("navState stack overflow");
169
+ }
170
+ w.u8(static_cast<uint8_t>(n));
171
+ for (int64_t i = 0; i < n; i++) {
172
+ JSValue e = JS_GetPropertyUint32(ctx, stack, static_cast<uint32_t>(i));
173
+ const char *s = JS_ToCString(ctx, e);
174
+ w.str16(s ? s : "");
175
+ JS_FreeCString(ctx, s);
176
+ JS_FreeValue(ctx, e);
177
+ }
178
+ JS_FreeValue(ctx, stack);
179
+ }
180
+
181
+ static void encodeOpQjs(JSContext *ctx, JSValueConst op, DLBuf &w);
182
+ static void encodeOpsQjs(JSContext *ctx, JSValueConst ops, DLBuf &w);
183
+
184
+ // ADR-0119 — adaptador Obj del vocabulario wire generado (dlOps.inc):
185
+ // la tabla canónica wireSchema define op→campos; este adaptador es lo
186
+ // único engine-specific (cómo leer props de un JSValue).
187
+ class ObjQjs {
188
+ JSContext *ctx;
189
+ JSValueConst v;
190
+
191
+ public:
192
+ ObjQjs(JSContext *c, JSValueConst o) : ctx(c), v(o) {}
193
+ bool isStr(const char *n) const {
194
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
195
+ bool r = JS_IsString(p);
196
+ JS_FreeValue(ctx, p);
197
+ return r;
198
+ }
199
+ bool isObj(const char *n) const {
200
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
201
+ bool r = JS_IsObject(p);
202
+ JS_FreeValue(ctx, p);
203
+ return r;
204
+ }
205
+ bool isArr(const char *n) const {
206
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
207
+ bool r = JS_IsArray(p);
208
+ JS_FreeValue(ctx, p);
209
+ return r;
210
+ }
211
+ int32_t i32(const char *n) const { return propI32(ctx, v, n); }
212
+ double num(const char *n) const {
213
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
214
+ double d = 0;
215
+ JS_ToFloat64(ctx, &d, p);
216
+ JS_FreeValue(ctx, p);
217
+ return d;
218
+ }
219
+ bool b(const char *n) const { return propBool(ctx, v, n); }
220
+ std::string s(const char *n) const { return propStr(ctx, v, n); }
221
+ std::string json(const char *n) const {
222
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
223
+ std::string r = jsonStringify(ctx, p);
224
+ JS_FreeValue(ctx, p);
225
+ return r;
226
+ }
227
+ void entries(const char *n, bool sem, DLBuf &w) const {
228
+ JSValue p = JS_GetPropertyStr(ctx, v, n);
229
+ if (sem)
230
+ encodeSemanticsQjs(ctx, p, w);
231
+ else
232
+ encodeStyleQjs(ctx, p, w);
233
+ JS_FreeValue(ctx, p);
234
+ }
235
+ void navState(DLBuf &w) const { navStateQjs(ctx, v, w); }
236
+ // ABI v11 (ADR-0165): u8 kind; custom(2) → str32 JSON del spec
237
+ // resuelto (name + duration? + def?).
238
+ void transition(DLBuf &w) const {
239
+ uint8_t code = elur::transitionCode(ctx, v);
240
+ w.u8(code);
241
+ if (code == 2) {
242
+ JSValue t = JS_GetPropertyStr(ctx, v, "transition");
243
+ w.str32(jsonStringify(ctx, t));
244
+ JS_FreeValue(ctx, t);
245
+ }
246
+ }
247
+ };
248
+
249
+ static void encodeOpsQjs(JSContext *ctx, JSValueConst ops, DLBuf &w) {
250
+ JSValue lv = JS_GetPropertyStr(ctx, ops, "length");
251
+ int64_t n = 0;
252
+ JS_ToInt64(ctx, &n, lv);
253
+ JS_FreeValue(ctx, lv);
254
+ for (int64_t i = 0; i < n; i++) {
255
+ JSValue v = JS_GetPropertyUint32(ctx, ops, static_cast<uint32_t>(i));
256
+ if (JS_IsObject(v))
257
+ encodeOpQjs(ctx, v, w);
258
+ JS_FreeValue(ctx, v);
259
+ }
260
+ }
261
+
262
+ static void encodeOpQjs(JSContext *ctx, JSValueConst op, DLBuf &w) {
263
+ const std::string kind = propStr(ctx, op, "op");
264
+ // batch-update: contenedor JS-side — se expande a hojas, no viaja.
265
+ if (kind == "batch-update") {
266
+ JSValue inner = JS_GetPropertyStr(ctx, op, "ops");
267
+ if (JS_IsArray(inner))
268
+ encodeOpsQjs(ctx, inner, w);
269
+ JS_FreeValue(ctx, inner);
270
+ return;
271
+ }
272
+ // ADR-0119: emit por op derivado del esquema canónico (dlOps.inc).
273
+ ObjQjs o(ctx, op);
274
+ #include "dlOps.inc"
275
+ }
276
+
277
+ // Cuenta ops reales tras expandir batch-update recursivamente (header
278
+ // opCount) — espejo de countExpandedOps en src/transport/format.ts: el
279
+ // contenedor no viaja al wire, solo sus hojas; un batch anidado cuenta
280
+ // sus propias hojas, no 1 (U15).
281
+ static int32_t countOpsQjs(JSContext *ctx, JSValueConst ops) {
282
+ JSValue lv = JS_GetPropertyStr(ctx, ops, "length");
283
+ int64_t size = 0;
284
+ JS_ToInt64(ctx, &size, lv);
285
+ JS_FreeValue(ctx, lv);
286
+ int32_t n = 0;
287
+ for (int64_t i = 0; i < size; i++) {
288
+ JSValue v = JS_GetPropertyUint32(ctx, ops, static_cast<uint32_t>(i));
289
+ if (JS_IsObject(v) && propStr(ctx, v, "op") == "batch-update") {
290
+ JSValue inner = JS_GetPropertyStr(ctx, v, "ops");
291
+ if (JS_IsArray(inner))
292
+ n += countOpsQjs(ctx, inner);
293
+ JS_FreeValue(ctx, inner);
294
+ } else if (JS_IsObject(v)) {
295
+ n++;
296
+ }
297
+ JS_FreeValue(ctx, v);
298
+ }
299
+ return n;
300
+ }
301
+
302
+ // P1-TREE: el árbol Yoga observa el stream de ops (estructura + style).
303
+ static void yogaObserveOpQjs(JSContext *ctx, JSValueConst op) {
304
+ const std::string kind = propStr(ctx, op, "op");
305
+ if (kind == "create-node") {
306
+ yogaCreateNode(propI32(ctx, op, "id"), propStr(ctx, op, "type"));
307
+ } else if (kind == "create-platform-view") {
308
+ yogaCreateNode(propI32(ctx, op, "id"), "platform-view");
309
+ } else if (kind == "insert-child") {
310
+ yogaInsertChild(propI32(ctx, op, "parentId"), propI32(ctx, op, "childId"),
311
+ propI32(ctx, op, "index"));
312
+ } else if (kind == "remove-child") {
313
+ yogaRemoveChild(propI32(ctx, op, "parentId"), propI32(ctx, op, "childId"));
314
+ } else if (kind == "move-child") {
315
+ yogaMoveChild(propI32(ctx, op, "parentId"), propI32(ctx, op, "childId"),
316
+ propI32(ctx, op, "index"));
317
+ } else if (kind == "delete-node") {
318
+ yogaDeleteNode(propI32(ctx, op, "id"));
319
+ } else if (kind == "update-style") {
320
+ int id = propI32(ctx, op, "id");
321
+ JSValue style = JS_GetPropertyStr(ctx, op, "style");
322
+ if (JS_IsObject(style)) {
323
+ JSPropertyEnum *props = nullptr;
324
+ uint32_t plen = 0;
325
+ if (JS_GetOwnPropertyNames(ctx, &props, &plen, style,
326
+ JS_GPN_STRING_MASK) == 0) {
327
+ for (uint32_t i = 0; i < plen; i++) {
328
+ JSValue key = JS_AtomToValue(ctx, props[i].atom);
329
+ const char *ks = JS_ToCString(ctx, key);
330
+ JSValue val = JS_GetProperty(ctx, style, props[i].atom);
331
+ if (JS_IsNumber(val)) {
332
+ double d = 0;
333
+ JS_ToFloat64(ctx, &d, val);
334
+ yogaSetStyle(id, ks ? ks : "", d, "", true);
335
+ } else if (JS_IsString(val)) {
336
+ const char *vs = JS_ToCString(ctx, val);
337
+ yogaSetStyle(id, ks ? ks : "", 0, vs ? vs : "", false);
338
+ JS_FreeCString(ctx, vs);
339
+ } else if (JS_IsNull(val) || JS_IsUndefined(val)) {
340
+ // ADR-0122: null/undefined = valor ausente — viaja como str
341
+ // vacío: `layout` lo toma como off, el resto no-op.
342
+ yogaSetStyle(id, ks ? ks : "", 0, "", false);
343
+ }
344
+ JS_FreeValue(ctx, val);
345
+ JS_FreeCString(ctx, ks);
346
+ JS_FreeValue(ctx, key);
347
+ }
348
+ JS_FreePropertyEnum(ctx, props, plen);
349
+ }
350
+ }
351
+ JS_FreeValue(ctx, style);
352
+ } else if (kind == "batch-update") {
353
+ JSValue inner = JS_GetPropertyStr(ctx, op, "ops");
354
+ if (JS_IsArray(inner)) {
355
+ JSValue lv = JS_GetPropertyStr(ctx, inner, "length");
356
+ int64_t n = 0;
357
+ JS_ToInt64(ctx, &n, lv);
358
+ JS_FreeValue(ctx, lv);
359
+ for (int64_t i = 0; i < n; i++) {
360
+ JSValue v = JS_GetPropertyUint32(ctx, inner, static_cast<uint32_t>(i));
361
+ if (JS_IsObject(v))
362
+ yogaObserveOpQjs(ctx, v);
363
+ JS_FreeValue(ctx, v);
364
+ }
365
+ }
366
+ JS_FreeValue(ctx, inner);
367
+ }
368
+ }
369
+
370
+ } // namespace elur
371
+
372
+ // API pública del encoder quickjs — usada por elurBridge.cpp.
373
+ void elurEncodeFrameQjs(JSContext *ctx, int32_t frame, JSValueConst ops,
374
+ elur::DLBuf &w) {
375
+ w.header(frame, elur::countOpsQjs(ctx, ops));
376
+ elur::encodeOpsQjs(ctx, ops, w);
377
+ }
378
+
379
+ // Observa ops → árbol Yoga C++ y, si dirty + viewport, emite ops layout
380
+ // al final del frame (P1-TREE).
381
+ void elurYogaObserveAndLayoutQjs(JSContext *ctx, JSValueConst ops,
382
+ elur::DLBuf &buf) {
383
+ JSValue lv = JS_GetPropertyStr(ctx, ops, "length");
384
+ int64_t n = 0;
385
+ JS_ToInt64(ctx, &n, lv);
386
+ JS_FreeValue(ctx, lv);
387
+ for (int64_t i = 0; i < n; i++) {
388
+ JSValue v = JS_GetPropertyUint32(ctx, ops, static_cast<uint32_t>(i));
389
+ if (JS_IsObject(v))
390
+ elur::yogaObserveOpQjs(ctx, v);
391
+ JS_FreeValue(ctx, v);
392
+ }
393
+ buf.addOpCount(elur::yogaLayoutIfDirty(buf));
394
+ }
@@ -0,0 +1,145 @@
1
+ // Generated by cli/gen-wire-codec.mjs — do not edit.
2
+ // Emit del vocabulario wire — el call-site define kind/o/w.
3
+ // o = adaptador Obj del engine (dlEncoderQjs/dlEncoderJsi).
4
+
5
+ if (kind == "create-node") {
6
+ w.u8(1);
7
+ w.i32(o.i32("id"));
8
+ w.str16(o.s("type"));
9
+ }
10
+ else if (kind == "update-text") {
11
+ w.u8(2);
12
+ w.i32(o.i32("id"));
13
+ w.str32(o.s("value"));
14
+ }
15
+ else if (kind == "update-style") {
16
+ w.u8(3);
17
+ w.i32(o.i32("id"));
18
+ o.entries("style", false, w);
19
+ }
20
+ else if (kind == "update-props") {
21
+ w.u8(4);
22
+ w.i32(o.i32("id"));
23
+ w.str32(o.json("changedProps"));
24
+ }
25
+ else if (kind == "insert-child") {
26
+ w.u8(5);
27
+ w.i32(o.i32("parentId"));
28
+ w.i32(o.i32("childId"));
29
+ w.i32(o.i32("index"));
30
+ }
31
+ else if (kind == "remove-child") {
32
+ w.u8(6);
33
+ w.i32(o.i32("parentId"));
34
+ w.i32(o.i32("childId"));
35
+ }
36
+ else if (kind == "move-child") {
37
+ w.u8(7);
38
+ w.i32(o.i32("parentId"));
39
+ w.i32(o.i32("childId"));
40
+ w.i32(o.i32("index"));
41
+ }
42
+ else if (kind == "delete-node") {
43
+ w.u8(8);
44
+ w.i32(o.i32("id"));
45
+ }
46
+ else if (kind == "attach-event") {
47
+ w.u8(9);
48
+ w.i32(o.i32("id"));
49
+ w.str16(o.s("event"));
50
+ w.str16(o.s("handler"));
51
+ w.u8(o.s("class") == "continuous" ? 1 : 0);
52
+ if (o.isStr("payload")) { w.u8(1); w.str32(o.s("payload")); } else { w.u8(0); }
53
+ }
54
+ else if (kind == "detach-event") {
55
+ w.u8(10);
56
+ w.i32(o.i32("id"));
57
+ w.str16(o.s("event"));
58
+ }
59
+ else if (kind == "nav-push") {
60
+ w.u8(11);
61
+ w.str16(o.s("shellId"));
62
+ w.str16(o.s("entryId"));
63
+ o.transition(w);
64
+ o.navState(w);
65
+ }
66
+ else if (kind == "nav-pop") {
67
+ w.u8(12);
68
+ w.str16(o.s("shellId"));
69
+ w.str16(o.s("entryId"));
70
+ o.transition(w);
71
+ o.navState(w);
72
+ }
73
+ else if (kind == "nav-replace") {
74
+ w.u8(13);
75
+ w.str16(o.s("shellId"));
76
+ w.str16(o.s("fromId"));
77
+ w.str16(o.s("toId"));
78
+ o.transition(w);
79
+ o.navState(w);
80
+ }
81
+ else if (kind == "create-platform-view") {
82
+ w.u8(14);
83
+ w.i32(o.i32("id"));
84
+ w.str16(o.s("module"));
85
+ w.str16(o.s("view"));
86
+ w.str32(o.isObj("props") ? o.json("props") : "");
87
+ }
88
+ else if (kind == "update-platform-view-props") {
89
+ w.u8(15);
90
+ w.i32(o.i32("id"));
91
+ w.str32(o.json("changedProps"));
92
+ }
93
+ else if (kind == "set-platform-view-visible") {
94
+ w.u8(16);
95
+ w.i32(o.i32("id"));
96
+ w.u8(o.b("visible") ? 1 : 0);
97
+ }
98
+ else if (kind == "layout") {
99
+ w.u8(17);
100
+ w.i32(o.i32("id"));
101
+ w.f32(static_cast<float>(o.num("x")));
102
+ w.f32(static_cast<float>(o.num("y")));
103
+ w.f32(static_cast<float>(o.num("w")));
104
+ w.f32(static_cast<float>(o.num("h")));
105
+ }
106
+ else if (kind == "set-list-template") {
107
+ w.u8(18);
108
+ w.i32(o.i32("id"));
109
+ w.f64(o.num("rowHeight"));
110
+ w.str32(o.json("template"));
111
+ }
112
+ else if (kind == "set-list-items") {
113
+ w.u8(19);
114
+ w.i32(o.i32("id"));
115
+ w.str32(o.json("items"));
116
+ }
117
+ else if (kind == "list-splice") {
118
+ w.u8(20);
119
+ w.i32(o.i32("id"));
120
+ w.i32(o.i32("index"));
121
+ w.i32(o.i32("removeCount"));
122
+ w.str32(o.isArr("items") ? o.json("items") : "");
123
+ }
124
+ else if (kind == "list-update") {
125
+ w.u8(21);
126
+ w.i32(o.i32("id"));
127
+ w.str16(o.s("key"));
128
+ w.str32(o.json("fields"));
129
+ w.str32(o.isArr("removed") ? o.json("removed") : "[]");
130
+ }
131
+ else if (kind == "list-move") {
132
+ w.u8(22);
133
+ w.i32(o.i32("id"));
134
+ w.i32(o.i32("from"));
135
+ w.i32(o.i32("to"));
136
+ }
137
+ else if (kind == "reset-node") {
138
+ w.u8(23);
139
+ w.i32(o.i32("id"));
140
+ }
141
+ else if (kind == "update-semantics") {
142
+ w.u8(24);
143
+ w.i32(o.i32("id"));
144
+ o.entries("semantics", true, w);
145
+ }