@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.
- package/LICENSE +21 -0
- package/README.md +408 -2
- package/bin/den-ui-parity.mjs +365 -0
- package/inventory/nav-inventory.d.ts +89 -0
- package/inventory/nav-inventory.js +590 -0
- package/inventory/reference/den-chromium-1280.json +5137 -0
- package/inventory/reference/den-chromium-390.json +3653 -0
- package/inventory/reference/den-webkit-1280.json +5137 -0
- package/inventory/reference/den-webkit-390.json +3653 -0
- package/package.json +51 -4
- package/src/base.css +80 -0
- package/src/busy-words.d.ts +2 -0
- package/src/busy-words.js +71 -0
- package/src/busy.css +155 -0
- package/src/busy.d.ts +80 -0
- package/src/busy.js +662 -0
- package/src/dialog.css +103 -0
- package/src/dialog.d.ts +44 -0
- package/src/dialog.js +282 -0
- package/src/fonts/OFL.txt +97 -0
- package/src/fonts/rubik-latin-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-500-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-500-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-400-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts.css +71 -0
- package/src/icons.d.ts +4 -0
- package/src/icons.js +43 -0
- package/src/kit.d.ts +146 -0
- package/src/kit.js +224 -0
- package/src/report-shot.d.ts +47 -0
- package/src/report-shot.js +255 -0
- package/src/report.css +387 -0
- package/src/report.d.ts +61 -0
- package/src/report.js +909 -0
- package/src/shell-client.d.ts +31 -0
- package/src/shell-client.js +240 -0
- package/src/shell-html.d.ts +91 -0
- package/src/shell-html.js +289 -0
- package/src/shell.css +558 -0
- package/src/strings.d.ts +18 -0
- package/src/strings.js +514 -0
- package/src/time.d.ts +18 -0
- package/src/time.js +254 -0
- package/src/tokens.css +158 -0
- package/src/update-pill.css +32 -0
- package/src/update-pill.d.ts +17 -0
- package/src/update-pill.js +95 -0
- package/src/version.d.ts +7 -0
- package/src/version.js +31 -0
- package/src/whatsnew.css +235 -0
- package/src/whatsnew.d.ts +36 -0
- package/src/whatsnew.js +411 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface HydrateOptions {
|
|
2
|
+
lang?: string | (() => string);
|
|
3
|
+
/** The toggle was pressed: store it, then call shell.setCollapsed(next). */
|
|
4
|
+
onCollapse?: (next: boolean) => void;
|
|
5
|
+
/** Delete on a pinned row. */
|
|
6
|
+
onUnpin?: (id: string) => void;
|
|
7
|
+
/** The elements made inert behind the open drawer. */
|
|
8
|
+
inert?: () => (Element | null)[];
|
|
9
|
+
/** True while a product menu is open (Escape is the menu's then). */
|
|
10
|
+
menuOpen?: () => boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface Shell {
|
|
13
|
+
nav: HTMLElement | null;
|
|
14
|
+
rove(): void;
|
|
15
|
+
paint(html: string, force?: boolean): boolean;
|
|
16
|
+
setCollapsed(on: boolean): void;
|
|
17
|
+
unpin(id: string): void;
|
|
18
|
+
openDrawer(): void;
|
|
19
|
+
closeDrawer(refocus?: boolean): void;
|
|
20
|
+
drawerOpen(): boolean;
|
|
21
|
+
syncPinToggles(root: ParentNode, isPinned: (id: string) => boolean): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function syncPinToggles(
|
|
24
|
+
root: ParentNode,
|
|
25
|
+
isPinned: (id: string) => boolean,
|
|
26
|
+
lang?: string,
|
|
27
|
+
): void;
|
|
28
|
+
export declare function hydrateShell(
|
|
29
|
+
root: ParentNode,
|
|
30
|
+
opts?: HydrateOptions,
|
|
31
|
+
): Shell;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* den-ui shell, in the page: hydrates the markup shell-html.js drew (on
|
|
3
|
+
* the server or in the page). It draws nothing of the frame itself; it
|
|
4
|
+
* binds the rail's keys, the collapse toggle, pins' Delete, and the ☰
|
|
5
|
+
* drawer, and repaints the rail when the product asks.
|
|
6
|
+
*
|
|
7
|
+
* const shell = hydrateShell(root, opts)
|
|
8
|
+
* root the element holding the shell (its .den-top and #den-rail)
|
|
9
|
+
* opts.lang the kit's words' language
|
|
10
|
+
* opts.onCollapse(next) the toggle was pressed: store it, then call
|
|
11
|
+
* shell.setCollapsed(next) (or repaint)
|
|
12
|
+
* opts.onUnpin(id) Delete on a pinned row: unpin it (and repaint);
|
|
13
|
+
* focus moves to the next pinned row by itself
|
|
14
|
+
* opts.inert() the elements made inert behind the open drawer
|
|
15
|
+
* (default: the top bar and #den-content)
|
|
16
|
+
* opts.menuOpen() true while a product menu is open: Escape is the
|
|
17
|
+
* menu's then, not the drawer's
|
|
18
|
+
*
|
|
19
|
+
* shell.rove() one tab stop in the rail (current, else first)
|
|
20
|
+
* shell.paint(html, force) the rail's new content, focus kept on the
|
|
21
|
+
* same entry; false when it was the same
|
|
22
|
+
* (force: paint it anyway)
|
|
23
|
+
* shell.setCollapsed(on) body.den-rail-collapsed
|
|
24
|
+
* shell.openDrawer(), closeDrawer(refocus), drawerOpen()
|
|
25
|
+
* shell.unpin(id) Delete's path: onUnpin, then focus
|
|
26
|
+
* syncPinToggles(root, isPinned, lang) every [data-pin-toggle] in root:
|
|
27
|
+
* ★ "Unpin x" pressed, or ☆ "Pin x"
|
|
28
|
+
*
|
|
29
|
+
* The drawer is the rail below 720px: a modal over the page. Focus moves
|
|
30
|
+
* into the rail (the current entry); the top bar and the page are inert
|
|
31
|
+
* behind a scrim; Escape or the scrim closes it and focus goes back to ☰;
|
|
32
|
+
* Tab stays inside. Wider than that, it is a rail again.
|
|
33
|
+
*/
|
|
34
|
+
import { kitT } from "./strings.js";
|
|
35
|
+
|
|
36
|
+
const all = (root, sel) =>
|
|
37
|
+
Array.prototype.slice.call(root.querySelectorAll(sel));
|
|
38
|
+
|
|
39
|
+
/** A pin toggle's look for its id: ★ "Unpin x" pressed, or ☆ "Pin x". */
|
|
40
|
+
export function syncPinToggles(root, isPinned, lang) {
|
|
41
|
+
if (!root || !root.querySelectorAll) return;
|
|
42
|
+
for (const b of all(root, "[data-pin-toggle]")) {
|
|
43
|
+
const id = b.getAttribute("data-pin-toggle");
|
|
44
|
+
const on = !!isPinned(id);
|
|
45
|
+
const label = kitT(lang, on ? "kit.pin.unpinX" : "kit.pin.pinX", { s: id });
|
|
46
|
+
b.textContent = on ? "★" : "☆";
|
|
47
|
+
b.setAttribute("aria-pressed", on ? "true" : "false");
|
|
48
|
+
b.setAttribute("aria-label", label);
|
|
49
|
+
b.title = label;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function hydrateShell(root, opts = {}) {
|
|
54
|
+
const lang = () =>
|
|
55
|
+
typeof opts.lang === "function" ? opts.lang() : opts.lang;
|
|
56
|
+
const nav = root.querySelector(".den-rail");
|
|
57
|
+
const railBox = root.querySelector(".den-rail-box");
|
|
58
|
+
const menu = root.querySelector(".den-menu-btn");
|
|
59
|
+
let scrim = null;
|
|
60
|
+
|
|
61
|
+
function rove() {
|
|
62
|
+
if (!nav) return;
|
|
63
|
+
const links = all(nav, ".den-ni");
|
|
64
|
+
let stop = null;
|
|
65
|
+
for (const a of links)
|
|
66
|
+
if (a.getAttribute("aria-current") === "page") stop = a;
|
|
67
|
+
if (!stop) stop = links[0];
|
|
68
|
+
for (const a of links) a.tabIndex = a === stop ? 0 : -1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let lastHtml = null;
|
|
72
|
+
function paint(html, force) {
|
|
73
|
+
if (!nav || (!force && html === lastHtml)) return false;
|
|
74
|
+
// Keep keyboard focus on the same entry across a repaint.
|
|
75
|
+
const active = document.activeElement;
|
|
76
|
+
const keep =
|
|
77
|
+
active && nav.contains(active) && active.dataset
|
|
78
|
+
? active.dataset.nav
|
|
79
|
+
: null;
|
|
80
|
+
lastHtml = html;
|
|
81
|
+
nav.innerHTML = html;
|
|
82
|
+
rove();
|
|
83
|
+
if (keep) {
|
|
84
|
+
const again = nav.querySelector('[data-nav="' + keep + '"]');
|
|
85
|
+
if (again) {
|
|
86
|
+
again.tabIndex = 0;
|
|
87
|
+
again.focus();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function setCollapsed(on) {
|
|
94
|
+
if (document.body)
|
|
95
|
+
document.body.classList.toggle("den-rail-collapsed", !!on);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Delete on a pinned row: unpin it, and keep focus in the rail: the next
|
|
100
|
+
* pinned row, else the previous one, else the first entry.
|
|
101
|
+
*/
|
|
102
|
+
function unpin(pinId) {
|
|
103
|
+
const pins = all(nav, ".den-ni[data-pin]");
|
|
104
|
+
const at = pins.findIndex((p) => p.dataset.pin === pinId);
|
|
105
|
+
const to = at < 0 ? null : pins[at + 1] || pins[at - 1] || null;
|
|
106
|
+
const toNav = to ? to.dataset.nav : null;
|
|
107
|
+
if (opts.onUnpin) opts.onUnpin(pinId);
|
|
108
|
+
const dest =
|
|
109
|
+
(toNav && nav.querySelector('[data-nav="' + toNav + '"]')) ||
|
|
110
|
+
nav.querySelector(".den-ni");
|
|
111
|
+
if (!dest) return;
|
|
112
|
+
for (const a of all(nav, ".den-ni")) a.tabIndex = a === dest ? 0 : -1;
|
|
113
|
+
dest.focus();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function drawerOpen() {
|
|
117
|
+
return document.body.classList.contains("den-rail-open");
|
|
118
|
+
}
|
|
119
|
+
function inertEls() {
|
|
120
|
+
if (opts.inert) return opts.inert();
|
|
121
|
+
return [
|
|
122
|
+
root.querySelector(".den-top"),
|
|
123
|
+
document.getElementById("den-content"),
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
function setInert(on) {
|
|
127
|
+
for (const el of inertEls()) {
|
|
128
|
+
if (!el) continue;
|
|
129
|
+
if (on) el.setAttribute("inert", "");
|
|
130
|
+
else el.removeAttribute("inert");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function openDrawer() {
|
|
134
|
+
document.body.classList.add("den-rail-open");
|
|
135
|
+
if (menu) menu.setAttribute("aria-expanded", "true");
|
|
136
|
+
railBox.setAttribute("role", "dialog");
|
|
137
|
+
railBox.setAttribute("aria-modal", "true");
|
|
138
|
+
railBox.setAttribute("aria-label", kitT(lang(), "kit.pages"));
|
|
139
|
+
if (!scrim) {
|
|
140
|
+
scrim = document.createElement("div");
|
|
141
|
+
scrim.className = "den-scrim";
|
|
142
|
+
scrim.addEventListener("click", () => closeDrawer(true));
|
|
143
|
+
}
|
|
144
|
+
document.body.appendChild(scrim);
|
|
145
|
+
setInert(true);
|
|
146
|
+
const stop =
|
|
147
|
+
nav.querySelector('.den-ni[aria-current="page"]') ||
|
|
148
|
+
nav.querySelector('.den-ni[tabindex="0"]') ||
|
|
149
|
+
nav.querySelector(".den-ni");
|
|
150
|
+
if (stop) stop.focus();
|
|
151
|
+
}
|
|
152
|
+
function closeDrawer(refocus) {
|
|
153
|
+
if (!drawerOpen()) return;
|
|
154
|
+
document.body.classList.remove("den-rail-open");
|
|
155
|
+
if (menu) menu.setAttribute("aria-expanded", "false");
|
|
156
|
+
railBox.removeAttribute("role");
|
|
157
|
+
railBox.removeAttribute("aria-modal");
|
|
158
|
+
railBox.removeAttribute("aria-label");
|
|
159
|
+
if (scrim) scrim.remove();
|
|
160
|
+
setInert(false);
|
|
161
|
+
if (refocus && menu) menu.focus();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (nav) {
|
|
165
|
+
// ↑/↓, Home and End move along the rail; Tab still leaves it (except
|
|
166
|
+
// in the narrow drawer, a modal: Tab stays inside).
|
|
167
|
+
nav.addEventListener("keydown", (e) => {
|
|
168
|
+
if (e.key === "Tab" && drawerOpen()) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const links = all(nav, ".den-ni");
|
|
173
|
+
const i = links.indexOf(document.activeElement);
|
|
174
|
+
if (i < 0) return;
|
|
175
|
+
const pinId =
|
|
176
|
+
links[i].dataset && links[i].dataset.pin ? links[i].dataset.pin : null;
|
|
177
|
+
if (pinId && (e.key === "Delete" || e.key === "Backspace")) {
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
unpin(pinId);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const next =
|
|
183
|
+
e.key === "ArrowDown"
|
|
184
|
+
? (i + 1) % links.length
|
|
185
|
+
: e.key === "ArrowUp"
|
|
186
|
+
? (i - 1 + links.length) % links.length
|
|
187
|
+
: e.key === "Home"
|
|
188
|
+
? 0
|
|
189
|
+
: e.key === "End"
|
|
190
|
+
? links.length - 1
|
|
191
|
+
: -1;
|
|
192
|
+
if (next < 0) return;
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
links[i].tabIndex = -1;
|
|
195
|
+
links[next].tabIndex = 0;
|
|
196
|
+
links[next].focus();
|
|
197
|
+
});
|
|
198
|
+
nav.addEventListener("click", (e) => {
|
|
199
|
+
const c =
|
|
200
|
+
e.target && e.target.closest
|
|
201
|
+
? e.target.closest('[data-act="collapse"]')
|
|
202
|
+
: null;
|
|
203
|
+
if (!c) return;
|
|
204
|
+
const next = !document.body.classList.contains("den-rail-collapsed");
|
|
205
|
+
if (opts.onCollapse) opts.onCollapse(next);
|
|
206
|
+
else setCollapsed(next);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (menu)
|
|
210
|
+
menu.addEventListener("click", () => {
|
|
211
|
+
if (drawerOpen()) closeDrawer(true);
|
|
212
|
+
else openDrawer();
|
|
213
|
+
});
|
|
214
|
+
document.addEventListener("keydown", (e) => {
|
|
215
|
+
if (
|
|
216
|
+
e.key === "Escape" &&
|
|
217
|
+
drawerOpen() &&
|
|
218
|
+
!(opts.menuOpen && opts.menuOpen())
|
|
219
|
+
) {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
closeDrawer(true);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
window.addEventListener("resize", () => {
|
|
225
|
+
if (drawerOpen() && window.innerWidth > 720) closeDrawer(false);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
rove();
|
|
229
|
+
return {
|
|
230
|
+
nav,
|
|
231
|
+
rove,
|
|
232
|
+
paint,
|
|
233
|
+
setCollapsed,
|
|
234
|
+
unpin,
|
|
235
|
+
openDrawer,
|
|
236
|
+
closeDrawer,
|
|
237
|
+
drawerOpen,
|
|
238
|
+
syncPinToggles: (r, isPinned) => syncPinToggles(r, isPinned, lang()),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export { icon } from "./icons.js";
|
|
2
|
+
export { esc } from "./strings.js";
|
|
3
|
+
|
|
4
|
+
export interface Product {
|
|
5
|
+
/** The word beside the mark. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Its tooltip (default: name). */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** The version chip's text ("v" + version; "v…" when unknown). */
|
|
10
|
+
version?: string | null;
|
|
11
|
+
/** Where the brand goes (default "/"). */
|
|
12
|
+
href?: string;
|
|
13
|
+
/** The mark: text (escaped) or the product's own svg, named by label. */
|
|
14
|
+
mark?: { text?: string; svg?: string; label: string } | null;
|
|
15
|
+
}
|
|
16
|
+
export interface NavItem {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
href: string;
|
|
20
|
+
group?: string;
|
|
21
|
+
icon?: string;
|
|
22
|
+
tip?: string;
|
|
23
|
+
current?: boolean;
|
|
24
|
+
badge?: { n: number | string; bad?: boolean; label?: string } | null;
|
|
25
|
+
/** HTML in place of the icon (a status dot). */
|
|
26
|
+
lead?: string;
|
|
27
|
+
mono?: boolean;
|
|
28
|
+
cls?: string;
|
|
29
|
+
attrs?: Record<string, string | number | boolean | null | undefined>;
|
|
30
|
+
/** The pinned id: the row is a pin row (Delete unpins it). */
|
|
31
|
+
pin?: string | null;
|
|
32
|
+
/** HTML after the link inside the pin row. */
|
|
33
|
+
after?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface NavGroup {
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
/** A "from <d>" tag on the group's heading. */
|
|
39
|
+
from?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface Slots {
|
|
42
|
+
/** After the brand (a search, a scope menu). */
|
|
43
|
+
start?: string;
|
|
44
|
+
/** The right group's start, before Report (status chips). */
|
|
45
|
+
end?: string;
|
|
46
|
+
/** After Report. */
|
|
47
|
+
bell?: string;
|
|
48
|
+
/** Last, after the version chip. */
|
|
49
|
+
account?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface RailModel {
|
|
52
|
+
nav?: NavItem[];
|
|
53
|
+
groups?: NavGroup[];
|
|
54
|
+
/** Entries (or HTML) under the rail's spacer, before the collapse toggle. */
|
|
55
|
+
foot?: (NavItem | string)[];
|
|
56
|
+
lang?: string;
|
|
57
|
+
collapsed?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ShellModel extends RailModel {
|
|
60
|
+
product?: Product;
|
|
61
|
+
slots?: Slots;
|
|
62
|
+
/** false: no Report button (reports off). */
|
|
63
|
+
report?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export declare function navItemHtml(n: NavItem): string;
|
|
66
|
+
export declare function railGroupHtml(
|
|
67
|
+
g: NavGroup,
|
|
68
|
+
body: string,
|
|
69
|
+
lang?: string,
|
|
70
|
+
): string;
|
|
71
|
+
export declare function railHtml(model?: RailModel): string;
|
|
72
|
+
export declare function versionChipHtml(o?: {
|
|
73
|
+
version?: string | null;
|
|
74
|
+
lang?: string;
|
|
75
|
+
}): string;
|
|
76
|
+
export declare function reportButtonHtml(o?: {
|
|
77
|
+
inFoot?: boolean;
|
|
78
|
+
inTop?: boolean;
|
|
79
|
+
lang?: string;
|
|
80
|
+
/** The button's own words, and its accessible name (escaped). */
|
|
81
|
+
label?: string;
|
|
82
|
+
/** Kept on the button as JSON; the kit's click opens Report with it. */
|
|
83
|
+
prefill?: { kind?: string; title?: string; description?: string };
|
|
84
|
+
}): string;
|
|
85
|
+
/** A Report button's prefill (its data-den-report-prefill), or undefined. */
|
|
86
|
+
export declare function reportPrefillOf(
|
|
87
|
+
el: Element | null | undefined,
|
|
88
|
+
): { kind?: string; title?: string; description?: string } | undefined;
|
|
89
|
+
export declare function topBarHtml(model?: ShellModel): string;
|
|
90
|
+
/** The whole shell: skip link, top bar and rail, as HTML. Pure: runs in Node. */
|
|
91
|
+
export declare function shellHtml(model?: ShellModel): string;
|
|
@@ -0,0 +1,289 @@
|
|
|
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, lang, slots, collapsed, report })
|
|
12
|
+
* product { name, title?, version?, href?, mark? } the brand: `name` is the
|
|
13
|
+
* word beside the mark, `title` its tooltip (default name),
|
|
14
|
+
* `version` the chip's text ("v" + version; "v…" when unknown),
|
|
15
|
+
* `href` where the brand goes (default "/"), `mark`
|
|
16
|
+
* { text?, svg?, label } the mark beside it (text escaped;
|
|
17
|
+
* svg the product's own markup; label its name)
|
|
18
|
+
* nav [{ id, label, href, group, icon?, tip?, current?, badge?,
|
|
19
|
+
* lead?, mono?, cls?, attrs?, pin?, after? }] rail entries
|
|
20
|
+
* groups [{ id, label, from? }] in rail order; a group with no
|
|
21
|
+
* entry is left out
|
|
22
|
+
* foot entries under the rail's spacer (Settings, say), then the
|
|
23
|
+
* kit's collapse toggle
|
|
24
|
+
* lang "en", "es" or "ja" (the kit's words; else en)
|
|
25
|
+
* slots { start, end, bell, account }: the product's own HTML in
|
|
26
|
+
* the top bar. start: after the brand; end: the right group's
|
|
27
|
+
* start, before Report; bell, account: after Report, so the
|
|
28
|
+
* right group reads Report · bell · version · account
|
|
29
|
+
* collapsed the rail drawn collapsed (the toggle says Expand)
|
|
30
|
+
* report false: no Report button (reports off)
|
|
31
|
+
*
|
|
32
|
+
* An entry: `badge` { n, bad?, label? } (label is read with the name);
|
|
33
|
+
* `lead` HTML in place of the icon (a status dot); `attrs` more
|
|
34
|
+
* attributes { name: value } (escaped); `cls` more classes; `pin` the
|
|
35
|
+
* pinned id (the row is a pin row: Delete unpins it); `after` HTML after
|
|
36
|
+
* the link inside the pin row (a Visit link).
|
|
37
|
+
*/
|
|
38
|
+
import { esc, kitT } from "./strings.js";
|
|
39
|
+
import { icon } from "./icons.js";
|
|
40
|
+
|
|
41
|
+
export { icon } from "./icons.js";
|
|
42
|
+
export { esc } from "./strings.js";
|
|
43
|
+
|
|
44
|
+
function attrs(o) {
|
|
45
|
+
let s = "";
|
|
46
|
+
if (!o) return s;
|
|
47
|
+
for (const k of Object.keys(o)) {
|
|
48
|
+
const v = o[k];
|
|
49
|
+
if (v == null || v === false) continue;
|
|
50
|
+
s += v === true ? ` ${k}` : ` ${k}="${esc(v)}"`;
|
|
51
|
+
}
|
|
52
|
+
return s;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One rail entry (a link, .den-ni). */
|
|
56
|
+
export function navItemHtml(n) {
|
|
57
|
+
const b = n.badge || null;
|
|
58
|
+
const extra = b
|
|
59
|
+
? '<span class="den-bdg' +
|
|
60
|
+
(b.bad ? " bad" : "") +
|
|
61
|
+
'" aria-hidden="true">' +
|
|
62
|
+
esc(b.n) +
|
|
63
|
+
"</span>"
|
|
64
|
+
: "";
|
|
65
|
+
const more = { ...(n.attrs || {}) };
|
|
66
|
+
if (b && b.label && more["aria-label"] == null)
|
|
67
|
+
more["aria-label"] = n.label + ", " + b.label;
|
|
68
|
+
const link =
|
|
69
|
+
'<a class="den-ni' +
|
|
70
|
+
(n.cls ? " " + esc(n.cls) : "") +
|
|
71
|
+
'" href="' +
|
|
72
|
+
esc(n.href) +
|
|
73
|
+
'" data-nav="' +
|
|
74
|
+
esc(n.id) +
|
|
75
|
+
'"' +
|
|
76
|
+
(n.current ? ' aria-current="page"' : "") +
|
|
77
|
+
attrs(more) +
|
|
78
|
+
' title="' +
|
|
79
|
+
esc(n.tip || n.label) +
|
|
80
|
+
'">' +
|
|
81
|
+
(n.lead || icon(n.icon)) +
|
|
82
|
+
'<span class="den-lbl' +
|
|
83
|
+
(n.mono ? " den-mono" : "") +
|
|
84
|
+
'">' +
|
|
85
|
+
esc(n.label) +
|
|
86
|
+
"</span>" +
|
|
87
|
+
extra +
|
|
88
|
+
"</a>";
|
|
89
|
+
return n.pin != null
|
|
90
|
+
? '<div class="den-pin-row">' + link + (n.after || "") + "</div>"
|
|
91
|
+
: link;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A rail group: its heading (and "from <d>" tag) and its entries. */
|
|
95
|
+
export function railGroupHtml(g, body, lang) {
|
|
96
|
+
const id = esc(g.id);
|
|
97
|
+
const from = g.from;
|
|
98
|
+
return (
|
|
99
|
+
'<div class="den-rail-group" role="group" aria-labelledby="den-gh-' +
|
|
100
|
+
id +
|
|
101
|
+
'"' +
|
|
102
|
+
(from ? ' aria-describedby="den-gd-' + id + '"' : "") +
|
|
103
|
+
'><div class="den-gh"><span id="den-gh-' +
|
|
104
|
+
id +
|
|
105
|
+
'">' +
|
|
106
|
+
esc(g.label) +
|
|
107
|
+
"</span>" +
|
|
108
|
+
(from
|
|
109
|
+
? '<span class="den-tagx" aria-hidden="true" title="' +
|
|
110
|
+
esc(kitT(lang, "kit.from", { d: from })) +
|
|
111
|
+
'">' +
|
|
112
|
+
esc(from) +
|
|
113
|
+
"</span>"
|
|
114
|
+
: "") +
|
|
115
|
+
"</div>" +
|
|
116
|
+
(from
|
|
117
|
+
? '<span class="den-sr" id="den-gd-' +
|
|
118
|
+
id +
|
|
119
|
+
'">' +
|
|
120
|
+
esc(kitT(lang, "kit.from", { d: from })) +
|
|
121
|
+
"</span>"
|
|
122
|
+
: "") +
|
|
123
|
+
body +
|
|
124
|
+
"</div>"
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The collapse toggle at the rail's foot. */
|
|
129
|
+
function collapseHtml(collapsed, lang) {
|
|
130
|
+
const word = kitT(lang, collapsed ? "kit.expand" : "kit.collapse");
|
|
131
|
+
return (
|
|
132
|
+
'<button class="den-ni den-collapse-btn" type="button" data-act="collapse" aria-expanded="' +
|
|
133
|
+
(collapsed ? "false" : "true") +
|
|
134
|
+
'" title="' +
|
|
135
|
+
esc(word) +
|
|
136
|
+
'"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="' +
|
|
137
|
+
(collapsed ? "M9 6l6 6-6 6" : "M15 6l-6 6 6 6") +
|
|
138
|
+
'"/></svg><span class="den-lbl">' +
|
|
139
|
+
esc(word) +
|
|
140
|
+
"</span></button>"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The rail's content: the groups, the spacer, the foot, the toggle. */
|
|
145
|
+
export function railHtml({
|
|
146
|
+
nav = [],
|
|
147
|
+
groups = [],
|
|
148
|
+
foot = [],
|
|
149
|
+
lang,
|
|
150
|
+
collapsed,
|
|
151
|
+
} = {}) {
|
|
152
|
+
let html = "";
|
|
153
|
+
for (const g of groups) {
|
|
154
|
+
const items = nav.filter((n) => n.group === g.id);
|
|
155
|
+
if (!items.length) continue;
|
|
156
|
+
html += railGroupHtml(g, items.map(navItemHtml).join(""), lang);
|
|
157
|
+
}
|
|
158
|
+
html += '<div class="den-rail-grow"></div>';
|
|
159
|
+
html += foot
|
|
160
|
+
.map((n) => (typeof n === "string" ? n : navItemHtml(n)))
|
|
161
|
+
.join("");
|
|
162
|
+
html += collapseHtml(!!collapsed, lang);
|
|
163
|
+
return html;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The version chip: "v<version>" (v… until known); a click opens What's new. */
|
|
167
|
+
export function versionChipHtml({ version, lang } = {}) {
|
|
168
|
+
return (
|
|
169
|
+
'<button class="den-ib v-pill" id="version-pill" title="' +
|
|
170
|
+
esc(kitT(lang, "kit.version.title")) +
|
|
171
|
+
'"><span class="v-txt">' +
|
|
172
|
+
esc(version ? "v" + String(version).replace(/^v/, "") : "v…") +
|
|
173
|
+
'</span><span class="v-pip" id="v-pip"></span></button>'
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The Report button: the flat speech bubble, the word, ⌘⇧F (hidden on a
|
|
179
|
+
* phone). `inFoot`: a pop-up's footer; `inTop`: the top bar. `label`:
|
|
180
|
+
* the button's own words (a row's "Report this"), its name too. `prefill`:
|
|
181
|
+
* { kind?, title?, description? }, kept as JSON on the button; the kit's
|
|
182
|
+
* click opens Report with it. A click on any [data-den-report] opens the
|
|
183
|
+
* Report form (the client's job).
|
|
184
|
+
*/
|
|
185
|
+
export function reportButtonHtml({ inFoot, inTop, lang, label, prefill } = {}) {
|
|
186
|
+
return (
|
|
187
|
+
'<button type="button" class="den-rb' +
|
|
188
|
+
(inFoot ? " den-rb-in" : "") +
|
|
189
|
+
(inTop ? " den-rb-top" : "") +
|
|
190
|
+
'" data-den-report' +
|
|
191
|
+
(prefill
|
|
192
|
+
? ' data-den-report-prefill="' + esc(JSON.stringify(prefill)) + '"'
|
|
193
|
+
: "") +
|
|
194
|
+
(label != null ? ' aria-label="' + esc(label) + '"' : "") +
|
|
195
|
+
' aria-keyshortcuts="Meta+Shift+F Control+Shift+F" title="' +
|
|
196
|
+
esc(kitT(lang, "kit.report.tip")) +
|
|
197
|
+
'">' +
|
|
198
|
+
icon("report") +
|
|
199
|
+
"<span>" +
|
|
200
|
+
esc(label != null ? label : kitT(lang, "kit.report.word")) +
|
|
201
|
+
'</span><kbd aria-hidden="true">⌘⇧F</kbd></button>'
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A Report button's prefill (data-den-report-prefill), or undefined. */
|
|
206
|
+
export function reportPrefillOf(el) {
|
|
207
|
+
const raw =
|
|
208
|
+
el && el.getAttribute && el.getAttribute("data-den-report-prefill");
|
|
209
|
+
if (!raw) return undefined;
|
|
210
|
+
try {
|
|
211
|
+
const p = JSON.parse(raw);
|
|
212
|
+
return p && typeof p === "object" ? p : undefined;
|
|
213
|
+
} catch {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The brand's mark: none, the empty slot (a product may fill it itself);
|
|
220
|
+
* `text`, escaped; or `svg`, the product's own markup (the same trust as
|
|
221
|
+
* the icons). `label` names it.
|
|
222
|
+
*/
|
|
223
|
+
function markHtml(mark) {
|
|
224
|
+
if (!mark || (mark.text == null && mark.svg == null))
|
|
225
|
+
return '<span class="den-mark" id="den-mark" aria-hidden="true"></span>';
|
|
226
|
+
return (
|
|
227
|
+
'<span class="den-mark" id="den-mark" role="img" aria-label="' +
|
|
228
|
+
esc(mark.label ?? "") +
|
|
229
|
+
'">' +
|
|
230
|
+
(mark.svg != null ? String(mark.svg) : esc(mark.text)) +
|
|
231
|
+
"</span>"
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The top bar (header.den-top). */
|
|
236
|
+
export function topBarHtml({
|
|
237
|
+
product = {},
|
|
238
|
+
lang,
|
|
239
|
+
slots = {},
|
|
240
|
+
report = true,
|
|
241
|
+
} = {}) {
|
|
242
|
+
const name = product.name ?? "";
|
|
243
|
+
return (
|
|
244
|
+
'<header class="den-top">' +
|
|
245
|
+
'<button class="den-ib den-menu-btn" id="den-menu-btn" aria-label="' +
|
|
246
|
+
esc(kitT(lang, "kit.menu")) +
|
|
247
|
+
'" aria-expanded="false" aria-controls="den-rail">☰</button>' +
|
|
248
|
+
'<a class="den-brand" href="' +
|
|
249
|
+
esc(product.href || "/") +
|
|
250
|
+
'" title="' +
|
|
251
|
+
esc(product.title || name) +
|
|
252
|
+
'">' +
|
|
253
|
+
markHtml(product.mark) +
|
|
254
|
+
// The brand is a name, not a heading: the page's own h1 is its one.
|
|
255
|
+
'<span class="den-title">' +
|
|
256
|
+
esc(name) +
|
|
257
|
+
"</span></a>" +
|
|
258
|
+
(slots.start || "") +
|
|
259
|
+
'<div class="den-chips">' +
|
|
260
|
+
(slots.end || "") +
|
|
261
|
+
(report === false ? "" : reportButtonHtml({ inTop: true, lang })) +
|
|
262
|
+
(slots.bell || "") +
|
|
263
|
+
versionChipHtml({ version: product.version, lang }) +
|
|
264
|
+
(slots.account || "") +
|
|
265
|
+
"</div>" +
|
|
266
|
+
"</header>"
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The whole shell: the skip link, the top bar and the rail (in its box:
|
|
272
|
+
* no box of its own, display: contents; as ☰'s drawer it is the modal
|
|
273
|
+
* dialog the rail sits in, so the rail stays a nav).
|
|
274
|
+
*/
|
|
275
|
+
export function shellHtml(o = {}) {
|
|
276
|
+
const lang = o.lang;
|
|
277
|
+
return (
|
|
278
|
+
'<a class="den-skip" href="#den-content">' +
|
|
279
|
+
esc(kitT(lang, "kit.skip")) +
|
|
280
|
+
"</a>" +
|
|
281
|
+
topBarHtml(o) +
|
|
282
|
+
'<div class="den-rail-box" id="den-rail-box">' +
|
|
283
|
+
'<nav class="den-rail" id="den-rail" aria-label="' +
|
|
284
|
+
esc(kitT(lang, "kit.pages")) +
|
|
285
|
+
'">' +
|
|
286
|
+
railHtml(o) +
|
|
287
|
+
"</nav></div>"
|
|
288
|
+
);
|
|
289
|
+
}
|