shopar-plugin 0.1.2-alpha.0 → 0.1.2-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{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 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),c=s^s,l=new n[1]([c]);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.2-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 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 R,E,A;function C(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}(A.parse(e));return t.mapping=E.EquirectangularReflectionMapping,t.colorSpace=E.LinearSRGBColorSpace,t}const M=45,P=45,I=3,T=1.5,L=1,x=.5;let k,U,D,$,_,N,j=!1;const O=0,F=300,q=2e3,G=.05,W=1/(32*Math.PI);let V,K,Q,B=!1,H=1,z=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,c,l,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,S=1,L=1,N=1;const j={threeInit:()=>{f||(te(),i=new K.Scene,a=new K.PerspectiveCamera(25,1,.5),s=new V.OrbitControls(a,t),s.enableInteraction(),({renderShadow:l,shadowGroup:c}=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(M,P).rotateX(Math.PI/2),i=new k.MeshBasicMaterial({map:t.texture,opacity:x,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 c=new k.OrthographicCamera(-M/2,M/2,P/2,-P/2,0,I);function l(e){s.visible=!0,$.uniforms.tDiffuse.value=t.texture,$.uniforms.h.value=1*e/256,s.material=$,U.setRenderTarget(n),U.render(s,c),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,U.setRenderTarget(t),U.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=D;const o=U.getClearAlpha();U.setClearAlpha(0),U.setRenderTarget(t),U.render(e,c),e.overrideMaterial=null,l(T),l(.4*T),U.setRenderTarget(null),U.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=V).THREE,A=new e.RGBELoader,i.environment=C(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)}(Y,V),o=t,R.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-O,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,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: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>F&&y<=F+q))return o.style.opacity="0",void(y>F+2*q&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-F,t=2*Math.PI/q*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${G*r*Math.min(S,L)}px)`,s.updateTheta(W*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(Q,0,z-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===S&&n===L&&X===N||(t.width=Math.ceil(e*X*Z),t.height=Math.ceil(n*X*Z),S=e,L=n,N=X,g=!0)},target_:t};return J.set(t,j),j}function te(){if(B)return;V=window.ShopAR__THREE,K=V.THREE,Q=document.createElement("canvas");var e,t;Q.style.position="block",Y=new K.WebGLRenderer({powerPreference:"high-performance",canvas:Q,antialias:!0,alpha:!0}),Y.outputColorSpace=K.SRGBColorSpace,Y.toneMapping=K.ACESFilmicToneMapping,Y.setClearColor(new K.Color(16777215)),e=Y,t=V,j||(k=t.THREE,U=e,D=new k.MeshDepthMaterial,D.userData.darkness={value:L},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 k.ShaderMaterial(t.HorizontalBlurShader),$.depthTest=!1,_=new k.ShaderMaterial(t.VerticalBlurShader),_.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=S();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===H&&t===z&&n===X||(H=e,z=t,X=n,Y.setSize(H,z,!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 ce="shopar-error";function le(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 Se(){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 Re(){Se();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 c=function(){const e=se("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),l=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(l);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=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=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 S=le("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(S);const R=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);b.appendChild(R);const E=le("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);b.append(E);let A,C=ye.None,M=!1,P=!1,I=!1,T=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function x(){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 l},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;M=e,P=t,I=n,T=o,A=r,Ee(b,M),Ee(S,M&&(I||P)&&C===ye.None),Ee(R,M&&T&&C===ye.None),Ee(E,M&&C!==ye.None),L(),x(),M||""===(i=y).style.display&&Ee(i,!1)},getUIState:function(){return C},setUIState:function(e){C=e,C===ye.None?(L(),x(),M&&(Ee(y,!1),Ee(E,!1),(P||I)&&Ee(S,!0),T&&Ee(R,!0))):C!==ye.QR&&C!==ye.AR&&C!==ye.Preview||M&&(Ee(y,!1),Ee(S,!1),Ee(R,!1),Ee(E,!0))},setDefaultUIActions:function(e,t,n){M&&((P||I)&&(!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}`;S.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(A),S.onclick=e),T&&(R.onclick=t),E.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:x,showCameraError:function(){M&&Ee(y,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Ae=new Map;function Ce(t){let n=Ae.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Re()),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}}}(),Ae.set(t,n)):n.incrementSetupId_(),n}function Me(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()===ye.AR&&r(ye.None)}}let Pe;const Ie=new Uint8Array(16);function Te(){if(!Pe&&(Pe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Pe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Pe(Ie)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var xe={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(xe.randomUUID&&!t&&!e)return xe.randomUUID();const o=(e=e||{}).random||(e.rng||Te)();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 Ue="qrLaunch",De="arLaunch",$e="previewLaunch",_e="heartbeat";let Ne,je,Oe=!1;const Fe=[];function qe(){null==Ne&&(je=ke(),Ne=y(`${w}/shopar-analytics.js`),Ne.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),Fe.forEach((e=>e()))})))}function Ge(e){Oe?e():Fe.push(e)}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ve(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 Ke=200,Qe=10;let Be=!1,He=null,ze=[],Xe=[];function Ze(t){return e(this,void 0,void 0,(function*(){Be=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${w}/wasm/mediapipe`,t),He&&(console.log("previous interval present, clearing"),clearInterval(He));const o=[],r=[];He=setInterval((()=>e(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 ze)t(e)}({translation:a,rotation:s}),null==e?(o.push(t),r.push(i),o.length<Qe||(o.shift(),r.shift(),function(e,t){for(let n of Xe)n({faceWidth:e,IPD:t})}(Je(o),Je(r)))):console.error(`TrueScale predict error: ${e}`))}))),Ke)}))}function Ye(){Xe=[],ze=[],Be=!0}function Je(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function et(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.")}}))}var tt="undefined"!=typeof Float32Array?Float32Array:Array;function nt(){var e=new tt(16);return tt!=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 ot(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],S=n[2],R=n[3];return e[0]=y*o+b*s+S*u+R*m,e[1]=y*r+b*c+S*h+R*g,e[2]=y*i+b*l+S*p+R*v,e[3]=y*a+b*d+S*f+R*w,y=n[4],b=n[5],S=n[6],R=n[7],e[4]=y*o+b*s+S*u+R*m,e[5]=y*r+b*c+S*h+R*g,e[6]=y*i+b*l+S*p+R*v,e[7]=y*a+b*d+S*f+R*w,y=n[8],b=n[9],S=n[10],R=n[11],e[8]=y*o+b*s+S*u+R*m,e[9]=y*r+b*c+S*h+R*g,e[10]=y*i+b*l+S*p+R*v,e[11]=y*a+b*d+S*f+R*w,y=n[12],b=n[13],S=n[14],R=n[15],e[12]=y*o+b*s+S*u+R*m,e[13]=y*r+b*c+S*h+R*g,e[14]=y*i+b*l+S*p+R*v,e[15]=y*a+b*d+S*f+R*w,e}function rt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function it(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 at(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],S=o[1],R=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)*S,e[5]=(1-(u+g))*S,e[6]=(m+v)*S,e[7]=0,e[8]=(p+w)*R,e[9]=(m-v)*R,e[10]=(1-(u+f))*R,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function st(){var e=new tt(3);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function ct(e,t,n){var o=new tt(3);return o[0]=e,o[1]=t,o[2]=n,o}function lt(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 dt(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 ut(){var e=new tt(4);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}st(),function(){var e,t=(e=new tt(4),tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var ht;let pt,ft,mt;st(),ct(1,0,0),ct(0,1,0),ut(),ut(),ht=new tt(9),tt!=Float32Array&&(ht[1]=0,ht[2]=0,ht[3]=0,ht[5]=0,ht[6]=0,ht[7]=0),ht[0]=1,ht[4]=1,ht[8]=1;let gt,vt,wt,yt,bt=!0,St=null;const Rt=new Set;let Et,At,Ct,Mt,Pt,It,Tt;function Lt(){null==pt&&(pt=y(`${w}/shopar-deepar.js`))}function xt(){null==ft&&(ft=y(`${w}/shopar-true-scale.js`))}function kt(n){return e(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=n;return Pt=r,null==Et&&(Et=(()=>e(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 t("No camera available!");var e;const n=Ft(wt),r=We(n);gt=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:yt,additionalOptions:{hint:It,cameraConfig:{disableDefaultCamera:!0}}}),vt=yield Ve(r),yield qt(gt,vt,"user"===n),"Glasses"===wt&&(yield ft,Ze(vt),"DetectionLoop"!==Pt&&Kt((e=>{Mt=e.faceWidth})))})))()),Et}))}function Ut(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===wt&&(n=t,o=It,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!=gt&&(gt.shutdown(),gt=null,Et=null),wt=e,It=t)}function Dt(e){e!==yt&&(yt=e,null!=gt&>.changePreviewElement(yt))}function $t(e){St=e}function _t(e){gt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Mt){const e=137/(Mt+5);gt.changeParameterVector("GLASSES","","scale",e,e,e,0),gt.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=Wt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Wt("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);gt.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),gt.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return void console.error(e)}}(e),Ye(),Mt=null}e(),Gt("Glasses")}},gt.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Gt("Shoes"))},gt.callbacks.onWristTracked=t=>{t.detected&&(e(),Gt("Watches"))}}function Nt(t,n){return e(this,void 0,void 0,(function*(){return null!=At&&Ct===n||(yield At,At=gt.switchEffect(t),Ct=n),At}))}function jt(){return e(this,void 0,void 0,(function*(){if(null!=gt){if(bt=!1,null==vt){const e=Ft(wt),t=We(e);vt=yield Ve(t),yield qt(gt,vt,"user"===e),Ze(vt),"DetectionLoop"!==Pt&&Kt((e=>{Mt=e.faceWidth}))}!function(){if(null==St)return;if(null==wt||Rt.has(wt))return;St.style.visibility="visible",St.style.opacity="1"}(),gt.setPaused(bt),yt.style.display=""}}))}function Ot(){null!=gt&&(bt=!0,gt.setPaused(bt),Ye(),null!=vt&&null!=vt.srcObject&&vt.srcObject instanceof MediaStream&&(vt.srcObject.getTracks().forEach((e=>e.stop())),vt=null),function(){if(null==St)return;St.style.visibility="hidden",St.style.opacity="0"}(),gt.stopCamera(),yt.style.display="none")}function Ft(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function qt(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 Gt(e){null!=St&&(Rt.has(e)||(Rt.add(e),St.style.opacity="0"))}function Wt(e,t,n,o,r,i,a){const s=gt.getTransformationBetween(e,t),c=rt(st(),s),l=function(e,t){var n=new tt(3);it(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}(ut(),s);at(s,l,c,ct(a,a,a));const d=gt.getTransformationBetween(t,n),u=rt(st(),d);at(d,ut(),u,it(st(),d));const h=ot(nt(),s,d),p=rt(st(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=gt.getTransformationBetween(n,o)}catch(e){return console.error(e),f}const g=ot(nt(),d,m),v=ot(nt(),s,g),w=ct(p[0],i[1],i[2]),y=dt(st(),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,S=o*c-r*s,R=o*l-i*s,E=r*l-i*c,A=d*m-u*f,C=d*g-h*f,M=d*v-p*f,P=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*P+S*M-R*C+E*A;return L?(L=1/L,e[0]=(s*T-c*I+l*P)*L,e[1]=(r*I-o*T-i*P)*L,e[2]=(m*E-g*R+v*S)*L,e[3]=(h*R-u*E-p*S)*L,e[4]=(c*M-a*T-l*C)*L,e[5]=(n*T-r*M+i*C)*L,e[6]=(g*b-f*E-v*y)*L,e[7]=(d*E-h*b+p*y)*L,e[8]=(a*I-s*M+l*A)*L,e[9]=(o*M-n*I-i*A)*L,e[10]=(f*R-m*b+v*w)*L,e[11]=(u*b-d*R-p*w)*L,e[12]=(s*C-a*P-c*A)*L,e[13]=(n*P-o*C+r*A)*L,e[14]=(m*y-f*S-g*w)*L,e[15]=(d*S-u*y+h*w)*L,e):null}(nt(),v));let b=gt.getClosestPointOnMesh(o,y);try{const e=gt.getClosestPointOnMesh(r,y);lt(y,e)<lt(y,b)&&(b=e)}catch(e){console.error(e)}const S=dt(st(),b,g);return f-Math.atan2(S[0]-u[0],Math.abs(S[2]-u[2]))}function Vt(e){!function(e){ze.push(e)}(e)}function Kt(e){!function(e){Xe.push(e)}(e)}function Qt(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(l[c]=Math.min(76,r)*((a>>5)-1),152===l[c]&&(l[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)l[c]^=l[i]<<13,l[c]^=l[i]>>17,l[c]^=l[i]<<5,v[e]=v[e]^l[c];return i^=l[0],i^=l[1],i^=l[2],v}))}function Bt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Ht(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const zt=["AR","3D"];function Xt(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;Bt(n,"apiKey"),Ht(n,"apiKey"),Bt(o,"sku"),Ht(o,"sku"),Bt(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",zt),null!=a&&Ht(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=c&&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.`)}}(c,"strings",ie)}let Zt=!1;function Yt(n){return e(this,void 0,void 0,(function*(){const{targetElement:o}=n;w.update(n.baseUrl),qe();const{trackEvent:r}=function(e){const t=performance.now(),n=ke();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:g,sessionId:je,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Ge((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(n.apiKey);r("visionSetup");const i=yield function(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:n,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 o.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(n.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Ce(o),{getSetupId:c,findUI:l}=s,u=c();Lt(),xt();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:v,setUIState:y,startDeepARLoading:b,stopDeepARLoading:S,showCameraError:R}=l();if(v()!=ye.None)throw Error("UI state is not None, this is weird..");y(ye.AR),h(o),m(!1,!1,!0,!1,void 0),b(),yield pt,Jt(c(),u);try{r("visionArLaunch"),Ot(),Ut("Glasses",["faceInit"]),Dt(f()),yield kt({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Jt(c(),u),yield jt(),Jt(c(),u)}catch(e){const n=e instanceof Error;throw r("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),R(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{S()}return Zt=!0,{registerFacePoseListener:e=>{Zt&&(r("registerFacePoseListener"),Vt(e))},registerFaceMeasurementListener:e=>{Zt&&(r("registerFaceMeasurementListener"),Kt(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Zt&&(r("switchEffect",{arUrl:t}),function(e){gt.switchEffect(e)}(t))})),clearEffect:()=>{Zt&&(r("clearEffect"),gt.clearEffect())}}}))}function Jt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function en(n){var o,r;return e(this,void 0,void 0,(function*(){Xt(n);const{apiKey:i,sku:a,targetElement:s,initialState:c}=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 l=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=Ce(s),{getSetupId:h,findUI:v,findQR:S,findThree:R}=u,E=h();qe();const{trackEvent:A,arInteracted:C,previewInteracted:M}=function(e,t){const n=performance.now(),o=ke();let r=0,i=0,a=0,s=0,c=0,l=!1;window.setInterval((()=>{l&&(r=i+a,l=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Ge((()=>{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);A("setup",{hostname:window.location.hostname});const P=yield l;A("apiResponse",P);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_}=P;tn(h(),E);const j=null!=T&&function(e){return null!=e&&f.includes(e)}(I),O=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),F=j&&function(e){return null!=e&&m.includes(e)}(I),q=O&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==Tt&&(Tt=y(`${w}/shopar-platform.js`)),yield Tt,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),G=j&&!q,W=null!=D;if(tn(h(),E),q&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),G&&(Lt(),function(e){e!==mt&&(mt=e,et(e),At=null,Ye())}(T),"Glasses"===I&&xt()),W){null==N&&(N=y(`${w}/shopar-three.js`));const e=255;Qt(D,(new Date).getTime()+e,Math.random()*e),et(null!=$?$:`${w}/env/default.hdr`)}const{setTargetElement:V,getDeepARTarget:K,getDeepARPrompt:Q,customizeDeepARPrompt:B,setVisibilityParameters:H,getUIState:z,setUIState:X,setDefaultUIActions:Z,startDeepARLoading:Y,stopDeepARLoading:J,startThreeLoading:ee,stopThreeLoading:te,showCameraError:ne}=v();V(s);H(null==n.defaultUI||n.defaultUI,q,G,W,I),B(null!=k?k:"",null!=U?U:""),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||oe()||ae(),z()!==ye.AR||bt||Ot(),z()!==ye.Preview||de()||he(),X(ye.None)}));const{qrPaused:oe,qrDraw:ie,qrPause:ae}=S(),{threeInit:se,threeParse:ce,threeLoad:le,threePaused:de,threeResume:ue,threePause:he,threeSetToneMapping:pe,threeSetOnInteracted:fe}=R();let me=0;if(z()===ye.QR){if(!oe())if(q){A(Ue);try{yield ie(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ae(),X(ye.None)}else if(z()===ye.AR){if(!bt)if(G){A(De);const e=yield et(T);tn(h(),E),Me(u),Ut(I),Dt(K()),$t(x?Q():null),yield Nt(e,T),_t(C),tn(h(),E)}else Ot(),X(ye.None)}else if(z()===ye.Preview&&!de())if(W){A($e),ee();const e=255,t=yield Qt(D,(new Date).getTime()+e,Math.random()*e);tn(h(),E);const n=yield et(null!=$?$:`${w}/env/default.hdr`);tn(h(),E);const o=yield ce(t,n,`${D}${$}`);tn(h(),E),le(o,I),pe(null!=_?_:"ACES"),fe(M),te()}else he(),X(ye.None);const ge=()=>e(this,void 0,void 0,(function*(){if(q){if(z()===ye.QR||z()===ye.AR)throw new t("AR already launched.");try{A(Ue);const e=++me;if(z()===ye.Preview&&W&&!de()&&he(),X(ye.QR),yield ie(i,a),me!==e)return;return void tn(h(),E)}catch(e){const n=e instanceof Error;throw A("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!G)throw new t("Model does not have AR enabled.");if(z()===ye.AR)throw new t("AR already launched.");try{A(De);const e=++me;z()===ye.Preview&&W&&!de()&&he(),Me(u),X(ye.AR),Y();const t=yield et(T);if(me!==e)return;if(tn(h(),E),yield pt,me!==e)return;if(tn(h(),E),Ot(),Ut(I),Dt(K()),$t(x?Q():null),yield kt({licenseKey:L}),me!==e)return;if(tn(h(),E),yield Nt(t,T),_t(C),me!==e)return;if(tn(h(),E),yield jt(),me!==e)return;tn(h(),E)}catch(e){const n=e instanceof Error;throw A("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),ne(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{J()}})),ve=()=>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{A($e);const e=++me;z()===ye.AR&&(G&&!bt&&Ot(),ae()),X(ye.Preview),ee();const t=255,n=yield Qt(D,(new Date).getTime()+t,Math.random()*t);if(me!==e)return;tn(h(),E);const o=yield et(null!=$?$:`${w}/env/default.hdr`);if(me!==e)return;if(tn(h(),E),yield N,me!==e)return;if(tn(h(),E),se(),me!==e)return;tn(h(),E);const r=yield ce(n,o,`${D}${$}`);if(me!==e)return;tn(h(),E),le(r,I),pe(null!=_?_:"ACES"),fe(M),ue()}catch(e){const n=e instanceof Error;throw A("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{te()}})),we=()=>e(this,void 0,void 0,(function*(){if(z()===ye.None)throw new t("Neither AR or 3D launched.");++me,z()===ye.QR||z()===ye.AR?(G&&!bt&&Ot(),ae()):z()===ye.Preview&&W&&!de()&&he(),X(ye.None)}));return Z(ge,ve,we),"AR"===c?(yield ge(),tn(h(),E)):"3D"===c&&(yield ve(),tn(h(),E)),Zt=!1,{launchAR:j?ge:void 0,launch3D:W?ve:void 0,closeAR:j?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.AR&&z()!==ye.QR)throw new t("AR not launched.");++me,G&&!bt&&Ot(),ae(),X(ye.None)})):void 0,close3D:W?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.Preview)throw new t("3D not launched.");++me,W&&!de()&&he(),X(ye.None)})):void 0,close:j||W?we:void 0}}))}function tn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const nn={setup:function(t){return e(this,void 0,void 0,(function*(){return Yt(t)}))}},on={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",(()=>en(n)))}))},version:g};export{on as plugin,nn as vision};
|
|
1
|
+
function e(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 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),c=s^s,l=new n[1]([c]);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.2-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 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 R,E,A;function C(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}(A.parse(e));return t.mapping=E.EquirectangularReflectionMapping,t.colorSpace=E.LinearSRGBColorSpace,t}const M=45,P=45,I=3,T=1.5,L=1,x=.5;let k,U,D,$,_,N,j=!1;const O=0,F=300,q=2e3,G=.05,W=1/(32*Math.PI);let V,K,Q,B=!1,H=1,z=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,c,l,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,S=1,L=1,N=1;const j={threeInit:()=>{f||(te(),i=new K.Scene,a=new K.PerspectiveCamera(25,1,.5),s=new V.OrbitControls(a,t),s.enableInteraction(),({renderShadow:l,shadowGroup:c}=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(M,P).rotateX(Math.PI/2),i=new k.MeshBasicMaterial({map:t.texture,opacity:x,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 c=new k.OrthographicCamera(-M/2,M/2,P/2,-P/2,0,I);function l(e){s.visible=!0,$.uniforms.tDiffuse.value=t.texture,$.uniforms.h.value=1*e/256,s.material=$,U.setRenderTarget(n),U.render(s,c),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,U.setRenderTarget(t),U.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=D;const o=U.getClearAlpha();U.setClearAlpha(0),U.setRenderTarget(t),U.render(e,c),e.overrideMaterial=null,l(T),l(.4*T),U.setRenderTarget(null),U.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=V).THREE,A=new e.RGBELoader,i.environment=C(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)}(Y,V),o=t,R.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-O,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,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: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>F&&y<=F+q))return o.style.opacity="0",void(y>F+2*q&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-F,t=2*Math.PI/q*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${G*r*Math.min(S,L)}px)`,s.updateTheta(W*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(Q,0,z-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===S&&n===L&&X===N||(t.width=Math.ceil(e*X*Z),t.height=Math.ceil(n*X*Z),S=e,L=n,N=X,g=!0)},target_:t};return J.set(t,j),j}function te(){if(B)return;V=window.ShopAR__THREE,K=V.THREE,Q=document.createElement("canvas");var e,t;Q.style.position="block",Y=new K.WebGLRenderer({powerPreference:"high-performance",canvas:Q,antialias:!0,alpha:!0}),Y.outputColorSpace=K.SRGBColorSpace,Y.toneMapping=K.ACESFilmicToneMapping,Y.setClearColor(new K.Color(16777215)),e=Y,t=V,j||(k=t.THREE,U=e,D=new k.MeshDepthMaterial,D.userData.darkness={value:L},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 k.ShaderMaterial(t.HorizontalBlurShader),$.depthTest=!1,_=new k.ShaderMaterial(t.VerticalBlurShader),_.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=S();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===H&&t===z&&n===X||(H=e,z=t,X=n,Y.setSize(H,z,!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 ce="shopar-error";function le(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 Se(){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 Re(){Se();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 c=function(){const e=se("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),l=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(l);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=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=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 S=le("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(S);const R=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);b.appendChild(R);const E=le("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);b.append(E);let A,C=ye.None,M=!1,P=!1,I=!1,T=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function x(){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 l},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;M=e,P=t,I=n,T=o,A=r,Ee(b,M),Ee(S,M&&(I||P)&&C===ye.None),Ee(R,M&&T&&C===ye.None),Ee(E,M&&C!==ye.None),L(),x(),M||""===(i=y).style.display&&Ee(i,!1)},getUIState:function(){return C},setUIState:function(e){C=e,C===ye.None?(L(),x(),M&&(Ee(y,!1),Ee(E,!1),(P||I)&&Ee(S,!0),T&&Ee(R,!0))):C!==ye.QR&&C!==ye.AR&&C!==ye.Preview||M&&(Ee(y,!1),Ee(S,!1),Ee(R,!1),Ee(E,!0))},setDefaultUIActions:function(e,t,n){M&&((P||I)&&(!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}`;S.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(A),S.onclick=e),T&&(R.onclick=t),E.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:x,showCameraError:function(){M&&Ee(y,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Ae=new Map;function Ce(t){let n=Ae.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Re()),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}}}(),Ae.set(t,n)):n.incrementSetupId_(),n}function Me(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()===ye.AR&&r(ye.None)}}let Pe;const Ie=new Uint8Array(16);function Te(){if(!Pe&&(Pe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Pe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Pe(Ie)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var xe={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(xe.randomUUID&&!t&&!e)return xe.randomUUID();const o=(e=e||{}).random||(e.rng||Te)();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 Ue="qrLaunch",De="arLaunch",$e="previewLaunch",_e="heartbeat";let Ne,je,Oe=!1;const Fe=[];function qe(){null==Ne&&(je=ke(),Ne=y(`${w}/shopar-analytics.js`),Ne.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),Fe.forEach((e=>e()))})))}function Ge(e){Oe?e():Fe.push(e)}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ve(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 Ke=200,Qe=10;let Be=!1,He=null,ze=[],Xe=[];function Ze(t){return e(this,void 0,void 0,(function*(){Be=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${w}/wasm/mediapipe`,t),He&&(console.log("previous interval present, clearing"),clearInterval(He));const o=[],r=[];He=setInterval((()=>e(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 ze)t(e)}({translation:a,rotation:s}),null==e?(o.push(t),r.push(i),o.length<Qe||(o.shift(),r.shift(),function(e,t){for(let n of Xe)n({faceWidth:e,IPD:t})}(Je(o),Je(r)))):console.error(`TrueScale predict error: ${e}`))}))),Ke)}))}function Ye(){Xe=[],ze=[],Be=!0}function Je(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function et(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.")}}))}var tt="undefined"!=typeof Float32Array?Float32Array:Array;function nt(){var e=new tt(16);return tt!=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 ot(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],S=n[2],R=n[3];return e[0]=y*o+b*s+S*u+R*m,e[1]=y*r+b*c+S*h+R*g,e[2]=y*i+b*l+S*p+R*v,e[3]=y*a+b*d+S*f+R*w,y=n[4],b=n[5],S=n[6],R=n[7],e[4]=y*o+b*s+S*u+R*m,e[5]=y*r+b*c+S*h+R*g,e[6]=y*i+b*l+S*p+R*v,e[7]=y*a+b*d+S*f+R*w,y=n[8],b=n[9],S=n[10],R=n[11],e[8]=y*o+b*s+S*u+R*m,e[9]=y*r+b*c+S*h+R*g,e[10]=y*i+b*l+S*p+R*v,e[11]=y*a+b*d+S*f+R*w,y=n[12],b=n[13],S=n[14],R=n[15],e[12]=y*o+b*s+S*u+R*m,e[13]=y*r+b*c+S*h+R*g,e[14]=y*i+b*l+S*p+R*v,e[15]=y*a+b*d+S*f+R*w,e}function rt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function it(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 at(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],S=o[1],R=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)*S,e[5]=(1-(u+g))*S,e[6]=(m+v)*S,e[7]=0,e[8]=(p+w)*R,e[9]=(m-v)*R,e[10]=(1-(u+f))*R,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function st(){var e=new tt(3);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function ct(e,t,n){var o=new tt(3);return o[0]=e,o[1]=t,o[2]=n,o}function lt(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 dt(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 ut(){var e=new tt(4);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}st(),function(){var e,t=(e=new tt(4),tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var ht;let pt,ft,mt;st(),ct(1,0,0),ct(0,1,0),ut(),ut(),ht=new tt(9),tt!=Float32Array&&(ht[1]=0,ht[2]=0,ht[3]=0,ht[5]=0,ht[6]=0,ht[7]=0),ht[0]=1,ht[4]=1,ht[8]=1;let gt,vt,wt,yt,bt=!0,St=null;const Rt=new Set;let Et,At,Ct,Mt,Pt,It,Tt;function Lt(){null==pt&&(pt=y(`${w}/shopar-deepar.js`))}function xt(){null==ft&&(ft=y(`${w}/shopar-true-scale.js`))}function kt(n){return e(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=n;return Pt=r,null==Et&&(Et=(()=>e(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 t("No camera available!");var e;const n=Ft(wt),r=We(n);gt=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:yt,additionalOptions:{hint:It,cameraConfig:{disableDefaultCamera:!0}}}),vt=yield Ve(r),yield qt(gt,vt,"user"===n),"Glasses"===wt&&(yield ft,Ze(vt),"DetectionLoop"!==Pt&&Kt((e=>{Mt=e.faceWidth})))})))()),Et}))}function Ut(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===wt&&(n=t,o=It,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!=gt&&(gt.shutdown(),gt=null,Et=null),wt=e,It=t)}function Dt(e){e!==yt&&(yt=e,null!=gt&>.changePreviewElement(yt))}function $t(e){St=e}function _t(e){gt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Mt){const e=137/(Mt+5);gt.changeParameterVector("GLASSES","","scale",e,e,e,0),gt.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=Wt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Wt("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);gt.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),gt.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return void console.error(e)}}(e),Ye(),Mt=null}e(),Gt("Glasses")}},gt.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Gt("Shoes"))},gt.callbacks.onWristTracked=t=>{t.detected&&(e(),Gt("Watches"))}}function Nt(t,n){return e(this,void 0,void 0,(function*(){return null!=At&&Ct===n||(yield At,At=gt.switchEffect(t),Ct=n),At}))}function jt(){return e(this,void 0,void 0,(function*(){if(null!=gt){if(bt=!1,null==vt){const e=Ft(wt),t=We(e);vt=yield Ve(t),yield qt(gt,vt,"user"===e),Ze(vt),"DetectionLoop"!==Pt&&Kt((e=>{Mt=e.faceWidth}))}!function(){if(null==St)return;if(null==wt||Rt.has(wt))return;St.style.visibility="visible",St.style.opacity="1"}(),gt.setPaused(bt),yt.style.display=""}}))}function Ot(){null!=gt&&(bt=!0,gt.setPaused(bt),Ye(),null!=vt&&null!=vt.srcObject&&vt.srcObject instanceof MediaStream&&(vt.srcObject.getTracks().forEach((e=>e.stop())),vt=null),function(){if(null==St)return;St.style.visibility="hidden",St.style.opacity="0"}(),gt.stopCamera(),yt.style.display="none")}function Ft(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function qt(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 Gt(e){null!=St&&(Rt.has(e)||(Rt.add(e),St.style.opacity="0"))}function Wt(e,t,n,o,r,i,a){const s=gt.getTransformationBetween(e,t),c=rt(st(),s),l=function(e,t){var n=new tt(3);it(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}(ut(),s);at(s,l,c,ct(a,a,a));const d=gt.getTransformationBetween(t,n),u=rt(st(),d);at(d,ut(),u,it(st(),d));const h=ot(nt(),s,d),p=rt(st(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=gt.getTransformationBetween(n,o)}catch(e){return console.error(e),f}const g=ot(nt(),d,m),v=ot(nt(),s,g),w=ct(p[0],i[1],i[2]),y=dt(st(),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,S=o*c-r*s,R=o*l-i*s,E=r*l-i*c,A=d*m-u*f,C=d*g-h*f,M=d*v-p*f,P=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*P+S*M-R*C+E*A;return L?(L=1/L,e[0]=(s*T-c*I+l*P)*L,e[1]=(r*I-o*T-i*P)*L,e[2]=(m*E-g*R+v*S)*L,e[3]=(h*R-u*E-p*S)*L,e[4]=(c*M-a*T-l*C)*L,e[5]=(n*T-r*M+i*C)*L,e[6]=(g*b-f*E-v*y)*L,e[7]=(d*E-h*b+p*y)*L,e[8]=(a*I-s*M+l*A)*L,e[9]=(o*M-n*I-i*A)*L,e[10]=(f*R-m*b+v*w)*L,e[11]=(u*b-d*R-p*w)*L,e[12]=(s*C-a*P-c*A)*L,e[13]=(n*P-o*C+r*A)*L,e[14]=(m*y-f*S-g*w)*L,e[15]=(d*S-u*y+h*w)*L,e):null}(nt(),v));let b=gt.getClosestPointOnMesh(o,y);try{const e=gt.getClosestPointOnMesh(r,y);lt(y,e)<lt(y,b)&&(b=e)}catch(e){console.error(e)}const S=dt(st(),b,g);return f-Math.atan2(S[0]-u[0],Math.abs(S[2]-u[2]))}function Vt(e){!function(e){ze.push(e)}(e)}function Kt(e){!function(e){Xe.push(e)}(e)}function Qt(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(l[c]=Math.min(76,r)*((a>>5)-1),152===l[c]&&(l[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)l[c]^=l[i]<<13,l[c]^=l[i]>>17,l[c]^=l[i]<<5,v[e]=v[e]^l[c];return i^=l[0],i^=l[1],i^=l[2],v}))}function Bt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Ht(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const zt=["AR","3D"];function Xt(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;Bt(n,"apiKey"),Ht(n,"apiKey"),Bt(o,"sku"),Ht(o,"sku"),Bt(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",zt),null!=a&&Ht(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=c&&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.`)}}(c,"strings",ie)}let Zt=!1;function Yt(n){return e(this,void 0,void 0,(function*(){const{targetElement:o}=n;w.update(n.baseUrl),qe();const{trackEvent:r}=function(e){const t=performance.now(),n=ke();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:g,sessionId:je,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Ge((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(n.apiKey);r("visionSetup");const i=yield function(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:n,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 o.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(n.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Ce(o),{getSetupId:c,findUI:l}=s,u=c();Lt(),xt();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:v,setUIState:y,startDeepARLoading:b,stopDeepARLoading:S,showCameraError:R}=l();if(v()!=ye.None)throw Error("UI state is not None, this is weird..");y(ye.AR),h(o),m(!1,!1,!0,!1,void 0),b(),yield pt,Jt(c(),u);try{r("visionArLaunch"),Ot(),Ut("Glasses",["faceInit"]),Dt(f()),yield kt({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Jt(c(),u),yield jt(),Jt(c(),u)}catch(e){const n=e instanceof Error;throw r("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),R(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{S()}return Zt=!0,{registerFacePoseListener:e=>{Zt&&(r("registerFacePoseListener"),Vt(e))},registerFaceMeasurementListener:e=>{Zt&&(r("registerFaceMeasurementListener"),Kt(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Zt&&(r("switchEffect",{arUrl:t}),function(e){gt.switchEffect(e)}(t))})),clearEffect:()=>{Zt&&(r("clearEffect"),gt.clearEffect())}}}))}function Jt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function en(n){var o,r;return e(this,void 0,void 0,(function*(){Xt(n);const{apiKey:i,sku:a,targetElement:s,initialState:c}=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 l=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=Ce(s),{getSetupId:h,findUI:v,findQR:S,findThree:R}=u,E=h();qe();const{trackEvent:A,arInteracted:C,previewInteracted:M}=function(e,t){const n=performance.now(),o=ke();let r=0,i=0,a=0,s=0,c=0,l=!1;window.setInterval((()=>{l&&(r=i+a,l=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Ge((()=>{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);A("setup",{hostname:window.location.hostname});const P=yield l;A("apiResponse",P);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_}=P;tn(h(),E);const j=null!=T&&function(e){return null!=e&&f.includes(e)}(I),O=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),F=j&&function(e){return null!=e&&m.includes(e)}(I),q=O&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==Tt&&(Tt=y(`${w}/shopar-platform.js`)),yield Tt,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),G=j&&!q,W=null!=D;if(tn(h(),E),q&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),G&&(Lt(),function(e){e!==mt&&(mt=e,et(e),At=null,Ye())}(T),"Glasses"===I&&xt()),W){null==N&&(N=y(`${w}/shopar-three.js`));const e=255;Qt(D,(new Date).getTime()+e,Math.random()*e),et(null!=$?$:`${w}/env/default.hdr`)}const{setTargetElement:V,getDeepARTarget:K,getDeepARPrompt:Q,customizeDeepARPrompt:B,setVisibilityParameters:H,getUIState:z,setUIState:X,setDefaultUIActions:Z,startDeepARLoading:Y,stopDeepARLoading:J,startThreeLoading:ee,stopThreeLoading:te,showCameraError:ne}=v();V(s);H(null==n.defaultUI||n.defaultUI,q,G,W,I),B(null!=k?k:"",null!=U?U:""),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||oe()||ae(),z()!==ye.AR||bt||Ot(),z()!==ye.Preview||de()||he(),X(ye.None)}));const{qrPaused:oe,qrDraw:ie,qrPause:ae}=S(),{threeInit:se,threeParse:ce,threeLoad:le,threePaused:de,threeResume:ue,threePause:he,threeSetToneMapping:pe,threeSetOnInteracted:fe}=R();let me=0;if(z()===ye.QR){if(!oe())if(q){A(Ue);try{yield ie(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ae(),X(ye.None)}else if(z()===ye.AR){if(!bt)if(G&&!Zt){A(De);const e=yield et(T);tn(h(),E),Me(u),Ut(I),Dt(K()),$t(x?Q():null),yield Nt(e,T),_t(C),tn(h(),E)}else Ot(),X(ye.None)}else if(z()===ye.Preview&&!de())if(W){A($e),ee();const e=255,t=yield Qt(D,(new Date).getTime()+e,Math.random()*e);tn(h(),E);const n=yield et(null!=$?$:`${w}/env/default.hdr`);tn(h(),E);const o=yield ce(t,n,`${D}${$}`);tn(h(),E),le(o,I),pe(null!=_?_:"ACES"),fe(M),te()}else he(),X(ye.None);const ge=()=>e(this,void 0,void 0,(function*(){if(q){if(z()===ye.QR||z()===ye.AR)throw new t("AR already launched.");try{A(Ue);const e=++me;if(z()===ye.Preview&&W&&!de()&&he(),X(ye.QR),yield ie(i,a),me!==e)return;return void tn(h(),E)}catch(e){const n=e instanceof Error;throw A("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!G)throw new t("Model does not have AR enabled.");if(z()===ye.AR)throw new t("AR already launched.");try{A(De);const e=++me;z()===ye.Preview&&W&&!de()&&he(),Me(u),X(ye.AR),Y();const t=yield et(T);if(me!==e)return;if(tn(h(),E),yield pt,me!==e)return;if(tn(h(),E),Ot(),Ut(I),Dt(K()),$t(x?Q():null),yield kt({licenseKey:L}),me!==e)return;if(tn(h(),E),yield Nt(t,T),_t(C),me!==e)return;if(tn(h(),E),yield jt(),me!==e)return;tn(h(),E)}catch(e){const n=e instanceof Error;throw A("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),ne(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{J()}})),ve=()=>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{A($e);const e=++me;z()===ye.AR&&(G&&!bt&&Ot(),ae()),X(ye.Preview),ee();const t=255,n=yield Qt(D,(new Date).getTime()+t,Math.random()*t);if(me!==e)return;tn(h(),E);const o=yield et(null!=$?$:`${w}/env/default.hdr`);if(me!==e)return;if(tn(h(),E),yield N,me!==e)return;if(tn(h(),E),se(),me!==e)return;tn(h(),E);const r=yield ce(n,o,`${D}${$}`);if(me!==e)return;tn(h(),E),le(r,I),pe(null!=_?_:"ACES"),fe(M),ue()}catch(e){const n=e instanceof Error;throw A("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{te()}})),we=()=>e(this,void 0,void 0,(function*(){if(z()===ye.None)throw new t("Neither AR or 3D launched.");++me,z()===ye.QR||z()===ye.AR?(G&&!bt&&Ot(),ae()):z()===ye.Preview&&W&&!de()&&he(),X(ye.None)}));return Z(ge,ve,we),"AR"===c?(yield ge(),tn(h(),E)):"3D"===c&&(yield ve(),tn(h(),E)),Zt=!1,{launchAR:j?ge:void 0,launch3D:W?ve:void 0,closeAR:j?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.AR&&z()!==ye.QR)throw new t("AR not launched.");++me,G&&!bt&&Ot(),ae(),X(ye.None)})):void 0,close3D:W?()=>e(this,void 0,void 0,(function*(){if(z()!==ye.Preview)throw new t("3D not launched.");++me,W&&!de()&&he(),X(ye.None)})):void 0,close:j||W?we:void 0}}))}function tn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const nn={setup:function(t){return e(this,void 0,void 0,(function*(){return Yt(t)}))}},on={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",(()=>en(n)))}))},version:g};export{on as plugin,nn as vision};
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -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-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 S;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 A,E,C;function M(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,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,V=1/(32*Math.PI);let K,Q,B,H=!1,z=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,S=1,R=1,x=1;const j={threeInit:()=>{f||(ne(),i=new Q.Scene,a=new Q.PerspectiveCamera(25,1,.5),s=new K.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(P,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(-P/2,P/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=K).THREE,C=new t.RGBELoader,i.environment=M(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,K),o=e,A.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new Q.Box3).setFromObject(e.scene);c.position.y=n.min.y-F,i.add(c),l(),i.traverse((e=>{if(e instanceof Q.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Q.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(K.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,Q.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:Q.ACESFilmicToneMapping,Linear:Q.LinearToneMapping,Neutral:Q.NeutralToneMapping}[e||"ACES"]||Q.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(S,R)}px)`,s.updateTheta(V*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===S&&n===R&&Z===x||(e.width=Math.ceil(t*Z*Y),e.height=Math.ceil(n*Z*Y),S=t,R=n,x=Z,g=!0)},target_:e};return ee.set(e,j),j}function ne(){if(H)return;K=window.ShopAR__THREE,Q=K.THREE,B=document.createElement("canvas");var e,t;B.style.position="block",J=new Q.WebGLRenderer({powerPreference:"high-performance",canvas:B,antialias:!0,alpha:!0}),J.outputColorSpace=Q.SRGBColorSpace,J.toneMapping=Q.ACESFilmicToneMapping,J.setClearColor(new Q.Color(16777215)),e=J,t=K,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(),H=!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=R();e=Math.ceil(e*n*Y),t=Math.ceil(t*n*Y),e===z&&t===X&&n===Z||(z=e,X=t,Z=n,J.setSize(z,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 ce(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 de(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ce("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 Se=!1;function Re(){Se||(!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.")}}(),Se=!0)}function Ae(){Re();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 c=function(){const e=ce("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),l=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(l);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=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=ce("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 S=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(S);const R=de("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);b.appendChild(R);const A=de("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);b.append(A);let E,C=be.None,M=!1,P=!1,I=!1,T=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function x(){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 l},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;M=e,P=t,I=n,T=o,E=r,Ee(b,M),Ee(S,M&&(I||P)&&C===be.None),Ee(R,M&&T&&C===be.None),Ee(A,M&&C!==be.None),L(),x(),M||""===(i=w).style.display&&Ee(i,!1)},getUIState:function(){return C},setUIState:function(e){C=e,C===be.None?(L(),x(),M&&(Ee(w,!1),Ee(A,!1),(P||I)&&Ee(S,!0),T&&Ee(R,!0))):C!==be.QR&&C!==be.AR&&C!==be.Preview||M&&(Ee(w,!1),Ee(S,!1),Ee(R,!1),Ee(A,!0))},setDefaultUIActions:function(e,t,n){M&&((P||I)&&(!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}`;S.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(E),S.onclick=e),T&&(R.onclick=t),A.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:x,showCameraError:function(){M&&Ee(w,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Ce=new Map;function Me(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 S;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 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()===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 Ve(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ke(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 Qe=200,Be=10;let He=!1,ze=null,Xe=[],Ze=[];function Ye(e){return t(this,void 0,void 0,(function*(){He=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,e),ze&&(console.log("previous interval present, clearing"),clearInterval(ze));const o=[],r=[];ze=setInterval((()=>t(this,void 0,void 0,(function*(){if(He)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());He||(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<Be||(o.shift(),r.shift(),function(e,t){for(let n of Ze)n({faceWidth:e,IPD:t})}(et(o),et(r)))):console.error(`TrueScale predict error: ${e}`))}))),Qe)}))}function Je(){Ze=[],Xe=[],He=!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],S=n[2],R=n[3];return e[0]=y*o+b*s+S*u+R*m,e[1]=y*r+b*c+S*h+R*g,e[2]=y*i+b*l+S*p+R*v,e[3]=y*a+b*d+S*f+R*w,y=n[4],b=n[5],S=n[6],R=n[7],e[4]=y*o+b*s+S*u+R*m,e[5]=y*r+b*c+S*h+R*g,e[6]=y*i+b*l+S*p+R*v,e[7]=y*a+b*d+S*f+R*w,y=n[8],b=n[9],S=n[10],R=n[11],e[8]=y*o+b*s+S*u+R*m,e[9]=y*r+b*c+S*h+R*g,e[10]=y*i+b*l+S*p+R*v,e[11]=y*a+b*d+S*f+R*w,y=n[12],b=n[13],S=n[14],R=n[15],e[12]=y*o+b*s+S*u+R*m,e[13]=y*r+b*c+S*h+R*g,e[14]=y*i+b*l+S*p+R*v,e[15]=y*a+b*d+S*f+R*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],S=o[1],R=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)*S,e[5]=(1-(u+g))*S,e[6]=(m+v)*S,e[7]=0,e[8]=(p+w)*R,e[9]=(m-v)*R,e[10]=(1-(u+f))*R,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,St=!0,Rt=null;const At=new Set;let Et,Ct,Mt,Pt,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=Ve(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 Ke(r),yield Gt(vt,wt,"user"===t),"Glasses"===yt&&(yield mt,Ye(wt),"DetectionLoop"!==It&&Qt((e=>{Pt=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){Rt=e}function Nt(e){vt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Pt){const e=137/(Pt+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=Vt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Vt("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 void console.error(e)}}(e),Je(),Pt=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&&Mt===n||(yield Ct,Ct=vt.switchEffect(e),Mt=n),Ct}))}function Ot(){return t(this,void 0,void 0,(function*(){if(null!=vt){if(St=!1,null==wt){const e=qt(yt),t=Ve(e);wt=yield Ke(t),yield Gt(vt,wt,"user"===e),Ye(wt),"DetectionLoop"!==It&&Qt((e=>{Pt=e.faceWidth}))}!function(){if(null==Rt)return;if(null==yt||At.has(yt))return;Rt.style.visibility="visible",Rt.style.opacity="1"}(),vt.setPaused(St),bt.style.display=""}}))}function Ft(){null!=vt&&(St=!0,vt.setPaused(St),Je(),null!=wt&&null!=wt.srcObject&&wt.srcObject instanceof MediaStream&&(wt.srcObject.getTracks().forEach((e=>e.stop())),wt=null),function(){if(null==Rt)return;Rt.style.visibility="hidden",Rt.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!=Rt&&(At.has(e)||(At.add(e),Rt.style.opacity="0"))}function Vt(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 console.error(e),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,S=o*c-r*s,R=o*l-i*s,A=r*l-i*c,E=d*m-u*f,C=d*g-h*f,M=d*v-p*f,P=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*P+S*M-R*C+A*E;return L?(L=1/L,e[0]=(s*T-c*I+l*P)*L,e[1]=(r*I-o*T-i*P)*L,e[2]=(m*A-g*R+v*S)*L,e[3]=(h*R-u*A-p*S)*L,e[4]=(c*M-a*T-l*C)*L,e[5]=(n*T-r*M+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*M+l*E)*L,e[9]=(o*M-n*I-i*E)*L,e[10]=(f*R-m*b+v*w)*L,e[11]=(u*b-d*R-p*w)*L,e[12]=(s*C-a*P-c*E)*L,e[13]=(n*P-o*C+r*E)*L,e[14]=(m*y-f*S-g*w)*L,e[15]=(d*S-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){console.error(e)}const S=ut(ct(),b,g);return f-Math.atan2(S[0]-u[0],Math.abs(S[2]-u[2]))}function Kt(e){!function(e){Xe.push(e)}(e)}function Qt(e){!function(e){Ze.push(e)}(e)}function Bt(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 Ht(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function zt(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;Ht(t,"apiKey"),zt(t,"apiKey"),Ht(o,"sku"),zt(o,"sku"),Ht(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&&zt(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=Me(o),{getSetupId:c,findUI:l}=s,d=c();xt(),kt();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:S,showCameraError:R}=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:""}),R(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{S()}return Yt=!0,{registerFacePoseListener:e=>{Yt&&(r("registerFacePoseListener"),Kt(e))},registerFaceMeasurementListener:e=>{Yt&&(r("registerFaceMeasurementListener"),Qt(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())}}}))}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=Me(s),{getSetupId:h,findUI:p,findQR:w,findThree:R}=d,A=h();Ge();const{trackEvent:E,arInteracted:C,previewInteracted:M}=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 P=yield l;E("apiResponse",P);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_}=P;nn(h(),A);const N=null!=T&&function(e){return null!=e&&m.includes(e)}(I),O=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),F=N&&function(e){return null!=e&&g.includes(e)}(I),q=O&&F&&!(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)}))}()),G=N&&!q,W=null!=D;if(nn(h(),A),q&&function(){t(this,void 0,void 0,(function*(){null==S&&(S=b(`${y}/shopar-qr.js`))}))}(),G&&(xt(),function(e){e!==gt&&(gt=e,tt(e),Ct=null,Je())}(T),"Glasses"===I&&kt()),W){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;Bt(D,(new Date).getTime()+e,Math.random()*e),tt(null!=$?$:`${y}/env/default.hdr`)}const{setTargetElement:V,getDeepARTarget:K,getDeepARPrompt:Q,customizeDeepARPrompt:B,setVisibilityParameters:H,getUIState:z,setUIState:X,setDefaultUIActions:Z,startDeepARLoading:Y,stopDeepARLoading:J,startThreeLoading:ee,stopThreeLoading:te,showCameraError:ne}=p();V(s);H(null==e.defaultUI||e.defaultUI,q,G,W,I),B(null!=k?k:"",null!=U?U:""),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||oe()||ae(),z()!==be.AR||St||Ft(),z()!==be.Preview||de()||he(),X(be.None)}));const{qrPaused:oe,qrDraw:re,qrPause:ae}=w(),{threeInit:se,threeParse:ce,threeLoad:le,threePaused:de,threeResume:ue,threePause:he,threeSetToneMapping:pe,threeSetOnInteracted:fe}=R();let me=0;if(z()===be.QR){if(!oe())if(q){E(De);try{yield re(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ae(),X(be.None)}else if(z()===be.AR){if(!St)if(G){E($e);const e=yield tt(T);nn(h(),A),Pe(d),Dt(I),$t(K()),_t(x?Q():null),yield jt(e,T),Nt(C),nn(h(),A)}else Ft(),X(be.None)}else if(z()===be.Preview&&!de())if(W){E(_e),ee();const e=255,t=yield Bt(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 ce(t,n,`${D}${$}`);nn(h(),A),le(o,I),pe(null!=_?_:"ACES"),fe(M),te()}else he(),X(be.None);const ge=()=>t(this,void 0,void 0,(function*(){if(q){if(z()===be.QR||z()===be.AR)throw new n("AR already launched.");try{E(De);const e=++me;if(z()===be.Preview&&W&&!de()&&he(),X(be.QR),yield re(i,a),me!==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(!G)throw new n("Model does not have AR enabled.");if(z()===be.AR)throw new n("AR already launched.");try{E($e);const e=++me;z()===be.Preview&&W&&!de()&&he(),Pe(d),X(be.AR),Y();const t=yield tt(T);if(me!==e)return;if(nn(h(),A),yield ft,me!==e)return;if(nn(h(),A),Ft(),Dt(I),$t(K()),_t(x?Q():null),yield Ut({licenseKey:L}),me!==e)return;if(nn(h(),A),yield jt(t,T),Nt(C),me!==e)return;if(nn(h(),A),yield Ot(),me!==e)return;nn(h(),A)}catch(e){const t=e instanceof Error;throw E("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),ne(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{J()}})),ve=()=>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(_e);const e=++me;z()===be.AR&&(G&&!St&&Ft(),ae()),X(be.Preview),ee();const t=255,n=yield Bt(D,(new Date).getTime()+t,Math.random()*t);if(me!==e)return;nn(h(),A);const o=yield tt(null!=$?$:`${y}/env/default.hdr`);if(me!==e)return;if(nn(h(),A),yield j,me!==e)return;if(nn(h(),A),se(),me!==e)return;nn(h(),A);const r=yield ce(n,o,`${D}${$}`);if(me!==e)return;nn(h(),A),le(r,I),pe(null!=_?_:"ACES"),fe(M),ue()}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{te()}})),we=()=>t(this,void 0,void 0,(function*(){if(z()===be.None)throw new n("Neither AR or 3D launched.");++me,z()===be.QR||z()===be.AR?(G&&!St&&Ft(),ae()):z()===be.Preview&&W&&!de()&&he(),X(be.None)}));return Z(ge,ve,we),"AR"===c?(yield ge(),nn(h(),A)):"3D"===c&&(yield ve(),nn(h(),A)),Yt=!1,{launchAR:N?ge:void 0,launch3D:W?ve:void 0,closeAR:N?()=>t(this,void 0,void 0,(function*(){if(z()!==be.AR&&z()!==be.QR)throw new n("AR not launched.");++me,G&&!St&&Ft(),ae(),X(be.None)})):void 0,close3D:W?()=>t(this,void 0,void 0,(function*(){if(z()!==be.Preview)throw new n("3D not launched.");++me,W&&!de()&&he(),X(be.None)})):void 0,close:N||W?we: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,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-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 S;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 A,E,C;function M(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,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,V=1/(32*Math.PI);let K,Q,B,H=!1,z=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,S=1,R=1,x=1;const j={threeInit:()=>{f||(ne(),i=new Q.Scene,a=new Q.PerspectiveCamera(25,1,.5),s=new K.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(P,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(-P/2,P/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=K).THREE,C=new t.RGBELoader,i.environment=M(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,K),o=e,A.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new Q.Box3).setFromObject(e.scene);c.position.y=n.min.y-F,i.add(c),l(),i.traverse((e=>{if(e instanceof Q.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Q.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(K.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,Q.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:Q.ACESFilmicToneMapping,Linear:Q.LinearToneMapping,Neutral:Q.NeutralToneMapping}[e||"ACES"]||Q.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(S,R)}px)`,s.updateTheta(V*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===S&&n===R&&Z===x||(e.width=Math.ceil(t*Z*Y),e.height=Math.ceil(n*Z*Y),S=t,R=n,x=Z,g=!0)},target_:e};return ee.set(e,j),j}function ne(){if(H)return;K=window.ShopAR__THREE,Q=K.THREE,B=document.createElement("canvas");var e,t;B.style.position="block",J=new Q.WebGLRenderer({powerPreference:"high-performance",canvas:B,antialias:!0,alpha:!0}),J.outputColorSpace=Q.SRGBColorSpace,J.toneMapping=Q.ACESFilmicToneMapping,J.setClearColor(new Q.Color(16777215)),e=J,t=K,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(),H=!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=R();e=Math.ceil(e*n*Y),t=Math.ceil(t*n*Y),e===z&&t===X&&n===Z||(z=e,X=t,Z=n,J.setSize(z,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 ce(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 de(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ce("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 Se=!1;function Re(){Se||(!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.")}}(),Se=!0)}function Ae(){Re();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 c=function(){const e=ce("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),l=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(l);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=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=ce("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 S=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(S);const R=de("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);b.appendChild(R);const A=de("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);b.append(A);let E,C=be.None,M=!1,P=!1,I=!1,T=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function x(){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 l},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){i.textContent=e,a.src=t},setVisibilityParameters:function(e,t,n,o,r){var i;M=e,P=t,I=n,T=o,E=r,Ee(b,M),Ee(S,M&&(I||P)&&C===be.None),Ee(R,M&&T&&C===be.None),Ee(A,M&&C!==be.None),L(),x(),M||""===(i=w).style.display&&Ee(i,!1)},getUIState:function(){return C},setUIState:function(e){C=e,C===be.None?(L(),x(),M&&(Ee(w,!1),Ee(A,!1),(P||I)&&Ee(S,!0),T&&Ee(R,!0))):C!==be.QR&&C!==be.AR&&C!==be.Preview||M&&(Ee(w,!1),Ee(S,!1),Ee(R,!1),Ee(A,!0))},setDefaultUIActions:function(e,t,n){M&&((P||I)&&(!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}`;S.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(E),S.onclick=e),T&&(R.onclick=t),A.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){v.classList.add("active"),f.style.visibility="visible"},stopThreeLoading:x,showCameraError:function(){M&&Ee(w,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Ce=new Map;function Me(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 S;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 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()===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 Ve(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ke(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 Qe=200,Be=10;let He=!1,ze=null,Xe=[],Ze=[];function Ye(e){return t(this,void 0,void 0,(function*(){He=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,e),ze&&(console.log("previous interval present, clearing"),clearInterval(ze));const o=[],r=[];ze=setInterval((()=>t(this,void 0,void 0,(function*(){if(He)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());He||(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<Be||(o.shift(),r.shift(),function(e,t){for(let n of Ze)n({faceWidth:e,IPD:t})}(et(o),et(r)))):console.error(`TrueScale predict error: ${e}`))}))),Qe)}))}function Je(){Ze=[],Xe=[],He=!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],S=n[2],R=n[3];return e[0]=y*o+b*s+S*u+R*m,e[1]=y*r+b*c+S*h+R*g,e[2]=y*i+b*l+S*p+R*v,e[3]=y*a+b*d+S*f+R*w,y=n[4],b=n[5],S=n[6],R=n[7],e[4]=y*o+b*s+S*u+R*m,e[5]=y*r+b*c+S*h+R*g,e[6]=y*i+b*l+S*p+R*v,e[7]=y*a+b*d+S*f+R*w,y=n[8],b=n[9],S=n[10],R=n[11],e[8]=y*o+b*s+S*u+R*m,e[9]=y*r+b*c+S*h+R*g,e[10]=y*i+b*l+S*p+R*v,e[11]=y*a+b*d+S*f+R*w,y=n[12],b=n[13],S=n[14],R=n[15],e[12]=y*o+b*s+S*u+R*m,e[13]=y*r+b*c+S*h+R*g,e[14]=y*i+b*l+S*p+R*v,e[15]=y*a+b*d+S*f+R*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],S=o[1],R=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)*S,e[5]=(1-(u+g))*S,e[6]=(m+v)*S,e[7]=0,e[8]=(p+w)*R,e[9]=(m-v)*R,e[10]=(1-(u+f))*R,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,St=!0,Rt=null;const At=new Set;let Et,Ct,Mt,Pt,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=Ve(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 Ke(r),yield Gt(vt,wt,"user"===t),"Glasses"===yt&&(yield mt,Ye(wt),"DetectionLoop"!==It&&Qt((e=>{Pt=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){Rt=e}function Nt(e){vt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Pt){const e=137/(Pt+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=Vt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Vt("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 void console.error(e)}}(e),Je(),Pt=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&&Mt===n||(yield Ct,Ct=vt.switchEffect(e),Mt=n),Ct}))}function Ot(){return t(this,void 0,void 0,(function*(){if(null!=vt){if(St=!1,null==wt){const e=qt(yt),t=Ve(e);wt=yield Ke(t),yield Gt(vt,wt,"user"===e),Ye(wt),"DetectionLoop"!==It&&Qt((e=>{Pt=e.faceWidth}))}!function(){if(null==Rt)return;if(null==yt||At.has(yt))return;Rt.style.visibility="visible",Rt.style.opacity="1"}(),vt.setPaused(St),bt.style.display=""}}))}function Ft(){null!=vt&&(St=!0,vt.setPaused(St),Je(),null!=wt&&null!=wt.srcObject&&wt.srcObject instanceof MediaStream&&(wt.srcObject.getTracks().forEach((e=>e.stop())),wt=null),function(){if(null==Rt)return;Rt.style.visibility="hidden",Rt.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!=Rt&&(At.has(e)||(At.add(e),Rt.style.opacity="0"))}function Vt(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 console.error(e),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,S=o*c-r*s,R=o*l-i*s,A=r*l-i*c,E=d*m-u*f,C=d*g-h*f,M=d*v-p*f,P=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*P+S*M-R*C+A*E;return L?(L=1/L,e[0]=(s*T-c*I+l*P)*L,e[1]=(r*I-o*T-i*P)*L,e[2]=(m*A-g*R+v*S)*L,e[3]=(h*R-u*A-p*S)*L,e[4]=(c*M-a*T-l*C)*L,e[5]=(n*T-r*M+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*M+l*E)*L,e[9]=(o*M-n*I-i*E)*L,e[10]=(f*R-m*b+v*w)*L,e[11]=(u*b-d*R-p*w)*L,e[12]=(s*C-a*P-c*E)*L,e[13]=(n*P-o*C+r*E)*L,e[14]=(m*y-f*S-g*w)*L,e[15]=(d*S-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){console.error(e)}const S=ut(ct(),b,g);return f-Math.atan2(S[0]-u[0],Math.abs(S[2]-u[2]))}function Kt(e){!function(e){Xe.push(e)}(e)}function Qt(e){!function(e){Ze.push(e)}(e)}function Bt(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 Ht(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function zt(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;Ht(t,"apiKey"),zt(t,"apiKey"),Ht(o,"sku"),zt(o,"sku"),Ht(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&&zt(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=Me(o),{getSetupId:c,findUI:l}=s,d=c();xt(),kt();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:S,showCameraError:R}=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:""}),R(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{S()}return Yt=!0,{registerFacePoseListener:e=>{Yt&&(r("registerFacePoseListener"),Kt(e))},registerFaceMeasurementListener:e=>{Yt&&(r("registerFaceMeasurementListener"),Qt(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())}}}))}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=Me(s),{getSetupId:h,findUI:p,findQR:w,findThree:R}=d,A=h();Ge();const{trackEvent:E,arInteracted:C,previewInteracted:M}=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 P=yield l;E("apiResponse",P);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_}=P;nn(h(),A);const N=null!=T&&function(e){return null!=e&&m.includes(e)}(I),O=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),F=N&&function(e){return null!=e&&g.includes(e)}(I),q=O&&F&&!(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)}))}()),G=N&&!q,W=null!=D;if(nn(h(),A),q&&function(){t(this,void 0,void 0,(function*(){null==S&&(S=b(`${y}/shopar-qr.js`))}))}(),G&&(xt(),function(e){e!==gt&&(gt=e,tt(e),Ct=null,Je())}(T),"Glasses"===I&&kt()),W){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;Bt(D,(new Date).getTime()+e,Math.random()*e),tt(null!=$?$:`${y}/env/default.hdr`)}const{setTargetElement:V,getDeepARTarget:K,getDeepARPrompt:Q,customizeDeepARPrompt:B,setVisibilityParameters:H,getUIState:z,setUIState:X,setDefaultUIActions:Z,startDeepARLoading:Y,stopDeepARLoading:J,startThreeLoading:ee,stopThreeLoading:te,showCameraError:ne}=p();V(s);H(null==e.defaultUI||e.defaultUI,q,G,W,I),B(null!=k?k:"",null!=U?U:""),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||oe()||ae(),z()!==be.AR||St||Ft(),z()!==be.Preview||de()||he(),X(be.None)}));const{qrPaused:oe,qrDraw:re,qrPause:ae}=w(),{threeInit:se,threeParse:ce,threeLoad:le,threePaused:de,threeResume:ue,threePause:he,threeSetToneMapping:pe,threeSetOnInteracted:fe}=R();let me=0;if(z()===be.QR){if(!oe())if(q){E(De);try{yield re(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ae(),X(be.None)}else if(z()===be.AR){if(!St)if(G&&!Yt){E($e);const e=yield tt(T);nn(h(),A),Pe(d),Dt(I),$t(K()),_t(x?Q():null),yield jt(e,T),Nt(C),nn(h(),A)}else Ft(),X(be.None)}else if(z()===be.Preview&&!de())if(W){E(_e),ee();const e=255,t=yield Bt(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 ce(t,n,`${D}${$}`);nn(h(),A),le(o,I),pe(null!=_?_:"ACES"),fe(M),te()}else he(),X(be.None);const ge=()=>t(this,void 0,void 0,(function*(){if(q){if(z()===be.QR||z()===be.AR)throw new n("AR already launched.");try{E(De);const e=++me;if(z()===be.Preview&&W&&!de()&&he(),X(be.QR),yield re(i,a),me!==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(!G)throw new n("Model does not have AR enabled.");if(z()===be.AR)throw new n("AR already launched.");try{E($e);const e=++me;z()===be.Preview&&W&&!de()&&he(),Pe(d),X(be.AR),Y();const t=yield tt(T);if(me!==e)return;if(nn(h(),A),yield ft,me!==e)return;if(nn(h(),A),Ft(),Dt(I),$t(K()),_t(x?Q():null),yield Ut({licenseKey:L}),me!==e)return;if(nn(h(),A),yield jt(t,T),Nt(C),me!==e)return;if(nn(h(),A),yield Ot(),me!==e)return;nn(h(),A)}catch(e){const t=e instanceof Error;throw E("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),ne(),Ft(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{J()}})),ve=()=>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(_e);const e=++me;z()===be.AR&&(G&&!St&&Ft(),ae()),X(be.Preview),ee();const t=255,n=yield Bt(D,(new Date).getTime()+t,Math.random()*t);if(me!==e)return;nn(h(),A);const o=yield tt(null!=$?$:`${y}/env/default.hdr`);if(me!==e)return;if(nn(h(),A),yield j,me!==e)return;if(nn(h(),A),se(),me!==e)return;nn(h(),A);const r=yield ce(n,o,`${D}${$}`);if(me!==e)return;nn(h(),A),le(r,I),pe(null!=_?_:"ACES"),fe(M),ue()}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{te()}})),we=()=>t(this,void 0,void 0,(function*(){if(z()===be.None)throw new n("Neither AR or 3D launched.");++me,z()===be.QR||z()===be.AR?(G&&!St&&Ft(),ae()):z()===be.Preview&&W&&!de()&&he(),X(be.None)}));return Z(ge,ve,we),"AR"===c?(yield ge(),nn(h(),A)):"3D"===c&&(yield ve(),nn(h(),A)),Yt=!1,{launchAR:N?ge:void 0,launch3D:W?ve:void 0,closeAR:N?()=>t(this,void 0,void 0,(function*(){if(z()!==be.AR&&z()!==be.QR)throw new n("AR not launched.");++me,G&&!St&&Ft(),ae(),X(be.None)})):void 0,close3D:W?()=>t(this,void 0,void 0,(function*(){if(z()!==be.Preview)throw new n("3D not launched.");++me,W&&!de()&&he(),X(be.None)})):void 0,close:N||W?we: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}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "0.1.2-alpha.
|
|
3
|
+
"version": "0.1.2-alpha.1",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"main": "dist/shopar-plugin.esm.js",
|
|
6
6
|
"module": "dist/shopar-plugin.esm.js",
|