@monster-orange/den-ui 0.6.6 → 0.7.1
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 +271 -7
- package/bin/den-ui-parity.mjs +80 -3
- package/inventory/fonts-dir.cjs +8 -0
- package/inventory/fonts-dir.mjs +10 -0
- package/inventory/nav-inventory.d.ts +81 -0
- package/inventory/nav-inventory.js +496 -16
- package/inventory/reference/den-chromium-1280.json +577 -98
- package/inventory/reference/den-chromium-390.json +457 -44
- package/inventory/reference/den-webkit-1280.json +577 -98
- package/inventory/reference/den-webkit-390.json +457 -44
- package/package.json +8 -1
- package/src/kit.d.ts +76 -3
- package/src/kit.js +79 -2
- package/src/marks/den.svg +6 -0
- package/src/report-shot.js +194 -12
- package/src/shell-client.d.ts +118 -0
- package/src/shell-client.js +621 -0
- package/src/shell-html.d.ts +240 -3
- package/src/shell-html.js +724 -12
- package/src/shell.css +721 -5
- package/src/strings.js +54 -0
- package/src/tokens.css +69 -63
- package/src/version.js +5 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* compareNav(actual, reference, { hostSlots, themeTokens, tolerance })
|
|
9
9
|
* → NavDiff[] (empty: the same nav)
|
|
10
10
|
* formatNavDiffs(diffs) → string, one line per difference
|
|
11
|
+
* pinNavFonts(context, { fontsDir }?) → Promise<void>: the same glyphs
|
|
12
|
+
* on every machine (see below)
|
|
11
13
|
*
|
|
12
14
|
* `page` is a Playwright Page (anything with `evaluate(fn, arg)` works),
|
|
13
15
|
* already on a page that draws the kit's shell.
|
|
@@ -38,6 +40,13 @@
|
|
|
38
40
|
* sides.
|
|
39
41
|
*/
|
|
40
42
|
|
|
43
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
44
|
+
import * as path from "node:path";
|
|
45
|
+
// The kit's own src/fonts, found from the kit's files themselves: an ES
|
|
46
|
+
// module reads it from import.meta.url, CommonJS from __dirname (the
|
|
47
|
+
// package's "imports" picks the side).
|
|
48
|
+
import { FONTS_DIR } from "#den-ui-fonts-dir";
|
|
49
|
+
|
|
41
50
|
/** The computed styles kept for each element. */
|
|
42
51
|
export const STYLE_PROPS = [
|
|
43
52
|
"display",
|
|
@@ -199,7 +208,9 @@ export async function collectNav(page, opts = {}) {
|
|
|
199
208
|
// `pathKey`: the DOM parent's key (an element with no box of its own,
|
|
200
209
|
// display: contents, still names its children); `boxParent`: the
|
|
201
210
|
// nearest ancestor with a box, the one the snapshot lists.
|
|
202
|
-
|
|
211
|
+
// `host`: the nearest element (this one or an ancestor) with a
|
|
212
|
+
// data-nav-role: host content ({ role, key }), else null.
|
|
213
|
+
const walk = (el, pathKey, boxParent, slot, hostIn) => {
|
|
203
214
|
if (el.hidden) return slot;
|
|
204
215
|
const cs = getComputedStyle(el);
|
|
205
216
|
if (cs.display === "none") return slot;
|
|
@@ -208,7 +219,29 @@ export async function collectNav(page, opts = {}) {
|
|
|
208
219
|
const n = (used.get(key) || 0) + 1;
|
|
209
220
|
used.set(key, n);
|
|
210
221
|
if (n > 1) key += `{${n}}`;
|
|
222
|
+
const navRole = el.getAttribute("data-nav-role");
|
|
223
|
+
const host = navRole
|
|
224
|
+
? { role: navRole, key }
|
|
225
|
+
: hostIn
|
|
226
|
+
? { role: hostIn.role, key: hostIn.key }
|
|
227
|
+
: null;
|
|
211
228
|
const boxed = el.getClientRects().length > 0;
|
|
229
|
+
// A host root's own width: its contents' plus its padding and
|
|
230
|
+
// border (a field that fills the bar is wider than its words).
|
|
231
|
+
if (navRole && boxed) {
|
|
232
|
+
const rg = document.createRange();
|
|
233
|
+
rg.selectNodeContents(el);
|
|
234
|
+
const px = (p) => parseFloat(cs.getPropertyValue(p)) || 0;
|
|
235
|
+
const edge =
|
|
236
|
+
px("padding-left") +
|
|
237
|
+
px("padding-right") +
|
|
238
|
+
px("border-left-width") +
|
|
239
|
+
px("border-right-width");
|
|
240
|
+
const w = el.getBoundingClientRect().width;
|
|
241
|
+
host.fit = round(
|
|
242
|
+
Math.min(w, rg.getBoundingClientRect().width + edge),
|
|
243
|
+
);
|
|
244
|
+
}
|
|
212
245
|
if (boxed) {
|
|
213
246
|
const r = el.getBoundingClientRect();
|
|
214
247
|
const style = {};
|
|
@@ -228,20 +261,59 @@ export async function collectNav(page, opts = {}) {
|
|
|
228
261
|
h: round(r.height),
|
|
229
262
|
},
|
|
230
263
|
style,
|
|
264
|
+
...(host ? { host } : {}),
|
|
265
|
+
// Its name is the host's words (the search's label, say).
|
|
266
|
+
...(el.getAttribute("data-nav-name") === "host"
|
|
267
|
+
? { hostName: true }
|
|
268
|
+
: {}),
|
|
269
|
+
// 0.7.1: a kit-owned slot's content shape (which fields it
|
|
270
|
+
// draws), the old free-text path, and the kit's own stamp.
|
|
271
|
+
// A crumb showing its label with its value hidden (the
|
|
272
|
+
// value must outlast the label).
|
|
273
|
+
...(el.getAttribute("data-nav-role") === "crumb" &&
|
|
274
|
+
(() => {
|
|
275
|
+
const k = el.querySelector(":scope > .den-k");
|
|
276
|
+
const v = el.lastElementChild;
|
|
277
|
+
if (!k || !v || v === k) return false;
|
|
278
|
+
const kw = k.getClientRects().length
|
|
279
|
+
? k.getBoundingClientRect().width
|
|
280
|
+
: 0;
|
|
281
|
+
const vw = v.getClientRects().length
|
|
282
|
+
? v.getBoundingClientRect().width
|
|
283
|
+
: 0;
|
|
284
|
+
return kw > 1 && vw < 8;
|
|
285
|
+
})()
|
|
286
|
+
? { labelOnly: true }
|
|
287
|
+
: {}),
|
|
288
|
+
...(el.hasAttribute("data-nav-shape")
|
|
289
|
+
? { shape: el.getAttribute("data-nav-shape") }
|
|
290
|
+
: {}),
|
|
291
|
+
...(el.hasAttribute("data-nav-legacy") ? { legacy: true } : {}),
|
|
292
|
+
...(el.hasAttribute("data-den-account")
|
|
293
|
+
? {
|
|
294
|
+
account: true,
|
|
295
|
+
lines: el.querySelectorAll(
|
|
296
|
+
".den-acct-n, .den-acct-l, .den-acct-r",
|
|
297
|
+
).length,
|
|
298
|
+
}
|
|
299
|
+
: {}),
|
|
300
|
+
...(el.hasAttribute("data-nav-kit")
|
|
301
|
+
? { kit: el.getAttribute("data-nav-kit") }
|
|
302
|
+
: {}),
|
|
231
303
|
});
|
|
232
304
|
}
|
|
233
305
|
if (el.tagName.toLowerCase() === "svg") return mySlot;
|
|
234
306
|
let kidSlot = mySlot;
|
|
235
307
|
for (const k of Array.from(el.children)) {
|
|
236
308
|
// Everything after the rail's spacer is the rail's foot.
|
|
237
|
-
kidSlot = walk(k, key, boxed ? key : boxParent, kidSlot);
|
|
309
|
+
kidSlot = walk(k, key, boxed ? key : boxParent, kidSlot, host);
|
|
238
310
|
}
|
|
239
311
|
return kidSlot === "foot" ? "foot" : mySlot;
|
|
240
312
|
};
|
|
241
313
|
const top = document.querySelector("header.den-top");
|
|
242
314
|
const rail = document.querySelector("nav.den-rail, .den-rail");
|
|
243
|
-
if (top) walk(top, null, null, "top");
|
|
244
|
-
if (rail) walk(rail, null, null, "rail");
|
|
315
|
+
if (top) walk(top, null, null, "top", null);
|
|
316
|
+
if (rail) walk(rail, null, null, "rail", null);
|
|
245
317
|
|
|
246
318
|
// The theme tokens: each colour seen → the --tokens that make it.
|
|
247
319
|
const names = new Set();
|
|
@@ -313,8 +385,10 @@ export async function collectNav(page, opts = {}) {
|
|
|
313
385
|
"sans-serif",
|
|
314
386
|
"serif",
|
|
315
387
|
"monospace",
|
|
316
|
-
|
|
317
|
-
|
|
388
|
+
// One line, single-spaced: a token written over lines (tokens.css
|
|
389
|
+
// wraps long values) is the same family (navFamily, below).
|
|
390
|
+
rootCs.getPropertyValue("--sans").replace(/\s+/g, " ").trim(),
|
|
391
|
+
rootCs.getPropertyValue("--mono").replace(/\s+/g, " ").trim(),
|
|
318
392
|
])
|
|
319
393
|
if (fam)
|
|
320
394
|
for (const wt of ["400", "500"]) faceKeys.add(`${wt} 14px ${fam}`);
|
|
@@ -353,11 +427,22 @@ export function fingerprint(snap) {
|
|
|
353
427
|
return JSON.stringify([
|
|
354
428
|
env.userAgent || "",
|
|
355
429
|
Object.keys(faces)
|
|
356
|
-
.
|
|
357
|
-
.
|
|
430
|
+
.map((k) => [navFamily(k), faces[k]])
|
|
431
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)),
|
|
358
432
|
]);
|
|
359
433
|
}
|
|
360
434
|
|
|
435
|
+
/**
|
|
436
|
+
* A font family (or a face key) as one line: every run of whitespace one
|
|
437
|
+
* space, the ends trimmed. "a,\n b" is "a, b": a token's value keeps
|
|
438
|
+
* the line breaks it was written with, and must still name one face.
|
|
439
|
+
*/
|
|
440
|
+
export function navFamily(s) {
|
|
441
|
+
return String(s ?? "")
|
|
442
|
+
.replace(/\s+/g, " ")
|
|
443
|
+
.trim();
|
|
444
|
+
}
|
|
445
|
+
|
|
361
446
|
/** Where a snapshot was taken, in words: its image (if named) and browser. */
|
|
362
447
|
function envWords(snap) {
|
|
363
448
|
const env = snap.env || {};
|
|
@@ -388,7 +473,7 @@ function kept(snap, hostSlots) {
|
|
|
388
473
|
* moves or stretches its neighbours by just that much: each host slot's
|
|
389
474
|
* change in width, per nav slot, and every sum of them.
|
|
390
475
|
*/
|
|
391
|
-
function slotShifts(actual, reference, hostSlots) {
|
|
476
|
+
function slotShifts(actual, reference, hostSlots, extra = {}) {
|
|
392
477
|
const roots = (snap) => {
|
|
393
478
|
const byKey = new Map(snap.elements.map((e) => [e.key, e]));
|
|
394
479
|
const out = new Map();
|
|
@@ -418,6 +503,8 @@ function slotShifts(actual, reference, hostSlots) {
|
|
|
418
503
|
const d = x && y ? x.w - y.w : x ? x.w + x.gap : -(y.w + y.gap);
|
|
419
504
|
if (d) (deltas[slot] = deltas[slot] || []).push(d);
|
|
420
505
|
}
|
|
506
|
+
for (const [slot, ds] of Object.entries(extra))
|
|
507
|
+
for (const d of ds) if (d) (deltas[slot] = deltas[slot] || []).push(d);
|
|
421
508
|
const sums = {};
|
|
422
509
|
for (const [slot, ds] of Object.entries(deltas)) {
|
|
423
510
|
let set = [0];
|
|
@@ -470,6 +557,205 @@ function lcs(a, b) {
|
|
|
470
557
|
* stretch sideways by exactly that change (or a sum of such changes, with
|
|
471
558
|
* the flex gap of a slot there on one side only), never by anything else.
|
|
472
559
|
*/
|
|
560
|
+
/** The rail's column: its slots stack top to bottom. */
|
|
561
|
+
const COLUMN = ["rail", "foot"];
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* issue 303: the top bar's search and the kit's right-side items (Report,
|
|
565
|
+
* the bell, the version chip, ◐ ▾) sit at the reference's x and width,
|
|
566
|
+
* whatever the host's words: a host's crumbs, title or chips never excuse
|
|
567
|
+
* moving them.
|
|
568
|
+
*/
|
|
569
|
+
/**
|
|
570
|
+
* The search's slot for a viewport width (issue 303, "the search never
|
|
571
|
+
* moves"): its x and width are a function of the viewport only, the same
|
|
572
|
+
* in any host. Above 720px: the left part is 444px, less what the bar
|
|
573
|
+
* needs for the search and the kit's right group (TOP_RIGHT_MIN);
|
|
574
|
+
* 481–720px: 200px; up to 480px: 62px. The bar's padding is 12px and
|
|
575
|
+
* its column gap 8px. Mirrors shell.css's .den-top columns (defaults).
|
|
576
|
+
*/
|
|
577
|
+
export const TOP_RIGHT_MIN = 380;
|
|
578
|
+
export function searchSlot(viewportW) {
|
|
579
|
+
const pad = 12;
|
|
580
|
+
const gap = 8;
|
|
581
|
+
if (viewportW > 720) {
|
|
582
|
+
const left = Math.max(
|
|
583
|
+
0,
|
|
584
|
+
Math.min(444, viewportW - 2 * pad - 304 - 2 * gap - TOP_RIGHT_MIN),
|
|
585
|
+
);
|
|
586
|
+
return { x: pad + left + gap, w: 304 };
|
|
587
|
+
}
|
|
588
|
+
return { x: pad + (viewportW < 480 ? 62 : 200) + gap, w: 54 };
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* The search away from its slot (searchSlot for the snapshot's viewport):
|
|
593
|
+
* a difference per edge, at any width, with no reference box needed.
|
|
594
|
+
*/
|
|
595
|
+
export function searchSlotDiffs(snap, tolerance = 2) {
|
|
596
|
+
const out = [];
|
|
597
|
+
const slot = searchSlot(snap.viewport.w);
|
|
598
|
+
for (const e of snap.elements) {
|
|
599
|
+
if (e.slot !== "top" || !e.classes.includes("den-search") || !e.box)
|
|
600
|
+
continue;
|
|
601
|
+
const near = (a, b) => Math.abs(a - b) <= tolerance;
|
|
602
|
+
if (!near(e.box.x, slot.x))
|
|
603
|
+
out.push({
|
|
604
|
+
key: e.key,
|
|
605
|
+
slot: e.slot,
|
|
606
|
+
property: "slot.x",
|
|
607
|
+
reference: String(slot.x),
|
|
608
|
+
actual: String(e.box.x),
|
|
609
|
+
});
|
|
610
|
+
if (!near(e.box.w, slot.w))
|
|
611
|
+
out.push({
|
|
612
|
+
key: e.key,
|
|
613
|
+
slot: e.slot,
|
|
614
|
+
property: "slot.w",
|
|
615
|
+
reference: String(slot.w),
|
|
616
|
+
actual: String(e.box.w),
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
return out;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** The account entry's shapes the kit draws, and their line counts. */
|
|
623
|
+
export const ACCOUNT_SHAPES = { "name,login": 2, login: 1, local: 1 };
|
|
624
|
+
|
|
625
|
+
/** The version's fixed slot for a viewport width (none on a phone). */
|
|
626
|
+
export function versionSlotW(viewportW) {
|
|
627
|
+
return viewportW > 1100 ? 96 : viewportW > 720 ? 64 : 0;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* The top bar's kit slots at any width: the search (searchSlot), and the
|
|
632
|
+
* right group anchored from the right edge: ◐ at the bar's padding, then
|
|
633
|
+
* the version's fixed slot, the bell and Report, 4px apart. Widths that
|
|
634
|
+
* depend on the engine (Report's words, ◐'s glyph) are taken as drawn;
|
|
635
|
+
* their places follow, the same in any host.
|
|
636
|
+
*/
|
|
637
|
+
export function topSlotDiffs(snap, tolerance = 2) {
|
|
638
|
+
const out = searchSlotDiffs(snap, tolerance);
|
|
639
|
+
const vw = snap.viewport.w;
|
|
640
|
+
if (vw <= 720) return out;
|
|
641
|
+
const near = (a, b) => Math.abs(a - b) <= tolerance;
|
|
642
|
+
const find = (pred) =>
|
|
643
|
+
snap.elements.find((e) => e.slot === "top" && e.box && pred(e));
|
|
644
|
+
const ap = find((e) => e.key === "#appearance-btn");
|
|
645
|
+
const ver = find((e) => e.key === "#version-pill");
|
|
646
|
+
const bell = find((e) => e.key === "#den-bell");
|
|
647
|
+
const rb = find((e) => e.classes.includes("den-rb-top"));
|
|
648
|
+
const push = (e, property, want, got) =>
|
|
649
|
+
out.push({
|
|
650
|
+
key: e.key,
|
|
651
|
+
slot: e.slot,
|
|
652
|
+
property,
|
|
653
|
+
reference: String(Math.round(want * 100) / 100),
|
|
654
|
+
actual: String(Math.round(got * 100) / 100),
|
|
655
|
+
});
|
|
656
|
+
let right = vw - 12;
|
|
657
|
+
for (const e of [ap, ver, bell, rb]) {
|
|
658
|
+
if (!e) continue;
|
|
659
|
+
if (e === ver && !near(e.box.w, versionSlotW(vw)))
|
|
660
|
+
push(e, "slot.w", versionSlotW(vw), e.box.w);
|
|
661
|
+
const wantX = right - e.box.w;
|
|
662
|
+
if (!near(e.box.x, wantX)) push(e, "slot.x", wantX, e.box.x);
|
|
663
|
+
right = e.box.x - 4;
|
|
664
|
+
}
|
|
665
|
+
return out;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* 0.7.1: host HTML in the kit's account and search slots, listed (a
|
|
670
|
+
* warning: 0.7.2 makes every slot data, and then it fails). The kit
|
|
671
|
+
* stamps what it draws: the account entry's data-nav-shape, the search's
|
|
672
|
+
* data-nav-kit.
|
|
673
|
+
*/
|
|
674
|
+
export function navWarnings(snap) {
|
|
675
|
+
const out = [];
|
|
676
|
+
for (const e of snap.elements) {
|
|
677
|
+
if (e.account && e.shape == null)
|
|
678
|
+
out.push(
|
|
679
|
+
`account: ${e.key} is not the kit's (host HTML; draw it with accountHtml)`,
|
|
680
|
+
);
|
|
681
|
+
if (
|
|
682
|
+
e.slot === "top" &&
|
|
683
|
+
e.classes.includes("den-search") &&
|
|
684
|
+
e.kit !== "search"
|
|
685
|
+
)
|
|
686
|
+
out.push(
|
|
687
|
+
`search: ${e.key} is not the kit's (host HTML; draw it with searchHtml)`,
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
return out;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
export const PINNED_CLASSES = [
|
|
694
|
+
"den-search",
|
|
695
|
+
"den-rb-top",
|
|
696
|
+
"den-bell",
|
|
697
|
+
"v-pill",
|
|
698
|
+
"appearance-btn",
|
|
699
|
+
];
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Host content's size, by role: for each role, the sum of its roots'
|
|
703
|
+
* widths (in a row) or heights (in the rail's column), each with its
|
|
704
|
+
* parent's gap. `row`: { slot: { role: n } }; `column`: { role: n }.
|
|
705
|
+
*/
|
|
706
|
+
function hostExtent(snap) {
|
|
707
|
+
const byKey = new Map(snap.elements.map((e) => [e.key, e]));
|
|
708
|
+
const row = {};
|
|
709
|
+
const column = {};
|
|
710
|
+
for (const e of snap.elements) {
|
|
711
|
+
if (!e.host || e.host.key !== e.key) continue;
|
|
712
|
+
const parent = e.parent && byKey.get(e.parent);
|
|
713
|
+
const r = e.host.role;
|
|
714
|
+
if (COLUMN.includes(e.slot)) {
|
|
715
|
+
const gap = parseFloat(parent ? parent.style["row-gap"] : "") || 0;
|
|
716
|
+
column[r] = (column[r] || 0) + e.box.h + gap;
|
|
717
|
+
} else {
|
|
718
|
+
const gap = parseFloat(parent ? parent.style["column-gap"] : "") || 0;
|
|
719
|
+
row[e.slot] = row[e.slot] || {};
|
|
720
|
+
const w = e.host.fit == null ? e.box.w : e.host.fit;
|
|
721
|
+
row[e.slot][r] = (row[e.slot][r] || 0) + w + gap;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return { row, column };
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** Every subset's sum of up to 8 deltas, with either sign. */
|
|
728
|
+
function subsetSums(ds) {
|
|
729
|
+
let set = [0];
|
|
730
|
+
for (const d of ds.filter(Boolean).slice(0, 8))
|
|
731
|
+
set = [...set, ...set.map((v) => v + d)];
|
|
732
|
+
return set.flatMap((v) => [v, -v]);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Host content (an element with a data-nav-role, and what it holds): the
|
|
737
|
+
* first of each role on each side, and what it holds by its key's tail,
|
|
738
|
+
* as [role, tail, element] for each.
|
|
739
|
+
*/
|
|
740
|
+
function firstOfRoles(els) {
|
|
741
|
+
const roots = new Map();
|
|
742
|
+
for (const e of els)
|
|
743
|
+
if (e.host && !roots.has(e.host.role)) roots.set(e.host.role, e.host.key);
|
|
744
|
+
const out = new Map();
|
|
745
|
+
for (const e of els) {
|
|
746
|
+
if (!e.host || roots.get(e.host.role) !== e.host.key) continue;
|
|
747
|
+
const root = e.host.key;
|
|
748
|
+
const tail =
|
|
749
|
+
e.key === root
|
|
750
|
+
? ""
|
|
751
|
+
: e.key.startsWith(root)
|
|
752
|
+
? e.key.slice(root.length)
|
|
753
|
+
: null;
|
|
754
|
+
if (tail != null) out.set(`${e.host.role}|${tail}`, e);
|
|
755
|
+
}
|
|
756
|
+
return out;
|
|
757
|
+
}
|
|
758
|
+
|
|
473
759
|
export function compareNav(actual, reference, opts = {}) {
|
|
474
760
|
const hostSlots = opts.hostSlots || [];
|
|
475
761
|
const themeTokens = new Set(opts.themeTokens || []);
|
|
@@ -519,8 +805,41 @@ export function compareNav(actual, reference, opts = {}) {
|
|
|
519
805
|
actual: `running in theme ${themeWords(actual)}`,
|
|
520
806
|
},
|
|
521
807
|
];
|
|
522
|
-
const
|
|
523
|
-
const
|
|
808
|
+
const allWant = kept(reference, hostSlots);
|
|
809
|
+
const allGot = kept(actual, hostSlots);
|
|
810
|
+
// Host content is never keyed: its count, keys, ids and text are the
|
|
811
|
+
// host's. The kit's chrome around it is.
|
|
812
|
+
const want = allWant.filter((e) => !e.host);
|
|
813
|
+
const got = allGot.filter((e) => !e.host);
|
|
814
|
+
// A kit element that holds host content: its name is the host's words.
|
|
815
|
+
const holders = (snap) => {
|
|
816
|
+
const byKey = new Map(snap.elements.map((e) => [e.key, e]));
|
|
817
|
+
const out = new Set();
|
|
818
|
+
for (const e of snap.elements)
|
|
819
|
+
if (e.host)
|
|
820
|
+
for (
|
|
821
|
+
let x = e.parent && byKey.get(e.parent);
|
|
822
|
+
x;
|
|
823
|
+
x = x.parent && byKey.get(x.parent)
|
|
824
|
+
)
|
|
825
|
+
out.add(x.key);
|
|
826
|
+
return out;
|
|
827
|
+
};
|
|
828
|
+
const holdsHost = new Set([...holders(reference), ...holders(actual)]);
|
|
829
|
+
// issue 303: the kit's pinned elements, and all they hold, by the
|
|
830
|
+
// reference's tree.
|
|
831
|
+
const pinnedKeys = new Set();
|
|
832
|
+
{
|
|
833
|
+
const isRoot = (e) =>
|
|
834
|
+
e.slot === "top" && e.classes.some((c) => PINNED_CLASSES.includes(c));
|
|
835
|
+
const byKey = new Map(reference.elements.map((e) => [e.key, e]));
|
|
836
|
+
for (const e of reference.elements)
|
|
837
|
+
for (let x = e; x; x = x.parent && byKey.get(x.parent))
|
|
838
|
+
if (isRoot(x)) {
|
|
839
|
+
pinnedKeys.add(e.key);
|
|
840
|
+
break;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
524
843
|
const wantBy = new Map(want.map((e) => [e.key, e]));
|
|
525
844
|
const gotBy = new Map(got.map((e) => [e.key, e]));
|
|
526
845
|
for (const e of want)
|
|
@@ -539,12 +858,69 @@ export function compareNav(actual, reference, opts = {}) {
|
|
|
539
858
|
`#${b.indexOf(k) + 1} of ${b.length}`,
|
|
540
859
|
);
|
|
541
860
|
const tokenOf = (snap, c) => (snap.tokens && snap.tokens[c]) || [];
|
|
542
|
-
|
|
861
|
+
// Host content's size moves what follows it: in a row by its width's
|
|
862
|
+
// change, in the rail's column by its height's.
|
|
863
|
+
const ea = hostExtent(actual);
|
|
864
|
+
const er = hostExtent(reference);
|
|
865
|
+
const rowDeltas = {};
|
|
866
|
+
for (const slot of new Set([
|
|
867
|
+
...Object.keys(ea.row),
|
|
868
|
+
...Object.keys(er.row),
|
|
869
|
+
])) {
|
|
870
|
+
const a = ea.row[slot] || {};
|
|
871
|
+
const r = er.row[slot] || {};
|
|
872
|
+
rowDeltas[slot] = [...new Set([...Object.keys(a), ...Object.keys(r)])].map(
|
|
873
|
+
(k) => (a[k] || 0) - (r[k] || 0),
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
const shifts = slotShifts(actual, reference, hostSlots, rowDeltas);
|
|
877
|
+
const drops = subsetSums(
|
|
878
|
+
[...new Set([...Object.keys(ea.column), ...Object.keys(er.column)])].map(
|
|
879
|
+
(k) => (ea.column[k] || 0) - (er.column[k] || 0),
|
|
880
|
+
),
|
|
881
|
+
);
|
|
882
|
+
// Issue 303: the search's slot, from the viewport alone.
|
|
883
|
+
diffs.push(...topSlotDiffs(actual, tol));
|
|
884
|
+
// A crumb's value outlasts its label: one whose label shows while its
|
|
885
|
+
// value is hidden fails, whatever the reference drew (crumbs are host
|
|
886
|
+
// content, so this is checked on every element drawn).
|
|
887
|
+
for (const g of actual.elements)
|
|
888
|
+
if (g.labelOnly)
|
|
889
|
+
diffs.push({
|
|
890
|
+
key: g.key,
|
|
891
|
+
slot: g.slot,
|
|
892
|
+
property: "crumb.value",
|
|
893
|
+
reference: "shown",
|
|
894
|
+
actual: "hidden while its label shows",
|
|
895
|
+
});
|
|
543
896
|
for (const w of want) {
|
|
544
897
|
const g = gotBy.get(w.key);
|
|
545
898
|
if (!g) continue;
|
|
546
899
|
for (const p of ["slot", "role", "tag", "name"])
|
|
547
|
-
if (
|
|
900
|
+
if (
|
|
901
|
+
w[p] !== g[p] &&
|
|
902
|
+
!(p === "name" && (holdsHost.has(w.key) || w.hostName || g.hostName))
|
|
903
|
+
)
|
|
904
|
+
add(w, p, w[p], g[p]);
|
|
905
|
+
// 0.7.1: what a kit-owned slot draws (its fields, its lines), and
|
|
906
|
+
// the old free-text path, flagged.
|
|
907
|
+
// The account entry's shape is the kit's: name over @login (two
|
|
908
|
+
// lines), or @login alone, or the kit's local word; never a role
|
|
909
|
+
// or other fields. Checked on what is drawn, not against the
|
|
910
|
+
// reference's data.
|
|
911
|
+
if (g.account && g.shape != null) {
|
|
912
|
+
const want = ACCOUNT_SHAPES[g.shape];
|
|
913
|
+
if (want == null || (g.lines != null && g.lines !== want))
|
|
914
|
+
add(
|
|
915
|
+
w,
|
|
916
|
+
"shape",
|
|
917
|
+
"name,login | login | local",
|
|
918
|
+
`${g.shape} (${g.lines} lines)`,
|
|
919
|
+
);
|
|
920
|
+
} else if ((w.shape ?? "") !== (g.shape ?? ""))
|
|
921
|
+
add(w, "shape", w.shape, g.shape);
|
|
922
|
+
if (g.legacy && !w.legacy)
|
|
923
|
+
add(w, "legacy", "data", "label/detail (deprecated)");
|
|
548
924
|
const wc = w.classes.join(" ");
|
|
549
925
|
const gc = g.classes.join(" ");
|
|
550
926
|
if (wc !== gc) add(w, "classes", wc, gc);
|
|
@@ -556,16 +932,55 @@ export function compareNav(actual, reference, opts = {}) {
|
|
|
556
932
|
});
|
|
557
933
|
const we = edges(w);
|
|
558
934
|
const ge = edges(g);
|
|
559
|
-
|
|
935
|
+
// The search and the kit's right-side items are pinned (issue 303):
|
|
936
|
+
// nothing the host draws may move them.
|
|
937
|
+
const moves = pinnedKeys.has(w.key) ? [0] : shifts[w.slot] || [0];
|
|
560
938
|
for (const edge of ["left", "top", "right", "bottom"]) {
|
|
561
939
|
const d = ge[edge] - we[edge];
|
|
562
940
|
const ok =
|
|
563
941
|
edge === "left" || edge === "right"
|
|
564
942
|
? moves.some((m) => Math.abs(d - m) <= tol)
|
|
565
|
-
:
|
|
943
|
+
: COLUMN.includes(w.slot)
|
|
944
|
+
? drops.some((m) => Math.abs(d - m) <= tol)
|
|
945
|
+
: Math.abs(d) <= tol;
|
|
566
946
|
if (!ok) add(w, `box.${edge}`, we[edge], ge[edge]);
|
|
567
947
|
}
|
|
948
|
+
// The rail's spacer takes up what the rail's pages don't.
|
|
949
|
+
const grows =
|
|
950
|
+
w.classes.includes("den-rail-grow") &&
|
|
951
|
+
drops.some(
|
|
952
|
+
(m) =>
|
|
953
|
+
Math.abs(
|
|
954
|
+
parseFloat(g.style.height) - parseFloat(w.style.height) - m,
|
|
955
|
+
) <= tol,
|
|
956
|
+
);
|
|
957
|
+
styles(w, g, grows ? ["height"] : []);
|
|
958
|
+
}
|
|
959
|
+
// The first of each role on each side, and what it holds, compared on
|
|
960
|
+
// every style and on height: never on text, width or where it sits.
|
|
961
|
+
const fw = firstOfRoles(allWant);
|
|
962
|
+
const fg = firstOfRoles(allGot);
|
|
963
|
+
for (const [k, w] of fw) {
|
|
964
|
+
const g = fg.get(k);
|
|
965
|
+
if (!g) continue;
|
|
966
|
+
if (Math.abs(g.box.h - w.box.h) > tol)
|
|
967
|
+
add(w, "box.height", w.box.h, g.box.h);
|
|
968
|
+
styles(w, g, []);
|
|
969
|
+
}
|
|
970
|
+
// Name over @login is taller than @login alone: an entry with another
|
|
971
|
+
// line count than the reference's (both the kit's shapes) moves nothing
|
|
972
|
+
// else's place; its own height and what it centres are its data.
|
|
973
|
+
const acct = actual.elements.find((e) => e.account);
|
|
974
|
+
const acctRef = acct && reference.elements.find((e) => e.key === acct.key);
|
|
975
|
+
if (acct && acctRef && (acct.lines ?? 0) !== (acctRef.lines ?? 0)) {
|
|
976
|
+
const own = (k) => k === acct.key || k.startsWith(acct.key + " >");
|
|
977
|
+
const tall = /^(box\.(height|top|bottom)|style\.height)$/;
|
|
978
|
+
return diffs.filter((d) => !(own(d.key) && tall.test(d.property)));
|
|
979
|
+
}
|
|
980
|
+
return diffs;
|
|
981
|
+
function styles(w, g, skip) {
|
|
568
982
|
for (const p of STYLE_PROPS) {
|
|
983
|
+
if (skip.includes(p)) continue;
|
|
569
984
|
const rv = w.style[p];
|
|
570
985
|
const av = g.style[p];
|
|
571
986
|
if (rv === av) continue;
|
|
@@ -577,7 +992,6 @@ export function compareNav(actual, reference, opts = {}) {
|
|
|
577
992
|
add(w, `style.${p}`, rv, av);
|
|
578
993
|
}
|
|
579
994
|
}
|
|
580
|
-
return diffs;
|
|
581
995
|
}
|
|
582
996
|
|
|
583
997
|
/** The differences, one per line: "top #den-search style.font-weight: 500 → 700". */
|
|
@@ -588,3 +1002,69 @@ export function formatNavDiffs(diffs) {
|
|
|
588
1002
|
)
|
|
589
1003
|
.join("\n");
|
|
590
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// ── The font pin ─────────────────────────────────────────────────────────
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* The system faces a nav names, pinned to the kit's own font files, so
|
|
1010
|
+
* text lays out alike on every machine: the sans faces to Rubik (400 up
|
|
1011
|
+
* to 449, 500 from 450), the mono ones to Space Mono. The reference was
|
|
1012
|
+
* taken with this pin.
|
|
1013
|
+
*/
|
|
1014
|
+
const PIN_SANS = [
|
|
1015
|
+
"-apple-system",
|
|
1016
|
+
"BlinkMacSystemFont",
|
|
1017
|
+
"Segoe UI",
|
|
1018
|
+
"Noto Sans",
|
|
1019
|
+
"Hiragino Sans",
|
|
1020
|
+
"Noto Sans JP",
|
|
1021
|
+
"Helvetica",
|
|
1022
|
+
"Arial",
|
|
1023
|
+
"Times New Roman",
|
|
1024
|
+
];
|
|
1025
|
+
const PIN_MONO = ["ui-monospace", "SFMono-Regular", "Menlo", "Consolas"];
|
|
1026
|
+
export const PIN_FONTS_CSS = [
|
|
1027
|
+
...PIN_SANS.flatMap((f) => [
|
|
1028
|
+
`@font-face{font-family:"${f}";font-weight:100 449;src:url(/__pin-fonts/rubik-latin-400-normal.woff2) format("woff2")}`,
|
|
1029
|
+
`@font-face{font-family:"${f}";font-weight:450 900;src:url(/__pin-fonts/rubik-latin-500-normal.woff2) format("woff2")}`,
|
|
1030
|
+
]),
|
|
1031
|
+
...PIN_MONO.map(
|
|
1032
|
+
(f) =>
|
|
1033
|
+
`@font-face{font-family:"${f}";src:url(/__pin-fonts/space-mono-latin-400-normal.woff2) format("woff2")}`,
|
|
1034
|
+
),
|
|
1035
|
+
].join("\n");
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Pins a Playwright BrowserContext's fonts for the inventory (call it
|
|
1039
|
+
* before the context opens a page): every page gets the pin stylesheet
|
|
1040
|
+
* first in its <head>, and /__pin-fonts/* answers with the kit's own woff2
|
|
1041
|
+
* files. `opts.fontsDir`: where they are, if not this package's.
|
|
1042
|
+
*/
|
|
1043
|
+
export async function pinNavFonts(context, opts = {}) {
|
|
1044
|
+
const dir = opts.fontsDir || FONTS_DIR;
|
|
1045
|
+
await context.route("**/__pin-fonts/**", (route) => {
|
|
1046
|
+
const name = decodeURIComponent(
|
|
1047
|
+
new URL(route.request().url()).pathname.split("/").pop() || "",
|
|
1048
|
+
);
|
|
1049
|
+
if (name === "pin.css")
|
|
1050
|
+
return route.fulfill({ contentType: "text/css", body: PIN_FONTS_CSS });
|
|
1051
|
+
// Only a font file of the kit's: no path in the name.
|
|
1052
|
+
const file = path.join(dir, path.basename(name));
|
|
1053
|
+
if (!/^[\w.-]+\.woff2$/.test(name) || !existsSync(file))
|
|
1054
|
+
return route.fulfill({ status: 404, body: "" });
|
|
1055
|
+
return route.fulfill({
|
|
1056
|
+
contentType: "font/woff2",
|
|
1057
|
+
body: readFileSync(file),
|
|
1058
|
+
});
|
|
1059
|
+
});
|
|
1060
|
+
await context.addInitScript(() => {
|
|
1061
|
+
const add = () => {
|
|
1062
|
+
const l = document.createElement("link");
|
|
1063
|
+
l.rel = "stylesheet";
|
|
1064
|
+
l.href = "/__pin-fonts/pin.css";
|
|
1065
|
+
document.head.prepend(l);
|
|
1066
|
+
};
|
|
1067
|
+
if (document.head) add();
|
|
1068
|
+
else document.addEventListener("DOMContentLoaded", add);
|
|
1069
|
+
});
|
|
1070
|
+
}
|