gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainf9b8f918Merge branch 'calendar-vendor-day61' into mainAtlasmain/plugins/web/viewserver.hl

13.0 KB

  1. // THE SERVER'S SIDE OF THE VIEW: what only the server's passes call (the element list, the implied
  2. // elements, names and classes, the compile step's text helpers). The browser never imports this file; it
  3. // carries view.hl, the readers both realms use (value, evalExpr, kidKey, rowKey, listKeys, refValue).
  4. // The server's HTML writer that once stood here (html, render, block) had no caller since the compile step
  5. // unrolls a View into steps; it is gone (W196).
  6. import HlwView from './view.hl'
  7. reader = new HlwView
  8. // THE HTML ELEMENTS. An entry whose key is one of these is that element; any other
  9. // key is a CUSTOM element and is written kebab-case (`postsList` → `<posts-list>`),
  10. // which is also what a Style rule of that name selects. This list is what §4 calls
  11. // "the compiler's own View element list": one list, so a tag rule in a styles file
  12. // and a tag in a View can never disagree.
  13. static tags = [
  14. 'a' 'abbr' 'address' 'article' 'aside' 'audio' 'b' 'bdi' 'bdo' 'blockquote' 'body' 'br' 'button'
  15. 'canvas' 'caption' 'cite' 'code' 'col' 'colgroup' 'data' 'datalist' 'dd' 'del' 'details' 'dfn'
  16. 'dialog' 'div' 'dl' 'dt' 'em' 'embed' 'fieldset' 'figcaption' 'figure' 'footer' 'form'
  17. 'h1' 'h2' 'h3' 'h4' 'h5' 'h6' 'head' 'header' 'hgroup' 'hr' 'html' 'i' 'iframe' 'img' 'input'
  18. 'ins' 'kbd' 'label' 'legend' 'li' 'link' 'main' 'map' 'mark' 'menu' 'meta' 'meter' 'nav'
  19. 'noscript' 'object' 'ol' 'optgroup' 'option' 'output' 'p' 'picture' 'pre' 'progress' 'q' 'rp'
  20. 'rt' 'ruby' 's' 'samp' 'script' 'search' 'section' 'select' 'slot' 'small' 'source' 'span'
  21. 'strong' 'style' 'sub' 'summary' 'sup' 'table' 'tbody' 'td' 'template' 'textarea' 'tfoot'
  22. 'th' 'thead' 'time' 'title' 'tr' 'track' 'u' 'ul' 'var' 'video' 'wbr' 'svg' 'path' 'circle'
  23. 'rect' 'line' 'polyline' 'polygon' 'g' 'text' 'use' 'defs' 'symbol' 'ellipse' 'stop' 'tspan'
  24. 'feBlend' 'feColorMatrix' 'feComposite' 'feFlood' 'feGaussianBlur' 'feMerge' 'feMergeNode'
  25. 'feOffset' 'feTurbulence' 'feDropShadow' 'feMorphology' 'feImage' 'feTile'
  26. 'feComponentTransfer' 'feFuncR' 'feFuncG' 'feFuncB' 'feFuncA' 'feConvolveMatrix'
  27. 'feDiffuseLighting' 'feSpecularLighting' 'feDisplacementMap' 'feDistantLight' 'fePointLight'
  28. 'feSpotLight' 'linearGradient' 'radialGradient' 'clipPath' 'textPath' 'foreignObject'
  29. 'animateMotion' 'animateTransform'
  30. ]
  31. // a form control with a `value` the app binds (a member or a field path), and no
  32. // autocomplete of the author's own
  33. boundValue(&node) {
  34. if (node.tag != 'input' && node.tag != 'textarea' && node.tag != 'select') { return false }
  35. let bound = false
  36. for (a of node.attrs) {
  37. if (a.name == 'autocomplete') { return false }
  38. if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }
  39. }
  40. return bound
  41. }
  42. // ---- THE ELEMENTS THE BROWSER'S PARSER INSERTS ----------------------------------
  43. // HTML has elements whose START TAG IS OPTIONAL: a `tr` written straight inside a
  44. // `table` is parsed into a `tbody` the parser creates, a `td` outside a `tr` gets both,
  45. // and a `col` gets a `colgroup`. The served tree and the PARSED tree have to be the same
  46. // tree — the claim walk pairs them element for element — so the tree carries what the
  47. // parser would insert and the author goes on writing `table { tr { td { … } } }`.
  48. // (Measured 2026-09-14 on demo-nested: 38 rows, 38 "claim: no element for tr under
  49. // TABLE", one per row; the fix in the app was to write the `tbody` by hand.)
  50. //
  51. // One row per (parent, child) pair the standard's optional-tag rules name. The walk
  52. // applies them REPEATEDLY, so a `td` under a `table` gains a `tbody` and then a `tr`
  53. // inside it — what the parser does, and not a table special case: a pair added to this
  54. // list is a pair the language then renders the way the browser will read it.
  55. static impliedElements = [
  56. { under = 'table' child = 'tr' wrap = 'tbody' }
  57. { under = 'table' child = 'td' wrap = 'tbody' }
  58. { under = 'table' child = 'th' wrap = 'tbody' }
  59. { under = 'table' child = 'col' wrap = 'colgroup' }
  60. { under = 'tbody' child = 'td' wrap = 'tr' }
  61. { under = 'tbody' child = 'th' wrap = 'tr' }
  62. { under = 'thead' child = 'td' wrap = 'tr' }
  63. { under = 'thead' child = 'th' wrap = 'tr' }
  64. { under = 'tfoot' child = 'td' wrap = 'tr' }
  65. { under = 'tfoot' child = 'th' wrap = 'tr' }
  66. ]
  67. // the container the parser would open for this child under this parent, or null
  68. impliedWrap(under, child) {
  69. if (child == null) { return null }
  70. for (r of impliedElements) { if (r.under == under && r.child == child) { return r.wrap } }
  71. return null
  72. }
  73. // THE TAG A NODE PUTS IN THE DOCUMENT: an element's own, and for a `for` or an `if` the
  74. // tag of the first element it renders — a region of `tr`s under a `table` needs the
  75. // `tbody` a bare `tr` needs, and it is the same rule that says so.
  76. firstTag(&n) {
  77. if (n == null) { return null }
  78. if (n.k == 'el') { return n.tag }
  79. if (n.k == 'for') { return firstTagIn(&n.body) }
  80. if (n.k == 'if') {
  81. let t = firstTagIn(&n.then)
  82. return t == null ? firstTagIn(&n.other) : t
  83. }
  84. return null
  85. }
  86. firstTagIn(&list) {
  87. if (list == null) { return null }
  88. for (n of list) {
  89. let t = firstTag(&n)
  90. if (t != null) { return t }
  91. }
  92. return null
  93. }
  94. // an element's children with those containers written out. A RUN of children that need
  95. // the same one SHARES it, because the parser opens one `tbody` and goes on putting rows
  96. // in it until something else closes it.
  97. implied(under, children, path, site) {
  98. let out = []
  99. let run = []
  100. let runWrap = null
  101. for (c of children) {
  102. let w = impliedWrap(under, firstTag(&c))
  103. if (w != runWrap && run.length > 0) {
  104. out.push(impliedNode(runWrap, run, path, site))
  105. run = []
  106. }
  107. runWrap = w
  108. if (w == null) { out.push(c) } else { run.push(c) }
  109. }
  110. if (run.length > 0) { out.push(impliedNode(runWrap, run, path, site)) }
  111. return out
  112. }
  113. // the node for a container nobody wrote: no attributes, no handlers, and the rule
  114. // applied again inside it (`table { td }` is `table > tbody > tr > td`)
  115. impliedNode(tag, children, path, site) {
  116. let here = path.slice(0)
  117. here.push(tag)
  118. return { k = 'el'; tag = tag; key = tag; path = here; attrs = []; children = implied(tag, children, here, site + '>' + tag); site = site + '>' + tag; }
  119. }
  120. static voidTags = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]
  121. // THE VERBATIM ELEMENTS: whitespace between their tags is CONTENT, not layout. A
  122. // textarea's text IS its value, and a `pre`, a `script` and a `style` show or run
  123. // exactly what stands there — so the readable form never indents inside them
  124. // (the creator, 2026-09-13: "textarea seems to show the indentation as value").
  125. static verbatimTags = [ 'textarea' 'pre' 'script' 'style' ]
  126. isTag(name) {
  127. return tags.includes(name)
  128. }
  129. // the tag the DOM gets: an element of the list keeps its spelling (SVG has camelCase
  130. // elements: `linearGradient`, `clipPath`, `foreignObject`), any other key is custom, kebab-case
  131. domTag(name) {
  132. return tags.includes(name) ? name : kebab(name)
  133. }
  134. // camelCase → kebab-case (the archived WebView.kebab, verbatim): a separator only
  135. // BETWEEN a lowercase letter or digit and an uppercase one; at position 0, after
  136. // another uppercase or after a sigil an uppercase simply lowercases, so `ChatForm`
  137. // is `chat-form` and `#Svg` is `#svg`. The tag written on a custom element and the
  138. // selector a Style rule emits both come through here, so they cannot disagree.
  139. static KEBAB_JOINERS = "-_#@"
  140. kebab(name) {
  141. let out = ''
  142. let i = 0
  143. let prev = ''
  144. while (i < name.length) {
  145. let c = name.charAt(i)
  146. let lower = c.toLowerCase()
  147. let between = prev != '' && prev == prev.toLowerCase() && KEBAB_JOINERS.indexOf(prev) < 0
  148. if (c != lower && between) { out = out + '-' + lower } else { out = out + lower }
  149. prev = c
  150. i = i + 1
  151. }
  152. return out
  153. }
  154. // THE TAG-PREFIX STRIP (archived WebView.className, verbatim): rule `headerMain`
  155. // referenced under `header` is class `main`; under any other tag it keeps its name.
  156. className(rule, tag) {
  157. if (rule.length <= tag.length) { return rule }
  158. if (!rule.startsWith(tag)) { return rule }
  159. let rest = rule.slice(tag.length)
  160. let head = rest.charAt(0)
  161. if (head == head.toLowerCase()) { return rule }
  162. return head.toLowerCase() + rest.slice(1)
  163. }
  164. // THE PER-FILE CLASS of a `#local` rule (archived WebView.localClass, verbatim):
  165. // four characters out of the file's project-relative key, so it is stable across
  166. // checkouts and a golden can pin it. Every local rule of one file shares it; the
  167. // element's tag in front of it keeps them apart in the sheet (`svg.ma31`).
  168. static LOCAL_KEY_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-"
  169. static LOCAL_LETTERS = "abcdefghijklmnopqrstuvwxyz"
  170. static LOCAL_ALPHA = "abcdefghijklmnopqrstuvwxyz0123456789"
  171. localClass(fileKey) {
  172. let h = 0
  173. let i = 0
  174. while (i < fileKey.length) {
  175. h = (h * 31 + LOCAL_KEY_CHARS.indexOf(fileKey.charAt(i)) + 1) % 1000003
  176. i = i + 1
  177. }
  178. let out = LOCAL_LETTERS.charAt(h % 26)
  179. let rest = (h - (h % 26)) / 26
  180. let j = 0
  181. while (j < 3) {
  182. out = out + LOCAL_ALPHA.charAt(rest % 36)
  183. rest = (rest - (rest % 36)) / 36
  184. j = j + 1
  185. }
  186. return out
  187. }
  188. // THE KEY OF ONE ROW'S CHILD: the component node's path plus the index of every
  189. // enclosing `for` iteration, which `ctx.rowKey` carries down the walk. Outside
  190. // every `for` the rowKey is empty and this is the plain path key.
  191. kidKeyIn(&path, &ctx) {
  192. return reader.kidKey(&path) + (ctx.rowKey != null ? ctx.rowKey : '')
  193. }
  194. // the walking context of one `for` iteration: the same slot and kids, one row deeper (`key`: listKeys' key of the row)
  195. rowCtx(&ctx, key) {
  196. let out = ctx + {}
  197. out.rowKey = (ctx.rowKey != null ? ctx.rowKey : '') + '#' + key
  198. return out
  199. }
  200. // HTML boolean attributes use presence in server markup and browser writes (#33, #302).
  201. static boolAttrs = [
  202. 'allowfullscreen' 'async' 'autofocus' 'autoplay' 'checked' 'controls' 'default' 'defer'
  203. 'disabled' 'formnovalidate' 'hidden' 'inert' 'ismap' 'itemscope' 'loop' 'multiple' 'muted'
  204. 'nomodule' 'novalidate' 'open' 'playsinline' 'readonly' 'required' 'reversed' 'selected'
  205. ]
  206. isBoolAttr(name) {
  207. return boolAttrs.includes(name)
  208. }
  209. // is a boolean attribute ON for this value? false, null, '' and 0 leave it off — what the
  210. // browser's own `!!v` says, so the server's markup and the client's write agree
  211. boolOn(val) {
  212. if (val == null || val == false || val == '') { return false }
  213. if (hlTypeName(val) == 'Number' && val == 0) { return false }
  214. return true
  215. }
  216. escape(s) {
  217. if (s == null) { return '' }
  218. // EVERY occurrence, not the first: `replace` stops after one, so a value with two
  219. // quotes in it ("a" "b") left the second one raw in the attribute it was written into
  220. return ('' + s).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;')
  221. }
  222. rawText(s) {
  223. if (s == null) { return '' }
  224. return ('' + s).replaceAll('</script', '<\/script').replaceAll('</style', '<\/style')
  225. }
  226. // THE CLASSES A REFERENCE PUTS ON THE CHILD'S ROOT, appended to a class the child
  227. // BINDS (`button { class = tone }`): the bound value is only known at render, so the
  228. // extra classes ride beside it and every writer of that attribute appends them —
  229. // here, and in the browser's create and repaint. Before this the merge handled only a
  230. // LITERAL class, and a child root that bound its own came out with TWO class
  231. // attributes, of which a browser keeps the first — so the host's `#Child` class
  232. // silently did nothing (measured 2026-09-13 on press.hl's `button { class = tone }`).
  233. extraOf(a) {
  234. if (a.extra == null) { return '' }
  235. return ' ' + a.extra
  236. }
  237. // A composed child's ROOT elements carry the classes the host's `#Child` local rule
  238. // put on the reference: the child's tree is shared, so the roots are copied with
  239. // the class merged in, and the child's own tree is untouched.
  240. withRootClasses(&nodes, &classes) {
  241. if (classes == null || classes.length == 0) { return nodes }
  242. let out = []
  243. for (n of nodes) {
  244. if (n.k == 'el') {
  245. let attrs = []
  246. let merged = false
  247. for (a of n.attrs) {
  248. if (a.name == 'class' && a.text != null) { attrs.push({ name = 'class'; text = a.text + ' ' + joinClasses(classes); }) merged = true }
  249. else if (a.name == 'class') { attrs.push({ name = 'class'; member = a.member; ref = a.ref; extra = joinClasses(classes); }) merged = true }
  250. else { attrs.push(a) }
  251. }
  252. if (!merged) { attrs.push({ name = 'class'; text = joinClasses(classes); }) }
  253. out.push({ k = 'el'; tag = n.tag; key = n.key; path = n.path; attrs = attrs; children = n.children; site = n.site; })
  254. } else { out.push(n) }
  255. }
  256. return out
  257. }
  258. joinClasses(classes) {
  259. let out = ''
  260. for (c of classes) { out = out == '' ? c : out + ' ' + c }
  261. return out
  262. }
  263. // Does this element hold only elements (and control flow around them)? Then its
  264. // children may each take a line. A text or member child makes it inline. The
  265. // shell's `slot` counts as an element: the child page stands there as a block.
  266. blocky(&node, &ctx) {
  267. if (verbatimTags.includes(node.tag)) { return false }
  268. if (node.children.length == 0) { return false }
  269. for (c of node.children) {
  270. if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }
  271. if (c.k == 'member' && !(c.name == 'slot' && ctx.slot != null)) { return false }
  272. }
  273. return true
  274. }

Branches

Latest commits

  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre