@elurjs/universal 0.1.9 → 0.1.11

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 (58) hide show
  1. package/cli/create-app.mjs +15 -8
  2. package/cli/dev.mjs +45 -16
  3. package/cli/doctor.mjs +40 -14
  4. package/cli/elur.mjs +18 -4
  5. package/docs/INSTALACION-Y-DEV.md +13 -6
  6. package/package.json +5 -1
  7. package/targets/linux/CMakeLists.txt +196 -0
  8. package/targets/linux/README.md +422 -0
  9. package/targets/linux/ci/tsan.supp +15 -0
  10. package/targets/linux/generated/elur_module_registrar.cpp +14 -0
  11. package/targets/linux/generated/module_sources.cmake +5 -0
  12. package/targets/linux/src/elur_applicator.cpp +5073 -0
  13. package/targets/linux/src/elur_applicator.h +387 -0
  14. package/targets/linux/src/elur_clip.cpp +76 -0
  15. package/targets/linux/src/elur_clip.h +23 -0
  16. package/targets/linux/src/elur_crypto_module.cpp +121 -0
  17. package/targets/linux/src/elur_events.h +57 -0
  18. package/targets/linux/src/elur_fonts.cpp +106 -0
  19. package/targets/linux/src/elur_fonts.h +31 -0
  20. package/targets/linux/src/elur_host.cpp +1041 -0
  21. package/targets/linux/src/elur_host.h +66 -0
  22. package/targets/linux/src/elur_http_module.cpp +437 -0
  23. package/targets/linux/src/elur_js.h +40 -0
  24. package/targets/linux/src/elur_modules.cpp +453 -0
  25. package/targets/linux/src/elur_modules.h +159 -0
  26. package/targets/linux/src/elur_renderer.h +46 -0
  27. package/targets/linux/src/elur_shot.cpp +64 -0
  28. package/targets/linux/src/elur_shot.h +17 -0
  29. package/targets/linux/src/elur_skia_a11y.cpp +987 -0
  30. package/targets/linux/src/elur_skia_a11y.h +146 -0
  31. package/targets/linux/src/elur_skia_app.cpp +1770 -0
  32. package/targets/linux/src/elur_skia_app.h +18 -0
  33. package/targets/linux/src/elur_state_module.cpp +99 -0
  34. package/targets/linux/src/elur_tck_module.cpp +186 -0
  35. package/targets/linux/src/elur_ui_module.cpp +84 -0
  36. package/targets/linux/src/elur_yoga.cpp +452 -0
  37. package/targets/linux/src/elur_yoga.h +95 -0
  38. package/targets/linux/src/main.cpp +294 -0
  39. package/targets/windows/Package.appxmanifest +28 -0
  40. package/targets/windows/README.md +44 -0
  41. package/targets/windows/elur-windows.vcxproj +133 -0
  42. package/targets/windows/packages.config +10 -0
  43. package/targets/windows/src/elur_crypto_module_win.cpp +106 -0
  44. package/targets/windows/src/elur_events.h +58 -0
  45. package/targets/windows/src/elur_host_win.cpp +645 -0
  46. package/targets/windows/src/elur_host_win.h +75 -0
  47. package/targets/windows/src/elur_http_module_win.cpp +331 -0
  48. package/targets/windows/src/elur_js.h +40 -0
  49. package/targets/windows/src/elur_modules.cpp +460 -0
  50. package/targets/windows/src/elur_modules.h +159 -0
  51. package/targets/windows/src/elur_state_module.cpp +99 -0
  52. package/targets/windows/src/elur_ui_module_win.cpp +75 -0
  53. package/targets/windows/src/elur_uia_host.h +129 -0
  54. package/targets/windows/src/elur_win_applicator.cpp +3118 -0
  55. package/targets/windows/src/elur_win_applicator.h +186 -0
  56. package/targets/windows/src/elur_yoga.cpp +452 -0
  57. package/targets/windows/src/elur_yoga.h +95 -0
  58. package/targets/windows/src/main.cpp +321 -0
