@elurjs/universal 0.1.14 → 0.1.16

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.
package/cli/dev.mjs CHANGED
@@ -201,7 +201,8 @@ const WEB_MIME = {
201
201
  };
202
202
  function withReloadScript(html) {
203
203
  const script = `<script>(()=>{const es=new EventSource("/__elur_dev");` +
204
- `es.onmessage=e=>{if(e.data==="reload")location.reload();};})();</script>`;
204
+ `es.onmessage=e=>{if(e.data==="reload")location.reload();};` +
205
+ `addEventListener("beforeunload",()=>es.close());})();</script>`;
205
206
  return html.includes("</body>")
206
207
  ? html.replace("</body>", script + "</body>")
207
208
  : html + script;
package/cli/sdui.mjs CHANGED
@@ -635,6 +635,15 @@ if (sub === "gateway") {
635
635
  const urlObj = new URL(req.url ?? "/", "http://127.0.0.1");
636
636
  const pathname = urlObj.pathname;
637
637
 
638
+ if (req.method === "GET" &&
639
+ (pathname === "/" || pathname === "/favicon.ico")) {
640
+ return send(200, {
641
+ ok: true, rev,
642
+ rutas: "POST /serve | POST /publish | GET /poll | " +
643
+ "GET /stream | POST /action | GET /actions",
644
+ });
645
+ }
646
+
638
647
  if (req.method === "GET" && pathname === "/poll") {
639
648
  const since = Number(urlObj.searchParams.get("since") ?? "0");
640
649
  if (rev > since && liveItem) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elurjs/universal",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -5,7 +5,7 @@
5
5
  // TweetNaCl (native/ed25519, dominio público) con randombytes sobre
6
6
  // BCryptGenRandom.
7
7
  //
8
- // Comando "verify": input { payload, signature(b64url), pubkey(b64url) }
8
+ // Comando "verify": input { payload, sig(b64url), key(b64url) }
9
9
  // → output { ok }.
10
10
 
11
11
  #include "elur_modules.h"
@@ -89,10 +89,14 @@ public:
89
89
  std::string payload;
90
90
  if (auto *p = args.get("payload"))
91
91
  payload = p->asStr();
92
+ // Contrato (src/sdui/cryptoModule.ts): { payload, sig, key };
93
+ // `signature`/`pubkey` quedan como alias heredados.
94
+ auto *sigArg = args.get("sig") ? args.get("sig") : args.get("signature");
95
+ auto *keyArg = args.get("key") ? args.get("key") : args.get("pubkey");
92
96
  std::vector<unsigned char> sig, pub;
93
- bool ok = args.get("signature") && args.get("pubkey") &&
94
- b64urlDecode(args.get("signature")->asStr(), sig) &&
95
- b64urlDecode(args.get("pubkey")->asStr(), pub) &&
97
+ bool ok = sigArg && keyArg &&
98
+ b64urlDecode(sigArg->asStr(), sig) &&
99
+ b64urlDecode(keyArg->asStr(), pub) &&
96
100
  verifyEd25519(payload, sig, pub);
97
101
  reply(true, std::string("{\"ok\":") + (ok ? "true" : "false") + "}");
98
102
  }
@@ -190,9 +190,11 @@ std::pair<bool, std::string> runRequest(const Request &r) {
190
190
  WinHttpCloseHandle(ses);
191
191
  return fail("net_error", "WinHttpOpenRequest failed");
192
192
  }
193
+ // lpBuffer debe apuntar a un DWORD con el flag (no el flag como
194
+ // puntero): pasar (LPVOID)WINHTTP_DISABLE_REDIRECTS hacía leer 0x2.
195
+ DWORD disableFeature = WINHTTP_DISABLE_REDIRECTS;
193
196
  WinHttpSetOption(req, WINHTTP_OPTION_DISABLE_FEATURE,
194
- (LPVOID)WINHTTP_DISABLE_REDIRECTS,
195
- sizeof(WINHTTP_DISABLE_REDIRECTS));
197
+ &disableFeature, sizeof(disableFeature));
196
198
 
197
199
  std::wstring extra;
198
200
  for (auto &kv : r.headers)
@@ -67,6 +67,10 @@ wu::Color parseColor(const std::string &s, bool &ok) {
67
67
  return -1;
68
68
  };
69
69
  auto dup = [](int h) { return h * 16 + h; };
70
+ if (s == "transparent") {
71
+ ok = true;
72
+ return wu::Color{0, 0, 0, 0};
73
+ }
70
74
  if (s.size() == 4 && s[0] == '#') {
71
75
  // #rgb shorthand — Color.parseColor (android) y gdk_rgba_parse
72
76
  // (GTK) lo aceptan; el wire lo emite verbatim.
@@ -108,6 +112,15 @@ wu::Color parseColor(const std::string &s, bool &ok) {
108
112
  ok = true;
109
113
  return c;
110
114
  }
115
+ if (s.rfind("rgba(", 0) == 0 && s.size() > 6) {
116
+ int r = 0, g = 0, b = 0;
117
+ double a = 1.0;
118
+ if (sscanf_s(s.c_str() + 5, "%d,%d,%d,%lf", &r, &g, &b, &a) == 4) {
119
+ ok = true;
120
+ int alpha = std::clamp((int)std::lround(a * 255.0), 0, 255);
121
+ return wu::Color{(uint8_t)alpha, (uint8_t)r, (uint8_t)g, (uint8_t)b};
122
+ }
123
+ }
111
124
  if (s.rfind("rgb(", 0) == 0 && s.size() > 5) {
112
125
  int r = 0, g = 0, b = 0;
113
126
  if (sscanf_s(s.c_str() + 4, "%d,%d,%d", &r, &g, &b) == 3) {
@@ -452,6 +465,14 @@ void WinApplicator::createNode(int id, const std::string &type) {
452
465
  auto withHost = [&](mux::UIElement content) {
453
466
  auto hostImpl = winrt::make_self<ElurHost>();
454
467
  n.host = *hostImpl;
468
+ // ContentControl alinea Left/Top por defecto: sin Stretch el control
469
+ // interior (Button/TextBox/Slider) queda en su DesiredSize mínimo
470
+ // en (0,0) en vez de cubrir el rect w×h calculado por Yoga.
471
+ n.host.Padding(Thickness{0, 0, 0, 0});
472
+ n.host.MinWidth(0);
473
+ n.host.MinHeight(0);
474
+ n.host.HorizontalContentAlignment(mux::HorizontalAlignment::Stretch);
475
+ n.host.VerticalContentAlignment(mux::VerticalAlignment::Stretch);
455
476
  if (content)
456
477
  n.host.Content(content);
457
478
  n.el = n.host;
@@ -473,6 +494,24 @@ void WinApplicator::createNode(int id, const std::string &type) {
473
494
  withBorder(n.textBlock);
474
495
  } else if (type == "button") {
475
496
  n.button = muxc::Button();
497
+ // ADR-0125: neutraliza el cromo WinUI (borde 1px, CornerRadius 4,
498
+ // fondo gris, padding 11,5,11,6 y visuales hover/press opacos) —
499
+ // la apariencia sale íntegra del estilo Elur, igual que Android/GTK.
500
+ auto clear = muxm::SolidColorBrush(wu::Color{0, 0, 0, 0});
501
+ n.button.MinWidth(0);
502
+ n.button.MinHeight(0);
503
+ n.button.Padding(Thickness{0, 0, 0, 0});
504
+ n.button.BorderThickness(Thickness{0, 0, 0, 0});
505
+ n.button.CornerRadius(mux::CornerRadius{0, 0, 0, 0});
506
+ n.button.Background(clear);
507
+ n.button.BorderBrush(clear);
508
+ auto res = n.button.Resources();
509
+ res.Insert(winrt::box_value(L"ButtonBackgroundPointerOver"), clear);
510
+ res.Insert(winrt::box_value(L"ButtonBackgroundPressed"), clear);
511
+ res.Insert(winrt::box_value(L"ButtonBackgroundDisabled"), clear);
512
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPointerOver"), clear);
513
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPressed"), clear);
514
+ res.Insert(winrt::box_value(L"ButtonBorderBrushDisabled"), clear);
476
515
  withHost(n.button);
477
516
  } else if (type == "text-input") {
478
517
  n.input = muxc::TextBox();
@@ -1283,11 +1322,16 @@ void WinApplicator::updateStyle(WinNode &n, JSContext *ctx,
1283
1322
  std::string key = jsStr(ctx, keyv);
1284
1323
  JS_FreeValue(ctx, keyv);
1285
1324
  JSValue val = JS_GetProperty(ctx, style, atom);
1286
- if (JS_IsNumber(val)) {
1325
+ if (JS_IsNull(val) || JS_IsUndefined(val)) {
1326
+ yoga::nodeSetStyle(n.id, key, false, 0, "");
1327
+ n.visual.erase(key);
1328
+ } else if (JS_IsNumber(val)) {
1287
1329
  double num = 0;
1288
1330
  JS_ToFloat64(ctx, &num, val);
1289
1331
  yoga::nodeSetStyle(n.id, key, true, num, "");
1290
- n.visual.erase(key);
1332
+ char buf[40];
1333
+ snprintf(buf, sizeof(buf), "%.6g", num);
1334
+ n.visual[key] = buf;
1291
1335
  } else {
1292
1336
  std::string s = jsStr(ctx, val);
1293
1337
  yoga::nodeSetStyle(n.id, key, false, 0, s);
@@ -1310,13 +1354,24 @@ void WinApplicator::applyVisual(WinNode &n) {
1310
1354
  if (auto b = brushOf(*bg)) {
1311
1355
  if (n.border)
1312
1356
  n.border.Background(b);
1313
- else if (n.button)
1357
+ else if (n.button) {
1314
1358
  n.button.Background(b);
1315
- else if (n.input)
1359
+ auto res = n.button.Resources();
1360
+ res.Insert(winrt::box_value(L"ButtonBackgroundPointerOver"), b);
1361
+ res.Insert(winrt::box_value(L"ButtonBackgroundPressed"), b);
1362
+ res.Insert(winrt::box_value(L"ButtonBackgroundDisabled"), b);
1363
+ } else if (n.input)
1316
1364
  n.input.Background(b);
1317
1365
  else if (n.sw)
1318
1366
  n.sw.Background(b);
1319
1367
  }
1368
+ } else if (n.button) {
1369
+ auto clear = muxm::SolidColorBrush(wu::Color{0, 0, 0, 0});
1370
+ n.button.Background(clear);
1371
+ auto res = n.button.Resources();
1372
+ res.Insert(winrt::box_value(L"ButtonBackgroundPointerOver"), clear);
1373
+ res.Insert(winrt::box_value(L"ButtonBackgroundPressed"), clear);
1374
+ res.Insert(winrt::box_value(L"ButtonBackgroundDisabled"), clear);
1320
1375
  }
1321
1376
  if (const std::string *fg = find("color")) {
1322
1377
  if (auto b = brushOf(*fg)) {
@@ -1381,6 +1436,33 @@ void WinApplicator::applyVisual(WinNode &n) {
1381
1436
  // Padding visual: Yoga lo lleva en el árbol para contenedores;
1382
1437
  // en hojas con measureFunc lo suma la medida (padVals), como en
1383
1438
  // GTK — aquí no lo duplicamos.
1439
+ } else if (n.button) {
1440
+ double r = 0;
1441
+ if (const std::string *br = find("borderRadius"))
1442
+ r = pxOf(*br);
1443
+ n.button.CornerRadius(mux::CornerRadius{r, r, r, r});
1444
+ const std::string *bc = find("borderColor");
1445
+ const std::string *bw = find("borderWidth");
1446
+ if (bc || bw) {
1447
+ double t = bw ? pxOf(*bw, 0) : 1;
1448
+ n.button.BorderThickness(Thickness{t, t, t, t});
1449
+ auto bb = bc ? brushOf(*bc) : nullptr;
1450
+ if (!bb)
1451
+ bb = muxm::SolidColorBrush(wu::Color{0, 0, 0, 0});
1452
+ n.button.BorderBrush(bb);
1453
+ auto res = n.button.Resources();
1454
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPointerOver"), bb);
1455
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPressed"), bb);
1456
+ res.Insert(winrt::box_value(L"ButtonBorderBrushDisabled"), bb);
1457
+ } else {
1458
+ auto clear = muxm::SolidColorBrush(wu::Color{0, 0, 0, 0});
1459
+ n.button.BorderThickness(Thickness{0, 0, 0, 0});
1460
+ n.button.BorderBrush(clear);
1461
+ auto res = n.button.Resources();
1462
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPointerOver"), clear);
1463
+ res.Insert(winrt::box_value(L"ButtonBorderBrushPressed"), clear);
1464
+ res.Insert(winrt::box_value(L"ButtonBorderBrushDisabled"), clear);
1465
+ }
1384
1466
  }
1385
1467
  if (const std::string *op = find("opacity")) {
1386
1468
  if (n.el)
@@ -1425,9 +1507,15 @@ void WinApplicator::measureLeaf(int id, float w, int wMode, float h,
1425
1507
  mux::UIElement probe{nullptr};
1426
1508
  if (n.textBlock)
1427
1509
  probe = n.textBlock;
1428
- else if (n.button)
1429
- probe = n.button;
1430
- else if (n.swEl)
1510
+ else if (n.button) {
1511
+ if (n.absorbedTextId != 0) {
1512
+ auto ti = nodes_.find(n.absorbedTextId);
1513
+ if (ti != nodes_.end() && ti->second.textBlock)
1514
+ probe = ti->second.textBlock;
1515
+ }
1516
+ if (!probe)
1517
+ probe = n.button;
1518
+ } else if (n.swEl)
1431
1519
  probe = n.swEl;
1432
1520
  else if (n.slider)
1433
1521
  probe = n.slider;
@@ -1451,7 +1539,7 @@ void WinApplicator::measureLeaf(int id, float w, int wMode, float h,
1451
1539
  d = Size{20, 20};
1452
1540
  else if (n.input)
1453
1541
  d = Size{120, 32};
1454
- else if (n.button)
1542
+ else if (n.button && (!n.textValue.empty() || n.absorbedTextId != 0))
1455
1543
  d = Size{88, 32};
1456
1544
  else if (n.slider)
1457
1545
  d = Size{120, 32};
@@ -2398,10 +2486,22 @@ void WinApplicator::relayout() {
2398
2486
  nd.inner.Width(w);
2399
2487
  nd.inner.Height(h);
2400
2488
  }
2401
- if (nd.border && w > 0 && h > 0) {
2489
+ if (nd.border && w >= 0 && h >= 0) {
2402
2490
  nd.border.Width(w);
2403
2491
  nd.border.Height(h);
2404
2492
  }
2493
+ if (nd.button && w >= 0 && h >= 0) {
2494
+ nd.button.Width(w);
2495
+ nd.button.Height(h);
2496
+ }
2497
+ if (nd.input && w >= 0 && h >= 0) {
2498
+ nd.input.Width(w);
2499
+ nd.input.Height(h);
2500
+ }
2501
+ if (nd.slider && w >= 0 && h >= 0) {
2502
+ nd.slider.Width(w);
2503
+ nd.slider.Height(h);
2504
+ }
2405
2505
  // El inner canvas del scroll necesita su propio tamaño de
2406
2506
  // contenido: ScrollViewer desplaza, el canvas recibe los rects
2407
2507
  // de los hijos igual que el GtkFixed interno.
@@ -2535,11 +2635,33 @@ void WinApplicator::applyFrame(JSContext *ctx, JSValueConst v) {
2535
2635
  if (ci != nodes_.end() && ci->second.el) {
2536
2636
  muxc::Canvas target = surfaceOf(parentId);
2537
2637
  detachVisual(ci->second.el);
2538
- // Button absorbe hijos text como label (paridad GTK).
2539
- if (pi != nodes_.end() && pi->second.button &&
2540
- ci->second.textBlock) {
2541
- pi->second.button.Content(ci->second.el);
2542
- yoga::absorbIntoButton(childId, parentId);
2638
+ // Button absorbe hijos text como label (paridad GTK); si recibe
2639
+ // hijos compuestos (p.ej. A2UI Button→Column), materializa un
2640
+ // Canvas interno como Content para posicionarlos con Yoga.
2641
+ if (pi != nodes_.end() && pi->second.button) {
2642
+ if (ci->second.textBlock && !pi->second.inner) {
2643
+ pi->second.button.HorizontalContentAlignment(
2644
+ mux::HorizontalAlignment::Center);
2645
+ pi->second.button.VerticalContentAlignment(
2646
+ mux::VerticalAlignment::Center);
2647
+ pi->second.button.Content(ci->second.el);
2648
+ pi->second.absorbedTextId = childId;
2649
+ yoga::absorbIntoButton(childId, parentId);
2650
+ } else {
2651
+ if (!pi->second.inner) {
2652
+ pi->second.inner = muxc::Canvas();
2653
+ pi->second.button.HorizontalContentAlignment(
2654
+ mux::HorizontalAlignment::Stretch);
2655
+ pi->second.button.VerticalContentAlignment(
2656
+ mux::VerticalAlignment::Stretch);
2657
+ pi->second.button.Content(pi->second.inner);
2658
+ }
2659
+ auto count = pi->second.inner.Children().Size();
2660
+ uint32_t idx =
2661
+ index < 0 ? count
2662
+ : std::min<uint32_t>((uint32_t)index, count);
2663
+ pi->second.inner.Children().InsertAt(idx, ci->second.el);
2664
+ }
2543
2665
  } else if (target) {
2544
2666
  auto count = target.Children().Size();
2545
2667
  uint32_t idx =
@@ -2561,6 +2683,8 @@ void WinApplicator::applyFrame(JSContext *ctx, JSValueConst v) {
2561
2683
  // re-inserta como overlay parallax (ADR-0013). WinRT retiene
2562
2684
  // la referencia — su delete-node puede llegar antes de la op.
2563
2685
  auto pi = nodes_.find(parentId);
2686
+ if (pi != nodes_.end() && pi->second.absorbedTextId == childId)
2687
+ pi->second.absorbedTextId = 0;
2564
2688
  if (pi != nodes_.end() && pi->second.type == "shell") {
2565
2689
  clearDetached();
2566
2690
  detachedEl_ = ci->second.el;
@@ -76,6 +76,7 @@ struct WinNode {
76
76
  std::unordered_map<std::string, EventBind> events;
77
77
  std::unordered_map<std::string, std::string> visual;
78
78
  std::string textValue;
79
+ int absorbedTextId = 0;
79
80
  bool suppressSignal = false;
80
81
  bool alignSet = false;
81
82
  float fontSizePx = 0;
@@ -209,9 +209,10 @@ void nodeInsert(int parentId, int childId, int index) {
209
209
  if (p == g_nodes.end() || c == g_nodes.end())
210
210
  return;
211
211
  YGNodeRef parent = p->second.node;
212
- // button absorbe todo hijo como label: no entra al árbol; el padre
213
- // pasa a medirse como hoja (paridad con yogaInsertChild Android).
214
- if (p->second.type == "button") {
212
+ // button absorbe hijos text como label: no entran al árbol y el padre
213
+ // se mide como hoja (paridad Android/GTK). Hijos compuestos (column/
214
+ // row, p.ej. A2UI Button) sí entran al árbol Yoga bajo el button.
215
+ if (p->second.type == "button" && c->second.type == "text") {
215
216
  YGNodeSetMeasureFunc(p->second.node, measureLeaf);
216
217
  g_absorbedByButton[childId] = parentId;
217
218
  clearPadding(p->second.node);