Red Dot Tracker

Nav

Markup
<nav class="f-nav" aria-label="Site">
  <span class="f-nav__brand">Duna Feline</span>
  <a href="/" aria-current="page">Blog</a>
  <a href="/projects/">Projects</a>
</nav>
<!-- Floating over the page: class="f-nav f-nav--fixed" -->

<button class="f-theme-toggle" type="button" data-f-theme-toggle>Auto</button>

Buttons

Markup
<button class="f-btn" type="button">Default</button>
<button class="f-btn f-btn--primary" type="button">Primary</button>
<a class="f-btn f-btn--quiet" href="/hairball/">Quiet</a>

Chips and segmented

Purrometheus
Markup
<span class="f-chip">Purrometheus</span>
<button class="f-chip" type="button" aria-pressed="true">Hairball</button>

<div class="f-segmented" role="group" aria-label="View">
  <button type="button" aria-pressed="true">List</button>
  <button type="button" aria-pressed="false">Grid</button>
</div>

Inputs

Markup
<input class="f-input" type="text" aria-label="Name your cat" />
<input class="f-input f-search" type="search" aria-label="Search" />

Select

A dropdown of checkboxes, or of radios for a single choice. It is real form controls in a details: without JavaScript it opens, closes, toggles and submits with a form. select.js adds the search, the current value on the trigger, the keyboard and the Clear and Done actions. A change applies at once: the boxes fire their own bubbling change events, so a dashboard can filter right away, with no extra Apply step. On phones it opens as a bottom sheet.

Project All
Repository All
Sort Newest
Markup
<details class="f-select" data-f-select
  data-f-select-none="All" data-f-select-many="{n} selected">
  <summary class="f-select__trigger">
    <span class="f-select__label">Project</span>
    <span class="f-select__value">All</span>
  </summary>
  <div class="f-select__panel">
    <!-- Shown by select.js; hidden without JavaScript -->
    <input class="f-input f-search f-select__search" type="search"
      aria-label="Filter projects" hidden />
    <div class="f-select__list" role="group" aria-label="Project">
      <label class="f-select__option">
        <input type="checkbox" name="project" value="hairball" /><span>Hairball</span>
      </label>
      <!-- …; type="radio" for a single choice -->
    </div>
    <p class="f-select__empty" role="status" hidden>No matching projects</p>
    <div class="f-select__foot" hidden>
      <button class="f-btn f-btn--quiet" type="button" data-f-select-clear>Clear</button>
      <button class="f-btn" type="button" data-f-select-done>Done</button>
    </div>
  </div>
</details>

<script>
  // Changes apply at once: read the checked boxes on change.
  document.querySelector(".f-select").addEventListener("change", (e) => {
    const picked = [...e.currentTarget.querySelectorAll("input:checked")].map((i) => i.value);
  });
</script>

Code

$ curl https://example.com/hairball
200 OK  red dot found
Markup
<pre class="f-code"><span class="f-code__prompt">$ </span>curl https://example.com/hairball
<span class="f-code__out">200 OK</span></pre>

<!-- Inline code inside .f-prose is plain <code>. -->

Syntax colors

A highlighter-neutral set of classes: f-syn-keyword, -string, -comment, -number, -constant, -type, -function, -property, -tag and -punctuation. Map your highlighter's scopes to them on the server and facet colors them in both themes. The colors are decoration: code reads the same without them. They use the accent chroma and keep 4.5:1 on code and diff backgrounds.

use std::time::Duration;

/// How fast to chase the red dot.
pub fn follow(dot: &RedDot) -> Speed {
    let room = dot.room();
    if room == "kitchen" && !dot.is_still() {
        return Speed::Walk;
    }
    let wait = Duration::from_millis(250);
    Speed::Pounce { wait, retries: MAX_TRIES }
}
Markup
<pre class="f-code"><code><span class="f-syn-keyword">let</span> room = dot.<span class="f-syn-function">room</span>();
<span class="f-syn-comment">// A comment</span></code></pre>

<!-- Each token's color is also a variable: --f-syn-keyword, --f-syn-string, … -->

Diff

