Download Link
A download link that shows the file's type and weight beside its words, read from the file itself. On hover the arrow sinks into its tray; a click sends it through and back from the top.
View codeFootnotes that stay on their line. Wide, the note sits in the margin level with its line and inks with its number; narrow, it folds out under the line. Picks up WordPress footnotes as they are.
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 Footnote Link to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-footnote-link" data-kodza-footnote-link>
<p>We shipped the redesign on a Friday at 4:40 pm.<button type="button" class="kodza-footnote-link__ref">1</button><span class="kodza-footnote-link__note">Yes, on purpose. Monday deploys only feel safer because nobody is looking.</span> Nothing broke. The new header, the pricing page and thirty-one components went out in one deploy, and the error graph stayed flat all weekend.</p>
<p>The rollback plan fit in one command,<button type="button" class="kodza-footnote-link__ref">2</button><span class="kodza-footnote-link__note">git revert on the merge commit, then a push. The pipeline does the rest.</span> and nobody had to run it. We had rehearsed it twice on staging, timed it, and written the number down: ninety seconds from the first alert to the old site.</p>
<p>The trick wasn't courage. It was a diff small enough to review in one sitting:<button type="button" class="kodza-footnote-link__ref">3</button><span class="kodza-footnote-link__note">If the review needs a meeting, the diff is too big. That's the whole rule.</span> forty lines per pull request, one reviewer each, and a test that failed before it passed.</p>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Footnote Link
Footnotes that stay on their line. In a wide column the note sits in the margin, level with
its line, and the number and the note ink together; in a narrow one a tap folds the note out
under the line and the text slides down. Without the script, every note stays readable.
Everything is tuned with the --kz-footnote-link-* variables. */
.kodza-footnote-link {
--kz-footnote-link-ink: #0a0a0a;
--kz-footnote-link-paper: #fff;
--kz-footnote-link-muted: rgba(10, 10, 10, 0.62);
--kz-footnote-link-sheet: rgba(10, 10, 10, 0.05);
--kz-footnote-link-note-width: 210px;
--kz-footnote-link-gap: 48px;
--kz-footnote-link-note-size: 0.82em;
--kz-footnote-link-duration: 0.26s;
--kz-footnote-link-ease: cubic-bezier(0.22, 1, 0.36, 1);
container: kodza-footnote-link / inline-size;
display: flow-root;
counter-reset: kodza-footnote-link;
}
/* The paragraphs it holds: their own spacing, whatever the theme gives to p */
.kodza-footnote-link > p {
margin: 0 0 1.1em;
}
.kodza-footnote-link > p:last-child {
margin-bottom: 0;
}
/* The number in the text: a small mono pill, raised without making its line taller */
.kodza-footnote-link__ref {
position: relative;
top: -0.5em;
display: inline-block;
box-sizing: border-box;
min-width: 1.7em;
height: 1.6em;
margin: 0 0.1em 0 0.2em;
padding: 0 0.45em;
border: 0;
border-radius: 999px;
background: var(--kz-footnote-link-sheet);
color: var(--kz-footnote-link-muted);
font: 500 0.62em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
letter-spacing: 0;
text-align: center;
text-transform: none;
vertical-align: baseline;
cursor: pointer;
counter-increment: kodza-footnote-link;
-webkit-tap-highlight-color: transparent;
}
/* A target of 24 px at least, more under a finger */
.kodza-footnote-link__ref::before {
content: "";
position: absolute;
inset: -4px;
}
@media (pointer: coarse) {
.kodza-footnote-link__ref::before {
inset: -10px -8px;
}
}
.kodza-footnote-link__ref:focus-visible {
outline: 2px solid var(--kz-footnote-link-ink);
outline-offset: 2px;
}
/* The word before a number, the number and its note, kept on one line by the script */
.kodza-footnote-link__tie {
white-space: nowrap;
}
/* The note. Narrow column (and the default): a sheet under the line, the text flows below it */
.kodza-footnote-link__note {
--kz-footnote-link-pad-top: 12px;
position: relative;
white-space: normal;
float: left;
clear: both;
box-sizing: border-box;
width: 100%;
margin: 0.55em 0 0.9em;
padding: var(--kz-footnote-link-pad-top) 16px 13px 46px;
border-radius: 12px;
background: var(--kz-footnote-link-sheet);
color: var(--kz-footnote-link-ink);
font-size: var(--kz-footnote-link-note-size);
line-height: 1.55;
text-wrap: pretty;
}
/* Its number, the same pill as in the text, centred on the first line */
.kodza-footnote-link__note::before,
.kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
position: absolute;
top: calc(var(--kz-footnote-link-pad-top) + 0.225em);
left: 16px;
box-sizing: border-box;
min-width: 1.7em;
height: 1.6em;
padding: 0 0.45em;
border-radius: 999px;
font: 500 0.756em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
letter-spacing: 0;
text-align: center;
}
.kodza-footnote-link__note::before {
content: counter(kodza-footnote-link);
background: var(--kz-footnote-link-sheet);
color: var(--kz-footnote-link-muted);
}
.kodza-footnote-link.is-ready .kodza-footnote-link__note::before {
content: attr(data-n);
}
/* Folded until its number is pressed, once the script runs */
@container kodza-footnote-link (max-width: 759.98px) {
.kodza-footnote-link.is-ready .kodza-footnote-link__note:not(.is-open) {
display: none;
}
}
.kodza-footnote-link__note.is-moving {
overflow: hidden;
}
/* Wide column: the text keeps a margin on its right, and each note sits there, level with its
line. Notes close together stack instead of overlapping. */
@container kodza-footnote-link (min-width: 760px) {
.kodza-footnote-link > * {
padding-right: calc(var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap));
}
.kodza-footnote-link__note {
--kz-footnote-link-pad-top: 0px;
float: right;
clear: right;
width: var(--kz-footnote-link-note-width);
margin: 0.3em calc(-1 * (var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap))) 1em 0;
padding: 0 0 0 2.1em;
border-radius: 0;
background: none;
color: var(--kz-footnote-link-muted);
}
.kodza-footnote-link__note::before,
.kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
left: 0;
}
}
/* The ink: a double of the number, ink on paper, uncovered from the bottom up. It rises in the
number and in its note at the same time */
.kodza-footnote-link.is-ready .kodza-footnote-link__ref::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
content: attr(data-n);
background: var(--kz-footnote-link-ink);
color: var(--kz-footnote-link-paper);
clip-path: inset(100% 0 0 0);
pointer-events: none;
transition: clip-path var(--kz-footnote-link-duration) var(--kz-footnote-link-ease);
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref::after {
position: absolute;
inset: 0;
border-radius: inherit;
}
.kodza-footnote-link.is-ready .kodza-footnote-link__note {
transition: color 0.2s ease;
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"]::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible + .kodza-footnote-link__note::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active + .kodza-footnote-link__note::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"] + .kodza-footnote-link__note::after {
clip-path: inset(0);
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible + .kodza-footnote-link__note,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active + .kodza-footnote-link__note {
color: var(--kz-footnote-link-ink);
}
/* Pointing at the number or at its note inks both */
@media (hover: hover) {
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:has(+ .kodza-footnote-link__note:hover)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover + .kodza-footnote-link__note::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__note:hover::after {
clip-path: inset(0);
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover + .kodza-footnote-link__note,
.kodza-footnote-link.is-ready .kodza-footnote-link__note:hover {
color: var(--kz-footnote-link-ink);
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-footnote-link *,
.kodza-footnote-link *::before,
.kodza-footnote-link *::after {
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
/* kodza-guard 73c91f13db29 — 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-footnote-link__ref):not(#_) {
outline: revert;
outline-offset: revert;
transition-duration: revert;
}
:where(.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *))):not(#_) {
padding-right: revert;
transition-duration: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-footnote-link:not(#_),
.kodza-footnote-link__tie:not(#_) {
box-sizing: revert;
}
.kodza-footnote-link__ref:not(#_) {
text-decoration: revert;
list-style: revert;
float: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
text-underline-offset: revert;
text-indent: revert;
text-shadow: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
white-space: revert;
min-height: revert;
}
.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
padding-top: 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;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: 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-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_):where([hidden]) {
display: none;
}
.kodza-footnote-link__ref:not(#_)::before,
.kodza-footnote-link__ref:not(#_)::after {
box-sizing: revert;
}
/* 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-footnote-link > p:not(#_) {
margin: 0 0 1.1em;
}
.kodza-footnote-link > p:last-child:not(#_) {
margin-bottom: 0;
}
.kodza-footnote-link__ref:not(#_) {
position: relative;
top: -0.5em;
display: inline-block;
box-sizing: border-box;
min-width: 1.7em;
height: 1.6em;
margin: 0 0.1em 0 0.2em;
padding: 0 0.45em;
border: 0;
border-radius: 999px;
background: var(--kz-footnote-link-sheet);
color: var(--kz-footnote-link-muted);
font: 500 0.62em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
letter-spacing: 0;
text-align: center;
text-transform: none;
vertical-align: baseline;
cursor: pointer;
counter-increment: kodza-footnote-link;
-webkit-tap-highlight-color: transparent;
}
.kodza-footnote-link__ref:not(#_)::before {
content: "";
position: absolute;
inset: -4px;
}
@media (pointer: coarse) {
.kodza-footnote-link__ref:not(#_)::before {
inset: -10px -8px;
}
}
.kodza-footnote-link__ref:focus-visible:not(#_) {
outline: 2px solid var(--kz-footnote-link-ink);
outline-offset: 2px;
}
@container kodza-footnote-link (min-width: 760px) {
.kodza-footnote-link > *:not(#_) {
padding-right: calc(var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap));
}
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:not(#_)::after {
content: attr(data-n);
background: var(--kz-footnote-link-ink);
color: var(--kz-footnote-link-paper);
clip-path: inset(100% 0 0 0);
pointer-events: none;
transition: clip-path var(--kz-footnote-link-duration) var(--kz-footnote-link-ease);
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:not(#_)::after {
position: absolute;
inset: 0;
border-radius: inherit;
}
.kodza-footnote-link.is-ready .kodza-footnote-link__note:not(#_) {
transition: color 0.2s ease;
}
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible:not(#_)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active:not(#_)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"]:not(#_)::after {
clip-path: inset(0);
}
@media (hover: hover) {
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover:not(#_)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:has(+ .kodza-footnote-link__note:hover):not(#_)::after {
clip-path: inset(0);
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-footnote-link *:not(#_),
.kodza-footnote-link *:not(#_)::before,
.kodza-footnote-link *:not(#_)::after {
transition-duration: 0.01ms !important;
animation-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 — Footnote Link
// Numbers each note, sets it level with its line in the margin (wide column) or folds it out under
// its line (narrow column, animated height), and turns WordPress or Markdown footnotes into the same.
(() => {
const SELECTOR = '[data-kodza-footnote-link]';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const OPEN = { duration: 460, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
const CLOSE = { duration: 380, easing: 'cubic-bezier(0.65, 0, 0.35, 1)' };
const FOLDED = { height: '0px', paddingTop: '0px', paddingBottom: '0px', marginTop: '0px', marginBottom: '0px', opacity: 0 };
const BACK_LINK = /^[\s↩︎️]+$/; // a "↩" that leads back to the number, nothing else
let uid = 0;
// Footnotes already written: the WordPress Footnotes block, or Markdown (<sup><a href="#fn1">).
// Each number becomes a button with its note right after it, and the list at the bottom hides.
function borrow(root, signal) {
const lists = new Set();
root.querySelectorAll('sup a[href^="#"]').forEach((link) => {
const sup = link.closest('sup');
let item = null;
try {
item = document.getElementById(decodeURIComponent(link.getAttribute('href').slice(1)));
} catch {
return;
}
if (item?.tagName !== 'LI') return;
const copy = item.cloneNode(true);
const backs = [link.id, sup.id].filter(Boolean).map((id) => `#${id}`);
copy.querySelectorAll('a[href]').forEach((a) => {
if (backs.includes(a.getAttribute('href')) || BACK_LINK.test(a.textContent)) a.remove();
});
copy.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'));
const body = copy.children.length === 1 && copy.firstElementChild.tagName === 'P' ? copy.firstElementChild : copy;
const ref = document.createElement('button');
ref.type = 'button';
ref.className = 'kodza-footnote-link__ref';
ref.textContent = link.textContent.replace(/[[\]]/g, '').trim();
const note = document.createElement('span');
note.className = 'kodza-footnote-link__note';
note.innerHTML = body.innerHTML.trim();
sup.replaceWith(ref, note);
lists.add(item.closest('.wp-block-footnotes, .footnotes') || item.parentElement);
});
lists.forEach((list) => {
const hidden = list.hidden;
list.hidden = true;
signal.addEventListener('abort', () => { list.hidden = hidden; });
});
}
// 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) {
borrow(root, signal);
const pairs = [...root.querySelectorAll('.kodza-footnote-link__ref')]
.map((ref) => ({ ref, note: ref.nextElementSibling, open: false }))
.filter(({ note }) => note?.classList.contains('kodza-footnote-link__note'));
if (!pairs.length) return;
pairs.forEach(({ ref, note }, i) => {
const n = ref.textContent.trim() || String(i + 1);
ref.dataset.n = n;
note.dataset.n = n;
if (!ref.hasAttribute('aria-label')) ref.setAttribute('aria-label', `Note ${n}`);
if (!note.id) note.id = `kodza-footnote-link-${++uid}`;
ref.setAttribute('aria-controls', note.id);
// A number never starts a line on its own: it is tied to the word before it
const text = ref.previousSibling;
if (text?.nodeType !== Node.TEXT_NODE || !/\S$/.test(text.data)) return;
const at = text.data.search(/\S+$/);
const word = at > 0 ? text.splitText(at) : text;
const tie = document.createElement('span');
tie.className = 'kodza-footnote-link__tie';
word.before(tie);
tie.append(word, ref, note);
});
// Which layout the CSS picked: the container query floats the notes right in a wide column
const isWide = () => getComputedStyle(pairs[0].note).float === 'right';
let wide = null;
let pinned = null;
const setPin = (pair) => {
pinned?.ref.classList.remove('is-active');
pinned = pair;
pair?.ref.classList.add('is-active');
};
// In the margin, each note's first line sits on the baseline of the line that calls it. A
// note pushed down by the one above stays where it is: it is never pulled up over it.
const baseline = () => {
const probe = document.createElement('span');
probe.style.cssText = 'display: inline-block; width: 0; height: 0; margin: 0; padding: 0; vertical-align: baseline';
return probe;
};
const align = () => {
if (!root.offsetWidth) return;
const scale = root.getBoundingClientRect().width / root.offsetWidth || 1;
pairs.forEach(({ note }) => {
note.style.marginTop = '0px';
const line = baseline();
const first = baseline();
note.before(line);
note.prepend(first);
const shift = (line.getBoundingClientRect().top - first.getBoundingClientRect().top) / scale;
line.remove();
first.remove();
note.style.marginTop = `${Math.max(0, Math.round(shift * 100) / 100)}px`;
});
};
const settle = (pair) => {
pair.note.getAnimations().forEach((animation) => animation.cancel());
pair.note.classList.remove('is-moving');
pair.note.classList.toggle('is-open', pair.open);
};
const layout = () => {
const now = isWide();
if (now !== wide) {
wide = now;
setPin(null);
pairs.forEach((pair) => {
settle(pair);
if (wide) {
pair.ref.removeAttribute('aria-expanded');
} else {
pair.ref.setAttribute('aria-expanded', String(pair.open));
pair.note.style.removeProperty('margin-top');
}
});
}
if (wide) align();
};
// Narrow column: the note opens under its line and the text below slides down with it.
// Stopped half-way, it turns back from where it is.
const read = (style) => ({
height: style.height,
paddingTop: style.paddingTop,
paddingBottom: style.paddingBottom,
marginTop: style.marginTop,
marginBottom: style.marginBottom,
opacity: style.opacity,
});
const toggle = (pair, open) => {
const { ref, note } = pair;
if (pair.open === open) return;
pair.open = open;
ref.setAttribute('aria-expanded', String(open));
const moving = note.getAnimations().length > 0 && note.classList.contains('is-moving');
const from = moving ? read(getComputedStyle(note)) : null;
note.getAnimations().forEach((animation) => animation.cancel());
note.classList.add('is-open');
if (reduceMotion) {
settle(pair);
return;
}
const full = read(getComputedStyle(note));
note.classList.add('is-moving');
const animation = note.animate(
[from || (open ? FOLDED : full), open ? full : FOLDED],
{ ...(open ? OPEN : CLOSE), fill: open ? 'none' : 'forwards' },
);
animation.onfinish = () => settle(pair);
};
pairs.forEach((pair) => {
pair.ref.addEventListener('click', () => {
if (wide) setPin(pinned === pair ? null : pair);
else toggle(pair, !pair.open);
}, { signal });
});
root.addEventListener('keydown', (event) => {
if (event.key !== 'Escape') return;
if (wide) {
if (!pinned) return;
setPin(null);
} else {
const pair = pairs.find(({ ref, note }) => ref === event.target || note.contains(event.target));
if (!pair?.open) return;
const inside = pair.note.contains(event.target);
toggle(pair, false);
if (inside) pair.ref.focus();
}
event.preventDefault();
}, { signal });
document.addEventListener('pointerdown', (event) => {
if (pinned && !pinned.ref.contains(event.target) && !pinned.note.contains(event.target)) setPin(null);
}, { signal });
// The width decides the layout; anything that moves the lines (fonts, images) moves the notes
let frame = 0;
const observer = new ResizeObserver(() => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(layout);
});
layout();
observer.observe(root);
document.fonts?.ready.then(() => {
if (!signal.aborted) layout();
});
signal.addEventListener('abort', () => {
observer.disconnect();
cancelAnimationFrame(frame);
pairs.forEach(({ note }) => note.getAnimations().forEach((animation) => animation.cancel()));
});
}
// 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.
const KODZA = Symbol.for('kodza');
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) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
const saved = { html: written(root), attrs: attrsOf(root), stop: () => destroy(root) };
instances.set(root, { controller, saved });
root[KODZA] = saved;
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);
// 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[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 — Footnote Link, for React. From https://kodza.dev/components/footnote-link/
// 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: footnote-link.css and footnote-link.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.
// 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 './footnote-link.css';
export type FootnoteLinkProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-footnote-link-ink"?: string | number;
/** default: #fff */
"--kz-footnote-link-paper"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-footnote-link-muted"?: string | number;
/** default: rgba(10, 10, 10, 0.05) */
"--kz-footnote-link-sheet"?: string | number;
/** default: 210px */
"--kz-footnote-link-note-width"?: string | number;
/** default: 48px */
"--kz-footnote-link-gap"?: string | number;
/** default: 0.82em */
"--kz-footnote-link-note-size"?: string | number;
/** default: 0.26s */
"--kz-footnote-link-duration"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-footnote-link-ease"?: string | number;
};
className?: string;
};
export function FootnoteLink({ vars, className, style, ...rest }: FootnoteLinkProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-footnote-link", 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, 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('./footnote-link.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-footnote-link="" key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<p>We shipped the redesign on a Friday at 4:40 pm.<button type="button" className="kodza-footnote-link__ref">1</button><span className="kodza-footnote-link__note">Yes, on purpose. Monday deploys only feel safer because nobody is looking.</span> Nothing broke. The new header, the pricing page and thirty-one components went out in one deploy, and the error graph stayed flat all weekend.</p>
<p>The rollback plan fit in one command,<button type="button" className="kodza-footnote-link__ref">2</button><span className="kodza-footnote-link__note">git revert on the merge commit, then a push. The pipeline does the rest.</span> and nobody had to run it. We had rehearsed it twice on staging, timed it, and written the number down: ninety seconds from the first alert to the old site.</p>
<p>The trick wasn't courage. It was a diff small enough to review in one sitting:<button type="button" className="kodza-footnote-link__ref">3</button><span className="kodza-footnote-link__note">If the review needs a meeting, the diff is too big. That's the whole rule.</span> forty lines per pull request, one reviewer each, and a test that failed before it passed.</p>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.