calendar
All repositories: gitoria
13.0 KB
// THE SERVER'S SIDE OF THE VIEW: what only the server's passes call (the element list, the implied// elements, names and classes, the compile step's text helpers). The browser never imports this file; it// carries view.hl, the readers both realms use (value, evalExpr, kidKey, rowKey, listKeys, refValue).// The server's HTML writer that once stood here (html, render, block) had no caller since the compile step// unrolls a View into steps; it is gone (W196).import HlwView from './view.hl'reader = new HlwView// THE HTML ELEMENTS. An entry whose key is one of these is that element; any other// key is a CUSTOM element and is written kebab-case (`postsList` → `<posts-list>`),// which is also what a Style rule of that name selects. This list is what §4 calls// "the compiler's own View element list": one list, so a tag rule in a styles file// and a tag in a View can never disagree.static tags = ['a' 'abbr' 'address' 'article' 'aside' 'audio' 'b' 'bdi' 'bdo' 'blockquote' 'body' 'br' 'button''canvas' 'caption' 'cite' 'code' 'col' 'colgroup' 'data' 'datalist' 'dd' 'del' 'details' 'dfn''dialog' 'div' 'dl' 'dt' 'em' 'embed' 'fieldset' 'figcaption' 'figure' 'footer' 'form''h1' 'h2' 'h3' 'h4' 'h5' 'h6' 'head' 'header' 'hgroup' 'hr' 'html' 'i' 'iframe' 'img' 'input''ins' 'kbd' 'label' 'legend' 'li' 'link' 'main' 'map' 'mark' 'menu' 'meta' 'meter' 'nav''noscript' 'object' 'ol' 'optgroup' 'option' 'output' 'p' 'picture' 'pre' 'progress' 'q' 'rp''rt' 'ruby' 's' 'samp' 'script' 'search' 'section' 'select' 'slot' 'small' 'source' 'span''strong' 'style' 'sub' 'summary' 'sup' 'table' 'tbody' 'td' 'template' 'textarea' 'tfoot''th' 'thead' 'time' 'title' 'tr' 'track' 'u' 'ul' 'var' 'video' 'wbr' 'svg' 'path' 'circle''rect' 'line' 'polyline' 'polygon' 'g' 'text' 'use' 'defs' 'symbol' 'ellipse' 'stop' 'tspan''feBlend' 'feColorMatrix' 'feComposite' 'feFlood' 'feGaussianBlur' 'feMerge' 'feMergeNode''feOffset' 'feTurbulence' 'feDropShadow' 'feMorphology' 'feImage' 'feTile''feComponentTransfer' 'feFuncR' 'feFuncG' 'feFuncB' 'feFuncA' 'feConvolveMatrix''feDiffuseLighting' 'feSpecularLighting' 'feDisplacementMap' 'feDistantLight' 'fePointLight''feSpotLight' 'linearGradient' 'radialGradient' 'clipPath' 'textPath' 'foreignObject''animateMotion' 'animateTransform']// a form control with a `value` the app binds (a member or a field path), and no// autocomplete of the author's ownboundValue(&node) {if (node.tag != 'input' && node.tag != 'textarea' && node.tag != 'select') { return false }let bound = falsefor (a of node.attrs) {if (a.name == 'autocomplete') { return false }if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }}return bound}// ---- THE ELEMENTS THE BROWSER'S PARSER INSERTS ----------------------------------// HTML has elements whose START TAG IS OPTIONAL: a `tr` written straight inside a// `table` is parsed into a `tbody` the parser creates, a `td` outside a `tr` gets both,// and a `col` gets a `colgroup`. The served tree and the PARSED tree have to be the same// tree — the claim walk pairs them element for element — so the tree carries what the// parser would insert and the author goes on writing `table { tr { td { … } } }`.// (Measured 2026-09-14 on demo-nested: 38 rows, 38 "claim: no element for tr under// TABLE", one per row; the fix in the app was to write the `tbody` by hand.)//// One row per (parent, child) pair the standard's optional-tag rules name. The walk// applies them REPEATEDLY, so a `td` under a `table` gains a `tbody` and then a `tr`// inside it — what the parser does, and not a table special case: a pair added to this// list is a pair the language then renders the way the browser will read it.static impliedElements = [{ under = 'table' child = 'tr' wrap = 'tbody' }{ under = 'table' child = 'td' wrap = 'tbody' }{ under = 'table' child = 'th' wrap = 'tbody' }{ under = 'table' child = 'col' wrap = 'colgroup' }{ under = 'tbody' child = 'td' wrap = 'tr' }{ under = 'tbody' child = 'th' wrap = 'tr' }{ under = 'thead' child = 'td' wrap = 'tr' }{ under = 'thead' child = 'th' wrap = 'tr' }{ under = 'tfoot' child = 'td' wrap = 'tr' }{ under = 'tfoot' child = 'th' wrap = 'tr' }]// the container the parser would open for this child under this parent, or nullimpliedWrap(under, child) {if (child == null) { return null }for (r of impliedElements) { if (r.under == under && r.child == child) { return r.wrap } }return null}// THE TAG A NODE PUTS IN THE DOCUMENT: an element's own, and for a `for` or an `if` the// tag of the first element it renders — a region of `tr`s under a `table` needs the// `tbody` a bare `tr` needs, and it is the same rule that says so.firstTag(&n) {if (n == null) { return null }if (n.k == 'el') { return n.tag }if (n.k == 'for') { return firstTagIn(&n.body) }if (n.k == 'if') {let t = firstTagIn(&n.then)return t == null ? firstTagIn(&n.other) : t}return null}firstTagIn(&list) {if (list == null) { return null }for (n of list) {let t = firstTag(&n)if (t != null) { return t }}return null}// an element's children with those containers written out. A RUN of children that need// the same one SHARES it, because the parser opens one `tbody` and goes on putting rows// in it until something else closes it.implied(under, children, path, site) {let out = []let run = []let runWrap = nullfor (c of children) {let w = impliedWrap(under, firstTag(&c))if (w != runWrap && run.length > 0) {out.push(impliedNode(runWrap, run, path, site))run = []}runWrap = wif (w == null) { out.push(c) } else { run.push(c) }}if (run.length > 0) { out.push(impliedNode(runWrap, run, path, site)) }return out}// the node for a container nobody wrote: no attributes, no handlers, and the rule// applied again inside it (`table { td }` is `table > tbody > tr > td`)impliedNode(tag, children, path, site) {let here = path.slice(0)here.push(tag)return { k = 'el'; tag = tag; key = tag; path = here; attrs = []; children = implied(tag, children, here, site + '>' + tag); site = site + '>' + tag; }}static voidTags = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]// THE VERBATIM ELEMENTS: whitespace between their tags is CONTENT, not layout. A// textarea's text IS its value, and a `pre`, a `script` and a `style` show or run// exactly what stands there — so the readable form never indents inside them// (the creator, 2026-09-13: "textarea seems to show the indentation as value").static verbatimTags = [ 'textarea' 'pre' 'script' 'style' ]isTag(name) {return tags.includes(name)}// the tag the DOM gets: an element of the list keeps its spelling (SVG has camelCase// elements: `linearGradient`, `clipPath`, `foreignObject`), any other key is custom, kebab-casedomTag(name) {return tags.includes(name) ? name : kebab(name)}// camelCase → kebab-case (the archived WebView.kebab, verbatim): a separator only// BETWEEN a lowercase letter or digit and an uppercase one; at position 0, after// another uppercase or after a sigil an uppercase simply lowercases, so `ChatForm`// is `chat-form` and `#Svg` is `#svg`. The tag written on a custom element and the// selector a Style rule emits both come through here, so they cannot disagree.static KEBAB_JOINERS = "-_#@"kebab(name) {let out = ''let i = 0let prev = ''while (i < name.length) {let c = name.charAt(i)let lower = c.toLowerCase()let between = prev != '' && prev == prev.toLowerCase() && KEBAB_JOINERS.indexOf(prev) < 0if (c != lower && between) { out = out + '-' + lower } else { out = out + lower }prev = ci = i + 1}return out}// THE TAG-PREFIX STRIP (archived WebView.className, verbatim): rule `headerMain`// referenced under `header` is class `main`; under any other tag it keeps its name.className(rule, tag) {if (rule.length <= tag.length) { return rule }if (!rule.startsWith(tag)) { return rule }let rest = rule.slice(tag.length)let head = rest.charAt(0)if (head == head.toLowerCase()) { return rule }return head.toLowerCase() + rest.slice(1)}// THE PER-FILE CLASS of a `#local` rule (archived WebView.localClass, verbatim):// four characters out of the file's project-relative key, so it is stable across// checkouts and a golden can pin it. Every local rule of one file shares it; the// element's tag in front of it keeps them apart in the sheet (`svg.ma31`).static LOCAL_KEY_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-"static LOCAL_LETTERS = "abcdefghijklmnopqrstuvwxyz"static LOCAL_ALPHA = "abcdefghijklmnopqrstuvwxyz0123456789"localClass(fileKey) {let h = 0let i = 0while (i < fileKey.length) {h = (h * 31 + LOCAL_KEY_CHARS.indexOf(fileKey.charAt(i)) + 1) % 1000003i = i + 1}let out = LOCAL_LETTERS.charAt(h % 26)let rest = (h - (h % 26)) / 26let j = 0while (j < 3) {out = out + LOCAL_ALPHA.charAt(rest % 36)rest = (rest - (rest % 36)) / 36j = j + 1}return out}// THE KEY OF ONE ROW'S CHILD: the component node's path plus the index of every// enclosing `for` iteration, which `ctx.rowKey` carries down the walk. Outside// every `for` the rowKey is empty and this is the plain path key.kidKeyIn(&path, &ctx) {return reader.kidKey(&path) + (ctx.rowKey != null ? ctx.rowKey : '')}// the walking context of one `for` iteration: the same slot and kids, one row deeper (`key`: listKeys' key of the row)rowCtx(&ctx, key) {let out = ctx + {}out.rowKey = (ctx.rowKey != null ? ctx.rowKey : '') + '#' + keyreturn out}// HTML boolean attributes use presence in server markup and browser writes (#33, #302).static boolAttrs = ['allowfullscreen' 'async' 'autofocus' 'autoplay' 'checked' 'controls' 'default' 'defer''disabled' 'formnovalidate' 'hidden' 'inert' 'ismap' 'itemscope' 'loop' 'multiple' 'muted''nomodule' 'novalidate' 'open' 'playsinline' 'readonly' 'required' 'reversed' 'selected']isBoolAttr(name) {return boolAttrs.includes(name)}// is a boolean attribute ON for this value? false, null, '' and 0 leave it off — what the// browser's own `!!v` says, so the server's markup and the client's write agreeboolOn(val) {if (val == null || val == false || val == '') { return false }if (hlTypeName(val) == 'Number' && val == 0) { return false }return true}escape(s) {if (s == null) { return '' }// EVERY occurrence, not the first: `replace` stops after one, so a value with two// quotes in it ("a" "b") left the second one raw in the attribute it was written intoreturn ('' + s).replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"')}rawText(s) {if (s == null) { return '' }return ('' + s).replaceAll('</script', '<\/script').replaceAll('</style', '<\/style')}// THE CLASSES A REFERENCE PUTS ON THE CHILD'S ROOT, appended to a class the child// BINDS (`button { class = tone }`): the bound value is only known at render, so the// extra classes ride beside it and every writer of that attribute appends them —// here, and in the browser's create and repaint. Before this the merge handled only a// LITERAL class, and a child root that bound its own came out with TWO class// attributes, of which a browser keeps the first — so the host's `#Child` class// silently did nothing (measured 2026-09-13 on press.hl's `button { class = tone }`).extraOf(a) {if (a.extra == null) { return '' }return ' ' + a.extra}// A composed child's ROOT elements carry the classes the host's `#Child` local rule// put on the reference: the child's tree is shared, so the roots are copied with// the class merged in, and the child's own tree is untouched.withRootClasses(&nodes, &classes) {if (classes == null || classes.length == 0) { return nodes }let out = []for (n of nodes) {if (n.k == 'el') {let attrs = []let merged = falsefor (a of n.attrs) {if (a.name == 'class' && a.text != null) { attrs.push({ name = 'class'; text = a.text + ' ' + joinClasses(classes); }) merged = true }else if (a.name == 'class') { attrs.push({ name = 'class'; member = a.member; ref = a.ref; extra = joinClasses(classes); }) merged = true }else { attrs.push(a) }}if (!merged) { attrs.push({ name = 'class'; text = joinClasses(classes); }) }out.push({ k = 'el'; tag = n.tag; key = n.key; path = n.path; attrs = attrs; children = n.children; site = n.site; })} else { out.push(n) }}return out}joinClasses(classes) {let out = ''for (c of classes) { out = out == '' ? c : out + ' ' + c }return out}// Does this element hold only elements (and control flow around them)? Then its// children may each take a line. A text or member child makes it inline. The// shell's `slot` counts as an element: the child page stands there as a block.blocky(&node, &ctx) {if (verbatimTags.includes(node.tag)) { return false }if (node.children.length == 0) { return false }for (c of node.children) {if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }if (c.k == 'member' && !(c.name == 'slot' && ctx.slot != null)) { return false }}return true}
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