{"version":3,"file":"QRCodeGenerator.KF4-SeAI.mjs","names":["useRef","useState","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/R5zJOGROjfodUtklU0BX/1nykNzT5z3SGUwVdyt6z/QRCodeGenerator.js"],"sourcesContent":["// Welcome to Code in Framer\n// Get Started: https://www.framer.com/developers/\nimport{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useEffect,useMemo,useRef,useState}from\"react\";import{apiGetProductDetails,PRODUCT_AR_ROUTE,backToCataloguePage,showHideLoading,isCanvas}from\"https://framerusercontent.com/modules/OOTEhGHcmjgDAX6AjJX8/y9s80vAUFEu1vf5bE7Dh/Products.js\";/**\n * These annotations control how your component sizes\n * Learn more: https://www.framer.com/developers/#code-components-auto-sizing\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export const checkIsMobile=()=>{if(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i))return true;return false;};export default function QRCodeGenerator(props){const btnRef=useRef();const modRef=useRef();const[propData,setPropData]=useState(null);const addQRScript=()=>{const script=document.createElement(\"script\");const scriptId=document.querySelector(\"#product-qr-code\");if(script&&!scriptId){script.id=\"product-qr-code\";script.src=\"https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js\";// script.defer = true\n// script.async = \"true\"\nscript.onload=()=>{generateQRCode();console.log(\"QR script loaded\");};document.head.appendChild(script);}};const removeScript=(id=\"\")=>{if(!id)return;const script=document.querySelector(id);if(script){script.remove();}};const getResponsiveQRSize=()=>{const screenWidth=window.innerWidth;// For Android devices and smaller screens, use a percentage-based approach\nif(screenWidth<=360){return Math.min(screenWidth*.4,120)// 40% of screen width, max 120px\n;}else if(screenWidth<=480){return Math.min(screenWidth*.35,140)// 35% of screen width, max 140px\n;}else if(screenWidth<=768){return 150;}return 180// Default for larger screens\n;};const generateQRCode=()=>{const qrcode=document.querySelectorAll(\".qrCode\");if(qrcode?.length>0){const qrSize=getResponsiveQRSize();for(let i=0;i<qrcode.length;i++){// Clear any existing QR code content\nqrcode[i].innerHTML=\"\";const qr=new QRCode(qrcode[i],{width:qrSize,height:qrSize,correctLevel:QRCode.CorrectLevel.M});const params=new URLSearchParams(window.location.search);const name=params?.get(\"name\")?.replaceAll(\" \",\"__\");const path=window.location.origin+PRODUCT_AR_ROUTE+`?name=${name}`;qr.makeCode(path);console.log(\"DEBUG__props\",props);// Style both canvas and img elements for consistency\nconst canvas=qrcode?.[i]?.querySelector(\"canvas\");const img=qrcode?.[i]?.querySelector(\"img\");if(canvas){canvas.style.maxWidth=\"100%\";canvas.style.height=\"auto\";canvas.style.display=\"block\";canvas.style.margin=\"0 auto\";}if(img){img.style.maxWidth=\"100%\";img.style.width=`${qrSize}px`;img.style.height=\"auto\";img.style.objectFit=\"contain\";img.style.objectPosition=\"center\";img.style.display=\"block\";img.style.margin=\"0 auto\";}}}};const addModelViewerScript=()=>{if(isCanvas())return;const script=document.createElement(\"script\");const scriptId=document.querySelector(\"#product-model-viewer\");if(script&&!scriptId){script.id=\"product-model-viewer\";script.src=\"https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js\";// script.defer = true\n// script.async = true\nscript.type=\"module\";script.onload=()=>{console.log(\"model script loaded\");};document.head.appendChild(script);}};const modelViewer=()=>{return /*#__PURE__*/_jsx(\"model-viewer\",{src:propData?.glb_file+\"#canonicalWebPageURL=https://imagine.io\",\"ios-src\":propData?.usdz_file?propData?.usdz_file+\"#canonicalWebPageURL=https://imagine.io\":\"\",\"ar-modes\":\"webxr quick-look scene-viewer\",id:\"main-frame\",orientation:\"0 0 0 1\",\"camera-controls\":true,ar:true,\"ar-scale\":\"auto\",\"shadow-intensity\":\"1\",ref:modRef,style:{width:\"0\",height:\"0\"},children:/*#__PURE__*/_jsx(\"button\",{slot:\"ar-button\",id:\"ar-button\",ref:btnRef,style:{width:24,height:24,opacity:1}})});};const ModelViewComponent=useMemo(()=>modelViewer(),[btnRef,propData]);useEffect(()=>{addQRScript();addModelViewerScript();},[]);useEffect(()=>{if(!modRef?.current||!checkIsMobile())return;modRef?.current?.addEventListener(\"load\",()=>{showHideLoading({loading:false});console.log(\"Model has finished loading.\");});return()=>{if(!modRef?.current)return;showHideLoading({loading:false});removeScript(\"#product-qr-code\");removeScript(\"#product-model-viewer\");modRef?.current?.removeEventListener(\"load\",()=>{});};},[modRef?.current]);useEffect(()=>{const fetchProduct=async(n=\"\")=>{if(n&&window.location.pathname.includes(PRODUCT_AR_ROUTE)){const _n=n?.replace(/__/g,\" \");showHideLoading({loading:true,transparent:false});const response=await apiGetProductDetails(`name=${_n}`);const result=response?.results?.[0];showHideLoading({loading:false});if(result?.glb_file&&!result?.glb_file?.toLowerCase()?.includes(\".glb\")){alert(\"Invalid model file.\");showHideLoading({loading:false});}else if(result?.glb_file){const canLoadFile=await fetch(result?.glb_file);if(canLoadFile?.ok)setPropData(result);else{alert(\"Unable to load file. Please try again later!\");}showHideLoading({loading:false});}else{alert(\"Product does not found!!!\");backToCataloguePage();}}else{showHideLoading({loading:false});// alert(\"Product does not found!!!\")\n// backToCataloguePage()\n}};const params=new URLSearchParams(window.location.search);if(!isCanvas()&&checkIsMobile())fetchProduct(params?.get(\"name\"));},[]);useEffect(()=>{if(isCanvas()||!propData||!btnRef?.current||!checkIsMobile())return;showHideLoading({loading:true,transparent:false});const timerId=setTimeout(()=>{if(propData&&btnRef?.current){btnRef?.current?.click?.();showHideLoading({loading:true,transparent:false});}},500);return()=>{if(timerId)clearInterval(timerId);};},[propData,btnRef,isCanvas]);return /*#__PURE__*/_jsxs(_Fragment,{children:[propData?ModelViewComponent:null,/*#__PURE__*/_jsx(\"div\",{id:\"qrCode\",className:\"qrCode\",style:{display:\"flex\",alignItems:\"center\",justifyContent:\"center\",width:\"100%\",maxWidth:\"100%\",overflow:\"visible\",boxSizing:\"border-box\"}})]});}// Styles are written in object syntax\n// Learn more: https://reactjs.org/docs/dom-elements.html#style\n\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"QRCodeGenerator\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"checkIsMobile\":{\"type\":\"variable\",\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"yPAQiV,SAAwB,EAAgB,EAAM,CAAC,IAAM,EAAOA,EAAO,EAAQ,EAAOA,EAAO,EAAO,CAAC,EAAS,GAAaC,EAAS,IAAI,EAAQ,MAAgB,CAAC,IAAM,EAAO,SAAS,cAAc,QAAQ,EAAQ,EAAS,SAAS,cAAc,kBAAkB,EAAK,GAAQ,CAAC,IAAU,EAAO,GAAG,kBAAkB,EAAO,IAAI,sEAEnpB,EAAO,WAAW,CAAC,EAAe,EAAE,QAAQ,IAAI,kBAAkB,CAAE,EAAE,SAAS,KAAK,YAAY,CAAM,EAAG,EAAQ,GAAc,EAAG,KAAK,CAAC,GAAG,CAAC,EAAG,OAAO,IAAM,EAAO,SAAS,cAAc,CAAE,EAAK,GAAQ,EAAO,OAAO,CAAG,EAAQ,MAAwB,CAAC,IAAM,EAAY,EAAO,WAG5O,OAFrC,GAAa,IAAY,KAAK,IAAI,EAAY,GAAG,GAAG,EAC7C,GAAa,IAAY,KAAK,IAAI,EAAY,IAAI,GAAG,EACrD,GAAa,IAAY,IAAY,GAC9C,EAAQ,MAAmB,CAAC,IAAM,EAAO,SAAS,iBAAiB,SAAS,EAAE,GAAG,GAAQ,OAAO,EAAE,CAAC,IAAM,EAAO,EAAoB,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,EAAO,OAAO,IAAI,CACvK,EAAO,EAAE,CAAC,UAAU,GAA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