Ruled Paper
A section ruled like a notebook page, with an ink margin line. The rules follow the text's line height and every line of text sits on its rule, at every size.
View codeA hero dimensioned like a technical drawing: arrowed lines measure its real margins, columns, title and height, and recompute on resize. They open one by one on entry.
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 Dimension Lines to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<section class="kodza-dimension-lines" data-kodza-dimension-lines>
<div class="kodza-dimension-lines__content">
<p class="kodza-dimension-lines__note">Sheet A-01 · scale 1:1 · units px</p>
<p class="kodza-dimension-lines__eyebrow">Atelier Brun · interfaces & design systems · Nantes</p>
<div class="kodza-dimension-lines__grid">
<h1 class="kodza-dimension-lines__title">
<span class="kodza-dimension-lines__line">Off by one?</span>
<span class="kodza-dimension-lines__line">Not here.</span>
</h1>
<div class="kodza-dimension-lines__side">
<p class="kodza-dimension-lines__lead">A two-person studio for product teams who spot a 1 px shift before their first coffee. Grids, specs and handoff files your developers never have to guess at.</p>
<p class="kodza-dimension-lines__actions">
<a class="kodza-dimension-lines__button" href="#">See the work</a>
<a class="kodza-dimension-lines__button kodza-dimension-lines__button--ghost" href="#">How we measure</a>
</p>
</div>
</div>
</div>
</section>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Dimension Lines
A hero dimensioned like a drawing sheet: construction lines on the edges of the real content,
a chain of dimensions that adds up the margins and the columns, the title's width and height,
the section's height, every value read from the page. Drawn by the script on one SVG behind
the text; without it, the hero stays as is. Tuned with the --kz-dimension-lines-* variables. */
.kodza-dimension-lines {
--kz-dimension-lines-bg: #f2f2f0; /* the paper */
--kz-dimension-lines-ink: #0a0a0a; /* the lines, the text, the button */
--kz-dimension-lines-muted: rgba(10, 10, 10, 0.62);
--kz-dimension-lines-lines: 0.4; /* opacity of the dimension lines and arrows, 0 to 1 */
--kz-dimension-lines-guides: 0.09; /* opacity of the construction lines */
--kz-dimension-lines-values: 0.62; /* opacity of the values */
--kz-dimension-lines-height: 600px;
--kz-dimension-lines-width: 1152px; /* the text column */
--kz-dimension-lines-side: clamp(20px, 5vw, 64px);
position: relative;
isolation: isolate;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: flex-end;
min-height: var(--kz-dimension-lines-height);
padding: 120px var(--kz-dimension-lines-side) 72px;
overflow: hidden;
background: var(--kz-dimension-lines-bg);
color: var(--kz-dimension-lines-ink);
}
/* The drawing: lines in one SVG, values in mono over it, all made by the script */
.kodza-dimension-lines__sheet {
position: absolute;
inset: 0;
z-index: -1;
color: var(--kz-dimension-lines-ink);
pointer-events: none;
}
.kodza-dimension-lines__sheet.is-waiting {
visibility: hidden;
}
.kodza-dimension-lines__drawing {
position: absolute;
top: 0;
left: 0;
display: block;
overflow: visible;
}
.kodza-dimension-lines__guide,
.kodza-dimension-lines__dim {
fill: none;
stroke: currentColor;
stroke-width: 1;
}
.kodza-dimension-lines__guide {
stroke-dasharray: 1;
}
.kodza-dimension-lines__guide {
stroke-opacity: var(--kz-dimension-lines-guides);
}
.kodza-dimension-lines__dim {
stroke-opacity: var(--kz-dimension-lines-lines);
}
.kodza-dimension-lines__arrow {
fill: currentColor;
fill-opacity: var(--kz-dimension-lines-lines);
}
/* Under a value a line would cross: the paper again */
.kodza-dimension-lines__knock {
fill: var(--kz-dimension-lines-bg);
}
.kodza-dimension-lines__value {
position: absolute;
overflow: hidden;
transform: translate(-50%, -50%);
opacity: var(--kz-dimension-lines-values);
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 11px;
font-variant-numeric: tabular-nums;
line-height: 14px;
letter-spacing: 0;
white-space: nowrap;
}
.kodza-dimension-lines__value--up {
transform: translate(-50%, -50%) rotate(-90deg);
}
.kodza-dimension-lines__digits {
display: block;
}
.kodza-dimension-lines__content {
width: 100%;
max-width: var(--kz-dimension-lines-width);
margin: 0 auto;
}
/* The sheet's title block in the corner, on the content's right edge */
.kodza-dimension-lines__note {
position: absolute;
top: 40px;
right: max(var(--kz-dimension-lines-side), calc((100% - var(--kz-dimension-lines-width)) / 2));
margin: 0;
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
}
.kodza-dimension-lines__eyebrow {
margin: 0 0 20px;
color: var(--kz-dimension-lines-muted);
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
text-wrap: balance;
}
.kodza-dimension-lines__grid {
display: grid;
grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
align-items: end;
gap: 28px 64px;
}
.kodza-dimension-lines__title {
margin: 0;
font-size: clamp(44px, 6.6vw, 92px);
font-weight: 600;
line-height: 0.94;
letter-spacing: -0.055em;
}
.kodza-dimension-lines__line {
display: block;
}
.kodza-dimension-lines__lead {
max-width: 30em;
margin: 0 0 24px;
color: var(--kz-dimension-lines-muted);
font-size: clamp(16px, 1.4vw, 18px);
line-height: 1.5;
text-wrap: pretty;
}
.kodza-dimension-lines__actions {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 0;
}
.kodza-dimension-lines__button {
box-sizing: border-box;
display: inline-flex;
align-items: center;
height: 48px;
padding: 0 22px;
border-radius: 999px;
background: var(--kz-dimension-lines-ink);
color: var(--kz-dimension-lines-bg);
font-size: 15px;
font-weight: 500;
letter-spacing: -0.01em;
text-decoration: none;
white-space: nowrap;
transition: opacity 0.18s ease;
}
.kodza-dimension-lines__button:hover {
opacity: 0.86;
}
.kodza-dimension-lines__button--ghost {
background: var(--kz-dimension-lines-bg);
color: inherit;
box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 22%, transparent);
}
.kodza-dimension-lines__button:focus-visible {
outline: 2px solid currentColor;
outline-offset: 3px;
}
@media (max-width: 720px) {
.kodza-dimension-lines {
padding: 96px var(--kz-dimension-lines-side) 56px;
}
.kodza-dimension-lines__note {
top: 28px;
}
.kodza-dimension-lines__grid {
grid-template-columns: minmax(0, 1fr);
gap: 24px;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-dimension-lines__button {
transition: none;
}
}
/* kodza-guard 225d444e00ae — 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-dimension-lines__button):not(#_) {
outline: revert;
box-shadow: revert;
outline-offset: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-dimension-lines__sheet:not(#_),
.kodza-dimension-lines__guide:not(#_),
.kodza-dimension-lines__dim:not(#_),
.kodza-dimension-lines__arrow:not(#_),
.kodza-dimension-lines__knock:not(#_),
.kodza-dimension-lines__value:not(#_),
.kodza-dimension-lines__digits:not(#_),
.kodza-dimension-lines__content:not(#_),
.kodza-dimension-lines__grid:not(#_),
.kodza-dimension-lines__line:not(#_),
.kodza-dimension-lines__side:not(#_) {
box-sizing: revert;
}
.kodza-dimension-lines__drawing:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: 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;
}
.kodza-dimension-lines__note:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: 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;
}
.kodza-dimension-lines__eyebrow:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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;
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;
}
.kodza-dimension-lines__title:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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-family: revert;
font-style: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-dimension-lines__lead:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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;
}
.kodza-dimension-lines__actions:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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-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;
}
.kodza-dimension-lines__button:not(#_) {
border: revert;
margin: revert;
list-style: revert;
float: revert;
position: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-style: revert;
line-height: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-dimension-lines__note:not(#_):where(:not([hidden])),
.kodza-dimension-lines__eyebrow:not(#_):where(:not([hidden])),
.kodza-dimension-lines__title:not(#_):where(:not([hidden])),
.kodza-dimension-lines__lead:not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-dimension-lines__note:not(#_):where([hidden]),
.kodza-dimension-lines__eyebrow:not(#_):where([hidden]),
.kodza-dimension-lines__title:not(#_):where([hidden]),
.kodza-dimension-lines__lead: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-dimension-lines__drawing:not(#_) {
position: absolute;
display: block;
}
.kodza-dimension-lines__note:not(#_) {
position: absolute;
margin: 0;
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
}
.kodza-dimension-lines__eyebrow:not(#_) {
margin: 0 0 20px;
color: var(--kz-dimension-lines-muted);
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
}
.kodza-dimension-lines__title:not(#_) {
margin: 0;
font-size: clamp(44px, 6.6vw, 92px);
font-weight: 600;
line-height: 0.94;
letter-spacing: -0.055em;
}
.kodza-dimension-lines__lead:not(#_) {
max-width: 30em;
margin: 0 0 24px;
color: var(--kz-dimension-lines-muted);
font-size: clamp(16px, 1.4vw, 18px);
line-height: 1.5;
}
.kodza-dimension-lines__actions:not(#_) {
display: flex;
margin: 0;
}
.kodza-dimension-lines__button:not(#_) {
box-sizing: border-box;
display: inline-flex;
padding: 0 22px;
border-radius: 999px;
background: var(--kz-dimension-lines-ink);
color: var(--kz-dimension-lines-bg);
font-size: 15px;
font-weight: 500;
letter-spacing: -0.01em;
text-decoration: none;
transition: opacity 0.18s ease;
}
.kodza-dimension-lines__button--ghost:not(#_) {
background: var(--kz-dimension-lines-bg);
color: inherit;
box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 22%, transparent);
}
.kodza-dimension-lines__button:focus-visible:not(#_) {
outline: 2px solid currentColor;
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.kodza-dimension-lines__button:not(#_) {
transition: none;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Dimension Lines
// Dimensions the hero like a drawing sheet, from its real layout: construction lines on the
// column edges, a chain of dimensions under the text (margins, columns, gap), the width of the
// title's longest line above it, the title's height and the section's in the side margins. Every
// value is measured, and measured again when the section reflows. The first time it is seen, the
// dimensions open one after another from their middle, their arrows pushing out.
(() => {
const SELECTOR = '[data-kodza-dimension-lines]';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const SVG = 'http://www.w3.org/2000/svg';
const ARROW = 7; // arrowhead length, in px
const SPREAD = 2.5; // arrowhead half-width
const LIFT = 9; // a value sits this far off its line
const GAP = 8; // between a feature and its extension line
const MARGIN = 44; // a side margin narrower than this gets no vertical dimension
const TOP = 72; // the title's width is dimensioned only if its line fits this far down
const OPEN = 560; // ms for a dimension to open
const STEP = 110; // ms between two dimensions
const DRAW = 'cubic-bezier(0.65, 0, 0.35, 1)';
const ARRIVE = 'cubic-bezier(0.22, 1, 0.36, 1)';
const format = (v) => String(Math.round(v)).replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
const crisp = (v) => Math.round(v - 0.5) + 0.5; // a 1 px line on one row of pixels, not across two
// 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 sheet = document.createElement('div');
sheet.className = 'kodza-dimension-lines__sheet';
sheet.setAttribute('aria-hidden', 'true');
const svg = document.createElementNS(SVG, 'svg');
svg.setAttribute('class', 'kodza-dimension-lines__drawing');
sheet.append(svg);
root.prepend(sheet);
const part = (name) => root.querySelector(`.kodza-dimension-lines__${name}`);
const pen = document.createElement('canvas').getContext('2d');
let entered = reduceMotion;
let drawn = '';
let animations = [];
let guides = [];
let dims = [];
if (!entered) sheet.classList.add('is-waiting'); // nothing shows before it is drawn in
// The layout, in the root's own pixels: a parent scaled by transform must not change a value
const measure = () => {
const box = root.getBoundingClientRect();
const k = box.width / root.offsetWidth || 1;
const rect = (el) => {
if (!el) return null;
const r = el.getBoundingClientRect();
return { left: (r.left - box.left) / k, top: (r.top - box.top) / k, right: (r.right - box.left) / k, bottom: (r.bottom - box.top) / k };
};
// Each letter of a block of text, with its box on screen
const letters = (el) => {
const found = [];
if (!el) return found;
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
for (let i = 0; i < node.data.length; i += 1) {
if (!node.data[i].trim()) continue;
const range = document.createRange();
range.setStart(node, i);
range.setEnd(node, i + 1);
const r = range.getBoundingClientRect();
if (r.width) found.push({ node, char: node.data[i], r });
}
}
return found;
};
// The title's ink, not its box: the box is as wide as its column, the longest line is not,
// and a letter's box is wider than the letter itself (side bearings, letter spacing). The
// first and last letters are measured in a canvas, in the title's font
const ink = (el) => {
const all = letters(el);
if (!all.length) return null;
const first = all.reduce((a, b) => (b.r.left < a.r.left ? b : a));
const last = all.reduce((a, b) => (b.r.right > a.r.right ? b : a));
const shape = (l) => {
const css = getComputedStyle(l.node.parentElement);
pen.font = `${css.fontStyle} ${css.fontWeight} ${css.fontSize} ${css.fontFamily}`;
return pen.measureText(l.char);
};
const left = first.r.left - shape(first).actualBoundingBoxLeft * k;
const right = last.r.left + shape(last).actualBoundingBoxRight * k;
return right > left ? { left: (left - box.left) / k, right: (right - box.left) / k } : null;
};
// The lines of a block of text, where a construction line must not run through them
const lines = (el) => {
const rows = [];
letters(el).forEach(({ r }) => {
const row = rows.find((o) => r.top < o.bottom && r.bottom > o.top);
if (row) {
row.left = Math.min(row.left, r.left);
row.right = Math.max(row.right, r.right);
} else rows.push({ left: r.left, top: r.top, right: r.right, bottom: r.bottom });
});
return rows.map((o) => ({ left: (o.left - box.left) / k, top: (o.top - box.top) / k, right: (o.right - box.left) / k, bottom: (o.bottom - box.top) / k }));
};
const title = part('title');
return {
width: root.offsetWidth,
height: root.offsetHeight,
content: rect(part('content')),
title: rect(title),
side: rect(part('side')),
ink: ink(title),
eyebrow: lines(part('eyebrow')),
};
};
const add = (cls, d, extra) => {
const el = document.createElementNS(SVG, 'path');
el.setAttribute('class', `kodza-dimension-lines__${cls}`);
el.setAttribute('d', d);
if (extra) Object.entries(extra).forEach(([name, value]) => el.setAttribute(name, value));
svg.append(el);
return el;
};
// A construction or extension line, drawn in from its first point at the entrance
const guide = (cls, x1, y1, x2, y2) => {
guides.push(add(cls, `M${x1} ${y1}L${x2} ${y2}`, { pathLength: 1 }));
};
// A dimension from a to b, along x (at height `at`) or along y (at `at` across): the line,
// an arrow at each end when there is room for them, and the value off the line
const dimension = (axis, a, b, at) => {
const length = b - a;
if (length < 4) return;
const mid = (a + b) / 2;
const across = crisp(at);
const line = axis === 'x' ? add('dim', `M${a} ${across}H${b}`) : add('dim', `M${across} ${a}V${b}`);
const arrows = [];
if (length >= ARROW * 2 + 4) {
const head = (tip, dir) => (axis === 'x'
? `M${tip} ${across}l${dir * ARROW} ${-SPREAD}v${SPREAD * 2}z`
: `M${across} ${tip}l${-SPREAD} ${dir * ARROW}h${SPREAD * 2}z`);
arrows.push([add('arrow', head(a, 1)), mid - a], [add('arrow', head(b, -1)), mid - b]);
}
const value = document.createElement('span');
value.className = `kodza-dimension-lines__value${axis === 'y' ? ' kodza-dimension-lines__value--up' : ''}`;
value.style.left = `${axis === 'x' ? mid : across - LIFT}px`;
value.style.top = `${axis === 'x' ? across - LIFT : mid}px`;
const digits = document.createElement('span');
digits.className = 'kodza-dimension-lines__digits';
digits.textContent = format(length);
value.append(digits);
sheet.append(value);
dims.push({ axis, mid, across, line, arrows, digits });
return value;
};
const draw = (m) => {
animations.forEach((a) => a.cancel());
animations = [];
guides = [];
dims = [];
svg.replaceChildren();
sheet.querySelectorAll('.kodza-dimension-lines__value').forEach((el) => el.remove());
const { width: w, height: h, content, title, side, ink, eyebrow } = m;
svg.setAttribute('width', w);
svg.setAttribute('height', h);
svg.setAttribute('viewBox', `0 0 ${w} ${h}`);
if (!content) return;
// The column edges: one construction line each, the whole height of the sheet
const columns = Boolean(title && side && side.left >= title.right - 1);
const breaks = [content.left, ...(columns ? [title.right, side.left] : []), content.right];
breaks.forEach((x) => guide('guide', crisp(x), 0, crisp(x), h));
const left = title && content.left >= MARGIN ? content.left / 2 : null;
const right = w - content.right >= MARGIN ? content.right + (w - content.right) / 2 : null;
if (title) { // the title's top and bottom, out to its height in the margin
const from = left === null ? 0 : left - GAP;
guide('guide', from, crisp(title.top), title.right, crisp(title.top));
guide('guide', from, crisp(title.bottom), title.right, crisp(title.bottom));
}
// Above the text: the width of the title's longest line, read from the glyphs
const top = content.top - 36;
const inked = ink && title && top >= TOP;
if (inked) {
guide('dim', crisp(ink.left), top - 6, crisp(ink.left), top + GAP);
guide('dim', crisp(ink.right), top - 6, crisp(ink.right), top + GAP);
// Down to the title, broken around a line of text it would cross, as on a drawing
let from = top + GAP;
eyebrow.filter((o) => ink.right > o.left - GAP && ink.right < o.right + GAP && o.bottom > from)
.sort((a, b) => a.top - b.top)
.forEach((o) => {
if (o.top - GAP / 2 > from + 2) guide('guide', crisp(ink.right), from, crisp(ink.right), o.top - GAP / 2);
from = o.bottom + GAP / 2;
});
if (title.top > from + 2) guide('guide', crisp(ink.right), from, crisp(ink.right), title.top);
}
// Under the text: margins, columns and gap, end to end, from one edge of the section to the other
const chain = (content.bottom + h) / 2;
breaks.forEach((x) => guide('dim', crisp(x), content.bottom + GAP, crisp(x), chain + 6));
if (inked) dimension('x', ink.left, ink.right, top);
let margin = null;
[0, ...breaks, w].reduce((a, b) => {
margin = dimension('x', a, b, chain);
return b;
});
if (left !== null) dimension('y', title.top, title.bottom, left);
if (right !== null) {
dimension('y', 0, h, right);
// The section's height runs through the right margin's value: the paper again under the
// value, so the line breaks around the text, as on a drawing
if (margin) {
const half = margin.offsetWidth / 2 + 3;
add('knock', `M${right - half} ${chain - LIFT - 10}H${right + half}V${chain - 2}H${right - half}z`);
}
}
};
// The first time it is seen: the construction lines draw in, then each dimension opens from
// its middle, its arrows riding the ends of the line, and its value rises out of a mask
const play = () => {
guides.forEach((el, i) => {
animations.push(el.animate([{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], {
duration: 900, delay: i * 40, easing: DRAW, fill: 'backwards',
}));
});
dims.forEach((d, i) => {
const timing = { duration: OPEN, delay: 280 + i * STEP, easing: DRAW, fill: 'backwards' };
const axis = d.axis.toUpperCase();
d.line.style.transformOrigin = d.axis === 'x' ? `${d.mid}px ${d.across}px` : `${d.across}px ${d.mid}px`;
animations.push(d.line.animate([{ transform: `scale${axis}(0)` }, { transform: `scale${axis}(1)` }], timing));
d.arrows.forEach(([el, shift]) => {
animations.push(el.animate([{ transform: `translate${axis}(${shift}px)` }, { transform: 'none' }], timing));
});
animations.push(d.digits.animate([{ transform: 'translateY(110%)' }, { transform: 'none' }], {
duration: 420, delay: timing.delay + OPEN * 0.55, easing: ARRIVE, fill: 'backwards',
}));
});
};
// Measured again whenever the layout moves (a resize, the web font coming in, new text);
// redrawn only if a value actually changed
const refresh = () => {
if (signal.aborted) return;
const m = measure();
if (!m.width || !m.height) return;
const key = JSON.stringify(m, (name, value) => (typeof value === 'number' ? Math.round(value) : value));
if (key === drawn) return;
drawn = key;
draw(m);
};
let frame = 0;
const soon = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(refresh);
};
const ro = new ResizeObserver(soon);
ro.observe(root);
const content = part('content');
if (content) ro.observe(content);
const fonts = document.fonts?.ready || Promise.resolve();
fonts.then(soon);
const io = new IntersectionObserver((entries) => {
if (entered || !entries[entries.length - 1].isIntersecting) return;
entered = true;
io.disconnect();
// Played once the web font is in, so the values it opens on are the ones that stay
fonts.then(() => {
if (signal.aborted) return;
cancelAnimationFrame(frame);
refresh();
sheet.classList.remove('is-waiting');
play();
});
}, { threshold: 0.25 });
if (!entered) io.observe(root);
refresh();
signal.addEventListener('abort', () => {
cancelAnimationFrame(frame);
animations.forEach((a) => a.cancel());
io.disconnect();
ro.disconnect();
sheet.remove();
});
}
// 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 — Dimension Lines, for React. From https://kodza.dev/components/dimension-lines/
// 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: dimension-lines.css and dimension-lines.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.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './dimension-lines.css';
export type DimensionLinesProps = Omit<ComponentPropsWithoutRef<'section'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** the paper — default: #f2f2f0 */
"--kz-dimension-lines-bg"?: string | number;
/** the lines, the text, the button — default: #0a0a0a */
"--kz-dimension-lines-ink"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-dimension-lines-muted"?: string | number;
/** opacity of the dimension lines and arrows, 0 to 1 — default: 0.4 */
"--kz-dimension-lines-lines"?: string | number;
/** opacity of the construction lines — default: 0.09 */
"--kz-dimension-lines-guides"?: string | number;
/** opacity of the values — default: 0.62 */
"--kz-dimension-lines-values"?: string | number;
/** default: 600px */
"--kz-dimension-lines-height"?: string | number;
/** the text column — default: 1152px */
"--kz-dimension-lines-width"?: string | number;
/** default: clamp(20px, 5vw, 64px) */
"--kz-dimension-lines-side"?: string | number;
};
className?: string;
};
export function DimensionLines({ vars, className, style, ...rest }: DimensionLinesProps) {
const ref = useRef<ComponentRef<'section'>>(null);
const classes = ["kodza-dimension-lines", 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('./dimension-lines.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 (
<section data-kodza-dimension-lines="" key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<div className="kodza-dimension-lines__content">
<p className="kodza-dimension-lines__note">Sheet A-01 · scale 1:1 · units px</p>
<p className="kodza-dimension-lines__eyebrow">{"Atelier Brun · interfaces & design systems · Nantes"}</p>
<div className="kodza-dimension-lines__grid">
<h1 className="kodza-dimension-lines__title">
<span className="kodza-dimension-lines__line">Off by one?</span>
{' '}
<span className="kodza-dimension-lines__line">Not here.</span>
</h1>
<div className="kodza-dimension-lines__side">
<p className="kodza-dimension-lines__lead">A two-person studio for product teams who spot a 1 px shift before their first coffee. Grids, specs and handoff files your developers never have to guess at.</p>
<p className="kodza-dimension-lines__actions">
<a className="kodza-dimension-lines__button" href="#">See the work</a>
{' '}
<a className="kodza-dimension-lines__button kodza-dimension-lines__button--ghost" href="#">How we measure</a>
</p>
</div>
</div>
</div>
</section>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.