shopar-plugin 0.1.1-alpha.0 → 0.1.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function e(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[r[i[i[o]]]][r[i[i[i.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];const g="0.1.1-alpha.0";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${g}/dist`;const w={update:e=>{null!=e&&(v=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>v};function y(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b;const R=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let E,S,C;function A(e){const t=function(e){const t=new S.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,S.ClampToEdgeWrapping,S.ClampToEdgeWrapping,S.LinearFilter,S.LinearFilter,1,S.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=S.EquirectangularReflectionMapping,t.encoding=S.LinearEncoding,t}const P=45,T=45,x=3,I=1.5,M=1,L=.5;let k,D,$,U,N,_,j=!1;const O=0,G=300,q=2e3,W=.05,Q=1/(32*Math.PI);let F,V,H,z=!1,B=1,K=1,X=1;const Z=1;let Y;const J=new Map;function ee(t,n,o){const r=t.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f,m=!1,g=!0,v=!1,w=!1,y=!1,b=0,R=0,M=1,_=1,j=1;const z={threeInit:()=>{m||(te(),i=new V.Scene,a=new V.PerspectiveCamera(25,1,.5),s=new F.OrbitControls(a,t),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new k.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new k.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new k.Group;o.position.y=-.7;const r=new k.PlaneGeometry(P,T).rotateX(Math.PI/2),i=new k.MeshBasicMaterial({map:t.texture,opacity:L,transparent:!0,depthWrite:!1}),a=new k.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new k.Mesh(r);s.visible=!1,o.add(s);const l=new k.OrthographicCamera(-P/2,P/2,T/2,-T/2,0,x);function c(e){s.visible=!0,U.uniforms.tDiffuse.value=t.texture,U.uniforms.h.value=1*e/256,s.material=U,D.setRenderTarget(n),D.render(s,l),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,D.setRenderTarget(t),D.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=$;const o=D.getClearAlpha();D.setClearAlpha(0),D.setRenderTarget(t),D.render(e,l),e.overrideMaterial=null,c(I),c(.4*I),D.setRenderTarget(null),D.setClearAlpha(o),e.background=n}}}(i)),m=!0)},threeParse:(t,n,o)=>e(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>e(this,void 0,void 0,(function*(){var e,o;return S=(e=F).THREE,C=new e.RGBELoader,i.environment=A(n),function(e,t){const{THREE:n}=t;E=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(Y,F),o=t,E.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new V.Box3).setFromObject(e.scene);l.position.y=n.min.y-O,i.add(l),c(),i.traverse((e=>{if(e instanceof V.Mesh){const t=e.material;t.depthWrite=!0,t instanceof V.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(F.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,V.Vector3)),y=!0},threePaused:()=>g,threeResume:()=>{g=!1,Y.setAnimationLoop(ne),t.style.visibility="visible",b=0,R=0},threePause:()=>{g=!0,function(){for(const{threePaused:e}of J.values())if(!e())return!1;return!0}()&&Y.setAnimationLoop(null),t.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>{"ACES"===e?h=V.ACESFilmicToneMapping:"Linear"===e&&(h=V.LinearToneMapping)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},preRender_:e=>{if(!m||g)return;e=performance.now();const t=0!==R?e-R:0;if(R=e,!s.update()){if(w)return;if(y)return void(y=!1);if(null==f&&(f=()=>{y||(w=!0,n.style.visibility="hidden",null!=f&&(s.removeEventListener("change",f),f=null))},s.addEventListener("change",f)),b+=t,!(b>G&&b<=G+q))return o.style.opacity="0",void(b>G+2*q&&(b=0));{n.style.visibility="visible",o.style.opacity="1";const e=b-G,t=2*Math.PI/q*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${W*r*Math.min(M,_)}px)`,s.updateTheta(Q*i)}}v=!0},shouldRender_:()=>!(!m||g)&&v,render_:()=>{const e=Y.toneMapping;null!=h&&(Y.toneMapping=h),Y.setViewport(0,0,t.width,t.height),Y.render(i,a),Y.toneMapping=e,v=!1,null!=r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(H,0,K-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===M&&n===_&&X===j||(t.width=Math.ceil(e*X*Z),t.height=Math.ceil(n*X*Z),M=e,_=n,j=X,v=!0)},target_:t};return J.set(t,z),z}function te(){if(z)return;F=window.ShopAR__THREE,V=F.THREE,H=document.createElement("canvas");var e,t;H.style.position="block",Y=new V.WebGLRenderer({powerPreference:"high-performance",canvas:H,antialias:!0,alpha:!0}),Y.outputEncoding=V.sRGBEncoding,Y.toneMapping=V.ACESFilmicToneMapping,Y.setClearColor(new V.Color(16777215)),e=Y,t=F,j||(k=t.THREE,D=e,$=new k.MeshDepthMaterial,$.userData.darkness={value:M},$.onBeforeCompile=e=>{e.uniforms.darkness=$.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},$.depthTest=!1,$.depthWrite=!1,U=new k.ShaderMaterial(t.HorizontalBlurShader),U.depthTest=!1,N=new k.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,j=!0),oe(),z=!0}function ne(e){oe(),Y.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of J.values())t(e),n()&&o()}function oe(){let e=0,t=0;for(const{target_:n}of J.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=R();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===B&&t===K&&n===X||(B=e,K=t,X=n,Y.setSize(B,K,!1));for(const{updateSize_:e}of J.values())e()}const re={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ie=Object.keys(re);function ae(e){return re[e]}function se(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const le="shopar-error";function ce(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=se("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const de="shopar-control";const ue="shopar-deepar-output";function he(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function pe(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function fe(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function me(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const ge="shopar-main";const ve="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ye||(ye={}));let be=!1;function Re(){be||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),be=!0)}function Ee(){Re();const e=function(){const e=document.createElement("div");e.id=ge;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=ve;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=ue;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const r=function(){const e=document.createElement("canvas");e.id=we;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(r);const i=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),a=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),s=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.pointerEvents="none",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(i,a);e.appendChild(s);const l=function(){const e=se("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),c=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(l);e.appendChild(c);const d=he("shopar-ar-loading-container"),u=pe("shopar-ar-loading-text",ae("loading.ar"));d.appendChild(u);const h=fe("shopar-ar-loading-bar-bg"),p=me("shopar-ar-loading-bar-fg");h.appendChild(p),d.appendChild(h),e.appendChild(d);const f=he("shopar-3d-loading-container"),m=pe("shopar-3d-loading-text",ae("loading.3d"));f.appendChild(m);const g=fe("shopar-3d-loading-bar-bg"),v=me("shopar-3d-loading-bar-fg");g.appendChild(v),f.appendChild(g),e.appendChild(f);const y=function(){const e=document.createElement("div");e.id=le;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=se("4rem",`${w}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(y);const b=function(){const e=document.createElement("div");return e.id=de,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(b);const R=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");b.appendChild(R);const E=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);b.appendChild(E);const S=ce("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);b.append(S);let C,A=ye.None,P=!1,T=!1,x=!1,I=!1;function M(){p.classList.remove("active"),d.style.visibility="hidden"}function L(){v.classList.remove("active"),f.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return s},getThreeTarget:function(){return r},getThreePrompt:function(){return c},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;P=e,T=t,x=n,I=o,C=r,Se(b,P),Se(R,P&&(x||T)&&A===ye.None),Se(E,P&&I&&A===ye.None),Se(S,P&&A!==ye.None),M(),L(),P||""===(i=y).style.display&&Se(i,!1)},getUIState:function(){return A},setUIState:function(e){A=e,A===ye.None?(M(),L(),P&&(Se(y,!1),Se(S,!1),(T||x)&&Se(R,!0),I&&Se(E,!0))):A!==ye.QR&&A!==ye.AR&&A!==ye.Preview||P&&(Se(y,!1),Se(R,!1),Se(E,!1),Se(S,!0))},setDefaultUIActions:function(e,t,n){P&&((T||x)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${w}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(C),R.onclick=e),I&&(E.onclick=t),S.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:M,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:L,showCameraError:function(){P&&Se(y,!0)}}}function Se(e,t){e.style.display=t?"":"none"}const Ce=new Map;function Ae(t){let n=Ce.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Ee()),n);return{getSetupId:()=>t,incrementSetupId_:()=>t++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:t,getQRImage:n}=i();o=function(t,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>e(this,void 0,void 0,(function*(){yield b;const e=`https://apps.deepar.ai/${g.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(e),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,t.style.display=""})),qrPause:()=>e(this,void 0,void 0,(function*(){o=!0,t.style.display="none"}))}}(t(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=ee(e(),t(),n())}return r}}}(),Ce.set(t,n)):n.incrementSetupId_(),n}function Pe(e){for(const t of Ce.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===ye.AR&&r(ye.None)}}let Te;const xe=new Uint8Array(16);function Ie(){if(!Te&&(Te="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Te))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Te(xe)}const Me=[];for(let e=0;e<256;++e)Me.push((e+256).toString(16).slice(1));var Le={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(Le.randomUUID&&!t&&!e)return Le.randomUUID();const o=(e=e||{}).random||(e.rng||Ie)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Me[e[t+0]]+Me[e[t+1]]+Me[e[t+2]]+Me[e[t+3]]+"-"+Me[e[t+4]]+Me[e[t+5]]+"-"+Me[e[t+6]]+Me[e[t+7]]+"-"+Me[e[t+8]]+Me[e[t+9]]+"-"+Me[e[t+10]]+Me[e[t+11]]+Me[e[t+12]]+Me[e[t+13]]+Me[e[t+14]]+Me[e[t+15]]}(o)}const De="qrLaunch",$e="arLaunch",Ue="previewLaunch",Ne="heartbeat";let _e,je,Oe=!1;const Ge=[];function qe(e,t){const n=performance.now(),o=ke();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(Ne,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},Oe?a():Ge.push(a)};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Qe(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const Fe=200,Ve=10;let He,ze,Be,Ke=!1;function Xe(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let Ze,Ye,Je,et,tt=!0,nt=null;const ot=new Set;let rt,it,at,st;function lt(e){e!==Be&&(Be=e,Xe(e),it=null,Ke=!0)}function ct(n){return e(this,void 0,void 0,(function*(){return null==rt&&(rt=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(o=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===o?void 0:o.getUserMedia))throw new t("No camera available!");var o;const r=vt(Je),i=We(r),a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(Je);Ze=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:n||"your_license_key_goes_here",previewElement:et,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}}),Ye=yield Qe(i),yield wt(Ze,Ye,"user"===r),"Glasses"===Je&&(yield ze,function(t,n){e(this,void 0,void 0,(function*(){Ke=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${w}/wasm/mediapipe`,t);const r=[],i=setInterval((()=>e(this,void 0,void 0,(function*(){if(Ke)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Ke)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<Ve)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Fe)}))}(Ye,Ze))})))()),rt}))}function dt(e){e!==Je&&(null!=Ze&&(Ze.shutdown(),Ze=null,rt=null),Je=e)}function ut(e){e!==et&&(et=e,null!=Ze&&Ze.changePreviewElement(et))}function ht(e){nt=e}function pt(e){Ze.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&(e(),yt("Glasses"))},Ze.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),yt("Shoes"))},Ze.callbacks.onWristTracked=t=>{t.detected&&(e(),yt("Watches"))}}function ft(t,n){return e(this,void 0,void 0,(function*(){return null!=it&&at===n||(yield it,it=Ze.switchEffect(t),at=n),it}))}function mt(){return e(this,void 0,void 0,(function*(){if(null!=Ze){if(tt=!1,null==Ye){const e=vt(Je),t=We(e);Ye=yield Qe(t),yield wt(Ze,Ye,"user"===e)}!function(){if(null==nt)return;if(null==Je||ot.has(Je))return;nt.style.visibility="visible",nt.style.opacity="1"}(),Ze.setPaused(tt),et.style.display=""}}))}function gt(){null!=Ze&&(tt=!0,Ze.setPaused(tt),null!=Ye&&null!=Ye.srcObject&&Ye.srcObject instanceof MediaStream&&(Ye.srcObject.getTracks().forEach((e=>e.stop())),Ye=null),function(){if(null==nt)return;nt.style.visibility="hidden",nt.style.opacity="0"}(),Ze.stopCamera(),et.style.display="none")}function vt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function wt(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),r()}))))}}))}))}function yt(e){null!=nt&&(ot.has(e)||(ot.add(e),nt.style.opacity="0"))}function bt(o,r,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield g.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));i+=s;const w=v.byteLength;if(c[l]=Math.min(76,r)*((a>>5)-1),152===c[l]&&(c[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)c[l]^=c[i]<<13,c[l]^=c[i]>>17,c[l]^=c[i]<<5,v[e]=v[e]^c[l];return i^=c[0],i^=c[1],i^=c[2],v}))}function Rt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Et(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const St=["AR","3D"];function Ct(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;Rt(n,"apiKey"),Et(n,"apiKey"),Rt(o,"sku"),Et(o,"sku"),Rt(r,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,n,o){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!o.includes(e))throw new t(`'${n}' must be ${o.join("' or '")}.`)}(i,"initialState",St),null!=a&&Et(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=l&&function(e,n,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new t(`Value for key '${r}' in '${n}' must be a string.`)}}(l,"strings",ie)}function At(n){var o,r;return e(this,void 0,void 0,(function*(){Ct(n);const{apiKey:i,sku:a,targetElement:s,initialState:l}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),w.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(re,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(re[t]=n)}}(n.strings);const c=function(n,o){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a),u=Ae(s),{getSetupId:h,findUI:g,findQR:v,findThree:R}=u,E=h();null==_e&&(je=ke(),_e=y(`${w}/shopar-analytics.js`),_e.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),Ge.forEach((e=>e()))})));const{trackEvent:S,arInteracted:C,previewInteracted:A}=qe(a,i);S("setup",{hostname:window.location.hostname});const P=yield c;S("apiResponse",P);const{category:T,arUrl:x,arKey:I,arPromptEnabled:M,arPromptText:L,arPromptImage:k,previewUrl:D,previewEnvUrl:$,previewToneMapping:U}=P;Pt(h(),E);const N=null!=x&&function(e){return null!=e&&f.includes(e)}(T),j=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),O=N&&function(e){return null!=e&&m.includes(e)}(T),G=j&&O&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==st&&(st=y(`${w}/shopar-platform.js`)),yield st,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),q=N&&!G,W=null!=D;if(Pt(h(),E),G&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),q&&(null==He&&(He=y(`${w}/shopar-deepar.js`)),lt(x),"Glasses"===T&&null==ze&&(ze=y(`${w}/shopar-true-scale.js`))),W){null==_&&(_=y(`${w}/shopar-three.js`));const e=255;bt(D,(new Date).getTime()+e,Math.random()*e),Xe(null!=$?$:`${w}/env/default.hdr`)}const{setTargetElement:Q,getDeepARTarget:F,getDeepARPrompt:V,customizeDeepARPrompt:H,setVisibilityParameters:z,getUIState:B,setUIState:K,setDefaultUIActions:X,startDeepARLoading:Z,stopDeepARLoading:Y,startThreeLoading:J,stopThreeLoading:ee,showCameraError:te}=g();Q(s);z(null==n.defaultUI||n.defaultUI,G,q,W,T),H(null!=L?L:"",null!=k?k:""),function(e,n){const o=e.parentNode;if(null==o)throw new t("Parent node missing.");new MutationObserver((t=>{for(const o of t)for(const t of o.removedNodes)if(t===e)return void n()})).observe(o,{childList:!0})}(s,(()=>{B()!==ye.QR||ne()||ie(),B()!==ye.AR||tt||gt(),B()!==ye.Preview||ce()||ue(),K(ye.None)}));const{qrPaused:ne,qrDraw:oe,qrPause:ie}=v(),{threeInit:ae,threeParse:se,threeLoad:le,threePaused:ce,threeResume:de,threePause:ue,threeSetToneMapping:he,threeSetOnInteracted:pe}=R();let fe=0;if(B()===ye.QR){if(!ne())if(G){S(De);try{yield oe(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ie(),K(ye.None)}else if(B()===ye.AR){if(!tt)if(q){S($e);const e=yield Xe(x);Pt(h(),E),Pe(u),dt(T),ut(F()),ht(M?V():null),yield ft(e,x),pt(C),Pt(h(),E)}else gt(),K(ye.None)}else if(B()===ye.Preview&&!ce())if(W){S(Ue),J();const e=255,t=yield bt(D,(new Date).getTime()+e,Math.random()*e);Pt(h(),E);const n=yield Xe(null!=$?$:`${w}/env/default.hdr`);Pt(h(),E);const o=yield se(t,n,`${D}${$}`);Pt(h(),E),le(o,T),he(null!=U?U:"ACES"),pe(A),ee()}else ue(),K(ye.None);const me=()=>e(this,void 0,void 0,(function*(){if(G){if(B()===ye.QR||B()===ye.AR)throw new t("AR already launched.");try{S(De);const e=++fe;if(B()===ye.Preview&&W&&!ce()&&ue(),K(ye.QR),yield oe(i,a),fe!==e)return;return void Pt(h(),E)}catch(e){const n=e instanceof Error;throw S("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!q)throw new t("Model does not have AR enabled.");if(B()===ye.AR)throw new t("AR already launched.");try{S($e);const e=++fe;B()===ye.Preview&&W&&!ce()&&ue(),Pe(u),K(ye.AR),Z();const t=yield Xe(x);if(fe!==e)return;if(Pt(h(),E),yield He,fe!==e)return;if(Pt(h(),E),gt(),dt(T),ut(F()),ht(M?V():null),yield ct(I),fe!==e)return;if(Pt(h(),E),yield ft(t,x),pt(C),fe!==e)return;if(Pt(h(),E),yield mt(),fe!==e)return;Pt(h(),E)}catch(e){const n=e instanceof Error;throw S("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),te(),gt(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Y()}})),ge=()=>e(this,void 0,void 0,(function*(){if(!W)throw new t("Model does not have 3D enabled.");if(B()===ye.Preview)throw new t("3D already launched.");try{S(Ue);const e=++fe;B()===ye.AR&&(q&&!tt&&gt(),ie()),K(ye.Preview),J();const t=255,n=yield bt(D,(new Date).getTime()+t,Math.random()*t);if(fe!==e)return;Pt(h(),E);const o=yield Xe(null!=$?$:`${w}/env/default.hdr`);if(fe!==e)return;if(Pt(h(),E),yield _,fe!==e)return;if(Pt(h(),E),ae(),fe!==e)return;Pt(h(),E);const r=yield se(n,o,`${D}${$}`);if(fe!==e)return;Pt(h(),E),le(r,T),he(null!=U?U:"ACES"),pe(A),de()}catch(e){const n=e instanceof Error;throw S("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{ee()}})),ve=()=>e(this,void 0,void 0,(function*(){if(B()===ye.None)throw new t("Neither AR or 3D launched.");++fe,B()===ye.QR||B()===ye.AR?(q&&!tt&&gt(),ie()):B()===ye.Preview&&W&&!ce()&&ue(),K(ye.None)}));return X(me,ge,ve),"AR"===l?(yield me(),Pt(h(),E)):"3D"===l&&(yield ge(),Pt(h(),E)),{launchAR:N?me:void 0,launch3D:W?ge:void 0,closeAR:N?()=>e(this,void 0,void 0,(function*(){if(B()!==ye.AR&&B()!==ye.QR)throw new t("AR not launched.");++fe,q&&!tt&&gt(),ie(),K(ye.None)})):void 0,close3D:W?()=>e(this,void 0,void 0,(function*(){if(B()!==ye.Preview)throw new t("3D not launched.");++fe,W&&!ce()&&ue(),K(ye.None)})):void 0,close:N||W?ve:void 0}}))}function Pt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Tt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>At(n)))}))},version:g};export{Tt as plugin};
1
+ function e(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[r[i[i[o]]]][r[i[i[i.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];const g="0.1.1-alpha.1";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${g}/dist`;const w={update:e=>{null!=e&&(v=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>v};function y(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b;const R=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let S,E,C;function A(e){const t=function(e){const t=new E.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,E.ClampToEdgeWrapping,E.ClampToEdgeWrapping,E.LinearFilter,E.LinearFilter,1,E.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=E.EquirectangularReflectionMapping,t.colorSpace=E.LinearSRGBColorSpace,t}const P=45,T=45,x=3,I=1.5,M=1,L=.5;let k,$,D,U,N,_,j=!1;const O=0,G=300,q=2e3,W=.05,F=1/(32*Math.PI);let Q,V,H,B=!1,z=1,K=1,X=1;const Z=1;let Y;const J=new Map;function ee(t,n,o){const r=t.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,R=1,M=1,_=1;const j={threeInit:()=>{f||(te(),i=new V.Scene,a=new V.PerspectiveCamera(25,1,.5),s=new Q.OrbitControls(a,t),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new k.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new k.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new k.Group;o.position.y=-.7;const r=new k.PlaneGeometry(P,T).rotateX(Math.PI/2),i=new k.MeshBasicMaterial({map:t.texture,opacity:L,transparent:!0,depthWrite:!1}),a=new k.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new k.Mesh(r);s.visible=!1,o.add(s);const l=new k.OrthographicCamera(-P/2,P/2,T/2,-T/2,0,x);function c(e){s.visible=!0,U.uniforms.tDiffuse.value=t.texture,U.uniforms.h.value=1*e/256,s.material=U,$.setRenderTarget(n),$.render(s,l),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,$.setRenderTarget(t),$.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=D;const o=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(I),c(.4*I),$.setRenderTarget(null),$.setClearAlpha(o),e.background=n}}}(i)),f=!0)},threeParse:(t,n,o)=>e(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>e(this,void 0,void 0,(function*(){var e,o;return E=(e=Q).THREE,C=new e.RGBELoader,i.environment=A(n),function(e,t){const{THREE:n}=t;S=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(Y,Q),o=t,S.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new V.Box3).setFromObject(e.scene);l.position.y=n.min.y-O,i.add(l),c(),i.traverse((e=>{if(e instanceof V.Mesh){const t=e.material;t.depthWrite=!0,t instanceof V.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(Q.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,V.Vector3)),w=!0},threePaused:()=>m,threeResume:()=>{m=!1,Y.setAnimationLoop(ne),t.style.visibility="visible",y=0,b=0},threePause:()=>{m=!0,function(){for(const{threePaused:e}of J.values())if(!e())return!1;return!0}()&&Y.setAnimationLoop(null),t.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>({ACES:V.ACESFilmicToneMapping,Linear:V.LinearToneMapping,Neutral:V.NeutralToneMapping}[e||"ACES"]||V.ACESFilmicToneMapping),threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},preRender_:e=>{if(!f||m)return;e=performance.now();const t=0!==b?e-b:0;if(b=e,!s.update()){if(v)return;if(w)return void(w=!1);if(null==p&&(p=()=>{w||(v=!0,n.style.visibility="hidden",null!=p&&(s.removeEventListener("change",p),p=null))},s.addEventListener("change",p)),y+=t,!(y>G&&y<=G+q))return o.style.opacity="0",void(y>G+2*q&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-G,t=2*Math.PI/q*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${W*r*Math.min(R,M)}px)`,s.updateTheta(F*i)}}g=!0},shouldRender_:()=>!(!f||m)&&g,render_:()=>{const e=Y.toneMapping;Y.setViewport(0,0,t.width,t.height),Y.render(i,a),Y.toneMapping=e,g=!1,null!=r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(H,0,K-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===R&&n===M&&X===_||(t.width=Math.ceil(e*X*Z),t.height=Math.ceil(n*X*Z),R=e,M=n,_=X,g=!0)},target_:t};return J.set(t,j),j}function te(){if(B)return;Q=window.ShopAR__THREE,V=Q.THREE,H=document.createElement("canvas");var e,t;H.style.position="block",Y=new V.WebGLRenderer({powerPreference:"high-performance",canvas:H,antialias:!0,alpha:!0}),Y.outputColorSpace=V.SRGBColorSpace,Y.toneMapping=V.ACESFilmicToneMapping,Y.setClearColor(new V.Color(16777215)),e=Y,t=Q,j||(k=t.THREE,$=e,D=new k.MeshDepthMaterial,D.userData.darkness={value:M},D.onBeforeCompile=e=>{e.uniforms.darkness=D.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},D.depthTest=!1,D.depthWrite=!1,U=new k.ShaderMaterial(t.HorizontalBlurShader),U.depthTest=!1,N=new k.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,j=!0),oe(),B=!0}function ne(e){oe(),Y.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of J.values())t(e),n()&&o()}function oe(){let e=0,t=0;for(const{target_:n}of J.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=R();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===z&&t===K&&n===X||(z=e,K=t,X=n,Y.setSize(z,K,!1));for(const{updateSize_:e}of J.values())e()}const re={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ie=Object.keys(re);function ae(e){return re[e]}function se(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const le="shopar-error";function ce(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=se("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const de="shopar-control";const ue="shopar-deepar-output";function he(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function pe(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function fe(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function me(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const ge="shopar-main";const ve="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ye||(ye={}));let be=!1;function Re(){be||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),be=!0)}function Se(){Re();const e=function(){const e=document.createElement("div");e.id=ge;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=ve;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=ue;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const r=function(){const e=document.createElement("canvas");e.id=we;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(r);const i=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),a=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),s=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.pointerEvents="none",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(i,a);e.appendChild(s);const l=function(){const e=se("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),c=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(l);e.appendChild(c);const d=he("shopar-ar-loading-container"),u=pe("shopar-ar-loading-text",ae("loading.ar"));d.appendChild(u);const h=fe("shopar-ar-loading-bar-bg"),p=me("shopar-ar-loading-bar-fg");h.appendChild(p),d.appendChild(h),e.appendChild(d);const f=he("shopar-3d-loading-container"),m=pe("shopar-3d-loading-text",ae("loading.3d"));f.appendChild(m);const g=fe("shopar-3d-loading-bar-bg"),v=me("shopar-3d-loading-bar-fg");g.appendChild(v),f.appendChild(g),e.appendChild(f);const y=function(){const e=document.createElement("div");e.id=le;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=se("4rem",`${w}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(y);const b=function(){const e=document.createElement("div");return e.id=de,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(b);const R=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");b.appendChild(R);const S=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);b.appendChild(S);const E=ce("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);b.append(E);let C,A=ye.None,P=!1,T=!1,x=!1,I=!1;function M(){p.classList.remove("active"),d.style.visibility="hidden"}function L(){v.classList.remove("active"),f.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return s},getThreeTarget:function(){return r},getThreePrompt:function(){return c},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;P=e,T=t,x=n,I=o,C=r,Ee(b,P),Ee(R,P&&(x||T)&&A===ye.None),Ee(S,P&&I&&A===ye.None),Ee(E,P&&A!==ye.None),M(),L(),P||""===(i=y).style.display&&Ee(i,!1)},getUIState:function(){return A},setUIState:function(e){A=e,A===ye.None?(M(),L(),P&&(Ee(y,!1),Ee(E,!1),(T||x)&&Ee(R,!0),I&&Ee(S,!0))):A!==ye.QR&&A!==ye.AR&&A!==ye.Preview||P&&(Ee(y,!1),Ee(R,!1),Ee(S,!1),Ee(E,!0))},setDefaultUIActions:function(e,t,n){P&&((T||x)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${w}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(C),R.onclick=e),I&&(S.onclick=t),E.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:M,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:L,showCameraError:function(){P&&Ee(y,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Ce=new Map;function Ae(t){let n=Ce.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Se()),n);return{getSetupId:()=>t,incrementSetupId_:()=>t++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:t,getQRImage:n}=i();o=function(t,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>e(this,void 0,void 0,(function*(){yield b;const e=`https://apps.deepar.ai/${g.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(e),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,t.style.display=""})),qrPause:()=>e(this,void 0,void 0,(function*(){o=!0,t.style.display="none"}))}}(t(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=ee(e(),t(),n())}return r}}}(),Ce.set(t,n)):n.incrementSetupId_(),n}function Pe(e){for(const t of Ce.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===ye.AR&&r(ye.None)}}let Te;const xe=new Uint8Array(16);function Ie(){if(!Te&&(Te="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Te))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Te(xe)}const Me=[];for(let e=0;e<256;++e)Me.push((e+256).toString(16).slice(1));var Le={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(Le.randomUUID&&!t&&!e)return Le.randomUUID();const o=(e=e||{}).random||(e.rng||Ie)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Me[e[t+0]]+Me[e[t+1]]+Me[e[t+2]]+Me[e[t+3]]+"-"+Me[e[t+4]]+Me[e[t+5]]+"-"+Me[e[t+6]]+Me[e[t+7]]+"-"+Me[e[t+8]]+Me[e[t+9]]+"-"+Me[e[t+10]]+Me[e[t+11]]+Me[e[t+12]]+Me[e[t+13]]+Me[e[t+14]]+Me[e[t+15]]}(o)}const $e="qrLaunch",De="arLaunch",Ue="previewLaunch",Ne="heartbeat";let _e,je,Oe=!1;const Ge=[];function qe(e,t){const n=performance.now(),o=ke();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(Ne,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},Oe?a():Ge.push(a)};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Fe(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const Qe=200,Ve=10;let He,Be,ze,Ke=!1;function Xe(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let Ze,Ye,Je,et,tt=!0,nt=null;const ot=new Set;let rt,it,at,st;function lt(e){e!==ze&&(ze=e,Xe(e),it=null,Ke=!0)}function ct(n){return e(this,void 0,void 0,(function*(){return null==rt&&(rt=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(o=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===o?void 0:o.getUserMedia))throw new t("No camera available!");var o;const r=vt(Je),i=We(r),a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(Je);Ze=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:n||"your_license_key_goes_here",previewElement:et,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}}),Ye=yield Fe(i),yield wt(Ze,Ye,"user"===r),"Glasses"===Je&&(yield Be,function(t,n){e(this,void 0,void 0,(function*(){Ke=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${w}/wasm/mediapipe`,t);const r=[],i=setInterval((()=>e(this,void 0,void 0,(function*(){if(Ke)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Ke)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<Ve)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Qe)}))}(Ye,Ze))})))()),rt}))}function dt(e){e!==Je&&(null!=Ze&&(Ze.shutdown(),Ze=null,rt=null),Je=e)}function ut(e){e!==et&&(et=e,null!=Ze&&Ze.changePreviewElement(et))}function ht(e){nt=e}function pt(e){Ze.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&(e(),yt("Glasses"))},Ze.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),yt("Shoes"))},Ze.callbacks.onWristTracked=t=>{t.detected&&(e(),yt("Watches"))}}function ft(t,n){return e(this,void 0,void 0,(function*(){return null!=it&&at===n||(yield it,it=Ze.switchEffect(t),at=n),it}))}function mt(){return e(this,void 0,void 0,(function*(){if(null!=Ze){if(tt=!1,null==Ye){const e=vt(Je),t=We(e);Ye=yield Fe(t),yield wt(Ze,Ye,"user"===e)}!function(){if(null==nt)return;if(null==Je||ot.has(Je))return;nt.style.visibility="visible",nt.style.opacity="1"}(),Ze.setPaused(tt),et.style.display=""}}))}function gt(){null!=Ze&&(tt=!0,Ze.setPaused(tt),null!=Ye&&null!=Ye.srcObject&&Ye.srcObject instanceof MediaStream&&(Ye.srcObject.getTracks().forEach((e=>e.stop())),Ye=null),function(){if(null==nt)return;nt.style.visibility="hidden",nt.style.opacity="0"}(),Ze.stopCamera(),et.style.display="none")}function vt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function wt(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),r()}))))}}))}))}function yt(e){null!=nt&&(ot.has(e)||(ot.add(e),nt.style.opacity="0"))}function bt(o,r,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield g.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));i+=s;const w=v.byteLength;if(c[l]=Math.min(76,r)*((a>>5)-1),152===c[l]&&(c[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)c[l]^=c[i]<<13,c[l]^=c[i]>>17,c[l]^=c[i]<<5,v[e]=v[e]^c[l];return i^=c[0],i^=c[1],i^=c[2],v}))}function Rt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function St(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const Et=["AR","3D"];function Ct(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;Rt(n,"apiKey"),St(n,"apiKey"),Rt(o,"sku"),St(o,"sku"),Rt(r,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,n,o){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!o.includes(e))throw new t(`'${n}' must be ${o.join("' or '")}.`)}(i,"initialState",Et),null!=a&&St(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=l&&function(e,n,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new t(`Value for key '${r}' in '${n}' must be a string.`)}}(l,"strings",ie)}function At(n){var o,r;return e(this,void 0,void 0,(function*(){Ct(n);const{apiKey:i,sku:a,targetElement:s,initialState:l}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),w.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(re,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(re[t]=n)}}(n.strings);const c=function(n,o){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a),u=Ae(s),{getSetupId:h,findUI:g,findQR:v,findThree:R}=u,S=h();null==_e&&(je=ke(),_e=y(`${w}/shopar-analytics.js`),_e.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),Ge.forEach((e=>e()))})));const{trackEvent:E,arInteracted:C,previewInteracted:A}=qe(a,i);E("setup",{hostname:window.location.hostname});const P=yield c;E("apiResponse",P);const{category:T,arUrl:x,arKey:I,arPromptEnabled:M,arPromptText:L,arPromptImage:k,previewUrl:$,previewEnvUrl:D,previewToneMapping:U}=P;Pt(h(),S);const N=null!=x&&function(e){return null!=e&&f.includes(e)}(T),j=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),O=N&&function(e){return null!=e&&m.includes(e)}(T),G=j&&O&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==st&&(st=y(`${w}/shopar-platform.js`)),yield st,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),q=N&&!G,W=null!=$;if(Pt(h(),S),G&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),q&&(null==He&&(He=y(`${w}/shopar-deepar.js`)),lt(x),"Glasses"===T&&null==Be&&(Be=y(`${w}/shopar-true-scale.js`))),W){null==_&&(_=y(`${w}/shopar-three.js`));const e=255;bt($,(new Date).getTime()+e,Math.random()*e),Xe(null!=D?D:`${w}/env/default.hdr`)}const{setTargetElement:F,getDeepARTarget:Q,getDeepARPrompt:V,customizeDeepARPrompt:H,setVisibilityParameters:B,getUIState:z,setUIState:K,setDefaultUIActions:X,startDeepARLoading:Z,stopDeepARLoading:Y,startThreeLoading:J,stopThreeLoading:ee,showCameraError:te}=g();F(s);B(null==n.defaultUI||n.defaultUI,G,q,W,T),H(null!=L?L:"",null!=k?k:""),function(e,n){const o=e.parentNode;if(null==o)throw new t("Parent node missing.");new MutationObserver((t=>{for(const o of t)for(const t of o.removedNodes)if(t===e)return void n()})).observe(o,{childList:!0})}(s,(()=>{z()!==ye.QR||ne()||ie(),z()!==ye.AR||tt||gt(),z()!==ye.Preview||ce()||ue(),K(ye.None)}));const{qrPaused:ne,qrDraw:oe,qrPause:ie}=v(),{threeInit:ae,threeParse:se,threeLoad:le,threePaused:ce,threeResume:de,threePause:ue,threeSetToneMapping:he,threeSetOnInteracted:pe}=R();let fe=0;if(z()===ye.QR){if(!ne())if(G){E($e);try{yield oe(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ie(),K(ye.None)}else if(z()===ye.AR){if(!tt)if(q){E(De);const e=yield Xe(x);Pt(h(),S),Pe(u),dt(T),ut(Q()),ht(M?V():null),yield ft(e,x),pt(C),Pt(h(),S)}else gt(),K(ye.None)}else if(z()===ye.Preview&&!ce())if(W){E(Ue),J();const e=255,t=yield bt($,(new Date).getTime()+e,Math.random()*e);Pt(h(),S);const n=yield Xe(null!=D?D:`${w}/env/default.hdr`);Pt(h(),S);const o=yield se(t,n,`${$}${D}`);Pt(h(),S),le(o,T),he(null!=U?U:"ACES"),pe(A),ee()}else ue(),K(ye.None);const me=()=>e(this,void 0,void 0,(function*(){if(G){if(z()===ye.QR||z()===ye.AR)throw new t("AR already launched.");try{E($e);const e=++fe;if(z()===ye.Preview&&W&&!ce()&&ue(),K(ye.QR),yield oe(i,a),fe!==e)return;return void Pt(h(),S)}catch(e){const n=e instanceof Error;throw E("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!q)throw new t("Model does not have AR enabled.");if(z()===ye.AR)throw new t("AR already launched.");try{E(De);const e=++fe;z()===ye.Preview&&W&&!ce()&&ue(),Pe(u),K(ye.AR),Z();const t=yield Xe(x);if(fe!==e)return;if(Pt(h(),S),yield He,fe!==e)return;if(Pt(h(),S),gt(),dt(T),ut(Q()),ht(M?V():null),yield ct(I),fe!==e)return;if(Pt(h(),S),yield ft(t,x),pt(C),fe!==e)return;if(Pt(h(),S),yield mt(),fe!==e)return;Pt(h(),S)}catch(e){const n=e instanceof Error;throw E("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),te(),gt(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Y()}})),ge=()=>e(this,void 0,void 0,(function*(){if(!W)throw new t("Model does not have 3D enabled.");if(z()===ye.Preview)throw new t("3D already launched.");try{E(Ue);const e=++fe;z()===ye.AR&&(q&&!tt&&gt(),ie()),K(ye.Preview),J();const t=255,n=yield bt($,(new Date).getTime()+t,Math.random()*t);if(fe!==e)return;Pt(h(),S);const o=yield Xe(null!=D?D:`${w}/env/default.hdr`);if(fe!==e)return;if(Pt(h(),S),yield _,fe!==e)return;if(Pt(h(),S),ae(),fe!==e)return;Pt(h(),S);const r=yield se(n,o,`${$}${D}`);if(fe!==e)return;Pt(h(),S),le(r,T),he(null!=U?U:"ACES"),pe(A),de()}catch(e){const n=e instanceof Error;throw E("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{ee()}})),ve=()=>e(this,void 0,void 0,(function*(){if(z()===ye.None)throw new t("Neither AR or 3D launched.");++fe,z()===ye.QR||z()===ye.AR?(q&&!tt&&gt(),ie()):z()===ye.Preview&&W&&!ce()&&ue(),K(ye.None)}));return X(me,ge,ve),"AR"===l?(yield me(),Pt(h(),S)):"3D"===l&&(yield ge(),Pt(h(),S)),{launchAR:N?me:void 0,launch3D:W?ge:void 0,closeAR:N?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.AR&&z()!==ye.QR)throw new t("AR not launched.");++fe,q&&!tt&&gt(),ie(),K(ye.None)})):void 0,close3D:W?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.Preview)throw new t("3D not launched.");++fe,W&&!ce()&&ue(),K(ye.None)})):void 0,close:N||W?ve:void 0}}))}function Pt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Tt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>At(n)))}))},version:g};export{Tt as plugin};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(r),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const m=["Glasses","Shoes","Watches"],g=["Shoes"];const v="0.1.1-alpha.0";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let R;const E=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let S,A,C;function P(e){const t=function(e){const t=new A.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,A.ClampToEdgeWrapping,A.ClampToEdgeWrapping,A.LinearFilter,A.LinearFilter,1,A.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=A.EquirectangularReflectionMapping,t.encoding=A.LinearEncoding,t}const T=45,x=45,I=3,M=1.5,L=1,k=.5;let D,$,U,N,_,j,O=!1;const G=0,q=300,W=2e3,Q=.05,F=1/(32*Math.PI);let V,H,z,B=!1,K=1,X=1,Z=1;const Y=1;let J;const ee=new Map;function te(e,n,o){const r=e.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f,m=!1,g=!0,v=!1,w=!1,y=!1,b=0,R=0,E=1,L=1,j=1;const O={threeInit:()=>{m||(ne(),i=new H.Scene,a=new H.PerspectiveCamera(25,1,.5),s=new V.OrbitControls(a,e),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new D.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new D.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new D.Group;o.position.y=-.7;const r=new D.PlaneGeometry(T,x).rotateX(Math.PI/2),i=new D.MeshBasicMaterial({map:t.texture,opacity:k,transparent:!0,depthWrite:!1}),a=new D.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new D.Mesh(r);s.visible=!1,o.add(s);const l=new D.OrthographicCamera(-T/2,T/2,x/2,-x/2,0,I);function c(e){s.visible=!0,N.uniforms.tDiffuse.value=t.texture,N.uniforms.h.value=1*e/256,s.material=N,$.setRenderTarget(n),$.render(s,l),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,$.setRenderTarget(t),$.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=U;const o=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(M),c(.4*M),$.setRenderTarget(null),$.setClearAlpha(o),e.background=n}}}(i)),m=!0)},threeParse:(e,n,o)=>t(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>t(this,void 0,void 0,(function*(){var t,o;return A=(t=V).THREE,C=new t.RGBELoader,i.environment=P(n),function(e,t){const{THREE:n}=t;S=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(J,V),o=e,S.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new H.Box3).setFromObject(e.scene);l.position.y=n.min.y-G,i.add(l),c(),i.traverse((e=>{if(e instanceof H.Mesh){const t=e.material;t.depthWrite=!0,t instanceof H.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(V.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,H.Vector3)),y=!0},threePaused:()=>g,threeResume:()=>{g=!1,J.setAnimationLoop(oe),e.style.visibility="visible",b=0,R=0},threePause:()=>{g=!0,function(){for(const{threePaused:e}of ee.values())if(!e())return!1;return!0}()&&J.setAnimationLoop(null),e.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>{"ACES"===e?h=H.ACESFilmicToneMapping:"Linear"===e&&(h=H.LinearToneMapping)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},preRender_:e=>{if(!m||g)return;e=performance.now();const t=0!==R?e-R:0;if(R=e,!s.update()){if(w)return;if(y)return void(y=!1);if(null==f&&(f=()=>{y||(w=!0,n.style.visibility="hidden",null!=f&&(s.removeEventListener("change",f),f=null))},s.addEventListener("change",f)),b+=t,!(b>q&&b<=q+W))return o.style.opacity="0",void(b>q+2*W&&(b=0));{n.style.visibility="visible",o.style.opacity="1";const e=b-q,t=2*Math.PI/W*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${Q*r*Math.min(E,L)}px)`,s.updateTheta(F*i)}}v=!0},shouldRender_:()=>!(!m||g)&&v,render_:()=>{const t=J.toneMapping;null!=h&&(J.toneMapping=h),J.setViewport(0,0,e.width,e.height),J.render(i,a),J.toneMapping=t,v=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),r.drawImage(z,0,X-e.height,e.width,e.height,0,0,e.width,e.height))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===E&&n===L&&Z===j||(e.width=Math.ceil(t*Z*Y),e.height=Math.ceil(n*Z*Y),E=t,L=n,j=Z,v=!0)},target_:e};return ee.set(e,O),O}function ne(){if(B)return;V=window.ShopAR__THREE,H=V.THREE,z=document.createElement("canvas");var e,t;z.style.position="block",J=new H.WebGLRenderer({powerPreference:"high-performance",canvas:z,antialias:!0,alpha:!0}),J.outputEncoding=H.sRGBEncoding,J.toneMapping=H.ACESFilmicToneMapping,J.setClearColor(new H.Color(16777215)),e=J,t=V,O||(D=t.THREE,$=e,U=new D.MeshDepthMaterial,U.userData.darkness={value:L},U.onBeforeCompile=e=>{e.uniforms.darkness=U.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},U.depthTest=!1,U.depthWrite=!1,N=new D.ShaderMaterial(t.HorizontalBlurShader),N.depthTest=!1,_=new D.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,O=!0),re(),B=!0}function oe(e){re(),J.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of ee.values())t(e),n()&&o()}function re(){let e=0,t=0;for(const{target_:n}of ee.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=E();e=Math.ceil(e*n*Y),t=Math.ceil(t*n*Y),e===K&&t===X&&n===Z||(K=e,X=t,Z=n,J.setSize(K,X,!1));for(const{updateSize_:e}of ee.values())e()}const ie={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ae=Object.keys(ie);function se(e){return ie[e]}function le(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ce="shopar-error";function de(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=le("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const ue="shopar-control";const he="shopar-deepar-output";function pe(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function fe(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function me(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function ge(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const ve="shopar-main";const we="shopar-qr-output";const ye="shopar-three-output";var be;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(be||(be={}));let Re=!1;function Ee(){Re||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),Re=!0)}function Se(){Ee();const e=function(){const e=document.createElement("div");e.id=ve;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=we;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=he;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const r=function(){const e=document.createElement("canvas");e.id=ye;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(r);const i=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),a=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),s=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.pointerEvents="none",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(i,a);e.appendChild(s);const l=function(){const e=le("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),c=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(l);e.appendChild(c);const d=pe("shopar-ar-loading-container"),u=fe("shopar-ar-loading-text",se("loading.ar"));d.appendChild(u);const h=me("shopar-ar-loading-bar-bg"),p=ge("shopar-ar-loading-bar-fg");h.appendChild(p),d.appendChild(h),e.appendChild(d);const f=pe("shopar-3d-loading-container"),m=fe("shopar-3d-loading-text",se("loading.3d"));f.appendChild(m);const g=me("shopar-3d-loading-bar-bg"),v=ge("shopar-3d-loading-bar-fg");g.appendChild(v),f.appendChild(g),e.appendChild(f);const w=function(){const e=document.createElement("div");e.id=ce;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=le("4rem",`${y}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(w);const b=function(){const e=document.createElement("div");return e.id=ue,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(b);const R=de("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");b.appendChild(R);const E=de("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);b.appendChild(E);const S=de("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);b.append(S);let A,C=be.None,P=!1,T=!1,x=!1,I=!1;function M(){p.classList.remove("active"),d.style.visibility="hidden"}function L(){v.classList.remove("active"),f.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return s},getThreeTarget:function(){return r},getThreePrompt:function(){return c},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;P=e,T=t,x=n,I=o,A=r,Ae(b,P),Ae(R,P&&(x||T)&&C===be.None),Ae(E,P&&I&&C===be.None),Ae(S,P&&C!==be.None),M(),L(),P||""===(i=w).style.display&&Ae(i,!1)},getUIState:function(){return C},setUIState:function(e){C=e,C===be.None?(M(),L(),P&&(Ae(w,!1),Ae(S,!1),(T||x)&&Ae(R,!0),I&&Ae(E,!0))):C!==be.QR&&C!==be.AR&&C!==be.Preview||P&&(Ae(w,!1),Ae(R,!1),Ae(E,!1),Ae(S,!0))},setDefaultUIActions:function(e,t,n){P&&((T||x)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${y}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(A),R.onclick=e),I&&(E.onclick=t),S.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:M,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:L,showCameraError:function(){P&&Ae(w,!0)}}}function Ae(e,t){e.style.display=t?"":"none"}const Ce=new Map;function Pe(e){let n=Ce.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Se()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield R;const t=`https://apps.deepar.ai/${v.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=te(e(),t(),n())}return r}}}(),Ce.set(e,n)):n.incrementSetupId_(),n}function Te(e){for(const t of Ce.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===be.AR&&r(be.None)}}let xe;const Ie=new Uint8Array(16);function Me(){if(!xe&&(xe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xe(Ie)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var ke={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function De(e,t,n){if(ke.randomUUID&&!t&&!e)return ke.randomUUID();const o=(e=e||{}).random||(e.rng||Me)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Le[e[t+0]]+Le[e[t+1]]+Le[e[t+2]]+Le[e[t+3]]+"-"+Le[e[t+4]]+Le[e[t+5]]+"-"+Le[e[t+6]]+Le[e[t+7]]+"-"+Le[e[t+8]]+Le[e[t+9]]+"-"+Le[e[t+10]]+Le[e[t+11]]+Le[e[t+12]]+Le[e[t+13]]+Le[e[t+14]]+Le[e[t+15]]}(o)}const $e="qrLaunch",Ue="arLaunch",Ne="previewLaunch",_e="heartbeat";let je,Oe,Ge=!1;const qe=[];function We(e,t){const n=performance.now(),o=De();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:Oe,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},Ge?a():qe.push(a)};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}function Qe(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Fe(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Ve=200,He=10;let ze,Be,Ke,Xe=!1;function Ze(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let Ye,Je,et,tt,nt=!0,ot=null;const rt=new Set;let it,at,st,lt;function ct(e){e!==Ke&&(Ke=e,Ze(e),at=null,Xe=!0)}function dt(e){return t(this,void 0,void 0,(function*(){return null==it&&(it=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(o=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===o?void 0:o.getUserMedia))throw new n("No camera available!");var o;const r=wt(et),i=Qe(r),a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(et);Ye=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:tt,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}}),Je=yield Fe(i),yield yt(Ye,Je,"user"===r),"Glasses"===et&&(yield Be,function(e,n){t(this,void 0,void 0,(function*(){Xe=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,e);const r=[],i=setInterval((()=>t(this,void 0,void 0,(function*(){if(Xe)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Xe)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<He)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Ve)}))}(Je,Ye))})))()),it}))}function ut(e){e!==et&&(null!=Ye&&(Ye.shutdown(),Ye=null,it=null),et=e)}function ht(e){e!==tt&&(tt=e,null!=Ye&&Ye.changePreviewElement(tt))}function pt(e){ot=e}function ft(e){Ye.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&(e(),bt("Glasses"))},Ye.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),bt("Shoes"))},Ye.callbacks.onWristTracked=t=>{t.detected&&(e(),bt("Watches"))}}function mt(e,n){return t(this,void 0,void 0,(function*(){return null!=at&&st===n||(yield at,at=Ye.switchEffect(e),st=n),at}))}function gt(){return t(this,void 0,void 0,(function*(){if(null!=Ye){if(nt=!1,null==Je){const e=wt(et),t=Qe(e);Je=yield Fe(t),yield yt(Ye,Je,"user"===e)}!function(){if(null==ot)return;if(null==et||rt.has(et))return;ot.style.visibility="visible",ot.style.opacity="1"}(),Ye.setPaused(nt),tt.style.display=""}}))}function vt(){null!=Ye&&(nt=!0,Ye.setPaused(nt),null!=Je&&null!=Je.srcObject&&Je.srcObject instanceof MediaStream&&(Je.srcObject.getTracks().forEach((e=>e.stop())),Je=null),function(){if(null==ot)return;ot.style.visibility="hidden",ot.style.opacity="0"}(),Ye.stopCamera(),tt.style.display="none")}function wt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function yt(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function bt(e){null!=ot&&(rt.has(e)||(rt.add(e),ot.style.opacity="0"))}function Rt(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],g=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(d[c]=Math.min(76,r)*((a>>5)-1),152===d[c]&&(d[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)d[c]^=d[i]<<13,d[c]^=d[i]>>17,d[c]^=d[i]<<5,v[e]=v[e]^d[c];return i^=d[0],i^=d[1],i^=d[2],v}))}function Et(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function St(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const At=["AR","3D"];function Ct(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;Et(t,"apiKey"),St(t,"apiKey"),Et(o,"sku"),St(o,"sku"),Et(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",At),null!=a&&St(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI"),null!=l&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(l,"strings",ae)}function Pt(e){var o,r;return t(this,void 0,void 0,(function*(){Ct(e);const{apiKey:i,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),y.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(ie,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(ie[t]=n)}}(e.strings);const c=function(e,o){return t(this,void 0,void 0,(function*(){const r=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a),d=Pe(s),{getSetupId:h,findUI:p,findQR:v,findThree:w}=d,E=h();null==je&&(Oe=De(),je=b(`${y}/shopar-analytics.js`),je.then((()=>{Ge=!0,window.ShopAR__analytics.initializeImpl(),qe.forEach((e=>e()))})));const{trackEvent:S,arInteracted:A,previewInteracted:C}=We(a,i);S("setup",{hostname:window.location.hostname});const P=yield c;S("apiResponse",P);const{category:T,arUrl:x,arKey:I,arPromptEnabled:M,arPromptText:L,arPromptImage:k,previewUrl:D,previewEnvUrl:$,previewToneMapping:U}=P;Tt(h(),E);const N=null!=x&&function(e){return null!=e&&m.includes(e)}(T),_=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),O=N&&function(e){return null!=e&&g.includes(e)}(T),G=_&&O&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==lt&&(lt=b(`${y}/shopar-platform.js`)),yield lt,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}()),q=N&&!G,W=null!=D;if(Tt(h(),E),G&&function(){t(this,void 0,void 0,(function*(){null==R&&(R=b(`${y}/shopar-qr.js`))}))}(),q&&(null==ze&&(ze=b(`${y}/shopar-deepar.js`)),ct(x),"Glasses"===T&&null==Be&&(Be=b(`${y}/shopar-true-scale.js`))),W){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;Rt(D,(new Date).getTime()+e,Math.random()*e),Ze(null!=$?$:`${y}/env/default.hdr`)}const{setTargetElement:Q,getDeepARTarget:F,getDeepARPrompt:V,customizeDeepARPrompt:H,setVisibilityParameters:z,getUIState:B,setUIState:K,setDefaultUIActions:X,startDeepARLoading:Z,stopDeepARLoading:Y,startThreeLoading:J,stopThreeLoading:ee,showCameraError:te}=p();Q(s);z(null==e.defaultUI||e.defaultUI,G,q,W,T),H(null!=L?L:"",null!=k?k:""),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{B()!==be.QR||ne()||re(),B()!==be.AR||nt||vt(),B()!==be.Preview||ce()||ue(),K(be.None)}));const{qrPaused:ne,qrDraw:oe,qrPause:re}=v(),{threeInit:ae,threeParse:se,threeLoad:le,threePaused:ce,threeResume:de,threePause:ue,threeSetToneMapping:he,threeSetOnInteracted:pe}=w();let fe=0;if(B()===be.QR){if(!ne())if(G){S($e);try{yield oe(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else re(),K(be.None)}else if(B()===be.AR){if(!nt)if(q){S(Ue);const e=yield Ze(x);Tt(h(),E),Te(d),ut(T),ht(F()),pt(M?V():null),yield mt(e,x),ft(A),Tt(h(),E)}else vt(),K(be.None)}else if(B()===be.Preview&&!ce())if(W){S(Ne),J();const e=255,t=yield Rt(D,(new Date).getTime()+e,Math.random()*e);Tt(h(),E);const n=yield Ze(null!=$?$:`${y}/env/default.hdr`);Tt(h(),E);const o=yield se(t,n,`${D}${$}`);Tt(h(),E),le(o,T),he(null!=U?U:"ACES"),pe(C),ee()}else ue(),K(be.None);const me=()=>t(this,void 0,void 0,(function*(){if(G){if(B()===be.QR||B()===be.AR)throw new n("AR already launched.");try{S($e);const e=++fe;if(B()===be.Preview&&W&&!ce()&&ue(),K(be.QR),yield oe(i,a),fe!==e)return;return void Tt(h(),E)}catch(e){const t=e instanceof Error;throw S("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!q)throw new n("Model does not have AR enabled.");if(B()===be.AR)throw new n("AR already launched.");try{S(Ue);const e=++fe;B()===be.Preview&&W&&!ce()&&ue(),Te(d),K(be.AR),Z();const t=yield Ze(x);if(fe!==e)return;if(Tt(h(),E),yield ze,fe!==e)return;if(Tt(h(),E),vt(),ut(T),ht(F()),pt(M?V():null),yield dt(I),fe!==e)return;if(Tt(h(),E),yield mt(t,x),ft(A),fe!==e)return;if(Tt(h(),E),yield gt(),fe!==e)return;Tt(h(),E)}catch(e){const t=e instanceof Error;throw S("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),te(),vt(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{Y()}})),ge=()=>t(this,void 0,void 0,(function*(){if(!W)throw new n("Model does not have 3D enabled.");if(B()===be.Preview)throw new n("3D already launched.");try{S(Ne);const e=++fe;B()===be.AR&&(q&&!nt&&vt(),re()),K(be.Preview),J();const t=255,n=yield Rt(D,(new Date).getTime()+t,Math.random()*t);if(fe!==e)return;Tt(h(),E);const o=yield Ze(null!=$?$:`${y}/env/default.hdr`);if(fe!==e)return;if(Tt(h(),E),yield j,fe!==e)return;if(Tt(h(),E),ae(),fe!==e)return;Tt(h(),E);const r=yield se(n,o,`${D}${$}`);if(fe!==e)return;Tt(h(),E),le(r,T),he(null!=U?U:"ACES"),pe(C),de()}catch(e){const t=e instanceof Error;throw S("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{ee()}})),ve=()=>t(this,void 0,void 0,(function*(){if(B()===be.None)throw new n("Neither AR or 3D launched.");++fe,B()===be.QR||B()===be.AR?(q&&!nt&&vt(),re()):B()===be.Preview&&W&&!ce()&&ue(),K(be.None)}));return X(me,ge,ve),"AR"===l?(yield me(),Tt(h(),E)):"3D"===l&&(yield ge(),Tt(h(),E)),{launchAR:N?me:void 0,launch3D:W?ge:void 0,closeAR:N?()=>t(this,void 0,void 0,(function*(){if(B()!==be.AR&&B()!==be.QR)throw new n("AR not launched.");++fe,q&&!nt&&vt(),re(),K(be.None)})):void 0,close3D:W?()=>t(this,void 0,void 0,(function*(){if(B()!==be.Preview)throw new n("3D not launched.");++fe,W&&!ce()&&ue(),K(be.None)})):void 0,close:N||W?ve:void 0}}))}function Tt(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const xt={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Pt(e)))}))},version:v};e.plugin=xt}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(r),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const m=["Glasses","Shoes","Watches"],g=["Shoes"];const v="0.1.1-alpha.1";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let R;const S=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let E,C,A;function T(e){const t=function(e){const t=new C.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,C.ClampToEdgeWrapping,C.ClampToEdgeWrapping,C.LinearFilter,C.LinearFilter,1,C.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(A.parse(e));return t.mapping=C.EquirectangularReflectionMapping,t.colorSpace=C.LinearSRGBColorSpace,t}const P=45,x=45,I=3,M=1.5,L=1,k=.5;let $,D,U,N,_,j,O=!1;const G=0,q=300,W=2e3,F=.05,Q=1/(32*Math.PI);let V,H,B,z=!1,K=1,X=1,Z=1;const Y=1;let J;const ee=new Map;function te(e,n,o){const r=e.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,R=1,S=1,L=1;const j={threeInit:()=>{f||(ne(),i=new H.Scene,a=new H.PerspectiveCamera(25,1,.5),s=new V.OrbitControls(a,e),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new $.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new $.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new $.Group;o.position.y=-.7;const r=new $.PlaneGeometry(P,x).rotateX(Math.PI/2),i=new $.MeshBasicMaterial({map:t.texture,opacity:k,transparent:!0,depthWrite:!1}),a=new $.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new $.Mesh(r);s.visible=!1,o.add(s);const l=new $.OrthographicCamera(-P/2,P/2,x/2,-x/2,0,I);function c(e){s.visible=!0,N.uniforms.tDiffuse.value=t.texture,N.uniforms.h.value=1*e/256,s.material=N,D.setRenderTarget(n),D.render(s,l),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,D.setRenderTarget(t),D.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=U;const o=D.getClearAlpha();D.setClearAlpha(0),D.setRenderTarget(t),D.render(e,l),e.overrideMaterial=null,c(M),c(.4*M),D.setRenderTarget(null),D.setClearAlpha(o),e.background=n}}}(i)),f=!0)},threeParse:(e,n,o)=>t(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>t(this,void 0,void 0,(function*(){var t,o;return C=(t=V).THREE,A=new t.RGBELoader,i.environment=T(n),function(e,t){const{THREE:n}=t;E=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(J,V),o=e,E.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new H.Box3).setFromObject(e.scene);l.position.y=n.min.y-G,i.add(l),c(),i.traverse((e=>{if(e instanceof H.Mesh){const t=e.material;t.depthWrite=!0,t instanceof H.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(V.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,H.Vector3)),w=!0},threePaused:()=>m,threeResume:()=>{m=!1,J.setAnimationLoop(oe),e.style.visibility="visible",y=0,b=0},threePause:()=>{m=!0,function(){for(const{threePaused:e}of ee.values())if(!e())return!1;return!0}()&&J.setAnimationLoop(null),e.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>({ACES:H.ACESFilmicToneMapping,Linear:H.LinearToneMapping,Neutral:H.NeutralToneMapping}[e||"ACES"]||H.ACESFilmicToneMapping),threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},preRender_:e=>{if(!f||m)return;e=performance.now();const t=0!==b?e-b:0;if(b=e,!s.update()){if(v)return;if(w)return void(w=!1);if(null==p&&(p=()=>{w||(v=!0,n.style.visibility="hidden",null!=p&&(s.removeEventListener("change",p),p=null))},s.addEventListener("change",p)),y+=t,!(y>q&&y<=q+W))return o.style.opacity="0",void(y>q+2*W&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-q,t=2*Math.PI/W*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${F*r*Math.min(R,S)}px)`,s.updateTheta(Q*i)}}g=!0},shouldRender_:()=>!(!f||m)&&g,render_:()=>{const t=J.toneMapping;J.setViewport(0,0,e.width,e.height),J.render(i,a),J.toneMapping=t,g=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),r.drawImage(B,0,X-e.height,e.width,e.height,0,0,e.width,e.height))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===R&&n===S&&Z===L||(e.width=Math.ceil(t*Z*Y),e.height=Math.ceil(n*Z*Y),R=t,S=n,L=Z,g=!0)},target_:e};return ee.set(e,j),j}function ne(){if(z)return;V=window.ShopAR__THREE,H=V.THREE,B=document.createElement("canvas");var e,t;B.style.position="block",J=new H.WebGLRenderer({powerPreference:"high-performance",canvas:B,antialias:!0,alpha:!0}),J.outputColorSpace=H.SRGBColorSpace,J.toneMapping=H.ACESFilmicToneMapping,J.setClearColor(new H.Color(16777215)),e=J,t=V,O||($=t.THREE,D=e,U=new $.MeshDepthMaterial,U.userData.darkness={value:L},U.onBeforeCompile=e=>{e.uniforms.darkness=U.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},U.depthTest=!1,U.depthWrite=!1,N=new $.ShaderMaterial(t.HorizontalBlurShader),N.depthTest=!1,_=new $.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,O=!0),re(),z=!0}function oe(e){re(),J.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of ee.values())t(e),n()&&o()}function re(){let e=0,t=0;for(const{target_:n}of ee.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=S();e=Math.ceil(e*n*Y),t=Math.ceil(t*n*Y),e===K&&t===X&&n===Z||(K=e,X=t,Z=n,J.setSize(K,X,!1));for(const{updateSize_:e}of ee.values())e()}const ie={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ae=Object.keys(ie);function se(e){return ie[e]}function le(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ce="shopar-error";function de(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=le("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const ue="shopar-control";const he="shopar-deepar-output";function pe(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function fe(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function me(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function ge(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const ve="shopar-main";const we="shopar-qr-output";const ye="shopar-three-output";var be;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(be||(be={}));let Re=!1;function Se(){Re||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),Re=!0)}function Ee(){Se();const e=function(){const e=document.createElement("div");e.id=ve;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=we;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=he;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const r=function(){const e=document.createElement("canvas");e.id=ye;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(r);const i=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),a=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),s=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.pointerEvents="none",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(i,a);e.appendChild(s);const l=function(){const e=le("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),c=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(l);e.appendChild(c);const d=pe("shopar-ar-loading-container"),u=fe("shopar-ar-loading-text",se("loading.ar"));d.appendChild(u);const h=me("shopar-ar-loading-bar-bg"),p=ge("shopar-ar-loading-bar-fg");h.appendChild(p),d.appendChild(h),e.appendChild(d);const f=pe("shopar-3d-loading-container"),m=fe("shopar-3d-loading-text",se("loading.3d"));f.appendChild(m);const g=me("shopar-3d-loading-bar-bg"),v=ge("shopar-3d-loading-bar-fg");g.appendChild(v),f.appendChild(g),e.appendChild(f);const w=function(){const e=document.createElement("div");e.id=ce;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=le("4rem",`${y}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(w);const b=function(){const e=document.createElement("div");return e.id=ue,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(b);const R=de("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");b.appendChild(R);const S=de("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);b.appendChild(S);const E=de("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);b.append(E);let C,A=be.None,T=!1,P=!1,x=!1,I=!1;function M(){p.classList.remove("active"),d.style.visibility="hidden"}function L(){v.classList.remove("active"),f.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return s},getThreeTarget:function(){return r},getThreePrompt:function(){return c},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;T=e,P=t,x=n,I=o,C=r,Ce(b,T),Ce(R,T&&(x||P)&&A===be.None),Ce(S,T&&I&&A===be.None),Ce(E,T&&A!==be.None),M(),L(),T||""===(i=w).style.display&&Ce(i,!1)},getUIState:function(){return A},setUIState:function(e){A=e,A===be.None?(M(),L(),T&&(Ce(w,!1),Ce(E,!1),(P||x)&&Ce(R,!0),I&&Ce(S,!0))):A!==be.QR&&A!==be.AR&&A!==be.Preview||T&&(Ce(w,!1),Ce(R,!1),Ce(S,!1),Ce(E,!0))},setDefaultUIActions:function(e,t,n){T&&((P||x)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${y}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(C),R.onclick=e),I&&(S.onclick=t),E.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:M,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:L,showCameraError:function(){T&&Ce(w,!0)}}}function Ce(e,t){e.style.display=t?"":"none"}const Ae=new Map;function Te(e){let n=Ae.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Ee()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield R;const t=`https://apps.deepar.ai/${v.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=te(e(),t(),n())}return r}}}(),Ae.set(e,n)):n.incrementSetupId_(),n}function Pe(e){for(const t of Ae.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===be.AR&&r(be.None)}}let xe;const Ie=new Uint8Array(16);function Me(){if(!xe&&(xe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xe(Ie)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var ke={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function $e(e,t,n){if(ke.randomUUID&&!t&&!e)return ke.randomUUID();const o=(e=e||{}).random||(e.rng||Me)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Le[e[t+0]]+Le[e[t+1]]+Le[e[t+2]]+Le[e[t+3]]+"-"+Le[e[t+4]]+Le[e[t+5]]+"-"+Le[e[t+6]]+Le[e[t+7]]+"-"+Le[e[t+8]]+Le[e[t+9]]+"-"+Le[e[t+10]]+Le[e[t+11]]+Le[e[t+12]]+Le[e[t+13]]+Le[e[t+14]]+Le[e[t+15]]}(o)}const De="qrLaunch",Ue="arLaunch",Ne="previewLaunch",_e="heartbeat";let je,Oe,Ge=!1;const qe=[];function We(e,t){const n=performance.now(),o=$e();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:Oe,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},Ge?a():qe.push(a)};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}function Fe(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Qe(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Ve=200,He=10;let Be,ze,Ke,Xe=!1;function Ze(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let Ye,Je,et,tt,nt=!0,ot=null;const rt=new Set;let it,at,st,lt;function ct(e){e!==Ke&&(Ke=e,Ze(e),at=null,Xe=!0)}function dt(e){return t(this,void 0,void 0,(function*(){return null==it&&(it=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(o=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===o?void 0:o.getUserMedia))throw new n("No camera available!");var o;const r=wt(et),i=Fe(r),a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(et);Ye=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:tt,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}}),Je=yield Qe(i),yield yt(Ye,Je,"user"===r),"Glasses"===et&&(yield ze,function(e,n){t(this,void 0,void 0,(function*(){Xe=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,e);const r=[],i=setInterval((()=>t(this,void 0,void 0,(function*(){if(Xe)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Xe)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<He)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Ve)}))}(Je,Ye))})))()),it}))}function ut(e){e!==et&&(null!=Ye&&(Ye.shutdown(),Ye=null,it=null),et=e)}function ht(e){e!==tt&&(tt=e,null!=Ye&&Ye.changePreviewElement(tt))}function pt(e){ot=e}function ft(e){Ye.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&(e(),bt("Glasses"))},Ye.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),bt("Shoes"))},Ye.callbacks.onWristTracked=t=>{t.detected&&(e(),bt("Watches"))}}function mt(e,n){return t(this,void 0,void 0,(function*(){return null!=at&&st===n||(yield at,at=Ye.switchEffect(e),st=n),at}))}function gt(){return t(this,void 0,void 0,(function*(){if(null!=Ye){if(nt=!1,null==Je){const e=wt(et),t=Fe(e);Je=yield Qe(t),yield yt(Ye,Je,"user"===e)}!function(){if(null==ot)return;if(null==et||rt.has(et))return;ot.style.visibility="visible",ot.style.opacity="1"}(),Ye.setPaused(nt),tt.style.display=""}}))}function vt(){null!=Ye&&(nt=!0,Ye.setPaused(nt),null!=Je&&null!=Je.srcObject&&Je.srcObject instanceof MediaStream&&(Je.srcObject.getTracks().forEach((e=>e.stop())),Je=null),function(){if(null==ot)return;ot.style.visibility="hidden",ot.style.opacity="0"}(),Ye.stopCamera(),tt.style.display="none")}function wt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function yt(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function bt(e){null!=ot&&(rt.has(e)||(rt.add(e),ot.style.opacity="0"))}function Rt(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],g=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(d[c]=Math.min(76,r)*((a>>5)-1),152===d[c]&&(d[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)d[c]^=d[i]<<13,d[c]^=d[i]>>17,d[c]^=d[i]<<5,v[e]=v[e]^d[c];return i^=d[0],i^=d[1],i^=d[2],v}))}function St(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Et(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Ct=["AR","3D"];function At(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;St(t,"apiKey"),Et(t,"apiKey"),St(o,"sku"),Et(o,"sku"),St(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",Ct),null!=a&&Et(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI"),null!=l&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(l,"strings",ae)}function Tt(e){var o,r;return t(this,void 0,void 0,(function*(){At(e);const{apiKey:i,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),y.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(ie,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(ie[t]=n)}}(e.strings);const c=function(e,o){return t(this,void 0,void 0,(function*(){const r=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a),d=Te(s),{getSetupId:h,findUI:p,findQR:v,findThree:w}=d,S=h();null==je&&(Oe=$e(),je=b(`${y}/shopar-analytics.js`),je.then((()=>{Ge=!0,window.ShopAR__analytics.initializeImpl(),qe.forEach((e=>e()))})));const{trackEvent:E,arInteracted:C,previewInteracted:A}=We(a,i);E("setup",{hostname:window.location.hostname});const T=yield c;E("apiResponse",T);const{category:P,arUrl:x,arKey:I,arPromptEnabled:M,arPromptText:L,arPromptImage:k,previewUrl:$,previewEnvUrl:D,previewToneMapping:U}=T;Pt(h(),S);const N=null!=x&&function(e){return null!=e&&m.includes(e)}(P),_=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),O=N&&function(e){return null!=e&&g.includes(e)}(P),G=_&&O&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==lt&&(lt=b(`${y}/shopar-platform.js`)),yield lt,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}()),q=N&&!G,W=null!=$;if(Pt(h(),S),G&&function(){t(this,void 0,void 0,(function*(){null==R&&(R=b(`${y}/shopar-qr.js`))}))}(),q&&(null==Be&&(Be=b(`${y}/shopar-deepar.js`)),ct(x),"Glasses"===P&&null==ze&&(ze=b(`${y}/shopar-true-scale.js`))),W){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;Rt($,(new Date).getTime()+e,Math.random()*e),Ze(null!=D?D:`${y}/env/default.hdr`)}const{setTargetElement:F,getDeepARTarget:Q,getDeepARPrompt:V,customizeDeepARPrompt:H,setVisibilityParameters:B,getUIState:z,setUIState:K,setDefaultUIActions:X,startDeepARLoading:Z,stopDeepARLoading:Y,startThreeLoading:J,stopThreeLoading:ee,showCameraError:te}=p();F(s);B(null==e.defaultUI||e.defaultUI,G,q,W,P),H(null!=L?L:"",null!=k?k:""),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{z()!==be.QR||ne()||re(),z()!==be.AR||nt||vt(),z()!==be.Preview||ce()||ue(),K(be.None)}));const{qrPaused:ne,qrDraw:oe,qrPause:re}=v(),{threeInit:ae,threeParse:se,threeLoad:le,threePaused:ce,threeResume:de,threePause:ue,threeSetToneMapping:he,threeSetOnInteracted:pe}=w();let fe=0;if(z()===be.QR){if(!ne())if(G){E(De);try{yield oe(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else re(),K(be.None)}else if(z()===be.AR){if(!nt)if(q){E(Ue);const e=yield Ze(x);Pt(h(),S),Pe(d),ut(P),ht(Q()),pt(M?V():null),yield mt(e,x),ft(C),Pt(h(),S)}else vt(),K(be.None)}else if(z()===be.Preview&&!ce())if(W){E(Ne),J();const e=255,t=yield Rt($,(new Date).getTime()+e,Math.random()*e);Pt(h(),S);const n=yield Ze(null!=D?D:`${y}/env/default.hdr`);Pt(h(),S);const o=yield se(t,n,`${$}${D}`);Pt(h(),S),le(o,P),he(null!=U?U:"ACES"),pe(A),ee()}else ue(),K(be.None);const me=()=>t(this,void 0,void 0,(function*(){if(G){if(z()===be.QR||z()===be.AR)throw new n("AR already launched.");try{E(De);const e=++fe;if(z()===be.Preview&&W&&!ce()&&ue(),K(be.QR),yield oe(i,a),fe!==e)return;return void Pt(h(),S)}catch(e){const t=e instanceof Error;throw E("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!q)throw new n("Model does not have AR enabled.");if(z()===be.AR)throw new n("AR already launched.");try{E(Ue);const e=++fe;z()===be.Preview&&W&&!ce()&&ue(),Pe(d),K(be.AR),Z();const t=yield Ze(x);if(fe!==e)return;if(Pt(h(),S),yield Be,fe!==e)return;if(Pt(h(),S),vt(),ut(P),ht(Q()),pt(M?V():null),yield dt(I),fe!==e)return;if(Pt(h(),S),yield mt(t,x),ft(C),fe!==e)return;if(Pt(h(),S),yield gt(),fe!==e)return;Pt(h(),S)}catch(e){const t=e instanceof Error;throw E("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),te(),vt(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{Y()}})),ge=()=>t(this,void 0,void 0,(function*(){if(!W)throw new n("Model does not have 3D enabled.");if(z()===be.Preview)throw new n("3D already launched.");try{E(Ne);const e=++fe;z()===be.AR&&(q&&!nt&&vt(),re()),K(be.Preview),J();const t=255,n=yield Rt($,(new Date).getTime()+t,Math.random()*t);if(fe!==e)return;Pt(h(),S);const o=yield Ze(null!=D?D:`${y}/env/default.hdr`);if(fe!==e)return;if(Pt(h(),S),yield j,fe!==e)return;if(Pt(h(),S),ae(),fe!==e)return;Pt(h(),S);const r=yield se(n,o,`${$}${D}`);if(fe!==e)return;Pt(h(),S),le(r,P),he(null!=U?U:"ACES"),pe(A),de()}catch(e){const t=e instanceof Error;throw E("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{ee()}})),ve=()=>t(this,void 0,void 0,(function*(){if(z()===be.None)throw new n("Neither AR or 3D launched.");++fe,z()===be.QR||z()===be.AR?(q&&!nt&&vt(),re()):z()===be.Preview&&W&&!ce()&&ue(),K(be.None)}));return X(me,ge,ve),"AR"===l?(yield me(),Pt(h(),S)):"3D"===l&&(yield ge(),Pt(h(),S)),{launchAR:N?me:void 0,launch3D:W?ge:void 0,closeAR:N?()=>t(this,void 0,void 0,(function*(){if(z()!==be.AR&&z()!==be.QR)throw new n("AR not launched.");++fe,q&&!nt&&vt(),re(),K(be.None)})):void 0,close3D:W?()=>t(this,void 0,void 0,(function*(){if(z()!==be.Preview)throw new n("3D not launched.");++fe,W&&!ce()&&ue(),K(be.None)})):void 0,close:N||W?ve:void 0}}))}function Pt(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const xt={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Tt(e)))}))},version:v};e.plugin=xt}));