@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,411 @@
1
+ /**
2
+ * den-ui What's new: the release notes pop-up, opened from the version
3
+ * chip (or on a new version's first visit). Its look is whatsnew.css.
4
+ *
5
+ * configureWhatsNew({ lang, changelog, reportButton, onClose })
6
+ * lang the kit's words' language (a string or a function)
7
+ * changelog() the product's adapter: Promise of the entries, newest
8
+ * first: [{ version, date, note?, raw?, sections:
9
+ * { "Added": [{ text, sub? }] } }]
10
+ * reportButton() the footer's Report button HTML ("" when reports
11
+ * are off); default the kit's
12
+ * onClose(latest) after a close: the newest version, to remember it
13
+ * as seen (the chip's dot goes)
14
+ * loadWhatsNew() asks changelog() and keeps the entries
15
+ * setEntries(list) or gives them directly
16
+ * openWhatsNew() opens it at the newest release; focus on its heading
17
+ * closeWhatsNew() closes it; focus back where it was (else the chip)
18
+ * changelogView(entries, showAll) what it shows (pure)
19
+ *
20
+ * It is an aria-modal dialog: Tab stays in it, Escape and a click on the
21
+ * veil close it. Markdown and Slack copy buttons on each version.
22
+ */
23
+ import { esc, kitT } from "./strings.js";
24
+ import { reportButtonHtml } from "./shell-html.js";
25
+ import { focusBack, openerOf } from "./dialog.js";
26
+
27
+ const cfg = {
28
+ lang: "en",
29
+ changelog: null,
30
+ reportButton: null,
31
+ onClose: null,
32
+ };
33
+ let entries = [];
34
+ let showAll = false;
35
+ let returnFocus = null;
36
+ let made = false;
37
+
38
+ const lang = () => (typeof cfg.lang === "function" ? cfg.lang() : cfg.lang);
39
+ const t = (key, vars) => kitT(lang(), key, vars);
40
+ const escT = (key, vars) => esc(t(key, vars));
41
+
42
+ export function configureWhatsNew(o = {}) {
43
+ Object.assign(cfg, o);
44
+ }
45
+
46
+ /**
47
+ * What the pop-up shows: the newest release only, or every version once
48
+ * the reader asks for them, plus the one button that toggles between the
49
+ * two (null when there is nothing earlier to show).
50
+ */
51
+ export function changelogView(list, all) {
52
+ const l = Array.isArray(list) ? list : [];
53
+ const earlier = l.length - 1;
54
+ if (earlier < 1) return { shown: l.slice(0, 1), toggle: null };
55
+ return {
56
+ shown: all ? l : l.slice(0, 1),
57
+ toggle: all
58
+ ? { label: "Show latest only", expanded: true }
59
+ : { label: `Show all versions (${earlier} earlier)`, expanded: false },
60
+ };
61
+ }
62
+
63
+ export function setEntries(list) {
64
+ entries = Array.isArray(list) ? list : [];
65
+ }
66
+ export function getEntries() {
67
+ return entries;
68
+ }
69
+
70
+ export async function loadWhatsNew() {
71
+ try {
72
+ setEntries(cfg.changelog ? await cfg.changelog() : []);
73
+ } catch {
74
+ setEntries([]);
75
+ }
76
+ return entries;
77
+ }
78
+
79
+ /** The overlay, made once (hidden until opened). */
80
+ export function ensureWhatsNew() {
81
+ if (made && document.getElementById("cl-overlay")) return;
82
+ made = true;
83
+ const report = cfg.reportButton
84
+ ? cfg.reportButton()
85
+ : reportButtonHtml({ inFoot: false, lang: lang() });
86
+ const overlay = document.createElement("div");
87
+ overlay.id = "cl-overlay";
88
+ overlay.className = "cl-overlay";
89
+ overlay.innerHTML =
90
+ '<div class="cl-box" role="dialog" aria-modal="true" aria-labelledby="cl-title">' +
91
+ `<div class="cl-hdr"><h3 id="cl-title" tabindex="-1">${escT("kit.whatsnew.title")}</h3><button type="button" class="cl-close" id="cl-close-btn" title="${escT("kit.whatsnew.close")}" aria-label="${escT("kit.whatsnew.close")}">×</button></div>` +
92
+ '<div class="cl-body" id="cl-body"></div>' +
93
+ '<div class="cl-footer">' +
94
+ // Report, as in every pop-up.
95
+ (report || "") +
96
+ '<button type="button" class="cl-more-btn" id="cl-more" aria-controls="cl-body" aria-expanded="false" hidden></button><button class="cl-got-it" id="cl-got-it-btn">' +
97
+ escT("kit.whatsnew.gotIt") +
98
+ "</button></div>" +
99
+ "</div>";
100
+ document.body.appendChild(overlay);
101
+ document.getElementById("cl-more")?.addEventListener("click", () => {
102
+ showAll = !showAll;
103
+ renderBody();
104
+ const body = document.getElementById("cl-body");
105
+ if (body) body.scrollTop = 0;
106
+ });
107
+ overlay.addEventListener("click", (e) => {
108
+ if (e.target === overlay) closeWhatsNew();
109
+ });
110
+ document
111
+ .getElementById("cl-close-btn")
112
+ ?.addEventListener("click", () => closeWhatsNew());
113
+ document
114
+ .getElementById("cl-got-it-btn")
115
+ ?.addEventListener("click", () => closeWhatsNew());
116
+ document.addEventListener("keydown", (e) => {
117
+ if (!overlay.classList.contains("open")) return;
118
+ if (e.key === "Escape") {
119
+ e.preventDefault();
120
+ closeWhatsNew();
121
+ } else if (e.key === "Tab") trapTab(e, overlay);
122
+ });
123
+ }
124
+
125
+ /** Tab and Shift+Tab stay inside the open dialog (aria-modal). */
126
+ function trapTab(e, overlay) {
127
+ const box = overlay.querySelector(".cl-box");
128
+ const stops = [
129
+ ...box.querySelectorAll("button, a[href], [tabindex]:not([tabindex='-1'])"),
130
+ ].filter((el) => !el.hidden && !el.disabled && el.getClientRects().length);
131
+ if (!stops.length) return;
132
+ const first = stops[0];
133
+ const last = stops[stops.length - 1];
134
+ const at = document.activeElement;
135
+ // Anything not one of the stops (the focused heading, or outside) counts
136
+ // as outside: Shift+Tab from the heading must not leave the dialog.
137
+ const inside = stops.includes(at);
138
+ if (e.shiftKey ? at === first || !inside : at === last) {
139
+ e.preventDefault();
140
+ (e.shiftKey ? last : first).focus();
141
+ } else if (!inside) {
142
+ e.preventDefault();
143
+ first.focus();
144
+ }
145
+ }
146
+
147
+ const COPY_ICON =
148
+ '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
149
+ '<rect x="4" y="0.5" width="8.5" height="8.5" rx="1.5"/>' +
150
+ '<path d="M8.5 9v2.5a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h2.5"/>' +
151
+ "</svg>";
152
+ const SLACK_ICON =
153
+ '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
154
+ '<path d="M1 2a1 1 0 0 1 1-1h9a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7.5L5 12v-3H2a1 1 0 0 1-1-1V2z"/>' +
155
+ "</svg>";
156
+ const CHECK_ICON =
157
+ '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
158
+ '<polyline points="2,7 5,10 11,3"/>' +
159
+ "</svg>";
160
+
161
+ const escHtml = (s) =>
162
+ String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
163
+ const renderItem = (s) =>
164
+ escHtml(s)
165
+ .replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
166
+ .replace(/`([^`]+)`/g, "<code>$1</code>");
167
+
168
+ /** The body: the release(s) shown, and the footer's toggle. */
169
+ export function renderBody() {
170
+ const body = document.getElementById("cl-body");
171
+ if (!body) return;
172
+ if (!entries.length) {
173
+ body.innerHTML = `<p class="cl-none">${escT("kit.whatsnew.none")}</p>`;
174
+ return;
175
+ }
176
+ const view = changelogView(entries, showAll);
177
+ body.innerHTML = view.shown
178
+ .map(
179
+ (entry, i) =>
180
+ (i > 0 ? '<hr class="cl-divider">' : "") +
181
+ '<div class="cl-entry">' +
182
+ '<div class="cl-ver-row">' +
183
+ '<h4 class="cl-ver">v' +
184
+ escHtml(entry.version) +
185
+ "</h4>" +
186
+ '<span class="cl-date">' +
187
+ escHtml(entry.date) +
188
+ "</span>" +
189
+ '<div class="cl-copy-group">' +
190
+ '<button class="cl-copy-btn" data-cl-version="' +
191
+ escHtml(entry.version) +
192
+ '" title="' +
193
+ escT("kit.whatsnew.copyMd") +
194
+ '" aria-label="' +
195
+ escT("kit.whatsnew.copyMdX", { v: entry.version }) +
196
+ '">' +
197
+ COPY_ICON +
198
+ "</button>" +
199
+ '<button class="cl-slack-btn" data-cl-version="' +
200
+ escHtml(entry.version) +
201
+ '" title="' +
202
+ escT("kit.whatsnew.copySlack") +
203
+ '" aria-label="' +
204
+ escT("kit.whatsnew.copySlackX", { v: entry.version }) +
205
+ '">' +
206
+ SLACK_ICON +
207
+ "</button>" +
208
+ "</div>" +
209
+ "</div>" +
210
+ (entry.note
211
+ ? '<p class="cl-note">' + renderItem(entry.note) + "</p>"
212
+ : "") +
213
+ Object.entries(entry.sections ?? {})
214
+ .map(
215
+ ([sec, items]) =>
216
+ '<div class="cl-sec">' +
217
+ escHtml(sec) +
218
+ "</div>" +
219
+ '<ul class="cl-items">' +
220
+ items
221
+ .map(
222
+ (it) =>
223
+ "<li>" +
224
+ renderItem(it.text) +
225
+ (it.sub?.length
226
+ ? '<ul class="cl-subitems">' +
227
+ it.sub
228
+ .map((s) => "<li>" + renderItem(s) + "</li>")
229
+ .join("") +
230
+ "</ul>"
231
+ : "") +
232
+ "</li>",
233
+ )
234
+ .join("") +
235
+ "</ul>",
236
+ )
237
+ .join("") +
238
+ "</div>",
239
+ )
240
+ .join("");
241
+
242
+ // The toggle lives in the footer, so it is in view however long the
243
+ // newest entry is.
244
+ const more = document.getElementById("cl-more");
245
+ if (more) {
246
+ more.hidden = !view.toggle;
247
+ if (view.toggle) {
248
+ more.textContent = view.toggle.expanded
249
+ ? t("kit.whatsnew.latest")
250
+ : t("kit.whatsnew.all", { n: entries.length - 1 });
251
+ more.setAttribute("aria-expanded", String(view.toggle.expanded));
252
+ }
253
+ }
254
+
255
+ const copyBtn = (sel, icon, title, make, write) =>
256
+ body.querySelectorAll(sel).forEach((btn) => {
257
+ btn.addEventListener("click", async () => {
258
+ const entry = entries.find((e) => e.version === btn.dataset.clVersion);
259
+ if (!entry) return;
260
+ try {
261
+ await write(make(entry));
262
+ btn.innerHTML = CHECK_ICON;
263
+ btn.classList.add("copied");
264
+ setTimeout(() => {
265
+ btn.innerHTML = icon;
266
+ btn.classList.remove("copied");
267
+ }, 2000);
268
+ } catch {
269
+ btn.title = t("kit.whatsnew.copyFailed");
270
+ setTimeout(() => (btn.title = t(title)), 2000);
271
+ }
272
+ });
273
+ });
274
+ // Markdown copy: plain text for GitHub, MD editors, etc.
275
+ copyBtn(
276
+ ".cl-copy-btn",
277
+ COPY_ICON,
278
+ "kit.whatsnew.copyMd",
279
+ (e) => e.raw || buildMarkdown(e),
280
+ copyText,
281
+ );
282
+ // Rich copy: a DOM selection's HTML, which Slack (and Notion, Docs)
283
+ // trusts and renders as formatted text.
284
+ copyBtn(
285
+ ".cl-slack-btn",
286
+ SLACK_ICON,
287
+ "kit.whatsnew.copySlack",
288
+ buildRichHtml,
289
+ writeRich,
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Plain text to the clipboard: navigator.clipboard where it can (secure
295
+ * contexts), else execCommand('copy') (an http:// origin).
296
+ */
297
+ export function copyText(text) {
298
+ if (navigator.clipboard?.writeText)
299
+ return navigator.clipboard.writeText(text);
300
+ return new Promise((resolve, reject) => {
301
+ const ta = document.createElement("textarea");
302
+ ta.value = text;
303
+ ta.className = "kit-offscreen";
304
+ document.body.appendChild(ta);
305
+ ta.focus();
306
+ ta.select();
307
+ try {
308
+ document.execCommand("copy")
309
+ ? resolve()
310
+ : reject(new Error("execCommand failed"));
311
+ } catch (e) {
312
+ reject(e);
313
+ } finally {
314
+ document.body.removeChild(ta);
315
+ }
316
+ });
317
+ }
318
+
319
+ /**
320
+ * Rich HTML to the clipboard through a hidden contenteditable: the "copy
321
+ * from a web page" path, whose HTML Slack's paste trusts (a ClipboardItem's
322
+ * it ignores).
323
+ */
324
+ function writeRich(html) {
325
+ return new Promise((resolve, reject) => {
326
+ const el = document.createElement("div");
327
+ el.contentEditable = "true";
328
+ el.className = "kit-offscreen";
329
+ el.innerHTML = html;
330
+ document.body.appendChild(el);
331
+ const range = document.createRange();
332
+ range.selectNodeContents(el);
333
+ const sel = window.getSelection();
334
+ sel.removeAllRanges();
335
+ sel.addRange(range);
336
+ try {
337
+ document.execCommand("copy")
338
+ ? resolve()
339
+ : reject(new Error("execCommand failed"));
340
+ } catch (e) {
341
+ reject(e);
342
+ } finally {
343
+ sel.removeAllRanges();
344
+ document.body.removeChild(el);
345
+ }
346
+ });
347
+ }
348
+
349
+ /** Slack's HTML: bold paragraphs for headings, <code>, bullets. */
350
+ export function buildRichHtml(entry) {
351
+ const sections = Object.entries(entry.sections ?? {})
352
+ .map(([sec, items]) => {
353
+ const li = items.flatMap((it) => [
354
+ `<li>${renderItem(it.text)}</li>`,
355
+ ...(it.sub ?? []).map((s) => `<li>${renderItem(s)}</li>`),
356
+ ]);
357
+ return `<p><strong>${escHtml(sec)}</strong></p><ul>${li.join("")}</ul>`;
358
+ })
359
+ .join("");
360
+ return `<p><strong>v${escHtml(entry.version)} — ${escHtml(entry.date)}</strong></p>${sections}`;
361
+ }
362
+
363
+ /** Markdown rebuilt from an entry (when it has no `raw`). */
364
+ export function buildMarkdown(entry) {
365
+ const lines = [`## [${entry.version}] — ${entry.date}`];
366
+ for (const [sec, items] of Object.entries(entry.sections ?? {})) {
367
+ lines.push("", `### ${sec}`, "");
368
+ for (const item of items) {
369
+ lines.push(`- ${item.text}`);
370
+ for (const s of item.sub ?? []) lines.push(` - ${s}`);
371
+ }
372
+ }
373
+ return lines.join("\n");
374
+ }
375
+
376
+ export function openWhatsNew() {
377
+ showAll = false;
378
+ ensureWhatsNew();
379
+ renderBody();
380
+ const overlay = document.getElementById("cl-overlay");
381
+ if (!overlay) return;
382
+ if (!overlay.classList.contains("open")) {
383
+ const at = openerOf();
384
+ // Nothing focused (a first-visit open): the version chip.
385
+ returnFocus =
386
+ at && !overlay.contains(at)
387
+ ? at
388
+ : document.getElementById("version-pill");
389
+ }
390
+ overlay.classList.add("open");
391
+ // Always at the newest release. After `.open`: while the overlay is
392
+ // display:none the body has no scroll box, so a reset there doesn't stick.
393
+ const body = document.getElementById("cl-body");
394
+ if (body) body.scrollTop = 0;
395
+ // The heading first, so a screen reader starts at the latest notes.
396
+ document.getElementById("cl-title")?.focus();
397
+ }
398
+
399
+ export function closeWhatsNew() {
400
+ const overlay = document.getElementById("cl-overlay");
401
+ const wasOpen = !!overlay?.classList.contains("open");
402
+ if (overlay) overlay.classList.remove("open");
403
+ if (wasOpen) {
404
+ const back = returnFocus;
405
+ returnFocus = null;
406
+ if (!focusBack(back)) focusBack(document.getElementById("version-pill"));
407
+ }
408
+ if (cfg.onClose) cfg.onClose(entries[0]?.version ?? null);
409
+ const pip = document.getElementById("v-pip");
410
+ if (pip) pip.style.display = "none";
411
+ }