@@ -0,0 +1,95 @@
1
+ // elur_yoga.h — árbol Yoga único del host Linux (P1-TREE, port de
2
+ // targets/android elurYoga.cpp sin JNI ni árboles de fila).
3
+ //
4
+ // Un YGNodeRef por id del Display List; las ops create/insert/remove/
5
+ // move/delete/update-style actualizan el árbol espejo y
6
+ // yogaLayoutIfDirty() recalcula una vez por frame y emite rects por
7
+ // DFS al aplicador (delta-cache como Android: solo ids con rect
8
+ // cambiado).
9
+ //
10
+ // Medida de hojas: hook síncrono al aplicador — mismo hilo GTK/JS
11
+ // (modelo single-thread del host, ADR-0158); no hace falta el
12
+ // dispatch-a-main + drain de Android porque la medida no cruza hilos.
13
+ //
14
+ // Unidades lógicas end-to-end (ADR-0120): sin density aquí — la
15
+ // conversión a px físicos es responsabilidad del llamador (dpi_scale
16
+ // llega por yogaSetViewport si hiciera falta; GTK ya trabaja en px
17
+ // lógicos del monitor, scale factor lo aplica internamente).
18
+ #pragma once
19
+
20
+ #include <cstdint>
21
+ #include <functional>
22
+ #include <string>
23
+ #include <yoga/Yoga.h>
24
+
25
+ namespace elur::yoga {
26
+
27
+ // hook(id, w, wMode, h, hMode) → tamaño deseado de la hoja.
28
+ // baseline(id, w, h) → offset del baseline desde el top; default h.
29
+ using BaselineHook = std::function<float(int id, float w, float h)>;
30
+ using MeasureHook = std::function<void(int id, float w, int wMode, float h,
31
+ int hMode, float &outW, float &outH)>;
32
+
33
+ // cb(id, relX, relY, w, h) — relX/relY respecto al padre del árbol
34
+ // (coordenadas de Yoga, lo que GtkFixed espera al anidar).
35
+ using RectSink =
36
+ std::function<void(int id, float x, float y, float w, float h)>;
37
+
38
+ void init();
39
+ void shutdown();
40
+
41
+ // Viewport en unidades lógicas — un resize llama a esto y dirtya.
42
+ void setViewport(float w, float h, bool rtl);
43
+
44
+ // Espejo de ops del Display List.
45
+ void nodeCreate(int id, const std::string &type);
46
+ void nodeDelete(int id);
47
+ void nodeInsert(int parentId, int childId, int index);
48
+ void nodeRemove(int parentId, int childId);
49
+ void nodeMove(int parentId, int childId, int index);
50
+ // update-style: isNum decide el carril f64/str del wire tipado
51
+ // (ADR-0050). null llega como str vacío → retirada de clave.
52
+ void nodeSetStyle(int id, const std::string &key, bool isNum, double num,
53
+ const std::string &str);
54
+ // Texto de hoja (update-text) — marca dirty para re-medida.
55
+ void nodeSetText(int id);
56
+ // Prop `dir` — dirección de layout del subárbol (paridad
57
+ // gtk_widget_set_direction: hereda por descendencia Yoga).
58
+ void nodeSetDir(int id, bool rtl);
59
+
60
+ // Hijos text absorbidos por un button (label): su update-text redirige
61
+ // el dirty al button — el hijo queda fuera del árbol visual.
62
+ void absorbIntoButton(int textId, int buttonId);
63
+
64
+ // Dirty explícito desde fuera (p.ej. props que afectan medida).
65
+ void markDirty();
66
+
67
+ /** Re-mide todas las hojas (measureFunc) — cambio de fontScale. */
68
+ void markAllLeavesDirty();
69
+ bool hasViewport();
70
+
71
+ // Recalcula si dirty y emite rects a sink (solo deltas). Devuelve
72
+ // cuántos rects se emitieron.
73
+ int layoutIfDirty(const RectSink &sink);
74
+
75
+ // Dump completo del árbol tras la última pasada — formato [rect] de
76
+ // ElurTrace (Android) para el harness de paridad geométrica.
77
+ void dumpRects(FILE *out);
78
+
79
+ // Rect de un nodo tras el último layout (para superficies internas,
80
+ // p.ej. contenido de scroll).
81
+ // Padding host-side de hojas (Yoga lo salta en nodos con measureFunc).
82
+ void padOf(int id, float &l, float &t, float &r, float &b);
83
+ bool rectOf(int id, float &x, float &y, float &w, float &h);
84
+
85
+ // Margin numérico (points) resuelto en un edge físico; 0 si pct/auto.
86
+ float nodeStyleMargin(int id, YGEdge edge);
87
+
88
+ // La hoja con measure func necesita saber su widget — el hook recibe id.
89
+ void setMeasureHook(MeasureHook hook);
90
+ void setBaselineHook(BaselineHook hook);
91
+
92
+ // Tipo de un nodo (para isLeafType / absorb en el aplicador).
93
+ std::string nodeType(int id);
94
+
95
+ } // namespace elur::yoga
@@ -0,0 +1,321 @@
1
+ // main.cpp — host Elur para Windows (WinUI 3 + QuickJS-ng in-process).
2
+ // ADR-0220. UNVERIFIED: se compila y verifica en la VM (Windows 11 x64).
3
+ //
4
+ // Uso (mismo contrato que elur-linux):
5
+ // elur-windows --dir generated [--app elurApp.js] [--signals elurSignals.js]
6
+ // [--title T] [--width W] [--height H] [--now MS] [--trace]
7
+ // [--rtl] [--deeplink URL]
8
+ //
9
+ // El proceso: parsea args → WinUI Application/Window con un Canvas raíz
10
+ // → hostInit crea QuickJS + ElurBridge + módulos + aplicador → evalúa
11
+ // signals y app. El runtime vive en el hilo UI (perfil S, ADR-0187 —
12
+ // mismo default que Linux); las respuestas http cruzan por
13
+ // DispatcherQueue.
14
+
15
+ #include "elur_host_win.h"
16
+ #include "elur_win_applicator.h"
17
+
18
+ #include <winrt/Windows.Foundation.Collections.h>
19
+ #include <MddBootstrap.h>
20
+ #include <roerrorapi.h>
21
+ #include <restrictederrorinfo.h>
22
+ #include <cstdarg>
23
+ #include <shellapi.h>
24
+ #include <string>
25
+ #include <windows.h>
26
+ #include <microsoft.ui.xaml.window.h>
27
+ #include <winrt/Microsoft.UI.Windowing.h>
28
+ #include <winrt/Microsoft.UI.Xaml.Controls.h>
29
+ #include <winrt/Microsoft.UI.Xaml.Markup.h>
30
+ #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
31
+ #include <winrt/Microsoft.UI.Xaml.h>
32
+ #include <winrt/Windows.Foundation.h>
33
+ #include <winrt/Windows.UI.Xaml.Interop.h>
34
+ #include <winrt/base.h>
35
+
36
+ namespace ux = winrt::Microsoft::UI::Xaml;
37
+ namespace uxc = winrt::Microsoft::UI::Xaml::Controls;
38
+
39
+ // Diagnóstico de bring-up (temporal): log a <exe>\..\elur-run.log —
40
+ // en sesión 0 / scheduled task no hay consola que leer. Con identidad
41
+ // de paquete el dir del exe (WindowsApps) es de solo lectura: %TEMP%.
42
+ void dlog(const char *fmt, ...) {
43
+ wchar_t exe[MAX_PATH];
44
+ GetModuleFileNameW(nullptr, exe, MAX_PATH);
45
+ std::wstring p = exe;
46
+ p = p.substr(0, p.find_last_of(L"\\/") + 1) + L"elur-run.log";
47
+ FILE *f = _wfopen(p.c_str(), L"a");
48
+ if (!f) {
49
+ wchar_t tmp[MAX_PATH];
50
+ GetTempPathW(MAX_PATH, tmp);
51
+ f = _wfopen((std::wstring(tmp) + L"elur-run.log").c_str(), L"a");
52
+ }
53
+ if (f) {
54
+ va_list ap;
55
+ va_start(ap, fmt);
56
+ vfprintf(f, fmt, ap);
57
+ va_end(ap);
58
+ fclose(f);
59
+ }
60
+ }
61
+ static void dlogH(const char *where, winrt::hresult_error const &e) {
62
+ dlog("[elur] %s: hr=0x%08x %ls\n", where, (unsigned)e.code().value,
63
+ e.message().c_str());
64
+ }
65
+
66
+ struct Args {
67
+ std::string dir = "generated";
68
+ std::string app = "elurApp.js";
69
+ std::string signals = "elurSignals.js";
70
+ std::string title = "Elur";
71
+ std::string deeplink;
72
+ std::string shot;
73
+ int width = 390;
74
+ int height = 844;
75
+ double now = -1;
76
+ bool trace = false;
77
+ bool rtl = false;
78
+ };
79
+
80
+ static Args g_args;
81
+ static uint64_t g_hwnd = 0;
82
+
83
+ static std::string u8(const std::wstring &w) {
84
+ int n = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), (int)w.size(),
85
+ nullptr, 0, nullptr, nullptr);
86
+ std::string s((size_t)n, '\0');
87
+ WideCharToMultiByte(CP_UTF8, 0, w.c_str(), (int)w.size(), s.data(), n,
88
+ nullptr, nullptr);
89
+ return s;
90
+ }
91
+
92
+ static Args parseArgs(int argc, wchar_t **argv) {
93
+ Args a;
94
+ for (int i = 1; i < argc; ++i) {
95
+ std::wstring k = argv[i];
96
+ auto next = [&]() { return i + 1 < argc ? u8(argv[++i]) : ""; };
97
+ if (k == L"--dir") a.dir = next();
98
+ else if (k == L"--app") a.app = next();
99
+ else if (k == L"--signals") a.signals = next();
100
+ else if (k == L"--title") a.title = next();
101
+ else if (k == L"--deeplink") a.deeplink = next();
102
+ else if (k == L"--shot") a.shot = next();
103
+ else if (k == L"--width") a.width = atoi(next().c_str());
104
+ else if (k == L"--height") a.height = atoi(next().c_str());
105
+ else if (k == L"--now") a.now = atof(next().c_str());
106
+ else if (k == L"--trace") a.trace = true;
107
+ else if (k == L"--rtl") a.rtl = true;
108
+ }
109
+ return a;
110
+ }
111
+
112
+ // Apps code-only: el Application debe implementar IXamlMetadataProvider
113
+ // (parámetro de template de ApplicationT) o XamlControlsResources y los
114
+ // templates de controles no resuelven — sin él la familia de edición
115
+ // muere con E_FAIL en el pase de render (ADR-0220). El merge va en
116
+ // OnLaunched: en el ctor el host Xaml aún no está listo (0x8000ffff).
117
+ class ElurApp
118
+ : public ux::ApplicationT<ElurApp, ux::Markup::IXamlMetadataProvider> {
119
+ public:
120
+ ux::Markup::IXamlType GetXamlType(
121
+ winrt::Windows::UI::Xaml::Interop::TypeName const &type) {
122
+ return provider().GetXamlType(type);
123
+ }
124
+ ux::Markup::IXamlType GetXamlType(winrt::hstring const &fullName) {
125
+ return provider().GetXamlType(fullName);
126
+ }
127
+ winrt::com_array<ux::Markup::XmlnsDefinition> GetXmlnsDefinitions() {
128
+ return provider().GetXmlnsDefinitions();
129
+ }
130
+
131
+ ElurApp() {
132
+ dlog("[elur] ElurApp ctor\n");
133
+ // Diagnóstico: las excepciones stowed (0xC000027B) solo exponen el
134
+ // hresult real a través de este evento.
135
+ UnhandledException(
136
+ [](winrt::Windows::Foundation::IInspectable const &,
137
+ ux::UnhandledExceptionEventArgs const &e) {
138
+ dlog("[elur] unhandled hr=0x%08x %ls\n",
139
+ (unsigned)e.Exception(), e.Message().c_str());
140
+ IRestrictedErrorInfo *ri = nullptr;
141
+ if (SUCCEEDED(GetRestrictedErrorInfo(&ri)) && ri) {
142
+ BSTR desc = nullptr, res = nullptr;
143
+ HRESULT cap = S_OK;
144
+ ri->GetErrorDetails(&desc, &cap, &res, nullptr);
145
+ dlog("[elur] restricted desc=%ls res=%ls caphr=0x%08x\n",
146
+ desc ? desc : L"", res ? res : L"", (unsigned)cap);
147
+ SysFreeString(desc);
148
+ SysFreeString(res);
149
+ ri->Release();
150
+ }
151
+ });
152
+ }
153
+ void OnLaunched(ux::LaunchActivatedEventArgs const &) {
154
+ dlog("[elur] OnLaunched enter\n");
155
+ try {
156
+ ux::XamlTypeInfo::XamlControlsXamlMetaDataProvider::Initialize();
157
+ dlog("[elur] xamltypeinfo init ok\n");
158
+ } catch (winrt::hresult_error const &e) {
159
+ dlogH("xamltypeinfo init", e);
160
+ }
161
+ try {
162
+ Resources().MergedDictionaries().Append(uxc::XamlControlsResources());
163
+ dlog("[elur] resources merged\n");
164
+ } catch (winrt::hresult_error const &e) {
165
+ dlogH("resources merge", e);
166
+ }
167
+ try {
168
+ window_ = ux::Window();
169
+ dlog("[elur] window ok\n");
170
+ // Canvas raíz = GtkFixed equivalente — el aplicador posiciona
171
+ // los hijos con los rects que emite el mirror Yoga.
172
+ root_ = uxc::Canvas();
173
+ dlog("[elur] canvas ok\n");
174
+ window_.Content(root_);
175
+ window_.Title(winrt::to_hstring(g_args.title));
176
+ dlog("[elur] content+title ok\n");
177
+ window_.Activate();
178
+ window_.Closed(
179
+ [](auto const &, auto const &) { elur::hostShutdown(); });
180
+ dlog("[elur] window activated\n");
181
+ // Resize tras Activate (ResizeClient sobre ventana no activada
182
+ // puede stowear en Xaml — bisect M1).
183
+ try {
184
+ if (auto aw = window_.AppWindow()) {
185
+ aw.Changed(
186
+ [](winrt::Microsoft::UI::Windowing::AppWindow const &w,
187
+ auto const &) {
188
+ auto s = w.ClientSize();
189
+ if (s.Width > 0 && s.Height > 0)
190
+ elur::g_winapp.setViewport(s.Width, s.Height);
191
+ });
192
+ aw.ResizeClient({g_args.width, g_args.height});
193
+ }
194
+ } catch (winrt::hresult_error const &e) {
195
+ dlogH("AppWindow", e);
196
+ }
197
+ dlog("[elur] appwindow ok\n");
198
+ try {
199
+ HWND hwnd = nullptr;
200
+ winrt::check_hresult(
201
+ window_.as<IWindowNative>()->get_WindowHandle(&hwnd));
202
+ g_hwnd = (uint64_t)hwnd;
203
+ dlog("[elur] hwnd ok\n");
204
+ } catch (winrt::hresult_error const &e) {
205
+ dlogH("hwnd", e);
206
+ }
207
+ } catch (winrt::hresult_error const &e) {
208
+ dlogH("OnLaunched", e);
209
+ throw;
210
+ } catch (std::exception const &e) {
211
+ dlog("[elur] OnLaunched std: %s\n", e.what());
212
+ throw;
213
+ } catch (...) {
214
+ dlog("[elur] OnLaunched unknown\n");
215
+ throw;
216
+ }
217
+
218
+ elur::HostOptions opts;
219
+ opts.bundleDir = g_args.dir;
220
+ opts.signals = g_args.signals;
221
+ opts.app = g_args.app;
222
+ opts.width = g_args.width;
223
+ opts.height = g_args.height;
224
+ opts.title = g_args.title;
225
+ opts.debugNow = g_args.now;
226
+ opts.trace = g_args.trace;
227
+ opts.rtl = g_args.rtl;
228
+ opts.deeplink = g_args.deeplink;
229
+ opts.shot = g_args.shot;
230
+ opts.hwnd = g_hwnd;
231
+ dlog("[elur] hostInit...\n");
232
+ try {
233
+ if (!elur::hostInit(root_, opts))
234
+ dlog("[elur] hostInit devolvió false\n");
235
+ else
236
+ dlog("[elur] hostInit ok\n");
237
+ } catch (winrt::hresult_error const &e) {
238
+ dlogH("hostInit", e);
239
+ throw;
240
+ } catch (std::exception const &e) {
241
+ dlog("[elur] hostInit std: %s\n", e.what());
242
+ throw;
243
+ }
244
+ }
245
+
246
+ private:
247
+ ux::XamlTypeInfo::XamlControlsXamlMetaDataProvider const &provider() {
248
+ // Lazy: construirlo en el ctor cae en el mismo host-no-listo que el
249
+ // merge de recursos (0x8000ffff).
250
+ if (!provider_)
251
+ provider_ = ux::XamlTypeInfo::XamlControlsXamlMetaDataProvider();
252
+ return provider_;
253
+ }
254
+ ux::XamlTypeInfo::XamlControlsXamlMetaDataProvider provider_{nullptr};
255
+ ux::Window window_{nullptr};
256
+ uxc::Canvas root_{nullptr};
257
+ };
258
+
259
+ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int);
260
+
261
+ // SubSystem Console durante el bring-up: el linker exige main.
262
+ int main() {
263
+ return wWinMain(GetModuleHandleW(nullptr), nullptr, nullptr, 0);
264
+ }
265
+
266
+ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) {
267
+ // Unpackaged: adjuntar el framework WASDK instalado al grafo de
268
+ // paquete del proceso (bootstrapper API) — resolución de recursos
269
+ // ms-appx y licencias del runtime. S_OK = framework en el grafo;
270
+ // el build sigue funcionando si falla (log honesto).
271
+ static bool booted = false;
272
+ {
273
+ // Solo tiene sentido sin identidad de paquete — con identidad el
274
+ // framework ya entra por la PackageDependency del manifest.
275
+ UINT32 blen = 0;
276
+ bool hasIdentity =
277
+ GetCurrentPackageId(&blen, nullptr) == ERROR_INSUFFICIENT_BUFFER;
278
+ if (!hasIdentity) {
279
+ PACKAGE_VERSION minV{};
280
+ minV.Major = 2;
281
+ HRESULT hrBoot = MddBootstrapInitialize2(
282
+ 0x00020000, nullptr, minV,
283
+ MddBootstrapInitializeOptions_None);
284
+ booted = SUCCEEDED(hrBoot);
285
+ dlog("[elur] bootstrap hr=0x%08x\n", (unsigned)hrBoot);
286
+ } else
287
+ dlog("[elur] bootstrap skip (package identity)\n");
288
+ }
289
+ winrt::init_apartment(winrt::apartment_type::single_threaded);
290
+ int argc = 0;
291
+ LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
292
+ g_args = parseArgs(argc, argv);
293
+ // --dir relativo se resuelve contra el dir del exe, no el CWD:
294
+ // en app empaquetada el CWD es System32.
295
+ if (!g_args.dir.empty() && g_args.dir[1] != ':' &&
296
+ g_args.dir[0] != '/' && g_args.dir[0] != '\\') {
297
+ wchar_t exe[MAX_PATH];
298
+ GetModuleFileNameW(nullptr, exe, MAX_PATH);
299
+ std::wstring wexe = exe;
300
+ g_args.dir = u8(
301
+ wexe.substr(0, wexe.find_last_of(L"\\/") + 1) +
302
+ std::wstring(g_args.dir.begin(), g_args.dir.end()));
303
+ }
304
+ dlog("[elur] start dir=%s app=%s\n", g_args.dir.c_str(),
305
+ g_args.app.c_str());
306
+
307
+ try {
308
+ ux::Application::Start(
309
+ [](auto &&) { winrt::make<ElurApp>(); });
310
+ } catch (winrt::hresult_error const &e) {
311
+ dlogH("Application::Start", e);
312
+ return 1;
313
+ } catch (std::exception const &e) {
314
+ dlog("[elur] Application::Start std: %s\n", e.what());
315
+ return 1;
316
+ }
317
+ dlog("[elur] Application::Start returned\n");
318
+ if (booted)
319
+ MddBootstrapShutdown();
320
+ return 0;
321
+ }