@monster-orange/den-ui 0.0.0-stage → 0.6.6

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +408 -2
  3. package/bin/den-ui-parity.mjs +365 -0
  4. package/inventory/nav-inventory.d.ts +89 -0
  5. package/inventory/nav-inventory.js +590 -0
  6. package/inventory/reference/den-chromium-1280.json +5137 -0
  7. package/inventory/reference/den-chromium-390.json +3653 -0
  8. package/inventory/reference/den-webkit-1280.json +5137 -0
  9. package/inventory/reference/den-webkit-390.json +3653 -0
  10. package/package.json +51 -4
  11. package/src/base.css +80 -0
  12. package/src/busy-words.d.ts +2 -0
  13. package/src/busy-words.js +71 -0
  14. package/src/busy.css +155 -0
  15. package/src/busy.d.ts +80 -0
  16. package/src/busy.js +662 -0
  17. package/src/dialog.css +103 -0
  18. package/src/dialog.d.ts +44 -0
  19. package/src/dialog.js +282 -0
  20. package/src/fonts/OFL.txt +97 -0
  21. package/src/fonts/rubik-latin-400-normal.woff2 +0 -0
  22. package/src/fonts/rubik-latin-500-normal.woff2 +0 -0
  23. package/src/fonts/rubik-latin-ext-400-normal.woff2 +0 -0
  24. package/src/fonts/rubik-latin-ext-500-normal.woff2 +0 -0
  25. package/src/fonts/space-mono-latin-400-normal.woff2 +0 -0
  26. package/src/fonts/space-mono-latin-ext-400-normal.woff2 +0 -0
  27. package/src/fonts.css +71 -0
  28. package/src/icons.d.ts +4 -0
  29. package/src/icons.js +43 -0
  30. package/src/kit.d.ts +146 -0
  31. package/src/kit.js +224 -0
  32. package/src/report-shot.d.ts +47 -0
  33. package/src/report-shot.js +255 -0
  34. package/src/report.css +387 -0
  35. package/src/report.d.ts +61 -0
  36. package/src/report.js +909 -0
  37. package/src/shell-client.d.ts +31 -0
  38. package/src/shell-client.js +240 -0
  39. package/src/shell-html.d.ts +91 -0
  40. package/src/shell-html.js +289 -0
  41. package/src/shell.css +558 -0
  42. package/src/strings.d.ts +18 -0
  43. package/src/strings.js +514 -0
  44. package/src/time.d.ts +18 -0
  45. package/src/time.js +254 -0
  46. package/src/tokens.css +158 -0
  47. package/src/update-pill.css +32 -0
  48. package/src/update-pill.d.ts +17 -0
  49. package/src/update-pill.js +95 -0
  50. package/src/version.d.ts +7 -0
  51. package/src/version.js +31 -0
  52. package/src/whatsnew.css +235 -0
  53. package/src/whatsnew.d.ts +36 -0
  54. package/src/whatsnew.js +411 -0
