Skip to content

Write HTML. Render video. Built for agents.

15.5 KB
Raw Blame
{"html":"<!doctype html>\n<!--\n  Exploded Stack: isometric layer plates sit as one stack, explode apart along the vertical\n  axis with labels drawing in beside each layer, hold, then collapse back, so the clip loops.\n  Seek-safe: every frame is render(t), driven by one linear GSAP clock.\n-->\n<html\n  lang=\"en\"\n  data-composition-variables='[{\"id\":\"title\",\"type\":\"string\",\"role\":\"content\",\"label\":\"Title\",\"default\":\"How a request moves\",\"maxLength\":32},{\"id\":\"layer_1\",\"type\":\"string\",\"role\":\"content\",\"label\":\"Top layer\",\"default\":\"Interface\",\"maxLength\":22},{\"id\":\"layer_2\",\"type\":\"string\",\"role\":\"content\",\"label\":\"Layer 2\",\"default\":\"API gateway\",\"maxLength\":22},{\"id\":\"layer_3\",\"type\":\"string\",\"role\":\"content\",\"label\":\"Layer 3\",\"default\":\"Services\",\"maxLength\":22},{\"id\":\"layer_4\",\"type\":\"string\",\"role\":\"content\",\"label\":\"Bottom layer\",\"default\":\"Data\",\"maxLength\":22},{\"id\":\"accent\",\"type\":\"color\",\"role\":\"style\",\"label\":\"Accent\",\"default\":\"#0a84ff\"},{\"id\":\"background\",\"type\":\"color\",\"role\":\"style\",\"label\":\"Backdrop\",\"default\":\"#f4f4f5\"}]'\n>\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n    <title>Exploded Stack</title>\n    <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n    <style>\n      @font-face {\n        font-family: \"ES Inter\";\n        font-weight: 500;\n        src: url(https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-500-normal.woff2)\n          format(\"woff2\");\n      }\n      @font-face {\n        font-family: \"ES Inter\";\n        font-weight: 700;\n        src: url(https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-700-normal.woff2)\n          format(\"woff2\");\n      }\n      html,\n      body {\n        margin: 0;\n        width: 1920px;\n        height: 1080px;\n        overflow: hidden;\n        background: #f4f4f5;\n      }\n      #es-root {\n        position: relative;\n        width: 1920px;\n        height: 1080px;\n        overflow: hidden;\n        background: var(--es-bg, #f4f4f5);\n        font-family: \"ES Inter\", system-ui, sans-serif;\n      }\n      #es-canvas,\n      #es-leaders {\n        position: absolute;\n        inset: 0;\n        width: 1920px;\n        height: 1080px;\n        display: block;\n      }\n      #es-title {\n        position: absolute;\n        left: 120px;\n        top: 110px;\n        font-size: 60px;\n        font-weight: 700;\n        letter-spacing: -0.02em;\n        color: #14161c;\n      }\n      .es-label {\n        position: absolute;\n        left: 0;\n        top: 0;\n        display: flex;\n        align-items: center;\n        gap: 18px;\n        font-size: 34px;\n        font-weight: 500;\n        color: #1b1e27;\n        white-space: nowrap;\n        opacity: 0;\n      }\n      .es-index {\n        font-size: 20px;\n        font-weight: 700;\n        letter-spacing: 0.08em;\n      }\n      #es-leaders line {\n        stroke: rgba(27, 30, 39, 0.35);\n        stroke-width: 2;\n      }\n    </style>\n  </head>\n  <body>\n    <div\n      id=\"es-root\"\n      data-composition-id=\"exploded-stack\"\n      data-start=\"0\"\n      data-duration=\"5\"\n      data-width=\"1920\"\n      data-height=\"1080\"\n    >\n      <canvas\n        id=\"es-canvas\"\n        class=\"clip\"\n        data-start=\"0\"\n        data-duration=\"5\"\n        data-track-index=\"1\"\n      ></canvas>\n      <svg id=\"es-leaders\" viewBox=\"0 0 1920 1080\" aria-hidden=\"true\"></svg>\n      <div id=\"es-title\"></div>\n      <div id=\"es-labels\"></div>\n    </div>\n\n    <script>\n      (function () {\n        var html = document.documentElement;\n        var defaults = {};\n        try {\n          JSON.parse(html.getAttribute(\"data-composition-variables\") || \"[]\").forEach(function (v) {\n            defaults[v.id] = v.default;\n          });\n        } catch (error) {\n          /* malformed declaration: the scene module falls back to its own defaults */\n        }\n        var scoped =\n          (window.__hyperframes &&\n            window.__hyperframes.getVariables &&\n            window.__hyperframes.getVariables()) ||\n          {};\n        var vars = Object.assign({}, defaults, window.__hfVariables || {}, scoped);\n        var hex = function (v, fallback) {\n          return /^#[0-9a-f]{6}$/i.test(String(v)) ? String(v) : fallback;\n        };\n        var root = document.getElementById(\"es-root\");\n        var duration = Math.max(0.001, parseFloat(root.dataset.duration) || 5);\n        root.style.setProperty(\"--es-bg\", hex(vars.background, \"#f4f4f5\"));\n        document.getElementById(\"es-title\").textContent = vars.title || \"\";\n\n        var names = [vars.layer_1, vars.layer_2, vars.layer_3, vars.layer_4].map(function (n, i) {\n          return String(n || [\"Interface\", \"API gateway\", \"Services\", \"Data\"][i]);\n        });\n        var labels = document.getElementById(\"es-labels\");\n        var leaders = document.getElementById(\"es-leaders\");\n        var svg = \"http://www.w3.org/2000/svg\";\n        names.forEach(function (name, i) {\n          var el = document.createElement(\"div\");\n          el.className = \"es-label\";\n          el.innerHTML = '<span class=\"es-index\">0' + (i + 1) + \"</span><span></span>\";\n          el.lastChild.textContent = name;\n          labels.appendChild(el);\n          var line = document.createElementNS(svg, \"line\");\n          var dot = document.createElementNS(svg, \"circle\");\n          dot.setAttribute(\"r\", \"6\");\n          leaders.appendChild(line);\n          leaders.appendChild(dot);\n        });\n\n        var clock = { t: 0 };\n        var scene = {\n          vars: vars,\n          names: names,\n          duration: duration,\n          clock: clock,\n          hex: hex,\n          render: null,\n        };\n        window.__explodedStack = scene;\n        window.__hf = window.__hf || {};\n        window.__hf.buildReady = window.__hf.buildReady || {};\n        window.__hf.buildReady[\"exploded-stack\"] = new Promise(function (resolve) {\n          scene.ready = resolve;\n        });\n\n        var tl = gsap.timeline({ paused: true });\n        tl.to(clock, {\n          t: duration,\n          duration: duration,\n          ease: \"none\",\n          onUpdate: function () {\n            if (scene.render) scene.render(clock.t);\n          },\n        });\n        window.__timelines = window.__timelines || {};\n        window.__timelines[\"exploded-stack\"] = tl;\n      })();\n    </script>\n\n    <script type=\"module\">\n      import * as THREE from \"https://cdn.jsdelivr.net/npm/[email protected]/+esm\";\n      import { RoundedBoxGeometry } from \"https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/geometries/RoundedBoxGeometry.js/+esm\";\n\n      const host = window.__explodedStack;\n      const V = host.vars;\n      const hex = host.hex;\n      const accent = new THREE.Color(hex(V.accent, \"#0a84ff\"));\n      const D = host.duration;\n\n      const renderer = new THREE.WebGLRenderer({\n        canvas: document.getElementById(\"es-canvas\"),\n        antialias: true,\n        alpha: true,\n        preserveDrawingBuffer: true,\n      });\n      renderer.setPixelRatio(1);\n      renderer.setSize(1920, 1080, false);\n      renderer.outputColorSpace = THREE.SRGBColorSpace;\n\n      const scene = new THREE.Scene();\n      // True isometric: orthographic, 45 degrees around Y, arctan(1/sqrt 2) down.\n      const view = 5.9;\n      const camera = new THREE.OrthographicCamera(\n        (-view * 16) / 9,\n        (view * 16) / 9,\n        view,\n        -view,\n        0.1,\n        100,\n      );\n      camera.position.set(10, 10.7, 10);\n      camera.lookAt(0, 0.7, 0);\n      // Slide along the camera's right axis so the stack sits left and labels get the right.\n      camera.position.add(new THREE.Vector3(1.9, 0, -1.9));\n      camera.updateMatrixWorld();\n\n      scene.add(new THREE.HemisphereLight(0xffffff, 0xd6d9e4, 2.2));\n      const sun = new THREE.DirectionalLight(0xffffff, 1.4);\n      sun.position.set(-4, 10, 6);\n      scene.add(sun);\n\n      const texture = (c) => {\n        const tex = new THREE.CanvasTexture(c);\n        tex.colorSpace = THREE.SRGBColorSpace;\n        tex.anisotropy = renderer.capabilities.getMaxAnisotropy();\n        return tex;\n      };\n      // White face with a hairline where the flat top meets the rounded edge.\n      function faceTexture() {\n        const c = document.createElement(\"canvas\");\n        c.width = c.height = 512;\n        const g = c.getContext(\"2d\");\n        g.fillStyle = \"#ffffff\";\n        g.fillRect(0, 0, 512, 512);\n        g.strokeStyle = \"#d6d8dd\";\n        g.lineWidth = 3;\n        g.strokeRect(1.5, 1.5, 509, 509);\n        return texture(c);\n      }\n      // White glyphs on transparent; the material colour tints them per frame.\n      function glyphTexture(i) {\n        const c = document.createElement(\"canvas\");\n        c.width = c.height = 512;\n        const g = c.getContext(\"2d\");\n        g.strokeStyle = g.fillStyle = \"#ffffff\";\n        g.lineWidth = 6;\n        // Each layer gets its own motif, so the plates read as different systems.\n        if (i === 0) {\n          for (let k = 0; k < 3; k++) g.strokeRect(70 + k * 130, 150, 110, 212);\n        } else if (i === 1) {\n          for (let k = 0; k < 5; k++) {\n            g.beginPath();\n            g.moveTo(80, 110 + k * 72);\n            g.lineTo(432, 110 + k * 72);\n            g.stroke();\n          }\n        } else if (i === 2) {\n          for (let y = 0; y < 3; y++)\n            for (let x = 0; x < 3; x++) g.fillRect(96 + x * 120, 96 + y * 120, 80, 80);\n        } else {\n          for (let k = 0; k < 3; k++) {\n            g.beginPath();\n            g.ellipse(256, 150 + k * 100, 150, 40, 0, 0, Math.PI * 2);\n            g.stroke();\n          }\n        }\n        return texture(c);\n      }\n\n      const LAYERS = 4;\n      const THICK = 0.22;\n      const GAP = 1.55;\n      const edge = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.6 });\n      const shadowCanvas = document.createElement(\"canvas\");\n      shadowCanvas.width = shadowCanvas.height = 256;\n      const sg = shadowCanvas.getContext(\"2d\");\n      const sgrad = sg.createRadialGradient(128, 128, 40, 128, 128, 128);\n      sgrad.addColorStop(0, \"rgba(20,24,40,0.22)\");\n      sgrad.addColorStop(1, \"rgba(20,24,40,0)\");\n      sg.fillStyle = sgrad;\n      sg.fillRect(0, 0, 256, 256);\n      const shadow = new THREE.Mesh(\n        new THREE.PlaneGeometry(7, 7),\n        new THREE.MeshBasicMaterial({\n          map: new THREE.CanvasTexture(shadowCanvas),\n          transparent: true,\n          depthWrite: false,\n        }),\n      );\n      shadow.rotation.x = -Math.PI / 2;\n      shadow.position.y = -2.4;\n      scene.add(shadow);\n      const top = new THREE.MeshStandardMaterial({ map: faceTexture(), roughness: 0.7 });\n      const plates = [];\n      const glyphs = [];\n      for (let i = 0; i < LAYERS; i++) {\n        const plate = new THREE.Mesh(new RoundedBoxGeometry(4.2, THICK, 4.2, 4, 0.08), edge);\n        // 4.04 = the flat top inside the 0.08 rounded edge.\n        const face = new THREE.Mesh(new THREE.PlaneGeometry(4.04, 4.04), top);\n        face.rotation.x = -Math.PI / 2;\n        face.position.y = THICK / 2 + 0.002;\n        const glyph = new THREE.MeshStandardMaterial({\n          map: glyphTexture(i),\n          roughness: 0.7,\n          transparent: true,\n          depthWrite: false,\n        });\n        const motif = new THREE.Mesh(new THREE.PlaneGeometry(4.04, 4.04), glyph);\n        motif.rotation.x = -Math.PI / 2;\n        motif.position.y = THICK / 2 + 0.004;\n        plate.add(face, motif);\n        scene.add(plate);\n        plates.push(plate);\n        glyphs.push(glyph);\n      }\n\n      // Beats in seconds at the 5 s default; another duration scales them.\n      const BASE = 5;\n      const OPEN_AT = 0.3,\n        OPEN_FOR = 0.9,\n        OPEN_STAGGER = 0.06;\n      const LAND_AT = 1.25,\n        LAND_EVERY = 0.7,\n        DRAW = 0.3,\n        FULL = 0.4,\n        SETTLE = 0.3;\n      const CLOSE_AT = LAND_AT + (LAYERS - 1) * LAND_EVERY + 0.7;\n      const CLOSE_FOR = 0.6,\n        CLOSE_STAGGER = 0.05,\n        LIFT = 0.08;\n      const clamp01 = (x) => Math.min(1, Math.max(0, x));\n      const ease = (x) => {\n        const u = clamp01(x);\n        return u < 0.5 ? 4 * u * u * u : 1 - Math.pow(-2 * u + 2, 3) / 2;\n      };\n      const easeOut = (x) => 1 - Math.pow(1 - clamp01(x), 3);\n      // Ease-out with a soft first frame, so the separation reads from OPEN_AT on.\n      const easeOpen = (x) => easeOut(Math.pow(clamp01(x), 1.4));\n      // 0 at rest, 1 from the moment layer i's label lands until FULL later.\n      const focus = (T, i) => {\n        const land = LAND_AT + i * LAND_EVERY;\n        return easeOut((T - land + DRAW) / DRAW) * (1 - ease((T - land - FULL) / SETTLE));\n      };\n      const GLYPH_REST = new THREE.Color(0xc9ccd3);\n      const INK_REST = new THREE.Color(0x8b909a);\n      const ink = new THREE.Color();\n\n      const labelEls = [...document.querySelectorAll(\".es-label\")];\n      const indexEls = [...document.querySelectorAll(\".es-index\")];\n      const lines = [...document.querySelectorAll(\"#es-leaders line\")];\n      const dots = [...document.querySelectorAll(\"#es-leaders circle\")];\n      const anchor = new THREE.Vector3();\n      const toScreen = (v) => {\n        const p = v.clone().project(camera);\n        return [(p.x * 0.5 + 0.5) * 1920, (-p.y * 0.5 + 0.5) * 1080];\n      };\n\n      host.render = (t) => {\n        const T = (t / D) * BASE;\n        for (let i = 0; i < LAYERS; i++) {\n          // Bottom plate stays put; the top plate travels furthest and leaves first.\n          const order = LAYERS - 1 - i;\n          const open =\n            easeOpen((T - OPEN_AT - i * OPEN_STAGGER) / OPEN_FOR) -\n            ease((T - CLOSE_AT - 0.05 - order * CLOSE_STAGGER) / CLOSE_FOR);\n          const w = focus(T, i);\n          const y = order * (THICK + 0.02 + open * GAP) - 2.2 + LIFT * w;\n          plates[i].position.y = y;\n          glyphs[i].color.copy(GLYPH_REST).lerp(accent, w);\n          const inkHex = `#${ink.copy(INK_REST).lerp(accent, w).getHexString()}`;\n          indexEls[i].style.color = inkHex;\n          dots[i].style.fill = inkHex;\n\n          const shown =\n            easeOut((T - LAND_AT - i * LAND_EVERY + DRAW) / DRAW) *\n            (1 - clamp01((T - CLOSE_AT) / 0.2));\n          // The plate's right-hand corner, where a label has open space beside it.\n          anchor.set(2.1, y, -2.1);\n          const [ax, ay] = toScreen(anchor);\n          const lx = ax + 90;\n          labelEls[i].style.opacity = shown.toFixed(3);\n          // Whole pixels: a fractional offset rasterises text differently by frame order.\n          labelEls[i].style.transform =\n            `translate(${Math.round(lx + 24 + (1 - shown) * 16)}px, ${Math.round(ay - 22)}px)`;\n          lines[i].setAttribute(\"x1\", ax.toFixed(1));\n          lines[i].setAttribute(\"y1\", ay.toFixed(1));\n          lines[i].setAttribute(\"x2\", (ax + 90 * shown).toFixed(1));\n          lines[i].setAttribute(\"y2\", ay.toFixed(1));\n          lines[i].style.opacity = shown > 0 ? 1 : 0;\n          dots[i].setAttribute(\"cx\", ax.toFixed(1));\n          dots[i].setAttribute(\"cy\", ay.toFixed(1));\n          dots[i].style.opacity = shown.toFixed(3);\n        }\n        renderer.render(scene, camera);\n      };\n      host.render(host.clock.t);\n      host.ready();\n    </script>\n  </body>\n</html>\n"}