{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "logo-build",
  "type": "block",
  "title": "Logo build",
  "summary": "The wordmark builds itself: each letter traces its outline, the fill rises from the baseline, and the domain lands under it.",
  "tags": [
    "block",
    "brand",
    "wordmark",
    "logo",
    "outline",
    "end-card"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "word",
      "type": "string",
      "default": "",
      "description": "empty takes the brand's wordmark",
      "group": "main",
      "control": "text"
    },
    {
      "name": "domain",
      "type": "string",
      "default": "paper-motion.app",
      "description": "domain",
      "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/logo-build/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>logo-build</title>\n<!--\n  Brand · logo build (5 s). The wordmark builds itself: each letter's outline traces on in turn, the fill rises inside\n  the outlines from the baseline, the strokes let go, and the domain lands under it. The camera starts close on the\n  first letters and travels back along the word as it builds.\n  Vertical/square: a wordmark with a hyphen or space stacks on two lines (paper- / motion), sized to the width; the\n  camera starts on the first letters of the top line.\n  Trace 0.2–1.7 s · Fill 1.3–2.5 s · Domain 2.7 s · Hold to 5 s.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #mark { position: absolute; }\n  #svg { position: absolute; left: 0; top: 0; overflow: visible; }\n  #meas { position: absolute; visibility: hidden; white-space: pre; }\n  #dom { position: absolute; left: 0; right: 0; text-align: center; white-space: nowrap; }\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=\"mark\"><svg id=\"svg\"><defs id=\"defs\"></defs><g id=\"fills\"></g><g id=\"strokes\"></g></svg><div id=\"dom\"></div></div></div>\n  <div id=\"meas\"></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\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  word: '',                              // empty takes the brand's wordmark\n  domain: 'paper-motion.app',\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.35;\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 figure = B.color('figure'), accent = B.color('accent', '#E9E4D8'), muted = B.color('muted');\nconst text = CONFIG.word || B.tokens?.wordmark?.text || B.name;\nconst family = B.font('display');\nawait document.fonts.ready;\n// measure each letter's place with the brand's display font\nconst meas = $('meas'); Object.assign(meas.style, { fontFamily: family, fontSize: '100px' });\n// narrow frames stack the wordmark on two lines when it has a break (a hyphen or a space)\nconst cut = W > H ? -1 : text.search(/[-\\s]/);\nconst rows = cut > 0 && cut < text.length - 1 ? [text.slice(0, cut + 1).trim(), text.slice(cut + 1).trim()] : [text];\nconst LH = 1.08;\nmeas.innerHTML = rows.map((r) => `<div>${[...r].map((c) => `<span>${c}</span>`).join('')}</div>`).join('');\nObject.assign(meas.style, { textAlign: 'center', lineHeight: LH });\nlet fs = 100 * (W * 0.8 * K) / meas.offsetWidth;\nif (rows.length > 1) fs = Math.min(fs, 100 * (H * 0.5 * K) / (100 * LH * rows.length));\nmeas.style.fontSize = `${fs}px`;\nconst spans = rows.flatMap((r, ri) => [...meas.children[ri].children].map((sp) => Object.assign(sp, { row: ri })));\nconst chars = rows.join('');\nconst mw = meas.offsetWidth, base = fs * 0.95, mh = fs * (rows.length > 1 ? LH * (rows.length - 1) + 1.2 : 1.2);\nconst mark = $('mark'); Object.assign(mark.style, { width: `${mw}px`, height: `${mh}px` });\nconst svg = $('svg'); svg.setAttribute('width', mw); svg.setAttribute('height', mh);\nconst NS = 'http://www.w3.org/2000/svg';\nconst letters = spans.map((sp, i) => {\n  const x = sp.offsetLeft, w = sp.offsetWidth, ch = chars[i], by = base + sp.row * fs * LH;\n  const mk = (cls) => { const t = document.createElementNS(NS, 'text'); t.textContent = ch; t.setAttribute('x', x); t.setAttribute('y', by); Object.assign(t.style, { fontFamily: family, fontSize: `${fs}px` }); return t; };\n  const clip = document.createElementNS(NS, 'clipPath'); clip.id = `c${i}`; const r = document.createElementNS(NS, 'rect'); r.setAttribute('x', x - fs * 0.1); r.setAttribute('width', w + fs * 0.2); clip.append(r); $('defs').append(clip);\n  const fill = mk(); fill.style.fill = figure; fill.setAttribute('clip-path', `url(#c${i})`); $('fills').append(fill);\n  const st = mk(); Object.assign(st.style, { fill: 'none', stroke: accent, strokeWidth: `${fs * 0.012}`, strokeLinejoin: 'round', strokeDasharray: `${fs * 4} ${fs * 4}` }); $('strokes').append(st);\n  return { fill, st, r, x, w, by, blank: !ch.trim() };\n});\nconst dom = $('dom'); Object.assign(dom.style, { top: `${mh + fs * 0.05}px`, fontFamily: B.font('mono'), fontSize: `${fs * (rows.length > 1 ? 0.17 : 0.13)}px`, color: muted, letterSpacing: '0.04em' });\ndom.textContent = CONFIG.domain;\ncam.place(mark, { x: 0, y: 0, z: 0 });\n\n// where the camera starts: the first letters (of the top line, when stacked)\nconst two = rows.length > 1, sx = two ? (letters[0].x + letters[1].x + letters[1].w) / 2 - mw / 2 : -mw * 0.38, sy = two ? fs * 0.6 - mh / 2 : -mh * 0.05;\nconst T = { trace: [0.2, 1.7], fill: [1.3, 2.5], dom: 2.7 };\nconst n = letters.length;\ns.update((t) => {\n  letters.forEach(({ fill, st, r, by }, i) => {\n    const k = i / Math.max(1, n - 1);\n    const a = T.trace[0] + (T.trace[1] - T.trace[0] - 0.6) * k, d = progress(t, a, a + 0.6, ease.inOutCubic);\n    st.style.strokeDashoffset = `${fs * 4 * (1 - d)}`;\n    const fa = T.fill[0] + (T.fill[1] - T.fill[0] - 0.5) * k, f = progress(t, fa, fa + 0.5, ease.inOutCubic);\n    r.setAttribute('y', by - fs * 0.9 * f - 1); r.setAttribute('height', fs * 1.3 * f + 2);     // rises from the baseline\n    st.style.opacity = String(d > 0 ? 1 - 0.85 * progress(t, fa + 0.3, fa + 0.9) : 0);\n  });\n  const dp = t >= T.dom ? spring(t - T.dom, { stiffness: 200, damping: 16 }) : 0;\n  dom.style.opacity = String(Math.min(1, dp * 1.5)); dom.style.transform = `translateY(${(1 - dp) * fs * 0.1}px)`; dom.style.letterSpacing = `${0.04 + 0.2 * (1 - Math.min(1, dp))}em`;\n  // the camera: close on the first letters, travelling back along the word as it builds\n  const p = progress(t, 0, T.fill[1] + 0.3, ease.inOutCubic), settle = progress(t, T.fill[1], D, ease.outCubic);\n  cam.at({ x: sx * (1 - p), y: sy * (1 - p) + fs * 0.08 * settle, z: DIST - SHORT * 0.9 * (1 - p) + SHORT * 0.05 * settle, yaw: -4 * (1 - p), pitch: 1 * (1 - p), roll: -1.5 * (1 - p) });\n});\nB.cue(s, 'text', T.trace[0]); B.cue(s, 'transition', T.fill[0]); B.cue(s, 'land', T.dom);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/logo-build/brief.md",
      "content": "# Logo build\n\nBlock: logo-build (5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nThe wordmark builds itself: each letter traces its outline, the fill rises from the baseline, and the domain lands under it.\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 1.7 and 2.5 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add logo-build --name my-logo-build\n# edit CONFIG in pieces/my-logo-build/scene.html, then:\nnpx paper-motion render pieces/my-logo-build/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": [
    "svg-logo",
    "text-mask"
  ],
  "preview": {
    "video": "previews/logo-build.webm",
    "poster": "previews/logo-build.jpg",
    "at": 4.6,
    "values": {}
  },
  "mood": [
    "technical",
    "calm"
  ],
  "duration": 5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Trace",
      "from": 0.2,
      "to": 1.7,
      "what": "trace"
    },
    {
      "name": "Fill",
      "from": 1.3,
      "to": 2.5,
      "what": "fill"
    },
    {
      "name": "Domain",
      "from": 2.7,
      "to": 3.3000000000000003,
      "what": "domain"
    },
    {
      "name": "Hold",
      "from": 3.3000000000000003,
      "to": 5,
      "what": "hold"
    }
  ],
  "when": [
    "the end card",
    "a logo sting"
  ],
  "needs": [
    {
      "kind": "name",
      "fill": {
        "domain": "$brief.action"
      }
    }
  ]
}