Skip to content

Leonxlnx/taste-skill / skills/taste-skill

design-taste-frontend

Verified

tasteskill 2.5.1, the anti-slop frontend skill. Builds professional company websites at the level of figma.com and x.ai: plain copy in a voice of its own, one system, one section per screen, equal edges, real photographs and real product UI (licensed stand-in photographs when the client has none; a product render only when the brief asks for 3D), a hero entrance and one or two dealt moments on every page, shader effects and scenes only on tech, gaming and software pages, quiet micro-interactions, and a checker and finish gate that enforce it in a real browser. Use this whenever you build, design, redesign, restyle, polish or review a landing page, company, product, shop, cafe, hotel, studio, SaaS, AI, developer-tool or game site, as static HTML/CSS or inside an existing React, Next.js, Vue, Svelte, Astro or Tailwind project, or when the user says a page looks generic, templated or "AI-made".

FileKindSize
SKILL.mdskill md30.2 KB
assets/backgrounds/backgrounds.cssother41.5 KB
assets/backgrounds/backgrounds.jsscript8.9 KB
assets/backgrounds/check.htmlother4.8 KB
assets/backgrounds/check.mjsscript14.2 KB
assets/backgrounds/demo.htmlother43.3 KB
assets/backgrounds/index.jsonconfig19.6 KB
assets/backgrounds/pick.mjsscript14.0 KB
assets/components/_lab.htmlother6.4 KB
assets/components/base.cssother7.6 KB
assets/components/fx-avatar/component.cssother3.3 KB
assets/components/fx-avatar/component.htmlother1.2 KB
assets/components/fx-avatar/component.jsscript2.7 KB
assets/components/fx-avatar/meta.jsonconfig870 B
assets/components/fx-band/component.cssother1.4 KB
assets/components/fx-band/component.htmlother482 B
assets/components/fx-band/component.jsscript2.7 KB
assets/components/fx-band/meta.jsonconfig1.1 KB
assets/components/fx-bars/component.cssother3.4 KB
assets/components/fx-bars/component.htmlother2.3 KB
assets/components/fx-bars/component.jsscript2.2 KB
assets/components/fx-bars/meta.jsonconfig1.2 KB
assets/components/fx-button/component.cssother1.6 KB
assets/components/fx-button/component.htmlother798 B
assets/components/fx-button/component.jsscript3.0 KB
assets/components/fx-button/meta.jsonconfig1.1 KB
assets/components/fx-chart/component.cssother3.4 KB
assets/components/fx-chart/component.htmlother1.2 KB
assets/components/fx-chart/component.jsscript5.3 KB
assets/components/fx-chart/meta.jsonconfig1.3 KB
assets/components/fx-dither-object/component.cssother452 B
assets/components/fx-dither-object/component.htmlother177 B
assets/components/fx-dither-object/component.jsscript24.1 KB
assets/components/fx-dither-object/meta.jsonconfig2.7 KB
assets/components/fx-feature-card/component.cssother10.7 KB
assets/components/fx-feature-card/component.htmlother8.9 KB
assets/components/fx-feature-card/component.jsscript12.1 KB
assets/components/fx-feature-card/meta.jsonconfig3.0 KB
assets/components/fx-globe/component.cssother2.2 KB
assets/components/fx-globe/component.htmlother1.6 KB
assets/components/fx-globe/component.jsscript1.3 KB
assets/components/fx-globe/meta.jsonconfig819 B
assets/components/fx-headline/component.cssother1.6 KB
assets/components/fx-headline/component.htmlother833 B
assets/components/fx-headline/component.jsscript742 B
assets/components/fx-headline/meta.jsonconfig964 B
assets/components/fx-icon-tiles/component.cssother1.7 KB
assets/components/fx-icon-tiles/component.htmlother2.1 KB
assets/components/fx-icon-tiles/component.jsscript1.4 KB
assets/components/fx-icon-tiles/meta.jsonconfig922 B
assets/components/fx-logos/component.cssother2.0 KB
assets/components/fx-logos/component.htmlother12.4 KB
assets/components/fx-logos/component.jsscript1.2 KB
assets/components/fx-logos/meta.jsonconfig1.0 KB
assets/components/fx-map/bake.mjsscript25.2 KB
assets/components/fx-map/component.cssother10.6 KB
assets/components/fx-map/component.htmlother1.2 KB
assets/components/fx-map/component.jsscript14.4 KB
assets/components/fx-map/meta.jsonconfig2.6 KB
assets/components/fx-map/sample-map.jsonconfig55.7 KB
assets/components/fx-photo/component.cssother2.0 KB
assets/components/fx-photo/component.htmlother553 B
assets/components/fx-photo/component.jsscript1.9 KB
assets/components/fx-photo/meeting-room.jpgbinary198.7 KB
assets/components/fx-photo/meta.jsonconfig1.8 KB
assets/components/fx-pricing/component.cssother3.8 KB
assets/components/fx-pricing/component.htmlother1.8 KB
assets/components/fx-pricing/component.jsscript1.5 KB
assets/components/fx-pricing/meta.jsonconfig971 B
assets/components/fx-progress/component.cssother2.9 KB
assets/components/fx-progress/component.htmlother2.0 KB
assets/components/fx-progress/component.jsscript4.3 KB
assets/components/fx-progress/meta.jsonconfig1.3 KB
assets/components/fx-prompt/component.cssother3.1 KB
assets/components/fx-prompt/component.htmlother1.3 KB
assets/components/fx-prompt/component.jsscript1.1 KB
assets/components/fx-prompt/meta.jsonconfig782 B
assets/components/fx-search/component.cssother2.6 KB
assets/components/fx-search/component.htmlother1.4 KB
assets/components/fx-search/component.jsscript4.9 KB
assets/components/fx-search/meta.jsonconfig953 B
assets/components/fx-spotlight/component.cssother1.8 KB
assets/components/fx-spotlight/component.htmlother1.6 KB
assets/components/fx-spotlight/component.jsscript4.0 KB
assets/components/fx-spotlight/meta.jsonconfig1.1 KB
assets/components/fx-stat/component.cssother1.6 KB
assets/components/fx-stat/component.htmlother694 B
assets/components/fx-stat/component.jsscript1.2 KB
assets/components/fx-stat/meta.jsonconfig1.1 KB
assets/components/fx-tabs/component.cssother5.0 KB
assets/components/fx-tabs/component.htmlother2.9 KB
assets/components/fx-tabs/component.jsscript3.1 KB
assets/components/fx-tabs/meta.jsonconfig1.2 KB
assets/components/index.htmlother18.6 KB
assets/components/shared.jsscript25.9 KB
assets/diagrams/demo.htmlother11.4 KB
assets/diagrams/diagram.cssother25.5 KB
assets/diagrams/diagram.jsscript89.2 KB
assets/diagrams/lab.htmlother11.2 KB
assets/diagrams/mount.jsscript609 B
assets/diagrams/presets.jsonconfig27.8 KB
assets/effects/README.mdmarkdown9.8 KB
assets/effects/ascii-shade/effect.jsscript18.3 KB
assets/effects/ascii-shade/meta.jsonconfig372 B
assets/effects/aurora-curtains/effect.jsscript9.2 KB
assets/effects/aurora-curtains/meta.jsonconfig361 B
assets/effects/bayer-dither/effect.jsscript5.9 KB
assets/effects/bayer-dither/meta.jsonconfig311 B
assets/effects/caustics/effect.jsscript7.3 KB
assets/effects/caustics/meta.jsonconfig357 B
assets/effects/contour-lines/effect.jsscript8.2 KB
assets/effects/contour-lines/meta.jsonconfig358 B
assets/effects/dot-terrain/effect.jsscript9.2 KB
assets/effects/dot-terrain/meta.jsonconfig332 B
assets/effects/dotted-globe/effect.jsscript52.9 KB
assets/effects/dotted-globe/meta.jsonconfig546 B
assets/effects/duotone-grade/effect.jsscript33.7 KB
assets/effects/duotone-grade/meta.jsonconfig395 B
assets/effects/edge-glow/effect.jsscript10.6 KB
assets/effects/edge-glow/meta.jsonconfig427 B
assets/effects/film-light-leak/effect.jsscript12.2 KB
assets/effects/film-light-leak/meta.jsonconfig343 B
assets/effects/fluted-glass/effect.jsscript9.7 KB
assets/effects/fluted-glass/meta.jsonconfig305 B
assets/effects/fx.jsscript40.5 KB
assets/effects/gallery.htmlother37.4 KB
assets/effects/god-rays/effect.jsscript9.1 KB
assets/effects/god-rays/meta.jsonconfig318 B
assets/effects/gradient-mesh/effect.jsscript11.0 KB
assets/effects/gradient-mesh/meta.jsonconfig334 B
assets/effects/grain-gradient/effect.jsscript8.1 KB
assets/effects/grain-gradient/meta.jsonconfig311 B
assets/effects/grid-pulse/effect.jsscript18.6 KB
assets/effects/grid-pulse/meta.jsonconfig343 B
assets/effects/halftone-screen/effect.jsscript12.8 KB
assets/effects/halftone-screen/meta.jsonconfig342 B
assets/effects/index.jsonconfig36.7 KB
assets/effects/lab.htmlother31.0 KB
assets/effects/line-engraving/effect.jsscript12.4 KB
assets/effects/line-engraving/meta.jsonconfig343 B
assets/effects/orb-sphere/effect.jsscript14.2 KB
assets/effects/orb-sphere/meta.jsonconfig366 B
assets/effects/painterly-landscape/effect.jsscript12.8 KB
assets/effects/painterly-landscape/meta.jsonconfig364 B
assets/effects/pick.jsscript10.1 KB
assets/effects/prism-dispersion/effect.jsscript9.6 KB
assets/effects/prism-dispersion/meta.jsonconfig331 B
assets/effects/ridgeline/effect.jsscript19.2 KB
assets/effects/ridgeline/meta.jsonconfig460 B
assets/effects/ruled-grounds/effect.jsscript11.3 KB
assets/effects/ruled-grounds/meta.jsonconfig357 B
assets/effects/silk-folds/effect.jsscript10.4 KB
assets/effects/silk-folds/meta.jsonconfig348 B
assets/effects/soft-light-bars/effect.jsscript21.1 KB
assets/effects/soft-light-bars/meta.jsonconfig391 B
assets/effects/spotlight-cone/effect.jsscript7.3 KB
assets/effects/spotlight-cone/meta.jsonconfig349 B
assets/icons/demo.htmlother475.1 KB
assets/icons/demo/adyen.svgother2.4 KB
assets/icons/demo/after-effects.svgother5.2 KB
assets/icons/demo/ai.svgother795 B
assets/icons/demo/airbnb.svgother5.2 KB
assets/icons/demo/airbyte.svgother3.0 KB
assets/icons/demo/airflow.svgother3.4 KB
assets/icons/demo/airtable.svgother1.8 KB
assets/icons/demo/akamai.svgother5.5 KB
assets/icons/demo/algolia.svgother11.5 KB
assets/icons/demo/alpinejs.svgother343 B
assets/icons/demo/amd.svgother1.5 KB
assets/icons/demo/amex.svgother8.4 KB
assets/icons/demo/amplitude.svgother3.3 KB
assets/icons/demo/android.svgother4.7 KB
assets/icons/demo/angular.svgother1.8 KB
assets/icons/demo/ansible.svgother5.4 KB
assets/icons/demo/anthropic.svgother1.2 KB
assets/icons/demo/app-store.svgother2.9 KB
assets/icons/demo/apple-pay.svgother3.1 KB
assets/icons/demo/apple.svgother1.2 KB
assets/icons/demo/arc.svgother4.6 KB
assets/icons/demo/archlinux.svgother1.0 KB
assets/icons/demo/arduino.svgother6.7 KB
assets/icons/demo/argo.svgother22.7 KB
assets/icons/demo/arm.svgother2.5 KB
assets/icons/demo/asana.svgother1004 B
assets/icons/demo/astro.svgother3.1 KB
assets/icons/demo/audio.svgother516 B
assets/icons/demo/auth0.svgother759 B
assets/icons/demo/aws.svgother7.9 KB
assets/icons/demo/azure.svgother3.2 KB
assets/icons/demo/babel.svgother68.6 KB
assets/icons/demo/basecamp.svgother3.4 KB
assets/icons/demo/baseten.svgother1.3 KB
assets/icons/demo/bash.svgother4.2 KB
assets/icons/demo/battle-net.svgother1.1 KB
assets/icons/demo/behance.svgother12.4 KB
assets/icons/demo/bitbucket.svgother1.5 KB
assets/icons/demo/bitcoin.svgother2.3 KB
assets/icons/demo/blender.svgother3.7 KB
assets/icons/demo/bluesky.svgother1.0 KB
assets/icons/demo/bootstrap.svgother2.0 KB

