Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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, 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)):

Expand Down Expand Up @@ -97,6 +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.

## Screenshot evidence

Expand Down
27 changes: 26 additions & 1 deletion app/components/brand-link.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use client';

import Link from 'next/link';
import { useEffect, useState, type ReactNode } from 'react';
import { useEffect, useRef, useState, type ReactNode } from 'react';
import { followLogoPress } from '../../lib/logo-picker';

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);

useEffect(() => {
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
Expand All @@ -17,6 +20,8 @@ export function BrandLink({ children }: { children: ReactNode }) {
reducedMotion.removeEventListener('change', stopForReducedMotion);
}, []);

useEffect(() => () => stopPicking.current?.(), []);

function startSpin() {
if (
spinning ||
Expand All @@ -31,10 +36,30 @@ export function BrandLink({ children }: { children: ReactNode }) {
className="brand"
href="/"
aria-label="fxcss home"
draggable={false}
data-spinning={spinning || undefined}
onPointerEnter={(event) => {
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();
}}
Expand Down
15 changes: 15 additions & 0 deletions app/easter-eggs.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@
.coffee-replay { display: flex !important; padding: 8px 0 0; font-size: 12px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.coffee-dismiss { padding: 2px; margin-left: auto; }

/* The logo picker wears the outline of `fxcss pick`. Its label is a deeper
pink so the white selector text keeps 4.9:1 contrast. */
.brand { user-select: none; }
.brand[data-picking] .brand-mark { visibility: hidden; }
html[data-logo-picking], html[data-logo-picking] * { cursor: grabbing !important; }
.logo-picker-outline, .logo-picker-ghost, .logo-picker-label { position: fixed; top: 0; left: 0; pointer-events: none; }
.logo-picker-outline { z-index: 1000; box-sizing: border-box; border: 2px solid #ff0080; border-radius: 3px; background: #ff008024; }
.logo-picker-ghost { z-index: 1001; scale: 1.15; filter: drop-shadow(0 8px 10px #18213947); }
.logo-picker-ghost .brand-braces { filter: drop-shadow(0 0 12px #00ddef) drop-shadow(0 0 24px #00ddef88); }
.logo-picker-label { z-index: 1002; max-width: calc(100% - 8px); overflow: hidden; padding: 2px 6px; border-radius: 3px; background: #db0078; color: #fff; font: 12px/1.5 'SFMono-Regular', Consolas, 'Liberation Mono', monospace; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
.logo-picker-ghost { animation: logo-picker-lift 140ms ease-out; }
}
@keyframes logo-picker-lift { from { scale: 1; } }

/* The arena uses the site's purple, orange and monospace details. */
.battle-page { max-width: 960px; padding-top: 60px; padding-bottom: 100px; }
.battle-intro { margin-bottom: 40px; }
Expand Down
280 changes: 280 additions & 0 deletions lib/logo-picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
// 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;
/** Longer class lists are shortened to this many classes and a count. */
const SHOWN_CLASSES = 3;

type Box = { left: number; top: number; bottom: number };
type Size = { width: number; height: number };
type Picker = { follow(x: number, y: number): void; land(fly: boolean): void };

export function classesOf(element: Element) {
return [
...new Set(element.getAttribute('class')?.split(/\s+/).filter(Boolean)),
];
}

/** The element itself or its nearest ancestor with a class, inside <body>. */
export function classedElement(element: Element | null) {
for (
let current = element;
current && current.localName !== 'body' && current.localName !== 'html';
current = current.parentElement
)
if (classesOf(current).length) return current;
return null;
}

/**
* Class names in style rules outside cascade layers. Those are the site's own
* stylesheets; Tailwind keeps its utilities in a layer.
*/
export function authoredClasses(
sheets: Iterable<{ readonly cssRules: CSSRuleList }>,
LayerBlock: typeof CSSLayerBlockRule = CSSLayerBlockRule,
) {
const names = new Set<string>();
function read(rules: Iterable<CSSRule>) {
for (const rule of rules) {
if (rule instanceof LayerBlock) continue;
if ('selectorText' in rule)
for (const [, name] of String(rule.selectorText).matchAll(
/\.(-?[_a-zA-Z][\w-]*)/g,
))
names.add(name);
if ('cssRules' in rule) read(rule.cssRules as CSSRuleList);
}
}
for (const sheet of sheets) {
try {
read(sheet.cssRules);
} catch {
// A stylesheet from another origin keeps its rules private.
}
}
return names;
}

/**
* A compound class selector. When the site's own CSS names some of the
* classes, only those are shown, so a Tailwind component's utilities do not
* bury the one class that identifies it.
*/
export function classLabel(
classes: string[],
authored: ReadonlySet<string>,
escape = (name: string) => CSS.escape(name),
) {
const own = classes.filter((name) => authored.has(name));
const shown = own.length ? own : classes;
const selector = shown
.slice(0, SHOWN_CLASSES)
.map((name) => `.${escape(name)}`)
.join('');
return shown.length > SHOWN_CLASSES
? `${selector} +${shown.length - SHOWN_CLASSES}`
: selector;
}

/**
* Underneath the element when there is room, above it when not, otherwise
* pinned to the bottom of the viewport. Never off the side of the screen.
*/
export function labelPosition(
box: Box,
label: Size,
viewport: Size,
gap = 2,
margin = 4,
) {
const below = box.bottom + gap;
const above = box.top - gap - label.height;
const top =
below + label.height <= viewport.height - margin
? below
: above >= margin
? above
: viewport.height - margin - label.height;
return {
left: Math.max(
margin,
Math.min(box.left, viewport.width - margin - label.width),
),
top: Math.max(margin, top),
};
}

/**
* 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
* 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) {
const home = link.querySelector<SVGSVGElement>('.brand-mark');
const view = link.ownerDocument.defaultView;
if (!home || !view) return () => {};
const listening = new AbortController();
const { signal } = listening;
let picker: Picker | undefined;
let held = true;

function end(fly: boolean) {
listening.abort();
if (link.hasPointerCapture(press.pointerId))
link.releasePointerCapture(press.pointerId);
picker?.land(fly);
}

link.setPointerCapture(press.pointerId);
link.addEventListener(
'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);
picker.follow(event.clientX, event.clientY);
},
{ signal },
);
link.addEventListener(
'pointerup',
(event) => {
if (event.pointerId !== press.pointerId) return;
end(true);
if (picker) swallowClick(view);
},
{ signal },
);
for (const type of ['pointercancel', 'lostpointercapture'] as const)
link.addEventListener(
type,
(event) => {
if (event.pointerId === press.pointerId) end(true);
},
{ signal },
);
view.addEventListener(
'keydown',
(event) => {
if (event.key !== 'Escape' || !picker || !held) return;
// Only put the logo back; search and the time machine keep their Escape.
event.preventDefault();
event.stopPropagation();
held = false;
picker.land(true);
},
{ signal, capture: true },
);
return () => end(false);
}

/** The click that ends a drag arrives in the same task as its pointerup. */
function swallowClick(view: Window) {
function swallow(event: MouseEvent) {
event.preventDefault();
event.stopPropagation();
}
view.addEventListener('click', swallow, { capture: true, once: true });
view.setTimeout(() => view.removeEventListener('click', swallow, true));
}

function liftMark(link: HTMLElement, home: SVGSVGElement): Picker {
const doc = link.ownerDocument;
const view = doc.defaultView!;
const root = doc.documentElement;
const size = home.getBoundingClientRect();
// appendChild, because the Workers types replace Element.append.
const [outline, ghost, label] = ['outline', 'ghost', 'label'].map((part) => {
const element = doc.body.appendChild(doc.createElement('div'));
element.className = `logo-picker-${part}`;
element.setAttribute('aria-hidden', 'true');
return element;
});
const mark = ghost.appendChild(home.cloneNode(true) as SVGSVGElement);
mark.style.width = `${size.width}px`;
mark.style.height = `${size.height}px`;
outline.hidden = label.hidden = true;
link.toggleAttribute('data-picking', true);
root.toggleAttribute('data-logo-picking', true);
const authored = authoredClasses(doc.styleSheets);
let pointer = { x: 0, y: 0 };
let target: Element | null = null;
let labelSize = { width: 0, height: 0 };
let frame = 0;
let flight: Animation | undefined;
let landed = false;

// 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));
if (found !== target) {
target = found;
outline.hidden = label.hidden = !target;
if (target) {
label.textContent = classLabel(classesOf(target), authored);
labelSize = { width: label.offsetWidth, height: label.offsetHeight };
}
}
if (target) {
const box = target.getBoundingClientRect();
outline.style.translate = `${box.left}px ${box.top}px`;
outline.style.width = `${box.width}px`;
outline.style.height = `${box.height}px`;
const { left, top } = labelPosition(box, labelSize, {
width: root.clientWidth,
height: root.clientHeight,
});
label.style.translate = `${left}px ${top}px`;
}
frame = view.requestAnimationFrame(draw);
}

function settle() {
if (landed) return;
landed = true;
flight?.cancel();
ghost.remove();
link.removeAttribute('data-picking');
}

return {
follow(x, y) {
pointer = { x, y };
if (!frame) draw();
},
land(fly) {
view.cancelAnimationFrame(frame);
outline.remove();
label.remove();
root.removeAttribute('data-logo-picking');
if (!fly || view.matchMedia('(prefers-reduced-motion: reduce)').matches)
return settle();
if (flight || landed) return;
const to = home.getBoundingClientRect();
flight = ghost.animate(
[
{
translate: ghost.style.translate,
scale: view.getComputedStyle(ghost).scale,
},
{ translate: `${to.left}px ${to.top}px`, scale: '1' },
],
{
duration: 260,
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
fill: 'forwards',
},
);
flight.finished.then(settle, settle);
},
};
}
Loading
Loading