@monster-orange/den-ui 0.5.1 → 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.
Files changed (45) hide show
  1. package/README.md +515 -1
  2. package/bin/den-ui-parity.mjs +440 -0
  3. package/inventory/fonts-dir.cjs +8 -0
  4. package/inventory/fonts-dir.mjs +10 -0
  5. package/inventory/nav-inventory.d.ts +133 -0
  6. package/inventory/nav-inventory.js +839 -0
  7. package/inventory/reference/den-chromium-1280.json +5388 -0
  8. package/inventory/reference/den-chromium-390.json +3834 -0
  9. package/inventory/reference/den-webkit-1280.json +5388 -0
  10. package/inventory/reference/den-webkit-390.json +3834 -0
  11. package/package.json +40 -3
  12. package/src/busy-words.d.ts +2 -0
  13. package/src/busy-words.js +6 -0
  14. package/src/busy.css +155 -0
  15. package/src/busy.d.ts +80 -0
  16. package/src/busy.js +105 -35
  17. package/src/dialog.css +103 -0
  18. package/src/dialog.d.ts +44 -0
  19. package/src/dialog.js +95 -30
  20. package/src/icons.d.ts +4 -0
  21. package/src/icons.js +43 -0
  22. package/src/kit.d.ts +217 -0
  23. package/src/kit.js +299 -0
  24. package/src/marks/den.svg +6 -0
  25. package/src/report-shot.d.ts +47 -0
  26. package/src/report-shot.js +437 -0
  27. package/src/report.css +387 -0
  28. package/src/report.d.ts +61 -0
  29. package/src/report.js +909 -0
  30. package/src/shell-client.d.ts +149 -0
  31. package/src/shell-client.js +820 -0
  32. package/src/shell-html.d.ts +305 -0
  33. package/src/shell-html.js +903 -0
  34. package/src/shell.css +1010 -0
  35. package/src/strings.d.ts +18 -0
  36. package/src/strings.js +565 -0
  37. package/src/time.d.ts +18 -0
  38. package/src/time.js +14 -2
  39. package/src/tokens.css +81 -67
  40. package/src/update-pill.d.ts +17 -0
  41. package/src/version.d.ts +7 -0
  42. package/src/version.js +31 -0
  43. package/src/whatsnew.css +235 -0
  44. package/src/whatsnew.d.ts +36 -0
  45. package/src/whatsnew.js +411 -0