assets/components/shared.js

View on GitHub
/*
  taste-skill components - shared helpers. Every component imports this file and fx.js from
  ../effects/. A component folder holds component.html (the markup), component.css, component.js
  (export default init(root) -> { destroy }) and meta.json.

  Four ways a component puts an effect somewhere other than a background:
    fill(el, id)      the glyphs of el (or its [data-fill] parts) show the effect: type, numbers, icons, logos
    windows(el, ...)  one effect seen only through a few shapes (icon chips, bars, cards): one canvas, many holes
    ring              a host with the class cx-ring shows its effect only in a thin border (padding = width)
    glow              a host with the class cx-glow is blurred into a soft light behind an object
  All of them take their colours from the page palette (fx.readPalette), never a fixed hue.

  Every part whose motion runs on its own for more than about 5 s gets pauser(): a round pause button
  in one corner of the looping visual (WCAG 2.2.2).

  Cost (a laptop's integrated GPU shares its memory with everything else):
    still(el, id)     an effect that does not move is drawn once, kept as a plain picture and its WebGL
                      context freed: it costs no context and no frames at rest. Stills draw one after
                      another, so they never hold more than one context at a time on the whole page.
                      fill(el, id, { still: true }) does the same inside glyphs.
    a page keeps at most 3 live WebGL contexts (moving effects only); everything pauses off screen
    and in a hidden tab (fx.js does this for every mounted effect).
*/
import fx from '../effects/fx.js';

