@elurjs/universal 0.1.16 → 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 (558) hide show
  1. package/README.md +24 -8
  2. package/cli/add-platform.mjs +121 -0
  3. package/cli/commands.mjs +11 -6
  4. package/cli/create-app.mjs +110 -190
  5. package/cli/dev.mjs +17 -21
  6. package/cli/doctor.mjs +144 -122
  7. package/cli/elur.mjs +112 -34
  8. package/cli/gen-es5.mjs +4 -2
  9. package/cli/gen-hbc.mjs +3 -5
  10. package/cli/gen-host-integration.mjs +26 -11
  11. package/cli/gen-signals.mjs +3 -2
  12. package/cli/gen-worklet-src.mjs +9 -1
  13. package/cli/lib-platforms.d.mts +18 -0
  14. package/cli/lib-platforms.mjs +338 -0
  15. package/cli/package-linux.mjs +8 -4
  16. package/cli/sync-platform-packages.mjs +153 -0
  17. package/docs/INSTALACION-Y-DEV.md +77 -102
  18. package/docs/doc-data.json +34 -14
  19. package/package.json +14 -33
  20. package/docs/AUDITORIA-STATE-OF-THE-ART-2026-11.md +0 -981
  21. package/docs/PENDIENTES.md +0 -1511
  22. package/docs/adr/0013-transiciones-navegacion.md +0 -169
  23. package/docs/adr/0014-list-renderitem-factory.md +0 -41
  24. package/docs/adr/0015-dl-header-versionado.md +0 -57
  25. package/docs/adr/0016-hermes-v1-runtime.md +0 -78
  26. package/docs/adr/0017-encoder-nativo-dl.md +0 -62
  27. package/docs/adr/0018-yoga-tree-nativo.md +0 -78
  28. package/docs/adr/0019-ssr-universal-hidratacion.md +0 -245
  29. package/docs/adr/0020-canvas-draw-list.md +0 -65
  30. package/docs/adr/0021-text-input-props.md +0 -55
  31. package/docs/adr/0022-deep-links.md +0 -49
  32. package/docs/adr/0023-animacion-declarativa.md +0 -130
  33. package/docs/adr/0024-estilos-reactivos-vocabulario.md +0 -100
  34. package/docs/adr/0025-worklets-contrato-runner.md +0 -181
  35. package/docs/adr/0026-threading-js-dedicado.md +0 -94
  36. package/docs/adr/0027-ui-array-children-y-scope-por-fila.md +0 -58
  37. package/docs/adr/0028-commit-por-frame-en-host-embebido.md +0 -93
  38. package/docs/adr/0029-render-commit-latest-wins-screenhost.md +0 -62
  39. package/docs/adr/0030-destruccion-recursiva-ids-monotonicos.md +0 -79
  40. package/docs/adr/0031-scopes-formales-pool-filas.md +0 -76
  41. package/docs/adr/0032-nav-commit-autoritativo.md +0 -64
  42. package/docs/adr/0033-lista-virtual-ventana.md +0 -80
  43. package/docs/adr/0034-attach-event-class-strict-styles.md +0 -89
  44. package/docs/adr/0035-pipeline-imagenes-acotado.md +0 -133
  45. package/docs/adr/0036-data-por-entry-spa.md +0 -91
  46. package/docs/adr/0037-ir-serializable-factories-por-id.md +0 -73
  47. package/docs/adr/0038-transform-keys-compositor.md +0 -79
  48. package/docs/adr/0039-destroy-postorder-scope-ownership.md +0 -86
  49. package/docs/adr/0040-outbound-barriers-overflow-ack.md +0 -60
  50. package/docs/adr/0041-diff-treap-ir-version-strict.md +0 -65
  51. package/docs/adr/0042-data-endpoint-seguridad-hasloader.md +0 -67
  52. package/docs/adr/0043-aplicador-dom-unico.md +0 -70
  53. package/docs/adr/0044-descriptor-runtime-explicito.md +0 -80
  54. package/docs/adr/0045-navstate-versionado-scroll-settle.md +0 -72
  55. package/docs/adr/0046-harness-build-fail-closed.md +0 -99
  56. package/docs/adr/0047-envelope-evento-normalizado.md +0 -110
  57. package/docs/adr/0048-sesion-embebida-estados.md +0 -91
  58. package/docs/adr/0049-strict-styles-valores-portables.md +0 -78
  59. package/docs/adr/0050-update-style-tipado-abi-v5.md +0 -66
  60. package/docs/adr/0051-plugin-sdk-comandos.md +0 -65
  61. package/docs/adr/0052-benchmarks-reproducibles.md +0 -50
  62. package/docs/adr/0053-fling-target-pool-estructural.md +0 -105
  63. package/docs/adr/0054-lista-nativa-render-policy.md +0 -130
  64. package/docs/adr/0055-cesm-core.md +0 -143
  65. package/docs/adr/0056-dos-ejes-superficie-vs-propietario-de-ventana.md +0 -112
  66. package/docs/adr/0057-reset-node-y-firma-de-reciclaje.md +0 -95
  67. package/docs/adr/0058-rollback-de-montaje.md +0 -83
  68. package/docs/adr/0059-traza-on-device-u01-y-scroll-unico-productor.md +0 -89
  69. package/docs/adr/0060-list-update-patch-por-campo.md +0 -73
  70. package/docs/adr/0061-elegibilidad-de-plantilla-nativa.md +0 -70
  71. package/docs/adr/0062-invalidacion-adapter-lista-nativa.md +0 -77
  72. package/docs/adr/0063-autoridad-eventos-y-scroll.md +0 -66
  73. package/docs/adr/0064-admision-unica-de-commits.md +0 -66
  74. package/docs/adr/0065-runtime-de-sesion-u11.md +0 -97
  75. package/docs/adr/0066-perfil-layout-y-safe-area.md +0 -78
  76. package/docs/adr/0067-sesion-robusta-y-procedencia-de-build.md +0 -121
  77. package/docs/adr/0068-metodologia-de-benchmark-y-carril-verificable.md +0 -94
  78. package/docs/adr/0069-schema-de-wire-y-corpus-comun-de-codecs.md +0 -126
  79. package/docs/adr/0070-modelo-publico-de-aplicacion-y-mount.md +0 -91
  80. package/docs/adr/0071-image-service-y-tck-de-plataforma.md +0 -133
  81. package/docs/adr/0072-par-compilador-runtime-hermes.md +0 -62
  82. package/docs/adr/0073-corpus-de-semantica-y-lowering-por-motor.md +0 -67
  83. package/docs/adr/0074-perfil-i18n-formateo-dom-free.md +0 -85
  84. package/docs/adr/0075-back-predictivo-restore-y-layout-adaptativo.md +0 -126
  85. package/docs/adr/0076-contrato-de-modulos-capa-1.md +0 -159
  86. package/docs/adr/0077-manifest-de-plugin-y-plugin-sync.md +0 -109
  87. package/docs/adr/0078-extraccion-de-i18n-a-paquete-propio.md +0 -114
  88. package/docs/adr/0079-handles-de-host-objects-por-epoch.md +0 -96
  89. package/docs/adr/0080-platform-views-por-contrato.md +0 -93
  90. package/docs/adr/0081-codegen-del-dsl-de-modulos.md +0 -118
  91. package/docs/adr/0082-variante-web-de-modulos-nativos.md +0 -126
  92. package/docs/adr/0083-perfiles-dev-release.md +0 -92
  93. package/docs/adr/0084-instrumentacion-acotada-exportable.md +0 -126
  94. package/docs/adr/0085-medicion-agrupada-en-main.md +0 -125
  95. package/docs/adr/0086-matriz-capacidades-props-eventos.md +0 -75
  96. package/docs/adr/0087-uithread-runner-android.md +0 -271
  97. package/docs/adr/0088-worklet-src-estatico.md +0 -82
  98. package/docs/adr/0089-composicion-animaciones-settle-drag.md +0 -122
  99. package/docs/adr/0090-linter-capturas-build.md +0 -94
  100. package/docs/adr/0091-router-core-vs-universal.md +0 -74
  101. package/docs/adr/0092-sharedregion-type-strings.md +0 -59
  102. package/docs/adr/0093-permission-request-estandar.md +0 -52
  103. package/docs/adr/0094-dispatch-worker-timeoutms.md +0 -51
  104. package/docs/adr/0095-tck-modulos.md +0 -65
  105. package/docs/adr/0096-cesm-ring-deferral.md +0 -47
  106. package/docs/adr/0097-tooling-diferido.md +0 -51
  107. package/docs/adr/0098-handshake-moduleabi.md +0 -46
  108. package/docs/adr/0099-modulos-ambient.md +0 -58
  109. package/docs/adr/0100-auto-declaracion-modulos.md +0 -43
  110. package/docs/adr/0101-plataforma-build.md +0 -49
  111. package/docs/adr/0102-permisos-manifest-build.md +0 -38
  112. package/docs/adr/0103-registrant-ownership.md +0 -45
  113. package/docs/adr/0104-toolchain-release.md +0 -125
  114. package/docs/adr/0105-cesm-ring-mode.md +0 -71
  115. package/docs/adr/0106-module-observabilidad.md +0 -100
  116. package/docs/adr/0107-layout-l1-oraculo.md +0 -67
  117. package/docs/adr/0108-semantica-como-ops.md +0 -69
  118. package/docs/adr/0109-text-input-composition.md +0 -64
  119. package/docs/adr/0110-yoga-3-2.md +0 -63
  120. package/docs/adr/0111-hot-reload-con-estado.md +0 -92
  121. package/docs/adr/0112-metricas-nativas-reales.md +0 -65
  122. package/docs/adr/0113-cesm-proyeccion-ampliada.md +0 -80
  123. package/docs/adr/0114-androidx-deps.md +0 -72
  124. package/docs/adr/0115-coil-imagenes.md +0 -57
  125. package/docs/adr/0116-precomputed-text-off-ui.md +0 -49
  126. package/docs/adr/0117-a11y-state-hint-foco.md +0 -54
  127. package/docs/adr/0118-yoga-3-2-vocabulario.md +0 -98
  128. package/docs/adr/0119-codecs-wire-desde-esquema.md +0 -86
  129. package/docs/adr/0120-unidades-logicas-pointscalefactor.md +0 -73
  130. package/docs/adr/0121-yoga-filas-lista.md +0 -100
  131. package/docs/adr/0122-delegado-layout-subarbol.md +0 -140
  132. package/docs/adr/0123-canvas-sobre-skia-raster.md +0 -101
  133. package/docs/adr/0124-evaluacion-taffy-css-grid.md +0 -52
  134. package/docs/adr/0125-paridad-visual-android.md +0 -89
  135. package/docs/adr/0126-documento-web-metadata-enlaces.md +0 -52
  136. package/docs/adr/0127-perfil-l1-shorthand-flex-herencia-texto.md +0 -70
  137. package/docs/adr/0128-pantalla-llena-fragmentos-transparentes.md +0 -56
  138. package/docs/adr/0129-content-visibility-canvas-unidades-logicas.md +0 -37
  139. package/docs/adr/0130-expresiones-reactivas-ui.md +0 -55
  140. package/docs/adr/0131-state-style.md +0 -59
  141. package/docs/adr/0132-create-theme-system-color-scheme.md +0 -58
  142. package/docs/adr/0133-navegacion-rutas-href-chrome.md +0 -59
  143. package/docs/adr/0134-servicios-ambient-modulos-timers.md +0 -63
  144. package/docs/adr/0135-registro-fuentes.md +0 -67
  145. package/docs/adr/0136-i18n-zonas-dst-locale-reactivo.md +0 -70
  146. package/docs/adr/0137-ssg-universal.md +0 -78
  147. package/docs/adr/0138-plantillas-fila-ui-rowref.md +0 -54
  148. package/docs/adr/0139-paridad-geometrica-e-inspector.md +0 -63
  149. package/docs/adr/0140-medida-line-height-css.md +0 -78
  150. package/docs/adr/0141-build-ssr-autocontenido.md +0 -37
  151. package/docs/adr/0142-tema-ssr-cookie-client-hint.md +0 -42
  152. package/docs/adr/0143-paridad-visual-ci.md +0 -51
  153. package/docs/adr/0144-oraculo-layout-chromium.md +0 -45
  154. package/docs/adr/0145-admision-opcodes-wire.md +0 -89
  155. package/docs/adr/0146-presupuesto-divergencias.md +0 -82
  156. package/docs/adr/0147-spans-texto-enriquecido.md +0 -113
  157. package/docs/adr/0148-scroll-restore.md +0 -92
  158. package/docs/adr/0149-gestion-foco.md +0 -94
  159. package/docs/adr/0150-sticky.md +0 -89
  160. package/docs/adr/0151-politica-migracion-snapshots.md +0 -83
  161. package/docs/adr/0152-vocabulario-semantico-v3.md +0 -112
  162. package/docs/adr/0153-puerta-doc-codigo.md +0 -59
  163. package/docs/adr/0154-matriz-paridad.md +0 -79
  164. package/docs/adr/0155-rtl-ambiente.md +0 -73
  165. package/docs/adr/0156-quickjs-ng-0170.md +0 -55
  166. package/docs/adr/0157-qjsc-bytecode-android.md +0 -73
  167. package/docs/adr/0158-abi-host-explicita.md +0 -62
  168. package/docs/adr/0159-entrada-desktop.md +0 -59
  169. package/docs/adr/0160-port-linux-hallazgos-plataforma.md +0 -91
  170. package/docs/adr/0161-paridad-deeplink-alineacion-estructural.md +0 -76
  171. package/docs/adr/0162-fontscale-linux-fuentes.md +0 -63
  172. package/docs/adr/0163-overflow-hidden-linux-clip.md +0 -67
  173. package/docs/adr/0164-nav-transitions-linux.md +0 -126
  174. package/docs/adr/0165-transiciones-declarativas.md +0 -147
  175. package/docs/adr/0166-ime-composition-linux.md +0 -68
  176. package/docs/adr/0167-spans-pango-linux.md +0 -80
  177. package/docs/adr/0168-statestyle-linux.md +0 -65
  178. package/docs/adr/0169-animate-linux.md +0 -114
  179. package/docs/adr/0170-image-service-linux.md +0 -54
  180. package/docs/adr/0171-semantics-atspi-linux.md +0 -80
  181. package/docs/adr/0172-conformidad-de-host-por-terceros.md +0 -159
  182. package/docs/adr/0173-licencias-espec-y-codigo.md +0 -95
  183. package/docs/adr/0174-tabla-estilo-yoga-compartida.md +0 -67
  184. package/docs/adr/0175-easings-normativos-cubic-bezier.md +0 -68
  185. package/docs/adr/0176-harness-plataforma-linux-y-locale-decimal.md +0 -80
  186. package/docs/adr/0177-gaps-linux-dir-as-navstate.md +0 -84
  187. package/docs/adr/0178-matriz-linux-y-tablas-normativas-generadas.md +0 -104
  188. package/docs/adr/0179-eventos-gesto-y-teclado.md +0 -132
  189. package/docs/adr/0180-desktop-nativo-linux-windows-macos-chromeos.md +0 -58
  190. package/docs/adr/0181-linux-platform-views-uiworklet-y-gaps-certificados.md +0 -101
  191. package/docs/adr/0182-sdui-envelope-dialecto-rico-y-lowering.md +0 -452
  192. package/docs/adr/0183-hermes-es6-block-scoping-en-source-eval.md +0 -99
  193. package/docs/adr/0184-sdui-consumidor-de-referencia-y-modulo-http.md +0 -72
  194. package/docs/adr/0185-sdui-modelo-de-seguridad-del-envelope.md +0 -160
  195. package/docs/adr/0186-linux-packaging-deb-rpm-flatpak.md +0 -61
  196. package/docs/adr/0187-modelo-de-hilos-ejecutores-logicos.md +0 -163
  197. package/docs/adr/0188-sdui-seguridad-hardening.md +0 -214
  198. package/docs/adr/0189-worklets-web-worker-y-egreso-pinning.md +0 -235
  199. package/docs/adr/0190-semantics-actions-linux-via-gaction-muxer.md +0 -102
  200. package/docs/adr/0191-reporte-de-errores-en-produccion.md +0 -126
  201. package/docs/adr/0192-source-maps-y-simbolizacion-de-stacks.md +0 -107
  202. package/docs/adr/0193-renderer-skia-opt-in-en-linux.md +0 -143
  203. package/docs/adr/0194-superficie-declarada-y-carril-skia-tree.md +0 -96
  204. package/docs/adr/0195-bundles-embebidos-subpaths-core.md +0 -66
  205. package/docs/adr/0196-matriz-capacidades-verdad.md +0 -84
  206. package/docs/adr/0197-entorno-reactivo-cableado.md +0 -67
  207. package/docs/adr/0198-csprng-host-wintertc.md +0 -57
  208. package/docs/adr/0199-testing-harness-dom-free.md +0 -59
  209. package/docs/adr/0200-overlays-back-foco.md +0 -84
  210. package/docs/adr/0201-paridad-nativa-props-texto-fase1.md +0 -79
  211. package/docs/adr/0202-node-ref-measure-web.md +0 -61
  212. package/docs/adr/0203-primitivas-headless.md +0 -54
  213. package/docs/adr/0204-imagen-load-error-fallback.md +0 -123
  214. package/docs/adr/0205-primitivas-controls-fase2.md +0 -79
  215. package/docs/adr/0206-a2ui-catalogo-tabs-modal-choicepicker-icon.md +0 -110
  216. package/docs/adr/0207-a2ui-superficie-viva.md +0 -104
  217. package/docs/adr/0208-a2ui-checks-validacion.md +0 -94
  218. package/docs/adr/0209-loaddata-nativo-default.md +0 -56
  219. package/docs/adr/0210-primitivas-navegacion-fase3.md +0 -69
  220. package/docs/adr/0211-a2ui-formato-localizado.md +0 -113
  221. package/docs/adr/0212-red-fuera-del-core.md +0 -67
  222. package/docs/adr/0213-dev-fast-y-rutas-automaticas.md +0 -68
  223. package/docs/adr/0214-dev-web-server-reload.md +0 -55
  224. package/docs/adr/0215-ui-host-noderef-back-http-linux.md +0 -77
  225. package/docs/adr/0216-paridad-nativa-switch-scroll-lista.md +0 -53
  226. package/docs/adr/0217-overlays-drag-y-popover-anclado.md +0 -64
  227. package/docs/adr/0218-sdui-gateway-live-mcp-y-scaffold.md +0 -32
  228. package/docs/adr/0219-event-ref-envelope-y-oracle-scroll-aware.md +0 -82
  229. package/docs/adr/0220-target-windows-winui3.md +0 -331
  230. package/docs/adr/0221-shell-tabs-desktop-normativa.md +0 -45
  231. package/docs/adr/0222-a2ui-v1-dialecto-por-superficie.md +0 -109
  232. package/docs/adr/README.md +0 -230
  233. package/docs/deuda/i18n-libreria-separada.md +0 -50
  234. package/docs/propuestas/dx-y-paridad.md +0 -684
  235. package/docs/propuestas/investigacion-apps-completas/PENDIENTES-CORE-APPS-COMPLETAS.md +0 -226
  236. package/docs/propuestas/investigacion-apps-completas/arquitectura-motor-videojuegos-elur.md +0 -254
  237. package/docs/propuestas/investigacion-apps-completas/auditoria-paridad-frameworks-y-sdui.md +0 -295
  238. package/docs/propuestas/investigacion-apps-completas/ciclo-de-vida-dx-y-apps-completas.md +0 -394
  239. package/docs/propuestas/investigacion-apps-completas/crear-proyecto-desde-npm-y-agentes.md +0 -477
  240. package/docs/propuestas/investigacion-apps-completas/especificacion-arquitectura-capacidades-faltantes.md +0 -407
  241. package/docs/propuestas/investigacion-apps-completas/identidad-y-nombre-elur-universal.md +0 -133
  242. package/docs/propuestas/investigacion-apps-completas/migracion-elur-core-4.md +0 -266
  243. package/docs/propuestas/investigacion-apps-completas/sdui-a2ui-aplicaciones-completas.md +0 -255
  244. package/docs/propuestas/investigacion-apps-completas/verificacion-mejoras-y-brechas-nuevas.md +0 -228
  245. package/docs/propuestas/modelo-de-consumo.md +0 -287
  246. package/docs/propuestas/modulos-nativos.md +0 -1062
  247. package/docs/propuestas/palabras-clave-normativas.md +0 -69
  248. package/docs/propuestas/sdui-seguridad-hardening.md +0 -322
  249. package/docs/propuestas/skia-graphite.md +0 -167
  250. package/docs/propuestas/skia-renderer-arbol.md +0 -603
  251. package/docs/propuestas/targets-nativos-nuevos.md +0 -359
  252. package/docs/propuestas/toolchain-y-distribucion.md +0 -311
  253. package/docs/propuestas/ui-worklet-capacidades-exclusivas.md +0 -114
  254. package/examples/a11ylive/elur.app.json +0 -8
  255. package/examples/a11ylive/entry.ts +0 -22
  256. package/examples/a11ysem/elur.app.json +0 -8
  257. package/examples/a11ysem/entry.ts +0 -24
  258. package/examples/anim/elur.app.json +0 -8
  259. package/examples/anim/entry.ts +0 -50
  260. package/examples/app.ts +0 -10
  261. package/examples/cliprad/elur.app.json +0 -8
  262. package/examples/cliprad/entry.ts +0 -16
  263. package/examples/controls/app.ts +0 -32
  264. package/examples/controls/elur.app.json +0 -8
  265. package/examples/counter/app.ts +0 -21
  266. package/examples/counter/elur.app.json +0 -8
  267. package/examples/counter/entry.ts +0 -7
  268. package/examples/entry.ts +0 -11
  269. package/examples/feedstress/app.ts +0 -334
  270. package/examples/feedstress/elur.app.json +0 -8
  271. package/examples/feedstress/entry.ts +0 -7
  272. package/examples/i18n/app.ts +0 -86
  273. package/examples/i18n/elur.app.json +0 -8
  274. package/examples/i18n/entry.ts +0 -22
  275. package/examples/imecomp/elur.app.json +0 -8
  276. package/examples/imecomp/entry.ts +0 -41
  277. package/examples/imgtest/elur.app.json +0 -8
  278. package/examples/imgtest/entry.ts +0 -18
  279. package/examples/mareas/app/ajustes/page.ts +0 -54
  280. package/examples/mareas/app/page.ts +0 -91
  281. package/examples/mareas/app/puerto/[id]/page.ts +0 -106
  282. package/examples/mareas/app.ts +0 -12
  283. package/examples/mareas/elur.app.json +0 -35
  284. package/examples/mareas/entry.ts +0 -11
  285. package/examples/mareas/fonts/DejaVuSansMono-Bold.ttf +0 -0
  286. package/examples/mareas/fonts/DejaVuSansMono.ttf +0 -0
  287. package/examples/mareas/fonts/DejaVuSerif-Bold.ttf +0 -0
  288. package/examples/mareas/fonts/DejaVuSerif-Italic.ttf +0 -0
  289. package/examples/mareas/fonts/DejaVuSerif.ttf +0 -0
  290. package/examples/mareas/fonts/LICENSE-DejaVu.txt +0 -187
  291. package/examples/mareas/fonts.ts +0 -6
  292. package/examples/mareas/head.ts +0 -12
  293. package/examples/mareas/i18n.ts +0 -163
  294. package/examples/mareas/ports.ts +0 -131
  295. package/examples/mareas/routes.gen.ts +0 -44
  296. package/examples/mareas/serve.ts +0 -70
  297. package/examples/mareas/services.ts +0 -5
  298. package/examples/mareas/services.web.ts +0 -6
  299. package/examples/mareas/state.ts +0 -64
  300. package/examples/mareas/theme.ts +0 -56
  301. package/examples/mareas/ui/controls.ts +0 -42
  302. package/examples/mareas/ui/frame.ts +0 -63
  303. package/examples/mareas/ui/marigram.ts +0 -52
  304. package/examples/masonry/app.ts +0 -32
  305. package/examples/masonry/elur.app.json +0 -8
  306. package/examples/masonry/entry.ts +0 -4
  307. package/examples/natprobe/elur.app.json +0 -8
  308. package/examples/natprobe/entry-a11y.ts +0 -52
  309. package/examples/natprobe/entry-tinput.ts +0 -73
  310. package/examples/natprobe/entry-tml.ts +0 -46
  311. package/examples/natprobe/entry.ts +0 -285
  312. package/examples/navdemo/app.ts +0 -109
  313. package/examples/navdemo/elur.app.json +0 -8
  314. package/examples/navdemo/entry.ts +0 -7
  315. package/examples/navtrans/elur.app.json +0 -8
  316. package/examples/navtrans/entry.ts +0 -53
  317. package/examples/platformview/app.ts +0 -26
  318. package/examples/platformview/elur.app.json +0 -8
  319. package/examples/sdui-demo/docs/home.envelope.json +0 -588
  320. package/examples/sdui-demo/docs/home.iife.json +0 -582
  321. package/examples/sdui-demo/elur.app.json +0 -8
  322. package/examples/sdui-demo/entry.ts +0 -346
  323. package/examples/select/elur.app.json +0 -8
  324. package/examples/select/entry.ts +0 -20
  325. package/examples/skiacanvas/app.ts +0 -34
  326. package/examples/skiacanvas/elur.app.json +0 -8
  327. package/examples/skiacanvas/entry.ts +0 -4
  328. package/examples/spans/elur.app.json +0 -8
  329. package/examples/spans/entry.ts +0 -28
  330. package/examples/ssr/app/about/page.ts +0 -18
  331. package/examples/ssr/app/items/[id]/page.ts +0 -16
  332. package/examples/ssr/app/layout.ts +0 -21
  333. package/examples/ssr/app/page.action.ts +0 -10
  334. package/examples/ssr/app/page.data.ts +0 -5
  335. package/examples/ssr/app/page.ts +0 -95
  336. package/examples/ssr/app/slow/loading.ts +0 -10
  337. package/examples/ssr/app/slow/page.data.ts +0 -4
  338. package/examples/ssr/app/slow/page.ts +0 -16
  339. package/examples/ssr/app/store.ts +0 -3
  340. package/examples/ssr/serve.ts +0 -53
  341. package/examples/statestyle/elur.app.json +0 -8
  342. package/examples/statestyle/entry.ts +0 -25
  343. package/examples/swipe/elur.app.json +0 -8
  344. package/examples/swipe/entry.ts +0 -39
  345. package/examples/tasks/app.ts +0 -145
  346. package/examples/tasks/elur.app.json +0 -8
  347. package/examples/uiprops/elur.app.json +0 -8
  348. package/examples/uiprops/entry.ts +0 -65
  349. package/examples/uiwk/app.ts +0 -288
  350. package/examples/uiwk/elur.app.json +0 -8
  351. package/examples/uiwk/entry.ts +0 -7
  352. package/examples/vertical/app.ts +0 -275
  353. package/examples/vertical/elur.app.json +0 -8
  354. package/examples/vertical/entry.ts +0 -31
  355. package/examples/yogafeatures/app.ts +0 -55
  356. package/examples/yogafeatures/elur.app.json +0 -8
  357. package/examples/yogafeatures/entry.ts +0 -4
  358. package/native/cesm/tests/CMakeLists.txt +0 -50
  359. package/native/cesm/tests/README.md +0 -89
  360. package/native/cesm/tests/compile_check_hermes.cpp +0 -23
  361. package/native/cesm/tests/test_core.cpp +0 -101
  362. package/native/cesm/tests/test_main.cpp +0 -13
  363. package/native/cesm/tests/test_quickjs_adapter.cpp +0 -252
  364. package/native/cesm/tests/test_ring.cpp +0 -131
  365. package/native/cesm/tests/test_slots.cpp +0 -81
  366. package/native/cesm/tests/test_sync.cpp +0 -157
  367. package/native/cesm/tests/test_util.h +0 -24
  368. package/targets/android/app/build.gradle.kts +0 -192
  369. package/targets/android/app/proguard-rules-elur.pro +0 -12
  370. package/targets/android/app/proguard-rules.pro +0 -3
  371. package/targets/android/app/src/main/AndroidManifest.xml +0 -81
  372. package/targets/android/app/src/main/cpp/CMakeLists.txt +0 -117
  373. package/targets/android/app/src/main/cpp/dlEncoder.h +0 -117
  374. package/targets/android/app/src/main/cpp/dlEncoderJsi.cpp +0 -315
  375. package/targets/android/app/src/main/cpp/dlEncoderQjs.cpp +0 -394
  376. package/targets/android/app/src/main/cpp/dlOps.inc +0 -145
  377. package/targets/android/app/src/main/cpp/elurBridge.cpp +0 -1350
  378. package/targets/android/app/src/main/cpp/elurBridgeHermes.cpp +0 -1294
  379. package/targets/android/app/src/main/cpp/elurSkia.cpp +0 -287
  380. package/targets/android/app/src/main/cpp/elurSkiaTree.cpp +0 -448
  381. package/targets/android/app/src/main/cpp/elurUiWorklet.cpp +0 -1233
  382. package/targets/android/app/src/main/cpp/elurYoga.cpp +0 -1060
  383. package/targets/android/app/src/main/cpp/elurYoga.h +0 -82
  384. package/targets/android/app/src/main/cpp/hermes-libs/LICENSE +0 -21
  385. package/targets/android/app/src/main/cpp/hermes-libs/arm64-v8a/libhermesvm.so +0 -0
  386. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/AsyncDebuggerAPI.h +0 -276
  387. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/CompileJS.h +0 -97
  388. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/DebuggerAPI.h +0 -502
  389. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/CrashManager.h +0 -107
  390. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/CtorConfig.h +0 -145
  391. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/DebuggerTypes.h +0 -193
  392. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/GCConfig.h +0 -211
  393. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/GCTripwireContext.h +0 -40
  394. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/HermesExport.h +0 -14
  395. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/JSOutOfMemoryError.h +0 -27
  396. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/RuntimeConfig.h +0 -141
  397. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/Public/SamplingProfiler.h +0 -270
  398. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/RuntimeTaskRunner.h +0 -64
  399. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/SynthTrace.h +0 -1566
  400. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/SynthTraceParser.h +0 -37
  401. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/ThreadSafetyAnalysis.h +0 -75
  402. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/TimerStats.h +0 -23
  403. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/TraceInterpreter.h +0 -334
  404. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/TracingRuntime.h +0 -328
  405. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPAgent.h +0 -131
  406. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPDebugAPI.h +0 -73
  407. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/CallbackOStream.h +0 -89
  408. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/ConsoleMessage.h +0 -135
  409. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainAgent.h +0 -280
  410. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainCoordinator.h +0 -137
  411. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainAgent.h +0 -107
  412. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainState.h +0 -140
  413. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/HeapProfilerDomainAgent.h +0 -71
  414. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/JSONValueInterfaces.h +0 -40
  415. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageConverters.h +0 -82
  416. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageInterfaces.h +0 -72
  417. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypes.h +0 -1279
  418. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypesInlines.h +0 -313
  419. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/ProfilerDomainAgent.h +0 -38
  420. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectConverters.h +0 -77
  421. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectsTable.h +0 -127
  422. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/cdp/RuntimeDomainAgent.h +0 -138
  423. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/Dummy.h +0 -24
  424. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/Extensions.h +0 -20
  425. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/ExtensionsBytecode.h +0 -23
  426. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/Intrinsics.h +0 -44
  427. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/JSIUtils.h +0 -123
  428. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/TextEncoder.h +0 -29
  429. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribDummy.h +0 -24
  430. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribExtensions.h +0 -23
  431. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoder.h +0 -30
  432. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoderUtils.h +0 -113
  433. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/hermes.h +0 -242
  434. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes/hermes_tracing.h +0 -52
  435. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIHelpers.h +0 -295
  436. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIRuntimeWrapper.h +0 -25
  437. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_abi.h +0 -642
  438. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_vtable.h +0 -29
  439. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/HermesSandboxRuntime.h +0 -41
  440. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_compiled.h +0 -12
  441. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled-impl.h +0 -8516
  442. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled.h +0 -137
  443. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled-impl.h +0 -3945
  444. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled.h +0 -119
  445. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-fb.h +0 -124
  446. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-impl.h +0 -66
  447. package/targets/android/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt.h +0 -456
  448. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/JSIDynamic.h +0 -26
  449. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/decorator.h +0 -1157
  450. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/hermes-interfaces.h +0 -242
  451. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/instrumentation.h +0 -132
  452. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/jsi-inl.h +0 -434
  453. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/jsi.h +0 -2266
  454. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/jsilib.h +0 -59
  455. package/targets/android/app/src/main/cpp/hermes-libs/include/jsi/threadsafe.h +0 -79
  456. package/targets/android/app/src/main/cpp/hermes-libs/jsi-impl/jsi.cpp +0 -1111
  457. package/targets/android/app/src/main/cpp/hermes-libs/x86_64/libhermesvm.so +0 -0
  458. package/targets/android/app/src/main/java/com/elur/universal/BinaryCodec.kt +0 -121
  459. package/targets/android/app/src/main/java/com/elur/universal/DlDecoder.kt +0 -260
  460. package/targets/android/app/src/main/java/com/elur/universal/DlOpsDecode.kt +0 -158
  461. package/targets/android/app/src/main/java/com/elur/universal/ElurBoxDrawable.kt +0 -161
  462. package/targets/android/app/src/main/java/com/elur/universal/ElurBridge.kt +0 -238
  463. package/targets/android/app/src/main/java/com/elur/universal/ElurBridgeHermes.kt +0 -223
  464. package/targets/android/app/src/main/java/com/elur/universal/ElurCanvasView.kt +0 -202
  465. package/targets/android/app/src/main/java/com/elur/universal/ElurCryptoModule.kt +0 -206
  466. package/targets/android/app/src/main/java/com/elur/universal/ElurCustomLayout.kt +0 -185
  467. package/targets/android/app/src/main/java/com/elur/universal/ElurEditText.kt +0 -17
  468. package/targets/android/app/src/main/java/com/elur/universal/ElurFontRegistry.kt +0 -190
  469. package/targets/android/app/src/main/java/com/elur/universal/ElurHttpModule.kt +0 -306
  470. package/targets/android/app/src/main/java/com/elur/universal/ElurImageService.kt +0 -348
  471. package/targets/android/app/src/main/java/com/elur/universal/ElurLicensesActivity.kt +0 -84
  472. package/targets/android/app/src/main/java/com/elur/universal/ElurListView.kt +0 -954
  473. package/targets/android/app/src/main/java/com/elur/universal/ElurManifest.kt +0 -117
  474. package/targets/android/app/src/main/java/com/elur/universal/ElurMetrics.kt +0 -325
  475. package/targets/android/app/src/main/java/com/elur/universal/ElurModuleRegistrar.kt +0 -14
  476. package/targets/android/app/src/main/java/com/elur/universal/ElurPermissionGate.kt +0 -36
  477. package/targets/android/app/src/main/java/com/elur/universal/ElurRenderer.kt +0 -6164
  478. package/targets/android/app/src/main/java/com/elur/universal/ElurRowYoga.kt +0 -130
  479. package/targets/android/app/src/main/java/com/elur/universal/ElurScrollView.kt +0 -240
  480. package/targets/android/app/src/main/java/com/elur/universal/ElurShellView.kt +0 -117
  481. package/targets/android/app/src/main/java/com/elur/universal/ElurSkiaCanvasView.kt +0 -162
  482. package/targets/android/app/src/main/java/com/elur/universal/ElurSkiaTreeRenderer.kt +0 -968
  483. package/targets/android/app/src/main/java/com/elur/universal/ElurStateModule.kt +0 -69
  484. package/targets/android/app/src/main/java/com/elur/universal/ElurSwipeDriver.kt +0 -34
  485. package/targets/android/app/src/main/java/com/elur/universal/ElurTckModule.kt +0 -99
  486. package/targets/android/app/src/main/java/com/elur/universal/ElurTextMeasure.kt +0 -16
  487. package/targets/android/app/src/main/java/com/elur/universal/ElurTrace.kt +0 -24
  488. package/targets/android/app/src/main/java/com/elur/universal/ElurUiModule.kt +0 -48
  489. package/targets/android/app/src/main/java/com/elur/universal/ElurUiWorklet.kt +0 -305
  490. package/targets/android/app/src/main/java/com/elur/universal/JsBridge.kt +0 -67
  491. package/targets/android/app/src/main/java/com/elur/universal/JsThread.kt +0 -189
  492. package/targets/android/app/src/main/java/com/elur/universal/MainActivity.kt +0 -844
  493. package/targets/android/app/src/main/java/com/elur/universal/ModuleRegistry.kt +0 -701
  494. package/targets/android/app/src/main/java/com/elur/universal/YogaRowScope.kt +0 -97
  495. package/targets/android/app/src/main/res/values/ids.xml +0 -10
  496. package/targets/android/app/src/main/res/values/strings.xml +0 -8
  497. package/targets/android/app/src/main/res/values-es/strings.xml +0 -5
  498. package/targets/android/app/src/main/res/xml/network_security_config.xml +0 -10
  499. package/targets/android/build.gradle.kts +0 -5
  500. package/targets/android/gradle/libs.versions.toml +0 -12
  501. package/targets/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  502. package/targets/android/gradle/wrapper/gradle-wrapper.properties +0 -8
  503. package/targets/android/gradle.properties +0 -23
  504. package/targets/android/gradlew +0 -251
  505. package/targets/android/gradlew.bat +0 -94
  506. package/targets/android/settings.gradle.kts +0 -32
  507. package/targets/linux/CMakeLists.txt +0 -196
  508. package/targets/linux/README.md +0 -422
  509. package/targets/linux/ci/tsan.supp +0 -15
  510. package/targets/linux/generated/elur_module_registrar.cpp +0 -18
  511. package/targets/linux/generated/module_sources.cmake +0 -7
  512. package/targets/linux/src/elur_applicator.cpp +0 -5073
  513. package/targets/linux/src/elur_applicator.h +0 -387
  514. package/targets/linux/src/elur_clip.cpp +0 -76
  515. package/targets/linux/src/elur_clip.h +0 -23
  516. package/targets/linux/src/elur_crypto_module.cpp +0 -121
  517. package/targets/linux/src/elur_events.h +0 -57
  518. package/targets/linux/src/elur_fonts.cpp +0 -106
  519. package/targets/linux/src/elur_fonts.h +0 -31
  520. package/targets/linux/src/elur_host.cpp +0 -1041
  521. package/targets/linux/src/elur_host.h +0 -66
  522. package/targets/linux/src/elur_http_module.cpp +0 -437
  523. package/targets/linux/src/elur_js.h +0 -40
  524. package/targets/linux/src/elur_modules.cpp +0 -453
  525. package/targets/linux/src/elur_modules.h +0 -159
  526. package/targets/linux/src/elur_renderer.h +0 -46
  527. package/targets/linux/src/elur_shot.cpp +0 -64
  528. package/targets/linux/src/elur_shot.h +0 -17
  529. package/targets/linux/src/elur_skia_a11y.cpp +0 -987
  530. package/targets/linux/src/elur_skia_a11y.h +0 -146
  531. package/targets/linux/src/elur_skia_app.cpp +0 -1770
  532. package/targets/linux/src/elur_skia_app.h +0 -18
  533. package/targets/linux/src/elur_state_module.cpp +0 -99
  534. package/targets/linux/src/elur_tck_module.cpp +0 -186
  535. package/targets/linux/src/elur_ui_module.cpp +0 -84
  536. package/targets/linux/src/elur_yoga.cpp +0 -452
  537. package/targets/linux/src/elur_yoga.h +0 -95
  538. package/targets/linux/src/main.cpp +0 -294
  539. package/targets/windows/Package.appxmanifest +0 -28
  540. package/targets/windows/README.md +0 -44
  541. package/targets/windows/elur-windows.vcxproj +0 -133
  542. package/targets/windows/packages.config +0 -10
  543. package/targets/windows/src/elur_crypto_module_win.cpp +0 -110
  544. package/targets/windows/src/elur_events.h +0 -58
  545. package/targets/windows/src/elur_host_win.cpp +0 -645
  546. package/targets/windows/src/elur_host_win.h +0 -75
  547. package/targets/windows/src/elur_http_module_win.cpp +0 -333
  548. package/targets/windows/src/elur_js.h +0 -40
  549. package/targets/windows/src/elur_modules.cpp +0 -460
  550. package/targets/windows/src/elur_modules.h +0 -159
  551. package/targets/windows/src/elur_state_module.cpp +0 -99
  552. package/targets/windows/src/elur_ui_module_win.cpp +0 -75
  553. package/targets/windows/src/elur_uia_host.h +0 -129
  554. package/targets/windows/src/elur_win_applicator.cpp +0 -3242
  555. package/targets/windows/src/elur_win_applicator.h +0 -187
  556. package/targets/windows/src/elur_yoga.cpp +0 -453
  557. package/targets/windows/src/elur_yoga.h +0 -95
  558. package/targets/windows/src/main.cpp +0 -321
