@elurjs/android 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +10 -2
  2. package/index.mjs +11 -0
  3. package/package.json +29 -4
  4. package/template/.gitkeep +0 -0
  5. package/template/app/build.gradle.kts +192 -0
  6. package/template/app/proguard-rules-elur.pro +12 -0
  7. package/template/app/proguard-rules.pro +3 -0
  8. package/template/app/src/main/AndroidManifest.xml +81 -0
  9. package/template/app/src/main/assets/oss-notices.txt +153 -0
  10. package/template/app/src/main/assets/tck_pixel.png +0 -0
  11. package/template/app/src/main/cpp/CMakeLists.txt +117 -0
  12. package/template/app/src/main/cpp/dlEncoder.h +117 -0
  13. package/template/app/src/main/cpp/dlEncoderJsi.cpp +315 -0
  14. package/template/app/src/main/cpp/dlEncoderQjs.cpp +394 -0
  15. package/template/app/src/main/cpp/dlOps.inc +145 -0
  16. package/template/app/src/main/cpp/elurBridge.cpp +1350 -0
  17. package/template/app/src/main/cpp/elurBridgeHermes.cpp +1294 -0
  18. package/template/app/src/main/cpp/elurSkia.cpp +287 -0
  19. package/template/app/src/main/cpp/elurSkiaTree.cpp +448 -0
  20. package/template/app/src/main/cpp/elurUiWorklet.cpp +1233 -0
  21. package/template/app/src/main/cpp/elurYoga.cpp +1060 -0
  22. package/template/app/src/main/cpp/elurYoga.h +82 -0
  23. package/template/app/src/main/cpp/hermes-libs/LICENSE +21 -0
  24. package/template/app/src/main/cpp/hermes-libs/arm64-v8a/libhermesvm.so +0 -0
  25. package/template/app/src/main/cpp/hermes-libs/include/hermes/AsyncDebuggerAPI.h +276 -0
  26. package/template/app/src/main/cpp/hermes-libs/include/hermes/CompileJS.h +97 -0
  27. package/template/app/src/main/cpp/hermes-libs/include/hermes/DebuggerAPI.h +502 -0
  28. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CrashManager.h +107 -0
  29. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CtorConfig.h +145 -0
  30. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/DebuggerTypes.h +193 -0
  31. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCConfig.h +211 -0
  32. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCTripwireContext.h +40 -0
  33. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/HermesExport.h +14 -0
  34. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/JSOutOfMemoryError.h +27 -0
  35. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/RuntimeConfig.h +141 -0
  36. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/SamplingProfiler.h +270 -0
  37. package/template/app/src/main/cpp/hermes-libs/include/hermes/RuntimeTaskRunner.h +64 -0
  38. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTrace.h +1566 -0
  39. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTraceParser.h +37 -0
  40. package/template/app/src/main/cpp/hermes-libs/include/hermes/ThreadSafetyAnalysis.h +75 -0
  41. package/template/app/src/main/cpp/hermes-libs/include/hermes/TimerStats.h +23 -0
  42. package/template/app/src/main/cpp/hermes-libs/include/hermes/TraceInterpreter.h +334 -0
  43. package/template/app/src/main/cpp/hermes-libs/include/hermes/TracingRuntime.h +328 -0
  44. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPAgent.h +131 -0
  45. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPDebugAPI.h +73 -0
  46. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CallbackOStream.h +89 -0
  47. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ConsoleMessage.h +135 -0
  48. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainAgent.h +280 -0
  49. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainCoordinator.h +137 -0
  50. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainAgent.h +107 -0
  51. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainState.h +140 -0
  52. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/HeapProfilerDomainAgent.h +71 -0
  53. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/JSONValueInterfaces.h +40 -0
  54. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageConverters.h +82 -0
  55. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageInterfaces.h +72 -0
  56. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypes.h +1279 -0
  57. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypesInlines.h +313 -0
  58. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ProfilerDomainAgent.h +38 -0
  59. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectConverters.h +77 -0
  60. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectsTable.h +127 -0
  61. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RuntimeDomainAgent.h +138 -0
  62. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Dummy.h +24 -0
  63. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Extensions.h +20 -0
  64. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/ExtensionsBytecode.h +23 -0
  65. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Intrinsics.h +44 -0
  66. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/JSIUtils.h +123 -0
  67. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/TextEncoder.h +29 -0
  68. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribDummy.h +24 -0
  69. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribExtensions.h +23 -0
  70. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoder.h +30 -0
  71. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoderUtils.h +113 -0
  72. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes.h +242 -0
  73. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes_tracing.h +52 -0
  74. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIHelpers.h +295 -0
  75. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIRuntimeWrapper.h +25 -0
  76. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_abi.h +642 -0
  77. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_vtable.h +29 -0
  78. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/HermesSandboxRuntime.h +41 -0
  79. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_compiled.h +12 -0
  80. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled-impl.h +8516 -0
  81. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled.h +137 -0
  82. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled-impl.h +3945 -0
  83. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled.h +119 -0
  84. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-fb.h +124 -0
  85. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-impl.h +66 -0
  86. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt.h +456 -0
  87. package/template/app/src/main/cpp/hermes-libs/include/jsi/JSIDynamic.h +26 -0
  88. package/template/app/src/main/cpp/hermes-libs/include/jsi/decorator.h +1157 -0
  89. package/template/app/src/main/cpp/hermes-libs/include/jsi/hermes-interfaces.h +242 -0
  90. package/template/app/src/main/cpp/hermes-libs/include/jsi/instrumentation.h +132 -0
  91. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi-inl.h +434 -0
  92. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi.h +2266 -0
  93. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsilib.h +59 -0
  94. package/template/app/src/main/cpp/hermes-libs/include/jsi/threadsafe.h +79 -0
  95. package/template/app/src/main/cpp/hermes-libs/jsi-impl/jsi.cpp +1111 -0
  96. package/template/app/src/main/cpp/hermes-libs/x86_64/libhermesvm.so +0 -0
  97. package/template/app/src/main/java/com/elur/universal/BinaryCodec.kt +121 -0
  98. package/template/app/src/main/java/com/elur/universal/DlDecoder.kt +260 -0
  99. package/template/app/src/main/java/com/elur/universal/DlOpsDecode.kt +158 -0
  100. package/template/app/src/main/java/com/elur/universal/ElurBoxDrawable.kt +161 -0
  101. package/template/app/src/main/java/com/elur/universal/ElurBridge.kt +238 -0
  102. package/template/app/src/main/java/com/elur/universal/ElurBridgeHermes.kt +223 -0
  103. package/template/app/src/main/java/com/elur/universal/ElurCanvasView.kt +202 -0
  104. package/template/app/src/main/java/com/elur/universal/ElurCryptoModule.kt +206 -0
  105. package/template/app/src/main/java/com/elur/universal/ElurCustomLayout.kt +185 -0
  106. package/template/app/src/main/java/com/elur/universal/ElurEditText.kt +17 -0
  107. package/template/app/src/main/java/com/elur/universal/ElurFontRegistry.kt +190 -0
  108. package/template/app/src/main/java/com/elur/universal/ElurHttpModule.kt +306 -0
  109. package/template/app/src/main/java/com/elur/universal/ElurImageService.kt +348 -0
  110. package/template/app/src/main/java/com/elur/universal/ElurLicensesActivity.kt +84 -0
  111. package/template/app/src/main/java/com/elur/universal/ElurListView.kt +954 -0
  112. package/template/app/src/main/java/com/elur/universal/ElurManifest.kt +117 -0
  113. package/template/app/src/main/java/com/elur/universal/ElurMetrics.kt +325 -0
  114. package/template/app/src/main/java/com/elur/universal/ElurModuleRegistrar.kt +14 -0
  115. package/template/app/src/main/java/com/elur/universal/ElurPermissionGate.kt +36 -0
  116. package/template/app/src/main/java/com/elur/universal/ElurRenderer.kt +6164 -0
  117. package/template/app/src/main/java/com/elur/universal/ElurRowYoga.kt +130 -0
  118. package/template/app/src/main/java/com/elur/universal/ElurScrollView.kt +240 -0
  119. package/template/app/src/main/java/com/elur/universal/ElurShellView.kt +117 -0
  120. package/template/app/src/main/java/com/elur/universal/ElurSkiaCanvasView.kt +162 -0
  121. package/template/app/src/main/java/com/elur/universal/ElurSkiaTreeRenderer.kt +968 -0
  122. package/template/app/src/main/java/com/elur/universal/ElurStateModule.kt +69 -0
  123. package/template/app/src/main/java/com/elur/universal/ElurSwipeDriver.kt +34 -0
  124. package/template/app/src/main/java/com/elur/universal/ElurTckModule.kt +99 -0
  125. package/template/app/src/main/java/com/elur/universal/ElurTextMeasure.kt +16 -0
  126. package/template/app/src/main/java/com/elur/universal/ElurTrace.kt +24 -0
  127. package/template/app/src/main/java/com/elur/universal/ElurUiModule.kt +48 -0
  128. package/template/app/src/main/java/com/elur/universal/ElurUiWorklet.kt +305 -0
  129. package/template/app/src/main/java/com/elur/universal/JsBridge.kt +67 -0
  130. package/template/app/src/main/java/com/elur/universal/JsThread.kt +189 -0
  131. package/template/app/src/main/java/com/elur/universal/MainActivity.kt +844 -0
  132. package/template/app/src/main/java/com/elur/universal/ModuleRegistry.kt +701 -0
  133. package/template/app/src/main/java/com/elur/universal/YogaRowScope.kt +97 -0
  134. package/template/app/src/main/res/values/ids.xml +10 -0
  135. package/template/app/src/main/res/values/strings.xml +8 -0
  136. package/template/app/src/main/res/values-es/strings.xml +5 -0
  137. package/template/app/src/main/res/xml/network_security_config.xml +10 -0
  138. package/template/build.gradle.kts +5 -0
  139. package/template/gradle/libs.versions.toml +12 -0
  140. package/template/gradle/wrapper/gradle-wrapper.jar +0 -0
  141. package/template/gradle/wrapper/gradle-wrapper.properties +8 -0
  142. package/template/gradle.properties +23 -0
  143. package/template/gradlew +251 -0
  144. package/template/gradlew.bat +94 -0
  145. package/template/settings.gradle.kts +32 -0
