feat(ui): ludic.ui grows toward HTML, CSS and React (Phase 0.U1-U4)

- Natives: ui_native(tag, measure, draw) makes an element the program draws itself; ui_fire
  runs its on-<event> with event.value. input, select and textarea have simple defaults.
- React:
  - keyed <each>, <let>, <provide> context through components, <fragment>;
  - named slots, default props on <component>;
  - on-mount / on-unmount;
  - inline text inside text elements.
- CSS:
  - custom properties and var();
  - position relative/absolute/fixed with insets and z-index;
  - em/rem/vw/vh and @media;
  - wrapping text and ellipsis, overflow;
  - + and ~ combinators, :nth-child(an+b), :checked, :active.
- Developing: errors with file:line, ui_errors(), ui_reload() keeping state, and an
  inspector-style ui_dump.
- view fields infer the type of a literal or a named function's result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 16:17:25 +03:00
parent 66a2bc2214
commit 637d07400e
39 changed files with 42012 additions and 40795 deletions

View file

@ -5,6 +5,7 @@
export property UiRule {
sel: UiSel = null
spec: int = 0
md: UiMedia = null # the @media it sits in, if any
keys: []string = null
vals: []UiExpr = null
}
@ -21,14 +22,20 @@ function lss_is(path: string) -> bool { return len(path) > 4 and path[len(path)
# a stylesheet file: a file with rules and imports and nothing else
function lss_file(src: string, path: string) -> UiFile {
let f = lib_new(path)
f.src = src
lss_text(f, src)
f.sheet = sheet_of(f)
return f
}
function lss_text(f: UiFile, src: string) -> void {
let err = new []string
lss_block(f, lss_strip(src), null, err)
for i in 0 .. len(err) { ui_err(`{f.path}: <style> {err[i]}`) }
}
# rules, @imports and @media blocks; the rules in a @media block carry its condition
function lss_block(f: UiFile, src: string, md: UiMedia, err: []string) -> void {
let r = new UiRd
r.s = lss_strip(src)
r.s = src
while r.err == "" {
rd_ws(r)
if r.i >= len(r.s) { break }
@ -36,11 +43,18 @@ function lss_text(f: UiFile, src: string) -> void {
lss_import(f, lss_upto(r, 59))
continue
}
if rd_op(r, "@media") {
let cond = md_parse(lss_upto(r, 123))
lss_block(f, lss_upto(r, 125), cond, err)
continue
}
let sels = lss_upto(r, 123)
let body = lss_upto(r, 125)
let at = len(f.own)
lss_rule(f, sels, body, err)
for i in at .. len(f.own) { f.own[i].md = md }
}
for i in 0 .. len(err) { ui_err(`{f.path}: <style> {err[i]}`) }
if r.err != "" { push(err, r.err) }
}
# @import "base.lss"; - its rules come before this file's own
function lss_import(f: UiFile, what: string) -> void {