Back to Top
A round button that shows up a screen down, its ring filling as you read. Its label unrolls on hover, the arrow takes off when you click.
View codeA figure pinned in a corner of a long page. Each section carries its value, and as you read, the figure rolls to it digit by digit, with its unit, a note and a scale of the whole story.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Add the Kodza Scroll Gauge to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-scroll-gauge" data-kodza-scroll-gauge data-label="Temperature" data-unit="°C">
<section class="kodza-scroll-gauge__section" data-gauge="4" data-gauge-note="Cold room">
<p class="kodza-scroll-gauge__time">21:00</p>
<h2 class="kodza-scroll-gauge__title">The dough sleeps.</h2>
<p class="kodza-scroll-gauge__text">Twelve hours at four degrees and nobody touches it. Flavour is just time you did not rush.</p>
</section>
<section class="kodza-scroll-gauge__section" data-gauge="26" data-gauge-note="Shaping bench">
<p class="kodza-scroll-gauge__time">04:00</p>
<h2 class="kodza-scroll-gauge__title">Hands, flour, no playlist.</h2>
<p class="kodza-scroll-gauge__text">The bench is warm and the dough wakes up. Shape it before it makes plans of its own.</p>
</section>
<section class="kodza-scroll-gauge__section" data-gauge="290" data-gauge-note="Oven floor">
<p class="kodza-scroll-gauge__time">05:10</p>
<h2 class="kodza-scroll-gauge__title">Stone, steam, no mercy.</h2>
<p class="kodza-scroll-gauge__text">A wood-fired oven, lit at midnight. Twenty-five minutes, one cloud of steam, and a crust that crackles as it cools.</p>
</section>
<section class="kodza-scroll-gauge__section" data-gauge="96" data-gauge-note="Inside the crumb">
<p class="kodza-scroll-gauge__time">05:35</p>
<h2 class="kodza-scroll-gauge__title">Done is a number.</h2>
<p class="kodza-scroll-gauge__text">Not “golden brown”, not hollow when you knock. A probe in the middle says 96 and the debate is over.</p>
</section>
<section class="kodza-scroll-gauge__section" data-gauge="36.5" data-gauge-note="Your hand">
<p class="kodza-scroll-gauge__time">07:00</p>
<h2 class="kodza-scroll-gauge__title">Still warm. Yours now.</h2>
<p class="kodza-scroll-gauge__text">The shop opens at seven. Ninety minutes out of the oven, the loaf is the temperature of the hand holding it.</p>
</section>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Scroll Gauge
A real figure pinned in a corner of a long page. Each section carries its value; once you
read it, the figure rolls there digit by digit like an odometer (up when it climbs, down when
it falls), its note rolls with it and a needle slides along the scale of the whole story.
The dial rides along at the bottom of the screen and leaves with the end of the story.
Everything is tuned with the --kz-scroll-gauge-* variables. */
.kodza-scroll-gauge {
--kz-scroll-gauge-fg: #0a0a0a;
--kz-scroll-gauge-muted: rgba(10, 10, 10, 0.62);
--kz-scroll-gauge-line: rgba(10, 10, 10, 0.1); /* the dial's edge and the rules between sections */
--kz-scroll-gauge-rule: rgba(10, 10, 10, 0.24); /* the scale and its ticks */
--kz-scroll-gauge-glass: rgba(255, 255, 255, 0.78);
--kz-scroll-gauge-shadow: 0 1px 2px rgba(10, 10, 10, 0.04), 0 14px 32px -14px rgba(10, 10, 10, 0.22);
--kz-scroll-gauge-size: 48px; /* the figure */
--kz-scroll-gauge-width: 208px; /* the narrowest the dial gets; a longer figure widens it */
--kz-scroll-gauge-inset: 24px; /* from the bottom of the screen */
--kz-scroll-gauge-side: 0px; /* from the side of the story (left, or right with data-side="right") */
--kz-scroll-gauge-radius: calc(14px * var(--kz-radius-scale, 1));
--kz-scroll-gauge-z: 20;
--kz-scroll-gauge-section: 560px; /* the least height of a section */
--kz-scroll-gauge-in: 0.6s; /* the dial coming in; the figure rolls in the script's time */
--kz-scroll-gauge-out: 0.4s; /* and going away */
--kz-scroll-gauge-ease: cubic-bezier(0.22, 1, 0.36, 1);
--kz-scroll-gauge-ease-out: cubic-bezier(0.65, 0, 0.35, 1);
color: var(--kz-scroll-gauge-fg);
}
/* The story: a rule, the time on the left, the words on the right */
.kodza-scroll-gauge__section {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
gap: 16px 64px;
align-content: start;
box-sizing: border-box;
min-height: var(--kz-scroll-gauge-section);
padding: 28px 0 64px;
border-top: 1px solid var(--kz-scroll-gauge-line);
}
.kodza-scroll-gauge__time {
margin: 0;
padding-top: 0.5em;
font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, 400);
line-height: var(--kz-font-label-leading, 1.4);
letter-spacing: var(--kz-font-label-tracking, normal);
text-transform: var(--kz-font-label-case, none);
color: var(--kz-scroll-gauge-muted);
}
.kodza-scroll-gauge__title {
margin: 0;
font-family: var(--kz-font-display, inherit);
font-size: calc(clamp(30px, 4vw, 52px) * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
line-height: 1.02;
letter-spacing: var(--kz-font-display-tracking, -0.045em);
text-transform: var(--kz-font-display-case, inherit);
text-wrap: balance;
}
.kodza-scroll-gauge__text {
grid-column: 2;
max-width: 30em;
margin: 4px 0 0;
font-size: 17px;
line-height: 1.55;
color: var(--kz-scroll-gauge-muted);
text-wrap: pretty;
}
/* The dial, on a rail of no height pinned to the bottom of the screen: it rides along while the
story scrolls, and goes up with the end of it */
.kodza-scroll-gauge__rail {
position: sticky;
bottom: var(--kz-scroll-gauge-inset);
z-index: var(--kz-scroll-gauge-z);
height: 0;
pointer-events: none;
}
/* A shutter: it opens from its bottom edge up, and closes back down. The clip leaves room for
the shadow */
.kodza-scroll-gauge__dial {
position: absolute;
bottom: 0;
left: var(--kz-scroll-gauge-side);
display: flex;
flex-direction: column;
box-sizing: border-box;
min-width: var(--kz-scroll-gauge-width);
padding: 13px 18px 16px;
border: 1px solid var(--kz-scroll-gauge-line);
border-radius: var(--kz-scroll-gauge-radius);
background: var(--kz-scroll-gauge-glass);
-webkit-backdrop-filter: blur(14px) saturate(1.3);
backdrop-filter: blur(14px) saturate(1.3);
box-shadow: var(--kz-scroll-gauge-shadow);
color: var(--kz-scroll-gauge-fg);
clip-path: inset(calc(100% + 48px) -48px -48px -48px);
transition: clip-path calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}
.kodza-scroll-gauge[data-side="right"] .kodza-scroll-gauge__dial {
right: var(--kz-scroll-gauge-side);
left: auto;
}
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__dial {
clip-path: inset(-48px);
transition: clip-path calc(var(--kz-scroll-gauge-in) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease);
}
/* What it measures, in small type, rising from behind its line */
.kodza-scroll-gauge__label {
display: block;
overflow: hidden;
overflow: clip;
font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, 400);
line-height: var(--kz-font-label-leading, 1.4);
letter-spacing: var(--kz-font-label-tracking, normal);
text-transform: var(--kz-font-label-case, none);
white-space: nowrap;
color: var(--kz-scroll-gauge-muted);
}
.kodza-scroll-gauge__label .kodza-scroll-gauge__in,
.kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
display: block;
transform: translateY(110%);
transition: transform calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__label .kodza-scroll-gauge__in,
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
transform: none;
transition: transform calc(var(--kz-scroll-gauge-in) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease) calc(0.08s * var(--kz-motion-scale, 1));
}
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
transition-delay: calc(0.16s * var(--kz-motion-scale, 1));
}
/* The figure and its unit */
.kodza-scroll-gauge__reading {
display: flex;
align-items: flex-start;
margin-top: 4px;
font-family: var(--kz-font-display, inherit);
font-size: calc(var(--kz-scroll-gauge-size) * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
line-height: 1.1;
letter-spacing: var(--kz-font-display-tracking, -0.045em);
text-transform: var(--kz-font-display-case, inherit);
}
.kodza-scroll-gauge__figure {
position: relative;
display: flex;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
white-space: nowrap;
}
/* One slot per character: a digit spins in its window, an unused one closes to no width */
.kodza-scroll-gauge__digit,
.kodza-scroll-gauge__char {
position: relative;
display: block;
flex: none;
width: 0.62em;
height: 1.1em;
overflow: hidden;
overflow: clip;
text-align: center;
transition:
width calc(0.6s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease),
opacity calc(0.6s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease);
}
/* A slot closing fades with its width, so no half digit is left at its edge */
.kodza-scroll-gauge__digit.is-closed,
.kodza-scroll-gauge__char.is-closed {
opacity: 0;
}
.kodza-scroll-gauge__strip {
position: absolute;
top: 0;
right: 0;
left: 0;
}
.kodza-scroll-gauge__cell {
display: block;
height: 1.1em;
}
/* Measures the widest digit in the page's own font, then leaves */
.kodza-scroll-gauge__probe {
position: absolute;
top: 0;
left: 0;
visibility: hidden;
white-space: nowrap;
}
.kodza-scroll-gauge__unit {
display: block;
overflow: hidden;
overflow: clip;
margin: 0.22em 0 0 0.16em;
font-size: 0.4em;
font-weight: 500;
line-height: 1.2;
letter-spacing: 0;
text-transform: none;
white-space: nowrap;
color: var(--kz-scroll-gauge-muted);
}
/* The note of the section being read: every note in one cell, so the dial keeps its width */
.kodza-scroll-gauge__note {
display: grid;
overflow: hidden;
overflow: clip;
margin-top: 2px;
font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, 400);
line-height: var(--kz-font-label-leading, 1.4);
letter-spacing: var(--kz-font-label-tracking, normal);
text-transform: var(--kz-font-label-case, none);
}
.kodza-scroll-gauge__line {
grid-area: 1 / 1;
white-space: nowrap;
transform: translateY(110%);
}
.kodza-scroll-gauge__line.is-current {
transform: none;
}
/* The scale of the whole story: a tick for each section, the needle on the one being read. It
draws itself from the left as the dial comes in */
.kodza-scroll-gauge__scale {
position: relative;
height: 9px;
margin-top: 12px;
clip-path: inset(0 100% 0 0);
transition: clip-path calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__scale {
clip-path: inset(0);
transition: clip-path calc(0.9s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease) calc(0.1s * var(--kz-motion-scale, 1));
}
.kodza-scroll-gauge__track {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 1px;
background: var(--kz-scroll-gauge-rule);
}
.kodza-scroll-gauge__stop {
position: absolute;
bottom: 0;
width: 1px;
height: 5px;
background: var(--kz-scroll-gauge-rule);
}
/* The needle moves across its own width (the scale less its 2 px), so 100% is the far end */
.kodza-scroll-gauge__needle {
position: absolute;
bottom: 0;
left: 0;
width: calc(100% - 2px);
height: 100%;
}
.kodza-scroll-gauge__tick {
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: 100%;
background: var(--kz-scroll-gauge-fg);
}
/* What the dial says, for screen readers */
.kodza-scroll-gauge__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
@media (max-width: 720px) {
.kodza-scroll-gauge {
--kz-scroll-gauge-size: 36px;
--kz-scroll-gauge-width: 172px;
--kz-scroll-gauge-inset: 16px;
--kz-scroll-gauge-section: 480px;
}
.kodza-scroll-gauge__section {
grid-template-columns: minmax(0, 1fr);
gap: 12px;
padding-bottom: 48px;
}
.kodza-scroll-gauge__text {
grid-column: auto;
font-size: 16px;
}
.kodza-scroll-gauge__dial {
padding: 11px 14px 13px;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-scroll-gauge *,
.kodza-scroll-gauge *::before,
.kodza-scroll-gauge *::after {
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
/* Dark mode: set the colours on the root, for instance
.dark .kodza-scroll-gauge {
--kz-scroll-gauge-fg: #f2f2f0;
--kz-scroll-gauge-muted: rgba(242, 242, 240, 0.62);
--kz-scroll-gauge-line: rgba(255, 255, 255, 0.14);
--kz-scroll-gauge-rule: rgba(255, 255, 255, 0.3);
--kz-scroll-gauge-glass: rgba(22, 22, 22, 0.72);
--kz-scroll-gauge-shadow: 0 14px 32px -14px rgba(0, 0, 0, 0.6);
} */
/* kodza-guard 7194bfa037ff — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */
:where(.kodza-scroll-gauge__time):not(#_),
:where(.kodza-scroll-gauge__title):not(#_),
:where(.kodza-scroll-gauge__text):not(#_) {
transition-duration: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-scroll-gauge:not(#_),
.kodza-scroll-gauge__rail:not(#_),
.kodza-scroll-gauge__label:not(#_),
.kodza-scroll-gauge__in:not(#_),
.kodza-scroll-gauge__reading:not(#_),
.kodza-scroll-gauge__figure:not(#_),
.kodza-scroll-gauge__digit:not(#_),
.kodza-scroll-gauge__strip:not(#_),
.kodza-scroll-gauge__cell:not(#_),
.kodza-scroll-gauge__char:not(#_),
.kodza-scroll-gauge__unit:not(#_),
.kodza-scroll-gauge__note:not(#_),
.kodza-scroll-gauge__line:not(#_),
.kodza-scroll-gauge__scale:not(#_),
.kodza-scroll-gauge__track:not(#_),
.kodza-scroll-gauge__stop:not(#_),
.kodza-scroll-gauge__needle:not(#_),
.kodza-scroll-gauge__tick:not(#_),
.kodza-scroll-gauge__sr:not(#_) {
box-sizing: revert;
}
.kodza-scroll-gauge__time:not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
padding-right: revert;
padding-bottom: revert;
padding-left: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-scroll-gauge__title:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-style: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-scroll-gauge__text:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-height: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-scroll-gauge__time:not(#_):where(:not([hidden])),
.kodza-scroll-gauge__title:not(#_):where(:not([hidden])),
.kodza-scroll-gauge__text:not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-scroll-gauge__time:not(#_):where([hidden]),
.kodza-scroll-gauge__title:not(#_):where([hidden]),
.kodza-scroll-gauge__text:not(#_):where([hidden]) {
display: none;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-scroll-gauge__time:not(#_) {
margin: 0;
padding-top: 0.5em;
font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, 400);
line-height: var(--kz-font-label-leading, 1.4);
letter-spacing: var(--kz-font-label-tracking, normal);
text-transform: var(--kz-font-label-case, none);
color: var(--kz-scroll-gauge-muted);
}
.kodza-scroll-gauge__title:not(#_) {
margin: 0;
font-family: var(--kz-font-display, inherit);
font-size: calc(clamp(30px, 4vw, 52px) * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
line-height: 1.02;
letter-spacing: var(--kz-font-display-tracking, -0.045em);
text-transform: var(--kz-font-display-case, inherit);
}
.kodza-scroll-gauge__text:not(#_) {
max-width: 30em;
margin: 4px 0 0;
font-size: 17px;
line-height: 1.55;
color: var(--kz-scroll-gauge-muted);
}
@media (max-width: 720px) {
.kodza-scroll-gauge__text:not(#_) {
font-size: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-scroll-gauge *:where(p, h2):not(#_) {
transition-duration: 0.01ms !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Scroll Gauge
// A real figure pinned in a corner that follows the reading. Each section carries its value
// (data-gauge="290", a plain number with a dot for decimals: "36.5" keeps one) and, if you like,
// a note (data-gauge-note="Oven floor"). Once a section's top passes the reading line, the figure
// rolls to its value digit by digit, like an odometer: up when the value climbs, down when it
// falls, and the needle slides along the scale of the whole story.
// On the root: data-label (what it measures), data-unit, data-side="right" for the right corner,
// data-grouping for thousands separators (an amount has them, a year does not).
// Settings: the --kz-scroll-gauge-* variables in the CSS, and the constants below.
(() => {
const SELECTOR = '[data-kodza-scroll-gauge]';
const LINE = 0.6; // the reading line, from the top of the screen (0 to 1): a section is read once its top passes it
const LINE_SHORT = 0.5; // the reading line on a screen 720 px tall or less, where a section shows less of itself
const ROLL = 1100; // ms: the highest digit that changes rolls straight to its new value in this time
const LAG = 150; // ms more for each digit on its right, which spin past and land later
const TURNS = 2; // full turns of the last digit; the digits in between spin 1 to this
const NOTE = 650; // ms: the note rolling to the next section's
const EASE = 'cubic-bezier(0.16, 1, 0.3, 1)'; // fast start, gentle landing: an odometer settling
const NOTE_EASE = 'cubic-bezier(0.22, 1, 0.36, 1)';
const CELL = 1.1; // em: the height of a digit window, the line-height of the figure in the CSS
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// The site's pace, --kz-motion-scale (set on :root, read on the instance): every duration of the
// script times it, and 0 moves nothing, like reduced motion
const paceOf = (el) => {
const pace = parseFloat(getComputedStyle(el).getPropertyValue('--kz-motion-scale'));
return pace >= 0 ? pace : 1;
};
// One instance, with its own state: two copies on a page never interfere. Everything it
// starts is tied to `signal` (listeners get { signal }, observers and timers stop on its
// 'abort' event), so kodza:destroy stops it all.
function mount(root, signal) {
const pace = paceOf(root);
const still = reduceMotion || !pace; // the still path: no motion asked, by the visitor or the site
// The story: every section with a value, in the order of the page (inside nested blocks too)
const stops = [...root.querySelectorAll('[data-gauge]')]
.filter((el) => el.closest(SELECTOR) === root)
.map((el) => {
const raw = el.getAttribute('data-gauge').replace(/\s/g, '').replace('−', '-');
return {
el,
raw,
value: Number(raw),
decimals: (raw.split('.')[1] || '').length,
note: (el.getAttribute('data-gauge-note') || '').trim(),
};
})
.filter((stop) => stop.raw !== '' && Number.isFinite(stop.value));
if (!stops.length) return;
const label = (root.getAttribute('data-label') || '').trim();
const unit = (root.getAttribute('data-unit') || '').trim();
const grouping = root.hasAttribute('data-grouping');
// The decimal point and the thousands separator of the page's language (36,5 in French)
const lang = root.closest('[lang]')?.getAttribute('lang') || undefined;
let decimalChar = '.';
let groupChar = ',';
try {
const parts = new Intl.NumberFormat(lang).formatToParts(12345.6);
decimalChar = parts.find((part) => part.type === 'decimal')?.value || '.';
groupChar = parts.find((part) => part.type === 'group')?.value || ',';
} catch (error) {
// An unknown language tag: the dot and the comma
}
const spoken = (stop) => {
try {
return new Intl.NumberFormat(lang, { minimumFractionDigits: stop.decimals, maximumFractionDigits: stop.decimals, useGrouping: grouping }).format(stop.value);
} catch (error) {
return stop.raw;
}
};
// The places of the figure: as many whole digits and decimals as the longest value needs.
// A value shows only its own: no leading zeros, no decimals it does not have
const DECIMALS = Math.max(...stops.map((stop) => stop.decimals));
const scaled = (stop) => Math.round(Math.abs(stop.value) * 10 ** DECIMALS);
const wholeLength = (stop) => String(Math.floor(scaled(stop) / 10 ** DECIMALS)).length;
const WHOLE = Math.max(...stops.map(wholeLength));
const PLACES = WHOLE + DECIMALS;
const shapeOf = (stop) => {
const digits = String(scaled(stop)).padStart(PLACES, '0').split('').map(Number);
const length = wholeLength(stop);
return {
digits,
visible: digits.map((digit, place) => (place < WHOLE ? place >= WHOLE - length : place - WHOLE < stop.decimals)),
negative: stop.value < 0 && scaled(stop) > 0,
point: stop.decimals > 0,
value: stop.value,
};
};
const EMPTY = { digits: Array(PLACES).fill(0), visible: Array(PLACES).fill(false), negative: false, point: false, value: null };
const make = (tag, part, text) => {
const el = document.createElement(tag);
el.className = `kodza-scroll-gauge__${part}`;
if (text != null) el.textContent = text;
return el;
};
// The dial, on a rail of no height pinned to the bottom of the screen with position: sticky:
// it rides along while the story scrolls and leaves with the end of it
const rail = make('div', 'rail');
const dial = make('div', 'dial');
dial.setAttribute('aria-hidden', 'true');
const sr = make('span', 'sr'); // what the dial says, for screen readers
rail.append(dial, sr);
if (label) {
const row = make('span', 'label');
row.append(make('span', 'in', label));
dial.append(row);
}
const reading = make('span', 'reading');
const figure = make('span', 'figure');
reading.append(figure);
if (unit) {
const box = make('span', 'unit');
box.append(make('span', 'in', unit));
reading.append(box);
}
dial.append(reading);
// The slots, left to right: sign, whole digits (with their thousands separators), decimal
// point, decimals. A digit spins in its window; an empty slot closes to no width
const slots = [];
const digitSlots = [];
const addChar = (kind, char, place) => {
const el = make('span', 'char', char);
figure.append(el);
slots.push({ el, kind, place });
};
if (stops.some((stop) => stop.value < 0)) addChar('sign', '−');
for (let place = 0; place < PLACES; place += 1) {
if (place === WHOLE) addChar('point', decimalChar);
const el = make('span', 'digit');
const strip = make('span', 'strip');
strip.append(make('span', 'cell', ''));
el.append(strip);
figure.append(el);
const slot = { el, kind: 'digit', place, strip, anim: null };
slots.push(slot);
digitSlots.push(slot);
if (grouping && place < WHOLE - 1 && (WHOLE - 1 - place) % 3 === 0) addChar('group', groupChar, place);
}
const notes = stops.some((stop) => stop.note) ? stops.map((stop) => make('span', 'line', stop.note)) : [];
if (notes.length) {
const row = make('span', 'note');
row.append(...notes);
dial.append(row);
}
// The scale of the whole story, from its lowest value to its highest: a tick for each section,
// and the needle on the one being read
const values = stops.map((stop) => stop.value);
const low = Math.min(...values);
const high = Math.max(...values);
const at = (v) => (high > low ? (v - low) / (high - low) : 0.5);
const scale = make('span', 'scale');
scale.append(make('span', 'track'));
stops.forEach((stop) => {
const tick = make('span', 'stop');
tick.style.left = `calc(${at(stop.value).toFixed(4)} * (100% - 1px))`;
scale.append(tick);
});
const needle = make('span', 'needle');
needle.append(make('span', 'tick'));
scale.append(needle);
dial.append(scale);
root.append(rail);
// The width of each kind of slot, in em of the figure, measured in the page's own font
const ems = { digit: 0.62, sign: 0.6, point: 0.28, group: 0.28 };
let measured = false;
const measure = () => {
const probe = make('span', 'probe');
figure.append(probe);
const size = parseFloat(getComputedStyle(figure).fontSize) || 0;
const widthOf = (text) => {
probe.textContent = text.repeat(10);
return probe.offsetWidth / 10 / size;
};
const digit = size ? Math.max(...'0123456789'.split('').map(widthOf)) : 0;
if (digit > 0) {
Object.assign(ems, { digit, sign: widthOf('−'), point: widthOf(decimalChar), group: widthOf(groupChar) });
measured = true;
}
probe.remove();
};
const open = (slot, shape) => {
if (slot.kind === 'sign') return shape.negative;
if (slot.kind === 'point') return shape.point;
return shape.visible[slot.place];
};
// animate: false sets the widths at once (the dial coming in, the font loading)
const size = (shape, animate) => {
slots.forEach((slot) => {
if (!animate) slot.el.style.transition = 'none';
const shown = open(slot, shape);
slot.el.style.width = `${shown ? ems[slot.kind].toFixed(4) : 0}em`;
slot.el.classList.toggle('is-closed', !shown);
});
if (animate) return;
void figure.offsetWidth;
slots.forEach((slot) => {
slot.el.style.transition = '';
});
};
let shape = EMPTY; // what the figure shows, EMPTY while the dial is away
let current = -1; // the section on the dial, -1 before the first one
// The digit a slot shows right now, and how far past it: a roll cut short by the next one
// starts again from there, nothing jumps
const cellOf = (slot) => {
if (slot.anim?.playState !== 'running') return null;
const cells = slot.strip.children;
const height = parseFloat(getComputedStyle(cells[0]).height) || 1;
const pos = -new DOMMatrixReadOnly(getComputedStyle(slot.strip).transform).m42 / height;
const index = Math.min(cells.length - 1, Math.max(0, Math.round(pos)));
const text = cells[index].textContent;
return { digit: text === '' ? 0 : Number(text), blank: text === '', offset: pos - index };
};
const rollTo = (stop, animate) => {
const to = shapeOf(stop);
const from = shape;
const up = from.value === null || stop.value >= from.value;
const now = digitSlots.map((slot) => (from.value !== null && cellOf(slot)) || { digit: from.digits[slot.place], blank: !from.visible[slot.place], offset: 0 });
// The highest digit that changes rolls straight to its value; the ones on its right spin
// 1 to TURNS full turns more and land later, the ones on its left stay put
const first = now.findIndex((cell, i) => cell.digit !== to.digits[i] || cell.blank === to.visible[i]);
let last = -1;
now.forEach((cell, i) => {
if (!cell.blank || to.visible[i]) last = i;
});
digitSlots.forEach((slot, i) => {
const cell = now[i];
const blank = !to.visible[i];
let steps = 0;
if (first >= 0 && i >= first && !(cell.blank && blank)) {
steps = ((((up ? to.digits[i] - cell.digit : cell.digit - to.digits[i]) % 10) + 10) % 10);
if (i > first) steps += 10 * (last - first > 1 ? 1 + Math.round(((i - first - 1) / (last - first - 1)) * (TURNS - 1)) : 1);
}
// The cells from the digit shown to the new one, in the direction of the value: the
// strip goes up when it climbs (new digits from below), down when it falls (from above)
let texts = [blank ? '' : String(to.digits[i])];
if (steps) {
texts = [];
for (let s = 0; s <= steps; s += 1) texts.push(String((((up ? cell.digit + s : cell.digit - s) % 10) + 10) % 10));
if (cell.blank) texts[0] = '';
if (blank) texts[steps] = '';
if (!up) texts.reverse();
}
const end = up ? steps : 0;
// Cut short, a roll carries on from where it was, when that cell has a neighbour
const offset = steps && (up ? cell.offset > 0 : cell.offset < 0) ? cell.offset : 0;
const start = (up ? 0 : steps) + offset;
slot.anim?.cancel();
slot.anim = null;
slot.strip.replaceChildren(...texts.map((text) => make('span', 'cell', text)));
slot.strip.style.transform = `translateY(${(-end * CELL).toFixed(3)}em)`;
if (!animate || start === end) return;
slot.anim = slot.strip.animate(
[{ transform: `translateY(${(-start * CELL).toFixed(3)}em)` }, { transform: `translateY(${(-end * CELL).toFixed(3)}em)` }],
{ duration: (ROLL + Math.max(0, i - first) * LAG) * pace, easing: EASE },
);
});
size(to, animate);
shape = to;
};
// The needle: from where it is, even halfway through a slide
const point = (to, from, animate) => {
const target = `translateX(${(at(to) * 100).toFixed(2)}%)`;
const before = needle.getAnimations().length ? getComputedStyle(needle).transform : from;
needle.getAnimations().forEach((anim) => anim.cancel());
needle.style.transform = target;
if (animate) needle.animate([{ transform: before }, { transform: target }], { duration: ROLL * pace, easing: EASE });
};
// The note rolls like a word: the old one leaves on the side you scroll from, the new one
// comes in from the side you scroll to
const note = (index, dir, animate) => {
notes.forEach((line, i) => {
const on = i === index;
if (line.classList.contains('is-current') === on) return;
const before = line.getAnimations().length ? getComputedStyle(line).transform : null;
line.getAnimations().forEach((anim) => anim.cancel());
// The class gives the resting place, the animation the way there
line.classList.toggle('is-current', on);
if (!animate) return;
line.animate(
[{ transform: before || (on ? `translateY(${dir * 110}%)` : 'none') }, { transform: on ? 'none' : `translateY(${-dir * 110}%)` }],
{ duration: NOTE * pace, easing: NOTE_EASE },
);
});
};
const show = (index) => {
const stop = stops[index];
if (current < 0) {
// The dial comes in from its corner: the figure rolls up from nothing, the needle sweeps
// from the start of the scale, the note rises with the label
if (!measured) measure();
shape = EMPTY;
size(EMPTY, false);
rollTo(stop, !still);
notes.forEach((line) => line.classList.remove('is-current'));
note(index, 1, !still);
point(stop.value, 'translateX(0%)', !still);
root.classList.add('is-shown');
} else {
rollTo(stop, !still);
note(index, index > current ? 1 : -1, !still);
point(stop.value, needle.style.transform, !still);
}
current = index;
sr.textContent = `${[label, spoken(stop), unit].filter(Boolean).join(' ')}${stop.note ? `, ${stop.note}` : ''}`;
};
const hide = () => {
current = -1;
root.classList.remove('is-shown');
sr.textContent = '';
};
let frame = 0;
const read = () => {
frame = 0;
const line = window.innerHeight * (window.innerHeight <= 720 ? LINE_SHORT : LINE);
let index = -1;
stops.forEach((stop, i) => {
if (stop.el.getBoundingClientRect().top <= line) index = i;
});
if (index === current) return;
if (index < 0) hide();
else show(index);
};
const schedule = () => {
if (!frame) frame = requestAnimationFrame(read);
};
measure();
size(EMPTY, false);
document.fonts?.ready.then(() => {
if (signal.aborted) return;
measure();
size(shape, false);
});
// Scrolling anywhere: the page, or a box the story scrolls in
document.addEventListener('scroll', schedule, { capture: true, passive: true, signal });
window.addEventListener('resize', schedule, { signal });
signal.addEventListener('abort', () => cancelAnimationFrame(frame));
schedule();
}
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load. Each running root
// keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
// component inside another one is saved as written, not half-started, and stopped with it. Two
// components on one root (a reveal on a stat card) both start, and stop together.
const KODZA = Symbol.for('kodza');
const RUNNING = Symbol.for(`kodza ${SELECTOR}`); // a root this component runs on, for every copy of this script
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
const put = (el, saved) => {
[...el.attributes].forEach((a) => el.removeAttribute(a.name));
saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
el.innerHTML = saved.html;
};
// The markup inside a root as written: Kodza components already running in it give back their own
const written = (root) => {
const all = [...root.querySelectorAll('*')];
if (!all.some((el) => el[KODZA])) return root.innerHTML;
const copy = root.cloneNode(true);
const twins = copy.querySelectorAll('*');
let last = null;
all.forEach((el, i) => {
if (!el[KODZA] || last?.contains(el)) return;
last = el;
put(twins[i], el[KODZA]);
});
return copy.innerHTML;
};
const init = (scope) => find(scope).forEach((root) => {
// Already running, maybe from another copy of this script. Marked is-ready with no Kodza component
// running on it, a root is a copy of a started one (a cloned slide): it is left as it is
if (root[RUNNING] || (root.classList.contains('is-ready') && !root[KODZA])) return;
// Rendered by React (data-kodza-manual): React starts it, with an init aimed at that markup once
// it has hydrated it. Any earlier start would change markup React has not taken over yet
const owner = root.closest('[data-kodza-manual]');
if (owner && !(scope && owner.contains(scope))) return;
const controller = new AbortController();
// Another Kodza component already running on this root: its markup as written is kept, and the
// two stop together
const before = root[KODZA];
const saved = { html: before ? before.html : written(root), attrs: before ? before.attrs : attrsOf(root), stop: () => destroy(root) };
if (before) before.above = saved;
instances.set(root, { controller, saved, before });
root[KODZA] = saved;
root[RUNNING] = true;
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.saved.above?.stop(); // a Kodza component started after it on the same root stops first
// The Kodza components running inside it stop first: once its markup is put back, their own
// script could not find them any more
root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
instance.controller.abort();
delete root[RUNNING];
// Started on top of another one: that one stops next, and puts the markup back
if (instance.before) {
delete instance.before.above;
root[KODZA] = instance.before;
return instance.before.stop();
}
delete root[KODZA];
put(root, instance.saved);
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Scroll Gauge, for React. From https://kodza.dev/components/scroll-gauge/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: scroll-gauge.css and scroll-gauge.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// data-kodza-manual keeps the script from starting it on its own: the effect below does, once
// React has hydrated the markup (on a page that streams in, the script can load first).
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './scroll-gauge.css';
export type ScrollGaugeProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "label" | "unit"> & {
/** data-label on the root (default: Temperature) */
label?: "Temperature";
/** data-unit on the root (default: °C) */
unit?: "°C";
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-scroll-gauge-fg"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-scroll-gauge-muted"?: string | number;
/** the dial's edge and the rules between sections — default: rgba(10, 10, 10, 0.1) */
"--kz-scroll-gauge-line"?: string | number;
/** the scale and its ticks — default: rgba(10, 10, 10, 0.24) */
"--kz-scroll-gauge-rule"?: string | number;
/** default: rgba(255, 255, 255, 0.78) */
"--kz-scroll-gauge-glass"?: string | number;
/** default: 0 1px 2px rgba(10, 10, 10, 0.04), 0 14px 32px -14px rgba(10, 10, 10, 0.22) */
"--kz-scroll-gauge-shadow"?: string | number;
/** the figure — default: 48px */
"--kz-scroll-gauge-size"?: string | number;
/** the narrowest the dial gets; a longer figure widens it — default: 208px */
"--kz-scroll-gauge-width"?: string | number;
/** from the bottom of the screen — default: 24px */
"--kz-scroll-gauge-inset"?: string | number;
/** from the side of the story (left, or right with data-side="right") — default: 0px */
"--kz-scroll-gauge-side"?: string | number;
/** default: calc(14px * var(--kz-radius-scale, 1)) */
"--kz-scroll-gauge-radius"?: string | number;
/** default: 20 */
"--kz-scroll-gauge-z"?: string | number;
/** the least height of a section — default: 560px */
"--kz-scroll-gauge-section"?: string | number;
/** the dial coming in; the figure rolls in the script's time — default: 0.6s */
"--kz-scroll-gauge-in"?: string | number;
/** and going away — default: 0.4s */
"--kz-scroll-gauge-out"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-scroll-gauge-ease"?: string | number;
/** default: cubic-bezier(0.65, 0, 0.35, 1) */
"--kz-scroll-gauge-ease-out"?: string | number;
};
className?: string;
};
export function ScrollGauge({ label = "Temperature", unit = "°C", vars, className, style, ...rest }: ScrollGaugeProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-scroll-gauge", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, label, unit, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./scroll-gauge.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
return (
<div data-kodza-scroll-gauge="" key={key} {...rest} className={classes} data-kodza-manual data-label={label} data-unit={unit} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<section className="kodza-scroll-gauge__section" data-gauge="4" data-gauge-note="Cold room">
<p className="kodza-scroll-gauge__time">21:00</p>
<h2 className="kodza-scroll-gauge__title">The dough sleeps.</h2>
<p className="kodza-scroll-gauge__text">Twelve hours at four degrees and nobody touches it. Flavour is just time you did not rush.</p>
</section>
<section className="kodza-scroll-gauge__section" data-gauge="26" data-gauge-note="Shaping bench">
<p className="kodza-scroll-gauge__time">04:00</p>
<h2 className="kodza-scroll-gauge__title">Hands, flour, no playlist.</h2>
<p className="kodza-scroll-gauge__text">The bench is warm and the dough wakes up. Shape it before it makes plans of its own.</p>
</section>
<section className="kodza-scroll-gauge__section" data-gauge="290" data-gauge-note="Oven floor">
<p className="kodza-scroll-gauge__time">05:10</p>
<h2 className="kodza-scroll-gauge__title">Stone, steam, no mercy.</h2>
<p className="kodza-scroll-gauge__text">A wood-fired oven, lit at midnight. Twenty-five minutes, one cloud of steam, and a crust that crackles as it cools.</p>
</section>
<section className="kodza-scroll-gauge__section" data-gauge="96" data-gauge-note="Inside the crumb">
<p className="kodza-scroll-gauge__time">05:35</p>
<h2 className="kodza-scroll-gauge__title">Done is a number.</h2>
<p className="kodza-scroll-gauge__text">Not “golden brown”, not hollow when you knock. A probe in the middle says 96 and the debate is over.</p>
</section>
<section className="kodza-scroll-gauge__section" data-gauge="36.5" data-gauge-note="Your hand">
<p className="kodza-scroll-gauge__time">07:00</p>
<h2 className="kodza-scroll-gauge__title">Still warm. Yours now.</h2>
<p className="kodza-scroll-gauge__text">The shop opens at seven. Ninety minutes out of the oven, the loaf is the temperature of the hand holding it.</p>
</section>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.