API docs
Search docs
Guides, operations and types

Render paints

A paint colors a chat name: gradients, patterns, glow, outline and animation. You get it as a JSON document and as a pre-rendered animated WebP, so it renders on any website or app. No key needed.

How paints work

A paint is a stack of layers clipped to the letters of a name. Under all layers lies the user's own Twitch name color, so transparent parts of a paint show that color, just like in Twitch chat. Some paints put a contrast color picked from the name color there instead, and some have their own look for each time of day. Shadows and the outline sit around the letters. Every paint loops seamlessly, and every name wearing it moves in step.

There are three ways to show one, from simplest to fullest:

WayLooksUse it for
Baked textureThe whole paint, animatedAny website or app. Start here.
CSS compilerPixel-exact, sharp at any sizeWebsites, through the Cosmetics SDK
Fallback colorOne plain colorClients without images in names

1. Get the paint

Chat clients load the catalog once: every published paint with its document and baked texture. Users only reference paints by ID (see Show what chatters wear). Cache entries by id and v; the version goes up with every design change.

HTTP
GET https://api.jiltv.app/v1/cosmetics/catalog

{
  "paints": [{
    "id": "01JA…", "name": "Sunset", "v": 3,
    "data": { "v": 1, "duration": 4, "mapping": { "mode": "stretch" },
              "layers": […], "shadows": […], "stroke": null,
              "fallback": "#ff8a3dff", "texture": "9f2c…", … },
    "texture": {
      "url":   "https://cdn.jiltv.app/paints/9f2c….webp",
      "still": "https://cdn.jiltv.app/paints/9f2c…-0.webp",
      "w": 360, "h": 54, "tile": false
    }
  }, {
    "id": "01JB…", "name": "Daylight", "v": 2,
    "data": { …,
              "base": { "mode": "contrast", "onLight": "#000000ff", "onDark": "#ffffffff", "threshold": 60 },
              "phases": { "starts": [360, 660, 1020, 1260],
                          "night": { "v": 1, "layers": […], "texture": "4be1…", … } } },
    "texture": { … },
    "phaseTextures": {
      "night": { "url": "https://cdn.jiltv.app/paints/4be1….webp", "still": "…", "w": 360, "h": 54 }
    }
  }],
  "badges": […], "decorations": […],
  "cdn": "https://cdn.jiltv.app"
}

For a single user, GraphQL gives you the paint and the name color in one request:

GraphQL
query NamePaint($twitchId: String!) {
  userByPlatform(platform: TWITCH, platformId: $twitchId) {
    displayName
    twitchColor
    paint { id version data assetBase }
  }
}

Supporters can wear a different paint per channel. In chat, always resolve the paint for the channel you show, as the chat guide describes.

2. The Twitch name color