@@ -1,3242 +0,0 @@
1
- // elur_win_applicator.cpp — ver header. M1: tipos box/column/row/
2
- // text/button/text-input/switch/scroll-view/image/stack (fallback a
3
- // contenedor); eventos press/input/change/submit/scroll; estilos
4
- // visuales bg/color/fontSize/fontWeight/borderRadius/borders/opacity/
5
- // textAlign/padding-visual; resto → warnOnce honesto.
6
-
7
- #include "elur_win_applicator.h"
8
-
9
- #include "elur_js.h"
10
- #include "elur_modules.h"
11
- #include "elur_yoga.h"
12
-
13
- #include <algorithm>
14
- #include <cctype>
15
- #include <climits>
16
- #include <cmath>
17
- #include <cstdio>
18
- #include <cstdlib>
19
- #include <fstream>
20
- #include <winrt/Microsoft.UI.Dispatching.h>
21
- #include <winrt/Microsoft.UI.Input.h>
22
- #include <winrt/Microsoft.UI.Text.h>
23
- #include <winrt/Microsoft.UI.Xaml.Automation.Peers.h>
24
- #include <winrt/Microsoft.UI.Xaml.Automation.h>
25
- #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
26
- #include <winrt/Microsoft.UI.Xaml.Documents.h>
27
- #include <winrt/Microsoft.UI.Xaml.Input.h>
28
- #include <winrt/Microsoft.UI.Xaml.Media.Animation.h>
29
- #include <winrt/Microsoft.UI.Xaml.Media.Imaging.h>
30
- #include <winrt/Microsoft.UI.Xaml.Media.h>
31
- #include <winrt/Windows.Foundation.Collections.h>
32
- #include <winrt/Windows.Foundation.Numerics.h>
33
- #include <winrt/Windows.Foundation.h>
34
- #include <winrt/Windows.Security.Cryptography.h>
35
- #include <winrt/Windows.Storage.Streams.h>
36
- #include <winrt/Windows.System.h>
37
- #include <winrt/Windows.UI.Core.h>
38
- #include <winrt/Windows.UI.h>
39
- #include <winrt/base.h>
40
-
41
- namespace wf = winrt::Windows::Foundation;
42
- namespace wu = winrt::Windows::UI;
43
- namespace wut = winrt::Microsoft::UI::Text;
44
- namespace mui = winrt::Microsoft::UI::Input;
45
- namespace muxd = winrt::Microsoft::UI::Xaml::Documents;
46
- namespace muxm = winrt::Microsoft::UI::Xaml::Media;
47
- namespace muxi = winrt::Microsoft::UI::Xaml::Input;
48
- namespace mud = winrt::Microsoft::UI::Dispatching;
49
- using winrt::Microsoft::UI::Xaml::Thickness;
50
- using winrt::Windows::Foundation::Size;
51
-
52
- void dlog(const char *fmt, ...);
53
-
54
- namespace elur {
55
-
56
- WinApplicator g_winapp;
57
-
58
- namespace {
59
-
60
- // "#rrggbb" | "#aarrggbb" | "rgb(r,g,b)" → Color. "" → transparent.
61
- wu::Color parseColor(const std::string &s, bool &ok) {
62
- ok = false;
63
- auto hex = [](char c) -> int {
64
- if (c >= '0' && c <= '9') return c - '0';
65
- if (c >= 'a' && c <= 'f') return c - 'a' + 10;
66
- if (c >= 'A' && c <= 'F') return c - 'A' + 10;
67
- return -1;
68
- };
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
- }
74
- if (s.size() == 4 && s[0] == '#') {
75
- // #rgb shorthand — Color.parseColor (android) y gdk_rgba_parse
76
- // (GTK) lo aceptan; el wire lo emite verbatim.
77
- int r = hex(s[1]), g = hex(s[2]), b = hex(s[3]);
78
- if (r < 0 || g < 0 || b < 0) return {};
79
- ok = true;
80
- return wu::Color{255, (uint8_t)dup(r), (uint8_t)dup(g),
81
- (uint8_t)dup(b)};
82
- }
83
- if (s.size() == 5 && s[0] == '#') {
84
- int a = hex(s[1]), r = hex(s[2]), g = hex(s[3]), b = hex(s[4]);
85
- if (a < 0 || r < 0 || g < 0 || b < 0) return {};
86
- ok = true;
87
- return wu::Color{(uint8_t)dup(a), (uint8_t)dup(r), (uint8_t)dup(g),
88
- (uint8_t)dup(b)};
89
- }
90
- if (s.size() == 7 && s[0] == '#') {
91
- wu::Color c{255, 0, 0, 0};
92
- int v[3];
93
- for (int i = 0; i < 3; i++) {
94
- int h1 = hex(s[1 + i * 2]), h2 = hex(s[2 + i * 2]);
95
- if (h1 < 0 || h2 < 0) return {};
96
- v[i] = h1 * 16 + h2;
97
- }
98
- c.R = (uint8_t)v[0]; c.G = (uint8_t)v[1]; c.B = (uint8_t)v[2];
99
- ok = true;
100
- return c;
101
- }
102
- if (s.size() == 9 && s[0] == '#') {
103
- wu::Color c;
104
- int v[4];
105
- for (int i = 0; i < 4; i++) {
106
- int h1 = hex(s[1 + i * 2]), h2 = hex(s[2 + i * 2]);
107
- if (h1 < 0 || h2 < 0) return {};
108
- v[i] = h1 * 16 + h2;
109
- }
110
- c.A = (uint8_t)v[0]; c.R = (uint8_t)v[1]; c.G = (uint8_t)v[2];
111
- c.B = (uint8_t)v[3];
112
- ok = true;
113
- return c;
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
- }
124
- if (s.rfind("rgb(", 0) == 0 && s.size() > 5) {
125
- int r = 0, g = 0, b = 0;
126
- if (sscanf_s(s.c_str() + 4, "%d,%d,%d", &r, &g, &b) == 3) {
127
- ok = true;
128
- return wu::Color{255, (uint8_t)r, (uint8_t)g, (uint8_t)b};
129
- }
130
- }
131
- return {};
132
- }
133
-
134
- muxm::Brush brushOf(const std::string &s) {
135
- bool ok = false;
136
- wu::Color c = parseColor(s, ok);
137
- if (!ok)
138
- return nullptr;
139
- return muxm::SolidColorBrush(c);
140
- }
141
-
142
- winrt::hstring hs(const std::string &s) {
143
- int n = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(),
144
- nullptr, 0);
145
- std::wstring w((size_t)n, L'\0');
146
- MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), w.data(), n);
147
- return winrt::hstring(w);
148
- }
149
-
150
- // Sufijos "px" tolerados (el wire emite números o "12px").
151
- double pxOf(const std::string &s, double dflt = 0) {
152
- if (s.empty())
153
- return dflt;
154
- return atof(s.c_str());
155
- }
156
-
157
- // Xaml no permite reparenting directo (E_INVALIDARG si el elemento ya
158
- // tiene padre visual; GTK lo toleraba). Hay que quitarlo primero.
159
- void detachVisual(mux::UIElement const &el) {
160
- if (!el)
161
- return;
162
- auto fe = el.try_as<mux::FrameworkElement>();
163
- if (!fe)
164
- return;
165
- auto parent = fe.Parent();
166
- if (!parent)
167
- return;
168
- if (auto panel = parent.try_as<muxc::Panel>()) {
169
- auto children = panel.Children();
170
- uint32_t idx = 0;
171
- if (children.IndexOf(el, idx))
172
- children.RemoveAt(idx);
173
- } else if (auto border = parent.try_as<muxc::Border>()) {
174
- if (border.Child() == el)
175
- border.Child(nullptr);
176
- } else if (auto sv = parent.try_as<muxc::ScrollViewer>()) {
177
- if (sv.Content() == el)
178
- sv.Content(nullptr);
179
- } else if (auto cc = parent.try_as<muxc::ContentControl>()) {
180
- if (cc.Content() == el)
181
- cc.Content(nullptr);
182
- }
183
- }
184
-
185
- } // namespace
186
-
187
- void WinApplicator::warnOnce(std::unordered_map<std::string, int> &m,
188
- const char *kind, const std::string &what) {
189
- if (++m[what] == 1)
190
- fprintf(stderr, "[elur-windows] %s sin soporte aún: %s\n", kind,
191
- what.c_str());
192
- }
193
-
194
- namespace {
195
-
196
- // VirtualKey → nombre DOM `KeyboardEvent.key` (ADR-0159/0179 — misma
197
- // tabla que elurDomKeyName en el host GTK: "Return"→"Enter",
198
- // "Left"→"ArrowLeft"; letras en minúscula, el shift llega en mods).
199
- std::string domKeyName(winrt::Windows::System::VirtualKey k) {
200
- namespace vk = winrt::Windows::System;
201
- switch (k) {
202
- case vk::VirtualKey::Enter: return "Enter";
203
- case vk::VirtualKey::Tab: return "Tab";
204
- case vk::VirtualKey::Back: return "Backspace";
205
- case vk::VirtualKey::Delete: return "Delete";
206
- case vk::VirtualKey::Left: return "ArrowLeft";
207
- case vk::VirtualKey::Right: return "ArrowRight";
208
- case vk::VirtualKey::Up: return "ArrowUp";
209
- case vk::VirtualKey::Down: return "ArrowDown";
210
- case vk::VirtualKey::Home: return "Home";
211
- case vk::VirtualKey::End: return "End";
212
- case vk::VirtualKey::PageUp: return "PageUp";
213
- case vk::VirtualKey::PageDown: return "PageDown";
214
- case vk::VirtualKey::Escape: return "Escape";
215
- case vk::VirtualKey::Space: return " ";
216
- case vk::VirtualKey::Shift:
217
- case vk::VirtualKey::LeftShift:
218
- case vk::VirtualKey::RightShift: return "Shift";
219
- case vk::VirtualKey::Control:
220
- case vk::VirtualKey::LeftControl:
221
- case vk::VirtualKey::RightControl: return "Control";
222
- case vk::VirtualKey::Menu:
223
- case vk::VirtualKey::LeftMenu:
224
- case vk::VirtualKey::RightMenu: return "Alt";
225
- case vk::VirtualKey::LeftWindows:
226
- case vk::VirtualKey::RightWindows: return "Meta";
227
- case vk::VirtualKey::Add: return "+";
228
- default: break;
229
- }
230
- int i = (int)k;
231
- if (i >= 'A' && i <= 'Z')
232
- return std::string(1, (char)tolower(i));
233
- if (i >= '0' && i <= '9')
234
- return std::string(1, (char)i);
235
- if (i >= 0x70 && i <= 0x87) // F1..F24
236
- return "F" + std::to_string(i - 0x6f);
237
- return "";
238
- }
239
-
240
- bool modDown(winrt::Windows::System::VirtualKey a,
241
- winrt::Windows::System::VirtualKey b,
242
- winrt::Windows::System::VirtualKey c) {
243
- // InputKeyboardSource (Microsoft.UI.Input) es el API para WinUI 3
244
- // desktop — CoreWindow.GetForCurrentThread devuelve null en apps de
245
- // escritorio (solo existe en UWP) y los modificadores no se leen.
246
- namespace wuc = winrt::Windows::UI::Core;
247
- auto down = [](winrt::Windows::System::VirtualKey k) {
248
- return (mui::InputKeyboardSource::GetKeyStateForCurrentThread(k) &
249
- wuc::CoreVirtualKeyStates::Down) != wuc::CoreVirtualKeyStates::None;
250
- };
251
- return down(a) || down(b) || down(c);
252
- }
253
-
254
- // Espejo de src/ir/shortcut.ts (ADR-0179): forma canónica
255
- // `ctrl+alt+shift+meta+tecla`. El host no parsea combos de autor —
256
- // construye esta forma desde la tecla y compara strings.
257
- std::string keyToken(std::string k) {
258
- if (k == " ")
259
- return "space";
260
- if (k == "+")
261
- return "plus";
262
- for (auto &c : k)
263
- c = (char)tolower((unsigned char)c);
264
- return k;
265
- }
266
-
267
- std::string comboOf(winrt::Windows::System::VirtualKey k) {
268
- namespace vk = winrt::Windows::System;
269
- std::string c;
270
- if (modDown(vk::VirtualKey::Control, vk::VirtualKey::LeftControl,
271
- vk::VirtualKey::RightControl))
272
- c += "ctrl+";
273
- if (modDown(vk::VirtualKey::Menu, vk::VirtualKey::LeftMenu,
274
- vk::VirtualKey::RightMenu))
275
- c += "alt+";
276
- if (modDown(vk::VirtualKey::Shift, vk::VirtualKey::LeftShift,
277
- vk::VirtualKey::RightShift))
278
- c += "shift+";
279
- if (modDown(vk::VirtualKey::LeftWindows, vk::VirtualKey::RightWindows,
280
- vk::VirtualKey::LeftWindows))
281
- c += "meta+";
282
- return c + keyToken(domKeyName(k));
283
- }
284
-
285
- // En edición solo disparan combos con ctrl/alt/meta, Escape o F1-F24
286
- // (misma regla que el host GTK — el resto se lo queda el TextBox).
287
- bool firesWhileEditing(const std::string &combo) {
288
- if (combo.rfind("ctrl+", 0) == 0 || combo.rfind("alt+", 0) == 0 ||
289
- combo.find("meta+") != std::string::npos)
290
- return true;
291
- std::string key = combo.substr(
292
- combo.rfind('+') == std::string::npos ? 0 : combo.rfind('+') + 1);
293
- if (key == "escape")
294
- return true;
295
- if (key.size() >= 2 && key[0] == 'f') {
296
- int n = atoi(key.c_str() + 1);
297
- return n >= 1 && n <= 24 && std::to_string(n) == key.substr(1);
298
- }
299
- return false;
300
- }
301
-
302
- } // namespace
303
-
304
- // `variant` del switch (ADR-0216): ToggleSwitch ≠ CheckBox ≠
305
- // RadioButton — hay que recrear el control, copiar estado y
306
- // reinsertarlo en el índice que ocupaba el anterior.
307
- void WinApplicator::swapVariant(WinNode &n, const std::string &v) {
308
- std::string want = v.empty() ? "switch" : v;
309
- if (want == n.variant && n.swEl)
310
- return;
311
- bool on = false;
312
- if (n.sw)
313
- on = n.sw.IsOn();
314
- else if (n.check)
315
- on = n.check.IsChecked() && n.check.IsChecked().Value();
316
- else if (n.radio)
317
- on = n.radio.IsChecked() && n.radio.IsChecked().Value();
318
- mux::UIElement fresh{nullptr};
319
- if (want == "checkbox") {
320
- if (!n.check)
321
- n.check = muxc::CheckBox();
322
- fresh = n.check;
323
- } else if (want == "radio") {
324
- if (!n.radio)
325
- n.radio = muxc::RadioButton();
326
- fresh = n.radio;
327
- } else if (want == "switch") {
328
- if (!n.sw) {
329
- n.sw = muxc::ToggleSwitch();
330
- n.sw.OnContent(nullptr);
331
- n.sw.OffContent(nullptr);
332
- }
333
- fresh = n.sw;
334
- } else {
335
- warnOnce(unknownProps_, "prop", "variant=" + v + "@switch");
336
- return;
337
- }
338
- // El host (n.el) es permanente — el swap cambia solo su contenido;
339
- // la geometría vive en el host, no en el control intercambiado.
340
- if (auto cur = n.host.Content().try_as<mux::UIElement>()) {
341
- if (cur == fresh)
342
- return;
343
- if (auto cf = cur.try_as<mux::FrameworkElement>())
344
- if (auto nf = fresh.try_as<mux::FrameworkElement>()) {
345
- nf.Width(cf.Width());
346
- nf.Height(cf.Height());
347
- }
348
- }
349
- n.host.Content(fresh);
350
- n.swEl = fresh;
351
- n.variant = want;
352
- // Reaplicar estado y label conocidos.
353
- n.suppressSignal = true;
354
- if (n.sw)
355
- n.sw.IsOn(on);
356
- else if (n.check && n.check == fresh)
357
- n.check.IsChecked(
358
- winrt::box_value(on).as<wf::IReference<bool>>());
359
- else if (n.radio && n.radio == fresh)
360
- n.radio.IsChecked(
361
- winrt::box_value(on).as<wf::IReference<bool>>());
362
- n.suppressSignal = false;
363
- if (!n.textValue.empty() && n.check && n.check == fresh)
364
- n.check.Content(winrt::box_value(hs(n.textValue)));
365
- if (!n.textValue.empty() && n.radio && n.radio == fresh)
366
- n.radio.Content(winrt::box_value(hs(n.textValue)));
367
- wireCheckLike(n.id, n);
368
- yoga::nodeSetText(n.id); // la medida cambia con el control nuevo
369
- }
370
-
371
- // Cablea change/input sobre el control switch-like activo
372
- // (Toggled en ToggleSwitch; Checked/Unchecked en CheckBox/RadioButton).
373
- // Control interactivo del nodo para foco/tabstop — el específico del
374
- // tipo si existe; si no, el host (ContentControl sí es Control).
375
- static muxc::Control innerCtl(WinNode &n) {
376
- if (n.input)
377
- return n.input;
378
- if (n.button)
379
- return n.button;
380
- if (n.swEl)
381
- if (auto c = n.swEl.try_as<muxc::Control>())
382
- return c;
383
- if (n.slider)
384
- return n.slider;
385
- return n.el ? n.el.try_as<muxc::Control>() : nullptr;
386
- }
387
-
388
- void WinApplicator::wireCheckLike(int id, WinNode &n) {
389
- auto emitChecked = [this, id]() {
390
- auto i = nodes_.find(id);
391
- if (i == nodes_.end() || i->second.suppressSignal)
392
- return;
393
- WinNode &nn = i->second;
394
- const char *ev = nn.events.count("change") ? "change" : "input";
395
- auto eb = nn.events.find(ev);
396
- if (eb == nn.events.end())
397
- return;
398
- bool on = nn.sw ? nn.sw.IsOn()
399
- : nn.check ? (nn.check.IsChecked() &&
400
- nn.check.IsChecked().Value())
401
- : nn.radio ? (nn.radio.IsChecked() &&
402
- nn.radio.IsChecked().Value())
403
- : false;
404
- emitEvent(nn, ev, "user",
405
- std::string("{\"value\":") + (on ? "true" : "false") + "}",
406
- eb->second);
407
- };
408
- if (n.sw && !n.tokToggle.value)
409
- n.tokToggle = n.sw.Toggled(
410
- [emitChecked](auto const &, auto const &) { emitChecked(); });
411
- if (n.check) {
412
- if (!n.tokCheckOn.value)
413
- n.tokCheckOn = n.check.Checked(
414
- [emitChecked](auto const &, auto const &) { emitChecked(); });
415
- if (!n.tokCheckOff.value)
416
- n.tokCheckOff = n.check.Unchecked(
417
- [emitChecked](auto const &, auto const &) { emitChecked(); });
418
- }
419
- if (n.radio) {
420
- if (!n.tokRadioOn.value)
421
- n.tokRadioOn = n.radio.Checked(
422
- [emitChecked](auto const &, auto const &) { emitChecked(); });
423
- if (!n.tokRadioOff.value)
424
- n.tokRadioOff = n.radio.Unchecked(
425
- [emitChecked](auto const &, auto const &) { emitChecked(); });
426
- }
427
- }
428
-
429
- // pull-to-refresh (ADR-0216): RefreshContainer envuelve al
430
- // ScrollViewer — se crea al primer attach `refresh` / prop
431
- // `refreshing` para no alterar scrolls sin el gesto.
432
- void WinApplicator::ensureRefresh(WinNode &n) {
433
- if (n.refresh || !n.scroll || !n.border)
434
- return;
435
- warnOnce(unknownProps_, "prop", "refresh-skip-bisect@scroll-view");
436
- return;
437
- auto rc = muxc::RefreshContainer();
438
- n.border.Child(rc);
439
- rc.Content(n.scroll);
440
- n.refresh = rc;
441
- int id = n.id;
442
- n.tokRefresh = rc.RefreshRequested(
443
- [this, id](auto const &, auto const &) {
444
- auto i = nodes_.find(id);
445
- if (i == nodes_.end() || i->second.suppressSignal)
446
- return;
447
- auto eb = i->second.events.find("refresh");
448
- if (eb != i->second.events.end())
449
- emitEvent(i->second, "refresh", "user", "{}", eb->second);
450
- });
451
- }
452
-
453
- // ── Fábrica por tipo IR ────────────────────────────────────────────
454
-
455
- void WinApplicator::createNode(int id, const std::string &type) {
456
- WinNode n;
457
- n.id = id;
458
- n.type = type;
459
-
460
- // Todo nodo queda bajo un ElurHost (peer UIA propio — elur_uia_host.h);
461
- // el contenido visible es el Border de chrome o el control directo.
462
- // El impl queda retenido como com_ptr: sobre un objeto composable no
463
- // hay ruta projected→impl (get_self exige produce<D,IRuntimeClass>
464
- // como base y el runtime class lo aporta el objeto interior).
465
- auto withHost = [&](mux::UIElement content) {
466
- auto hostImpl = winrt::make_self<ElurHost>();
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);
476
- if (content)
477
- n.host.Content(content);
478
- n.el = n.host;
479
- n.a11y = hostImpl->a11y;
480
- n.a11y->invoke = [this, id](const char *act) {
481
- onA11yInvoke(id, act);
482
- };
483
- };
484
- auto withBorder = [&](mux::UIElement content) {
485
- n.border = muxc::Border();
486
- if (content)
487
- n.border.Child(content);
488
- withHost(n.border);
489
- };
490
-
491
- if (type == "text") {
492
- n.textBlock = muxc::TextBlock();
493
- n.textBlock.TextWrapping(mux::TextWrapping::Wrap);
494
- withBorder(n.textBlock);
495
- } else if (type == "button") {
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);
515
- withHost(n.button);
516
- } else if (type == "text-input") {
517
- n.input = muxc::TextBox();
518
- withHost(n.input);
519
- } else if (type == "switch") {
520
- n.sw = muxc::ToggleSwitch();
521
- n.sw.OnContent(nullptr);
522
- n.sw.OffContent(nullptr);
523
- n.swEl = n.sw;
524
- withHost(n.sw);
525
- } else if (type == "slider") {
526
- n.slider = muxc::Slider();
527
- withHost(n.slider);
528
- } else if (type == "scroll-view" || type == "scroll") {
529
- n.inner = muxc::Canvas();
530
- n.scroll = muxc::ScrollViewer();
531
- n.scroll.Content(n.inner);
532
- n.scroll.VerticalScrollBarVisibility(
533
- muxc::ScrollBarVisibility::Auto);
534
- n.scroll.HorizontalScrollBarVisibility(
535
- muxc::ScrollBarVisibility::Disabled);
536
- withBorder(n.scroll);
537
- } else if (type == "image") {
538
- n.image = muxc::Image();
539
- n.image.Stretch(muxm::Stretch::UniformToFill);
540
- // ADR-0204: resultados materializados en flags; el attach-event de
541
- // load/error hace replay (el attach llega tras la carga).
542
- n.tokImgOpen = n.image.ImageOpened(
543
- [this, id](auto const &, auto const &) {
544
- auto i = nodes_.find(id);
545
- if (i == nodes_.end())
546
- return;
547
- WinNode &nn = i->second;
548
- nn.imgLoaded = true;
549
- nn.imgFailed = false;
550
- nn.imgW = (int)nn.image.ActualWidth();
551
- nn.imgH = (int)nn.image.ActualHeight();
552
- auto eb = nn.events.find("load");
553
- if (eb != nn.events.end()) {
554
- char buf[96];
555
- snprintf(buf, sizeof(buf), "{\"width\":%d,\"height\":%d%s}",
556
- nn.imgW, nn.imgH,
557
- nn.imgLoadFallback ? ",\"fallback\":true" : "");
558
- emitEvent(nn, "load", "program", buf, eb->second);
559
- }
560
- });
561
- n.tokImgFail = n.image.ImageFailed(
562
- [this, id](auto const &, auto const &) {
563
- auto i = nodes_.find(id);
564
- if (i == nodes_.end())
565
- return;
566
- WinNode &nn = i->second;
567
- if (!nn.fallbackSrc.empty() && !nn.imgFailFallback) {
568
- // fallbackSrc (ADR-0204): primer fallo → reintenta con el
569
- // respaldo y marca la procedencia para el payload.
570
- nn.imgFailFallback = true;
571
- nn.imgLoadFallback = true;
572
- try {
573
- muxm::Imaging::BitmapImage fb;
574
- fb.UriSource(wf::Uri(hs(nn.fallbackSrc)));
575
- nn.image.Source(fb);
576
- } catch (...) {
577
- }
578
- return;
579
- }
580
- nn.imgFailed = true;
581
- auto eb = nn.events.find("error");
582
- if (eb != nn.events.end()) {
583
- std::string d = "{\"message\":\"image load failed\"";
584
- if (nn.imgFailFallback)
585
- d += ",\"fallback\":true";
586
- d += "}";
587
- emitEvent(nn, "error", "program", d, eb->second);
588
- }
589
- });
590
- withBorder(n.image);
591
- } else {
592
- // box/column/row/stack/view/<desconocido> — contenedor con inner.
593
- n.inner = muxc::Canvas();
594
- withBorder(n.inner);
595
- if (type != "box" && type != "column" && type != "row" &&
596
- type != "stack" && type != "view")
597
- warnOnce(unknownOps_, "type", type);
598
- }
599
- nodes_[id] = n;
600
- yoga::nodeCreate(id, type);
601
- }
602
-
603
- // Superficie de hijos para parentId — mismo contrato que surfaceOf()
604
- // en el aplicador GTK: 0 o padre desconocido → Canvas raíz; padre con
605
- // `inner` → su Canvas interno; padre hoja → null (el caller advierte).
606
- muxc::Canvas WinApplicator::surfaceOf(int parentId) {
607
- auto it = nodes_.find(parentId);
608
- if (it == nodes_.end())
609
- return root_;
610
- return it->second.inner;
611
- }
612
-
613
- void WinApplicator::deleteNode(int id) {
614
- auto it = nodes_.find(id);
615
- if (it == nodes_.end())
616
- return;
617
- WinNode &n = it->second;
618
- if (n.button && n.tokClick.value)
619
- n.button.Click(n.tokClick);
620
- if (n.input && n.tokText.value)
621
- n.input.TextChanged(n.tokText);
622
- if (n.sw && n.tokToggle.value)
623
- n.sw.Toggled(n.tokToggle);
624
- if (n.scroll && n.tokView.value)
625
- n.scroll.ViewChanged(n.tokView);
626
- if (n.slider && n.tokSlider.value)
627
- n.slider.ValueChanged(n.tokSlider);
628
- if (n.check) {
629
- if (n.tokCheckOn.value)
630
- n.check.Checked(n.tokCheckOn);
631
- if (n.tokCheckOff.value)
632
- n.check.Unchecked(n.tokCheckOff);
633
- }
634
- if (n.radio) {
635
- if (n.tokRadioOn.value)
636
- n.radio.Checked(n.tokRadioOn);
637
- if (n.tokRadioOff.value)
638
- n.radio.Unchecked(n.tokRadioOff);
639
- }
640
- if (n.image) {
641
- if (n.tokImgOpen.value)
642
- n.image.ImageOpened(n.tokImgOpen);
643
- if (n.tokImgFail.value)
644
- n.image.ImageFailed(n.tokImgFail);
645
- }
646
- if (n.refresh && n.tokRefresh.value)
647
- n.refresh.RefreshRequested(n.tokRefresh);
648
- detachVisual(n.el);
649
- nodes_.erase(it);
650
- yoga::nodeDelete(id);
651
- }
652
-
653
- // ── Texto / props / estilos ────────────────────────────────────────
654
-
655
- // UTF-8 → UTF-16: los offsets de `spans` (ADR-0147) son unidades
656
- // UTF-16 sobre el texto renderizado, igual que hstring/wchar.
657
- std::wstring ws(const std::string &s) {
658
- int n = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(),
659
- nullptr, 0);
660
- std::wstring w((size_t)n, L'\0');
661
- MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), w.data(), n);
662
- return w;
663
- }
664
-
665
- winrt::hstring hsw(std::wstring_view v) {
666
- return winrt::hstring(v.data(), (uint32_t)v.size());
667
- }
668
-
669
- // Subset TEXT_SPAN_STYLE_KEYS (ADR-0147); backgroundColor no tiene
670
- // equivalente en Span — se ignora (approx).
671
- void spanStyle(const WinSpan &sp, muxd::TextElement const &el) {
672
- namespace wuct = winrt::Windows::UI::Text;
673
- for (auto const &[k, v] : sp.style) {
674
- if (k == "color") {
675
- if (auto b = brushOf(v))
676
- el.Foreground(b);
677
- } else if (k == "fontSize") {
678
- el.FontSize(pxOf(v));
679
- } else if (k == "fontWeight") {
680
- int wgt = v == "bold" ? 700 : v == "normal" ? 400 : atoi(v.c_str());
681
- wuct::FontWeight fw;
682
- fw.Weight = (uint16_t)std::clamp(wgt, 1, 999);
683
- el.FontWeight(fw);
684
- } else if (k == "fontStyle") {
685
- if (v == "italic")
686
- el.FontStyle(wuct::FontStyle::Italic);
687
- else if (v == "oblique")
688
- el.FontStyle(wuct::FontStyle::Oblique);
689
- } else if (k == "textDecoration") {
690
- if (v == "underline")
691
- el.TextDecorations(wuct::TextDecorations::Underline);
692
- else if (v == "line-through")
693
- el.TextDecorations(wuct::TextDecorations::Strikethrough);
694
- else
695
- el.TextDecorations(wuct::TextDecorations::None);
696
- } else if (k == "fontFamily") {
697
- el.FontFamily(muxm::FontFamily(hs(v)));
698
- }
699
- }
700
- }
701
-
702
- // Construye el árbol de spans desde la lista plana ordenada
703
- // (s asc, e desc): los que siguen a un span dentro de su rango son
704
- // sus hijos — el resto, sus hermanos.
705
- void treeify(const std::vector<WinSpan> &flat, size_t &i, int lo,
706
- int hi, std::vector<WinSpan> &dst) {
707
- while (i < flat.size() && flat[i].s >= lo && flat[i].e <= hi) {
708
- WinSpan cur = flat[i++];
709
- treeify(flat, i, cur.s, cur.e, cur.kids);
710
- dst.push_back(std::move(cur));
711
- }
712
- }
713
-
714
- // Emite Run/Span/Hyperlink en `out` para el rango [lo,hi): huecos
715
- // como Run plano y cada span como Span (o Hyperlink si href) con sus
716
- // kids anidados dentro — los rangos se clampean (ADR-0147).
717
- void emitSpanRange(const std::wstring &t, int lo, int hi,
718
- const std::vector<WinSpan> &inside,
719
- muxd::InlineCollection const &out, WinApplicator *self) {
720
- int pos = lo;
721
- auto run = [&](int a, int b) {
722
- auto r = muxd::Run();
723
- r.Text(hsw(std::wstring_view(t).substr((size_t)a, (size_t)(b - a))));
724
- out.Append(r);
725
- };
726
- for (const WinSpan &sp : inside) {
727
- int s = std::clamp(sp.s, lo, hi);
728
- int e = std::clamp(sp.e, s, hi);
729
- if (s > pos)
730
- run(pos, s);
731
- muxd::Span sub{nullptr};
732
- if (sp.href.empty()) {
733
- sub = muxd::Span();
734
- } else {
735
- // ADR-0133/0147: el handler JS decide interna vs openUrl.
736
- muxd::Hyperlink hl;
737
- std::string url = sp.href;
738
- auto self_ = self;
739
- hl.Click([self_, url](auto const &,
740
- muxd::HyperlinkClickEventArgs const &) {
741
- self_->cb_.callHandlerStr("__elur_span_href", url.c_str());
742
- });
743
- sub = hl;
744
- }
745
- spanStyle(sp, sub);
746
- emitSpanRange(t, s, e, sp.kids, sub.Inlines(), self);
747
- out.Append(sub);
748
- pos = e;
749
- }
750
- if (pos < hi)
751
- run(pos, hi);
752
- }
753
-
754
- void WinApplicator::applySpans(WinNode &n) {
755
- if (!n.textBlock)
756
- return;
757
- auto inlines = n.textBlock.Inlines();
758
- inlines.Clear();
759
- if (n.spans.empty()) {
760
- n.textBlock.Text(hs(n.textValue));
761
- return;
762
- }
763
- std::wstring t = ws(n.textValue);
764
- emitSpanRange(t, 0, (int)t.size(), n.spans, inlines, this);
765
- }
766
-
767
- void WinApplicator::updateText(WinNode &n, const std::string &val) {
768
- n.textValue = val;
769
- if (n.textBlock) {
770
- if (!n.spans.empty())
771
- applySpans(n);
772
- else
773
- n.textBlock.Text(hs(val));
774
- }
775
- else if (n.button)
776
- n.button.Content(winrt::box_value(hs(val)));
777
- else if (n.input) {
778
- n.suppressSignal = true;
779
- n.input.Text(hs(val));
780
- n.suppressSignal = false;
781
- } else if (n.sw) {
782
- n.suppressSignal = true;
783
- n.sw.IsOn(val == "true" || val == "1");
784
- n.suppressSignal = false;
785
- } else if (n.check) {
786
- n.check.Content(winrt::box_value(hs(val)));
787
- } else if (n.radio) {
788
- n.radio.Content(winrt::box_value(hs(val)));
789
- } else
790
- warnOnce(unknownOps_, "update-text", n.type);
791
- yoga::nodeSetText(n.id);
792
- }
793
-
794
- void WinApplicator::updateProp(WinNode &n, const std::string &key,
795
- JSContext *ctx, JSValueConst val) {
796
- if (key == "value" && n.input) {
797
- n.suppressSignal = true;
798
- n.input.Text(hs(jsStr(ctx, val)));
799
- n.suppressSignal = false;
800
- return;
801
- }
802
- if (key == "placeholder" && n.input) {
803
- n.input.PlaceholderText(hs(jsStr(ctx, val)));
804
- return;
805
- }
806
- if (key == "src" && n.image) {
807
- std::string src = jsStr(ctx, val);
808
- try {
809
- muxm::Imaging::BitmapImage bi;
810
- namespace wss = winrt::Windows::Storage::Streams;
811
- // Image no repinta cuando un stream asignado antes de decodificar
812
- // completa tarde — con streams la Source se asigna tras el decode
813
- // (Completed retiene ras+bi; el lookup cubre nodos borrados).
814
- int nid = n.id;
815
- auto dq = n.image.DispatcherQueue();
816
- auto assignDecoded =
817
- [this, nid, bi, dq](wss::InMemoryRandomAccessStream const &ras) {
818
- bi.SetSourceAsync(ras).Completed(
819
- [this, nid, bi, ras, dq](auto const &,
820
- wf::AsyncStatus st) {
821
- // Completed puede correr en threadpool (decode
822
- // asíncrono); Source solo se asigna en UI thread.
823
- dq.TryEnqueue(mud::DispatcherQueuePriority::Normal,
824
- mud::DispatcherQueueHandler(
825
- [this, nid, bi, st]() {
826
- auto i = nodes_.find(nid);
827
- if (i == nodes_.end() ||
828
- !i->second.image)
829
- return;
830
- if (st ==
831
- wf::AsyncStatus::Completed) {
832
- i->second.image.Source(bi);
833
- return;
834
- }
835
- auto eb = i->second.events.find(
836
- "error");
837
- if (eb != i->second.events.end())
838
- emitEvent(
839
- i->second, "error",
840
- "program",
841
- "{\"message\":\"image load "
842
- "failed\"}",
843
- eb->second);
844
- }));
845
- });
846
- };
847
- // BitmapImage.UriSource no acepta data: URIs (WinUI) — el payload
848
- // va por stream en memoria, igual que el decode de GTK (ADR-0071).
849
- if (src.rfind("data:", 0) == 0) {
850
- auto comma = src.find(',');
851
- std::string b64 =
852
- comma == std::string::npos ? "" : src.substr(comma + 1);
853
- namespace wsc = winrt::Windows::Security::Cryptography;
854
- wss::InMemoryRandomAccessStream ras;
855
- ras.WriteAsync(
856
- wsc::CryptographicBuffer::DecodeFromBase64String(hs(b64)))
857
- .get();
858
- ras.Seek(0);
859
- assignDecoded(ras);
860
- } else if (src.find(":/") == std::string::npos &&
861
- src.find(":\\") == std::string::npos) {
862
- // Sin esquema URI (asset empaquetado o ruta de disco): path
863
- // relativo al cwd, como gdk_texture_new_from_filename en GTK.
864
- // UriSource no soporta file:// en apps unpackaged — va por
865
- // stream, igual que el path data:.
866
- char abs[MAX_PATH];
867
- DWORD len = GetFullPathNameA(src.c_str(), MAX_PATH, abs, nullptr);
868
- if (len == 0 || len >= MAX_PATH)
869
- throw winrt::hresult_error(E_INVALIDARG);
870
- std::ifstream f(abs, std::ios::binary);
871
- std::string bytes((std::istreambuf_iterator<char>(f)),
872
- std::istreambuf_iterator<char>());
873
- if (bytes.empty())
874
- throw winrt::hresult_error(HRESULT_FROM_WIN32(
875
- ERROR_FILE_NOT_FOUND));
876
- namespace wsc = winrt::Windows::Security::Cryptography;
877
- wss::InMemoryRandomAccessStream ras;
878
- ras.WriteAsync(
879
- wsc::CryptographicBuffer::CreateFromByteArray(
880
- winrt::array_view<const uint8_t>(
881
- reinterpret_cast<const uint8_t *>(
882
- bytes.data()),
883
- (uint32_t)bytes.size())))
884
- .get();
885
- ras.Seek(0);
886
- assignDecoded(ras);
887
- } else {
888
- bi.UriSource(wf::Uri(hs(src)));
889
- n.image.Source(bi);
890
- }
891
- } catch (...) {
892
- emitEvent(n, "error", "program",
893
- "{\"message\":\"image load failed\"}",
894
- n.events.count("error") ? n.events["error"]
895
- : EventBind{});
896
- }
897
- return;
898
- }
899
- if (key == "editable" && n.input) {
900
- n.input.IsReadOnly(!JS_ToBool(ctx, val));
901
- return;
902
- }
903
- if (key == "readOnly" && n.input) {
904
- n.input.IsReadOnly(JS_ToBool(ctx, val));
905
- return;
906
- }
907
- if (key == "checked" && n.sw) {
908
- n.suppressSignal = true;
909
- n.sw.IsOn(JS_ToBool(ctx, val));
910
- n.suppressSignal = false;
911
- return;
912
- }
913
- if (key == "checked" && (n.check || n.radio)) {
914
- n.suppressSignal = true;
915
- auto b = winrt::box_value(JS_ToBool(ctx, val))
916
- .as<wf::IReference<bool>>();
917
- if (n.check)
918
- n.check.IsChecked(b);
919
- else
920
- n.radio.IsChecked(b);
921
- n.suppressSignal = false;
922
- return;
923
- }
924
- if (key == "variant" && n.type == "switch") {
925
- swapVariant(n, jsStr(ctx, val));
926
- return;
927
- }
928
- if (key == "value" && n.slider) {
929
- n.suppressSignal = true;
930
- double v = 0;
931
- JS_ToFloat64(ctx, &v, val);
932
- n.slider.Value(v);
933
- n.suppressSignal = false;
934
- return;
935
- }
936
- if (key == "min" && n.slider) {
937
- double v = 0;
938
- JS_ToFloat64(ctx, &v, val);
939
- n.slider.Minimum(v);
940
- return;
941
- }
942
- if (key == "max" && n.slider) {
943
- double v = 0;
944
- JS_ToFloat64(ctx, &v, val);
945
- n.slider.Maximum(v);
946
- return;
947
- }
948
- if (key == "fallbackSrc" && n.image) {
949
- n.fallbackSrc = jsStr(ctx, val);
950
- return;
951
- }
952
- // ─ Estado / foco / a11y genérico (AutomationProperties) ──
953
- if (key == "disabled") {
954
- if (n.el) {
955
- bool b = JS_ToBool(ctx, val);
956
- n.el.IsHitTestVisible(!b);
957
- if (auto c = n.el.try_as<muxc::Control>())
958
- c.IsEnabled(!b);
959
- }
960
- return;
961
- }
962
- if (key == "focused") {
963
- // El foco programático va al control interactivo del nodo — el
964
- // host (ContentControl) no es focusable por sí mismo.
965
- if (JS_ToBool(ctx, val)) {
966
- if (auto c = innerCtl(n)) {
967
- // Focus() exige elemento en el árbol + ventana activa — si el
968
- // op llega antes del insert/Loaded, difiere a baja prioridad.
969
- if (!c.Focus(mux::FocusState::Programmatic)) {
970
- namespace mud = winrt::Microsoft::UI::Dispatching;
971
- if (auto dq = c.DispatcherQueue())
972
- dq.TryEnqueue(mud::DispatcherQueuePriority::Low,
973
- mud::DispatcherQueueHandler([c]() {
974
- c.Focus(mux::FocusState::Programmatic);
975
- }));
976
- }
977
- }
978
- }
979
- return;
980
- }
981
- if (key == "focusable") {
982
- if (auto c = innerCtl(n))
983
- c.IsTabStop(JS_ToBool(ctx, val));
984
- return;
985
- }
986
- if (key == "label") {
987
- auto nm = hs(jsStr(ctx, val));
988
- if (n.el)
989
- mux::Automation::AutomationProperties::SetName(n.el, nm);
990
- // El widget real es el control interno (Edit/Button…): el lector
991
- // de pantalla anuncia su Name, no el del wrapper Custom — igual
992
- // que gtk_accessible nombre al entry en GTK.
993
- if (auto ic = innerCtl(n))
994
- mux::Automation::AutomationProperties::SetName(ic, nm);
995
- return;
996
- }
997
- if (key == "hint") {
998
- if (n.el)
999
- mux::Automation::AutomationProperties::SetHelpText(
1000
- n.el, hs(jsStr(ctx, val)));
1001
- return;
1002
- }
1003
- if (key == "live") {
1004
- if (n.el) {
1005
- std::string v = jsStr(ctx, val);
1006
- namespace peers = mux::Automation::Peers;
1007
- mux::Automation::AutomationProperties::SetLiveSetting(
1008
- n.el, v == "assertive"
1009
- ? peers::AutomationLiveSetting::Assertive
1010
- : peers::AutomationLiveSetting::Polite);
1011
- }
1012
- return;
1013
- }
1014
- if (key == "required") {
1015
- if (n.el)
1016
- mux::Automation::AutomationProperties::SetIsRequiredForForm(
1017
- n.el, JS_ToBool(ctx, val));
1018
- return;
1019
- }
1020
- if ((key == "valueMin" || key == "valueMax" || key == "valueNow") &&
1021
- n.slider) {
1022
- // UIA no tiene attached-prop de valor para elementos genéricos —
1023
- // en nodos slider el rango ya lo expone RangeValuePattern;
1024
- // materializan sobre el propio widget.
1025
- double v = 0;
1026
- JS_ToFloat64(ctx, &v, val);
1027
- if (key == "valueMin")
1028
- n.slider.Minimum(v);
1029
- else if (key == "valueMax")
1030
- n.slider.Maximum(v);
1031
- else {
1032
- n.suppressSignal = true;
1033
- n.slider.Value(v);
1034
- n.suppressSignal = false;
1035
- }
1036
- return;
1037
- }
1038
- if (key == "invalid") {
1039
- // UIA IsDataValidForForm=false ≡ aria-invalid=true (ADR-0152).
1040
- if (n.el)
1041
- mux::Automation::AutomationProperties::SetIsDataValidForForm(
1042
- n.el, !JS_ToBool(ctx, val));
1043
- return;
1044
- }
1045
- if (key == "selected" || key == "expanded" || key == "valueText") {
1046
- // Estado → ElurA11y del host: el peer lo lee por patrón
1047
- // (SelectionItem/ExpandCollapse/Value) — elur_uia_host.h.
1048
- if (!n.a11y)
1049
- return;
1050
- bool isNull = JS_IsNull(val) || JS_IsUndefined(val);
1051
- if (key == "selected") {
1052
- n.a11y->hasSel = !isNull;
1053
- n.a11y->sel = !isNull && JS_ToBool(ctx, val);
1054
- } else if (key == "expanded") {
1055
- n.a11y->hasExp = !isNull;
1056
- n.a11y->exp = !isNull && JS_ToBool(ctx, val);
1057
- } else {
1058
- n.a11y->hasVal = !isNull;
1059
- n.a11y->valueText = isNull ? L"" : hs(jsStr(ctx, val));
1060
- }
1061
- return;
1062
- }
1063
- if (key == "sticky") {
1064
- // ADR-0150 — translationY por ViewChanged con clamp al padre
1065
- // (mismo modelo que ElurScrollView en android).
1066
- float th = 0;
1067
- bool on = JS_ToBool(ctx, val);
1068
- if (on && JS_IsNumber(val)) {
1069
- double d = 0;
1070
- JS_ToFloat64(ctx, &d, val);
1071
- th = (float)d;
1072
- }
1073
- if (!on) {
1074
- n.sticky = false;
1075
- if (n.el)
1076
- n.el.Translation(winrt::Windows::Foundation::Numerics::float3(
1077
- 0.f, 0.f, 0.f));
1078
- if (n.stickyScroll && n.tokSticky.value)
1079
- n.stickyScroll.ViewChanged(n.tokSticky);
1080
- n.stickyScroll = nullptr;
1081
- return;
1082
- }
1083
- n.sticky = true;
1084
- n.stickyTop = th;
1085
- ensureStickyScroll(n);
1086
- return;
1087
- }
1088
- if (key == "accessible") {
1089
- bool acc = JS_IsNull(val) || JS_IsUndefined(val) || JS_ToBool(ctx, val);
1090
- if (n.a11y)
1091
- n.a11y->hidden = !acc;
1092
- if (n.el)
1093
- mux::Automation::AutomationProperties::SetAccessibilityView(
1094
- n.el, acc ? mux::Automation::Peers::AccessibilityView::Control
1095
- : mux::Automation::Peers::AccessibilityView::Raw);
1096
- return;
1097
- }
1098
- if (key == "role") {
1099
- // LocalizedControlType solo anuncia el rol al narrador — no cambia
1100
- // comportamiento (igual que android role→contentDescription).
1101
- if (n.el)
1102
- mux::Automation::AutomationProperties::SetLocalizedControlType(
1103
- n.el, hs(jsStr(ctx, val)));
1104
- return;
1105
- }
1106
- if (key == "href") {
1107
- // ADR-0133 — el reconciler ya convirtió href→press/openUrl; el
1108
- // cursor de enlace no existe en este WASDK (ProtectedCursor ausente).
1109
- return;
1110
- }
1111
- if (key == "as") {
1112
- // Paridad views/Android/Linux: solo h1–h6 materializan rol
1113
- // heading; el resto de etiquetas se ignora.
1114
- std::string v = jsStr(ctx, val);
1115
- if (n.el && v.size() == 2 && v[0] == 'h' && v[1] >= '1' &&
1116
- v[1] <= '6')
1117
- mux::Automation::AutomationProperties::SetHeadingLevel(
1118
- n.el, (mux::Automation::Peers::AutomationHeadingLevel)(
1119
- v[1] - '0'));
1120
- return;
1121
- }
1122
- if (key == "spans" && n.textBlock) {
1123
- // ADR-0147 — array {start,end,style,href} normalizado por el
1124
- // reconciler (orden s asc/e desc, anidación verificada); aquí solo
1125
- // se construye el árbol por contención.
1126
- n.spans.clear();
1127
- std::vector<WinSpan> flat;
1128
- int64_t len = 0;
1129
- JS_GetLength(ctx, val, &len);
1130
- for (int64_t i = 0; i < len; i++) {
1131
- JSValue it = JS_GetPropertyInt64(ctx, val, i);
1132
- WinSpan sp;
1133
- sp.s = jsInt(ctx, it, "start");
1134
- sp.e = jsInt(ctx, it, "end");
1135
- sp.href = jsGetStr(ctx, it, "href");
1136
- JSValue st = jsGet(ctx, it, "style");
1137
- JSPropertyEnum *tab = nullptr;
1138
- uint32_t plen = 0;
1139
- if (JS_GetOwnPropertyNames(ctx, &tab, &plen, st,
1140
- JS_GPN_STRING_MASK |
1141
- JS_GPN_ENUM_ONLY) == 0) {
1142
- for (uint32_t k = 0; k < plen; k++) {
1143
- JSValue keyv = JS_AtomToString(ctx, tab[k].atom);
1144
- std::string skey = jsStr(ctx, keyv);
1145
- JS_FreeValue(ctx, keyv);
1146
- JSValue sv = JS_GetProperty(ctx, st, tab[k].atom);
1147
- sp.style[skey] = jsStr(ctx, sv);
1148
- JS_FreeValue(ctx, sv);
1149
- JS_FreeAtom(ctx, tab[k].atom);
1150
- }
1151
- js_free(ctx, tab);
1152
- }
1153
- JS_FreeValue(ctx, st);
1154
- flat.push_back(std::move(sp));
1155
- JS_FreeValue(ctx, it);
1156
- }
1157
- std::sort(flat.begin(), flat.end(),
1158
- [](const WinSpan &a, const WinSpan &b) {
1159
- return a.s < b.s || (a.s == b.s && a.e > b.e);
1160
- });
1161
- size_t idx = 0;
1162
- treeify(flat, idx, 0, INT_MAX, n.spans);
1163
- applySpans(n);
1164
- return;
1165
- }
1166
- // ─ TextBlock ──
1167
- if (key == "selectable" && n.textBlock) {
1168
- n.textBlock.IsTextSelectionEnabled(JS_ToBool(ctx, val));
1169
- return;
1170
- }
1171
- if (key == "maxLines" && n.textBlock) {
1172
- double v = 0;
1173
- JS_ToFloat64(ctx, &v, val);
1174
- n.textBlock.MaxLines((int)v);
1175
- return;
1176
- }
1177
- if (key == "textOverflow" && n.textBlock) {
1178
- std::string v = jsStr(ctx, val);
1179
- n.textBlock.TextTrimming(
1180
- v == "ellipsis" ? mux::TextTrimming::CharacterEllipsis
1181
- : v == "clip" ? mux::TextTrimming::Clip
1182
- : mux::TextTrimming::None);
1183
- return;
1184
- }
1185
- // ─ TextBox ──
1186
- if (key == "maxlength" && n.input) {
1187
- double v = 0;
1188
- JS_ToFloat64(ctx, &v, val);
1189
- n.input.MaxLength((int)v);
1190
- return;
1191
- }
1192
- if (key == "spellcheck" && n.input) {
1193
- n.input.IsSpellCheckEnabled(JS_ToBool(ctx, val));
1194
- return;
1195
- }
1196
- if (key == "multiline" && n.input) {
1197
- bool b = JS_ToBool(ctx, val);
1198
- n.input.AcceptsReturn(b);
1199
- if (b)
1200
- n.input.TextWrapping(mux::TextWrapping::Wrap);
1201
- return;
1202
- }
1203
- if (key == "rows" && n.input) {
1204
- double v = 0;
1205
- JS_ToFloat64(ctx, &v, val);
1206
- if (v > 0) {
1207
- // Aprox: TextBox no expone filas — MinHeight por línea
1208
- // (fontSize*1.4 + chrome).
1209
- double fs = n.fontSizePx > 0 ? n.fontSizePx : 14;
1210
- n.inputMinH = (float)(v * fs * 1.4 + 16);
1211
- n.input.MinHeight(n.inputMinH);
1212
- }
1213
- return;
1214
- }
1215
- if ((key == "keyboard" || key == "autocomplete") && n.input) {
1216
- // `autocomplete` en desktop no tiene autofill de sistema —
1217
- // InputScope es el hint más cercano (mismo vocabulario que
1218
- // `keyboard`: email/tel/url/search/password).
1219
- std::string v = jsStr(ctx, val);
1220
- muxi::InputScopeNameValue kv = muxi::InputScopeNameValue::Default;
1221
- if (v == "number" || v == "decimal")
1222
- kv = muxi::InputScopeNameValue::Number;
1223
- else if (v == "phone" || v == "tel")
1224
- kv = muxi::InputScopeNameValue::TelephoneNumber;
1225
- else if (v == "email")
1226
- kv = muxi::InputScopeNameValue::EmailSmtpAddress;
1227
- else if (v == "url")
1228
- kv = muxi::InputScopeNameValue::Url;
1229
- else if (v == "search")
1230
- kv = muxi::InputScopeNameValue::Search;
1231
- else if (v == "password" || v == "current-password")
1232
- kv = muxi::InputScopeNameValue::Password;
1233
- else if (v == "username")
1234
- kv = muxi::InputScopeNameValue::NameOrPhoneNumber;
1235
- else if (v == "name")
1236
- kv = muxi::InputScopeNameValue::PersonalFullName;
1237
- muxi::InputScope scope;
1238
- scope.Names().Append(muxi::InputScopeName(kv));
1239
- n.input.InputScope(scope);
1240
- return;
1241
- }
1242
- if (key == "selection" && n.input) {
1243
- // {start,end} objeto o número (caret colapsado).
1244
- int s = 0, e = 0;
1245
- if (JS_IsObject(val)) {
1246
- s = jsInt(ctx, val, "start");
1247
- e = jsInt(ctx, val, "end", s);
1248
- } else {
1249
- double v = 0;
1250
- JS_ToFloat64(ctx, &v, val);
1251
- s = e = (int)v;
1252
- }
1253
- n.input.SelectionStart(s);
1254
- n.input.SelectionLength(std::max(0, e - s));
1255
- return;
1256
- }
1257
- // ─ ScrollViewer ──
1258
- if (key == "scrollTop" && n.scroll) {
1259
- double v = 0;
1260
- JS_ToFloat64(ctx, &v, val);
1261
- n.suppressSignal = true;
1262
- n.scroll.ChangeView(nullptr, v, nullptr, true);
1263
- n.suppressSignal = false;
1264
- return;
1265
- }
1266
- if (key == "scrollLeft" && n.scroll) {
1267
- double v = 0;
1268
- JS_ToFloat64(ctx, &v, val);
1269
- n.suppressSignal = true;
1270
- n.scroll.ChangeView(v, nullptr, nullptr, true);
1271
- n.suppressSignal = false;
1272
- return;
1273
- }
1274
- if (key == "horizontal" && n.scroll) {
1275
- bool b = JS_ToBool(ctx, val);
1276
- n.scroll.HorizontalScrollBarVisibility(
1277
- b ? muxc::ScrollBarVisibility::Auto
1278
- : muxc::ScrollBarVisibility::Disabled);
1279
- return;
1280
- }
1281
- if ((key == "refreshing" || key == "refresh") && n.scroll) {
1282
- ensureRefresh(n);
1283
- if (key == "refreshing" && JS_ToBool(ctx, val))
1284
- n.refresh.RequestRefresh();
1285
- return;
1286
- }
1287
- if (key == "dir") {
1288
- std::string dv = jsStr(ctx, val);
1289
- yoga::nodeSetDir(n.id, dv == "rtl");
1290
- // FlowDirection solo en hojas: en contenedores (n.inner = Canvas de
1291
- // hijos posicionados por Yoga) invierte la interpretación de
1292
- // Canvas.Left y cancela el RTL que Yoga ya aplicó — doble volteo.
1293
- // En hojas sí aporta: bidi del texto y alineación start del control.
1294
- if (!n.inner && n.el)
1295
- if (auto fe = n.el.try_as<mux::FrameworkElement>())
1296
- fe.FlowDirection(dv == "rtl"
1297
- ? mux::FlowDirection::RightToLeft
1298
- : mux::FlowDirection::LeftToRight);
1299
- return;
1300
- }
1301
- if (key == "visible") {
1302
- if (n.el)
1303
- n.el.Visibility(JS_ToBool(ctx, val) ? mux::Visibility::Visible
1304
- : mux::Visibility::Collapsed);
1305
- return;
1306
- }
1307
- warnOnce(unknownProps_, "prop", key + "@" + n.type);
1308
- }
1309
-
1310
- // update-style: isNum decide el carril f64/str (ADR-0050). Los estilos
1311
- // de layout van al mirror Yoga; los visuales al wrapper/control.
1312
- void WinApplicator::updateStyle(WinNode &n, JSContext *ctx,
1313
- JSValueConst style) {
1314
- JSPropertyEnum *tab = nullptr;
1315
- uint32_t len = 0;
1316
- if (JS_GetOwnPropertyNames(ctx, &tab, &len, style,
1317
- JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0)
1318
- return;
1319
- for (uint32_t i = 0; i < len; i++) {
1320
- JSAtom atom = tab[i].atom;
1321
- JSValue keyv = JS_AtomToString(ctx, atom);
1322
- std::string key = jsStr(ctx, keyv);
1323
- JS_FreeValue(ctx, keyv);
1324
- JSValue val = JS_GetProperty(ctx, style, atom);
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)) {
1329
- double num = 0;
1330
- JS_ToFloat64(ctx, &num, val);
1331
- yoga::nodeSetStyle(n.id, key, true, num, "");
1332
- char buf[40];
1333
- snprintf(buf, sizeof(buf), "%.6g", num);
1334
- n.visual[key] = buf;
1335
- } else {
1336
- std::string s = jsStr(ctx, val);
1337
- yoga::nodeSetStyle(n.id, key, false, 0, s);
1338
- n.visual[key] = s;
1339
- }
1340
- JS_FreeValue(ctx, val);
1341
- JS_FreeAtom(ctx, atom);
1342
- }
1343
- js_free(ctx, tab);
1344
- applyVisual(n);
1345
- }
1346
-
1347
- void WinApplicator::applyVisual(WinNode &n) {
1348
- auto find = [&](const char *k) -> const std::string * {
1349
- auto i = n.visual.find(k);
1350
- return i == n.visual.end() ? nullptr : &i->second;
1351
- };
1352
- mux::UIElement target = n.el;
1353
- if (const std::string *bg = find("backgroundColor")) {
1354
- if (auto b = brushOf(*bg)) {
1355
- if (n.border)
1356
- n.border.Background(b);
1357
- else if (n.button) {
1358
- n.button.Background(b);
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)
1364
- n.input.Background(b);
1365
- else if (n.sw)
1366
- n.sw.Background(b);
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);
1375
- }
1376
- if (const std::string *fg = find("color")) {
1377
- if (auto b = brushOf(*fg)) {
1378
- if (n.textBlock)
1379
- n.textBlock.Foreground(b);
1380
- else if (n.button)
1381
- n.button.Foreground(b);
1382
- else if (n.input)
1383
- n.input.Foreground(b);
1384
- }
1385
- }
1386
- if (const std::string *fs = find("fontSize")) {
1387
- double px = pxOf(*fs);
1388
- if (px > 0) {
1389
- n.fontSizePx = (float)px;
1390
- if (n.textBlock)
1391
- n.textBlock.FontSize(px);
1392
- else if (n.button)
1393
- n.button.FontSize(px);
1394
- else if (n.input)
1395
- n.input.FontSize(px);
1396
- }
1397
- }
1398
- if (const std::string *fw = find("fontWeight")) {
1399
- auto w = wut::FontWeights::Normal();
1400
- if (*fw == "bold" || pxOf(*fw) >= 600)
1401
- w = wut::FontWeights::Bold();
1402
- if (n.textBlock)
1403
- n.textBlock.FontWeight(w);
1404
- else if (n.button)
1405
- n.button.FontWeight(w);
1406
- }
1407
- if (const std::string *ta = find("textAlign")) {
1408
- n.alignSet = true;
1409
- mux::TextAlignment a = mux::TextAlignment::Left;
1410
- if (*ta == "center")
1411
- a = mux::TextAlignment::Center;
1412
- else if (*ta == "right" || *ta == "end")
1413
- a = mux::TextAlignment::Right;
1414
- else if (*ta == "justify")
1415
- a = mux::TextAlignment::Justify;
1416
- if (n.textBlock)
1417
- n.textBlock.TextAlignment(a);
1418
- else if (n.input)
1419
- n.input.TextAlignment(a);
1420
- }
1421
- if (n.border) {
1422
- const std::string *br = find("borderRadius");
1423
- if (br) {
1424
- double r = pxOf(*br);
1425
- n.border.CornerRadius(mux::CornerRadius{r, r, r, r});
1426
- }
1427
- const std::string *bc = find("borderColor");
1428
- const std::string *bw = find("borderWidth");
1429
- if (bc || bw) {
1430
- if (bc)
1431
- if (auto b = brushOf(*bc))
1432
- n.border.BorderBrush(b);
1433
- double t = bw ? pxOf(*bw, 1) : 1;
1434
- n.border.BorderThickness(Thickness{t, t, t, t});
1435
- }
1436
- // Padding visual: Yoga lo lleva en el árbol para contenedores;
1437
- // en hojas con measureFunc lo suma la medida (padVals), como en
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
- }
1466
- }
1467
- if (const std::string *op = find("opacity")) {
1468
- if (n.el)
1469
- n.el.Opacity(pxOf(*op, 1));
1470
- }
1471
- if (const std::string *ov = find("overflow")) {
1472
- // M1: ScrollViewer ya gestiona scroll; hidden → clip al rect
1473
- // (XAML recorta hijos por defecto en Canvas si el border tiene
1474
- // tamaño fijado por el rect Yoga — nada que hacer de momento).
1475
- if (*ov != "hidden" && *ov != "scroll" && *ov != "auto" &&
1476
- *ov != "visible")
1477
- warnOnce(unknownStyles_, "style", "overflow:" + *ov);
1478
- }
1479
- }
1480
-
1481
- // ── Medida de hojas (hook síncrono de yoga) ────────────────────────
1482
-
1483
- void WinApplicator::measureLeaf(int id, float w, int wMode, float h,
1484
- int hMode, float &ow, float &oh) {
1485
- auto it = nodes_.find(id);
1486
- if (it == nodes_.end()) {
1487
- ow = oh = 0;
1488
- return;
1489
- }
1490
- WinNode &n = it->second;
1491
- auto availW = (wMode == YGMeasureModeUndefined || w <= 0)
1492
- ? std::numeric_limits<float>::infinity()
1493
- : w;
1494
- auto availH = (hMode == YGMeasureModeUndefined || h <= 0)
1495
- ? std::numeric_limits<float>::infinity()
1496
- : h;
1497
- if (n.input) {
1498
- // Measure() sobre un TextBox/RichEditBox detached corrompe el
1499
- // estado de WinUIEdit (crash 0x80004005 stowed en el siguiente
1500
- // pase de render — medido en repro mínimo). Se usa el intrínseco
1501
- // del default style: alto 32 por línea, ancho mínimo 120.
1502
- ow = wMode == YGMeasureModeUndefined ? 120 : w;
1503
- float ih = n.inputMinH > 32 ? n.inputMinH : 32;
1504
- oh = hMode == YGMeasureModeUndefined ? ih : h;
1505
- return;
1506
- }
1507
- mux::UIElement probe{nullptr};
1508
- if (n.textBlock)
1509
- probe = n.textBlock;
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)
1519
- probe = n.swEl;
1520
- else if (n.slider)
1521
- probe = n.slider;
1522
- else if (n.image)
1523
- probe = n.image;
1524
- if (!probe) {
1525
- ow = wMode == YGMeasureModeUndefined ? 0 : w;
1526
- oh = hMode == YGMeasureModeUndefined ? 0 : h;
1527
- return;
1528
- }
1529
- probe.Measure(Size{availW, availH});
1530
- Size d = probe.DesiredSize();
1531
- // Controles templated (Button/ToggleSwitch/TextBox) devuelven 0×0
1532
- // si se miden antes de entrar al visual tree: el template solo se
1533
- // instancia en load. Sin fallback Yoga les da rect 0 y el control
1534
- // queda invisible aunque funcione — intrínsecos del default style.
1535
- if (d.Width <= 0 || d.Height <= 0) {
1536
- if (n.sw)
1537
- d = Size{60, 24};
1538
- else if (n.check || n.radio)
1539
- d = Size{20, 20};
1540
- else if (n.input)
1541
- d = Size{120, 32};
1542
- else if (n.button && (!n.textValue.empty() || n.absorbedTextId != 0))
1543
- d = Size{88, 32};
1544
- else if (n.slider)
1545
- d = Size{120, 32};
1546
- else if (n.image)
1547
- d = Size{64, 64};
1548
- }
1549
- ow = wMode == YGMeasureModeExactly ? w : std::min(d.Width, availW);
1550
- oh = hMode == YGMeasureModeExactly ? h : std::min(d.Height, availH);
1551
- float pl = 0, pt = 0, pr = 0, pb = 0;
1552
- yoga::padOf(id, pl, pt, pr, pb);
1553
- ow += pl + pr;
1554
- oh += pt + pb;
1555
- }
1556
-
1557
- // ── Eventos (attach-event → control nativo) ────────────────────────
1558
-
1559
- void WinApplicator::attachEvent(int id, const std::string &event,
1560
- const std::string &handler,
1561
- bool continuous,
1562
- const std::string &payload) {
1563
- auto it = nodes_.find(id);
1564
- if (it == nodes_.end())
1565
- return;
1566
- WinNode &n = it->second;
1567
- n.events[event] = EventBind{handler, continuous, payload};
1568
-
1569
- if (event == "press") {
1570
- // ADR-0179: el release que cierra un longPress o un pan disparado
1571
- // no es press — los consume lpFired/panMoved (una sola vez).
1572
- auto consumeGesture = [](WinNode &nn) {
1573
- if (nn.lpFired || nn.panMoved) {
1574
- nn.lpFired = false;
1575
- nn.panMoved = false;
1576
- return true;
1577
- }
1578
- return false;
1579
- };
1580
- if (n.button) {
1581
- if (!n.tokClick.value)
1582
- n.tokClick = n.button.Click(
1583
- [this, id, consumeGesture](auto const &, auto const &) {
1584
- auto i = nodes_.find(id);
1585
- if (i == nodes_.end() || consumeGesture(i->second))
1586
- return;
1587
- if (i->second.events.count("press"))
1588
- emitEvent(i->second, "press", "user", "{}",
1589
- i->second.events["press"]);
1590
- });
1591
- } else if (n.el) {
1592
- // IsTapEnabled default false en UIElement — sin el flag el Tapped
1593
- // nunca se genera en la ruta de hit (el hit cae en el Border del
1594
- // chrome, no en el host ContentControl).
1595
- if (n.border)
1596
- n.border.IsTapEnabled(true);
1597
- n.el.IsTapEnabled(true);
1598
- n.el.Tapped(
1599
- [this, id, consumeGesture](auto const &,
1600
- muxi::TappedRoutedEventArgs const &) {
1601
- auto i = nodes_.find(id);
1602
- if (i == nodes_.end() || consumeGesture(i->second))
1603
- return;
1604
- if (i->second.events.count("press"))
1605
- emitEvent(i->second, "press", "user", "{}",
1606
- i->second.events["press"]);
1607
- });
1608
- }
1609
- return;
1610
- }
1611
- if (event == "input" || event == "change") {
1612
- if (n.input) {
1613
- if (!n.tokText.value)
1614
- n.tokText =
1615
- n.input.TextChanged([this, id](auto const &, auto const &) {
1616
- auto i = nodes_.find(id);
1617
- if (i == nodes_.end() || i->second.suppressSignal)
1618
- return;
1619
- WinNode &nn = i->second;
1620
- std::string t = winrt::to_string(nn.input.Text());
1621
- const char *ev = nn.events.count("input") ? "input"
1622
- : "change";
1623
- auto eb = nn.events.find(ev);
1624
- if (eb != nn.events.end())
1625
- emitEvent(nn, ev, "user",
1626
- std::string("{\"value\":") +
1627
- modules::jsonQuote(t) + "}",
1628
- eb->second);
1629
- });
1630
- } else if (n.swEl) {
1631
- wireCheckLike(id, n);
1632
- } else if (n.slider) {
1633
- if (!n.tokSlider.value)
1634
- n.tokSlider = n.slider.ValueChanged(
1635
- [this, id](auto const &,
1636
- muxc::Primitives::RangeBaseValueChangedEventArgs
1637
- const &e) {
1638
- auto i = nodes_.find(id);
1639
- if (i == nodes_.end() || i->second.suppressSignal)
1640
- return;
1641
- WinNode &nn = i->second;
1642
- const char *ev = nn.events.count("change") ? "change"
1643
- : "input";
1644
- auto eb = nn.events.find(ev);
1645
- if (eb != nn.events.end()) {
1646
- char buf[48];
1647
- snprintf(buf, sizeof(buf), "{\"value\":%.4g}",
1648
- e.NewValue());
1649
- emitEvent(nn, ev, "user", buf, eb->second);
1650
- }
1651
- });
1652
- } else
1653
- warnOnce(unknownProps_, "event-pendiente",
1654
- event + "@" + n.type);
1655
- return;
1656
- }
1657
- if (event == "submit" && n.input) {
1658
- n.input.KeyDown([this, id](auto const &,
1659
- muxi::KeyRoutedEventArgs const &e) {
1660
- if (e.Key() != winrt::Windows::System::VirtualKey::Enter)
1661
- return;
1662
- auto i = nodes_.find(id);
1663
- if (i == nodes_.end())
1664
- return;
1665
- auto eb = i->second.events.find("submit");
1666
- if (eb != i->second.events.end())
1667
- emitEvent(i->second, "submit", "user",
1668
- std::string("{\"text\":") +
1669
- modules::jsonQuote(
1670
- winrt::to_string(i->second.input.Text())) +
1671
- "}",
1672
- eb->second);
1673
- });
1674
- return;
1675
- }
1676
- if (event == "scroll" && n.scroll) {
1677
- auto emitMetrics = [this](WinNode &nd) {
1678
- auto eb = nd.events.find("scroll");
1679
- if (eb == nd.events.end())
1680
- return;
1681
- // {y,x,vh,vw,ch,cw,node} — mismo contrato que emitScrollMetrics
1682
- // GTK: endReached lo sintetiza el reconciler sobre estos campos.
1683
- char buf[256];
1684
- snprintf(buf, sizeof(buf),
1685
- "{\"y\":%.1f,\"x\":%.1f,\"vh\":%.1f,\"vw\":%.1f,"
1686
- "\"ch\":%.1f,\"cw\":%.1f,\"node\":%d}",
1687
- nd.scroll.VerticalOffset(), nd.scroll.HorizontalOffset(),
1688
- nd.scroll.ViewportHeight(), nd.scroll.ViewportWidth(),
1689
- nd.scroll.ExtentHeight(), nd.scroll.ExtentWidth(),
1690
- nd.id);
1691
- emitEvent(nd, "scroll", "user", buf, eb->second);
1692
- };
1693
- if (!n.tokView.value)
1694
- n.tokView = n.scroll.ViewChanged(
1695
- [this, id, emitMetrics](auto const &, auto const &) {
1696
- auto i = nodes_.find(id);
1697
- if (i == nodes_.end() || i->second.suppressSignal)
1698
- return;
1699
- emitMetrics(i->second);
1700
- });
1701
- emitMetrics(n); // métricas iniciales — igual que en el attach GTK
1702
- return;
1703
- }
1704
- if (event == "focus" || event == "blur") {
1705
- auto fire = [this, id](const char *ev) {
1706
- auto i = nodes_.find(id);
1707
- if (i == nodes_.end())
1708
- return;
1709
- auto eb = i->second.events.find(ev);
1710
- if (eb != i->second.events.end())
1711
- emitEvent(i->second, ev, "user", "{}", eb->second);
1712
- };
1713
- if (event == "focus")
1714
- n.el.GotFocus([fire](auto const &, auto const &) { fire("focus"); });
1715
- else
1716
- n.el.LostFocus([fire](auto const &, auto const &) { fire("blur"); });
1717
- return;
1718
- }
1719
- if (event == "key" && n.el) {
1720
- // Paridad GTK/web (tabindex): el nodo se vuelve enfocable y el
1721
- // PointerPressed le da el foco — sin él el KeyDown nunca llega.
1722
- if (auto ctl = n.el.try_as<muxc::Control>())
1723
- ctl.IsTabStop(true);
1724
- auto grabKeyFocus = [this](mux::UIElement el) {
1725
- // La asignación de foco por puntero del sistema termina tras el
1726
- // release y pisa cualquier Focus previo — el diferido en el
1727
- // release gana la carrera.
1728
- if (auto dq = mud::DispatcherQueue::GetForCurrentThread())
1729
- dq.TryEnqueue(
1730
- mud::DispatcherQueuePriority::Low,
1731
- mud::DispatcherQueueHandler([el]() {
1732
- if (auto ctl = el.try_as<muxc::Control>())
1733
- ctl.Focus(mux::FocusState::Programmatic);
1734
- }));
1735
- };
1736
- muxi::PointerEventHandler onP(
1737
- [this, id, grabKeyFocus](
1738
- auto const &, muxi::PointerRoutedEventArgs const &) {
1739
- auto i = nodes_.find(id);
1740
- if (i != nodes_.end())
1741
- grabKeyFocus(i->second.el);
1742
- });
1743
- n.el.AddHandler(mux::UIElement::PointerReleasedEvent(),
1744
- winrt::box_value(onP), true);
1745
- n.el.KeyDown(
1746
- [this, id](auto const &, muxi::KeyRoutedEventArgs const &e) {
1747
- emitKeyFor(id, e.Key());
1748
- });
1749
- return;
1750
- }
1751
- if (event == "shortcut") {
1752
- // El reconciler deja el combo canónico en el payload (ADR-0179) —
1753
- // mismo modelo que GTK: registro de ventana + PreviewKeyDown.
1754
- modules::Json p;
1755
- const modules::Json *c =
1756
- modules::jsonParse(payload, p) ? p.get("combo") : nullptr;
1757
- std::string combo = c ? c->asStr() : "";
1758
- if (combo.empty())
1759
- return;
1760
- dropHotkeys(id);
1761
- hotkeys_.push_back({id, combo});
1762
- ensureHotkeyHook();
1763
- return;
1764
- }
1765
- if (event == "hover" && n.el) {
1766
- // GTK: hover = solo la fase enter.
1767
- n.el.PointerEntered(
1768
- [this, id](auto const &, muxi::PointerRoutedEventArgs const &) {
1769
- auto i = nodes_.find(id);
1770
- if (i == nodes_.end())
1771
- return;
1772
- auto eb = i->second.events.find("hover");
1773
- if (eb != i->second.events.end())
1774
- emitEvent(i->second, "hover", "user", "{}", eb->second);
1775
- });
1776
- return;
1777
- }
1778
- if (event == "pointer" && n.el) {
1779
- auto firePt = [this, id](const char *phase, auto const &e) {
1780
- auto i = nodes_.find(id);
1781
- if (i == nodes_.end())
1782
- return;
1783
- auto eb = i->second.events.find("pointer");
1784
- if (eb == i->second.events.end())
1785
- return;
1786
- auto pt = e.GetCurrentPoint(i->second.el).Position();
1787
- char buf[128];
1788
- snprintf(buf, sizeof(buf), "{\"phase\":\"%s\",\"x\":%.1f,\"y\":%.1f}",
1789
- phase, pt.X, pt.Y);
1790
- emitEvent(i->second, "pointer", "user", buf, eb->second);
1791
- };
1792
- n.el.PointerEntered(
1793
- [firePt](auto const &,
1794
- muxi::PointerRoutedEventArgs const &e) { firePt("enter", e); });
1795
- n.el.PointerMoved(
1796
- [firePt](auto const &,
1797
- muxi::PointerRoutedEventArgs const &e) { firePt("move", e); });
1798
- n.el.PointerExited(
1799
- [firePt](auto const &,
1800
- muxi::PointerRoutedEventArgs const &e) { firePt("leave", e); });
1801
- // down/up sobre un Button llega handled: AddHandler los ve igual.
1802
- n.el.AddHandler(
1803
- mux::UIElement::PointerPressedEvent(),
1804
- winrt::box_value(muxi::PointerEventHandler(
1805
- [firePt](auto const &,
1806
- muxi::PointerRoutedEventArgs const &e) {
1807
- firePt("down", e);
1808
- })),
1809
- true);
1810
- n.el.AddHandler(
1811
- mux::UIElement::PointerReleasedEvent(),
1812
- winrt::box_value(muxi::PointerEventHandler(
1813
- [firePt](auto const &,
1814
- muxi::PointerRoutedEventArgs const &e) {
1815
- firePt("up", e);
1816
- })),
1817
- true);
1818
- return;
1819
- }
1820
- if (event == "contextMenu" && n.el) {
1821
- n.el.RightTapped(
1822
- [this, id](auto const &,
1823
- muxi::RightTappedRoutedEventArgs const &e) {
1824
- auto i = nodes_.find(id);
1825
- if (i == nodes_.end())
1826
- return;
1827
- auto eb = i->second.events.find("contextMenu");
1828
- if (eb == i->second.events.end())
1829
- return;
1830
- auto pt = e.GetPosition(i->second.el);
1831
- char buf[64];
1832
- snprintf(buf, sizeof(buf), "{\"x\":%.1f,\"y\":%.1f}", pt.X, pt.Y);
1833
- emitEvent(i->second, "contextMenu", "user", buf, eb->second);
1834
- });
1835
- return;
1836
- }
1837
- if (event == "longPress" && n.el) {
1838
- auto fireLp = [this, id](float x, float y) {
1839
- auto i = nodes_.find(id);
1840
- if (i == nodes_.end())
1841
- return;
1842
- auto eb = i->second.events.find("longPress");
1843
- if (eb == i->second.events.end())
1844
- return;
1845
- char buf[64];
1846
- snprintf(buf, sizeof(buf), "{\"x\":%.1f,\"y\":%.1f}", x, y);
1847
- emitEvent(i->second, "longPress", "user", buf, eb->second);
1848
- };
1849
- // ADR-0179: umbral del SO — Holding cubre touch/pen; el ratón no
1850
- // genera Holding en WinUI3, así que lleva un timer propio
1851
- // (500 ms / cancela a 8 px — el estándar web del ADR). La ruta de
1852
- // hit pasa por el Border: los flags van en los dos niveles.
1853
- if (n.border)
1854
- n.border.IsHoldingEnabled(true);
1855
- n.el.IsHoldingEnabled(true);
1856
- n.el.Holding(
1857
- [this, id, fireLp](auto const &,
1858
- muxi::HoldingRoutedEventArgs const &e) {
1859
- if (e.HoldingState() != mui::HoldingState::Started)
1860
- return;
1861
- auto i = nodes_.find(id);
1862
- if (i == nodes_.end())
1863
- return;
1864
- i->second.lpFired = true;
1865
- auto pt = e.GetPosition(i->second.el);
1866
- fireLp((float)pt.X, (float)pt.Y);
1867
- });
1868
- // AddHandler(handledEventsToo): Button marca pressed/released
1869
- // handled — con += el timer no vería nunca el ciclo del ratón.
1870
- n.el.AddHandler(
1871
- mux::UIElement::PointerPressedEvent(),
1872
- winrt::box_value(muxi::PointerEventHandler(
1873
- [this, id](auto const &,
1874
- muxi::PointerRoutedEventArgs const &e) {
1875
- auto i = nodes_.find(id);
1876
- if (i == nodes_.end())
1877
- return;
1878
- WinNode &nn = i->second;
1879
- nn.lpFired = false;
1880
- if (!nn.lpTimer) {
1881
- nn.lpTimer = mux::DispatcherTimer();
1882
- nn.lpTimer.Interval(
1883
- wf::TimeSpan{std::chrono::milliseconds(500)});
1884
- nn.lpTimer.Tick([this, id](auto const &, auto const &) {
1885
- auto it = nodes_.find(id);
1886
- if (it == nodes_.end())
1887
- return;
1888
- it->second.lpTimer.Stop();
1889
- auto eb = it->second.events.find("longPress");
1890
- if (eb == it->second.events.end())
1891
- return;
1892
- it->second.lpFired = true;
1893
- char buf[64];
1894
- snprintf(buf, sizeof(buf), "{\"x\":%.1f,\"y\":%.1f}",
1895
- it->second.lpX, it->second.lpY);
1896
- emitEvent(it->second, "longPress", "user", buf,
1897
- eb->second);
1898
- });
1899
- }
1900
- auto pt = e.GetCurrentPoint(nn.el).Position();
1901
- nn.lpX = (float)pt.X;
1902
- nn.lpY = (float)pt.Y;
1903
- nn.lpTimer.Start();
1904
- })),
1905
- true);
1906
- auto cancelLp = [this, id](float mx, float my, bool hard) {
1907
- auto i = nodes_.find(id);
1908
- if (i == nodes_.end() || !i->second.lpTimer)
1909
- return;
1910
- if (hard ||
1911
- std::abs(mx - i->second.lpX) > 8.f ||
1912
- std::abs(my - i->second.lpY) > 8.f)
1913
- i->second.lpTimer.Stop();
1914
- };
1915
- // El gesto reclamado a manipulación con desplazamiento real no es
1916
- // longPress — ManipulationStarted llega ya en el press (Translate
1917
- // activo), así que se cancela por distancia, no por el inicio.
1918
- n.el.ManipulationDelta(
1919
- [this, id, cancelLp](
1920
- auto const &,
1921
- muxi::ManipulationDeltaRoutedEventArgs const &e) {
1922
- auto cum = e.Cumulative().Translation;
1923
- if (std::abs((float)cum.X) > 8.f ||
1924
- std::abs((float)cum.Y) > 8.f)
1925
- cancelLp(0, 0, true);
1926
- });
1927
- n.el.AddHandler(
1928
- mux::UIElement::PointerMovedEvent(),
1929
- winrt::box_value(muxi::PointerEventHandler(
1930
- [this, id, cancelLp](
1931
- auto const &, muxi::PointerRoutedEventArgs const &e) {
1932
- auto i = nodes_.find(id);
1933
- if (i == nodes_.end())
1934
- return;
1935
- auto pt = e.GetCurrentPoint(i->second.el).Position();
1936
- cancelLp((float)pt.X, (float)pt.Y, false);
1937
- })),
1938
- true);
1939
- n.el.AddHandler(
1940
- mux::UIElement::PointerReleasedEvent(),
1941
- winrt::box_value(muxi::PointerEventHandler(
1942
- [this, id, cancelLp](
1943
- auto const &, muxi::PointerRoutedEventArgs const &) {
1944
- cancelLp(0, 0, true);
1945
- })),
1946
- true);
1947
- n.el.PointerExited(
1948
- [this, id, cancelLp](auto const &,
1949
- muxi::PointerRoutedEventArgs const &) {
1950
- cancelLp(0, 0, true);
1951
- });
1952
- n.el.PointerCaptureLost(
1953
- [this, id, cancelLp](auto const &,
1954
- muxi::PointerRoutedEventArgs const &) {
1955
- cancelLp(0, 0, true);
1956
- });
1957
- return;
1958
- }
1959
- // El gesture recognizer lo genera el elemento más profundo bajo el
1960
- // puntero (Button captura el contacto y los PointerMoved no llegan
1961
- // al wrapper; ManipulationDelta tampoco burbujea — solo Started/
1962
- // Completed). Pan/pinch escuchan ese elemento, que además necesita
1963
- // los modos reales: System produce Started/Completed con cum=0.
1964
- auto gestureEl = [&n]() -> mux::UIElement {
1965
- if (n.button) return n.button;
1966
- if (n.input) return n.input;
1967
- if (n.swEl) return n.swEl;
1968
- if (n.slider) return n.slider;
1969
- if (n.image) return n.image;
1970
- return n.el;
1971
- };
1972
- if (event == "pan" && n.el) {
1973
- auto ge = gestureEl();
1974
- // Pan por ManipulationDelta en el elemento gestual (ge): el
1975
- // recognizer vive en el control más profundo — los deltas no
1976
- // burbujean al host (Started/Completed sí). Slop 8px como
1977
- // GtkGestureDrag; el reclamo niega longPress (timer) y el press
1978
- // del release (consumeGesture). Payload {x,y} = posición del
1979
- // contacto en coords del elemento, {dx,dy} = traslación
1980
- // acumulada — mismo contrato que GTK.
1981
- ge.ManipulationMode(
1982
- (ge.ManipulationMode() & ~muxi::ManipulationModes::System) |
1983
- muxi::ManipulationModes::TranslateX |
1984
- muxi::ManipulationModes::TranslateY |
1985
- muxi::ManipulationModes::Scale);
1986
- auto emitPan = [this, id](const char *phase, float px, float py,
1987
- float ox, float oy) {
1988
- auto i = nodes_.find(id);
1989
- if (i == nodes_.end())
1990
- return;
1991
- auto eb = i->second.events.find("pan");
1992
- if (eb == i->second.events.end())
1993
- return;
1994
- char buf[160];
1995
- snprintf(buf, sizeof(buf),
1996
- "{\"phase\":\"%s\",\"x\":%.1f,\"y\":%.1f,"
1997
- "\"dx\":%.1f,\"dy\":%.1f}",
1998
- phase, px, py, ox, oy);
1999
- emitEvent(i->second, "pan", "user", buf, eb->second);
2000
- };
2001
- ge.ManipulationStarted(
2002
- [this, id](auto const &,
2003
- muxi::ManipulationStartedRoutedEventArgs const &) {
2004
- auto i = nodes_.find(id);
2005
- if (i != nodes_.end())
2006
- i->second.panMoved = false;
2007
- });
2008
- ge.ManipulationDelta(
2009
- [this, id, emitPan](
2010
- auto const &,
2011
- muxi::ManipulationDeltaRoutedEventArgs const &e) {
2012
- auto i = nodes_.find(id);
2013
- if (i == nodes_.end())
2014
- return;
2015
- WinNode &nn = i->second;
2016
- auto cum = e.Cumulative().Translation;
2017
- float ox = (float)cum.X, oy = (float)cum.Y;
2018
- bool first = false;
2019
- if (!nn.panMoved) {
2020
- if (std::hypot(ox, oy) <= 8.f)
2021
- return;
2022
- nn.panMoved = true;
2023
- first = true;
2024
- if (nn.lpTimer)
2025
- nn.lpTimer.Stop();
2026
- }
2027
- auto pos = e.Position();
2028
- emitPan(first ? "start" : "move", (float)pos.X, (float)pos.Y,
2029
- ox, oy);
2030
- });
2031
- ge.ManipulationCompleted(
2032
- [this, id, emitPan](
2033
- auto const &,
2034
- muxi::ManipulationCompletedRoutedEventArgs const &e) {
2035
- auto i = nodes_.find(id);
2036
- if (i == nodes_.end() || !i->second.panMoved)
2037
- return;
2038
- auto cum = e.Cumulative().Translation;
2039
- auto pos = e.Position();
2040
- emitPan("end", (float)pos.X, (float)pos.Y, (float)cum.X,
2041
- (float)cum.Y);
2042
- });
2043
- // Ratón: la manipulación de WinUI 3 desktop solo se alimenta de
2044
- // touch/pen — el drag de ratón se mide por PointerMoved con botón
2045
- // (mismo camino que GtkGestureDrag). panMoved queda tras el end:
2046
- // consumeGesture lo usa para negar el press del release.
2047
- ge.AddHandler(
2048
- mux::UIElement::PointerPressedEvent(),
2049
- winrt::box_value(muxi::PointerEventHandler(
2050
- [this, id, ge](auto const &,
2051
- muxi::PointerRoutedEventArgs const &e) {
2052
- if (e.Pointer().PointerDeviceType() !=
2053
- mui::PointerDeviceType::Mouse)
2054
- return;
2055
- auto i = nodes_.find(id);
2056
- if (i == nodes_.end())
2057
- return;
2058
- WinNode &nn = i->second;
2059
- nn.panMouseDown = true;
2060
- nn.panMoved = false;
2061
- auto pt = e.GetCurrentPoint(ge).Position();
2062
- nn.panSX = (float)pt.X;
2063
- nn.panSY = (float)pt.Y;
2064
- ge.CapturePointer(e.Pointer());
2065
- })),
2066
- true);
2067
- ge.AddHandler(
2068
- mux::UIElement::PointerMovedEvent(),
2069
- winrt::box_value(muxi::PointerEventHandler(
2070
- [this, id, ge, emitPan](
2071
- auto const &, muxi::PointerRoutedEventArgs const &e) {
2072
- auto i = nodes_.find(id);
2073
- if (i == nodes_.end())
2074
- return;
2075
- WinNode &nn = i->second;
2076
- if (!nn.panMouseDown)
2077
- return;
2078
- auto cp = e.GetCurrentPoint(ge);
2079
- if (!cp.Properties().IsLeftButtonPressed()) {
2080
- nn.panMouseDown = false;
2081
- return;
2082
- }
2083
- auto pt = cp.Position();
2084
- float ox = (float)pt.X - nn.panSX;
2085
- float oy = (float)pt.Y - nn.panSY;
2086
- if (!nn.panMoved) {
2087
- if (std::hypot(ox, oy) <= 8.f)
2088
- return;
2089
- nn.panMoved = true;
2090
- if (nn.lpTimer)
2091
- nn.lpTimer.Stop();
2092
- emitPan("start", (float)pt.X, (float)pt.Y, ox, oy);
2093
- } else {
2094
- emitPan("move", (float)pt.X, (float)pt.Y, ox, oy);
2095
- }
2096
- })),
2097
- true);
2098
- auto endMousePan = [this, id, ge, emitPan](
2099
- muxi::PointerRoutedEventArgs const &e) {
2100
- auto i = nodes_.find(id);
2101
- if (i == nodes_.end() || !i->second.panMouseDown)
2102
- return;
2103
- WinNode &nn = i->second;
2104
- nn.panMouseDown = false;
2105
- if (!nn.panMoved)
2106
- return;
2107
- auto pt = e.GetCurrentPoint(ge).Position();
2108
- emitPan("end", (float)pt.X, (float)pt.Y,
2109
- (float)pt.X - nn.panSX, (float)pt.Y - nn.panSY);
2110
- };
2111
- ge.AddHandler(mux::UIElement::PointerReleasedEvent(),
2112
- winrt::box_value(muxi::PointerEventHandler(
2113
- [endMousePan](
2114
- auto const &,
2115
- muxi::PointerRoutedEventArgs const &e) {
2116
- endMousePan(e);
2117
- })),
2118
- true);
2119
- ge.AddHandler(mux::UIElement::PointerCaptureLostEvent(),
2120
- winrt::box_value(muxi::PointerEventHandler(
2121
- [endMousePan](
2122
- auto const &,
2123
- muxi::PointerRoutedEventArgs const &e) {
2124
- endMousePan(e);
2125
- })),
2126
- true);
2127
- return;
2128
- }
2129
- if (event == "pinch" && n.el) {
2130
- // events.ts {scale,focalX,focalY,phase} — ManipulationDelta con
2131
- // modo Scale. El delta dispara con CUALQUIER manipulación (un pan
2132
- // de un dedo también es manipulación): el gesto solo es pinch si
2133
- // hubo 2+ contactos simultáneos — ptrCount los lleva la cuenta.
2134
- auto ge = gestureEl();
2135
- ge.ManipulationMode((ge.ManipulationMode() &
2136
- ~muxi::ManipulationModes::System) |
2137
- muxi::ManipulationModes::Scale);
2138
- // AddHandler(handledEventsToo): los controles marcan pressed
2139
- // handled; la cuenta de contactos tiene que verlos igual.
2140
- n.el.AddHandler(
2141
- mux::UIElement::PointerPressedEvent(),
2142
- winrt::box_value(muxi::PointerEventHandler(
2143
- [this, id](auto const &,
2144
- muxi::PointerRoutedEventArgs const &) {
2145
- auto i = nodes_.find(id);
2146
- if (i != nodes_.end())
2147
- i->second.ptrCount++;
2148
- })),
2149
- true);
2150
- auto dropPtr = [this, id]() {
2151
- auto i = nodes_.find(id);
2152
- if (i != nodes_.end() && i->second.ptrCount > 0)
2153
- i->second.ptrCount--;
2154
- };
2155
- n.el.AddHandler(
2156
- mux::UIElement::PointerReleasedEvent(),
2157
- winrt::box_value(muxi::PointerEventHandler(
2158
- [this, id, dropPtr](
2159
- auto const &, muxi::PointerRoutedEventArgs const &) {
2160
- dropPtr();
2161
- })),
2162
- true);
2163
- n.el.PointerCaptureLost(
2164
- [this, id, dropPtr](auto const &,
2165
- muxi::PointerRoutedEventArgs const &) {
2166
- dropPtr();
2167
- });
2168
- ge.ManipulationStarted(
2169
- [this, id](auto const &, auto const &) {
2170
- auto i = nodes_.find(id);
2171
- if (i != nodes_.end())
2172
- i->second.pinchActive = false;
2173
- });
2174
- ge.ManipulationDelta(
2175
- [this, id](auto const &,
2176
- muxi::ManipulationDeltaRoutedEventArgs const &e) {
2177
- auto i = nodes_.find(id);
2178
- if (i == nodes_.end() || i->second.ptrCount < 2)
2179
- return;
2180
- auto eb = i->second.events.find("pinch");
2181
- if (eb == i->second.events.end())
2182
- return;
2183
- auto pos = e.Position();
2184
- char buf[160];
2185
- if (!i->second.pinchActive) {
2186
- i->second.pinchActive = true;
2187
- snprintf(buf, sizeof(buf),
2188
- "{\"phase\":\"start\",\"scale\":1,\"focalX\":%.1f,"
2189
- "\"focalY\":%.1f}",
2190
- (float)pos.X, (float)pos.Y);
2191
- emitEvent(i->second, "pinch", "user", buf, eb->second);
2192
- }
2193
- float sc = (float)e.Delta().Scale;
2194
- if (sc == 1.f || sc != sc)
2195
- return;
2196
- auto cum = e.Cumulative().Scale;
2197
- snprintf(buf, sizeof(buf),
2198
- "{\"phase\":\"move\",\"scale\":%.3f,"
2199
- "\"focalX\":%.1f,\"focalY\":%.1f}",
2200
- (float)cum, (float)pos.X, (float)pos.Y);
2201
- emitEvent(i->second, "pinch", "user", buf, eb->second);
2202
- });
2203
- ge.ManipulationCompleted(
2204
- [this, id](auto const &, auto const &) {
2205
- auto i = nodes_.find(id);
2206
- if (i == nodes_.end() || !i->second.pinchActive)
2207
- return;
2208
- i->second.pinchActive = false;
2209
- auto eb = i->second.events.find("pinch");
2210
- if (eb == i->second.events.end())
2211
- return;
2212
- emitEvent(i->second, "pinch", "user",
2213
- "{\"phase\":\"end\",\"scale\":1,\"focalX\":0,"
2214
- "\"focalY\":0}",
2215
- eb->second);
2216
- });
2217
- return;
2218
- }
2219
- if (event == "select" && n.input) {
2220
- n.input.SelectionChanged(
2221
- [this, id](auto const &, auto const &) {
2222
- auto i = nodes_.find(id);
2223
- if (i == nodes_.end() || i->second.suppressSignal)
2224
- return;
2225
- WinNode &nn = i->second;
2226
- auto eb = nn.events.find("select");
2227
- if (eb == nn.events.end())
2228
- return;
2229
- char buf[64];
2230
- snprintf(buf, sizeof(buf), "{\"start\":%d,\"end\":%d}",
2231
- nn.input.SelectionStart(),
2232
- nn.input.SelectionStart() + nn.input.SelectionLength());
2233
- emitEvent(nn, "select", "user", buf, eb->second);
2234
- });
2235
- return;
2236
- }
2237
- if (event == "composition" && n.input) {
2238
- auto fireComp = [this, id](const char *phase) {
2239
- auto i = nodes_.find(id);
2240
- if (i == nodes_.end())
2241
- return;
2242
- WinNode &nn = i->second;
2243
- auto eb = nn.events.find("composition");
2244
- if (eb == nn.events.end())
2245
- return;
2246
- emitEvent(nn, "composition", "user",
2247
- std::string("{\"phase\":\"") + phase + "\",\"text\":" +
2248
- modules::jsonQuote(winrt::to_string(nn.input.Text())) +
2249
- "}",
2250
- eb->second);
2251
- };
2252
- n.input.TextCompositionStarted(
2253
- [fireComp](auto const &, auto const &) { fireComp("start"); });
2254
- n.input.TextCompositionChanged(
2255
- [fireComp](auto const &, auto const &) { fireComp("update"); });
2256
- n.input.TextCompositionEnded(
2257
- [fireComp](auto const &, auto const &) { fireComp("end"); });
2258
- return;
2259
- }
2260
- if ((event == "load" || event == "error") && n.image) {
2261
- // Replay ADR-0204: si el bitmap ya resolvió antes del attach, se
2262
- // reemite el resultado (como imgLoaded/imgFailed en GTK).
2263
- if (event == "load" && n.imgLoaded) {
2264
- char buf[96];
2265
- snprintf(buf, sizeof(buf), "{\"width\":%d,\"height\":%d%s}",
2266
- n.imgW, n.imgH,
2267
- n.imgLoadFallback ? ",\"fallback\":true" : "");
2268
- emitEvent(n, "load", "program", buf, n.events["load"]);
2269
- } else if (event == "error" && n.imgFailed) {
2270
- std::string d = "{\"message\":\"image load failed\"";
2271
- if (n.imgFailFallback)
2272
- d += ",\"fallback\":true";
2273
- d += "}";
2274
- emitEvent(n, "error", "program", d, n.events["error"]);
2275
- }
2276
- return;
2277
- }
2278
- if (event == "refresh" && n.scroll) {
2279
- ensureRefresh(n);
2280
- return;
2281
- }
2282
- warnOnce(unknownProps_, "event-pendiente", event + "@" + n.type);
2283
- }
2284
-
2285
- void WinApplicator::detachEvent(int id, const std::string &event) {
2286
- auto it = nodes_.find(id);
2287
- if (it != nodes_.end())
2288
- it->second.events.erase(event);
2289
- if (event == "shortcut")
2290
- dropHotkeys(id);
2291
- }
2292
-
2293
- void WinApplicator::dropHotkeys(int id) {
2294
- hotkeys_.erase(std::remove_if(hotkeys_.begin(), hotkeys_.end(),
2295
- [id](const Hotkey &h) { return h.id == id; }),
2296
- hotkeys_.end());
2297
- }
2298
-
2299
- void WinApplicator::ensureHotkeyHook() {
2300
- if (hotkeyHooked_ || !root_)
2301
- return;
2302
- hotkeyHooked_ = true;
2303
- // Capture en el root: PreviewKeyDown se ve antes que el control
2304
- // enfocado — mismo rol que el controller GTK_PHASE_CAPTURE.
2305
- root_.PreviewKeyDown(
2306
- [this](auto const &, muxi::KeyRoutedEventArgs const &e) {
2307
- if (e.KeyStatus().WasKeyDown)
2308
- return; // autorepeat
2309
- std::string combo = comboOf(e.Key());
2310
- if (hotkeys_.empty() || combo.empty())
2311
- return;
2312
- // Si el foco está en un campo de texto solo disparan los
2313
- // combos editing-safe (ctrl/alt/meta, Escape, F1-F24).
2314
- auto focusedObj =
2315
- root_.XamlRoot()
2316
- ? muxi::FocusManager::GetFocusedElement(root_.XamlRoot())
2317
- : nullptr;
2318
- bool editing =
2319
- focusedObj &&
2320
- (focusedObj.try_as<muxc::TextBox>() ||
2321
- focusedObj.try_as<muxc::RichEditBox>() ||
2322
- focusedObj.try_as<muxc::PasswordBox>());
2323
- if (editing && !firesWhileEditing(combo))
2324
- return;
2325
- for (auto h = hotkeys_.rbegin(); h != hotkeys_.rend(); ++h) {
2326
- if (h->combo != combo)
2327
- continue;
2328
- auto it = nodes_.find(h->id);
2329
- if (it == nodes_.end())
2330
- continue;
2331
- auto eb = it->second.events.find("shortcut");
2332
- if (eb == it->second.events.end())
2333
- continue;
2334
- emitEvent(it->second, "shortcut", "user", "{}", eb->second);
2335
- e.Handled(true);
2336
- return;
2337
- }
2338
- });
2339
- }
2340
-
2341
- void WinApplicator::ensureStickyScroll(WinNode &n) {
2342
- if (n.stickyScroll || !n.el)
2343
- return;
2344
- // El ancestro scroll se busca por el árbol visual — los nodos no
2345
- // guardan parentId.
2346
- auto fe = n.el.try_as<mux::FrameworkElement>();
2347
- mux::DependencyObject p = fe ? fe.Parent() : nullptr;
2348
- while (p) {
2349
- if (auto sv = p.try_as<muxc::ScrollViewer>()) {
2350
- n.stickyScroll = sv;
2351
- break;
2352
- }
2353
- p = mux::Media::VisualTreeHelper::GetParent(p);
2354
- }
2355
- if (!n.stickyScroll) {
2356
- warnOnce(unknownProps_, "prop-pendiente", "sticky-fuera-de-scroll");
2357
- n.sticky = false;
2358
- return;
2359
- }
2360
- n.tokSticky = n.stickyScroll.ViewChanged(
2361
- [this, id = n.id](auto const &, auto const &) { applySticky(id); });
2362
- applySticky(n.id);
2363
- }
2364
-
2365
- void WinApplicator::applySticky(int id) {
2366
- auto it = nodes_.find(id);
2367
- if (it == nodes_.end())
2368
- return;
2369
- WinNode &n = it->second;
2370
- if (!n.sticky || !n.stickyScroll || !n.el)
2371
- return;
2372
- if (!n.stickyBaseValid) {
2373
- // Top de contenido = posición dentro del Content del scroll sin
2374
- // la translation aplicada.
2375
- auto content = n.stickyScroll.Content()
2376
- .try_as<mux::UIElement>();
2377
- if (!content)
2378
- return;
2379
- auto t = n.el.TransformToVisual(content);
2380
- auto pt = t.TransformPoint(
2381
- winrt::Windows::Foundation::Point(0.f, 0.f));
2382
- n.stickyBaseY = (float)pt.Y - n.stickyShift;
2383
- n.stickyBaseValid = true;
2384
- }
2385
- float off = (float)n.stickyScroll.VerticalOffset();
2386
- float shift = off - (n.stickyBaseY - n.stickyTop);
2387
- // Clamp al containing block (padre visual directo, igual que
2388
- // android): el nodo no puede salir por abajo de su padre.
2389
- float maxShift = 3.4e38f;
2390
- auto pfe = n.el.try_as<mux::FrameworkElement>();
2391
- if (auto canvas = pfe ? pfe.Parent().try_as<muxc::Canvas>()
2392
- : nullptr) {
2393
- double ph = canvas.Height();
2394
- if (ph == ph && ph > 0)
2395
- maxShift = (float)ph - n.stickyBaseY - n.layH;
2396
- }
2397
- if (shift > maxShift)
2398
- shift = maxShift;
2399
- if (shift < 0 || shift != shift)
2400
- shift = 0;
2401
- if (shift == n.stickyShift)
2402
- return;
2403
- n.stickyShift = shift;
2404
- n.el.Translation(winrt::Windows::Foundation::Numerics::float3(
2405
- 0.f, shift, 0.f));
2406
- }
2407
-
2408
- void WinApplicator::emitKeyFor(int id,
2409
- winrt::Windows::System::VirtualKey k) {
2410
- auto i = nodes_.find(id);
2411
- if (i == nodes_.end())
2412
- return;
2413
- auto eb = i->second.events.find("key");
2414
- if (eb == i->second.events.end())
2415
- return;
2416
- std::string name = domKeyName(k);
2417
- if (name.empty())
2418
- return;
2419
- namespace vk = winrt::Windows::System;
2420
- std::string d = "{\"key\":\"" + name + "\"";
2421
- if (modDown(vk::VirtualKey::Control, vk::VirtualKey::LeftControl,
2422
- vk::VirtualKey::RightControl))
2423
- d += ",\"ctrl\":true";
2424
- if (modDown(vk::VirtualKey::Menu, vk::VirtualKey::LeftMenu,
2425
- vk::VirtualKey::RightMenu))
2426
- d += ",\"alt\":true";
2427
- if (modDown(vk::VirtualKey::Shift, vk::VirtualKey::LeftShift,
2428
- vk::VirtualKey::RightShift))
2429
- d += ",\"shift\":true";
2430
- if (modDown(vk::VirtualKey::LeftWindows, vk::VirtualKey::RightWindows,
2431
- vk::VirtualKey::LeftWindows))
2432
- d += ",\"meta\":true";
2433
- emitEvent(i->second, "key", "user", d + "}", eb->second);
2434
- }
2435
-
2436
- void WinApplicator::emitEvent(WinNode &n, const char *event,
2437
- const char *origin,
2438
- const std::string &dataJson,
2439
- const EventBind &bind) {
2440
- (void)n;
2441
- dlog("[elur] emit %s handler=%s\n", event, bind.handler.c_str());
2442
- emitHostEvent(cb_, bind, event, origin, dataJson);
2443
- }
2444
-
2445
- // AT invoca una acción del peer (select/expand/collapse) → evento
2446
- // `action` al JS con fallback `press` — mismo contrato que
2447
- // onA11yAction en GTK (ADR-0190).
2448
- void WinApplicator::onA11yInvoke(int id, const char *act) {
2449
- auto it = nodes_.find(id);
2450
- if (it == nodes_.end())
2451
- return;
2452
- WinNode &n = it->second;
2453
- std::string data = std::string("{\"action\":\"") + act + "\"}";
2454
- auto eb = n.events.find("action");
2455
- if (eb != n.events.end()) {
2456
- emitEvent(n, "action", "user", data, eb->second);
2457
- return;
2458
- }
2459
- if (auto pb = n.events.find("press"); pb != n.events.end())
2460
- emitEvent(n, "press", "user", "{}", pb->second);
2461
- }
2462
-
2463
- // ── Layout ─────────────────────────────────────────────────────────
2464
-
2465
- void WinApplicator::relayout() {
2466
- int n = yoga::layoutIfDirty([this](int id, float x, float y, float w,
2467
- float h) {
2468
- auto it = nodes_.find(id);
2469
- if (it == nodes_.end() || !it->second.el)
2470
- return;
2471
- WinNode &nd = it->second;
2472
- nd.layX = x; nd.layY = y; nd.layW = w; nd.layH = h;
2473
- muxc::Canvas::SetLeft(nd.el, x);
2474
- muxc::Canvas::SetTop(nd.el, y);
2475
- if (auto fe = nd.el.try_as<mux::FrameworkElement>()) {
2476
- if (w >= 0)
2477
- fe.Width(w);
2478
- if (h >= 0)
2479
- fe.Height(h);
2480
- }
2481
- // Contenedor vacío: el peer UIA deriva su BoundingRectangle del
2482
- // sub-árbol visual — un Canvas sin tamaño explícito colapsa a 0
2483
- // y el nodo queda IsOffscreen (inaccesible para el harness). El
2484
- // scroll tiene su propia regla abajo (extent = bbox de hijos).
2485
- if (nd.inner && !nd.scroll && w > 0 && h > 0) {
2486
- nd.inner.Width(w);
2487
- nd.inner.Height(h);
2488
- }
2489
- if (nd.border && w >= 0 && h >= 0) {
2490
- nd.border.Width(w);
2491
- nd.border.Height(h);
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
- }
2505
- // El inner canvas del scroll necesita su propio tamaño de
2506
- // contenido: ScrollViewer desplaza, el canvas recibe los rects
2507
- // de los hijos igual que el GtkFixed interno.
2508
- });
2509
- // Canvas no reporta DesiredSize: sin extent el ScrollViewer no
2510
- // scrollea. Se fija al bbox de los hijos (equivalente al natural
2511
- // size que GtkFixed da al GtkScrolledWindow en Linux).
2512
- for (auto &kv : nodes_) {
2513
- WinNode &nd = kv.second;
2514
- if (!nd.scroll || !nd.inner)
2515
- continue;
2516
- float cw = 0, ch = 0;
2517
- for (auto const &child : nd.inner.Children()) {
2518
- auto fe = child.try_as<mux::FrameworkElement>();
2519
- if (!fe)
2520
- continue;
2521
- float x = (float)muxc::Canvas::GetLeft(child) + (float)fe.Width();
2522
- float y = (float)muxc::Canvas::GetTop(child) + (float)fe.Height();
2523
- if (x > cw)
2524
- cw = x;
2525
- if (y > ch)
2526
- ch = y;
2527
- }
2528
- if (cw > 0)
2529
- nd.inner.Width(cw);
2530
- if (ch > 0)
2531
- nd.inner.Height(ch);
2532
- }
2533
- if (trace && n > 0)
2534
- yoga::dumpRects(stderr);
2535
- }
2536
-
2537
- // ── Ops ────────────────────────────────────────────────────────────
2538
-
2539
- void WinApplicator::applyFrame(JSContext *ctx, JSValueConst v) {
2540
- applyCycle_++;
2541
- JSValue ops = jsGet(ctx, v, "ops");
2542
- if (!JS_IsArray(ops)) {
2543
- JS_FreeValue(ctx, ops);
2544
- return;
2545
- }
2546
- int64_t len = 0;
2547
- JS_GetLength(ctx, ops, &len);
2548
-
2549
- for (int64_t i = 0; i < len; i++) {
2550
- JSValue op = JS_GetPropertyInt64(ctx, ops, i);
2551
- std::string name = jsGetStr(ctx, op, "op");
2552
- int id = jsInt(ctx, op, "id");
2553
- if (GetEnvironmentVariableA("ELUR_DEBUG", nullptr, 0) > 1) {
2554
- JSValue js = JS_JSONStringify(ctx, op, JS_UNDEFINED,
2555
- JS_UNDEFINED);
2556
- const char *s = JS_ToCString(ctx, js);
2557
- fprintf(stderr, "[op] %s id=%d %s\n", name.c_str(), id,
2558
- s ? s : "");
2559
- dlog("[op] %s id=%d %s\n", name.c_str(), id, s ? s : "");
2560
- if (s)
2561
- JS_FreeCString(ctx, s);
2562
- JS_FreeValue(ctx, js);
2563
- }
2564
-
2565
- try {
2566
- if (name == "create-node") {
2567
- createNode(id, jsGetStr(ctx, op, "type"));
2568
- } else if (name == "update-text") {
2569
- auto it = nodes_.find(id);
2570
- if (it != nodes_.end())
2571
- updateText(it->second, jsGetStr(ctx, op, "value"));
2572
- } else if (name == "update-style") {
2573
- auto it = nodes_.find(id);
2574
- if (it != nodes_.end()) {
2575
- JSValue st = jsGet(ctx, op, "style");
2576
- updateStyle(it->second, ctx, st);
2577
- JS_FreeValue(ctx, st);
2578
- }
2579
- } else if (name == "update-props" ||
2580
- name == "update-platform-view-props") {
2581
- auto it = nodes_.find(id);
2582
- if (it != nodes_.end()) {
2583
- JSValue pr = jsGet(ctx, op, "changedProps");
2584
- JSPropertyEnum *tab = nullptr;
2585
- uint32_t plen = 0;
2586
- if (JS_GetOwnPropertyNames(ctx, &tab, &plen, pr,
2587
- JS_GPN_STRING_MASK |
2588
- JS_GPN_ENUM_ONLY) == 0) {
2589
- for (uint32_t k = 0; k < plen; k++) {
2590
- JSAtom atom = tab[k].atom;
2591
- JSValue keyv = JS_AtomToString(ctx, atom);
2592
- std::string key = jsStr(ctx, keyv);
2593
- JS_FreeValue(ctx, keyv);
2594
- JSValue val = JS_GetProperty(ctx, pr, atom);
2595
- updateProp(it->second, key, ctx, val);
2596
- JS_FreeValue(ctx, val);
2597
- JS_FreeAtom(ctx, atom);
2598
- }
2599
- js_free(ctx, tab);
2600
- }
2601
- JS_FreeValue(ctx, pr);
2602
- }
2603
- } else if (name == "update-semantics") {
2604
- // ADR-0108 — el vocabulario a11y llega en una op dedicada;
2605
- // cada clave se aplica como prop normal (AutomationProperties).
2606
- // Las claves sin equivalente UIA caen en warnOnce.
2607
- auto it = nodes_.find(id);
2608
- if (it != nodes_.end()) {
2609
- JSValue pr = jsGet(ctx, op, "semantics");
2610
- JSPropertyEnum *tab = nullptr;
2611
- uint32_t plen = 0;
2612
- if (JS_GetOwnPropertyNames(ctx, &tab, &plen, pr,
2613
- JS_GPN_STRING_MASK |
2614
- JS_GPN_ENUM_ONLY) == 0) {
2615
- for (uint32_t k = 0; k < plen; k++) {
2616
- JSAtom atom = tab[k].atom;
2617
- JSValue keyv = JS_AtomToString(ctx, atom);
2618
- std::string key = jsStr(ctx, keyv);
2619
- JS_FreeValue(ctx, keyv);
2620
- JSValue val = JS_GetProperty(ctx, pr, atom);
2621
- updateProp(it->second, key, ctx, val);
2622
- JS_FreeValue(ctx, val);
2623
- JS_FreeAtom(ctx, atom);
2624
- }
2625
- js_free(ctx, tab);
2626
- }
2627
- JS_FreeValue(ctx, pr);
2628
- }
2629
- } else if (name == "insert-child") {
2630
- int parentId = jsInt(ctx, op, "parentId");
2631
- int childId = jsInt(ctx, op, "childId");
2632
- int index = jsInt(ctx, op, "index");
2633
- auto pi = nodes_.find(parentId);
2634
- auto ci = nodes_.find(childId);
2635
- if (ci != nodes_.end() && ci->second.el) {
2636
- muxc::Canvas target = surfaceOf(parentId);
2637
- detachVisual(ci->second.el);
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
- }
2665
- } else if (target) {
2666
- auto count = target.Children().Size();
2667
- uint32_t idx =
2668
- index < 0 ? count
2669
- : std::min<uint32_t>((uint32_t)index, count);
2670
- target.Children().InsertAt(idx, ci->second.el);
2671
- } else {
2672
- warnOnce(unknownOps_, "insert", name);
2673
- }
2674
- yoga::nodeInsert(parentId, childId, index);
2675
- }
2676
- } else if (name == "remove-child") {
2677
- int parentId = jsInt(ctx, op, "parentId");
2678
- int childId = jsInt(ctx, op, "childId");
2679
- auto ci = nodes_.find(childId);
2680
- if (ci != nodes_.end() && ci->second.el) {
2681
- detachVisual(ci->second.el);
2682
- // Hijo detachado de un shell: la nav-* del mismo batch lo
2683
- // re-inserta como overlay parallax (ADR-0013). WinRT retiene
2684
- // la referencia — su delete-node puede llegar antes de la op.
2685
- auto pi = nodes_.find(parentId);
2686
- if (pi != nodes_.end() && pi->second.absorbedTextId == childId)
2687
- pi->second.absorbedTextId = 0;
2688
- if (pi != nodes_.end() && pi->second.type == "shell") {
2689
- clearDetached();
2690
- detachedEl_ = ci->second.el;
2691
- detX_ = ci->second.layX;
2692
- detY_ = ci->second.layY;
2693
- detW_ = ci->second.layW;
2694
- detH_ = ci->second.layH;
2695
- }
2696
- yoga::nodeRemove(parentId, childId);
2697
- }
2698
- } else if (name == "move-child") {
2699
- yoga::nodeMove(jsInt(ctx, op, "parentId"),
2700
- jsInt(ctx, op, "childId"), jsInt(ctx, op, "index"));
2701
- // Reorden visual en el Canvas: quitar y reinsertar en index.
2702
- int parentId = jsInt(ctx, op, "parentId");
2703
- int childId = jsInt(ctx, op, "childId");
2704
- auto ci = nodes_.find(childId);
2705
- if (ci != nodes_.end() && ci->second.el) {
2706
- muxc::Canvas target = surfaceOf(parentId);
2707
- if (target) {
2708
- auto children = target.Children();
2709
- detachVisual(ci->second.el);
2710
- int index = jsInt(ctx, op, "index");
2711
- uint32_t idx = index < 0
2712
- ? children.Size()
2713
- : std::min<uint32_t>((uint32_t)index,
2714
- children.Size());
2715
- children.InsertAt(idx, ci->second.el);
2716
- }
2717
- }
2718
- } else if (name == "delete-node") {
2719
- deleteNode(id);
2720
- } else if (name == "attach-event") {
2721
- attachEvent(id, jsGetStr(ctx, op, "event"),
2722
- jsGetStr(ctx, op, "handler"),
2723
- jsGetStr(ctx, op, "class") == "continuous",
2724
- jsGetStr(ctx, op, "payload"));
2725
- } else if (name == "detach-event") {
2726
- detachEvent(id, jsGetStr(ctx, op, "event"));
2727
- } else if (name == "reset-node") {
2728
- auto it = nodes_.find(id);
2729
- if (it != nodes_.end() && it->second.scroll) {
2730
- it->second.suppressSignal = true;
2731
- it->second.scroll.ChangeView(nullptr, 0.0, nullptr);
2732
- it->second.suppressSignal = false;
2733
- }
2734
- } else if (name == "nav-push" || name == "nav-pop" ||
2735
- name == "nav-replace") {
2736
- navTransition(name, ctx, op);
2737
- } else {
2738
- // list-*/create-platform-view/layout/batch-update —
2739
- // caps ausentes → warn-once honesto, nunca silencio.
2740
- warnOnce(unknownOps_, "op", name);
2741
- }
2742
- } catch (winrt::hresult_error const &e) {
2743
- JSValue dump = JS_JSONStringify(ctx, op, JS_UNDEFINED, JS_UNDEFINED);
2744
- const char *ds = JS_ToCString(ctx, dump);
2745
- dlog("[elur] op %s id=%d hr=0x%08x %ls op=%s\n", name.c_str(), id,
2746
- (unsigned)e.code().value, e.message().c_str(),
2747
- ds ? ds : "?");
2748
- if (ds)
2749
- JS_FreeCString(ctx, ds);
2750
- JS_FreeValue(ctx, dump);
2751
- throw;
2752
- } catch (std::exception const &e) {
2753
- dlog("[elur] op %s id=%d std: %s\n", name.c_str(), id, e.what());
2754
- throw;
2755
- }
2756
- JS_FreeValue(ctx, op);
2757
- }
2758
- JS_FreeValue(ctx, ops);
2759
-
2760
- try {
2761
- relayout();
2762
- } catch (winrt::hresult_error const &e) {
2763
- dlog("[elur] relayout hr=0x%08x %ls\n", (unsigned)e.code().value,
2764
- e.message().c_str());
2765
- throw;
2766
- }
2767
- int frame = jsInt(ctx, v, "frame");
2768
- char fbuf[32];
2769
- snprintf(fbuf, sizeof(fbuf), "%d", frame);
2770
- cb_.callHandlerStr("__elur_commit_ack", fbuf);
2771
- }
2772
-
2773
- // ── Transiciones nav-* (paridad linux/web ADR-0013/0165) ──────────
2774
- // Modelo: hijo detachado de un `shell` se retiene como overlay; la
2775
- // nav-* del mismo batch lo re-inserta (push: debajo de la entrante;
2776
- // pop: encima) y un Storyboard con SplineDoubleKeyFrame anima
2777
- // Canvas.Left/Top + Opacity + escala — KeySpline es la MISMA
2778
- // cubic-bezier que resuelve bezierY en linux (control points directos,
2779
- // sin re-solver). El descriptor `def` declara capas incoming/outgoing
2780
- // con keyframes {from,to} por prop (x e y en % del shell si vienen
2781
- // como cadena "%"; ausentes → no anima esa prop, capa presente con x
2782
- // ausente → quieta en su sitio).
2783
-
2784
- static void jsToJson(JSContext *ctx, JSValueConst v, modules::Json &out) {
2785
- out = modules::Json();
2786
- if (JS_IsNull(v) || JS_IsUndefined(v))
2787
- return;
2788
- JSValue js = JS_JSONStringify(ctx, v, JS_UNDEFINED, JS_UNDEFINED);
2789
- if (JS_IsException(js))
2790
- return;
2791
- const char *s = JS_ToCString(ctx, js);
2792
- if (s) {
2793
- modules::Json parsed;
2794
- if (modules::jsonParse(s, parsed))
2795
- out = std::move(parsed);
2796
- JS_FreeCString(ctx, s);
2797
- }
2798
- JS_FreeValue(ctx, js);
2799
- }
2800
-
2801
- static double navValW(const modules::Json *v, double span) {
2802
- if (!v)
2803
- return NAN;
2804
- if (v->kind == modules::Json::Num)
2805
- return v->num;
2806
- if (v->kind == modules::Json::Str) {
2807
- const std::string &s = v->str;
2808
- if (!s.empty() && s.back() == '%')
2809
- return strtod(s.substr(0, s.size() - 1).c_str(), nullptr) / 100.0 *
2810
- span;
2811
- return strtod(s.c_str(), nullptr);
2812
- }
2813
- return NAN;
2814
- }
2815
-
2816
- struct NavSideW {
2817
- double x0 = NAN, x1 = NAN, y0 = NAN, y1 = NAN;
2818
- double op0 = NAN, op1 = NAN, sc0 = NAN, sc1 = NAN;
2819
- };
2820
-
2821
- static NavSideW navSideParseW(const modules::Json *side, double W,
2822
- double H) {
2823
- NavSideW s;
2824
- if (!side || side->kind != modules::Json::Obj)
2825
- return s;
2826
- const modules::Json *f = side->get("from"), *t = side->get("to");
2827
- if (f && f->kind == modules::Json::Obj) {
2828
- s.x0 = navValW(f->get("x"), W);
2829
- s.y0 = navValW(f->get("y"), H);
2830
- s.sc0 = navValW(f->get("scale"), 1);
2831
- s.op0 = navValW(f->get("opacity"), 1);
2832
- }
2833
- if (t && t->kind == modules::Json::Obj) {
2834
- s.x1 = navValW(t->get("x"), W);
2835
- s.y1 = navValW(t->get("y"), H);
2836
- s.sc1 = navValW(t->get("scale"), 1);
2837
- s.op1 = navValW(t->get("opacity"), 1);
2838
- }
2839
- return s;
2840
- }
2841
-
2842
- // easing del descriptor → control points de KeySpline (los nombres
2843
- // mapean a las mismas curvas que animEase en linux).
2844
- static void navSpline(const std::string &e, double cp[4]) {
2845
- if (e == "linear") { cp[0]=0; cp[1]=0; cp[2]=1; cp[3]=1; return; }
2846
- if (e == "ease-in") { cp[0]=.42; cp[1]=0; cp[2]=1; cp[3]=1; return; }
2847
- if (e == "ease-in-out") { cp[0]=.42; cp[1]=0; cp[2]=.58; cp[3]=1; return; }
2848
- // ADR-0165 "spring" = cubic-bezier(.34,1.56,.64,1).
2849
- if (e == "spring") { cp[0]=.34; cp[1]=1.56; cp[2]=.64; cp[3]=1; return; }
2850
- if (e == "ease") { cp[0]=.25; cp[1]=.1; cp[2]=.25; cp[3]=1; return; }
2851
- if (e.rfind("cubic-bezier(", 0) == 0) {
2852
- double p[4];
2853
- int i = 0;
2854
- const char *s = e.c_str() + 13;
2855
- char *end = nullptr;
2856
- while (i < 4 && (p[i] = strtod(s, &end), end != s)) {
2857
- s = end;
2858
- if (*s == ',' || *s == ' ')
2859
- s++;
2860
- i++;
2861
- }
2862
- if (i == 4) {
2863
- cp[0] = p[0]; cp[1] = p[1]; cp[2] = p[2]; cp[3] = p[3];
2864
- return;
2865
- }
2866
- }
2867
- // ease-out y desconocidos → cubic-bezier(0,0,.58,1).
2868
- cp[0] = 0; cp[1] = 0; cp[2] = .58; cp[3] = 1;
2869
- }
2870
-
2871
- namespace muxa_anim = winrt::Microsoft::UI::Xaml::Media::Animation;
2872
-
2873
- void WinApplicator::clearDetached() {
2874
- if (!detachedEl_)
2875
- return;
2876
- detachVisual(detachedEl_);
2877
- detachedEl_ = nullptr;
2878
- }
2879
-
2880
- void WinApplicator::navTransition(const std::string &op, JSContext *ctx,
2881
- JSValueConst jop) {
2882
- std::string kind = "system";
2883
- int dur = 250;
2884
- bool specHasDur = false;
2885
- modules::Json def;
2886
- JSValue t = jsGet(ctx, jop, "transition");
2887
- if (!JS_IsUndefined(t) && !JS_IsNull(t)) {
2888
- std::string k = jsGetStr(ctx, t, "kind");
2889
- if (!k.empty())
2890
- kind = k;
2891
- JSValue dv = jsGet(ctx, t, "duration");
2892
- if (JS_IsNumber(dv)) {
2893
- JS_ToInt32(ctx, &dur, dv);
2894
- specHasDur = true;
2895
- }
2896
- JS_FreeValue(ctx, dv);
2897
- if (kind == "custom") {
2898
- JSValue dj = jsGet(ctx, t, "def");
2899
- jsToJson(ctx, dj, def);
2900
- JS_FreeValue(ctx, dj);
2901
- }
2902
- }
2903
- JS_FreeValue(ctx, t);
2904
- if (kind == "none") {
2905
- clearDetached();
2906
- return;
2907
- }
2908
- bool hasDef = kind == "custom" && def.kind == modules::Json::Obj;
2909
- if (kind == "custom" && !hasDef)
2910
- warnOnce(unknownOps_, "transition", "custom->system");
2911
-
2912
- int shellId = -1;
2913
- for (auto &kv : nodes_)
2914
- if (kv.second.type == "shell") {
2915
- shellId = kv.first;
2916
- break;
2917
- }
2918
- muxc::Canvas surface = shellId >= 0 ? surfaceOf(shellId) : nullptr;
2919
- if (!surface) {
2920
- clearDetached();
2921
- return;
2922
- }
2923
- auto kids = surface.Children();
2924
- if (kids.Size() == 0) {
2925
- clearDetached();
2926
- return;
2927
- }
2928
- mux::UIElement incoming = kids.GetAt(kids.Size() - 1);
2929
- if (!incoming ||
2930
- winrt::get_abi(incoming) == winrt::get_abi(detachedEl_)) {
2931
- clearDetached();
2932
- return;
2933
- }
2934
- int inId = -1;
2935
- for (auto &kv : nodes_)
2936
- if (kv.second.el &&
2937
- winrt::get_abi(kv.second.el) == winrt::get_abi(incoming)) {
2938
- inId = kv.first;
2939
- break;
2940
- }
2941
- double finalX = inId >= 0 ? nodes_[inId].layX : 0;
2942
- double W = nodes_[shellId].layW > 0 ? nodes_[shellId].layW
2943
- : (vpW_ > 0 ? vpW_ : 390);
2944
-
2945
- double inFromX = finalX, inToX = finalX;
2946
- mux::UIElement outgoing{nullptr};
2947
- double outFromX = 0, outToX = 0;
2948
- bool fade = false;
2949
-
2950
- if (op == "nav-replace") {
2951
- fade = true;
2952
- dur = 180;
2953
- } else if (op == "nav-push") {
2954
- inFromX = finalX + W;
2955
- if (detachedEl_) {
2956
- outgoing = detachedEl_;
2957
- detachedEl_ = nullptr;
2958
- // Debajo de la entrante: overlay 0→-30%W parallax.
2959
- muxc::Canvas::SetLeft(outgoing, detX_);
2960
- muxc::Canvas::SetTop(outgoing, detY_);
2961
- if (auto fe = outgoing.try_as<mux::FrameworkElement>()) {
2962
- // Restore: el remove puede preceder al primer relayout —
2963
- // layW/layH quedan a -1 y Width(-1) lanza E_INVALIDARG.
2964
- if (detW_ > 0)
2965
- fe.Width(detW_);
2966
- if (detH_ > 0)
2967
- fe.Height(detH_);
2968
- }
2969
- // Re-insertar un elemento ya en la colección lanza 0x800f1000;
2970
- // FE.Parent puede ser null aunque siga en Children (árbol lógico
2971
- // ≠ visual), así que se quita por IndexOf directo.
2972
- {
2973
- uint32_t oi = 0;
2974
- if (kids.IndexOf(outgoing, oi))
2975
- kids.RemoveAt(oi);
2976
- }
2977
- kids.InsertAt(kids.Size() - 1, outgoing);
2978
- outFromX = detX_;
2979
- outToX = detX_ - 0.30 * W;
2980
- }
2981
- } else { // nav-pop: entrante -30%→0; saliente encima 0→+W.
2982
- inFromX = finalX - 0.30 * W;
2983
- if (detachedEl_) {
2984
- outgoing = detachedEl_;
2985
- detachedEl_ = nullptr;
2986
- muxc::Canvas::SetLeft(outgoing, detX_);
2987
- muxc::Canvas::SetTop(outgoing, detY_);
2988
- if (auto fe = outgoing.try_as<mux::FrameworkElement>()) {
2989
- if (detW_ > 0)
2990
- fe.Width(detW_);
2991
- if (detH_ > 0)
2992
- fe.Height(detH_);
2993
- }
2994
- {
2995
- uint32_t oi = 0;
2996
- if (kids.IndexOf(outgoing, oi))
2997
- kids.RemoveAt(oi);
2998
- }
2999
- kids.Append(outgoing);
3000
- outFromX = detX_;
3001
- outToX = detX_ + W;
3002
- }
3003
- }
3004
-
3005
- NavSideW in, out;
3006
- double inY0 = NAN, inY1 = NAN, outY0 = NAN, outY1 = NAN;
3007
- if (hasDef) {
3008
- double H = nodes_[shellId].layH > 0 ? nodes_[shellId].layH
3009
- : (vpH_ > 0 ? vpH_ : 844);
3010
- const modules::Json *dd = def.get("duration");
3011
- if (!specHasDur && dd && dd->kind == modules::Json::Num)
3012
- dur = (int)dd->num;
3013
- const modules::Json *inDef = def.get("incoming");
3014
- if (inDef && inDef->kind == modules::Json::Obj)
3015
- inFromX = inToX = finalX;
3016
- in = navSideParseW(inDef, W, H);
3017
- if (!std::isnan(in.x0))
3018
- inFromX = in.x0;
3019
- if (!std::isnan(in.x1))
3020
- inToX = in.x1;
3021
- inY0 = in.y0;
3022
- inY1 = std::isnan(in.y1) ? in.y0 : in.y1;
3023
- if (outgoing) {
3024
- const modules::Json *outDef = def.get("outgoing");
3025
- if (outDef && outDef->kind == modules::Json::Obj)
3026
- outFromX = outToX = detX_;
3027
- out = navSideParseW(outDef, W, H);
3028
- if (!std::isnan(out.x0))
3029
- outFromX = out.x0;
3030
- if (!std::isnan(out.x1))
3031
- outToX = out.x1;
3032
- outY0 = out.y0;
3033
- outY1 = std::isnan(out.y1) ? out.y0 : out.y1;
3034
- }
3035
- if (fade) {
3036
- fade = false;
3037
- incoming.Opacity(std::isnan(in.op0) ? 1 : in.op0);
3038
- }
3039
- }
3040
-
3041
- double cp[4] = {.32, .72, 0, 1}; // system cubic-bezier(.32,.72,0,1)
3042
- const modules::Json *ez = def.get("easing");
3043
- if (ez && ez->kind == modules::Json::Str)
3044
- navSpline(ez->str, cp);
3045
- if (dur <= 0)
3046
- dur = 250;
3047
-
3048
- auto mkKey = [&](double to) {
3049
- auto ks = muxa_anim::KeySpline();
3050
- ks.ControlPoint1(winrt::Windows::Foundation::Point(
3051
- (float)cp[0], (float)cp[1]));
3052
- ks.ControlPoint2(winrt::Windows::Foundation::Point(
3053
- (float)cp[2], (float)cp[3]));
3054
- auto kf = muxa_anim::SplineDoubleKeyFrame();
3055
- kf.KeySpline(ks);
3056
- kf.Value(to);
3057
- muxa_anim::KeyTime kt;
3058
- kt.TimeSpan = winrt::Windows::Foundation::TimeSpan(
3059
- std::chrono::milliseconds(dur));
3060
- kf.KeyTime(kt);
3061
- return kf;
3062
- };
3063
- // Canvas.Left/Top son "dependent animations" en WinUI: sin el flag
3064
- // el storyboard las descarta en silencio. Opacity/transforms son
3065
- // independientes (no afectan layout) — el flag no les hace daño.
3066
- auto addCh = [&](muxa_anim::Storyboard &sb, mux::DependencyObject target,
3067
- const wchar_t *path, double to) {
3068
- auto a = muxa_anim::DoubleAnimationUsingKeyFrames();
3069
- a.EnableDependentAnimation(true);
3070
- a.KeyFrames().Append(mkKey(to));
3071
- muxa_anim::Storyboard::SetTarget(a, target);
3072
- muxa_anim::Storyboard::SetTargetProperty(a, path);
3073
- sb.Children().Append(a);
3074
- };
3075
- // Escala: CompositeTransform perezoso (RenderTransformOrigin centro).
3076
- auto scaleCh = [&](muxa_anim::Storyboard &sb, mux::UIElement el,
3077
- double w, double h, double s0, double s1) {
3078
- if (std::isnan(s0) && std::isnan(s1))
3079
- return;
3080
- auto fe = el.try_as<mux::FrameworkElement>();
3081
- if (!fe)
3082
- return;
3083
- fe.RenderTransformOrigin(
3084
- winrt::Windows::Foundation::Point(0.5f, 0.5f));
3085
- auto tf = mux::Media::CompositeTransform();
3086
- double s = std::isnan(s0) ? 1.0 : s0;
3087
- tf.ScaleX(s);
3088
- tf.ScaleY(s);
3089
- fe.RenderTransform(tf);
3090
- double sv = std::isnan(s1) ? s : s1;
3091
- addCh(sb, el,
3092
- L"(UIElement.RenderTransform).(CompositeTransform.ScaleX)", sv);
3093
- addCh(sb, el,
3094
- L"(UIElement.RenderTransform).(CompositeTransform.ScaleY)", sv);
3095
- };
3096
-
3097
- // Estado inicial: posición de arranque en el Canvas (los base values
3098
- // los posee la animación — un relayout no pelea con el storyboard).
3099
- muxa_anim::Storyboard sb;
3100
- if (fade) {
3101
- incoming.Opacity(0);
3102
- addCh(sb, incoming, L"(UIElement.Opacity)", 1);
3103
- } else {
3104
- muxc::Canvas::SetLeft(incoming, inFromX);
3105
- if (!std::isnan(inY0))
3106
- muxc::Canvas::SetTop(incoming, inY0);
3107
- addCh(sb, incoming, L"(Canvas.Left)", inToX);
3108
- if (!std::isnan(inY0) || !std::isnan(inY1))
3109
- addCh(sb, incoming, L"(Canvas.Top)",
3110
- std::isnan(inY1) ? inY0 : inY1);
3111
- if (!std::isnan(in.op0) || !std::isnan(in.op1)) {
3112
- if (!std::isnan(in.op0))
3113
- incoming.Opacity(in.op0);
3114
- addCh(sb, incoming, L"(UIElement.Opacity)",
3115
- std::isnan(in.op1) ? in.op0 : in.op1);
3116
- }
3117
- scaleCh(sb, incoming, W,
3118
- nodes_[shellId].layH > 0 ? nodes_[shellId].layH : vpH_,
3119
- in.sc0, in.sc1);
3120
- }
3121
- if (outgoing) {
3122
- addCh(sb, outgoing, L"(Canvas.Left)", outToX);
3123
- if (!std::isnan(outY0) || !std::isnan(outY1)) {
3124
- if (!std::isnan(outY0))
3125
- muxc::Canvas::SetTop(outgoing, outY0);
3126
- addCh(sb, outgoing, L"(Canvas.Top)",
3127
- std::isnan(outY1) ? outY0 : outY1);
3128
- }
3129
- if (!std::isnan(out.op0) || !std::isnan(out.op1)) {
3130
- if (!std::isnan(out.op0))
3131
- outgoing.Opacity(out.op0);
3132
- addCh(sb, outgoing, L"(UIElement.Opacity)",
3133
- std::isnan(out.op1) ? out.op0 : out.op1);
3134
- }
3135
- scaleCh(sb, outgoing, W,
3136
- nodes_[shellId].layH > 0 ? nodes_[shellId].layH : vpH_,
3137
- out.sc0, out.sc1);
3138
- }
3139
-
3140
- mux::UIElement outCap = outgoing;
3141
- sb.Completed([this, outCap, surface](
3142
- winrt::Windows::Foundation::IInspectable const &,
3143
- winrt::Windows::Foundation::IInspectable const &) {
3144
- if (outCap) {
3145
- // La saliente sale de la superficie — el píxel muere aquí
3146
- // (su delete-node ya pudo haber llegado).
3147
- auto ch = surface.Children();
3148
- uint32_t idx = 0;
3149
- if (ch.IndexOf(outCap, idx))
3150
- ch.RemoveAt(idx);
3151
- }
3152
- });
3153
- sb.Begin();
3154
- }
3155
-
3156
- // ── Ciclo de vida ──────────────────────────────────────────────────
3157
-
3158
- void WinApplicator::init(const muxc::Canvas &root, const HostOptions &opts,
3159
- HostCallbacks cb) {
3160
- root_ = root;
3161
- root.AddHandler(mux::UIElement::KeyDownEvent(),
3162
- winrt::box_value(muxi::KeyEventHandler(
3163
- [this](auto const &,
3164
- muxi::KeyRoutedEventArgs const &e) {
3165
- // XAML islands: el foco de entrada queda en la
3166
- // raíz aunque el foco lógico esté en el nodo —
3167
- // la tecla burbujea desde root_. Si el foco
3168
- // lógico está en un nodo con `key`, emitimos
3169
- // por él (misma semántica que GTK/web).
3170
- if (auto xr = root_.XamlRoot()) {
3171
- auto fe = muxi::FocusManager::
3172
- GetFocusedElement(xr)
3173
- .try_as<mux::UIElement>();
3174
- // Si el origen es fe o un descendiente, el
3175
- // bubble ya pasó por su KeyDown → no duplicar.
3176
- auto os = e.OriginalSource()
3177
- .try_as<mux::UIElement>();
3178
- bool covered = false;
3179
- for (auto anc = os; anc;) {
3180
- if (anc == fe) {
3181
- covered = true;
3182
- break;
3183
- }
3184
- anc = muxm::VisualTreeHelper::GetParent(anc)
3185
- .try_as<mux::UIElement>();
3186
- }
3187
- if (fe && !covered) {
3188
- for (auto &kv : nodes_) {
3189
- if (kv.second.el == fe &&
3190
- kv.second.events.count("key")) {
3191
- emitKeyFor(kv.first, e.Key());
3192
- break;
3193
- }
3194
- }
3195
- }
3196
- }
3197
- })),
3198
- true);
3199
- cb_ = std::move(cb);
3200
- vpW_ = opts.width;
3201
- vpH_ = opts.height;
3202
- yoga::init();
3203
- yoga::setViewport((float)vpW_, (float)vpH_, rtl_);
3204
- yoga::setMeasureHook([this](int id, float w, int wMode, float h,
3205
- int hMode, float &ow, float &oh) {
3206
- measureLeaf(id, w, wMode, h, hMode, ow, oh);
3207
- });
3208
- }
3209
-
3210
- void WinApplicator::setViewport(int w, int h) {
3211
- vpW_ = w;
3212
- vpH_ = h;
3213
- yoga::setViewport((float)w, (float)h, rtl_);
3214
- relayout();
3215
- if (!densityReported_) {
3216
- densityReported_ = true;
3217
- cb_.callHandlerStr("onDensity", "1");
3218
- }
3219
- if (h > 0) {
3220
- char buf[32];
3221
- snprintf(buf, sizeof(buf), "%d", h);
3222
- cb_.callHandlerStr("onViewportResize", buf);
3223
- }
3224
- }
3225
-
3226
- void WinApplicator::setRtl(bool rtl) {
3227
- rtl_ = rtl;
3228
- yoga::setViewport((float)vpW_, (float)vpH_, rtl);
3229
- }
3230
-
3231
- void WinApplicator::shutdown() {
3232
- std::vector<int> ids;
3233
- ids.reserve(nodes_.size());
3234
- for (auto &kv : nodes_)
3235
- ids.push_back(kv.first);
3236
- for (int id : ids)
3237
- deleteNode(id);
3238
- nodes_.clear();
3239
- yoga::shutdown();
3240
- }
3241
-
3242
- } // namespace elur