@@ -0,0 +1,903 @@
1
+ /**
2
+ * den-ui shell markup: the global shell (top bar and left rail), the
3
+ * version chip and the Report button, as HTML strings. Pure: no DOM, so it
4
+ * runs in Node (a server renders the page with it from the first byte) and
5
+ * in the page (a client draws or redraws the rail with it). The client
6
+ * script (shell-client.js) only hydrates what this drew.
7
+ *
8
+ * No inline style attributes, no inline handlers: the markup is clean
9
+ * under `script-src 'self'; style-src 'self'`. Its look is shell.css.
10
+ *
11
+ * shellHtml({ product, nav, groups, foot, settings, account, lang, slots,
12
+ * collapsed, report })
13
+ * product { name, title?, version?, href?, mark? } the brand: `name` is the
14
+ * word beside the mark, `title` its tooltip (default name),
15
+ * `version` the chip's text ("v" + version; "v…" when unknown),
16
+ * `href` where the brand goes (default "/"), `mark`
17
+ * { text?, svg?, label } the mark beside it (text escaped;
18
+ * svg the product's own markup; label its name)
19
+ * nav [{ id, label, href, group, icon?, tip?, current?, badge?,
20
+ * lead?, mono?, cls?, attrs?, pin?, after? }] rail entries
21
+ * groups [{ id, label, from? }] in rail order; a group with no
22
+ * entry is left out
23
+ * foot entries under the rail's spacer (Settings, say), then the
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)
29
+ * lang "en", "es" or "ja" (the kit's words; else en)
30
+ * slots { start, end, bell, account }: the product's own HTML in
31
+ * the top bar. start: after the brand; end: the right group's
32
+ * start, before Report; bell, account: after Report, so the
33
+ * right group reads Report · bell · version · account
34
+ * collapsed the rail drawn collapsed (the toggle says Expand)
35
+ * report false: no Report button (reports off)
36
+ *
37
+ * An entry: `badge` { n, bad?, label? } (label is read with the name);
38
+ * `lead` HTML in place of the icon (a status dot); `attrs` more
39
+ * attributes { name: value } (escaped); `cls` more classes; `pin` the
40
+ * pinned id (the row is a pin row: Delete unpins it); `after` HTML after
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).
46
+ */
47
+ import { esc, kitT } from "./strings.js";
48
+ import { icon } from "./icons.js";
49
+
50
+ export { icon } from "./icons.js";
51
+ export { esc } from "./strings.js";
52
+
53
+ function attrs(o) {
54
+ let s = "";
55
+ if (!o) return s;
56
+ for (const k of Object.keys(o)) {
57
+ const v = o[k];
58
+ if (v == null || v === false) continue;
59
+ s += v === true ? ` ${k}` : ` ${k}="${esc(v)}"`;
60
+ }
61
+ return s;
62
+ }
63
+
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) + '"' : "";
71
+ const b = n.badge || null;
72
+ const extra = b
73
+ ? '<span class="den-bdg' +
74
+ (b.bad ? " bad" : "") +
75
+ '" aria-hidden="true">' +
76
+ esc(b.n) +
77
+ "</span>"
78
+ : "";
79
+ const more = { ...(n.attrs || {}) };
80
+ if (b && b.label && more["aria-label"] == null)
81
+ more["aria-label"] = n.label + ", " + b.label;
82
+ const link =
83
+ '<a class="den-ni' +
84
+ (n.cls ? " " + esc(n.cls) : "") +
85
+ '" href="' +
86
+ esc(n.href) +
87
+ '" data-nav="' +
88
+ esc(n.id) +
89
+ '"' +
90
+ (n.pin != null ? "" : role) +
91
+ (n.current ? ' aria-current="page"' : "") +
92
+ attrs(more) +
93
+ ' title="' +
94
+ esc(n.tip || n.label) +
95
+ '">' +
96
+ (n.lead || icon(n.icon)) +
97
+ '<span class="den-lbl' +
98
+ (n.mono ? " den-mono" : "") +
99
+ '">' +
100
+ esc(n.label) +
101
+ "</span>" +
102
+ extra +
103
+ "</a>";
104
+ return n.pin != null
105
+ ? '<div class="den-pin-row"' +
106
+ role +
107
+ ">" +
108
+ link +
109
+ (n.after || "") +
110
+ "</div>"
111
+ : link;
112
+ }
113
+
114
+ /** A rail group: its heading (and "from <d>" tag) and its entries. */
115
+ export function railGroupHtml(g, body, lang) {
116
+ const id = esc(g.id);
117
+ const from = g.from;
118
+ return (
119
+ '<div class="den-rail-group" data-nav-role="rail-group" role="group" aria-labelledby="den-gh-' +
120
+ id +
121
+ '"' +
122
+ (from ? ' aria-describedby="den-gd-' + id + '"' : "") +
123
+ '><div class="den-gh" data-nav-role="group"><span id="den-gh-' +
124
+ id +
125
+ '">' +
126
+ esc(g.label) +
127
+ "</span>" +
128
+ (from
129
+ ? '<span class="den-tagx" aria-hidden="true" title="' +
130
+ esc(kitT(lang, "kit.from", { d: from })) +
131
+ '">' +
132
+ esc(from) +
133
+ "</span>"
134
+ : "") +
135
+ "</div>" +
136
+ (from
137
+ ? '<span class="den-sr" id="den-gd-' +
138
+ id +
139
+ '">' +
140
+ esc(kitT(lang, "kit.from", { d: from })) +
141
+ "</span>"
142
+ : "") +
143
+ body +
144
+ "</div>"
145
+ );
146
+ }
147
+
148
+ /** The collapse toggle at the rail's foot. */
149
+ function collapseHtml(collapsed, lang) {
150
+ const word = kitT(lang, collapsed ? "kit.expand" : "kit.collapse");
151
+ return (
152
+ '<button class="den-ni den-collapse-btn" type="button" data-act="collapse" aria-expanded="' +
153
+ (collapsed ? "false" : "true") +
154
+ '" title="' +
155
+ esc(word) +
156
+ '"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="' +
157
+ (collapsed ? "M9 6l6 6-6 6" : "M15 6l-6 6 6 6") +
158
+ '"/></svg><span class="den-lbl">' +
159
+ esc(word) +
160
+ "</span></button>"
161
+ );
162
+ }
163
+
164
+ /** The rail's content: the groups, the spacer, the foot, the toggle. */
165
+ export function railHtml({
166
+ nav = [],
167
+ groups = [],
168
+ foot = [],
169
+ settings,
170
+ account,
171
+ lang,
172
+ collapsed,
173
+ } = {}) {
174
+ let html = "";
175
+ for (const g of groups) {
176
+ const items = nav.filter((n) => n.group === g.id);
177
+ if (!items.length) continue;
178
+ html += railGroupHtml(
179
+ g,
180
+ items.map((n) => navItemHtml(n, "page")).join(""),
181
+ lang,
182
+ );
183
+ }
184
+ html += '<div class="den-rail-grow"></div>';
185
+ html += foot
186
+ .map((n) => (typeof n === "string" ? n : navItemHtml(n)))
187
+ .join("");
188
+ html += settingsHtml(settings, lang);
189
+ html += accountHtml(account);
190
+ html += collapseHtml(!!collapsed, lang);
191
+ return html;
192
+ }
193
+
194
+ /** The version chip: "v<version>" (v… until known); a click opens What's new. */
195
+ export function versionChipHtml({ version, lang } = {}) {
196
+ return (
197
+ '<button class="den-ib v-pill" id="version-pill" title="' +
198
+ esc(kitT(lang, "kit.version.title")) +
199
+ '"><span class="v-txt">' +
200
+ esc(version ? "v" + String(version).replace(/^v/, "") : "v…") +
201
+ '</span><span class="v-pip" id="v-pip"></span></button>'
202
+ );
203
+ }
204
+
205
+ /**
206
+ * The Report button: the flat speech bubble, the word, ⌘⇧F (hidden on a
207
+ * phone). `inFoot`: a pop-up's footer; `inTop`: the top bar. `label`:
208
+ * the button's own words (a row's "Report this"), its name too. `prefill`:
209
+ * { kind?, title?, description? }, kept as JSON on the button; the kit's
210
+ * click opens Report with it. A click on any [data-den-report] opens the
211
+ * Report form (the client's job).
212
+ */
213
+ export function reportButtonHtml({ inFoot, inTop, lang, label, prefill } = {}) {
214
+ return (
215
+ '<button type="button" class="den-rb' +
216
+ (inFoot ? " den-rb-in" : "") +
217
+ (inTop ? " den-rb-top" : "") +
218
+ '" data-den-report' +
219
+ (prefill
220
+ ? ' data-den-report-prefill="' + esc(JSON.stringify(prefill)) + '"'
221
+ : "") +
222
+ (label != null ? ' aria-label="' + esc(label) + '"' : "") +
223
+ ' aria-keyshortcuts="Meta+Shift+F Control+Shift+F" title="' +
224
+ esc(kitT(lang, "kit.report.tip")) +
225
+ '">' +
226
+ icon("report") +
227
+ "<span>" +
228
+ esc(label != null ? label : kitT(lang, "kit.report.word")) +
229
+ '</span><kbd aria-hidden="true">⌘⇧F</kbd></button>'
230
+ );
231
+ }
232
+
233
+ /** A Report button's prefill (data-den-report-prefill), or undefined. */
234
+ export function reportPrefillOf(el) {
235
+ const raw =
236
+ el && el.getAttribute && el.getAttribute("data-den-report-prefill");
237
+ if (!raw) return undefined;
238
+ try {
239
+ const p = JSON.parse(raw);
240
+ return p && typeof p === "object" ? p : undefined;
241
+ } catch {
242
+ return undefined;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * The brand's mark: none, the empty slot (a product may fill it itself);
248
+ * `text`, escaped; or `svg`, the product's own markup (the same trust as
249
+ * the icons). `label` names it.
250
+ */
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
+ );
269
+ if (!mark || (mark.text == null && mark.svg == null))
270
+ return '<span class="den-mark" id="den-mark" aria-hidden="true"></span>';
271
+ return (
272
+ '<span class="den-mark" id="den-mark" role="img" aria-label="' +
273
+ esc(mark.label ?? "") +
274
+ '">' +
275
+ (mark.svg != null ? String(mark.svg) : esc(mark.text)) +
276
+ "</span>"
277
+ );
278
+ }
279
+
280
+ /** The top bar (header.den-top). */
281
+ export function topBarHtml({
282
+ product = {},
283
+ lang,
284
+ slots = {},
285
+ report = true,
286
+ } = {}) {
287
+ const name = product.name ?? "";
288
+ return (
289
+ '<header class="den-top">' +
290
+ '<button class="den-ib den-menu-btn" id="den-menu-btn" aria-label="' +
291
+ esc(kitT(lang, "kit.menu")) +
292
+ '" aria-expanded="false" aria-controls="den-rail">☰</button>' +
293
+ '<a class="den-brand" href="' +
294
+ esc(product.href || "/") +
295
+ '" title="' +
296
+ esc(product.title || name) +
297
+ '">' +
298
+ markHtml(product.mark) +
299
+ // The brand is a name, not a heading: the page's own h1 is its one.
300
+ '<span class="den-title" data-nav-role="brand-title">' +
301
+ esc(name) +
302
+ "</span></a>" +
303
+ (slots.start || "") +
304
+ '<div class="den-chips">' +
305
+ (slots.end || "") +
306
+ (report === false ? "" : reportButtonHtml({ inTop: true, lang })) +
307
+ (slots.bell || "") +
308
+ versionChipHtml({ version: product.version, lang }) +
309
+ (slots.account || "") +
310
+ "</div>" +
311
+ "</header>"
312
+ );
313
+ }
314
+
315
+ /**
316
+ * The whole shell: the skip link, the top bar and the rail (in its box:
317
+ * no box of its own, display: contents; as ☰'s drawer it is the modal
318
+ * dialog the rail sits in, so the rail stays a nav).
319
+ */
320
+ export function shellHtml(o = {}) {
321
+ const lang = o.lang;
322
+ return (
323
+ '<a class="den-skip" href="#den-content">' +
324
+ esc(kitT(lang, "kit.skip")) +
325
+ "</a>" +
326
+ topBarHtml(o) +
327
+ '<div class="den-rail-box" id="den-rail-box">' +
328
+ '<nav class="den-rail" id="den-rail" aria-label="' +
329
+ esc(kitT(lang, "kit.pages")) +
330
+ '">' +
331
+ railHtml(o) +
332
+ "</nav></div>"
333
+ );
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
+ }