From fbb0c3783646918e7c64df9a77cdca5e6af70e04 Mon Sep 17 00:00:00 2001 From: adamXbot <111877622+adamXbot@users.noreply.github.com> Date: Sat, 31 Oct 2026 23:50:28 +1100 Subject: [PATCH 1/2] Drop the logo to print the fxcss pick report Releasing a dragged logo over an element now picks it, as a click does in `fxcss pick`. A card beside the element prints the CLI's report for the live page: tag and selector, classes with the site's own first, box, notable computed styles, and the matching rules, with rules naming one of its classes first and Tailwind's layered rules marked by layer. It copies the selector and links to the `fxcss pick` documentation. It is a non-modal dialog that takes focus; Escape or its close button returns focus to the logo, and a press elsewhere, a new drag or leaving the page closes it. The logo now lifts only once the pointer leaves it, so a shaky click still goes home. Carrying it back onto itself, releasing outside the page or pressing Escape picks nothing and follows nothing. Each time-machine stop gets its own terminal: an MS-DOS Prompt in 1999, Terminal on Mac OS X in 2003 and an xterm in 2002, with contrast checked for every colour pair. `allowImportingTsExtensions` lets `lib/pick-report.ts` import `./logo-picker.ts`, which Node's test runner needs. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +- app/components/brand-link.tsx | 105 +++++++++------ app/components/pick-card.tsx | 152 +++++++++++++++++++++ app/easter-eggs.css | 68 ++++++++++ lib/logo-picker.ts | 77 ++++++++--- lib/pick-report.ts | 213 ++++++++++++++++++++++++++++++ tests/browser/logo-picker.spec.ts | 153 ++++++++++++++++++++- tests/easter-eggs.test.mjs | 84 +++++++++++- tsconfig.json | 1 + 9 files changed, 797 insertions(+), 60 deletions(-) create mode 100644 app/components/pick-card.tsx create mode 100644 lib/pick-report.ts diff --git a/README.md b/README.md index 423ccc9..0f7c6d3 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ just verify vinext 1.0.1 includes `@vercel/og` 1.0.3 with the Satori SVG-escaping fix and the framework's HarfBuzz runtime support. The `satori` override pins `fflate` 0.7.5 to fix its ZIP64 parsing advisory while Satori pins 0.7.3; remove that override once Satori uses a patched release. The lockfile also keeps `@hono/node-server` and `systeminformation` on patched versions within their existing dependency ranges. -The Website GitHub Actions workflow (`.github/workflows/website.yml`) runs the same checks, plus a deploy dry run, on every pull request and push to `website`, without deploying. Pull requests stacked on `fix/website-*` branches also run these checks. A second job warns when the recorded documentation is behind `main`. The production check visits every documentation page, validates asset responses and the security headers on pages, redirects and static files, checks raw-head metadata and share cards, checks that each labelled control's name contains its visible text, and verifies not-found responses and redirects. On Node 24, CI also runs the Playwright Chromium and Firefox suite (`npm run test:browser`) against the built Worker. It covers journey selection, game completion, search loading and recovery, route announcements, code copying, keyboard-operated comparison controls, catalogue toggles, mobile Escape handling, logo picking, sidebar search sizing and scrolling, narrow layouts, and the reported catalogue and retro contrast regressions. The main checks also run on the declared minimum Node 22.18.0. For local browser checks, run `npx playwright install chromium firefox`, `npm run build`, then `npm run test:browser`; Playwright starts and stops its own local Worker and blocks outside requests. These checks do not replace testing with screen readers or native browser zoom. +The Website GitHub Actions workflow (`.github/workflows/website.yml`) runs the same checks, plus a deploy dry run, on every pull request and push to `website`, without deploying. Pull requests stacked on `fix/website-*` branches also run these checks. A second job warns when the recorded documentation is behind `main`. The production check visits every documentation page, validates asset responses and the security headers on pages, redirects and static files, checks raw-head metadata and share cards, checks that each labelled control's name contains its visible text, and verifies not-found responses and redirects. On Node 24, CI also runs the Playwright Chromium and Firefox suite (`npm run test:browser`) against the built Worker. It covers journey selection, game completion, search loading and recovery, route announcements, code copying, keyboard-operated comparison controls, catalogue toggles, mobile Escape handling, logo picking and its report card, sidebar search sizing and scrolling, narrow layouts, and the reported catalogue and retro contrast regressions. The main checks also run on the declared minimum Node 22.18.0. For local browser checks, run `npx playwright install chromium firefox`, `npm run build`, then `npm run test:browser`; Playwright starts and stops its own local Worker and blocks outside requests. These checks do not replace testing with screen readers or native browser zoom. To run only Firefox, use `npm run test:browser -- --project=firefox`. If the bundled Firefox fails to start on macOS 27 with “Could not find profile folder”, give the test browser separate application data directories ([upstream issue](https://github.com/microsoft/playwright/issues/42768)): @@ -97,7 +97,7 @@ The root layout loads Simple Analytics for page views. A delegated click listene - `/important` is a seven-round specificity boss battle with hints, explanations, actual isolated CSS previews, scoring and replay. A quiet `{ !important }` footer link and an exact `!important` search lead to it. The examples cover matching, unlayered author declarations; the page links to MDN for the wider cascade and stays out of the sitemap. - Search `c0ffee` or `#c0ffee` for a short, replayable coffee party. The non-modal message can be dismissed, and reduced-motion visitors get a still celebration. Ordinary search results remain available. - The favicon sleeps when the tab is hidden and restores the original icons on return, including icons replaced during navigation. It uses a local SVG. -- Drag the fxcss logo in the header or footer and it becomes `fxcss pick` for the site: whatever it is over gets the picker's pink outline, with the element's classes labelled underneath (above, near the bottom of the window). It labels the nearest element that has a class. When some of an element's classes come from the site's own stylesheet rather than Tailwind's utility layer, only those are shown; utility-only lists are shortened. Release, or press Escape, and the logo returns; reduced-motion visitors skip the flight. Dropping it activates nothing, and a click without a drag still goes home. Mouse and pen only, so touch scrolling and taps behave as before. +- Drag the fxcss logo in the header or footer out past its edge and it becomes `fxcss pick` for the site. Until the pointer leaves the logo the press stays a click, however much it wobbles, so a shaky click still goes home. Once lifted, whatever it is over gets the picker's pink outline, with the element's classes labelled underneath (above, near the bottom of the window). It labels the nearest element that has a class. When some of an element's classes come from the site's own stylesheet rather than Tailwind's utility layer, only those are shown; utility-only lists are shortened. Release it over an element to pick it, as a click does in `fxcss pick`: a terminal-style card beside the element prints the CLI's report for it, with its tag and selector, classes (the site's own first), box, notable computed styles and the rules on the site that match it, with rules naming one of its classes listed first and Tailwind's layered rules marked by layer. The card copies the selector and links to the `fxcss pick` documentation. It looks like the terminal of the current time-machine stop: an MS-DOS Prompt in 1999, Terminal on Mac OS X in 2003, and an xterm in 2002. The report itself follows the page, so it lists the time machine's `html[data-retro]` rules when they apply. It is a non-modal dialog that takes focus; Escape or its close button returns focus to the logo, and a press elsewhere or leaving the page closes it. Carry the logo back onto itself, release it outside the page, or press Escape during the drag, and nothing is picked or followed. Either way the logo returns; reduced-motion visitors skip the flight and the card's fade. Dropping it activates nothing underneath, and a click without a drag still goes home. Mouse and pen only, so touch scrolling and taps behave as before. ## Screenshot evidence diff --git a/app/components/brand-link.tsx b/app/components/brand-link.tsx index 8b2f30d..657b85a 100644 --- a/app/components/brand-link.tsx +++ b/app/components/brand-link.tsx @@ -1,14 +1,28 @@ 'use client'; import Link from 'next/link'; +import { usePathname } from 'next/navigation'; import { useEffect, useRef, useState, type ReactNode } from 'react'; import { followLogoPress } from '../../lib/logo-picker'; +import { pickReport, type PickReport } from '../../lib/pick-report'; +import { PickCard } from './pick-card'; export function BrandLink({ children }: { children: ReactNode }) { // Keep an active turn latched when pointer or keyboard focus leaves. const [spinning, setSpinning] = useState(false); // Ends a logo drag that outlives the link, such as across navigation. const stopPicking = useRef<() => void>(undefined); + const link = useRef(null); + // The element a dropped logo picked, reported as `fxcss pick` would. + const [picked, setPicked] = useState<{ + element: Element; + report: PickReport; + /** A report describes one page, so it closes when the page changes. */ + pathname: string; + }>(); + const pathname = usePathname(); + // Leaving the page drops its report, so coming back does not revive it. + if (picked && picked.pathname !== pathname) setPicked(undefined); useEffect(() => { const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); @@ -31,43 +45,60 @@ export function BrandLink({ children }: { children: ReactNode }) { setSpinning(true); } + // The card is the link's sibling, not its child: React events bubble + // through portals, and the link would treat a press on the card as its own. return ( - { - if (event.pointerType !== 'touch') startSpin(); - }} - onPointerDown={(event) => { - // Mouse and pen can pick up the mark. Touch keeps scrolling and - // tapping, and modified clicks keep opening new tabs and windows. - if ( - event.pointerType === 'touch' || - !event.isPrimary || - event.button !== 0 || - event.metaKey || - event.ctrlKey || - event.shiftKey || - event.altKey - ) - return; - stopPicking.current?.(); - stopPicking.current = followLogoPress( - event.currentTarget, - event.nativeEvent, - ); - }} - onFocus={(event) => { - if (event.currentTarget.matches(':focus-visible')) startSpin(); - }} - onAnimationEnd={(event) => { - if (event.animationName === 'fxcss-flame-spin') setSpinning(false); - }} - > - {children} - + <> + { + if (event.pointerType !== 'touch') startSpin(); + }} + onPointerDown={(event) => { + // Mouse and pen can pick up the mark. Touch keeps scrolling and + // tapping, and modified clicks keep opening new tabs and windows. + if ( + event.pointerType === 'touch' || + !event.isPrimary || + event.button !== 0 || + event.metaKey || + event.ctrlKey || + event.shiftKey || + event.altKey + ) + return; + stopPicking.current?.(); + stopPicking.current = followLogoPress( + event.currentTarget, + event.nativeEvent, + (element) => + setPicked({ element, report: pickReport(element), pathname }), + ); + }} + onFocus={(event) => { + if (event.currentTarget.matches(':focus-visible')) startSpin(); + }} + onAnimationEnd={(event) => { + if (event.animationName === 'fxcss-flame-spin') setSpinning(false); + }} + > + {children} + + {picked && ( + { + setPicked(undefined); + if (restoreFocus) link.current?.focus({ preventScroll: true }); + }} + /> + )} + ); } diff --git a/app/components/pick-card.tsx b/app/components/pick-card.tsx new file mode 100644 index 0000000..6bc7321 --- /dev/null +++ b/app/components/pick-card.tsx @@ -0,0 +1,152 @@ +'use client'; + +import Link from 'next/link'; +import { + useEffect, + useEffectEvent, + useId, + useLayoutEffect, + useRef, + useState, +} from 'react'; +import { createPortal } from 'react-dom'; +import { Check, Copy, X } from 'lucide-react'; +import { labelPosition } from '../../lib/logo-picker'; +import { reportLines, type PickReport } from '../../lib/pick-report'; + +/** + * What a dropped logo picked, printed the way `fxcss pick` prints a click. + * A non-modal dialog beside the element: Escape, the close button, a press + * anywhere else or leaving the page closes it. + */ +export function PickCard({ + element, + report, + onClose, +}: { + element: Element; + report: PickReport; + /** `true` when focus should go back to the logo. */ + onClose: (restoreFocus: boolean) => void; +}) { + const card = useRef(null); + const heading = useId(); + const [status, setStatus] = useState(''); + const statusTimer = useRef>(undefined); + const close = useEffectEvent(onClose); + const [header, ...details] = reportLines(report); + + // Beside the element, as the label was, and still beside it after scrolling. + useLayoutEffect(() => { + const node = card.current!; + const view = node.ownerDocument.defaultView!; + const root = node.ownerDocument.documentElement; + let frame = 0; + function place() { + frame = 0; + if (!element.isConnected) return close(false); + const { left, top } = labelPosition( + element.getBoundingClientRect(), + { width: node.offsetWidth, height: node.offsetHeight }, + { width: root.clientWidth, height: root.clientHeight }, + 6, + 8, + ); + node.style.translate = `${left}px ${top}px`; + } + function schedule() { + frame ||= view.requestAnimationFrame(place); + } + place(); + node.focus({ preventScroll: true }); + view.addEventListener('scroll', schedule, { capture: true, passive: true }); + view.addEventListener('resize', schedule); + return () => { + view.cancelAnimationFrame(frame); + view.removeEventListener('scroll', schedule, { capture: true }); + view.removeEventListener('resize', schedule); + }; + }, [element]); + + useEffect(() => { + const node = card.current!; + const doc = node.ownerDocument; + function pressElsewhere(event: PointerEvent) { + if (!node.contains(event.target as Node)) close(false); + } + // Only while focus is in the card; search and the time machine keep theirs. + function escape(event: KeyboardEvent) { + if (event.key !== 'Escape') return; + event.preventDefault(); + event.stopPropagation(); + close(true); + } + doc.addEventListener('pointerdown', pressElsewhere, true); + node.addEventListener('keydown', escape); + return () => { + doc.removeEventListener('pointerdown', pressElsewhere, true); + node.removeEventListener('keydown', escape); + clearTimeout(statusTimer.current); + }; + }, []); + + async function copy() { + try { + await navigator.clipboard.writeText(report.selector); + setStatus('Copied'); + } catch { + setStatus('Select the selector and copy it manually.'); + } + clearTimeout(statusTimer.current); + statusTimer.current = setTimeout(() => setStatus(''), 3000); + } + + return createPortal( + // Open without showModal: the rest of the page stays usable. + +
+ + {/* The prompt changes with the time machine: $, C:\> or %. */} + + +
+
+        {/* One block per line, so a wrapped rule hangs under its own start. */}
+        {header}
+        {details.map((line, index) => (
+          {line}
+        ))}
+      
+
+ + onClose(false)}> + Pick Firefox’s UI with fxcss pick + + {status} +
+
, + element.ownerDocument.body, + ); +} diff --git a/app/easter-eggs.css b/app/easter-eggs.css index 3042bca..ff5a978 100644 --- a/app/easter-eggs.css +++ b/app/easter-eggs.css @@ -136,6 +136,74 @@ html[data-logo-picking], html[data-logo-picking] * { cursor: grabbing !important .logo-picker-ghost { animation: logo-picker-lift 140ms ease-out; } } @keyframes logo-picker-lift { from { scale: 1; } } +/* Dropping the logo prints what `fxcss pick` prints for a click, in a + terminal that keeps its colours in every theme and time-machine stop. */ +.pick-card { position: fixed; z-index: 1003; inset: 0 auto auto 0; margin: 0; padding: 0; width: min(440px, calc(100% - 16px)); max-height: calc(100dvh - 16px); display: flex; flex-direction: column; overflow: hidden; border: 1px solid #39425e; border-radius: 8px; box-shadow: 0 14px 44px #18213952; background: #121a2c; color: #dfe4f2; font: 12px/1.6 'SFMono-Regular', Consolas, 'Liberation Mono', monospace; text-align: left; } +.pick-card:focus { outline: none; } +.pick-card:focus-visible { outline: 2px solid #ff4fa7; outline-offset: 2px; } +.pick-card-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px 5px 12px; border-bottom: 1px solid #2b3350; background: #1b2440; color: #b4bdd6; } +.pick-card-close { display: grid; place-items: center; padding: 4px; border: 0; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; } +.pick-card-close:hover { background: #2b3556; color: #fff; } +.pick-card-report { min-height: 0; margin: 0; padding: 10px 12px; overflow: auto; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; } +.pick-card-report strong { color: #ff6fb5; font-weight: 700; } +.pick-card-report > * { display: block; padding-left: 4ch; text-indent: -4ch; } +.pick-card-prompt::before { content: '$ '; } +.pick-card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 8px 12px 10px; border-top: 1px solid #2b3350; } +.pick-card-actions button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid #ff4fa7; border-radius: 4px; background: #db0078; color: #fff; font: inherit; cursor: pointer; } +.pick-card-actions button:hover { background: #b80065; } +.pick-card-actions a { color: #9fc4ff; text-decoration: underline; text-underline-offset: 3px; } +.pick-card-actions a:hover { color: #c9ddff; } +.pick-card :is(button, a):focus-visible { outline: 2px solid #ff9ccc; outline-offset: 2px; } +.pick-card-status { color: #9be7c4; } +@media (prefers-reduced-motion: no-preference) { + .pick-card { animation: pick-card-open 140ms ease-out; } +} +@keyframes pick-card-open { from { opacity: 0; scale: 0.97; } } +/* Each time-machine stop gets the terminal it would have had: an MS-DOS + Prompt in 1999, Terminal on Mac OS X in 2003 and an xterm in 2002. The + pink header stays, as `fxcss pick` keeps its colours everywhere. */ +html[data-retro='windows'] .pick-card { padding: 2px; border: 2px outset #eee; border-radius: 0; box-shadow: 2px 2px 0 #0007; background: #c0c0c0; color: #111; font-family: 'Lucida Console', 'Courier New', monospace; } +html[data-retro='windows'] .pick-card-bar { padding: 2px 2px 2px 6px; border: 0; background: var(--retro-titlebar); color: #fff; font: 700 12px/1.6 Tahoma, Verdana, sans-serif; } +html[data-retro='windows'] .pick-card-prompt::before { content: 'C:\\> '; } +html[data-retro='windows'] .pick-card-close { padding: 0 1px; border: 2px outset #eee; border-radius: 0; background: #c0c0c0; color: #111; } +html[data-retro='windows'] .pick-card-close:active { border-style: inset; } +html[data-retro='windows'] .pick-card-report { margin: 2px 0; border: 2px inset #eee; background: #000; color: #c0c0c0; } +html[data-retro='windows'] .pick-card-report strong { color: #ff55ff; } +html[data-retro='windows'] .pick-card-actions { border: 0; padding: 6px 4px 4px; font-family: Tahoma, Verdana, sans-serif; } +html[data-retro='windows'] .pick-card-actions button { border: 2px outset #eee; border-radius: 0; background: #c0c0c0; color: #111; } +html[data-retro='windows'] .pick-card-actions button:active { border-style: inset; } +html[data-retro='windows'] .pick-card-actions a { color: #000080; } +html[data-retro='windows'] .pick-card-status { color: #111; } +html[data-retro='windows'] .pick-card :is(button, a):focus-visible { outline: 1px dotted #111; outline-offset: -4px; } +html[data-retro='windows'] .pick-card-actions a:focus-visible { outline-offset: 2px; } + +html[data-retro='mac'] .pick-card { border: 1px solid #8d8d8d; border-radius: 6px; box-shadow: 0 12px 34px #0007; background: var(--retro-surface); color: #111; font-family: Monaco, Menlo, 'Courier New', monospace; } +html[data-retro='mac'] .pick-card-bar { position: relative; justify-content: center; padding: 4px 28px; border-bottom: 1px solid #9a9a9a; background: linear-gradient(#f1f1f1, #cfcfcf); color: #252525; font: 12px/1.6 'Lucida Grande', 'Lucida Sans Unicode', Arial, sans-serif; } +html[data-retro='mac'] .pick-card-prompt::before { content: '% '; } +html[data-retro='mac'] .pick-card-close { position: absolute; left: 8px; width: 14px; height: 14px; padding: 0; border: 1px solid #a9564b; border-radius: 50%; background: radial-gradient(circle at 35% 25%, #ffe4de, #ec6255 65%); color: #5c130c; } +html[data-retro='mac'] .pick-card-close svg { width: 9px; height: 9px; opacity: 0; } +html[data-retro='mac'] .pick-card-close:is(:hover, :focus-visible) svg { opacity: 1; } +html[data-retro='mac'] .pick-card-report { background: #fff; color: #111; } +html[data-retro='mac'] .pick-card-report strong { color: #b8005f; } +html[data-retro='mac'] .pick-card-actions { border-top-color: #c6c6c6; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, sans-serif; } +html[data-retro='mac'] .pick-card-actions button { padding: 3px 14px; border: 1px solid #3a6fb0; border-radius: 999px; background: linear-gradient(#d8ecff, #8cc2f8 50%, #6aaef5 50%, #b6dcff); color: #111; } +html[data-retro='mac'] .pick-card-actions button:hover { filter: brightness(1.05); } +html[data-retro='mac'] .pick-card-actions a { color: #17529c; } +html[data-retro='mac'] .pick-card-status { color: #1d6131; } +html[data-retro='mac'] .pick-card :is(button, a):focus-visible { outline: 3px solid #2f6fc0; outline-offset: 1px; } + +html[data-retro='linux'] .pick-card { border: 1px solid #2c3a4c; border-radius: 0; box-shadow: 3px 3px 0 #0005; background: var(--retro-surface); color: #111; font-family: 'DejaVu Sans Mono', 'Liberation Mono', 'Courier New', monospace; } +html[data-retro='linux'] .pick-card-bar { padding: 3px 3px 3px 8px; border: 0; background: var(--retro-titlebar); color: #fff; font: 700 12px/1.6 'DejaVu Sans', 'Liberation Sans', Arial, sans-serif; } +html[data-retro='linux'] .pick-card-close { border: 1px solid #2c3a4c; border-radius: 2px; background: #dedcd4; color: #111; } +html[data-retro='linux'] .pick-card-close:hover { background: #fff; color: #111; } +html[data-retro='linux'] .pick-card-report { background: #000; color: #e5e5e5; } +html[data-retro='linux'] .pick-card-report strong { color: #ff55ff; } +html[data-retro='linux'] .pick-card-actions { border-top-color: #a9a69b; font-family: 'DejaVu Sans', 'Liberation Sans', Arial, sans-serif; } +html[data-retro='linux'] .pick-card-actions button { border: 1px solid #8a877d; border-radius: 3px; background: linear-gradient(#f4f3ef, #dedcd4); color: #111; } +html[data-retro='linux'] .pick-card-actions button:hover { background: #fff; } +html[data-retro='linux'] .pick-card-actions a { color: #334f75; } +html[data-retro='linux'] .pick-card-status { color: #1d5a2c; } +html[data-retro='linux'] .pick-card :is(button, a):focus-visible { outline: 2px solid #334f75; outline-offset: 2px; } /* The arena uses the site's purple, orange and monospace details. */ .battle-page { max-width: 960px; padding-top: 60px; padding-bottom: 100px; } diff --git a/lib/logo-picker.ts b/lib/logo-picker.ts index 6927f2d..a6be3fa 100644 --- a/lib/logo-picker.ts +++ b/lib/logo-picker.ts @@ -1,14 +1,38 @@ // Drag the fxcss mark across the site and it outlines the element underneath, // with its classes labelled below it: `fxcss pick` for the website itself. -/** Movement that turns a press into a drag; anything shorter stays a click. */ -export const PICK_DISTANCE = 4; +/** + * How far outside the logo the pointer must go before the mark lifts off. + * Until then a press is a click, however much it wobbles, so a shaky hand + * still goes home. + */ +export const CLICK_SLOP = 8; /** Longer class lists are shortened to this many classes and a count. */ const SHOWN_CLASSES = 3; type Box = { left: number; top: number; bottom: number }; + +/** Whether a point is on the box or within `slop` pixels of it. */ +export function nearBox( + box: Box & { right: number }, + x: number, + y: number, + slop = CLICK_SLOP, +) { + return ( + x >= box.left - slop && + x <= box.right + slop && + y >= box.top - slop && + y <= box.bottom + slop + ); +} type Size = { width: number; height: number }; -type Picker = { follow(x: number, y: number): void; land(fly: boolean): void }; +type Picker = { + follow(x: number, y: number): void; + land(fly: boolean): void; + /** What a release here picks: nothing over the logo or off the page. */ + pickAt(x: number, y: number): Element | null; +}; export function classesOf(element: Element) { return [ @@ -66,15 +90,16 @@ export function classLabel( classes: string[], authored: ReadonlySet, escape = (name: string) => CSS.escape(name), + limit = SHOWN_CLASSES, ) { const own = classes.filter((name) => authored.has(name)); const shown = own.length ? own : classes; const selector = shown - .slice(0, SHOWN_CLASSES) + .slice(0, limit) .map((name) => `.${escape(name)}`) .join(''); - return shown.length > SHOWN_CLASSES - ? `${selector} +${shown.length - SHOWN_CLASSES}` + return shown.length > limit + ? `${selector} +${shown.length - limit}` : selector; } @@ -107,13 +132,19 @@ export function labelPosition( } /** - * Follows a press on the logo. Past PICK_DISTANCE the mark lifts off and - * labels the classed element under the pointer; releasing flies it home, and - * Escape puts it back early. The click that ends a drag is swallowed, so + * Follows a press on the logo. Once the pointer leaves the logo by CLICK_SLOP + * the mark lifts off and labels the classed element under the pointer. + * Releasing over one picks it, as a click does in `fxcss pick`, and flies the + * logo home. Releasing back on the logo or outside the page, or pressing + * Escape, puts it back without picking. The click that ends a drag is swallowed, so * neither the logo nor whatever it was dropped on activates. Returns a * function that ends everything at once. */ -export function followLogoPress(link: HTMLElement, press: PointerEvent) { +export function followLogoPress( + link: HTMLElement, + press: PointerEvent, + onPick: (element: Element) => void = () => {}, +) { const home = link.querySelector('.brand-mark'); const view = link.ownerDocument.defaultView; if (!home || !view) return () => {}; @@ -121,6 +152,8 @@ export function followLogoPress(link: HTMLElement, press: PointerEvent) { const { signal } = listening; let picker: Picker | undefined; let held = true; + const overLogo = (x: number, y: number) => + nearBox(link.getBoundingClientRect(), x, y); function end(fly: boolean) { listening.abort(); @@ -134,12 +167,8 @@ export function followLogoPress(link: HTMLElement, press: PointerEvent) { 'pointermove', (event) => { if (event.pointerId !== press.pointerId || !held) return; - const moved = Math.hypot( - event.clientX - press.clientX, - event.clientY - press.clientY, - ); - if (!picker && moved < PICK_DISTANCE) return; - picker ??= liftMark(link, home); + if (!picker && overLogo(event.clientX, event.clientY)) return; + picker ??= liftMark(link, home, overLogo); picker.follow(event.clientX, event.clientY); }, { signal }, @@ -148,8 +177,10 @@ export function followLogoPress(link: HTMLElement, press: PointerEvent) { 'pointerup', (event) => { if (event.pointerId !== press.pointerId) return; + const picked = held ? picker?.pickAt(event.clientX, event.clientY) : null; end(true); if (picker) swallowClick(view); + if (picked) onPick(picked); }, { signal }, ); @@ -186,7 +217,11 @@ function swallowClick(view: Window) { view.setTimeout(() => view.removeEventListener('click', swallow, true)); } -function liftMark(link: HTMLElement, home: SVGSVGElement): Picker { +function liftMark( + link: HTMLElement, + home: SVGSVGElement, + overLogo: (x: number, y: number) => boolean, +): Picker { const doc = link.ownerDocument; const view = doc.defaultView!; const root = doc.documentElement; @@ -212,10 +247,15 @@ function liftMark(link: HTMLElement, home: SVGSVGElement): Picker { let flight: Animation | undefined; let landed = false; + function find(x: number, y: number) { + return overLogo(x, y) ? null : classedElement(doc.elementFromPoint(x, y)); + } + // Every frame, so scrolling and layout changes under a still pointer count. function draw() { ghost.style.translate = `${pointer.x - size.width / 2}px ${pointer.y - size.height / 2}px`; - const found = classedElement(doc.elementFromPoint(pointer.x, pointer.y)); + // Over the logo there is nothing to pick: dropping there puts it back. + const found = find(pointer.x, pointer.y); if (found !== target) { target = found; outline.hidden = label.hidden = !target; @@ -247,6 +287,7 @@ function liftMark(link: HTMLElement, home: SVGSVGElement): Picker { } return { + pickAt: find, follow(x, y) { pointer = { x, y }; if (!frame) draw(); diff --git a/lib/pick-report.ts b/lib/pick-report.ts new file mode 100644 index 0000000..359c2f6 --- /dev/null +++ b/lib/pick-report.ts @@ -0,0 +1,213 @@ +// What `fxcss pick` prints when you click an element, built from the website's +// own page: the selector, classes, box, notable styles and the rules that +// style it. + +import { authoredClasses, classesOf, classLabel } from './logo-picker.ts'; + +/** The properties `fxcss pick` reports, in its order. */ +export const REPORTED_STYLES = [ + 'background-color', + 'color', + 'border-radius', + 'box-shadow', + 'list-style-image', + 'font-size', + 'padding', + 'margin', + 'opacity', + 'height', + 'width', + 'display', +] as const; +/** Values `fxcss pick` leaves out, because they say nothing. */ +const UNREMARKABLE = new Set([ + 'none', + 'normal', + 'auto', + '0px', + 'rgba(0, 0, 0, 0)', + '1', +]); +/** `fxcss pick` lists this many rules, then counts the rest. */ +export const SHOWN_RULES = 8; +/** Tailwind components carry dozens of classes; the rest are counted. */ +export const SHOWN_CLASSES = 6; + +export type PickedRule = { selector: string; layer?: string }; +export type PickReport = { + tag: string; + /** Every class the label names, for copying. */ + selector: string; + /** The selector as the pink label shows it, shortened when long. */ + label: string; + /** The site's own classes first, then the rest in attribute order. */ + classes: string[]; + box: { x: number; y: number; width: number; height: number }; + styles: [property: string, value: string][]; + /** The site's own rules first, then Tailwind's layered ones. */ + rules: PickedRule[]; +}; + +type Sheet = { readonly cssRules: CSSRuleList }; +type Environment = { + matchMedia(query: string): { matches: boolean }; + supports(condition: string): boolean; + LayerBlock: typeof CSSLayerBlockRule; + MediaRule: typeof CSSMediaRule; + SupportsRule: typeof CSSSupportsRule; +}; + +/** + * Style rules whose selectors match the element right now, with the cascade + * layer each one sits in. Conditional groups count only when their condition + * holds; rules nested inside style rules and cross-origin sheets are skipped. + * + * Like `fxcss pick`, which lists the rules that name the element, rules naming + * one of its classes come first; then the site's own rules before Tailwind's + * layered ones, each in stylesheet order. + */ +export function matchingRules( + element: Pick, + sheets: Iterable, + environment: Environment, + classes: readonly string[] = [], +) { + const found: PickedRule[] = []; + function read(rules: Iterable, layer?: string) { + for (const rule of rules) { + if ('selectorText' in rule) { + const selector = String(rule.selectorText); + try { + if (element.matches(selector)) + found.push(layer ? { selector, layer } : { selector }); + } catch { + // A selector the engine cannot match against, such as a pseudo-element. + } + continue; + } + if (!('cssRules' in rule)) continue; + if (rule instanceof environment.LayerBlock) { + const name = rule.name || 'anonymous'; + read(rule.cssRules, layer ? `${layer}.${name}` : name); + continue; + } + if ( + rule instanceof environment.MediaRule && + !environment.matchMedia(rule.conditionText).matches + ) + continue; + if ( + rule instanceof environment.SupportsRule && + !environment.supports(rule.conditionText) + ) + continue; + read(rule.cssRules as CSSRuleList, layer); + } + } + for (const sheet of sheets) { + try { + read(sheet.cssRules); + } catch { + // A stylesheet from another origin keeps its rules private. + } + } + const names = new Set(classes); + const rank = (rule: PickedRule) => + (rule.layer ? 1 : 0) + + ([...rule.selector.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)].some(([, name]) => + names.has(name), + ) + ? 0 + : 2); + return found + .map((rule, order) => ({ rule, order, rank: rank(rule) })) + .sort((a, b) => a.rank - b.rank || a.order - b.order) + .map(({ rule }) => rule); +} + +export function reportedStyles(style: { + getPropertyValue(property: string): string; +}) { + return REPORTED_STYLES.flatMap((property) => { + const value = style.getPropertyValue(property); + return value && !UNREMARKABLE.has(value) + ? [[property, value] as [string, string]] + : []; + }); +} + +/** The report for one picked element of the live page. */ +export function pickReport(element: Element): PickReport { + const doc = element.ownerDocument; + const view = doc.defaultView!; + const authored = authoredClasses(doc.styleSheets); + const classes = classesOf(element); + const box = element.getBoundingClientRect(); + return { + tag: element.localName, + selector: classLabel(classes, authored, undefined, Infinity), + label: classLabel(classes, authored), + classes: [ + ...classes.filter((name) => authored.has(name)), + ...classes.filter((name) => !authored.has(name)), + ], + box: { + x: Math.round(box.x), + y: Math.round(box.y), + width: Math.round(box.width), + height: Math.round(box.height), + }, + styles: reportedStyles(view.getComputedStyle(element)), + rules: matchingRules( + element, + doc.styleSheets, + { + matchMedia: (query) => view.matchMedia(query), + supports: (condition) => CSS.supports(condition), + LayerBlock: CSSLayerBlockRule, + MediaRule: CSSMediaRule, + SupportsRule: CSSSupportsRule, + }, + classes, + ), + }; +} + +/** The report as `fxcss pick` would print it in a terminal. */ +export function reportLines(report: PickReport) { + const { box, rules } = report; + const lines = [`${report.tag} → ${report.label}`]; + const { classes } = report; + if (classes.length) + lines.push( + `classes ${classes.slice(0, SHOWN_CLASSES).join(' ')}` + + (classes.length > SHOWN_CLASSES + ? ` +${classes.length - SHOWN_CLASSES} more` + : ''), + ); + lines.push( + `box ${box.width}×${box.height} at (${box.x}, ${box.y})` + + (box.width && box.height ? '' : ' (not visible in this layout)'), + ); + if (report.styles.length) { + lines.push('styles'); + for (const [property, value] of report.styles) + lines.push(` ${property}: ${value}`); + } + if (!rules.length) { + lines.push('styled by no rules on this site (browser defaults only)'); + return lines; + } + lines.push( + `styled by ${rules.length} rule${rules.length === 1 ? '' : 's'} on this site`, + ); + for (const rule of rules.slice(0, SHOWN_RULES)) + lines.push( + rule.layer + ? ` @layer ${rule.layer} ${rule.selector}` + : ` ${rule.selector}`, + ); + if (rules.length > SHOWN_RULES) + lines.push(` … and ${rules.length - SHOWN_RULES} more`); + return lines; +} diff --git a/tests/browser/logo-picker.spec.ts b/tests/browser/logo-picker.spec.ts index 88f793e..a24d312 100644 --- a/tests/browser/logo-picker.spec.ts +++ b/tests/browser/logo-picker.spec.ts @@ -80,6 +80,9 @@ test('a dropped logo follows no link, and Escape puts it back without leaving th ); await page.keyboard.press('Escape'); await expect(pickerParts(page)).toHaveCount(0); + await expect(page.locator('.pick-card'), 'Escape picks nothing').toHaveCount( + 0, + ); await expect(page.locator('html')).toHaveAttribute('data-retro', 'windows'); // The press continues without the logo and ends without a click. const home = await centre(page.locator('.site-header .brand-mark')); @@ -89,17 +92,39 @@ test('a dropped logo follows no link, and Escape puts it back without leaving th await expect(page).toHaveURL(/\/docs\/watch$/); }); -test('a click that wobbles less than the drag distance still goes home', async ({ +test('a shaky click that stays on the logo still goes home', async ({ page, }) => { await page.goto('/docs/watch'); const start = await centre(page.locator('.site-header .brand-mark')); await page.mouse.move(start.x, start.y); await page.mouse.down(); - await page.mouse.move(start.x + 2, start.y + 1); + // Well past a drag threshold, but still on the logo and its wordmark. + await page.mouse.move(start.x + 30, start.y + 6, { steps: 5 }); + await expect(pickerParts(page), 'the mark stays put').toHaveCount(0); + await page.mouse.move(start.x - 4, start.y - 3, { steps: 3 }); await page.mouse.up(); await expect(page).toHaveURL('/'); await expect(pickerParts(page)).toHaveCount(0); + await expect(page.locator('.pick-card')).toHaveCount(0); +}); + +test('carrying the logo back home puts it down without picking or following it', async ({ + page, +}) => { + await page.goto('/docs/watch'); + await dragLogoTo(page, page.locator('.site-header .github-link')); + await expect(page.locator('.logo-picker-label')).toHaveText('.github-link'); + const home = await centre(page.locator('.site-header .brand-mark')); + await page.mouse.move(home.x + 3, home.y + 2, { steps: 10 }); + await expect( + page.locator('.logo-picker-outline'), + 'nothing is outlined over the logo', + ).toBeHidden(); + await page.mouse.up(); + await expect(pickerParts(page)).toHaveCount(0); + await expect(page.locator('.pick-card')).toHaveCount(0); + await expect(page).toHaveURL(/\/docs\/watch$/); }); test('a Tailwind component is named by the site’s own class', async ({ @@ -118,3 +143,127 @@ test('a Tailwind component is named by the site’s own class', async ({ await page.mouse.up(); await expect(pickerParts(page)).toHaveCount(0); }); + +test('dropping the logo prints the fxcss pick report and copies the selector', async ({ + page, +}) => { + await page.addInitScript(() => { + const copied: string[] = []; + Object.assign(window, { copied }); + Object.defineProperty(navigator, 'clipboard', { + value: { writeText: async (text: string) => void copied.push(text) }, + }); + }); + await page.goto('/docs/watch'); + const github = page.locator('.site-header .github-link'); + await dragLogoTo(page, github); + await page.mouse.up(); + + const card = page.getByRole('dialog', { name: 'fxcss pick' }); + await expect(card).toBeVisible(); + await expect(card).toBeFocused(); + const report = card.locator('.pick-card-report'); + await expect(report.locator('strong')).toHaveText('a → .github-link'); + const line = (text: RegExp) => + report.locator(':scope > span').filter({ hasText: text }); + await expect(line(/^classes {3}.*github-link/)).toHaveCount(1); + const box = (await github.boundingBox())!; + await expect( + line( + new RegExp( + `^box {7}${Math.round(box.width)}×${Math.round(box.height)} at \\(${Math.round(box.x)}, ${Math.round(box.y)}\\)$`, + ), + ), + ).toHaveCount(1); + await expect(line(/^ {2}color: rgb/)).toHaveCount(1); + const styledBy = line(/^styled by \d+ rules? on this site$/); + await expect(styledBy).toHaveCount(1); + // Rules naming the element's class come first. + await expect(styledBy.locator('xpath=following-sibling::span[1]')).toHaveText( + /^ {2}.*\.github-link/, + ); + const cardBox = (await card.boundingBox())!; + expect(cardBox.y, 'the card sits beside the element').toBeGreaterThanOrEqual( + box.y + box.height, + ); + + await card.getByRole('button', { name: 'Copy selector' }).click(); + await expect(card.locator('.pick-card-status')).toHaveText('Copied'); + expect( + await page.evaluate( + () => (window as unknown as { copied: string[] }).copied, + ), + ).toEqual(['.github-link']); + await expect(page).toHaveURL(/\/docs\/watch$/); + + await page.keyboard.press('Escape'); + await expect(card).toHaveCount(0); + await expect(page.locator('.site-header .brand')).toBeFocused(); + await expect(page).toHaveURL(/\/docs\/watch$/); +}); + +test('the pick card closes on a press elsewhere, a new drag, and its docs link', async ({ + page, +}) => { + await page.goto('/docs/watch'); + const card = page.locator('.pick-card'); + await dragLogoTo(page, page.locator('.site-header .header-install')); + await page.mouse.up(); + await expect(card.locator('strong')).toHaveText(/→ {2}\.header-install$/); + // A press beside the card closes it and activates nothing else. + const heading = (await page.locator('h1').boundingBox())!; + await page.mouse.click(heading.x + 2, heading.y + 2); + await expect(card).toHaveCount(0); + + await dragLogoTo(page, page.locator('.site-header .github-link')); + await page.mouse.up(); + await expect(card).toHaveCount(1); + // Picking up the logo again replaces the card rather than adding another. + await dragLogoTo(page, page.locator('.site-header .header-install')); + await expect(card).toHaveCount(0); + await page.mouse.up(); + await expect(card.locator('strong')).toHaveText(/→ {2}\.header-install$/); + + await card.getByRole('link', { name: /fxcss pick/ }).click(); + await expect(page).toHaveURL(/\/docs\/pick$/); + await expect(card).toHaveCount(0); +}); + +for (const [stop, prompt] of [ + ['windows', 'C:\\> '], + ['mac', '% '], + ['linux', '$ '], +] as const) + test(`in the ${stop} time machine the card is a period terminal that reports the retro rules`, async ({ + page, + }) => { + await page.addInitScript( + (destination) => + sessionStorage.setItem('fxcss-time-machine', destination), + stop, + ); + await page.goto('/docs/watch'); + await expect(page.locator('html')).toHaveAttribute('data-retro', stop); + await dragLogoTo(page, page.locator('.site-header .github-link')); + await page.mouse.up(); + const card = page.getByRole('dialog', { name: 'fxcss pick' }); + await expect(card).toBeVisible(); + const promptText = await card + .locator('.pick-card-prompt') + .evaluate((element) => + getComputedStyle(element, '::before').content.replace(/^"|"$/g, ''), + ); + expect(promptText.replace(/\\\\/g, '\\')).toBe(prompt); + await expect( + card + .locator('.pick-card-report > span') + .filter({ hasText: /^ {2}html\[data-retro\]/ }) + .first(), + ).toBeVisible(); + await page.keyboard.press('Escape'); + await expect(card).toHaveCount(0); + await expect( + page.locator('html'), + 'Escape closes only the card', + ).toHaveAttribute('data-retro', stop); + }); diff --git a/tests/easter-eggs.test.mjs b/tests/easter-eggs.test.mjs index ba115c8..8ce4460 100644 --- a/tests/easter-eggs.test.mjs +++ b/tests/easter-eggs.test.mjs @@ -1,7 +1,8 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { searchSecret } from '../lib/easter-eggs.ts'; -import { authoredClasses, classedElement, classesOf, classLabel, labelPosition } from '../lib/logo-picker.ts'; +import { authoredClasses, classedElement, classesOf, classLabel, labelPosition, nearBox } from '../lib/logo-picker.ts'; +import { matchingRules, reportedStyles, reportLines } from '../lib/pick-report.ts'; import { battleRounds, winningRule } from '../lib/specificity.ts'; import { watchSleepyFavicon } from '../lib/sleepy-favicon.ts'; import { retroDestinationForQuery, retroDestinations, storedRetroDestination } from '../lib/time-machine.ts'; @@ -142,3 +143,84 @@ test('logo picker labels sit underneath, flip above at the bottom and stay on sc // An element taller than the viewport keeps its label inside it. assert.deepEqual(labelPosition({ left: -20, top: -400, bottom: 2000 }, label, viewport), { left: 4, top: 874 }); }); + +test('a dropped logo reports the rules that match, the site’s own before Tailwind’s layers', () => { + class Layer { constructor(name, cssRules) { this.name = name; this.cssRules = cssRules; } } + class Media { constructor(conditionText, cssRules) { this.conditionText = conditionText; this.cssRules = cssRules; } } + class Supports { constructor(conditionText, cssRules) { this.conditionText = conditionText; this.cssRules = cssRules; } } + const element = { matches(selector) { + if (selector.includes('::')) throw new SyntaxError(selector); + return ['.github-link', '.inline-flex', '.site-header nav a', '.wide', '.grid-ok'].includes(selector); + } }; + const rules = matchingRules(element, [ + { cssRules: [ + new Layer('utilities', [{ selectorText: '.inline-flex' }, new Layer('', [{ selectorText: '.github-link' }])]), + { selectorText: '.github-link' }, + { selectorText: '.github-link::after' }, + { selectorText: '.other' }, + new Media('(min-width: 900px)', [{ selectorText: '.wide' }]), + new Media('print', [{ selectorText: '.github-link' }]), + new Supports('display: grid', [{ selectorText: '.grid-ok' }]), + new Supports('display: nonsense', [{ selectorText: '.github-link' }]), + { name: 'spin', cssRules: [{ keyText: 'from' }] }, + ] }, + { cssRules: [{ selectorText: '.site-header nav a' }] }, + { get cssRules() { throw new Error('SecurityError'); } }, + ], { + matchMedia: (query) => ({ matches: query !== 'print' }), + supports: (condition) => condition === 'display: grid', + LayerBlock: Layer, MediaRule: Media, SupportsRule: Supports, + }, ['github-link']); + // Rules naming the element's class lead, as fxcss pick lists the rules naming it. + assert.deepEqual(rules.map(({ selector, layer }) => layer ? `${layer} ${selector}` : selector), [ + '.github-link', + 'utilities.anonymous .github-link', + '.wide', + '.grid-ok', + '.site-header nav a', + 'utilities .inline-flex', + ]); + assert.deepEqual(rules.slice(0, 2), [{ selector: '.github-link' }, { selector: '.github-link', layer: 'utilities.anonymous' }]); + const unsorted = matchingRules(element, [{ cssRules: [new Layer('utilities', [{ selectorText: '.inline-flex' }]), { selectorText: '.site-header nav a' }, { selectorText: '.github-link' }] }], { + matchMedia: () => ({ matches: true }), supports: () => true, LayerBlock: Layer, MediaRule: Media, SupportsRule: Supports, + }); + assert.deepEqual(unsorted, [ + { selector: '.site-header nav a' }, + { selector: '.github-link' }, + { selector: '.inline-flex', layer: 'utilities' }, + ]); +}); + +test('a dropped logo prints its report in the order and wording of fxcss pick', () => { + const computed = { color: 'rgb(24, 33, 57)', 'background-color': 'rgba(0, 0, 0, 0)', 'border-radius': '8px', opacity: '1', margin: '0px', display: 'flex', padding: '' }; + assert.deepEqual(reportedStyles({ getPropertyValue: (name) => computed[name] ?? '' }), [['color', 'rgb(24, 33, 57)'], ['border-radius', '8px'], ['display', 'flex']]); + + const report = { tag: 'a', selector: '.github-link', label: '.github-link', classes: ['github-link', 'inline-flex'], box: { x: 1180, y: 14, width: 36, height: 36 }, styles: [['color', 'rgb(24, 33, 57)']], rules: [{ selector: '.github-link' }, ...Array.from({ length: 9 }, (_, index) => ({ selector: `.u${index}`, layer: 'utilities' }))] }; + assert.deepEqual(reportLines(report), [ + 'a → .github-link', + 'classes github-link inline-flex', + 'box 36×36 at (1180, 14)', + 'styles', + ' color: rgb(24, 33, 57)', + 'styled by 10 rules on this site', + ' .github-link', + ...Array.from({ length: 7 }, (_, index) => ` @layer utilities .u${index}`), + ' … and 2 more', + ]); + assert.deepEqual(reportLines({ ...report, classes: [], box: { x: 0, y: 0, width: 0, height: 12 }, styles: [], rules: [{ selector: '.only' }] }), [ + 'a → .github-link', + 'box 0×12 at (0, 0) (not visible in this layout)', + 'styled by 1 rule on this site', + ' .only', + ]); + assert.deepEqual(reportLines({ ...report, rules: [] }).at(-1), 'styled by no rules on this site (browser defaults only)'); + const utilities = ['detail-toggle', ...Array.from({ length: 30 }, (_, index) => `u-${index}`)]; + assert.equal(reportLines({ ...report, classes: utilities })[1], 'classes detail-toggle u-0 u-1 u-2 u-3 u-4 +25 more'); +}); + +test('the logo stays a click until the pointer leaves it, so a shaky click still goes home', () => { + const logo = { left: 40, top: 20, right: 180, bottom: 60 }; + for (const [x, y] of [[40, 20], [180, 60], [110, 40], [33, 13], [188, 68]]) assert.equal(nearBox(logo, x, y), true, `${x},${y}`); + for (const [x, y] of [[31, 40], [189, 40], [110, 11], [110, 69]]) assert.equal(nearBox(logo, x, y), false, `${x},${y}`); + assert.equal(nearBox(logo, 30, 40, 10), true); +}); diff --git a/tsconfig.json b/tsconfig.json index 028e8df..9418c04 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "skipLibCheck": true, "strict": true, "noEmit": true, + "allowImportingTsExtensions": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", From e3c0d2b7ae73961d2ff5a98c0789bc2bed95fff4 Mon Sep 17 00:00:00 2001 From: adamXbot <111877622+adamXbot@users.noreply.github.com> Date: Sat, 31 Oct 2026 23:53:32 +1100 Subject: [PATCH 2/2] Move minimatch to 11.0.3 for its denial-of-service advisory GHSA-g3hv-75wg-m249, published on 30 October, affects every minimatch release before 11.0.1 and fails the dependency audit. minimatch reaches the site only through the shadcn CLI, via ts-morph and @ts-morph/common, which asks for minimatch ^10. No 10.x release is patched, and the newest shadcn and ts-morph releases still ask for 10, so an override moves @ts-morph/common to 11.0.3. ts-morph calls only minimatch(path, pattern), which 11 keeps; its glob matching and the shadcn CLI still work. The README notes when to remove the override. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- package-lock.json | 16 ++++++++++++---- package.json | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0f7c6d3..b94e069 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ just verify `npm run check:audit` runs `npm audit` and fails on any advisory at moderate or above. There are no accepted advisories in `scripts/audit.mjs`. The `miniflare` override in `package.json` pins the patched `undici` 7.30.1 while the Cloudflare development tools still pin an affected release; remove the override when their dependency is patched. -vinext 1.0.1 includes `@vercel/og` 1.0.3 with the Satori SVG-escaping fix and the framework's HarfBuzz runtime support. The `satori` override pins `fflate` 0.7.5 to fix its ZIP64 parsing advisory while Satori pins 0.7.3; remove that override once Satori uses a patched release. The lockfile also keeps `@hono/node-server` and `systeminformation` on patched versions within their existing dependency ranges. +vinext 1.0.1 includes `@vercel/og` 1.0.3 with the Satori SVG-escaping fix and the framework's HarfBuzz runtime support. The `satori` override pins `fflate` 0.7.5 to fix its ZIP64 parsing advisory while Satori pins 0.7.3; remove that override once Satori uses a patched release. The `@ts-morph/common` override moves `minimatch` to 11.0.3 for its globparts denial-of-service advisory; it is reached only through the `shadcn` CLI (via `ts-morph`), whose newest release still asks for `minimatch` 10, which has no patched version. Remove it once `@ts-morph/common` depends on `minimatch` 11. The lockfile also keeps `@hono/node-server` and `systeminformation` on patched versions within their existing dependency ranges. The Website GitHub Actions workflow (`.github/workflows/website.yml`) runs the same checks, plus a deploy dry run, on every pull request and push to `website`, without deploying. Pull requests stacked on `fix/website-*` branches also run these checks. A second job warns when the recorded documentation is behind `main`. The production check visits every documentation page, validates asset responses and the security headers on pages, redirects and static files, checks raw-head metadata and share cards, checks that each labelled control's name contains its visible text, and verifies not-found responses and redirects. On Node 24, CI also runs the Playwright Chromium and Firefox suite (`npm run test:browser`) against the built Worker. It covers journey selection, game completion, search loading and recovery, route announcements, code copying, keyboard-operated comparison controls, catalogue toggles, mobile Escape handling, logo picking and its report card, sidebar search sizing and scrolling, narrow layouts, and the reported catalogue and retro contrast regressions. The main checks also run on the declared minimum Node 22.18.0. For local browser checks, run `npx playwright install chromium firefox`, `npm run build`, then `npm run test:browser`; Playwright starts and stops its own local Worker and blocks outside requests. These checks do not replace testing with screen readers or native browser zoom. diff --git a/package-lock.json b/package-lock.json index a31f51f..5cfc391 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1967,6 +1967,13 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz", + "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -6599,13 +6606,14 @@ } }, "node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.3.tgz", + "integrity": "sha512-iny/40PEGkNJQ5/Pv6z3nm6FbRAby32GeZRjCUJk2WnNDbgPSTcdI+DDvLqsgBdD4cD5sMtMheqPPnehCCa8Nw==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^5.0.8" + "@isaacs/nonrecursive-glob-match": "^1.0.3", + "brace-expansion": "^5.0.12" }, "engines": { "node": "18 || 20 || >=22" diff --git a/package.json b/package.json index bf5cfe2..24cda68 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,9 @@ }, "miniflare": { "undici": "7.30.1" + }, + "@ts-morph/common": { + "minimatch": "11.0.3" } } }