@elurjs/universal 0.1.10 → 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 (57) hide show
  1. package/cli/create-app.mjs +4 -2
  2. package/cli/dev.mjs +1 -1
  3. package/cli/elur.mjs +18 -4
  4. package/docs/INSTALACION-Y-DEV.md +7 -4
  5. package/package.json +5 -1
  6. package/targets/linux/CMakeLists.txt +196 -0
  7. package/targets/linux/README.md +422 -0
  8. package/targets/linux/ci/tsan.supp +15 -0
  9. package/targets/linux/generated/elur_module_registrar.cpp +14 -0
  10. package/targets/linux/generated/module_sources.cmake +5 -0
  11. package/targets/linux/src/elur_applicator.cpp +5073 -0
  12. package/targets/linux/src/elur_applicator.h +387 -0
  13. package/targets/linux/src/elur_clip.cpp +76 -0
  14. package/targets/linux/src/elur_clip.h +23 -0
  15. package/targets/linux/src/elur_crypto_module.cpp +121 -0
  16. package/targets/linux/src/elur_events.h +57 -0
  17. package/targets/linux/src/elur_fonts.cpp +106 -0
  18. package/targets/linux/src/elur_fonts.h +31 -0
  19. package/targets/linux/src/elur_host.cpp +1041 -0
  20. package/targets/linux/src/elur_host.h +66 -0
  21. package/targets/linux/src/elur_http_module.cpp +437 -0
  22. package/targets/linux/src/elur_js.h +40 -0
  23. package/targets/linux/src/elur_modules.cpp +453 -0
  24. package/targets/linux/src/elur_modules.h +159 -0
  25. package/targets/linux/src/elur_renderer.h +46 -0
  26. package/targets/linux/src/elur_shot.cpp +64 -0
  27. package/targets/linux/src/elur_shot.h +17 -0
  28. package/targets/linux/src/elur_skia_a11y.cpp +987 -0
  29. package/targets/linux/src/elur_skia_a11y.h +146 -0
  30. package/targets/linux/src/elur_skia_app.cpp +1770 -0
  31. package/targets/linux/src/elur_skia_app.h +18 -0
  32. package/targets/linux/src/elur_state_module.cpp +99 -0
  33. package/targets/linux/src/elur_tck_module.cpp +186 -0
  34. package/targets/linux/src/elur_ui_module.cpp +84 -0
  35. package/targets/linux/src/elur_yoga.cpp +452 -0
  36. package/targets/linux/src/elur_yoga.h +95 -0
  37. package/targets/linux/src/main.cpp +294 -0
  38. package/targets/windows/Package.appxmanifest +28 -0
  39. package/targets/windows/README.md +44 -0
  40. package/targets/windows/elur-windows.vcxproj +133 -0
  41. package/targets/windows/packages.config +10 -0
  42. package/targets/windows/src/elur_crypto_module_win.cpp +106 -0
  43. package/targets/windows/src/elur_events.h +58 -0
  44. package/targets/windows/src/elur_host_win.cpp +645 -0
  45. package/targets/windows/src/elur_host_win.h +75 -0
  46. package/targets/windows/src/elur_http_module_win.cpp +331 -0
  47. package/targets/windows/src/elur_js.h +40 -0
  48. package/targets/windows/src/elur_modules.cpp +460 -0
  49. package/targets/windows/src/elur_modules.h +159 -0
  50. package/targets/windows/src/elur_state_module.cpp +99 -0
  51. package/targets/windows/src/elur_ui_module_win.cpp +75 -0
  52. package/targets/windows/src/elur_uia_host.h +129 -0
  53. package/targets/windows/src/elur_win_applicator.cpp +3118 -0
  54. package/targets/windows/src/elur_win_applicator.h +186 -0
  55. package/targets/windows/src/elur_yoga.cpp +452 -0
  56. package/targets/windows/src/elur_yoga.h +95 -0
  57. package/targets/windows/src/main.cpp +321 -0
