Spaces:
Running on Zero
Running on Zero
Download embed-resize.js from Hayeonbang/PitchIn: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/Hayeonbang/PitchIn/resolve/main/embed-resize.js
- Command line
-
hf download hf://spaces/Hayeonbang/PitchIn/embed-resize.js
-
curl -L -o embed-resize.js https://huggingface.co/spaces/Hayeonbang/PitchIn/resolve/main/embed-resize.js
1.64 kB
| () => { | |
| const allowedParents = new Set([ | |
| "https://hayeonbang.github.io", | |
| "http://127.0.0.1:8765", | |
| "http://localhost:8765" | |
| ]); | |
| let parentOrigin; | |
| try { parentOrigin = new URL(document.referrer).origin; } | |
| catch (_) { return; } | |
| if (window.parent === window || !allowedParents.has(parentOrigin)) return; | |
| // Gradio calls this after mounting; clean up if its app is mounted again. | |
| window.__pitchinEmbedCleanup?.(); | |
| let root; | |
| let timer; | |
| let lastHeight = 0; | |
| const report = () => { | |
| clearTimeout(timer); | |
| timer = setTimeout(() => { | |
| const nextRoot = document.getElementById("component-0"); | |
| if (nextRoot !== root) { | |
| if (root) sizeObserver.unobserve(root); | |
| root = nextRoot; | |
| if (root) sizeObserver.observe(root); | |
| } | |
| if (!root) return; | |
| // Measure content rather than iframe/body height to avoid a resize loop. | |
| const height = Math.ceil(root.getBoundingClientRect().bottom + window.scrollY + 4); | |
| if (height <= 0 || height === lastHeight) return; | |
| lastHeight = height; | |
| window.parent.postMessage({ type: "pitchin-embed-height", height }, parentOrigin); | |
| }, 60); | |
| }; | |
| const sizeObserver = new ResizeObserver(report); | |
| const contentObserver = new MutationObserver(report); | |
| contentObserver.observe(document.body, { childList: true, subtree: true }); | |
| window.addEventListener("resize", report); | |
| document.fonts?.ready.then(report); | |
| window.__pitchinEmbedCleanup = () => { | |
| clearTimeout(timer); | |
| sizeObserver.disconnect(); | |
| contentObserver.disconnect(); | |
| window.removeEventListener("resize", report); | |
| }; | |
| report(); | |
| } | |