@@ -0,0 +1,130 @@
1
+ package com.elur.universal
2
+
3
+ import android.view.View
4
+ import android.widget.TextView
5
+ import java.util.concurrent.ConcurrentHashMap
6
+
7
+ /**
8
+ * ADR-0121: árboles Yoga por view-holder de [ElurListView] — sustituye al mini-flex
9
+ * (LinearLayout/weight/gravity aproximado) por layout real de Yoga sobre la misma config del árbol
10
+ * principal (unidades lógicas + PointScaleFactor).
11
+ *
12
+ * JNI: los símbolos `native*` se exportan desde `elurYoga.cpp`, que se compila dentro de
13
+ * `elur-bridge` y `elur-bridge-hermes`. Este objeto no carga librería propia: la resolución lazy de
14
+ * JNI encuentra los nombres en la lib del engine activo (cargada antes de que exista lista alguna).
15
+ * Usar la otra lib sería un fallo real — su arena global distinta tendría `g_config`/`g_rowYoga`
16
+ * sin inicializar.
17
+ */
18
+ object ElurRowYoga {
19
+
20
+ private external fun nativeTreeCreate(): Int
21
+ private external fun nativeRowNode(tree: Int, key: Int, parentKey: Int, type: String)
22
+ private external fun nativeRowStyle(
23
+ tree: Int,
24
+ key: Int,
25
+ name: String,
26
+ isNum: Boolean,
27
+ num: Double,
28
+ str: String?
29
+ )
30
+ private external fun nativeRowStyleReset(tree: Int, key: Int, name: String)
31
+ private external fun nativeRowLayout(tree: Int, wPx: Float, forceWidth: Boolean): IntArray
32
+ private external fun nativeRowFree(tree: Int)
33
+
34
+ /**
35
+ * Estado Kotlin de un árbol nativo: [rects] se rellena en cada [layout] (px, relativo al padre
36
+ * del nodo) y [views] mapea la pseudo-key del nodo a la View reciclada que mide.
37
+ */
38
+ class RowTree(val treeId: Int) {
39
+ val rects = HashMap<Int, IntArray>()
40
+ val views = HashMap<Int, View>()
41
+ var alive = true
42
+ }
43
+
44
+ /** treeId → estado — las scopes consultan rects y el callback de medida las views. */
45
+ private val trees = ConcurrentHashMap<Int, RowTree>()
46
+
47
+ fun treeCreate(): RowTree {
48
+ val t = RowTree(nativeTreeCreate())
49
+ trees[t.treeId] = t
50
+ return t
51
+ }
52
+
53
+ fun treeFree(t: RowTree) {
54
+ if (!t.alive) return
55
+ t.alive = false
56
+ trees.remove(t.treeId)
57
+ nativeRowFree(t.treeId)
58
+ }
59
+
60
+ fun node(t: RowTree, key: Int, parentKey: Int, type: String) =
61
+ nativeRowNode(t.treeId, key, parentKey, type)
62
+
63
+ /**
64
+ * Estilo desde la plantilla o un bind: `Number` → num, `null` → reset a Undefined/default,
65
+ * cualquier otro → string enum/porcentaje.
66
+ */
67
+ fun style(t: RowTree, key: Int, name: String, value: Any?) {
68
+ when (value) {
69
+ null, org.json.JSONObject.NULL -> nativeRowStyleReset(t.treeId, key, name)
70
+ is Number -> nativeRowStyle(t.treeId, key, name, true, value.toDouble(), null)
71
+ else -> nativeRowStyle(t.treeId, key, name, false, 0.0, value.toString())
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Calcula el layout del árbol con ancho `wPx` y llena [RowTree.rects] con [key]=[l,t,w,h] px
77
+ * (convertidos en C++ con el mismo round que applyLayout). `wPx < 0` = ancho libre (spec
78
+ * UNSPECIFIED — fila horizontal WRAP_CONTENT); `forceWidth` clava el ancho raíz al spec
79
+ * (EXACTLY — fila MATCH_PARENT de lista vertical). Con AT_MOST el ancho del template manda
80
+ * y la scope clampea al bound. Devuelve false si el árbol murió (lista reciclada tras un
81
+ * template swap — la scope se re-infla antes de volver a medir).
82
+ */
83
+ fun layout(t: RowTree, wPx: Float, forceWidth: Boolean): Boolean {
84
+ if (!t.alive) return false
85
+ val flat = nativeRowLayout(t.treeId, wPx, forceWidth) ?: return false
86
+ t.rects.clear()
87
+ var i = 0
88
+ while (i + 4 < flat.size) {
89
+ t.rects[flat[i]] = intArrayOf(flat[i + 1], flat[i + 2], flat[i + 3], flat[i + 4])
90
+ i += 5
91
+ }
92
+ return true
93
+ }
94
+
95
+ /**
96
+ * Callback JNI desde `measureLeaf` (mismo thread que CalculateLayout — el de onMeasure): mide
97
+ * la View real del nodo con los constraints que Yoga pasa ya convertidos a px y devuelve
98
+ * `w<<32|h` como measureNode.
99
+ */
100
+ @Suppress("unused")
101
+ fun measureRowNode(treeId: Int, key: Int, w: Float, wMode: Int, h: Float, hMode: Int): Long {
102
+ val v = trees[treeId]?.views?.get(key) ?: return 0L
103
+ v.measure(spec(w, wMode), spec(h, hMode))
104
+ val mw = v.measuredWidth.coerceAtLeast(0)
105
+ var mh = v.measuredHeight.coerceAtLeast(0)
106
+ // ADR-0140: con line-height declarado la caja es lineCount×lh×textSize —
107
+ // el widget reporta el extent natural de la última línea (~±0.8dp corto),
108
+ // igual que StaticLayout en la hoja normal.
109
+ if (v is TextView) {
110
+ val lh = v.getTag(R.id.elur_line_height) as? Float
111
+ if (lh != null && v.lineCount > 0) {
112
+ mh =
113
+ Math.round(v.lineCount * lh * v.textSize) +
114
+ v.extendedPaddingTop +
115
+ v.extendedPaddingBottom
116
+ }
117
+ }
118
+ return (mw.toLong() shl 32) or (mh.toLong() and 0xffffffffL)
119
+ }
120
+
121
+ /** YGMeasureMode → MeasureSpec: 0=Undefined→UNSPECIFIED, 1=Exactly, 2=AtMost. */
122
+ private fun spec(v: Float, mode: Int): Int {
123
+ val size = if (v.isFinite() && v > 0) Math.round(v) else 0
124
+ return when (mode) {
125
+ 1 -> View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.EXACTLY)
126
+ 2 -> View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.AT_MOST)
127
+ else -> View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,240 @@
1
+ package com.elur.universal
2
+
3
+ import android.content.Context
4
+ import android.view.Gravity
5
+ import android.view.MotionEvent
6
+ import android.view.View
7
+ import android.widget.FrameLayout
8
+ import android.widget.HorizontalScrollView
9
+ import android.widget.OverScroller
10
+ import android.widget.ProgressBar
11
+ import android.widget.ScrollView
12
+ import kotlin.math.roundToInt
13
+
14
+ /**
15
+ * ScrollView vertical que conoce el destino del fling (ADR-0033) y soporta
16
+ * paging, inverted y pull-to-refresh (P1.1).
17
+ */
18
+ class ElurScrollView(context: Context) : ScrollView(context) {
19
+
20
+ var flingTargetY: Int = -1
21
+ private set
22
+
23
+ var onOwnScroll: (() -> Unit)? = null
24
+ var onRefreshTrigger: (() -> Unit)? = null
25
+ var pagingEnabled: Boolean = false
26
+ var invertedEnabled: Boolean = false
27
+ var isRefreshing: Boolean = false
28
+ set(value) {
29
+ field = value
30
+ refreshSpinner?.visibility = if (value) View.VISIBLE else View.GONE
31
+ }
32
+
33
+ private var refreshSpinner: ProgressBar? = null
34
+ private var pullStartY = -1f
35
+ private var pullArmed = false
36
+
37
+ val stickyViews = java.util.WeakHashMap<View, Float>()
38
+
39
+ fun ensureRefreshSpinner() {
40
+ if (refreshSpinner != null) return
41
+ val parentGroup = parent as? FrameLayout ?: return
42
+ val size = (28 * resources.displayMetrics.density).toInt()
43
+ val pb = ProgressBar(context).apply {
44
+ isIndeterminate = true
45
+ visibility = if (isRefreshing) View.VISIBLE else View.GONE
46
+ }
47
+ val lp = FrameLayout.LayoutParams(size, size).apply {
48
+ gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
49
+ topMargin = (8 * resources.displayMetrics.density).toInt()
50
+ }
51
+ parentGroup.addView(pb, lp)
52
+ refreshSpinner = pb
53
+ }
54
+
55
+ override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
56
+ super.onScrollChanged(l, t, oldl, oldt)
57
+ if (t != oldt || l != oldl) {
58
+ onOwnScroll?.invoke()
59
+ applySticky()
60
+ }
61
+ }
62
+
63
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
64
+ val wasZero = scrollY == 0
65
+ super.onLayout(changed, l, t, r, b)
66
+ if (invertedEnabled && wasZero) {
67
+ val maxY = maxOf(0, computeVerticalScrollRange() - height)
68
+ if (maxY > 0) scrollTo(scrollX, maxY)
69
+ }
70
+ if (stickyViews.isNotEmpty()) applySticky()
71
+ }
72
+
73
+ internal fun applySticky() {
74
+ if (stickyViews.isEmpty()) return
75
+ for ((v, thrPx) in stickyViews) {
76
+ var top = 0
77
+ var n: View? = v
78
+ while (n != null && n !== this) {
79
+ top += n.top
80
+ n = n.parent as? View
81
+ }
82
+ if (n !== this) continue
83
+ val p = v.parent as? View ?: continue
84
+ val parentH = if (p === this) computeVerticalScrollRange() else p.height
85
+ val maxOff = (parentH - v.top - v.height).coerceAtLeast(0)
86
+ val off = (scrollY + thrPx.toInt() - top).coerceIn(0, maxOff)
87
+ if (v.translationY != off.toFloat()) v.translationY = off.toFloat()
88
+ val z = if (off > 0) 1f else 0f
89
+ if (v.translationZ != z) v.translationZ = z
90
+ }
91
+ }
92
+
93
+ private val probeScroller = OverScroller(context)
94
+
95
+ override fun fling(velocityY: Int) {
96
+ if (pagingEnabled && height > 0) {
97
+ val page = height
98
+ val curPage = scrollY.toFloat() / page
99
+ val targetPage = when {
100
+ velocityY > 300 -> kotlin.math.ceil(curPage).toInt()
101
+ velocityY < -300 -> kotlin.math.floor(curPage).toInt()
102
+ else -> curPage.roundToInt()
103
+ }
104
+ val maxY = maxOf(0, computeVerticalScrollRange() - height)
105
+ val targetY = (targetPage * page).coerceIn(0, maxY)
106
+ flingTargetY = targetY
107
+ smoothScrollTo(scrollX, targetY)
108
+ return
109
+ }
110
+ super.fling(velocityY)
111
+ val maxY = maxOf(0, computeVerticalScrollRange() - height)
112
+ probeScroller.fling(0, scrollY, 0, velocityY, 0, 0, 0, maxY, 0, height / 2)
113
+ flingTargetY = probeScroller.finalY
114
+ }
115
+
116
+ override fun onTouchEvent(ev: MotionEvent): Boolean {
117
+ when (ev.actionMasked) {
118
+ MotionEvent.ACTION_DOWN -> {
119
+ flingTargetY = -1
120
+ if (onRefreshTrigger != null && !canScrollVertically(-1)) {
121
+ pullStartY = ev.y
122
+ pullArmed = false
123
+ } else {
124
+ pullStartY = -1f
125
+ }
126
+ }
127
+ MotionEvent.ACTION_MOVE -> {
128
+ if (pullStartY >= 0f) {
129
+ if (canScrollVertically(-1)) {
130
+ pullStartY = -1f
131
+ pullArmed = false
132
+ } else {
133
+ val dy = ev.y - pullStartY
134
+ pullArmed = dy >= 56f * resources.displayMetrics.density
135
+ }
136
+ }
137
+ }
138
+ MotionEvent.ACTION_UP -> {
139
+ if (pullArmed) {
140
+ pullArmed = false
141
+ pullStartY = -1f
142
+ onRefreshTrigger?.invoke()
143
+ }
144
+ val handled = super.onTouchEvent(ev)
145
+ if (pagingEnabled && flingTargetY < 0 && height > 0) {
146
+ val maxY = maxOf(0, computeVerticalScrollRange() - height)
147
+ val snapped = ((scrollY.toFloat() / height).roundToInt() * height).coerceIn(0, maxY)
148
+ smoothScrollTo(scrollX, snapped)
149
+ }
150
+ return handled
151
+ }
152
+ MotionEvent.ACTION_CANCEL -> {
153
+ pullStartY = -1f
154
+ pullArmed = false
155
+ }
156
+ }
157
+ return super.onTouchEvent(ev)
158
+ }
159
+
160
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
161
+ val child = if (childCount > 0) getChildAt(0) else null
162
+ if (child?.tag === NATIVE_LIST_CHILD) {
163
+ child.measure(
164
+ widthMeasureSpec,
165
+ MeasureSpec.makeMeasureSpec(
166
+ MeasureSpec.getSize(heightMeasureSpec),
167
+ MeasureSpec.EXACTLY,
168
+ ),
169
+ )
170
+ setMeasuredDimension(
171
+ MeasureSpec.getSize(widthMeasureSpec),
172
+ MeasureSpec.getSize(heightMeasureSpec),
173
+ )
174
+ return
175
+ }
176
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
177
+ }
178
+
179
+ fun contentHeightPx(): Int = computeVerticalScrollRange()
180
+ fun contentWidthPx(): Int = computeHorizontalScrollRange()
181
+
182
+ companion object {
183
+ const val NATIVE_LIST_CHILD = "elur:native-list-child"
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Contrapartida horizontal de [ElurScrollView] cuando `horizontal=true`.
189
+ */
190
+ class ElurHorizontalScrollView(context: Context) : HorizontalScrollView(context) {
191
+
192
+ var onOwnScroll: (() -> Unit)? = null
193
+ var pagingEnabled: Boolean = false
194
+ var invertedEnabled: Boolean = false
195
+
196
+ override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
197
+ super.onScrollChanged(l, t, oldl, oldt)
198
+ if (l != oldl || t != oldt) {
199
+ onOwnScroll?.invoke()
200
+ }
201
+ }
202
+
203
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
204
+ val wasZero = scrollX == 0
205
+ super.onLayout(changed, l, t, r, b)
206
+ if (invertedEnabled && wasZero) {
207
+ val maxX = maxOf(0, computeHorizontalScrollRange() - width)
208
+ if (maxX > 0) scrollTo(maxX, scrollY)
209
+ }
210
+ }
211
+
212
+ override fun fling(velocityX: Int) {
213
+ if (pagingEnabled && width > 0) {
214
+ val page = width
215
+ val curPage = scrollX.toFloat() / page
216
+ val targetPage = when {
217
+ velocityX > 300 -> kotlin.math.ceil(curPage).toInt()
218
+ velocityX < -300 -> kotlin.math.floor(curPage).toInt()
219
+ else -> curPage.roundToInt()
220
+ }
221
+ val maxX = maxOf(0, computeHorizontalScrollRange() - width)
222
+ smoothScrollTo((targetPage * page).coerceIn(0, maxX), scrollY)
223
+ return
224
+ }
225
+ super.fling(velocityX)
226
+ }
227
+
228
+ override fun onTouchEvent(ev: MotionEvent): Boolean {
229
+ val handled = super.onTouchEvent(ev)
230
+ if (ev.actionMasked == MotionEvent.ACTION_UP && pagingEnabled && width > 0) {
231
+ val maxX = maxOf(0, computeHorizontalScrollRange() - width)
232
+ val snapped = ((scrollX.toFloat() / width).roundToInt() * width).coerceIn(0, maxX)
233
+ smoothScrollTo(snapped, scrollY)
234
+ }
235
+ return handled
236
+ }
237
+
238
+ fun contentHeightPx(): Int = computeVerticalScrollRange()
239
+ fun contentWidthPx(): Int = computeHorizontalScrollRange()
240
+ }
@@ -0,0 +1,117 @@
1
+ package com.elur.universal
2
+
3
+ // Swipe-back interactivo (ADR-0013): recognizer de edge-drag sobre el
4
+ // shell. DOWN en la zona de borde (24dp) + drag horizontal dominante →
5
+ // intercepta y conduce translationX de top/prev via ElurRenderer — sin
6
+ // round-trip JS por move; JS solo monta el preview (popPreview) y
7
+ // commitea/cancela al soltar. Espejo del recognizer web
8
+ // (backends/web/index.ts attachSwipeBack): mismos umbrales (≥33% o
9
+ // flick ≥0.3px/ms) y mismo parallax (top 0→w, prev −30%→0).
10
+ // Nota: en API 29+ con navegación por gestos el borde lo posee el
11
+ // sistema (predictive back → __elur_back). El recognizer cubre API<29
12
+ // y nav por botones; reclamar el borde vía setSystemGestureExclusionRects
13
+ // quedó descartado: la cuota del sistema es 200dp verticales por app →
14
+ // exclusión parcial (solo franja inferior) = UX inconsistente.
15
+
16
+ import android.content.Context
17
+ import android.view.MotionEvent
18
+ import android.view.VelocityTracker
19
+ import android.view.ViewConfiguration
20
+ import android.widget.FrameLayout
21
+ import kotlin.math.abs
22
+
23
+ class ElurShellView(context: Context) : FrameLayout(context) {
24
+
25
+ /**
26
+ * El renderer conduce las views; MainActivity lo inyecta — duck-typed sobre ElurSwipeDriver
27
+ * (views o skia-tree).
28
+ */
29
+ var swipeDriver: ElurSwipeDriver? = null
30
+
31
+ private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
32
+ private val edgeSize = 24 * resources.displayMetrics.density
33
+ private var startX = 0f
34
+ private var startY = 0f
35
+ private var edgeCandidate = false
36
+ private var dragging = false
37
+ private var tracker: VelocityTracker? = null
38
+
39
+ override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
40
+ when (ev.actionMasked) {
41
+ MotionEvent.ACTION_DOWN -> {
42
+ startX = ev.x
43
+ startY = ev.y
44
+ edgeCandidate = ev.x <= edgeSize
45
+ dragging = false
46
+ if (edgeCandidate) {
47
+ tracker?.recycle()
48
+ tracker = VelocityTracker.obtain()
49
+ tracker?.addMovement(ev)
50
+ }
51
+ }
52
+ MotionEvent.ACTION_MOVE -> {
53
+ if (edgeCandidate && !dragging) {
54
+ tracker?.addMovement(ev)
55
+ val dx = ev.x - startX
56
+ val dy = ev.y - startY
57
+ if (dx > touchSlop && dx > abs(dy)) {
58
+ dragging = true
59
+ swipeDriver?.onSwipeBegin()
60
+ return true
61
+ }
62
+ }
63
+ }
64
+ MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
65
+ edgeCandidate = false
66
+ dragging = false
67
+ tracker?.recycle()
68
+ tracker = null
69
+ }
70
+ }
71
+ return super.onInterceptTouchEvent(ev)
72
+ }
73
+
74
+ override fun onTouchEvent(ev: MotionEvent): Boolean {
75
+ // Si ningún hijo consumió el DOWN (zona vacía/no touchable), el
76
+ // stream MOVE/UP viene directo aquí sin pasar por onInterceptTouchEvent
77
+ // (mFirstTouchTarget == null). Hay que devolver true en el DOWN para
78
+ // que el stream continúe y detectar el slop en este path también.
79
+ if (edgeCandidate && ev.actionMasked == MotionEvent.ACTION_DOWN) return true
80
+ if (edgeCandidate && !dragging && ev.actionMasked == MotionEvent.ACTION_MOVE) {
81
+ tracker?.addMovement(ev)
82
+ val dx = ev.x - startX
83
+ val dy = ev.y - startY
84
+ if (dx > touchSlop && dx > abs(dy)) {
85
+ dragging = true
86
+ swipeDriver?.onSwipeBegin()
87
+ return true
88
+ }
89
+ }
90
+ if (!dragging) return super.onTouchEvent(ev)
91
+ when (ev.actionMasked) {
92
+ MotionEvent.ACTION_MOVE -> {
93
+ tracker?.addMovement(ev)
94
+ swipeDriver?.onSwipeMove(ev.x - startX)
95
+ }
96
+ MotionEvent.ACTION_UP -> {
97
+ tracker?.addMovement(ev)
98
+ tracker?.computeCurrentVelocity(1000) // px/s
99
+ val vx = tracker?.xVelocity ?: 0f
100
+ swipeDriver?.onSwipeEnd(ev.x - startX, vx, false)
101
+ reset()
102
+ }
103
+ MotionEvent.ACTION_CANCEL -> {
104
+ swipeDriver?.onSwipeEnd(ev.x - startX, 0f, true)
105
+ reset()
106
+ }
107
+ }
108
+ return true
109
+ }
110
+
111
+ private fun reset() {
112
+ dragging = false
113
+ edgeCandidate = false
114
+ tracker?.recycle()
115
+ tracker = null
116
+ }
117
+ }
@@ -0,0 +1,162 @@
1
+ package com.elur.universal
2
+
3
+ import android.content.Context
4
+ import android.graphics.Bitmap
5
+ import android.graphics.Canvas
6
+ import android.graphics.Color
7
+ import android.util.Log
8
+ import android.view.View
9
+ import org.json.JSONArray
10
+ import org.json.JSONObject
11
+
12
+ /**
13
+ * Superficie Skia (raster CPU) para `canvas` con `renderPolicy:"custom"` (ADR-0123, §5.6).
14
+ * El draw-list ADR-0020 se aplana a pools ([cmds]/[ints]/[floats]/[strs]) y libskia lo
15
+ * replaya sobre un Bitmap del tamaño exacto de la View — JNI único por repintado.
16
+ *
17
+ * `isAvailable` = cap `skia`: false si libelur-skia.so no se linkeó al build
18
+ * (prebuilt ausente) — el host degrada a Platform Views con warn, nunca crash.
19
+ */
20
+ class ElurSkiaCanvasView(context: Context) : View(context) {
21
+
22
+ companion object {
23
+ private const val TAG = "ElurSkia"
24
+ val isAvailable: Boolean by lazy {
25
+ try {
26
+ System.loadLibrary("elur-skia")
27
+ true
28
+ } catch (e: UnsatisfiedLinkError) {
29
+ Log.w(TAG, "libelur-skia ausente — canvas 'custom' degrada a views")
30
+ false
31
+ }
32
+ }
33
+
34
+ @JvmStatic
35
+ external fun nativeDraw(
36
+ bitmap: Bitmap,
37
+ cmds: IntArray,
38
+ floats: FloatArray,
39
+ ints: IntArray,
40
+ strs: Array<String?>,
41
+ density: Float
42
+ ): Int
43
+ }
44
+
45
+ private var bitmap: Bitmap? = null
46
+ private var encoded: Flattened? = null
47
+ private var dirty = true
48
+
49
+ fun setCommands(cmds: JSONArray) {
50
+ encoded = flatten(cmds)
51
+ dirty = true
52
+ invalidate()
53
+ }
54
+
55
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
56
+ if (w > 0 && h > 0) {
57
+ bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
58
+ dirty = true
59
+ }
60
+ }
61
+
62
+ override fun onDraw(canvas: Canvas) {
63
+ val bm = bitmap ?: return
64
+ val enc = encoded
65
+ if (dirty && enc != null) {
66
+ val rc =
67
+ nativeDraw(
68
+ bm, enc.cmds, enc.floats, enc.ints, enc.strs,
69
+ resources.displayMetrics.density)
70
+ if (rc != 0) Log.w(TAG, "nativeDraw rc=$rc")
71
+ dirty = false
72
+ }
73
+ canvas.drawBitmap(bm, 0f, 0f, null)
74
+ }
75
+
76
+ private class Flattened(
77
+ val cmds: IntArray,
78
+ val floats: FloatArray,
79
+ val ints: IntArray,
80
+ val strs: Array<String?>
81
+ )
82
+
83
+ private fun flatten(list: JSONArray): Flattened {
84
+ val cmds = ArrayList<Int>(list.length() * 4)
85
+ val ints = ArrayList<Int>()
86
+ val floats = ArrayList<Float>()
87
+ val strs = ArrayList<String?>()
88
+ fun color(obj: JSONObject, key: String, hasFlag: Boolean): Int {
89
+ val has = obj.has(key)
90
+ if (hasFlag) ints.add(if (has) 1 else 0)
91
+ ints.add(if (has) parseElurColor(obj.optString(key), Color.BLACK) else 0)
92
+ return 0
93
+ }
94
+ for (i in 0 until list.length()) {
95
+ val c = list.optJSONObject(i) ?: continue
96
+ when (c.optString("op")) {
97
+ "clear" -> {
98
+ cmds.add(0); cmds.add(2); cmds.add(0); cmds.add(0)
99
+ val has = c.has("color")
100
+ ints.add(if (has) 1 else 0)
101
+ ints.add(if (has) parseElurColor(c.optString("color"), Color.BLACK) else 0)
102
+ }
103
+ "rect" -> {
104
+ cmds.add(1); cmds.add(4); cmds.add(6); cmds.add(0)
105
+ color(c, "fill", true); color(c, "stroke", true)
106
+ floats.add(c.optDouble("x").toFloat()); floats.add(c.optDouble("y").toFloat())
107
+ floats.add(c.optDouble("w").toFloat()); floats.add(c.optDouble("h").toFloat())
108
+ floats.add(c.optDouble("radius", 0.0).toFloat())
109
+ floats.add(c.optDouble("lineWidth", 1.0).toFloat())
110
+ }
111
+ "circle" -> {
112
+ cmds.add(2); cmds.add(4); cmds.add(4); cmds.add(0)
113
+ color(c, "fill", true); color(c, "stroke", true)
114
+ floats.add(c.optDouble("x").toFloat()); floats.add(c.optDouble("y").toFloat())
115
+ floats.add(c.optDouble("r").toFloat())
116
+ floats.add(c.optDouble("lineWidth", 1.0).toFloat())
117
+ }
118
+ "line" -> {
119
+ cmds.add(3); cmds.add(1); cmds.add(5); cmds.add(0)
120
+ ints.add(parseElurColor(c.optString("stroke", "#000000"), Color.BLACK))
121
+ floats.add(c.optDouble("x1").toFloat()); floats.add(c.optDouble("y1").toFloat())
122
+ floats.add(c.optDouble("x2").toFloat()); floats.add(c.optDouble("y2").toFloat())
123
+ floats.add(c.optDouble("lineWidth", 1.0).toFloat())
124
+ }
125
+ "path" -> {
126
+ cmds.add(4); cmds.add(4); cmds.add(1); cmds.add(1)
127
+ color(c, "fill", true); color(c, "stroke", true)
128
+ floats.add(c.optDouble("lineWidth", 1.0).toFloat())
129
+ strs.add(c.optString("d"))
130
+ }
131
+ "text" -> {
132
+ cmds.add(5); cmds.add(1); cmds.add(3); cmds.add(2)
133
+ ints.add(parseElurColor(c.optString("color", "#000000"), Color.BLACK))
134
+ floats.add(c.optDouble("x").toFloat()); floats.add(c.optDouble("y").toFloat())
135
+ floats.add(c.optDouble("size", 14.0).toFloat())
136
+ strs.add(c.optString("text")); strs.add(c.optString("align", "left"))
137
+ }
138
+ "save" -> { cmds.add(6); cmds.add(0); cmds.add(0); cmds.add(0) }
139
+ "restore" -> { cmds.add(7); cmds.add(0); cmds.add(0); cmds.add(0) }
140
+ "translate" -> {
141
+ cmds.add(8); cmds.add(0); cmds.add(2); cmds.add(0)
142
+ floats.add(c.optDouble("x").toFloat()); floats.add(c.optDouble("y").toFloat())
143
+ }
144
+ "rotate" -> {
145
+ cmds.add(9); cmds.add(0); cmds.add(1); cmds.add(0)
146
+ floats.add(c.optDouble("deg").toFloat())
147
+ }
148
+ "scale" -> {
149
+ cmds.add(10); cmds.add(0); cmds.add(2); cmds.add(0)
150
+ floats.add(c.optDouble("x").toFloat())
151
+ floats.add(if (c.has("y")) c.optDouble("y").toFloat() else c.optDouble("x").toFloat())
152
+ }
153
+ }
154
+ }
155
+ return Flattened(
156
+ cmds.toIntArray(),
157
+ floats.toFloatArray(),
158
+ ints.toIntArray(),
159
+ strs.toTypedArray())
160
+ }
161
+
162
+ }