A unified diff for code review. Each file is a details: its header shows the path and the added and removed counts, and collapses the file. Added and removed lines get a faint green or red background and a + or − marker, never color alone. Line numbers sit in data-old and data-new and CSS draws them, so copying takes only the code. Long lines scroll inside the diff on wide screens and wrap on phones (always, with f-diff--wrap).

src/tracker.rs +5 −2
@@ -12,9 +12,11 @@ pub fn follow(dot: &RedDot) -> Speed {
pub fn follow(dot: &RedDot) -> Speed {
let room = dot.room();
if room == "kitchen" {
// The kitchen floor is slippery: walk first, and pounce only once the dot has stopped moving for a while.
if room == "kitchen" && !dot.is_still() {
return Speed::Walk;
}
Speed::Pounce
let wait = Duration::from_millis(250);
Speed::Pounce { wait, retries: MAX_TRIES }
}
@@ -44,6 +46,7 @@ impl RedDot {
pub fn is_still(&self) -> bool {
self.moves.is_empty()
|| self.last_move.elapsed() > STILL_AFTER
}
docs/笔记/追踪红点.md +18 −0
@@ -0,0 +1,18 @@
# Tracking the red dot
Markup
<details class="f-diff" open>
  <summary class="f-diff__head">
    <span class="f-diff__path">src/tracker.rs</span>
    <span class="f-diff__stat">
      <span class="f-diff__added">+5</span> <span class="f-diff__removed">−2</span>
    </span>
  </summary>
  <div class="f-diff__body">
    <div class="f-diff__lines">
      <div class="f-diff__hunk">@@ -12,9 +12,11 @@ pub fn follow(dot: &amp;RedDot)</div>
      <div class="f-diff__line" data-old="13" data-new="13">
        <code class="f-diff__code">    let room = dot.room();</code></div>
      <div class="f-diff__line f-diff__line--del" data-old="14">
        <code class="f-diff__code">…</code></div>
      <div class="f-diff__line f-diff__line--add" data-new="14">
        <code class="f-diff__code">…</code></div>
      <!-- Where the next part of a large diff loads -->
      <div class="f-diff__more"><button type="button">Show 24 more lines</button></div>
    </div>
  </div>
</details>

Code block options

Line numbers, wrapping, a title and a terminal frame are CSS only, switched on by attributes. data-f-code-ln, data-f-code-wrap and data-f-code-frame take "true" or "false": on a container (main or article) they set the page's default, and on the block (pre or code) they set that block alone, which wins over the container either way. The article below numbers its code by default, and the third block opts out with data-f-code-ln="false".

Numbered (Giallo's .giallo-l markup); the long line scrolls:

fn main() {
    let dot = RedDot::new("living-room");

    tracker.follow(dot, Speed::Pounce).expect("the red dot always escapes under the sofa, behind the bookshelf and out past the sunbeam, but the chase is the whole point");
}

Numbered and wrapped (Shiki's .line markup): a wrapped line hangs past its number, the empty line stays, and the first line keeps clear of the Copy button.

fn main() {
    let dot = RedDot::new("living-room");

    tracker.follow(dot, Speed::Pounce).expect("the red dot always escapes under the sofa, behind the bookshelf and out past the sunbeam, but the chase is the whole point");
}

Opting out of the page's line numbers:

duna feed --bowl kitchen
duna nap --spot sunbeam

A title with no frame: the file name sits in a quiet strip above the code, with the Copy button.

pub struct RedDot {
    room: String,
}
鸡肉罐头 ×3
冻干 ×1

A terminal frame with a title, around a dark code theme (dark in a light page too):

$ curl https://example.com/hairball
200 OK  red dot found in the living room, under the sofa, next to the second-best sunbeam

$ duna pounce
Markup
<!-- A page-wide default on the container -->
<main data-f-code-ln="true" data-f-code-wrap="true">…</main>

<!-- One block opts in or out; the block wins -->
<pre data-f-code-ln="false"><code>…</code></pre>
<pre><code data-f-code-wrap="true">…</code></pre>

<!-- One element per line, as code's direct children -->
<pre class="f-code"><code><span class="line">fn main() {</span>
<span class="line"></span>
<span class="line">}</span></code></pre>

<!-- A title (or Zola's data-name), and a terminal frame -->
<pre class="f-code" data-f-code-title="src/tracker.rs">
  <button class="f-code-copy" type="button">Copy</button><code>…</code></pre>
<pre class="f-code" data-f-code-frame="true" data-f-code-title="zsh"><code>…</code></pre>

Alerts

Info

Purrometheus refreshes every five minutes.

Success

The red dot was caught.

Warning

The Hairball queue is getting long.

Danger

The red dot escaped the tracker.
Markup
<div class="f-alert f-alert--warning">
  <p class="f-alert__title">Warning</p>
  The Hairball queue is getting long.
</div>
<!-- Kinds: f-alert--info, --success, --warning, --danger. -->

Cards

Red Dot Tracker

Follows the red dot wherever it hides.

Hairball

A small tool that collects hairballs.

Markup
<div class="f-cluster" data-f-liquid>
  <article class="f-card">
    <div class="f-card__media" style="background-image: url(board.jpg)"></div>
    <div class="f-card__body">
      <h3>Red Dot Tracker</h3>
      <p>Follows the red dot wherever it hides.</p>
    </div>
  </article>
  <article class="f-card f-card--text">
    <div class="f-card__body">…</div>
  </article>
</div>

Sheet

New tracker

Purrometheus will tell you when the red dot shows up.

Markup
<dialog class="f-sheet" aria-labelledby="sheet-title">
  <div class="f-sheet__panel">
    <h3 id="sheet-title">New tracker</h3>
    <p>Purrometheus will tell you when the red dot shows up.</p>
    <button class="f-btn" type="button">Close</button>
  </div>
</dialog>
<!-- Open it with dialog.showModal(). -->

Media toggle

Markup
<button class="f-media-toggle" type="button">Pause</button>
<!-- Over a cover or panel video; see the Cover and Panels layouts. -->

Table of contents

Markup
<nav class="f-toc" aria-label="On this page" data-f-scrollspy>
  <a href="#overview">Overview</a>
  <a href="#install">Install</a>
  <a href="#usage">Usage</a>
</nav>

Hero

A card filled with a deep shade of the accent, the same in both themes. The title is an h3 here because this page has its own h1.

Project

Red Dot Tracker

Maps every wall the red dot has touched.

Markup
<section class="f-hero">
  <div>
    <p class="f-hero__kicker">Project</p>
    <h3 class="f-hero__title">Red Dot Tracker</h3>
    <p class="f-hero__lead">Maps every wall the red dot has touched.</p>
    <div class="f-hero__actions">
      <a class="f-btn f-btn--primary" href="#">Learn more ↗</a>
      <a class="f-btn" href="#">Source</a>
    </div>
  </div>
  <figure class="f-hero__media">…</figure> <!-- optional -->
</section>

Social

A row of round icon links. The icons live in dist/icons.css, linked on its own; every link carries a visually hidden name.

Every icon is below; twitter is an alias of x. The same icons are SVG files in dist/icons/, for inlining. They come from Simple Icons (CC0) and Bootstrap Icons (MIT); brand names and marks belong to their owners.

Markup
<link rel="stylesheet" href="…/dist/icons.css" />

<ul class="f-social" aria-label="Elsewhere">
  <li>
    <a class="f-social__link" href="https://github.com/example" rel="me noopener">
      <span class="f-icon f-icon--github" aria-hidden="true"></span>
      <span class="f-visually-hidden">GitHub</span>
    </a>
  </li>
</ul>

Divider

or find me on

Markup
<p class="f-divider">or find me on</p>

Empty state

404

This cat wandered off

The page you want is not here. Maybe the red dot took it.

Markup
<div class="f-empty">
  <div>
    <div class="f-empty__cat" aria-hidden="true"></div>
    <p class="f-empty__code">404</p>
    <h1>This cat wandered off</h1>
    <p>The page you want is not here.</p>
    <a class="f-btn f-btn--primary" href="/">Back to home</a>
  </div>
</div>

Figure

Diagram

Soft bands of light over a dark horizon
Steer the light. Mirrors and filters mix the bands.
An SVG with its own panel takes --bare.
Markup
<figure class="f-figure">
  <p class="f-figure__kicker">Diagram</p>
  <img src="aurora.jpg" alt="…" width="1920" height="1080" />
  <figcaption><b>Steer the light.</b> Mirrors and filters mix the bands.</figcaption>
</figure>
<!-- A self-framed SVG or picture: class="f-figure f-figure--bare" -->

Stat tiles

When one number tells the story, skip the chart: a label, the number, and one line of context. The number is serif with proportional figures; the context says what it is compared with.

Markup
<ul class="f-stats">
  <li class="f-stat">
    <p class="f-stat__label">Pass rate</p>
    <p class="f-stat__value">87<span class="f-stat__unit">%</span></p>
    <p class="f-stat__context">Of 342 attempts</p>
  </li>
</ul>

Meters

How much of a whole is used, such as a quota. The fill is the accent and the track a faint step of the same color. Near a limit it switches to the warning or danger color, always with an icon and words, never color alone. --v is the share used (or a raw value with --max), and aria-valuenow carries the same number.

Usage window 62%

Resets in 2 h 10 min

Weekly quota 88%, near the limit
Workspace disk 3.1 / 10 GB
Markup
<div class="f-meter" style="--v: 0.62">
  <div class="f-meter__head">
    <span class="f-meter__label" id="usage">Usage window</span>
    <span class="f-meter__value">62%</span>
  </div>
  <div class="f-meter__track" role="meter" aria-labelledby="usage"
    aria-valuenow="62" aria-valuemin="0" aria-valuemax="100" aria-valuetext="62%">
    <span class="f-meter__fill"></span>
  </div>
  <p class="f-meter__context">Resets in 2 h 10 min</p>
</div>
<!-- Near a limit: class="f-meter f-meter--warning" (or --danger), and say so in words -->

Bar charts

Thin columns grow from one baseline, over a faint grid and a single y-axis. Each column holds its x label and a .f-bars__tip text (read by screen readers) before its bars; --v is a value and --max the top of the y-axis. Bars in one column stack upward with a 2px gap, and the top one gets the rounded end. With chart.js, hover, a tap or the arrow keys show a tooltip.

Attempts per day Last 7 days
  1. Mon18 attempts
  2. Tue26 attempts
  3. Wed31 attempts
  4. Thu22 attempts
  5. Fri35 attempts
  6. Sat12 attempts
  7. Sun9 attempts
Table
Day Attempts
Mon 18
Tue 26
Wed 31
Thu 22
Fri 35
Sat 12
Sun 9
Tasks done by each worker Last 7 days, stacked
  • Duna
  • Dudu
  • Nangnang
  1. MonDuna 8 · Dudu 6 · Nangnang 4
  2. TueDuna 11 · Dudu 9 · Nangnang 3
  3. WedDuna 7 · Dudu 12 · Nangnang 8
  4. ThuDuna 10 · Dudu 5 · Nangnang 6
  5. FriDuna 13 · Dudu 10 · Nangnang 9
  6. SatDuna 4 · Dudu 3 · Nangnang 2
  7. SunDuna 2 · Dudu 4 · Nangnang 1
Table
Day Duna Dudu Nangnang
Mon 8 6 4
Tue 11 9 3
Wed 7 12 8
Thu 10 5 6
Fri 13 10 9
Sat 4 3 2
Sun 2 4 1
Markup
<figure class="f-chart">
  <figcaption class="f-chart__head">
    <span class="f-chart__title" id="workers">Tasks done by each worker</span>
    <span class="f-chart__sub">Last 7 days, stacked</span>
  </figcaption>
  <!-- A legend for two or more series -->
  <ul class="f-legend">
    <li class="f-series-1">Duna</li>
    <li class="f-series-2">Dudu</li>
  </ul>
  <div class="f-bars" role="group" aria-labelledby="workers" data-f-chart
    style="--max: 40; --ticks: 3">
    <div class="f-bars__y" aria-hidden="true"><span>40</span><span>20</span><span>0</span></div>
    <ol class="f-bars__plot">
      <li class="f-bars__col">
        <span class="f-bars__x">Mon</span>
        <span class="f-bars__tip">Duna 8 · Dudu 6</span>
        <span class="f-bars__bar f-series-1" style="--v: 8"></span>
        <span class="f-bars__bar f-series-2" style="--v: 6"></span>
      </li>
      <!-- … one li per column; one bar for a single series -->
    </ol>
  </div>
  <details class="f-chart__table">
    <summary>Table</summary>
    <div><table>…</table></div>
  </details>
</figure>

Small multiples

When there are too many series, or each one deserves a look, draw one small chart per series side by side in .f-multiples. They share one --max, set on the grid, so heights compare directly; each title names its series, so every chart uses the first series color.

Duna 55 tasks
  1. Mon8 tasks
  2. Tue11 tasks
  3. Wed7 tasks
  4. Thu10 tasks
  5. Fri13 tasks
  6. Sat4 tasks
  7. Sun2 tasks
Dudu 49 tasks
  1. Mon6 tasks
  2. Tue9 tasks
  3. Wed12 tasks
  4. Thu5 tasks
  5. Fri10 tasks
  6. Sat3 tasks
  7. Sun4 tasks
Nangnang 33 tasks
  1. Mon4 tasks
  2. Tue3 tasks
  3. Wed8 tasks
  4. Thu6 tasks
  5. Fri9 tasks
  6. Sat2 tasks
  7. Sun1 tasks
Markup
<div class="f-multiples" style="--max: 14; --h: 6rem">
  <figure class="f-chart">
    <figcaption class="f-chart__head">
      <span class="f-chart__title" id="duna">Duna</span>
    </figcaption>
    <div class="f-bars" role="group" aria-labelledby="duna" data-f-chart>…</div>
  </figure>
  <!-- … one figure per series -->
</div>

Variants

One segmented control switches between versions of the same content, such as two looks of the same screenshots. Radios are the recommended markup: they switch with CSS alone, no JavaScript needed, and arrow keys move between the options. When variants.js loads it takes over and matches by value instead of position. The older button form still works, but only switches with JavaScript.

Edge cases:

  • The control's parent is its scope: the control switches every data-f-variant="group:value" inside it. The value is split off at the last colon, so group a and group a:b are distinct.
  • Without JavaScript the match is by position: the nth radio shows the nth variant among its siblings, so each set of alternatives (a gallery item's images, say) shares one parent and follows the radios' order. CSS covers up to six options. With JavaScript the values decide.
  • Without JavaScript, give each radio control its own parent; sibling and nested groups stay independent. A parent with two controls shows every variant until the script runs, which then tells the groups apart by value.
  • A radio's name must be unique in the page (or form), or two controls become one radio group. Each radio sits directly in its label, and each label directly in the control.
  • Radio-form variants carry no hidden; CSS hides them. That rule is layered, so unlayered site CSS that sets display on a variant element (such as img { display: block }) shows it again; add :not([data-f-variant]) to such rules.
  • Browsers without @scope (Firefox before 146, Safari before 17.4) show every variant without JavaScript; with it, switching works as usual.
  • Button form: the control and the non-default variants ship hidden, so without JavaScript the first variant shows and there are no dead buttons. In both forms, a variant whose value has no option stays hidden, a control with no options is skipped, and variants added after init are not picked up (call init again).
Markup
<!-- Radios (recommended): switch with or without JavaScript -->
<div>
  <div class="f-segmented" role="radiogroup" aria-label="Look" data-f-variants="look">
    <label><input type="radio" name="board-look" value="modern" checked />Modern</label>
    <label><input type="radio" name="board-look" value="classic" />Classic</label>
  </div>
  <ul class="f-gallery">
    <li>
      <img data-f-variant="look:modern" src="modern.jpg" alt="…" />
      <img data-f-variant="look:classic" src="classic.jpg" alt="…" />
      <span class="f-gallery__label">Board</span>
    </li>
  </ul>
</div>

<!-- Buttons: switch only with JavaScript -->
<div>
  <div class="f-segmented" role="group" aria-label="Look" data-f-variants="look" hidden>
    <button type="button" data-variant="modern" aria-pressed="true">Modern</button>
    <button type="button" data-variant="classic" aria-pressed="false">Classic</button>
  </div>
  <img data-f-variant="look:modern" src="modern.jpg" alt="…" />
  <img data-f-variant="look:classic" hidden src="classic.jpg" alt="…" />
</div>