@@ -0,0 +1,18 @@
1
+ // elur_skia_app.h — carril Skia opt-in del host Linux (fase 0 de
2
+ // docs/propuestas/skia-renderer-arbol.md). La implementación solo se
3
+ // compila con ELUR_HAS_SKIA (targets/linux/skia-libs/libskia.a,
4
+ // gitignored) — sin la lib el símbolo devuelve nullptr y el host cae
5
+ // a Platform Views con warn explícito.
6
+ #pragma once
7
+
8
+ #include "elur_renderer.h"
9
+
10
+ namespace elur {
11
+
12
+ // &aplicador skia si la build lo trae, nullptr si no.
13
+ HostRenderer *skiaHostRenderer();
14
+
15
+ // true si el binario se compiló con soporte Skia.
16
+ bool skiaAvailable();
17
+
18
+ } // namespace elur
@@ -0,0 +1,99 @@
1
+ // elur_state_module.cpp — módulo builtin "state" (U21/ADR-0075, port
2
+ // de ElurStateModule.kt). Retiene el último snapshot NavState que JS
3
+ // empuja ("save", fire-and-forget) y lo devuelve por "getRestore".
4
+ // La serialización es íntegramente JS — el host almacena el payload
5
+ // sin inspeccionarlo.
6
+ //
7
+ // En Android el medio es savedInstanceState; en escritorio no hay
8
+ // equivalente — el host persiste a disco write-through:
9
+ // $XDG_STATE_HOME/elur/<appId>/navstate.json (fallback
10
+ // ~/.local/state/elur/...). Escritura atómica tmp+rename. El seed se
11
+ // lee perezoso en el primer getRestore y queda fijo el resto de la
12
+ // sesión (misma semántica que restoreJson en Android).
13
+
14
+ #include "elur_modules.h"
15
+
16
+ #include <glib.h>
17
+ #include <glib/gstdio.h>
18
+
19
+ #include <string>
20
+
21
+ namespace {
22
+
23
+ std::string statePath() {
24
+ const char *stateDir = g_get_user_state_dir(); // nunca null
25
+ return std::string(stateDir) + "/elur/" + elur::modules::registry().appId() +
26
+ "/navstate.json";
27
+ }
28
+
29
+ // Escritura atómica: tmp + rename — un crash a mitad de write no
30
+ // deja un snapshot truncado que el siguiente boot intente leer.
31
+ void writeSnapshot(const std::string &json) {
32
+ const std::string path = statePath();
33
+ const std::string dir = path.substr(0, path.rfind('/'));
34
+ g_mkdir_with_parents(dir.c_str(), 0700);
35
+ const std::string tmp = path + ".tmp";
36
+ if (!g_file_set_contents(tmp.c_str(), json.c_str(), (gssize)json.size(),
37
+ nullptr)) {
38
+ return;
39
+ }
40
+ g_rename(tmp.c_str(), path.c_str());
41
+ }
42
+
43
+ std::string readSnapshot() {
44
+ gchar *contents = nullptr;
45
+ gsize len = 0;
46
+ if (!g_file_get_contents(statePath().c_str(), &contents, &len, nullptr) ||
47
+ contents == nullptr || len == 0) {
48
+ g_free(contents);
49
+ return "";
50
+ }
51
+ std::string s(contents, len);
52
+ g_free(contents);
53
+ return s;
54
+ }
55
+
56
+ class ElurStateModule : public elur::modules::ElurModule {
57
+ public:
58
+ std::string name() const override { return "state"; }
59
+
60
+ void onCommand(int, const std::string &command, const std::string &argsJson,
61
+ elur::modules::Reply reply) override {
62
+ if (command == "save") {
63
+ // §4.2.2: reply único por callId — aunque JS lo invoque
64
+ // fire-and-forget, una invocación sin respuesta deja el slot
65
+ // pending ocupado hasta reset (fuga de callIds).
66
+ writeSnapshot(argsJson);
67
+ reply(true, "{}");
68
+ return;
69
+ }
70
+ if (command == "getRestore") {
71
+ if (!seedLoaded_) {
72
+ seedLoaded_ = true;
73
+ seed_ = readSnapshot();
74
+ // Snapshot truncado/corrupto → cold boot (el reader JS valida
75
+ // la ventana de versiones, pero un payload no-JSON rompería
76
+ // el reply entero — el host solo chequea la forma externa).
77
+ if (!seed_.empty() && seed_.front() != '{')
78
+ seed_.clear();
79
+ }
80
+ reply(true, seed_.empty() ? "{\"snapshot\":null}"
81
+ : "{\"snapshot\":" + seed_ + "}");
82
+ return;
83
+ }
84
+ reply(false,
85
+ "{\"code\":\"unknown_command\",\"message\":" +
86
+ elur::modules::jsonQuote("comando desconocido: " + command) +
87
+ "}");
88
+ }
89
+
90
+ private:
91
+ bool seedLoaded_ = false;
92
+ std::string seed_;
93
+ };
94
+
95
+ } // namespace
96
+
97
+ void elurRegisterStateModule() {
98
+ elur::modules::registry().registerModule(std::make_unique<ElurStateModule>());
99
+ }
@@ -0,0 +1,186 @@
1
+ // elur_tck_module.cpp — impl host del módulo de contrato "elur.tck"
2
+ // (spec §18, ADR-0095; port de ElurTckModule.kt). Se registra solo
3
+ // cuando el appId empieza por "elurTck" — igual que MainActivity, el
4
+ // módulo de prueba no existe en apps reales.
5
+ //
6
+ // echo — request/response
7
+ // slow — reply aparcada; nunca responde solo (el TCK cancela)
8
+ // fail — vocabulario canónico de errores
9
+ // emitTick — evento discrete
10
+ // emitFrame — evento continuous (el registry gatea la suscripción)
11
+ // probe/* — handle con estado nativo + handle_invalid
12
+ // tck-perm — permission.request estándar atendido por el registry
13
+ // tck:probe — platform-view declarada por ElurPlatformViewSource
14
+ // (ADR-0181): GtkButton que emite "probeTap" al click
15
+
16
+ #include "elur_modules.h"
17
+
18
+ #include <glib.h>
19
+ #include <gtk/gtk.h>
20
+
21
+ #include <unordered_map>
22
+ #include <unordered_set>
23
+
24
+ namespace {
25
+
26
+ class ElurTckModule : public elur::modules::ElurModule,
27
+ public elur::modules::ElurEventSource,
28
+ public elur::modules::ElurPlatformViewSource {
29
+ public:
30
+ std::string name() const override { return "elur.tck"; }
31
+
32
+ const std::unordered_map<std::string, std::string> &
33
+ permissions() const override {
34
+ static const std::unordered_map<std::string, std::string> perms = {
35
+ {"tck-perm", "org.freedesktop.impl.portal.Notification"},
36
+ };
37
+ return perms;
38
+ }
39
+
40
+ void attachEmit(elur::modules::Emit emit) override {
41
+ emit_ = std::move(emit);
42
+ }
43
+
44
+ // ADR-0181 — vista de contrato "probe": GtkButton cuyo "clicked"
45
+ // emite probeTap por el canal del nodo (un GtkGestureClick ajeno
46
+ // quedaría denegado: el botón reclama la secuencia). El bind vive
47
+ // lo que viva la señal — destroy-notify al desconectar/finalizar.
48
+ const std::unordered_map<std::string, elur::modules::PvFactory> &
49
+ platformViews() const override {
50
+ static const std::unordered_map<std::string, elur::modules::PvFactory> pvs =
51
+ {
52
+ {"probe",
53
+ [](int nodeId, elur::modules::PvEmit emit) -> GtkWidget * {
54
+ GtkWidget *b = gtk_button_new_with_label("tck-pv-probe");
55
+ struct Bind {
56
+ int id;
57
+ elur::modules::PvEmit emit;
58
+ };
59
+ auto *bind = new Bind{nodeId, std::move(emit)};
60
+ g_signal_connect_data(
61
+ b, "clicked", G_CALLBACK(+[](GtkWidget *, gpointer p) {
62
+ auto *bn = static_cast<Bind *>(p);
63
+ bn->emit(bn->id, "probeTap", "{}");
64
+ }),
65
+ bind,
66
+ [](gpointer p, GClosure *) {
67
+ delete static_cast<Bind *>(p);
68
+ },
69
+ G_CONNECT_DEFAULT);
70
+ return b;
71
+ }},
72
+ };
73
+ return pvs;
74
+ }
75
+
76
+ void onCommand(int callId, const std::string &command,
77
+ const std::string &argsJson,
78
+ elur::modules::Reply reply) override {
79
+ elur::modules::Json args;
80
+ elur::modules::jsonParse(argsJson, args);
81
+ const elur::modules::Json *v;
82
+
83
+ if (command == "echo") {
84
+ // std::string, no c_str(): el payload puede llevar NUL embebido.
85
+ std::string msg = (v = args.get("msg")) ? v->str : std::string();
86
+ reply(true, "{\"pong\":" + elur::modules::jsonQuote(msg) + "}");
87
+ return;
88
+ }
89
+ if (command == "slow") {
90
+ pendings_[callId] = std::move(reply);
91
+ return;
92
+ }
93
+ if (command == "fail") {
94
+ std::string code = (v = args.get("code")) ? v->str : "";
95
+ if (code.empty())
96
+ code = "internal";
97
+ reply(false, "{\"code\":" + elur::modules::jsonQuote(code) +
98
+ ",\"message\":\"tck fail\"}");
99
+ return;
100
+ }
101
+ if (command == "emitTick") {
102
+ if (emit_)
103
+ emit_("tick", "{\"v\":" + num(args) + "}");
104
+ reply(true, "{}");
105
+ return;
106
+ }
107
+ if (command == "emitFrame") {
108
+ if (emit_)
109
+ emit_("frame", "{\"v\":" + num(args) + "}");
110
+ reply(true, "{}");
111
+ return;
112
+ }
113
+ if (command == "probe/create") {
114
+ std::string id = "h" + std::to_string(++probeSeq_);
115
+ probes_.insert(id);
116
+ reply(true, "{\"handleId\":" + elur::modules::jsonQuote(id) +
117
+ ",\"n\":" + std::to_string(probeN_) + "}");
118
+ return;
119
+ }
120
+ if (command == "probe/bump") {
121
+ std::string hid = (v = args.get("handleId")) ? v->str : "";
122
+ if (probes_.find(hid) == probes_.end()) {
123
+ reply(false, "{\"code\":\"unavailable\",\"message\":"
124
+ "\"handle_invalid\"}");
125
+ } else {
126
+ reply(true, "{\"n\":" + std::to_string(++probeN_) + "}");
127
+ }
128
+ return;
129
+ }
130
+ if (command == "release") {
131
+ std::string hid = (v = args.get("handleId")) ? v->str : "";
132
+ probes_.erase(hid);
133
+ reply(true, "{}");
134
+ return;
135
+ }
136
+ reply(false, "{\"code\":\"unknown_command\",\"message\":" +
137
+ elur::modules::jsonQuote(command) + "}");
138
+ }
139
+
140
+ void onCancel(int callId) override {
141
+ auto it = pendings_.find(callId);
142
+ if (it != pendings_.end()) {
143
+ it->second(false, "{\"code\":\"cancelled\",\"message\":"
144
+ "\"tck cancel\"}");
145
+ pendings_.erase(it);
146
+ }
147
+ }
148
+
149
+ void onSessionEnd() override {
150
+ probes_.clear();
151
+ probeN_ = 0;
152
+ for (auto &kv : pendings_)
153
+ kv.second(false, "{\"code\":\"session_reset\",\"message\":"
154
+ "\"fin de epoch\"}");
155
+ pendings_.clear();
156
+ }
157
+
158
+ private:
159
+ std::string num(const elur::modules::Json &args) {
160
+ const elur::modules::Json *v = args.get("v");
161
+ if (!v || v->kind != elur::modules::Json::Num)
162
+ return "0";
163
+ // g_ascii_dtostr — locale-independiente (ADR-0160: std::to_string
164
+ // emite coma decimal bajo es_ES y rompe el wire JSON).
165
+ char b[32];
166
+ g_ascii_dtostr(b, sizeof(b), v->num);
167
+ std::string s = b;
168
+ while (s.size() > 1 && s.back() == '0')
169
+ s.pop_back();
170
+ if (!s.empty() && s.back() == '.')
171
+ s.pop_back();
172
+ return s;
173
+ }
174
+
175
+ elur::modules::Emit emit_;
176
+ std::unordered_map<int, elur::modules::Reply> pendings_;
177
+ std::unordered_set<std::string> probes_;
178
+ int probeSeq_ = 0;
179
+ int probeN_ = 0;
180
+ };
181
+
182
+ } // namespace
183
+
184
+ void elurRegisterTckModule() {
185
+ elur::modules::registry().registerModule(std::make_unique<ElurTckModule>());
186
+ }
@@ -0,0 +1,84 @@
1
+ // elur_ui_module.cpp — módulo builtin "ui" (ADR-0200 / ADR-0202):
2
+ // - measureInWindow { id } → { x, y, width, height } en coordenadas lógicas
3
+ // - setBackIntercept { active } → {} (habilita Escape para overlays/guards)
4
+
5
+ #include "elur_host.h"
6
+ #include "elur_modules.h"
7
+ #include "elur_renderer.h"
8
+
9
+ #include <glib.h>
10
+
11
+ #include <cstdio>
12
+ #include <memory>
13
+ #include <string>
14
+
15
+ namespace {
16
+
17
+ struct MeasureReq {
18
+ int id = 0;
19
+ elur::modules::Reply reply;
20
+ };
21
+
22
+ void respondMeasure(int id, const elur::modules::Reply &reply) {
23
+ double x = 0, y = 0, w = 0, h = 0;
24
+ if (elur::g_rend)
25
+ elur::g_rend->measureInWindow(id, x, y, w, h);
26
+ char bx[32], by[32], bw[32], bh[32];
27
+ g_ascii_dtostr(bx, sizeof bx, x);
28
+ g_ascii_dtostr(by, sizeof by, y);
29
+ g_ascii_dtostr(bw, sizeof bw, w);
30
+ g_ascii_dtostr(bh, sizeof bh, h);
31
+ char json[192];
32
+ snprintf(json, sizeof json,
33
+ "{\"x\":%s,\"y\":%s,\"width\":%s,\"height\":%s}", bx, by, bw, bh);
34
+ reply(true, json);
35
+ }
36
+
37
+ class ElurUiModule : public elur::modules::ElurModule {
38
+ public:
39
+ std::string name() const override { return "ui"; }
40
+
41
+ void onSessionEnd() override { elur::hostSetBackIntercept(false); }
42
+
43
+ void onCommand(int, const std::string &command, const std::string &argsJson,
44
+ elur::modules::Reply reply) override {
45
+ elur::modules::Json args;
46
+ elur::modules::jsonParse(argsJson, args);
47
+ if (command == "setBackIntercept") {
48
+ const auto *a = args.get("active");
49
+ bool active = a && a->kind == elur::modules::Json::Bool && a->b;
50
+ elur::hostSetBackIntercept(active);
51
+ reply(true, "{}");
52
+ return;
53
+ }
54
+ if (command == "measureInWindow") {
55
+ const auto *idVal = args.get("id");
56
+ int id = (idVal && idVal->kind == elur::modules::Json::Num)
57
+ ? static_cast<int>(idVal->num)
58
+ : 0;
59
+ #if ELUR_THREAD_MODEL_D
60
+ auto *req = new MeasureReq{id, std::move(reply)};
61
+ g_idle_add(
62
+ [](gpointer data) -> gboolean {
63
+ std::unique_ptr<MeasureReq> r(static_cast<MeasureReq *>(data));
64
+ respondMeasure(r->id, r->reply);
65
+ return G_SOURCE_REMOVE;
66
+ },
67
+ req);
68
+ #else
69
+ respondMeasure(id, reply);
70
+ #endif
71
+ return;
72
+ }
73
+ reply(false,
74
+ "{\"code\":\"unknown_command\",\"message\":" +
75
+ elur::modules::jsonQuote("comando desconocido: " + command) +
76
+ "}");
77
+ }
78
+ };
79
+
80
+ } // namespace
81
+
82
+ void elurRegisterUiModule() {
83
+ elur::modules::registry().registerModule(std::make_unique<ElurUiModule>());
84
+ }