grid: packing, pinning, resize steps (port of Layout.js and app.py's grid logic). gesture: pointer state machine (tap, long press, drag, release, swipe). updater: release/version parsing and the update decision. vdom: pure virtual DOM with an HTML-text renderer for tests. app: Elm-style Model/Msg/update/view with effects as data, persistence (JSON layout, import of the old WebView build's localStorage), drawer/search, menus, drag and resize. 60 headless tests drive it through pointer input. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
53 lines
950 B
MoonBit
53 lines
950 B
MoonBit
///|
|
|
/// Small accessors over `Json`, so decoding code reads as lookups with defaults.
|
|
|
|
///|
|
|
pub fn get(j : Json, key : String) -> Json? {
|
|
match j {
|
|
Object(o) => o.get(key)
|
|
_ => None
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn str(j : Json, key : String, default? : String = "") -> String {
|
|
match get(j, key) {
|
|
Some(String(s)) => s
|
|
_ => default
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn int(j : Json, key : String, default? : Int = 0) -> Int {
|
|
match get(j, key) {
|
|
Some(Number(n, ..)) => n.to_int()
|
|
Some(True) => 1
|
|
_ => default
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn bool(j : Json, key : String, default? : Bool = false) -> Bool {
|
|
match get(j, key) {
|
|
Some(True) => true
|
|
Some(False) => false
|
|
Some(Number(n, ..)) => n != 0.0
|
|
_ => default
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn arr(j : Json, key : String) -> Array[Json] {
|
|
match get(j, key) {
|
|
Some(Array(a)) => a
|
|
_ => []
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn parse(text : String) -> Json? {
|
|
try Some(@json.parse(text)) catch {
|
|
_ => None
|
|
}
|
|
}
|