{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "text-mask",
  "type": "block",
  "title": "Liquid metal word",
  "summary": "The name in rounded, sharp-edged liquid metal; the camera travels along the letters close, then pulls back to the whole word.",
  "tags": [
    "block",
    "brand",
    "wordmark",
    "liquid-metal",
    "3d",
    "title"
  ],
  "params": [
    {
      "name": "word",
      "type": "string",
      "default": "",
      "description": "empty takes the brand's name",
      "group": "main",
      "control": "text"
    },
    {
      "name": "line",
      "type": "string",
      "default": "Brand videos, made by your coding agent.",
      "description": "line",
      "group": "main",
      "control": "text"
    },
    {
      "name": "weight",
      "type": "number",
      "default": 3,
      "description": "extra stroke on the letters, in px at 400px type: 0 keeps the face's own weight",
      "group": "main"
    },
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "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/text-mask/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>text-mask</title>\n<!--\n  Text · liquid metal word (5.6 s). The word itself made of liquid metal: rounded, bevelled letters with the metal\n  flowing over them. The shot starts close on the first letter and travels along the word, left to right, then pulls\n  back until the whole word reads; a line lands under it.\n  Vertical/square: a word with a hyphen or space stacks on two lines (paper- / motion) and the travel runs diagonally\n  from the first letter to the last; the line under it grows and wraps.\n  Travel 0–2.8 s · Pull back 2.6–3.9 s · Line 4.0 s · Hold to 5.6 s.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #metal { position: absolute; left: 0; top: 0; transform-origin: 0 0; }\n  #line { position: absolute; left: 0; right: 0; 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=\"metal\"></div>\n  <div id=\"line\"></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease } from 'paper-motion';\nimport { blurIn } from 'paper-motion/moves';\nimport { loadBrand } from 'paper-motion/brand';\n\nconst CONFIG = {\n  word: '',                              // empty takes the brand's name\n  line: 'Brand videos, made by your coding agent.',\n  weight: 3,                             // extra stroke on the letters, in px at 400px type: 0 keeps the face's own weight\n  metal: { repetition: 4, softness: 0.02, shiftRed: 0.3, shiftBlue: 0.3, distortion: 0.12, contour: 0.8, angle: 70, speed: 1 },\n  background: null,                      // a calm shader-set id behind the metal, or null for the brand's first entry\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.6;\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.25;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 25%, rgba(0,0,0,0.75) 100%)';\nawait document.fonts.ready;\n\n// the word as a shape: drawn white on transparent in the brand's display face, cropped to the ink\nconst word = CONFIG.word || B.name, fam = B.font('display');\nconst probe = document.createElement('canvas').getContext('2d'); probe.font = `400 400px ${fam}`;\n// narrow frames stack the word on two lines when it has a break (a hyphen or a space)\nconst cut = W > H ? -1 : word.search(/[-\\s]/);\nconst parts = cut > 0 && cut < word.length - 1 ? [word.slice(0, cut + 1).trim(), word.slice(cut + 1).trim()] : [word];\nconst ms = parts.map((p) => probe.measureText(p)), padX = 60, padY = 80, GAP = 40;\nconst lw = ms.map((m) => m.actualBoundingBoxLeft + m.actualBoundingBoxRight), lh = ms.map((m) => m.actualBoundingBoxAscent + m.actualBoundingBoxDescent);\nconst iw = Math.ceil(Math.max(...lw)) + padX * 2, ih = Math.ceil(lh.reduce((a, b) => a + b, 0) + GAP * (parts.length - 1)) + padY * 2;\nconst cv = document.createElement('canvas'); cv.width = iw; cv.height = ih; const cx = cv.getContext('2d');\ncx.font = `400 400px ${fam}`; cx.fillStyle = cx.strokeStyle = '#fff'; cx.lineJoin = 'miter'; cx.miterLimit = 10;   // sharp corners cx.lineWidth = CONFIG.weight;\nlet ly = padY;\nconst rowsY = parts.map((p, i) => {\n  const m = ms[i], x = (iw - lw[i]) / 2 + m.actualBoundingBoxLeft, y = ly + m.actualBoundingBoxAscent;\n  cx.fillText(p, x, y);\n  cx.strokeText(p, x, y);   // fuller letters: rounder bevels\n  const mid = (ly + lh[i] * 0.52) / ih; ly += lh[i] + GAP; return mid;\n});\nconst shape = cv.toDataURL('image/png');\n// the metal word fills most of the frame width; its own box keeps the word's proportions\nconst mw = Math.min(W * 0.88, H * 0.6 * (iw / ih)), mh = mw * (ih / iw), ox = (W - mw) / 2, oy = (H - mh) / 2 - H * 0.03;\nObject.assign($('metal').style, { width: `${mw}px`, height: `${mh}px` });\ns.shader('#metal', 'LiquidMetal', { fit: 'contain', scale: 1, shape: 'none', colorBack: '#00000000', colorTint: '#ffffff', image: shape, ...CONFIG.metal });\nconst line = B.style($('line'), 'title', { short: SHORT, color: 'figure' }); line.textContent = CONFIG.line;\nObject.assign(line.style, { top: `${oy + mh + SHORT * 0.01}px`, fontSize: `${SHORT * (H > W ? 0.046 : W === H ? 0.042 : 0.035)}px`, opacity: 0.85, padding: `0 ${W * 0.05}px` });\n\nconst T = { travel: [0, 2.8], pull: [2.6, 3.9] };\ns.update((t) => {\n  // along the word, close, left to right; then back to the whole word\n  const a = progress(t, ...T.travel, ease.inOutSine), b = progress(t, ...T.pull, ease.inOutCubic);\n  const z = 2.6 * (1 - b) + 1 * b - 0.3 * a * (1 - b);\n  const rowY = rowsY.length > 1 ? rowsY[0] + (rowsY[1] - rowsY[0]) * a : 0.52;   // two lines: diagonally, first letter to last\n  const fx = (ox + mw * (0.1 + 0.8 * a)) * (1 - b) + (W / 2) * b, fy = (oy + mh * rowY) * (1 - b) + (H / 2) * b;\n  $('metal').style.transform = `translate(${W / 2 - (fx - ox) * z}px, ${H / 2 - (fy - oy) * z}px) scale(${z})`;\n  blurIn(line, t, { start: T.pull[1] + 0.1, duration: 0.8 });\n  $('bg').style.transform = `translateX(${-SHORT * 0.05 * a}px) scale(${1.1 - 0.05 * b})`;\n});\nB.cue(s, 'transition', T.pull[0]); B.cue(s, 'land', T.pull[1]); B.cue(s, 'text', T.pull[1] + 0.1);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/text-mask/brief.md",
      "content": "# Liquid metal word\n\nBlock: text-mask (5.6 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nThe name in rounded, sharp-edged liquid metal; the camera travels along the letters close, then pulls back to the whole word.\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 2.8 and 3.9 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add text-mask --name my-text-mask\n# edit CONFIG in pieces/my-text-mask/scene.html, then:\nnpx paper-motion render pieces/my-text-mask/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": [
    "logo-build",
    "liquid-metal"
  ],
  "preview": {
    "video": "previews/text-mask.webm",
    "poster": "previews/text-mask.jpg",
    "at": 5.2,
    "values": {}
  },
  "mood": [
    "bold",
    "luxury"
  ],
  "duration": 5.6,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Travel",
      "from": 0,
      "to": 2.8,
      "what": "travel"
    },
    {
      "name": "Pull back",
      "from": 2.6,
      "to": 3.9,
      "what": "pull back"
    },
    {
      "name": "Line",
      "from": 4,
      "to": 4.6,
      "what": "line"
    },
    {
      "name": "Hold",
      "from": 4.6,
      "to": 5.6,
      "what": "hold"
    }
  ],
  "when": [
    "a title card with weight",
    "the opening or close on the name"
  ],
  "needs": [
    {
      "kind": "name",
      "fill": {
        "line": "$brief.what"
      }
    }
  ]
}