export { fx };
export const color = fx.color;

const mqReduce = window.matchMedia('(prefers-reduced-motion: reduce)');
const mqHover = window.matchMedia('(hover: hover) and (pointer: fine)');
export const reduced = () => mqReduce.matches;
export const hoverable = () => mqHover.matches;

export const palette = el => fx.readPalette(el);
export const isDark = p => color.isDark(p.bg);
/** a step of ink over the ground, the same mix the CSS does with color-mix(in oklab, ink k, bg) */
export const tone = (p, k) => color.mix(p.bg, p.ink, k);

/** move c's lightness away from `against` until the contrast reaches min */
export function safe(c, against, min = 4.5) {
  let out = c;
  const away = color.isDark(against) ? 0.02 : -0.02;
  for (let i = 0; i < 40 && color.contrast(out, against) < min; i++) out = color.lighten(out, away);
  return out;
}

/**
  The palette for an effect drawn inside glyphs: the opposite ground, so the fill reads as ink.
  On a dark page the letters come out pale with the accent moving in them; on a light page dark.
*/
export function inkPalette(p) {
  return fx.normalizePalette({
    bg: p.ink,
    surface: color.mix(p.ink, p.bg, 0.1),
    ink: p.bg,
    muted: color.mix(p.ink, p.bg, 0.45),
    accent: safe(p.accent, p.bg, 3),
    accentInk: p.accentInk,
  });
}