Set the user's Twitch name color as the element's color. Paints with transparent parts let it shine through, so the same paint looks slightly different on a red name than on a green one. That is intended.

  • In chat, take it from the color tag of the IRC message. On a website, use twitchColor (GraphQL, #rrggbb).
  • null means the user never picked one. Use your client's default name color, or leave color unset so the surrounding text color shows.
  • Put the paint on the element holding only the name, not on the line with badges, the colon or the message.

Contrast base

Some paints show a contrast color instead of the name color: data.base is then { "mode": "contrast", "onLight": "#000000ff", "onDark": "#ffffffff", "threshold": 60 }. When the name color's OKLCH lightness (0 to 100) is at least threshold, use onLight, otherwise onDark, everywhere you would use the name color. Without base, use the name color as it is. The texture example below shows the calculation.

Looks by time of day

data.phases gives a paint its own look for the morning, midday, evening and night of the viewer's local time. starts are the minutes after midnight where each phase begins; night runs past midnight up to morning. Each of morning, midday, evening and night is a whole paint document of its own, or missing: then that phase shows the main document. The catalog has the baked texture of each own look in phaseTextures. Pick the look when you draw a name and again when the next phase starts.

3. Render the baked texture

texture is the whole paint rendered over one loop: every layer, filter, rotation and animation, as an animated WebP with alpha at up to 3 times the pixel density. still is its first frame. There is no GIF; GIFs have no smooth alpha and would leave jagged edges around letters. Every browser and most image libraries play animated WebP.

Draw it in three steps, the same way jiltv.app does:

  1. The name in its Twitch color, or the contrast color picked from it.
  2. The texture on top, clipped to the letters. Transparent parts show the name color.
  3. The outline (data.stroke) and shadows (data.shadows) around the letters, in CSS pixels. They follow the letters, so they are not part of the texture.

tile: false means the texture stretches over the whole name. tile: true means it is scaled to the name's height and repeats horizontally, so short and long names look like the same material.

CSS
/* What the paint function below produces for one name */
.name {
  color: #ff4500;                                   /* Twitch name color */
  background-image: url(".../9f2c….webp"),          /* the baked paint */
                    linear-gradient(currentColor, currentColor); /* name color underneath */
  background-size: 100% 100%, 100% 100%;            /* tile: auto 100%, 100% 100% */
  background-repeat: no-repeat, no-repeat;          /* tile: repeat-x, no-repeat */
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px #000000ff;               /* data.stroke, if set */
  paint-order: stroke fill;
  filter: drop-shadow(0px 1px 2px #00000080);       /* one per data.shadows entry */
  white-space: nowrap;
}
JavaScript
const HEX = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;

const PHASES = ['morning', 'midday', 'evening', 'night'];

/** The look shown now: a day phase's own look and texture, or the main ones. */
function lookNow(paint, now = new Date()) {
  const p = paint.data.phases;
  if (!p) return { d: paint.data, tex: paint.texture };
  const minutes = now.getHours() * 60 + now.getMinutes();
  let phase = 'night'; // night runs past midnight up to morning
  p.starts.forEach((start, i) => { if (minutes >= start) phase = PHASES[i]; });
  if (!p[phase]) return { d: paint.data, tex: paint.texture };
  return { d: p[phase], tex: paint.phaseTextures?.[phase] };
}

/** OKLCH lightness (0-1) of a #rrggbb color. */
function lightness(hex) {
  const [r, g, b] = [1, 3, 5].map((i) => {
    const c = parseInt(hex.slice(i, i + 2), 16) / 255;
    return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
  });
  const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
  const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
  const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
  return 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
}

/** The color under the paint: the name color, or the contrast color picked from it. */
function baseColor(d, name) {
  if (!d.base || !name) return name;
  return lightness(name) * 100 >= d.base.threshold ? d.base.onLight : d.base.onDark;
}

/**
 * CSS for a painted name. `paint` is a catalog entry, `color` the Twitch
 * name color (or null). Works in any browser, no JilTV code needed.
 * Paints with day phases change look: build it again at the next phase.
 */
function paintCss(paint, color) {
  const { d, tex } = lookNow(paint);
  const name = color && HEX.test(color) ? color : null; // never put unchecked text into CSS
  if (!tex) return `color: ${d.fallback}`;          // not baked yet: plain color

  const still = d.still != null || matchMedia('(prefers-reduced-motion: reduce)').matches;
  const under = baseColor(d, name);
  const css = [
    under && `color: ${under}`,
    `background-image: url("${still ? tex.still : tex.url}"), linear-gradient(currentColor, currentColor)`,
    `background-size: ${tex.tile ? 'auto 100%' : '100% 100%'}, 100% 100%`,
    `background-repeat: ${tex.tile ? 'repeat-x' : 'no-repeat'}, no-repeat`,
    '-webkit-background-clip: text', 'background-clip: text',
    '-webkit-text-fill-color: transparent',
    'white-space: nowrap',
  ];
  if (d.stroke) css.push(`-webkit-text-stroke: ${d.stroke.width}px ${d.stroke.color}`, 'paint-order: stroke fill');
  if (d.shadows.length) {
    css.push('filter: ' + d.shadows.map((s) => `drop-shadow(${s.x}px ${s.y}px ${s.blur}px ${s.color})`).join(' '));
  }
  return css.filter(Boolean).join('; ');
}

// <span style="${paintCss(paint, '#ff4500')}">Jilence</span>

Native apps do the same: draw the name in its color, draw the current frame over it with "source atop" compositing (only where the letters are), then the stroke and shadows. w and h are the pixels of one frame; scale it to your name's height.

4. Compile to CSS

jiltv.app, the browser extension and the Cosmetics SDK turn the document into CSS instead: gradients and patterns are drawn by the browser, so names stay sharp at any size and the animation runs without any script. With the SDK it is one call, jiltv.paint(el, paint, { color }), or jiltv.paintCss(paint, selector) on servers. Underneath it does this:

JavaScript
// Inside the SDK (the engine is bundled into it, not a package of its own)
import { normalize, compilePaint, syncDelay } from '@jiltv/paint';

const sheets = new Map(); // key -> { animated, durationMs }

/** One <style> per paint version, shared by every name that wears it. */
function usePaint(paint, cdn) {
  const key = `p${paint.id.toLowerCase()}v${paint.v}`; // [a-z0-9] only
  if (!sheets.has(key)) {
    const out = compilePaint(normalize(paint.data), {
      key,
      selector: `[data-paint="${key}"]`,
      assetBase: cdn, // shader layers play their baked loops from the CDN
    });
    const style = document.createElement('style');
    style.textContent = out.css;
    document.head.append(style);
    sheets.set(key, out);
  }
  return { key, ...sheets.get(key) };
}

function paintName(el, paint, cdn, color) {
  const { key, animated, durationMs } = usePaint(paint, cdn);
  el.dataset.paint = key;
  if (color) el.style.color = color;           // shows through transparent parts
  if (animated) el.style.setProperty('--jiltv-sync', syncDelay(durationMs)); // in step with the others
}
  • Always normalize() first. It turns any input into a valid document, so old or broken data degrades instead of breaking your page.
  • Pass assetBase (the catalog's cdn, or assetBase in GraphQL). Shader layers (liquid, lava, aurora and others) play their baked loops from {cdn}/paints/{hash}.webp; without it they only show their palette.
  • Server-side rendering: put the <style> into the <head> on the server, so names never flash unpainted.
  • Keep names in step: set --jiltv-sync to syncDelay(durationMs) when a name is added. --jiltv-play: paused on any ancestor freezes all paints inside it. Reduced motion is handled by the CSS itself.
  • Compile again at changesAt. Paints with day phases compile to the look for now and return when the next phase starts (epoch ms, null for paints with one look). Contrast bases are part of the CSS, nothing to do for them.

5. Fallback color

data.fallback (of the look shown now) is one #rrggbbaa color, the average of the paint. Use it as the name color when you can't show images in names, or while a paint has no texture. It replaces the Twitch color, like the paint would.

Common mistakes

  • Padding on the painted element. Stretch textures cover the element's box, so padding squeezes the paint off the letters. Pad a wrapper instead.
  • Names that wrap. Keep white-space: nowrap, so the paint covers the name as one piece.
  • Stale paints. Key everything by id and v. When a user.cosmetics event or the catalog brings a new version, replace it.
  • Ignoring reduced motion. Show still instead of url when the user asks for less motion, and when data.still is set (static paints).
  • Unchecked colors. Validate the Twitch color as hex before writing it into CSS.
Search
Find emotes or users, or jump to a page