Files
Spaghet.io/public/js/bg.js
T
spaghet 9e157a4fa3 feat(theme): implement dual light/dark colour token system with WCAG AA contrast
Replace hard-coded hex values and ad-hoc `dark:` variants with a single
semantic token layer in `src/styles/global.css` (`@theme` + `html.dark`
re-declaration), so every component uses the same Tailwind class list in
both modes.

Key changes:
- Define semantic tokens (page, surface, ink, accent, edge, etc.) and raw
  ingredient palette (--color-spaghetti-*, --color-marinara*, etc.)
- Configure dual Shiki themes (light-plus / everforest-dark) with
  `defaultColor: false` for proper per-mode code block colours, replacing
  the old `.prose pre { #1f2937 !important }` hack
- Tint background particles to match the warm cream/espresso palette
  instead of pure black dots
- Document theme rules: add tokens not `dark:` variants, keep colour rules
  inside `@layer`, never target Tailwind utility classes with unlayered
  overrides, route prose colours through `--tw-prose-*` only

All text and interactive elements meet WCAG AA contrast (4.5:1 body, 3:1
large/interactive). Light mode is a warm cream plate with white cards; dark
mode is espresso (#140C08) with raised cards.
2026-11-12 20:48:10 -05:00

100 lines
2.7 KiB
JavaScript

// Light-mode "particles" are grains of parmesan over the cream plate, not
// hard black dots: #000 at 1-2px reads as dirt and fights the pasta palette.
// Tinted with the ink token's hue and kept low-contrast on purpose.
function generateParticles(n) {
let value = `${getRandom(2560)}px ${getRandom(2560)}px #C9B49B`;
for (let i = 2; i <= n; i++) {
value += `, ${getRandom(2560)}px ${getRandom(2560)}px #C9B49B`;
}
return value;
}
// Dark-mode stars: parmesan and cream over espresso (#140C08), not pure black.
function generateStars(n) {
let value = `${getRandom(2560)}px ${getRandom(2560)}px #FFF6E5`;
for (let i = 2; i <= n; i++) {
value += `, ${getRandom(2560)}px ${getRandom(2560)}px #F5E6D3`;
}
return value;
}
function getRandom(max) {
return Math.floor(Math.random() * max);
}
function initBG() {
const particlesSmall = generateParticles(1000);
const particlesMedium = generateParticles(500);
const particlesLarge = generateParticles(250);
const particles1 = document.getElementById('particles1');
const particles2 = document.getElementById('particles2');
const particles3 = document.getElementById('particles3');
if (particles1) {
particles1.style.cssText = `
width: 1px;
height: 1px;
border-radius: 50%;
box-shadow: ${particlesSmall};
animation: animStar 50s linear infinite;
`;
}
if (particles2) {
particles2.style.cssText = `
width: 1.5px;
height: 1.5px;
border-radius: 50%;
box-shadow: ${particlesMedium};
animation: animateParticle 100s linear infinite;
`;
}
if (particles3) {
particles3.style.cssText = `
width: 2px;
height: 2px;
border-radius: 50%;
box-shadow: ${particlesLarge};
animation: animateParticle 150s linear infinite;
`;
}
const starsSmall = generateStars(1000);
const starsMedium = generateStars(500);
const starsLarge = generateStars(250);
const stars1 = document.getElementById('stars1');
const stars2 = document.getElementById('stars2');
const stars3 = document.getElementById('stars3');
if (stars1) {
stars1.style.cssText = `
width: 1px;
height: 1px;
border-radius: 50%;
box-shadow: ${starsSmall};
`;
}
if (stars2) {
stars2.style.cssText = `
width: 1.5px;
height: 1.5px;
border-radius: 50%;
box-shadow: ${starsMedium};
`;
}
if (stars3) {
stars3.style.cssText = `
width: 2px;
height: 2px;
border-radius: 50%;
box-shadow: ${starsLarge};
`;
}
}
document.addEventListener('astro:after-swap', initBG);
initBG();