/**
  The palette for an effect inside an accent-filled control (button, tab, chip): kept close to the
  accent, with the light side checked against the label colour so the label always reads.
*/
export function accentPalette(p, { min = 4.5, lift = 0.1 } = {}) {
  const a = p.accent;
  const label = p.accentInk;
  const towards = color.isDark(label) ? lift : -lift * 0.6;
  const deep = color.adjust(a, { l: -towards * 0.5, c: 1.05 });
  const light = safe(color.adjust(a, { l: towards, c: 1.1 }), label, min);
  return fx.normalizePalette({
    bg: safe(a, label, min),
    surface: safe(deep, label, min),
    ink: label,
    muted: color.mix(a, label, 0.25),
    accent: light,
    accentInk: label,
  });
}

/** mount an effect with a fixed palette; resolves to the fx controller */
export function mount(el, id, { palette: pal, params, seed } = {}) {
  return fx.mount(el, id, { palette: pal || palette(el), params, seed });
}

/* ------------------------------------------------------------------ still */

// stills render one after another: at most one WebGL context is open for them on the whole page
let stillChain = Promise.resolve();
// the stills near the screen that have no picture yet. On a CPU renderer each takes about a second (a new
// context, its shader compiled, one frame), so a screenshot taken a fixed time after a scroll catches
// some blank: <html data-cx-baking="n"> says how many are still to come, and a screenshot script waits
// until it is gone (it is removed at 0)
const pendingStills = new Set();
const markPending = () => {
  const d = document.documentElement.dataset;
  if (pendingStills.size) d.cxBaking = String(pendingStills.size); else delete d.cxBaking;
};
const nextFrame = () => new Promise(r => requestAnimationFrame(() => r()));
const STILL_CSS = {
  position: 'absolute', inset: '0', width: '100%', height: '100%', display: 'block', zIndex: '-1',
  pointerEvents: 'none', borderRadius: 'inherit', objectFit: 'cover',
};

/* the next frame the runtime draws into this context, copied into a plain 2D canvas placed first in
   host (null if no frame comes within a second and a half, e.g. the tab was hidden) */
function grab(ctrl, gl, cv, host) {
  return new Promise(resolve => {
    let done = false, timer = 0;
    let nudge = 0;
    const finish = shot => {
      if (done) return;
      done = true;
      clearTimeout(timer);
      clearTimeout(nudge);
      delete gl.drawArrays;
      resolve(shot);
    };
    const own = gl.drawArrays;
    gl.drawArrays = function (...a) {
      own.apply(this, a);
      // read back in the same task as the draw, before the browser presents and clears the buffer.
      // The copy is a plain CPU canvas (willReadFrequently): it owns its pixels at once and holds no GPU
      // memory
      const c = document.createElement('canvas');
      c.width = cv.width;
      c.height = cv.height;
      c.className = 'cx-still';
      c.setAttribute('aria-hidden', 'true');
      Object.assign(c.style, STILL_CSS, { imageRendering: cv.style.imageRendering || 'auto' });
      host.insertBefore(c, host.firstChild);
      const g = c.getContext('2d', { willReadFrequently: true });
      g.drawImage(cv, 0, 0);
      finish(c);
    };
    timer = setTimeout(() => finish(null), 1500);
    ctrl.resume();
    // an effect that holds itself still (a photograph with no drift) draws nothing on resume: set({})
    // asks it for one frame (every effect's controller redraws on set)
    nudge = setTimeout(() => { if (!done) { try { ctrl.set?.({}); } catch (_) { /* no frame: finish(null) */ } } }, 250);
  });
}

