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.
ProjectAll
No matching projects
RepositoryAll
No matching repositories
SortNewest
The trigger shows data-f-select-none when nothing is checked (default
“All”), the one checked option's text, or data-f-select-many with
{n} replaced by the count (default “{n} selected”). Write both in the
page's language. Without JavaScript it keeps the text in the markup.
Keys: Enter, Space or ArrowDown on the trigger opens it; arrows, Home and End move
between the search and the options; Space toggles; Enter or Escape closes and returns
focus to the trigger; typing on an option goes to the search. A click outside, or focus
moving out, closes it too.
The list stops at 18rem and scrolls inside the panel, so hundreds of options work. With
radios it is a single select, which closes once an option is picked with the pointer.
Add f-select--end to a trigger near the right edge to align the panel to
its right; with JavaScript a panel that would leave the window also shifts left.
Without JavaScript a click outside closes the panel through a clear layer on the trigger
that covers the window. Inside an element with backdrop-filter or
transform (a glass nav, say) that layer only covers that element, and
JavaScript does the closing.
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.pubfnfollow(dot:&RedDot)->Speed{let room = dot.room();if room =="kitchen"&&!dot.is_still(){returnSpeed::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).
// 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(){
returnSpeed::Walk;
}
Speed::Pounce
let wait =Duration::from_millis(250);
Speed::Pounce { wait, retries:MAX_TRIES}
}
@@ -44,6 +46,7 @@ impl RedDot {
pubfnis_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
The load more row (.f-diff__more) is for a large diff loaded in parts: when
the reader clicks its button, or the row nears the screen, your code replaces it with
the next part. Set aria-busy="true" on it while a part loads, and the
button shows a spinner (still under reduced motion). Facet ships the styling and markup
only.
The number columns are 4 characters wide (3 on phones); past 9999 lines, widen them with
--f-diff-num-width. Syntax colors inside lines use the
f-syn-* classes above.
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: &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 kitchenduna 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/hairball200 OK red dot found in the living room, under the sofa, next to the second-best sunbeam$ duna pounce
The title is the pre's data-f-code-title, or
data-name (Zola writes ```rust,name=src/main.rs as
data-name on code; set
data_attr_position = "both" under [markdown.highlighting] to
put it on pre too). A long title ends in an ellipsis on one line.
On a block, the short names data-ln, data-wrap and
data-frame work too: Zola writes a fence's ln=,
wrap= and frame= as those, so ```txt,wrap=false
keeps one table-like output scrolling sideways.
The title is a pseudo-element, which screen readers may not announce. When the name
matters, give the pre an aria-label, or wrap the block in a
figure with a figcaption.
Numbers and wrapping need one element per line as a direct child of
code: .giallo-l (Zola 0.23), .line (Shiki, Astro)
or [data-line] (rehype-pretty-code). Blocks with the highlighter's own
numbers (.giallo-ln from Zola's linenos, or
data-line-numbers) are not numbered twice; .giallo-ln takes
the same column.
Edge cases: a pre > code with no line elements wraps but cannot be
numbered. A title or frame needs pre > code; long lines scroll inside
code, under a bar that stays put. The number column is 3 characters wide;
past 999 lines, widen it with --f-code-ln-width.
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
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. -->
<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.
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.
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 window62%
Resets in 2 h 10 min
Weekly quota88%, near the limit
Workspace disk3.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 dayLast 7 days
40200
Mon18 attempts
Tue26 attempts
Wed31 attempts
Thu22 attempts
Fri35 attempts
Sat12 attempts
Sun9 attempts
Table
Day
Attempts
Mon
18
Tue
26
Wed
31
Thu
22
Fri
35
Sat
12
Sun
9
Tasks done by each workerLast 7 days, stacked
Duna
Dudu
Nangnang
40200
MonDuna 8 · Dudu 6 · Nangnang 4
TueDuna 11 · Dudu 9 · Nangnang 3
WedDuna 7 · Dudu 12 · Nangnang 8
ThuDuna 10 · Dudu 5 · Nangnang 6
FriDuna 13 · Dudu 10 · Nangnang 9
SatDuna 4 · Dudu 3 · Nangnang 2
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
Series colors go in a fixed order, .f-series-1 to .f-series-5:
never cycle them or pick them by rank, and a series keeps its color when a filter hides
others. Past five series, fold the rest into “Other” or use small multiples.
Two or more series always get a legend. Text (values, labels, legends) stays in the text
colors; series colors are for marks and legend keys only. Status colors mean status and
are never “series 4”.
Every chart has a text version: screen readers read each column's label and tip text,
and .f-chart__table puts the same numbers in a table. The tooltip repeats
that text and is never the only way to a value.
--h sets the plot height (default 10rem) and --ticks the
number of gridlines, baseline included (default 3), to match the y labels. Keep x labels
short: they do not wrap.
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.
Duna55 tasks
1470
Mon8 tasks
Tue11 tasks
Wed7 tasks
Thu10 tasks
Fri13 tasks
Sat4 tasks
Sun2 tasks
Dudu49 tasks
1470
Mon6 tasks
Tue9 tasks
Wed12 tasks
Thu5 tasks
Fri10 tasks
Sat3 tasks
Sun4 tasks
Nangnang33 tasks
1470
Mon4 tasks
Tue3 tasks
Wed8 tasks
Thu6 tasks
Fri9 tasks
Sat2 tasks
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.
Board
Another board
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).
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;
twitteris an alias ofx. The same icons are SVG files indist/icons/, for inlining. They come from Simple Icons (CC0) and Bootstrap Icons (MIT); brand names and marks belong to their owners.githublinkedingoogle-scholarinstagramxemailrssorciddblpsemantic-scholarwechatweibozhihubilibilixiaohongshublueskymastodonthreadsyoutubeMarkup
<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>