oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// Roster alignment, measured in the page. Called as (phase, phone) and
2// returns the failures as text ("" when aligned). Phases: "compact" (a
3// report whose decision card follows it) and "full" (that card set aside).
4// The Chromium and WebKit tests both evaluate this file.
5(phase, phone) => {
6 const bad = [], q = (s, r = document) => r.querySelector(s), all = (s, r = document) => [...r.querySelectorAll(s)];
7 const box = e => e.getBoundingClientRect(), near = (a, b, t = 1) => Math.abs(a - b) <= t;
8 const report = q("[equipo-roster-report]"), flat = report.closest("[equipo-roster-card]");
9 const inner = e => { const b = box(e), s = getComputedStyle(e); return { left: b.left + parseFloat(s.paddingLeft), right: b.right - parseFloat(s.paddingRight) }; };
10 const fs = getComputedStyle(flat);
11 if (parseFloat(fs.borderTopWidth) || parseFloat(fs.borderLeftWidth) || fs.backgroundColor !== "rgba(0, 0, 0, 0)" || fs.boxShadow !== "none") bad.push("a report is still a card");
12 if (parseFloat(getComputedStyle(flat, "::before").width) > 2) bad.push("the report rail is not a hairline");
13 const gaps = all("[equipo-roster-byline]").map(b => box(b.nextElementSibling).top - Math.max(box(b).bottom, box(q("[equipo-roster-avatar]", b)).bottom));
14 if (gaps.some(g => !near(g, 8))) bad.push("byline to content gap is not 8px: " + gaps.map(Math.round));
15 const ask = q("[equipo-roster-card][data-ask]");
16 if (ask && phone) {
17 const mark = q("[equipo-roster-avatar]", ask.previousElementSibling), edge = box(mark.matches("[equipo-coordinator-mark]") ? q("svg", mark) : mark).left;
18 if (!near(edge, box(ask).left)) bad.push(`byline mark at ${edge}, card at ${box(ask).left}`);
19 }
20 const pads = all("[equipo-roster-card][data-ask]").map(c => getComputedStyle(c)).map(s => [s.paddingTop, s.paddingRight, s.paddingBottom, s.paddingLeft].join(" "));
21 if (new Set(pads).size > 1 || pads.some(p => new Set(p.split(" ")).size > 1)) bad.push("raised cards use uneven padding: " + pads.join(" | "));
22 const pill = q("[data-question-thread] [equipo-mini-pill]"), main = q("#composer [equipo-pill]");
23 if (pill) {
24 const p = box(pill), s = box(q("button", pill)), x = q("[equipo-set-aside] button", pill.closest("[equipo-roster-card]"));
25 if (!near((s.top + s.bottom) / 2, (p.top + p.bottom) / 2)) bad.push(`send sits ${(s.top + s.bottom - p.top - p.bottom) / 2}px off the pill's centre`);
26 if (!near(p.bottom - s.bottom, p.right - s.right)) bad.push("send is not inset evenly in the pill");
27 if (main && !near(p.height, box(main).height)) bad.push(`card pill is ${p.height}px, the composer's ${box(main).height}px`);
28 const range = document.createRange(); range.selectNodeContents(q("[data-first] [equipo-thread-text]", pill.closest("[equipo-roster-card]")));
29 const line = range.getClientRects()[0], xb = box(x);
30 if (!near((xb.top + xb.bottom) / 2, (line.top + line.bottom) / 2, 2)) bad.push(`set aside is ${(xb.top + xb.bottom - line.top - line.bottom) / 2}px off the first line`);
31 }
32 if (phase === "compact") {
33 if (!report.hasAttribute("data-compact") || q("[data-track], [equipo-roster-facts], [equipo-roster-links] [rst-btn='primary']", report)) bad.push("a report beside its decision is not compact");
34 if (all("[equipo-needs-chip]", flat.closest("[data-card]").parentElement).length !== 1) bad.push("Needs you is not said exactly once");
35 } else {
36 const track = q("[data-track]", report), dots = all("[equipo-dot]", track), content = inner(report);
37 if (!near(box(dots[0]).left, content.left) || !near(box(dots.at(-1)).right, content.right)) bad.push(`track ${box(dots[0]).left}..${box(dots.at(-1)).right} does not span ${content.left}..${content.right}`);
38 const steps = dots.slice(1).map((d, i) => box(d).left - box(dots[i]).left);
39 if (steps.some(s => !near(s, steps[0]))) bad.push("track dots are uneven: " + steps.map(Math.round));
40 const now = q("[aria-current]", track), i = [...track.children].indexOf(now);
41 if (i > 0 && i < dots.length - 1) {
42 const range = document.createRange(); range.selectNodeContents(now.querySelector("span:not([equipo-dot])"));
43 const l = box(range), d = box(dots[i]);
44 if (!near((l.left + l.right) / 2, (d.left + d.right) / 2)) bad.push(`stage label is ${(l.left + l.right - d.left - d.right) / 2}px off its dot`);
45 }
46 const head = q("[equipo-roster-report-head]", report), stage = q("[equipo-roster-stage]", head), chip = q("[equipo-needs-chip]", head);
47 if (box(stage).height > 1.6 * parseFloat(getComputedStyle(stage).fontSize)) bad.push("the eyebrow wraps");
48 if (chip && !near((box(stage).top + box(stage).bottom) / 2, (box(chip).top + box(chip).bottom) / 2, 2)) bad.push("eyebrow and chip are not on one line");
49 const links = all("[equipo-roster-links] > a", report), mids = links.map(a => Math.round((box(a).top + box(a).bottom) / 2));
50 if (!phone && new Set(mids).size > 1) bad.push("report actions are not one row");
51 }
52 const scroll = q("[equipo-scroll]"); scroll.scrollTop = scroll.scrollHeight;
53 const last = all("[equipo-feed] > li").filter(e => box(e).height > 0).at(-1), clear = box(q("#chat-composer")).top - box(last).bottom;
54 if (clear < 16) bad.push(`the last item ends ${clear}px above the composer`);
55 return bad.join("; ");
56}
57