/**
  still(el, id, opts): an effect that does not move (speed and drift 0), drawn once and kept as a
  picture. When el first comes into view the effect is mounted paused, one frame is copied into a plain
  2D canvas where the effect canvas was (with any layer the effect adds, such as a grain), and the
  effect and its WebGL context are removed. When el changes size by more than a few percent the picture
  is drawn again (until then it is cropped to fit, never stretched). Without WebGL the effect's own CSS
  fallback stays; an effect drawn on a 2D canvas is simply kept paused. opts: palette, params, seed,
  fade (a short fade-in of the first picture). Returns { el, ready, info, pause(), resume(), destroy() };
  ready resolves once the first picture is in place.
*/
export function still(el, id, { palette: pal, params, seed, fade = true } = {}) {
  // fade: false where the effect hides something of its own that comes back when it is removed (the
  // photograph under duotone-grade), so the picture takes its place at once
  let destroyed = false, pic = null, extras = [], kept = null, size = null, visible = false, queued = false, timer = 0, tries = 0;
  let ready;
  const readyP = new Promise(r => { ready = r; });
  const stale = () => {
    if (!size) return true;
    const w = el.clientWidth, h = el.clientHeight;
    return Math.abs(w - size[0]) > Math.max(2, size[0] * 0.04) || Math.abs(h - size[1]) > Math.max(2, size[1] * 0.04);
  };
  const token = {};
  const pend = () => {
    if (!destroyed && visible && !document.hidden && !pic && !kept && tries <= 3 && el.clientWidth && el.clientHeight) pendingStills.add(token);
    else pendingStills.delete(token);
    markPending();
  };
  const want = () => {
    pend();
    if (destroyed || queued || kept || !visible || document.hidden || !stale() || tries > 3) return;
    queued = true;
    stillChain = stillChain.then(render, render).then(() => { queued = false; want(); });
  };
  const keep = ctrl => { kept = ctrl; ready(); pend(); };

  async function render() {
    if (destroyed || !visible || document.hidden) return;
    const w = el.clientWidth, h = el.clientHeight;
    if (!w || !h) return;
    const before = new Set(el.children);
    let ctrl;
    try { ctrl = await fx.mount(el, id, { palette: pal || palette(el), params, seed }); }
    catch (err) { console.warn('still:', err); tries = 9; return; }
    ctrl.pause();
    // the runtime makes its canvas and draws one frame as soon as el is in view
    let cv = null, seenAt = 0;
    for (const t0 = performance.now(); ;) {
      if (destroyed) { ctrl.destroy(); return; }
      if (ctrl.info?.fallback) return keep(ctrl);             // the CSS fallback: no context to free
      const c = [...el.querySelectorAll(':scope > canvas')].find(n => !before.has(n));
      if (c) {
        if (!cv) { cv = c; seenAt = performance.now(); }
        if (cv.style.opacity === '1' || performance.now() - seenAt > 600) break;
      }
      if (performance.now() - t0 > 5000) {                     // never drawn (scrolled away): try again later
        ctrl.destroy();
        if (visible) tries++;
        return;
      }
      await nextFrame();
    }
    // not a context of its own: cv is the canvas fx.mount made above, so this returns the context fx.js already counts in
    // window.__tpGl (its liveGL set: enforceBudget before the mount, released by ctrl.destroy() below); one still at a time
    const gl = cv.getContext('webgl2') || cv.getContext('webgl');
    if (!gl) return keep(ctrl);                               // drawn on a 2D canvas: paused, it costs nothing
    const shot = await grab(ctrl, gl, cv, el);
    if (destroyed) { shot?.remove(); ctrl.destroy(); return; }
    // no frame came (hidden tab, scrolled away, a renderer that never calls drawArrays): on screen the
    // paused effect stays as it is; off screen it goes and the picture is tried again later
    if (!shot) { if (visible && !document.hidden) return keep(ctrl); ctrl.destroy(); return; }
    const added = [...el.children].filter(n => !before.has(n) && n !== cv && n !== shot);
    const copies = added.map(n => { const k = n.cloneNode(true); k.setAttribute('data-cx-still', ''); return k; });
    ctrl.destroy();
    const old = [pic, ...extras];
    shot.after(...copies);
    old.forEach(n => n?.remove());
    if (fade && !pic && !reduced()) shot.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 450, easing: 'ease-out' });
    pic = shot;
    extras = copies;
    size = [w, h];
    ready();
  }

  // the same margin fx.js makes its contexts at, so the picture is ready as el comes into view
  const io = new IntersectionObserver(e => { visible = e[e.length - 1].isIntersecting; want(); }, { rootMargin: '12% 0px' });
  io.observe(el);
  const ro = new ResizeObserver(() => { clearTimeout(timer); timer = setTimeout(want, size ? 250 : 0); });
  ro.observe(el);
  document.addEventListener('visibilitychange', want);
  return {
    el,
    still: true,
    ready: readyP,
    pause() {},
    resume() {},
    get info() { return kept ? kept.info : { still: true, webgl: 0, running: false, size: pic ? [pic.width, pic.height] : null }; },
    destroy() {
      destroyed = true;
      pend();
      io.disconnect();
      ro.disconnect();
      clearTimeout(timer);
      document.removeEventListener('visibilitychange', want);
      kept?.destroy();
      kept = null;
      [pic, ...extras].forEach(n => n?.remove());
      pic = null;
      extras = [];
    },
  };
}

/* ------------------------------------------------------------------ fill */

