@monster-orange/den-ui 0.6.6 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/shell-html.js CHANGED
@@ -8,7 +8,8 @@
8
8
  * No inline style attributes, no inline handlers: the markup is clean
9
9
  * under `script-src 'self'; style-src 'self'`. Its look is shell.css.
10
10
  *
11
- * shellHtml({ product, nav, groups, foot, lang, slots, collapsed, report })
11
+ * shellHtml({ product, nav, groups, foot, settings, account, lang, slots,
12
+ * collapsed, report })
12
13
  * product { name, title?, version?, href?, mark? } the brand: `name` is the
13
14
  * word beside the mark, `title` its tooltip (default name),
14
15
  * `version` the chip's text ("v" + version; "v…" when unknown),
@@ -21,6 +22,10 @@
21
22
  * entry is left out
22
23
  * foot entries under the rail's spacer (Settings, say), then the
23
24
  * kit's collapse toggle
25
+ * settings (0.7.0) the Settings entry, after foot: { href, label?,
26
+ * current?, id? } (settingsHtml)
27
+ * account (0.7.0) the account entry, last in the foot: { label,
28
+ * detail?, href? | action? } (accountHtml)
24
29
  * lang "en", "es" or "ja" (the kit's words; else en)
25
30
  * slots { start, end, bell, account }: the product's own HTML in
26
31
  * the top bar. start: after the brand; end: the right group's
@@ -34,6 +39,10 @@
34
39
  * attributes { name: value } (escaped); `cls` more classes; `pin` the
35
40
  * pinned id (the row is a pin row: Delete unpins it); `after` HTML after
36
41
  * the link inside the pin row (a Visit link).
42
+ *
43
+ * 0.7.0, for the slots: scopeHtml (the scope crumbs), searchHtml (the
44
+ * search field with ⌘K inside), bellButtonHtml and bellPanelHtml (the
45
+ * bell and its panel); and accountHtml (the rail's account entry).
37
46
  */
38
47
  import { esc, kitT } from "./strings.js";
39
48
  import { icon } from "./icons.js";
@@ -52,8 +61,13 @@ function attrs(o) {
52
61
  return s;
53
62
  }
54
63
 
55
- /** One rail entry (a link, .den-ni). */
56
- export function navItemHtml(n) {
64
+ /**
65
+ * One rail entry (a link, .den-ni). `navRole`: the data-nav-role the nav
66
+ * inventory reads ("page" for a rail group's entries: host content).
67
+ */
68
+ export function navItemHtml(n, navRole) {
69
+ const role =
70
+ typeof navRole === "string" ? ' data-nav-role="' + esc(navRole) + '"' : "";
57
71
  const b = n.badge || null;
58
72
  const extra = b
59
73
  ? '<span class="den-bdg' +
@@ -73,6 +87,7 @@ export function navItemHtml(n) {
73
87
  '" data-nav="' +
74
88
  esc(n.id) +
75
89
  '"' +
90
+ (n.pin != null ? "" : role) +
76
91
  (n.current ? ' aria-current="page"' : "") +
77
92
  attrs(more) +
78
93
  ' title="' +
@@ -87,7 +102,12 @@ export function navItemHtml(n) {
87
102
  extra +
88
103
  "</a>";
89
104
  return n.pin != null
90
- ? '<div class="den-pin-row">' + link + (n.after || "") + "</div>"
105
+ ? '<div class="den-pin-row"' +
106
+ role +
107
+ ">" +
108
+ link +
109
+ (n.after || "") +
110
+ "</div>"
91
111
  : link;
92
112
  }
93
113
 
@@ -96,11 +116,11 @@ export function railGroupHtml(g, body, lang) {
96
116
  const id = esc(g.id);
97
117
  const from = g.from;
98
118
  return (
99
- '<div class="den-rail-group" role="group" aria-labelledby="den-gh-' +
119
+ '<div class="den-rail-group" data-nav-role="rail-group" role="group" aria-labelledby="den-gh-' +
100
120
  id +
101
121
  '"' +
102
122
  (from ? ' aria-describedby="den-gd-' + id + '"' : "") +
103
- '><div class="den-gh"><span id="den-gh-' +
123
+ '><div class="den-gh" data-nav-role="group"><span id="den-gh-' +
104
124
  id +
105
125
  '">' +
106
126
  esc(g.label) +
@@ -146,6 +166,8 @@ export function railHtml({
146
166
  nav = [],
147
167
  groups = [],
148
168
  foot = [],
169
+ settings,
170
+ account,
149
171
  lang,
150
172
  collapsed,
151
173
  } = {}) {
@@ -153,12 +175,18 @@ export function railHtml({
153
175
  for (const g of groups) {
154
176
  const items = nav.filter((n) => n.group === g.id);
155
177
  if (!items.length) continue;
156
- html += railGroupHtml(g, items.map(navItemHtml).join(""), lang);
178
+ html += railGroupHtml(
179
+ g,
180
+ items.map((n) => navItemHtml(n, "page")).join(""),
181
+ lang,
182
+ );
157
183
  }
158
184
  html += '<div class="den-rail-grow"></div>';
159
185
  html += foot
160
186
  .map((n) => (typeof n === "string" ? n : navItemHtml(n)))
161
187
  .join("");
188
+ html += settingsHtml(settings, lang);
189
+ html += accountHtml(account);
162
190
  html += collapseHtml(!!collapsed, lang);
163
191
  return html;
164
192
  }
@@ -220,7 +248,24 @@ export function reportPrefillOf(el) {
220
248
  * `text`, escaped; or `svg`, the product's own markup (the same trust as
221
249
  * the icons). `label` names it.
222
250
  */
223
- function markHtml(mark) {
251
+ /**
252
+ * The brand's mark (#den-mark).
253
+ * { src, label }: an image file (the default: the kit's marks/den.svg),
254
+ * drawn as Den's theme draws its own: span.den-mark.den-mark-svg,
255
+ * titled by label, holding an 18px <img alt="">. An image runs no
256
+ * script, so no markup of the host's is trusted.
257
+ * { text, label }: escaped text. { svg, label }: the host's own markup.
258
+ * none: the empty slot.
259
+ */
260
+ export function markHtml(mark) {
261
+ if (mark && mark.src != null)
262
+ return (
263
+ '<span class="den-mark den-mark-svg" id="den-mark" aria-hidden="true" title="' +
264
+ esc(mark.label ?? "") +
265
+ '"><img src="' +
266
+ esc(mark.src) +
267
+ '" alt="" width="18" height="18"></span>'
268
+ );
224
269
  if (!mark || (mark.text == null && mark.svg == null))
225
270
  return '<span class="den-mark" id="den-mark" aria-hidden="true"></span>';
226
271
  return (
@@ -252,7 +297,7 @@ export function topBarHtml({
252
297
  '">' +
253
298
  markHtml(product.mark) +
254
299
  // The brand is a name, not a heading: the page's own h1 is its one.
255
- '<span class="den-title">' +
300
+ '<span class="den-title" data-nav-role="brand-title">' +
256
301
  esc(name) +
257
302
  "</span></a>" +
258
303
  (slots.start || "") +
@@ -287,3 +332,572 @@ export function shellHtml(o = {}) {
287
332
  "</nav></div>"
288
333
  );
289
334
  }
335
+
336
+ // ── 0.7.0: the scope crumbs, the search field, the bell, the account ────
337
+ // Pieces of the top bar and the rail a host gave as its own HTML before.
338
+ // The host gives the words and the values; the kit draws them, and
339
+ // shell-client.js wires them (hydrateScope, hydrateSearch, hydrateBell,
340
+ // hydrateAccount). A piece left out draws nothing.
341
+
342
+ /** Crumb ids: "den-scope-<key>" unless the host names its own. */
343
+ const crumbId = (c) => c.id || "den-scope-" + (c.key || "x");
344
+
345
+ /**
346
+ * Whether a menu of `n` entries gets the filter field: `filter` false
347
+ * never, a number past that many, true always, else past 6.
348
+ */
349
+ export function menuHasFilter(filter, n) {
350
+ if (filter === false) return false;
351
+ if (filter === true) return true;
352
+ return n > (typeof filter === "number" ? filter : 6);
353
+ }
354
+
355
+ /**
356
+ * A menu's type-to-filter field (first in it) and its "No match" line
357
+ * (last): [field, none]. `label`: the menu's name ("Filter <label>").
358
+ */
359
+ export function menuFilterParts(menuId, label, lang) {
360
+ return [
361
+ '<input type="search" class="den-mfilter" id="' +
362
+ esc(menuId) +
363
+ '-filter" aria-controls="' +
364
+ esc(menuId) +
365
+ '-list" aria-label="' +
366
+ esc(kitT(lang, "kit.menu.filter", { label: label ?? "" })) +
367
+ '" placeholder="' +
368
+ esc(kitT(lang, "kit.menu.filter.ph")) +
369
+ '" autocomplete="off" spellcheck="false">',
370
+ '<p class="den-mnote den-mnone" role="status" hidden>' +
371
+ esc(kitT(lang, "kit.menu.none")) +
372
+ "</p>",
373
+ ];
374
+ }
375
+
376
+ /** A crumb's menu, drawn by the kit: links ({ label, href, current }) or HTML. */
377
+ function crumbMenuHtml(c, lang) {
378
+ const m = c.menu;
379
+ if (!m || m === true) return "";
380
+ const menuId = crumbId(c) + "-menu";
381
+ // A long list: a type-to-filter field first, "No match" last.
382
+ const filter =
383
+ Array.isArray(m) && menuHasFilter(c.filter, m.length)
384
+ ? menuFilterParts(menuId, c.label, lang)
385
+ : ["", ""];
386
+ const body = Array.isArray(m)
387
+ ? m
388
+ .map(
389
+ (l) =>
390
+ '<a class="den-mi" role="menuitem" href="' +
391
+ esc(l.href) +
392
+ '"' +
393
+ (l.current ? ' aria-current="true"' : "") +
394
+ '><span class="den-mi-l">' +
395
+ esc(l.label) +
396
+ "</span></a>",
397
+ )
398
+ .join("")
399
+ : String(m);
400
+ // With a filter, the pop-up holds the field, then the role="menu" list
401
+ // (a menu owns only its items), then "No match".
402
+ if (filter[0])
403
+ return (
404
+ '<div class="den-pop den-scope-menu" id="' +
405
+ esc(menuId) +
406
+ '" hidden>' +
407
+ filter[0] +
408
+ '<div class="den-mlist" role="menu" id="' +
409
+ esc(menuId) +
410
+ '-list" aria-label="' +
411
+ esc(c.label) +
412
+ '">' +
413
+ body +
414
+ "</div>" +
415
+ filter[1] +
416
+ "</div>"
417
+ );
418
+ return (
419
+ '<div class="den-pop den-scope-menu" id="' +
420
+ esc(menuId) +
421
+ '" role="menu" aria-label="' +
422
+ esc(c.label) +
423
+ '" hidden>' +
424
+ body +
425
+ "</div>"
426
+ );
427
+ }
428
+
429
+ /**
430
+ * One scope crumb: its small-caps key and its value. With a menu, a
431
+ * button with ▾ (aria-haspopup="menu"); without, a plain label.
432
+ * { key, label, value, menu?, id?, title?, hidden?, optional?, cls?,
433
+ * valueCls? }
434
+ * `menu`: links [{ label, href, current? }] or HTML (the kit draws and
435
+ * opens it), or true (the host opens its own: hydrateScope's onOpen).
436
+ * `filter`: a type-to-filter field at the top of a list of links: by
437
+ * default past 6 of them; a number sets that threshold; false, never.
438
+ * `optional`: the first to give way on a narrow bar. `cls`: more classes;
439
+ * `valueCls`: more classes on the value.
440
+ */
441
+ export function scopeCrumbHtml(c, lang) {
442
+ if (!c) return "";
443
+ const id = crumbId(c);
444
+ const title = c.title != null ? ' title="' + esc(c.title) + '"' : "";
445
+ const hidden = c.hidden ? " hidden" : "";
446
+ const more = (c.cls ? " " + esc(c.cls) : "") + (c.optional ? " den-opt" : "");
447
+ const key = '<span class="den-k">' + esc(c.label) + "</span> ";
448
+ if (!c.menu)
449
+ return (
450
+ '<span id="' +
451
+ esc(id) +
452
+ '" class="den-ib' +
453
+ more +
454
+ '" data-nav-role="crumb"' +
455
+ hidden +
456
+ title +
457
+ ">" +
458
+ key +
459
+ '<span class="' +
460
+ esc(c.valueCls || "den-vn") +
461
+ '">' +
462
+ esc(c.value ?? "") +
463
+ "</span></span>"
464
+ );
465
+ const own = c.menu !== true;
466
+ return (
467
+ '<button type="button" id="' +
468
+ esc(id) +
469
+ '" class="den-ib den-scope-btn' +
470
+ more +
471
+ '" data-scope="' +
472
+ esc(c.key || "") +
473
+ '" data-nav-role="crumb" aria-haspopup="menu" aria-expanded="false"' +
474
+ (own ? ' aria-controls="' + esc(id) + '-menu"' : "") +
475
+ hidden +
476
+ title +
477
+ ">" +
478
+ key +
479
+ '<span class="den-v"><span class="den-vn' +
480
+ (c.valueCls ? " " + esc(c.valueCls) : "") +
481
+ '">' +
482
+ esc(c.value ?? "") +
483
+ '</span> <span aria-hidden="true">▾</span></span></button>' +
484
+ crumbMenuHtml(c, lang)
485
+ );
486
+ }
487
+
488
+ /**
489
+ * The scope crumbs: / KEY value ▾ / KEY value ▾ …, a group named "Scope".
490
+ * scopeHtml({ crumbs, label?, lang, after? })
491
+ * A crumb left out (null, or not in the list) draws nothing, and no
492
+ * separator. Each separator after a crumb is "den-sep den-<key>-sep",
493
+ * hidden with it. `after`: the host's HTML at the group's end (a hidden
494
+ * <select> its pages read, say). No crumbs: nothing at all.
495
+ */
496
+ export function scopeHtml({ crumbs, label, lang, after } = {}) {
497
+ const list = (crumbs || []).filter(Boolean);
498
+ if (!list.length) return "";
499
+ let html =
500
+ '<div class="den-scope" role="group" aria-label="' +
501
+ esc(label ?? kitT(lang, "kit.scope")) +
502
+ '"><span class="den-sep" aria-hidden="true">/</span>';
503
+ // Each separator after a crumb comes and goes with it: host content.
504
+ list.forEach((c, i) => {
505
+ html += scopeCrumbHtml(c, lang);
506
+ if (i < list.length - 1)
507
+ html +=
508
+ '<span class="den-sep den-' +
509
+ esc(c.key || "x") +
510
+ '-sep" data-nav-role="crumb-sep" aria-hidden="true"' +
511
+ (c.hidden ? " hidden" : "") +
512
+ ">/</span>";
513
+ });
514
+ return html + (after || "") + "</div>";
515
+ }
516
+
517
+ /**
518
+ * The search field: the placeholder, then ⌘K inside it, as a button (the
519
+ * host's palette or page opens on it: hydrateSearch).
520
+ * searchHtml({ placeholder?, label?, id?, shortcut?, lang })
521
+ * `label`: its name (default the kit's "Search", in the page's language;
522
+ * the host's own words are host content for the nav inventory);
523
+ * `shortcut: false`: no ⌘K.
524
+ */
525
+ export function searchHtml({ placeholder, label, id, shortcut, lang } = {}) {
526
+ const ph = placeholder ?? kitT(lang, "kit.search.ph");
527
+ const keys = shortcut !== false;
528
+ return (
529
+ '<button type="button" class="den-search" id="' +
530
+ esc(id || "den-search") +
531
+ '" aria-haspopup="dialog" data-nav-name="host"' +
532
+ (keys ? ' aria-keyshortcuts="Meta+K Control+K"' : "") +
533
+ ' aria-label="' +
534
+ esc(label ?? kitT(lang, "kit.search.label")) +
535
+ '"><span class="den-search-ph" data-nav-role="search-ph">' +
536
+ esc(ph) +
537
+ "</span>" +
538
+ (keys ? '<kbd aria-hidden="true">⌘K</kbd>' : "") +
539
+ '<span class="den-search-ic" aria-hidden="true">⌕</span></button>'
540
+ );
541
+ }
542
+
543
+ /** The bell's count on its badge: "" for none, 99+ past 99. */
544
+ export function bellCount(n) {
545
+ const c = Number(n) || 0;
546
+ return c <= 0 ? "" : c > 99 ? "99+" : String(c);
547
+ }
548
+
549
+ /**
550
+ * The bell: a button that opens the notifications panel, with its count.
551
+ * bellButtonHtml({ count?, label?, id?, lang })
552
+ * Its name says the count ("Notifications: 3 unread").
553
+ */
554
+ export function bellButtonHtml({ count, label, id, lang } = {}) {
555
+ const n = Number(count) || 0;
556
+ const word = label ?? kitT(lang, "kit.bell");
557
+ const name = n > 0 ? kitT(lang, "kit.bell.n", { n }) : word;
558
+ return (
559
+ '<button type="button" class="den-ib den-bell" id="' +
560
+ esc(id || "den-bell") +
561
+ '" aria-haspopup="dialog" aria-expanded="false" aria-label="' +
562
+ esc(name) +
563
+ '" title="' +
564
+ esc(word) +
565
+ '"><svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg>' +
566
+ '<span class="den-bell-n"' +
567
+ (n > 0 ? "" : " hidden") +
568
+ ">" +
569
+ esc(bellCount(n)) +
570
+ "</span></button>"
571
+ );
572
+ }
573
+
574
+ /** One row of the bell's panel. */
575
+ function bellRowHtml(it) {
576
+ const text = esc(it.text ?? "");
577
+ return (
578
+ '<div class="den-bell-row' +
579
+ (it.read ? " read" : "") +
580
+ '"' +
581
+ (it.id != null ? ' data-id="' + esc(it.id) + '"' : "") +
582
+ ">" +
583
+ (it.href != null
584
+ ? '<a href="' + esc(it.href) + '">' + text + "</a>"
585
+ : '<span class="den-bell-t">' + text + "</span>") +
586
+ (it.time
587
+ ? "<time" +
588
+ (it.datetime ? ' datetime="' + esc(it.datetime) + '"' : "") +
589
+ ">" +
590
+ esc(it.time) +
591
+ "</time>"
592
+ : "") +
593
+ "</div>"
594
+ );
595
+ }
596
+
597
+ /**
598
+ * The bell's panel content: its heading, then rows or the empty state.
599
+ * bellPanelHtml({ title?, titleId?, actions?, lead?, items?, body?,
600
+ * empty?, after?, foot?, lang })
601
+ * `items`: [{ text, href?, time?, datetime?, read?, id? }], drawn as rows;
602
+ * or `body`, the host's own HTML for them. Neither (or no items): the
603
+ * empty state, `empty` { text?, more? } (more: HTML under the words).
604
+ * `actions`: buttons beside the heading (Mark all read); `lead`: HTML
605
+ * under the heading; `after`: HTML after the rows; `foot`: the footer (a
606
+ * Report button). Every HTML part is the host's own.
607
+ */
608
+ export function bellPanelHtml({
609
+ title,
610
+ titleId,
611
+ actions,
612
+ lead,
613
+ items,
614
+ body,
615
+ empty,
616
+ after,
617
+ foot,
618
+ lang,
619
+ } = {}) {
620
+ const list = Array.isArray(items) ? items : [];
621
+ const e = empty || {};
622
+ const rows =
623
+ body != null && body !== ""
624
+ ? body
625
+ : list.length
626
+ ? list.map(bellRowHtml).join("")
627
+ : '<div class="den-bell-empty"><p>' +
628
+ esc(e.text ?? kitT(lang, "kit.bell.empty")) +
629
+ "</p>" +
630
+ (e.more || "") +
631
+ "</div>";
632
+ return (
633
+ '<div class="den-bell-hd"><h2 id="' +
634
+ esc(titleId || "den-bell-h") +
635
+ '">' +
636
+ esc(title ?? kitT(lang, "kit.bell")) +
637
+ "</h2>" +
638
+ (actions || "") +
639
+ "</div>" +
640
+ (lead || "") +
641
+ rows +
642
+ (after || "") +
643
+ (foot || "")
644
+ );
645
+ }
646
+
647
+ /**
648
+ * The account entry, in the rail's foot: who is signed in, here.
649
+ * accountHtml({ label, detail?, href?, action?, icon?, id?, navId?,
650
+ * attrs?, current? })
651
+ * `href`: a link; else `menu` true: a button opening the account menu
652
+ * (accountMenuHtml, hydrateAccount's menu; id "den-account" unless
653
+ * given); else `action` true: a button (hydrateAccount's onAction). The
654
+ * name and tooltip read "label · detail". It is a rail entry (.den-ni)
655
+ * marked data-den-account. No label: nothing.
656
+ */
657
+ export function accountHtml(a) {
658
+ if (!a || !a.label) return "";
659
+ const full = a.detail ? a.label + " · " + a.detail : a.label;
660
+ const more = { ...(a.attrs || {}) };
661
+ if (a.id) more.id = a.id;
662
+ // Who is signed in: the host's words (host content for the nav inventory).
663
+ const words =
664
+ '<span class="den-lbl" data-nav-role="account-name">' +
665
+ esc(a.label) +
666
+ (a.detail
667
+ ? '<span class="den-acct-d"> · ' + esc(a.detail) + "</span>"
668
+ : "") +
669
+ "</span>";
670
+ if (a.href == null && a.menu && !a.id) more.id = "den-account";
671
+ const open =
672
+ a.href != null
673
+ ? '<a class="den-ni" data-den-account href="' + esc(a.href) + '"'
674
+ : a.menu
675
+ ? '<button type="button" class="den-ni" data-den-account aria-haspopup="menu" aria-expanded="false"'
676
+ : '<button type="button" class="den-ni" data-den-account data-act="account"';
677
+ return (
678
+ open +
679
+ ' data-nav="' +
680
+ esc(a.navId || "account") +
681
+ '"' +
682
+ (a.current ? ' aria-current="page"' : "") +
683
+ attrs(more) +
684
+ ' title="' +
685
+ esc(full) +
686
+ '">' +
687
+ icon(a.icon || "person") +
688
+ words +
689
+ (a.href != null ? "</a>" : "</button>")
690
+ );
691
+ }
692
+
693
+ /**
694
+ * The Settings entry, in the rail's foot after the host's entries.
695
+ * settingsHtml({ href, label?, current?, id? }, lang)
696
+ * No href: nothing.
697
+ */
698
+ export function settingsHtml(o, lang) {
699
+ if (!o || !o.href) return "";
700
+ return navItemHtml({
701
+ id: o.id || "settings",
702
+ href: o.href,
703
+ label: o.label ?? kitT(lang, "kit.settings"),
704
+ icon: "settings",
705
+ current: !!o.current,
706
+ });
707
+ }
708
+
709
+ /**
710
+ * The appearance button, ◐ ▾, last in the bar (the `account` slot): its
711
+ * menu (hydrateAppearance) holds the mode, the theme and the language.
712
+ * appearanceButtonHtml({ id?, label?, title?, lang })
713
+ */
714
+ export function appearanceButtonHtml({ id, label, title, lang } = {}) {
715
+ return (
716
+ '<button id="' +
717
+ esc(id || "appearance-btn") +
718
+ '" type="button" class="den-ib appearance-btn" title="' +
719
+ esc(title ?? kitT(lang, "kit.appearance.title")) +
720
+ '" aria-label="' +
721
+ esc(label ?? kitT(lang, "kit.appearance")) +
722
+ '" aria-haspopup="menu" aria-expanded="false"><span aria-hidden="true">◐ ▾</span></button>'
723
+ );
724
+ }
725
+
726
+ /** One row of a kit menu: a radio (checked set), a link or a button. */
727
+ function menuRowHtml(r) {
728
+ const radio = r.checked != null;
729
+ const tag = r.href != null ? "a" : "button";
730
+ return (
731
+ "<" +
732
+ tag +
733
+ ' class="den-mi" tabindex="-1" role="' +
734
+ (radio ? "menuitemradio" : "menuitem") +
735
+ '"' +
736
+ (radio ? ' aria-checked="' + (r.checked ? "true" : "false") + '"' : "") +
737
+ (r.href != null ? ' href="' + esc(r.href) + '"' : ' type="button"') +
738
+ (r.kind ? ' data-kind="' + esc(r.kind) + '"' : "") +
739
+ (r.value != null ? ' data-value="' + esc(r.value) + '"' : "") +
740
+ '><span class="den-mi-l">' +
741
+ esc(r.label) +
742
+ "</span></" +
743
+ tag +
744
+ ">"
745
+ );
746
+ }
747
+
748
+ /**
749
+ * The appearance menu's content.
750
+ * appearanceMenuHtml({ mode, modes?, themes?, notice?, languages?,
751
+ * items?, lang })
752
+ * mode: "system", "dark" or "light" (checked); modes: [{ value, label }]
753
+ * (default the kit's System, Dark, Light); themes: [{ value, label,
754
+ * selected? }]; notice: a line under the themes; languages: [{ id, name,
755
+ * current? }], each named in itself; items: [{ label, href? | id }] after
756
+ * a rule (Settings, say). A part with nothing in it draws nothing.
757
+ */
758
+ export function appearanceMenuHtml({
759
+ mode,
760
+ modes,
761
+ themes,
762
+ notice,
763
+ languages,
764
+ items,
765
+ lang,
766
+ } = {}) {
767
+ const head = (w) =>
768
+ '<div class="den-ml" aria-hidden="true">' + esc(w) + "</div>";
769
+ const hr = '<div class="den-hr" role="separator"></div>';
770
+ const ms = modes || [
771
+ { value: "system", label: kitT(lang, "kit.mode.system") },
772
+ { value: "dark", label: kitT(lang, "kit.mode.dark") },
773
+ { value: "light", label: kitT(lang, "kit.mode.light") },
774
+ ];
775
+ const parts = [];
776
+ parts.push(
777
+ head(kitT(lang, "kit.appearance")) +
778
+ ms
779
+ .map((m) =>
780
+ menuRowHtml({
781
+ label: m.label,
782
+ checked: m.value === mode,
783
+ kind: "mode",
784
+ value: m.value,
785
+ }),
786
+ )
787
+ .join(""),
788
+ );
789
+ if ((themes && themes.length) || notice)
790
+ parts.push(
791
+ head(kitT(lang, "kit.theme")) +
792
+ (themes || [])
793
+ .map((t) =>
794
+ menuRowHtml({
795
+ label: t.label,
796
+ checked: !!t.selected,
797
+ kind: "theme",
798
+ value: t.value ?? "",
799
+ }),
800
+ )
801
+ .join("") +
802
+ (notice
803
+ ? '<p class="den-mnote" role="status">' + esc(notice) + "</p>"
804
+ : ""),
805
+ );
806
+ if (languages && languages.length)
807
+ parts.push(
808
+ head(kitT(lang, "kit.language")) +
809
+ languages
810
+ .map((l) =>
811
+ menuRowHtml({
812
+ label: l.name,
813
+ checked: !!l.current,
814
+ kind: "language",
815
+ value: l.id,
816
+ }),
817
+ )
818
+ .join(""),
819
+ );
820
+ if (items && items.length)
821
+ parts.push(
822
+ items
823
+ .map((it) =>
824
+ menuRowHtml({
825
+ label: it.label,
826
+ href: it.href,
827
+ kind: "item",
828
+ value: it.id,
829
+ }),
830
+ )
831
+ .join(""),
832
+ );
833
+ return parts.join(hr);
834
+ }
835
+
836
+ /**
837
+ * The account entry's menu: who is signed in (name), where (detail), a
838
+ * rule, then the entries.
839
+ * accountMenuHtml({ name, detail?, items, lang })
840
+ * items: [{ label, href }] links, [{ label, id }] buttons (onPick "item"),
841
+ * or [{ label, action: { method?, url, csrf?, field? } }]: a form that
842
+ * posts to url on its own, with no script (csrf, if any, in a hidden
843
+ * field named `field`, "csrf" by default).
844
+ */
845
+ export function accountMenuHtml({ name, detail, items } = {}) {
846
+ const parts = [];
847
+ const who =
848
+ (name ? '<div class="den-ml">' + esc(name) + "</div>" : "") +
849
+ (detail ? '<p class="den-mnote">' + esc(detail) + "</p>" : "");
850
+ if (who) parts.push(who);
851
+ const rows = (items || [])
852
+ .map((it) => {
853
+ if (!it || !it.label) return "";
854
+ const a = it.action;
855
+ if (a && a.url)
856
+ return (
857
+ '<form class="den-mform" method="' +
858
+ esc(a.method || "post") +
859
+ '" action="' +
860
+ esc(a.url) +
861
+ '">' +
862
+ (a.csrf != null
863
+ ? '<input type="hidden" name="' +
864
+ esc(a.field || "csrf") +
865
+ '" value="' +
866
+ esc(a.csrf) +
867
+ '">'
868
+ : "") +
869
+ '<button type="submit" class="den-mi" tabindex="-1" role="menuitem"><span class="den-mi-l">' +
870
+ esc(it.label) +
871
+ "</span></button></form>"
872
+ );
873
+ return menuRowHtml({
874
+ label: it.label,
875
+ href: it.href,
876
+ kind: "item",
877
+ value: it.id,
878
+ });
879
+ })
880
+ .join("");
881
+ if (rows) parts.push(rows);
882
+ return parts.join('<div class="den-hr" role="separator"></div>');
883
+ }
884
+
885
+ /**
886
+ * The update-waiting pill beside the version chip: ⚠ and its words, a
887
+ * button (setWaiting in version.js shows and wires it).
888
+ * waitingHtml({ label, action, title?, name?, id? })
889
+ * Reads "⚠ label · action"; below 720px only ⚠.
890
+ */
891
+ export function waitingHtml({ label, action, title, name, id } = {}) {
892
+ return (
893
+ '<button id="' +
894
+ esc(id || "stale-pill") +
895
+ '" class="stale-pill"' +
896
+ (title != null ? ' title="' + esc(title) + '"' : "") +
897
+ (name != null ? ' aria-label="' + esc(name) + '"' : "") +
898
+ '><span aria-hidden="true">⚠</span><span class="stale-lbl"> ' +
899
+ esc(label ?? "") +
900
+ (action != null ? " · <b>" + esc(action) + "</b>" : "") +
901
+ "</span></button>"
902
+ );
903
+ }