{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "browser-frame",
  "type": "block",
  "title": "Browser frame",
  "summary": "The real product in a browser: the address types close up, the page loads and settles, the camera travels down it with pauses.",
  "tags": [
    "block",
    "ui",
    "browser",
    "website",
    "screenshot",
    "scroll"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "image",
      "type": "string",
      "default": "",
      "description": "a full-page screenshot of the product (tall); empty draws a stand-in page in the brand's colours",
      "group": "main",
      "control": "text"
    },
    {
      "name": "url",
      "type": "string",
      "default": "your-product.com",
      "description": "url",
      "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/browser-frame/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>browser-frame</title>\n<!--\n  Component · browser frame (6.4 s). The real product, in a browser: the address types itself, the page loads with a\n  thin progress bar and settles in from a blur, then the camera travels down the page as it scrolls, pausing on the\n  sections that matter. Give it a full-page screenshot (`image`, tall) and the stops to pause on.\n  Type 0.4–1.3 s · Load 1.35–2.0 s · Scroll 2.2–5.8 s · Hold to 6.4 s.\n  Square: a taller window, page shown a little larger. Vertical: a narrow portrait window, page shown larger (sidebar cropped). Both aim the URL zoom at the full address.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #win { position: absolute; box-sizing: border-box; overflow: hidden; display: flex; flex-direction: column; }\n  #bar { position: relative; display: flex; align-items: center; gap: 1em; padding: 0 1.2em; flex: none; }\n  #url { flex: 1; display: flex; align-items: center; gap: 0.6em; padding: 0.55em 1em; border-radius: 0.6em; max-width: 60%; margin: 0 auto; }\n  .caret { display: inline-block; width: 0.08em; height: 1.1em; vertical-align: -0.15em; }\n  #prog { position: absolute; left: 0; bottom: 0; height: 2px; transform-origin: 0 50%; }\n  #view { position: relative; flex: 1; overflow: hidden; }\n  #page { position: absolute; left: 0; top: 0; width: 100%; }\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=\"win\"><div id=\"bar\"><div id=\"dots\"></div><div id=\"url\"></div><div id=\"prog\"></div></div><div id=\"view\"><img id=\"page\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease } 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  image: '',                             // a full-page screenshot of the product (tall); empty draws a stand-in page in the brand's colours\n  url: 'your-product.com',\n  stops: [0, 0.32, 0.68],                 // where the scroll pauses, as fractions of the page's scrollable height\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 6.4;\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\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 browser chrome and the page's cards are always dark, so their type is always light, whatever the brand's mode\n// 16:9 a desktop window; square a taller one; vertical a narrow portrait window; outside 16:9 the page is shown larger, sidebar cropped, so it reads\nconst tall = H > W, square = W === H;\nconst L = tall ? { cw: W * 0.9, ch: H * 0.64, page: 1.8, crop: 0.17, fs: 0.026, url: 0.82 } : square ? { cw: W * 0.86, ch: W * 0.66, page: 1.22, crop: 0.17, fs: 0.017, url: 0.7 } : { cw: W * 0.74, ch: W * 0.74 * 0.6, page: 1, crop: 0, fs: 0.0125, url: 0.6 };\nconst win = $('win'), cw = L.cw * K, ch = L.ch * K, R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nObject.assign(win.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: '#0b0b0b', border: `1.5px solid ${muted}55`, boxShadow: `0 ${SHORT * 0.05}px ${SHORT * 0.14}px rgba(0,0,0,0.6)`, fontSize: `${cw * L.fs}px`, fontFamily: B.font('text'), color: INK });\nObject.assign($('bar').style, { height: '3.4em', background: '#141414', borderBottom: `1px solid ${muted}33` });\n$('dots').innerHTML = ['#ff5f57', '#febc2e', '#28c840'].map((c) => `<i style=\"display:inline-block;width:0.8em;height:0.8em;border-radius:50%;margin-right:0.45em;background:${c};opacity:0.75\"></i>`).join('');\nObject.assign($('url').style, { background: '#0b0b0b', border: `1px solid ${muted}33`, color: muted });\n$('url').innerHTML = `<svg width=\"0.9em\" height=\"0.9em\" viewBox=\"0 0 16 16\"><rect x=\"3\" y=\"7\" width=\"10\" height=\"7\" rx=\"1.5\" fill=\"none\" stroke=\"${muted}\" stroke-width=\"1.5\"/><path d=\"M5 7 V5 a3 3 0 0 1 6 0 V7\" fill=\"none\" stroke=\"${muted}\" stroke-width=\"1.5\"/></svg><span style=\"white-space:pre;color:${INK}\"><span id=\"u\"></span><span class=\"caret\" style=\"background:${accent}\"></span></span>`;\n$('prog').style.background = accent;\n$('url').style.maxWidth = `${L.url * 100}%`;\n// no screenshot yet: a stand-in page drawn in the brand's colours (a header, a hero, rows of cards), so the scene works at once\nconst standIn = () => {\n  const c = document.createElement('canvas'); c.width = 1440; c.height = 3200; const x = c.getContext('2d');\n  const box = (l, t, w, h, col, r = 14) => { x.fillStyle = col; x.beginPath(); x.roundRect(l, t, w, h, r); x.fill(); };\n  x.fillStyle = ground; x.fillRect(0, 0, 1440, 3200);\n  box(60, 40, 180, 20, figure, 10); [1000, 1110, 1220].forEach((l) => box(l, 42, 80, 16, muted, 8));\n  box(60, 220, 760, 90, figure, 20); box(60, 340, 560, 90, figure, 20); box(60, 480, 640, 22, muted, 11); box(60, 520, 520, 22, muted, 11);\n  box(60, 600, 220, 64, accent, 32);\n  for (let row = 0; row < 6; row++) for (let col = 0; col < 3; col++) {\n    const l = 60 + col * 450, t = 800 + row * 400; box(l, t, 420, 260, '#161616', 18); box(l + 24, t + 24, 372, 150, (row + col) % 3 === 1 ? accent : '#222', 12);\n    box(l + 24, t + 196, 220, 18, INK, 9); box(l + 24, t + 226, 300, 14, muted, 7);\n  }\n  return c.toDataURL('image/png');\n};\nconst page = $('page'); page.src = CONFIG.image || standIn(); page.style.width = `${L.page * 100}%`; page.style.left = `${-L.crop * L.page * 100}%`;\ncam.place(win, { x: 0, y: 0, z: 0 });\nawait new Promise((r) => (page.complete ? r() : (page.onload = r)));\nawait document.fonts.ready;\n// outside 16:9 the URL close-up aims at the middle of the full address and zooms only as far as the address fits the width\nconst urlEl = $('url'), uEl = $('u'); uEl.textContent = CONFIG.url;\nconst lockW = cw * L.fs * 1.5, textW = uEl.offsetWidth + lockW, urlX = uEl.offsetLeft - lockW + textW / 2 - cw / 2;   // lock + address, in the window\nuEl.textContent = '';\nconst P = SHORT * 1.7, zoomIn = W > H ? SHORT * 1.45 : DIST - (P / Math.min(1.95, (W * 0.8) / textW) - P);\nconst view = $('view'), vh = view.offsetHeight, ph = page.offsetHeight, travel = Math.max(0, ph - vh);\n\nconst T = { type: [0.4, 1.3], enter: 1.35, load: [1.35, 2.0], scroll: [2.2, 5.8] };\n// the scroll: glide to each stop, rest a beat there\nconst seg = (T.scroll[1] - T.scroll[0]) / (CONFIG.stops.length - 1);\nconst scrollAt = (t) => {\n  let y = CONFIG.stops[0];\n  for (let i = 1; i < CONFIG.stops.length; i++) y += (CONFIG.stops[i] - CONFIG.stops[i - 1]) * progress(t, T.scroll[0] + (i - 1) * seg, T.scroll[0] + (i - 1) * seg + seg * 0.7, ease.inOutCubic);\n  return y * travel;\n};\ns.update((t) => {\n  const n = Math.round(CONFIG.url.length * progress(t, ...T.type));\n  $('u').textContent = CONFIG.url.slice(0, n);\n  win.querySelector('.caret').style.opacity = t < T.enter && (t < T.type[1] || Math.sin(t * 10) > 0) ? '1' : '0';\n  // load: the bar runs, then fades; the page settles in from a blur\n  const l = progress(t, ...T.load, ease.inOutCubic);\n  $('prog').style.width = '100%'; $('prog').style.transform = `scaleX(${l})`; $('prog').style.opacity = String(t < T.load[1] + 0.2 ? (t >= T.enter ? 1 : 0) : 1 - progress(t, T.load[1] + 0.2, T.load[1] + 0.5));\n  const show = progress(t, T.load[0] + 0.3, T.load[1] + 0.2, ease.outCubic);\n  page.style.opacity = String(show); page.style.filter = show < 1 ? `blur(${(1 - show) * 12}px)` : 'none';\n  const y = scrollAt(t);\n  page.style.transform = `translateY(${-y + (1 - show) * vh * 0.04}px)`;\n  // the camera: close on the address bar while it types, back to the page as it loads, leaning with the scroll\n  const arrive = progress(t, 0, 0.8, ease.outCubic), onUrl = progress(t, 0.2, 0.7, ease.inOutCubic) * (1 - progress(t, T.load[0], T.load[1] + 0.3, ease.inOutCubic));\n  const sv = (scrollAt(t + 0.05) - scrollAt(t - 0.05)) / (0.1 * Math.max(1, travel));    // scroll speed, for a lean\n  cam.at({ x: (W > H && !square ? -cw * 0.15 : urlX) * onUrl, y: (-ch / 2 + cw * L.fs * 1.7) * onUrl, z: DIST + SHORT * 0.3 * (1 - arrive) - zoomIn * onUrl - SHORT * 0.18 * progress(t, T.load[1], D, ease.inOutSine), yaw: -7 * (1 - arrive) + 3 * Math.sin(t * 0.6), pitch: 2 * (1 - arrive) - sv * 6, roll: 0 });\n  win.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'text', T.type[0]); B.cue(s, 'land', T.enter); B.cue(s, 'transition', T.scroll[0]);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/browser-frame/brief.md",
      "content": "# Browser frame\n\nBlock: browser-frame (6.4 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nThe real product in a browser: the address types close up, the page loads and settles, the camera travels down it with pauses.\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.3 and 2 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add browser-frame --name my-browser-frame\n# edit CONFIG in pieces/my-browser-frame/scene.html, then:\nnpx paper-motion render pieces/my-browser-frame/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": [
    "device-frame",
    "pass-over"
  ],
  "preview": {
    "video": "previews/browser-frame.webm",
    "poster": "previews/browser-frame.jpg",
    "at": 4.4,
    "values": {
      "image": "browser-site.jpg",
      "url": "paper-motion.vercel.app/library"
    }
  },
  "mood": [
    "minimal",
    "bold"
  ],
  "duration": 6.4,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Type",
      "from": 0.4,
      "to": 1.3,
      "what": "type"
    },
    {
      "name": "Load",
      "from": 1.35,
      "to": 2,
      "what": "load"
    },
    {
      "name": "Scroll",
      "from": 2.2,
      "to": 5.8,
      "what": "scroll"
    },
    {
      "name": "Hold",
      "from": 5.8,
      "to": 6.4,
      "what": "hold"
    }
  ],
  "when": [
    "show a real site or web app",
    "a tour of a long page"
  ],
  "needs": [
    {
      "kind": "screen",
      "prefer": {
        "device": "desktop"
      },
      "fill": {
        "image": "$image",
        "url": "$url"
      }
    }
  ]
}