/**
  fill(el, id, opts): the glyphs of el show the effect. Mark the parts with data-fill (text, an
  icon drawn in currentColor, a .cx-glyph mask icon) or data-fill="box" (the element's whole box,
  its border-radius kept); with no mark, all of el's text is filled. opts.still: the effect does not
  move, so it is drawn once and kept as a picture (see still()).

  How: one effect canvas sits in an overlay placed NEXT TO el (its next sibling, positioned over
  el's box), never inside it, so el's own text and HTML stay clean: a <ul> holds only <li>, a <dl>
  only its groups, and an <h1> reads once. The overlay holds a copy of el's content that paints the
  filled parts white and the rest black (or the reverse) and blends with the canvas; the overlay
  blends with the page (screen on a dark ground, multiply on a light one), so outside the glyphs the
  page shows unchanged. The copy of a heading or paragraph is a <div> with the same classes and
  computed type, so the page keeps one h1. The overlay is aria-hidden, inert and data-nosnippet.
  Before the script runs, and in forced colours, the text keeps its own colour. el needs a parent
  element and no border (its padding is fine).
*/
const TYPE_PROPS = ['font-family', 'font-size', 'font-weight', 'font-style', 'font-stretch', 'line-height', 'letter-spacing',
  'word-spacing', 'text-align', 'text-transform', 'text-indent', 'font-feature-settings', 'font-variation-settings',
  'font-variant-numeric', 'font-kerning', 'text-wrap-mode', 'text-wrap-style', 'white-space-collapse', 'padding'];
function knockOf(el) {
  let copy;
  if (/^(H[1-6]|P)$/.test(el.tagName)) {
    copy = document.createElement('div');
    for (const a of el.attributes) if (a.name !== 'id') copy.setAttribute(a.name, a.value);
    copy.append(...[...el.childNodes].map(n => n.cloneNode(true)));
    const cs = getComputedStyle(el);
    for (const p of TYPE_PROPS) copy.style.setProperty(p, cs.getPropertyValue(p));
  } else {
    copy = el.cloneNode(true);
    copy.removeAttribute('id');
  }
  copy.querySelectorAll('[id]').forEach(n => n.removeAttribute('id'));
  copy.querySelectorAll('.cx-fill').forEach(n => n.remove());
  return copy;
}

export async function fill(el, id, { seed, params, palette: pal, page, keep = false, still: isStill = false } = {}) {
  page = page || palette(el);
  const parent = el.parentElement;
  if (!parent) return { el: null, ctrl: null, destroy() {} };
  const dark = isDark(page);
  const whole = !el.querySelector('[data-fill]');
  // keep: the glyphs keep their own colour and the effect is laid over them (a passing light)
  const filled = keep ? ['cx-overlaid'] : whole ? ['cx-filled', 'cx-filled--all'] : ['cx-filled'];
  const over = document.createElement('div');
  over.className = `cx-fill ${dark ? 'cx-fill--screen' : 'cx-fill--multiply'}`;
  over.setAttribute('aria-hidden', 'true');
  over.setAttribute('data-nosnippet', '');
  over.inert = true;
  const knock = knockOf(el);
  knock.classList.add('cx-knock');
  if (whole) knock.classList.add('cx-knock--all');
  over.append(knock);
  const movedParent = getComputedStyle(parent).position === 'static';
  if (movedParent) parent.style.position = 'relative';
  // the overlay covers el's border box, measured from the parent's padding box
  const place = () => {
    const pr = parent.getBoundingClientRect(), r = el.getBoundingClientRect(), s = over.style;
    s.left = `${(r.left - pr.left - parent.clientLeft + parent.scrollLeft).toFixed(2)}px`;
    s.top = `${(r.top - pr.top - parent.clientTop + parent.scrollTop).toFixed(2)}px`;
    s.width = `${r.width.toFixed(2)}px`;
    s.height = `${r.height.toFixed(2)}px`;
    s.borderRadius = getComputedStyle(el).borderRadius;
  };
  el.classList.add(...filled);
  el.after(over);
  place();
  const ro = new ResizeObserver(place);
  ro.observe(el);
  ro.observe(parent);
  addEventListener('resize', place);
  document.fonts?.ready.then(place);
  const undo = () => {
    ro.disconnect();
    removeEventListener('resize', place);
    over.remove();
    el.classList.remove(...filled);
    if (movedParent) parent.style.position = '';
  };
  let ctrl = null;
  try {
    // a fill that does not move is drawn once and kept as a picture (no context, no frames at rest)
    ctrl = isStill
      ? still(over, id, { palette: pal || inkPalette(page), params, seed })
      : await fx.mount(over, id, { palette: pal || inkPalette(page), params, seed });
  } catch (err) {
    console.warn('fill:', err);
    undo();
    return { el: over, ctrl: null, destroy() {} };
  }
  return {
    el: over,
    ctrl,
    ready: ctrl?.ready || Promise.resolve(),
    pause: () => ctrl?.pause(),
    resume: () => ctrl?.resume(),
    destroy() {
      ctrl?.destroy();
      undo();
    },
  };
}

