{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "device-frame",
  "type": "block",
  "title": "Device frame",
  "summary": "A phone with real thickness, the product scrolling on its screen; the camera orbits round it from the side to face-on.",
  "tags": [
    "block",
    "ui",
    "phone",
    "mockup",
    "3d",
    "mobile"
  ],
  "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 screenshot of the app (tall); empty draws the placeholder app",
      "group": "main",
      "control": "text"
    },
    {
      "name": "title",
      "type": "string",
      "default": "Renders",
      "description": "title",
      "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/device-frame/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>device-frame</title>\n<!--\n  Component · device frame (5.5 s). A phone with real thickness stands in space with the product on its screen; the\n  camera comes round it from the side to face it, close, while the screen scrolls on its own. Put any screen in it\n  (`image`), or the placeholder app draws in the brand's colours.\n  Arrive 0–1 s · Orbit 0.3–4 s · Scroll 1.2–4.4 s · Hold to 5.5 s.\n  Vertical: the phone takes the height (half of H); square sizes it a little larger from the short side.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  .slab { position: absolute; box-sizing: border-box; }\n  #screen { position: absolute; overflow: hidden; }\n  #feed { position: absolute; left: 0; right: 0; top: 0; display: flex; flex-direction: column; gap: 1.2em; padding: 4.2em 1.4em 2em; }\n  .card { border-radius: 1em; overflow: hidden; }\n  i { display: block; height: 0.65em; 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=\"vig\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"></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 screenshot of the app (tall); empty draws the placeholder app\n  title: 'Renders',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.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.4;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.6) 100%)';\n\nconst DIST = SHORT * 0.7, 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 tall = H > W, square = W === H;\nconst ph = (tall ? H * 0.5 : SHORT * (square ? 0.68 : 0.6)) * K, pw = ph * 0.48, rad = pw * 0.16, depth = pw * 0.1, bezel = pw * 0.035;\n// the body: slices stacked in depth make the thickness; the front one holds the screen\nconst N = 8, slabs = [];\nfor (let k = 0; k < N; k++) {\n  const el = document.createElement('div'); el.className = 'slab';\n  const front = k === N - 1, edge = k === 0 || front;\n  Object.assign(el.style, { width: `${pw}px`, height: `${ph}px`, borderRadius: `${rad}px`, background: front ? '#050505' : `linear-gradient(90deg, #2a2a2a, #3b3b3b 50%, #222)`, border: `1px solid ${edge ? '#4a4a4a' : '#333'}` });\n  $('world').append(el); slabs.push(el);\n  cam.place(el, { x: 0, y: 0, z: -depth + (depth * k) / (N - 1) });\n}\nconst front = slabs[N - 1];\nfront.style.boxShadow = `inset 0 0 0 ${bezel * 0.25}px #1d1d1d`;\nconst screen = document.createElement('div'); screen.id = 'screen';\nObject.assign(screen.style, { left: `${bezel}px`, top: `${bezel}px`, right: `${bezel}px`, bottom: `${bezel}px`, borderRadius: `${rad - bezel}px`, background: B.surface(0.12), fontSize: `${pw * 0.034}px`, fontFamily: B.font('text') });\nfront.append(screen);\nconst island = document.createElement('div');\nObject.assign(island.style, { position: 'absolute', left: '50%', top: `${bezel * 1.6}px`, width: `${pw * 0.28}px`, height: `${pw * 0.075}px`, transform: 'translateX(-50%)', borderRadius: '999px', background: '#000', zIndex: 2 });\nfront.append(island);\nconst feed = document.createElement('div'); feed.id = 'feed'; screen.append(feed);\nif (CONFIG.image) { feed.innerHTML = `<img src=\"${CONFIG.image}\" style=\"width:100%;display:block\">`; feed.style.padding = 0; }\nelse {\n  const line = (w, c = muted, o = 0.45) => `<i style=\"width:${w}%;background:${c};opacity:${o}\"></i>`;\n  const card = (k) => `<div class=\"card\" style=\"background:${ground};border:1px solid ${muted}33\"><div class=\"pic\" style=\"height:${pw * 0.5}px;position:relative;background:${k % 3 === 1 ? accent : '#151515'}\"></div><div style=\"padding:1em;display:flex;flex-direction:column;gap:0.6em\">${line(55, figure, 0.85)}${line(80)}</div></div>`;\n  feed.innerHTML = `<div style=\"font:400 2.2em ${B.font('display')};color:${figure}\">${CONFIG.title}</div>${line(45)}` + Array.from({ length: 7 }, (_, k) => card(k)).join('');\n  if (bgId) [...feed.querySelectorAll('.pic')].forEach((p, k) => { if (k % 3 !== 1) { const f = document.createElement('div'); f.style.cssText = 'position:absolute;inset:0'; p.append(f); B.shader(s, f, bgId); } });\n}\n// a glint across the glass that moves with the turn\nconst glass = document.createElement('div');\nObject.assign(glass.style, { position: 'absolute', inset: 0, borderRadius: `${rad}px`, pointerEvents: 'none', zIndex: 3 });\nfront.append(glass);\nawait document.fonts.ready;\n\nconst T = { orbit: [0.3, 4.0], scroll: [1.2, 4.4] };\ns.update((t) => {\n  const arrive = progress(t, 0, 1.0, ease.outCubic), o = progress(t, ...T.orbit, ease.inOutCubic);\n  const yaw = 48 - 58 * o;                 // from the side, round past face-on, settling a touch to the other side\n  const Rr = DIST + SHORT * 0.5 * (1 - arrive) - SHORT * 0.4 * o, a = yaw * Math.PI / 180;   // a true orbit: the phone stays on the axis\n  cam.at({ x: Rr * Math.sin(a), y: -ph * 0.02, z: Rr * Math.cos(a), yaw, pitch: 9 * (1 - o) + 2 * o, roll: -3 * (1 - o) });\n  slabs.forEach((el) => { el.style.opacity = String(progress(t, 0, 0.4)); });\n  const sc = progress(t, ...T.scroll, ease.inOutCubic);\n  feed.style.transform = `translateY(${-sc * (feed.offsetHeight - screen.offsetHeight * 1.1)}px)`;\n  glass.style.background = `linear-gradient(${115 + yaw * 0.6}deg, transparent 35%, rgba(255,255,255,${0.1 + 0.06 * (1 - o)}) 48%, transparent 60%)`;\n  glass.style.backgroundPosition = `${-yaw}% 0`;\n});\nB.cue(s, 'transition', 0.2); B.cue(s, 'land', T.orbit[1]);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/device-frame/brief.md",
      "content": "# Device frame\n\nBlock: device-frame (5.5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA phone with real thickness, the product scrolling on its screen; the camera orbits round it from the side to face-on.\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 4 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add device-frame --name my-device-frame\n# edit CONFIG in pieces/my-device-frame/scene.html, then:\nnpx paper-motion render pieces/my-device-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": [
    "browser-frame",
    "parallax-stack"
  ],
  "preview": {
    "video": "previews/device-frame.webm",
    "poster": "previews/device-frame.jpg",
    "at": 4.8,
    "values": {}
  },
  "mood": [
    "luxury",
    "calm"
  ],
  "duration": 5.5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 1,
      "what": "arrive"
    },
    {
      "name": "Orbit",
      "from": 0.3,
      "to": 4,
      "what": "orbit"
    },
    {
      "name": "Scroll",
      "from": 1.2,
      "to": 4.4,
      "what": "scroll"
    },
    {
      "name": "Hold",
      "from": 4.4,
      "to": 5.5,
      "what": "hold"
    }
  ],
  "when": [
    "a mobile app",
    "any screen that deserves an object"
  ],
  "needs": [
    {
      "kind": "screen",
      "where": {
        "device": "phone"
      },
      "fill": {
        "image": "$image",
        "title": "$title"
      }
    }
  ]
}