Alert
A message in the page: note, success, warning or error, told apart by the icon, not by color. The icon draws itself, a dismissed alert folds away and an error unfolds its log.
View codeBones drawn from the content itself, one shine across them all. When it loads, a soft edge sweeps down and turns each bone into its line; late images keep theirs.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Show a Kodza Skeleton while my posts load.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<article class="kodza-skeleton kodza-skeleton--card" data-loading>
<div class="kodza-skeleton__media" data-bone="block">
<img src="https://kodza.dev/media/kz-steps-1400.webp" alt="Concrete steps climbing towards a bright opening" width="1400" height="933" />
</div>
<div class="kodza-skeleton__body">
<p class="kodza-skeleton__meta" data-bone>Changelog · 3 min read</p>
<h3 class="kodza-skeleton__title" data-bone>Version 2.0 deletes more code than it adds</h3>
<p class="kodza-skeleton__text" data-bone>Four thousand lines gone, zero features lost, one very confused linter.</p>
<p class="kodza-skeleton__by">
<span class="kodza-skeleton__avatar" data-bone="block">KZ</span>
<span data-bone>The Kodza team</span>
</p>
</div>
</article>
<ul class="kodza-skeleton kodza-skeleton--list" data-loading>
<li class="kodza-skeleton__row">
<span class="kodza-skeleton__avatar" data-bone="block">AL</span>
<span class="kodza-skeleton__lines"><strong data-bone>Ada merged #482</strong><span data-bone>Fixed the bug she wrote on Monday</span></span>
<span class="kodza-skeleton__time" data-bone>2m</span>
</li>
<li class="kodza-skeleton__row">
<span class="kodza-skeleton__avatar" data-bone="block">LT</span>
<span class="kodza-skeleton__lines"><strong data-bone>Linus opened #483</strong><span data-bone>Tabs or spaces, round 2,048</span></span>
<span class="kodza-skeleton__time" data-bone>14m</span>
</li>
<li class="kodza-skeleton__row">
<span class="kodza-skeleton__avatar" data-bone="block">GH</span>
<span class="kodza-skeleton__lines"><strong data-bone>Grace deployed v2.0</strong><span data-bone>Production is fine. Probably.</span></span>
<span class="kodza-skeleton__time" data-bone>1h</span>
</li>
</ul>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Skeleton
The bones are taken from the content itself: each line of text becomes a bar of its real
length, each image or avatar a block of its real shape, so nothing moves when it loads. One
shine runs across all the bones at once. Remove data-loading and the bones open in reading
order: each bar pulls away to the right and uncovers its line, the image settles from a
slight zoom, the avatar pops; an image that has not arrived yet keeps its bone until it
has. Mark the parts with data-bone (text) or data-bone="block" (image, avatar, any
box); keep placeholder words in them while loading, they give the bones their shape.
Ready-made layouts: --card and --list. Everything is tuned with the --kz-skel-* variables. */
.kodza-skeleton {
--kz-skel-bg: #ffffff;
--kz-skel-fg: #0a0a0a;
--kz-skel-muted: rgba(10, 10, 10, 0.62);
--kz-skel-border: rgba(10, 10, 10, 0.1);
--kz-skel-bone: #ededeb;
--kz-skel-shine: rgba(255, 255, 255, 0.85);
--kz-skel-speed: 1.6s;
--kz-skel-radius: 16px;
--kz-skel-pad: 28px;
position: relative;
box-sizing: border-box;
color: var(--kz-skel-fg);
}
/* The parts hide while loading (the bones are drawn over them) */
.kodza-skeleton[data-loading] [data-bone],
.kodza-skeleton [data-bone].is-waiting {
opacity: 0;
transition: opacity 0.2s ease;
}
/* The bones: one layer over the content, bars placed by the script */
.kodza-skeleton__bones {
position: absolute;
inset: 0;
z-index: 1;
overflow: hidden;
border-radius: inherit;
pointer-events: none;
}
.kodza-skeleton__bone {
position: absolute;
border-radius: 6px;
background-color: var(--kz-skel-bone);
background-image: linear-gradient(90deg, transparent, var(--kz-skel-shine), transparent);
background-repeat: no-repeat;
background-size: var(--kz-skel-band, 240px) 100%;
background-position: calc(var(--kz-skel-band, 240px) * -1 - var(--kz-skel-x, 0px)) 0;
animation: kodza-skeleton-shine var(--kz-skel-speed) cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
/* A line of text: a bar a little thinner than the words */
.kodza-skeleton__bone.is-line {
transform: scaleY(0.62);
}
/* Every bone uses the same clock and the card's coordinates: one shine crosses them all */
@keyframes kodza-skeleton-shine {
0% {
background-position: calc(var(--kz-skel-band, 240px) * -1 - var(--kz-skel-x, 0px)) 0;
}
70%,
100% {
background-position: calc(var(--kz-skel-w, 600px) - var(--kz-skel-x, 0px)) 0;
}
}
/* Card */
.kodza-skeleton--card {
display: flex;
flex-direction: column;
overflow: hidden;
border-radius: var(--kz-skel-radius);
background: var(--kz-skel-bg);
box-shadow: inset 0 0 0 1px var(--kz-skel-border);
}
.kodza-skeleton__media {
aspect-ratio: 4 / 3;
overflow: hidden;
}
.kodza-skeleton__media img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.kodza-skeleton__body {
display: grid;
gap: 10px;
padding: var(--kz-skel-pad);
}
.kodza-skeleton__meta {
margin: 0;
justify-self: start;
color: var(--kz-skel-muted);
font-size: 13px;
}
.kodza-skeleton__title {
margin: 0;
font-size: 22px;
font-weight: 600;
line-height: 1.25;
letter-spacing: -0.02em;
text-wrap: balance;
}
.kodza-skeleton__text {
margin: 0;
color: var(--kz-skel-muted);
font-size: 15px;
line-height: 1.55;
text-wrap: pretty;
}
.kodza-skeleton__by {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0 0;
font-size: 14px;
font-weight: 500;
}
.kodza-skeleton__avatar {
display: grid;
flex: none;
place-items: center;
width: 32px;
height: 32px;
border-radius: 50%;
background: var(--kz-skel-fg);
color: var(--kz-skel-bg);
font-size: 12px;
font-weight: 600;
letter-spacing: 0.02em;
}
/* List */
.kodza-skeleton--list {
margin: 0;
padding: 8px var(--kz-skel-pad);
border-radius: var(--kz-skel-radius);
background: var(--kz-skel-bg);
box-shadow: inset 0 0 0 1px var(--kz-skel-border);
list-style: none;
}
.kodza-skeleton__row {
display: flex;
align-items: center;
gap: 14px;
padding: 16px 0;
}
.kodza-skeleton__row + .kodza-skeleton__row {
border-top: 1px solid var(--kz-skel-border);
}
.kodza-skeleton__row .kodza-skeleton__avatar {
width: 40px;
height: 40px;
font-size: 13px;
}
.kodza-skeleton__lines {
display: grid;
flex: 1;
justify-items: start;
gap: 2px;
min-width: 0;
font-size: 15px;
line-height: 1.45;
}
.kodza-skeleton__lines strong {
font-weight: 600;
}
.kodza-skeleton__lines span {
color: var(--kz-skel-muted);
font-size: 14px;
}
.kodza-skeleton__time {
align-self: flex-start;
margin-top: 2px;
color: var(--kz-skel-muted);
font-size: 13px;
font-variant-numeric: tabular-nums;
}
@media (prefers-reduced-motion: reduce) {
.kodza-skeleton__bone {
animation: none;
}
.kodza-skeleton[data-loading] [data-bone] {
transition: none;
}
}
/* Theming example — on a dark background:
.dark-section .kodza-skeleton {
--kz-skel-bg: #161616;
--kz-skel-fg: #f2f2f0;
--kz-skel-muted: rgba(242, 242, 240, 0.62);
--kz-skel-border: rgba(255, 255, 255, 0.12);
--kz-skel-bone: #232323;
--kz-skel-shine: rgba(255, 255, 255, 0.07);
}
*/
/* kodza-guard 958420f1ca00 — 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-skeleton):not(#_) {
padding: revert;
list-style: revert;
}
:where(.kodza-skeleton__meta):not(#_),
:where(.kodza-skeleton__title):not(#_),
:where(.kodza-skeleton__text):not(#_),
:where(.kodza-skeleton__by):not(#_),
:where(.kodza-skeleton__media img:where(:not([class*="kodza-"]))):not(#_),
:where(.kodza-skeleton__lines strong:where(:not([class*="kodza-"]))):not(#_) {
transition: revert;
}
:where(.kodza-skeleton__row):not(#_) {
transition: revert;
border-top-width: revert;
border-top-style: revert;
border-top-color: revert;
}
:where(.kodza-skeleton):not(#_):where(:not([hidden])) {
display: revert;
}
:where(.kodza-skeleton):not(#_):where([hidden]) {
display: none;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-skeleton:not(#_) {
border: revert;
outline: revert;
text-decoration: revert;
transition: revert;
outline-offset: revert;
appearance: revert;
max-height: 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-skeleton__media:not(#_),
.kodza-skeleton__body:not(#_),
.kodza-skeleton__avatar:not(#_),
.kodza-skeleton__bones:not(#_),
.kodza-skeleton__bone:not(#_),
.kodza-skeleton__lines:not(#_),
.kodza-skeleton__time:not(#_),
.kodza-skeleton__by span:where(:not([class*="kodza-"])):not(#_),
.kodza-skeleton__lines span:where(:not([class*="kodza-"])):not(#_) {
box-sizing: revert;
}
.kodza-skeleton__meta: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;
font-family: 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-skeleton__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-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-skeleton__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-width: 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-skeleton__by: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-family: 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-skeleton__row:not(#_) {
margin: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
border-right-width: revert;
border-bottom-width: revert;
border-left-width: revert;
border-right-style: revert;
border-bottom-style: revert;
border-left-style: revert;
border-right-color: revert;
border-bottom-color: revert;
border-left-color: 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-skeleton__media img:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: 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-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-skeleton__lines strong:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: 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-family: revert;
font-size: 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-skeleton__meta:not(#_):where(:not([hidden])),
.kodza-skeleton__title:not(#_):where(:not([hidden])),
.kodza-skeleton__text:not(#_):where(:not([hidden])),
.kodza-skeleton__lines strong:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-skeleton__meta:not(#_):where([hidden]),
.kodza-skeleton__title:not(#_):where([hidden]),
.kodza-skeleton__text:not(#_):where([hidden]),
.kodza-skeleton__lines strong:where(:not([class*="kodza-"])):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-skeleton:not(#_) {
position: relative;
box-sizing: border-box;
color: var(--kz-skel-fg);
}
.kodza-skeleton[data-loading] [data-bone]:where(img, p, h3, li, strong):not(#_),
.kodza-skeleton [data-bone].is-waiting:where(img, p, h3, li, strong):not(#_) {
transition: opacity 0.2s ease;
}
.kodza-skeleton--card:not(#_) {
display: flex;
border-radius: var(--kz-skel-radius);
background: var(--kz-skel-bg);
box-shadow: inset 0 0 0 1px var(--kz-skel-border);
}
.kodza-skeleton__media img:not(#_) {
display: block;
}
.kodza-skeleton__meta:not(#_) {
margin: 0;
color: var(--kz-skel-muted);
font-size: 13px;
}
.kodza-skeleton__title:not(#_) {
margin: 0;
font-size: 22px;
font-weight: 600;
line-height: 1.25;
letter-spacing: -0.02em;
}
.kodza-skeleton__text:not(#_) {
margin: 0;
color: var(--kz-skel-muted);
font-size: 15px;
line-height: 1.55;
}
.kodza-skeleton__by:not(#_) {
display: flex;
margin: 8px 0 0;
font-size: 14px;
font-weight: 500;
}
.kodza-skeleton--list:not(#_) {
padding: 8px var(--kz-skel-pad);
border-radius: var(--kz-skel-radius);
background: var(--kz-skel-bg);
box-shadow: inset 0 0 0 1px var(--kz-skel-border);
list-style: none;
}
.kodza-skeleton__row:not(#_) {
display: flex;
padding: 16px 0;
}
.kodza-skeleton__row + .kodza-skeleton__row:not(#_) {
border-top: 1px solid var(--kz-skel-border);
}
.kodza-skeleton__lines strong:not(#_) {
font-weight: 600;
}
@media (prefers-reduced-motion: reduce) {
.kodza-skeleton[data-loading] [data-bone]:where(img, p, h3, li, strong):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 — Skeleton
// Draws the bones from the content (one bar per line of text, one block per data-bone="block"),
// in the skeleton's own pixels so a scaled parent does not shift them, and redraws them when the
// size changes. When data-loading goes, the bones open in reading order: each bar swells to the
// height of its line and pulls away to the right, uncovering the words; a block lifts off its
// image, which settles from a slight zoom; an avatar pops. An image still on its way keeps its
// bone until it has loaded. Set data-loading again to go back to the bones.
(() => {
const SELECTOR = '.kodza-skeleton';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const STEP = 70; // between two bones, in reading order
const SWELL = 220; // a bar swells to the height of its line
const PULL = 420; // then pulls away to the right
const inOut = 'cubic-bezier(0.76, 0, 0.24, 1)';
const out = 'cubic-bezier(0.22, 1, 0.36, 1)';
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const parts = [...root.querySelectorAll('[data-bone]')];
if (!parts.length) return;
const layer = Object.assign(document.createElement('span'), { className: 'kodza-skeleton__bones' });
layer.setAttribute('aria-hidden', 'true');
root.append(layer);
const bones = new Map(); // part → its bars
const unloaded = (part) => [...(part.matches('img') ? [part] : part.querySelectorAll('img'))].some((img) => !img.complete || !img.naturalWidth);
// One bar per line of text (a little thinner than the line), or the part's own box
const draw = () => {
layer.replaceChildren();
bones.clear();
const box = root.getBoundingClientRect();
const k = box.width / root.offsetWidth || 1;
root.style.setProperty('--kz-skel-w', `${root.offsetWidth}px`);
root.style.setProperty('--kz-skel-band', `${Math.round(root.offsetWidth * 0.45)}px`);
parts.forEach((part) => {
if (!root.hasAttribute('data-loading') && !part.classList.contains('is-waiting')) return;
const block = part.dataset.bone === 'block' || !part.textContent.trim();
let rects;
if (block) rects = [part.getBoundingClientRect()];
else {
const range = document.createRange();
range.selectNodeContents(part);
rects = [...range.getClientRects()].filter((r) => r.width > 1);
}
const radius = block ? getComputedStyle(part).borderRadius : '';
const bars = rects.map((r) => {
const x = (r.left - box.left) / k;
const w = r.width / k;
const full = r.height / k;
const h = full;
const y = (r.top - box.top) / k;
const bar = Object.assign(document.createElement('span'), { className: 'kodza-skeleton__bone' });
Object.assign(bar.style, { left: `${x}px`, top: `${y}px`, width: `${w}px`, height: `${h}px` });
if (block) bar.style.borderRadius = radius;
else bar.classList.add('is-line');
bar.style.setProperty('--kz-skel-x', `${x}px`);
layer.append(bar);
return { bar, y, h };
});
bones.set(part, bars);
});
};
const reveal = (list) => {
const box = root.getBoundingClientRect();
const k = box.width / root.offsetWidth || 1;
const top = (el) => el.getBoundingClientRect().top;
let order = 0;
[...list].sort((a, b) => top(a) - top(b)).forEach((part) => {
part.classList.remove('is-waiting');
const bars = bones.get(part) || [];
bones.delete(part);
if (reduceMotion) return bars.forEach(({ bar }) => bar.remove());
const block = part.dataset.bone === 'block' || !part.textContent.trim();
if (block) {
const delay = order++ * STEP;
const img = part.matches('img') ? part : part.querySelector('img');
// The bone lifts off, quick at first so the image never shows as a thin line under
// it; the image settles from a slight zoom, an avatar pops
bars.forEach(({ bar }) => {
bar.style.transformOrigin = img ? '50% 0' : '50% 50%';
bar.animate([{ transform: 'none' }, { transform: img ? 'scaleY(0)' : 'scale(0)' }], { duration: img ? 650 : 420, delay, easing: img ? out : inOut, fill: 'forwards' }).onfinish = () => bar.remove();
});
if (img) img.animate([{ transform: 'scale(1.14)' }, { transform: 'none' }], { duration: 1300, delay, easing: out, fill: 'backwards' });
else part.animate([{ transform: 'scale(0.4)', opacity: 0 }, { transform: 'scale(1.08)', opacity: 1, offset: 0.6 }, { transform: 'none', opacity: 1 }], { duration: 520, delay: delay + 140, easing: out, fill: 'backwards' });
return;
}
// Each line: the bars of a part swell together to the height of the words, which show
// only once every bar covers its line (no ascender or descender peeks out); then each
// bar pulls away to the right, one line after the other
const delay = order * STEP;
order += bars.length;
bars.forEach(({ bar }, i) => {
const hold = SWELL + i * STEP;
const duration = hold + PULL;
bar.style.transformOrigin = '100% 50%';
bar.animate([
{ transform: 'scale(1, 0.62)', easing: out },
{ transform: 'scale(1, 1)', offset: SWELL / duration },
{ transform: 'scale(1, 1)', offset: hold / duration, easing: inOut },
{ transform: 'scale(0, 1)' },
], { duration, delay, fill: 'forwards' }).onfinish = () => bar.remove();
});
if (bars.length) part.animate({ opacity: [0, 0] }, { duration: delay + SWELL });
});
};
const finish = () => {
root.removeAttribute('aria-busy');
// Images still on their way keep their bones, and come in on their own
const late = parts.filter(unloaded);
late.forEach((part) => {
part.classList.add('is-waiting');
part.querySelectorAll('img').forEach((img) => img.addEventListener('load', () => {
if (!root.hasAttribute('data-loading') && part.classList.contains('is-waiting') && !unloaded(part)) reveal([part]);
}, { once: true, signal }));
});
reveal(parts.filter((part) => !late.includes(part)));
};
const start = () => {
root.setAttribute('aria-busy', 'true');
// Stop a reveal still playing, but not the fade of the content under the bones
parts.forEach((part) => {
part.getAnimations({ subtree: true }).forEach((animation) => animation instanceof CSSTransition || animation.cancel());
});
draw();
if (!reduceMotion) layer.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 220, easing: 'ease' });
};
if (root.hasAttribute('data-loading')) start();
const mutations = new MutationObserver(() => (root.hasAttribute('data-loading') ? start() : finish()));
mutations.observe(root, { attributes: true, attributeFilter: ['data-loading'] });
const resize = new ResizeObserver(() => (root.hasAttribute('data-loading') || parts.some((part) => part.classList.contains('is-waiting'))) && draw());
resize.observe(root);
signal.addEventListener('abort', () => {
mutations.disconnect();
resize.disconnect();
});
document.fonts?.ready.then(() => !signal.aborted && root.hasAttribute('data-loading') && draw());
}
// 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.
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
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();
instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
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.controller.abort();
[...root.attributes].forEach((a) => root.removeAttribute(a.name));
instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
root.innerHTML = instance.html;
});
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 — Skeleton, for React. From https://kodza.dev/components/skeleton-loader/
// 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: skeleton-loader.css and skeleton-loader.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 './skeleton-loader.css';
type Variant = "card" | "list";
export type SkeletonProps = Omit<ComponentPropsWithoutRef<'article'>, "children" | "variant" | "vars" | "loading"> & {
/** Modifier class(es): .kodza-skeleton--card, .kodza-skeleton--list */
variant?: Variant | Variant[];
/** data-loading on the root */
loading?: string;
/** Settings, as CSS variables on the root */
vars?: {
/** default: #ffffff */
"--kz-skel-bg"?: string | number;
/** default: #0a0a0a */
"--kz-skel-fg"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-skel-muted"?: string | number;
/** default: rgba(10, 10, 10, 0.1) */
"--kz-skel-border"?: string | number;
/** default: #ededeb */
"--kz-skel-bone"?: string | number;
/** default: rgba(255, 255, 255, 0.85) */
"--kz-skel-shine"?: string | number;
/** default: 1.6s */
"--kz-skel-speed"?: string | number;
/** default: 16px */
"--kz-skel-radius"?: string | number;
/** default: 28px */
"--kz-skel-pad"?: string | number;
};
className?: string;
};
export function Skeleton({ variant, loading, vars, className, style, ...rest }: SkeletonProps) {
const ref = useRef<ComponentRef<'article'>>(null);
const classes = ["kodza-skeleton", "kodza-skeleton--card", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-skeleton--${v}`), 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, loading, 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('./skeleton-loader.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 (
<article key={key} {...rest} className={classes} data-loading={loading} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<div className="kodza-skeleton__media" data-bone="block">
<img src="https://kodza.dev/media/kz-steps-1400.webp" alt="Concrete steps climbing towards a bright opening" width="1400" height="933" />
</div>
<div className="kodza-skeleton__body">
<p className="kodza-skeleton__meta" data-bone="">Changelog · 3 min read</p>
<h3 className="kodza-skeleton__title" data-bone="">Version 2.0 deletes more code than it adds</h3>
<p className="kodza-skeleton__text" data-bone="">Four thousand lines gone, zero features lost, one very confused linter.</p>
<p className="kodza-skeleton__by">
<span className="kodza-skeleton__avatar" data-bone="block">KZ</span>
{' '}
<span data-bone="">The Kodza team</span>
</p>
</div>
</article>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.