/* ------------------------------------------------------------------ windows */

const svgURL = svg => `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
/** a rounded rectangle as a mask image, w x h CSS px */
export function roundRect(w, h, r) {
  r = Math.max(0, Math.min(r, w / 2, h / 2));
  return svgURL(`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><rect width="${w}" height="${h}" rx="${r}" ry="${r}"/></svg>`);
}

/**
  a rounded rectangle that fades out from one corner: opaque at (cx, cy) (0..1 of the box), clear at
  `reach` of the box diagonal. Used to keep an effect to the empty corner of a card, away from its text.
*/
export function roundRectFade(w, h, r, { cx = 1, cy = 0, reach = 0.7, peak = 1 } = {}) {
  r = Math.max(0, Math.min(r, w / 2, h / 2));
  const d = Math.hypot(w, h) * reach;
  return svgURL(`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><defs><radialGradient id="f" gradientUnits="userSpaceOnUse" cx="${(cx * w).toFixed(1)}" cy="${(cy * h).toFixed(1)}" r="${d.toFixed(1)}"><stop offset="0" stop-color="#fff" stop-opacity="${peak}"/><stop offset=".55" stop-color="#fff" stop-opacity="${(peak * 0.45).toFixed(3)}"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient></defs><rect width="${w}" height="${h}" rx="${r}" ry="${r}" fill="url(#f)"/></svg>`);
}

/**
  windows(host, targets, opts): host (an effect element over the group) is masked to the boxes of
  targets, each with its own border-radius, so one canvas shows through many shapes. `extra` adds
  mask layers on top (CSS images) that intersect the union, e.g. a moving band or a spotlight.
  `shape(w, h, r)` replaces the plain rounded box (e.g. roundRectFade). Rebuilt when anything
  resizes; returns { update, destroy }.
*/
export function windows(host, targets, { extra = () => [], radius, shape = roundRect } = {}) {
  let raf = 0;
  const update = () => {
    raf = 0;
    const hr = host.getBoundingClientRect();
    const layers = [], sizes = [], pos = [], comp = [];
    for (const extraLayer of extra()) {
      layers.push(extraLayer.image);
      sizes.push(extraLayer.size || '100% 100%');
      pos.push(extraLayer.position || '0 0');
      comp.push('intersect');
    }
    const list = typeof targets === 'function' ? targets() : targets;
    list.forEach(t => {
      const r = t.getBoundingClientRect();
      if (!r.width || !r.height) return;
      const w = Math.round(r.width * 100) / 100, h = Math.round(r.height * 100) / 100;
      const rad = radius != null ? radius : parseFloat(getComputedStyle(t).borderTopLeftRadius) || 0;
      layers.push(shape(w, h, rad));
      sizes.push(`${w}px ${h}px`);
      pos.push(`${(r.left - hr.left).toFixed(2)}px ${(r.top - hr.top).toFixed(2)}px`);
      comp.push('add');
    });
    const s = host.style;
    s.maskImage = s.webkitMaskImage = layers.join(', ') || 'none';
    s.maskSize = s.webkitMaskSize = sizes.join(', ');
    s.maskPosition = s.webkitMaskPosition = pos.join(', ');
    s.maskRepeat = s.webkitMaskRepeat = 'no-repeat';
    s.maskComposite = comp.join(', ');
  };
  const queue = () => { if (!raf) raf = requestAnimationFrame(update); };
  const ro = new ResizeObserver(queue);
  ro.observe(host);
  (typeof targets === 'function' ? targets() : targets).forEach(t => ro.observe(t));
  update();
  return { update: queue, now: update, destroy() { ro.disconnect(); cancelAnimationFrame(raf); } };
}

/* ------------------------------------------------------------------ small things */

/** run fn on the next frames while the condition holds (pointer smoothing and the like) */
export function smoother(step) {
  let raf = 0, last = 0;
  const tick = ts => {
    const dt = last ? Math.min(0.05, (ts - last) / 1000) : 0.016;
    last = ts;
    raf = step(dt) ? requestAnimationFrame(tick) : 0;
    if (!raf) last = 0;
  };
  return {
    kick() { if (!raf) raf = requestAnimationFrame(tick); },
    stop() { cancelAnimationFrame(raf); raf = 0; last = 0; },
  };
}

/** true while el sits inside a part whose pause button is pressed */
export const held = el => !!el.closest('.cx-paused');

/** a timer that only runs while el is on screen, the tab is visible, motion is allowed and no pause button holds it */
export function whileVisible(el, { every, run, still }) {
  let timer = 0, onScreen = false;
  const go = () => {
    clearInterval(timer);
    timer = 0;
    if (onScreen && !document.hidden && !reduced() && !held(el)) timer = setInterval(run, every);
    else if (reduced() && still) still();
  };
  const io = new IntersectionObserver(e => { onScreen = e[e.length - 1].isIntersecting; go(); });
  io.observe(el);
  document.addEventListener('visibilitychange', go);
  document.addEventListener('cx-pause', go);
  mqReduce.addEventListener?.('change', go);
  return {
    destroy() {
      clearInterval(timer);
      io.disconnect();
      document.removeEventListener('visibilitychange', go);
      document.removeEventListener('cx-pause', go);
      mqReduce.removeEventListener?.('change', go);
    },
  };
}

/* ------------------------------------------------------------------ pause */

const PAUSE_ICON = '<svg class="cx-pause__off" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><rect x="4" y="3" width="2.6" height="10" rx="1"/><rect x="9.4" y="3" width="2.6" height="10" rx="1"/></svg>';
const PLAY_ICON = '<svg class="cx-pause__on" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M5 3.2v9.6a.8.8 0 0 0 1.2.7l7.6-4.8a.8.8 0 0 0 0-1.4L6.2 2.5A.8.8 0 0 0 5 3.2Z"/></svg>';

/**
  pauser(host, opts): a round pause button for a looping visual, as every loop that runs on its own
  for more than about 5 s needs one (WCAG 2.2.2). It sits in a corner (`corner`: br, bl, tr, tl) of
  `at` (host by default, e.g. the panel that loops inside a card) or, with `into`, at the end of a row
  of the part's own UI. Pressing it adds .cx-paused to host (CSS animations inside stop), pauses
  every effect controller given to add(), and holds every whileVisible() timer inside host;
  components with their own frame loop check held(el). Under reduced motion the loops already hold
  one state, so the button is not shown. Returns { el, add(ctrl | promise), paused(), destroy() }.
*/
export function pauser(host, { label = 'animation', corner = 'br', at = host, into = null } = {}) {
  const btn = document.createElement('button');
  btn.type = 'button';
  btn.className = into ? 'cx-pause cx-pause--inline' : `cx-pause cx-pause--${corner}`;
  btn.innerHTML = PAUSE_ICON + PLAY_ICON;
  const ctrls = new Set();
  let paused = false;
  const set = v => {
    paused = v;
    host.classList.toggle('cx-paused', v);
    btn.classList.toggle('is-paused', v);
    btn.setAttribute('aria-label', `${v ? 'Play' : 'Pause'} ${label}`);
    btn.title = `${v ? 'Play' : 'Pause'} ${label}`;
    ctrls.forEach(c => { try { v ? c.pause?.() : c.resume?.(); } catch (_) {} });
    // a CSS transition in flight (a pointer gliding) stops where it is, then carries on
    if (typeof CSSTransition === 'function') {
      for (const a of host.getAnimations?.({ subtree: true }) || []) if (a instanceof CSSTransition) v ? a.pause() : a.play();
    }
    host.dispatchEvent(new CustomEvent('cx-pause', { bubbles: true, detail: { paused: v } }));
  };
  set(false);
  const click = () => set(!paused);
  btn.addEventListener('click', click);
  const movedAt = !into && getComputedStyle(at).position === 'static';
  if (movedAt) at.style.position = 'relative';
  (into || at).append(btn);
  const api = {
    el: btn,
    add(c) {
      if (!c) return c;
      if (typeof c.then === 'function') { c.then(v => api.add(v), () => {}); return c; }
      ctrls.add(c);
      if (paused) c.pause?.();
      return c;
    },
    paused: () => paused,
    destroy() {
      btn.removeEventListener('click', click);
      btn.remove();
      host.classList.remove('cx-paused');
      if (movedAt) at.style.position = '';
      ctrls.clear();
    },
  };
  return api;
}

/** collect destroy functions */
export function bag() {
  const fns = [];
  let done = false;
  const kill = x => (typeof x === 'function' ? x() : x?.destroy?.());
  const api = {
    /** a destroy function, an object with destroy(), or a promise of either */
    add(x) {
      if (!x) return x;
      if (typeof x.then === 'function') {
        x.then(v => (done ? kill(v) : api.add(v)), () => {});
        return x;
      }
      if (done) kill(x); else fns.push(() => kill(x));
      return x;
    },
    destroy() {
      done = true;
      while (fns.length) { try { fns.pop()(); } catch (e) { console.warn(e); } }
    },
  };
  return api;
}

/**
  tuned(table, id): the params a part has tuned for effect id, a copy. Every part that takes several
  effects keeps one entry per effect and passes only that one: one effect's numbers mean something else
  to another (contour-lines' opacity and calm left dot-terrain almost blank on the map). An effect with
  no entry gets `base` only, so its own defaults hold.
*/
export function tuned(table, id, base = { calm: 0 }) { return { ...(table[id] || base) }; }

/** data-cx-params='{"speed":0.2}' on an element, parsed */
export function paramsOf(el) {
  try { return el.dataset.cxParams ? JSON.parse(el.dataset.cxParams) : undefined; } catch (_) { return undefined; }
}

export default { fx, color, reduced, hoverable, palette, isDark, tone, safe, inkPalette, accentPalette, mount, still, fill, windows, tuned, roundRect, roundRectFade, smoother, whileVisible, held, pauser, bag, paramsOf };
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall