{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "line-in",
  "type": "block",
  "title": "A sentence",
  "summary": "One sentence in the brand's display type, arriving in one of eight entrances; the words that carry it land in the accent.",
  "tags": [
    "block",
    "text",
    "sentence",
    "line",
    "headline",
    "entrance"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "text",
      "type": "string",
      "default": "Video editing without the timeline",
      "description": "the sentence",
      "group": "main",
      "control": "text"
    },
    {
      "name": "mark",
      "type": "string",
      "default": "without the timeline",
      "description": "the words that land in the accent",
      "group": "main",
      "control": "text"
    },
    {
      "name": "entrance",
      "type": "enum",
      "default": "rise",
      "options": [
        "rise",
        "focus",
        "scramble",
        "type",
        "track",
        "flip",
        "pop",
        "bar"
      ],
      "description": "how it arrives",
      "group": "main",
      "control": "segmented"
    },
    {
      "name": "align",
      "type": "enum",
      "default": "center",
      "options": [
        "center",
        "left"
      ],
      "description": "where it sits",
      "group": "main",
      "control": "segmented"
    },
    {
      "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/line-in/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>line-in</title>\n<!--\n  Text · a sentence on screen (4 s). One sentence in the brand's display type, over its field, arriving in one of the\n  library's eight text entrances; the words that carry it (`mark`) land in the accent, and the camera keeps a slow\n  push so the hold is never still. Because the entrance is a setting, one piece can hold several sentences, each\n  arriving its own way.\n  Vertical/square: the sentence wraps narrower and sits larger.\n  Enter 0.3–1.7 s · Hold to 4 s.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #p { display: flex; align-items: center; }\n  #line { line-height: 1.06; text-wrap: balance; }\n  #line > span { white-space: pre-wrap; }\n  #rule { height: 2px; transform-origin: 0 50%; }\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=\"p\" class=\"abs\" style=\"inset:0\"><div id=\"box\"><div id=\"line\"></div><div id=\"rule\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, clamp } from 'paper-motion';\nimport { wordRise, blurIn, scramble, typeOn, typingTimes, keySounds, trackIn, flipIn, popIn, barReveal } from 'paper-motion/moves';\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  text: 'Video editing without the timeline',\n  mark: 'without the timeline',          // the words that land in the accent; empty for none\n  entrance: 'rise',                      // rise · focus · scramble · type · track · flip · pop · bar; null for the brand's\n  align: 'center',                       // center or left\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 4, tall = H > W;\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.42;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 28%, rgba(0,0,0,0.62) 100%)';\n\n// the sentence: split around the marked words, so each part can arrive and the mark can take the accent\nconst text = String(CONFIG.text ?? ''), at = CONFIG.mark ? text.indexOf(CONFIG.mark) : -1;\nconst parts = at < 0 ? [[text, false]] : [[text.slice(0, at), false], [CONFIG.mark, true], [text.slice(at + CONFIG.mark.length), false]].filter(([x]) => x);\nconst line = B.style($('line'), 'display', { short: SHORT, color: 'figure' }), accent = B.color('accent', '#E9E4D8');\n// longer sentences set smaller, so any of them fits on two or three lines\nconst len = text.length, size = SHORT * clamp((tall ? 0.19 : 0.185) - len * 0.0013, tall ? 0.085 : 0.075, tall ? 0.16 : 0.15);\nline.style.fontSize = `${size}px`;\nconst left = CONFIG.align === 'left';\nObject.assign($('p').style, { justifyContent: left ? 'flex-start' : 'center', padding: `0 ${W * (left ? 0.09 : 0.07)}px` });\nObject.assign($('box').style, { maxWidth: `${W * (tall ? 0.86 : 0.78)}px`, textAlign: left ? 'left' : 'center' });\nconst segs = parts.map(([t, mark]) => { const e = document.createElement('span'); e.textContent = t; if (mark) e.style.color = accent; line.append(e); return e; });\nObject.assign($('rule').style, { background: accent, width: `${Math.min(W * 0.18, size * 3)}px`, marginTop: `${size * 0.42}px`, marginLeft: left ? '0' : 'auto', marginRight: left ? '0' : 'auto' });\nawait document.fonts.ready;\n\n// one entrance, chosen by name; each is the library's own move, so they read as a family\nconst E = CONFIG.entrance ?? B.motion?.entrance ?? 'rise', T0 = 0.3, ENTER = 1.4;   // null: the brand's own entrance\nconst each = (fn) => { let off = 0; const n = Math.max(1, text.replace(/\\s/g, '').length); return (t) => segs.forEach((e) => { const share = e.textContent.replace(/\\s/g, '').length / n; fn(e, t, T0 + off * ENTER, Math.max(0.35, share * ENTER)); off += share; }) || (off = 0); };\nlet enter;\nif (E === 'focus') enter = (t) => blurIn(line, t, { start: T0, duration: 1.1, blur: size * 0.18 });\nelse if (E === 'track') enter = (t) => trackIn(line, t, { start: T0, duration: 1.3, from: 0.38 });\nelse if (E === 'bar') enter = (t) => barReveal(line, t, { start: T0, duration: 1.0, color: accent });\nelse if (E === 'type') {\n  const times = typingTimes(text, { start: T0, cps: Math.max(14, text.length / 1.4), seed: 3 });\n  let k = 0; const spans = segs.map((e) => { const tx = e.textContent, sl = times.slice(k, k + tx.length); k += tx.length; e.textContent = ''; return [e, tx, sl]; });\n  const cur = document.createElement('span'); Object.assign(cur.style, { display: 'inline-block', width: '0.08em', height: '0.9em', marginLeft: '0.04em', background: accent, verticalAlign: '-0.08em' }); line.append(cur);\n  enter = (t) => { spans.forEach(([e, tx, sl]) => { let n = 0; while (n < sl.length && t >= sl[n]) n++; e.textContent = tx.slice(0, n); }); cur.style.opacity = t > times.at(-1) + 0.4 ? (Math.floor(t * 2.2) % 2 ? 0 : 1) : 1; };\n  keySounds(s, text, times, { ...B.keys, seed: 5 });\n} else {\n  const fn = { rise: (e, t, a, d) => wordRise(e, t, { start: a, each: 0.08, duration: 0.6 }), scramble: (e, t, a, d) => scramble(e, t, { start: a, duration: d + 0.4 }),\n    flip: (e, t, a) => flipIn(e, t, { start: a, each: 0.035 }), pop: (e, t, a) => popIn(e, t, { start: a, each: 0.03 }) }[E] ?? ((e, t, a) => wordRise(e, t, { start: a, each: 0.08, duration: 0.6 }));\n  enter = each(fn);\n}\n\ns.update((t) => {\n  enter(t);\n  const r = progress(t, T0 + ENTER * 0.8, T0 + ENTER + 0.4, ease.outExpo);\n  $('rule').style.transform = `scaleX(${r})`;\n  // a slow push that never stops, and the field a little slower behind it\n  const k = progress(t, 0, D, ease.outSine);\n  $('box').style.transform = `scale(${1.02 + 0.05 * k}) translateY(${(1 - progress(t, 0, 1.6, ease.outCubic)) * size * 0.12}px)`;\n  $('bg').style.transform = `scale(${1.06 + 0.04 * k})`;\n});\nB.cue(s, 'text', T0); B.cue(s, 'land', T0 + ENTER);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/line-in/brief.md",
      "content": "# A sentence\n\nBlock: line-in (4 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nOne sentence in the brand's display type, arriving in one of eight entrances (rise, focus, scramble, type, track,\nflip, pop, bar); the marked words land in the accent and a short rule draws under it.\n\nA block is one ready-made moment. Edit `CONFIG` (its sentence, the words to mark, the entrance, the alignment and the\nformat: 16:9, 9:16 or 1:1); check `npx paper-motion still` at 1.0 and 2.4 s; render. A piece may use it more than\nonce, each time with a different entrance.\n"
    }
  ],
  "requires": {
    "engine": ">=0.3.0"
  },
  "usage": "npx paper-motion add line-in --name my-line\n# edit CONFIG in pieces/my-line/scene.html, then:\nnpx paper-motion render pieces/my-line/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.",
    "The entrance is a setting: a piece may hold several sentences, each arriving its own way (the planner gives each one a different entrance unless the user chose)."
  ],
  "related": [
    "marker-highlight",
    "word-rise",
    "dither-dissolve"
  ],
  "preview": {
    "video": "previews/line-in.webm",
    "poster": "previews/line-in.jpg",
    "at": 2.4,
    "values": {}
  },
  "mood": [
    "calm",
    "editorial",
    "bold"
  ],
  "duration": 4,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Enter",
      "from": 0.3,
      "to": 1.7,
      "what": "the sentence arrives"
    },
    {
      "name": "Hold",
      "from": 1.7,
      "to": 4,
      "what": "it holds under a slow push"
    }
  ],
  "when": [
    "any sentence that should be read on its own",
    "several lines in one piece, each arriving differently"
  ],
  "needs": [
    {
      "kind": "line",
      "fill": {
        "text": "$text",
        "mark": "$mark"
      }
    }
  ],
  "repeat": {
    "param": "entrance",
    "previews": {
      "rise": "word-rise",
      "focus": "blur-in",
      "scramble": "scramble",
      "type": "type-on",
      "track": "track-in",
      "flip": "flip-in",
      "pop": "pop-in",
      "bar": "bar-reveal"
    }
  }
}