Skip to content

Write HTML. Render video. Built for agents.

13.3 KB
Raw Blame
{"html":"<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n    <title>World Map</title>\n    <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n    <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin />\n    <link\n      href=\"https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=block\"\n      rel=\"stylesheet\"\n    />\n    <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/topojson-client.min.js\"></script>\n    <style>\n      * {\n        margin: 0;\n        padding: 0;\n        box-sizing: border-box;\n      }\n\n      html,\n      body {\n        margin: 0;\n        width: 1920px;\n        height: 1080px;\n        overflow: hidden;\n        background: #0f172a;\n      }\n\n      #world-map {\n        position: relative;\n        width: 1920px;\n        height: 1080px;\n        background: linear-gradient(145deg, #0f172a 0%, #1e293b 100%);\n        font-family: \"Inter\", sans-serif;\n        color: #f0fdfa;\n        overflow: hidden;\n      }\n\n      #world-map .headline {\n        position: absolute;\n        top: 48px;\n        left: 80px;\n        font-size: 52px;\n        font-weight: 700;\n        letter-spacing: -0.02em;\n        color: #f0fdfa;\n        clip-path: inset(0 100% 0 0);\n      }\n\n      #world-map .subtitle {\n        position: absolute;\n        top: 114px;\n        left: 80px;\n        font-size: 22px;\n        font-weight: 300;\n        color: #94a3b8;\n        opacity: 0;\n      }\n\n      #world-map .map-container {\n        position: absolute;\n        top: 170px;\n        left: 80px;\n        width: 1380px;\n        height: 700px;\n      }\n\n      #world-map .map-container svg {\n        width: 1380px;\n        height: 700px;\n      }\n\n      #world-map .country-path {\n        stroke: #1e293b;\n        stroke-width: 0.6;\n        opacity: 0;\n        cursor: default;\n      }\n\n      #world-map .ocean {\n        fill: none;\n      }\n\n      #world-map .graticule {\n        fill: none;\n        stroke: #1e293b;\n        stroke-width: 0.3;\n        stroke-opacity: 0.4;\n      }\n\n      #world-map .legend-group {\n        position: absolute;\n        bottom: 80px;\n        right: 80px;\n        display: flex;\n        flex-direction: column;\n        align-items: flex-end;\n        gap: 8px;\n        opacity: 0;\n      }\n\n      #world-map .legend-bar {\n        width: 280px;\n        height: 14px;\n        border-radius: 7px;\n      }\n\n      #world-map .legend-labels {\n        display: flex;\n        justify-content: space-between;\n        width: 280px;\n        font-size: 13px;\n        font-weight: 500;\n        color: #94a3b8;\n      }\n\n      #world-map .source {\n        position: absolute;\n        bottom: 36px;\n        left: 80px;\n        font-size: 13px;\n        font-weight: 400;\n        color: #475569;\n        opacity: 0;\n      }\n\n      #world-map .tooltip {\n        position: absolute;\n        pointer-events: none;\n        background: rgba(15, 23, 42, 0.92);\n        border: 1px solid #334155;\n        border-radius: 8px;\n        padding: 10px 16px;\n        font-size: 14px;\n        font-weight: 500;\n        color: #f0fdfa;\n        white-space: nowrap;\n        opacity: 0;\n        transform: translateY(4px);\n        backdrop-filter: blur(8px);\n        z-index: 10;\n      }\n\n      #world-map .tooltip .tt-value {\n        color: #22d3ee;\n        font-weight: 600;\n        margin-left: 6px;\n      }\n    </style>\n  </head>\n  <body>\n    <div\n      id=\"world-map\"\n      data-composition-id=\"world-map\"\n      data-width=\"1920\"\n      data-height=\"1080\"\n      data-start=\"0\"\n      data-duration=\"14\"\n    >\n      <h1 class=\"headline\">Global GDP per Capita</h1>\n      <p class=\"subtitle\">Nominal GDP per capita, 2024 IMF estimates</p>\n\n      <div class=\"map-container\">\n        <svg id=\"world-map-svg\"></svg>\n      </div>\n\n      <div class=\"legend-group\">\n        <div\n          class=\"legend-bar\"\n          style=\"\n            background: linear-gradient(90deg, #064e3b 0%, #0d9488 33%, #22d3ee 66%, #f0fdfa 100%);\n          \"\n        ></div>\n        <div class=\"legend-labels\">\n          <span>Low</span>\n          <span>High</span>\n        </div>\n      </div>\n\n      <p class=\"source\">Source: International Monetary Fund</p>\n\n      <div class=\"tooltip\"></div>\n    </div>\n\n    <script>\n      (function () {\n        /* ── GDP per capita data (2024 IMF estimates, USD) ── */\n        /* Keys are ISO 3166-1 numeric codes as strings (3-digit, zero-padded) */\n        var gdpData = {\n          840: { name: \"United States\", gdp: 85373 },\n          156: { name: \"China\", gdp: 13136 },\n          356: { name: \"India\", gdp: 2731 },\n          276: { name: \"Germany\", gdp: 54291 },\n          826: { name: \"United Kingdom\", gdp: 48913 },\n          250: { name: \"France\", gdp: 44408 },\n          392: { name: \"Japan\", gdp: 33950 },\n          \"076\": { name: \"Brazil\", gdp: 10412 },\n          \"036\": { name: \"Australia\", gdp: 65366 },\n          124: { name: \"Canada\", gdp: 54866 },\n          643: { name: \"Russia\", gdp: 14403 },\n          410: { name: \"South Korea\", gdp: 33147 },\n          484: { name: \"Mexico\", gdp: 13434 },\n          360: { name: \"Indonesia\", gdp: 5108 },\n          566: { name: \"Nigeria\", gdp: 1621 },\n          710: { name: \"South Africa\", gdp: 6190 },\n          818: { name: \"Egypt\", gdp: 4295 },\n          792: { name: \"Turkey\", gdp: 13110 },\n          682: { name: \"Saudi Arabia\", gdp: 32270 },\n          764: { name: \"Thailand\", gdp: 7647 },\n          704: { name: \"Vietnam\", gdp: 4623 },\n          616: { name: \"Poland\", gdp: 22393 },\n          752: { name: \"Sweden\", gdp: 59324 },\n          578: { name: \"Norway\", gdp: 94660 },\n          756: { name: \"Switzerland\", gdp: 105669 },\n          \"032\": { name: \"Argentina\", gdp: 13709 },\n          170: { name: \"Colombia\", gdp: 7230 },\n          404: { name: \"Kenya\", gdp: 2198 },\n          586: { name: \"Pakistan\", gdp: 1658 },\n          \"050\": { name: \"Bangladesh\", gdp: 2688 },\n        };\n\n        /* Top 5 GDP countries for highlight pulse */\n        var top5Codes = [\"756\", \"578\", \"840\", \"036\", \"752\"];\n\n        /* GDP range for color scale */\n        var gdpValues = [];\n        var codes = Object.keys(gdpData);\n        for (var i = 0; i < codes.length; i++) {\n          gdpValues.push(gdpData[codes[i]].gdp);\n        }\n        var minGdp = Math.min.apply(null, gdpValues);\n        var maxGdp = Math.max.apply(null, gdpValues);\n\n        /* Color interpolation: green → teal → cyan → white */\n        var colorStops = [\n          { r: 6, g: 78, b: 59 },\n          { r: 13, g: 148, b: 136 },\n          { r: 34, g: 211, b: 238 },\n          { r: 240, g: 253, b: 250 },\n        ];\n\n        function gdpToColor(value) {\n          var t = (value - minGdp) / (maxGdp - minGdp);\n          t = Math.max(0, Math.min(1, t));\n          var scaledT = t * (colorStops.length - 1);\n          var idx = Math.floor(scaledT);\n          if (idx >= colorStops.length - 1) idx = colorStops.length - 2;\n          var localT = scaledT - idx;\n          var c0 = colorStops[idx];\n          var c1 = colorStops[idx + 1];\n          var r = Math.round(c0.r + (c1.r - c0.r) * localT);\n          var g = Math.round(c0.g + (c1.g - c0.g) * localT);\n          var b = Math.round(c0.b + (c1.b - c0.b) * localT);\n          return \"rgb(\" + r + \",\" + g + \",\" + b + \")\";\n        }\n\n        /* Default fill for countries without data */\n        var defaultFill = \"#1e293b\";\n\n        /* ── Build the map ── */\n        var svg = d3\n          .select(\"#world-map-svg\")\n          .attr(\"viewBox\", \"0 0 1380 700\")\n          .attr(\"preserveAspectRatio\", \"xMidYMid meet\");\n\n        var projection = d3.geoNaturalEarth1().fitSize([1380, 700], { type: \"Sphere\" });\n\n        var pathGenerator = d3.geoPath().projection(projection);\n\n        /* Graticule */\n        var graticule = d3.geoGraticule10();\n        svg.append(\"path\").datum(graticule).attr(\"class\", \"graticule\").attr(\"d\", pathGenerator);\n\n        /* Tooltip element */\n        var tooltipEl = document.querySelector(\"#world-map .tooltip\");\n\n        /* Fetch topology and render countries */\n        d3.json(\"https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json\").then(\n          function (world) {\n            var countries = topojson.feature(world, world.objects.countries).features;\n\n            svg\n              .selectAll(\".country-path\")\n              .data(countries)\n              .enter()\n              .append(\"path\")\n              .attr(\"class\", \"country-path\")\n              .attr(\"d\", pathGenerator)\n              .attr(\"data-country\", function (d) {\n                return String(d.id).padStart(3, \"0\");\n              })\n              .attr(\"fill\", function (d) {\n                var code = String(d.id).padStart(3, \"0\");\n                if (gdpData[code]) {\n                  return gdpToColor(gdpData[code].gdp);\n                }\n                return defaultFill;\n              })\n              .on(\"mouseenter\", function (event, d) {\n                var code = String(d.id).padStart(3, \"0\");\n                if (gdpData[code]) {\n                  var entry = gdpData[code];\n                  tooltipEl.innerHTML =\n                    entry.name +\n                    '<span class=\"tt-value\">$' +\n                    entry.gdp.toLocaleString() +\n                    \"</span>\";\n                  tooltipEl.style.opacity = \"1\";\n                  tooltipEl.style.transform = \"translateY(0)\";\n                }\n              })\n              .on(\"mousemove\", function (event) {\n                var container = document.querySelector(\"#world-map\");\n                var rect = container.getBoundingClientRect();\n                var x = event.clientX - rect.left + 16;\n                var y = event.clientY - rect.top - 40;\n                tooltipEl.style.left = x + \"px\";\n                tooltipEl.style.top = y + \"px\";\n              })\n              .on(\"mouseleave\", function () {\n                tooltipEl.style.opacity = \"0\";\n                tooltipEl.style.transform = \"translateY(4px)\";\n              });\n\n            /* ── GSAP Timeline ── */\n            buildTimeline();\n          },\n        );\n\n        function buildTimeline() {\n          var tl = gsap.timeline({ paused: true });\n\n          /* 0s: Headline clip-path wipe reveal (1s) */\n          tl.to(\n            \"#world-map .headline\",\n            {\n              clipPath: \"inset(0 0% 0 0)\",\n              duration: 1,\n              ease: \"power3.inOut\",\n            },\n            0,\n          );\n\n          /* 0.4s: Subtitle fade in (0.6s) */\n          tl.to(\n            \"#world-map .subtitle\",\n            {\n              opacity: 1,\n              duration: 0.6,\n              ease: \"power2.out\",\n            },\n            0.4,\n          );\n\n          /* 1.0s: Countries stagger reveal */\n          tl.to(\n            \"#world-map .country-path\",\n            {\n              opacity: 1,\n              duration: 0.3,\n              stagger: {\n                each: 0.02,\n                from: \"center\",\n              },\n              ease: \"power1.out\",\n            },\n            1.0,\n          );\n\n          /* 4.0s: Legend fade in */\n          tl.to(\n            \"#world-map .legend-group\",\n            {\n              opacity: 1,\n              duration: 0.6,\n              ease: \"power2.out\",\n            },\n            4.0,\n          );\n\n          /* 4.5s: Source fade in */\n          tl.to(\n            \"#world-map .source\",\n            {\n              opacity: 1,\n              duration: 0.5,\n              ease: \"power2.out\",\n            },\n            4.5,\n          );\n\n          /* 5.0s: Highlight pulse on top 5 GDP countries */\n          for (var i = 0; i < top5Codes.length; i++) {\n            var selector = '#world-map [data-country=\"' + top5Codes[i] + '\"]';\n\n            /* Pulse up: brightness + white stroke */\n            tl.to(\n              selector,\n              {\n                filter: \"brightness(1.5)\",\n                stroke: \"#ffffff\",\n                strokeWidth: 1.8,\n                duration: 0.4,\n                ease: \"power2.out\",\n              },\n              5.0 + i * 0.15,\n            );\n\n            /* Pulse back to normal */\n            tl.to(\n              selector,\n              {\n                filter: \"brightness(1)\",\n                stroke: \"#1e293b\",\n                strokeWidth: 0.6,\n                duration: 0.6,\n                ease: \"power2.inOut\",\n              },\n              5.0 + i * 0.15 + 0.4,\n            );\n          }\n\n          /* Register timeline */\n          if (!window.__timelines) {\n            window.__timelines = {};\n          }\n          window.__timelines[\"world-map\"] = tl;\n        }\n      })();\n    </script>\n  </body>\n</html>\n"}