{"version":3,"sources":["../src/components/EmbedResize/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\n\n/**\n * Listens for iframely-style resize messages from embedded iframes and applies\n * the reported height to the matching iframe. This is what lets dynamic-height\n * embeds (tweets, link cards, article readers) size to their content.\n *\n * A cross-origin iframe cannot resize its own frame, so the page showing it\n * must run this listener. Rendering <VenueContent> mounts it automatically, so\n * consumers don't add a script tag or a third-party include — it ships with the\n * SDK. Fixed-ratio embeds (video/audio) don't rely on this; they size via CSS\n * aspect-ratio.\n *\n * Iframes are matched by their content window (event.source), so no id/data\n * attribute is required on the iframe.\n */\n\n// Module-level guard: only one global listener regardless of how many\n// <VenueContent> / <EmbedResize> instances mount.\nlet installed = false;\n\nconst applyResize = (event: MessageEvent) => {\n  const data = event.data;\n  if (!data || typeof data !== \"object\") return;\n\n  // iframely resize protocol: { method: \"resize\", height: <number> }.\n  if (data.method !== \"resize\") return;\n\n  const height = Number(data.height);\n  if (!Number.isFinite(height) || height <= 0) return;\n\n  const iframes = document.querySelectorAll(\"iframe\");\n  for (const iframe of Array.from(iframes)) {\n    if (iframe.contentWindow === event.source) {\n      iframe.style.height = `${Math.round(height)}px`;\n      break;\n    }\n  }\n};\n\nexport const useEmbedResize = () => {\n  useEffect(() => {\n    if (installed || typeof window === \"undefined\") return;\n    installed = true;\n    window.addEventListener(\"message\", applyResize);\n    // Intentionally not removed: a single passive listener is shared across the\n    // app's lifetime and de-duplicated via the module guard.\n  }, []);\n};\n\n/**\n * Component form of {@link useEmbedResize}. Renders nothing. Mounted once by\n * VenueContent; can also be placed in a layout if rendering embeds elsewhere.\n */\nexport const EmbedResize = (): null => {\n  useEmbedResize();\n  return null;\n};\n"],"mappings":"AAEA,OAAS,aAAAA,MAAiB,QAmB1B,IAAIC,EAAY,GAEVC,EAAeC,GAAwB,CAC3C,IAAMC,EAAOD,EAAM,KAInB,GAHI,CAACC,GAAQ,OAAOA,GAAS,UAGzBA,EAAK,SAAW,SAAU,OAE9B,IAAMC,EAAS,OAAOD,EAAK,MAAM,EACjC,GAAI,CAAC,OAAO,SAASC,CAAM,GAAKA,GAAU,EAAG,OAE7C,IAAMC,EAAU,SAAS,iBAAiB,QAAQ,EAClD,QAAWC,KAAU,MAAM,KAAKD,CAAO,EACrC,GAAIC,EAAO,gBAAkBJ,EAAM,OAAQ,CACzCI,EAAO,MAAM,OAAS,GAAG,KAAK,MAAMF,CAAM,CAAC,KAC3C,KACF,CAEJ,EAEaG,EAAiB,IAAM,CAClCR,EAAU,IAAM,CACVC,GAAa,OAAO,OAAW,MACnCA,EAAY,GACZ,OAAO,iBAAiB,UAAWC,CAAW,EAGhD,EAAG,CAAC,CAAC,CACP,EAMaO,EAAc,KACzBD,EAAe,EACR","names":["useEffect","installed","applyResize","event","data","height","iframes","iframe","useEmbedResize","EmbedResize"]}