@monster-orange/den-ui 0.5.1 → 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/README.md CHANGED
@@ -56,6 +56,338 @@ own copy, so a page never mixes two versions.
56
56
  `--text`, `--muted`, `--border-strong`, `--accent`, `--accent-text` and
57
57
  `--upd-shadow`.
58
58
 
59
+ ## The shell and its parts (0.6.0)
60
+
61
+ The global shell is the kit's: the top bar, the left rail with its pins,
62
+ collapse toggle and ☰ drawer, the version chip, What's new, the Report
63
+ button and form, and the update pill. A product gives its own parts as
64
+ data and HTML slots; it keeps no copy of the kit's markup, CSS or code.
65
+
66
+ - `src/shell-html.js` (export `./shell-html`): the markup, pure (no DOM),
67
+ so it runs in Node and in the page. A product renders its frame on the
68
+ server and in the browser with the same function.
69
+
70
+ import { shellHtml } from "@monster-orange/den-ui/shell-html";
71
+ const html = shellHtml({
72
+ product: { name: "Acme", version: "2.0.0" }, // title?, href?
73
+ nav: [{ id: "home", label: "Home", href: "/", group: "work",
74
+ icon: "home", current: true }], // badge, pin, lead, …
75
+ groups: [{ id: "work", label: "Work" }], // from? tags a group
76
+ foot: [], // under the spacer
77
+ lang: "en", // en, es or ja
78
+ slots: { start, end, bell, account }, // the product's HTML
79
+ collapsed: false,
80
+ report: true, // false: reports off
81
+ });
82
+
83
+ Also `topBarHtml`, `railHtml`, `navItemHtml`, `versionChipHtml`,
84
+ `reportButtonHtml`, `icon(name)` (`src/icons.js`) and `esc`.
85
+
86
+ - **Slots.** The top bar reads: ☰, the brand, `start` (a search, a scope
87
+ menu), then the right group: `end` (status chips), Report, `bell`, the
88
+ version chip, `account`. Report · bell · account keep their place
89
+ whatever a product puts in its slots.
90
+ - `src/shell-client.js` (export `./shell-client`): hydrates what
91
+ shell-html drew. `hydrateShell(root, { lang, onCollapse, onUnpin,
92
+ inert, menuOpen })` binds the rail's keys (↑ ↓ Home End, Delete unpins),
93
+ the collapse toggle and the ☰ drawer (a modal below 720px: the page
94
+ inert, Escape or the scrim closes it), and returns `{ rove, paint(html,
95
+ force), setCollapsed, unpin, openDrawer, closeDrawer, drawerOpen,
96
+ syncPinToggles }`.
97
+ - `src/shell.css`, `src/whatsnew.css`, `src/report.css`: the look. Link
98
+ them after `tokens.css`.
99
+ - `src/version.js` (the chip's label and its unread dot), `src/whatsnew.js`
100
+ (the release notes pop-up: newest first, earlier versions on request,
101
+ copy as Markdown or for chat), `src/report.js` and `src/report-shot.js`
102
+ (the Report form, its screenshot and masks).
103
+
104
+ ### The client entry: `src/kit.js` (`window.DenUI`)
105
+
106
+ import DenUI from "/kit/kit.js"; // also sets window.DenUI
107
+ DenUI.configure({ lang, product: { name }, adapter, report, whatsNew });
108
+ DenUI.mount(root, model) // shellHtml(model) into root, hydrated
109
+ DenUI.hydrate(root, opts) // a shell rendered on the server
110
+ DenUI.version.set("v2.0.0"); DenUI.version.unread(true);
111
+ DenUI.whatsNew.open(); // .close(), .load()
112
+ DenUI.update.set({ version }); // the update pill; .hide()
113
+ DenUI.report.open({ prefill }); // ⌘⇧F and any [data-den-report] too
114
+ DenUI.busy.run(action, run, opts) // the working pop-up (busy.js)
115
+
116
+ ### The adapter
117
+
118
+ The kit names no URL. Every call to the product goes through the adapter;
119
+ a missing call turns its feature off rather than failing.
120
+
121
+ | call | used by | returns |
122
+ | --------------------- | -------------------------------- | --------------------------------------------- |
123
+ | `changelog()` | What's new | `[{ version, date, sections }]`, newest first |
124
+ | `applyUpdate()` | the update pill's Reload | anything; the page reloads after |
125
+ | `fileReport(payload)` | Report | `{ number, url }` or `{ error }` |
126
+ | `request(id)` | the working pop-up's Check again | `{ state, result?, error? }` |
127
+
128
+ With `fileReport`, Report ends on "Filed as #N" and a link to it. With no
129
+ way to send, Report offers "Copy report" only: the report as text, to
130
+ paste where the team tracks issues. A product with more (a preview, a
131
+ sign-in flow, drafts) gives `info`, `diagnostics`, `preview`, `send`,
132
+ `githubSend`, `githubPoll` and `saveDraft`; see the top of `report.js`.
133
+
134
+ ### Strings
135
+
136
+ `src/strings.js` (export `./strings`) exports `en`, `es` and `ja`: every
137
+ word the kit shows, each key starting `kit.`, the same keys and
138
+ `{placeholders}` in all three (a test checks). `{product}` is the name
139
+ given to `configure`. A product adds its own words, or its own versions
140
+ of the kit's, with `DenUI.strings(lang, table)`; an unknown language falls
141
+ back to English.
142
+
143
+ ### Content Security Policy
144
+
145
+ The shell, the version chip, What's new, the update pill, Report, the
146
+ working pop-up and the dialogs work under `script-src 'self'; style-src 'self'`: no
147
+ inline `style` attributes, no inline scripts, handlers or `<style>`, no
148
+ `eval`. They set custom properties through the CSSOM
149
+ (`style.setProperty`), which the policy allows. A browser test loads a
150
+ kit page under that policy and fails on any violation. Since 0.6.2 the
151
+ ask-and-tell dialogs (dialog.js) work under it too, and the test covers
152
+ them.
153
+
154
+ ### The parity gate: `den-ui-parity`
155
+
156
+ npx den-ui-parity [--root .] [--src src]... [--json]
157
+
158
+ It scans a product's source for its own copy of a kit component (markup
159
+ that draws the kit's elements, CSS for them, a function with a kit
160
+ builder's name, a file named as or identical to a kit file) and exits 1
161
+ when it finds one. Den runs it in CI (`npm run gate:den-ui`).
162
+
163
+ A product that keeps a copy on purpose names it in `DIVERGE.md` at its
164
+ repository root, one row per component, with a reason:
165
+
166
+ | component | reason |
167
+ |---|---|
168
+ | report | our reports go to a ticket desk, not an issue tracker |
169
+
170
+ (or a list: `- report: our reports go to …`). The components are `shell`,
171
+ `version`, `whatsnew`, `update`, `report` and `working`. A row without a
172
+ reason does not count. With no DIVERGE.md, every copy fails.
173
+
174
+ ### Nav inventory
175
+
176
+ `inventory/nav-inventory.js` (export `./inventory`, types beside it): one
177
+ spec every product runs, so two products' top bars and rails never
178
+ quietly differ. It lists the global nav element by element and compares
179
+ it with the kit's reference: Den's nav as signed off, in
180
+ `inventory/reference/den-<browser>-<width>.json` (export
181
+ `./inventory/reference/*`), for `chromium` and `webkit` at `1280` and
182
+ `390`.
183
+
184
+ One browser build and one theme. The references were taken on
185
+ Playwright's image `NAV_BROWSER_IMAGE`, its linux/amd64 build (the arm64
186
+ build ships another Chromium; on an arm64 machine add
187
+ `--platform linux/amd64`):
188
+
189
+ mcr.microsoft.com/playwright:v1.61.1-noble@sha256:cf0daee9b994042e011bc29f20cdff1a9f682a039b43fcd738f7d8a9d3bcd9d6
190
+
191
+ in the theme `NAV_THEME`, Den's default theme "den" 2.0.1 (the kit's
192
+ default tokens). A host must run the inventory on that image, in that
193
+ theme, with the shipped references, so both products are measured in one
194
+ browser build and one look. Start the image's run-server and connect both
195
+ browsers to it through `DEN_PW_WS`:
196
+
197
+ docker run -d --init --platform linux/amd64 -p 127.0.0.1:3921:3921 \
198
+ mcr.microsoft.com/playwright:v1.61.1-noble@sha256:cf0daee9b994042e011bc29f20cdff1a9f682a039b43fcd738f7d8a9d3bcd9d6 \
199
+ npx -y playwright@1.61.1 run-server --port 3921 --host 0.0.0.0
200
+ DEN_PW_WS=ws://localhost:3921/
201
+
202
+ import { chromium } from "playwright"; // 1.61.1, as the image
203
+ import { collectNav, compareNav, formatNavDiffs, NAV_BROWSER_IMAGE,
204
+ NAV_THEME } from "@monster-orange/den-ui/inventory";
205
+ import { readFileSync } from "node:fs";
206
+ import { createRequire } from "node:module";
207
+
208
+ // exposeNetwork: the browser in the container reaches the host's own
209
+ // server on this machine's loopback through the connection.
210
+ const browser = await chromium.connect(process.env.DEN_PW_WS,
211
+ { exposeNetwork: "<loopback>" });
212
+ const page = await browser.newPage({ viewport: { width: 1280, height: 900 },
213
+ colorScheme: "light" });
214
+ await page.goto("http://localhost:<port>/"); // the host's own page
215
+ const ref = JSON.parse(readFileSync(createRequire(import.meta.url)
216
+ .resolve("@monster-orange/den-ui/inventory/reference/den-chromium-1280.json"),
217
+ "utf-8"));
218
+ const diffs = compareNav(
219
+ await collectNav(page, { image: NAV_BROWSER_IMAGE, theme: NAV_THEME }),
220
+ ref,
221
+ { hostSlots: ["#my-status"] }, // what the host fills itself
222
+ );
223
+ expect(formatNavDiffs(diffs)).toBe(""); // one line per difference
224
+
225
+ Pass `theme` as the theme the page really draws in (Den reads it from
226
+ `/api/themes`). On another browser build (a different fingerprint: user
227
+ agent and the measured width of one fixed line in each face the nav
228
+ uses) the one difference is `env`, "reference taken on X, running on Y";
229
+ in another theme it is `theme`. Boxes that can't match are never
230
+ compared.
231
+
232
+ - `collectNav(page, { image, theme })` returns `{ version, viewport,
233
+ env, elements, tokens }`. `env`: `userAgent`, `faces` (the
234
+ fingerprint), `image`, `theme`. `elements`: `header.den-top`,
235
+ `nav.den-rail` and every element under them with a box, in DOM order
236
+ (hidden ones and an `<svg>`'s shapes left out). Each has `key`,
237
+ `parent`, `slot` (`top`, `rail`, or `foot`: after the rail's spacer),
238
+ `role`, `tag`, `name` (aria-label, aria-labelledby, alt, its text for a
239
+ control or a leaf, title), `classes`, `box` `{ x, y, w, h }` and
240
+ `style`: display, visibility, height, the four corner radii,
241
+ background-color, each side's border width, style and colour,
242
+ font-size, -weight, -family, -style, line-height, letter-spacing,
243
+ text-transform, padding, row-gap, column-gap, color, opacity,
244
+ box-shadow. A key is `#id`, `[data-nav="x"]`, or the parent's key `>`
245
+ tag.class (`[n]` among like siblings): `#den-search > kbd`.
246
+ - `compareNav(actual, reference, { hostSlots, themeTokens, tolerance })`
247
+ returns `[{ key, slot, property, reference, actual }]`, empty when the
248
+ navs match. It fails on an element missing, extra or out of order
249
+ (`property` `element`, `order`); a role, tag, name or class list that
250
+ differs; a box edge moved more than `tolerance` px (default 2:
251
+ `box.left`, …); any computed style that differs (`style.font-weight`),
252
+ colours and fonts included.
253
+ - `hostSlots`: keys (`#den-status`) or one class (`.den-scope`) whose
254
+ element and everything under it are the host's own: not compared, on
255
+ either side. A host slot wider or narrower than the reference (or on
256
+ one side only) may move or stretch its neighbours sideways by exactly
257
+ that much, never by anything else.
258
+ - `themeTokens`: empty by default, and never set on a parity run: both
259
+ products run in `NAV_THEME`, so any colour or font that differs is a
260
+ real gap. It is only for a run that switches themes on purpose. What a
261
+ theme may change, and so what the list may name: the colour tokens
262
+ (`--bg`, `--surface`, `--raised`, `--sunken`, `--text`, `--muted`,
263
+ `--faint`, `--border`, `--border-strong`, `--accent`, and the rest of
264
+ tokens.css's colours) and the font tokens (`--sans`, `--mono`,
265
+ `--display`). A colour or font-family listed may differ when, on both
266
+ sides, it comes from that token. How a value's token is found: every
267
+ custom property declared on `:root` or `html` (in any sheet the page
268
+ can read, inside `@media` and `@layer` too) is read from `<html>`'s
269
+ computed style; a colour is set on a probe element's `color`, a family
270
+ list on its `font-family`, and read back, so it is in the form computed
271
+ values take. `snapshot.tokens` maps each colour and family seen to the
272
+ tokens that compute to it.
273
+ - Fonts in Den's test: the system faces are pinned to the kit's own
274
+ Rubik and Space Mono, so text lays out alike from run to run. A host
275
+ pins them the same way (see `tests/unit/den-ui/nav-inventory-helpers.ts`).
276
+
277
+ Den runs it in `tests/unit/den-ui/nav-inventory.browser.test.ts` (CI's
278
+ `den-ui-nav` job starts the image) with red cases that must fail: the
279
+ search field 3 px over, its corners, the bell gone, two elements
280
+ swapped, a font weight, the search's ⌘K and icon gone, a theme token's
281
+ colour, a font-family; a host slot's new contents must pass.
282
+ `nav-inventory.test.ts` checks the comparer with no browser. To take the
283
+ reference again, on purpose only: `DEN_UI_NAV_CAPTURE=1` with the
284
+ browser test, on the image (Den's real server on the demo distribution,
285
+ `/settings`).
286
+
287
+ ## The working pop-up and types (0.6.1)
288
+
289
+ - `src/busy.js`, `src/busy-words.js` and `src/busy.css` (exports `./busy`,
290
+ `./busy-words`, `./busy.css`): the working pop-up. Its look is
291
+ `busy.css`, linked, never injected. Link it in the page's `<head>`;
292
+ without that, busy.js links it from beside itself the first time it
293
+ opens.
294
+
295
+ busyAction("save", async (headers, progress) => {
296
+ progress("Copying files"); // a line under the title
297
+ const r = await fetch("/api/save", { method: "POST", headers });
298
+ if (!r.ok) throw { status: r.status };
299
+ return r.json();
300
+ }, {
301
+ // A failure trying again won't fix: its link in place of Try again.
302
+ next: (err) => (err.status === 403
303
+ ? { label: "Sign in", href: "/sign-in" } : null),
304
+ });
305
+
306
+ `next` is `{ label, href }` or a function of the failure that returns
307
+ one (or null for Try again). The pop-up then says that trying again
308
+ won't help, and the link is its primary button. `progress(text)` lines
309
+ show in order while it works. `quietFail`, `inlineError`, `skipDone`
310
+ and `extra` are as before, and a success still closes at once with a
311
+ toast.
312
+
313
+ - Types: every `src/*.js` has a `.d.ts` beside it; the package's `types`
314
+ is `src/kit.d.ts`. A test compiles a consumer against them with
315
+ `--strict`.
316
+
317
+ ## 0.6.6
318
+
319
+ - A time drawn by `upgradeTimes` reads in the language of the part of
320
+ the page it sits in: the nearest `[lang]` around the `<time>` first,
321
+ then `<html lang>`, then the browser's. Text and title both. A row
322
+ still in English on a translated page no longer reads "connected 今".
323
+ - No new files: hosts serving a fixed list change nothing.
324
+
325
+ ## 0.6.5
326
+
327
+ - Focus goes back to what opened a pop-up when it closes, in Safari too.
328
+ Safari doesn't focus a button on a click, so the browser's own dialog
329
+ restore went to the page's body. Report, `askConfirm`, `askText`,
330
+ `tell` and What's new now remember their opener and focus it again on
331
+ every way out (Esc, Discard, Cancel, Close, after a send), without
332
+ scrolling, when it is still on the page.
333
+ - The opener is `opts.opener` when given (`report.open({ opener })`,
334
+ `askConfirm({ opener })`), else the focused element, else the control
335
+ just pressed. A kit Report button is its own opener.
336
+ - The shared helper is in `dialog.js` (`openerOf`, `focusBack`), a file
337
+ hosts already serve: no new kit file. The working pop-up already
338
+ focuses its own `button` again; it is unchanged.
339
+
340
+ ## 0.6.4
341
+
342
+ - shell.css: the top bar is its own layer from the start
343
+ (`will-change: transform`). The update pill's glass (`blur(3px)
344
+ saturate(1.4)`, unchanged) made Chromium draw the page's text grayscale
345
+ while the pill showed, so the bar's mark and name changed pixels when
346
+ the pill appeared. Now the bar is the same with the pill shown or
347
+ hidden. Its text is drawn as on any layer of its own (grayscale), as a
348
+ sticky bar's always was.
349
+ - Inside the bar, a `position: fixed` element is placed against the bar,
350
+ not the window: put pop-ups, palettes and toasts on `<body>`. A slot's
351
+ `position: absolute` menu still drops below the bar (the bar never
352
+ clips).
353
+
354
+ ## 0.6.3
355
+
356
+ - Report: ⌘↵ (Ctrl+Enter) is the form's primary button on Write and on
357
+ Include, as in every pop-up: Write → Include → Review. Review still
358
+ sends nothing until the person clicks.
359
+ - shell.css: the page's main (`#den-content`) takes what is left of the
360
+ window under the top bar (`flex: 1 1 auto`), so a short page's last row
361
+ can reach the window's bottom at every width.
362
+ - shell.css: the top bar is pinned. It is `position: fixed` at the top,
363
+ as the rail under it is, and the body has `padding-top` of the bar's
364
+ height (and `box-sizing: border-box`, so its 100vh minimum still holds).
365
+ On a page whose body scrolls, or whose `html, body` are `height: 100%`,
366
+ the bar stays put and no gap opens above the rail.
367
+ - `reportButtonHtml({ label, prefill })` (and `DenUI.report.button`): a
368
+ row's own Report button. `label` replaces the word and names the button;
369
+ `prefill` (`{ kind?, title?, description? }`) is kept on it as JSON
370
+ (`data-den-report-prefill`), and the kit's click opens Report filled
371
+ from it. `reportPrefillOf(el)` reads it back. With neither, the button
372
+ is as before.
373
+
374
+ ## 0.6.2
375
+
376
+ - `src/dialog.css` (export `./dialog.css`): the ask-and-tell dialogs'
377
+ look, linked, never injected. Link it in the page's `<head>`. Without
378
+ that, dialog.js links it from `configureDialog({ css })`, else from
379
+ beside another kit stylesheet on the page.
380
+ - Report: `fileReport(payload)` gets `payload.shot`, the masked
381
+ screenshot as a PNG data URL, or `null` when "Don't include" is picked.
382
+ - `busyAction`'s `next` takes `{ label }` with no `href`: the failure
383
+ says those words in place of Try again, and Close is the primary.
384
+ - `shellHtml`'s `product.mark`: `{ text?, svg?, label }`, drawn in
385
+ `.den-mark`. `text` is escaped. `svg` is the product's own markup, with
386
+ the same trust as the icons. `label` names it (role="img"). With no
387
+ mark, the slot is empty as before.
388
+ - `den-ui-parity` works through npx and `node_modules/.bin`: it compares
389
+ real paths to know it was run as a command.
390
+
59
391
  ## Themes
60
392
 
61
393
  A theme may override every colour in both modes, the shadow, the bar,
@@ -67,7 +399,8 @@ spacing, motion or layers, so layouts stay the same.
67
399
  - Components use tokens only: a test fails on a raw colour outside
68
400
  `tokens.css`.
69
401
  - Every text and background pair passes WCAG AA in both modes (4.5:1 for
70
- text, 3:1 for marks); status pills are checked on their own tint.
402
+ text, 3:1 for marks); status pills are checked on their own tint, and
403
+ the remote colour on its 16% disc.
71
404
  - The fonts stay within 120 KB.
72
405
 
73
406
  ## Licence