{
  "$schema": "../../schema.json",
  "id": "roll",
  "type": "text",
  "title": "Roll",
  "summary": "The last word rolls like a slot machine through a list of words.",
  "tags": [
    "text",
    "kinetic",
    "headline"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "roll",
  "signature": "roll(el, list, t, { start, every, duration, curve, line })",
  "params": [
    {
      "name": "start",
      "type": "number",
      "default": 0,
      "description": "start time in seconds",
      "hidden": true
    },
    {
      "name": "every",
      "type": "number",
      "default": 0.9,
      "description": "seconds between words",
      "min": 0.2,
      "max": 3,
      "step": 0.05,
      "group": "main"
    },
    {
      "name": "duration",
      "type": "number",
      "default": 0.55,
      "description": "length of the transition in seconds; springs use it to keep their feel",
      "min": 0.2,
      "max": 3,
      "step": 0.05,
      "group": "main"
    },
    {
      "name": "curve",
      "type": "function",
      "default": "ease.inOutQuart",
      "description": "easing function (from `ease`)",
      "control": "ease",
      "group": "main"
    },
    {
      "name": "line",
      "type": "number",
      "default": 1.3,
      "description": "line height (em)",
      "min": 1,
      "max": 2,
      "step": 0.05,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/roll.js",
      "content": "import { ease, clamp, lerp } from 'paper-motion';\n\n/** The element rolls through `list` like a slot machine, one word every `every` seconds; its width follows. */\nexport function roll(el, list, t, { start = 0, every = 0.9, duration = 0.55, curve = ease.inOutQuart, line = 1.3 } = {}) {\n  if (!el._labRoll) {\n    el.textContent = '';\n    Object.assign(el.style, { display: 'inline-block', overflow: 'hidden', verticalAlign: 'bottom', height: `${line}em`, lineHeight: `${line}em` });\n    const strip = document.createElement('span');\n    strip.style.display = 'block';\n    const items = list.map((w) => { const s = document.createElement('span'); s.textContent = w; Object.assign(s.style, { display: 'block', whiteSpace: 'nowrap', width: 'max-content' }); strip.append(s); return s; });\n    el.append(strip);\n    el._labRoll = { strip, widths: items.map((s) => s.getBoundingClientRect().width) };\n  }\n  const { strip, widths } = el._labRoll;\n  const x = Math.max(0, t - start) / every;\n  let k = Math.floor(x), q = curve(clamp(((x - k) * every) / duration));\n  if (k >= list.length - 1) { k = list.length - 1; q = 0; }\n  strip.style.transform = `translateY(${-(k + q) * line}em)`;\n  el.style.width = `${lerp(widths[k], widths[k + 1] ?? widths[k], q)}px`;\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { roll } from './moves/roll.js';\n\ns.update((t) => roll(el, ['move.', 'faster.', 'yours.'], t, { start: 0.5 }));",
  "notes": [
    "The element rolls through `list` like a slot machine, one word every `every` seconds; its width follows."
  ],
  "preview": {
    "video": "previews/roll.webm",
    "poster": "previews/roll.jpg"
  },
  "mood": [
    "bold",
    "playful",
    "editorial"
  ],
  "energy": 3,
  "role": "text",
  "when": [
    "one headline with a changing last word",
    "listing what the product does"
  ]
}