shopar-plugin 0.1.2 → 0.1.3-alpha.2

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,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{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((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]]]],c=s.charCodeAt(r),l=c^c,d=new o[1]([l]);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.2";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 A,E,C;function P(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 M=45,I=45,T=3,L=1.5,x=1,k=.5;let U,D,$,_,N,j,O=!1;const F=0,q=300,G=2e3,W=.05,Q=1/(32*Math.PI);let V,K,z,B=!1,H=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,c,l,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,R=1,S=1,x=1;const j={threeInit:()=>{f||(ne(),i=new K.Scene,a=new K.PerspectiveCamera(25,1,.5),s=new V.OrbitControls(a,e),s.enableInteraction(),({renderShadow:l,shadowGroup:c}=function(e){const t=new U.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new U.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new U.Group;o.position.y=-.7;const r=new U.PlaneGeometry(M,I).rotateX(Math.PI/2),i=new U.MeshBasicMaterial({map:t.texture,opacity:k,transparent:!0,depthWrite:!1}),a=new U.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new U.Mesh(r);s.visible=!1,o.add(s);const c=new U.OrthographicCamera(-M/2,M/2,I/2,-I/2,0,T);function l(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,D.setRenderTarget(n),D.render(s,c),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,D.setRenderTarget(t),D.render(s,c),s.visible=!1}return c.rotation.x=Math.PI/2,o.add(c),{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,c),e.overrideMaterial=null,l(L),l(.4*L),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 E=(t=V).THREE,C=new t.RGBELoader,i.environment=P(n),function(e,t){const{THREE:n}=t;A=(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,A.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new K.Box3).setFromObject(e.scene);c.position.y=n.min.y-F,i.add(c),l(),i.traverse((e=>{if(e instanceof K.Mesh){const t=e.material;t.depthWrite=!0,t instanceof K.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,K.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:K.ACESFilmicToneMapping,Linear:K.LinearToneMapping,Neutral:K.NeutralToneMapping}[e||"ACES"]||K.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+G))return o.style.opacity="0",void(y>q+2*G&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-q,t=2*Math.PI/G*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${W*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),z.width>0&&z.height>0&&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===R&&n===S&&Z===x||(e.width=Math.ceil(t*Z*Y),e.height=Math.ceil(n*Z*Y),R=t,S=n,x=Z,g=!0)},target_:e};return ee.set(e,j),j}function ne(){if(B)return;V=window.ShopAR__THREE,K=V.THREE,z=document.createElement("canvas");var e,t;z.style.position="block",J=new K.WebGLRenderer({powerPreference:"high-performance",canvas:z,antialias:!0,alpha:!0}),J.outputColorSpace=K.SRGBColorSpace,J.toneMapping=K.ACESFilmicToneMapping,J.setClearColor(new K.Color(16777215)),e=J,t=V,O||(U=t.THREE,D=e,$=new U.MeshDepthMaterial,$.userData.darkness={value:x},$.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,_=new U.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,N=new U.ShaderMaterial(t.VerticalBlurShader),N.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=S();e=Math.ceil(e*n*Y),t=Math.ceil(t*n*Y),e===H&&t===X&&n===Z||(H=e,X=t,Z=n,J.setSize(H,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]}const ce="shopar-error";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}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 Ae(){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=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),o=function(e,t){const n=document.createElement("div");n.id=we;const o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="none";const r=document.createElement("div");r.className="shopar-qr";const i=r.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(r),r.appendChild(e);const a=document.createElement("div");return a.appendChild(t),r.appendChild(a),n}(t,n);e.appendChild(o);const r=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(r);const i=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(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),c=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}(a,s);e.appendChild(c);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}(),d=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(d);const u=pe("shopar-ar-loading-container"),h=fe("shopar-ar-loading-text",se("loading.ar"));u.appendChild(h);const p=me("shopar-ar-loading-bar-bg"),f=ge("shopar-ar-loading-bar-fg");p.appendChild(f),u.appendChild(p),e.appendChild(u);const m=pe("shopar-3d-loading-container"),g=fe("shopar-3d-loading-text",se("loading.3d"));m.appendChild(g);const v=me("shopar-3d-loading-bar-bg"),w=ge("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),R=function(e){const t=document.createElement("div");t.id=ce;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div"),r=o.style;return r.position="absolute",r.width="100%",r.height="100%",r.backgroundColor="#ffffff",r.display="flex",r.flexDirection="column",r.justifyContent="center",r.alignItems="center",t.appendChild(o),o.appendChild(e),t}(b);e.appendChild(R);const S=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(S);const A=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");S.appendChild(A);const E=de("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);S.appendChild(E);const C=de("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);S.append(C);let P,M=be.None,I=!1,T=!1,L=!1,x=!1;function k(){f.classList.remove("active"),u.style.visibility="hidden"}function U(){w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return o},getQRImage:function(){return n},getDeepARTarget:function(){return r},getDeepARPrompt:function(){return c},getThreeTarget:function(){return i},getThreePrompt:function(){return d},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){b.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,o,r){var i;I=e,T=t,L=n,x=o,P=r,Ee(S,I),Ee(A,I&&(L||T)&&M===be.None),Ee(E,I&&x&&M===be.None),Ee(C,I&&M!==be.None),k(),U(),I||""===(i=R).style.display&&Ee(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===be.None?(k(),U(),I&&(Ee(R,!1),Ee(C,!1),(T||L)&&Ee(A,!0),x&&Ee(E,!0))):M!==be.QR&&M!==be.AR&&M!==be.Preview||I&&(Ee(R,!1),Ee(A,!1),Ee(E,!1),Ee(C,!0))},setDefaultUIActions:function(e,t,n){I&&((T||L)&&(!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}`;A.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(P),A.onclick=e),x&&(E.onclick=t),C.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),u.style.visibility="visible"},stopDeepARLoading:k,startThreeLoading:function(){w.classList.add("active"),m.style.visibility="visible"},stopThreeLoading:U,showCameraError:function(){I&&Ee(R,!0)}}}function Ee(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=Ae()),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 Me(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 Ie;const Te=new Uint8Array(16);function Le(){if(!Ie&&(Ie="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ie))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ie(Te)}const xe=[];for(let e=0;e<256;++e)xe.push((e+256).toString(16).slice(1));var ke={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ue(e,t,n){if(ke.randomUUID&&!t&&!e)return ke.randomUUID();const o=(e=e||{}).random||(e.rng||Le)();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 xe[e[t+0]]+xe[e[t+1]]+xe[e[t+2]]+xe[e[t+3]]+"-"+xe[e[t+4]]+xe[e[t+5]]+"-"+xe[e[t+6]]+xe[e[t+7]]+"-"+xe[e[t+8]]+xe[e[t+9]]+"-"+xe[e[t+10]]+xe[e[t+11]]+xe[e[t+12]]+xe[e[t+13]]+xe[e[t+14]]+xe[e[t+15]]}(o)}const De="qrLaunch",$e="arLaunch",_e="previewLaunch",Ne="heartbeat";let je,Oe,Fe=!1;const qe=[];function Ge(){null==je&&(Oe=Ue(),je=b(`${y}/shopar-analytics.js`),je.then((()=>{Fe=!0,window.ShopAR__analytics.initializeImpl(),qe.forEach((e=>e()))})))}function We(e){Fe?e():qe.push(e)}function Qe(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ve(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 Ke=200,ze=10;let Be=!1,He=null,Xe=[],Ze=[];function Ye(e){return t(this,void 0,void 0,(function*(){Be=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,e),He&&clearInterval(He);const o=[],r=[];He=setInterval((()=>t(this,void 0,void 0,(function*(){if(Be)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Be||(null!=a&&null!=s&&function(e){for(let t of Xe)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<ze||(o.shift(),r.shift(),function(e,t){for(let n of Ze)n({faceWidth:e,IPD:t})}(et(o),et(r)))))}))),Ke)}))}function Je(){Ze=[],Xe=[],Be=!0}function et(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function tt(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.")}}))}var nt="undefined"!=typeof Float32Array?Float32Array:Array;function ot(){var e=new nt(16);return nt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function rt(e,t,n){var o=t[0],r=t[1],i=t[2],a=t[3],s=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],R=n[2],S=n[3];return e[0]=y*o+b*s+R*u+S*m,e[1]=y*r+b*c+R*h+S*g,e[2]=y*i+b*l+R*p+S*v,e[3]=y*a+b*d+R*f+S*w,y=n[4],b=n[5],R=n[6],S=n[7],e[4]=y*o+b*s+R*u+S*m,e[5]=y*r+b*c+R*h+S*g,e[6]=y*i+b*l+R*p+S*v,e[7]=y*a+b*d+R*f+S*w,y=n[8],b=n[9],R=n[10],S=n[11],e[8]=y*o+b*s+R*u+S*m,e[9]=y*r+b*c+R*h+S*g,e[10]=y*i+b*l+R*p+S*v,e[11]=y*a+b*d+R*f+S*w,y=n[12],b=n[13],R=n[14],S=n[15],e[12]=y*o+b*s+R*u+S*m,e[13]=y*r+b*c+R*h+S*g,e[14]=y*i+b*l+R*p+S*v,e[15]=y*a+b*d+R*f+S*w,e}function it(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function at(e,t){var n=t[0],o=t[1],r=t[2],i=t[4],a=t[5],s=t[6],c=t[8],l=t[9],d=t[10];return e[0]=Math.hypot(n,o,r),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(c,l,d),e}function st(e,t,n,o){var r=t[0],i=t[1],a=t[2],s=t[3],c=r+r,l=i+i,d=a+a,u=r*c,h=r*l,p=r*d,f=i*l,m=i*d,g=a*d,v=s*c,w=s*l,y=s*d,b=o[0],R=o[1],S=o[2];return e[0]=(1-(f+g))*b,e[1]=(h+y)*b,e[2]=(p-w)*b,e[3]=0,e[4]=(h-y)*R,e[5]=(1-(u+g))*R,e[6]=(m+v)*R,e[7]=0,e[8]=(p+w)*S,e[9]=(m-v)*S,e[10]=(1-(u+f))*S,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function ct(){var e=new nt(3);return nt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function lt(e,t,n){var o=new nt(3);return o[0]=e,o[1]=t,o[2]=n,o}function dt(e,t){var n=t[0]-e[0],o=t[1]-e[1],r=t[2]-e[2];return Math.hypot(n,o,r)}function ut(e,t,n){var o=t[0],r=t[1],i=t[2],a=n[3]*o+n[7]*r+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*o+n[4]*r+n[8]*i+n[12])/a,e[1]=(n[1]*o+n[5]*r+n[9]*i+n[13])/a,e[2]=(n[2]*o+n[6]*r+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function ht(){var e=new nt(4);return nt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}ct(),function(){var e,t=(e=new nt(4),nt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var pt;let ft,mt,gt;ct(),lt(1,0,0),lt(0,1,0),ht(),ht(),pt=new nt(9),nt!=Float32Array&&(pt[1]=0,pt[2]=0,pt[3]=0,pt[5]=0,pt[6]=0,pt[7]=0),pt[0]=1,pt[4]=1,pt[8]=1;let vt,wt,yt,bt,Rt=!0,St=null;const At=new Set;let Et,Ct,Pt,Mt,It,Tt,Lt;function xt(){null==ft&&(ft=b(`${y}/shopar-deepar.js`))}function kt(){null==mt&&(mt=b(`${y}/shopar-true-scale.js`))}function Ut(e){return t(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=e;return It=r,null==Et&&(Et=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=qt(yt),r=Qe(t);vt=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:bt,additionalOptions:{hint:Tt,cameraConfig:{disableDefaultCamera:!0}}}),wt=yield Ve(r),yield Gt(vt,wt,"user"===t),"Glasses"===yt&&(yield mt,Ye(wt),"DetectionLoop"!==It&&Kt((e=>{Mt=e.faceWidth})))})))()),Et}))}function Dt(e,t){var n,o;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===yt&&(n=t,o=Tt,n===o||null!=n&&null!=o&&n.length===o.length&&n.every((e=>o.find((t=>e===t))))&&o.every((e=>n.find((t=>t===e))))))||(null!=vt&&(vt.shutdown(),vt=null,Et=null),yt=e,Tt=t)}function $t(e){e!==bt&&(bt=e,null!=vt&&vt.changePreviewElement(bt))}function _t(e){St=e}function Nt(e){vt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Mt){const e=137/(Mt+5);vt.changeParameterVector("GLASSES","","scale",e,e,e,0),vt.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const o=Qt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Qt("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);vt.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),vt.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),Je(),Mt=null}e(),Wt("Glasses")}},vt.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Wt("Shoes"))},vt.callbacks.onWristTracked=t=>{t.detected&&(e(),Wt("Watches"))}}function jt(e,n){return t(this,void 0,void 0,(function*(){return null!=Ct&&Pt===n||(yield Ct,Ct=vt.switchEffect(e),Pt=n),Ct}))}function Ot(){return t(this,void 0,void 0,(function*(){if(null!=vt){if(Rt=!1,null==wt){const e=qt(yt),t=Qe(e);wt=yield Ve(t),yield Gt(vt,wt,"user"===e),Ye(wt),"DetectionLoop"!==It&&Kt((e=>{Mt=e.faceWidth}))}!function(){if(null==St)return;if(null==yt||At.has(yt))return;St.style.visibility="visible",St.style.opacity="1"}(),vt.setPaused(Rt),bt.style.display=""}}))}function Ft(){null!=vt&&(Rt=!0,vt.setPaused(Rt),Je(),null!=wt&&null!=wt.srcObject&&wt.srcObject instanceof MediaStream&&(wt.srcObject.getTracks().forEach((e=>e.stop())),wt=null),function(){if(null==St)return;St.style.visibility="hidden",St.style.opacity="0"}(),vt.stopCamera(),bt.style.display="none")}function qt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Gt(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 Wt(e){null!=St&&(At.has(e)||(At.add(e),St.style.opacity="0"))}function Qt(e,t,n,o,r,i,a){const s=vt.getTransformationBetween(e,t),c=it(ct(),s),l=function(e,t){var n=new nt(3);at(n,t);var o=1/n[0],r=1/n[1],i=1/n[2],a=t[0]*o,s=t[1]*r,c=t[2]*i,l=t[4]*o,d=t[5]*r,u=t[6]*i,h=t[8]*o,p=t[9]*r,f=t[10]*i,m=a+d+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(u-p)/g,e[1]=(h-c)/g,e[2]=(s-l)/g):a>d&&a>f?(g=2*Math.sqrt(1+a-d-f),e[3]=(u-p)/g,e[0]=.25*g,e[1]=(s+l)/g,e[2]=(h+c)/g):d>f?(g=2*Math.sqrt(1+d-a-f),e[3]=(h-c)/g,e[0]=(s+l)/g,e[1]=.25*g,e[2]=(u+p)/g):(g=2*Math.sqrt(1+f-a-d),e[3]=(s-l)/g,e[0]=(h+c)/g,e[1]=(u+p)/g,e[2]=.25*g),e}(ht(),s);st(s,l,c,lt(a,a,a));const d=vt.getTransformationBetween(t,n),u=it(ct(),d);st(d,ht(),u,at(ct(),d));const h=rt(ot(),s,d),p=it(ct(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=vt.getTransformationBetween(n,o)}catch(e){return f}const g=rt(ot(),d,m),v=rt(ot(),s,g),w=lt(p[0],i[1],i[2]),y=ut(ct(),w,function(e,t){var n=t[0],o=t[1],r=t[2],i=t[3],a=t[4],s=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-o*a,y=n*c-r*a,b=n*l-i*a,R=o*c-r*s,S=o*l-i*s,A=r*l-i*c,E=d*m-u*f,C=d*g-h*f,P=d*v-p*f,M=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*M+R*P-S*C+A*E;return L?(L=1/L,e[0]=(s*T-c*I+l*M)*L,e[1]=(r*I-o*T-i*M)*L,e[2]=(m*A-g*S+v*R)*L,e[3]=(h*S-u*A-p*R)*L,e[4]=(c*P-a*T-l*C)*L,e[5]=(n*T-r*P+i*C)*L,e[6]=(g*b-f*A-v*y)*L,e[7]=(d*A-h*b+p*y)*L,e[8]=(a*I-s*P+l*E)*L,e[9]=(o*P-n*I-i*E)*L,e[10]=(f*S-m*b+v*w)*L,e[11]=(u*b-d*S-p*w)*L,e[12]=(s*C-a*M-c*E)*L,e[13]=(n*M-o*C+r*E)*L,e[14]=(m*y-f*R-g*w)*L,e[15]=(d*R-u*y+h*w)*L,e):null}(ot(),v));let b=vt.getClosestPointOnMesh(o,y);try{const e=vt.getClosestPointOnMesh(r,y);dt(y,e)<dt(y,b)&&(b=e)}catch(e){}const R=ut(ct(),b,g);return f-Math.atan2(R[0]-u[0],Math.abs(R[2]-u[2]))}function Vt(e){!function(e){Xe.push(e)}(e)}function Kt(e){!function(e){Ze.push(e)}(e)}function zt(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 c=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+c+(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[l]=Math.min(76,r)*((a>>5)-1),152===d[l]&&(d[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)d[l]^=d[i]<<13,d[l]^=d[i]>>17,d[l]^=d[i]<<5,v[e]=v[e]^d[l];return i^=d[0],i^=d[1],i^=d[2],v}))}function Bt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Ht(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Xt=["AR","3D"];function Zt(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;Bt(t,"apiKey"),Ht(t,"apiKey"),Bt(o,"sku"),Ht(o,"sku"),Bt(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",Xt),null!=a&&Ht(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI"),null!=c&&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.`)}}(c,"strings",ae)}let Yt=!1;function Jt(e){return t(this,void 0,void 0,(function*(){const{targetElement:o}=e;y.update(e.baseUrl),Ge();const{trackEvent:r}=function(e){const t=performance.now(),n=Ue();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:v,sessionId:Oe,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),We((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(e.apiKey);r("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,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 o.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(e.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Pe(o),{getSetupId:c,findUI:l}=s,d=c();xt(),kt();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:R,showCameraError:S}=l();if(g()!=be.None)throw Error("UI state is not None, this is weird..");w(be.AR),h(o),m(!1,!1,!0,!1,void 0),b(),yield ft,en(c(),d);try{r("visionArLaunch"),Ft(),Dt("Glasses",["faceInit"]),$t(p()),yield Ut({licenseKey:a,truescaleUsecase:"DetectionLoop"}),en(c(),d),yield Ot(),en(c(),d)}catch(e){const t=e instanceof Error;throw r("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),S(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{R()}return Yt=!0,{registerFacePoseListener:e=>{Yt&&(r("registerFacePoseListener"),Vt(e))},registerFaceMeasurementListener:e=>{Yt&&(r("registerFaceMeasurementListener"),Kt(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){Yt&&(r("switchEffect",{arUrl:e}),function(e){vt.switchEffect(e)}(e))})),clearEffect:()=>{Yt&&(r("clearEffect"),vt.clearEffect())},close:()=>{if(Yt){if(Yt=!1,r("visionClose"),g()!==be.AR)throw new n("AR not launched.");Ft(),w(be.None)}}}}))}function en(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function tn(e){var o,r;return t(this,void 0,void 0,(function*(){Zt(e);const{apiKey:i,sku:a,targetElement:s,initialState:c}=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 l=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:w,findThree:S}=d,A=h();Ge();const{trackEvent:E,arInteracted:C,previewInteracted:P}=function(e,t){const n=performance.now(),o=Ue();let r=0,i=0,a=0,s=0,c=0,l=!1;window.setInterval((()=>{l&&(r=i+a,l=!1,d(Ne,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:Oe,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),We((()=>{window.ShopAR__analytics.trackEventImpl(r,i)}))};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,l=!0)},previewInteracted:()=>{const e=performance.now(),t=e-c;c=e,t<200&&(a+=t,l=!0)}}}(a,i);E("setup",{hostname:window.location.hostname});const M=yield l;E("apiResponse",M);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_,cameraErrorText:N,qrPromptText:O}=M;nn(h(),A);const F=null!=T&&function(e){return null!=e&&m.includes(e)}(I),q=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),G=F&&function(e){return null!=e&&g.includes(e)}(I),W=q&&G&&!(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=F&&!W,V=null!=D;if(nn(h(),A),W&&function(){t(this,void 0,void 0,(function*(){null==R&&(R=b(`${y}/shopar-qr.js`))}))}(),Q&&(xt(),function(e){e!==gt&&(gt=e,tt(e),Ct=null,Je())}(T),"Glasses"===I&&kt()),V){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;zt(D,(new Date).getTime()+e,Math.random()*e),tt(null!=$?$:`${y}/env/default.hdr`)}const{setTargetElement:K,getDeepARTarget:z,getDeepARPrompt:B,customizeDeepARPrompt:H,customizeCameraError:X,customizeQRPrompt:Z,setVisibilityParameters:Y,getUIState:J,setUIState:ee,setDefaultUIActions:te,startDeepARLoading:ne,stopDeepARLoading:oe,startThreeLoading:re,stopThreeLoading:ae,showCameraError:se}=p();K(s);Y(null==e.defaultUI||e.defaultUI,W,Q,V,I),H(null!=k?k:"",null!=U?U:""),X(N),Z(O),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,(()=>{J()!==be.QR||ce()||de(),J()!==be.AR||Rt||Ft(),J()!==be.Preview||fe()||ge(),ee(be.None)}));const{qrPaused:ce,qrDraw:le,qrPause:de}=w(),{threeInit:ue,threeParse:he,threeLoad:pe,threePaused:fe,threeResume:me,threePause:ge,threeSetToneMapping:ve,threeSetOnInteracted:we}=S();let ye=0;if(J()===be.QR){if(!ce())if(W){E(De);try{yield le(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else de(),ee(be.None)}else if(J()===be.AR){if(!Rt)if(Q&&!Yt){E($e);const e=yield tt(T);nn(h(),A),Me(d),Dt(I),$t(z()),_t(x?B():null),yield jt(e,T),Nt(C),nn(h(),A)}else Ft(),ee(be.None)}else if(J()===be.Preview&&!fe())if(V){E(_e),re();const e=255,t=yield zt(D,(new Date).getTime()+e,Math.random()*e);nn(h(),A);const n=yield tt(null!=$?$:`${y}/env/default.hdr`);nn(h(),A);const o=yield he(t,n,`${D}${$}`);nn(h(),A),pe(o,I),ve(null!=_?_:"ACES"),we(P),ae()}else ge(),ee(be.None);const Re=()=>t(this,void 0,void 0,(function*(){if(W){if(J()===be.QR||J()===be.AR)throw new n("AR already launched.");try{E(De);const e=++ye;if(J()===be.Preview&&V&&!fe()&&ge(),ee(be.QR),yield le(i,a),ye!==e)return;return void nn(h(),A)}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(J()===be.AR)throw new n("AR already launched.");try{E($e);const e=++ye;J()===be.Preview&&V&&!fe()&&ge(),Me(d),ee(be.AR),ne();const t=yield tt(T);if(ye!==e)return;if(nn(h(),A),yield ft,ye!==e)return;if(nn(h(),A),Ft(),Dt(I),$t(z()),_t(x?B():null),yield Ut({licenseKey:L}),ye!==e)return;if(nn(h(),A),yield jt(t,T),Nt(C),ye!==e)return;if(nn(h(),A),yield Ot(),ye!==e)return;nn(h(),A)}catch(e){const t=e instanceof Error;throw E("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{oe()}})),Se=()=>t(this,void 0,void 0,(function*(){if(!V)throw new n("Model does not have 3D enabled.");if(J()===be.Preview)throw new n("3D already launched.");try{E(_e);const e=++ye;J()===be.AR&&(Q&&!Rt&&Ft(),de()),ee(be.Preview),re();const t=255,n=yield zt(D,(new Date).getTime()+t,Math.random()*t);if(ye!==e)return;nn(h(),A);const o=yield tt(null!=$?$:`${y}/env/default.hdr`);if(ye!==e)return;if(nn(h(),A),yield j,ye!==e)return;if(nn(h(),A),ue(),ye!==e)return;nn(h(),A);const r=yield he(n,o,`${D}${$}`);if(ye!==e)return;nn(h(),A),pe(r,I),ve(null!=_?_:"ACES"),we(P),me()}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{ae()}})),Ae=()=>t(this,void 0,void 0,(function*(){if(J()===be.None)throw new n("Neither AR or 3D launched.");++ye,J()===be.QR||J()===be.AR?(Q&&!Rt&&Ft(),de()):J()===be.Preview&&V&&!fe()&&ge(),ee(be.None)}));return te(Re,Se,Ae),"AR"===c?(yield Re(),nn(h(),A)):"3D"===c&&(yield Se(),nn(h(),A)),Yt=!1,{launchAR:F?Re:void 0,launch3D:V?Se:void 0,closeAR:F?()=>t(this,void 0,void 0,(function*(){if(J()!==be.AR&&J()!==be.QR)throw new n("AR not launched.");++ye,Q&&!Rt&&Ft(),de(),ee(be.None)})):void 0,close3D:V?()=>t(this,void 0,void 0,(function*(){if(J()!==be.Preview)throw new n("3D not launched.");++ye,V&&!fe()&&ge(),ee(be.None)})):void 0,close:F||V?Ae:void 0}}))}function nn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const on={setup:function(e){return t(this,void 0,void 0,(function*(){return Jt(e)}))}},rn={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",(()=>tn(e)))}))},version:v};e.plugin=rn,e.vision=on}));
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,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.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 r=[Uint8Array,Uint32Array],o=r.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[o]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(o),c=l^l,u=new r[1]([c]);function d(){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],f=h.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=f)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),p(e,n+1)}}))}const m=["Glasses","Shoes","Watches"],g=["Shoes"];const v="0.1.3-alpha.2";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 E;const A=(()=>{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 R,S,C;function I(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.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=S.EquirectangularReflectionMapping,t.colorSpace=S.LinearSRGBColorSpace,t}const P=45,x=45,M=3,T=1.5,k=1,L=.5;let U,$,D,_,N,j=!1;const O=4,F=.001,W=1e-7,q=10,G=11,z=1/(G-1),Q="function"==typeof Float32Array;function V(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===r)return Y;const o=Q?new Float32Array(G):new Array(G);for(let t=0;t<G;++t)o[t]=X(t*z,e,n);function i(t){let r=0,i=1;const a=G-1;for(;i!==a&&o[i]<=t;++i)r+=z;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*z,l=Z(s,e,n);return l>=F?function(e,t,n,r){for(let o=0;o<O;++o){const o=Z(t,n,r);if(0===o)return t;t-=(X(t,n,r)-e)/o}return t}(t,s,e,n):0===l?s:function(e,t,n,r,o){let i,a,s=0;do{a=t+(n-t)/2,i=X(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>W&&++s<q);return a}(t,r,r+z,e,n)}return function(e){return 0===e||1===e?e:X(i(e),t,r)}}function K(e,t){return 1-3*t+3*e}function B(e,t){return 3*t-6*e}function H(e){return 3*e}function X(e,t,n){return((K(t,n)*e+B(t,n))*e+H(t))*e}function Z(e,t,n){return 3*K(t,n)*e*e+2*B(t,n)*e+H(t)}function Y(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=V(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function ee(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)})));let r=0,o=n[0].value;return{reset:()=>{r=0},update:e=>{for(r+=e;r>=t;)r-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(r>=t.time&&r<i.time){const e=t.interpolate((r-t.time)/(i.time-t.time));o=t.value+e*(i.value-t.value)}}},get:()=>o}}const te="#",ne="time",re="interpolation",oe="yaw",ie="pitch",ae="fov",se=[ne,oe,ie,ae,re],le="s",ce="ms",ue=1e3,de="deg",he="rad",fe=Math.PI/180,pe="ease-in-out",me="cubic-bezier(",ge=")";function ve(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(te);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const r=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!se.includes(r))throw new Error(`Invalid token in header: '${r}'.`);if(t.includes(r))throw new Error(`Duplicate token in header: '${r}'.`);t.push(r)}if(!t.includes(ne))throw new Error(`Missing required token: '${ne}'.`);return t}(t.split(/\s+/)),o={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=we(r,e);null!=t&&(null==o.theta&&(o.theta=[]),o.theta.push(t)),null!=n&&(null==o.phi&&(o.phi=[]),o.phi.push(n)),null!=i&&(null==o.fov&&(o.fov=[]),o.fov.push(i))}if(0===Object.values(o).length)throw new Error("At least one parameter should be animated.");return o}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const r of e){const{time:e,pitch:o,yaw:i,fov:a}=r;if(null==e)throw new Error("Time missing.");const s=be(null!==(t=r.interpolation)&&void 0!==t?t:pe);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*fe,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*fe,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*fe,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function we(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const r=e.indexOf(ne),o=function(e){if(e.endsWith(ce))return Ae(e.substring(0,e.length-ce.length));if(e.endsWith(le))return Ae(e.substring(0,e.length-le.length))*ue;return Ae(e)}(n[r]),i=e.indexOf(re),a=be(-1===i?pe:n[i]),s={};for(let t=0;t<n.length;t++){if(t===r||t===i)continue;const l=e[t],c=n[t];switch(l){case oe:s.theta={time:o,value:ye(c),interpolation:a};break;case ie:s.phi={time:o,value:ye(c),interpolation:a};break;case ae:s.fov={time:o,value:ye(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function ye(e){return e.endsWith(de)?Ae(e.substring(0,e.length-de.length))*fe:e.endsWith(he)?Ae(e.substring(0,e.length-he.length)):Ae(e)*fe}function be(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ee(0,0,1,1);if("sine"===e)return Ee(.37,0,.63,1);if("sine-in"===e)return Ee(.12,0,.39,0);if("sine-out"===e)return Ee(.61,1,.88,1);if("ease"===e)return Ee(.25,.1,.25,1);if("ease-in"===e)return Ee(.42,0,1,1);if("ease-out"===e)return Ee(0,0,.58,1);if("ease-in-out"===e)return Ee(.42,0,.58,1);if(e.startsWith(me)&&e.endsWith(ge)){const t=e.substring(me.length,e.length-ge.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ee(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Re=300,Se=2e3,Ce=.05,Ie=2*Math.PI/32,Pe=be("hold"),xe=be("sine"),Me=be("sine-in"),Te=be("sine-out");let ke;const Le=0;let Ue,$e,De,_e=!1,Ne=1,je=1,Oe=1;const Fe=1;let We;const qe=new Map;function Ge(e,n,r){const o=e.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,f,p,m,g,v,w=!1,y=!0,b=!1,E=!0,A=!1,k=!1,j=0,O=1,F=1,W=1;const q={threeInit:()=>{w||(ze(),i=new $e.Scene,a=new $e.PerspectiveCamera(25,1,.5),s=new Ue.OrbitControls(a,e),s.setInteractionEnabled(E),({renderShadow:c,shadowGroup:l}=function(e){const t=new U.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new U.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new U.Group;r.position.y=-.7;const o=new U.PlaneGeometry(P,x).rotateX(Math.PI/2),i=new U.MeshBasicMaterial({map:t.texture,opacity:L,transparent:!0,depthWrite:!1}),a=new U.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new U.Mesh(o);s.visible=!1,r.add(s);const l=new U.OrthographicCamera(-P/2,P/2,x/2,-x/2,0,M);function c(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,$.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,r.add(l),{shadowGroup:r,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=D;const r=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(T),c(.4*T),$.setRenderTarget(null),$.setClearAlpha(r),e.background=n}}}(i)),w=!0)},threeParse:(e,n,r)=>t(this,void 0,void 0,(function*(){return null!=u&&d===r||(yield u,u=(()=>t(this,void 0,void 0,(function*(){var t,r;return S=(t=Ue).THREE,C=new t.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;R=(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)}(We,Ue),r=e,R.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new $e.Box3).setFromObject(e.scene);l.position.y=n.min.y-Le,i.add(l),c(),i.traverse((e=>{if(e instanceof $e.Mesh){const t=e.material;t.depthWrite=!0,t instanceof $e.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt(Ue.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));s.reset(r,o,function(e,t){var n;const r={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?r.Glasses:null!==(n=r[e])&&void 0!==n?n:r.Glasses).normalize()}(t,$e.Vector3)),k=!0},threePaused:()=>y,threeResume:()=>{y=!1,We.setAnimationLoop(Qe),e.style.visibility="visible",j=0,null==f||f.reset(),null==p||p.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset()},threePause:()=>{y=!0,function(){for(const{threePaused:e}of qe.values())if(!e())return!1;return!0}()&&We.setAnimationLoop(null),e.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>({ACES:$e.ACESFilmicToneMapping,Linear:$e.LinearToneMapping,Neutral:$e.NeutralToneMapping}[e||"ACES"]||$e.ACESFilmicToneMapping),threeIsInteractive:()=>E,threeSetInteractive:e=>{E=e,null==s||s.setInteractionEnabled(E)},threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=ee([{time:0,value:e,interpolation:Pe},{time:Re,value:e,interpolation:Te},{time:Re+Se/4,value:e+Ie,interpolation:xe},{time:Re+3*Se/4,value:e-Ie,interpolation:Me},{time:Re+Se,value:e,interpolation:Pe},{time:Re+2*Se,value:e,interpolation:Pe}]),p=null,m=null,g=ee([{time:0,value:0,interpolation:Pe},{time:Re,value:1,interpolation:Pe},{time:Re+Se,value:0,interpolation:Pe},{time:Re+2*Se,value:0,interpolation:Pe}]),v=ee([{time:0,value:0,interpolation:Pe},{time:Re,value:0,interpolation:Te},{time:Re+Se/4,value:-Ce,interpolation:xe},{time:Re+3*Se/4,value:Ce,interpolation:Me},{time:Re+Se,value:0,interpolation:Pe},{time:Re+2*Se,value:0,interpolation:Pe}])},threeInitCameraAnimation:e=>{const{theta:t,phi:n,fov:r}=e;f=null!=t?ee(t):null,p=null!=n?ee(n):null,m=null!=r?ee(r):null},preRender_:e=>{if(!w||y)return;e=performance.now();const t=0!==j?e-j:0;j=e,k&&(b=!0,k=!1),A||(s.hasUserInteracted()?(A=!0,f=null,p=null,m=null,g=null,v=null):(null==f||f.update(t),null==p||p.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null!=f&&(s.setTheta(f.get()),b=!0),null!=p&&(s.setPhi(p.get()),b=!0),null!=m&&(s.setFovRadians(m.get()),b=!0))),s.update()&&(b=!0)},shouldRender_:()=>!(!w||y)&&b,render_:()=>{const t=We.toneMapping;We.setViewport(0,0,e.width,e.height),We.render(i,a),We.toneMapping=t,b=!1,null!=o&&(o.clearRect(0,0,e.width,e.height),De.width>0&&De.height>0&&o.drawImage(De,0,je-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=E&&!A?"visible":"hidden",null!=g&&(r.style.opacity=`${g.get()}`),null!=v&&(r.style.transform=`translateX(${v.get()*Math.min(O,F)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===O&&n===F&&Oe===W||(e.width=Math.ceil(t*Oe*Fe),e.height=Math.ceil(n*Oe*Fe),O=t,F=n,W=Oe,b=!0)},target_:e};return qe.set(e,q),q}function ze(){if(_e)return;Ue=window.ShopAR__THREE,$e=Ue.THREE,De=document.createElement("canvas");var e,t;De.style.position="block",We=new $e.WebGLRenderer({powerPreference:"high-performance",canvas:De,antialias:!0,alpha:!0}),We.outputColorSpace=$e.SRGBColorSpace,We.toneMapping=$e.ACESFilmicToneMapping,We.setClearColor(new $e.Color(16777215)),e=We,t=Ue,j||(U=t.THREE,$=e,D=new U.MeshDepthMaterial,D.userData.darkness={value:k},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,_=new U.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,N=new U.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,j=!0),Ve(),_e=!0}function Qe(e){Ve(),We.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of qe.values())t(e),n()&&r()}function Ve(){let e=0,t=0;for(const{target_:n}of qe.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=A();e=Math.ceil(e*n*Fe),t=Math.ceil(t*n*Fe),e===Ne&&t===je&&n===Oe||(Ne=e,je=t,Oe=n,We.setSize(Ne,je,!1));for(const{updateSize_:e}of qe.values())e()}const Ke={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Be=Object.keys(Ke);function He(e){return Ke[e]}const Xe="shopar-error";function Ze(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const r=document.createElementNS("http://www.w3.org/2000/svg","image");r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),r.setAttribute("width",e),r.setAttribute("height",e),n.appendChild(r)}return n}function Ye(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Ze("1.75rem",r);o.appendChild(e)}{const e=document.createElement("span");e.textContent=t,o.appendChild(e)}o.ariaLabel=n;return o.style.display="none",o}const Je="shopar-control";const et="shopar-deepar-output";function tt(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 nt(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function rt(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 ot(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 it="shopar-main";const at="shopar-qr-output";const st="shopar-three-output";var lt;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(lt||(lt={}));let ct=!1;function ut(){ct||(!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.")}}(),ct=!0)}function dt(){ut();const e=function(){const e=document.createElement("div");e.id=it;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=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),r=function(e,t){const n=document.createElement("div");n.id=at;const r=n.style;r.position="absolute",r.top="0",r.left="0",r.width="100%",r.height="100%",r.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o),o.appendChild(e);const a=document.createElement("div");return a.appendChild(t),o.appendChild(a),n}(t,n);e.appendChild(r);const o=function(){const e=document.createElement("div");e.id=et;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 i=function(){const e=document.createElement("canvas");e.id=st;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(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:r}=n;return r.position="absolute",r.width="100%",r.height="100%",r.pointerEvents="none",r.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=Ze("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=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}(c);e.appendChild(u);const d=tt("shopar-ar-loading-container"),h=nt("shopar-ar-loading-text",He("loading.ar"));d.appendChild(h);const f=rt("shopar-ar-loading-bar-bg"),p=ot("shopar-ar-loading-bar-fg");f.appendChild(p),d.appendChild(f),e.appendChild(d);const m=tt("shopar-3d-loading-container"),g=nt("shopar-3d-loading-text",He("loading.3d"));m.appendChild(g);const v=rt("shopar-3d-loading-bar-bg"),w=ot("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),E=function(e){const t=document.createElement("div");t.id=Xe;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const r=document.createElement("div"),o=r.style;return o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",t.appendChild(r),r.appendChild(e),t}(b);e.appendChild(E);const A=function(){const e=document.createElement("div");return e.id=Je,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(A);const R=Ye("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");A.appendChild(R);const S=Ye("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);A.appendChild(S);const C=Ye("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);A.append(C);let I,P=lt.None,x=!1,M=!1,T=!1,k=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function U(){w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return r},getQRImage:function(){return n},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){b.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,r,o){var i;x=e,M=t,T=n,k=r,I=o,ht(A,x),ht(R,x&&(T||M)&&P===lt.None),ht(S,x&&k&&P===lt.None),ht(C,x&&P!==lt.None),L(),U(),x||""===(i=E).style.display&&ht(i,!1)},getUIState:function(){return P},setUIState:function(e){P=e,P===lt.None?(L(),U(),x&&(ht(E,!1),ht(C,!1),(M||T)&&ht(R,!0),k&&ht(S,!0))):P!==lt.QR&&P!==lt.AR&&P!==lt.Preview||x&&(ht(E,!1),ht(R,!1),ht(S,!1),ht(C,!0))},setDefaultUIActions:function(e,t,n){x&&((M||T)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${y}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(I),R.onclick=e),k&&(S.onclick=t),C.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){w.classList.add("active"),m.style.visibility="visible"},stopThreeLoading:U,showCameraError:function(){x&&ht(E,!0)}}}function ht(e,t){e.style.display=t?"":"none"}const ft=new Map;function pt(e){let n=ft.get(e);return null==n?(n=function(){let e=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=dt()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==r){const{getQRTarget:e,getQRImage:n}=i();r=function(e,n){let r=!0;return{qrPaused:()=>r,qrDraw:(o,i)=>t(this,void 0,void 0,(function*(){yield E;const t=`https://apps.deepar.ai/${v.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:o,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,r=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){r=!0,e.style.display="none"}))}}(e(),n())}return r},findThree:()=>{if(null==o){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();o=Ge(e(),t(),n())}return o}}}(),ft.set(e,n)):n.incrementSetupId_(),n}function mt(e){for(const t of ft.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===lt.AR&&o(lt.None)}}let gt;const vt=new Uint8Array(16);function wt(){if(!gt&&(gt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!gt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return gt(vt)}const yt=[];for(let e=0;e<256;++e)yt.push((e+256).toString(16).slice(1));var bt={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Et(e,t,n){if(bt.randomUUID&&!t&&!e)return bt.randomUUID();const r=(e=e||{}).random||(e.rng||wt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return yt[e[t+0]]+yt[e[t+1]]+yt[e[t+2]]+yt[e[t+3]]+"-"+yt[e[t+4]]+yt[e[t+5]]+"-"+yt[e[t+6]]+yt[e[t+7]]+"-"+yt[e[t+8]]+yt[e[t+9]]+"-"+yt[e[t+10]]+yt[e[t+11]]+yt[e[t+12]]+yt[e[t+13]]+yt[e[t+14]]+yt[e[t+15]]}(r)}const At="qrLaunch",Rt="arLaunch",St="previewLaunch",Ct="heartbeat";let It,Pt,xt=!1;const Mt=[];function Tt(){null==It&&(Pt=Et(),It=b(`${y}/shopar-analytics.js`),It.then((()=>{xt=!0,window.ShopAR__analytics.initializeImpl(),Mt.forEach((e=>e()))})))}function kt(e){xt?e():Mt.push(e)}function Lt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ut(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 $t=200,Dt=10;let _t=!1,Nt=null,jt=[],Ot=[];function Ft(e){return t(this,void 0,void 0,(function*(){_t=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,e),Nt&&clearInterval(Nt);const r=[],o=[];Nt=setInterval((()=>t(this,void 0,void 0,(function*(){if(_t)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());_t||(null!=a&&null!=s&&function(e){for(let t of jt)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<Dt||(r.shift(),o.shift(),function(e,t){for(let n of Ot)n({faceWidth:e,IPD:t})}(qt(r),qt(o)))))}))),$t)}))}function Wt(){Ot=[],jt=[],_t=!0}function qt(e){let t=0;const n=e.length;for(let r=0;r<n;r++)t+=e[r];return t/n}function Gt(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>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 r.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}var zt="undefined"!=typeof Float32Array?Float32Array:Array;function Qt(){var e=new zt(16);return zt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Vt(e,t,n){var r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],f=t[10],p=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*r+b*s+E*d+A*m,e[1]=y*o+b*l+E*h+A*g,e[2]=y*i+b*c+E*f+A*v,e[3]=y*a+b*u+E*p+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*r+b*s+E*d+A*m,e[5]=y*o+b*l+E*h+A*g,e[6]=y*i+b*c+E*f+A*v,e[7]=y*a+b*u+E*p+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*r+b*s+E*d+A*m,e[9]=y*o+b*l+E*h+A*g,e[10]=y*i+b*c+E*f+A*v,e[11]=y*a+b*u+E*p+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*r+b*s+E*d+A*m,e[13]=y*o+b*l+E*h+A*g,e[14]=y*i+b*c+E*f+A*v,e[15]=y*a+b*u+E*p+A*w,e}function Kt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Bt(e,t){var n=t[0],r=t[1],o=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,r,o),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function Ht(e,t,n,r){var o=t[0],i=t[1],a=t[2],s=t[3],l=o+o,c=i+i,u=a+a,d=o*l,h=o*c,f=o*u,p=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=r[0],E=r[1],A=r[2];return e[0]=(1-(p+g))*b,e[1]=(h+y)*b,e[2]=(f-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(f+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+p))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Xt(){var e=new zt(3);return zt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Zt(e,t,n){var r=new zt(3);return r[0]=e,r[1]=t,r[2]=n,r}function Yt(e,t){var n=t[0]-e[0],r=t[1]-e[1],o=t[2]-e[2];return Math.hypot(n,r,o)}function Jt(e,t,n){var r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function en(){var e=new zt(4);return zt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Xt(),function(){var e,t=(e=new zt(4),zt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var tn;let nn,rn,on;Xt(),Zt(1,0,0),Zt(0,1,0),en(),en(),tn=new zt(9),zt!=Float32Array&&(tn[1]=0,tn[2]=0,tn[3]=0,tn[5]=0,tn[6]=0,tn[7]=0),tn[0]=1,tn[4]=1,tn[8]=1;let an,sn,ln,cn,un=!0,dn=null;const hn=new Set;let fn,pn,mn,gn,vn,wn,yn;function bn(){null==nn&&(nn=b(`${y}/shopar-deepar.js`))}function En(){null==rn&&(rn=b(`${y}/shopar-true-scale.js`))}function An(e){return t(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=e;return vn=o,null==fn&&(fn=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=Tn(ln),o=Lt(t);an=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:cn,additionalOptions:{hint:wn,cameraConfig:{disableDefaultCamera:!0}}}),sn=yield Ut(o),yield kn(an,sn,"user"===t),"Glasses"===ln&&(yield rn,Ft(sn),"DetectionLoop"!==vn&&Dn((e=>{gn=e.faceWidth})))})))()),fn}))}function Rn(e,t){var n,r;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===ln&&(n=t,r=wn,n===r||null!=n&&null!=r&&n.length===r.length&&n.every((e=>r.find((t=>e===t))))&&r.every((e=>n.find((t=>t===e))))))||(null!=an&&(an.shutdown(),an=null,fn=null),ln=e,wn=t)}function Sn(e){e!==cn&&(cn=e,null!=an&&an.changePreviewElement(cn))}function Cn(e){dn=e}function In(e){an.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(gn){const e=137/(gn+5);an.changeParameterVector("GLASSES","","scale",e,e,e,0),an.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const r=Un("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=Un("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);an.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),an.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),Wt(),gn=null}e(),Ln("Glasses")}},an.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Ln("Shoes"))},an.callbacks.onWristTracked=t=>{t.detected&&(e(),Ln("Watches"))}}function Pn(e,n){return t(this,void 0,void 0,(function*(){return null!=pn&&mn===n||(yield pn,pn=an.switchEffect(e),mn=n),pn}))}function xn(){return t(this,void 0,void 0,(function*(){if(null!=an){if(un=!1,null==sn){const e=Tn(ln),t=Lt(e);sn=yield Ut(t),yield kn(an,sn,"user"===e),Ft(sn),"DetectionLoop"!==vn&&Dn((e=>{gn=e.faceWidth}))}!function(){if(null==dn)return;if(null==ln||hn.has(ln))return;dn.style.visibility="visible",dn.style.opacity="1"}(),an.setPaused(un),cn.style.display=""}}))}function Mn(){null!=an&&(un=!0,an.setPaused(un),Wt(),null!=sn&&null!=sn.srcObject&&sn.srcObject instanceof MediaStream&&(sn.srcObject.getTracks().forEach((e=>e.stop())),sn=null),function(){if(null==dn)return;dn.style.visibility="hidden",dn.style.opacity="0"}(),an.stopCamera(),cn.style.display="none")}function Tn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function kn(e,n,r){return t(this,void 0,void 0,(function*(){yield new Promise((o=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,r),o()}))))}}))}))}function Ln(e){null!=dn&&(hn.has(e)||(hn.add(e),dn.style.opacity="0"))}function Un(e,t,n,r,o,i,a){const s=an.getTransformationBetween(e,t),l=Kt(Xt(),s),c=function(e,t){var n=new zt(3);Bt(n,t);var r=1/n[0],o=1/n[1],i=1/n[2],a=t[0]*r,s=t[1]*o,l=t[2]*i,c=t[4]*r,u=t[5]*o,d=t[6]*i,h=t[8]*r,f=t[9]*o,p=t[10]*i,m=a+u+p,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-f)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>p?(g=2*Math.sqrt(1+a-u-p),e[3]=(d-f)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>p?(g=2*Math.sqrt(1+u-a-p),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+f)/g):(g=2*Math.sqrt(1+p-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+f)/g,e[2]=.25*g),e}(en(),s);Ht(s,c,l,Zt(a,a,a));const u=an.getTransformationBetween(t,n),d=Kt(Xt(),u);Ht(u,en(),d,Bt(Xt(),u));const h=Vt(Qt(),s,u),f=Kt(Xt(),h),p=Math.atan2(i[0]-f[0],Math.abs(i[2]-f[2]));let m;try{m=an.getTransformationBetween(n,r)}catch(e){return p}const g=Vt(Qt(),u,m),v=Vt(Qt(),s,g),w=Zt(f[0],i[1],i[2]),y=Jt(Xt(),w,function(e,t){var n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],f=t[11],p=t[12],m=t[13],g=t[14],v=t[15],w=n*s-r*a,y=n*l-o*a,b=n*c-i*a,E=r*l-o*s,A=r*c-i*s,R=o*c-i*l,S=u*m-d*p,C=u*g-h*p,I=u*v-f*p,P=d*g-h*m,x=d*v-f*m,M=h*v-f*g,T=w*M-y*x+b*P+E*I-A*C+R*S;return T?(T=1/T,e[0]=(s*M-l*x+c*P)*T,e[1]=(o*x-r*M-i*P)*T,e[2]=(m*R-g*A+v*E)*T,e[3]=(h*A-d*R-f*E)*T,e[4]=(l*I-a*M-c*C)*T,e[5]=(n*M-o*I+i*C)*T,e[6]=(g*b-p*R-v*y)*T,e[7]=(u*R-h*b+f*y)*T,e[8]=(a*x-s*I+c*S)*T,e[9]=(r*I-n*x-i*S)*T,e[10]=(p*A-m*b+v*w)*T,e[11]=(d*b-u*A-f*w)*T,e[12]=(s*C-a*P-l*S)*T,e[13]=(n*P-r*C+o*S)*T,e[14]=(m*y-p*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Qt(),v));let b=an.getClosestPointOnMesh(r,y);try{const e=an.getClosestPointOnMesh(o,y);Yt(y,e)<Yt(y,b)&&(b=e)}catch(e){}const E=Jt(Xt(),b,g);return p-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function $n(e){!function(e){jt.push(e)}(e)}function Dn(e){!function(e){Ot.push(e)}(e)}function _n(e,o,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 d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>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 r[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(u[c]=Math.min(76,o)*((a>>5)-1),152===u[c]&&(u[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)u[c]^=u[i]<<13,u[c]^=u[i]>>17,u[c]^=u[i]<<5,v[e]=v[e]^u[c];return i^=u[0],i^=u[1],i^=u[2],v}))}function Nn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function jn(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function On(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Fn=["AR","3D"];function Wn(e){const{apiKey:t,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;Nn(t,"apiKey"),On(t,"apiKey"),Nn(r,"sku"),On(r,"sku"),Nn(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,r){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!r.includes(e))throw new n(`'${t}' must be ${r.join("' or '")}.`)}(i,"initialState",Fn),null!=a&&function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new n(`'${t}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&On(s,"baseUrl"),null!=l&&jn(l,"defaultUI"),null!=c&&jn(c,"interactive"),null!=u&&function(e,t,r){for(const o of r){const r=e[o];if(null!=r&&"string"!=typeof r)throw new n(`Value for key '${o}' in '${t}' must be a string.`)}}(u,"strings",Be)}let qn=!1;function Gn(e){return t(this,void 0,void 0,(function*(){const{targetElement:r}=e;y.update(e.baseUrl),Tt();const{trackEvent:o}=function(e){const t=performance.now(),n=Et();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:v,sessionId:Pt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),kt((()=>{window.ShopAR__analytics.trackEventImpl(r,o)}))}}}(e.apiKey);o("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,sid:d()})}`).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.")}}))}(e.apiKey);o("visionApiResponse",i);const{arKey:a}=i,s=pt(r),{getSetupId:l,findUI:c}=s,u=l();bn(),En();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:E,showCameraError:A}=c();if(g()!=lt.None)throw Error("UI state is not None, this is weird..");w(lt.AR),h(r),m(!1,!1,!0,!1,void 0),b(),yield nn,zn(l(),u);try{o("visionArLaunch"),Mn(),Rn("Glasses",["faceInit"]),Sn(f()),yield An({licenseKey:a,truescaleUsecase:"DetectionLoop"}),zn(l(),u),yield xn(),zn(l(),u)}catch(e){const t=e instanceof Error;throw o("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),Mn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{E()}return qn=!0,{registerFacePoseListener:e=>{qn&&(o("registerFacePoseListener"),$n(e))},registerFaceMeasurementListener:e=>{qn&&(o("registerFaceMeasurementListener"),Dn(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){qn&&(o("switchEffect",{arUrl:e}),function(e){an.switchEffect(e)}(e))})),clearEffect:()=>{qn&&(o("clearEffect"),an.clearEffect())},close:()=>{if(qn){if(qn=!1,o("visionClose"),g()!==lt.AR)throw new n("AR not launched.");Mn(),w(lt.None)}}}}))}function zn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function Qn(e){var r,o;return t(this,void 0,void 0,(function*(){Wn(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=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(Ke,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Ke[t]=n)}}(e.strings);const u=null!=c?ve(c):null,h=function(e,r){return t(this,void 0,void 0,(function*(){const o=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:r,sid:d()})}`).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 o.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a),f=pt(s),{getSetupId:w,findUI:A,findQR:R,findThree:S}=f,C=w();Tt();const{trackEvent:I,arInteracted:P,previewInteracted:x}=function(e,t){const n=performance.now(),r=Et();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(Ct,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:Pt,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),kt((()=>{window.ShopAR__analytics.trackEventImpl(o,i)}))};return{trackEvent:u,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)}}}(a,i);I("setup",{hostname:window.location.hostname});const M=yield h;I("apiResponse",M);const{category:T,arUrl:k,arKey:L,arPromptEnabled:U,arPromptText:$,arPromptImage:D,previewUrl:_,previewEnvUrl:N,previewToneMapping:j,cameraErrorText:O,qrPromptText:F}=M;Vn(w(),C);const W=null!=k&&function(e){return null!=e&&m.includes(e)}(T),q=null==(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled),G=W&&function(e){return null!=e&&g.includes(e)}(T),z=q&&G&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==yn&&(yn=b(`${y}/shopar-platform.js`)),yield yn,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}()),Q=W&&!z,V=null!=_;if(Vn(w(),C),z&&function(){t(this,void 0,void 0,(function*(){null==E&&(E=b(`${y}/shopar-qr.js`))}))}(),Q&&(bn(),function(e){e!==on&&(on=e,Gt(e),pn=null,Wt())}(k),"Glasses"===T&&En()),V){null==ke&&(ke=b(`${y}/shopar-three.js`));const e=255;_n(_,(new Date).getTime()+e,Math.random()*e),Gt(null!=N?N:`${y}/env/default.hdr`)}const{setTargetElement:K,getDeepARTarget:B,getDeepARPrompt:H,customizeDeepARPrompt:X,customizeCameraError:Z,customizeQRPrompt:Y,setVisibilityParameters:J,getUIState:ee,setUIState:te,setDefaultUIActions:ne,startDeepARLoading:re,stopDeepARLoading:oe,startThreeLoading:ie,stopThreeLoading:ae,showCameraError:se}=A();K(s);J(null==e.defaultUI||e.defaultUI,z,Q,V,T),X(null!=$?$:"",null!=D?D:""),Z(O),Y(F),function(e,t){const r=e.parentNode;if(null==r)throw new n("Parent node missing.");new MutationObserver((n=>{for(const r of n)for(const n of r.removedNodes)if(n===e)return void t()})).observe(r,{childList:!0})}(s,(()=>{ee()!==lt.QR||le()||ue(),ee()!==lt.AR||un||Mn(),ee()!==lt.Preview||pe()||ge(),te(lt.None)}));const{qrPaused:le,qrDraw:ce,qrPause:ue}=R(),{threeInit:de,threeParse:he,threeLoad:fe,threePaused:pe,threeResume:me,threePause:ge,threeSetToneMapping:we,threeIsInteractive:ye,threeSetInteractive:be,threeSetOnInteracted:Ee,threeInitPromptAnimation:Ae,threeInitCameraAnimation:Re}=S(),Se=null==e.interactive||e.interactive;be(Se);let Ce=0;if(ee()===lt.QR){if(!le())if(z){I(At);try{yield ce(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ue(),te(lt.None)}else if(ee()===lt.AR){if(!un)if(Q&&!qn){I(Rt);const e=yield Gt(k);Vn(w(),C),mt(f),Rn(T),Sn(B()),Cn(U?H():null),yield Pn(e,k),In(P),Vn(w(),C)}else Mn(),te(lt.None)}else if(ee()===lt.Preview&&!pe())if(V){I(St),ie();const e=255,t=yield _n(_,(new Date).getTime()+e,Math.random()*e);Vn(w(),C);const n=yield Gt(null!=N?N:`${y}/env/default.hdr`);Vn(w(),C);const r=yield he(t,n,`${_}${N}`);Vn(w(),C),fe(r,T),we(null!=j?j:"ACES"),Ee(x),ae()}else ge(),te(lt.None);const Ie=()=>t(this,void 0,void 0,(function*(){if(z){if(ee()===lt.QR||ee()===lt.AR)throw new n("AR already launched.");try{I(At);const e=++Ce;if(ee()===lt.Preview&&V&&!pe()&&ge(),te(lt.QR),yield ce(i,a),Ce!==e)return;return void Vn(w(),C)}catch(e){const t=e instanceof Error;throw I("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(ee()===lt.AR)throw new n("AR already launched.");try{I(Rt);const e=++Ce;ee()===lt.Preview&&V&&!pe()&&ge(),mt(f),te(lt.AR),re();const t=yield Gt(k);if(Ce!==e)return;if(Vn(w(),C),yield nn,Ce!==e)return;if(Vn(w(),C),Mn(),Rn(T),Sn(B()),Cn(U?H():null),yield An({licenseKey:L}),Ce!==e)return;if(Vn(w(),C),yield Pn(t,k),In(P),Ce!==e)return;if(Vn(w(),C),yield xn(),Ce!==e)return;Vn(w(),C)}catch(e){const t=e instanceof Error;throw I("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se(),Mn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{oe()}})),Pe=()=>t(this,void 0,void 0,(function*(){if(!V)throw new n("Model does not have 3D enabled.");if(ee()===lt.Preview)throw new n("3D already launched.");try{I(St);const e=++Ce;ee()===lt.AR&&(Q&&!un&&Mn(),ue()),te(lt.Preview),ie();const t=255,n=yield _n(_,(new Date).getTime()+t,Math.random()*t);if(Ce!==e)return;Vn(w(),C);const r=yield Gt(null!=N?N:`${y}/env/default.hdr`);if(Ce!==e)return;if(Vn(w(),C),yield ke,Ce!==e)return;if(Vn(w(),C),de(),Ce!==e)return;Vn(w(),C);const o=yield he(n,r,`${_}${N}`);if(Ce!==e)return;Vn(w(),C),fe(o,T),we(null!=j?j:"ACES"),Ee(x),Ae(),null!=u&&Re(u),me()}catch(e){const t=e instanceof Error;throw I("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{ae()}})),xe=()=>t(this,void 0,void 0,(function*(){if(ee()===lt.None)throw new n("Neither AR or 3D launched.");++Ce,ee()===lt.QR||ee()===lt.AR?(Q&&!un&&Mn(),ue()):ee()===lt.Preview&&V&&!pe()&&ge(),te(lt.None)}));return ne(Ie,Pe,xe),"AR"===l?(yield Ie(),Vn(w(),C)):"3D"===l&&(yield Pe(),Vn(w(),C)),qn=!1,{launchAR:W?Ie:void 0,launch3D:V?Pe:void 0,closeAR:W?()=>t(this,void 0,void 0,(function*(){if(ee()!==lt.AR&&ee()!==lt.QR)throw new n("AR not launched.");++Ce,Q&&!un&&Mn(),ue(),te(lt.None)})):void 0,close3D:V?()=>t(this,void 0,void 0,(function*(){if(ee()!==lt.Preview)throw new n("3D not launched.");++Ce,V&&!pe()&&ge(),te(lt.None)})):void 0,close:W||V?xe:void 0,isInteractive:()=>ye(),setInteractive:e=>be(e)}}))}function Vn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Kn={setup:function(e){return t(this,void 0,void 0,(function*(){return Gn(e)}))}},Bn={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,r){return t(this,void 0,void 0,(function*(){try{return r()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Qn(e)))}))},version:v};e.plugin=Bn,e.vision=Kn}));