Skip to content

Write HTML. Render video. Built for agents.

9.6 KB
Raw Blame
{"html":"<!doctype html>\n<html lang=\"en\">\n  <head><base href=\"/public/catalog/items/hw-text-cloud/\">\n    <meta charset=\"utf-8\" />\n    <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n    <style>\n      @font-face {\n        font-family: \"Caveat\";\n        src: url(\"/public/catalog/assets/891951df5e8b5b0f.woff2\") format(\"woff2\");\n        font-weight: 700;\n        font-display: block;\n      }\n      *,\n      *::before,\n      *::after {\n        margin: 0;\n        padding: 0;\n        box-sizing: border-box;\n      }\n      body {\n        background: transparent;\n        overflow: hidden;\n      }\n      #hw-tc-root {\n        /* ---- hw tokens ---- */\n        --hw-font-print: \"Caveat\", cursive;\n        --hw-font-script: \"Caveat\", cursive;\n        --hw-ink: #f4f2ec;\n        --hw-ink-dark: #26241f;\n\n        position: relative;\n        width: 1920px;\n        height: 1080px;\n        overflow: hidden;\n        background: transparent; /* overlays footage */\n        font-family: var(--hw-font-print, \"Caveat\", cursive);\n      }\n      #hw-tc-wrap {\n        position: absolute;\n        pointer-events: none;\n      }\n      #hw-tc-wrap svg {\n        position: absolute;\n        inset: 0;\n        width: 100%;\n        height: 100%;\n        overflow: visible;\n      }\n      #hw-tc-fill {\n        fill: var(--hw-ink);\n        opacity: 0;\n      }\n      #hw-tc-stroke {\n        fill: none;\n        stroke: var(--hw-ink-dark);\n        stroke-width: 4;\n        stroke-linecap: round;\n        stroke-linejoin: round;\n      }\n      #hw-tc-text {\n        position: absolute;\n        display: flex;\n        align-items: center;\n        justify-content: center;\n        text-align: center;\n        font-weight: 700;\n        color: var(--hw-ink-dark);\n        line-height: 1.05;\n      }\n      #hw-tc-text .ch {\n        opacity: 0;\n      }\n    </style>\n  </head>\n  <body>\n    <div\n      id=\"hw-tc-root\"\n      data-composition-id=\"hw-text-cloud\"\n      data-start=\"0\"\n      data-duration=\"6\"\n      data-width=\"1920\"\n      data-height=\"1080\"\n    >\n      <div id=\"hw-tc-wrap\">\n        <svg id=\"hw-tc-svg\">\n          <path id=\"hw-tc-fill\"></path>\n          <path id=\"hw-tc-stroke\"></path>\n        </svg>\n        <div id=\"hw-tc-text\"></div>\n      </div>\n      <div\n        id=\"hw-tc-drv\"\n        class=\"clip\"\n        data-start=\"0\"\n        data-duration=\"6\"\n        data-track-index=\"0\"\n        style=\"position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none\"\n      ></div>\n    </div>\n    <script>\n      (function () {\n        window.__timelines = window.__timelines || {};\n\n        /* ---- published parameters ----\n           Speech bubble with a movable tip (pointable at any subject): wobbled\n           cloud, draw-on outline, paper fill, per-char handwritten text. */\n        var CONFIG = {\n          text: \"what are you looking at?\",\n          x: 620, // wrapper left\n          y: 180, // wrapper top\n          w: 560,\n          h: 300,\n          fontSize: 58,\n          tip: { side: \"bottom-left\", len: 90 }, // \"bottom-left\"|\"bottom-right\"\n          seed: 6,\n          boil: { enabled: true, amp: 1.6, rot: 0.4, frameDrop: 3 },\n          typeCharDelay: 0.03,\n          animationIn: true,\n          animationOut: true,\n        };\n\n        var DUR = 6;\n        function clamp(v, lo, hi) {\n          return Math.min(hi, Math.max(lo, v));\n        }\n        var OUT = clamp(DUR * 0.06, 0.25, 0.6);\n\n        /* hw family runtime */\n        window.hwOnUpdate = function (tl, fn) {\n          if (!tl.__hwRenders) {\n            tl.__hwRenders = [];\n            tl.eventCallback(\"onUpdate\", function () {\n              for (var i = 0; i < tl.__hwRenders.length; i++) tl.__hwRenders[i]();\n            });\n          }\n          tl.__hwRenders.push(fn);\n          fn();\n        };\n        window.hwHash = function (n, seed) {\n          var x = Math.sin(n * 127.1 + (seed || 1) * 311.7) * 43758.5453;\n          return (x - Math.floor(x)) * 2 - 1;\n        };\n        window.hwBoil = function (tl, target, opts) {\n          opts = opts || {};\n          var amp = opts.amp !== undefined ? opts.amp : 1.6;\n          var rot = opts.rot !== undefined ? opts.rot : 0.5;\n          var fps = opts.fps || 30;\n          var drop = opts.frameDrop || 3;\n          var seed = opts.seed || 1;\n          var els = gsap.utils.toArray(target);\n          window.hwOnUpdate(tl, function () {\n            var step = Math.floor((tl.time() * fps) / drop);\n            for (var i = 0; i < els.length; i++) {\n              gsap.set(els[i], {\n                x: window.hwHash(step * 3 + i * 97, seed) * amp,\n                y: window.hwHash(step * 3 + 1 + i * 97, seed) * amp,\n                rotation: (opts.baseRot || 0) + window.hwHash(step * 3 + 2 + i * 97, seed) * rot,\n              });\n            }\n          });\n        };\n\n        /* wobbled cloud with a tail tip */\n        function cloudPath(W, H, tip, seed) {\n          var cx = W / 2,\n            cy = H / 2 - 14,\n            rx = W / 2 - 12,\n            ry = H / 2 - 34;\n          var N = 16,\n            pts = [];\n          for (var i = 0; i < N; i++) {\n            var a = (i / N) * Math.PI * 2;\n            var wr = 1 + window.hwHash(i * 11 + 3, seed) * 0.06;\n            pts.push([cx + Math.cos(a) * rx * wr, cy + Math.sin(a) * ry * wr]);\n          }\n          var mx = (pts[0][0] + pts[N - 1][0]) / 2,\n            my = (pts[0][1] + pts[N - 1][1]) / 2;\n          var d = \"M\" + mx.toFixed(1) + \" \" + my.toFixed(1);\n          for (var j = 0; j < N; j++) {\n            var p = pts[j],\n              q = pts[(j + 1) % N];\n            d +=\n              \" Q\" +\n              p[0].toFixed(1) +\n              \" \" +\n              p[1].toFixed(1) +\n              \" \" +\n              ((p[0] + q[0]) / 2).toFixed(1) +\n              \" \" +\n              ((p[1] + q[1]) / 2).toFixed(1);\n          }\n          d += \"Z\";\n          /* tail */\n          var left = tip.side !== \"bottom-right\";\n          var bx = cx + (left ? -rx * 0.45 : rx * 0.45),\n            by = cy + ry * 0.92;\n          var tx = bx + (left ? -tip.len * 0.5 : tip.len * 0.5),\n            ty = by + tip.len;\n          d +=\n            \" M \" +\n            (bx - 26).toFixed(1) +\n            \" \" +\n            (by - 6).toFixed(1) +\n            \" Q \" +\n            (bx - 8 + window.hwHash(31, seed) * 6).toFixed(1) +\n            \" \" +\n            ((by + ty) / 2).toFixed(1) +\n            \" \" +\n            tx.toFixed(1) +\n            \" \" +\n            ty.toFixed(1) +\n            \" Q \" +\n            (bx + 18).toFixed(1) +\n            \" \" +\n            ((by + ty) / 2).toFixed(1) +\n            \" \" +\n            (bx + 30).toFixed(1) +\n            \" \" +\n            (by - 2).toFixed(1);\n          return d;\n        }\n\n        var wrap = document.getElementById(\"hw-tc-wrap\");\n        wrap.style.left = CONFIG.x + \"px\";\n        wrap.style.top = CONFIG.y + \"px\";\n        wrap.style.width = CONFIG.w + \"px\";\n        wrap.style.height = CONFIG.h + \"px\";\n        var svg = document.getElementById(\"hw-tc-svg\");\n        svg.setAttribute(\"viewBox\", \"0 0 \" + CONFIG.w + \" \" + CONFIG.h);\n        var d = cloudPath(CONFIG.w, CONFIG.h, CONFIG.tip, CONFIG.seed);\n        var fillEl = document.getElementById(\"hw-tc-fill\");\n        var stroke = document.getElementById(\"hw-tc-stroke\");\n        fillEl.setAttribute(\"d\", d);\n        stroke.setAttribute(\"d\", d);\n\n        var text = document.getElementById(\"hw-tc-text\");\n        text.style.left = CONFIG.w * 0.12 + \"px\";\n        text.style.top = CONFIG.h * 0.1 + \"px\";\n        text.style.width = CONFIG.w * 0.76 + \"px\";\n        text.style.height = CONFIG.h * 0.62 + \"px\";\n        text.style.fontSize = CONFIG.fontSize + \"px\";\n        var inner = document.createElement(\"div\");\n        Array.from(CONFIG.text).forEach(function (ch) {\n          var s = document.createElement(\"span\");\n          s.className = \"ch\";\n          s.textContent = ch;\n          inner.appendChild(s);\n        });\n        text.appendChild(inner);\n\n        var tl = gsap.timeline({ paused: true });\n\n        /* draw outline, fade fill, type text */\n        var len = stroke.getTotalLength();\n        gsap.set(stroke, { strokeDasharray: len, strokeDashoffset: len });\n        var t0 = CONFIG.animationIn ? 0.3 : 0;\n        if (CONFIG.animationIn) {\n          tl.to(stroke, { strokeDashoffset: 0, duration: 0.8, ease: \"power2.inOut\" }, t0);\n          tl.to(\"#hw-tc-fill\", { opacity: 0.94, duration: 0.4, ease: \"power2.out\" }, t0 + 0.55);\n        } else {\n          gsap.set(stroke, { strokeDashoffset: 0 });\n          gsap.set(\"#hw-tc-fill\", { opacity: 0.94 });\n        }\n        var chars = text.querySelectorAll(\".ch\");\n        var delay = Math.min(CONFIG.typeCharDelay, 1.8 / Math.max(1, chars.length));\n        tl.to(chars, { opacity: 1, duration: 0.02, stagger: delay, ease: \"none\" }, t0 + 0.9);\n\n        if (CONFIG.boil.enabled) {\n          window.hwBoil(tl, \"#hw-tc-wrap\", {\n            amp: CONFIG.boil.amp,\n            rot: CONFIG.boil.rot,\n            frameDrop: CONFIG.boil.frameDrop,\n            seed: CONFIG.seed,\n          });\n        }\n\n        if (CONFIG.animationOut) {\n          tl.to(wrap, { opacity: 0, duration: OUT, ease: \"power2.in\" }, DUR - OUT - 0.05);\n        }\n        tl.set(\"#hw-tc-root\", { visibility: \"hidden\" }, DUR - 0.02);\n\n        window.__timelines[\"hw-text-cloud\"] = tl;\n      })();\n    </script>\n  </body>\n</html>\n"}