gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit383cce23383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas383cce23/plugins/web/css.hl

26.1 KB

  1. // The framework's STYLESHEET — the Style convention of COMPONENTS §4, as the
  2. // archived hl:web implemented it (archive/hlweb-v1/plugins-web/web_css.hl), re-read
  3. // 2026-09-12 after a version built from the doc alone got most of it wrong.
  4. //
  5. // STRUCTURE FROM THE SYNTAX, VALUES FROM THE INSTANCE. A hybrid's keys come back
  6. // alphabetical, so the ORDER of rules, declarations and media conditions is read
  7. // off the syntax (hlSyntax entries are authored order) while every VALUE is read
  8. // off the constructed instance at the same path — the language has already folded
  9. // the statics (`background = dark`) and merged `base + { … }` by then.
  10. //
  11. // WHAT A RULE NAME MEANS (the archive's `placesFor`, per file):
  12. // `@root` / `':root'` a CONTRIBUTION: collected from every file into ONE
  13. // `:root { }` at the top of the sheet, in order
  14. // `'@media …'` / `@media` a BLOCK of rules: collected at the END of the sheet,
  15. // (`@supports`, the same shape and place for the other two queries
  16. // `@container`) (ticket #66, proposal 5)
  17. // one `@media` per distinct query, first-seen order;
  18. // `@media { minWidth = 960 … }` composes the query from
  19. // conditions (number → px, string verbatim); any number of
  20. // different bare ones may stand in one block (read off the
  21. // syntax, see SYNTAX), inside a rule the feature-named scalars
  22. // are the conditions (hybriel#257)
  23. // `'@keyframes name'` an ANIMATION: its stops (`'from'`, `to`, `'50%'`) with
  24. // their declarations, emitted where it stands (ticket #66, 4)
  25. // selector-shaped verbatim (`'.icon'`, `'#page-anchor'`, `'a:hover'`)
  26. // referenced `Style.x` the class the View wrote (tag-prefix strip): `.x`, or
  27. // `tag.stripped`
  28. // `#x` id the View writes `id = 'x'` on an element: `#x` (R3)
  29. // `#x` local otherwise matched by NAME to this file's elements `x` (and
  30. // a composed child's root for `#Child`): `tag.<file class>`
  31. // own-name a rule named like an element of this file's View (or
  32. // body/html): the TAG selector, no class
  33. // anything else DEAD: a build error naming the file and the rule
  34. // In a STYLES FILE (root members, no View) a bare name is a tag, kebab-cased.
  35. // NESTED under a rule, a name of PSEUDOS is that rule's pseudo-class, not a
  36. // descendant: `a { hover { … } }` → `a:hover` (ticket #66, proposal 1).
  37. // A rule with no declarations and nested rules is a CONTAINER: not emitted.
  38. // Two rules emitting one selector with different bodies: refused.
  39. import HlwCssVar from './cssvar.hl'
  40. static NL = "
  41. "
  42. static SELECTOR_CHARS = ":-.#>[]()*+~,/ %@=^|!"
  43. static HEADER = "/* GENERATED by hl:web — ONE global stylesheet.
  44. Components author their Style rules per file; only the rules a View actually
  45. REFERENCES are emitted (dead rules are dropped and listed at boot). Class names
  46. follow the tag-prefix strip rule: rule `headerMain` referenced inside `header`
  47. emits class=\"main\" under the TAG-QUALIFIED selector `header.main`; under any
  48. other tag it keeps `.headerMain`. */
  49. "
  50. Boolean minify = false
  51. view = null // the View walk: kebab, className, localClass live there
  52. gen = 0 // the analysis generation the syntax handles belong to
  53. // per sheet
  54. parts = []
  55. seen = {}
  56. dead = []
  57. mediaOrder = []
  58. mediaParts = []
  59. rootDecls = []
  60. // ---- names ----------------------------------------------------------------------
  61. // ---- css variables (creator's ruling 2026-09-13) --------------------------------
  62. // `bg = var('#FFF')` declares a custom property as a VALUE; the walker names it after
  63. // its member, writes it into the sheet's one `:root`, and rewrites every use.
  64. static counter = { n = 0 }
  65. // `var('#FFF', dark = '#000')` carries its dark-scheme value too (ticket #66,
  66. // proposal 2): the sheet writes it into `:root` under `(prefers-color-scheme: dark)`
  67. static var = (value, dark = null) => {
  68. counter.n = counter.n + 1
  69. return new HlwCssVar(value = value, id = counter.n, dark = dark)
  70. }
  71. static DARK = '@media (prefers-color-scheme: dark)'
  72. // ---- units as functions (ticket #66, proposal 3) ---------------------------------
  73. // a number is emitted unitless as written; `rem(1.5)`, `px(12)`, `pct(50)` answer the
  74. // TEXT with its unit — '1.5rem', '12px', '50%' — so a value says what it measures
  75. static rem = (n) => { return '' + n + 'rem' }
  76. static px = (n) => { return '' + n + 'px' }
  77. static pct = (n) => { return '' + n + '%' }
  78. vars = {} // id → { name value } for the sheet being built
  79. varNames = {} // name → true
  80. isVar(v) { return v != null && hlTypeName(v) == 'Instance' }
  81. // the variables a file's root members declare, named after the member
  82. collectVars(f) {
  83. for (r of fileRules(f)) {
  84. if (!r.isBlock && isVar(r.value)) {
  85. r.value.name = r.key
  86. vars['' + r.value.id] = { name = r.key; value = r.value.value; }
  87. varNames[r.key] = true
  88. }
  89. }
  90. // a token the file INHERITS: its own instance's copy, under the parent's name (ticket #39)
  91. if (f.aliases != null) {
  92. for (a of f.aliases) {
  93. a.value.name = a.key
  94. vars['' + a.value.id] = { name = a.key; value = a.value.value; }
  95. }
  96. }
  97. return null
  98. }
  99. // a value's text with every variable reference resolved: a variable itself →
  100. // var(--name); a composed string carries placeholders var(--hlv<id>) → var(--name)
  101. varText(v) {
  102. if (isVar(v)) {
  103. let d = vars['' + v.id]
  104. if (d == null) { hlError("a css variable is used before any styles file declared it as a root member — `name = var(…)` at the root of the styles file") }
  105. return 'var(--' + view.kebab(d.name) + ')'
  106. }
  107. let s = '' + v
  108. if (s.indexOf('var(--hlv') < 0) { return s }
  109. for (id of vars.keys()) { s = s.replaceAll('var(--hlv' + id + ')', 'var(--' + view.kebab(vars[id].name) + ')') }
  110. return s
  111. }
  112. // the pseudo-classes a nested entry may name, camelCase as written (kebab-cased on emit)
  113. static PSEUDOS = ['hover', 'focus', 'focusVisible', 'focusWithin', 'active', 'visited', 'target',
  114. 'disabled', 'enabled', 'checked', 'required', 'optional', 'valid', 'invalid', 'readOnly',
  115. 'placeholderShown', 'firstChild', 'lastChild', 'onlyChild', 'firstOfType', 'lastOfType', 'empty']
  116. isPseudo(name) { return PSEUDOS.includes(name) }
  117. // the selectors a nested entry composes under its enclosing rule's `sels`: a
  118. // pseudo-class sticks to each (`a:hover`), anything else is a descendant (`a span`)
  119. nestedSels(f, sels, key) {
  120. let out = []
  121. if (isPseudo(key)) {
  122. for (p of sels) { out.push(p + ':' + view.kebab(key)) }
  123. return out
  124. }
  125. let kidSels = selectorsFor(f, key)
  126. // a tag that only a COMPOSED component's View renders (hybriel#243): `'.bar' { 'img' { … } }`
  127. // is `.bar img` when Child, composed inside `.bar`, has the img
  128. if (kidSels.length == 0 && f.deepTags != null && f.deepTags.includes(key)) { kidSels = [view.domTag(key)] }
  129. // a tag a CALLER writes into this component's slot (hybriel#270): it lands inside the element
  130. if (kidSels.length == 0 && f.fillTags != null && f.fillTags.includes(view.domTag(key))) { kidSels = [view.domTag(key)] }
  131. for (p of sels) { for (s of kidSels) { out.push(p + ' ' + s) } }
  132. return out
  133. }
  134. isKeyframes(name) { return name == '@keyframes' || name.startsWith('@keyframes ') }
  135. isRootBlock(name) { return name == '@root' || name == ':root' }
  136. // THE THREE QUERIES share one shape: `@media`, `@supports`, `@container` — bare with
  137. // conditions as scalars, or spelled out in the key
  138. static QUERIES = ['@media', '@supports', '@container']
  139. queryKind(name) {
  140. for (k of QUERIES) {
  141. if (name == k || name.startsWith(k + ' ') || name.startsWith(k + '(')) { return k }
  142. }
  143. return ''
  144. }
  145. isMediaBlock(name) { return queryKind(name) != '' }
  146. // THE FEATURES a bare query inside a rule reads as conditions, camelCase as written.
  147. // `width`, `height`, `color` and `grid` are also declarations and stay declarations
  148. // there: write `minWidth` / `maxWidth` (and `minHeight`, `maxHeight`) for a size.
  149. static MEDIA_FEATURES = ['aspectRatio', 'orientation', 'resolution', 'pointer', 'hover', 'anyPointer', 'anyHover',
  150. 'prefersColorScheme', 'prefersReducedMotion', 'prefersContrast', 'prefersReducedData', 'prefersReducedTransparency',
  151. 'displayMode', 'overflowBlock', 'overflowInline', 'update', 'scan', 'colorGamut', 'colorIndex', 'monochrome',
  152. 'forcedColors', 'invertedColors', 'scripting', 'videoDynamicRange', 'dynamicRange']
  153. static RANGE_FEATURES = ['width', 'height', 'aspectRatio', 'resolution', 'color', 'colorIndex', 'monochrome']
  154. static CONTAINER_FEATURES = ['inlineSize', 'blockSize', 'aspectRatio', 'orientation']
  155. isFeature(kind, name) {
  156. if (kind == '@media') {
  157. if (MEDIA_FEATURES.includes(name)) { return true }
  158. if (name.length > 3 && (name.startsWith('min') || name.startsWith('max'))) {
  159. rest = name.slice(3, name.length)
  160. low = rest.charAt(0).toLowerCase() + rest.slice(1, rest.length)
  161. return RANGE_FEATURES.includes(low)
  162. }
  163. return false
  164. }
  165. if (kind == '@container') {
  166. if (CONTAINER_FEATURES.includes(name)) { return true }
  167. if (name.length > 3 && (name.startsWith('min') || name.startsWith('max'))) {
  168. rest = name.slice(3, name.length)
  169. low = rest.charAt(0).toLowerCase() + rest.slice(1, rest.length)
  170. return ['width', 'height', 'inlineSize', 'blockSize', 'aspectRatio'].includes(low)
  171. }
  172. }
  173. return false
  174. }
  175. mediaLiteral(name) { return name.slice(queryKind(name).length, name.length).trim() }
  176. localName(name) { return name.startsWith('#') ? name.slice(1) : '' }
  177. selectorShaped(name) {
  178. if (name.length == 0) { return false }
  179. if ('0123456789'.indexOf(name.charAt(0)) >= 0) { return true }
  180. let i = 0
  181. while (i < name.length) {
  182. if (SELECTOR_CHARS.indexOf(name.charAt(i)) >= 0) { return true }
  183. i = i + 1
  184. }
  185. return false
  186. }
  187. // ---- one block's syntax, with its values --------------------------------------
  188. // the entries of a hybrid node: [{ key node value isBlock }] in authored order,
  189. // values read off `hybrid` (the instance's evaluated member at the same path)
  190. entriesOf(key, node, hybrid) {
  191. let out = []
  192. let n = node == 0 ? null : hlSyntax(gen, key, node)
  193. if (n == null || n.tag != 'object_expression') {
  194. // A MERGED RULE (`extR = baseR + { top = 'auto' }`, COMPONENTS §4: "Style gets it
  195. // for free") has no literal to read: its entries are the merged VALUE's, and a
  196. // nested block is read the same way. It used to read as no entries at all, so the
  197. // View wrote the class and the sheet carried no rule for it (mission 322 row 9).
  198. if (isHybridValue(hybrid)) {
  199. for (k of hybrid.keys()) { out.push({ key = k; node = 0; value = hybrid[k]; isBlock = isHybridValue(hybrid[k]); }) }
  200. }
  201. return out
  202. }
  203. own = hybrid == SYNTAX
  204. for (h of n.entries) {
  205. let e = hlSyntax(gen, key, h)
  206. if (e != null && e.tag == 'object_property') {
  207. if (e.key.indexOf('&') >= 0) {
  208. hlError("hl:web: " + key + ':' + e.line + ':' + e.col + " — '&' in Style key '" + e.key + "' is refused. Apply a class with Style.name on the element, or write the whole selector quoted without '&'")
  209. }
  210. let v = hlSyntax(gen, key, e.value)
  211. if (own) {
  212. out.push(syntaxEntry(key, e, v))
  213. } else {
  214. val = hybrid != null ? hybrid[e.key] : null
  215. // A static hybrid has no syntax block here; its evaluated value is the rule (W219, #253).
  216. out.push({ key = e.key; node = e.value; value = val; isBlock = (v != null && v.tag == 'object_expression') || isHybridValue(val); })
  217. }
  218. }
  219. }
  220. return markRepeated(key, out)
  221. }
  222. // THE VALUES OF A BLOCK THAT THE INSTANCE CANNOT HOLD (hybriel#257). Two members of one
  223. // name are one member in the constructed instance, so a query written twice
  224. // (`@media { minWidth … }` and `@media { maxWidth … }`) cannot be read from it by name.
  225. // Every occurrence of such a name is marked SYNTAX: its entries, at any depth, are read
  226. // off the source in place, where each block has its own position. Only a literal can be
  227. // read that way (a string, a number, a boolean); a name or a call inside such a block
  228. // is a located error that says what to do.
  229. static SYNTAX = '[read from the syntax]'
  230. syntaxEntry(key, e, v) {
  231. if (v != null && v.tag == 'object_expression') { return { key = e.key; node = e.value; value = SYNTAX; isBlock = true; } }
  232. if (v == null || v.tag != 'literal') {
  233. hlError("'" + e.key + "' in " + key + " sits in a query that is written more than once in one block, and such a block's values are read off the source, where only a literal (a string or a number) can be read. Write '" + e.key + "' as a literal, or give the queries distinct keys ('@media (min-width: 60rem)' = { … })")
  234. }
  235. let val = v.text
  236. if (v.kind == 'number') { val = toNumber(v.text) }
  237. if (v.kind == 'boolean') { val = v.text == 'true' }
  238. return { key = e.key; node = e.value; value = val; isBlock = false; }
  239. }
  240. // a query name that occurs more than once among the entries of one block: every
  241. // occurrence is read from the syntax (see SYNTAX)
  242. markRepeated(key, entries) {
  243. count = {}
  244. for (e of entries) {
  245. if (isMediaBlock(e.key)) { count[e.key] = count[e.key] == null ? 1 : count[e.key] + 1 }
  246. }
  247. out = []
  248. for (e of entries) {
  249. if (count[e.key] != null && count[e.key] > 1 && e.value != SYNTAX) {
  250. sn = hlSyntax(gen, key, e.node)
  251. if (sn == null || sn.tag != 'object_expression') {
  252. hlError("'" + e.key + "' in " + key + " is written more than once and one of them is not a block literal — write each as { … } or give the queries distinct keys")
  253. }
  254. out.push({ key = e.key; node = e.node; value = SYNTAX; isBlock = true; })
  255. } else {
  256. out.push(e)
  257. }
  258. }
  259. return out
  260. }
  261. // a hybrid VALUE (a rule), as opposed to a scalar declaration or a var() token
  262. isHybridValue(v) { return v != null && hlTypeName(v) == 'Hybrid' }
  263. // a value as CSS text: a string as written, a number unitless, a static already
  264. // folded, a css variable (or a string composed with one) resolved to var(--name)
  265. text(v) {
  266. return varText(v)
  267. }
  268. declLine(k, v) {
  269. if (minify) { return view.kebab(k) + ':' + text(v) + ';' }
  270. return ' ' + view.kebab(k) + ': ' + text(v) + ';' + NL
  271. }
  272. // a media condition: `minWidth = 960` → `(min-width: 960px)`, a string verbatim
  273. condition(k, v) {
  274. if (hlTypeName(v) == 'Number') { return '(' + view.kebab(k) + ': ' + v + 'px)' }
  275. return '(' + view.kebab(k) + ': ' + v + ')'
  276. }
  277. // the whole prelude, `@media (a) and (b)`: an enclosing query of the SAME kind is
  278. // joined with `and`; one of another kind cannot be, in a sheet written flat
  279. queryText(kind, outer, literal, conds, name) {
  280. let parts = []
  281. if (outer != '') {
  282. if (!outer.startsWith(kind + ' ')) { hlError("'" + name + "' stands inside '" + outer + "' — two kinds of query cannot be joined into one; write the block beside it, not inside") }
  283. parts.push(outer.slice(kind.length + 1, outer.length))
  284. }
  285. if (literal != '') { parts.push(literal) }
  286. for (c of conds) { parts.push(c) }
  287. let out = ''
  288. for (p of parts) { out = out == '' ? p : out + ' and ' + p }
  289. return kind + ' ' + out
  290. }
  291. // ---- where a rule lands (the archive's placesFor) -------------------------------
  292. // `f` is the file block: { key cls refs tags hasView isStyles }; refs are what the
  293. // View wrote ([{ tag rule }]), tags the element names the file's own View renders.
  294. selectorsFor(f, name) {
  295. if (f.isStyles) {
  296. if (selectorShaped(name)) { return [name] }
  297. return [view.domTag(name)]
  298. }
  299. let local = localName(name)
  300. // the View writes `id = 'x'`: `#x` is that id, nothing else (ticket #51, R3)
  301. if (local != '' && f.ids != null && f.ids.includes(view.kebab(local))) { return [view.kebab(name)] }
  302. if (local != '' && !selectorShaped(local)) {
  303. let out = []
  304. for (r of f.refs) {
  305. if (r.rule == name) {
  306. let sel = view.domTag(r.tag) + '.' + view.localClass(f.key)
  307. if (!out.includes(sel)) { out.push(sel) }
  308. }
  309. }
  310. return out
  311. }
  312. if (selectorShaped(name)) { return [name] }
  313. let classes = []
  314. for (r of f.refs) {
  315. if (r.rule == name) {
  316. let cls = view.className(name, r.tag)
  317. if (!classes.includes(cls)) { classes.push(cls) }
  318. }
  319. }
  320. if (classes.length == 0) {
  321. if (f.tags.includes(name) || name == 'body' || name == 'html') { return [view.domTag(name)] }
  322. return []
  323. }
  324. let out = []
  325. for (cls of classes) {
  326. if (cls == name) { out.push('.' + view.kebab(cls)) }
  327. else { out.push(view.domTag(name.slice(0, name.length - cls.length)) + '.' + view.kebab(cls)) }
  328. }
  329. return out
  330. }
  331. // ---- emission -------------------------------------------------------------------
  332. // Normalize CSS whitespace only outside quoted strings and attribute brackets.
  333. cssWhitespace(source) {
  334. let out = ''
  335. let quote = ''
  336. let brackets = 0
  337. let escaped = false
  338. let pending = false
  339. for (c of source) {
  340. if (escaped) { out = out + c escaped = false }
  341. else if (c.charCodeAt(0) == 92) {
  342. if (pending && out != '') { out = out + ' ' }
  343. pending = false
  344. out = out + c
  345. escaped = true
  346. } else if (quote != '') {
  347. out = out + c
  348. if (c == quote) { quote = '' }
  349. } else if (brackets == 0 && c.trim() == '') { pending = true }
  350. else {
  351. if (pending && out != '') { out = out + ' ' }
  352. pending = false
  353. out = out + c
  354. if (c == "'" || c == '"') { quote = c }
  355. else if (c == '[') { brackets = brackets + 1 }
  356. else if (c == ']') { brackets = brackets - 1 }
  357. }
  358. }
  359. return out
  360. }
  361. putRule(f, name, selector, body, query) {
  362. selector = cssWhitespace(selector)
  363. query = cssWhitespace(query)
  364. let first = seen[query + '|' + selector]
  365. if (first != null) {
  366. if (first.body == body) { return null }
  367. let msg = "style rule '" + selector + "' is emitted twice with different bodies — '" + first.rule + "' in " + first.file + " and '" + name + "' in " + f.key + " both emit that selector; put the declarations in ONE rule, or rename one of them"
  368. // printed first: an app's own `on Error` that ends the start with exit(1) takes the error and its text with it (hybriel#247)
  369. console.log('error: ' + msg)
  370. hlError(msg)
  371. }
  372. seen[query + '|' + selector] = { body = body; rule = name; file = f.key; }
  373. if (query == '') {
  374. parts.push(minify ? selector + '{' + body + '}' : NL + selector + ' {' + NL + body + '}' + NL)
  375. } else {
  376. mediaPut(query, selector, body)
  377. }
  378. return null
  379. }
  380. mediaPut(query, selector, body) {
  381. if (!mediaOrder.includes(query)) { mediaOrder.push(query) }
  382. // inside a media block every line is indented two spaces (the archive's goldens)
  383. let inner = minify ? selector + '{' + body + '}' : ' ' + selector + ' {' + NL + ' ' + body.replace(NL + ' ', NL + ' ') + ' }' + NL
  384. mediaParts.push({ query = query; text = inner; })
  385. return null
  386. }
  387. // ONE RULE: its own declarations under `sels`, its nested rules composed below it
  388. // (descendant), its media blocks under the query; a container emits nothing itself
  389. emitRule(f, name, sels, entries, query) {
  390. let body = ''
  391. let kids = []
  392. let medias = []
  393. for (e of entries) {
  394. if (e.isBlock) {
  395. if (isMediaBlock(e.key)) { medias.push(e) } else { kids.push(e) }
  396. } else if (e.value != null) {
  397. body = body + declLine(e.key, e.value)
  398. }
  399. }
  400. if (body != '') {
  401. for (sel of sels) { putRule(f, name, sel, body, query) }
  402. }
  403. for (k of kids) {
  404. if (isKeyframes(k.key)) { hlError("'" + k.key + "' inside '" + name + "' in " + f.key + " — an animation is not a rule's child: write it at the top of the Style or of the styles file") }
  405. let composed = nestedSels(f, sels, k.key)
  406. if (composed.length == 0) {
  407. dead.push(f.key + ' ' + f.cls + '.' + name + ' ' + k.key)
  408. } else {
  409. emitRule(f, name + ' ' + k.key, composed, entriesOf(f.key, k.node, k.value), query)
  410. }
  411. }
  412. for (m of medias) {
  413. // a query inside a query of the SAME kind joins with `and` (queryText refuses another kind)
  414. mediaBlock(f, m.key, m.node, m.value, sels, name, query)
  415. }
  416. return null
  417. }
  418. // ONE `@media` BLOCK, at the top of a Style (prefixes empty) or inside a rule
  419. // (prefixes = the enclosing rule's selectors): scalar entries are CONDITIONS
  420. // (only for the bare `@media` spelling), block entries are RULES under the query;
  421. // inside a rule, scalar entries are the ENCLOSING RULE's declarations under it.
  422. mediaBlock(f, name, node, hybrid, prefixes, outer, outerQuery) {
  423. let literal = mediaLiteral(name)
  424. let conds = []
  425. let own = ''
  426. let rules = []
  427. let overrides = ''
  428. for (e of entriesOf(f.key, node, hybrid)) {
  429. if (e.isBlock) { rules.push(e) }
  430. // a css VARIABLE re-assigned under the query: `bg = '#000'` inside
  431. // `@media { prefersColorScheme = 'dark' … }` is `:root { --bg: #000 }` there
  432. else if (prefixes.length == 0 && varNames[e.key] != null) { overrides = overrides + declLine('--' + view.kebab(e.key), e.value) }
  433. else if (literal == '' && prefixes.length == 0) { conds.push(condition(e.key, e.value)) }
  434. // INSIDE A RULE a bare query's scalars are its conditions when they name a feature
  435. // (`pointer = 'coarse'`, `minWidth = 960`) and the rule's declarations otherwise
  436. else if (literal == '' && isFeature(queryKind(name), e.key)) { conds.push(condition(e.key, e.value)) }
  437. else if (prefixes.length > 0) { own = own + declLine(e.key, e.value) }
  438. else { hlError("'" + name + "' already spells its query out, so '" + e.key + "' is a declaration directly inside an at-rule — put it in a rule inside the block") }
  439. }
  440. if (prefixes.length > 0 && literal == '' && conds.length == 0) {
  441. hlError("'" + name + "' inside '" + outer + "' in " + f.key + " names no condition. Inside a rule a bare query takes its conditions as scalars named after a feature (`pointer = 'coarse'`, `minWidth = 960`; `width` and `height` alone are declarations, write `minWidth`), or spell it out: '" + queryKind(name) + " (min-width: 60rem)' = { … }")
  442. }
  443. let q = queryText(queryKind(name), outerQuery, literal, conds, name)
  444. if (overrides != '') { putRule(f, name, ':root', overrides, q) }
  445. if (own != '') { for (sel of prefixes) { putRule(f, outer, sel, own, q) } }
  446. for (r of rules) {
  447. if (isMediaBlock(r.key)) { mediaBlock(f, r.key, r.node, r.value, prefixes, outer, q) }
  448. else if (isKeyframes(r.key)) { hlError("'" + r.key + "' inside '" + name + "' in " + f.key + " — an animation is not scoped by a query: write it at the top of the Style or of the styles file") }
  449. else {
  450. let composed = prefixes.length > 0 ? nestedSels(f, prefixes, r.key) : selectorsFor(f, r.key)
  451. if (composed.length == 0) { dead.push(f.key + ' ' + f.cls + '.' + r.key + ' (in ' + name + ')') }
  452. else { emitRule(f, r.key, composed, entriesOf(f.key, r.node, r.value), q) }
  453. }
  454. }
  455. return null
  456. }
  457. // a file's rules in authored order: [{ key node value isBlock }] — a component's
  458. // Style entries, or a styles file's root members (its inherits' first)
  459. fileRules(f) {
  460. return f.rules
  461. }
  462. // ONE `'@keyframes name' = { 'from' = { … } to { … } '50%' = { … } }`: every entry is
  463. // a stop, its key the stop's selector verbatim, its entries declarations
  464. keyframes(f, r) {
  465. let name = r.key.slice(10, r.key.length).trim()
  466. if (name == '') { hlError("'@keyframes' in " + f.key + " names no animation — write the name into the key: '@keyframes fade' = { 'from' = { opacity = 0 } to { opacity = 1 } }") }
  467. let body = ''
  468. for (st of entriesOf(f.key, r.node, r.value)) {
  469. if (!st.isBlock) { hlError("'" + st.key + "' in '" + r.key + "' (" + f.key + ") is a declaration, and an animation holds stops — 'from', to, '50%' — each a block of declarations") }
  470. let decls = ''
  471. for (d of entriesOf(f.key, st.node, st.value)) {
  472. if (d.isBlock) { hlError("'" + d.key + "' in the stop '" + st.key + "' of '" + r.key + "' (" + f.key + ") is a block — a stop holds declarations only") }
  473. if (d.value != null) { decls = decls + (minify ? declLine(d.key, d.value) : ' ' + declLine(d.key, d.value)) }
  474. }
  475. body = body + (minify ? st.key + '{' + decls + '}' : ' ' + st.key + ' {' + NL + decls + ' }' + NL)
  476. }
  477. putRule(f, r.key, '@keyframes ' + name, body, '')
  478. return null
  479. }
  480. // ---- the sheet ------------------------------------------------------------------
  481. // `files` are the blocks in cascade order: the styles file (with its inherits
  482. // walked first by the caller), then every served component.
  483. sheet(files) {
  484. parts = []
  485. seen = {}
  486. dead = []
  487. mediaOrder = []
  488. mediaParts = []
  489. rootDecls = []
  490. vars = {}
  491. varNames = {}
  492. for (f of files) { collectVars(f) }
  493. // the declared variables come first in :root, in declaration order; their dark
  494. // values open the dark-scheme query with a :root of their own (an explicit
  495. // `@media { prefersColorScheme = 'dark' … }` re-assignment lands after it and wins)
  496. let darkBody = ''
  497. for (f of files) {
  498. for (r of fileRules(f)) {
  499. if (!r.isBlock && isVar(r.value)) {
  500. rootDecls.push(declLine('--' + view.kebab(r.key), r.value.value))
  501. if (r.value.dark != null) { darkBody = darkBody + declLine('--' + view.kebab(r.key), r.value.dark) }
  502. }
  503. }
  504. }
  505. if (darkBody != '') { mediaPut(DARK, ':root', darkBody) }
  506. for (f of files) {
  507. for (r of fileRules(f)) {
  508. if (!r.isBlock) {
  509. // a scalar root member of a styles file is not a rule (a variable was taken above)
  510. } else if (isMediaBlock(r.key)) {
  511. mediaBlock(f, r.key, r.node, r.value, [], '', '')
  512. } else if (isKeyframes(r.key)) {
  513. keyframes(f, r)
  514. } else if (isRootBlock(r.key)) {
  515. for (d of entriesOf(f.key, r.node, r.value)) {
  516. if (d.isBlock) { hlError("'" + r.key + "' holds custom properties only — '" + d.key + "' is a rule; put it beside the block, not inside it") }
  517. rootDecls.push(declLine(d.key, d.value))
  518. }
  519. } else {
  520. let sels = selectorsFor(f, r.key)
  521. if (sels.length == 0) { dead.push(f.key + ' ' + f.cls + '.' + r.key + ' bound to nothing (no reference, no matching element)') }
  522. else { emitRule(f, r.key, sels, entriesOf(f.key, r.node, r.value), '') }
  523. }
  524. }
  525. }
  526. let out = minify ? '' : HEADER
  527. if (rootDecls.length > 0) {
  528. let body = ''
  529. for (d of rootDecls) { body = body + d }
  530. out = out + (minify ? ':root{' + body + '}' : NL + ':root {' + NL + body + '}' + NL)
  531. }
  532. for (p of parts) { out = out + p }
  533. for (q of mediaOrder) {
  534. let inner = ''
  535. for (p of mediaParts) { if (p.query == q) { inner = inner + p.text } }
  536. out = out + (minify ? q + '{' + inner + '}' : NL + q + ' {' + NL + inner + '}' + NL)
  537. }
  538. if (dead.length > 0) {
  539. // A RULE THAT MATCHES NOTHING IS A BUILD ERROR (hybriel#243), not a log line: the
  540. // page would ship without it and nothing on the page says so
  541. let all = ''
  542. for (d of dead) { all = all + NL + ' ' + d }
  543. hlError('hl:web: style rules that match nothing in their file, nor in any component it composes (file.rule):' + all + NL + 'Reference the rule with Style.rule on an element, name an element of the View, write the selector whole (\'.bar section h2\'), or delete the rule')
  544. }
  545. return out
  546. }

Branches

Latest commits

  • 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
  • 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
  • 649cef37|||PR Vendor Hybriel day56Atlas
  • aadd0abcMerge branch 'hl-standard-2' into mainAtlas
  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
  • 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
  • d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
  • 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
  • d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
  • 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
  • 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
  • e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre
  • 27b6a09enotes#8: Style blocks in the nested form (note-list, note-editor, .ask with their children nested, :empty as a nested pseudo-class); the same CSS rules, the pages look the samemre
  • 71a9538bnotes: B27W report, log linemre
  • 78ba0073notes: an ident access key (Authorization: Bearer idt_…) reads and writes its identity's notes through /api/me and /api/notes; gate tests/ident-access-notes.mjs (ident#27)mre
  • 3de46dacnotes: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 73+5 failing → 78 passedmre