gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit109cfc5c109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre109cfc5c/plugins/web/view.hl

30.7 KB

  1. // The View walker — realm-neutral: the same code renders HTML on the server and
  2. // (compiled to JS) creates or claims DOM in the browser. It walks a TREE, the
  3. // syntax of a View member reflected into plain hybrids by the server (see
  4. // server.hl `tree()`), against an INSTANCE whose members supply the values.
  5. //
  6. // Tree node shapes:
  7. // { k = 'el' tag key path = [ keys… ] site attrs = [ { name text } | { name member } ] children = [ … ] }
  8. // `site` is `file:line:col` of the literal — the id its class is minted under
  9. // `tag` is what the DOM gets (a custom key kebab-cased), `key` the source key
  10. // { k = 'text' text }
  11. // { k = 'member' name } an ordered entry naming a member of the class — a SITE
  12. // { k = 'field' name path } `p.title`: a path off a member or a `for` row variable
  13. // { k = 'for' row list body } `for (row of list) { … }`, body rendered per entry
  14. // { k = 'if' cond then other } `if (cond) { … } else { … }`
  15. // { k = 'on' event } a DOM event the owning literal handles (its inline `on`)
  16. // { k = 'component' cls key path bindings ons } `Child { count = count on done(v) { … } }`:
  17. // a composed component — its own mount renders here
  18. // { k = 'other' tag } a construct this round does not render yet (if / for / on)
  19. //
  20. // `ctx` rides through every call: `ctx.slot` is the HTML a shell's `slot` member
  21. // stands for (null when rendering a page alone), `ctx.kids` the child mounts of
  22. // the instance being rendered, keyed by the component node's path joined with
  23. // '/'. A component node renders ITS mount: its own instance, its own kids.
  24. // THE HTML ELEMENTS. An entry whose key is one of these is that element; any other
  25. // key is a CUSTOM element and is written kebab-case (`postsList` → `<posts-list>`),
  26. // which is also what a Style rule of that name selects. This list is what §4 calls
  27. // "the compiler's own View element list": one list, so a tag rule in a styles file
  28. // and a tag in a View can never disagree.
  29. static tags = [
  30. 'a' 'abbr' 'address' 'article' 'aside' 'audio' 'b' 'bdi' 'bdo' 'blockquote' 'body' 'br' 'button'
  31. 'canvas' 'caption' 'cite' 'code' 'col' 'colgroup' 'data' 'datalist' 'dd' 'del' 'details' 'dfn'
  32. 'dialog' 'div' 'dl' 'dt' 'em' 'embed' 'fieldset' 'figcaption' 'figure' 'footer' 'form'
  33. 'h1' 'h2' 'h3' 'h4' 'h5' 'h6' 'head' 'header' 'hgroup' 'hr' 'html' 'i' 'iframe' 'img' 'input'
  34. 'ins' 'kbd' 'label' 'legend' 'li' 'link' 'main' 'map' 'mark' 'menu' 'meta' 'meter' 'nav'
  35. 'noscript' 'object' 'ol' 'optgroup' 'option' 'output' 'p' 'picture' 'pre' 'progress' 'q' 'rp'
  36. 'rt' 'ruby' 's' 'samp' 'script' 'search' 'section' 'select' 'slot' 'small' 'source' 'span'
  37. 'strong' 'style' 'sub' 'summary' 'sup' 'table' 'tbody' 'td' 'template' 'textarea' 'tfoot'
  38. 'th' 'thead' 'time' 'title' 'tr' 'track' 'u' 'ul' 'var' 'video' 'wbr' 'svg' 'path' 'circle'
  39. 'rect' 'line' 'polyline' 'polygon' 'g' 'text' 'use' 'defs' 'symbol' 'ellipse' 'stop' 'tspan'
  40. 'feBlend' 'feColorMatrix' 'feComposite' 'feFlood' 'feGaussianBlur' 'feMerge' 'feMergeNode'
  41. 'feOffset' 'feTurbulence' 'feDropShadow' 'feMorphology' 'feImage' 'feTile'
  42. 'feComponentTransfer' 'feFuncR' 'feFuncG' 'feFuncB' 'feFuncA' 'feConvolveMatrix'
  43. 'feDiffuseLighting' 'feSpecularLighting' 'feDisplacementMap' 'feDistantLight' 'fePointLight'
  44. 'feSpotLight' 'linearGradient' 'radialGradient' 'clipPath' 'textPath' 'foreignObject'
  45. 'animateMotion' 'animateTransform'
  46. ]
  47. // a form control with a `value` the app binds (a member or a field path), and no
  48. // autocomplete of the author's own
  49. boundValue(&node) {
  50. if (node.tag != 'input' && node.tag != 'textarea' && node.tag != 'select') { return false }
  51. let bound = false
  52. for (a of node.attrs) {
  53. if (a.name == 'autocomplete') { return false }
  54. if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }
  55. }
  56. return bound
  57. }
  58. // the value an option reports to the form: its `value`, or null when it has none
  59. // and its text stands for it
  60. optionValue(&node, &page, &rows) {
  61. for (a of node.attrs) {
  62. if (a.name == 'value') {
  63. if (a.member != null) { return '' + value({ k = 'member'; name = a.member; }, page, rows) }
  64. if (a.ref != null) { return '' + value(a.ref, page, rows) }
  65. return '' + a.text
  66. }
  67. }
  68. return null
  69. }
  70. // ---- THE ELEMENTS THE BROWSER'S PARSER INSERTS ----------------------------------
  71. // HTML has elements whose START TAG IS OPTIONAL: a `tr` written straight inside a
  72. // `table` is parsed into a `tbody` the parser creates, a `td` outside a `tr` gets both,
  73. // and a `col` gets a `colgroup`. The served tree and the PARSED tree have to be the same
  74. // tree — the claim walk pairs them element for element — so the tree carries what the
  75. // parser would insert and the author goes on writing `table { tr { td { … } } }`.
  76. // (Measured 2026-09-14 on demo-nested: 38 rows, 38 "claim: no element for tr under
  77. // TABLE", one per row; the fix in the app was to write the `tbody` by hand.)
  78. //
  79. // One row per (parent, child) pair the standard's optional-tag rules name. The walk
  80. // applies them REPEATEDLY, so a `td` under a `table` gains a `tbody` and then a `tr`
  81. // inside it — what the parser does, and not a table special case: a pair added to this
  82. // list is a pair the language then renders the way the browser will read it.
  83. static impliedElements = [
  84. { under = 'table' child = 'tr' wrap = 'tbody' }
  85. { under = 'table' child = 'td' wrap = 'tbody' }
  86. { under = 'table' child = 'th' wrap = 'tbody' }
  87. { under = 'table' child = 'col' wrap = 'colgroup' }
  88. { under = 'tbody' child = 'td' wrap = 'tr' }
  89. { under = 'tbody' child = 'th' wrap = 'tr' }
  90. { under = 'thead' child = 'td' wrap = 'tr' }
  91. { under = 'thead' child = 'th' wrap = 'tr' }
  92. { under = 'tfoot' child = 'td' wrap = 'tr' }
  93. { under = 'tfoot' child = 'th' wrap = 'tr' }
  94. ]
  95. // the container the parser would open for this child under this parent, or null
  96. impliedWrap(under, child) {
  97. if (child == null) { return null }
  98. for (r of impliedElements) { if (r.under == under && r.child == child) { return r.wrap } }
  99. return null
  100. }
  101. // THE TAG A NODE PUTS IN THE DOCUMENT: an element's own, and for a `for` or an `if` the
  102. // tag of the first element it renders — a region of `tr`s under a `table` needs the
  103. // `tbody` a bare `tr` needs, and it is the same rule that says so.
  104. firstTag(&n) {
  105. if (n == null) { return null }
  106. if (n.k == 'el') { return n.tag }
  107. if (n.k == 'for') { return firstTagIn(n.body) }
  108. if (n.k == 'if') {
  109. let t = firstTagIn(n.then)
  110. return t == null ? firstTagIn(n.other) : t
  111. }
  112. return null
  113. }
  114. firstTagIn(&list) {
  115. if (list == null) { return null }
  116. for (n of list) {
  117. let t = firstTag(n)
  118. if (t != null) { return t }
  119. }
  120. return null
  121. }
  122. // an element's children with those containers written out. A RUN of children that need
  123. // the same one SHARES it, because the parser opens one `tbody` and goes on putting rows
  124. // in it until something else closes it.
  125. implied(under, children, path, site) {
  126. let out = []
  127. let run = []
  128. let runWrap = null
  129. for (c of children) {
  130. let w = impliedWrap(under, firstTag(c))
  131. if (w != runWrap && run.length > 0) {
  132. out.push(impliedNode(runWrap, run, path, site))
  133. run = []
  134. }
  135. runWrap = w
  136. if (w == null) { out.push(c) } else { run.push(c) }
  137. }
  138. if (run.length > 0) { out.push(impliedNode(runWrap, run, path, site)) }
  139. return out
  140. }
  141. // the node for a container nobody wrote: no attributes, no handlers, and the rule
  142. // applied again inside it (`table { td }` is `table > tbody > tr > td`)
  143. impliedNode(tag, children, path, site) {
  144. let here = path.slice(0)
  145. here.push(tag)
  146. return { k = 'el'; tag = tag; key = tag; path = here; attrs = []; children = implied(tag, children, here, site + '>' + tag); site = site + '>' + tag; }
  147. }
  148. static voidTags = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]
  149. // THE VERBATIM ELEMENTS: whitespace between their tags is CONTENT, not layout. A
  150. // textarea's text IS its value, and a `pre`, a `script` and a `style` show or run
  151. // exactly what stands there — so the readable form never indents inside them
  152. // (the creator, 2026-09-13: "textarea seems to show the indentation as value").
  153. static verbatimTags = [ 'textarea' 'pre' 'script' 'style' ]
  154. isTag(name) {
  155. return tags.includes(name)
  156. }
  157. // the tag the DOM gets: an element of the list keeps its spelling (SVG has camelCase
  158. // elements: `linearGradient`, `clipPath`, `foreignObject`), any other key is custom, kebab-case
  159. domTag(name) {
  160. return tags.includes(name) ? name : kebab(name)
  161. }
  162. // camelCase → kebab-case (the archived WebView.kebab, verbatim): a separator only
  163. // BETWEEN a lowercase letter or digit and an uppercase one; at position 0, after
  164. // another uppercase or after a sigil an uppercase simply lowercases, so `ChatForm`
  165. // is `chat-form` and `#Svg` is `#svg`. The tag written on a custom element and the
  166. // selector a Style rule emits both come through here, so they cannot disagree.
  167. static KEBAB_JOINERS = "-_#@"
  168. kebab(name) {
  169. let out = ''
  170. let i = 0
  171. let prev = ''
  172. while (i < name.length) {
  173. let c = name.charAt(i)
  174. let lower = c.toLowerCase()
  175. let between = prev != '' && prev == prev.toLowerCase() && KEBAB_JOINERS.indexOf(prev) < 0
  176. if (c != lower && between) { out = out + '-' + lower } else { out = out + lower }
  177. prev = c
  178. i = i + 1
  179. }
  180. return out
  181. }
  182. // THE TAG-PREFIX STRIP (archived WebView.className, verbatim): rule `headerMain`
  183. // referenced under `header` is class `main`; under any other tag it keeps its name.
  184. className(rule, tag) {
  185. if (rule.length <= tag.length) { return rule }
  186. if (!rule.startsWith(tag)) { return rule }
  187. let rest = rule.slice(tag.length)
  188. let head = rest.charAt(0)
  189. if (head == head.toLowerCase()) { return rule }
  190. return head.toLowerCase() + rest.slice(1)
  191. }
  192. // THE PER-FILE CLASS of a `#local` rule (archived WebView.localClass, verbatim):
  193. // four characters out of the file's project-relative key, so it is stable across
  194. // checkouts and a golden can pin it. Every local rule of one file shares it; the
  195. // element's tag in front of it keeps them apart in the sheet (`svg.ma31`).
  196. static LOCAL_KEY_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-"
  197. static LOCAL_LETTERS = "abcdefghijklmnopqrstuvwxyz"
  198. static LOCAL_ALPHA = "abcdefghijklmnopqrstuvwxyz0123456789"
  199. localClass(fileKey) {
  200. let h = 0
  201. let i = 0
  202. while (i < fileKey.length) {
  203. h = (h * 31 + LOCAL_KEY_CHARS.indexOf(fileKey.charAt(i)) + 1) % 1000003
  204. i = i + 1
  205. }
  206. let out = LOCAL_LETTERS.charAt(h % 26)
  207. let rest = (h - (h % 26)) / 26
  208. let j = 0
  209. while (j < 3) {
  210. out = out + LOCAL_ALPHA.charAt(rest % 36)
  211. rest = (rest - (rest % 36)) / 36
  212. j = j + 1
  213. }
  214. return out
  215. }
  216. // the language has no escapes: a newline and a tab are written as themselves
  217. static newline = "
  218. "
  219. static tab = " "
  220. // a component node's key in a mount's `kids`: its path, '/'-joined (a list has no
  221. // join in the language; the walk is written out)
  222. kidKey(&path) {
  223. let out = ''
  224. for (p of path) { out = out + '/' + p }
  225. return out
  226. }
  227. // THE KEY OF ONE ROW'S CHILD: the component node's path plus the index of every
  228. // enclosing `for` iteration, which `ctx.rowKey` carries down the walk. Outside
  229. // every `for` the rowKey is empty and this is the plain path key.
  230. kidKeyIn(&path, &ctx) {
  231. return kidKey(path) + (ctx.rowKey != null ? ctx.rowKey : '')
  232. }
  233. // THE KEY OF ONE ROW — "lists are keyed by the record's id" (CONCEPT §2), and by
  234. // the row's index where the row is not a record or carries no id (a list of strings
  235. // is one: demo-blog's paragraphs). ONE rule, called by everything that has to tell
  236. // one row from the next: the server's HTML walk below, the mount key of a row's
  237. // children (WebFramework `mountKids`), and the browser's keyed region (client.hl).
  238. // Two rows with the SAME id are two rows to the language and one key to this rule;
  239. // the browser's region gives the second one a key of its own, the server does not.
  240. rowKey(&entry, i) {
  241. if (entry != null) {
  242. let t = hlTypeName(entry)
  243. if ((t == 'Hybrid' || t == 'Instance') && entry.id != null) { return '' + entry.id }
  244. }
  245. return '' + i
  246. }
  247. // the walking context of one `for` iteration: the same slot and kids, one row deeper
  248. rowCtx(&ctx, &entry, i) {
  249. let out = ctx + {}
  250. out.rowKey = (ctx.rowKey != null ? ctx.rowKey : '') + '#' + rowKey(entry, i)
  251. return out
  252. }
  253. // A LITERAL'S VALUE, TYPED — COMPONENTS.md §12, "typed, not stringified". `hlSyntax`
  254. // hands a literal back as its source text and its KIND, and a reference binding carries
  255. // the value rather than the text: `Level2 { n = 1 }` gives the child a Number, so `n * 97`
  256. // is arithmetic and not "operator '*' does not apply to String and Number" (measured
  257. // 2026-09-14, demo-nested wall 3). An attribute and a text child keep the text, because
  258. // HTML is text; only what crosses into a member of another class is typed.
  259. literalValue(kind, text) {
  260. if (kind == 'number') { return toNumber(text) }
  261. if (kind == 'boolean') { return text == 'true' }
  262. if (kind == 'null_literal') { return null }
  263. return text
  264. }
  265. // THE VALUE A REFERENCE BINDING CARRIES when it is a literal or a folded static — the
  266. // one place the two are read, so the server's mount and the browser's do it alike. A
  267. // static is folded to its VALUE and carried as one ('folded'), never printed and parsed
  268. // back; a literal carries its source text and its kind, which is all the syntax has.
  269. refValue(b) {
  270. if (b.kind == 'folded') { return b.value }
  271. if (b.kind != null) { return literalValue(b.kind, b.text) }
  272. return b.text
  273. }
  274. // HTML BOOLEAN ATTRIBUTES MEAN PRESENCE, NOT VALUE (mission 084's rule, ticket #33): a
  275. // parser reads `disabled="false"` as DISABLED, so a bound one is written ` disabled=""`
  276. // when its value is on and left out when it is off, and the browser sets or removes it
  277. // and writes the property. The list is mission 084's, the one the archived SSR, graph and
  278. // client agreed on.
  279. static boolAttrs = ['checked' 'disabled' 'selected' 'readonly' 'required' 'multiple' 'open' 'hidden']
  280. isBoolAttr(name) {
  281. return boolAttrs.includes(name)
  282. }
  283. // is a boolean attribute ON for this value? false, null, '' and 0 leave it off — what the
  284. // browser's own `!!v` says, so the server's markup and the client's write agree
  285. boolOn(val) {
  286. if (val == null || val == false || val == '') { return false }
  287. if (hlTypeName(val) == 'Number' && val == 0) { return false }
  288. return true
  289. }
  290. escape(s) {
  291. if (s == null) { return '' }
  292. // EVERY occurrence, not the first: `replace` stops after one, so a value with two
  293. // quotes in it ("a" "b") left the second one raw in the attribute it was written into
  294. return ('' + s).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;')
  295. }
  296. // THE VALUE a read names: a `for` row variable in scope wins over a member of the
  297. // same name (nesting is scope); a field path walks into it.
  298. value(&node, &page, &rows) {
  299. if (node.k == 'text') { return refValue(node) }
  300. if (node.k == 'expr') { return evalExpr(node.x, page, rows) }
  301. // READ IN PLACE: `v = rows[node.name]` copied the whole row value (a block with all its spans) and each
  302. // `v = v[f]` step copied the rest again, per read, per mount; a path of up to three steps is one indexed read
  303. let name = node.name
  304. let inRow = rows[name] != null
  305. if (node.k == 'field') {
  306. let path = node.path
  307. let n = path.length
  308. if (n == 1) {
  309. if (inRow) { return rows[name] == null ? null : rows[name][path[0]] }
  310. return page[name] == null ? null : page[name][path[0]]
  311. }
  312. if (n == 2) {
  313. if (inRow) { return rows[name][path[0]] == null ? null : rows[name][path[0]][path[1]] }
  314. return page[name][path[0]] == null ? null : page[name][path[0]][path[1]]
  315. }
  316. }
  317. let v = null
  318. if (inRow) { v = rows[name] } else { v = page[name] }
  319. if (node.k == 'field') {
  320. for (f of node.path) {
  321. if (v == null) { return null }
  322. v = v[f]
  323. }
  324. }
  325. return v
  326. }
  327. // A VIEW EXPRESSION (`p { "x" + n }`, `a - b`, `n > 3 ? 'big' : 'small'`) is evaluated by
  328. // the LANGUAGE'S OWN OPERATORS: this walk only picks the operator the author wrote and
  329. // applies it, so what `+` gives null and a string, what `==` says of two types, what `&&`
  330. // returns — all of it is the runtime's answer, on the server (the interpreter or a
  331. // binary) and in the browser (the client target), and hl:web has no rule of its own.
  332. // The leaves are reads (`value`) and literals. `&&`, `||` and `?:` evaluate what they
  333. // pick only, as the language does.
  334. evalExpr(&x, &page, &rows) {
  335. if (x.k == 'bin') {
  336. let l = evalExpr(x.l, page, rows)
  337. let op = x.op
  338. if (op == 'logical_and') { return l && evalExpr(x.r, page, rows) }
  339. if (op == 'logical_or') { return l || evalExpr(x.r, page, rows) }
  340. let r = evalExpr(x.r, page, rows)
  341. if (op == 'add') { return l + r }
  342. if (op == 'subtract') { return l - r }
  343. if (op == 'multiply') { return l * r }
  344. if (op == 'divide') { return l / r }
  345. if (op == 'modulo') { return l % r }
  346. if (op == 'equal') { return l == r }
  347. if (op == 'not_equal') { return l != r }
  348. if (op == 'less_than') { return l < r }
  349. if (op == 'greater_than') { return l > r }
  350. if (op == 'less_equal') { return l <= r }
  351. if (op == 'greater_equal') { return l >= r }
  352. if (op == 'bit_and') { return l & r }
  353. if (op == 'bit_or') { return l | r }
  354. if (op == 'bit_xor') { return l ^ r }
  355. if (op == 'shift_left') { return l << r }
  356. return l >> r
  357. }
  358. if (x.k == 'un') {
  359. let o = evalExpr(x.x, page, rows)
  360. if (x.op == 'logical_not') { return !o }
  361. if (x.op == 'negate') { return -o }
  362. return ~o
  363. }
  364. if (x.k == 'cond') { return evalExpr(x.c, page, rows) ? evalExpr(x.a, page, rows) : evalExpr(x.b, page, rows) }
  365. return value(x, page, rows)
  366. }
  367. // THE BIG VALUES OF THE WALK ARE TAKEN BY REFERENCE, and this is the whole of why the
  368. // server's render was slow (mission 312 wall 2, measured 2026-09-15). A METHOD CALL
  369. // DEEP-COPIES ITS ARGUMENTS — a lambda call does not, which is why this went unseen —
  370. // so every one of these calls copied the page INSTANCE and the `ctx` holding every
  371. // child mount of the page, once per element and once per read. The cost of rendering
  372. // one element was therefore proportional to everything the page was holding: a 43-row
  373. // table beside 120 components took 9.6 s, the same table alone 0.44 s, and a page whose
  374. // instance merely HELD 30 000 objects nobody renders took 34 s for 344 static elements.
  375. // Nothing in this walk writes through `page`, `rows` or `ctx` — `kidCtx`, `inner` and
  376. // `rowCtx`'s result are locals it copies on purpose — so a reference is the same walk,
  377. // and the `&` at a call site is optional, so every caller (client.hl included) is
  378. // unchanged. Measured after: 0.57 s, 1.27 s, 0.12 s for the three cases above.
  379. //
  380. // HTML of one node. `page` is the instance; `rows` the `for` variables in scope;
  381. // `ctx` carries the slot's HTML and the child mounts. `indent` is the current line's
  382. // indentation (a string of tabs) for the readable form, or null for the compact
  383. // one-line form (the production setting). Whitespace is only ever placed BETWEEN
  384. // elements: an element that carries text or a member value stays on one line, so
  385. // its text content is exactly what the author wrote and hydration finds it so.
  386. html(&node, &page, &rows, &ctx, indent) {
  387. if (node.k == 'text') { return escape(node.text) }
  388. if (node.k == 'on') { return '' } // the browser binds it
  389. if (node.k == 'member' || node.k == 'field' || node.k == 'expr') {
  390. if (node.k == 'member' && node.name == 'slot' && ctx.slot != null) { return ctx.slot }
  391. return escape(value(node, page, rows))
  392. }
  393. if (node.k == 'for') {
  394. let out = ''
  395. let list = value(node.list, page, rows)
  396. if (list == null) { return '' }
  397. let ri = 0
  398. for (entry of list) {
  399. let inner = rows + {}
  400. inner[node.row] = entry
  401. out = out + render(node.body, page, inner, rowCtx(ctx, entry, ri), indent)
  402. ri = ri + 1
  403. }
  404. return out
  405. }
  406. if (node.k == 'if') {
  407. if (value(node.cond, page, rows)) { return render(node.then, page, rows, ctx, indent) }
  408. return render(node.other, page, rows, ctx, indent)
  409. }
  410. if (node.k == 'component') {
  411. let kid = ctx.kids[kidKeyIn(node.path, ctx)]
  412. if (kid == null) { return '<!-- ' + node.cls + ' not mounted -->' }
  413. // THE FILL IS RENDERED HERE, IN THE HOST'S FRAME — the host's instance, the
  414. // host's `for` rows, the host's own child mounts — and handed to the child as
  415. // its `slot`, exactly as the shell is handed the page it wraps. The child
  416. // never evaluates it; it only places it.
  417. return render(withRootClasses(kid.view, node.classes), kid.page, {}, { slot = fillHtml(node, page, rows, ctx); kids = kid.kids; }, indent)
  418. }
  419. if (node.k == 'el') {
  420. let attrs = ''
  421. // HTML GIVES A TEXTAREA NO `value` ATTRIBUTE: what stands between its tags is
  422. // its value, so a bound one is written there — the server-rendered control
  423. // already shows what the member holds, before any script runs.
  424. let valueText = null
  425. // AND A SELECT NO `value` ATTRIBUTE EITHER: what it shows is the option marked
  426. // `selected`, so a bound value is carried down to the options (`childCtx.sel`)
  427. // and marks the matching one. A `value` written on the select itself means
  428. // nothing to the browser, which then shows the FIRST option — and hydration's
  429. // two-way read then wrote that first option back into the member (measured
  430. // 2026-09-13 on demo-blog: a published post's editor said "Draft", and saving
  431. // unpublished it).
  432. let selValue = null
  433. for (a of node.attrs) {
  434. if (node.tag == 'textarea' && a.name == 'value') {
  435. // not an attribute: it is written below, as the element's content
  436. if (a.member != null) { valueText = escape(value({ k = 'member'; name = a.member; }, page, rows)) }
  437. else if (a.ref != null) { valueText = escape(value(a.ref, page, rows)) }
  438. else { valueText = escape(a.text) }
  439. } else if (node.tag == 'select' && a.name == 'value') {
  440. // not an attribute: it selects an option below
  441. if (a.member != null) { selValue = '' + value({ k = 'member'; name = a.member; }, page, rows) }
  442. else if (a.ref != null) { selValue = '' + value(a.ref, page, rows) }
  443. else { selValue = '' + a.text }
  444. } else if (isBoolAttr(a.name) && (a.member != null || a.ref != null)) {
  445. if (boolOn(value(a.member != null ? { k = 'member'; name = a.member; } : a.ref, page, rows))) { attrs = attrs + ' ' + a.name + '=""' }
  446. } else if (a.member != null) {
  447. // a null read is no attribute (#177), unless extra classes ride on it
  448. let av = value({ k = 'member'; name = a.member; }, page, rows)
  449. if (av != null || a.extra != null) { attrs = attrs + ' ' + a.name + '="' + escape(av) + extraOf(a) + '"' }
  450. } else if (a.ref != null) {
  451. let av = value(a.ref, page, rows)
  452. if (av != null || a.extra != null) { attrs = attrs + ' ' + a.name + '="' + escape(av) + extraOf(a) + '"' }
  453. } else {
  454. attrs = attrs + ' ' + a.name + '="' + escape(a.text) + '"'
  455. }
  456. }
  457. // A CONTROL WHOSE VALUE THE APP BINDS IS THE APP'S: the browser must neither
  458. // autofill it nor restore a remembered value over it on reload (Chrome restores
  459. // unnamed text inputs by type and document order, so a remembered value lands
  460. // on whichever input now stands at that position — measured by the creator
  461. // 2026-09-13: "Gamma" in the add field after Ctrl+R)
  462. if (boundValue(node)) { attrs = attrs + ' autocomplete="off"' }
  463. // THE CONTEXT IS NEVER COPIED INTO A LOCAL HERE. `let kidCtx = ctx` costs a copy
  464. // of everything the frame holds — every child mount of this page — and it stood
  465. // on the path of EVERY element: with the 43-row matrix in a page of 121
  466. // components it was 5.1 s against 0.6 s for the same two halves apart (measured
  467. // 2026-09-15, mission 312 wall 2). A select is the only node that changes the
  468. // context for its children, so it is the only branch that builds one.
  469. let children = ''
  470. if (node.tag == 'select') {
  471. // the select's value walks down to its options, however deep the `for` or the
  472. // `if` that builds them stands
  473. let kidCtx = ctx + {}
  474. kidCtx.sel = selValue
  475. children = kidsHtml(node, page, rows, kidCtx, indent)
  476. } else if (node.tag == 'script') {
  477. children = rawKids(node, page, rows, ctx)
  478. } else {
  479. children = kidsHtml(node, page, rows, ctx, indent)
  480. }
  481. // the textarea's value stands where its content stands
  482. if (valueText != null) { children = valueText }
  483. // THE OPTION THE SELECT SHOWS: the one whose value is the member's. An option
  484. // with no `value` reports its text, as the browser reads it.
  485. if (node.tag == 'option' && ctx.sel != null) {
  486. let ov = optionValue(node, page, rows)
  487. if (ov == null) { ov = children }
  488. if (ov == ctx.sel) { attrs = attrs + ' selected' }
  489. }
  490. // a void element has no end tag (the HTML standard's list; the claim walks
  491. // elements, so the browser's parse of either form agrees with the tree)
  492. if (voidTags.includes(node.tag)) { return '<' + node.tag + attrs + '>' }
  493. return '<' + node.tag + attrs + '>' + children + '</' + node.tag + '>'
  494. }
  495. return '<!-- ' + node.tag + ' not rendered yet -->'
  496. }
  497. // AN ELEMENT'S CHILDREN, in the readable form or the compact one — split out of `html`
  498. // so that the one node which changes the context for its children (a select, which hands
  499. // its value down to its options) is the only one that builds a context at all.
  500. // A SCRIPT'S CONTENT IS RAW TEXT (#140): HTML decodes no entity in it, so `(() => 1)()`
  501. // served as `(() =&gt; 1)()` was a syntax error on a full page load (a client-built one
  502. // sets the text and never saw it). Text and values are written as they are, on one line;
  503. // only `</script` is broken (`<\/script`, the same string to the script), or the element
  504. // would end there.
  505. rawKids(&node, &page, &rows, &ctx) {
  506. let out = ''
  507. for (c of node.children) {
  508. if (c.k == 'text') { out = out + rawText(c.text) }
  509. else if (c.k == 'member' || c.k == 'field' || c.k == 'expr') { out = out + rawText(value(c, page, rows)) }
  510. else { out = out + html(c, page, rows, ctx, null) }
  511. }
  512. return out
  513. }
  514. rawText(s) {
  515. if (s == null) { return '' }
  516. return ('' + s).replaceAll('</script', '<\/script')
  517. }
  518. kidsHtml(&node, &page, &rows, &ctx, indent) {
  519. if (indent != null && blocky(node, ctx)) {
  520. return block(node.children, page, rows, ctx, indent + tab) + newline + indent
  521. }
  522. let out = ''
  523. for (c of node.children) { out = out + html(c, page, rows, ctx, null) }
  524. return out
  525. }
  526. // The HTML a reference's fill stands for, or null when the reference fills nothing
  527. // (a bare `Card`, or `Card { }`) — then the child's `slot` renders as the member it
  528. // is, which is nothing.
  529. //
  530. // COMPACT, whatever form the page is rendered in: this frame is the HOST's, and the
  531. // indentation of the line the child places `slot` on is decided inside the child,
  532. // one frame further down. Whitespace between elements is not content and the claim
  533. // walk steps ELEMENTS, so a fill that is written on one line is claimed the same.
  534. fillHtml(&node, &page, &rows, &ctx) {
  535. if (node.fill == null || node.fill.length == 0) { return null }
  536. return render(node.fill, page, rows, ctx, null)
  537. }
  538. // AN ELEMENT'S CHILDREN MINUS THE HANDLERS A REFERENCE OVERWROTE. COMPONENTS.md:757
  539. // — "a same-named event binding on the reference overwrites the child root's own": the
  540. // reference's `on click` REPLACES the child root's `on click`, it does not stand beside
  541. // it, so the child's own entry for that event is never bound on that element.
  542. withoutOns(&nodes, &ons) {
  543. let out = []
  544. for (n of nodes) {
  545. let overwritten = false
  546. for (o of ons) { if (n.k == 'on' && o.event == n.event) { overwritten = true } }
  547. if (!overwritten) { out.push(n) }
  548. }
  549. return out
  550. }
  551. // THE CLASSES A REFERENCE PUTS ON THE CHILD'S ROOT, appended to a class the child
  552. // BINDS (`button { class = tone }`): the bound value is only known at render, so the
  553. // extra classes ride beside it and every writer of that attribute appends them —
  554. // here, and in the browser's create and repaint. Before this the merge handled only a
  555. // LITERAL class, and a child root that bound its own came out with TWO class
  556. // attributes, of which a browser keeps the first — so the host's `#Child` class
  557. // silently did nothing (measured 2026-09-13 on press.hl's `button { class = tone }`).
  558. extraOf(a) {
  559. if (a.extra == null) { return '' }
  560. return ' ' + a.extra
  561. }
  562. // A composed child's ROOT elements carry the classes the host's `#Child` local rule
  563. // put on the reference: the child's tree is shared, so the roots are copied with
  564. // the class merged in, and the child's own tree is untouched.
  565. withRootClasses(&nodes, &classes) {
  566. if (classes == null || classes.length == 0) { return nodes }
  567. let out = []
  568. for (n of nodes) {
  569. if (n.k == 'el') {
  570. let attrs = []
  571. let merged = false
  572. for (a of n.attrs) {
  573. if (a.name == 'class' && a.text != null) { attrs.push({ name = 'class'; text = a.text + ' ' + joinClasses(classes); }) merged = true }
  574. else if (a.name == 'class') { attrs.push({ name = 'class'; member = a.member; ref = a.ref; extra = joinClasses(classes); }) merged = true }
  575. else { attrs.push(a) }
  576. }
  577. if (!merged) { attrs.push({ name = 'class'; text = joinClasses(classes); }) }
  578. out.push({ k = 'el'; tag = n.tag; key = n.key; path = n.path; attrs = attrs; children = n.children; site = n.site; })
  579. } else { out.push(n) }
  580. }
  581. return out
  582. }
  583. joinClasses(classes) {
  584. let out = ''
  585. for (c of classes) { out = out == '' ? c : out + ' ' + c }
  586. return out
  587. }
  588. // Does this element hold only elements (and control flow around them)? Then its
  589. // children may each take a line. A text or member child makes it inline. The
  590. // shell's `slot` counts as an element: the child page stands there as a block.
  591. blocky(&node, &ctx) {
  592. if (verbatimTags.includes(node.tag)) { return false }
  593. if (node.children.length == 0) { return false }
  594. for (c of node.children) {
  595. if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }
  596. if (c.k == 'member' && !(c.name == 'slot' && ctx.slot != null)) { return false }
  597. }
  598. return true
  599. }
  600. // Elements one per line at `indent`; `for` and `if` unfold into lines at the same
  601. // level. Anything else that appears here renders inline at the end of the run.
  602. block(&nodes, &page, &rows, &ctx, indent) {
  603. let out = ''
  604. for (n of nodes) {
  605. if (n.k == 'el') {
  606. out = out + newline + indent + html(n, page, rows, ctx, indent)
  607. } else if (n.k == 'component') {
  608. out = out + html(n, page, rows, ctx, indent)
  609. } else if (n.k == 'for') {
  610. let list = value(n.list, page, rows)
  611. if (list != null) {
  612. let ri = 0
  613. for (entry of list) {
  614. let inner = rows + {}
  615. inner[n.row] = entry
  616. out = out + block(n.body, page, inner, rowCtx(ctx, entry, ri), indent)
  617. ri = ri + 1
  618. }
  619. }
  620. } else if (n.k == 'if') {
  621. if (value(n.cond, page, rows)) { out = out + block(n.then, page, rows, ctx, indent) }
  622. else { out = out + block(n.other, page, rows, ctx, indent) }
  623. } else if (n.k == 'member' && n.name == 'slot' && ctx.slot != null) {
  624. out = out + newline + indent + ctx.slot
  625. } else if (n.k != 'on') {
  626. out = out + html(n, page, rows, ctx, indent)
  627. }
  628. }
  629. return out
  630. }
  631. // HTML of a whole View tree (a list of nodes), compact when `indent` is null
  632. render(&nodes, &page, &rows, &ctx, indent) {
  633. if (indent != null) { return block(nodes, page, rows, ctx, indent) }
  634. let out = ''
  635. for (n of nodes) { out = out + html(n, page, rows, ctx, null) }
  636. return out
  637. }

Branches

Latest commits

  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre
  • 9b0516fdgitoria#22: mark the tab underline functional (check-theme), chain E2E: serve/measure split, bring the lisbeth tab to frontmre
  • 19bc1df8gitoria#22: all repo pages under ONE layout level (components/repo.hl, hl:web D-CHAIN): a tab click replaces only the page in the slot; head and tab nav stay the same DOM nodesmre
  • 40658417tests/browser.mjs: wait for the page to be live (hydrated) before clicking Merge — a click on the server-rendered button before the client mounted was lost (flaky 'Clashing change' under load)mre