{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "search-type",
  "type": "block",
  "title": "Search type",
  "summary": "A command palette opens, the query types fast, the list filters live with the matches underlined and the top result is chosen.",
  "tags": [
    "block",
    "ui",
    "search",
    "command-palette",
    "typing"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "placeholder",
      "type": "string",
      "default": "Search resources…",
      "description": "placeholder",
      "group": "main",
      "control": "text"
    },
    {
      "name": "query",
      "type": "string",
      "default": "push",
      "description": "query",
      "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/search-type/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>search-type</title>\n<!--\n  Component · search type (5.6 s). A command palette springs open over a dimmed screen; a query types itself and the\n  list filters live, rows folding away as they stop matching, the matched letters lit in the accent; the top result\n  is chosen and flashes. The camera stays close on the palette and follows the list as it shortens.\n  Open 0.4 s · Type 0.95–1.5 s · Choose 2.3 s · Hold to 5.6 s.\n  Vertical/square: the app behind is a narrower, taller window sized from the short side, the palette takes most of\n  its width (larger type), and the camera fits the palette to the frame width, then keeps pushing in.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #comp { position: absolute; box-sizing: border-box; overflow: hidden; }\n  .ui { position: absolute; inset: 0; display: grid; grid-template-columns: 18% 1fr; }\n  .side { display: flex; flex-direction: column; gap: 1.1em; padding: 2.2em 1.6em; }\n  .main { display: flex; flex-direction: column; gap: 1.4em; padding: 2.2em; }\n  i { display: block; height: 0.6em; border-radius: 999px; }\n  #dim { position: absolute; inset: 0; }\n  #pal { position: absolute; left: 50%; top: 14%; border-radius: 1em; overflow: hidden; transform-origin: 50% 0; }\n  #q { display: flex; align-items: center; gap: 0.8em; padding: 1.2em 1.4em; font-size: 1.25em; }\n  .caret { display: inline-block; width: 0.08em; height: 1.1em; vertical-align: -0.15em; }\n  .r { overflow: hidden; }\n  .ri { display: flex; align-items: center; justify-content: space-between; padding: 0 1.4em; height: 2.9em; margin: 0 0.5em; border-radius: 0.6em; }\n  .kind { font-size: 0.85em; padding: 0.2em 0.6em; border-radius: 999px; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"comp\"><div class=\"ui\" id=\"ui\"></div><div id=\"dim\"></div><div id=\"pal\"><div id=\"q\"></div><div id=\"list\"></div></div></div></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  placeholder: 'Search resources…',\n  query: 'push',\n  items: [['magic-move', 'component'], ['push-in', 'shot'], ['word-rise', 'text'], ['pass-over', 'shot'], ['push', 'transition'], ['punch', 'camera'], ['dither-dissolve', 'transition'], ['focus-pull', 'shot']],\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.3;\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');\nconst INK = '#EDEAE3';   // the palette is always dark (a command palette), so its type is always light, whatever the brand's mode\nconst wide = W / H > 1.2, tall = H > W;\nconst FS = SHORT * (tall ? 0.03 : 0.026);                             // non-wide: the UI's type size in the world\nconst comp = $('comp'), cw = wide ? W * 0.72 * K : FS * (tall ? 24 / 0.84 : 30 / 0.66), ch = wide ? cw * 0.58 : cw * (tall ? 1.9 : 0.85), R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nObject.assign(comp.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: B.surface(0.2), border: `1.5px solid ${muted}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${wide ? cw * 0.0125 : FS}px`, fontFamily: B.font('text'), color: figure });\nconst line = (w, c = muted, o = 0.45) => `<i style=\"width:${w}%;background:${c};opacity:${o}\"></i>`;\nconst box = (h) => `<div style=\"height:${h}em;border-radius:0.8em;background:${ground};border:1px solid ${muted}33\"></div>`;\n$('ui').innerHTML = `<div class=\"side\" style=\"background:${ground}\">${line(70, figure, 0.9)}${line(85)}${line(60)}${line(75)}</div><div class=\"main\">${line(24, figure, 0.9)}${box(14)}${box(9)}</div>`;\n$('dim').style.background = 'rgba(0,0,0,0.55)';\nconst pal = $('pal'), pw = wide ? cw * 0.46 : FS * (tall ? 24 : 30);\nObject.assign(pal.style, { width: `${pw}px`, marginLeft: `${-pw / 2}px`, background: '#141414', color: INK, border: `1px solid ${muted}55`, boxShadow: `0 2em 5em rgba(0,0,0,0.7)` });\n$('q').style.borderBottom = `1px solid ${muted}33`;\n$('q').innerHTML = `<svg width=\"1.1em\" height=\"1.1em\" viewBox=\"0 0 20 20\"><circle cx=\"8.5\" cy=\"8.5\" r=\"6\" fill=\"none\" stroke=\"${muted}\" stroke-width=\"2\"/><path d=\"M13 13 L18 18\" stroke=\"${muted}\" stroke-width=\"2\" stroke-linecap=\"round\"/></svg><span style=\"white-space:pre\"><span id=\"qt\"></span><span class=\"caret\" style=\"background:${accent}\"></span></span><span id=\"ph\" style=\"color:${muted}\"></span><span style=\"margin-left:auto;color:${muted};font:400 0.75em ${B.font('mono')};border:1px solid ${muted}55;border-radius:0.4em;padding:0.2em 0.5em\">⌘K</span>`;\n$('ph').textContent = CONFIG.placeholder;\nconst list = $('list'); list.style.padding = '0.5em 0';\nconst rows = CONFIG.items.map(([name, kind]) => {\n  const r = document.createElement('div'); r.className = 'r';\n  r.innerHTML = `<div class=\"ri\"><span class=\"nm\" style=\"font:500 1.05em ${B.font('mono')}\"></span><span class=\"kind\" style=\"color:${muted};border:1px solid ${muted}44\">${kind}</span></div>`;\n  list.append(r); return { r, ri: r.firstChild, nm: r.querySelector('.nm'), name };\n});\ncam.place(comp, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\nconst rowH = rows[0].r.offsetHeight;\n\nconst T = { open: 0.4, type: [0.95, 1.5], choose: 2.3 };\nconst Q = CONFIG.query;\nconst typedAt = (u) => Math.round(Q.length * progress(u, ...T.type));\n// when each row last changed between matching and not, so the fold animates from there\nconst charT = Array.from({ length: Q.length + 1 }, (_, n) => n === 0 ? -1 : T.type[0] + (T.type[1] - T.type[0]) * ((n - 0.5) / Q.length));\nconst matches = (name, n) => name.includes(Q.slice(0, n));\ns.update((t) => {\n  const o = t >= T.open ? spring(t - T.open, { stiffness: 230, damping: 17 }) : 0;\n  pal.style.transform = `translateY(${(1 - o) * -1.2}em) scale(${0.92 + 0.08 * o})`; pal.style.opacity = String(Math.min(1, o * 2));\n  $('dim').style.opacity = String(progress(t, T.open, T.open + 0.3));\n  const n = typedAt(t);\n  $('qt').textContent = Q.slice(0, n); $('ph').style.display = n ? 'none' : ''; $('ph').style.marginLeft = '-0.6em';\n  $('q').querySelector('.caret').style.opacity = t < T.type[1] || Math.sin(t * 9) > 0 ? '1' : '0';\n  let first = -1;\n  rows.forEach((row, i) => {\n    const m = matches(row.name, n);\n    // fold height from the moment its status last flipped\n    let since = -10, was = true;\n    for (let k = 1; k <= n; k++) { const mk = matches(row.name, k); if (mk !== was) { since = charT[k]; was = mk; } }\n    const f = progress(t, since, since + 0.3, ease.inOutCubic);\n    const h = m ? 1 : 1 - f;\n    row.r.style.height = `${rowH * (since < 0 ? 1 : h)}px`; row.r.style.opacity = String(since < 0 ? 1 : (m ? 1 : 1 - f));\n    if (m && first < 0) first = i;\n    // the matched letters, lit\n    const q = Q.slice(0, n), at = q ? row.name.indexOf(q) : -1;\n    row.nm.innerHTML = at >= 0 ? `${row.name.slice(0, at)}<span style=\"color:${INK};text-decoration:underline;text-decoration-color:${accent};text-decoration-thickness:0.12em;text-underline-offset:0.25em\">${q}</span>${row.name.slice(at + q.length)}` : row.name;\n    row.nm.style.color = muted;\n  });\n  rows.forEach((row, i) => {\n    const sel = i === first && n > 0;\n    // the choice: the row brightens a step and presses, the words stay light\n    const press = sel && t >= T.choose ? spring(t - T.choose, { stiffness: 320, damping: 14 }) : 0;\n    const glow = sel && t >= T.choose ? Math.max(0, 1 - (t - T.choose) / 0.8) : 0;\n    row.ri.style.background = sel ? (t >= T.choose ? `color-mix(in srgb, #ffffff ${Math.round(8 + 10 * glow)}%, #141414)` : '#222') : 'transparent';\n    row.ri.style.boxShadow = 'none';\n    row.ri.style.transform = sel && t >= T.choose ? `scale(${1 + 0.04 * (1 - press) * (t - T.choose < 0.1 ? -1 : 1)})` : 'none';\n  });\n  // the camera: close on the palette; down the list as it settles; a nudge on the choice\n  const arrive = progress(t, 0, 0.8, ease.outCubic), close = progress(t, 0.3, 1.1, ease.inOutCubic);\n  const py = pal.offsetTop + Math.min(pal.offsetHeight, rowH * 5) * 0.5 - ch / 2;\n  const kick = t >= T.choose ? Math.sin(Math.min(1, (t - T.choose) / 0.4) * Math.PI) : 0;\n  if (!wide) {\n    // fit the palette to the frame's width, then keep pushing in; a nudge on the choice\n    const P = SHORT * 1.7, sFit = Math.min((W * 0.8) / pw, (H * 0.86) / (pal.offsetHeight + rowH));\n    const sNow = sFit * (0.55 + 0.45 * arrive) * (0.8 + 0.2 * close) * (1 + 0.1 * progress(t, T.type[1], D, ease.inOutSine) + 0.02 * kick);\n    cam.at({ x: 0, y: (pal.offsetTop + pal.offsetHeight / 2 - ch / 2) * Math.min(1, close + arrive * 0.6), z: P / sNow - P, yaw: -8 * (1 - arrive) + 2.5 * close * Math.sin(t * 0.8), pitch: 3 * (1 - arrive) + 3 * close });\n  } else\n  cam.at({ x: 0, y: py * close, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * 1.0 * close - SHORT * 0.15 * progress(t, T.type[1], D, ease.inOutSine) - SHORT * 0.02 * kick, yaw: -8 * (1 - arrive) + 3 * close * Math.sin(t * 0.8), pitch: 3 * (1 - arrive) + 3 * close });\n  comp.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'transition', T.open); B.cue(s, 'text', T.type[0]); B.cue(s, 'land', T.choose);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/search-type/brief.md",
      "content": "# Search type\n\nBlock: search-type (5.6 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA command palette opens, the query types fast, the list filters live with the matches underlined and the top result is chosen.\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 and 1.5 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add search-type --name my-search-type\n# edit CONFIG in pieces/my-search-type/scene.html, then:\nnpx paper-motion render pieces/my-search-type/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": [
    "code-type",
    "form-fill"
  ],
  "preview": {
    "video": "previews/search-type.webm",
    "poster": "previews/search-type.jpg",
    "at": 2.6,
    "values": {}
  },
  "mood": [
    "technical",
    "playful"
  ],
  "duration": 5.6,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Open",
      "from": 0.4,
      "to": 1,
      "what": "open"
    },
    {
      "name": "Type",
      "from": 0.95,
      "to": 1.5,
      "what": "type"
    },
    {
      "name": "Choose",
      "from": 2.3,
      "to": 2.9,
      "what": "choose"
    },
    {
      "name": "Hold",
      "from": 2.9,
      "to": 5.6,
      "what": "hold"
    }
  ],
  "when": [
    "find anything in one keystroke",
    "a library or catalog"
  ],
  "needs": [
    {
      "kind": "search",
      "fill": {
        "placeholder": "$placeholder",
        "query": "$query",
        "items": "$items"
      }
    }
  ]
}