refactor(naming): A1 — ente→arje, vista→revista, pluma→fana

Rename batch de la Fase A del PLAN_MACRO:
- 25 crates ente-* → arje-* (protocol/init/runtime/compat). El linaje
  arje (init Linux) queda con prefijo coherente.
- vista → revista (revista-core + revista-web).
- pluma → fana (fana-md + fana-md-reader-web). fana absorbe el linaje
  markdown de pluma; será el writer DAG editor (prioridad alta).

Cambios:
- git mv de 29 crate dirs + 2 SDDs
- package/lib/bin names + path refs + imports .rs reescritos
- workspace Cargo.toml + comentarios de sección
- SDDs de init/runtime/compat/protocol actualizados a arje-
- SDD de revista + SDD de fana (reescrito: writer DAG editor)
- docs/STATUS.md, ROADMAP.md, PLAN_MACRO.md, arje-boot.md,
  arje-replace-systemd.md actualizados
- docs/changelog/akasha.md → chasqui.md

scripts/rename-fase-a.py idempotente (--dry-run soportado).
cargo check --workspace verde.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
sergio
2026-05-20 00:10:14 +00:00
parent 3fc6dcfa72
commit b83d40a833
159 changed files with 2384 additions and 1111 deletions
+40
View File
@@ -0,0 +1,40 @@
# modules/revista/ — Deck horizontal swipe (PageView)
**Propósito.** Carousel/PageView estilo Flutter: gesto horizontal con
snap a página, distinción horizontal vs vertical, soporte mouse +
touch + pointer events. Lógica separada del binding DOM.
## Crates
| crate | tipo | rol |
| ------------- | ---- | --------------------------------------------------------- |
| `revista-core` | lib | `DeckState` agnóstico: pointer_down/move/end → outcomes |
| `revista-web` | lib | Binding DOM sobre `<strip>`: traduce eventos + aplica CSS |
## Dependencias
- `revista-core`: sin deps externas. Pura state machine.
- `revista-web``revista-core`, `wasm-bindgen`, `web-sys` (PointerEvent).
## API agnóstica (revista-core)
```rust
let mut deck = DeckState::new();
deck.pointer_down(x, y, pointer_id, viewport_width);
match deck.pointer_move(x, y) {
DragOutcome::StartHorizontal { pointer_id } => capture_pointer(),
DragOutcome::DragOffset(px) => apply_translate(px),
DragOutcome::CancelVertical => yield_to_scroll(),
DragOutcome::Idle => {}
}
if let Some(r) = deck.pointer_end(offset, width, n_pages) {
apply_translate(r.offset_px);
if r.changed { notify(r.target_index); }
}
```
## Estado
revista-core: 5 tests verdes (drag decision + snap + clamp + goto).
revista-web: binding DOM intacto, ahora delega toda la lógica a core.
LOC core 177 + web ~355. Reutilizable en backends no-web.
@@ -0,0 +1,8 @@
[package]
name = "revista-core"
description = "Vista — máquina de estados agnóstica para deck horizontal con snap. Sin dependencias web/DOM."
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
publish.workspace = true
@@ -0,0 +1,177 @@
//! Vista core — máquina de estados agnóstica del deck horizontal.
//!
//! Lógica pura: dados los eventos crudos de pointer (coords + viewport width
//! + n_pages) decide cuándo arrancar drag horizontal, cuánto trasladar el
//! strip y a qué página snapear al soltar. Sin DOM, sin wasm-bindgen.
/// Umbral en pixels para confirmar gesto horizontal vs vertical.
pub const DRAG_DECISION_PX: f64 = 8.0;
/// Cuán más horizontal que vertical debe ser el delta para considerarse "swipe".
pub const HORIZONTAL_BIAS: f64 = 1.3;
#[derive(Clone, Debug, Default)]
pub struct DeckState {
pub current_index: usize,
pointer_start: Option<(f64, f64, i32)>,
drag_active: bool,
drag_start_offset: f64,
}
#[derive(Clone, Debug, PartialEq)]
pub enum DragOutcome {
/// Aún no hay decisión — esperar más movimiento.
Idle,
/// Empezar drag horizontal: el host debe capturar el pointer.
StartHorizontal { pointer_id: i32 },
/// Movimiento vertical predominante — host debe ceder al scroll nativo.
CancelVertical,
/// Drag en curso — host debe trasladar el strip a este offset.
DragOffset(f64),
}
#[derive(Clone, Debug, PartialEq)]
pub struct SnapResult {
pub target_index: usize,
pub offset_px: f64,
pub changed: bool,
}
impl DeckState {
pub fn new() -> Self { Self::default() }
/// Marca el inicio de un gesto. `viewport_width` se usa para anclar el
/// drag_start_offset a la página visible actual.
pub fn pointer_down(&mut self, x: f64, y: f64, pointer_id: i32, viewport_width: f64) {
self.pointer_start = Some((x, y, pointer_id));
self.drag_active = false;
self.drag_start_offset = -(self.current_index as f64) * viewport_width;
}
/// Procesa un movimiento. Devuelve la acción que el host debe ejecutar.
pub fn pointer_move(&mut self, x: f64, y: f64) -> DragOutcome {
let Some((sx, sy, pid)) = self.pointer_start else {
return DragOutcome::Idle;
};
let dx = x - sx;
let dy = y - sy;
if !self.drag_active {
let abs_dx = dx.abs();
let abs_dy = dy.abs();
if abs_dx > DRAG_DECISION_PX && abs_dx > abs_dy * HORIZONTAL_BIAS {
self.drag_active = true;
return DragOutcome::StartHorizontal { pointer_id: pid };
} else if abs_dy > DRAG_DECISION_PX {
self.pointer_start = None;
return DragOutcome::CancelVertical;
} else {
return DragOutcome::Idle;
}
}
DragOutcome::DragOffset(self.drag_start_offset + dx)
}
/// Finaliza el gesto. Si había drag activo, calcula la página snap y
/// actualiza `current_index`. `current_offset` viene del estado real
/// del strip (el host lee CSS transform / variable).
pub fn pointer_end(
&mut self,
current_offset: f64,
viewport_width: f64,
n_pages: usize,
) -> Option<SnapResult> {
let was_active = self.drag_active;
self.drag_active = false;
self.pointer_start = None;
if !was_active || viewport_width <= 0.0 || n_pages == 0 {
return None;
}
let raw = -current_offset / viewport_width;
let target = (raw.round().max(0.0) as usize).min(n_pages - 1);
let offset_px = -(target as f64) * viewport_width;
let changed = self.current_index != target;
self.current_index = target;
Some(SnapResult { target_index: target, offset_px, changed })
}
/// Salto programático (click en tabs externos). Devuelve el offset
/// resultante para que el host lo aplique al strip.
pub fn goto(&mut self, index: usize, viewport_width: f64) -> SnapResult {
let offset_px = -(index as f64) * viewport_width;
let changed = self.current_index != index;
self.current_index = index;
SnapResult { target_index: index, offset_px, changed }
}
/// Reposiciona tras un resize. Devuelve el offset que el host debe
/// aplicar sin animación.
pub fn reposition(&self, viewport_width: f64) -> f64 {
-(self.current_index as f64) * viewport_width
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vertical_drag_is_cancelled() {
let mut s = DeckState::new();
s.pointer_down(100.0, 100.0, 1, 800.0);
// Movimiento vertical mayor que el umbral.
let r = s.pointer_move(100.0, 120.0);
assert_eq!(r, DragOutcome::CancelVertical);
}
#[test]
fn horizontal_drag_starts_after_threshold() {
let mut s = DeckState::new();
s.pointer_down(100.0, 100.0, 7, 800.0);
// Justo por debajo del umbral → Idle.
assert_eq!(s.pointer_move(105.0, 100.0), DragOutcome::Idle);
// Sobre el umbral con bias horizontal → Start.
let r = s.pointer_move(120.0, 100.0);
assert_eq!(r, DragOutcome::StartHorizontal { pointer_id: 7 });
}
#[test]
fn snap_rounds_to_nearest_page() {
let mut s = DeckState::new();
s.current_index = 1;
s.pointer_down(0.0, 0.0, 1, 1000.0); // drag_start_offset = -1000
// Forzar drag activo
s.pointer_move(20.0, 0.0);
// Offset actual = -1000 + 20 = -980 → target round(980/1000) = 1, sin cambio
let r = s.pointer_end(-980.0, 1000.0, 3).unwrap();
assert_eq!(r.target_index, 1);
assert!(!r.changed);
// Mover lo suficiente para snapear a página 0
s.pointer_down(0.0, 0.0, 1, 1000.0);
s.pointer_move(600.0, 0.0);
let r = s.pointer_end(-400.0, 1000.0, 3).unwrap();
assert_eq!(r.target_index, 0);
assert!(r.changed);
}
#[test]
fn snap_clamps_to_bounds() {
let mut s = DeckState::new();
s.current_index = 2;
s.pointer_down(0.0, 0.0, 1, 500.0);
s.pointer_move(50.0, 0.0);
// Offset muy a la izquierda → debería clamp a n_pages-1
let r = s.pointer_end(-9999.0, 500.0, 3).unwrap();
assert_eq!(r.target_index, 2);
}
#[test]
fn goto_updates_index_and_offset() {
let mut s = DeckState::new();
let r = s.goto(2, 800.0);
assert_eq!(r.target_index, 2);
assert_eq!(r.offset_px, -1600.0);
assert!(r.changed);
// segundo goto al mismo índice → changed=false
let r = s.goto(2, 800.0);
assert!(!r.changed);
}
}
@@ -0,0 +1,28 @@
[package]
name = "revista-web"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
publish.workspace = true
[dependencies]
revista-core = { path = "../revista-core" }
wasm-bindgen.workspace = true
js-sys.workspace = true
[dependencies.web-sys]
workspace = true
features = [
"Window",
"Document",
"Element",
"HtmlElement",
"CssStyleDeclaration",
"DomTokenList",
"Event",
"EventTarget",
"PointerEvent",
"MouseEvent",
"AddEventListenerOptions",
]
@@ -0,0 +1,210 @@
//! Vista-web — binding DOM del deck horizontal. Toda la lógica de
//! decisión de gesto/snap vive en `vista-core`; este crate sólo traduce
//! `PointerEvent`s en eventos de `DeckState` y aplica el offset al DOM.
//!
//! Contrato CSS (el caller provee):
//! ```css
//! .vista-deck { overflow: hidden; touch-action: pan-y; }
//! .vista-strip {
//! display: flex;
//! width: 100%;
//! height: 100%;
//! transform: translate3d(var(--vista-offset, 0px), 0, 0);
//! transition: transform 360ms cubic-bezier(0.22, 0.61, 0.36, 1);
//! }
//! .vista-strip.vista-dragging,
//! .vista-strip.vista-instant { transition: none; }
//! .vista-page { flex: 0 0 100%; height: 100%; overflow-y: auto; }
//! ```
use std::cell::RefCell;
use std::rc::Rc;
use revista_core::{DeckState, DragOutcome};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{Event, HtmlElement, PointerEvent};
#[derive(Clone)]
pub struct Deck {
strip: HtmlElement,
inner: Rc<RefCell<Inner>>,
}
struct Inner {
state: DeckState,
on_change: Option<Box<dyn FnMut(usize)>>,
}
impl Deck {
pub fn mount(strip: HtmlElement) -> Result<Self, JsValue> {
let inner = Rc::new(RefCell::new(Inner {
state: DeckState::new(),
on_change: None,
}));
install_pointerdown(&strip, &inner)?;
install_pointermove(&strip, &inner)?;
install_pointerend(&strip, &inner, "pointerup")?;
install_pointerend(&strip, &inner, "pointercancel")?;
install_pointerend(&strip, &inner, "pointerleave")?;
install_resize(&strip, &inner)?;
Ok(Self { strip, inner })
}
pub fn goto(&self, index: usize, smooth: bool) {
let width = self.strip.client_width() as f64;
let mut i = self.inner.borrow_mut();
let r = i.state.goto(index, width);
drop(i);
if !smooth {
let _ = self.strip.class_list().add_1("vista-instant");
}
set_offset(&self.strip, r.offset_px);
if !smooth {
clear_instant_next_frame(&self.strip);
}
if r.changed {
let mut i = self.inner.borrow_mut();
if let Some(cb) = i.on_change.as_mut() {
cb(r.target_index);
}
}
}
pub fn current_index(&self) -> usize {
self.inner.borrow().state.current_index
}
pub fn page_count(&self) -> u32 {
self.strip.child_element_count()
}
pub fn on_change<F: FnMut(usize) + 'static>(&self, cb: F) {
self.inner.borrow_mut().on_change = Some(Box::new(cb));
}
pub fn strip(&self) -> &HtmlElement {
&self.strip
}
}
fn install_pointerdown(strip: &HtmlElement, inner: &Rc<RefCell<Inner>>) -> Result<(), JsValue> {
let strip2 = strip.clone();
let inner2 = inner.clone();
let cb = Closure::<dyn FnMut(PointerEvent)>::new(move |e: PointerEvent| {
let width = strip2.client_width() as f64;
inner2.borrow_mut().state.pointer_down(
e.client_x() as f64,
e.client_y() as f64,
e.pointer_id(),
width,
);
});
strip.add_event_listener_with_callback("pointerdown", cb.as_ref().unchecked_ref())?;
cb.forget();
Ok(())
}
fn install_pointermove(strip: &HtmlElement, inner: &Rc<RefCell<Inner>>) -> Result<(), JsValue> {
let strip2 = strip.clone();
let inner2 = inner.clone();
let cb = Closure::<dyn FnMut(PointerEvent)>::new(move |e: PointerEvent| {
let outcome = inner2
.borrow_mut()
.state
.pointer_move(e.client_x() as f64, e.client_y() as f64);
match outcome {
DragOutcome::StartHorizontal { pointer_id } => {
let _ = strip2.class_list().add_1("vista-dragging");
let _ = strip2.set_pointer_capture(pointer_id);
}
DragOutcome::DragOffset(offset) => {
set_offset(&strip2, offset);
e.prevent_default();
}
DragOutcome::Idle | DragOutcome::CancelVertical => {}
}
});
let opts = web_sys::AddEventListenerOptions::new();
opts.set_passive(false);
strip.add_event_listener_with_callback_and_add_event_listener_options(
"pointermove",
cb.as_ref().unchecked_ref(),
&opts,
)?;
cb.forget();
Ok(())
}
fn install_pointerend(
strip: &HtmlElement,
inner: &Rc<RefCell<Inner>>,
event_name: &str,
) -> Result<(), JsValue> {
let strip2 = strip.clone();
let inner2 = inner.clone();
let cb = Closure::<dyn FnMut(PointerEvent)>::new(move |e: PointerEvent| {
let width = strip2.client_width() as f64;
let offset = current_offset_px(&strip2);
let n_pages = strip2.child_element_count() as usize;
let res = inner2.borrow_mut().state.pointer_end(offset, width, n_pages);
let _ = strip2.class_list().remove_1("vista-dragging");
let _ = strip2.release_pointer_capture(e.pointer_id());
if let Some(r) = res {
set_offset(&strip2, r.offset_px);
if r.changed {
let mut i = inner2.borrow_mut();
if let Some(cb) = i.on_change.as_mut() {
cb(r.target_index);
}
}
}
});
strip.add_event_listener_with_callback(event_name, cb.as_ref().unchecked_ref())?;
cb.forget();
Ok(())
}
fn install_resize(strip: &HtmlElement, inner: &Rc<RefCell<Inner>>) -> Result<(), JsValue> {
let Some(window) = web_sys::window() else { return Ok(()) };
let strip2 = strip.clone();
let inner2 = inner.clone();
let cb = Closure::<dyn FnMut()>::new(move || {
let width = strip2.client_width() as f64;
let offset = inner2.borrow().state.reposition(width);
let _ = strip2.class_list().add_1("vista-instant");
set_offset(&strip2, offset);
clear_instant_next_frame(&strip2);
});
window.add_event_listener_with_callback("resize", cb.as_ref().unchecked_ref())?;
cb.forget();
Ok(())
}
fn set_offset(strip: &HtmlElement, offset_px: f64) {
let _ = strip
.style()
.set_property("--vista-offset", &format!("{}px", offset_px));
}
fn current_offset_px(strip: &HtmlElement) -> f64 {
let s = strip
.style()
.get_property_value("--vista-offset")
.unwrap_or_default();
s.trim().trim_end_matches("px").parse::<f64>().unwrap_or(0.0)
}
fn clear_instant_next_frame(strip: &HtmlElement) {
let strip2 = strip.clone();
let cb = Closure::once(Box::new(move || {
let _ = strip2.class_list().remove_1("vista-instant");
}) as Box<dyn FnOnce()>);
if let Some(w) = web_sys::window() {
let _ = w.request_animation_frame(cb.as_ref().unchecked_ref());
}
cb.forget();
}
#[doc(hidden)]
pub fn __unused_event_marker(_e: &Event) {}