package/src/time.js ADDED
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Date-times for people: in the person's own time zone, never UTC.
3
+ *
4
+ * The data keeps ISO-8601 UTC; what a person reads is local. Framework-free
5
+ * and pure: formatTime runs in Node as well as in a page (it touches
6
+ * document or navigator only when they exist).
7
+ *
8
+ * formatTime(iso, opts?) → the text ("Nov 15, 4:32 PM"); "" for a
9
+ * missing or invalid stamp.
10
+ * timeHtml(iso, opts?) → '<time datetime="ISO-UTC" title="full local
11
+ * date-time with zone name" data-den-time="style">text</time>'.
12
+ * upgradeTimes(root = document) → every time[datetime][data-den-time]
13
+ * under root drawn again (after the zone changes).
14
+ * setTimeZone(zone | null) → the zone pick; null is the browser's.
15
+ *
16
+ * opts.style "datetime" (the default), "date", "time" or "relative"
17
+ * ("3 min ago"; its title is the local absolute time).
18
+ * opts.seconds true: the seconds too.
19
+ * opts.zone an IANA zone. Else <html data-den-tz> (a page), else
20
+ * setTimeZone's value, else the browser's (or process's).
21
+ * opts.locale else <html lang> (in the browser's variant of it), else
22
+ * the browser's. upgradeTimes uses the nearest [lang] around
23
+ * each <time> first.
24
+ * opts.now ms or ISO: "now" for relative and the year rule (tests,
25
+ * server use).
26
+ *
27
+ * The year shows only when it isn't the current year in that zone.
28
+ */
29
+
30
+ const STYLES = ["datetime", "date", "time", "relative"];
31
+
32
+ let picked = null;
33
+
34
+ const hasDoc = () =>
35
+ typeof document !== "undefined" && !!document.documentElement;
36
+
37
+ /** The browser's (or process's) own zone. */
38
+ export function browserTimeZone() {
39
+ try {
40
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
41
+ } catch {
42
+ return "UTC";
43
+ }
44
+ }
45
+
46
+ /** Every IANA zone this runtime knows, or [] when it can't list them. */
47
+ export function timeZones() {
48
+ try {
49
+ return typeof Intl.supportedValuesOf === "function"
50
+ ? Intl.supportedValuesOf("timeZone")
51
+ : [];
52
+ } catch {
53
+ return [];
54
+ }
55
+ }
56
+
57
+ /** True when `zone` is a zone this runtime can format in. */
58
+ export function isTimeZone(zone) {
59
+ if (typeof zone !== "string" || !zone) return false;
60
+ try {
61
+ new Intl.DateTimeFormat("en", { timeZone: zone });
62
+ return true;
63
+ } catch {
64
+ return false;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * The zone pick: an IANA zone, or null for the browser's. On a page it is
70
+ * also <html data-den-tz>, so the attribute is the one source there.
71
+ */
72
+ export function setTimeZone(zone) {
73
+ picked = isTimeZone(zone) ? zone : null;
74
+ if (hasDoc()) {
75
+ const ds = document.documentElement.dataset;
76
+ if (picked) ds.denTz = picked;
77
+ else delete ds.denTz;
78
+ }
79
+ }
80
+
81
+ /** The zone a stamp is drawn in. */
82
+ export function currentTimeZone(zone) {
83
+ if (isTimeZone(zone)) return zone;
84
+ if (hasDoc()) {
85
+ const z = document.documentElement.dataset?.denTz;
86
+ if (isTimeZone(z)) return z;
87
+ }
88
+ return picked ?? browserTimeZone();
89
+ }
90
+
91
+ /**
92
+ * The page's language, in the browser's own variant of it when they share
93
+ * a language ("en" with an en-GB browser reads en-GB: its 24-hour clock).
94
+ */
95
+ function currentLocale(locale) {
96
+ if (locale) return locale;
97
+ return localeOf(hasDoc() ? document.documentElement.lang : "");
98
+ }
99
+
100
+ /** A lang attribute's value as a locale, in the browser's variant of it. */
101
+ function localeOf(lang) {
102
+ const nav =
103
+ typeof navigator !== "undefined" && navigator.language
104
+ ? navigator.language
105
+ : undefined;
106
+ if (!lang) return nav;
107
+ if (nav && !lang.includes("-") && nav.split("-")[0] === lang) return nav;
108
+ return lang;
109
+ }
110
+
111
+ /** A Date for an ISO string, ms or Date; null when it isn't one. */
112
+ function toDate(v) {
113
+ if (v === null || v === undefined || v === "") return null;
114
+ const d = v instanceof Date ? new Date(v.getTime()) : new Date(v);
115
+ return Number.isNaN(d.getTime()) ? null : d;
116
+ }
117
+
118
+ function fmt(locale, o) {
119
+ try {
120
+ return new Intl.DateTimeFormat(locale, o);
121
+ } catch {
122
+ return new Intl.DateTimeFormat("en", o);
123
+ }
124
+ }
125
+
126
+ function yearIn(d, zone) {
127
+ return fmt("en", { timeZone: zone, year: "numeric" }).format(d);
128
+ }
129
+
130
+ function absolute(d, style, o) {
131
+ const f = { timeZone: o.zone };
132
+ const withYear = yearIn(d, o.zone) !== yearIn(o.now, o.zone);
133
+ if (style !== "time") {
134
+ f.month = "short";
135
+ f.day = "numeric";
136
+ if (withYear) f.year = "numeric";
137
+ }
138
+ if (style !== "date") {
139
+ f.hour = "numeric";
140
+ f.minute = "2-digit";
141
+ if (o.seconds) f.second = "2-digit";
142
+ }
143
+ return fmt(o.locale, f).format(d);
144
+ }
145
+
146
+ /** The full local date-time with the zone's name: a title. */
147
+ function full(d, o) {
148
+ return fmt(o.locale, {
149
+ timeZone: o.zone,
150
+ weekday: "short",
151
+ year: "numeric",
152
+ month: "short",
153
+ day: "numeric",
154
+ hour: "numeric",
155
+ minute: "2-digit",
156
+ second: "2-digit",
157
+ timeZoneName: "long",
158
+ }).format(d);
159
+ }
160
+
161
+ const UNITS = [
162
+ ["year", 365 * 86400],
163
+ ["month", 30 * 86400],
164
+ ["day", 86400],
165
+ ["hour", 3600],
166
+ ["minute", 60],
167
+ ];
168
+
169
+ function relative(d, o) {
170
+ const s = Math.round((d.getTime() - o.now.getTime()) / 1000);
171
+ let rtf;
172
+ try {
173
+ rtf = new Intl.RelativeTimeFormat(o.locale, { numeric: "auto" });
174
+ } catch {
175
+ rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
176
+ }
177
+ const abs = Math.abs(s);
178
+ if (abs < 45) return rtf.format(0, "second");
179
+ for (const [unit, size] of UNITS)
180
+ if (abs >= size || unit === "minute")
181
+ return rtf.format(Math.round(s / size), unit);
182
+ return "";
183
+ }
184
+
185
+ function resolve(opts) {
186
+ const o = opts || {};
187
+ return {
188
+ style: STYLES.includes(o.style) ? o.style : "datetime",
189
+ seconds: !!o.seconds,
190
+ zone: currentTimeZone(o.zone),
191
+ locale: currentLocale(o.locale),
192
+ now: toDate(o.now) ?? new Date(),
193
+ };
194
+ }
195
+
196
+ /** The text a person reads for `iso`; "" when it isn't a date-time. */
197
+ export function formatTime(iso, opts) {
198
+ const d = toDate(iso);
199
+ if (!d) return "";
200
+ const o = resolve(opts);
201
+ return o.style === "relative" ? relative(d, o) : absolute(d, o.style, o);
202
+ }
203
+
204
+ /** The full local date-time with its zone's name, for a title. */
205
+ export function formatTitle(iso, opts) {
206
+ const d = toDate(iso);
207
+ return d ? full(d, resolve(opts)) : "";
208
+ }
209
+
210
+ const ESC = {
211
+ "&": "&amp;",
212
+ "<": "&lt;",
213
+ ">": "&gt;",
214
+ '"': "&quot;",
215
+ "'": "&#39;",
216
+ };
217
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
218
+
219
+ /** A <time> element's HTML for `iso`; "" when it isn't a date-time. */
220
+ export function timeHtml(iso, opts) {
221
+ const d = toDate(iso);
222
+ if (!d) return "";
223
+ const o = resolve(opts);
224
+ const text = formatTime(d, opts);
225
+ return (
226
+ `<time datetime="${esc(d.toISOString())}" title="${esc(full(d, o))}"` +
227
+ ` data-den-time="${esc(o.style)}"${o.seconds ? ' data-den-seconds=""' : ""}>` +
228
+ `${esc(text)}</time>`
229
+ );
230
+ }
231
+
232
+ /** Draws every time[datetime][data-den-time] under `root` again. */
233
+ export function upgradeTimes(root) {
234
+ const r = root || (hasDoc() ? document : null);
235
+ if (!r || typeof r.querySelectorAll !== "function") return;
236
+ for (const el of r.querySelectorAll("time[datetime][data-den-time]")) {
237
+ const iso = el.getAttribute("datetime");
238
+ const opts = {
239
+ style: el.getAttribute("data-den-time"),
240
+ seconds: el.hasAttribute("data-den-seconds"),
241
+ };
242
+ // The language of the part the time sits in (a row still in English
243
+ // on a translated page reads in English), then the page's, then the
244
+ // browser's.
245
+ const near = typeof el.closest === "function" ? el.closest("[lang]") : null;
246
+ const page = hasDoc() ? document.documentElement : null;
247
+ if (near && near !== page)
248
+ opts.locale = localeOf(near.getAttribute("lang"));
249
+ const text = formatTime(iso, opts);
250
+ if (!text) continue;
251
+ el.textContent = text;
252
+ el.title = formatTitle(iso, opts);
253
+ }
254
+ }
package/src/tokens.css ADDED
@@ -0,0 +1,158 @@
1
+ /*
2
+ * den-ui tokens (UK-1). The kit's defaults: a theme laid on top overrides
3
+ * colours (both modes), shadow, bar, type, radius, radius-button, density
4
+ * and fonts; never spacing, motion or layers. Every rule here has zero
5
+ * specificity (:where), so any theme rule wins.
6
+ *
7
+ * Mode: <html data-mode="light|dark">. With none set, light, or dark when
8
+ * the system asks for it.
9
+ */
10
+
11
+ /* Type, shape, space, depth, motion, layers, targets: one set, both modes. */
12
+ :where(:root) {
13
+ --sans:
14
+ "Rubik", -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
15
+ "Noto Sans JP", sans-serif;
16
+ --mono: "Space Mono", ui-monospace, Menlo, Consolas, monospace;
17
+ --display: var(--sans);
18
+ --ja:
19
+ "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
20
+ --fs-xs: 12px;
21
+ --fs-s: 13px;
22
+ --fs-m: 14px;
23
+ --fs-l: 15px;
24
+ --fs-xl: 18px;
25
+ --fs-2xl: 22px;
26
+ --lh: 1.45;
27
+
28
+ --radius: 6px;
29
+ --radius-button: 0.2rem;
30
+ --r: var(--radius);
31
+ --r-btn: var(--radius-button);
32
+
33
+ --density: 1;
34
+ --space-1: calc(4px * var(--density));
35
+ --space-2: calc(8px * var(--density));
36
+ --space-3: calc(12px * var(--density));
37
+ --space-4: calc(16px * var(--density));
38
+ --space-5: calc(24px * var(--density));
39
+ --space-6: calc(32px * var(--density));
40
+
41
+ --shadow-menu: var(--shadow);
42
+ --shadow-dialog: var(--shadow);
43
+ --shadow-bar: 0 6px 18px color-mix(in srgb, var(--text) 14%, transparent);
44
+
45
+ --dur-fast: 120ms;
46
+ --dur: 200ms;
47
+ --dur-cue: 400ms;
48
+ --ease: cubic-bezier(0.2, 0, 0, 1);
49
+
50
+ --z-menu: 10;
51
+ --z-bar: 30;
52
+ --z-drawer: 35;
53
+ --z-dialog: 40;
54
+ --z-palette: 45;
55
+ --z-toast: 50;
56
+
57
+ --tap: 44px;
58
+ --tap-min: 36px;
59
+
60
+ /* Veils behind a pop-up, the same in both modes: the ☰ drawer's and the
61
+ status drawer's scrim, What's new's overlay, the Report form's backdrop. */
62
+ --kit-scrim: rgb(0 0 0 / 0.35);
63
+ --kit-veil: rgba(0, 0, 0, 0.65);
64
+ --kit-backdrop: rgba(0, 0, 0, 0.3);
65
+ }
66
+
67
+ /* Light: the default. */
68
+ :where(:root),
69
+ :where(:root[data-mode="light"]) {
70
+ color-scheme: light;
71
+ --bg: #fffcfc;
72
+ --surface: #ffffff;
73
+ --raised: #ffffff;
74
+ --sunken: #f4efee;
75
+ --text: hsl(220 6% 10%);
76
+ --muted: hsl(220 5% 34%);
77
+ --faint: #62656a;
78
+ --border: hsl(20 12% 86%);
79
+ --border-strong: #97867f;
80
+ --accent: #e16500;
81
+ --accent-text: #a34a00;
82
+ --accent-fill: #c23f00;
83
+ --on-accent: #ffffff;
84
+ --ok: #11692f;
85
+ --warn: #865700;
86
+ --bad: #af0900;
87
+ --info: hsl(213 22% 36%);
88
+ /* #0e7280 failed the pill rule over --sunken (4.20:1). #0d6b79 failed
89
+ the disc rule (an agent's initial on its 16% tint) over --sunken
90
+ (4.33:1); 4.56:1 now, the pill 4.84:1. */
91
+ --remote: #0c6774;
92
+ --violet: #6a4bc4;
93
+ --shadow: 0 8px 28px rgb(0 0 0 / 0.14);
94
+ /* The shared update pill's shadow (update-pill.css). */
95
+ --upd-shadow:
96
+ 0 2px 4px rgba(32, 38, 29, 0.07), 0 10px 28px rgba(32, 38, 29, 0.1),
97
+ inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
98
+ --bar: linear-gradient(90deg, #ff7300, #af0900);
99
+ }
100
+
101
+ /* Dark: asked for, or the system's choice when no mode is set. */
102
+ :where(:root[data-mode="dark"]) {
103
+ color-scheme: dark;
104
+ --bg: hsl(220 6% 10%);
105
+ --surface: hsl(220 6% 8.5%);
106
+ --raised: #1f2023;
107
+ --sunken: hsl(220 6% 7%);
108
+ --text: #fffcfc;
109
+ --muted: #c4c4c4;
110
+ --faint: #a3a3a3;
111
+ --border: hsl(220 5% 20%);
112
+ --border-strong: #676a71;
113
+ --accent: #ff7300;
114
+ --accent-text: #ff8f33;
115
+ --accent-fill: #ff7300;
116
+ --on-accent: hsl(220 6% 10%);
117
+ --ok: #4cc777;
118
+ --warn: #e3a72f;
119
+ --bad: #ff5a4f;
120
+ --info: hsl(213 30% 74%);
121
+ --remote: #4fd1db;
122
+ --violet: #a993ff;
123
+ --shadow: 0 12px 30px rgb(0 0 0 / 0.5);
124
+ --upd-shadow:
125
+ 0 2px 4px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.4),
126
+ inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
127
+ --bar: linear-gradient(90deg, #ff7300, #af0900);
128
+ }
129
+
130
+ @media (prefers-color-scheme: dark) {
131
+ :where(:root:not([data-mode])) {
132
+ color-scheme: dark;
133
+ --bg: hsl(220 6% 10%);
134
+ --surface: hsl(220 6% 8.5%);
135
+ --raised: #1f2023;
136
+ --sunken: hsl(220 6% 7%);
137
+ --text: #fffcfc;
138
+ --muted: #c4c4c4;
139
+ --faint: #a3a3a3;
140
+ --border: hsl(220 5% 20%);
141
+ --border-strong: #676a71;
142
+ --accent: #ff7300;
143
+ --accent-text: #ff8f33;
144
+ --accent-fill: #ff7300;
145
+ --on-accent: hsl(220 6% 10%);
146
+ --ok: #4cc777;
147
+ --warn: #e3a72f;
148
+ --bad: #ff5a4f;
149
+ --info: hsl(213 30% 74%);
150
+ --remote: #4fd1db;
151
+ --violet: #a993ff;
152
+ --shadow: 0 12px 30px rgb(0 0 0 / 0.5);
153
+ --upd-shadow:
154
+ 0 2px 4px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.4),
155
+ inset 0 1px 0 color-mix(in srgb, var(--text) 14%, transparent);
156
+ --bar: linear-gradient(90deg, #ff7300, #af0900);
157
+ }
158
+ }
@@ -0,0 +1,32 @@
1
+ /* den-ui: the shared update pill. Over the top bar and see-through: no
2
+ full-width strip; the pill's own fill is the surface at 20% with a blur, so
3
+ the bar shows through it, and the bar beside it stays clickable.
4
+ Tokens it reads: --surface --text --muted --border-strong --accent
5
+ --accent-text, and --upd-shadow (tokens.css, per mode).
6
+ Two knobs, set on .den-upd:
7
+ --upd-pad-y : the pill's vertical padding (8px).
8
+ --upd-top : where the pill sits; the default centres a 50px pill on a
9
+ 48px bar (top -1px). */
10
+ .den-upd { --upd-pad-y: 8px; --upd-top: calc(env(safe-area-inset-top, 0px) + (48px - 50px) / 2);
11
+ position: fixed; z-index: 30; top: var(--upd-top); left: 16px; right: 16px; display: flex; justify-content: center; pointer-events: none; background: none; }
12
+ .den-upd[hidden] { display: none; }
13
+ .den-upd .upd-pill { pointer-events: auto; display: flex; align-items: center; gap: 16px; width: fit-content; max-width: 100%; box-sizing: border-box;
14
+ padding: var(--upd-pad-y) 12px var(--upd-pad-y) 24px;
15
+ border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); font-size: 14px; line-height: 1.5;
16
+ background: var(--surface);
17
+ background: color-mix(in srgb, var(--surface) 20%, transparent);
18
+ background-image: linear-gradient(color-mix(in srgb, var(--text) 7%, transparent), color-mix(in srgb, var(--text) 3%, transparent));
19
+ -webkit-backdrop-filter: blur(3px) saturate(1.4); backdrop-filter: blur(3px) saturate(1.4);
20
+ box-shadow: var(--upd-shadow); }
21
+ .den-upd .upd-icon { flex: none; display: flex; color: var(--accent-text); }
22
+ .den-upd .upd-msg { flex: 1 1 auto; min-width: 0; text-wrap: balance; }
23
+ .den-upd .upd-acts { display: flex; align-items: center; gap: 8px; flex: none; }
24
+ .den-upd .upd-go { flex: none; display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px; border: 0; background: none; color: var(--accent-text); font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1.2; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; cursor: pointer; }
25
+ .den-upd .upd-dismiss { flex: none; display: flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; padding: 0; border: 0; border-radius: 999px; background: none; color: var(--muted); font-family: inherit; font-size: 18px; line-height: 1; cursor: pointer; }
26
+ .den-upd .upd-dismiss.is-text { width: auto; padding: 0 8px; font-weight: 500; font-size: 14px; line-height: 1.2; white-space: nowrap; }
27
+ .den-upd .upd-dismiss:hover { background: color-mix(in srgb, var(--border-strong) 50%, transparent); color: var(--text); }
28
+ .den-upd .upd-go:focus-visible, .den-upd .upd-dismiss:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
29
+ .den-upd .upd-pill.card { flex-wrap: wrap; gap: 8px; padding: 8px 8px 8px 16px; border-radius: 20px; }
30
+ .den-upd .upd-pill.card .upd-msg { flex: 1 0 100%; line-height: 1.35; }
31
+ .den-upd .upd-pill.card .upd-acts { margin-left: auto; }
32
+ .den-upd .upd-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@@ -0,0 +1,17 @@
1
+ export interface UpdatePillOptions {
2
+ message: string;
3
+ reloadLabel: string;
4
+ dismissLabel: string;
5
+ cancelLabel?: string;
6
+ /** The pill's region name. */
7
+ region?: string;
8
+ /** A message to ask first (unsaved text), or null to reload at once. */
9
+ askFirst?: () => { message: string } | null;
10
+ onReload: () => void;
11
+ onDismiss?: () => void;
12
+ }
13
+ export interface UpdatePill {
14
+ hide(): void;
15
+ }
16
+ /** The shared update pill over the top bar. */
17
+ export declare function showUpdate(o: UpdatePillOptions): UpdatePill;
@@ -0,0 +1,95 @@
1
+ // den-ui: the shared update pill (see update-pill.css). No framework.
2
+ // - text is written only when it changes (WebKit drops a click whose
3
+ // mouse-down node is replaced);
4
+ // - the words show at once (no layout shift under a click); a hidden status,
5
+ // filled just after, is what a screen reader hears;
6
+ // - a text past one line turns the pill into a card, re-measured on resize.
7
+ /**
8
+ * @param {{ message: string, reloadLabel: string, dismissLabel: string, cancelLabel?: string,
9
+ * askFirst?: { message: string } | null | (() => ({ message: string } | null)),
10
+ * onReload?: () => void, onDismiss?: () => void, region?: string, root?: HTMLElement }} o
11
+ * askFirst: when it returns a message (e.g. unsaved text), Reload asks once and the × reads Cancel.
12
+ * @returns {{ hide(): void }}
13
+ */
14
+ export function showUpdate(o) {
15
+ const box = document.createElement("div");
16
+ box.className = "den-upd";
17
+ box.setAttribute("role", "region");
18
+ box.setAttribute("aria-label", o.region || "Update");
19
+ const pill = document.createElement("div");
20
+ pill.className = "upd-pill";
21
+ const icon = document.createElement("span");
22
+ icon.className = "upd-icon";
23
+ icon.setAttribute("aria-hidden", "true");
24
+ icon.innerHTML =
25
+ '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>';
26
+ const msg = document.createElement("span");
27
+ msg.className = "upd-msg";
28
+ msg.setAttribute("aria-hidden", "true");
29
+ const said = document.createElement("span");
30
+ said.className = "upd-sr";
31
+ said.setAttribute("role", "status");
32
+ const btn = (cls) =>
33
+ Object.assign(document.createElement("button"), {
34
+ type: "button",
35
+ className: cls,
36
+ });
37
+ const go = btn("upd-go");
38
+ const other = btn("upd-dismiss");
39
+ const acts = document.createElement("span");
40
+ acts.className = "upd-acts";
41
+ acts.append(go, other);
42
+ pill.append(icon, msg, said, acts);
43
+ box.append(pill);
44
+ let asking = null;
45
+ const put = (el, t) => {
46
+ if (el.textContent !== t) el.textContent = t;
47
+ };
48
+ const fit = () => {
49
+ if (!box.isConnected || box.hidden) return;
50
+ pill.classList.remove("card");
51
+ const r = document.createRange();
52
+ r.selectNodeContents(msg);
53
+ if (new Set([...r.getClientRects()].map((x) => Math.round(x.top))).size > 1)
54
+ pill.classList.add("card");
55
+ };
56
+ const render = () => {
57
+ const text = asking ? asking.message : o.message;
58
+ put(msg, text);
59
+ put(said, text);
60
+ put(go, o.reloadLabel);
61
+ put(other, asking ? o.cancelLabel || "Cancel" : "×");
62
+ other.classList.toggle("is-text", Boolean(asking));
63
+ if (asking) other.removeAttribute("aria-label");
64
+ else other.setAttribute("aria-label", o.dismissLabel);
65
+ fit();
66
+ };
67
+ const hide = () => {
68
+ window.removeEventListener("resize", fit);
69
+ box.remove();
70
+ };
71
+ go.addEventListener("click", () => {
72
+ const ask = typeof o.askFirst === "function" ? o.askFirst() : o.askFirst;
73
+ if (!asking && ask) {
74
+ asking = ask;
75
+ render();
76
+ return;
77
+ }
78
+ (o.onReload || (() => location.reload()))();
79
+ });
80
+ other.addEventListener("click", () => {
81
+ if (asking) {
82
+ asking = null;
83
+ render();
84
+ return;
85
+ }
86
+ hide();
87
+ o.onDismiss?.();
88
+ });
89
+ window.addEventListener("resize", fit);
90
+ (o.root || document.body).append(box);
91
+ render();
92
+ said.textContent = "";
93
+ setTimeout(render, 50);
94
+ return { hide };
95
+ }
@@ -0,0 +1,7 @@
1
+ /** "v<running>" with its prerelease suffix, else the changelog's newest, else null. */
2
+ export declare function versionLabel(
3
+ running: string | null | undefined,
4
+ changelog: { version: string }[],
5
+ ): string | null;
6
+ export declare function setVersion(label: string, root?: ParentNode): void;
7
+ export declare function setUnread(on: boolean, root?: ParentNode): void;
package/src/version.js ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * den-ui version chip: the running product's version in the top bar
3
+ * (shell-html.js draws it as #version-pill; a click opens What's new).
4
+ *
5
+ * versionLabel(running, changelog) "v0.4.61-dev.0": the running build's
6
+ * own version, prerelease and all; the changelog's newest
7
+ * heading only as the fallback (it names the release being
8
+ * built, not this build). null when neither is known.
9
+ * setVersion(label, root?) the chip's text
10
+ * setUnread(on, root?) the dot: the newest notes are unread
11
+ */
12
+ export function versionLabel(running, changelog) {
13
+ const v =
14
+ (typeof running === "string" && running.trim()) || changelog?.[0]?.version;
15
+ return v ? `v${v}` : null;
16
+ }
17
+
18
+ export function setVersion(label, root = document) {
19
+ const el = root.getElementById
20
+ ? root.getElementById("version-pill")
21
+ : root.querySelector("#version-pill");
22
+ const txt = el?.querySelector(".v-txt");
23
+ if (txt && label) txt.textContent = label;
24
+ }
25
+
26
+ export function setUnread(on, root = document) {
27
+ const pip = root.getElementById
28
+ ? root.getElementById("v-pip")
29
+ : root.querySelector("#v-pip");
30
+ if (pip) pip.style.display = on ? "block" : "none";
31
+ }