{"version":3,"file":"MobiDataEmbed.DcFeeQf7.mjs","names":["Framer.useLocaleInfo","useMemo","useRef","useState","__esmMin","init_ssg_sandbox_shims","_e","pe","c","init_jsx_runtime","ce","init_npm_react_18_3_1","de","window","useLocaleInfo","init_framer_Bf4_tcb2","addPropertyControls","ControlType","usePageLang","info","choice","inLanguage","next","url","path","lang","MobiDataEmbed","props","loading","lazy","language","target","box","frame","height","setHeight","minHeight","src","setSrc","pageParams","names","name","page","resize","iframe","root","anchor","top","moved","origin","onMessage","data","event","ratio","scrollOffset","still","w","h","fit","observer","titleEn","title","rounded","init_MobiDataEmbed"],"sources":["https:/framerusercontent.com/modules/w5rzQhjjlaoaIGd4D4R8/Cs89fwITQMk39DBQPnT8/MobiDataEmbed.js"],"sourcesContent":["// Mobi.Data embed for Framer. In Framer: Assets → Code → New component, replace\n// everything with this code, then drag the component onto the page and set its width.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useMemo,useRef,useState}from\"react\";import*as Framer from\"framer\";import{addPropertyControls,ControlType}from\"framer\";// The page's language: Framer's localization, unless the panel picks one.\nfunction usePageLang(choice){const info=Framer.useLocaleInfo?.();if(choice===\"pt\"||choice===\"en\")return choice;const code=String(info?.activeLocale?.code??\"pt\").toLowerCase();return code.startsWith(\"en\")?\"en\":\"pt\";}// The embed in that language: Mobi.Data sends `?lang=` on to the same embed at its address\n// in that language (D114), so one URL serves every locale. A URL already in the language\n// goes as it is.\nfunction inLanguage(url,lang){try{const next=new URL(url);const path=next.pathname;const current=path===\"/en\"||path.startsWith(\"/en/\")?\"en\":\"pt\";if(current===lang||!/\\/embed(\\/|$)/.test(path))return url;next.searchParams.set(\"lang\",lang);return next.toString();}catch{return url;}}/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function MobiDataEmbed(props){// Defaults here too: an instance placed before a property existed gets none from\n// Framer, and an undefined offset made the scroll target NaN. One placed while\n// loading was a \"Lazy load\" switch keeps what it had.\nconst{url,title,titleEn=\"\",language=\"auto\",ratio=\"\",minHeight=400,rounded=false,scrollOffset=140,lazy=true,pageParams=\"\"}=props;const loading=props.loading||(lazy?\"lazy\":\"eager\");const lang=usePageLang(language);const target=useMemo(()=>inLanguage(url,lang),[url,lang]);const box=useRef(null);const frame=useRef(null);const[height,setHeight]=useState(minHeight);// The host page's own query values named in pageParams go on to the embed. They are\n// read in the browser, after the first render, so the frame waits for them.\nconst[src,setSrc]=useState(pageParams?null:target);useEffect(()=>{const names=String(pageParams).split(\",\").map(name=>name.trim()).filter(Boolean);if(!names.length)return setSrc(target);try{const next=new URL(target);const page=new URLSearchParams(window.location.search);for(const name of names)if(page.has(name))next.searchParams.set(name,page.get(name));setSrc(next.toString());}catch{setSrc(target);}},[target,pageParams]);// A new height keeps the page where the reader has it: the browser anchors the scroll\n// to something below the frame, so a taller frame would push the reader down. Anchoring\n// is off while the frame resizes, and any shift of the frame's top is scrolled back.\nconst resize=next=>{const iframe=frame.current;if(!iframe||iframe.offsetHeight===next)return setHeight(next);const root=document.documentElement;const anchor=root.style.overflowAnchor;const top=iframe.getBoundingClientRect().top;root.style.overflowAnchor=\"none\";setHeight(next);// Two frames: React draws the new height on its own schedule, after this handler.\nrequestAnimationFrame(()=>requestAnimationFrame(()=>{const moved=iframe.getBoundingClientRect().top-top;if(Math.abs(moved)>1)window.scrollBy(0,moved);root.style.overflowAnchor=anchor;}));};// Indicators and forms: the embed posts its content height, and a form asks to be\n// scrolled into view after sending or with problems to fix.\nuseEffect(()=>{let origin=\"\";try{origin=new URL(url).origin;}catch{return;}const onMessage=event=>{const data=event.data;if(event.origin!==origin||event.source!==frame.current?.contentWindow)return;if(!ratio&&data&&data.type===\"mobidata:height\")resize(Math.ceil(data.height));if(data&&data.type===\"mobidata:top\"){// Answered first, so the form does not scroll the page a second time.\nevent.source.postMessage({type:\"mobidata:scrolled\"},origin);const top=frame.current.getBoundingClientRect().top;if(top>=scrollOffset&&top<window.innerHeight)return;const still=window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;window.scrollTo({top:window.scrollY+top-scrollOffset,behavior:still?\"auto\":\"smooth\"});}};window.addEventListener(\"message\",onMessage);return()=>window.removeEventListener(\"message\",onMessage);},[url,ratio,scrollOffset]);// Maps: the height keeps a ratio to the width, never under the minimum.\nuseEffect(()=>{const[w,h]=String(ratio).split(\"/\").map(Number);if(!box.current||!(w>0&&h>0))return;const fit=()=>setHeight(Math.max(minHeight,Math.round(box.current.clientWidth*h/w)));fit();const observer=new ResizeObserver(fit);observer.observe(box.current);return()=>observer.disconnect();},[ratio,minHeight]);return /*#__PURE__*/_jsx(\"div\",{ref:box,style:{width:\"100%\"},children:/*#__PURE__*/_jsx(\"iframe\",{ref:frame,src:src??undefined,title:lang===\"en\"&&titleEn?titleEn:title,loading:loading===\"auto\"?undefined:loading,allow:\"geolocation; fullscreen\",style:{display:\"block\",width:\"100%\",height,border:0,borderRadius:rounded?20:0,overflow:\"hidden\"}})});}MobiDataEmbed.defaultProps={url:\"https://data.mobie.pt/indicadores/rede-total-disponivel/embed?fluid=1\",title:\"Indicadores da Mobi.e\",titleEn:\"\",language:\"auto\",ratio:\"\",minHeight:400,rounded:false,scrollOffset:140,loading:\"lazy\",pageParams:\"\"};addPropertyControls(MobiDataEmbed,{url:{type:ControlType.String,title:\"URL\"},title:{type:ControlType.String,title:\"Title\"},titleEn:{type:ControlType.String,title:\"Title (EN)\",description:\"The frame's name on English pages. Empty: the Title.\"},language:{type:ControlType.Enum,title:\"Language\",options:[\"auto\",\"pt\",\"en\"],optionTitles:[\"Page\",\"PT\",\"EN\"],description:\"Page follows the site's locale; one URL serves both languages.\"},ratio:{type:ControlType.String,title:\"Ratio (maps)\",placeholder:\"16/10\"},minHeight:{type:ControlType.Number,title:\"Min height\",min:100,max:2e3,unit:\"px\"},rounded:{type:ControlType.Boolean,title:\"Rounded\"},scrollOffset:{type:ControlType.Number,title:\"Scroll offset\",min:0,max:400,unit:\"px\"},loading:{type:ControlType.Enum,title:\"Loading\",options:[\"lazy\",\"eager\",\"auto\"],optionTitles:[\"Lazy\",\"Eager\",\"Off\"],description:\"Eager for a form, chart or map at the top of the page. Off leaves it to the browser.\"},pageParams:{type:ControlType.String,title:\"Page params\",placeholder:\"footerTxt,footerBkg\",description:\"Query values this page's URL passes on to the embed.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MobiDataEmbed\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MobiDataEmbed.map"],"mappings":"A,qNAGA,SAASkB,EAAY,EAAO,CAAC,IAAMC,EAAKnB,IAAuB,EAAgH,OAA3GoB,IAAS,MAAMA,IAAS,KAAYA,EAAkB,OAAOD,GAAM,cAAc,MAAM,IAAI,CAAC,CAAC,YAAwB,CAAC,CAAC,WAAW,IAAI,EAAE,KAAK,IAAK,CAGtN,SAASE,EAAW,EAAI,EAAK,CAAC,GAAG,CAAC,IAAMC,EAAK,IAAI,IAAIC,CAAG,EAAQC,EAAKF,EAAK,SAAoK,OAA7IE,IAAO,OAAOA,EAAK,WAAW,MAAM,EAAE,KAAK,QAAkBC,GAAM,CAAC,gBAAgB,KAAKD,CAAI,EAASD,GAAID,EAAK,aAAa,IAAI,OAAOG,CAAI,EAASH,EAAK,SAAS,EAAE,MAAM,CAAC,OAAOC,CAAI,CAAC,CAGrR,SAAwBG,EAAc,EAAM,CAG/C,GAAK,CAAC,MAAI,QAAM,UAAQ,GAAG,WAAS,OAAO,QAAM,GAAG,YAAU,IAAI,UAAQ,GAAM,eAAa,IAAI,OAAK,GAAK,aAAW,IAAIC,EAAYC,EAAQD,EAAM,UAAUE,EAAK,OAAO,SAAeJ,EAAKP,EAAYY,CAAQ,EAAQC,EAAO9B,MAAYoB,EAAWE,EAAIE,CAAI,EAAE,CA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