gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb19c478bb19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mreb19c478b/plugins/web/compile.hl

59.7 KB

  1. // plugins/web/compile.hl — THE FRAMEWORK COMPILES EACH COMPONENT.
  2. //
  3. // Mission 313 (the creator, 15 Sep 14:30: "clientside interpreter + table against
  4. // component code per component, no tables needed"). The old hl:web ships ONE generic client
  5. // that walks a tree the seed carries: it pairs elements with nodes, asks a table which
  6. // members each element shows, asks `view.value` what each bound spot holds, and does it
  7. // again on every paint. hl:web ships the ANSWERS instead — this file writes each
  8. // component's own code, once, where the old hl:web would have walked.
  9. //
  10. // WHAT IS EMITTED, per component, beside the class `hlJs` compiled:
  11. //
  12. // v(c,m,o,host,i,rows,rk,fill,cr,opt) the component's View, unrolled: one
  13. // statement per element, per handler, per
  14. // bound spot. `cr` false CLAIMS the server's
  15. // DOM (take host.children[i], step on), `cr`
  16. // true CREATES it — the two walks the old hl:web
  17. // spells out separately, which differ only in
  18. // where an element comes from.
  19. // b["<for site>"] one `for` body — the row factory the keyed
  20. // region builds a row with.
  21. // t/e["<if site>"] an `if`'s two branches.
  22. // f["<reference site>"] the fragment this component writes into a
  23. // child's `slot` — built in THIS frame, which
  24. // is why it is this component's code.
  25. // p["<element site>"] the paint statements: `p` writes what one
  26. // member feeds (the old hl:web's paint(&m,s,name)),
  27. // `r` rewrites a row's element where the DOM
  28. // does not already hold it (rowPaint).
  29. //
  30. // The generated code calls a FIXED runtime (client.hl) for everything that is not this
  31. // component: the mount records, the keyed region diff, the binding edges, the
  32. // derivations, the socket, navigation. It never looks anything up in a table — the
  33. // names, the sites and the write sets are written into the statements.
  34. //
  35. // It is TEXT the framework produces, served from memory beside the module (WebFramework
  36. // `module`), never a JavaScript file under plugins/.
  37. import { newline, tab } from './view.hl'
  38. import HlwView from './view.hl'
  39. import HlwViewServer from './viewserver.hl'
  40. // ---- the emitted half --------------------------------------------------------------
  41. module(gen, key, nodes, fnTable, fills) {
  42. fns = [] // the sub-walks: row bodies, if branches, fills
  43. done = {}
  44. rowVars = []
  45. tbl = tableOf(gen, key) // what the language says about this file, read once
  46. regions = regionIndex(tbl) // a `for`'s list reads, an `if`'s condition reads
  47. // A SHELL'S VIEW IS A `body` ELEMENT and the document already has one: the walk runs
  48. // against document.body itself, so the root list is that element's children and the
  49. // element only takes the marks a region rebuild on it would need.
  50. let roots = nodes
  51. let bodySite = null
  52. if (nodes.length == 1 && nodes[0].k == 'el' && nodes[0].tag == 'body') {
  53. roots = nodes[0].children
  54. bodySite = nodes[0].site
  55. }
  56. let root = walkTop(key, roots)
  57. // THE NAMED-REGION FILLS this View's root writes (`side { … }`): each is a sub-walk of THIS
  58. // component (its members, its handlers), run by the browser into the region a level above holds
  59. let fillNames = '{'
  60. let fillConds = '{'
  61. if (fills != null) {
  62. for (fl of fills) {
  63. sub(key, fl.children, 'R', fl.site)
  64. fillNames = fillNames + (fillNames == '{' ? '' : ',') + str(fl.name) + ':' + str(fl.site)
  65. // a conditional fill (`if (x) { side { … } }`): the condition, read off the filling instance
  66. if (fl.cond != null) { fillConds = fillConds + (fillConds == '{' ? '' : ',') + str(fl.name) + ':function(inst,r){return ' + rawRead(fl.cond) + ';}' }
  67. }
  68. }
  69. fillNames = fillNames + '}'
  70. fillConds = fillConds + '}'
  71. if (bodySite != null) {
  72. root = root.replace('let r=rows;', 'let r=rows;await c.markHost(m,host,' + str(bodySite) + ');')
  73. }
  74. let src = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);'
  75. src = src + 'var C=(g.__hlC=g.__hlC||{});'
  76. // the element a claim takes or a create makes — the one shape both walks share; a create
  77. // inside an svg (or an svg itself) is made in the SVG namespace, as the parser makes it
  78. // THE PRELUDE, one per module: the element a claim takes or a create makes, and the
  79. // two reads. A read written out in full — `(r["title"]!=null?r["title"]:inst["title"])`
  80. // — is 45 bytes and a component's View holds dozens of them; named, it is 16. The
  81. // rule is the same rule (a `for` row variable in scope wins over a member of the
  82. // same name, and a field path walks into it), spelled once.
  83. // A claim also moves the host's CURSOR — the last node the walk took there — which is
  84. // where a text leaf and a region's mark are looked for next (client.hl `leafNode`,
  85. // `markAt`).
  86. // MISSION 505: the five helpers (A, S, X, RV, RF) are bound off the runtime text (`paintHelpers` below) instead of written
  87. // into every module
  88. src = src + 'var A=g.__hlP.A,S=g.__hlP.S,X=g.__hlP.X,RV=g.__hlP.RV,RF=g.__hlP.RF;'
  89. src = src + 'var B={},T={},E={},F={},P={},D={},R={};'
  90. // ONE FUNCTION PER LIST, however many sites reach it: a nested walk is written once
  91. // and named — emitting it per site made the reference app's home page 215 KB of the
  92. // same code over and over.
  93. let wi = 0
  94. for (f of fns) {
  95. wi = wi + 1
  96. let name = 'w' + wi
  97. src = src + 'var ' + name + '=' + f.src + ';'
  98. for (site of f.sites) { src = src + f.slot + '[' + str(site) + ']=' + name + ';' }
  99. }
  100. let paints = []
  101. collectPaints(&paints, roots)
  102. for (e of paints) { src = src + 'P[' + str(e.site) + ']={p:' + e.paint + ',r:' + e.row + '};' }
  103. src = src + 'C[' + str(key) + ']={v:' + root + ',b:B,t:T,e:E,f:F,p:P,d:D,r:R,rn:' + fillNames + ',rc:' + fillConds
  104. // THE ANSWERS A LOOKUP STILL NEEDS, and only those. A local event's write set stands
  105. // at its own listener and a region's names at its own region — written into the
  106. // call. These three are asked for by NAME at run time and cannot be: an inbound
  107. // frame names its event, a routine handed down names the member that holds it, and
  108. // a write set names the derivations that follow it. `on` is the one thing run FROM the
  109. // module's own scope: the language's instance-scoped handler (`on page.ev`, the instance's
  110. // own bus: runtime `hlInstanceBus`) with the event named at run time, which client.hl
  111. // `wireUp` registers for a page (#193). The bus class is read off the instance's own class
  112. // (`static __events__`): a module imports no `hlScopedBus` unless it writes an `on x.y`, and
  113. // a minified module renames `EventBus`.
  114. src = src + ',ev:' + eventMap() + ',mw:' + memberMap() + ',dv:' + derivList() + ',fn:' + fnMap(fnTable) + ',on:function(i,e,f){if(!Object.prototype.hasOwnProperty.call(i,"__instanceEvents__")){Object.defineProperty(i,"__instanceEvents__",{value:new (i.constructor.__events__.constructor)()});}i.__instanceEvents__.on(e,f);}};'
  115. return src + '})();' + newline
  116. }
  117. // MISSION 505: THE SHARED PRELUDE, once per page. The five helpers every module's paint text calls — the element a claim
  118. // takes or a create makes (A), the text of a value (S), a region's sub-walk (X), the two reads (RV, RF) — were written
  119. // into every module: 699 bytes, 25 times on the reference app's start page. They are appended to the runtime text the
  120. // framework serves (WebFramework `runtime`), as `globalThis.__hlP`, and a module binds them by name (`module` above):
  121. // every module imports the runtime first, so they are there when its paint text runs. The two texts must agree on the
  122. // names; this is the only place the helpers are written.
  123. paintHelpers() {
  124. let s = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);var P=(g.__hlP=g.__hlP||{});'
  125. s = s + 'P.A=function(cr,host,i,tag){if(cr){if(tag==="svg"||(host.namespaceURI==="http://www.w3.org/2000/svg"&&host.localName.toLowerCase()!=="foreignobject")){return document.createElementNS("http://www.w3.org/2000/svg",tag);}return document.createElement(tag);}var e=host.children[i];if(e!=null){host.__hlCur=e;}return e;};'
  126. s = s + 'P.S=function(v){return v==null?"":""+v;};'
  127. s = s + 'P.X=async function(t,r,q){return await g.__hlX(t,q,r);};'
  128. s = s + 'P.RV=function(r,q,n){return r[n]!=null?r[n]:q[n];};'
  129. s = s + 'P.RF=function(r,q,n,p){var v=P.RV(r,q,n);for(var k=0;k<p.length;k++){if(v==null)return null;v=v[p[k]];}return v;};'
  130. s = s + 'P.L=function(u){return import(u);};'
  131. return s + '})();'
  132. }
  133. tbl = null
  134. regions = {}
  135. // WHAT A FUNCTION VALUE WRITES, by the site it was made at (tickets #98, #99): the
  136. // module announces a function's return with its site, and the browser repaints this
  137. // set — the members it writes, closed over the methods it calls and the events it
  138. // emits, the same closure a handler's set gets. A function that writes nothing has
  139. // no entry.
  140. fnMap(fns) {
  141. let bySite = {}
  142. if (fns != null) {
  143. for (f of fns) {
  144. let names = closeWrites(&tbl, f.writes, f.reads)
  145. if (names.length > 0) { bySite[f.site] = names }
  146. }
  147. }
  148. return mapOf(bySite)
  149. }
  150. // what a DECLARED handler writes, by event: one entry per event name, unioned
  151. eventMap() {
  152. let byEvent = {}
  153. for (h of tbl.handlers) {
  154. if (!h.nested) {
  155. let have = byEvent[h.event] == null ? [] : byEvent[h.event]
  156. for (w of closeWrites(&tbl, h.writes, h.reads)) { if (!have.includes(w)) { have.push(w) } }
  157. byEvent[h.event] = have
  158. }
  159. }
  160. return mapOf(byEvent)
  161. }
  162. // A MEMBER HOLDING A ROUTINE: what calling it writes is what its initializer writes
  163. memberMap() {
  164. let byName = {}
  165. for (m of tbl.members) {
  166. if (m.nodes != null) { byName[m.name] = memberNames(m.nodes.writes) }
  167. }
  168. return mapOf(byName)
  169. }
  170. // EVERY INITIALIZER, IN DECLARATION ORDER, with the members it reads — the whole of
  171. // what a derivation needs; the class carries the computation itself as `__derive__`.
  172. // `srv` (written only when true, same rule as `isStatic` on a read — every byte here
  173. // ships to the browser) marks a SERVER REFERENCE SITE (COMPONENTS.md §9.1/§9.3): an
  174. // initializer that calls an imported class (`import Store from './store.hl'`, then
  175. // `Store.chatsOf(…)` — `hlDenotes`'s own `kind: 'class'`, not a second resolution).
  176. // It is evaluated per request, on the SERVER, and its value ships into the page as
  177. // state; `client.hl`'s `moved()` must never call it locally — routger's `conversations
  178. // = … ? store.chatsOf(session.user.id) : []` reached `hl:time`, which ships no client
  179. // half, the moment a session sync (0b17f65b) made `session` move in the browser and
  180. // `moved()` re-ran every derivation that reads it. A fresh value for a server
  181. // reference site ships in `sync` instead (WebFramework.hl `serverSyncNames`).
  182. derivList() {
  183. let src = '['
  184. let first = true
  185. for (d of tbl.derivations) {
  186. if (!first) { src = src + ',' }
  187. first = false
  188. src = src + '{name:' + str(d.name) + ',site:' + str(d.site) + ',reads:' + list(memberNames(d.reads))
  189. if (d.serverSite) { src = src + ',srv:true' }
  190. src = src + '}'
  191. }
  192. return src + ']'
  193. }
  194. // does this read list (RAW — hlDenotes's own kind per name, before `memberNames`
  195. // narrows it to members) reach an imported class or a braced static of one — the two
  196. // forms COMPONENTS.md §9.1/§9.3 calls "a call on an imported class" (`import Store
  197. // from './store.hl'`, `Store.noteRows()`, OR the form the maintained demos actually
  198. // use, `import { postRow } from './store.hl'`, `postRow(id)`)? See `derivList` above.
  199. serverSite(reads) {
  200. if (reads == null) { return false }
  201. for (r of reads) { if (r.kind == 'class' || r.kind == 'import') { return true } }
  202. return false
  203. }
  204. mapOf(byName) {
  205. let src = '{'
  206. let first = true
  207. for (k of byName.keys()) {
  208. if (!first) { src = src + ',' }
  209. first = false
  210. src = src + str(k) + ':' + list(byName[k])
  211. }
  212. return src + '}'
  213. }
  214. // the write set and the read set of the handler at this site, closed over the methods
  215. // it calls and the handlers it emits to — computed here, written into the listener
  216. handlerSets(site) {
  217. for (h of tbl.handlers) {
  218. if (h.nested && h.site == site) {
  219. return list(closeWrites(&tbl, h.writes, h.reads)) + ',' + list(closeReads(&tbl, h.reads))
  220. }
  221. }
  222. return '[],[]'
  223. }
  224. // the named regions an `if`'s branch fills (`if (x) { side { … } }`), as a JS list, `null` for none: the
  225. // browser places those regions again when the condition changes
  226. fillNamesIn(nodes) {
  227. let out = ''
  228. for (c of nodes) {
  229. if (c.k == 'if' && c.regionfill != null) { out = out + (out == '' ? '' : ',') + str(c.regionfill) }
  230. }
  231. return out == '' ? 'null' : '[' + out + ']'
  232. }
  233. regionNamesAt(site) {
  234. let names = regions[site]
  235. return list(names == null ? [] : names)
  236. }
  237. fns = []
  238. // ---- the walk, unrolled ------------------------------------------------------------
  239. // `top` marks the View's own root list: an element there is a COMPOSITION ROOT — a
  240. // reference above may have overwritten some of its events and put classes on it, which
  241. // is what `opt` carries (the old hl:web's rootOverwrites and withRootClasses).
  242. walk(key, nodes) {
  243. return plain(key, nodes)
  244. }
  245. // a list's walk
  246. plain(key, nodes) {
  247. let body = ''
  248. for (n of nodes) { body = body + node(key, n, false, false) }
  249. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  250. }
  251. // the View's own root list, whose elements are composition roots
  252. walkTop(key, nodes) {
  253. let body = ''
  254. for (n of nodes) { body = body + node(key, n, true, false) }
  255. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  256. }
  257. // a sub-walk, registered under its own site so the runtime can reach it by name
  258. // A SUB-WALK IS WRITTEN ONCE, however often the compile reaches its list.
  259. sub(key, nodes, slot, site) {
  260. if (done[slot + ' ' + site] != null) { return null }
  261. done[slot + ' ' + site] = true
  262. fns.push({ slot = slot; sites = [site]; src = walk(key, nodes); })
  263. return null
  264. }
  265. done = {}
  266. node(key, n, top, filterOns) {
  267. if (n.k == 'el') { return elNode(key, n, top) }
  268. if (n.k == 'text') { return 'if(cr){host.appendChild(document.createTextNode(' + str(n.text) + '));}else{await c.leafAt(host,false,i,null,' + str(n.text) + ');}' }
  269. if (n.k == 'on') {
  270. // A REFERENCE ABOVE MAY HAVE OVERWRITTEN THIS EVENT on the composition root:
  271. // the root's own handler for it is dropped and the reference's stands instead
  272. // (the old hl:web's withoutOns, which applies to the root element's direct children).
  273. let guard = filterOns ? 'if(!(opt&&opt.over&&opt.over.indexOf(' + str(n.event) + ')>=0)){' : '{'
  274. return guard + 'await c.onAt(m,host,' + str(n.event) + ',' + str(n.site) + ',rows,' + handlerSets(n.site) + ');}'
  275. }
  276. if (n.k == 'member' && n.name == 'slot') {
  277. // the SHELL's slot is where the route component hangs; a child's slot is the
  278. // fragment its host wrote, and the host's frame builds it
  279. return 'if(m.isShell){i=await c.slotShell(m,host,i,cr);}else if(fill!=null){i=await c.slotFill(m,o,host,i,fill,cr);}'
  280. }
  281. // A TEXT LEAF STANDING IN A LIST — an `if` branch, a `for` body — beside elements or
  282. // alone: its own text node, and a site of the member it reads (or of the row it
  283. // stands in), painted by rewriting that node.
  284. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') {
  285. let names = readNames(n)
  286. return 'await c.textAt(m,host,cr,async function(inst,r){return ' + textRead(n) + ';},' + list(names) + ',rows,rk);'
  287. }
  288. if (n.k == 'for') {
  289. // THE ROW VARIABLE IS IN SCOPE INSIDE THE BODY, and a read of it is the ROW's,
  290. // not a member of the instance — the language resolves it that way and the site
  291. // sets must say the same, or a member of the same name would paint the row.
  292. rowVars.push(n.row)
  293. sub(key, n.body, 'B', n.site)
  294. rowVars.pop()
  295. return 'i=await c.forAt(m,o,host,i,' + str(n.site) + ',' + str(n.row) + ',function(inst,r){return ' + rawRead(n.list) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ');'
  296. }
  297. if (n.k == 'if' && n.regionfill != null) { return '' }
  298. if (n.k == 'if' && n.region != null) {
  299. // A NAMED REGION: the default is this component's own sub-walk; what stands between the
  300. // region's marks is the default, or the fill a lower level wrote (client.hl `regionAt`)
  301. sub(key, n.then, 'D', n.site)
  302. return 'i=await c.namedRegionAt(m,o,host,i,' + str(n.site) + ',' + str(n.region) + ',rows,rk,fill,cr);'
  303. }
  304. if (n.k == 'if') {
  305. sub(key, n.then, 'T', n.site)
  306. sub(key, n.other, 'E', n.site)
  307. return 'i=await c.ifAt(m,o,host,i,' + str(n.site) + ',function(inst,r){return ' + rawRead(n.cond) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ',' + fillNamesIn(n.then) + ');'
  308. }
  309. if (n.k == 'component') {
  310. if (n.fill != null && n.fill.length > 0) { sub(key, n.fill, 'F', n.site) }
  311. return 'i=await c.kidAt(m,host,i,' + kidSpec(n) + ',rows,rk,fill,cr,opt);'
  312. }
  313. return ''
  314. }
  315. // ---- an element --------------------------------------------------------------------
  316. elNode(key, n, top) {
  317. let src = '{let el=A(cr,host,i,' + str(n.tag) + ');if(!cr){i=i+1;}'
  318. src = src + 'if(el==null){await c.acqFail(' + str(n.tag) + ',host);}else{'
  319. // the attributes, on the walk that BUILDS the element (a claim takes the server's)
  320. src = src + 'if(cr){' + createAttrs(n) + (top ? 'await c.rootClasses(el,opt);' : '') + 'host.appendChild(el);}'
  321. src = src + 'el.__hlRows=rows;el.__hlSite=' + str(n.site) + ';el.__hlKey=' + str(key) + ';'
  322. // the element's own named entries, for the literal a handler on it fires
  323. src = src + 'el.__hlLit=function(inst,r){return ' + litNamed(n) + ';};'
  324. let names = siteNames(n)
  325. let valueMember = 'null'
  326. for (a of n.attrs) { if (a.member != null && a.name == 'value') { valueMember = str(a.member) } }
  327. let sited = ''
  328. if (names.length > 0 || valueMember != 'null') {
  329. sited = 'await c.siteAt(m,el,' + list(names) + ',' + str(n.site) + ',' + valueMember + ',' + (n.tag == 'select' ? 'true' : 'false') + ',rows);'
  330. }
  331. let kids = ''
  332. // AN ELEMENT THAT HOLDS ONLY TEXT is painted whole (`textContent`, see the paints):
  333. // built, it gets that text as one node; claimed, the server's is taken as it stands
  334. let whole = textOf(n)
  335. if (whole != null) {
  336. kids = 'if(cr){host.appendChild(document.createTextNode(' + whole + '));}'
  337. for (c of n.children) { if (c.k == 'on') { kids = kids + node(key, c, false, top) } }
  338. }
  339. else if (mixed(n)) { kids = mixedKids(key, n, top) }
  340. else { for (c of n.children) { kids = kids + node(key, c, false, top) } }
  341. let inner = '{let host=el;let i=0;' + kids + '}'
  342. // A SELECT IS SITED AFTER ITS OPTIONS: the member decides which option stands, and
  343. // the read-back that `siteAt` does reports nothing before they exist.
  344. if (n.tag == 'select') { src = src + inner + (selectValue(n) == 'null' ? '' : 'if(cr){await c.applySelectAt(m,el,' + selectValue(n) + ');}') + sited }
  345. else { src = src + sited + inner }
  346. return src + '}}'
  347. }
  348. // A TEXT LEAF BESIDE AN ELEMENT OR A REGION (ticket #86 follow-up): `td { d.n if (…) {…} }`
  349. // cannot be painted through `textContent`, which would wipe the branch. Each RUN of
  350. // adjacent leaves is one text node, held on the element (`__hlLeaves`, by the run's
  351. // index) where the walk builds or claims it, and the paints rewrite that node alone.
  352. mixed(n) {
  353. if (textOf(n) != null) { return false }
  354. for (c of n.children) { if (isReadNode(c)) { return true } }
  355. return false
  356. }
  357. isLeaf(c) { return c.k == 'text' || isReadNode(c) }
  358. // a node that shows a value read at render time: a member, a field path, or an expression
  359. isReadNode(c) { return (c.k == 'member' || c.k == 'field' || c.k == 'expr') && c.name != 'slot' }
  360. // the members whose move repaints a read (`Style` and a `for` row variable are not members
  361. // of the instance), and the guard a paint writes for them
  362. readNames(c) {
  363. let out = []
  364. for (nm of (c.k == 'expr' ? c.names : [c.name])) {
  365. if (nm != 'Style' && !rowVars.includes(nm) && !out.includes(nm)) { out.push(nm) }
  366. }
  367. return out
  368. }
  369. guardOf(c) {
  370. let g = ''
  371. for (nm of readNames(c)) { g = g + (g == '' ? '' : '||') + 'n===' + str(nm) }
  372. return g
  373. }
  374. // the runs of adjacent leaves, in order; an `on` renders nothing and splits none
  375. runsOf(n) {
  376. let out = []
  377. let run = []
  378. for (c of n.children) {
  379. if (isLeaf(c)) { run.push(c) }
  380. else if (c.k != 'on') {
  381. if (run.length > 0) { out.push(run) }
  382. run = []
  383. }
  384. }
  385. if (run.length > 0) { out.push(run) }
  386. return out
  387. }
  388. runText(run) {
  389. let src = '""'
  390. for (c of run) { src = src + '+(' + (c.k == 'text' ? str(c.text) : textRead(c)) + ')' }
  391. return src
  392. }
  393. runFeeds(run) {
  394. for (c of run) { if (c.k != 'text') { return true } }
  395. return false
  396. }
  397. mixedKids(key, n, top) {
  398. let kids = ''
  399. let run = []
  400. let k = 0
  401. for (c of n.children) {
  402. if (isLeaf(c)) { run.push(c) }
  403. else {
  404. if (c.k != 'on' && run.length > 0) { kids = kids + leafRun(run, k) k = k + 1 run = [] }
  405. kids = kids + node(key, c, false, top)
  406. }
  407. }
  408. if (run.length > 0) { kids = kids + leafRun(run, k) }
  409. return kids
  410. }
  411. // EVERY CALL INTO THE CLIENT IS AWAITED: its methods are async in the browser, and one
  412. // not awaited runs its DOM work after the walk has gone on — a built leaf then lands
  413. // after the elements that follow it (ticket #104).
  414. leafRun(run, k) {
  415. if (!runFeeds(run)) { return 'if(cr){host.appendChild(document.createTextNode(' + runText(run) + '));}else{await c.leafAt(host,false,i,null,' + runText(run) + ');}' }
  416. return 'await c.leafAt(host,cr,i,' + k + ',' + runText(run) + ');'
  417. }
  418. // the attributes an element is BUILT with — a bound one written in, a literal one as it
  419. // stands. `value` is a property once the page is live and an attribute as the control's
  420. // default; a textarea has no value attribute at all and a select's value is an option.
  421. createAttrs(n) {
  422. let src = ''
  423. for (a of n.attrs) {
  424. if (isBool(a)) {
  425. src = src + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  426. } else if (nullable(a)) {
  427. src = src + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v!=null){el.setAttribute(' + str(a.name) + ',""+v);}}'
  428. } else {
  429. let rd = a.member != null ? readOf({ k = 'member'; name = a.member; }) : (a.ref != null ? readOf(a.ref) : str(a.text))
  430. src = src + '{let v=' + rd + ';'
  431. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  432. if (n.tag == 'select' && a.name == 'value') { src = src + '}' }
  433. else if (a.name == 'value') {
  434. src = src + 'if(el.value!=null){el.value=v;' + (n.tag == 'textarea' ? '' : 'el.setAttribute("value",v);') + '}else{el.setAttribute("value",v);}}'
  435. } else { src = src + 'el.setAttribute(' + str(a.name) + ',v);}' }
  436. }
  437. }
  438. if (boundValue(n)) { src = src + 'el.setAttribute("autocomplete","off");' }
  439. return src
  440. }
  441. // a bound attribute whose null read is NO attribute (#177): not `value` (a control's
  442. // value has its own rules), and not one carrying extra classes
  443. nullable(a) {
  444. return (a.member != null || a.ref != null) && a.name != 'value' && a.extra == null && !v.isBoolAttr(a.name)
  445. }
  446. // a BOUND boolean attribute — a literal one was decided at build (WebFramework `element`)
  447. isBool(a) {
  448. return (a.member != null || a.ref != null) && v.isBoolAttr(a.name)
  449. }
  450. // A BOUND BOOLEAN ATTRIBUTE, WRITTEN (ticket #33): set when the value is on, REMOVED when
  451. // it is off — the markup's rule (view.boolAttrs) — and the DOM property with it, because
  452. // once the page is live `checked` is the property and the attribute only its default.
  453. boolWrite(a, raw) {
  454. let prop = a.name == 'readonly' ? 'readOnly' : a.name
  455. return 'let on=!!' + raw + ';if(on){el.setAttribute(' + str(a.name) + ',"");}else if(el.removeAttribute){el.removeAttribute(' + str(a.name) + ');}if(' + str(prop) + ' in el&&el[' + str(prop) + ']!==on){el[' + str(prop) + ']=on;}'
  456. }
  457. // view.hl's `boundValue`, to the letter: a FORM CONTROL whose `value` reads a member or
  458. // a field, and not one the author gave an `autocomplete` of its own
  459. boundValue(n) {
  460. if (n.tag != 'input' && n.tag != 'textarea' && n.tag != 'select') { return false }
  461. let bound = false
  462. for (a of n.attrs) {
  463. if (a.name == 'autocomplete') { return false }
  464. if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }
  465. }
  466. return bound
  467. }
  468. selectValue(n) {
  469. for (a of n.attrs) {
  470. if (a.name == 'value') {
  471. if (a.member != null) { return readOf({ k = 'member'; name = a.member; }) }
  472. if (a.ref != null) { return readOf(a.ref) }
  473. return str(a.text)
  474. }
  475. }
  476. return 'null'
  477. }
  478. // the element's own entries as the literal sees them — its attributes by name, then the
  479. // `for` row variables in scope (the row rides on the value)
  480. litNamed(n) {
  481. let src = '{'
  482. let first = true
  483. for (a of n.attrs) {
  484. if (!first) { src = src + ',' }
  485. first = false
  486. let v = a.member != null ? rawRead({ k = 'member'; name = a.member; }) : (a.ref != null ? rawRead(a.ref) : str(a.text))
  487. src = src + str(a.name) + ':' + v
  488. }
  489. return src + '}'
  490. }
  491. // the reference's own description, written at its use site: what it binds, what it
  492. // overwrites, the classes the host's `#Child` rule puts on it
  493. kidSpec(n) {
  494. let src = '{key:' + str(n.key) + ',kid:' + str(kidKeyOf(n)) + ',site:' + str(n.site) + ',fill:' + ((n.fill != null && n.fill.length > 0) ? 'true' : 'false')
  495. src = src + ',bindings:['
  496. let first = true
  497. for (b of n.bindings) {
  498. if (!first) { src = src + ',' }
  499. first = false
  500. src = src + '{name:' + str(b.name) + ',member:' + (b.member == null ? 'null' : str(b.member))
  501. src = src + ',ref:' + (b.ref == null ? 'null' : 'function(inst,r){return ' + rawRead(b.ref) + ';}')
  502. src = src + ',refName:' + (b.ref == null ? 'null' : str(b.ref.name))
  503. src = src + ',text:' + (b.text == null ? 'null' : 'true') + ',value:' + (b.text == null ? 'null' : refLiteral(b)) + '}'
  504. }
  505. src = src + '],ons:['
  506. first = true
  507. for (o of n.ons) {
  508. if (!first) { src = src + ',' }
  509. first = false
  510. src = src + '{event:' + str(o.event) + ',site:' + str(o.site) + ',sets:[' + handlerSets(o.site) + ']}'
  511. }
  512. src = src + '],classes:' + list(n.classes == null ? [] : n.classes) + '}'
  513. return src
  514. }
  515. // view.hl's kidKey: the reference's path, joined — the key the server mounted it under
  516. kidKeyOf(n) {
  517. let out = ''
  518. for (p of n.path) { out = out + '/' + p }
  519. return out
  520. }
  521. // the value a literal binding carries — view.refValue, folded at compile time
  522. refLiteral(b) {
  523. if (b.kind == 'folded') { return jsValue(b.value) }
  524. if (b.kind == 'number') { return '' + b.text }
  525. if (b.kind == 'boolean') { return b.text == 'true' ? 'true' : 'false' }
  526. if (b.kind == 'null_literal') { return 'null' }
  527. return str(b.text)
  528. }
  529. jsValue(v) {
  530. if (v == null) { return 'null' }
  531. if (hlTypeName(v) == 'String') { return str(v) }
  532. if (hlTypeName(v) == 'Boolean') { return v ? 'true' : 'false' }
  533. if (hlTypeName(v) == 'Number') { return '' + v }
  534. return JSON.stringify(v)
  535. }
  536. // ---- the site set: what this element SHOWS ------------------------------------------
  537. // The old hl:web asked the module's table which members the element at this site reads. The
  538. // answer is a fact about the View, so it is written in: the members its bound
  539. // attributes and its text leaves name. `Style` is folded into a class name at build and
  540. // the shell's `slot` is swapped by navigation — neither is ever painted, and neither is
  541. // a member read that reaches here (a `for` row variable resolves to its row).
  542. siteNames(n) {
  543. let out = []
  544. for (a of n.attrs) {
  545. if (a.member != null && a.member != 'Style' && !rowVars.includes(a.member) && !out.includes(a.member)) { out.push(a.member) }
  546. // A FIELD OF A MEMBER (`value = f.title`, ticket #93) is a read of the member:
  547. // a write to `f.title`, or a new `f`, moves `f`, and this element repaints
  548. if (a.ref != null && a.ref.name != 'Style' && !rowVars.includes(a.ref.name) && !out.includes(a.ref.name)) { out.push(a.ref.name) }
  549. }
  550. for (c of n.children) {
  551. if (isReadNode(c)) {
  552. for (nm of readNames(c)) { if (!out.includes(nm)) { out.push(nm) } }
  553. }
  554. }
  555. return out
  556. }
  557. rowVars = []
  558. // ---- the paints ---------------------------------------------------------------------
  559. collectPaints(&out, nodes) {
  560. for (n of nodes) {
  561. if (n.k == 'el') {
  562. let paint = paintFn(n)
  563. let row = rowFn(n)
  564. if (paint != null || row != 'null') {
  565. out.push({ site = n.site; paint = paint == null ? 'null' : paint; row = row; })
  566. }
  567. collectPaints(&out, n.children)
  568. } else if (n.k == 'for') { collectPaints(&out, n.body) }
  569. else if (n.k == 'if') { collectPaints(&out, n.then) collectPaints(&out, n.other) }
  570. else if (n.k == 'component') { if (n.fill != null) { collectPaints(&out, n.fill) } }
  571. }
  572. return null
  573. }
  574. // `paint(&m, s, name)`, compiled: the bound attributes under the member each reads, and
  575. // the text where the member that moved stands among the leaves.
  576. paintFn(n) {
  577. let body = ''
  578. for (a of n.attrs) {
  579. if (a.member != null) {
  580. body = body + 'if(n===' + str(a.member) + '){' + attrWrite(n, a, readOf({ k = 'member'; name = a.member; })) + '}'
  581. } else if (a.ref != null) {
  582. // a field of a member paints when the MEMBER moves (ticket #93)
  583. body = body + 'if(n===' + str(a.ref.name) + '){' + attrWrite(n, a, readOf(a.ref)) + '}'
  584. }
  585. }
  586. let text = textOf(n)
  587. if (text != null) {
  588. let guard = ''
  589. for (c of n.children) {
  590. if (isReadNode(c)) {
  591. let g = guardOf(c)
  592. if (g != '') {
  593. if (guard != '') { guard = guard + '||' }
  594. guard = guard + g
  595. }
  596. }
  597. }
  598. if (guard != '') { body = body + 'if(' + guard + '){el.textContent=' + text + ';}' }
  599. } else if (mixed(n)) {
  600. let k = 0
  601. for (run of runsOf(n)) {
  602. let guard = ''
  603. for (c of run) {
  604. if (c.k != 'text') {
  605. let g = guardOf(c)
  606. if (g != '') {
  607. if (guard != '') { guard = guard + '||' }
  608. guard = guard + g
  609. }
  610. }
  611. }
  612. if (guard != '') { body = body + 'if((' + guard + ')&&el.__hlLeaves&&el.__hlLeaves[' + k + ']){el.__hlLeaves[' + k + '].data=' + runText(run) + ';}' }
  613. k = k + 1
  614. }
  615. }
  616. if (body == '') { return null }
  617. return 'async function(el,inst,r,n){' + body + '}'
  618. }
  619. // `rowPaint(&m, el)`, compiled: every bound spot, written only where the DOM does not
  620. // already hold it — which is why a push into 2000 rows costs the 1999 nothing.
  621. rowFn(n) {
  622. let body = ''
  623. for (a of n.attrs) {
  624. if (isBool(a)) {
  625. body = body + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  626. } else if (nullable(a)) {
  627. body = body + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){if(el.hasAttribute(' + str(a.name) + ')){el.removeAttribute(' + str(a.name) + ');}}else{v=""+v;if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}}}'
  628. } else if (a.member != null || a.ref != null) {
  629. let one = 'let v=' + readOf(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';'
  630. if (a.extra != null) { one = one + 'v=v+" "+' + str(a.extra) + ';' }
  631. if (n.tag == 'select' && a.name == 'value') { one = one + 'if(el.value!==v){el.value=v;}' }
  632. else {
  633. one = one + 'if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}'
  634. if (a.name == 'value') { one = one + 'if(el.value!=null&&el.value!==v){el.value=v;}' }
  635. }
  636. body = body + '{' + one + '}'
  637. }
  638. }
  639. let text = textOf(n)
  640. let feeds = false
  641. for (c of n.children) { if (isReadNode(c)) { feeds = true } }
  642. if (text != null && feeds) { body = body + '{let t=' + text + ';if(el.textContent!==t){el.textContent=t;}}' }
  643. if (text == null && feeds) {
  644. let k = 0
  645. for (run of runsOf(n)) {
  646. if (runFeeds(run)) { body = body + '{let x=el.__hlLeaves&&el.__hlLeaves[' + k + '];let t=' + runText(run) + ';if(x&&x.data!==t){x.data=t;}}' }
  647. k = k + 1
  648. }
  649. }
  650. if (body == '') { return 'null' }
  651. return 'async function(el,inst,r){' + body + '}'
  652. }
  653. attrWrite(n, a, v) {
  654. if (isBool(a)) { return boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) }
  655. if (nullable(a)) { return 'let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){el.removeAttribute(' + str(a.name) + ');}else{el.setAttribute(' + str(a.name) + ',""+v);}' }
  656. let src = 'let v=' + v + ';'
  657. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  658. if (n.tag == 'select' && a.name == 'value') { return src + 'el.value=v;' }
  659. src = src + 'el.setAttribute(' + str(a.name) + ',v);'
  660. if (a.name == 'value') { src = src + 'if(el.value!=null){el.value=v;}' }
  661. return src
  662. }
  663. textOf(n) {
  664. let parts = []
  665. let content = 0
  666. let feeds = false
  667. for (c of n.children) {
  668. if (c.k != 'on') {
  669. content = content + 1
  670. if (c.k == 'text') { parts.push(str(c.text)) }
  671. else if (isReadNode(c)) { parts.push(textRead(c)) feeds = true }
  672. }
  673. }
  674. if (!feeds) { return null }
  675. if (parts.length != content) { return null }
  676. let src = '""'
  677. for (p of parts) { src = src + '+(' + p + ')' }
  678. return src
  679. }
  680. // ---- a read, written in ---------------------------------------------------------------
  681. // `view.value`'s own rule as an expression: a `for` row variable in scope wins over a
  682. // member of the same name, and a field path walks into it. `readOf` answers the STRING
  683. // the DOM takes; `rawRead` the value itself (a binding, a list, a condition).
  684. readOf(node) { return '(""+' + rawRead(node) + ')' }
  685. // A READ SHOWN AS TEXT: null is no text, as the server writes it (view.hl `escape`)
  686. textRead(node) { return 'S(' + rawRead(node) + ')' }
  687. rawRead(node) {
  688. if (node == null) { return 'null' }
  689. if (node.k == 'text') { return node.kind == 'folded' && hlTypeName(node.value) == 'Hybrid' ? JSON.stringify(node.value) : str(node.text) }
  690. if (node.k == 'expr') { return '(await X(' + JSON.stringify(node.x) + ',r,inst))' }
  691. if (node.k != 'field') { return 'RV(r,inst,' + str(node.name) + ')' }
  692. return 'RF(r,inst,' + str(node.name) + ',' + list(node.path) + ')'
  693. }
  694. list(names) {
  695. let src = '['
  696. let first = true
  697. for (n of names) {
  698. if (!first) { src = src + ',' }
  699. first = false
  700. src = src + str(n)
  701. }
  702. return src + ']'
  703. }
  704. // a JavaScript string literal — JSON's escaping is a subset of JavaScript's, so a
  705. // source text's quotes, newlines and backslashes survive into the statement unchanged
  706. str(s) {
  707. if (s == null) { return '""' }
  708. return JSON.stringify('' + s)
  709. }
  710. // ---- WHAT THE LANGUAGE SAYS ABOUT THIS FILE, read HERE and written into the code ----
  711. // The old hl:web shipped the language's answers to the browser as data: `hlJs` writes each file's
  712. // members, handlers and methods — every node of every initializer, with the names it
  713. // reads — into the module, and the client reduces that table on every boot. The answers
  714. // are facts about the source, so this file asks for them once, at compile time, and
  715. // writes the RESULT into the statements: a handler's write set stands at the listener
  716. // that needs it, a region's names at the region, the derivations as a list of what to
  717. // re-run. The module carries no table at all (WebFramework `module` drops the one the
  718. // emitter writes).
  719. //
  720. // The reflection is the framework's own analysis generation — the same `gen` the View
  721. // trees come from. Nothing starts a second one: a handle is only valid inside the
  722. // generation that made it.
  723. tableOf(gen, key) {
  724. let members = []
  725. let derivations = []
  726. let handlers = []
  727. let methods = []
  728. for (m of hlMembers(gen, key)) {
  729. let entry = { name = m.name; nodes = null; }
  730. if (m.hasValue) {
  731. let n = syntaxTree(gen, key, m.node)
  732. entry.nodes = n
  733. derivations.push({ name = m.name; site = n.site; reads = n.reads; serverSite = serverSite(browserReads(gen, n.reads)); })
  734. nestedHandlers(&handlers, n)
  735. }
  736. members.push(entry)
  737. }
  738. for (h of hlEvents(gen, key).handles) {
  739. let n = syntaxTree(gen, key, h.node)
  740. handlers.push({ event = h.event; site = n.site; reads = n.reads; writes = n.writes; nested = false; })
  741. }
  742. for (mm of hlMethods(gen, key)) {
  743. if (!mm.inlineHandler) {
  744. let n = syntaxTree(gen, key, mm.node)
  745. methods.push({ name = mm.name; reads = n.reads; writes = n.writes; })
  746. }
  747. }
  748. // A SERVER REFERENCE SITE IS ONE THROUGH A LOCAL HELPER TOO (#121): an initializer
  749. // that calls a method or static of this class which calls the import still reaches
  750. // the server only, so it is never re-derived in the browser either.
  751. let post = []
  752. for (d of derivations) {
  753. post.push({ name = d.name; site = d.site; reads = d.reads; serverSite = d.serverSite || reachesServerSite(gen, &members, &methods, d.reads); })
  754. }
  755. return { members = members; derivations = post; handlers = handlers; methods = methods; }
  756. }
  757. // AN IMPORTED STATIC FUNCTION THAT TOUCHES NOTHING BUT ITS OWN PARAMETERS IS NOT A SERVER
  758. // REFERENCE (#168): `imported = twice(n)` with `import { twice } from './lib.hl'` ships
  759. // with the page module (a const beside the class) and computes the same in the browser,
  760. // so the member is re-derived there when `n` moves. A braced import whose body reads a
  761. // class, another import, a static or a member stays a server site: the browser's copy
  762. // of that state is not the server's.
  763. browserReads(gen, reads) {
  764. let out = []
  765. if (reads == null) { return out }
  766. for (r of reads) {
  767. if (!(r.kind == 'import' && r.key != null && pureImport(gen, r))) { out.push(r) }
  768. }
  769. return out
  770. }
  771. pureImport(gen, r) {
  772. for (m of hlMembers(gen, r.key)) {
  773. if (m.name == r.name && m.isStatic == true && m.hasValue) {
  774. let n = syntaxTree(gen, r.key, m.node)
  775. if (n == null || n.reads == null) { return false }
  776. for (x of n.reads) {
  777. if (x.kind != 'local' && x.kind != 'none' && x.kind != 'row') { return false }
  778. }
  779. return true
  780. }
  781. }
  782. return false
  783. }
  784. // does a read list reach an imported class THROUGH this class's own methods and statics,
  785. // transitively — the walk of `closeReads`, over the helpers a derivation calls
  786. reachesServerSite(gen, &members, &methods, reads) {
  787. let queue = []
  788. if (reads != null) {
  789. for (r of reads) {
  790. if (r.kind == 'method' || (r.kind == 'member' && r.isStatic == true)) { queue.push(r.kind + ' ' + r.name) }
  791. }
  792. }
  793. let seen = {}
  794. while (queue.length > 0) {
  795. let at = queue.shift()
  796. if (seen[at] == null) {
  797. seen[at] = true
  798. let sp = at.indexOf(' ')
  799. let kind = at.slice(0, sp)
  800. let name = at.slice(sp + 1)
  801. let hop = []
  802. if (kind == 'method') { for (mm of methods) { if (mm.name == name) { hop = mm.reads } } }
  803. else { for (mb of members) { if (mb.name == name && mb.nodes != null) { hop = nodeReads(mb.nodes) } } }
  804. if (serverSite(browserReads(gen, hop))) { return true }
  805. for (r of hop) {
  806. if (r.kind == 'method' || (r.kind == 'member' && r.isStatic == true)) { queue.push(r.kind + ' ' + r.name) }
  807. }
  808. }
  809. }
  810. return false
  811. }
  812. // A NESTED `on` IS A DOM HANDLER, filed under its own site — the id the View node
  813. // carries. Its body is not the literal's syntax, so the node answers for it and the
  814. // walk stops there.
  815. nestedHandlers(&into, n) {
  816. if (n == null) { return null }
  817. if (n.tag == 'on_statement') {
  818. into.push({ event = n.event; site = n.site; reads = n.reads; writes = n.writes; nested = true; })
  819. return null
  820. }
  821. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  822. if (c != null) { nestedHandlers(&into, c) }
  823. }
  824. for (l of [n.entries, n.args, n.elements]) {
  825. if (l != null) { for (c of l) { nestedHandlers(&into, c) } }
  826. }
  827. return null
  828. }
  829. // the site with its file's base name: everything after the last '/'. The path part
  830. // is not "up to the first ':'" — a package key has a colon of its own
  831. // ('hl:markdown/Markdown.hl:24:3'), and that reading left a package component's
  832. // sites unshortened, so its regions found no reads and never repainted (#111)
  833. shortSite(site) {
  834. if (site == null) { return null }
  835. let cut = site.lastIndexOf('/')
  836. if (cut < 0) { return site }
  837. return site.slice(cut + 1)
  838. }
  839. // the syntax of one node, recursively — hl:core/AST's `tree`, read off the framework's
  840. // own generation instead of starting one of its own
  841. syntaxTree(gen, key, node) {
  842. let n = hlSyntax(gen, key, node)
  843. if (n == null) { return null }
  844. // A SITE IS NAMED BY THE FILE'S BASE NAME. The reflection answers with the project
  845. // key ('components/sort_list.hl:77:26'); the View tree, the emitter's own
  846. // `__derive__` branches and every site this framework writes use the base name
  847. // ('sort_list.hl:77:26'). One spelling, or a lookup by site finds nothing.
  848. let out = { tag = n.tag; site = shortSite(n.site); reads = n.reads; writes = n.writes; }
  849. if (n.tag == 'object_expression') {
  850. let kids = []
  851. for (h of n.entries) { kids.push(syntaxTree(gen, key, h)) }
  852. out.entries = kids
  853. } else if (n.tag == 'object_property') {
  854. out.key = n.key
  855. out.value = syntaxTree(gen, key, n.value)
  856. } else if (n.tag == 'view_for') {
  857. out.list = syntaxTree(gen, key, n.list)
  858. out.body = syntaxTree(gen, key, n.body)
  859. } else if (n.tag == 'view_if') {
  860. out.condition = syntaxTree(gen, key, n.condition)
  861. out.consequent = syntaxTree(gen, key, n.consequent)
  862. out.alternate = syntaxTree(gen, key, n.alternate)
  863. } else if (n.tag == 'on_statement') {
  864. out.event = n.event
  865. } else if (n.tag == 'member_expression') {
  866. out.object = syntaxTree(gen, key, n.object)
  867. out.property = syntaxTree(gen, key, n.property)
  868. } else if (n.tag == 'call_expression') {
  869. out.callee = syntaxTree(gen, key, n.callee)
  870. let args = []
  871. for (h of n.args) { args.push(syntaxTree(gen, key, h)) }
  872. out.args = args
  873. } else if (n.tag == 'binary_expression') {
  874. out.left = syntaxTree(gen, key, n.left)
  875. out.right = syntaxTree(gen, key, n.right)
  876. } else if (n.tag == 'unary_expression') {
  877. out.operand = syntaxTree(gen, key, n.operand)
  878. } else if (n.tag == 'conditional_expression') {
  879. out.condition = syntaxTree(gen, key, n.condition)
  880. out.consequent = syntaxTree(gen, key, n.consequent)
  881. out.alternate = syntaxTree(gen, key, n.alternate)
  882. } else if (n.tag == 'array_expression') {
  883. let els = []
  884. for (h of n.elements) { els.push(syntaxTree(gen, key, h)) }
  885. out.elements = els
  886. }
  887. return out
  888. }
  889. // ---- the reductions the browser used to make on every boot --------------------------
  890. // A `for`'s names are what its list reads, an `if`'s what its condition reads — filed
  891. // under the region's own site.
  892. regionIndex(t) {
  893. let idx = {}
  894. for (m of t.members) { if (m.nodes != null) { indexRegions(&idx, m.nodes) } }
  895. return idx
  896. }
  897. indexRegions(&idx, n) {
  898. if (n == null) { return null }
  899. if (n.tag == 'view_for') {
  900. idx[n.site] = memberNames(nodeReads(n.list))
  901. indexRegions(&idx, n.body)
  902. return null
  903. }
  904. if (n.tag == 'view_if') {
  905. idx[n.site] = memberNames(nodeReads(n.condition))
  906. indexRegions(&idx, n.consequent)
  907. indexRegions(&idx, n.alternate)
  908. return null
  909. }
  910. if (n.tag == 'on_statement') { return null }
  911. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  912. if (c != null) { indexRegions(&idx, c) }
  913. }
  914. for (l of [n.entries, n.args, n.elements]) {
  915. if (l != null) { for (c of l) { indexRegions(&idx, c) } }
  916. }
  917. return null
  918. }
  919. // the member reads of a read list — the language resolved every name, so this is a
  920. // filter and not a second resolution
  921. memberNames(reads) {
  922. let out = []
  923. if (reads == null) { return out }
  924. for (r of reads) {
  925. if (r.kind == 'member' && r.isStatic != true && !out.includes(r.name)) { out.push(r.name) }
  926. }
  927. return out
  928. }
  929. nodeReads(n) {
  930. if (n == null) { return [] }
  931. if (n.reads != null) { return n.reads }
  932. let out = []
  933. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  934. if (c != null) { for (r of nodeReads(c)) { out.push(r) } }
  935. }
  936. for (l of [n.entries, n.args, n.elements]) {
  937. if (l != null) { for (c of l) { for (r of nodeReads(c)) { out.push(r) } } }
  938. }
  939. return out
  940. }
  941. // A ROUTINE'S WRITES, PLUS THE WRITES OF EVERYTHING IT REACHES — the method it calls
  942. // and the handler it emits to, transitively. Both are READS the language resolved, so
  943. // this is a walk of its answer and never a guess.
  944. closeWrites(&t, writes, reads) {
  945. let out = memberNames(writes)
  946. let queue = []
  947. reached(&queue, reads)
  948. let seen = {}
  949. while (queue.length > 0) {
  950. let at = queue.shift()
  951. if (seen[at] == null) {
  952. seen[at] = true
  953. let sp = at.indexOf(' ')
  954. let kind = at.slice(0, sp)
  955. let name = at.slice(sp + 1)
  956. for (mm of t.methods) {
  957. if (kind == 'method' && mm.name == name) {
  958. for (w of memberNames(mm.writes)) { if (!out.includes(w)) { out.push(w) } }
  959. reached(&queue, mm.reads)
  960. }
  961. }
  962. for (h of t.handlers) {
  963. if (kind == 'handler' && !h.nested && h.event == name) {
  964. for (w of memberNames(h.writes)) { if (!out.includes(w)) { out.push(w) } }
  965. reached(&queue, h.reads)
  966. }
  967. }
  968. for (mb of t.members) {
  969. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  970. for (w of memberNames(mb.nodes.writes)) { if (!out.includes(w)) { out.push(w) } }
  971. reached(&queue, nodeReads(mb.nodes))
  972. }
  973. }
  974. }
  975. }
  976. return out
  977. }
  978. // the mirror: a handler's reads plus the reads of everything it reaches — the
  979. // candidates for a routine a host handed down, whose writes only the host's table names
  980. closeReads(&t, reads) {
  981. let out = memberNames(reads)
  982. let queue = []
  983. reached(&queue, reads)
  984. let seen = {}
  985. while (queue.length > 0) {
  986. let at = queue.shift()
  987. if (seen[at] == null) {
  988. seen[at] = true
  989. let sp = at.indexOf(' ')
  990. let kind = at.slice(0, sp)
  991. let name = at.slice(sp + 1)
  992. for (mm of t.methods) {
  993. if (kind == 'method' && mm.name == name) {
  994. for (r of memberNames(mm.reads)) { if (!out.includes(r)) { out.push(r) } }
  995. reached(&queue, mm.reads)
  996. }
  997. }
  998. for (h of t.handlers) {
  999. if (kind == 'handler' && !h.nested && h.event == name) {
  1000. for (r of memberNames(h.reads)) { if (!out.includes(r)) { out.push(r) } }
  1001. reached(&queue, h.reads)
  1002. }
  1003. }
  1004. for (mb of t.members) {
  1005. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  1006. for (r of memberNames(nodeReads(mb.nodes))) { if (!out.includes(r)) { out.push(r) } }
  1007. reached(&queue, nodeReads(mb.nodes))
  1008. }
  1009. }
  1010. }
  1011. }
  1012. return out
  1013. }
  1014. reached(&queue, reads) {
  1015. if (reads == null) { return null }
  1016. for (r of reads) {
  1017. if (r.kind == 'method' || r.kind == 'handler' || (r.kind == 'member' && r.isStatic != true)) { queue.push(r.kind + ' ' + r.name) }
  1018. }
  1019. return null
  1020. }
  1021. // ---- THE SERVER RENDER, COMPILED --------------------------------------------------
  1022. // The old hl:web rendered a page by WALKING the View tree per request: for every node it asks
  1023. // what kind it is, for every element it builds the attribute string, and it decides the
  1024. // indentation of every line again, on every request, for every one of the 121 mounts a
  1025. // page may hold. Every one of those decisions is a fact about the View.
  1026. //
  1027. // So a component's render is compiled ONCE into a list of STEPS — constant text, and a
  1028. // read with its own closure — and a request is a concatenation. The structure (tags,
  1029. // static attributes, the readable form's line breaks, which element is a block) is
  1030. // decided at compile time; only the values are asked for per request.
  1031. //
  1032. // KEYED BY THE INDENT IT IS RENDERED AT, because that is the only thing about a
  1033. // component's HTML that its caller decides: the shell renders at one tab, the page at
  1034. // the depth the slot stands, a fill compactly (null). An app has a handful of those.
  1035. // the framework's `(key) => View tree`, for a kid whose steps are not built yet (set after the trees are)
  1036. treeOf = null
  1037. // the steps of a kid mount: the memo when it holds them, else built from the key's tree (read once, when they are built)
  1038. kidSteps(key, indent, classes, slotted) {
  1039. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1040. if (steps[ck] == null) { return serverSteps(key, treeOf(key), indent, classes, slotted) }
  1041. return steps[ck]
  1042. }
  1043. serverSteps(key, &nodes, indent, classes, slotted) {
  1044. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1045. if (steps[ck] == null) {
  1046. steps[ck] = blockSteps(classes == null || classes.length == 0 ? nodes : v.withRootClasses(&nodes, &classes), indent, slotted)
  1047. }
  1048. return steps[ck]
  1049. }
  1050. // A `slot` THE HOST FILLED COUNTS AS CONTENT, and an empty one does not — the one
  1051. // thing about a component's shape its caller decides, so it is part of the key.
  1052. staticVoid = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]
  1053. staticVerbatim = [ 'textarea' 'pre' 'script' 'style' ]
  1054. blocky(n, slotted) {
  1055. if (staticVerbatim.includes(n.tag)) { return false }
  1056. if (n.children.length == 0) { return false }
  1057. for (c of n.children) {
  1058. if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }
  1059. if (c.k == 'member' && !(c.name == 'slot' && slotted)) { return false }
  1060. }
  1061. return true
  1062. }
  1063. steps = {}
  1064. v = new HlwViewServer
  1065. viewRead = new HlwView
  1066. joinList(l) {
  1067. if (l == null) { return '' }
  1068. let out = ''
  1069. for (c of l) { out = out + ',' + c }
  1070. return out
  1071. }
  1072. // `render(nodes, …, indent)`: the readable form puts each element on its own line at
  1073. // `indent`, the compact one writes them end to end.
  1074. blockSteps(nodes, indent, slotted) {
  1075. let out = []
  1076. for (n of nodes) {
  1077. if (indent != null) {
  1078. if (n.k == 'el') { push(&out, { k = 's'; v = newline + indent; }) nodeSteps(&out, n, indent, slotted) }
  1079. else if (n.k == 'component') { nodeSteps(&out, n, indent, slotted) }
  1080. else if (n.k == 'for') { forSteps(&out, n, indent, slotted) }
  1081. else if (n.k == 'if') { ifSteps(&out, n, indent, slotted) }
  1082. else if (n.k == 'member' && n.name == 'slot') { push(&out, { k = 'slotline'; v = newline + indent; }) }
  1083. else if (n.k != 'on') { nodeSteps(&out, n, indent, slotted) }
  1084. } else {
  1085. nodeSteps(&out, n, null, slotted)
  1086. }
  1087. }
  1088. return out
  1089. }
  1090. forSteps(&out, n, indent, slotted) {
  1091. out.push({ k = 'for'; row = n.row; read = readFn(n.list); body = blockSteps(n.body, indent, slotted); })
  1092. return null
  1093. }
  1094. ifSteps(&out, n, indent, slotted) {
  1095. if (n.regionfill != null) { return null }
  1096. if (n.region != null) {
  1097. out.push({ k = 'region'; name = n.region; ind = indent; late = n.deferred == true; body = n.deferred == true ? [] : blockSteps(n.then, indent, slotted); })
  1098. return null
  1099. }
  1100. out.push({ k = 'if'; read = readFn(n.cond); then = blockSteps(n.then, indent, slotted); other = blockSteps(n.other, indent, slotted); })
  1101. return null
  1102. }
  1103. // a script's children: text and values written as they are (`view.rawText`)
  1104. rawSteps(nodes, slotted) {
  1105. let out = []
  1106. for (n of nodes) {
  1107. if (n.k == 'text') { push(&out, { k = 's'; v = v.rawText(n.text); }) }
  1108. else if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'raw'; read = readFn(n); }) }
  1109. else { nodeSteps(&out, n, null, slotted) }
  1110. }
  1111. return out
  1112. }
  1113. // one node's steps — `html(node, …)`, decided once
  1114. nodeSteps(&out, n, indent, slotted) {
  1115. if (n.k == 'text') { push(&out, { k = 's'; v = v.escape(n.text); }) return null }
  1116. if (n.k == 'on') { return null }
  1117. if (n.k == 'member' && n.name == 'slot') { out.push({ k = 'slot'; }) return null }
  1118. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'r'; read = readFn(n); }) return null }
  1119. if (n.k == 'for') { forSteps(&out, n, indent, slotted) return null }
  1120. if (n.k == 'if') { ifSteps(&out, n, indent, slotted) return null }
  1121. if (n.k == 'component') {
  1122. out.push({ k = 'kid'; path = n.path; cls = n.cls; key = n.key; classes = n.classes; indent = indent;
  1123. fill = (n.fill == null || n.fill.length == 0) ? null : blockSteps(n.fill, null, slotted); })
  1124. return null
  1125. }
  1126. if (n.k == 'el') { elSteps(&out, n, indent, slotted) return null }
  1127. push(&out, { k = 's'; v = '<!-- ' + n.tag + ' not rendered yet -->'; })
  1128. return null
  1129. }
  1130. elSteps(&out, n, indent, slotted) {
  1131. let attrs = []
  1132. let valueRead = null // a textarea's value is its content
  1133. let selRead = null // a select's value selects an option
  1134. for (a of n.attrs) {
  1135. if (n.tag == 'textarea' && a.name == 'value') { valueRead = attrRead(a) }
  1136. else if (n.tag == 'select' && a.name == 'value') { selRead = attrRead(a) }
  1137. // a bound BOOLEAN attribute is its presence (ticket #33): ` checked=""` or nothing
  1138. else if ((a.member != null || a.ref != null) && v.isBoolAttr(a.name)) { attrs.push({ k = 'b'; name = a.name; read = attrRead(a); }) }
  1139. // a null read is no attribute (#177)
  1140. else if (nullable(a)) { attrs.push({ k = 'a'; name = a.name; read = attrRead(a); }) }
  1141. else if (a.member != null || a.ref != null) {
  1142. push(&attrs, { k = 's'; v = ' ' + a.name + '="'; })
  1143. attrs.push({ k = 'r'; read = attrRead(a); })
  1144. push(&attrs, { k = 's'; v = v.extraOf(a) + '"'; })
  1145. } else {
  1146. push(&attrs, { k = 's'; v = ' ' + a.name + '="' + v.escape(a.text) + '"'; })
  1147. }
  1148. }
  1149. if (v.boundValue(&n)) { push(&attrs, { k = 's'; v = ' autocomplete="off"'; }) }
  1150. // the children, in the form this element takes: a block puts them one per line
  1151. let kids = []
  1152. // a script's and a style's content is raw text (#140, view.rawKids says why)
  1153. if (n.tag == 'script' || n.tag == 'style') { kids = rawSteps(n.children, slotted) }
  1154. else if (indent != null && blocky(n, slotted)) {
  1155. kids = blockSteps(n.children, indent + tab, slotted)
  1156. push(&kids, { k = 's'; v = newline + indent; })
  1157. } else {
  1158. kids = blockSteps(n.children, null, slotted)
  1159. }
  1160. if (valueRead != null) { kids = [{ k = 'r'; read = valueRead; }] }
  1161. // AN OPTION IS THE ONE ELEMENT WHOSE OWN TAG DEPENDS ON THE VALUE ABOVE IT: it
  1162. // carries `selected` when its value is the select's. Everything else is settled.
  1163. if (n.tag == 'option') {
  1164. out.push({ k = 'opt'; attrs = attrs; body = kids; ov = optionRead(n); })
  1165. return null
  1166. }
  1167. push(&out, { k = 's'; v = '<' + n.tag; })
  1168. for (a of attrs) { push(&out, a) }
  1169. if (staticVoid.includes(n.tag)) { push(&out, { k = 's'; v = '>'; }) return null }
  1170. push(&out, { k = 's'; v = '>'; })
  1171. // A SELECT HANDS ITS VALUE TO ITS OPTIONS, however deep they stand: its children
  1172. // run under it, and it is the only element that changes anything for them.
  1173. if (n.tag == 'select') { out.push({ k = 'sel'; read = selRead; body = kids; }) }
  1174. else { for (kk of kids) { push(&out, kk) } }
  1175. push(&out, { k = 's'; v = '</' + n.tag + '>'; })
  1176. return null
  1177. }
  1178. // CONSTANT TEXT MERGES. Two literal steps in a row are one string decided at compile
  1179. // time — which is what makes a request a concatenation of a handful of pieces instead
  1180. // of one per node.
  1181. push(&out, step) {
  1182. if (step.k == 's' && out.length > 0 && out[out.length - 1].k == 's') {
  1183. let last = out[out.length - 1]
  1184. last.v = last.v + step.v
  1185. out[out.length - 1] = last
  1186. return null
  1187. }
  1188. out.push(step)
  1189. return null
  1190. }
  1191. // ---- the reads, each with its own closure ------------------------------------------
  1192. // `view.value`'s rule, split once: a `for` row variable in scope wins over a member of
  1193. // the same name, and a field path walks into it. The closure holds the name — there is
  1194. // no node to look at per request.
  1195. readFn(node) {
  1196. if (node == null) { return (inst, rows) => { return null } }
  1197. if (node.k == 'text') { let t = viewRead.refValue(node) return (inst, rows) => { return t } }
  1198. if (node.k == 'expr') { let x = node.x return (inst, rows) => { return viewRead.evalExpr(&x, &inst, &rows) } }
  1199. let name = node.name
  1200. if (node.k != 'field') {
  1201. return (inst, rows) => { return rows[name] != null ? rows[name] : inst[name] }
  1202. }
  1203. let path = node.path
  1204. return (inst, rows) => {
  1205. let val = rows[name] != null ? rows[name] : inst[name]
  1206. for (f of path) {
  1207. if (val == null) { return null }
  1208. val = val[f]
  1209. }
  1210. return val
  1211. }
  1212. }
  1213. attrRead(a) {
  1214. if (a.member != null) { return readFn({ k = 'member'; name = a.member; }) }
  1215. if (a.ref != null) { return readFn(a.ref) }
  1216. let t = a.text
  1217. return (inst, rows) => { return t }
  1218. }
  1219. // an option's own value: its `value` attribute, or null when it has none (the browser
  1220. // then reports its text, and the run compares against what it rendered)
  1221. optionRead(n) {
  1222. for (a of n.attrs) {
  1223. if (a.name == 'value') { return attrRead(a) }
  1224. }
  1225. return null
  1226. }
  1227. // ---- the run: a concatenation ------------------------------------------------------
  1228. // EVERY REGION IS WRITTEN BETWEEN TWO MARKS (tickets #103, #104): an `if` around the
  1229. // branch that stands, a `for` around its rows and each row around its own nodes. The
  1230. // client claims them as they are and builds the same ones, and a region's nodes are
  1231. // exactly what stands between its two marks — nothing it holds has to be remembered
  1232. // node by node, and text beside a region can never run into the region's text.
  1233. regionOpen = '<!--hl:rg:'
  1234. regionClose = '<!--hl:/rg:'
  1235. markOpen = '<!--[-->'
  1236. markClose = '<!--]-->'
  1237. // THE PIECES ARE JOINED ONCE, AT THE END (ticket #127). `out = out + piece` copied
  1238. // the whole page so far for every piece: a 3.5 MB page of 2000 rows allocated 2.3 GB
  1239. // in growing copies, 7 GB per render all told — 12 s a load once the collector ran
  1240. // by bytes (#126), where the joined pieces take 2.5 s.
  1241. runSteps(&list, &inst, &rows, &ctx, &mounts) {
  1242. let out = []
  1243. runInto(&out, &list, &inst, &rows, &ctx, &mounts)
  1244. return out.join('')
  1245. }
  1246. // the same run, its pieces pushed onto the ONE list the caller joins: a nested region used to be
  1247. // joined into a string and then concatenated into its parent's list, so every piece was copied once
  1248. // per level it sat in (a README's blocks sit several levels deep)
  1249. runInto(&out, &list, &inst, &rows, &ctx, &mounts) {
  1250. for (s of list) {
  1251. if (s.k == 's') { out.push(s.v) }
  1252. else if (s.k == 'r') { let f = s.read out.push(v.escape(f(&inst, &rows))) }
  1253. else if (s.k == 'raw') { let f = s.read out.push(v.rawText(f(&inst, &rows))) }
  1254. else if (s.k == 'a') { let f = s.read let av = f(&inst, &rows) if (av != null) { out.push(' ' + s.name + '="' + v.escape(av) + '"') } }
  1255. else if (s.k == 'b') { let f = s.read if (v.boolOn(f(&inst, &rows))) { out.push(' ' + s.name + '=""') } }
  1256. else if (s.k == 'slot') { if (ctx.slot != null) { out.push(ctx.slot) } }
  1257. else if (s.k == 'slotline') { if (ctx.slot != null) { out.push(s.v + ctx.slot) } }
  1258. else if (s.k == 'for') {
  1259. let f = s.read
  1260. let list2 = f(&inst, &rows)
  1261. out.push(markOpen)
  1262. if (list2 != null) {
  1263. // THE ROW IS SET IN PLACE, and the name it shadows put back after the loop:
  1264. // `rows + {}` copied every enclosing row per iteration, and an outer row holds the
  1265. // whole list its inner `for` walks (a list block holding its N items): N rows of N items
  1266. let held = rows[s.row]
  1267. let ri = 0
  1268. let keys = viewRead.listKeys(&list2)
  1269. for (entry of list2) {
  1270. rows[s.row] = entry
  1271. let rc = v.rowCtx(&ctx, keys[ri])
  1272. out.push(markOpen)
  1273. runInto(&out, &s.body, &inst, &rows, &rc, &mounts)
  1274. out.push(markClose)
  1275. ri = ri + 1
  1276. }
  1277. rows[s.row] = held
  1278. }
  1279. out.push(markClose)
  1280. }
  1281. else if (s.k == 'region') {
  1282. // the region's default, between PLACEHOLDERS the document replaces once the page is known
  1283. // (a level above is rendered before the page below it is constructed): WebFramework `regions`
  1284. out.push(regionOpen + s.name + ':' + (s.ind == null ? '-' : '' + s.ind.length) + (s.late == true ? '!' : '') + '-->')
  1285. runInto(&out, &s.body, &inst, &rows, &ctx, &mounts)
  1286. out.push(regionClose + s.name + '-->')
  1287. }
  1288. else if (s.k == 'if') {
  1289. let f = s.read
  1290. out.push(markOpen)
  1291. if (f(&inst, &rows)) { runInto(&out, &s.then, &inst, &rows, &ctx, &mounts) }
  1292. else { runInto(&out, &s.other, &inst, &rows, &ctx, &mounts) }
  1293. out.push(markClose)
  1294. }
  1295. else if (s.k == 'opt') {
  1296. let head = runSteps(&s.attrs, &inst, &rows, &ctx, &mounts)
  1297. let body = runSteps(&s.body, &inst, &rows, &ctx, &mounts)
  1298. let mark = ''
  1299. if (ctx.sel != null) {
  1300. let ov = body
  1301. if (s.ov != null) { let f = s.ov ov = '' + f(&inst, &rows) }
  1302. if (ov == ctx.sel) { mark = ' selected' }
  1303. }
  1304. out.push('<option' + head + mark + '>' + body + '</option>')
  1305. }
  1306. else if (s.k == 'sel') {
  1307. let f = s.read
  1308. let inner = ctx + {}
  1309. inner.sel = f == null ? null : '' + f(&inst, &rows)
  1310. runInto(&out, &s.body, &inst, &rows, &inner, &mounts)
  1311. }
  1312. else if (s.k == 'kid') {
  1313. // THE KID IS READ IN PLACE: `let kid = ctx.kids[…]` copied the whole mount (its tree, its
  1314. // params, its state, its own kids) once per mount rendered. And the mounts a level holds
  1315. // travel as their own reference (`mounts`), not inside `ctx`: every `for` row copies the
  1316. // ctx, and a ctx holding the kids copied ALL of them per row (N rows of N mounts).
  1317. let kk = v.kidKeyIn(&s.path, &ctx)
  1318. if (mounts[kk] == null) { out.push('<!-- ' + s.cls + ' not mounted -->') }
  1319. else {
  1320. let fillText = s.fill == null ? null : runSteps(&s.fill, &inst, &rows, &ctx, &mounts)
  1321. let kidCtx = { slot = fillText; }
  1322. let empty = {}
  1323. let ksteps = kidSteps(s.key, s.indent, s.classes, fillText != null)
  1324. runInto(&out, &ksteps, &mounts[kk].page, &empty, &kidCtx, &mounts[kk].kids)
  1325. }
  1326. }
  1327. }
  1328. }

Branches

Latest commits

  • b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
  • 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
  • 06c548d6jukebox JB15: report, log linemre
  • 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
  • 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
  • 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
  • 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
  • cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
  • 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
  • b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
  • 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
  • 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre
  • 63d0f2eejukebox ST1 (jukebox#2): styles of main, songs and search moved into their own Style blocks (styles.hl 81 to 8 rules, pixel-identical at 390 and 1280); artist and album wait for an hl:web fixmre
  • c5b8fde9jukebox JB3b: keyboard gap repro as a reportmre
  • 9daebb4bjukebox JB3b: shuffle, now-playing overlay, next and previous, play counting, media session, gates; keyboard left open (Hybriel gap)mre
  • 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
  • 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
  • 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
  • bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
  • 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre