oficina / home Public

Front page: a wisp at each section heading

Paul chose it over eight mock-up rounds (design-directions/wisp, 2026-10-03
to 10-30): a filament from the hero's nebula, in from off the left edge,
round the heading, and away off the right. Smoke, not string — a glow, a
body and braided tapering fibres — in five variants, one per heading, in
the section's colour. Quiet strength, Gentle pace.

Triggered by scrolling, not driven by it (Paul, 10-30): a scroll-driven
animation on each heading flips --wisp-play, and a style query on it
starts a timed animation, so the wisp runs on its own clock instead of
stuttering with the scroll. Only opacity and transform animate. Pure CSS;
no wisp without scroll timelines or with reduced motion.

Package wisp draws everything once, ported from the mock-up's build.py
byte for byte (its random choices carried as fixed numbers). The drawing
is set into the page, not served as a file: Safari draws symbols from
another file but drops their filters, so every blur vanished.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e7a3d0bb90be9db44a4fb59e5a38b008509ad8c8)
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b4074a817be4ae4a778e446a3cddb569e4891e61 parent 090d31e
6 files changed, +642 −6
  • internal/home/page.go +21 −1
  • internal/home/static/site/home.css +93 −0
  • internal/home/static/site/index.html +6 −5
  • internal/home/wisp/wisp.go +373 −0
  • internal/home/wisp/wisp_test.go +91 −0
  • internal/home/wisp_test.go +58 −0
