{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "donut-fill",
  "type": "block",
  "title": "Donut fill",
  "summary": "A ring fills to its percentage as the number counts, rising from a tilted view to face-on, and a pulse rings out when it lands.",
  "tags": [
    "block",
    "data",
    "chart",
    "percentage",
    "ring"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "value",
      "type": "number",
      "default": 87,
      "description": "the percentage",
      "group": "main"
    },
    {
      "name": "label",
      "type": "string",
      "default": "of renders pass on the first try",
      "description": "label",
      "group": "main",
      "control": "text"
    },
    {
      "name": "format",
      "type": "enum",
      "default": "1920x1080",
      "options": [
        "1920x1080",
        "1080x1920",
        "1080x1080"
      ],
      "description": "output size; the layout recomposes for each",
      "group": "main",
      "control": "segmented"
    }
  ],
  "install": {
    "kind": "scene"
  },
  "files": [
    {
      "path": "pieces/donut-fill/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>donut-fill</title>\n<!--\n  Data · donut fill (5 s). A ring fills to its percentage with a rounded head that slows as it arrives, the number at\n  its centre counting up with it; when it lands, a pulse rings out and the line under the number fades in. The camera\n  starts low and tilted, looking across the ring like a dial on a table, and rises to face it as it fills.\n  Arrive 0–0.8 s · Fill 0.7–2.8 s · Land 2.8 s · Hold to 5 s.\n  Square: as 16:9 (the dial is sized from the short side). Vertical: the dial fills the width and the line moves under\n  the ring, set large across the frame; the camera lands on the ring and settles down to frame ring and line together.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #dial { position: absolute; }\n  #svg { position: absolute; left: 0; top: 0; overflow: visible; }\n  #mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"vig\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"dial\"><svg id=\"svg\"><g id=\"ticks\"></g><circle id=\"track\"/><circle id=\"fill\"/><circle id=\"pulse\"/></svg><div id=\"mid\"><div id=\"num\"></div><div id=\"lab\"></div></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { blurIn } from 'paper-motion/moves';\nimport { camera } from 'paper-motion/kit';\nimport { loadBrand } from 'paper-motion/brand';\n\nconst CONFIG = {\n  background: null,                      // a shader-set id, or null for the brand's first entry\n  value: 87,                             // the percentage\n  label: 'of renders pass on the first try',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5;\nconst s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });\nconst bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;\nif (bgId) B.shader(s, '#bg', bgId);\nconst $ = (id) => document.getElementById(id);\n$('bg').style.opacity = 0.4;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.65) 100%)';\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst accent = B.color('accent', '#E9E4D8'), muted = B.color('muted');\nconst size = SHORT * 0.72 * K, r = size * 0.42, sw = size * 0.075, c = size / 2;\nconst dial = $('dial'); Object.assign(dial.style, { width: `${size}px`, height: `${size}px` });\nconst svg = $('svg'); svg.setAttribute('width', size); svg.setAttribute('height', size);\nconst track = $('track'), fill = $('fill'), pulse = $('pulse');\nfor (const el of [track, fill, pulse]) { el.setAttribute('cx', c); el.setAttribute('cy', c); el.setAttribute('r', r); el.style.fill = 'none'; }\nObject.assign(track.style, { stroke: `${muted}33`, strokeWidth: sw });\nObject.assign(fill.style, { stroke: accent, strokeWidth: sw, strokeLinecap: 'round', transform: `rotate(-90deg)`, transformOrigin: `${c}px ${c}px`, filter: `drop-shadow(0 0 ${sw * 0.6}px ${accent}55)` });\nObject.assign(pulse.style, { stroke: accent, strokeWidth: sw * 0.25 });\nconst ticks = $('ticks');\nconst num = B.style($('num'), 'display', { short: SHORT * K, color: 'figure' }); num.style.fontSize = `${size * 0.22}px`; num.style.lineHeight = 1; num.style.fontVariantNumeric = 'tabular-nums';\nconst lab = B.style($('lab'), 'body', { short: SHORT * K, color: 'muted' }); lab.textContent = CONFIG.label; Object.assign(lab.style, { fontSize: `${size * 0.035}px`, maxWidth: `${size * 0.5}px`, marginTop: `${size * 0.02}px` });\nconst tall = H > W;\nif (tall) Object.assign(lab.style, { position: 'absolute', left: `${-size * 0.05}px`, right: `${-size * 0.05}px`, top: `${size * 1.02}px`, maxWidth: \"none\", marginTop: \"0\", fontSize: `${size * 0.1}px`, lineHeight: '1.25' });\ncam.place(dial, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\nconst L = 2 * Math.PI * r;\n\nconst T = { fill: [0.7, 2.8] };\ns.update((t) => {\n  const p = progress(t, ...T.fill, ease.inOutCubic) * CONFIG.value / 100;\n  fill.style.strokeDasharray = `${L * p} ${L}`;\n  fill.style.opacity = p > 0.003 ? '1' : '0';\n  num.innerHTML = `${Math.round(progress(Math.round(t * 30) / 30, ...T.fill, ease.inOutCubic) * CONFIG.value)}<span style=\"font-size:0.45em;opacity:0.7\">%</span>`;\n  num.style.opacity = String(progress(t, 0.5, 0.9));\n  // the landing: a pulse rings out from the ring, the line fades in\n  const pl = progress(t, T.fill[1], T.fill[1] + 0.9, ease.outCubic);\n  pulse.setAttribute('r', r + sw * 2.5 * pl); pulse.style.opacity = String(t >= T.fill[1] ? 0.8 * (1 - pl) : 0);\n  blurIn(lab, t, { start: T.fill[1] - 0.1, duration: 0.7 });\n  // the camera: low and tilted across the dial, rising to face it as it fills, then a little closer\n  const arrive = progress(t, 0, 0.8, ease.outCubic), rise = progress(t, 0.2, T.fill[1] + 0.3, ease.inOutCubic), push = progress(t, T.fill[1], D, ease.inOutSine);\n  const a = (52 * (1 - rise)) * Math.PI / 180, Rr = DIST + SHORT * 0.3 * (1 - arrive) - SHORT * 0.12 * rise - SHORT * 0.18 * push;\n  const settle = tall ? size * 0.2 * progress(t, T.fill[1] - 0.2, T.fill[1] + 1.0, ease.inOutCubic) : 0;   // vertical: down to take in the line\n  cam.at({ x: -size * 0.05 * (1 - rise), y: Rr * Math.sin(a) + settle, z: Rr * Math.cos(a), yaw: -10 * (1 - rise), pitch: -52 * (1 - rise), roll: 4 * (1 - rise) });\n  dial.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'transition', 0.2); B.cue(s, 'text', T.fill[0]); B.cue(s, 'land', T.fill[1]);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/donut-fill/brief.md",
      "content": "# Donut fill\n\nBlock: donut-fill (5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA ring fills to its percentage as the number counts, rising from a tilted view to face-on, and a pulse rings out when it lands.\n\nA block is one ready-made moment. Edit `CONFIG` (its words, numbers and format: 16:9, 9:16 or 1:1, the layout recomposes for each); check `npx paper-motion still` at 0.8 and 2.8 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add donut-fill --name my-donut-fill\n# edit CONFIG in pieces/my-donut-fill/scene.html, then:\nnpx paper-motion render pieces/my-donut-fill/scene.html --motion-blur 5",
  "notes": [
    "Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work) and, for the field, a shader-set entry.",
    "Recomposes for 16:9, 9:16 and 1:1: set `format` and the layout and camera follow."
  ],
  "related": [
    "stat-row",
    "stat-compare"
  ],
  "preview": {
    "video": "previews/donut-fill.webm",
    "poster": "previews/donut-fill.jpg",
    "at": 4.6,
    "values": {}
  },
  "mood": [
    "calm",
    "bold"
  ],
  "duration": 5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.8,
      "what": "arrive"
    },
    {
      "name": "Fill",
      "from": 0.7,
      "to": 2.8,
      "what": "fill"
    },
    {
      "name": "Land",
      "from": 2.8,
      "to": 3.4,
      "what": "land"
    },
    {
      "name": "Hold",
      "from": 3.4,
      "to": 5,
      "what": "hold"
    }
  ],
  "when": [
    "one percentage that matters",
    "a success rate"
  ],
  "needs": [
    {
      "kind": "share",
      "fill": {
        "value": "$value",
        "label": "$label"
      }
    }
  ]
}