diff --git a/internal/home/page.go b/internal/home/page.go
index e41c60c..ce1ed30 100644
--- a/internal/home/page.go
+++ b/internal/home/page.go
@@ -7,9 +7,12 @@ import (
"bytes"
"embed"
"net/http"
+ "regexp"
+ "strconv"
"sync"
"amadan.net/oficina/estilo.git/theme"
+ "amadan.net/oficina/home/internal/home/wisp"
"github.com/go-chi/chi/v5"
)
@@ -66,6 +69,23 @@ func mountSite(r chi.Router) {
mountCSS(r, "/static/site/apps.css", appsCSS)
}
+// The wisps (package wisp): <!-- wisp:sprite --> is where the drawing
+// goes, once, at the top of the body; <!-- wisp:N --> is where a heading's
+// wisp goes, inside the heading, which also carries data-wisp="N" for
+// home.css to time it by.
+var (
+ wispSpriteMarker = []byte("<!-- wisp:sprite -->")
+ wispMarker = regexp.MustCompile(`<!-- wisp:(\d+) -->`)
+)
+
+func withWisps(page []byte) []byte {
+ page = bytes.Replace(page, wispSpriteMarker, wisp.Sprite(), 1)
+ return wispMarker.ReplaceAllFunc(page, func(m []byte) []byte {
+ n, _ := strconv.Atoi(string(wispMarker.FindSubmatch(m)[1]))
+ return []byte(wisp.Markup(n))
+ })
+}
+
// skyMarker is where the front page's sky goes: rendered from estilo's
// own template, so the page carries exactly the layers (and the inline
// placeholder) the pinned estilo draws, never a hand-copied set of URLs.
@@ -90,7 +110,7 @@ var (
// handleIndex serves the front page.
func (a *App) handleIndex(w http.ResponseWriter, _ *http.Request) {
- servedIndexOnce.Do(func() { servedIndex = versionStaticRefs(withSky(indexPage)) })
+ servedIndexOnce.Do(func() { servedIndex = versionStaticRefs(withWisps(withSky(indexPage))) })
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(servedIndex)
}
diff --git a/internal/home/static/site/home.css b/internal/home/static/site/home.css
index 4e42426..aac7613 100644
--- a/internal/home/static/site/home.css
+++ b/internal/home/static/site/home.css
@@ -187,3 +187,96 @@ h1, h2, h3 { text-wrap: balance; }
@media (prefers-reduced-motion: reduce) {
.btn, .family li { transition: none; }
}
+
+/* ── The wisps ──
+ A filament from the hero's nebula at each section heading: in from off
+ the left edge, round the heading, and away off the right edge. Drawn
+ once (package wisp) into the page as .wisp-defs; each heading's wisp is
+ seven overlapping stretches pointing into that drawing.
+
+ Triggered by scrolling, not driven by it. When a heading comes about a
+ third of the way up the screen its wisp starts, and from then on runs on
+ its own clock, so it moves at the display's frame rate whatever the
+ scrolling does. The trigger is CSS: a scroll-driven animation on the
+ heading flips --wisp-play to running as it crosses the line, and a
+ style query on that gives the stretches their timed animation. (Not
+ animation-play-state: var(--wisp-play) — CSS rightly ignores a value
+ one animation sets inside another's animation properties, and Chrome
+ enforces that.) Only opacity and transform animate, so the wisp is
+ composited, never repainted. No scroll-driven animations, or reduced
+ motion asked for: no wisp, and nothing missing. */
+.wisp { display: none; }
+.wisp-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
+main { overflow-x: clip; }
+
+@supports (animation-timeline: view()) {
+ @media (prefers-reduced-motion: no-preference) {
+ /* Each band is the wisp's stage: it paints over the band's background
+ but under everything in it, so a wisp passes behind the words,
+ cards and buttons, never over them. */
+ .band { isolation: isolate; overflow: clip; }
+
+ h2[data-wisp] {
+ position: relative;
+ width: fit-content;
+ view-timeline: --wisp-head block;
+ animation: wisp-trigger linear both;
+ animation-timeline: --wisp-head;
+ animation-range: cover 0% cover 100%;
+ }
+ .wisp {
+ display: block;
+ position: absolute;
+ z-index: -1;
+ overflow: visible;
+ pointer-events: none;
+ color: var(--rst-accent);
+ opacity: 0;
+ will-change: opacity, transform;
+ }
+ /* The three boxes meet corner to corner, so one wisp runs through
+ them. The tails are pixel-sized, as package wisp draws them. */
+ .wisp-loop { left: -1.5em; top: -1.1em; width: calc(100% + 4em); height: calc(100% + 1.7em); }
+ .wisp-in { right: calc(100% + 1.5em); bottom: calc(100% + 1.1em); width: 1400px; height: 90px; }
+ .wisp-out { left: calc(100% + 2.5em); top: calc(100% + 0.6em); width: 1600px; height: 160px; }
+
+ /* Once the heading's switch reads running, each stretch lights and
+ lets go over 1.9s, the next starting 0.32s later, plus the
+ variant's own head start (wisp.Delay). Scroll back above the line
+ and the animation is withdrawn, ready to play again. */
+ @container style(--wisp-play: running) {
+ .wisp {
+ animation: wisp-pass 1.9s cubic-bezier(.33, 0, .25, 1) both;
+ animation-delay: calc(var(--wisp-i) * 0.32s + var(--wisp-d0));
+ }
+ }
+ }
+}
+.wisp:nth-of-type(1) { --wisp-i: 0; }
+.wisp:nth-of-type(2) { --wisp-i: 1; }
+.wisp:nth-of-type(3) { --wisp-i: 2; }
+.wisp:nth-of-type(4) { --wisp-i: 3; }
+.wisp:nth-of-type(5) { --wisp-i: 4; }
+.wisp:nth-of-type(6) { --wisp-i: 5; }
+.wisp:nth-of-type(7) { --wisp-i: 6; }
+[data-wisp="0"] { --wisp-d0: 0.05s; }
+[data-wisp="1"] { --wisp-d0: 0.15s; }
+[data-wisp="2"] { --wisp-d0: 0.3s; }
+[data-wisp="3"] { --wisp-d0: 0s; }
+[data-wisp="4"] { --wisp-d0: 0.25s; }
+
+/* The switch. Custom properties animate discretely: paused until the
+ heading is 30% of the way through its crossing of the screen, running
+ after (and still running once it has gone, so a played wisp stays
+ played). */
+@keyframes wisp-trigger {
+ 0%, 29.9% { --wisp-play: paused; }
+ 30%, 100% { --wisp-play: running; }
+}
+/* A stretch lights quickly and lets go slowly, so the wisp leaves a trail
+ behind its brightest point as it travels. 0.6 is Quiet. */
+@keyframes wisp-pass {
+ 0% { opacity: 0; transform: translate(-8px, -3px); }
+ 22% { opacity: 0.6; }
+ 100% { opacity: 0; transform: translate(8px, 3px); }
+}
diff --git a/internal/home/static/site/index.html b/internal/home/static/site/index.html
index d76f5d9..8722a1c 100644
--- a/internal/home/static/site/index.html
+++ b/internal/home/static/site/index.html
@@ -21,6 +21,7 @@
<link rel="stylesheet" href="/static/site/home.css">
</head>
<body>
+<!-- wisp:sprite -->
<a class="skip" href="#directory">Skip to the apps</a>
@@ -83,7 +84,7 @@
<section class="band" id="directory">
<div class="shell">
<div class="sec-head">
- <h2>Six apps, one family.</h2>
+ <h2 data-wisp="0">Six apps, one family.<!-- wisp:0 --></h2>
<p class="prose">Every app runs in the browser, five have a Mac app, and the iPhone apps are close.</p>
</div>
<ul class="family">
@@ -131,7 +132,7 @@
<section class="band band-quiet" id="memoria" data-app="memoria">
<div class="shell two">
<div>
- <h2>Introducing Memoria, your organisation&rsquo;s shared memory.</h2>
+ <h2 data-wisp="1">Introducing Memoria, your organisation&rsquo;s shared memory.<!-- wisp:1 --></h2>
<p class="prose">Every team keeps its answers in places nobody can search: an old thread,
a deck from March, the contract nobody re-read. Memoria holds your team&rsquo;s
documents and answers questions from them &mdash; and it shows you the passage
@@ -157,7 +158,7 @@
<section class="band" id="isolation">
<div class="shell two">
<div>
- <h2>Every team gets its own building.</h2>
+ <h2 data-wisp="2">Every team gets its own building.<!-- wisp:2 --></h2>
<p class="prose">Most suites put every customer in one enormous database and
separate you with a column. Oficina doesn&rsquo;t. Your team gets its own
instance, its own store and its own key, so isolation is a property of
@@ -187,7 +188,7 @@
<section class="band band-quiet" id="native">
<div class="shell">
<div class="sec-head">
- <h2>Native apps, not a browser in a costume.</h2>
+ <h2 data-wisp="3">Native apps, not a browser in a costume.<!-- wisp:3 --></h2>
<p class="prose">Five of the six edit the same documents as the web apps,
with native editors rather than an embedded web view. They launch fast, they
keep working when the connection drops, and they sync when it comes back.</p>
@@ -217,7 +218,7 @@
<section class="band" id="signup">
<div class="shell two">
<div>
- <h2>Oficina isn&rsquo;t open for sign-ups yet.</h2>
+ <h2 data-wisp="4">Oficina isn&rsquo;t open for sign-ups yet.<!-- wisp:4 --></h2>
<p class="prose">Creating a team still means one of us provisioning the
instance by hand, so there is no form here that would do anything. The
apps above are real and running, though, and Memoria is the one worth
diff --git a/internal/home/wisp/wisp.go b/internal/home/wisp/wisp.go
new file mode 100644
index 0000000..eee3179
--- /dev/null
+++ b/internal/home/wisp/wisp.go
@@ -0,0 +1,373 @@
+// Package wisp draws the front page's wisps: a filament from the hero's
+// nebula that drifts across the screen at each section heading — in from
+// off the left edge, round the heading, and away off the right edge.
+//
+// A wisp is smoke, not string: a wide soft glow, a brighter body, and four
+// to six fine fibres braiding through them, every one a filled outline
+// that thickens in the middle and thins to nothing at both ends, blurred
+// by an SVG filter. Each heading has its own variant, so no two match.
+//
+// Everything here is drawn once, into one SVG sprite of symbols (Sprite),
+// set into the page itself; each heading's wisp points into it (Markup).
+// Inline, not a separate cached file: Safari draws symbols from another
+// file but drops their filters, so every blur vanished and the wisps
+// turned into hard-edged bands.
+// The motion is CSS (the front page's home.css): each wisp is cut into
+// seven overlapping stretches, and the stretches are faded in and out in
+// turn, so only opacity and transform ever animate — composited, never
+// repainted.
+//
+// The variants, their braids and their glow widths were tuned by eye in
+// the design mock-ups (design-directions/wisp, build.py) and are carried
+// here as fixed numbers, so the page draws exactly what was approved.
+package wisp
+
+import (
+ "fmt"
+ "math"
+ "strings"
+ "sync"
+)
+
+type pt struct{ x, y float64 }
+
+// fibre is one strand: half-width, how far it wanders from the centre
+// line, how many times it wanders along a stretch, its phase, its opacity.
+type fibre struct{ hw, amp, cycles, phase, opacity float64 }
+
+type variant struct {
+ name string
+ loop []pt // round the heading, top-left corner to bottom-right
+ enter, leave float64 // the tails' heights at the screen's edges
+ stray string // "in" or "out": a strand that peels away there
+ shift int // a head start or lag, in twentieths of a second
+ fibres []fibre
+ glowBody [7][2]float64 // per stretch: the glow's and the body's half-widths
+}
+
+// The boxes, in viewBox units. The tails' boxes are pixel-sized (home.css),
+// so their widths and blurs are true; the loop's follows the heading, and
+// is shaped like a typical heading's to stay near 1:1.
+var (
+ loopBox = pt{1000, 190}
+ inBox = pt{1400, 90}
+ outBox = pt{1600, 160}
+)
+
+const sx, sy = 0.71, 0.6 // a typical heading's loop box, px per viewBox unit
+
+var variants = []variant{
+ {
+ name: "dip-and-rise", enter: 10, leave: 70, stray: "out", shift: -2,
+ loop: []pt{{0, 0}, {60, 70}, {180, 146}, {380, 160}, {560, 136}, {700, 70}, {820, 22}, {930, 30}, {985, 90}, {992, 150}, {1000, 190}},
+ fibres: []fibre{
+ {0.9194453711499528, 8.998041044693247, 2.874923332911433, 2.8465436197772616, 0.5108623216941499},
+ {0.5139412187844232, 8.62730218904734, 2.141831766901303, 3.867940654573994, 0.33026689511100454},
+ {0.667955891654199, 3.992565904816193, 2.2928644205864286, 5.609397099678683, 0.4513022513785041},
+ {0.7572619035044018, 5.773119835207644, 2.0871876773939584, 4.655170044884421, 0.4555191629567996},
+ {0.7738770709112319, 8.821911377449847, 1.1515958081403572, 0.22461251689726125, 0.5174825425842748},
+ },
+ glowBody: [7][2]float64{{17.869030417162957, 4.9162485283850055}, {14.149368203441966, 5.49862163374645}, {16.382816316208235, 3.763774181234161}, {14.40762965341738, 4.449011440369359}, {13.523289678955368, 5.389633287936679}, {16.58480447629008, 3.6753077101062317}, {14.742083403838693, 4.16554875761766}},
+ },
+ {
+ name: "curl-and-tuck", enter: 2, leave: 150, stray: "", shift: 0,
+ loop: []pt{{0, 0}, {130, 11}, {330, 29}, {560, 28}, {790, 23}, {930, 45}, {985, 90}, {950, 138}, {860, 164}, {770, 170}, {690, 162}, {668, 142}, {700, 124}, {790, 128}, {890, 157}, {1000, 190}},
+ fibres: []fibre{
+ {0.9354600064291476, 3.5848547378147853, 2.4208653445257644, 2.6696086718802565, 0.4231237627318618},
+ {0.47818176474848834, 4.343980102775049, 2.066976577295231, 1.3925467908904803, 0.4028588988888835},
+ {0.4148601804937411, 3.600418603933758, 2.704019680587784, 2.653864678169423, 0.41841115958593617},
+ {0.8405254472700974, 5.512974518503398, 1.1381308711581244, 4.933544843811176, 0.43906334034844136},
+ {0.7947476260599373, 7.346940185966469, 3.329764546189497, 2.2855928664120833, 0.4851423853057534},
+ },
+ glowBody: [7][2]float64{{14.816383634374912, 4.10230589380269}, {17.602132304066274, 3.9399286575166172}, {17.10815160293447, 4.935768143165508}, {12.729796173810602, 4.061209069036683}, {15.324653028784795, 4.408407069531941}, {13.101867305629467, 4.781556267720861}, {14.897329062202902, 3.7080779085553335}},
+ },
+ {
+ name: "weave", enter: 70, leave: 110, stray: "in", shift: 3,
+ loop: []pt{{0, 0}, {140, 8}, {320, 22}, {480, 60}, {600, 130}, {720, 166}, {860, 163}, {950, 130}, {985, 80}, {960, 40}, {905, 55}, {910, 110}, {955, 160}, {1000, 190}},
+ fibres: []fibre{
+ {0.7646540452164527, 9.547194587623435, 2.5970387609348276, 4.704879126382371, 0.4512953282077222},
+ {0.4212651593880562, 9.886099924032456, 2.050580654049252, 4.971400029804536, 0.5452772187024093},
+ {0.6741132345825509, 8.568762995105025, 3.220649827335587, 6.1303199316384545, 0.3942718353111067},
+ {0.4866386635286334, 8.601256525507507, 3.1669797808831204, 0.3119220768919083, 0.3915388761482478},
+ {0.7262013746287792, 9.50791886097006, 2.5557540006331125, 2.7238139242633035, 0.43870357403091026},
+ {0.6196963592135507, 7.936277061786937, 3.3290310925374613, 5.0846841060964705, 0.4472378279833185},
+ },
+ glowBody: [7][2]float64{{16.604840845882713, 5.2391856808423665}, {12.592720425674786, 4.304067940469753}, {17.672557786849104, 5.178733466382322}, {12.497712599953376, 4.175850193465255}, {16.601847608666407, 3.9224792350675743}, {12.652377775290686, 3.6916157842398505}, {14.788069760959797, 3.6297593927463465}},
+ },
+ {
+ name: "high-loop", enter: 0, leave: 130, stray: "", shift: -3,
+ loop: []pt{{0, 0}, {150, 20}, {380, 30}, {600, 20}, {760, 10}, {860, 25}, {900, 70}, {860, 105}, {800, 90}, {810, 50}, {880, 40}, {960, 80}, {990, 140}, {1000, 190}},
+ fibres: []fibre{
+ {0.5993348683299982, 9.948204816596634, 3.1648134335368887, 2.4294673162774427, 0.5220313359523998},
+ {0.5700746516275085, 4.937503477072778, 3.0447122108630693, 4.808496248211682, 0.28251861595307726},
+ {0.5494424789916619, 9.984907648526773, 1.0440009314905614, 5.977468202090347, 0.546399601403292},
+ {0.9879825669072703, 5.232189209554907, 1.6180315015552376, 4.3545818277513435, 0.437622581094986},
+ {0.47189123385093046, 7.114289553694752, 2.0382338082830613, 1.7755670934810406, 0.4784041344991759},
+ },
+ glowBody: [7][2]float64{{15.68682257205295, 4.012732175493016}, {16.861213916195993, 5.0477096674663064}, {15.950982475061341, 4.5222458926817986}, {14.789900563204064, 4.9256848713644885}, {16.213590003158465, 5.299547822380571}, {15.145140951103027, 3.7795061572239073}, {14.112489128169598, 4.9404515620651654}},
+ },
+ {
+ name: "open-arc", enter: 60, leave: 40, stray: "out", shift: 2,
+ loop: []pt{{0, 0}, {200, 10}, {450, 15}, {700, 22}, {880, 50}, {960, 100}, {985, 150}, {1000, 190}},
+ fibres: []fibre{
+ {0.9119236047125096, 4.5123737990514226, 2.2049529977692024, 3.0409836970491866, 0.47383438922875487},
+ {0.616423438789726, 6.1824945442097405, 1.0749177072916019, 5.853237387774827, 0.5260559016891486},
+ {0.9865271121128315, 5.40633452853273, 1.3176759230076913, 5.549511542002782, 0.29514103670190284},
+ {0.4281286583553424, 4.603771083700763, 1.4756945472147724, 0.7971407374043049, 0.37482430060979605},
+ {0.8592105298356515, 8.96374100616438, 2.2277593373108653, 2.5403834774078455, 0.5341465616589269},
+ {0.599372817330031, 4.072545257460819, 2.8853556813707173, 3.4841196648727495, 0.38451654723767104},
+ },
+ glowBody: [7][2]float64{{12.672113021893889, 4.645730216648505}, {14.876703440749925, 3.6679764311793965}, {15.31219574248183, 4.3980766510654945}, {13.956458933133801, 4.010995329861434}, {15.886388361749637, 4.326108843030688}, {16.55489732524959, 4.033458698025226}, {12.745203181764076, 3.6941444767458096}},
+ },
+}
+
+// Count is how many variants there are: one per section heading.
+var Count = len(variants)
+
+// stretches are the overlapping lengths of each piece, in the order they
+// light: piece, start, length (fractions of the piece's length).
+var stretches = []struct {
+ piece string
+ start, length float64
+}{
+ {"in", 0, 0.62}, {"in", 0.38, 0.62}, {"loop", 0, 0.42}, {"loop", 0.3, 0.42},
+ {"loop", 0.6, 0.4}, {"out", 0, 0.62}, {"out", 0.38, 0.62},
+}
+
+// Stretches is how many stretches each wisp has.
+var Stretches = len(stretches)
+
+// ── Geometry ────────────────────────────────────────────────────────────
+
+type bez struct{ p1, c1, c2, p2 pt }
+
+// chain is Catmull-Rom through pts, as cubic Bezier segments.
+func chain(pts []pt) []bez {
+ var segs []bez
+ n := len(pts)
+ for i := 0; i < n-1; i++ {
+ p0, p1, p2, p3 := pts[max(i-1, 0)], pts[i], pts[i+1], pts[min(i+2, n-1)]
+ segs = append(segs, bez{p1,
+ pt{p1.x + (p2.x-p0.x)/6, p1.y + (p2.y-p0.y)/6},
+ pt{p2.x - (p3.x-p1.x)/6, p2.y - (p3.y-p1.y)/6}, p2})
+ }
+ return segs
+}
+
+type curve struct {
+ pts []pt
+ acc []float64 // cumulative arc length at each point
+}
+
+// sample is dense points along the curve through pts, with arc length.
+func sample(pts []pt) curve {
+ per := 600 / (len(pts) - 1)
+ var out []pt
+ for _, s := range chain(pts) {
+ for k := 0; k < per; k++ {
+ t := float64(k) / float64(per)
+ u := 1 - t
+ out = append(out, pt{
+ u*u*u*s.p1.x + 3*u*u*t*s.c1.x + 3*u*t*t*s.c2.x + t*t*t*s.p2.x,
+ u*u*u*s.p1.y + 3*u*u*t*s.c1.y + 3*u*t*t*s.c2.y + t*t*t*s.p2.y})
+ }
+ }
+ out = append(out, pts[len(pts)-1])
+ acc := []float64{0}
+ for i := 1; i < len(out); i++ {
+ acc = append(acc, acc[i-1]+math.Hypot(out[i].x-out[i-1].x, out[i].y-out[i-1].y))
+ }
+ return curve{out, acc}
+}
+
+// station is a point on a stretch: where it is, the unit normal there,
+// and the radius of the turn the curve is making.
+type station struct{ x, y, nx, ny, radius float64 }
+
+// stretchLine is k stations evenly along [start, start+length] of c.
+func stretchLine(c curve, start, length float64, k int) []station {
+ total := c.acc[len(c.acc)-1]
+ res := make([]station, k)
+ j := 0
+ for i := 0; i < k; i++ {
+ s := (start + length*float64(i)/float64(k-1)) * total
+ for j < len(c.acc)-2 && c.acc[j+1] < s {
+ j++
+ }
+ f := (s - c.acc[j]) / math.Max(c.acc[j+1]-c.acc[j], 1e-9)
+ a, b := c.pts[j], c.pts[j+1]
+ dx, dy := b.x-a.x, b.y-a.y
+ m := math.Hypot(dx, dy)
+ if m == 0 {
+ m = 1
+ }
+ res[i] = station{a.x + dx*f, a.y + dy*f, -dy / m, dx / m, 0}
+ }
+ // The local radius of the turn, from how fast the direction changes;
+ // ribbon keeps every outline inside it.
+ step := length * total / float64(k-1)
+ for i := range res {
+ a, b := res[max(i-1, 0)], res[min(i+1, k-1)]
+ turn := math.Abs(math.Atan2(a.nx*b.ny-a.ny*b.nx, a.nx*b.nx+a.ny*b.ny))
+ span := step * float64(min(i+1, k-1)-max(i-1, 0))
+ res[i].radius = 1e9
+ if turn > 1e-6 {
+ res[i].radius = span / turn
+ }
+ }
+ return res
+}
+
+// ribbon is a filled outline round line, its half-width and sideways
+// offset varying along it, as path data in relative whole-unit steps.
+func ribbon(line []station, halfWidth, offset func(u float64) float64) string {
+ k := len(line)
+ left := make([]pt, k)
+ right := make([]pt, k)
+ for i, s := range line {
+ u := float64(i) / float64(k-1)
+ w, o := halfWidth(u), offset(u)
+ // In a turn tighter than the shape is wide, the outline would fold
+ // back over itself into a hard corner: shrink it to fit the turn.
+ fit := math.Min(1, 0.75*s.radius/(math.Abs(o)+w+1e-6))
+ w, o = w*fit, o*fit
+ left[i] = pt{s.x + s.nx*(o+w), s.y + s.ny*(o+w)}
+ right[i] = pt{s.x + s.nx*(o-w), s.y + s.ny*(o-w)}
+ }
+ ring := left
+ for i := k - 1; i >= 0; i-- {
+ ring = append(ring, right[i])
+ }
+ var d strings.Builder
+ px, py := round(ring[0].x), round(ring[0].y)
+ fmt.Fprintf(&d, "M%d %dl", px, py)
+ for i, p := range ring[1:] {
+ x, y := round(p.x), round(p.y)
+ if i > 0 {
+ d.WriteByte(' ')
+ }
+ fmt.Fprintf(&d, "%d %d", x-px, y-py)
+ px, py = x, y
+ }
+ d.WriteByte('z')
+ return d.String()
+}
+
+func round(f float64) int { return int(math.RoundToEven(f)) }
+
+func taper(u, p float64) float64 { return math.Pow(math.Sin(math.Pi*u), p) }
+
+func zero(float64) float64 { return 0 }
+
+// slope is a->b's slope in pixels, at a typical heading's scale.
+func slope(a, b pt) float64 { return ((b.y - a.y) * sy) / math.Max((b.x-a.x)*sx, 1e-6) }
+
+// tailIn comes in from off the left edge at height enter, arriving on the
+// loop's own heading so the two join without a kink.
+func tailIn(v variant) []pt {
+ w, h := inBox.x, inBox.y
+ k := math.Min(slope(v.loop[0], v.loop[1]), 0.9)
+ y0 := v.enter
+ return []pt{{0, y0}, {w * 0.3, y0 + (h-y0)*0.08}, {w * 0.62, y0 + (h-y0)*0.3},
+ {w - 260, h - 260*k*0.55}, {w - 110, h - 110*k}, {w, h}}
+}
+
+// tailOut leaves the loop on its own heading and levels off at height
+// leave, off the right edge.
+func tailOut(v variant) []pt {
+ w := outBox.x
+ n := len(v.loop)
+ k := math.Min(slope(v.loop[n-2], v.loop[n-1]), 1.2)
+ y1 := v.leave
+ return []pt{{0, 0}, {90, 90 * k}, {260, 260*k*0.6 + y1*0.1}, {560, y1 * 0.75}, {1000, y1 * 0.95}, {w, y1}}
+}
+
+// ── The sprite ──────────────────────────────────────────────────────────
+
+func symbolID(vi, i int) string { return fmt.Sprintf("wisp-v%d-s%d", vi, i) }
+
+func symbol(vi int, v variant, curves map[string]curve, i int) string {
+ s := stretches[i]
+ box := map[string]pt{"in": inBox, "loop": loopBox, "out": outBox}[s.piece]
+ k := 34
+ if s.piece == "loop" {
+ k = 84
+ }
+ line := stretchLine(curves[s.piece], s.start, s.length, k)
+ glow, body := v.glowBody[i][0], v.glowBody[i][1]
+ var b strings.Builder
+ fmt.Fprintf(&b, `<symbol id="%s" viewBox="0 0 %g %g" preserveAspectRatio="none" overflow="visible">`, symbolID(vi, i), box.x, box.y)
+ shape := func(opacity, filter, d string) {
+ fmt.Fprintf(&b, `<path fill="currentColor" opacity="%s" filter="url(#wisp-%s)" d="%s"/>`, opacity, filter, d)
+ }
+ // The glow, a wide and very soft band of light; the body, a narrower,
+ // brighter haze along the middle.
+ shape("0.16", "glow", ribbon(line, func(u float64) float64 { return glow * taper(u, 0.7) }, zero))
+ shape("0.3", "body", ribbon(line, func(u float64) float64 { return body * taper(u, 0.9) }, zero))
+ // The fibres, braiding in and out of one another; no two stretches alike.
+ for _, f := range v.fibres {
+ f, ph := f, f.phase+float64(i)*0.9
+ shape(fmt.Sprintf("%.2f", f.opacity), "fibre", ribbon(line,
+ func(u float64) float64 { return f.hw * taper(u, 1.2) },
+ func(u float64) float64 { return f.amp * math.Sin(2*math.Pi*f.cycles*u+ph) * taper(u, 0.5) }))
+ }
+ // A stray: one strand that peels away from the rest and fades, on the
+ // first stretch in or the last stretch out.
+ if (v.stray == "in" && i == 0) || (v.stray == "out" && i == len(stretches)-1) {
+ peel := func(u float64) float64 { return 26 * u * u }
+ if i == 0 {
+ peel = func(u float64) float64 { return -26 * (1 - u) * (1 - u) }
+ }
+ shape("0.32", "fibre", ribbon(line, func(u float64) float64 { return 0.6 * taper(u, 1.0) }, peel))
+ }
+ b.WriteString("</symbol>")
+ return b.String()
+}
+
+var (
+ spriteOnce sync.Once
+ sprite []byte
+)
+
+// Sprite is every wisp, as one SVG of symbols with the blurs they share,
+// to set into the page: it takes no space and is hidden from assistive
+// technology. Deterministic: the same bytes on every start.
+func Sprite() []byte {
+ spriteOnce.Do(func() {
+ var b strings.Builder
+ b.WriteString(`<svg class="wisp-defs" width="0" height="0" aria-hidden="true" focusable="false">`)
+ // In user space with a generous region, so a thin shape's blur is
+ // never clipped to its own bounding box.
+ for _, f := range []struct {
+ name string
+ sd float64
+ }{{"glow", 9}, {"body", 3}, {"fibre", 0.8}} {
+ fmt.Fprintf(&b, `<filter id="wisp-%s" filterUnits="userSpaceOnUse" x="-200" y="-200" width="2200" height="600"><feGaussianBlur stdDeviation="%g"/></filter>`, f.name, f.sd)
+ }
+ for vi, v := range variants {
+ curves := map[string]curve{"in": sample(tailIn(v)), "loop": sample(v.loop), "out": sample(tailOut(v))}
+ for i := range stretches {
+ b.WriteString(symbol(vi, v, curves, i))
+ }
+ }
+ b.WriteString("</svg>\n")
+ sprite = []byte(b.String())
+ })
+ return sprite
+}
+
+// Markup is the wisp for the heading it sits in: its seven stretches, each
+// an empty SVG pointing at its symbol in the page's sprite. The heading
+// carries data-wisp, which home.css reads for the variant's timing; the
+// stretches' order is their order here.
+func Markup(variant int) string {
+ var b strings.Builder
+ for i, s := range stretches {
+ fmt.Fprintf(&b, `<svg class="wisp wisp-%s" aria-hidden="true" focusable="false"><use href="#%s"/></svg>`,
+ s.piece, symbolID(variant, i))
+ }
+ return b.String()
+}
+
+// Delay is the variant's head start or lag, in seconds, for home.css.
+func Delay(variant int) float64 { return float64(variants[variant].shift+3) * 5 / 100 }
diff --git a/internal/home/wisp/wisp_test.go b/internal/home/wisp/wisp_test.go
new file mode 100644
index 0000000..e646756
--- /dev/null
+++ b/internal/home/wisp/wisp_test.go
@@ -0,0 +1,91 @@
+package wisp
+
+import (
+ "bytes"
+ "regexp"
+ "strings"
+ "sync"
+ "testing"
+)
+
+// The sprite is the same bytes every time: its content version, and so
+// every browser's cached copy, must survive a restart and a release that
+// does not touch the wisps.
+func TestSpriteIsDeterministic(t *testing.T) {
+ a := string(Sprite())
+ spriteOnce, sprite = sync.Once{}, nil
+ if b := string(Sprite()); a != b {
+ t.Fatal("two draws of the sprite differ")
+ }
+}
+
+// Every stretch of every variant is in the sprite, drawn (a glow, a body
+// and at least four fibres), and finite: a NaN in path data draws nothing
+// and fails silently in the browser.
+func TestSpriteHasEveryStretch(t *testing.T) {
+ s := string(Sprite())
+ for v := 0; v < Count; v++ {
+ for i := 0; i < Stretches; i++ {
+ id := symbolID(v, i)
+ start := strings.Index(s, `<symbol id="`+id+`"`)
+ if start < 0 {
+ t.Fatalf("sprite lacks %s", id)
+ }
+ end := strings.Index(s[start:], "</symbol>")
+ sym := s[start : start+end]
+ if n := strings.Count(sym, "<path "); n < 6 {
+ t.Errorf("%s has %d shapes, want a glow, a body and 4+ fibres", id, n)
+ }
+ for _, f := range []string{"url(#wisp-glow)", "url(#wisp-body)", "url(#wisp-fibre)"} {
+ if !strings.Contains(sym, f) {
+ t.Errorf("%s draws nothing with %s", id, f)
+ }
+ }
+ }
+ }
+ if strings.Contains(s, "NaN") || strings.Contains(s, "Inf") {
+ t.Fatal("sprite has a non-finite coordinate")
+ }
+ for _, f := range []string{"glow", "body", "fibre"} {
+ if !strings.Contains(s, `<filter id="wisp-`+f+`"`) {
+ t.Errorf("sprite lacks the %s blur", f)
+ }
+ }
+}
+
+// The variants differ: the point of having five. Each stretch of each
+// variant draws something no other variant's same stretch does.
+func TestVariantsDiffer(t *testing.T) {
+ s := Sprite()
+ body := func(v, i int) []byte {
+ start := bytes.Index(s, []byte(`<symbol id="`+symbolID(v, i)+`"`))
+ end := bytes.Index(s[start:], []byte("</symbol>"))
+ return regexp.MustCompile(`id="[^"]*"`).ReplaceAll(s[start:start+end], nil)
+ }
+ for i := 0; i < Stretches; i++ {
+ for a := 0; a < Count; a++ {
+ for b := a + 1; b < Count; b++ {
+ if bytes.Equal(body(a, i), body(b, i)) {
+ t.Errorf("variants %d and %d draw stretch %d identically", a, b, i)
+ }
+ }
+ }
+ }
+}
+
+// Markup points at exactly the variant's seven symbols, in order.
+func TestMarkupPointsIntoTheSprite(t *testing.T) {
+ m := Markup(2)
+ uses := regexp.MustCompile(`<use href="([^"]+)"/>`).FindAllStringSubmatch(m, -1)
+ if len(uses) != Stretches {
+ t.Fatalf("%d stretches, want %d", len(uses), Stretches)
+ }
+ for i, u := range uses {
+ if want := "#" + symbolID(2, i); u[1] != want {
+ t.Errorf("stretch %d points at %q, want %q", i, u[1], want)
+ }
+ }
+ if strings.Count(m, `aria-hidden="true"`) != Stretches {
+ t.Error("a stretch is not hidden from assistive technology")
+ }
+}
diff --git a/internal/home/wisp_test.go b/internal/home/wisp_test.go
new file mode 100644
index 0000000..2ede848
--- /dev/null
+++ b/internal/home/wisp_test.go
@@ -0,0 +1,58 @@
+package home
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/home/internal/home/wisp"
+)
+
+// The front page as served: the drawing is in the page once, every
+// section heading carries its own wisp, every stretch points at a symbol
+// the drawing has — and no marker is left.
+func TestFrontPageWispsPointIntoTheDrawing(t *testing.T) {
+ f := newMountedChooser(t)
+ page := f.request("GET", "/", "", "", nil).Body.String()
+ if strings.Contains(page, "<!-- wisp:") {
+ t.Fatal("a wisp marker was not replaced")
+ }
+ if n := strings.Count(page, `<svg class="wisp-defs"`); n != 1 {
+ t.Fatalf("the wisps' drawing is in the page %d times, want once", n)
+ }
+ heads := regexp.MustCompile(`<h2 data-wisp="(\d+)">`).FindAllStringSubmatch(page, -1)
+ if len(heads) != wisp.Count {
+ t.Fatalf("%d headings carry a wisp, want one per variant (%d)", len(heads), wisp.Count)
+ }
+ uses := regexp.MustCompile(`<use href="#([^"]+)"/>`).FindAllStringSubmatch(page, -1)
+ if len(uses) != wisp.Count*wisp.Stretches {
+ t.Fatalf("%d wisp stretches on the page, want %d", len(uses), wisp.Count*wisp.Stretches)
+ }
+ for _, u := range uses {
+ if !strings.Contains(page, `<symbol id="`+u[1]+`"`) {
+ t.Errorf("a stretch points at %s, which the drawing lacks", u[1])
+ }
+ }
+}
+
+// home.css times each heading's wisp by its variant: the head starts it
+// declares are package wisp's, so the drawing and its timing cannot drift.
+func TestFrontPageWispTimingIsTheVariants(t *testing.T) {
+ css := string(siteAsset("home.css"))
+ for v := 0; v < wisp.Count; v++ {
+ want := fmt.Sprintf(`[data-wisp="%d"] { --wisp-d0: %gs; }`, v, wisp.Delay(v))
+ if !strings.Contains(css, want) {
+ t.Errorf("home.css lacks %s", want)
+ }
+ }
+ for i := 0; i < wisp.Stretches; i++ {
+ if want := fmt.Sprintf(".wisp:nth-of-type(%d) { --wisp-i: %d; }", i+1, i); !strings.Contains(css, want) {
+ t.Errorf("home.css lacks %s", want)
+ }
+ }
+ // Reduced motion and no scroll timelines both mean no wisp at all.
+ if !strings.Contains(css, ".wisp { display: none; }") || !strings.Contains(css, "@media (prefers-reduced-motion: no-preference)") {
+ t.Error("the wisp is not hidden by default and shown only where motion is welcome")
+ }
+}